summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2024-11-08 21:53:54 +0000
committertb <>2024-11-08 21:53:54 +0000
commite71b1edd47d2200ba7c87b037cee0587f6dedf1e (patch)
treee4cb79362b711009831afc5fc78139b3f59f2f3c /src/lib
parent272094545b800ccf1dbf9568237adcd8ee4b717a (diff)
downloadopenbsd-e71b1edd47d2200ba7c87b037cee0587f6dedf1e.tar.gz
openbsd-e71b1edd47d2200ba7c87b037cee0587f6dedf1e.tar.bz2
openbsd-e71b1edd47d2200ba7c87b037cee0587f6dedf1e.zip
Clean up EC_KEY_new_by_curve_name()
Use a better variable name, simpler error handling. This could be simplified further if we decide to have an ec_key_set0_group() that avoids a copy. ok beck jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ec/ec_key.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index 21c22823f9..c8f4c15bb5 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_key.c,v 1.42 2024/11/05 08:56:57 tb Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.43 2024/11/08 21:53:54 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -80,20 +80,26 @@ LCRYPTO_ALIAS(EC_KEY_new);
80EC_KEY * 80EC_KEY *
81EC_KEY_new_by_curve_name(int nid) 81EC_KEY_new_by_curve_name(int nid)
82{ 82{
83 EC_KEY *ret = EC_KEY_new(); 83 EC_KEY *ec_key;
84 if (ret == NULL) 84
85 return NULL; 85 if ((ec_key = EC_KEY_new()) == NULL)
86 ret->group = EC_GROUP_new_by_curve_name(nid); 86 goto err;
87 if (ret->group == NULL) { 87
88 EC_KEY_free(ret); 88 if ((ec_key->group = EC_GROUP_new_by_curve_name(nid)) == NULL)
89 return NULL; 89 goto err;
90 } 90
91 if (ret->meth->set_group != NULL && 91 /* XXX - do we want an ec_key_set0_group()? */
92 ret->meth->set_group(ret, ret->group) == 0) { 92 if (ec_key->meth->set_group != NULL) {
93 EC_KEY_free(ret); 93 if (!ec_key->meth->set_group(ec_key, ec_key->group))
94 return NULL; 94 goto err;
95 } 95 }
96 return ret; 96
97 return ec_key;
98
99 err:
100 EC_KEY_free(ec_key);
101
102 return NULL;
97} 103}
98LCRYPTO_ALIAS(EC_KEY_new_by_curve_name); 104LCRYPTO_ALIAS(EC_KEY_new_by_curve_name);
99 105