diff options
| author | tb <> | 2025-01-05 16:07:08 +0000 |
|---|---|---|
| committer | tb <> | 2025-01-05 16:07:08 +0000 |
| commit | 26c9248a10bd0d95f47397e21bc2f056e53e19c8 (patch) | |
| tree | 01052cd554006bd8d0b366164df08e22b7dd6d57 /src/lib/libcrypto/ec/ec_convert.c | |
| parent | 7d80fee84377d3dd9365558712de411fc7f8356b (diff) | |
| download | openbsd-26c9248a10bd0d95f47397e21bc2f056e53e19c8.tar.gz openbsd-26c9248a10bd0d95f47397e21bc2f056e53e19c8.tar.bz2 openbsd-26c9248a10bd0d95f47397e21bc2f056e53e19c8.zip | |
Move BIGNUMs in EC_GROUP and EC_POINT to the heap
The only way to get an EC_GROUP or an EC_POINT is by calling the relevant
_new() function and to get rid of it, something must call _free(). Thus we
can establish the invariant that every group has Weierstrass coefficients
p, a, b as well as order and cofactor hanging off it. Similarly, Every
point has allocated BIGNUMs for its Jacobian projective coordinates.
Unfortunately, a group has the generator as an optional component in
addition to seed and montgomery context/one (where optionality makes
more sense).
This is a mostly mechanical diff and only drops a few silly comments and
a couple of unnecessary NULL checks since in our part of the wrold the
word invariant has a meaning.
This should also appease Coverity who likes to throw fits at calling
BN_free() for BIGNUM on the stack (yes, this is actually a thing).
ok jsing
Diffstat (limited to 'src/lib/libcrypto/ec/ec_convert.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_convert.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/libcrypto/ec/ec_convert.c b/src/lib/libcrypto/ec/ec_convert.c index b48fc85315..a18bc49132 100644 --- a/src/lib/libcrypto/ec/ec_convert.c +++ b/src/lib/libcrypto/ec/ec_convert.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ec_convert.c,v 1.13 2024/12/16 06:11:26 tb Exp $ */ | 1 | /* $OpenBSD: ec_convert.c,v 1.14 2025/01/05 16:07:08 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 | */ |
| @@ -157,11 +157,11 @@ ec_encoded_length(const EC_GROUP *group, uint8_t form, size_t *out_len) | |||
| 157 | *out_len = 1; | 157 | *out_len = 1; |
| 158 | return 1; | 158 | return 1; |
| 159 | case EC_POINT_COMPRESSED: | 159 | case EC_POINT_COMPRESSED: |
| 160 | *out_len = 1 + BN_num_bytes(&group->p); | 160 | *out_len = 1 + BN_num_bytes(group->p); |
| 161 | return 1; | 161 | return 1; |
| 162 | case EC_POINT_UNCOMPRESSED: | 162 | case EC_POINT_UNCOMPRESSED: |
| 163 | case EC_POINT_HYBRID: | 163 | case EC_POINT_HYBRID: |
| 164 | *out_len = 1 + 2 * BN_num_bytes(&group->p); | 164 | *out_len = 1 + 2 * BN_num_bytes(group->p); |
| 165 | return 1; | 165 | return 1; |
| 166 | default: | 166 | default: |
| 167 | return 0; | 167 | return 0; |
| @@ -172,14 +172,14 @@ static int | |||
| 172 | ec_field_element_is_valid(const EC_GROUP *group, const BIGNUM *bn) | 172 | ec_field_element_is_valid(const EC_GROUP *group, const BIGNUM *bn) |
| 173 | { | 173 | { |
| 174 | /* Ensure bn is in the range [0, p). */ | 174 | /* Ensure bn is in the range [0, p). */ |
| 175 | return !BN_is_negative(bn) && BN_cmp(&group->p, bn) > 0; | 175 | return !BN_is_negative(bn) && BN_cmp(group->p, bn) > 0; |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | static int | 178 | static int |
| 179 | ec_add_field_element_cbb(CBB *cbb, const EC_GROUP *group, const BIGNUM *bn) | 179 | ec_add_field_element_cbb(CBB *cbb, const EC_GROUP *group, const BIGNUM *bn) |
| 180 | { | 180 | { |
| 181 | uint8_t *buf = NULL; | 181 | uint8_t *buf = NULL; |
| 182 | int buf_len = BN_num_bytes(&group->p); | 182 | int buf_len = BN_num_bytes(group->p); |
| 183 | 183 | ||
| 184 | if (!ec_field_element_is_valid(group, bn)) { | 184 | if (!ec_field_element_is_valid(group, bn)) { |
| 185 | ECerror(EC_R_BIGNUM_OUT_OF_RANGE); | 185 | ECerror(EC_R_BIGNUM_OUT_OF_RANGE); |
| @@ -202,7 +202,7 @@ ec_get_field_element_cbs(CBS *cbs, const EC_GROUP *group, BIGNUM *bn) | |||
| 202 | { | 202 | { |
| 203 | CBS field_element; | 203 | CBS field_element; |
| 204 | 204 | ||
| 205 | if (!CBS_get_bytes(cbs, &field_element, BN_num_bytes(&group->p))) { | 205 | if (!CBS_get_bytes(cbs, &field_element, BN_num_bytes(group->p))) { |
| 206 | ECerror(EC_R_INVALID_ENCODING); | 206 | ECerror(EC_R_INVALID_ENCODING); |
| 207 | return 0; | 207 | return 0; |
| 208 | } | 208 | } |
