diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-10-22 21:28:54 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-10-22 21:28:54 +0000 |
commit | ce661a32cb4dab2aefb0782466d643d24b44d829 (patch) | |
tree | 3123a7a3f1e08e4790bea639196a38b4c8de3335 /lib/libcrypto | |
parent | d7f37b7b536b5abf1cef4f58aacd0860dec6971a (diff) |
Move a check for hybrid point encoding into a helper function
Diffstat (limited to 'lib/libcrypto')
-rw-r--r-- | lib/libcrypto/ec/ecp_oct.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/libcrypto/ec/ecp_oct.c b/lib/libcrypto/ec/ecp_oct.c index 0a66a5cd48a..d4ef0406f58 100644 --- a/lib/libcrypto/ec/ecp_oct.c +++ b/lib/libcrypto/ec/ecp_oct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_oct.c,v 1.25 2024/10/22 21:10:45 tb Exp $ */ +/* $OpenBSD: ecp_oct.c,v 1.26 2024/10/22 21:28:53 tb Exp $ */ /* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> * for the OpenSSL project. * Includes code written by Bodo Moeller for the OpenSSL project. @@ -209,6 +209,17 @@ ec_oct_conversion_form_is_valid(uint8_t form) return (form & EC_OCT_POINT_CONVERSION_MASK) == form; } +static int +ec_oct_check_hybrid_ybit_is_consistent(uint8_t form, int ybit, const BIGNUM *y) +{ + if (form == EC_OCT_POINT_HYBRID && ybit != BN_is_odd(y)) { + ECerror(EC_R_INVALID_ENCODING); + return 0; + } + + return 1; +} + /* Nonzero y-bit only makes sense with compressed or hybrid encoding. */ static int ec_oct_nonzero_ybit_allowed(uint8_t form) @@ -437,12 +448,8 @@ ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point, goto err; if (!ec_oct_get_field_element_cbs(&cbs, group, y)) goto err; - if (form == EC_OCT_POINT_HYBRID) { - if (ybit != BN_is_odd(y)) { - ECerror(EC_R_INVALID_ENCODING); - goto err; - } - } + if (!ec_oct_check_hybrid_ybit_is_consistent(form, ybit, y)) + goto err; if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx)) goto err; } |