diff options
author | tb <> | 2024-10-18 19:55:34 +0000 |
---|---|---|
committer | tb <> | 2024-10-18 19:55:34 +0000 |
commit | 78eb5b882cac45cd24460fa3569aa965475abe1c (patch) | |
tree | d50d156a8551758eea5562268a6205b9a842663e /src | |
parent | 2b5b0449a68f53d499f44a405400ebd9de632ff5 (diff) | |
download | openbsd-78eb5b882cac45cd24460fa3569aa965475abe1c.tar.gz openbsd-78eb5b882cac45cd24460fa3569aa965475abe1c.tar.bz2 openbsd-78eb5b882cac45cd24460fa3569aa965475abe1c.zip |
ec_asn1_test: call EC_GROUP_check() for the builtin curves
This makes the internal curve test in ectest.c superfluous.
Also fix a logic error.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/ec/ec_asn1_test.c | 14 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/ec/ectest.c | 58 |
2 files changed, 13 insertions, 59 deletions
diff --git a/src/regress/lib/libcrypto/ec/ec_asn1_test.c b/src/regress/lib/libcrypto/ec/ec_asn1_test.c index 646350b834..86f694b848 100644 --- a/src/regress/lib/libcrypto/ec/ec_asn1_test.c +++ b/src/regress/lib/libcrypto/ec/ec_asn1_test.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_asn1_test.c,v 1.11 2024/10/18 17:29:24 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1_test.c,v 1.12 2024/10/18 19:55:34 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2024 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2024 Theo Buehler <tb@openbsd.org> |
@@ -117,7 +117,7 @@ compare_data(const char *label, const unsigned char *d1, size_t d1_len, | |||
117 | return -1; | 117 | return -1; |
118 | } | 118 | } |
119 | if (memcmp(d1, d2, d1_len) != 0) { | 119 | if (memcmp(d1, d2, d1_len) != 0) { |
120 | fprintf(stderr, "FAIL: %sdiffer\n", label); | 120 | fprintf(stderr, "FAIL: %s differ\n", label); |
121 | fprintf(stderr, "got:\n"); | 121 | fprintf(stderr, "got:\n"); |
122 | hexdump(d1, d1_len); | 122 | hexdump(d1, d1_len); |
123 | fprintf(stderr, "want:\n"); | 123 | fprintf(stderr, "want:\n"); |
@@ -288,10 +288,16 @@ ec_group_roundtrip_builtin_curve(const EC_builtin_curve *curve) | |||
288 | { | 288 | { |
289 | EC_GROUP *group = NULL; | 289 | EC_GROUP *group = NULL; |
290 | int failed = 0; | 290 | int failed = 0; |
291 | int ret = 0; | ||
291 | 292 | ||
292 | if ((group = EC_GROUP_new_by_curve_name(curve->nid)) == NULL) | 293 | if ((group = EC_GROUP_new_by_curve_name(curve->nid)) == NULL) |
293 | errx(1, "failed to instantiate curve %d", curve->nid); | 294 | errx(1, "failed to instantiate curve %d", curve->nid); |
294 | 295 | ||
296 | if (!EC_GROUP_check(group, NULL)) { | ||
297 | fprintf(stderr, "FAIL: EC_GROUP_check(%d) failed\n", curve->nid); | ||
298 | goto err; | ||
299 | } | ||
300 | |||
295 | if (EC_GROUP_get_asn1_flag(group) != OPENSSL_EC_NAMED_CURVE) { | 301 | if (EC_GROUP_get_asn1_flag(group) != OPENSSL_EC_NAMED_CURVE) { |
296 | fprintf(stderr, "FAIL: ASN.1 flag not set for %d\n", curve->nid); | 302 | fprintf(stderr, "FAIL: ASN.1 flag not set for %d\n", curve->nid); |
297 | goto err; | 303 | goto err; |
@@ -314,7 +320,11 @@ ec_group_roundtrip_builtin_curve(const EC_builtin_curve *curve) | |||
314 | EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_HYBRID); | 320 | EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_HYBRID); |
315 | failed |= ec_group_roundtrip_curve(group, "hybrid", curve->nid); | 321 | failed |= ec_group_roundtrip_curve(group, "hybrid", curve->nid); |
316 | 322 | ||
323 | ret = 1; | ||
324 | |||
317 | err: | 325 | err: |
326 | failed |= ret == 0; | ||
327 | |||
318 | EC_GROUP_free(group); | 328 | EC_GROUP_free(group); |
319 | 329 | ||
320 | return failed; | 330 | return failed; |
diff --git a/src/regress/lib/libcrypto/ec/ectest.c b/src/regress/lib/libcrypto/ec/ectest.c index e60fde60e6..b653ab7876 100644 --- a/src/regress/lib/libcrypto/ec/ectest.c +++ b/src/regress/lib/libcrypto/ec/ectest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ectest.c,v 1.23 2024/02/29 20:04:43 tb Exp $ */ | 1 | /* $OpenBSD: ectest.c,v 1.24 2024/10/18 19:55:34 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -703,68 +703,12 @@ prime_field_tests(void) | |||
703 | 703 | ||
704 | } | 704 | } |
705 | 705 | ||
706 | static void | ||
707 | internal_curve_test(void) | ||
708 | { | ||
709 | EC_builtin_curve *curves = NULL; | ||
710 | size_t crv_len = 0, n = 0; | ||
711 | int ok = 1; | ||
712 | |||
713 | crv_len = EC_get_builtin_curves(NULL, 0); | ||
714 | |||
715 | curves = reallocarray(NULL, sizeof(EC_builtin_curve), crv_len); | ||
716 | |||
717 | if (curves == NULL) | ||
718 | return; | ||
719 | |||
720 | if (!EC_get_builtin_curves(curves, crv_len)) { | ||
721 | free(curves); | ||
722 | return; | ||
723 | } | ||
724 | |||
725 | fprintf(stdout, "testing internal curves: "); | ||
726 | |||
727 | for (n = 0; n < crv_len; n++) { | ||
728 | EC_GROUP *group = NULL; | ||
729 | int nid = curves[n].nid; | ||
730 | if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL) { | ||
731 | ok = 0; | ||
732 | fprintf(stdout, "\nEC_GROUP_new_curve_name() failed with" | ||
733 | " curve %s\n", OBJ_nid2sn(nid)); | ||
734 | /* try next curve */ | ||
735 | continue; | ||
736 | } | ||
737 | if (!EC_GROUP_check(group, NULL)) { | ||
738 | ok = 0; | ||
739 | fprintf(stdout, "\nEC_GROUP_check() failed with" | ||
740 | " curve %s\n", OBJ_nid2sn(nid)); | ||
741 | EC_GROUP_free(group); | ||
742 | /* try the next curve */ | ||
743 | continue; | ||
744 | } | ||
745 | fprintf(stdout, "."); | ||
746 | fflush(stdout); | ||
747 | EC_GROUP_free(group); | ||
748 | } | ||
749 | if (ok) | ||
750 | fprintf(stdout, " ok\n\n"); | ||
751 | else { | ||
752 | fprintf(stdout, " failed\n\n"); | ||
753 | ABORT; | ||
754 | } | ||
755 | free(curves); | ||
756 | return; | ||
757 | } | ||
758 | |||
759 | int | 706 | int |
760 | main(int argc, char *argv[]) | 707 | main(int argc, char *argv[]) |
761 | { | 708 | { |
762 | ERR_load_crypto_strings(); | 709 | ERR_load_crypto_strings(); |
763 | 710 | ||
764 | prime_field_tests(); | 711 | prime_field_tests(); |
765 | puts(""); | ||
766 | /* test the internal curves */ | ||
767 | internal_curve_test(); | ||
768 | 712 | ||
769 | CRYPTO_cleanup_all_ex_data(); | 713 | CRYPTO_cleanup_all_ex_data(); |
770 | ERR_free_strings(); | 714 | ERR_free_strings(); |