From feba57a19b3cc7d98fc2e6c42a2aebe57fd59e2f Mon Sep 17 00:00:00 2001 From: tb <> Date: Thu, 13 Mar 2025 10:31:12 +0000 Subject: Simplify field and private key encoding Reach into the group (p and order are always available) and use BN_num_bytes() rather than using clumsy and badly named API. It's shorter and more readable. ok jsing --- src/lib/libcrypto/ec/ec_asn1.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c index faca6059e4..ef318f8d43 100644 --- a/src/lib/libcrypto/ec/ec_asn1.c +++ b/src/lib/libcrypto/ec/ec_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_asn1.c,v 1.110 2025/01/25 10:27:58 tb Exp $ */ +/* $OpenBSD: ec_asn1.c,v 1.111 2025/03/13 10:31:12 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -701,26 +701,16 @@ static int ec_asn1_encode_field_element(const EC_GROUP *group, const BIGNUM *bn, ASN1_OCTET_STRING *os) { - int len; - /* Zero-pad field element to byte length of p per SEC 1, 2.3.5. */ - len = (EC_GROUP_get_degree(group) + 7) / 8; - return ec_asn1_encode_bn(group, bn, len, os); + return ec_asn1_encode_bn(group, bn, BN_num_bytes(group->p), os); } static int ec_asn1_encode_private_key(const EC_GROUP *group, const BIGNUM *bn, ASN1_OCTET_STRING *os) { - const BIGNUM *order; - - if ((order = EC_GROUP_get0_order(group)) == NULL) { - ECerror(EC_R_INVALID_GROUP_ORDER); - return 0; - } - /* Zero-pad private key to byte length of order per SEC 1, C.4. */ - return ec_asn1_encode_bn(group, bn, BN_num_bytes(order), os); + return ec_asn1_encode_bn(group, bn, BN_num_bytes(group->order), os); } static int -- cgit v1.2.3-55-g6feb