summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-10-22 21:28:53 +0000
committertb <>2024-10-22 21:28:53 +0000
commite08beb53210eac71f0a2eb01bc51b7dec27338c5 (patch)
treefa77dad5feeef42fb96ae230aafe002e5d185b04 /src
parent2ecb80a0db01a12008dcf47db9a6f3f5862966ec (diff)
downloadopenbsd-e08beb53210eac71f0a2eb01bc51b7dec27338c5.tar.gz
openbsd-e08beb53210eac71f0a2eb01bc51b7dec27338c5.tar.bz2
openbsd-e08beb53210eac71f0a2eb01bc51b7dec27338c5.zip
Move a check for hybrid point encoding into a helper function
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/ec/ecp_oct.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/lib/libcrypto/ec/ecp_oct.c b/src/lib/libcrypto/ec/ecp_oct.c
index 0a66a5cd48..d4ef0406f5 100644
--- a/src/lib/libcrypto/ec/ecp_oct.c
+++ b/src/lib/libcrypto/ec/ecp_oct.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_oct.c,v 1.25 2024/10/22 21:10:45 tb Exp $ */ 1/* $OpenBSD: ecp_oct.c,v 1.26 2024/10/22 21:28:53 tb Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -209,6 +209,17 @@ ec_oct_conversion_form_is_valid(uint8_t form)
209 return (form & EC_OCT_POINT_CONVERSION_MASK) == form; 209 return (form & EC_OCT_POINT_CONVERSION_MASK) == form;
210} 210}
211 211
212static int
213ec_oct_check_hybrid_ybit_is_consistent(uint8_t form, int ybit, const BIGNUM *y)
214{
215 if (form == EC_OCT_POINT_HYBRID && ybit != BN_is_odd(y)) {
216 ECerror(EC_R_INVALID_ENCODING);
217 return 0;
218 }
219
220 return 1;
221}
222
212/* Nonzero y-bit only makes sense with compressed or hybrid encoding. */ 223/* Nonzero y-bit only makes sense with compressed or hybrid encoding. */
213static int 224static int
214ec_oct_nonzero_ybit_allowed(uint8_t form) 225ec_oct_nonzero_ybit_allowed(uint8_t form)
@@ -437,12 +448,8 @@ ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
437 goto err; 448 goto err;
438 if (!ec_oct_get_field_element_cbs(&cbs, group, y)) 449 if (!ec_oct_get_field_element_cbs(&cbs, group, y))
439 goto err; 450 goto err;
440 if (form == EC_OCT_POINT_HYBRID) { 451 if (!ec_oct_check_hybrid_ybit_is_consistent(form, ybit, y))
441 if (ybit != BN_is_odd(y)) { 452 goto err;
442 ECerror(EC_R_INVALID_ENCODING);
443 goto err;
444 }
445 }
446 if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx)) 453 if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
447 goto err; 454 goto err;
448 } 455 }