Coverage Report

Created: 2023-06-08 06:41

/src/openssl111/crypto/asn1/a_digest.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the OpenSSL license (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
21
#ifndef NO_ASN1_OLD
22
23
int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
24
                unsigned char *md, unsigned int *len)
25
0
{
26
0
    int inl;
27
0
    unsigned char *str, *p;
28
29
0
    inl = i2d(data, NULL);
30
0
    if (inl <= 0) {
31
0
        ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_INTERNAL_ERROR);
32
0
        return 0;
33
0
    }
34
0
    if ((str = OPENSSL_malloc(inl)) == NULL) {
35
0
        ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
36
0
        return 0;
37
0
    }
38
0
    p = str;
39
0
    i2d(data, &p);
40
41
0
    if (!EVP_Digest(str, inl, md, len, type, NULL)) {
42
0
        OPENSSL_free(str);
43
0
        return 0;
44
0
    }
45
0
    OPENSSL_free(str);
46
0
    return 1;
47
0
}
48
49
#endif
50
51
int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
52
                     unsigned char *md, unsigned int *len)
53
17.4k
{
54
17.4k
    int i;
55
17.4k
    unsigned char *str = NULL;
56
57
17.4k
    i = ASN1_item_i2d(asn, &str, it);
58
17.4k
    if (!str)
59
0
        return 0;
60
61
17.4k
    if (!EVP_Digest(str, i, md, len, type, NULL)) {
62
0
        OPENSSL_free(str);
63
0
        return 0;
64
0
    }
65
17.4k
    OPENSSL_free(str);
66
17.4k
    return 1;
67
17.4k
}