-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mirage-crypto-ec: implementation of SECP256K1 #259
base: main
Are you sure you want to change the base?
Conversation
CI failures seem to be unrelated. |
As an alternative I can also migrate the NIST curves to ECCKiila code, which is about 10% faster and would make the code simpler and more unified. On my Mac (M3, arm64)
ecckiila:
|
FWIW: I will also implement Brainpool curves. Please let me know, if you are interested in these as well. |
Thank you for your PR. Now, I have some questions:
Is this true across CPU architectures, or only on your Apple silicon? As you may have noticed, the other EC code is taken from projects with verification in mind, how much review and formal verification did ECCkiila get?
Sure, in the end it all depends on code clarity and binary size (we dropped P224 for the binary size reason). |
The license (MIT) is included in the generated file: mirage-crypto/ec/native/secp256k1.h Lines 1 to 24 in 1a4e3f2
The fiat code is automatically embedded in the file generated by ECCKiila. So, you want me to create the fiat files separately and remove them from the generated ECCKiila file? I sure can do that, just want to make sure we are on one page.
Unfortunately there doesn't seem to be any official or common test vectors for ECDSA signing and secp256k1, so I frankensteined them from some single test vectors I found at different places. (One of them is from Bouncy Castle IIRC)
Ok, but some code I had to change in order to make it reusable. Or would you prefer code duplication and untouched old code?
I just tested it on x86_64, there it is also around 10%.
You mean other projects than fiat-crypto? They don't have any formal verification beyond fiat. From their paper:
If the current EC arithmetic in mirage-crypto has stronger guarantees, that is of course an argument to keep the implementation, despite the slight performance difference. I don't know how much review it received, I only know that the fiat project referred you to it, which can be interpreted as a slight endorsement. Let me know what you prefer, and I will proceed accordingly. |
This change modularizes the point representation in preparation for the SECP256K1 implementation, which is based on ECCKiila and uses a different point representation.
I reduced the diff as much as possible without creating too much duplicate code, and split it up in two commits. The first is a pure restructuring without functional difference. The second is the addition of the new curve. Hope that helps to digest it. I added makefile targets for the fiat code generator (took ages to compile it), and replaced the embedded ones in the ECCKiila generated ones with |
I looked a bit more into the point add and double formulas ECCKiila is using for code generation. They are taken from this paper (which is also referenced in the comments of the generated code) that provides at least Magma code which provides "verification of the complete addition and exception-free doubling formulas". So there seems to be indeed some verification of the algorithm itself, and I guess if the tooling has no bugs, this is also true for the generated C code? Unfortunately I can't really tell how that compares to the guarantees of the implementations in |
This change implements the SECP256K1 curve (also known as the Bitcoin curve). - field primitives are generated by the fiat-crypto project[1] - point primitives are generated by the ECCKiila project[2] - Ocaml point operations are taken from NIST implementation, adapted to ECCKiila point primitives and optimized for a=0. - testvectors for ECDH and ECDSA verification from wycheproof[3] Closes: mirage#187 [1] https://github.com/mit-plv/fiat-crypto [2] https://gitlab.com/nisec/ecckiila [3] https://github.com/C2SP/wycheproof
This change implements the SECP256K1 curve (also known as the Bitcoin curve).
Closes: #187
[1] https://github.com/mit-plv/fiat-crypto
[2] https://gitlab.com/nisec/ecckiila
[3] https://github.com/C2SP/wycheproof