2016-05-18 02:52:22 +08:00
|
|
|
/*
|
2022-05-03 18:52:38 +08:00
|
|
|
* Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:54:58 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
2020-01-09 11:14:13 +08:00
|
|
|
/*
|
|
|
|
* SHA-1 low level APIs are deprecated for public use, but still ok for
|
|
|
|
* internal use.
|
|
|
|
*/
|
|
|
|
#include "internal/deprecated.h"
|
|
|
|
|
2011-02-16 22:40:06 +08:00
|
|
|
#include <openssl/crypto.h>
|
2005-06-01 00:36:27 +08:00
|
|
|
#include <openssl/opensslconf.h>
|
1999-09-05 20:42:04 +08:00
|
|
|
|
2019-04-11 18:27:59 +08:00
|
|
|
#include <openssl/opensslv.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/sha.h>
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2022-02-09 16:12:30 +08:00
|
|
|
/* The implementation is in crypto/md32_common.h */
|
2000-01-28 03:31:26 +08:00
|
|
|
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "sha_local.h"
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/sha.h"
|
2019-04-11 18:27:59 +08:00
|
|
|
|
2020-11-16 10:08:30 +08:00
|
|
|
int ossl_sha1_ctrl(SHA_CTX *sha1, int cmd, int mslen, void *ms)
|
2019-04-11 18:27:59 +08:00
|
|
|
{
|
|
|
|
unsigned char padtmp[40];
|
|
|
|
unsigned char sha1tmp[SHA_DIGEST_LENGTH];
|
|
|
|
|
|
|
|
if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
if (sha1 == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* SSLv3 client auth handling: see RFC-6101 5.6.8 */
|
|
|
|
if (mslen != 48)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* At this point hash contains all handshake messages, update
|
|
|
|
* with master secret and pad_1.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (SHA1_Update(sha1, ms, mslen) <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Set padtmp to pad_1 value */
|
|
|
|
memset(padtmp, 0x36, sizeof(padtmp));
|
|
|
|
|
|
|
|
if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!SHA1_Final(sha1tmp, sha1))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Reinitialise context */
|
|
|
|
|
|
|
|
if (!SHA1_Init(sha1))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (SHA1_Update(sha1, ms, mslen) <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Set padtmp to pad_2 value */
|
|
|
|
memset(padtmp, 0x5c, sizeof(padtmp));
|
|
|
|
|
|
|
|
if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!SHA1_Update(sha1, sha1tmp, sizeof(sha1tmp)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Now when ctx is finalised it will return the SSL v3 hash value */
|
|
|
|
OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|