summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-10-23 13:42:51 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-10-23 13:42:51 +0000
commiteaeb21bc0bae2801372055f86fda77350c546c6d (patch)
tree074522756caa2d235fae04248e91732a12aa6372
parent44c1448d0e6a9d2acab0dba0d15944178ea22d39 (diff)
EC_POINT_point2oct() need to special case the point at infinity
This is annoying since it undoes some polishing done before commit and reintroduces an unpleasant asymmetry. found by anton via openssl-ruby tests ok jsing
-rw-r--r--lib/libcrypto/ec/ecp_oct.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libcrypto/ec/ecp_oct.c b/lib/libcrypto/ec/ecp_oct.c
index d4ef0406f58..5444b5ec34b 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.26 2024/10/22 21:28:53 tb Exp $ */
+/* $OpenBSD: ecp_oct.c,v 1.27 2024/10/23 13:42:50 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.
@@ -377,6 +377,13 @@ ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
CBB_init_fixed(&cbb, buf, len);
BN_CTX_start(ctx);
+ if (form == EC_OCT_POINT_AT_INFINITY) {
+ if (!ec_oct_add_leading_octet_cbb(&cbb, form, 0))
+ goto err;
+
+ goto done;
+ }
+
if ((x = BN_CTX_get(ctx)) == NULL)
goto err;
if ((y = BN_CTX_get(ctx)) == NULL)
@@ -387,9 +394,7 @@ ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
if (!ec_oct_add_leading_octet_cbb(&cbb, form, BN_is_odd(y)))
goto err;
- if (form == EC_OCT_POINT_AT_INFINITY) {
- /* Encoded in leading octet. */;
- } else if (form == EC_OCT_POINT_COMPRESSED) {
+ if (form == EC_OCT_POINT_COMPRESSED) {
if (!ec_oct_add_field_element_cbb(&cbb, group, x))
goto err;
} else {
@@ -399,6 +404,7 @@ ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
goto err;
}
+ done:
if (!CBB_finish(&cbb, NULL, &ret))
goto err;