Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions k256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ mod tests {
}
}

/// t = (modulus - 1) >> S
const T: [u64; 4] = [
0xffffffff7ffffe17,
0xffffffffffffffff,
0xffffffffffffffff,
0x7fffffffffffffff,
];

#[test]
fn two_inv_constant() {
assert_eq!(
Expand All @@ -539,6 +547,14 @@ mod tests {
.normalize(),
FieldElement::ONE
);

// MULTIPLICATIVE_GENERATOR^{t} mod m == ROOT_OF_UNITY
assert_eq!(
FieldElement::MULTIPLICATIVE_GENERATOR
.pow_vartime(&T)
.normalize(),
FieldElement::ROOT_OF_UNITY
)
}

#[test]
Expand All @@ -551,13 +567,6 @@ mod tests {

#[test]
fn delta_constant() {
const T: [u64; 4] = [
0xffffffff7ffffe17,
0xffffffffffffffff,
0xffffffffffffffff,
0x7fffffffffffffff,
];

// DELTA^{t} mod m == 1
assert_eq!(
FieldElement::DELTA.pow_vartime(&T).normalize(),
Expand Down
21 changes: 14 additions & 7 deletions k256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,14 @@ mod tests {
}
}

/// t = (modulus - 1) >> S
const T: [u64; 4] = [
0xeeff497a3340d905,
0xfaeabb739abd2280,
0xffffffffffffffff,
0x03ffffffffffffff,
];

#[test]
fn two_inv_constant() {
assert_eq!(Scalar::from(2u32) * Scalar::TWO_INV, Scalar::ONE);
Expand All @@ -769,6 +777,12 @@ mod tests {
Scalar::ROOT_OF_UNITY.pow_vartime(&[1u64 << Scalar::S, 0, 0, 0]),
Scalar::ONE
);

// MULTIPLICATIVE_GENERATOR^{t} mod m == ROOT_OF_UNITY
assert_eq!(
Scalar::MULTIPLICATIVE_GENERATOR.pow_vartime(&T),
Scalar::ROOT_OF_UNITY
)
}

#[test]
Expand All @@ -781,13 +795,6 @@ mod tests {

#[test]
fn delta_constant() {
const T: [u64; 4] = [
0xeeff497a3340d905,
0xfaeabb739abd2280,
0xffffffffffffffff,
0x03ffffffffffffff,
];

// DELTA^{t} mod m == 1
assert_eq!(Scalar::DELTA.pow_vartime(&T), Scalar::ONE);
}
Expand Down
21 changes: 14 additions & 7 deletions p256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ mod tests {
use elliptic_curve::{bigint::U256, ff::PrimeField};
use proptest::{num, prelude::*};

/// t = (modulus - 1) >> S
const T: [u64; 4] = [
0xffffffffffffffff,
0x000000007fffffff,
0x8000000000000000,
0x7fffffff80000000,
];

#[test]
fn two_inv_constant() {
assert_eq!(
Expand All @@ -175,6 +183,12 @@ mod tests {
FieldElement::ROOT_OF_UNITY.pow_vartime(&[1u64 << FieldElement::S, 0, 0, 0]),
FieldElement::ONE
);

// MULTIPLICATIVE_GENERATOR^{t} mod m == ROOT_OF_UNITY
assert_eq!(
FieldElement::MULTIPLICATIVE_GENERATOR.pow_vartime(&T),
FieldElement::ROOT_OF_UNITY
)
}

#[test]
Expand All @@ -187,13 +201,6 @@ mod tests {

#[test]
fn delta_constant() {
const T: [u64; 4] = [
0xffffffffffffffff,
0x000000007fffffff,
0x8000000000000000,
0x7fffffff80000000,
];

// DELTA^{t} mod m == 1
assert_eq!(FieldElement::DELTA.pow_vartime(&T), FieldElement::ONE);
}
Expand Down
21 changes: 14 additions & 7 deletions p256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,14 @@ mod tests {
use crate::{FieldBytes, SecretKey};
use elliptic_curve::group::ff::{Field, PrimeField};

/// t = (modulus - 1) >> S
const T: [u64; 4] = [
0x4f3b9cac2fc63255,
0xfbce6faada7179e8,
0x0fffffffffffffff,
0x0ffffffff0000000,
];

#[test]
fn two_inv_constant() {
assert_eq!(Scalar::from(2u32) * Scalar::TWO_INV, Scalar::ONE);
Expand All @@ -698,6 +706,12 @@ mod tests {
Scalar::ROOT_OF_UNITY.pow_vartime(&[1u64 << Scalar::S, 0, 0, 0]),
Scalar::ONE
);

// MULTIPLICATIVE_GENERATOR^{t} mod m == ROOT_OF_UNITY
assert_eq!(
Scalar::MULTIPLICATIVE_GENERATOR.pow_vartime(&T),
Scalar::ROOT_OF_UNITY
)
}

#[test]
Expand All @@ -710,13 +724,6 @@ mod tests {

#[test]
fn delta_constant() {
const T: [u64; 4] = [
0x4f3b9cac2fc63255,
0xfbce6faada7179e8,
0x0fffffffffffffff,
0x0ffffffff0000000,
];

// DELTA^{t} mod m == 1
assert_eq!(Scalar::DELTA.pow_vartime(&T), Scalar::ONE);
}
Expand Down
25 changes: 16 additions & 9 deletions p384/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ mod tests {
use super::FieldElement;
use elliptic_curve::ff::PrimeField;

/// t = (modulus - 1) >> S
const T: [u64; 6] = [
0x000000007fffffff,
0x7fffffff80000000,
0xffffffffffffffff,
0xffffffffffffffff,
0xffffffffffffffff,
0x7fffffffffffffff,
];

#[test]
fn two_inv_constant() {
assert_eq!(
Expand All @@ -171,6 +181,12 @@ mod tests {
FieldElement::ROOT_OF_UNITY.pow_vartime(&[1u64 << FieldElement::S, 0, 0, 0]),
FieldElement::ONE
);

// MULTIPLICATIVE_GENERATOR^{t} mod m == ROOT_OF_UNITY
assert_eq!(
FieldElement::MULTIPLICATIVE_GENERATOR.pow_vartime(&T),
FieldElement::ROOT_OF_UNITY
)
}

#[test]
Expand All @@ -183,15 +199,6 @@ mod tests {

#[test]
fn delta_constant() {
const T: [u64; 6] = [
0x000000007fffffff,
0x7fffffff80000000,
0xffffffffffffffff,
0xffffffffffffffff,
0xffffffffffffffff,
0x7fffffffffffffff,
];

// DELTA^{t} mod m == 1
assert_eq!(FieldElement::DELTA.pow_vartime(&T), FieldElement::ONE);
}
Expand Down
25 changes: 16 additions & 9 deletions p384/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ mod tests {
use crate::FieldBytes;
use elliptic_curve::ff::PrimeField;

/// t = (modulus - 1) >> S
const T: [u64; 6] = [
0x76760cb5666294b9,
0xac0d06d9245853bd,
0xe3b1a6c0fa1b96ef,
0xffffffffffffffff,
0xffffffffffffffff,
0x7fffffffffffffff,
];

#[test]
fn two_inv_constant() {
assert_eq!(Scalar::from(2u32) * Scalar::TWO_INV, Scalar::ONE);
Expand All @@ -368,6 +378,12 @@ mod tests {
Scalar::ROOT_OF_UNITY.pow_vartime(&[1u64 << Scalar::S, 0, 0, 0]),
Scalar::ONE
);

// MULTIPLICATIVE_GENERATOR^{t} mod m == ROOT_OF_UNITY
assert_eq!(
Scalar::MULTIPLICATIVE_GENERATOR.pow_vartime(&T),
Scalar::ROOT_OF_UNITY
)
}

#[test]
Expand All @@ -380,15 +396,6 @@ mod tests {

#[test]
fn delta_constant() {
const T: [u64; 6] = [
0x76760cb5666294b9,
0xac0d06d9245853bd,
0xe3b1a6c0fa1b96ef,
0xffffffffffffffff,
0xffffffffffffffff,
0x7fffffffffffffff,
];

// DELTA^{t} mod m == 1
assert_eq!(Scalar::DELTA.pow_vartime(&T), Scalar::ONE);
}
Expand Down