summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-10-30 17:52:35 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-10-30 17:52:35 +0000
commit80fd4de48768a880579de27fa067cd0ff38c21b6 (patch)
tree7a3bedb05f6573cb171736e3b5faa3cd32234473 /lib
parent11248f787c06db7df9d4b3dcf4819b16291f469b (diff)
Provide ec_point_from_octets()
This is a wrapper that is the reverse of ec_point_to_octets(). It is a bit simpler since EC_POINT_oct2point() expects the point to be allocated already. It also hands back the correctly parsed point conversion form so that we don't have to do this by hand in a few places. ok jsing
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/ec/ec_local.h6
-rw-r--r--lib/libcrypto/ec/ec_oct.c32
2 files changed, 35 insertions, 3 deletions
diff --git a/lib/libcrypto/ec/ec_local.h b/lib/libcrypto/ec/ec_local.h
index 7aa1c3f64ea..148e94b7668 100644
--- a/lib/libcrypto/ec/ec_local.h
+++ b/lib/libcrypto/ec/ec_local.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec_local.h,v 1.33 2024/10/30 06:10:35 tb Exp $ */
+/* $OpenBSD: ec_local.h,v 1.34 2024/10/30 17:52:34 tb Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
@@ -360,8 +360,10 @@ int ec_group_is_builtin_curve(const EC_GROUP *group);
int ec_group_get_field_type(const EC_GROUP *group);
/*
- * Wrapper around the unergonomic EC_POINT_point2oct().
+ * Wrappers around the unergonomic EC_POINT_{oct2point,point2oct}().
*/
+int ec_point_from_octets(const EC_GROUP *group, const unsigned char *buf,
+ size_t buf_len, EC_POINT **out_point, uint8_t *out_form, BN_CTX *ctx_in);
int ec_point_to_octets(const EC_GROUP *group, const EC_POINT *point, int form,
unsigned char **out_buf, size_t *len, BN_CTX *ctx_in);
diff --git a/lib/libcrypto/ec/ec_oct.c b/lib/libcrypto/ec/ec_oct.c
index 6fcda174033..3277bf4dd51 100644
--- a/lib/libcrypto/ec/ec_oct.c
+++ b/lib/libcrypto/ec/ec_oct.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec_oct.c,v 1.18 2024/10/30 06:10:35 tb Exp $ */
+/* $OpenBSD: ec_oct.c,v 1.19 2024/10/30 17:52:34 tb Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
@@ -149,6 +149,36 @@ ec_point_to_octets(const EC_GROUP *group, const EC_POINT *point, int form,
return ret;
}
+int
+ec_point_from_octets(const EC_GROUP *group, const unsigned char *buf, size_t buf_len,
+ EC_POINT **out_point, uint8_t *out_form, BN_CTX *ctx)
+{
+ EC_POINT *point;
+ int ret = 0;
+
+ if ((point = *out_point) == NULL)
+ point = EC_POINT_new(group);
+ if (point == NULL)
+ goto err;
+
+ if (!EC_POINT_oct2point(group, point, buf, buf_len, ctx))
+ goto err;
+
+ if (out_form != NULL)
+ *out_form = buf[0] & ~1U; /* XXX - EC_OCT_YBIT */
+
+ *out_point = point;
+ point = NULL;
+
+ ret = 1;
+
+ err:
+ if (*out_point != point)
+ EC_POINT_free(point);
+
+ return ret;
+}
+
size_t
EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point,
point_conversion_form_t form, unsigned char *buf, size_t len,