Coverage Report

Created: 2025-12-08 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/crypto/asn1/a_digest.c
Line
Count
Source
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
#include <stdio.h>
11
#include <time.h>
12
#include <sys/types.h>
13
14
#include "internal/cryptlib.h"
15
16
#include <openssl/err.h>
17
#include <openssl/evp.h>
18
#include <openssl/buffer.h>
19
#include <openssl/x509.h>
20
#include "crypto/x509.h"
21
22
#ifndef OPENSSL_NO_DEPRECATED_3_0
23
24
int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
25
                unsigned char *md, unsigned int *len)
26
0
{
27
0
    int inl;
28
0
    unsigned char *str, *p;
29
30
0
    inl = i2d(data, NULL);
31
0
    if (inl <= 0) {
32
0
        ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR);
33
0
        return 0;
34
0
    }
35
0
    if ((str = OPENSSL_malloc(inl)) == NULL)
36
0
        return 0;
37
0
    p = str;
38
0
    i2d(data, &p);
39
40
0
    if (!EVP_Digest(str, inl, md, len, type, NULL)) {
41
0
        OPENSSL_free(str);
42
0
        return 0;
43
0
    }
44
0
    OPENSSL_free(str);
45
0
    return 1;
46
0
}
47
48
#endif
49
50
int ossl_asn1_item_digest_ex(const ASN1_ITEM *it, const EVP_MD *md, void *asn,
51
                             unsigned char *data, unsigned int *len,
52
                             OSSL_LIB_CTX *libctx, const char *propq)
53
0
{
54
0
    int i, ret = 0;
55
0
    unsigned char *str = NULL;
56
0
    EVP_MD *fetched_md = (EVP_MD *)md;
57
58
0
    i = ASN1_item_i2d(asn, &str, it);
59
0
    if (i < 0 || str == NULL)
60
0
        return 0;
61
62
0
    if (EVP_MD_get0_provider(md) == NULL)
63
0
        fetched_md = EVP_MD_fetch(libctx, EVP_MD_get0_name(md), propq);
64
0
    if (fetched_md == NULL)
65
0
        goto err;
66
67
0
    ret = EVP_Digest(str, i, data, len, fetched_md, NULL);
68
0
err:
69
0
    OPENSSL_free(str);
70
0
    if (fetched_md != md)
71
0
        EVP_MD_free(fetched_md);
72
0
    return ret;
73
0
}
74
75
int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *md, void *asn,
76
                     unsigned char *data, unsigned int *len)
77
0
{
78
0
    return ossl_asn1_item_digest_ex(it, md, asn, data, len, NULL, NULL);
79
0
}
80