Skip to content

Commit da2333a

Browse files
committed
elliptic-curve: add impl_field_element! macro
Extracts the macro of the same name from the `p384` crate so it can be used with other elliptic curve crates. Closes #1017.
1 parent 2bdca99 commit da2333a

File tree

3 files changed

+510
-0
lines changed

3 files changed

+510
-0
lines changed

elliptic-curve/src/dev.rs

+67
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,73 @@ impl Neg for ProjectivePoint {
707707
}
708708
}
709709

710+
/// Constant representing the base field modulus
711+
/// p = 2^{224}(2^{32} − 1) + 2^{192} + 2^{96} − 1
712+
pub const MODULUS: U256 =
713+
U256::from_be_hex("ffffffff00000001000000000000000000000000ffffffffffffffffffffffff");
714+
715+
/// Example base field element.
716+
#[derive(Clone, Copy, Debug)]
717+
pub struct FieldElement(pub(crate) U256);
718+
719+
/// Internal field element representation.
720+
type FeWords = [u64; 4];
721+
722+
impl_field_element!(
723+
FieldElement,
724+
FieldBytes,
725+
U256,
726+
MODULUS,
727+
FeWords,
728+
p256_from_montgomery,
729+
p256_to_montgomery,
730+
p256_add,
731+
p256_sub,
732+
p256_mul,
733+
p256_opp,
734+
p256_square
735+
);
736+
737+
impl FieldElement {
738+
/// Returns the multiplicative inverse of self, if self is non-zero.
739+
pub fn invert(&self) -> CtOption<Self> {
740+
unimplemented!()
741+
}
742+
743+
/// Returns the square root of self mod p, or `None` if no square root exists.
744+
pub fn sqrt(&self) -> CtOption<Self> {
745+
unimplemented!()
746+
}
747+
}
748+
749+
const fn p256_from_montgomery(_: &FeWords) -> FeWords {
750+
unimplemented!()
751+
}
752+
753+
const fn p256_to_montgomery(w: &FeWords) -> FeWords {
754+
*w
755+
}
756+
757+
const fn p256_add(_: &FeWords, _: &FeWords) -> FeWords {
758+
unimplemented!()
759+
}
760+
761+
const fn p256_sub(_: &FeWords, _: &FeWords) -> FeWords {
762+
unimplemented!()
763+
}
764+
765+
const fn p256_mul(_: &FeWords, _: &FeWords) -> FeWords {
766+
unimplemented!()
767+
}
768+
769+
const fn p256_opp(_: &FeWords) -> FeWords {
770+
unimplemented!()
771+
}
772+
773+
const fn p256_square(_: &FeWords) -> FeWords {
774+
unimplemented!()
775+
}
776+
710777
#[cfg(test)]
711778
mod tests {
712779
use super::Scalar;

elliptic-curve/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ pub mod ops;
7171
#[cfg(feature = "sec1")]
7272
pub mod sec1;
7373

74+
#[macro_use]
75+
mod macros;
76+
7477
mod error;
7578
mod point;
7679
mod scalar;

0 commit comments

Comments
 (0)