From e82910d215aeb4ba90d689f3253dac4f5a2e2d91 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Tue, 7 Jan 2020 08:06:27 +0000 Subject: [PATCH] Add test for basepoint table multiplication by unreduced scalar. --- src/edwards.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/edwards.rs b/src/edwards.rs index 3f21e96..09eaa56 100644 --- a/src/edwards.rs +++ b/src/edwards.rs @@ -1264,6 +1264,37 @@ mod test { assert_eq!(aP128, aP256); } + // Check a unreduced scalar multiplication by the basepoint tables. + #[test] + fn basepoint_tables_unreduced_scalar() { + let P = &constants::ED25519_BASEPOINT_POINT; + let a = Scalar::from_bits([ + 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, 0xFF, + ]); + + let table_radix16 = EdwardsBasepointTableRadix16::create(&P); + let table_radix32 = EdwardsBasepointTableRadix32::create(&P); + let table_radix64 = EdwardsBasepointTableRadix64::create(&P); + let table_radix128 = EdwardsBasepointTableRadix128::create(&P); + let table_radix256 = EdwardsBasepointTableRadix256::create(&P); + + let aP = (&constants::ED25519_BASEPOINT_TABLE * &a).compress(); + let aP16 = (&table_radix16 * &a).compress(); + let aP32 = (&table_radix32 * &a).compress(); + let aP64 = (&table_radix64 * &a).compress(); + let aP128 = (&table_radix128 * &a).compress(); + let aP256 = (&table_radix256 * &a).compress(); + + assert_eq!(aP, aP16); + assert_eq!(aP16, aP32); + assert_eq!(aP32, aP64); + assert_eq!(aP64, aP128); + assert_eq!(aP128, aP256); + } + /// Check that converting to projective and then back to extended round-trips. #[test] fn basepoint_projective_extended_round_trip() {