Skip to content

Commit e8fdd99

Browse files
committed
Add more tests for Scalar canonical checks
1 parent dcc101d commit e8fdd99

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/scalar.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,9 +1658,24 @@ mod test {
16581658
// encoding with high bit set, to check that the parser isn't pre-masking the high bit
16591659
let non_canonical_bytes_because_highbit = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128];
16601660

1661+
let canonical_l_minus_one = [237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15];
1662+
let canonical_zero = [0u8; 32];
1663+
let canonical_255_minus_1 = [132, 52, 71, 117, 71, 74, 127, 151, 35, 182, 58, 139, 233, 42, 231, 109, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 15];
1664+
let non_canonical_l = [237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16];
1665+
let non_canonical_l_plus_one = [237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17];
1666+
let non_canonical_full = [0xFF; 32];
1667+
let non_canonical_255_minus_1 = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0b0111_1111];
1668+
16611669
assert!( Scalar::from_canonical_bytes(canonical_bytes).is_some() );
1670+
assert!( Scalar::from_canonical_bytes(canonical_l_minus_one).is_some() );
1671+
assert!( Scalar::from_canonical_bytes(canonical_zero).is_some() );
1672+
assert!( Scalar::from_canonical_bytes(canonical_255_minus_1).is_some() );
16621673
assert!( Scalar::from_canonical_bytes(non_canonical_bytes_because_unreduced).is_none() );
16631674
assert!( Scalar::from_canonical_bytes(non_canonical_bytes_because_highbit).is_none() );
1675+
assert!( Scalar::from_canonical_bytes(non_canonical_l).is_none() );
1676+
assert!( Scalar::from_canonical_bytes(non_canonical_l_plus_one).is_none() );
1677+
assert!( Scalar::from_canonical_bytes(non_canonical_full).is_none() );
1678+
assert!( Scalar::from_canonical_bytes(non_canonical_255_minus_1).is_none() );
16641679
}
16651680

16661681
#[test]

0 commit comments

Comments
 (0)