summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec_oct.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ec_oct.c')
-rw-r--r--src/lib/libcrypto/ec/ec_oct.c42
1 files changed, 41 insertions, 1 deletions
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
73int 75int
@@ -109,6 +111,44 @@ EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
109} 111}
110LCRYPTO_ALIAS(EC_POINT_set_compressed_coordinates_GFp); 112LCRYPTO_ALIAS(EC_POINT_set_compressed_coordinates_GFp);
111 113
114int
115ec_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
112size_t 152size_t
113EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, 153EC_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,