Skip to content

Ability to check if an element is a square #112

@Rexicon226

Description

@Rexicon226

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.

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions