diff options
author | tb <> | 2024-11-06 09:10:55 +0000 |
---|---|---|
committer | tb <> | 2024-11-06 09:10:55 +0000 |
commit | 44fecf844216dcfcdd6c992dab1bb1842114b795 (patch) | |
tree | 4398c3c3220f5a8a97630560d202f2eab8d3704c /src/lib | |
parent | 89ed341527c32f26bc41fe456d57031ba8887e57 (diff) | |
download | openbsd-44fecf844216dcfcdd6c992dab1bb1842114b795.tar.gz openbsd-44fecf844216dcfcdd6c992dab1bb1842114b795.tar.bz2 openbsd-44fecf844216dcfcdd6c992dab1bb1842114b795.zip |
Clean up EC_GROUP_copy()
Switch from artistic free reinterpretations of public API in the same file
to calling the real thing if possible.
This means that we need to copy the group's coefficients first instead of
last, so that we can call EC_GROUP_set_generator() to set - yes - all three
of generator, order, and cofactor of the group.
However, we may not have a generator yet since for some reason it is an
optional field and some code relies on that. In that case simply copy over
order and cofactor and punt on sanity checking for now (since this API
never did that anyway).
Finally set the seed using EC_GROUP_set_seed() instead of using a custom
reimplementation.
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index c02f054cdc..b136753be9 100644 --- a/src/lib/libcrypto/ec/ec_lib.c +++ b/src/lib/libcrypto/ec/ec_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_lib.c,v 1.80 2024/11/06 08:59:32 tb Exp $ */ | 1 | /* $OpenBSD: ec_lib.c,v 1.81 2024/11/06 09:10:55 tb 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 | */ |
@@ -154,41 +154,29 @@ EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src) | |||
154 | if (dest == src) | 154 | if (dest == src) |
155 | return 1; | 155 | return 1; |
156 | 156 | ||
157 | if (!dest->meth->group_copy(dest, src)) | ||
158 | return 0; | ||
159 | |||
160 | EC_POINT_free(dest->generator); | ||
161 | dest->generator = NULL; | ||
157 | if (src->generator != NULL) { | 162 | if (src->generator != NULL) { |
158 | if (dest->generator == NULL) { | 163 | if (!EC_GROUP_set_generator(dest, src->generator, &src->order, |
159 | dest->generator = EC_POINT_new(dest); | 164 | &src->cofactor)) |
160 | if (dest->generator == NULL) | ||
161 | return 0; | ||
162 | } | ||
163 | if (!EC_POINT_copy(dest->generator, src->generator)) | ||
164 | return 0; | 165 | return 0; |
165 | } else { | 166 | } else { |
166 | /* src->generator == NULL */ | 167 | /* XXX - should do the sanity checks as in set_generator() */ |
167 | EC_POINT_free(dest->generator); | 168 | if (!bn_copy(&dest->order, &src->order)) |
168 | dest->generator = NULL; | 169 | return 0; |
170 | if (!bn_copy(&dest->cofactor, &src->cofactor)) | ||
171 | return 0; | ||
169 | } | 172 | } |
170 | 173 | ||
171 | if (!bn_copy(&dest->order, &src->order)) | ||
172 | return 0; | ||
173 | if (!bn_copy(&dest->cofactor, &src->cofactor)) | ||
174 | return 0; | ||
175 | |||
176 | dest->curve_name = src->curve_name; | 174 | dest->curve_name = src->curve_name; |
177 | dest->asn1_flag = src->asn1_flag; | 175 | dest->asn1_flag = src->asn1_flag; |
178 | dest->asn1_form = src->asn1_form; | 176 | dest->asn1_form = src->asn1_form; |
179 | 177 | ||
180 | if (src->seed) { | 178 | if (!EC_GROUP_set_seed(dest, src->seed, src->seed_len)) |
181 | free(dest->seed); | 179 | return 0; |
182 | dest->seed = malloc(src->seed_len); | ||
183 | if (dest->seed == NULL) | ||
184 | return 0; | ||
185 | memcpy(dest->seed, src->seed, src->seed_len); | ||
186 | dest->seed_len = src->seed_len; | ||
187 | } else { | ||
188 | free(dest->seed); | ||
189 | dest->seed = NULL; | ||
190 | dest->seed_len = 0; | ||
191 | } | ||
192 | 180 | ||
193 | return dest->meth->group_copy(dest, src); | 181 | return dest->meth->group_copy(dest, src); |
194 | } | 182 | } |