diff options
author | tb <> | 2024-12-06 04:35:03 +0000 |
---|---|---|
committer | tb <> | 2024-12-06 04:35:03 +0000 |
commit | ec6a80c2122918d0d43aa05322cc30a8d45c7d81 (patch) | |
tree | ed4fda406898fc81a1d4c617faf07972aad0d8ea /src/lib | |
parent | b32147fff9dbbaff86a38b82df29174c55cca816 (diff) | |
download | openbsd-ec6a80c2122918d0d43aa05322cc30a8d45c7d81.tar.gz openbsd-ec6a80c2122918d0d43aa05322cc30a8d45c7d81.tar.bz2 openbsd-ec6a80c2122918d0d43aa05322cc30a8d45c7d81.zip |
Set nid on group decoded from EC parameters
We match curve parameters against the builtin curves and only accept
them if they're encoding a curve known to us. After getting rid of the
wtls curves, some of which used to coincide with secp curves (sometimes
the wrong ones), the nid is unambiguous. Setting the nid has no direct
implications on the encoding.
This helps ssh avoid doing ugly computations during the key exchange
for PEM keys using this encoding.
ok djm joshua jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ec/ec_asn1.c | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_curve.c | 11 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_local.h | 4 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c index b5be7b496d..7d2243db0c 100644 --- a/src/lib/libcrypto/ec/ec_asn1.c +++ b/src/lib/libcrypto/ec/ec_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_asn1.c,v 1.107 2024/11/22 12:01:14 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1.c,v 1.108 2024/12/06 04:35:03 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -1069,6 +1069,7 @@ static EC_GROUP * | |||
1069 | ec_asn1_parameters2group(const ECPARAMETERS *params) | 1069 | ec_asn1_parameters2group(const ECPARAMETERS *params) |
1070 | { | 1070 | { |
1071 | EC_GROUP *group = NULL; | 1071 | EC_GROUP *group = NULL; |
1072 | int nid = NID_undef; | ||
1072 | 1073 | ||
1073 | if (params == NULL) { | 1074 | if (params == NULL) { |
1074 | ECerror(EC_R_ASN1_ERROR); | 1075 | ECerror(EC_R_ASN1_ERROR); |
@@ -1077,8 +1078,9 @@ ec_asn1_parameters2group(const ECPARAMETERS *params) | |||
1077 | 1078 | ||
1078 | if (!ec_asn1_parameters_extract_prime_group(params, &group)) | 1079 | if (!ec_asn1_parameters_extract_prime_group(params, &group)) |
1079 | goto err; | 1080 | goto err; |
1080 | if (!ec_group_is_builtin_curve(group)) | 1081 | if (!ec_group_is_builtin_curve(group, &nid)) |
1081 | goto err; | 1082 | goto err; |
1083 | EC_GROUP_set_curve_name(group, nid); | ||
1082 | 1084 | ||
1083 | return group; | 1085 | return group; |
1084 | 1086 | ||
diff --git a/src/lib/libcrypto/ec/ec_curve.c b/src/lib/libcrypto/ec/ec_curve.c index a37f324a24..cc5ad4d4e6 100644 --- a/src/lib/libcrypto/ec/ec_curve.c +++ b/src/lib/libcrypto/ec/ec_curve.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_curve.c,v 1.51 2024/12/04 09:50:52 tb Exp $ */ | 1 | /* $OpenBSD: ec_curve.c,v 1.52 2024/12/06 04:35:03 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -2685,16 +2685,21 @@ ec_group_nid_from_curve(const struct ec_curve *curve) | |||
2685 | } | 2685 | } |
2686 | 2686 | ||
2687 | int | 2687 | int |
2688 | ec_group_is_builtin_curve(const EC_GROUP *group) | 2688 | ec_group_is_builtin_curve(const EC_GROUP *group, int *out_nid) |
2689 | { | 2689 | { |
2690 | struct ec_curve *curve; | 2690 | struct ec_curve *curve; |
2691 | int ret = 0; | 2691 | int ret = 0; |
2692 | int nid; | ||
2693 | |||
2694 | *out_nid = NID_undef; | ||
2692 | 2695 | ||
2693 | if ((curve = ec_curve_from_group(group)) == NULL) | 2696 | if ((curve = ec_curve_from_group(group)) == NULL) |
2694 | goto err; | 2697 | goto err; |
2695 | if (ec_group_nid_from_curve(curve) == NID_undef) | 2698 | if ((nid = ec_group_nid_from_curve(curve)) == NID_undef) |
2696 | goto err; | 2699 | goto err; |
2697 | 2700 | ||
2701 | *out_nid = nid; | ||
2702 | |||
2698 | ret = 1; | 2703 | ret = 1; |
2699 | 2704 | ||
2700 | err: | 2705 | err: |
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index 11cc36cf67..9a5c42f866 100644 --- a/src/lib/libcrypto/ec/ec_local.h +++ b/src/lib/libcrypto/ec/ec_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_local.h,v 1.40 2024/11/30 21:09:59 tb Exp $ */ | 1 | /* $OpenBSD: ec_local.h,v 1.41 2024/12/06 04:35:03 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 | */ |
@@ -294,7 +294,7 @@ int EC_POINT_set_Jprojective_coordinates(const EC_GROUP *group, EC_POINT *p, | |||
294 | int EC_POINT_get_Jprojective_coordinates(const EC_GROUP *group, | 294 | int EC_POINT_get_Jprojective_coordinates(const EC_GROUP *group, |
295 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); | 295 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); |
296 | 296 | ||
297 | int ec_group_is_builtin_curve(const EC_GROUP *group); | 297 | int ec_group_is_builtin_curve(const EC_GROUP *group, int *out_nid); |
298 | int ec_group_get_field_type(const EC_GROUP *group); | 298 | int ec_group_get_field_type(const EC_GROUP *group); |
299 | 299 | ||
300 | /* | 300 | /* |