diff options
| author | tb <> | 2025-03-13 10:31:12 +0000 |
|---|---|---|
| committer | tb <> | 2025-03-13 10:31:12 +0000 |
| commit | a8dfe0e93a8dd087c97360014c85b4a5b706ac43 (patch) | |
| tree | ecce31f1c041cddddbf890310bf0e63db14d4839 /src | |
| parent | fa6fcfa10c39c657cc034faabd7bfed5972d48e3 (diff) | |
| download | openbsd-a8dfe0e93a8dd087c97360014c85b4a5b706ac43.tar.gz openbsd-a8dfe0e93a8dd087c97360014c85b4a5b706ac43.tar.bz2 openbsd-a8dfe0e93a8dd087c97360014c85b4a5b706ac43.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_asn1.c | 16 |
1 files changed, 3 insertions, 13 deletions
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 @@ | |||
| 1 | /* $OpenBSD: ec_asn1.c,v 1.110 2025/01/25 10:27:58 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1.c,v 1.111 2025/03/13 10:31:12 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
| 4 | */ | 4 | */ |
| @@ -701,26 +701,16 @@ static int | |||
| 701 | ec_asn1_encode_field_element(const EC_GROUP *group, const BIGNUM *bn, | 701 | ec_asn1_encode_field_element(const EC_GROUP *group, const BIGNUM *bn, |
| 702 | ASN1_OCTET_STRING *os) | 702 | ASN1_OCTET_STRING *os) |
| 703 | { | 703 | { |
| 704 | int len; | ||
| 705 | |||
| 706 | /* Zero-pad field element to byte length of p per SEC 1, 2.3.5. */ | 704 | /* Zero-pad field element to byte length of p per SEC 1, 2.3.5. */ |
| 707 | len = (EC_GROUP_get_degree(group) + 7) / 8; | 705 | return ec_asn1_encode_bn(group, bn, BN_num_bytes(group->p), os); |
| 708 | return ec_asn1_encode_bn(group, bn, len, os); | ||
| 709 | } | 706 | } |
| 710 | 707 | ||
| 711 | static int | 708 | static int |
| 712 | ec_asn1_encode_private_key(const EC_GROUP *group, const BIGNUM *bn, | 709 | ec_asn1_encode_private_key(const EC_GROUP *group, const BIGNUM *bn, |
| 713 | ASN1_OCTET_STRING *os) | 710 | ASN1_OCTET_STRING *os) |
| 714 | { | 711 | { |
| 715 | const BIGNUM *order; | ||
| 716 | |||
| 717 | if ((order = EC_GROUP_get0_order(group)) == NULL) { | ||
| 718 | ECerror(EC_R_INVALID_GROUP_ORDER); | ||
| 719 | return 0; | ||
| 720 | } | ||
| 721 | |||
| 722 | /* Zero-pad private key to byte length of order per SEC 1, C.4. */ | 712 | /* Zero-pad private key to byte length of order per SEC 1, C.4. */ |
| 723 | return ec_asn1_encode_bn(group, bn, BN_num_bytes(order), os); | 713 | return ec_asn1_encode_bn(group, bn, BN_num_bytes(group->order), os); |
| 724 | } | 714 | } |
| 725 | 715 | ||
| 726 | static int | 716 | static int |
