Skip to content

Commit

Permalink
EC Suite B: Remove reudndant "point_mul" tests.
Browse files Browse the repository at this point in the history
When I generated these test vectors, I gave all of them the same point: the
generator of the curve. Consequently these input files are 100% redundant
with the `point_mul_base.txt` input files. So just remove them and use the
`point_mul_base.txt` files instead.
  • Loading branch information
briansmith committed Oct 25, 2023
1 parent be27e8e commit 3565fe8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3,359 deletions.
29 changes: 8 additions & 21 deletions src/ec/suite_b/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,39 +892,26 @@ mod tests {
});
}

/// TODO: We should be testing `point_mul` with points other than the generator.
#[test]
fn p256_point_mul_test() {
point_mul_tests(
point_mul_base_tests(
&p256::PRIVATE_KEY_OPS,
test_file!("ops/p256_point_mul_tests.txt"),
|s| p256::PRIVATE_KEY_OPS.point_mul(s, &p256::GENERATOR),
test_file!("ops/p256_point_mul_base_tests.txt"),
);
}

/// TODO: We should be testing `point_mul` with points other than the generator.
#[test]
fn p384_point_mul_test() {
point_mul_tests(
point_mul_base_tests(
&p384::PRIVATE_KEY_OPS,
test_file!("ops/p384_point_mul_tests.txt"),
|s| p384::PRIVATE_KEY_OPS.point_mul(s, &p384::GENERATOR),
test_file!("ops/p384_point_mul_base_tests.txt"),
);
}

fn point_mul_tests(ops: &PrivateKeyOps, test_file: test::File) {
test::run(test_file, |section, test_case| {
assert_eq!(section, "");
let p_scalar = consume_scalar(ops.common, test_case, "p_scalar");
let (x, y) = match consume_point(ops, test_case, "p") {
TestPoint::Infinity => {
panic!("can't be inf.");
}
TestPoint::Affine(x, y) => (x, y),
};
let expected_result = consume_point(ops, test_case, "r");
let actual_result = ops.point_mul(&p_scalar, &(x, y));
assert_point_actual_equals_expected(ops, &actual_result, &expected_result);
Ok(())
})
}

#[test]
fn p256_point_mul_serialized_test() {
point_mul_serialized_test(
Expand Down
6 changes: 6 additions & 0 deletions src/ec/suite_b/ops/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub static COMMON_OPS: CommonOps = CommonOps {
point_add_jacobian_impl: p256_point_add,
};

#[cfg(test)]
pub(super) static GENERATOR: (Elem<R>, Elem<R>) = (
Elem::from_hex("18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c"),
Elem::from_hex("8571ff1825885d85d2e88688dd21f3258b4ab8e4ba19e45cddf25357ce95560a"),
);

pub static PRIVATE_KEY_OPS: PrivateKeyOps = PrivateKeyOps {
common: &COMMON_OPS,
elem_inv_squared: p256_elem_inv_squared,
Expand Down
4 changes: 0 additions & 4 deletions src/ec/suite_b/ops/p256_point_mul_serialized_tests.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Similar to p256_point_mul_tests.txt, but tests point decoding and point
# encoding too. In particular, the inputs coordinates here are not Montgomery
# encoded, but the inputs in p256_point_mul_tests.txt are.

# Regression Test from /~https://github.com/golang/go/issues/20040

p_scalar = 2a265f8bcbdcaf94d58519141e578124cb40d64a501fba9c11847b28965bc737
Expand Down
Loading

0 comments on commit 3565fe8

Please sign in to comment.