summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2024-11-06 08:59:32 +0000
committertb <>2024-11-06 08:59:32 +0000
commit89ed341527c32f26bc41fe456d57031ba8887e57 (patch)
tree7fc1ab769d4a48d17ef90b8b9f9afe0507f67f56 /src/lib
parent07ca277790942f778ce63607bfb364dde82b3b28 (diff)
downloadopenbsd-89ed341527c32f26bc41fe456d57031ba8887e57.tar.gz
openbsd-89ed341527c32f26bc41fe456d57031ba8887e57.tar.bz2
openbsd-89ed341527c32f26bc41fe456d57031ba8887e57.zip
Switch EC_GROUP_new() to calloc()
Use a single cleanup path, use calloc rather than setting several members to 0/NULL. This has the side effect that finished can be called even when init() wasn't called, but this isn't an issue with our EC_GROUP_METHODs. ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index 15e5055f34..c02f054cdc 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.79 2024/11/05 08:56:57 tb Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.80 2024/11/06 08:59:32 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 */
@@ -80,39 +80,38 @@
80EC_GROUP * 80EC_GROUP *
81EC_GROUP_new(const EC_METHOD *meth) 81EC_GROUP_new(const EC_METHOD *meth)
82{ 82{
83 EC_GROUP *ret; 83 EC_GROUP *group = NULL;
84 84
85 if (meth == NULL) { 85 if (meth == NULL) {
86 ECerror(EC_R_SLOT_FULL); 86 ECerror(EC_R_SLOT_FULL);
87 return NULL; 87 goto err;
88 } 88 }
89 if (meth->group_init == NULL) { 89 if (meth->group_init == NULL) {
90 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 90 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
91 return NULL; 91 goto err;
92 } 92 }
93 ret = malloc(sizeof *ret); 93 if ((group = calloc(1, sizeof(*group))) == NULL) {
94 if (ret == NULL) {
95 ECerror(ERR_R_MALLOC_FAILURE); 94 ECerror(ERR_R_MALLOC_FAILURE);
96 return NULL; 95 goto err;
97 } 96 }
98 ret->meth = meth;
99 97
100 ret->generator = NULL; 98 group->meth = meth;
101 BN_init(&ret->order);
102 BN_init(&ret->cofactor);
103 99
104 ret->curve_name = 0; 100 BN_init(&group->order);
105 ret->asn1_flag = OPENSSL_EC_NAMED_CURVE; 101 BN_init(&group->cofactor);
106 ret->asn1_form = POINT_CONVERSION_UNCOMPRESSED;
107 102
108 ret->seed = NULL; 103 group->asn1_flag = OPENSSL_EC_NAMED_CURVE;
109 ret->seed_len = 0; 104 group->asn1_form = POINT_CONVERSION_UNCOMPRESSED;
110 105
111 if (!meth->group_init(ret)) { 106 if (!meth->group_init(group))
112 free(ret); 107 goto err;
113 return NULL; 108
114 } 109 return group;
115 return ret; 110
111 err:
112 EC_GROUP_free(group);
113
114 return NULL;
116} 115}
117LCRYPTO_ALIAS(EC_GROUP_new); 116LCRYPTO_ALIAS(EC_GROUP_new);
118 117