-
Notifications
You must be signed in to change notification settings - Fork 96
Description
Hello!
I'm wondering if adding an API to check if a field element is a valid square would be possible.
Currently, the sqrt() function hangs if the input isn't a square, making it a bit difficult to work with when the input comes from some user-facing process.
The two best options I can see would be to either make the sqrt() function return an error if m is equal to the two-adicity of the field, and then another check below to see that x.square() == value.
libff/libff/algebra/field_utils/algorithms.tcc
Lines 136 to 146 in 674e437
| while (b != one) | |
| { | |
| size_t m = 0; | |
| FieldT b2m = b; | |
| while (b2m != one) | |
| { | |
| /* invariant: b2m = b^(2^m) after entering this loop */ | |
| b2m = b2m.squared(); | |
| m += 1; | |
| } | |
or adding a standalone function that checks via the legendre symbol, or maybe some more efficient way I'm not aware of (still pretty new to cryptography!);
I need this functionality for both Fp and Fp2.
Thanks!