Skip to main content
MMarq
Associate
September 24, 2019
Question

STM32F756 MD5 hash wrong result

  • September 24, 2019
  • 2 replies
  • 929 views

I'm using the hardware hash processor of an STM32F756 to calculate the MD5 of string "user:realm:password", but the result is wrong. I'm using the HAL library, this is my code.

static void AuthRespCalc(char * username, char *realm, char * password)
{
 uint8_t hash[16];
 
 /* HA1 -> HA1=MD5(username:realm:password) */
 HASH_Init();
 HAL_HASH_MD5_Accumulate(&hhash, (uint8_t *) username, strlen(username));
 HAL_HASH_MD5_Accumulate(&hhash, (uint8_t *) ":", 1);
 HAL_HASH_MD5_Accumulate(&hhash, (uint8_t *) realm, strlen(realm));
 HAL_HASH_MD5_Accumulate(&hhash, (uint8_t *) ":", 1);
 HAL_HASH_MD5_Start(&hhash, (uint8_t *) password, strlen(password), hash, 0xFF);
 
 HAL_HASH_DeInit(&hhash);
}

I'm doing something wrong? Has anyone faced the same problem?

Thanks for any help.

This topic has been closed for replies.

2 replies

Tesla DeLorean
Guru
September 24, 2019

Doesn't the Accumulate routine expect buffers with a multiple of 4-bytes?

You either need to manage the buffering differently, or frankly concatenate the entire phrase, and pass that as a singular call to HAL_HASH_MD5_Start.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
MMarq
MMarqAuthor
Associate
September 25, 2019

You're absolutely right! I didn't noticed the note in the HASH_Accumulate function...

 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
 * HASH digest computation is corrupted.

Thanks for the help.