/src/openssl30/crypto/asn1/a_digest.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 4 |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
| 5 |  |  * this file except in compliance with the License.  You can obtain a copy | 
| 6 |  |  * in the file LICENSE in the source distribution or at | 
| 7 |  |  * https://www.openssl.org/source/license.html | 
| 8 |  |  */ | 
| 9 |  |  | 
| 10 |  | /* We need to use some engine deprecated APIs */ | 
| 11 |  | #define OPENSSL_SUPPRESS_DEPRECATED | 
| 12 |  |  | 
| 13 |  | #include <stdio.h> | 
| 14 |  | #include <time.h> | 
| 15 |  | #include <sys/types.h> | 
| 16 |  |  | 
| 17 |  | #include "internal/cryptlib.h" | 
| 18 |  |  | 
| 19 |  | #include <openssl/engine.h> | 
| 20 |  | #include <openssl/err.h> | 
| 21 |  | #include <openssl/evp.h> | 
| 22 |  | #include <openssl/buffer.h> | 
| 23 |  | #include <openssl/x509.h> | 
| 24 |  | #include "crypto/x509.h" | 
| 25 |  |  | 
| 26 |  | #ifndef OPENSSL_NO_DEPRECATED_3_0 | 
| 27 |  |  | 
| 28 |  | int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, | 
| 29 |  |                 unsigned char *md, unsigned int *len) | 
| 30 | 0 | { | 
| 31 | 0 |     int inl; | 
| 32 | 0 |     unsigned char *str, *p; | 
| 33 |  | 
 | 
| 34 | 0 |     inl = i2d(data, NULL); | 
| 35 | 0 |     if (inl <= 0) { | 
| 36 | 0 |         ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR); | 
| 37 | 0 |         return 0; | 
| 38 | 0 |     } | 
| 39 | 0 |     if ((str = OPENSSL_malloc(inl)) == NULL) { | 
| 40 | 0 |         ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | 
| 41 | 0 |         return 0; | 
| 42 | 0 |     } | 
| 43 | 0 |     p = str; | 
| 44 | 0 |     i2d(data, &p); | 
| 45 |  | 
 | 
| 46 | 0 |     if (!EVP_Digest(str, inl, md, len, type, NULL)) { | 
| 47 | 0 |         OPENSSL_free(str); | 
| 48 | 0 |         return 0; | 
| 49 | 0 |     } | 
| 50 | 0 |     OPENSSL_free(str); | 
| 51 | 0 |     return 1; | 
| 52 | 0 | } | 
| 53 |  |  | 
| 54 |  | #endif | 
| 55 |  |  | 
| 56 |  | int ossl_asn1_item_digest_ex(const ASN1_ITEM *it, const EVP_MD *md, void *asn, | 
| 57 |  |                              unsigned char *data, unsigned int *len, | 
| 58 |  |                              OSSL_LIB_CTX *libctx, const char *propq) | 
| 59 | 118k | { | 
| 60 | 118k |     int i, ret = 0; | 
| 61 | 118k |     unsigned char *str = NULL; | 
| 62 | 118k |     EVP_MD *fetched_md = (EVP_MD *)md; | 
| 63 |  |  | 
| 64 | 118k |     i = ASN1_item_i2d(asn, &str, it); | 
| 65 | 118k |     if (i < 0 || str == NULL) | 
| 66 | 0 |         return 0; | 
| 67 |  |  | 
| 68 | 118k |     if (EVP_MD_get0_provider(md) == NULL) { | 
| 69 | 118k | #if !defined(OPENSSL_NO_ENGINE) | 
| 70 | 118k |         ENGINE *tmpeng = ENGINE_get_digest_engine(EVP_MD_get_type(md)); | 
| 71 |  |  | 
| 72 | 118k |         if (tmpeng != NULL) | 
| 73 | 0 |             ENGINE_finish(tmpeng); | 
| 74 | 118k |         else | 
| 75 | 118k | #endif | 
| 76 | 118k |             fetched_md = EVP_MD_fetch(libctx, EVP_MD_get0_name(md), propq); | 
| 77 | 118k |     } | 
| 78 | 118k |     if (fetched_md == NULL) | 
| 79 | 0 |         goto err; | 
| 80 |  |  | 
| 81 | 118k |     ret = EVP_Digest(str, i, data, len, fetched_md, NULL); | 
| 82 | 118k | err: | 
| 83 | 118k |     OPENSSL_free(str); | 
| 84 | 118k |     if (fetched_md != md) | 
| 85 | 118k |         EVP_MD_free(fetched_md); | 
| 86 | 118k |     return ret; | 
| 87 | 118k | } | 
| 88 |  |  | 
| 89 |  | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *md, void *asn, | 
| 90 |  |                      unsigned char *data, unsigned int *len) | 
| 91 | 153 | { | 
| 92 | 153 |     return ossl_asn1_item_digest_ex(it, md, asn, data, len, NULL, NULL); | 
| 93 | 153 | } | 
| 94 |  |  |