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.
I had the same problem that you had using STM32 Hashing hardware. After a few tries I decided to use a md5 library
Since I'm using lwip in my project I noticed that LWIP has a md5 module inside ppp.
Just get the files needed (md5.c, md5.h) from lwip (inside lwip /src/netif/ppp/md5.c), and copy it to your proyect.
Change the non-working line
for
Edited: Since i dont use ppp in the project, i have copied the md5 file from ppp to the project and I edited it a bit, removing all include references (except md5.h and string.h) and removing conditional compilation:
This is the stuff that I removed at the beginning
And this at the end:
You can download the source code for md5.c and md5.h here
https://github.com/goertzenator/lwip/blob/master/lwip-1.4.0/src/netif/ppp/md5.c https://github.com/goertzenator/lwip/blob/master/lwip-1.4.0/src/netif/ppp/md5.h