diff options
author | tb <> | 2024-10-30 06:10:35 +0000 |
---|---|---|
committer | tb <> | 2024-10-30 06:10:35 +0000 |
commit | c200e5f13afe3d84e11b9e70000121dafc8040d6 (patch) | |
tree | dfc67ef0691385235bc90ed6c5e22dbec04ba68e /src/lib | |
parent | 16ff4ccc2611ac3387e5353ab9ca88ecb4a47734 (diff) | |
download | openbsd-c200e5f13afe3d84e11b9e70000121dafc8040d6.tar.gz openbsd-c200e5f13afe3d84e11b9e70000121dafc8040d6.tar.bz2 openbsd-c200e5f13afe3d84e11b9e70000121dafc8040d6.zip |
Add a convenience wrapper for EC_POINT_point2oct()
EC_POING_point2oct() is annoying to use since its invocation involves
two calls: one to determine the space to allocate and one to pass the
buffer and perform the actual conversion. Wrap this dance in a helper
with the correct signature.
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ec/ec_local.h | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_oct.c | 42 |
2 files changed, 48 insertions, 2 deletions
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index 1a49067cd8..7aa1c3f64e 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.32 2024/10/28 18:01:26 tb Exp $ */ | 1 | /* $OpenBSD: ec_local.h,v 1.33 2024/10/30 06:10:35 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 | */ |
@@ -359,6 +359,12 @@ int EC_POINT_get_Jprojective_coordinates(const EC_GROUP *group, | |||
359 | int ec_group_is_builtin_curve(const EC_GROUP *group); | 359 | 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 | /* | ||
363 | * Wrapper around the unergonomic EC_POINT_point2oct(). | ||
364 | */ | ||
365 | 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); | ||
367 | |||
362 | /* Public API in OpenSSL */ | 368 | /* Public API in OpenSSL */ |
363 | const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group); | 369 | const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group); |
364 | const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group); | 370 | const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group); |
diff --git a/src/lib/libcrypto/ec/ec_oct.c b/src/lib/libcrypto/ec/ec_oct.c index 8249866502..6fcda17403 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.17 2024/04/10 15:01:31 beck Exp $ */ | 1 | /* $OpenBSD: ec_oct.c,v 1.18 2024/10/30 06:10:35 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 | */ |
@@ -65,9 +65,11 @@ | |||
65 | 65 | ||
66 | #include <openssl/opensslconf.h> | 66 | #include <openssl/opensslconf.h> |
67 | 67 | ||
68 | #include <openssl/asn1.h> | ||
68 | #include <openssl/err.h> | 69 | #include <openssl/err.h> |
69 | #include <openssl/opensslv.h> | 70 | #include <openssl/opensslv.h> |
70 | 71 | ||
72 | #include "asn1_local.h" | ||
71 | #include "ec_local.h" | 73 | #include "ec_local.h" |
72 | 74 | ||
73 | int | 75 | int |
@@ -109,6 +111,44 @@ EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point, | |||
109 | } | 111 | } |
110 | LCRYPTO_ALIAS(EC_POINT_set_compressed_coordinates_GFp); | 112 | LCRYPTO_ALIAS(EC_POINT_set_compressed_coordinates_GFp); |
111 | 113 | ||
114 | int | ||
115 | ec_point_to_octets(const EC_GROUP *group, const EC_POINT *point, int form, | ||
116 | unsigned char **out_buf, size_t *out_len, BN_CTX *ctx) | ||
117 | { | ||
118 | unsigned char *buf = NULL; | ||
119 | size_t len = 0; | ||
120 | int ret = 0; | ||
121 | |||
122 | if (out_buf != NULL && *out_buf != NULL) | ||
123 | goto err; | ||
124 | |||
125 | *out_len = 0; | ||
126 | |||
127 | if ((len = EC_POINT_point2oct(group, point, form, NULL, 0, ctx)) == 0) | ||
128 | goto err; | ||
129 | |||
130 | if (out_buf == NULL) | ||
131 | goto done; | ||
132 | |||
133 | if ((buf = calloc(1, len)) == NULL) | ||
134 | goto err; | ||
135 | if (EC_POINT_point2oct(group, point, form, buf, len, ctx) != len) | ||
136 | goto err; | ||
137 | |||
138 | *out_buf = buf; | ||
139 | buf = NULL; | ||
140 | |||
141 | done: | ||
142 | *out_len = len; | ||
143 | |||
144 | ret = 1; | ||
145 | |||
146 | err: | ||
147 | freezero(buf, len); | ||
148 | |||
149 | return ret; | ||
150 | } | ||
151 | |||
112 | size_t | 152 | size_t |
113 | EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, | 153 | EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, |
114 | point_conversion_form_t form, unsigned char *buf, size_t len, | 154 | point_conversion_form_t form, unsigned char *buf, size_t len, |