Coverage Report

Created: 2024-05-15 07:16

/src/openssl/crypto/sha/sha1dgst.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 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 <openssl/crypto.h>
17
#include <openssl/opensslconf.h>
18
19
#include <openssl/opensslv.h>
20
#include <openssl/evp.h>
21
#include <openssl/sha.h>
22
23
/* The implementation is in ../md32_common.h */
24
25
#include "sha_local.h"
26
#include "crypto/sha.h"
27
28
int sha1_ctrl(SHA_CTX *sha1, int cmd, int mslen, void *ms)
29
0
{
30
0
    unsigned char padtmp[40];
31
0
    unsigned char sha1tmp[SHA_DIGEST_LENGTH];
32
33
0
    if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
34
0
        return -2;
35
36
0
    if (sha1 == NULL)
37
0
        return 0;
38
39
    /* SSLv3 client auth handling: see RFC-6101 5.6.8 */
40
0
    if (mslen != 48)
41
0
        return 0;
42
43
    /* At this point hash contains all handshake messages, update
44
     * with master secret and pad_1.
45
     */
46
47
0
    if (SHA1_Update(sha1, ms, mslen) <= 0)
48
0
        return 0;
49
50
    /* Set padtmp to pad_1 value */
51
0
    memset(padtmp, 0x36, sizeof(padtmp));
52
53
0
    if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
54
0
        return 0;
55
56
0
    if (!SHA1_Final(sha1tmp, sha1))
57
0
        return 0;
58
59
    /* Reinitialise context */
60
61
0
    if (!SHA1_Init(sha1))
62
0
        return 0;
63
64
0
    if (SHA1_Update(sha1, ms, mslen) <= 0)
65
0
        return 0;
66
67
    /* Set padtmp to pad_2 value */
68
0
    memset(padtmp, 0x5c, sizeof(padtmp));
69
70
0
    if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
71
0
        return 0;
72
73
0
    if (!SHA1_Update(sha1, sha1tmp, sizeof(sha1tmp)))
74
0
        return 0;
75
76
    /* Now when ctx is finalised it will return the SSL v3 hash value */
77
0
    OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));
78
79
0
    return 1;
80
0
}