summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2024-10-30 18:21:12 +0000
committertb <>2024-10-30 18:21:12 +0000
commit7ec6e26ec26d9376a7e9b83eb15bacb60edf279e (patch)
treeb3aa42d47adfb87ed3a6543cdb53ae9f8d73cc14
parent49068deeca118969162ea5680e55dfd6aa3d1f00 (diff)
downloadopenbsd-7ec6e26ec26d9376a7e9b83eb15bacb60edf279e.tar.gz
openbsd-7ec6e26ec26d9376a7e9b83eb15bacb60edf279e.tar.bz2
openbsd-7ec6e26ec26d9376a7e9b83eb15bacb60edf279e.zip
Move the point2bn and point2hex API to ec_convert.c
discussed with jsing
-rw-r--r--src/lib/libcrypto/Makefile3
-rw-r--r--src/lib/libcrypto/ec/ec_convert.c84
-rw-r--r--src/lib/libcrypto/ec/ec_print.c143
3 files changed, 84 insertions, 146 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile
index 652d74ee92..e5e757ff39 100644
--- a/src/lib/libcrypto/Makefile
+++ b/src/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.215 2024/10/30 18:14:49 tb Exp $ 1# $OpenBSD: Makefile,v 1.216 2024/10/30 18:21:12 tb Exp $
2 2
3LIB= crypto 3LIB= crypto
4LIBREBUILD=y 4LIBREBUILD=y
@@ -290,7 +290,6 @@ SRCS+= ec_lib.c
290SRCS+= ec_mult.c 290SRCS+= ec_mult.c
291SRCS+= ec_oct.c 291SRCS+= ec_oct.c
292SRCS+= ec_pmeth.c 292SRCS+= ec_pmeth.c
293SRCS+= ec_print.c
294SRCS+= eck_prn.c 293SRCS+= eck_prn.c
295SRCS+= ecp_mont.c 294SRCS+= ecp_mont.c
296SRCS+= ecp_oct.c 295SRCS+= ecp_oct.c
diff --git a/src/lib/libcrypto/ec/ec_convert.c b/src/lib/libcrypto/ec/ec_convert.c
index f6ee1f9702..e8f8605c10 100644
--- a/src/lib/libcrypto/ec/ec_convert.c
+++ b/src/lib/libcrypto/ec/ec_convert.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_convert.c,v 1.3 2024/10/30 18:18:35 tb Exp $ */ 1/* $OpenBSD: ec_convert.c,v 1.4 2024/10/30 18:21:12 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 */
@@ -491,3 +491,85 @@ EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
491 return ret; 491 return ret;
492} 492}
493LCRYPTO_ALIAS(EC_POINT_oct2point); 493LCRYPTO_ALIAS(EC_POINT_oct2point);
494
495BIGNUM *
496EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *point,
497 point_conversion_form_t form, BIGNUM *in_bn, BN_CTX *ctx)
498{
499 BIGNUM *bn = NULL;
500 unsigned char *buf = NULL;
501 size_t buf_len = 0;
502
503 if (!ec_point_to_octets(group, point, form, &buf, &buf_len, ctx))
504 goto err;
505 if ((bn = BN_bin2bn(buf, buf_len, in_bn)) == NULL)
506 goto err;
507
508 err:
509 freezero(buf, buf_len);
510
511 return bn;
512}
513LCRYPTO_ALIAS(EC_POINT_point2bn);
514
515EC_POINT *
516EC_POINT_bn2point(const EC_GROUP *group,
517 const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx)
518{
519 unsigned char *buf = NULL;
520 size_t buf_len = 0;
521
522 /* Of course BN_bn2bin() is in no way symmetric to BN_bin2bn()... */
523 if ((buf_len = BN_num_bytes(bn)) == 0)
524 goto err;
525 if ((buf = calloc(1, buf_len)) == NULL)
526 goto err;
527 if (!BN_bn2bin(bn, buf))
528 goto err;
529 if (!ec_point_from_octets(group, buf, buf_len, &point, NULL, ctx))
530 goto err;
531
532 err:
533 freezero(buf, buf_len);
534
535 return point;
536}
537LCRYPTO_ALIAS(EC_POINT_bn2point);
538
539char *
540EC_POINT_point2hex(const EC_GROUP *group, const EC_POINT *point,
541 point_conversion_form_t form, BN_CTX *ctx)
542{
543 BIGNUM *bn;
544 char *hex = NULL;
545
546 if ((bn = EC_POINT_point2bn(group, point, form, NULL, ctx)) == NULL)
547 goto err;
548 if ((hex = BN_bn2hex(bn)) == NULL)
549 goto err;
550
551 err:
552 BN_free(bn);
553
554 return hex;
555}
556LCRYPTO_ALIAS(EC_POINT_point2hex);
557
558EC_POINT *
559EC_POINT_hex2point(const EC_GROUP *group, const char *hex,
560 EC_POINT *in_point, BN_CTX *ctx)
561{
562 EC_POINT *point = NULL;
563 BIGNUM *bn = NULL;
564
565 if (BN_hex2bn(&bn, hex) == 0)
566 goto err;
567 if ((point = EC_POINT_bn2point(group, bn, in_point, ctx)) == NULL)
568 goto err;
569
570 err:
571 BN_free(bn);
572
573 return point;
574}
575LCRYPTO_ALIAS(EC_POINT_hex2point);
diff --git a/src/lib/libcrypto/ec/ec_print.c b/src/lib/libcrypto/ec/ec_print.c
deleted file mode 100644
index 7a479a3ddc..0000000000
--- a/src/lib/libcrypto/ec/ec_print.c
+++ /dev/null
@@ -1,143 +0,0 @@
1/* $OpenBSD: ec_print.c,v 1.19 2024/10/30 18:01:52 tb Exp $ */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdlib.h>
57
58#include <openssl/bn.h>
59#include <openssl/ec.h>
60
61#include "ec_local.h"
62
63BIGNUM *
64EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *point,
65 point_conversion_form_t form, BIGNUM *in_bn, BN_CTX *ctx)
66{
67 BIGNUM *bn = NULL;
68 unsigned char *buf = NULL;
69 size_t buf_len = 0;
70
71 if (!ec_point_to_octets(group, point, form, &buf, &buf_len, ctx))
72 goto err;
73 if ((bn = BN_bin2bn(buf, buf_len, in_bn)) == NULL)
74 goto err;
75
76 err:
77 freezero(buf, buf_len);
78
79 return bn;
80}
81LCRYPTO_ALIAS(EC_POINT_point2bn);
82
83EC_POINT *
84EC_POINT_bn2point(const EC_GROUP *group,
85 const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx)
86{
87 unsigned char *buf = NULL;
88 size_t buf_len = 0;
89
90 /* Of course BN_bn2bin() is in no way symmetric to BN_bin2bn()... */
91 if ((buf_len = BN_num_bytes(bn)) == 0)
92 goto err;
93 if ((buf = calloc(1, buf_len)) == NULL)
94 goto err;
95 if (!BN_bn2bin(bn, buf))
96 goto err;
97 if (!ec_point_from_octets(group, buf, buf_len, &point, NULL, ctx))
98 goto err;
99
100 err:
101 freezero(buf, buf_len);
102
103 return point;
104}
105LCRYPTO_ALIAS(EC_POINT_bn2point);
106
107char *
108EC_POINT_point2hex(const EC_GROUP *group, const EC_POINT *point,
109 point_conversion_form_t form, BN_CTX *ctx)
110{
111 BIGNUM *bn;
112 char *hex = NULL;
113
114 if ((bn = EC_POINT_point2bn(group, point, form, NULL, ctx)) == NULL)
115 goto err;
116 if ((hex = BN_bn2hex(bn)) == NULL)
117 goto err;
118
119 err:
120 BN_free(bn);
121
122 return hex;
123}
124LCRYPTO_ALIAS(EC_POINT_point2hex);
125
126EC_POINT *
127EC_POINT_hex2point(const EC_GROUP *group, const char *hex,
128 EC_POINT *in_point, BN_CTX *ctx)
129{
130 EC_POINT *point = NULL;
131 BIGNUM *bn = NULL;
132
133 if (BN_hex2bn(&bn, hex) == 0)
134 goto err;
135 if ((point = EC_POINT_bn2point(group, bn, in_point, ctx)) == NULL)
136 goto err;
137
138 err:
139 BN_free(bn);
140
141 return point;
142}
143LCRYPTO_ALIAS(EC_POINT_hex2point);