Skip to content
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

Replace BigInt based elliptic curve library #4027

Open
2 of 10 tasks
randombit opened this issue Apr 20, 2024 · 3 comments
Open
2 of 10 tasks

Replace BigInt based elliptic curve library #4027

randombit opened this issue Apr 20, 2024 · 3 comments
Assignees
Milestone

Comments

@randombit
Copy link
Owner

randombit commented Apr 20, 2024

Botan 3.5.0

In this release pcurves is really just used for hash to curve

  • Initial pcurves (point arithmetic, fixed curve params) - that's Add library for compile time instantiation of elliptic curves #3979
  • Add EC_Scalar and EC_AffinePoint types and implement algorithms using them Add EC_Scalar and EC_AffinePoint types #4042
  • Deprecate all the functionality that existed just to support elliptic curves using BigInt, eg mod_sub, ct_reduce_below, many more.
  • Support for providing parameterized curves, where we eg compute Montgomery params at runtime. This is required not just for user provided/application specific curves but also I don't think it's worthwhile to provide the fully parameterized/hardcoded support for obscure curves like secp160r1. In the short term, application curves, secp160r1, etc fall back to the currently used BigInt code

Botan 3.6.0

In this release, we tie together EC_Scalar/EC_AffinePoint to pcurves so that everything goes fast 🚀

  • Bridge between EC_Scalar/EC_AffinePoint and pcurves
  • Convert EC keys internally to store EC_Scalar and EC_AffinePoint instead of BigInt/EC_Point

Botan 3.6.0 or later. Nice optimizations / cleanups but not critical

  • NAF for mul2_vartime
  • Avoid possibility of a doubling in the fixed window mul due to blinding (see Add library for compile time instantiation of elliptic curves #3979 (comment))
  • Figure out how to speed up inversions. Either searching for addition chains at compile time and/or providing a way of conveying a specific addition chain where a good one is known.
  • Specific field reduction support for P-256, P-384, secp256k1, NUMS
@reneme
Copy link
Collaborator

reneme commented Jun 5, 2024

We should consider compile time configuration of which curves get instantiated (as pointed out here). Much like the compile-time configuration of having "kyber" and/or "kyber_90s", for instance.

Adding one build module per curve should do the trick, and probably provides the best affordance for users. On the other hand, it produces quite a bit of boilerplate due to subdirectories, info.txt files and code machinery.

Alternatively, I could see this as a dedicated compile-time switch: Like:

  • ./configure.py --enable-elliptic-curves=all (the default)
  • ./configure.py --enable-elliptic-curves=p256,brainpool256 (a restricted set)

and then simply #ifdef the instantiations in pcurves.cpp accordingly.

@randombit
Copy link
Owner Author

The --enable-elliptic-curves approach is potentially confusing since even if you disable the pcurves module entirely, the elliptic curves still exist. All that ends up happening is you fall back to the slower BigInt code. [*]

[*] I mean right now ECDSA etc still use BigInt, even after both #3979 and #4042 land. There are several more steps here until the whole thing hangs together. But in the end state, we'll have fast ECC for specific curves, plus fallback code for weird curves, application curves, etc. If you disable the fast curve, it doesn't disable the curve, just disables it going fast.

That said there may be environments where the code size becomes an issue. I tried out a module per curve and it was not so bad. There are likely to not be more than ~5 new curves added here over time so I don't think it's an issue in an ongoing way.

In the end we could consider also having a way of disabling the slowpath BigInt stuff, which would benefit environments that are using just P-256 or something.

@reneme
Copy link
Collaborator

reneme commented Jun 9, 2024

Nice! I saw that you split the curve into compile-time modules. Indeed the boilerplate isn't so bad. Also provides a nice place to keep curve-specific special cases. 👍

I added a few minor suggestions, in which the type -> "Internal" might need some extra attention. Perhaps have a new module type "Feature" (which might also be better suited for "Kyber" vs. "Kyber90s", and similar situations...)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants