add HC-128 Blake2b 256 cipher suite for speed test

This commit is contained in:
toddouska
2013-10-23 17:13:54 -07:00
parent 14f4162180
commit c039b0106a
10 changed files with 236 additions and 5 deletions

View File

@@ -43,8 +43,8 @@ static int InitHmac(Hmac* hmac, int type)
hmac->innerHashKeyed = 0;
hmac->macType = (byte)type;
if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384
|| type == SHA512))
if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384
|| type == SHA512 || type == BLAKE2B_ID))
return BAD_FUNC_ARG;
switch (type) {
@@ -78,6 +78,12 @@ static int InitHmac(Hmac* hmac, int type)
break;
#endif
#ifdef HAVE_BLAKE2
case BLAKE2B_ID:
InitBlake2b(&hmac->hash.blake2b, BLAKE2B_256);
break;
#endif
default:
break;
}
@@ -180,6 +186,22 @@ void HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
break;
#endif
#ifdef HAVE_BLAKE2
case BLAKE2B_ID:
{
hmac_block_size = BLAKE2B_BLOCKBYTES;
if (length <= BLAKE2B_BLOCKBYTES) {
XMEMCPY(ip, key, length);
}
else {
Blake2bUpdate(&hmac->hash.blake2b, key, length);
Blake2bFinal(&hmac->hash.blake2b, ip, BLAKE2B_256);
length = BLAKE2B_256;
}
}
break;
#endif
default:
break;
}
@@ -229,6 +251,13 @@ static void HmacKeyInnerHash(Hmac* hmac)
break;
#endif
#ifdef HAVE_BLAKE2
case BLAKE2B_ID:
Blake2bUpdate(&hmac->hash.blake2b,
(byte*) hmac->ipad,BLAKE2B_BLOCKBYTES);
break;
#endif
default:
break;
}
@@ -278,6 +307,12 @@ void HmacUpdate(Hmac* hmac, const byte* msg, word32 length)
break;
#endif
#ifdef HAVE_BLAKE2
case BLAKE2B_ID:
Blake2bUpdate(&hmac->hash.blake2b, msg, length);
break;
#endif
default:
break;
}
@@ -369,6 +404,20 @@ void HmacFinal(Hmac* hmac, byte* hash)
break;
#endif
#ifdef HAVE_BLAKE2
case BLAKE2B_ID:
{
Blake2bFinal(&hmac->hash.blake2b, (byte*) hmac->innerHash,
BLAKE2B_256);
Blake2bUpdate(&hmac->hash.blake2b,
(byte*) hmac->opad, BLAKE2B_BLOCKBYTES);
Blake2bUpdate(&hmac->hash.blake2b,
(byte*) hmac->innerHash, BLAKE2B_256);
Blake2bFinal(&hmac->hash.blake2b, hash, BLAKE2B_256);
}
break;
#endif
default:
break;
}