diff options
author | tb <> | 2024-10-30 17:52:34 +0000 |
---|---|---|
committer | tb <> | 2024-10-30 17:52:34 +0000 |
commit | a24cd1519c6c51d5dd35264f69a238ace16fc410 (patch) | |
tree | 0951e63bad39a0eca5909a775384435b33a4e47d | |
parent | 3e6214259165b7da17edee3f76bb95cfafe0c5a4 (diff) | |
download | openbsd-a24cd1519c6c51d5dd35264f69a238ace16fc410.tar.gz openbsd-a24cd1519c6c51d5dd35264f69a238ace16fc410.tar.bz2 openbsd-a24cd1519c6c51d5dd35264f69a238ace16fc410.zip |
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
-rw-r--r-- | src/lib/libcrypto/ec/ec_local.h | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_oct.c | 32 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index 7aa1c3f64e..148e94b766 100644 --- a/src/lib/libcrypto/ec/ec_local.h +++ b/src/lib/libcrypto/ec/ec_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_local.h,v 1.33 2024/10/30 06:10:35 tb Exp $ */ | 1 | /* $OpenBSD: ec_local.h,v 1.34 2024/10/30 17:52:34 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 | */ |
@@ -360,8 +360,10 @@ int ec_group_is_builtin_curve(const EC_GROUP *group); | |||
360 | int ec_group_get_field_type(const EC_GROUP *group); | 360 | int ec_group_get_field_type(const EC_GROUP *group); |
361 | 361 | ||
362 | /* | 362 | /* |
363 | * Wrapper around the unergonomic EC_POINT_point2oct(). | 363 | * Wrappers around the unergonomic EC_POINT_{oct2point,point2oct}(). |
364 | */ | 364 | */ |
365 | int ec_point_from_octets(const EC_GROUP *group, const unsigned char *buf, | ||
366 | size_t buf_len, EC_POINT **out_point, uint8_t *out_form, BN_CTX *ctx_in); | ||
365 | int ec_point_to_octets(const EC_GROUP *group, const EC_POINT *point, int form, | 367 | int ec_point_to_octets(const EC_GROUP *group, const EC_POINT *point, int form, |
366 | unsigned char **out_buf, size_t *len, BN_CTX *ctx_in); | 368 | unsigned char **out_buf, size_t *len, BN_CTX *ctx_in); |
367 | 369 | ||
diff --git a/src/lib/libcrypto/ec/ec_oct.c b/src/lib/libcrypto/ec/ec_oct.c index 6fcda17403..3277bf4dd5 100644 --- a/src/lib/libcrypto/ec/ec_oct.c +++ b/src/lib/libcrypto/ec/ec_oct.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_oct.c,v 1.18 2024/10/30 06:10:35 tb Exp $ */ | 1 | /* $OpenBSD: ec_oct.c,v 1.19 2024/10/30 17:52:34 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 | */ |
@@ -149,6 +149,36 @@ ec_point_to_octets(const EC_GROUP *group, const EC_POINT *point, int form, | |||
149 | return ret; | 149 | return ret; |
150 | } | 150 | } |
151 | 151 | ||
152 | int | ||
153 | ec_point_from_octets(const EC_GROUP *group, const unsigned char *buf, size_t buf_len, | ||
154 | EC_POINT **out_point, uint8_t *out_form, BN_CTX *ctx) | ||
155 | { | ||
156 | EC_POINT *point; | ||
157 | int ret = 0; | ||
158 | |||
159 | if ((point = *out_point) == NULL) | ||
160 | point = EC_POINT_new(group); | ||
161 | if (point == NULL) | ||
162 | goto err; | ||
163 | |||
164 | if (!EC_POINT_oct2point(group, point, buf, buf_len, ctx)) | ||
165 | goto err; | ||
166 | |||
167 | if (out_form != NULL) | ||
168 | *out_form = buf[0] & ~1U; /* XXX - EC_OCT_YBIT */ | ||
169 | |||
170 | *out_point = point; | ||
171 | point = NULL; | ||
172 | |||
173 | ret = 1; | ||
174 | |||
175 | err: | ||
176 | if (*out_point != point) | ||
177 | EC_POINT_free(point); | ||
178 | |||
179 | return ret; | ||
180 | } | ||
181 | |||
152 | size_t | 182 | size_t |
153 | EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, | 183 | EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, |
154 | point_conversion_form_t form, unsigned char *buf, size_t len, | 184 | point_conversion_form_t form, unsigned char *buf, size_t len, |