I have got some problems trying to programm the HMAC_MD5 code.
I am working in C on a STM32F4 microprocessor.
Here is my (updated) code:
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_HASH, ENABLE); static uint8_t
static Challenge[16] = "ldopwhjtsnkiaq8f";
static uint8_t Key[16] = "abcdefghijklmnop";
static uint8_t* HMAC_Key;
static uint8_t* HMAC_Input;
static uint8_t HMAC_Response1[16];
static uint8_t HMAC_Response2[16];
int m = 0;
HMAC_Input = &Challenge[0];
HMAC_Key = &Key[0];
ErrorStatus Result = ERROR;
for(m=0;m<16;m++){
HMAC_Response1[m]=1;
HMAC_Response2[m]=2;
}
Result = HASH_MD5(HMAC_Input, 16, HMAC_Response1);
Result = HMAC_MD5(HMAC_Key, 16, HMAC_Input, 16, HMAC_Response2);
That is the official description of the HMAC_MD5 function (https://github.com/espruino/Espruino/blob/master/targetlibs/stm32f4/lib/stm32f4xx_hash_md5.c):
/**
* @brief Compute the HMAC MD5 digest.
* @param Key: pointer to the Key used for HMAC.
* @param Keylen: length of the Key used for HMAC.
* @param Input: pointer to the Input buffer to be treated.
* @param Ilen: length of the Input buffer
* @param Output: the returned digest
* @retval An ErrorStatus enumeration value:
* - SUCCESS: digest computation done
* - ERROR: digest computation failed
*/
ErrorStatus HMAC_MD5(uint8_t *Key, uint32_t Keylen, uint8_t *Input,
uint32_t Ilen, uint8_t Output[16])
The function returns the value "SUCCESS" but the digest "Output" is still empty (full of '\0').
I don't get any warning from the compiler (Attolic TrueStudio) and I cannot change the value of the Key or of the Challenge (Concatenation), because the server is already running with older systems.
Let me guess. You're using STM32F405 or STM32F407, right? These parts lack the hash processor, and thus always return zeros for the digest. ST kind of documented it by opening the section on hash processor in the manual with "This section applies to STM32F415/417xx and STM32F43xxx devices.", but a quick Google search demonstrates that you are not the first person that expected this sort of information to be present in a more prominent place (datasheet, family comparison doc, product selector, etc).
And yes, I fully agree that an MCU with a missing hash processor should not report success on operations that use said hash processor, but that's apparently not how folks at ST roll.
Anyway. You will need to upgrade to SMT32F415 (or STM32F417) to get hardware accelerated hashing. If that's not an option, well, there is always a software implementation.