X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=test%2Fectest.c;fp=test%2Fectest.c;h=e00e7c2b3a8b7a4955c7bae693c29dd03b85bcf0;hp=b047d88c3e5ee21ac567754c94b168117b234183;hb=f377e58fde1a7e6b29067c48df7d3c04fdaeba38;hpb=3d34bedfd7fb9120b6eb7b05c25cd0c3de14c562 diff --git a/test/ectest.c b/test/ectest.c index b047d88c3e..e00e7c2b3a 100644 --- a/test/ectest.c +++ b/test/ectest.c @@ -1,5 +1,5 @@ /* - * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved * * Licensed under the Apache License 2.0 (the "License"). You may not use @@ -18,20 +18,19 @@ #include "internal/nelem.h" #include "testutil.h" -#ifndef OPENSSL_NO_EC -# include -# ifndef OPENSSL_NO_ENGINE -# include -# endif -# include -# include -# include -# include -# include -# include -# include "openssl/core_names.h" -# include "openssl/param_build.h" -# include "openssl/evp.h" +#include +#ifndef OPENSSL_NO_ENGINE +# include +#endif +#include +#include +#include +#include +#include +#include +#include "openssl/core_names.h" +#include "openssl/param_build.h" +#include "openssl/evp.h" static size_t crv_len = 0; static EC_builtin_curve *curves = NULL; @@ -59,9 +58,9 @@ static int group_order_tests(EC_GROUP *group) if (!TEST_true(EC_GROUP_get_order(group, order, ctx)) || !TEST_true(EC_POINT_mul(group, Q, order, NULL, NULL, ctx)) || !TEST_true(EC_POINT_is_at_infinity(group, Q)) -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 || !TEST_true(EC_GROUP_precompute_mult(group, ctx)) -# endif +#endif || !TEST_true(EC_POINT_mul(group, Q, order, NULL, NULL, ctx)) || !TEST_true(EC_POINT_is_at_infinity(group, Q)) || !TEST_true(EC_POINT_copy(P, G)) @@ -75,10 +74,10 @@ static int group_order_tests(EC_GROUP *group) goto err; for (i = 1; i <= 2; i++) { -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 const BIGNUM *scalars[6]; const EC_POINT *points[6]; -# endif +#endif if (!TEST_true(BN_set_word(n1, i)) /* @@ -113,7 +112,7 @@ static int group_order_tests(EC_GROUP *group) || !TEST_false(EC_POINT_is_at_infinity(group, P))) goto err; -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 /* Exercise EC_POINTs_mul, including corner cases. */ scalars[0] = scalars[1] = BN_value_one(); points[0] = points[1] = P; @@ -138,7 +137,7 @@ static int group_order_tests(EC_GROUP *group) if (!TEST_true(EC_POINTs_mul(group, P, NULL, 6, points, scalars, ctx)) || !TEST_true(EC_POINT_is_at_infinity(group, P))) goto err; -# endif +#endif } r = 1; @@ -164,10 +163,10 @@ static int prime_field_tests(void) EC_GROUP *group = NULL; EC_POINT *P = NULL, *Q = NULL, *R = NULL; BIGNUM *x = NULL, *y = NULL, *z = NULL, *yplusone = NULL; -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 const EC_POINT *points[4]; const BIGNUM *scalars[4]; -# endif +#endif unsigned char buf[100]; size_t len, r = 0; int k; @@ -539,7 +538,7 @@ static int prime_field_tests(void) || !TEST_false(EC_POINT_is_at_infinity(group, Q))) goto err; -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 TEST_note("combined multiplication ..."); points[0] = Q; points[1] = Q; @@ -585,7 +584,7 @@ static int prime_field_tests(void) if (!TEST_true(EC_POINTs_mul(group, P, NULL, 4, points, scalars, ctx)) || !TEST_true(EC_POINT_is_at_infinity(group, P))) goto err; -# endif +#endif TEST_note(" ok\n"); r = 1; err: @@ -605,7 +604,7 @@ err: return r; } -# ifndef OPENSSL_NO_EC2M +#ifndef OPENSSL_NO_EC2M static struct c2_curve_test { const char *name; @@ -980,20 +979,20 @@ static int char2_field_tests(void) || !TEST_ptr(yplusone = BN_new()) || !TEST_true(BN_hex2bn(&x, "6")) /* Change test based on whether binary point compression is enabled or not. */ -# ifdef OPENSSL_EC_BIN_PT_COMP +# ifdef OPENSSL_EC_BIN_PT_COMP || !TEST_true(EC_POINT_set_compressed_coordinates(group, Q, x, 1, ctx)) -# else +# else || !TEST_true(BN_hex2bn(&y, "8")) || !TEST_true(EC_POINT_set_affine_coordinates(group, Q, x, y, ctx)) -# endif +# endif ) goto err; if (!TEST_int_gt(EC_POINT_is_on_curve(group, Q, ctx), 0)) { /* Change test based on whether binary point compression is enabled or not. */ -# ifdef OPENSSL_EC_BIN_PT_COMP +# ifdef OPENSSL_EC_BIN_PT_COMP if (!TEST_true(EC_POINT_get_affine_coordinates(group, Q, x, y, ctx))) goto err; -# endif +# endif TEST_info("Point is not on curve"); test_output_bignum("x", x); test_output_bignum("y", y); @@ -1028,7 +1027,7 @@ static int char2_field_tests(void) goto err; /* Change test based on whether binary point compression is enabled or not. */ -# ifdef OPENSSL_EC_BIN_PT_COMP +# ifdef OPENSSL_EC_BIN_PT_COMP len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof(buf), ctx); if (!TEST_size_t_ne(len, 0) @@ -1037,7 +1036,7 @@ static int char2_field_tests(void) goto err; test_output_memory("Generator as octet string, compressed form:", buf, len); -# endif +# endif len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof(buf), ctx); @@ -1049,7 +1048,7 @@ static int char2_field_tests(void) buf, len); /* Change test based on whether binary point compression is enabled or not. */ -# ifdef OPENSSL_EC_BIN_PT_COMP +# ifdef OPENSSL_EC_BIN_PT_COMP len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof(buf), ctx); @@ -1059,7 +1058,7 @@ static int char2_field_tests(void) goto err; test_output_memory("Generator as octet string, hybrid form:", buf, len); -# endif +# endif if (!TEST_true(EC_POINT_invert(group, P, ctx)) || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx))) @@ -1084,7 +1083,7 @@ err: BN_free(yplusone); return r; } -# endif +#endif static int internal_curve_test(int n) { @@ -1339,12 +1338,12 @@ static int nistp_single_test(int idx) /* random point multiplication */ EC_POINT_mul(NISTP, Q, NULL, P, m, ctx); if (!TEST_int_eq(0, EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 /* We have not performed precomp so this should be false */ || !TEST_false(EC_GROUP_have_precompute_mult(NISTP)) /* now repeat all tests with precomputation */ || !TEST_true(EC_GROUP_precompute_mult(NISTP, ctx)) -# endif +#endif ) goto err; @@ -1709,7 +1708,7 @@ int are_ec_nids_compatible(int n1d, int n2d) { int ret = 0; switch (n1d) { -# ifndef OPENSSL_NO_EC2M +#ifndef OPENSSL_NO_EC2M case NID_sect113r1: case NID_wap_wsg_idm_ecid_wtls4: ret = (n2d == NID_sect113r1 || n2d == NID_wap_wsg_idm_ecid_wtls4); @@ -1731,7 +1730,7 @@ int are_ec_nids_compatible(int n1d, int n2d) ret = (n2d == NID_X9_62_c2pnb163v1 || n2d == NID_wap_wsg_idm_ecid_wtls5); break; -# endif /* OPENSSL_NO_EC2M */ +#endif /* OPENSSL_NO_EC2M */ case NID_secp112r1: case NID_wap_wsg_idm_ecid_wtls6: ret = (n2d == NID_secp112r1 || n2d == NID_wap_wsg_idm_ecid_wtls6); @@ -1740,12 +1739,12 @@ int are_ec_nids_compatible(int n1d, int n2d) case NID_wap_wsg_idm_ecid_wtls7: ret = (n2d == NID_secp160r2 || n2d == NID_wap_wsg_idm_ecid_wtls7); break; -# ifdef OPENSSL_NO_EC_NISTP_64_GCC_128 +#ifdef OPENSSL_NO_EC_NISTP_64_GCC_128 case NID_secp224r1: case NID_wap_wsg_idm_ecid_wtls12: ret = (n2d == NID_secp224r1 || n2d == NID_wap_wsg_idm_ecid_wtls12); break; -# else +#else /* * For SEC P-224 we want to ensure that the SECP nid is returned, as * that is associated with a specialized method. @@ -1753,7 +1752,7 @@ int are_ec_nids_compatible(int n1d, int n2d) case NID_wap_wsg_idm_ecid_wtls12: ret = (n2d == NID_secp224r1); break; -# endif /* def(OPENSSL_NO_EC_NISTP_64_GCC_128) */ +#endif /* def(OPENSSL_NO_EC_NISTP_64_GCC_128) */ default: ret = (n1d == n2d); @@ -2139,14 +2138,14 @@ static int cardinality_test(int n) || !TEST_true(BN_copy(g1_order, EC_GROUP_get0_order(g1))) || !TEST_true(EC_GROUP_get_cofactor(g1, g1_cf, ctx)) /* construct g2 manually with g1 parameters */ -# ifndef OPENSSL_NO_EC2M +#ifndef OPENSSL_NO_EC2M || !TEST_ptr(g2 = (is_binary) ? EC_GROUP_new_curve_GF2m(g1_p, g1_a, g1_b, ctx) : EC_GROUP_new_curve_GFp(g1_p, g1_a, g1_b, ctx)) -# else +#else || !TEST_int_eq(0, is_binary) || !TEST_ptr(g2 = EC_GROUP_new_curve_GFp(g1_p, g1_a, g1_b, ctx)) -# endif +#endif || !TEST_ptr(g2_gen = EC_POINT_new(g2)) || !TEST_true(EC_POINT_set_affine_coordinates(g2, g2_gen, g1_x, g1_y, ctx)) /* pass NULL cofactor: lib should compute it */ @@ -2679,12 +2678,12 @@ static int custom_params_test(int id) goto err; is_prime = EC_GROUP_get_field_type(group) == NID_X9_62_prime_field; -# ifdef OPENSSL_NO_EC2M +#ifdef OPENSSL_NO_EC2M if (!is_prime) { ret = TEST_skip("binary curves not supported in this build"); goto err; } -# endif +#endif BN_CTX_start(ctx); if (!TEST_ptr(p = BN_CTX_get(ctx)) @@ -2721,12 +2720,12 @@ static int custom_params_test(int id) if (!TEST_ptr(altgroup = EC_GROUP_new_curve_GFp(p, a, b, ctx))) goto err; } -# ifndef OPENSSL_NO_EC2M +#ifndef OPENSSL_NO_EC2M else { if (!TEST_ptr(altgroup = EC_GROUP_new_curve_GF2m(p, a, b, ctx))) goto err; } -# endif +#endif /* set 2*G as the generator of altgroup */ EC_POINT_free(G2); /* discard G2 as it refers to the original group */ @@ -2915,11 +2914,8 @@ static int custom_params_test(int id) return ret; } -#endif /* OPENSSL_NO_EC */ - int setup_tests(void) { -#ifndef OPENSSL_NO_EC crv_len = EC_get_builtin_curves(NULL, 0); if (!TEST_ptr(curves = OPENSSL_malloc(sizeof(*curves) * crv_len)) || !TEST_true(EC_get_builtin_curves(curves, crv_len))) @@ -2929,10 +2925,10 @@ int setup_tests(void) ADD_TEST(cofactor_range_test); ADD_ALL_TESTS(cardinality_test, crv_len); ADD_TEST(prime_field_tests); -# ifndef OPENSSL_NO_EC2M +#ifndef OPENSSL_NO_EC2M ADD_TEST(char2_field_tests); ADD_ALL_TESTS(char2_curve_test, OSSL_NELEM(char2_curve_tests)); -# endif +#endif ADD_ALL_TESTS(nistp_single_test, OSSL_NELEM(nistp_tests_params)); ADD_ALL_TESTS(internal_curve_test, crv_len); ADD_ALL_TESTS(internal_curve_test_method, crv_len); @@ -2944,13 +2940,10 @@ int setup_tests(void) ADD_ALL_TESTS(ec_point_hex2point_test, crv_len); ADD_ALL_TESTS(custom_generator_test, crv_len); ADD_ALL_TESTS(custom_params_test, crv_len); -#endif /* OPENSSL_NO_EC */ return 1; } void cleanup_tests(void) { -#ifndef OPENSSL_NO_EC OPENSSL_free(curves); -#endif }