forked from wolfSSL/wolfssl
add hmac sha512
This commit is contained in:
@@ -42,7 +42,8 @@ static int InitHmac(Hmac* hmac, int type)
|
||||
hmac->innerHashKeyed = 0;
|
||||
hmac->macType = (byte)type;
|
||||
|
||||
if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384))
|
||||
if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384
|
||||
|| type == SHA512))
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
switch (type) {
|
||||
@@ -70,6 +71,12 @@ static int InitHmac(Hmac* hmac, int type)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
InitSha512(&hmac->hash.sha512);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -156,6 +163,22 @@ void HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
{
|
||||
hmac_block_size = SHA512_BLOCK_SIZE;
|
||||
if (length <= SHA512_BLOCK_SIZE) {
|
||||
XMEMCPY(ip, key, length);
|
||||
}
|
||||
else {
|
||||
Sha512Update(&hmac->hash.sha512, key, length);
|
||||
Sha512Final(&hmac->hash.sha512, ip);
|
||||
length = SHA512_DIGEST_SIZE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -198,6 +221,13 @@ static void HmacKeyInnerHash(Hmac* hmac)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
Sha512Update(&hmac->hash.sha512,
|
||||
(byte*) hmac->ipad, SHA512_BLOCK_SIZE);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -241,6 +271,12 @@ void HmacUpdate(Hmac* hmac, const byte* msg, word32 length)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
Sha512Update(&hmac->hash.sha512, msg, length);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -317,6 +353,21 @@ void HmacFinal(Hmac* hmac, byte* hash)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_SHA512
|
||||
case SHA512:
|
||||
{
|
||||
Sha512Final(&hmac->hash.sha512, (byte*) hmac->innerHash);
|
||||
|
||||
Sha512Update(&hmac->hash.sha512,
|
||||
(byte*) hmac->opad, SHA512_BLOCK_SIZE);
|
||||
Sha512Update(&hmac->hash.sha512,
|
||||
(byte*) hmac->innerHash, SHA512_DIGEST_SIZE);
|
||||
|
||||
Sha512Final(&hmac->hash.sha512, hash);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user