2021-03-11 11:58 AM
Hello everyone,
I was wondering the proper way to use the STM32_CHACHA_20_Encrypt() and STM32_CHACHA_20_Decrypt() functions available on the ST CryptoLib. I run the standard demo code on a STM32F072C8 MCU and it apparently run correctly, returning PASSED on the Buffercmp() that compares the function outputs to the expected const arrays declared statically.
Then I wrote a small code snipped, to encrypt a 'Test' buffer and decrypts it in sequence:
---------------------
Plaintext[0] = 'T';
Plaintext[1] = 'e';
Plaintext[2] = 's';
Plaintext[3] = 'T';
// Encrypt
status = STM32_CHACHA_20_Encrypt( (uint8_t *) Plaintext, 4, Key, IV, sizeof(IV), OutputMessage, &OutputMessageLength);
// Copy encrypted output into Plaintext buffer
for(idx=0;idx<4;idx++) Plaintext[idx] = OutputMessage[idx];
// Decrypt
status = STM32_CHACHA_20_Decrypt( (uint8_t *) Plaintext, 4, Key, IV, sizeof(IV), OutputMessage, &OutputMessageLength);
// Copy deencrypted output back into Plaintext buffer
for(idx=0;idx<4;idx++) Plaintext[idx] = OutputMessage[idx];
--------------------------------------------
The code returns and encrypted buffer of 0x85 0xCE 0x85 0x64, but when I try to decrypt it, it does not work as expected, returning 0x1A 0x63 0x71 0x6D.
Does anyone have experience using these functions of the CryptoLib?
Gabriel
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.