summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ecp_mont.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ecp_mont.c')
-rw-r--r--src/lib/libcrypto/ec/ecp_mont.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
index 915cf15f72..b113855603 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.28 2023/03/27 10:25:02 tb Exp $ */ 1/* $OpenBSD: ecp_mont.c,v 1.29 2023/04/11 18:58:20 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 */
@@ -127,18 +127,12 @@ static int
127ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, 127ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
128 const BIGNUM *b, BN_CTX *ctx) 128 const BIGNUM *b, BN_CTX *ctx)
129{ 129{
130 BN_CTX *new_ctx = NULL;
131 BN_MONT_CTX *mont = NULL; 130 BN_MONT_CTX *mont = NULL;
132 BIGNUM *one = NULL; 131 BIGNUM *one = NULL;
133 int ret = 0; 132 int ret = 0;
134 133
135 ec_GFp_mont_group_clear(group); 134 ec_GFp_mont_group_clear(group);
136 135
137 if (ctx == NULL) {
138 ctx = new_ctx = BN_CTX_new();
139 if (ctx == NULL)
140 return 0;
141 }
142 mont = BN_MONT_CTX_new(); 136 mont = BN_MONT_CTX_new();
143 if (mont == NULL) 137 if (mont == NULL)
144 goto err; 138 goto err;
@@ -158,14 +152,13 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
158 one = NULL; 152 one = NULL;
159 153
160 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); 154 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
161
162 if (!ret) 155 if (!ret)
163 ec_GFp_mont_group_clear(group); 156 ec_GFp_mont_group_clear(group);
164 157
165 err: 158 err:
166 BN_CTX_free(new_ctx);
167 BN_MONT_CTX_free(mont); 159 BN_MONT_CTX_free(mont);
168 BN_free(one); 160 BN_free(one);
161
169 return ret; 162 return ret;
170} 163}
171 164
@@ -222,6 +215,7 @@ ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx)
222 } 215 }
223 if (!bn_copy(r, group->mont_one)) 216 if (!bn_copy(r, group->mont_one))
224 return 0; 217 return 0;
218
225 return 1; 219 return 1;
226} 220}
227 221