diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-01-20 12:59:53 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-01-26 15:26:49 +0100 |
commit | f377e58fde1a7e6b29067c48df7d3c04fdaeba38 (patch) | |
tree | 1d2b1f08a50a1ec92e690b05feeba13d7341d42b | |
parent | 3d34bedfd7fb9120b6eb7b05c25cd0c3de14c562 (diff) | |
download | openssl-new-f377e58fde1a7e6b29067c48df7d3c04fdaeba38.tar.gz |
Disable the test-ec completely when building with no-ec
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13139)
-rw-r--r-- | test/ectest.c | 109 | ||||
-rw-r--r-- | test/recipes/15-test_ec.t | 132 |
2 files changed, 110 insertions, 131 deletions
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 <openssl/ec.h> -# ifndef OPENSSL_NO_ENGINE -# include <openssl/engine.h> -# endif -# include <openssl/err.h> -# include <openssl/obj_mac.h> -# include <openssl/objects.h> -# include <openssl/rand.h> -# include <openssl/bn.h> -# include <openssl/opensslconf.h> -# include "openssl/core_names.h" -# include "openssl/param_build.h" -# include "openssl/evp.h" +#include <openssl/ec.h> +#ifndef OPENSSL_NO_ENGINE +# include <openssl/engine.h> +#endif +#include <openssl/err.h> +#include <openssl/obj_mac.h> +#include <openssl/objects.h> +#include <openssl/rand.h> +#include <openssl/bn.h> +#include <openssl/opensslconf.h> +#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 } diff --git a/test/recipes/15-test_ec.t b/test/recipes/15-test_ec.t index 5a042d1d4d..acd1b3960d 100644 --- a/test/recipes/15-test_ec.t +++ b/test/recipes/15-test_ec.t @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -16,6 +16,8 @@ use OpenSSL::Test::Utils; setup("test_ec"); +plan skip_all => 'EC is not supported in this build' if disabled('ec'); + plan tests => 14; require_ok(srctop_file('test','recipes','tconversion.pl')); @@ -25,77 +27,61 @@ ok(run(test(["ectest"])), "running ectest"); # TODO: remove these when the 'ec' app is removed. # Also consider moving this to the 20-25 test section because it is testing # the command line tool in addition to the algorithm. -SKIP: { - skip "Skipping EC conversion test", 3 - if disabled("ec"); - - subtest 'EC conversions -- private key' => sub { - tconversion( -type => 'ec', -prefix => 'ec-priv', - -in => srctop_file("test","testec-p256.pem") ); - }; - subtest 'EC conversions -- private key PKCS#8' => sub { - tconversion( -type => 'ec', -prefix => 'ec-pkcs8', - -in => srctop_file("test","testec-p256.pem"), - -args => "pkey" ); - }; - subtest 'EC conversions -- public key' => sub { - tconversion( -type => 'ec', -prefix => 'ec-pub', - -in => srctop_file("test","testecpub-p256.pem"), - -args => [ "ec", "-pubin", "-pubout" ] ); - }; -} - -SKIP: { - skip "Skipping PKEY conversion test", 3 - if disabled("ec"); - - subtest 'PKEY conversions -- private key' => sub { - tconversion( -type => 'pkey', -prefix => 'ec-pkey-priv', - -in => srctop_file("test","testec-p256.pem") ); - }; - subtest 'PKEY conversions -- private key PKCS#8' => sub { - tconversion( -type => 'pkey', -prefix => 'ec-pkey-pkcs8', - -in => srctop_file("test","testec-p256.pem"), - -args => "pkey" ); - }; - subtest 'PKEY conversions -- public key' => sub { - tconversion( -type => 'pkey', -prefix => 'ec-pkey-pub', - -in => srctop_file("test","testecpub-p256.pem"), - -args => [ "pkey", "-pubin", "-pubout" ] ); - }; -} - -SKIP: { - skip "Skipping EdDSA conversion test", 6 - if disabled("ec"); +subtest 'EC conversions -- private key' => sub { + tconversion( -type => 'ec', -prefix => 'ec-priv', + -in => srctop_file("test","testec-p256.pem") ); +}; +subtest 'EC conversions -- private key PKCS#8' => sub { + tconversion( -type => 'ec', -prefix => 'ec-pkcs8', + -in => srctop_file("test","testec-p256.pem"), + -args => "pkey" ); +}; +subtest 'EC conversions -- public key' => sub { + tconversion( -type => 'ec', -prefix => 'ec-pub', + -in => srctop_file("test","testecpub-p256.pem"), + -args => [ "ec", "-pubin", "-pubout" ] ); +}; - subtest 'Ed25519 conversions -- private key' => sub { - tconversion( -type => "pkey", -prefix => "ed25519-pkey-priv", - -in => srctop_file("test", "tested25519.pem") ); - }; - subtest 'Ed25519 conversions -- private key PKCS#8' => sub { - tconversion( -type => "pkey", -prefix => "ed25519-pkey-pkcs8", - -in => srctop_file("test", "tested25519.pem"), - -args => ["pkey"] ); - }; - subtest 'Ed25519 conversions -- public key' => sub { - tconversion( -type => "pkey", -prefix => "ed25519-pkey-pub", - -in => srctop_file("test", "tested25519pub.pem"), - -args => ["pkey", "-pubin", "-pubout"] ); - }; +subtest 'PKEY conversions -- private key' => sub { + tconversion( -type => 'pkey', -prefix => 'ec-pkey-priv', + -in => srctop_file("test","testec-p256.pem") ); +}; +subtest 'PKEY conversions -- private key PKCS#8' => sub { + tconversion( -type => 'pkey', -prefix => 'ec-pkey-pkcs8', + -in => srctop_file("test","testec-p256.pem"), + -args => "pkey" ); +}; +subtest 'PKEY conversions -- public key' => sub { + tconversion( -type => 'pkey', -prefix => 'ec-pkey-pub', + -in => srctop_file("test","testecpub-p256.pem"), + -args => [ "pkey", "-pubin", "-pubout" ] ); +}; - subtest 'Ed448 conversions -- private key' => sub { - tconversion( -type => "pkey", -prefix => "ed448-pkey-priv", - -in => srctop_file("test", "tested448.pem") ); - }; - subtest 'Ed448 conversions -- private key PKCS#8' => sub { - tconversion( -type => "pkey", -prefix => "ed448-pkey-pkcs8", - -in => srctop_file("test", "tested448.pem"), - -args => ["pkey"] ); - }; - subtest 'Ed448 conversions -- public key' => sub { - tconversion( -type => "pkey", -prefix => "ed448-pkey-pub", - -in => srctop_file("test", "tested448pub.pem"), - -args => ["pkey", "-pubin", "-pubout"] ); - }; -} +subtest 'Ed25519 conversions -- private key' => sub { + tconversion( -type => "pkey", -prefix => "ed25519-pkey-priv", + -in => srctop_file("test", "tested25519.pem") ); +}; +subtest 'Ed25519 conversions -- private key PKCS#8' => sub { + tconversion( -type => "pkey", -prefix => "ed25519-pkey-pkcs8", + -in => srctop_file("test", "tested25519.pem"), + -args => ["pkey"] ); +}; +subtest 'Ed25519 conversions -- public key' => sub { + tconversion( -type => "pkey", -prefix => "ed25519-pkey-pub", + -in => srctop_file("test", "tested25519pub.pem"), + -args => ["pkey", "-pubin", "-pubout"] ); +}; +subtest 'Ed448 conversions -- private key' => sub { + tconversion( -type => "pkey", -prefix => "ed448-pkey-priv", + -in => srctop_file("test", "tested448.pem") ); +}; +subtest 'Ed448 conversions -- private key PKCS#8' => sub { + tconversion( -type => "pkey", -prefix => "ed448-pkey-pkcs8", + -in => srctop_file("test", "tested448.pem"), + -args => ["pkey"] ); +}; +subtest 'Ed448 conversions -- public key' => sub { + tconversion( -type => "pkey", -prefix => "ed448-pkey-pub", + -in => srctop_file("test", "tested448pub.pem"), + -args => ["pkey", "-pubin", "-pubout"] ); +}; |