cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F756 MD5 hash wrong result

MMarq
Associate

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.

2 REPLIES 2

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
MMarq
Associate

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.