summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-10-18 19:55:35 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-10-18 19:55:35 +0000
commitba6f3f3fe87e68014874a5ba0cc637465e5fff6c (patch)
tree77833a7a937d68c59fe137482ee4c74235d7b733
parent004e0f600266d411435a18565a49d38e4bb49291 (diff)
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.
-rw-r--r--regress/lib/libcrypto/ec/ec_asn1_test.c14
-rw-r--r--regress/lib/libcrypto/ec/ectest.c58
2 files changed, 13 insertions, 59 deletions
diff --git a/regress/lib/libcrypto/ec/ec_asn1_test.c b/regress/lib/libcrypto/ec/ec_asn1_test.c
index 646350b8342..86f694b8485 100644
--- a/regress/lib/libcrypto/ec/ec_asn1_test.c
+++ b/regress/lib/libcrypto/ec/ec_asn1_test.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec_asn1_test.c,v 1.11 2024/10/18 17:29:24 tb Exp $ */
+/* $OpenBSD: ec_asn1_test.c,v 1.12 2024/10/18 19:55:34 tb Exp $ */
/*
* Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org>
* 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,
return -1;
}
if (memcmp(d1, d2, d1_len) != 0) {
- fprintf(stderr, "FAIL: %sdiffer\n", label);
+ fprintf(stderr, "FAIL: %s differ\n", label);
fprintf(stderr, "got:\n");
hexdump(d1, d1_len);
fprintf(stderr, "want:\n");
@@ -288,10 +288,16 @@ ec_group_roundtrip_builtin_curve(const EC_builtin_curve *curve)
{
EC_GROUP *group = NULL;
int failed = 0;
+ int ret = 0;
if ((group = EC_GROUP_new_by_curve_name(curve->nid)) == NULL)
errx(1, "failed to instantiate curve %d", curve->nid);
+ if (!EC_GROUP_check(group, NULL)) {
+ fprintf(stderr, "FAIL: EC_GROUP_check(%d) failed\n", curve->nid);
+ goto err;
+ }
+
if (EC_GROUP_get_asn1_flag(group) != OPENSSL_EC_NAMED_CURVE) {
fprintf(stderr, "FAIL: ASN.1 flag not set for %d\n", curve->nid);
goto err;
@@ -314,7 +320,11 @@ ec_group_roundtrip_builtin_curve(const EC_builtin_curve *curve)
EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_HYBRID);
failed |= ec_group_roundtrip_curve(group, "hybrid", curve->nid);
+ ret = 1;
+
err:
+ failed |= ret == 0;
+
EC_GROUP_free(group);
return failed;
diff --git a/regress/lib/libcrypto/ec/ectest.c b/regress/lib/libcrypto/ec/ectest.c
index e60fde60e6e..b653ab78761 100644
--- a/regress/lib/libcrypto/ec/ectest.c
+++ b/regress/lib/libcrypto/ec/ectest.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ectest.c,v 1.23 2024/02/29 20:04:43 tb Exp $ */
+/* $OpenBSD: ectest.c,v 1.24 2024/10/18 19:55:34 tb Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
@@ -703,68 +703,12 @@ prime_field_tests(void)
}
-static void
-internal_curve_test(void)
-{
- EC_builtin_curve *curves = NULL;
- size_t crv_len = 0, n = 0;
- int ok = 1;
-
- crv_len = EC_get_builtin_curves(NULL, 0);
-
- curves = reallocarray(NULL, sizeof(EC_builtin_curve), crv_len);
-
- if (curves == NULL)
- return;
-
- if (!EC_get_builtin_curves(curves, crv_len)) {
- free(curves);
- return;
- }
-
- fprintf(stdout, "testing internal curves: ");
-
- for (n = 0; n < crv_len; n++) {
- EC_GROUP *group = NULL;
- int nid = curves[n].nid;
- if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL) {
- ok = 0;
- fprintf(stdout, "\nEC_GROUP_new_curve_name() failed with"
- " curve %s\n", OBJ_nid2sn(nid));
- /* try next curve */
- continue;
- }
- if (!EC_GROUP_check(group, NULL)) {
- ok = 0;
- fprintf(stdout, "\nEC_GROUP_check() failed with"
- " curve %s\n", OBJ_nid2sn(nid));
- EC_GROUP_free(group);
- /* try the next curve */
- continue;
- }
- fprintf(stdout, ".");
- fflush(stdout);
- EC_GROUP_free(group);
- }
- if (ok)
- fprintf(stdout, " ok\n\n");
- else {
- fprintf(stdout, " failed\n\n");
- ABORT;
- }
- free(curves);
- return;
-}
-
int
main(int argc, char *argv[])
{
ERR_load_crypto_strings();
prime_field_tests();
- puts("");
- /* test the internal curves */
- internal_curve_test();
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();