diff options
author | jsing <> | 2023-03-04 14:38:00 +0000 |
---|---|---|
committer | jsing <> | 2023-03-04 14:38:00 +0000 |
commit | e93b09fa751b09cd5cd85c041389468b31a87969 (patch) | |
tree | 02ba1f7650d9ab5893c2668214514a9103855b8f | |
parent | b1fae0e7a40efd6fd7973b0f8d56a2a501c4ca9a (diff) | |
download | openbsd-e93b09fa751b09cd5cd85c041389468b31a87969.tar.gz openbsd-e93b09fa751b09cd5cd85c041389468b31a87969.tar.bz2 openbsd-e93b09fa751b09cd5cd85c041389468b31a87969.zip |
Rename field_data1 and field_data2.
Rather than pretending that these "generic" variables are used for multiple
things, rename them to reflect their actual usage and use appropriate types
instead of void *.
ok tb@
-rw-r--r-- | src/lib/libcrypto/ec/ec_local.h | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ecp_mont.c | 90 |
2 files changed, 50 insertions, 48 deletions
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index 5fc9bfebbb..e1240bf6a8 100644 --- a/src/lib/libcrypto/ec/ec_local.h +++ b/src/lib/libcrypto/ec/ec_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_local.h,v 1.1 2022/11/26 16:08:52 tb Exp $ */ | 1 | /* $OpenBSD: ec_local.h,v 1.2 2023/03/04 14:38:00 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 | */ |
@@ -251,8 +251,10 @@ struct ec_group_st { | |||
251 | /* Enables optimized point arithmetics for special case. */ | 251 | /* Enables optimized point arithmetics for special case. */ |
252 | int a_is_minus3; | 252 | int a_is_minus3; |
253 | 253 | ||
254 | void *field_data1; | 254 | /* Montgomery context and values used by EC_GFp_mont_method. */ |
255 | void *field_data2; | 255 | BN_MONT_CTX *mont_ctx; |
256 | BIGNUM *mont_one; | ||
257 | |||
256 | int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *, | 258 | int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *, |
257 | BN_CTX *); | 259 | BN_CTX *); |
258 | } /* EC_GROUP */; | 260 | } /* EC_GROUP */; |
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c index 74204ed39a..178b438dff 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.22 2022/11/26 16:08:52 tb Exp $ */ | 1 | /* $OpenBSD: ecp_mont.c,v 1.23 2023/03/04 14:38:00 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 | */ |
@@ -124,8 +124,8 @@ ec_GFp_mont_group_init(EC_GROUP *group) | |||
124 | int ok; | 124 | int ok; |
125 | 125 | ||
126 | ok = ec_GFp_simple_group_init(group); | 126 | ok = ec_GFp_simple_group_init(group); |
127 | group->field_data1 = NULL; | 127 | group->mont_ctx = NULL; |
128 | group->field_data2 = NULL; | 128 | group->mont_one = NULL; |
129 | return ok; | 129 | return ok; |
130 | } | 130 | } |
131 | 131 | ||
@@ -133,10 +133,10 @@ ec_GFp_mont_group_init(EC_GROUP *group) | |||
133 | void | 133 | void |
134 | ec_GFp_mont_group_finish(EC_GROUP *group) | 134 | ec_GFp_mont_group_finish(EC_GROUP *group) |
135 | { | 135 | { |
136 | BN_MONT_CTX_free(group->field_data1); | 136 | BN_MONT_CTX_free(group->mont_ctx); |
137 | group->field_data1 = NULL; | 137 | group->mont_ctx = NULL; |
138 | BN_free(group->field_data2); | 138 | BN_free(group->mont_one); |
139 | group->field_data2 = NULL; | 139 | group->mont_one = NULL; |
140 | ec_GFp_simple_group_finish(group); | 140 | ec_GFp_simple_group_finish(group); |
141 | } | 141 | } |
142 | 142 | ||
@@ -144,10 +144,10 @@ ec_GFp_mont_group_finish(EC_GROUP *group) | |||
144 | void | 144 | void |
145 | ec_GFp_mont_group_clear_finish(EC_GROUP *group) | 145 | ec_GFp_mont_group_clear_finish(EC_GROUP *group) |
146 | { | 146 | { |
147 | BN_MONT_CTX_free(group->field_data1); | 147 | BN_MONT_CTX_free(group->mont_ctx); |
148 | group->field_data1 = NULL; | 148 | group->mont_ctx = NULL; |
149 | BN_clear_free(group->field_data2); | 149 | BN_clear_free(group->mont_one); |
150 | group->field_data2 = NULL; | 150 | group->mont_one = NULL; |
151 | ec_GFp_simple_group_clear_finish(group); | 151 | ec_GFp_simple_group_clear_finish(group); |
152 | } | 152 | } |
153 | 153 | ||
@@ -155,32 +155,32 @@ ec_GFp_mont_group_clear_finish(EC_GROUP *group) | |||
155 | int | 155 | int |
156 | ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) | 156 | ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) |
157 | { | 157 | { |
158 | BN_MONT_CTX_free(dest->field_data1); | 158 | BN_MONT_CTX_free(dest->mont_ctx); |
159 | dest->field_data1 = NULL; | 159 | dest->mont_ctx = NULL; |
160 | BN_clear_free(dest->field_data2); | 160 | BN_clear_free(dest->mont_one); |
161 | dest->field_data2 = NULL; | 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; |
165 | 165 | ||
166 | if (src->field_data1 != NULL) { | 166 | if (src->mont_ctx != NULL) { |
167 | dest->field_data1 = BN_MONT_CTX_new(); | 167 | dest->mont_ctx = BN_MONT_CTX_new(); |
168 | if (dest->field_data1 == NULL) | 168 | if (dest->mont_ctx == NULL) |
169 | return 0; | 169 | return 0; |
170 | if (!BN_MONT_CTX_copy(dest->field_data1, src->field_data1)) | 170 | if (!BN_MONT_CTX_copy(dest->mont_ctx, src->mont_ctx)) |
171 | goto err; | 171 | goto err; |
172 | } | 172 | } |
173 | if (src->field_data2 != NULL) { | 173 | if (src->mont_one != NULL) { |
174 | dest->field_data2 = BN_dup(src->field_data2); | 174 | dest->mont_one = BN_dup(src->mont_one); |
175 | if (dest->field_data2 == NULL) | 175 | if (dest->mont_one == NULL) |
176 | goto err; | 176 | goto err; |
177 | } | 177 | } |
178 | return 1; | 178 | return 1; |
179 | 179 | ||
180 | err: | 180 | err: |
181 | if (dest->field_data1 != NULL) { | 181 | if (dest->mont_ctx != NULL) { |
182 | BN_MONT_CTX_free(dest->field_data1); | 182 | BN_MONT_CTX_free(dest->mont_ctx); |
183 | dest->field_data1 = NULL; | 183 | dest->mont_ctx = NULL; |
184 | } | 184 | } |
185 | return 0; | 185 | return 0; |
186 | } | 186 | } |
@@ -195,10 +195,10 @@ 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->field_data1); | 198 | BN_MONT_CTX_free(group->mont_ctx); |
199 | group->field_data1 = NULL; | 199 | group->mont_ctx = NULL; |
200 | BN_free(group->field_data2); | 200 | BN_free(group->mont_one); |
201 | group->field_data2 = NULL; | 201 | group->mont_one = NULL; |
202 | if (ctx == NULL) { | 202 | if (ctx == NULL) { |
203 | ctx = new_ctx = BN_CTX_new(); | 203 | ctx = new_ctx = BN_CTX_new(); |
204 | if (ctx == NULL) | 204 | if (ctx == NULL) |
@@ -217,18 +217,18 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | |||
217 | if (!BN_to_montgomery(one, BN_value_one(), mont, ctx)) | 217 | if (!BN_to_montgomery(one, BN_value_one(), mont, ctx)) |
218 | goto err; | 218 | goto err; |
219 | 219 | ||
220 | group->field_data1 = mont; | 220 | group->mont_ctx = mont; |
221 | mont = NULL; | 221 | mont = NULL; |
222 | group->field_data2 = one; | 222 | group->mont_one = one; |
223 | one = NULL; | 223 | one = NULL; |
224 | 224 | ||
225 | ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); | 225 | ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); |
226 | 226 | ||
227 | if (!ret) { | 227 | if (!ret) { |
228 | BN_MONT_CTX_free(group->field_data1); | 228 | BN_MONT_CTX_free(group->mont_ctx); |
229 | group->field_data1 = NULL; | 229 | group->mont_ctx = NULL; |
230 | BN_free(group->field_data2); | 230 | BN_free(group->mont_one); |
231 | group->field_data2 = NULL; | 231 | group->mont_one = NULL; |
232 | } | 232 | } |
233 | err: | 233 | err: |
234 | BN_CTX_free(new_ctx); | 234 | BN_CTX_free(new_ctx); |
@@ -242,11 +242,11 @@ int | |||
242 | ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 242 | ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
243 | const BIGNUM *b, BN_CTX *ctx) | 243 | const BIGNUM *b, BN_CTX *ctx) |
244 | { | 244 | { |
245 | if (group->field_data1 == NULL) { | 245 | if (group->mont_ctx == NULL) { |
246 | ECerror(EC_R_NOT_INITIALIZED); | 246 | ECerror(EC_R_NOT_INITIALIZED); |
247 | return 0; | 247 | return 0; |
248 | } | 248 | } |
249 | return BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx); | 249 | return BN_mod_mul_montgomery(r, a, b, group->mont_ctx, ctx); |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
@@ -254,11 +254,11 @@ int | |||
254 | ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 254 | ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
255 | BN_CTX *ctx) | 255 | BN_CTX *ctx) |
256 | { | 256 | { |
257 | if (group->field_data1 == NULL) { | 257 | if (group->mont_ctx == NULL) { |
258 | ECerror(EC_R_NOT_INITIALIZED); | 258 | ECerror(EC_R_NOT_INITIALIZED); |
259 | return 0; | 259 | return 0; |
260 | } | 260 | } |
261 | return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx); | 261 | return BN_mod_mul_montgomery(r, a, a, group->mont_ctx, ctx); |
262 | } | 262 | } |
263 | 263 | ||
264 | 264 | ||
@@ -266,11 +266,11 @@ int | |||
266 | ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 266 | ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
267 | BN_CTX *ctx) | 267 | BN_CTX *ctx) |
268 | { | 268 | { |
269 | if (group->field_data1 == NULL) { | 269 | if (group->mont_ctx == NULL) { |
270 | ECerror(EC_R_NOT_INITIALIZED); | 270 | ECerror(EC_R_NOT_INITIALIZED); |
271 | return 0; | 271 | return 0; |
272 | } | 272 | } |
273 | return BN_to_montgomery(r, a, (BN_MONT_CTX *) group->field_data1, ctx); | 273 | return BN_to_montgomery(r, a, group->mont_ctx, ctx); |
274 | } | 274 | } |
275 | 275 | ||
276 | 276 | ||
@@ -278,22 +278,22 @@ int | |||
278 | ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 278 | ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
279 | BN_CTX *ctx) | 279 | BN_CTX *ctx) |
280 | { | 280 | { |
281 | if (group->field_data1 == NULL) { | 281 | if (group->mont_ctx == NULL) { |
282 | ECerror(EC_R_NOT_INITIALIZED); | 282 | ECerror(EC_R_NOT_INITIALIZED); |
283 | return 0; | 283 | return 0; |
284 | } | 284 | } |
285 | return BN_from_montgomery(r, a, group->field_data1, ctx); | 285 | return BN_from_montgomery(r, a, group->mont_ctx, ctx); |
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | int | 289 | int |
290 | ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx) | 290 | ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx) |
291 | { | 291 | { |
292 | if (group->field_data2 == NULL) { | 292 | if (group->mont_one == NULL) { |
293 | ECerror(EC_R_NOT_INITIALIZED); | 293 | ECerror(EC_R_NOT_INITIALIZED); |
294 | return 0; | 294 | return 0; |
295 | } | 295 | } |
296 | if (!BN_copy(r, group->field_data2)) | 296 | if (!BN_copy(r, group->mont_one)) |
297 | return 0; | 297 | return 0; |
298 | return 1; | 298 | return 1; |
299 | } | 299 | } |