2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
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
11 * SHA-1 low level APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
16 #include <openssl/crypto.h>
17 #include <openssl/opensslconf.h>
19 #include <openssl/opensslv.h>
20 #include <openssl/evp.h>
21 #include <openssl/sha.h>
23 /* The implementation is in ../md32_common.h */
25 #include "sha_local.h"
26 #include "crypto/sha.h"
28 int sha1_ctrl(SHA_CTX *sha1, int cmd, int mslen, void *ms)
30 unsigned char padtmp[40];
31 unsigned char sha1tmp[SHA_DIGEST_LENGTH];
33 if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
39 /* SSLv3 client auth handling: see RFC-6101 5.6.8 */
43 /* At this point hash contains all handshake messages, update
44 * with master secret and pad_1.
47 if (SHA1_Update(sha1, ms, mslen) <= 0)
50 /* Set padtmp to pad_1 value */
51 memset(padtmp, 0x36, sizeof(padtmp));
53 if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
56 if (!SHA1_Final(sha1tmp, sha1))
59 /* Reinitialise context */
64 if (SHA1_Update(sha1, ms, mslen) <= 0)
67 /* Set padtmp to pad_2 value */
68 memset(padtmp, 0x5c, sizeof(padtmp));
70 if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
73 if (!SHA1_Update(sha1, sha1tmp, sizeof(sha1tmp)))
76 /* Now when ctx is finalised it will return the SSL v3 hash value */
77 OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));