-
Notifications
You must be signed in to change notification settings - Fork 147
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
How do we compute the constant for scmul? #805
Comments
I'm not sure that's what is meant by "the scalar arithmetic files". Our @huitseeker is that indeed what you meant? If so, the answer I vaguely recall from years ago is "the scalar arithmetic isn't performance-critical or particularly complicated so it's lower priority than field arithmetic", but perhaps that's worth revisiting now that the field arithmetic is taken care of. |
That's pretty true. If you implement scalar inversion by Fermat's Little Theorem then the scalar multiplication and (especially) squaring performance matters a lot for that operation.
It is no simpler than the field arithmetic. It would be nice for Fiat to synthesize size-optimized (e.g. using loops) code for scalar operations instead of speed-optimized code, or at least have the option to do so. |
I also was looking for generated operations modulo 2^252 + 27742317777372353535851937790883648493 (the order of the prime-order subgroup of Curve25519), which in implementations we usually refer to as the "scalar field" (because it's the field of the scalars that you perform scalar multiplication of group elements with) as opposed to the "base field" (integers modulo 2^255 - 19). Almost everyone copy-pasted the same implementation of muladd (a + b * c) in that field (affectiously called the Christmas tree, because of how the multiplication step looks like, see below), and replacing it would be a great starting point for integrating fiat-crypto. I also think it's actually more complicated than the base field, because the prime doesn't have a nice shape. Indeed, performance is not critical, except for inversion as @briansmith said, which we have a custom implementation for in filippo.io/edwards25519 (by @hdevalence). (I think this has nothing to do with 121666, which is the denominator of the curve constant, is an element of the base field, and is apparently used in the implementation of group-level point scalar multiplication, so either we are off-topic or the issue should be retitled.) |
Just to close the circle on that archaeology, if I recall correctly the scalar inversion implementation I added to filippo.io/edwards25519 uses a ladder found by @briansmith :) |
We were asked over email by @huitseeker:
We have this for curve25519:
fiat-crypto/fiat-c/src/curve25519_64.c
Lines 572 to 615 in e525793
However, the number 121666 is a magic constant to me (according to the internet, it's
(d + 2) / 4
....). What are the equivalent numbers for the other unsaturated solinas curves? Is there a table of these numbers somewhere? Can they be computed somehow?cc @andres-erbsen
The text was updated successfully, but these errors were encountered: