diff options
| author | jsing <> | 2023-03-07 05:28:12 +0000 |
|---|---|---|
| committer | jsing <> | 2023-03-07 05:28:12 +0000 |
| commit | 9971ad6c7eaf40fdc6e2c5371dafa15d961ef6bd (patch) | |
| tree | 43744c1b5fc50fa422d73462de95d3ddf0c7d133 | |
| parent | 367fe9bf8b8826a416c722d7dc48bcc2a7ba0e5a (diff) | |
| download | openbsd-9971ad6c7eaf40fdc6e2c5371dafa15d961ef6bd.tar.gz openbsd-9971ad6c7eaf40fdc6e2c5371dafa15d961ef6bd.tar.bz2 openbsd-9971ad6c7eaf40fdc6e2c5371dafa15d961ef6bd.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@
| -rw-r--r-- | src/lib/libcrypto/ec/ecp_mont.c | 41 |
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 | ||
| 68 | static void | ||
| 69 | ec_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 | ||
| 69 | const EC_METHOD * | 78 | const EC_METHOD * |
| 70 | EC_GFp_mont_method(void) | 79 | EC_GFp_mont_method(void) |
| @@ -133,10 +142,7 @@ ec_GFp_mont_group_init(EC_GROUP *group) | |||
| 133 | void | 142 | void |
| 134 | ec_GFp_mont_group_finish(EC_GROUP *group) | 143 | ec_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) | |||
| 144 | void | 150 | void |
| 145 | ec_GFp_mont_group_clear_finish(EC_GROUP *group) | 151 | ec_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) | |||
| 155 | int | 158 | int |
| 156 | ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) | 159 | ec_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); |
