2 * Copyright 2015-2019 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 * MD5 and SHA-1 low level APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
17 #include "prov/md5_sha1.h"
18 #include <openssl/evp.h>
20 int md5_sha1_init(MD5_SHA1_CTX
*mctx
)
22 if (!MD5_Init(&mctx
->md5
))
24 return SHA1_Init(&mctx
->sha1
);
27 int md5_sha1_update(MD5_SHA1_CTX
*mctx
, const void *data
, size_t count
)
29 if (!MD5_Update(&mctx
->md5
, data
, count
))
31 return SHA1_Update(&mctx
->sha1
, data
, count
);
34 int md5_sha1_final(unsigned char *md
, MD5_SHA1_CTX
*mctx
)
36 if (!MD5_Final(md
, &mctx
->md5
))
38 return SHA1_Final(md
+ MD5_DIGEST_LENGTH
, &mctx
->sha1
);
41 int md5_sha1_ctrl(MD5_SHA1_CTX
*mctx
, int cmd
, int mslen
, void *ms
)
43 unsigned char padtmp
[48];
44 unsigned char md5tmp
[MD5_DIGEST_LENGTH
];
45 unsigned char sha1tmp
[SHA_DIGEST_LENGTH
];
47 if (cmd
!= EVP_CTRL_SSL3_MASTER_SECRET
)
53 /* SSLv3 client auth handling: see RFC-6101 5.6.8 */
57 /* At this point hash contains all handshake messages, update
58 * with master secret and pad_1.
61 if (md5_sha1_update(mctx
, ms
, mslen
) <= 0)
64 /* Set padtmp to pad_1 value */
65 memset(padtmp
, 0x36, sizeof(padtmp
));
67 if (!MD5_Update(&mctx
->md5
, padtmp
, sizeof(padtmp
)))
70 if (!MD5_Final(md5tmp
, &mctx
->md5
))
73 if (!SHA1_Update(&mctx
->sha1
, padtmp
, 40))
76 if (!SHA1_Final(sha1tmp
, &mctx
->sha1
))
79 /* Reinitialise context */
81 if (!md5_sha1_init(mctx
))
84 if (md5_sha1_update(mctx
, ms
, mslen
) <= 0)
87 /* Set padtmp to pad_2 value */
88 memset(padtmp
, 0x5c, sizeof(padtmp
));
90 if (!MD5_Update(&mctx
->md5
, padtmp
, sizeof(padtmp
)))
93 if (!MD5_Update(&mctx
->md5
, md5tmp
, sizeof(md5tmp
)))
96 if (!SHA1_Update(&mctx
->sha1
, padtmp
, 40))
99 if (!SHA1_Update(&mctx
->sha1
, sha1tmp
, sizeof(sha1tmp
)))
102 /* Now when ctx is finalised it will return the SSL v3 hash value */
104 OPENSSL_cleanse(md5tmp
, sizeof(md5tmp
));
105 OPENSSL_cleanse(sha1tmp
, sizeof(sha1tmp
));