summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2023-03-07 05:28:12 +0000
committerjsing <>2023-03-07 05:28:12 +0000
commitb5d85b984ce78973b781bfa529c8e884c9979a4a (patch)
tree43744c1b5fc50fa422d73462de95d3ddf0c7d133 /src/lib
parent94300da894e5468bd62ec59554e63c4ce7b63037 (diff)
downloadopenbsd-b5d85b984ce78973b781bfa529c8e884c9979a4a.tar.gz
openbsd-b5d85b984ce78973b781bfa529c8e884c9979a4a.tar.bz2
openbsd-b5d85b984ce78973b781bfa529c8e884c9979a4a.zip
Consolidate clear code for EC_GFp_mont_method.
Use a fang dangled thing (known as a function) to avoid duplicating the same code in five places. ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ec/ecp_mont.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
index 178b438dff..ed69d1f554 100644
--- a/src/lib/libcrypto/ec/ecp_mont.c
+++ b/src/lib/libcrypto/ec/ecp_mont.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_mont.c,v 1.23 2023/03/04 14:38:00 jsing Exp $ */ 1/* $OpenBSD: ecp_mont.c,v 1.24 2023/03/07 05:28:12 jsing 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 */
@@ -65,6 +65,15 @@
65 65
66#include "ec_local.h" 66#include "ec_local.h"
67 67
68static void
69ec_GFp_mont_group_clear(EC_GROUP *group)
70{
71 BN_MONT_CTX_free(group->mont_ctx);
72 group->mont_ctx = NULL;
73
74 BN_free(group->mont_one);
75 group->mont_one = NULL;
76}
68 77
69const EC_METHOD * 78const EC_METHOD *
70EC_GFp_mont_method(void) 79EC_GFp_mont_method(void)
@@ -133,10 +142,7 @@ ec_GFp_mont_group_init(EC_GROUP *group)
133void 142void
134ec_GFp_mont_group_finish(EC_GROUP *group) 143ec_GFp_mont_group_finish(EC_GROUP *group)
135{ 144{
136 BN_MONT_CTX_free(group->mont_ctx); 145 ec_GFp_mont_group_clear(group);
137 group->mont_ctx = NULL;
138 BN_free(group->mont_one);
139 group->mont_one = NULL;
140 ec_GFp_simple_group_finish(group); 146 ec_GFp_simple_group_finish(group);
141} 147}
142 148
@@ -144,10 +150,7 @@ ec_GFp_mont_group_finish(EC_GROUP *group)
144void 150void
145ec_GFp_mont_group_clear_finish(EC_GROUP *group) 151ec_GFp_mont_group_clear_finish(EC_GROUP *group)
146{ 152{
147 BN_MONT_CTX_free(group->mont_ctx); 153 ec_GFp_mont_group_clear(group);
148 group->mont_ctx = NULL;
149 BN_clear_free(group->mont_one);
150 group->mont_one = NULL;
151 ec_GFp_simple_group_clear_finish(group); 154 ec_GFp_simple_group_clear_finish(group);
152} 155}
153 156
@@ -155,10 +158,7 @@ ec_GFp_mont_group_clear_finish(EC_GROUP *group)
155int 158int
156ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) 159ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
157{ 160{
158 BN_MONT_CTX_free(dest->mont_ctx); 161 ec_GFp_mont_group_clear(dest);
159 dest->mont_ctx = NULL;
160 BN_clear_free(dest->mont_one);
161 dest->mont_one = NULL;
162 162
163 if (!ec_GFp_simple_group_copy(dest, src)) 163 if (!ec_GFp_simple_group_copy(dest, src))
164 return 0; 164 return 0;
@@ -195,10 +195,8 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
195 BIGNUM *one = NULL; 195 BIGNUM *one = NULL;
196 int ret = 0; 196 int ret = 0;
197 197
198 BN_MONT_CTX_free(group->mont_ctx); 198 ec_GFp_mont_group_clear(group);
199 group->mont_ctx = NULL; 199
200 BN_free(group->mont_one);
201 group->mont_one = NULL;
202 if (ctx == NULL) { 200 if (ctx == NULL) {
203 ctx = new_ctx = BN_CTX_new(); 201 ctx = new_ctx = BN_CTX_new();
204 if (ctx == NULL) 202 if (ctx == NULL)
@@ -224,12 +222,9 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
224 222
225 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); 223 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
226 224
227 if (!ret) { 225 if (!ret)
228 BN_MONT_CTX_free(group->mont_ctx); 226 ec_GFp_mont_group_clear(group);
229 group->mont_ctx = NULL; 227
230 BN_free(group->mont_one);
231 group->mont_one = NULL;
232 }
233 err: 228 err:
234 BN_CTX_free(new_ctx); 229 BN_CTX_free(new_ctx);
235 BN_MONT_CTX_free(mont); 230 BN_MONT_CTX_free(mont);