diff options
author | tb <> | 2024-10-30 17:53:28 +0000 |
---|---|---|
committer | tb <> | 2024-10-30 17:53:28 +0000 |
commit | 93e5d0e71fb8933f875cee0579c55866040e98a0 (patch) | |
tree | 0e1dd8a5600489b1d4e944a7425dfc9ec1193568 | |
parent | a24cd1519c6c51d5dd35264f69a238ace16fc410 (diff) | |
download | openbsd-93e5d0e71fb8933f875cee0579c55866040e98a0.tar.gz openbsd-93e5d0e71fb8933f875cee0579c55866040e98a0.tar.bz2 openbsd-93e5d0e71fb8933f875cee0579c55866040e98a0.zip |
Add ec_point_from_asn1_octet_string()
This is inverse to ec_point_to_asn1_octet_string() but again a lot
simpler. Simplify ec_asn1_set_group_parameters() by using it.
ok jsing
-rw-r--r-- | src/lib/libcrypto/ec/ec_asn1.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c index 0a488cac66..ec322a8559 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.99 2024/10/30 06:44:34 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1.c,v 1.100 2024/10/30 17:53:28 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -561,6 +561,21 @@ EC_PRIVATEKEY_free(EC_PRIVATEKEY *a) | |||
561 | } | 561 | } |
562 | 562 | ||
563 | static int | 563 | static int |
564 | ec_point_from_asn1_string(const EC_GROUP *group, const ASN1_STRING *astr, | ||
565 | EC_POINT **out_point, uint8_t *out_form) | ||
566 | { | ||
567 | return ec_point_from_octets(group, astr->data, astr->length, | ||
568 | out_point, out_form, NULL); | ||
569 | } | ||
570 | |||
571 | static int | ||
572 | ec_point_from_asn1_octet_string(const EC_GROUP *group, const ASN1_OCTET_STRING *aos, | ||
573 | EC_POINT **out_point, uint8_t *out_form) | ||
574 | { | ||
575 | return ec_point_from_asn1_string(group, aos, out_point, out_form); | ||
576 | } | ||
577 | |||
578 | static int | ||
564 | ec_point_to_asn1_string_type(const EC_GROUP *group, const EC_POINT *point, | 579 | ec_point_to_asn1_string_type(const EC_GROUP *group, const EC_POINT *point, |
565 | int form, int type, ASN1_STRING **out_astr) | 580 | int form, int type, ASN1_STRING **out_astr) |
566 | { | 581 | { |
@@ -958,19 +973,16 @@ ec_asn1_parameters_curve2group(const X9_62_CURVE *curve, | |||
958 | static int | 973 | static int |
959 | ec_asn1_set_group_parameters(const ECPARAMETERS *params, EC_GROUP *group) | 974 | ec_asn1_set_group_parameters(const ECPARAMETERS *params, EC_GROUP *group) |
960 | { | 975 | { |
961 | EC_POINT *generator; | 976 | EC_POINT *generator = NULL; |
962 | BIGNUM *order = NULL, *cofactor = NULL; | 977 | BIGNUM *order = NULL, *cofactor = NULL; |
963 | const ASN1_BIT_STRING *seed; | 978 | const ASN1_BIT_STRING *seed; |
964 | point_conversion_form_t form; | 979 | uint8_t form; |
965 | int ret = 0; | 980 | int ret = 0; |
966 | 981 | ||
967 | if ((generator = EC_POINT_new(group)) == NULL) | 982 | if (!ec_point_from_asn1_octet_string(group, params->base, &generator, &form)) |
968 | goto err; | 983 | goto err; |
969 | if (!EC_POINT_oct2point(group, generator, | 984 | EC_GROUP_set_point_conversion_form(group, form); |
970 | params->base->data, params->base->length, NULL)) { | 985 | |
971 | ECerror(ERR_R_EC_LIB); | ||
972 | goto err; | ||
973 | } | ||
974 | if ((order = ASN1_INTEGER_to_BN(params->order, NULL)) == NULL) { | 986 | if ((order = ASN1_INTEGER_to_BN(params->order, NULL)) == NULL) { |
975 | ECerror(ERR_R_ASN1_LIB); | 987 | ECerror(ERR_R_ASN1_LIB); |
976 | goto err; | 988 | goto err; |
@@ -996,10 +1008,6 @@ ec_asn1_set_group_parameters(const ECPARAMETERS *params, EC_GROUP *group) | |||
996 | } | 1008 | } |
997 | } | 1009 | } |
998 | 1010 | ||
999 | /* oct2point has ensured that to be compressed, uncompressed, or hybrid. */ | ||
1000 | form = params->base->data[0] & ~1U; | ||
1001 | EC_GROUP_set_point_conversion_form(group, form); | ||
1002 | |||
1003 | ret = 1; | 1011 | ret = 1; |
1004 | 1012 | ||
1005 | err: | 1013 | err: |