-
Notifications
You must be signed in to change notification settings - Fork 256
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
Refactor Fp
code to use const
generics, and more
#379
Conversation
* Switches from hardcoded `FpXYZ` to `Fp<N>` based on const generics. * Moves Montgomery arithmetic to an optional backend
* Rename `field_new` macros. * Introduce `const fn`s for generating many constants. * Add default associated constants to reduce boilerplate.
/// The modulus of the field. | ||
const MODULUS: crate::BigInt<N>; | ||
|
||
/// A multiplicative generator of the field. | ||
/// `Self::GENERATOR` is an element having multiplicative order | ||
/// `Self::MODULUS - 1`. | ||
const GENERATOR: Fp<Self, N>; | ||
|
||
/// Additive identity of the field, i.e. the element `e` | ||
/// such that, for all elements `f` of the field, `e + f = f`. | ||
const ZERO: Fp<Self, N>; | ||
|
||
/// Multiplicative identity of the field, i.e. the element `e` | ||
/// such that, for all elements `f` of the field, `e * f = f`. | ||
const ONE: Fp<Self, N>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The replacement for FpParameters
, FpConfig
, is much simplified; only the bare essentials need to be specified here, compared to implementation-details like R, CAPACITY, etc earlier.
/// Set a += b. | ||
fn add_assign(a: &mut Fp<Self, N>, b: &Fp<Self, N>); | ||
|
||
/// Set a -= b. | ||
fn sub_assign(a: &mut Fp<Self, N>, b: &Fp<Self, N>); | ||
|
||
/// Set a = a + a. | ||
fn double_in_place(a: &mut Fp<Self, N>); | ||
|
||
/// Set a *= b. | ||
fn mul_assign(a: &mut Fp<Self, N>, b: &Fp<Self, N>); | ||
|
||
/// Set a *= b. | ||
fn square_in_place(a: &mut Fp<Self, N>); | ||
|
||
/// Compute a^{-1} if `a` is not zero. | ||
fn inverse(a: &Fp<Self, N>) -> Option<Fp<Self, N>>; | ||
|
||
/// Compute the square root of a, if it exists. | ||
fn square_root(a: &Fp<Self, N>) -> Option<Fp<Self, N>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of arithmetic methods have moved here, because this allows specializing the arithmetic implementation downstream
Co-authored-by: Weikeng Chen <[email protected]>
Co-authored-by: Marcin <[email protected]>
Looks like the CI is passing (but, a corresponding update is needed in curves). |
I can make a PR for curves sometime early next week. |
Description
Closes #69
Close #180
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pending
section inCHANGELOG.md
Files changed
in the GitHub PR explorer