diff options
author | Theo Buehler <tb@openbsd.org> | 2021-05-01 13:09:10 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-05-17 10:41:27 +0200 |
commit | 7e12c2b3d9ccf97186e4d2cb27aafb084c893ce5 (patch) | |
tree | a9efa06d623511ed559581def9a7bc91527074a6 | |
parent | c054a6d45dab1bbe38e1c89518e40ba9a9660baa (diff) |
Test oct2point for hybrid point encoding of (0, y)
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15112)
-rw-r--r-- | test/ectest.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/test/ectest.c b/test/ectest.c index 9bdbf70afb..bb2ff699c6 100644 --- a/test/ectest.c +++ b/test/ectest.c @@ -1124,7 +1124,56 @@ err: BN_free(yplusone); return r; } -# endif + +static int hybrid_point_encoding_test(void) +{ + BIGNUM *x = NULL, *y = NULL; + EC_GROUP *group = NULL; + EC_POINT *point = NULL; + unsigned char *buf = NULL; + size_t len; + int r = 0; + + if (!TEST_true(BN_dec2bn(&x, "0")) + || !TEST_true(BN_dec2bn(&y, "1")) + || !TEST_ptr(group = EC_GROUP_new_by_curve_name(NID_sect571k1)) + || !TEST_ptr(point = EC_POINT_new(group)) + || !TEST_true(EC_POINT_set_affine_coordinates(group, point, x, y, NULL)) + || !TEST_size_t_ne(0, (len = EC_POINT_point2oct(group, + point, + POINT_CONVERSION_HYBRID, + NULL, + 0, + NULL))) + || !TEST_ptr(buf = OPENSSL_malloc(len)) + || !TEST_size_t_eq(len, EC_POINT_point2oct(group, + point, + POINT_CONVERSION_HYBRID, + buf, + len, + NULL))) + goto err; + + r = 1; + + /* buf contains a valid hybrid point, check that we can decode it. */ + if (!TEST_true(EC_POINT_oct2point(group, point, buf, len, NULL))) + r = 0; + + /* Flip the y_bit and verify that the invalid encoding is rejected. */ + buf[0] ^= 1; + if (!TEST_false(EC_POINT_oct2point(group, point, buf, len, NULL))) + r = 0; + +err: + BN_free(x); + BN_free(y); + EC_GROUP_free(group); + EC_POINT_free(point); + OPENSSL_free(buf); + return r; +} +#endif static int internal_curve_test(int n) { @@ -2195,6 +2244,7 @@ int setup_tests(void) ADD_ALL_TESTS(cardinality_test, crv_len); ADD_TEST(prime_field_tests); # ifndef OPENSSL_NO_EC2M + ADD_TEST(hybrid_point_encoding_test); ADD_TEST(char2_field_tests); ADD_ALL_TESTS(char2_curve_test, OSSL_NELEM(char2_curve_tests)); # endif |