summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2024-10-30 18:01:52 +0000
committertb <>2024-10-30 18:01:52 +0000
commit198c8abda2dbade2e5be1aebfc5d0c25d2944274 (patch)
tree77023a286bf92096a503cd7b3a3294ffc1c4c70a /src/lib
parent053aff6eb0d281ddc333965307239cf742b2eeb4 (diff)
downloadopenbsd-198c8abda2dbade2e5be1aebfc5d0c25d2944274.tar.gz
openbsd-198c8abda2dbade2e5be1aebfc5d0c25d2944274.tar.bz2
openbsd-198c8abda2dbade2e5be1aebfc5d0c25d2944274.zip
Rewrite EC_POINT_bn2point()
This is slightly asymmetric with EC_POINT_point2bn() and different from the other "print" functions since it has to deal with the asymmetry between BN_bin2bn() and BN_bn2bin() and allocate itself. Still, we can make this substantially shorter than it previously was. ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ec/ec_print.c43
1 files changed, 15 insertions, 28 deletions
diff --git a/src/lib/libcrypto/ec/ec_print.c b/src/lib/libcrypto/ec/ec_print.c
index be5f845423..7a479a3ddc 100644
--- a/src/lib/libcrypto/ec/ec_print.c
+++ b/src/lib/libcrypto/ec/ec_print.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_print.c,v 1.18 2024/10/30 17:51:35 tb Exp $ */ 1/* $OpenBSD: ec_print.c,v 1.19 2024/10/30 18:01:52 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -84,36 +84,23 @@ EC_POINT *
84EC_POINT_bn2point(const EC_GROUP *group, 84EC_POINT_bn2point(const EC_GROUP *group,
85 const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx) 85 const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx)
86{ 86{
87 unsigned char *buf = NULL;
87 size_t buf_len = 0; 88 size_t buf_len = 0;
88 unsigned char *buf;
89 EC_POINT *ret;
90 89
90 /* Of course BN_bn2bin() is in no way symmetric to BN_bin2bn()... */
91 if ((buf_len = BN_num_bytes(bn)) == 0) 91 if ((buf_len = BN_num_bytes(bn)) == 0)
92 return NULL; 92 goto err;
93 buf = malloc(buf_len); 93 if ((buf = calloc(1, buf_len)) == NULL)
94 if (buf == NULL) 94 goto err;
95 return NULL; 95 if (!BN_bn2bin(bn, buf))
96 96 goto err;
97 if (!BN_bn2bin(bn, buf)) { 97 if (!ec_point_from_octets(group, buf, buf_len, &point, NULL, ctx))
98 free(buf); 98 goto err;
99 return NULL; 99
100 } 100 err:
101 if (point == NULL) { 101 freezero(buf, buf_len);
102 if ((ret = EC_POINT_new(group)) == NULL) { 102
103 free(buf); 103 return point;
104 return NULL;
105 }
106 } else
107 ret = point;
108
109 if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) {
110 if (point == NULL)
111 EC_POINT_free(ret);
112 free(buf);
113 return NULL;
114 }
115 free(buf);
116 return ret;
117} 104}
118LCRYPTO_ALIAS(EC_POINT_bn2point); 105LCRYPTO_ALIAS(EC_POINT_bn2point);
119 106