oresat / oresat-firmware

OreSat firmware based on ChibiOS for M0 and M4 microcontrollers
GNU General Public License v3.0
37 stars 13 forks source link

Implement ChibiOS HMACSHA256 driver, tests #70

Closed ThirteenFish closed 2 years ago

ThirteenFish commented 2 years ago

This adds a ChibiOS patch file, similar to the efl driver for HMACSHA256 and turns on the necessary flags in halconf.h and mcuconf.h to use it in the app_control project. It also adds a cli test that runs through the RFC 4231 test cases for HMAC, which can also serve as an example of use.

Typical usage looks like:

HMACSHA256Context ctx = {0};
cryLoadHMACTransientKey(cryp, keylen, key);
cryHMACSHA256Init(cryp, &ctx));
cryHMACSHA256Update(cryp, &ctx, datalen, data);
<repeat calls to Update() as necessary>
uint8_t out[32] = {0};
cryHMACSHA256Final(cryp, &ctx, out);

Note that out must be 32 bytes, that key must still exist in the same place at the time Final() is called, and, except for the last call to Update(), data must be a multiple of the word length (4 bytes). Also note that the driver does not yet implement DMA.

The test can be run from the C3 CLI by issuing hmac as a command.

If the driver were to be submitted upstream it should probably be split into two parts, the first of which is the configuration changes necessary to get ChibiOS to compile when USE_CRYP1 is FALSE and USE_HASH1 is TRUE