summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/ec/ec_curve.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/lib/libcrypto/ec/ec_curve.c b/src/lib/libcrypto/ec/ec_curve.c
index 9ab8c88f5e..e5c3d87644 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.39 2023/05/01 17:53:01 tb Exp $ */ 1/* $OpenBSD: ec_curve.c,v 1.40 2023/05/02 10:44:20 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -3000,11 +3000,10 @@ static const struct ec_list_element {
3000static EC_GROUP * 3000static EC_GROUP *
3001ec_group_new_from_data(const struct ec_list_element *curve) 3001ec_group_new_from_data(const struct ec_list_element *curve)
3002{ 3002{
3003 EC_GROUP *group = NULL; 3003 EC_GROUP *group = NULL, *ret = NULL;
3004 EC_POINT *P = NULL; 3004 EC_POINT *P = NULL;
3005 BN_CTX *ctx = NULL; 3005 BN_CTX *ctx = NULL;
3006 BIGNUM *p, *a, *b, *x, *y, *order, *cofactor; 3006 BIGNUM *p, *a, *b, *x, *y, *order, *cofactor;
3007 int ok = 0;
3008 3007
3009 if ((ctx = BN_CTX_new()) == NULL) { 3008 if ((ctx = BN_CTX_new()) == NULL) {
3010 ECerror(ERR_R_MALLOC_FAILURE); 3009 ECerror(ERR_R_MALLOC_FAILURE);
@@ -3057,6 +3056,7 @@ ec_group_new_from_data(const struct ec_list_element *curve)
3057 ECerror(ERR_R_EC_LIB); 3056 ECerror(ERR_R_EC_LIB);
3058 goto err; 3057 goto err;
3059 } 3058 }
3059 EC_GROUP_set_curve_name(group, curve->nid);
3060 3060
3061 if ((P = EC_POINT_new(group)) == NULL) { 3061 if ((P = EC_POINT_new(group)) == NULL) {
3062 ECerror(ERR_R_EC_LIB); 3062 ECerror(ERR_R_EC_LIB);
@@ -3086,47 +3086,41 @@ ec_group_new_from_data(const struct ec_list_element *curve)
3086 ECerror(ERR_R_EC_LIB); 3086 ECerror(ERR_R_EC_LIB);
3087 goto err; 3087 goto err;
3088 } 3088 }
3089
3089 if (curve->seed != NULL) { 3090 if (curve->seed != NULL) {
3090 if (!EC_GROUP_set_seed(group, curve->seed, curve->seed_len)) { 3091 if (!EC_GROUP_set_seed(group, curve->seed, curve->seed_len)) {
3091 ECerror(ERR_R_EC_LIB); 3092 ECerror(ERR_R_EC_LIB);
3092 goto err; 3093 goto err;
3093 } 3094 }
3094 } 3095 }
3095 ok = 1; 3096
3097 ret = group;
3098 group = NULL;
3099
3096 err: 3100 err:
3097 if (!ok) { 3101 EC_GROUP_free(group);
3098 EC_GROUP_free(group);
3099 group = NULL;
3100 }
3101 EC_POINT_free(P); 3102 EC_POINT_free(P);
3102 BN_CTX_end(ctx); 3103 BN_CTX_end(ctx);
3103 BN_CTX_free(ctx); 3104 BN_CTX_free(ctx);
3104 3105
3105 return group; 3106 return ret;
3106} 3107}
3107 3108
3108EC_GROUP * 3109EC_GROUP *
3109EC_GROUP_new_by_curve_name(int nid) 3110EC_GROUP_new_by_curve_name(int nid)
3110{ 3111{
3111 size_t i; 3112 size_t i;
3112 EC_GROUP *ret = NULL;
3113 3113
3114 if (nid <= 0) 3114 if (nid <= 0)
3115 return NULL; 3115 return NULL;
3116 3116
3117 for (i = 0; i < CURVE_LIST_LENGTH; i++) { 3117 for (i = 0; i < CURVE_LIST_LENGTH; i++) {
3118 if (curve_list[i].nid == nid) { 3118 if (curve_list[i].nid == nid)
3119 ret = ec_group_new_from_data(&curve_list[i]); 3119 return ec_group_new_from_data(&curve_list[i]);
3120 break;
3121 }
3122 }
3123 if (ret == NULL) {
3124 ECerror(EC_R_UNKNOWN_GROUP);
3125 return NULL;
3126 } 3120 }
3127 EC_GROUP_set_curve_name(ret, nid);
3128 3121
3129 return ret; 3122 ECerror(EC_R_UNKNOWN_GROUP);
3123 return NULL;
3130} 3124}
3131 3125
3132size_t 3126size_t