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.c57
1 files changed, 20 insertions, 37 deletions
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
index ffbce81d4c..af8014ed38 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.8 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ecp_mont.c,v 1.9 2014/07/12 16:03:37 miod 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 */
@@ -128,14 +128,10 @@ ec_GFp_mont_group_init(EC_GROUP * group)
128void 128void
129ec_GFp_mont_group_finish(EC_GROUP * group) 129ec_GFp_mont_group_finish(EC_GROUP * group)
130{ 130{
131 if (group->field_data1 != NULL) { 131 BN_MONT_CTX_free(group->field_data1);
132 BN_MONT_CTX_free(group->field_data1); 132 group->field_data1 = NULL;
133 group->field_data1 = NULL; 133 BN_free(group->field_data2);
134 } 134 group->field_data2 = NULL;
135 if (group->field_data2 != NULL) {
136 BN_free(group->field_data2);
137 group->field_data2 = NULL;
138 }
139 ec_GFp_simple_group_finish(group); 135 ec_GFp_simple_group_finish(group);
140} 136}
141 137
@@ -143,14 +139,10 @@ ec_GFp_mont_group_finish(EC_GROUP * group)
143void 139void
144ec_GFp_mont_group_clear_finish(EC_GROUP * group) 140ec_GFp_mont_group_clear_finish(EC_GROUP * group)
145{ 141{
146 if (group->field_data1 != NULL) { 142 BN_MONT_CTX_free(group->field_data1);
147 BN_MONT_CTX_free(group->field_data1); 143 group->field_data1 = NULL;
148 group->field_data1 = NULL; 144 BN_clear_free(group->field_data2);
149 } 145 group->field_data2 = NULL;
150 if (group->field_data2 != NULL) {
151 BN_clear_free(group->field_data2);
152 group->field_data2 = NULL;
153 }
154 ec_GFp_simple_group_clear_finish(group); 146 ec_GFp_simple_group_clear_finish(group);
155} 147}
156 148
@@ -158,14 +150,11 @@ ec_GFp_mont_group_clear_finish(EC_GROUP * group)
158int 150int
159ec_GFp_mont_group_copy(EC_GROUP * dest, const EC_GROUP * src) 151ec_GFp_mont_group_copy(EC_GROUP * dest, const EC_GROUP * src)
160{ 152{
161 if (dest->field_data1 != NULL) { 153 BN_MONT_CTX_free(dest->field_data1);
162 BN_MONT_CTX_free(dest->field_data1); 154 dest->field_data1 = NULL;
163 dest->field_data1 = NULL; 155 BN_clear_free(dest->field_data2);
164 } 156 dest->field_data2 = NULL;
165 if (dest->field_data2 != NULL) { 157
166 BN_clear_free(dest->field_data2);
167 dest->field_data2 = NULL;
168 }
169 if (!ec_GFp_simple_group_copy(dest, src)) 158 if (!ec_GFp_simple_group_copy(dest, src))
170 return 0; 159 return 0;
171 160
@@ -201,14 +190,10 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
201 BIGNUM *one = NULL; 190 BIGNUM *one = NULL;
202 int ret = 0; 191 int ret = 0;
203 192
204 if (group->field_data1 != NULL) { 193 BN_MONT_CTX_free(group->field_data1);
205 BN_MONT_CTX_free(group->field_data1); 194 group->field_data1 = NULL;
206 group->field_data1 = NULL; 195 BN_free(group->field_data2);
207 } 196 group->field_data2 = NULL;
208 if (group->field_data2 != NULL) {
209 BN_free(group->field_data2);
210 group->field_data2 = NULL;
211 }
212 if (ctx == NULL) { 197 if (ctx == NULL) {
213 ctx = new_ctx = BN_CTX_new(); 198 ctx = new_ctx = BN_CTX_new();
214 if (ctx == NULL) 199 if (ctx == NULL)
@@ -241,10 +226,8 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
241 group->field_data2 = NULL; 226 group->field_data2 = NULL;
242 } 227 }
243err: 228err:
244 if (new_ctx != NULL) 229 BN_CTX_free(new_ctx);
245 BN_CTX_free(new_ctx); 230 BN_MONT_CTX_free(mont);
246 if (mont != NULL)
247 BN_MONT_CTX_free(mont);
248 return ret; 231 return ret;
249} 232}
250 233