diff options
| author | joshua <> | 2024-01-28 14:43:48 +0000 |
|---|---|---|
| committer | joshua <> | 2024-01-28 14:43:48 +0000 |
| commit | c33469682cf8c8a1224319946356725ae23ade27 (patch) | |
| tree | 61ef0416333eef6219afc4ccaefb6f49c9cf217e /src | |
| parent | 49b41170f3f0edb587f1b7107d440f81b0369b5a (diff) | |
| download | openbsd-c33469682cf8c8a1224319946356725ae23ade27.tar.gz openbsd-c33469682cf8c8a1224319946356725ae23ade27.tar.bz2 openbsd-c33469682cf8c8a1224319946356725ae23ade27.zip | |
Clean up EVP_MD_CTX_{init,cleanup}() usage in ASN1_item_verify()
ok tb@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_item.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_item.c b/src/lib/libcrypto/asn1/asn1_item.c index 18da77433e..99a08698c8 100644 --- a/src/lib/libcrypto/asn1/asn1_item.c +++ b/src/lib/libcrypto/asn1/asn1_item.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: asn1_item.c,v 1.19 2024/01/13 13:59:18 joshua Exp $ */ | 1 | /* $OpenBSD: asn1_item.c,v 1.20 2024/01/28 14:43:48 joshua Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -381,7 +381,7 @@ int | |||
| 381 | ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | 381 | ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, |
| 382 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) | 382 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) |
| 383 | { | 383 | { |
| 384 | EVP_MD_CTX ctx; | 384 | EVP_MD_CTX *md_ctx = NULL; |
| 385 | unsigned char *in = NULL; | 385 | unsigned char *in = NULL; |
| 386 | int mdnid, pknid; | 386 | int mdnid, pknid; |
| 387 | int in_len = 0; | 387 | int in_len = 0; |
| @@ -389,15 +389,16 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
| 389 | 389 | ||
| 390 | if (pkey == NULL) { | 390 | if (pkey == NULL) { |
| 391 | ASN1error(ERR_R_PASSED_NULL_PARAMETER); | 391 | ASN1error(ERR_R_PASSED_NULL_PARAMETER); |
| 392 | return -1; | 392 | goto err; |
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7) { | 395 | if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7) { |
| 396 | ASN1error(ASN1_R_INVALID_BIT_STRING_BITS_LEFT); | 396 | ASN1error(ASN1_R_INVALID_BIT_STRING_BITS_LEFT); |
| 397 | return -1; | 397 | goto err; |
| 398 | } | 398 | } |
| 399 | 399 | ||
| 400 | EVP_MD_CTX_init(&ctx); | 400 | if ((md_ctx = EVP_MD_CTX_new()) == NULL) |
| 401 | goto err; | ||
| 401 | 402 | ||
| 402 | /* Convert signature OID into digest and public key OIDs */ | 403 | /* Convert signature OID into digest and public key OIDs */ |
| 403 | if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) { | 404 | if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) { |
| @@ -409,7 +410,7 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
| 409 | ASN1error(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); | 410 | ASN1error(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); |
| 410 | goto err; | 411 | goto err; |
| 411 | } | 412 | } |
| 412 | ret = pkey->ameth->item_verify(&ctx, it, asn, a, | 413 | ret = pkey->ameth->item_verify(md_ctx, it, asn, a, |
| 413 | signature, pkey); | 414 | signature, pkey); |
| 414 | /* Return value of 2 means carry on, anything else means we | 415 | /* Return value of 2 means carry on, anything else means we |
| 415 | * exit straight away: either a fatal error of the underlying | 416 | * exit straight away: either a fatal error of the underlying |
| @@ -432,7 +433,7 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
| 432 | goto err; | 433 | goto err; |
| 433 | } | 434 | } |
| 434 | 435 | ||
| 435 | if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) { | 436 | if (!EVP_DigestVerifyInit(md_ctx, NULL, type, NULL, pkey)) { |
| 436 | ASN1error(ERR_R_EVP_LIB); | 437 | ASN1error(ERR_R_EVP_LIB); |
| 437 | ret = 0; | 438 | ret = 0; |
| 438 | goto err; | 439 | goto err; |
| @@ -446,7 +447,7 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
| 446 | goto err; | 447 | goto err; |
| 447 | } | 448 | } |
| 448 | 449 | ||
| 449 | if (EVP_DigestVerify(&ctx, signature->data, signature->length, | 450 | if (EVP_DigestVerify(md_ctx, signature->data, signature->length, |
| 450 | in, in_len) <= 0) { | 451 | in, in_len) <= 0) { |
| 451 | ASN1error(ERR_R_EVP_LIB); | 452 | ASN1error(ERR_R_EVP_LIB); |
| 452 | ret = 0; | 453 | ret = 0; |
| @@ -456,7 +457,7 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
| 456 | ret = 1; | 457 | ret = 1; |
| 457 | 458 | ||
| 458 | err: | 459 | err: |
| 459 | EVP_MD_CTX_cleanup(&ctx); | 460 | EVP_MD_CTX_free(md_ctx); |
| 460 | freezero(in, in_len); | 461 | freezero(in, in_len); |
| 461 | 462 | ||
| 462 | return ret; | 463 | return ret; |
