Implementation of HASH algorithms used in Wi-Fi.
Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | ADD_TWO_32BIT(z, x, y) |
#define | F1(x, y, z) (((x) & (y)) | (~(x) & (z))) |
#define | F2(x, y, z) (((x) & (z)) | ((y) & ~(z))) |
#define | F3(x, y, z) ((x) ^ (y) ^ (z)) |
#define | F4(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) |
#define | F5(x, y, z) ((y) ^ ((x) | ~(z))) |
#define | GET_UINT64_BE(n, b, i) |
#define | INT32_TO_INT64(z, x, y) z = (((uint64)(x)<<32)|((uint64)((y) & 0xffffffff))) |
#define | MD4_F(x, y, z) F1(x,y,z) |
#define | MD4_G(x, y, z) F4(x,y,z) |
#define | MD4_H(x, y, z) F3(x,y,z) |
#define | MD4_INERMEDIATE(A, B, C, D, W, K, S) |
#define | MD4_SEC OVERLAY_SEC1_API |
#define | MD5_F(x, y, z) F1(x,y,z) |
#define | MD5_G(x, y, z) F2(x,y,z) |
#define | MD5_H(x, y, z) F3(x,y,z) |
#define | MD5_I(x, y, z) F5(x,y,z) |
#define | MD5_INERMEDIATE(A, B, C, D, W, K, S) |
#define | PUTU64_BE(n, b, i) |
#define | SHA1_CH(x, y, z) F1(x,y,z) |
#define | SHA1_INERMEDIATE(A, B, C, D, E, W, K) |
#define | SHA1_MAJ(x, y, z) F4(x,y,z) |
#define | SHA256_CAP_SIGMA0(x) (SHA_ROTR(x, 2) ^ SHA_ROTR(x,13) ^ SHA_ROTR(x,22)) |
#define | SHA256_CAP_SIGMA1(x) (SHA_ROTR(x, 6) ^ SHA_ROTR(x,11) ^ SHA_ROTR(x,25)) |
#define | SHA256_CH(x, y, z) (z ^ (x & (y ^ z))) |
#define | SHA256_MAJ(x, y, z) ((x & y) | (z & (x | y))) |
#define | SHA256_MSG_LENGTH 8 |
#define | SHA256_SMALL_SIGMA0(x) (SHA_ROTR(x, 7) ^ SHA_ROTR(x,18) ^ SHA_SHR(x, 3)) |
#define | SHA256_SMALL_SIGMA1(x) (SHA_ROTR(x,17) ^ SHA_ROTR(x,19) ^ SHA_SHR(x,10)) |
#define | SHA512_CAP_SIGMA0(high, low) (SHA_ROTR_64(high,low, 28) ^ SHA_ROTR_64(low,high,2) ^ SHA_ROTR_64(low,high,7)) |
#define | SHA512_CAP_SIGMA1(high, low) (SHA_ROTR_64(high,low, 14) ^ SHA_ROTR_64(high,low,18) ^ SHA_ROTR_64(low,high,9)) |
#define | SHA512_CH_HIGH(x, y, z) (z[0] ^ (x[0] & (y[0] ^ z[0]))) |
#define | SHA512_CH_LOW(x, y, z) (z[1] ^ (x[1] & (y[1] ^ z[1]))) |
#define | SHA512_MAJ_HIGH(x, y, z) ((x[0] & y[0]) | (z[0] & (x[0] | y[0]))) |
#define | SHA512_MAJ_LOW(x, y, z) ((x[1] & y[1]) | (z[1] & (x[1] | y[1]))) |
#define | SHA512_MSG_LENGTH 16 |
#define | SHA512_SMALL_SIGMA0(high, low) (SHA_ROTR_64(high,low, 1) ^ SHA_ROTR_64(high,low,8) ^ SHA_SHR_64(high,low, 7)) |
#define | SHA512_SMALL_SIGMA1(high, low) (SHA_ROTR_64(high,low,19) ^ SHA_ROTR_64(low,high,29) ^ SHA_SHR_64(high,low,6)) |
#define | SHA_PAD_BYTE 0x80 |
#define | SHA_PARITY(x, y, z) F3(x,y,z) |
#define | UPDATE_SHA512_STATE(state_high, state_low, temp_state, temp_var, var_high, var_low) |
Functions | |
void | hmac_md5 (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Digest) |
void | hmac_sha1 (uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | HMAC_SHA256 (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Key, uint32 u32KeyLength, uint8 *pu8Digest) |
void | HMAC_Vector (tenuHashAlg enuHashAlg, uint8 *pu8Key, uint32 u32KeyLength, tstrBuffer *pstrInData, uint8 u8NumInputs, uint8 *pu8Out) |
void | MD4_Hash (uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
MD4_SEC void | MD4ProcessBlock (uint32 *pu32Md4State, const uint8 *pu8MessageBlock) |
void | MD5_Hash (tstrShaHashContext *pstrMD5Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | MD5_HashSW (tstrHash512Context *pstrMD5Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | MD5ProcessBlock (uint32 *pu32Md5State, const uint8 *pu8MessageBlock) |
void | SHA1_Hash (tstrShaHashContext *pstrSha1Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | SHA1_HashSW (tstrHash512Context *pstrSha1Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | SHA1ProcessBlock (uint32 *pu32Sha1State, const uint8 *pu8MessageBlock) |
void | SHA224_Hash (tstrShaHashContext *pstrSha224Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | SHA224_HashSW (tstrHash512Context *pstrSha224Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | SHA256_Hash (tstrShaHashContext *pstrSha256Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | SHA256_HashSW (tstrHash512Context *pstrSha256Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | SHA256ProcessBlock (uint32 *pu32Sha256State, const uint8 *pu8Data) |
void | SHA384_Hash (tstrShaHashContext *pstrSha384Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | SHA512_Hash (tstrShaHashContext *pstrSha512Cxt, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest) |
void | SHA512_HashSW (tstrHash512Context *pstrSha512Context, uint8 u8Flags, uint8 *pu8Data, uint32 u32DataLength, uint8 *pu8Digest, uint8 u8IsSHA384) |
void | SHA512ProcessBlock (uint32 *pu32Sha512State, const uint8 *pu8Data) |
void | Sha_HashFinish (tstrHash512Context *pstrHashCxt, uint8 *pu8LengthPadding, uint32 u32TotalMessageLength) |
void | Sha_HashUpdate (tstrHash512Context *pstrHashCxt, uint8 *pu8Data, uint32 u32DataLength) |
Variables | |
tstrHashInfo | eastrTlsHashes [] |
const uint32 | K_SHA1 [4] |
static const uint32 | K_SHA256 [] |
static const uint64 | K_SHA512 [][2] |
static const uint32 | T_MD5 [] |
#define ADD_TWO_32BIT | ( | z, | |
x, | |||
y | |||
) |
Referenced by SHA512ProcessBlock().
#define F1 | ( | x, | |
y, | |||
z | |||
) | (((x) & (y)) | (~(x) & (z))) |
#define F2 | ( | x, | |
y, | |||
z | |||
) | (((x) & (z)) | ((y) & ~(z))) |
#define F3 | ( | x, | |
y, | |||
z | |||
) | ((x) ^ (y) ^ (z)) |
#define F4 | ( | x, | |
y, | |||
z | |||
) | (((x) & (y)) | ((x) & (z)) | ((y) & (z))) |
#define F5 | ( | x, | |
y, | |||
z | |||
) | ((y) ^ ((x) | ~(z))) |
#define GET_UINT64_BE | ( | n, | |
b, | |||
i | |||
) |
Referenced by SHA512ProcessBlock().
#define MD4_F | ( | x, | |
y, | |||
z | |||
) | F1(x,y,z) |
Referenced by MD4ProcessBlock().
#define MD4_G | ( | x, | |
y, | |||
z | |||
) | F4(x,y,z) |
Referenced by MD4ProcessBlock().
#define MD4_H | ( | x, | |
y, | |||
z | |||
) | F3(x,y,z) |
Referenced by MD4ProcessBlock().
#define MD4_INERMEDIATE | ( | A, | |
B, | |||
C, | |||
D, | |||
W, | |||
K, | |||
S | |||
) |
Referenced by MD4ProcessBlock().
#define MD4_SEC OVERLAY_SEC1_API |
#define MD5_F | ( | x, | |
y, | |||
z | |||
) | F1(x,y,z) |
Referenced by MD5ProcessBlock().
#define MD5_G | ( | x, | |
y, | |||
z | |||
) | F2(x,y,z) |
Referenced by MD5ProcessBlock().
#define MD5_H | ( | x, | |
y, | |||
z | |||
) | F3(x,y,z) |
Referenced by MD5ProcessBlock().
#define MD5_I | ( | x, | |
y, | |||
z | |||
) | F5(x,y,z) |
Referenced by MD5ProcessBlock().
#define MD5_INERMEDIATE | ( | A, | |
B, | |||
C, | |||
D, | |||
W, | |||
K, | |||
S | |||
) |
Referenced by MD5ProcessBlock().
#define PUTU64_BE | ( | n, | |
b, | |||
i | |||
) |
#define SHA1_CH | ( | x, | |
y, | |||
z | |||
) | F1(x,y,z) |
Referenced by SHA1ProcessBlock().
#define SHA1_INERMEDIATE | ( | A, | |
B, | |||
C, | |||
D, | |||
E, | |||
W, | |||
K | |||
) |
Referenced by SHA1ProcessBlock().
#define SHA1_MAJ | ( | x, | |
y, | |||
z | |||
) | F4(x,y,z) |
Referenced by SHA1ProcessBlock().
Referenced by SHA256ProcessBlock().
Referenced by SHA256ProcessBlock().
#define SHA256_CH | ( | x, | |
y, | |||
z | |||
) | (z ^ (x & (y ^ z))) |
Referenced by SHA256ProcessBlock().
#define SHA256_MAJ | ( | x, | |
y, | |||
z | |||
) | ((x & y) | (z & (x | y))) |
Referenced by SHA256ProcessBlock().
#define SHA256_MSG_LENGTH 8 |
Referenced by MD4_Hash(), MD5_HashSW(), SHA1_HashSW(), SHA224_HashSW(), and SHA256_HashSW().
Referenced by SHA256ProcessBlock().
Referenced by SHA256ProcessBlock().
#define SHA512_CAP_SIGMA0 | ( | high, | |
low | |||
) | (SHA_ROTR_64(high,low, 28) ^ SHA_ROTR_64(low,high,2) ^ SHA_ROTR_64(low,high,7)) |
#define SHA512_CAP_SIGMA1 | ( | high, | |
low | |||
) | (SHA_ROTR_64(high,low, 14) ^ SHA_ROTR_64(high,low,18) ^ SHA_ROTR_64(low,high,9)) |
#define SHA512_CH_HIGH | ( | x, | |
y, | |||
z | |||
) | (z[0] ^ (x[0] & (y[0] ^ z[0]))) |
Referenced by SHA512ProcessBlock().
#define SHA512_CH_LOW | ( | x, | |
y, | |||
z | |||
) | (z[1] ^ (x[1] & (y[1] ^ z[1]))) |
Referenced by SHA512ProcessBlock().
#define SHA512_MAJ_HIGH | ( | x, | |
y, | |||
z | |||
) | ((x[0] & y[0]) | (z[0] & (x[0] | y[0]))) |
Referenced by SHA512ProcessBlock().
#define SHA512_MAJ_LOW | ( | x, | |
y, | |||
z | |||
) | ((x[1] & y[1]) | (z[1] & (x[1] | y[1]))) |
Referenced by SHA512ProcessBlock().
#define SHA512_MSG_LENGTH 16 |
Referenced by SHA512_HashSW().
#define SHA512_SMALL_SIGMA0 | ( | high, | |
low | |||
) | (SHA_ROTR_64(high,low, 1) ^ SHA_ROTR_64(high,low,8) ^ SHA_SHR_64(high,low, 7)) |
#define SHA512_SMALL_SIGMA1 | ( | high, | |
low | |||
) | (SHA_ROTR_64(high,low,19) ^ SHA_ROTR_64(low,high,29) ^ SHA_SHR_64(high,low,6)) |
#define SHA_PAD_BYTE 0x80 |
Referenced by Sha_HashFinish().
#define SHA_PARITY | ( | x, | |
y, | |||
z | |||
) | F3(x,y,z) |
Referenced by SHA1ProcessBlock().
#define UPDATE_SHA512_STATE | ( | state_high, | |
state_low, | |||
temp_state, | |||
temp_var, | |||
var_high, | |||
var_low | |||
) |
void hmac_md5 | ( | uint8 * | pu8Data, |
uint32 | u32DataLength, | ||
uint8 * | pu8Key, | ||
uint32 | u32KeyLength, | ||
uint8 * | pu8Digest | ||
) |
References HASH_ALG_MD5, HMAC_Vector(), tstrBuffer::pu8Data, and tstrBuffer::u16BufferSize.
void hmac_sha1 | ( | uint8 * | pu8Key, |
uint32 | u32KeyLength, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References HASH_ALG_SHA1, HMAC_Vector(), tstrBuffer::pu8Data, and tstrBuffer::u16BufferSize.
void HMAC_SHA256 | ( | uint8 * | pu8Data, |
uint32 | u32DataLength, | ||
uint8 * | pu8Key, | ||
uint32 | u32KeyLength, | ||
uint8 * | pu8Digest | ||
) |
References HASH_ALG_SHA256, HMAC_Vector(), tstrBuffer::pu8Data, and tstrBuffer::u16BufferSize.
void HMAC_Vector | ( | tenuHashAlg | enuHashAlg, |
uint8 * | pu8Key, | ||
uint32 | u32KeyLength, | ||
tstrBuffer * | pstrInData, | ||
uint8 | u8NumInputs, | ||
uint8 * | pu8Out | ||
) |
References tstrHashInfo::fpHash, HASH_ALG_MAX, HASH_ALG_NONE, i, M2M_MEMSET, NULL, SHA512_BLOCK_SIZE, SHA_FLAGS_FINISH, SHA_FLAGS_FULL_HASH, SHA_FLAGS_INIT, SHA_FLAGS_UPDATE, SHA_MAX_DIGEST_SIZE, tstrHashInfo::u16BlockSz, and tstrHashInfo::u16HashSz.
Referenced by hmac_md5(), hmac_sha1(), and HMAC_SHA256().
References M2M_MEMCPY, MD4_F, MD4_G, MD4_H, MD4_INERMEDIATE, and NULL.
Referenced by MD4_Hash().
void MD5_Hash | ( | tstrShaHashContext * | pstrMD5Cxt, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References MD5_HASH_SW.
void MD5_HashSW | ( | tstrHash512Context * | pstrMD5Context, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References tstrHash512Context::au32HashState, BYTE_0, BYTE_1, BYTE_2, BYTE_3, tstrHash512Context::fpHash, M2M_MEMSET, MD5_DIGEST_SIZE, MD5ProcessBlock(), NULL, SHA256_MSG_LENGTH, SHA_FLAGS_FINISH, SHA_FLAGS_INIT, SHA_FLAGS_UPDATE, Sha_HashFinish(), Sha_HashUpdate(), tstrHash512Context::u32TotalLength, tstrHash512Context::u8BlockSize, and tstrHash512Context::u8DigestSize.
References M2M_MEMCPY, MD5_F, MD5_G, MD5_H, MD5_I, MD5_INERMEDIATE, and T_MD5.
Referenced by MD5_HashSW().
void SHA1_Hash | ( | tstrShaHashContext * | pstrSha1Cxt, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References SHA1_HASH_SW.
void SHA1_HashSW | ( | tstrHash512Context * | pstrSha1Context, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References tstrHash512Context::au32HashState, tstrHash512Context::fpHash, M2M_MEMSET, NULL, PUTU32, SHA1_DIGEST_SIZE, SHA1ProcessBlock(), SHA256_MSG_LENGTH, SHA_BLOCK_SIZE, SHA_FLAGS_FINISH, SHA_FLAGS_INIT, SHA_FLAGS_UPDATE, Sha_HashFinish(), Sha_HashUpdate(), tstrHash512Context::u32TotalLength, tstrHash512Context::u8BlockSize, and tstrHash512Context::u8DigestSize.
References GETU32, K_SHA1, SHA1_CH, SHA1_INERMEDIATE, SHA1_MAJ, SHA_PARITY, and SHA_ROTL.
Referenced by SHA1_HashSW().
void SHA224_Hash | ( | tstrShaHashContext * | pstrSha224Cxt, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References SHA224_HASH_SW.
void SHA224_HashSW | ( | tstrHash512Context * | pstrSha224Cxt, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References tstrHash512Context::au32HashState, tstrHash512Context::fpHash, M2M_MEMSET, NULL, PUTU32, SHA224_DIGEST_SIZE, SHA256_MSG_LENGTH, SHA256ProcessBlock(), SHA_BLOCK_SIZE, SHA_FLAGS_FINISH, SHA_FLAGS_INIT, SHA_FLAGS_UPDATE, Sha_HashFinish(), Sha_HashUpdate(), tstrHash512Context::u32TotalLength, tstrHash512Context::u8BlockSize, and tstrHash512Context::u8DigestSize.
void SHA256_Hash | ( | tstrShaHashContext * | pstrSha256Cxt, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References SHA256_HASH_SW.
void SHA256_HashSW | ( | tstrHash512Context * | pstrSha256Context, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References tstrHash512Context::au32HashState, tstrHash512Context::fpHash, M2M_MEMSET, NULL, PUTU32, SHA256_DIGEST_SIZE, SHA256_MSG_LENGTH, SHA256ProcessBlock(), SHA_BLOCK_SIZE, SHA_FLAGS_FINISH, SHA_FLAGS_INIT, SHA_FLAGS_UPDATE, Sha_HashFinish(), Sha_HashUpdate(), tstrHash512Context::u32TotalLength, tstrHash512Context::u8BlockSize, and tstrHash512Context::u8DigestSize.
References K_SHA256, SHA256_CAP_SIGMA0, SHA256_CAP_SIGMA1, SHA256_CH, SHA256_MAJ, SHA256_SMALL_SIGMA0, and SHA256_SMALL_SIGMA1.
Referenced by SHA224_HashSW(), and SHA256_HashSW().
void SHA384_Hash | ( | tstrShaHashContext * | pstrSha384Cxt, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References SHA384_HASH_SW.
void SHA512_Hash | ( | tstrShaHashContext * | pstrSha512Cxt, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest | ||
) |
References SHA512_HASH_SW.
void SHA512_HashSW | ( | tstrHash512Context * | pstrSha512Context, |
uint8 | u8Flags, | ||
uint8 * | pu8Data, | ||
uint32 | u32DataLength, | ||
uint8 * | pu8Digest, | ||
uint8 | u8IsSHA384 | ||
) |
References tstrHash512Context::au32HashState, tstrHash512Context::fpHash, M2M_MEMSET, NULL, PUTU32, SHA384_DIGEST_SIZE, SHA512_BLOCK_SIZE, SHA512_DIGEST_SIZE, SHA512_MSG_LENGTH, SHA512ProcessBlock(), SHA_FLAGS_FINISH, SHA_FLAGS_INIT, SHA_FLAGS_UPDATE, Sha_HashFinish(), Sha_HashUpdate(), tstrHash512Context::u32TotalLength, tstrHash512Context::u8BlockSize, and tstrHash512Context::u8DigestSize.
References ADD_TWO_32BIT, GET_UINT64_BE, K_SHA512, M2M_MEMCPY, S0, S1, SHA512_CH_HIGH, SHA512_CH_LOW, SHA512_MAJ_HIGH, SHA512_MAJ_LOW, SHA_ROTR_64, and SHA_SHR_64.
Referenced by SHA512_HashSW().
void Sha_HashFinish | ( | tstrHash512Context * | pstrHashCxt, |
uint8 * | pu8LengthPadding, | ||
uint32 | u32TotalMessageLength | ||
) |
References tstrHash512Context::au32HashState, tstrHash512Context::au8CurrentBlock, tstrHash512Context::fpHash, M2M_MEMCPY, M2M_MEMSET, NULL, SHA_PAD_BYTE, tstrHash512Context::u32TotalLength, and tstrHash512Context::u8BlockSize.
Referenced by MD4_Hash(), MD5_HashSW(), SHA1_HashSW(), SHA224_HashSW(), SHA256_HashSW(), and SHA512_HashSW().
void Sha_HashUpdate | ( | tstrHash512Context * | pstrHashCxt, |
uint8 * | pu8Data, | ||
uint32 | u32DataLength | ||
) |
References tstrHash512Context::au32HashState, tstrHash512Context::au8CurrentBlock, tstrHash512Context::fpHash, M2M_MEMCPY, NULL, tstrHash512Context::u32TotalLength, and tstrHash512Context::u8BlockSize.
Referenced by MD4_Hash(), MD5_HashSW(), SHA1_HashSW(), SHA224_HashSW(), SHA256_HashSW(), and SHA512_HashSW().
tstrHashInfo eastrTlsHashes[] |
Referenced by Cert_ComputeTBSCertHash().
const uint32 K_SHA1[4] |
Referenced by SHA1ProcessBlock().
|
static |
Referenced by SHA256ProcessBlock().
|
static |
Referenced by SHA512ProcessBlock().
|
static |
Referenced by MD5ProcessBlock().