diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-10-30 17:36:23 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-10-30 17:36:23 +0000 |
commit | ae115314c59b4eb43da6b99e5a851b26d2d7ebfb (patch) | |
tree | 2bd2bf781e9740add7ea2807bdbf69eb6dcdd300 /lib | |
parent | e803c5d78086ec6f9963d320bccfd404585787e9 (diff) |
Rewrite EC_POINT_point2bn()
While it makes little sens to place either one of the uncompressed, the
compressed or the hybrid X9.62 octet string encoding of an elliptic curve
point into a BIGNUM, it is what this API does. It's ec_point_to_octets()
followed by BN_bin2bn().
ok jsing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libcrypto/ec/ec_print.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/lib/libcrypto/ec/ec_print.c b/lib/libcrypto/ec/ec_print.c index d0c95850079..d8261a94f58 100644 --- a/lib/libcrypto/ec/ec_print.c +++ b/lib/libcrypto/ec/ec_print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_print.c,v 1.15 2024/10/28 17:00:51 tb Exp $ */ +/* $OpenBSD: ec_print.c,v 1.16 2024/10/30 17:36:22 tb Exp $ */ /* ==================================================================== * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. * @@ -62,27 +62,21 @@ BIGNUM * EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *point, - point_conversion_form_t form, BIGNUM *ret, BN_CTX *ctx) + point_conversion_form_t form, BIGNUM *in_bn, BN_CTX *ctx) { + BIGNUM *bn = NULL; + unsigned char *buf = NULL; size_t buf_len = 0; - unsigned char *buf; - - buf_len = EC_POINT_point2oct(group, point, form, NULL, 0, ctx); - if (buf_len == 0) - return NULL; - - if ((buf = malloc(buf_len)) == NULL) - return NULL; - if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx)) { - free(buf); - return NULL; - } - ret = BN_bin2bn(buf, buf_len, ret); + if (!ec_point_to_octets(group, point, form, &buf, &buf_len, ctx)) + goto err; + if ((bn = BN_bin2bn(buf, buf_len, in_bn)) == NULL) + goto err; - free(buf); + err: + freezero(buf, buf_len); - return ret; + return bn; } LCRYPTO_ALIAS(EC_POINT_point2bn); |