2019-09-24 09:03 AM
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.
2019-09-24 10:29 AM
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.
2019-09-25 02:26 AM
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.