2025-07-01 2:00 AM
Hello,
I would like to use the X-CUBE-CRYPTOLIB to calculate a SHA256 with a key, i'm using STM32CubeIDE 1.18.0 for an STM32u083 microcontroller, STM32CubeExpansion_Crypto_V4.2.0.
The issue I have is the first time I call cmox_mac_compute the wrong result is returned.
cmox_init_arg_t init_target = {CMOX_INIT_TARGET_AUTO, NULL};
if (cmox_initialize(&init_target) != CMOX_INIT_SUCCESS)
{
Error_Handler();
}
uint8_t tResult[32] = {0};
uint8_t tMessage[63] = {153,234,98,104,200,115,43,208,16,24,124,106,63,66,15,0,0,0,0,0,250,191,113,33,0,0,0,0,0,0,0,53,231,216,222,211,203,112,30,58,145,125,101,150,57,215,149,108,50,229,247,80,239,35,157,119,19,121,218,120,231,50,70};
uint8_t tKey[32] = {173,182,187,187,244,184,224,88,49,224,82,119,184,125,189,202,255,179,154,153,213,5,120,138,162,120,25,250,40,96,170,122};
//Test 1
retval = cmox_mac_compute(CMOX_HMAC_SHA256_ALGO, // Use HMAC SHA256 algorithm
tMessage, sizeof(tMessage), // Message to authenticate
tKey,sizeof(tKey), //HMAC Key to use
NULL, 0, // Custom data
tResult, // Data buffer to receive generated authnetication tag
sizeof(tResult), // Expected authentication tag size
&computed_size);
//Test 2
retval = cmox_mac_compute(CMOX_HMAC_SHA256_ALGO, // Use HMAC SHA256 algorithm
tMessage, sizeof(tMessage), // Message to authenticate
tKey,sizeof(tKey), //HMAC Key to use
NULL, 0, // Custom data
tResult, // Data buffer to receive generated authnetication tag
sizeof(tResult), // Expected authentication tag size
&computed_size);
The test 1 result is
Solved! Go to Solution.
2025-07-02 12:27 PM
IIRC this is documented somewhere in the cryptolib. Practically, the user of cryptolib simply ignores existence of CRC: does not enable CRC in the cube, does not call __HAL_CRC_DR_RESET(hcrc) and so on.