Topic: HMAC MD5
I just load wolfSSL source code for the first time. Trying to use HMAC with MD5, in the Windows Visual Studio 2017 environment.
Found example for HMAC SHA256 on this page
https://www.wolfssl.com/docs/wolfssl-manual/ch10/
Modifyed to MD5
#include "wolfssl/wolfcrypt/hmac.h"
void printHex(const char* label, Uint8* data, Uint32 size)
{
printf("%s", label);
for (Uint8 i = 0; i < size; i++)
printf("%c%02x", i % 16 ? ' ' : '\n', data[i]);
printf("\n");
}
int main(void)
{
Uint8 key[MD4_DIGEST_SIZE];
wchar_t tmp[256] = L"Test string";
Uint8 digest[MD5_DIGEST_SIZE * 5];
Hmac hmac;
memset(key, 0x33, sizeof(key));
memset(digest, 0xAA, sizeof(digest));
printHex("digest 0 ", digest, sizeof(digest));
wc_HmacSetKey(&hmac, MD5, key, sizeof(key));
wc_HmacUpdate(&hmac, (const byte*)tmp, wcslen(tmp) * 2);
wc_HmacFinal(&hmac, digest + MD5_DIGEST_SIZE * 2);
printHex("digest 1", digest, sizeof(digest));
return 0;
}
Can you please give me a hint what i'm doing wrong, why does wc_HmacSetKey corrupting 'digest' variable? See bottom line in output bellow.
digest 0
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
digest 1
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
1b 20 7b b8 31 dd 2e 4e e3 bc 4a f2 83 94 ad 61
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
6f 6f 6f 6f 6f 6f 6f 6f 6f 6f 6f 6f 6f 6f 6f 6f