Add constant EDWARDS_D in dalek-ff-group (#78)

This commit is contained in:
J. Burfeind 2022-08-12 22:00:55 +02:00 committed by GitHub
parent 96a49d8a88
commit 169d5e26ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,10 @@ const FIELD_MODULUS: U256 =
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
pub struct FieldElement(U256);
pub const EDWARDS_D: FieldElement = FieldElement(U256::from_be_hex(
"52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3",
));
pub const SQRT_M1: FieldElement = FieldElement(U256::from_be_hex(
"2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0",
));
@ -154,6 +158,14 @@ impl FieldElement {
}
}
#[test]
fn test_edwards_d() {
let a = -FieldElement(U256::from_u32(121665));
let b = FieldElement(U256::from_u32(121666));
assert_eq!(EDWARDS_D, a * b.invert().unwrap());
}
#[test]
fn test_mul() {
assert_eq!(FieldElement(FIELD_MODULUS) * FieldElement::one(), FieldElement::zero());