Coverage Report

Created: 2025-06-13 06:58

/src/openssl30/crypto/sha/sha1_one.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
/*
11
 * SHA-1 low level APIs are deprecated for public use, but still ok for
12
 * internal use.
13
 */
14
#include "internal/deprecated.h"
15
16
#include <stdio.h>
17
#include <string.h>
18
#include <openssl/crypto.h>
19
#include <openssl/sha.h>
20
#include <openssl/evp.h>
21
#include "crypto/sha.h"
22
23
unsigned char *ossl_sha1(const unsigned char *d, size_t n, unsigned char *md)
24
0
{
25
0
    SHA_CTX c;
26
0
    static unsigned char m[SHA_DIGEST_LENGTH];
27
28
0
    if (md == NULL)
29
0
        md = m;
30
0
    if (!SHA1_Init(&c))
31
0
        return NULL;
32
0
    SHA1_Update(&c, d, n);
33
0
    SHA1_Final(md, &c);
34
0
    OPENSSL_cleanse(&c, sizeof(c));
35
0
    return md;
36
0
}
37
38
unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md)
39
0
{
40
0
    static unsigned char m[SHA_DIGEST_LENGTH];
41
42
0
    if (md == NULL)
43
0
        md = m;
44
0
    return EVP_Q_digest(NULL, "SHA1", NULL, d, n, md, NULL) ? md : NULL;
45
0
}
46
47
unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
48
0
{
49
0
    static unsigned char m[SHA224_DIGEST_LENGTH];
50
51
0
    if (md == NULL)
52
0
        md = m;
53
0
    return EVP_Q_digest(NULL, "SHA224", NULL, d, n, md, NULL) ? md : NULL;
54
0
}
55
56
unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md)
57
0
{
58
0
    static unsigned char m[SHA256_DIGEST_LENGTH];
59
60
0
    if (md == NULL)
61
0
        md = m;
62
0
    return EVP_Q_digest(NULL, "SHA256", NULL, d, n, md, NULL) ? md : NULL;
63
0
}
64
65
unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)
66
0
{
67
0
    static unsigned char m[SHA384_DIGEST_LENGTH];
68
69
0
    if (md == NULL)
70
0
        md = m;
71
0
    return EVP_Q_digest(NULL, "SHA384", NULL, d, n, md, NULL) ? md : NULL;
72
0
}
73
74
unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md)
75
0
{
76
0
    static unsigned char m[SHA512_DIGEST_LENGTH];
77
78
0
    if (md == NULL)
79
0
        md = m;
80
0
    return EVP_Q_digest(NULL, "SHA512", NULL, d, n, md, NULL) ? md : NULL;
81
0
}