2 * Copyright 2002-2024 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <string.h> /* strlen */
11 #include <openssl/crypto.h>
12 #include "internal/cryptlib.h"
15 /* the return value must be freed (using OPENSSL_free()) */
16 char *EC_POINT_point2hex(const EC_GROUP
*group
,
17 const EC_POINT
*point
,
18 point_conversion_form_t form
, BN_CTX
*ctx
)
22 unsigned char *buf
= NULL
;
24 buf_len
= EC_POINT_point2buf(group
, point
, form
, &buf
, ctx
);
29 ret
= OPENSSL_malloc(buf_len
* 2 + 2);
34 for (i
= 0; i
< buf_len
; ++i
)
35 p
+= ossl_to_hex(p
, buf
[i
]);
43 EC_POINT
*EC_POINT_hex2point(const EC_GROUP
*group
,
44 const char *hex
, EC_POINT
*point
, BN_CTX
*ctx
)
47 unsigned char *oct_buf
= NULL
;
48 size_t len
, oct_buf_len
= 0;
51 if (group
== NULL
|| hex
== NULL
)
55 pt
= EC_POINT_new(group
);
62 len
= strlen(hex
) / 2;
63 oct_buf
= OPENSSL_malloc(len
);
67 if (!OPENSSL_hexstr2buf_ex(oct_buf
, len
, &oct_buf_len
, hex
, '\0')
68 || !EC_POINT_oct2point(group
, pt
, oct_buf
, oct_buf_len
, ctx
))
72 OPENSSL_clear_free(oct_buf
, oct_buf_len
);
75 EC_POINT_clear_free(pt
);