Skip to content

Commit

Permalink
weierstrass: add impl_field_element! (#637)
Browse files Browse the repository at this point in the history
Imports this macro from the `elliptic-curve` crate:

https://docs.rs/elliptic-curve/0.12.3/elliptic_curve/macro.impl_field_element.html

It's used for defining the boilerplate of a `FieldElement` type backed
by a set of arithmetic ops, in a way that everything can be `const fn`
(which wouldn't be possible with traits/generics until const impl lands
on stable)

Having the macro defined in this crate makes it easier to iterate,
because changes can be made to all of the crates at the same time
including `weierstrass` which provides the macro implementation, as
opposed to it being in an out-of-repo crate like `elliptic-curve`.
  • Loading branch information
tarcieri authored Aug 5, 2022
1 parent d1ea1a3 commit efa2e63
Show file tree
Hide file tree
Showing 5 changed files with 447 additions and 3 deletions.
2 changes: 1 addition & 1 deletion p256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const R_2: U256 =
#[derive(Clone, Copy, Debug)]
pub struct FieldElement(pub(crate) U256);

elliptic_curve::impl_field_element!(
weierstrass::impl_field_element!(
FieldElement,
FieldBytes,
U256,
Expand Down
2 changes: 1 addition & 1 deletion p384/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) const MODULUS: U384 = U384::from_be_hex("ffffffffffffffffffffffffffff
#[derive(Clone, Copy, Debug)]
pub struct FieldElement(pub(super) U384);

elliptic_curve::impl_field_element!(
weierstrass::impl_field_element!(
FieldElement,
FieldBytes,
U384,
Expand Down
2 changes: 1 addition & 1 deletion p384/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use core::ops::{Add, Mul, Sub};
#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
pub struct Scalar(U384);

elliptic_curve::impl_field_element!(
weierstrass::impl_field_element!(
Scalar,
FieldBytes,
U384,
Expand Down
Loading

0 comments on commit efa2e63

Please sign in to comment.