Closed iquerejeta closed 2 years ago
I'm also a bit confused myself. But doesn't the standard define that the sign should be 1 if gx1
is a square? However, with what is currently there, the sign is 1 if gx1
is nonsquare, right? I'm assuming that fe25519_notsquare
returns 1 if the value is not a square, and 0 if it is a square.
Oh, right! Good catch! y
should be negative if gx1
is a square.
The failing test is due to x
being negative - The test vectors encode coordinates independently.
Removed the
y_sign
variable as it was misleading to cally_sign
tonotsquare
. If preferred, we could declarey_sign = notsquare == fe25519_isnegative(y)
directly.The equality check instead of the XOR gate is due to the
hash-to-curve
standard. The standard defines the following two steps:meaning that we should end up either with
gx1
a square andsgn0(y) = 1
, or withgx1
a nonsquare andsgn0(y) = 0
. However, the current version of the code computes the XOR gate with thenonsquare
variable to decide whether we change the sign ofy
or not, meaning that we end up with eithergx1
a nonsquare andsgn0(y) = 1
, or withgx1
a square andsgn0(y) = 0
.Surprisingly, all tests still pass, with the exception of the
oversized context
. How where these test vectors generated?