summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheo Buehler <tb@openbsd.org>2021-05-01 13:09:10 +0200
committerNicola Tuveri <nic.tuv@gmail.com>2021-05-09 14:52:53 +0300
commite70abb8b4cb3b6259812137f72efa100797bca22 (patch)
treed50733e4e2e3d89e07edc2463a14ece3fefe8225
parent56f0237938c7e99d04f004886d56cb76514c4d56 (diff)
Test oct2point for hybrid point encoding of (0, y)
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15108)
-rw-r--r--test/ectest.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/ectest.c b/test/ectest.c
index 8b737149d8..f58cd4e4bc 100644
--- a/test/ectest.c
+++ b/test/ectest.c
@@ -1083,6 +1083,55 @@ err:
BN_free(yplusone);
return r;
}
+
+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)
@@ -2929,6 +2978,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