Skip to content

[WIP] Add Legendre trait#79

Closed
davidnevadoc wants to merge 4 commits into
mainfrom
feat/legendre-trait
Closed

[WIP] Add Legendre trait#79
davidnevadoc wants to merge 4 commits into
mainfrom
feat/legendre-trait

Conversation

@davidnevadoc

Copy link
Copy Markdown
Collaborator

Add trait for computing Legendre symbol and field element norm.

 - Add Legendre macro with norm and legendre symbol computation
 - Add macro for automatic implementation in prime fields
Comment thread src/pasta/mod.rs
endo!(Ep, Fq, ENDO_PARAMS_EP);

// prime_field_legendre!(Fp);
// prime_field_legendre!(Fq);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this macro here results in conflicting names for the values generated in the lazy_static!. I have tried the following:

static ref [< $field _LE_AS_BIGUINT >]: BigUint = BigUint::from_bytes_le((-<$field as ff::Field>::ONE).to_repr().as_ref())/2usize ;
static ref [< $field _LEGENDRE_EXP >]: Vec<u64> = [< $field _LE_AS_BIGUINT >].to_u64_digits();

inside a paste!.
But I get some annoying warnings regarding non upper case globals that I haven't managed to remove

@davidnevadoc davidnevadoc marked this pull request as ready for review August 11, 2023 20:14
@davidnevadoc davidnevadoc requested a review from han0110 August 11, 2023 20:15
Comment thread src/legendre.rs
// This is (p-1)/2 where p is the modulus of the base prime field
fn legendre_exp() -> &'static Vec<u64>;

fn norm(&self) -> &Self::BasePrimeField;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this added to cover the extension field? If so I think we couldn't return a reference since the norm of Fq2 is calculated on the fly, so here we'd have some lifetime issue.

Comment thread src/legendre.rs
type BasePrimeField: PrimeField;

// This is (p-1)/2 where p is the modulus of the base prime field
fn legendre_exp() -> &'static Vec<u64>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could have this as some const 'static [u64] and we can print it out and pass it when calling prime_field_legendre, that might be an more direct approach? And we can avoid the naming conflict issue.

@davidnevadoc

Copy link
Copy Markdown
Collaborator Author

Changes moved to #77

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

Successfully merging this pull request may close these issues.

2 participants