summaryrefslogtreecommitdiff
path: root/lib/libcrypto
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-11-08 21:53:55 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-11-08 21:53:55 +0000
commit5e0296c17474ec8c96ea860eb042ef878eb89dfe (patch)
treea20de6e0598c1d5c0f86675651da0f1b2183cfe0 /lib/libcrypto
parent33b77b91741efd8a72fe839d1827c5910b6e6dd5 (diff)
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 'lib/libcrypto')
-rw-r--r--lib/libcrypto/ec/ec_key.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/libcrypto/ec/ec_key.c b/lib/libcrypto/ec/ec_key.c
index 21c22823f98..c8f4c15bb53 100644
--- a/lib/libcrypto/ec/ec_key.c
+++ b/lib/libcrypto/ec/ec_key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec_key.c,v 1.42 2024/11/05 08:56:57 tb Exp $ */
+/* $OpenBSD: ec_key.c,v 1.43 2024/11/08 21:53:54 tb Exp $ */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
@@ -80,20 +80,26 @@ LCRYPTO_ALIAS(EC_KEY_new);
EC_KEY *
EC_KEY_new_by_curve_name(int nid)
{
- EC_KEY *ret = EC_KEY_new();
- if (ret == NULL)
- return NULL;
- ret->group = EC_GROUP_new_by_curve_name(nid);
- if (ret->group == NULL) {
- EC_KEY_free(ret);
- return NULL;
- }
- if (ret->meth->set_group != NULL &&
- ret->meth->set_group(ret, ret->group) == 0) {
- EC_KEY_free(ret);
- return NULL;
+ EC_KEY *ec_key;
+
+ if ((ec_key = EC_KEY_new()) == NULL)
+ goto err;
+
+ if ((ec_key->group = EC_GROUP_new_by_curve_name(nid)) == NULL)
+ goto err;
+
+ /* XXX - do we want an ec_key_set0_group()? */
+ if (ec_key->meth->set_group != NULL) {
+ if (!ec_key->meth->set_group(ec_key, ec_key->group))
+ goto err;
}
- return ret;
+
+ return ec_key;
+
+ err:
+ EC_KEY_free(ec_key);
+
+ return NULL;
}
LCRYPTO_ALIAS(EC_KEY_new_by_curve_name);