diff options
author | tb <> | 2024-10-11 18:55:44 +0000 |
---|---|---|
committer | tb <> | 2024-10-11 18:55:44 +0000 |
commit | c24a29b0fcf61cf5b8d2c92ef2647c2ae5f77021 (patch) | |
tree | 26614aeaae29781f40e63b0430d4afd39d3d6005 /src | |
parent | 116457c99e8e4e7a290250ddda7975371326557e (diff) | |
download | openbsd-c24a29b0fcf61cf5b8d2c92ef2647c2ae5f77021.tar.gz openbsd-c24a29b0fcf61cf5b8d2c92ef2647c2ae5f77021.tar.bz2 openbsd-c24a29b0fcf61cf5b8d2c92ef2647c2ae5f77021.zip |
Clean up ec_asn1_group2fieldid()
This drops some unnecessary freeing that was turned into a double free
reachable via public API in OpenSSL 1.1. Other than that it unindents
code and uses better variable names.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/ec/ec_asn1.c | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c index 3cc91fe4c1..291b59ac06 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.66 2024/10/11 18:35:39 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1.c,v 1.67 2024/10/11 18:55:44 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -559,50 +559,46 @@ EC_PRIVATEKEY_free(EC_PRIVATEKEY *a) | |||
559 | static int | 559 | static int |
560 | ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field) | 560 | ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field) |
561 | { | 561 | { |
562 | int ok = 0, nid; | 562 | BIGNUM *p = NULL; |
563 | BIGNUM *tmp = NULL; | 563 | int nid; |
564 | int ret = 0; | ||
564 | 565 | ||
565 | if (group == NULL || field == NULL) | 566 | if (group == NULL || field == NULL) |
566 | return 0; | 567 | goto err; |
567 | |||
568 | /* clear the old values (if necessary) */ | ||
569 | if (field->fieldType != NULL) | ||
570 | ASN1_OBJECT_free(field->fieldType); | ||
571 | if (field->p.other != NULL) | ||
572 | ASN1_TYPE_free(field->p.other); | ||
573 | 568 | ||
574 | nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group)); | 569 | nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group)); |
575 | /* set OID for the field */ | 570 | if (nid == NID_X9_62_characteristic_two_field) { |
571 | ECerror(EC_R_GF2M_NOT_SUPPORTED); | ||
572 | goto err; | ||
573 | } | ||
574 | if (nid != NID_X9_62_prime_field) { | ||
575 | ECerror(EC_R_INVALID_FIELD); | ||
576 | goto err; | ||
577 | } | ||
578 | |||
576 | if ((field->fieldType = OBJ_nid2obj(nid)) == NULL) { | 579 | if ((field->fieldType = OBJ_nid2obj(nid)) == NULL) { |
577 | ECerror(ERR_R_OBJ_LIB); | 580 | ECerror(ERR_R_OBJ_LIB); |
578 | goto err; | 581 | goto err; |
579 | } | 582 | } |
580 | if (nid == NID_X9_62_prime_field) { | 583 | if ((p = BN_new()) == NULL) { |
581 | if ((tmp = BN_new()) == NULL) { | 584 | ECerror(ERR_R_MALLOC_FAILURE); |
582 | ECerror(ERR_R_MALLOC_FAILURE); | 585 | goto err; |
583 | goto err; | 586 | } |
584 | } | 587 | if (!EC_GROUP_get_curve(group, p, NULL, NULL, NULL)) { |
585 | /* the parameters are specified by the prime number p */ | 588 | ECerror(ERR_R_EC_LIB); |
586 | if (!EC_GROUP_get_curve(group, tmp, NULL, NULL, NULL)) { | 589 | goto err; |
587 | ECerror(ERR_R_EC_LIB); | 590 | } |
588 | goto err; | 591 | if ((field->p.prime = BN_to_ASN1_INTEGER(p, NULL)) == NULL) { |
589 | } | 592 | ECerror(ERR_R_ASN1_LIB); |
590 | /* set the prime number */ | ||
591 | field->p.prime = BN_to_ASN1_INTEGER(tmp, NULL); | ||
592 | if (field->p.prime == NULL) { | ||
593 | ECerror(ERR_R_ASN1_LIB); | ||
594 | goto err; | ||
595 | } | ||
596 | } else { | ||
597 | ECerror(EC_R_GF2M_NOT_SUPPORTED); | ||
598 | goto err; | 593 | goto err; |
599 | } | 594 | } |
600 | 595 | ||
601 | ok = 1; | 596 | ret = 1; |
602 | 597 | ||
603 | err: | 598 | err: |
604 | BN_free(tmp); | 599 | BN_free(p); |
605 | return (ok); | 600 | |
601 | return ret; | ||
606 | } | 602 | } |
607 | 603 | ||
608 | static int | 604 | static int |