2 * Copyright 1995-2016 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
10 #include <openssl/crypto.h>
11 #include <openssl/opensslconf.h>
13 #include <openssl/opensslv.h>
14 #include <openssl/evp.h>
15 #include <openssl/sha.h>
17 /* The implementation is in ../md32_common.h */
20 #include "internal/sha.h"
22 int sha1_ctrl(SHA_CTX *sha1, int cmd, int mslen, void *ms)
24 unsigned char padtmp[40];
25 unsigned char sha1tmp[SHA_DIGEST_LENGTH];
27 if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
33 /* SSLv3 client auth handling: see RFC-6101 5.6.8 */
37 /* At this point hash contains all handshake messages, update
38 * with master secret and pad_1.
41 if (SHA1_Update(sha1, ms, mslen) <= 0)
44 /* Set padtmp to pad_1 value */
45 memset(padtmp, 0x36, sizeof(padtmp));
47 if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
50 if (!SHA1_Final(sha1tmp, sha1))
53 /* Reinitialise context */
58 if (SHA1_Update(sha1, ms, mslen) <= 0)
61 /* Set padtmp to pad_2 value */
62 memset(padtmp, 0x5c, sizeof(padtmp));
64 if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
67 if (!SHA1_Update(sha1, sha1tmp, sizeof(sha1tmp)))
70 /* Now when ctx is finalised it will return the SSL v3 hash value */
71 OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));