diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/ec/ec_asn1_test.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/ec/ec_asn1_test.c b/src/regress/lib/libcrypto/ec/ec_asn1_test.c index 50e6304baf..0215cd7ec2 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.36 2025/07/23 07:42:33 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1_test.c,v 1.37 2025/08/26 15:56:46 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, 2025 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2024, 2025 Theo Buehler <tb@openbsd.org> |
@@ -1030,6 +1030,62 @@ ec_group_non_builtin_curves(void) | |||
1030 | return failed; | 1030 | return failed; |
1031 | } | 1031 | } |
1032 | 1032 | ||
1033 | static int | ||
1034 | ec_group_check_prime_order(EC_builtin_curve *curve, BN_CTX *ctx) | ||
1035 | { | ||
1036 | EC_GROUP *group; | ||
1037 | BIGNUM *p; | ||
1038 | int rv; | ||
1039 | int failed = 0; | ||
1040 | |||
1041 | if ((group = EC_GROUP_new_by_curve_name(curve->nid)) == NULL) | ||
1042 | errx(1, "EC_GROUP_new_by_curve_name"); | ||
1043 | |||
1044 | BN_CTX_start(ctx); | ||
1045 | |||
1046 | if ((p = BN_CTX_get(ctx)) == NULL) | ||
1047 | errx(1, "p = BN_CTX_get()"); | ||
1048 | |||
1049 | if (!EC_GROUP_get_curve(group, p, NULL, NULL, ctx)) | ||
1050 | errx(1, "EC_GROUP_get_curve"); | ||
1051 | |||
1052 | if ((rv = BN_is_prime_ex(p, 0, ctx, NULL)) != 1) { | ||
1053 | fprintf(stderr, "%s: nid %d: BN_is_prime_ex() returned %d, want 1\n", | ||
1054 | __func__, curve->nid, rv); | ||
1055 | failed = 1; | ||
1056 | } | ||
1057 | |||
1058 | BN_CTX_end(ctx); | ||
1059 | EC_GROUP_free(group); | ||
1060 | |||
1061 | return failed; | ||
1062 | } | ||
1063 | |||
1064 | static int | ||
1065 | ec_group_builtin_curves_have_prime_order(void) | ||
1066 | { | ||
1067 | BN_CTX *ctx = NULL; | ||
1068 | EC_builtin_curve *all_curves = NULL; | ||
1069 | size_t curve_id, ncurves; | ||
1070 | int failed = 0; | ||
1071 | |||
1072 | if ((ctx = BN_CTX_new()) == NULL) | ||
1073 | errx(1, "BN_CTX_new"); | ||
1074 | |||
1075 | ncurves = EC_get_builtin_curves(NULL, 0); | ||
1076 | if ((all_curves = calloc(ncurves, sizeof(*all_curves))) == NULL) | ||
1077 | err(1, "calloc builtin curves"); | ||
1078 | EC_get_builtin_curves(all_curves, ncurves); | ||
1079 | |||
1080 | for (curve_id = 0; curve_id < ncurves; curve_id++) | ||
1081 | failed |= ec_group_check_prime_order(&all_curves[curve_id], ctx); | ||
1082 | |||
1083 | free(all_curves); | ||
1084 | BN_CTX_free(ctx); | ||
1085 | |||
1086 | return failed; | ||
1087 | } | ||
1088 | |||
1033 | static const struct ec_private_key { | 1089 | static const struct ec_private_key { |
1034 | const char *name; | 1090 | const char *name; |
1035 | size_t der_len; | 1091 | size_t der_len; |
@@ -2554,6 +2610,7 @@ main(int argc, char **argv) | |||
2554 | failed |= ec_group_pkparameters_correct_padding_test(); | 2610 | failed |= ec_group_pkparameters_correct_padding_test(); |
2555 | failed |= ec_group_roundtrip_builtin_curves(); | 2611 | failed |= ec_group_roundtrip_builtin_curves(); |
2556 | failed |= ec_group_non_builtin_curves(); | 2612 | failed |= ec_group_non_builtin_curves(); |
2613 | failed |= ec_group_builtin_curves_have_prime_order(); | ||
2557 | failed |= ec_group_check_private_keys(); | 2614 | failed |= ec_group_check_private_keys(); |
2558 | failed |= ec_group_check_seeds(); | 2615 | failed |= ec_group_check_seeds(); |
2559 | 2616 | ||