Test Specification for Hal Crypto Chibios Hal Crypto Test Suite. Test suite for ChibiOS Crypto Hal. The purpose of this suite is to perform unit tests on the Hal Crypto and to converge to 100% code coverage through successive improvements. cry_ > 8u ) | ( (v & 0xff000000) >> 24u ); } #endif void cryptoTest_setStream(BaseSequentialStream * s) { ts = s; } void cryptoTest_printArray(const uint8_t *a,size_t len) { #if CRYPTO_LOG_LEVEL == 1 for(size_t i=0;i Internal Tests AES ECB AES ECB #include "ref_aes.h" static const CRYConfig config_Polling = { TRANSFER_POLLING, AES_CFBS_128 //cfbs }; static const CRYConfig config_DMA = { TRANSFER_DMA, AES_CFBS_128 //cfbs }; ]]> AES ECB Polling testing AES ECB with various Keys loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt loading the key with 32 byte size Encrypt Decrypt AES ECB DMA testing AES ECB with various Keys loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt loading the key with 32 byte size Encrypt Decrypt Internal Tests AES CFB AES CFB #include "ref_aes.h" static const CRYConfig config_Polling = { TRANSFER_POLLING, AES_CFBS_128 //cfbs }; static const CRYConfig config_DMA = { TRANSFER_DMA, AES_CFBS_128 //cfbs }; ]]> AES CFB Polling testing AES CFB with various Keys loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt loading the key with 32 byte size Encrypt Decrypt AES CFB DMA testing AES CFB with various Keys loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt loading the key with 32 byte size Encrypt Decrypt Internal Tests AES CBC AES CBC #include "ref_aes.h" static const CRYConfig config_Polling = { TRANSFER_POLLING, AES_CFBS_128 //cfbs }; static const CRYConfig config_DMA = { TRANSFER_DMA, AES_CFBS_128 //cfbs }; ]]> AES CBC Polling testing AES CBC with various Keys loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt loading the key with 32 byte size Encrypt Decrypt AES CBC DMA testing AES CBC with various Keys loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt loading the key with 32 byte size Encrypt Decrypt Internal Tests (T)DES (T)DES testing #include "ref_des.h" static const CRYConfig configDES_Polling= { TRANSFER_POLLING, 0 }; static const CRYConfig configDES_DMA= { TRANSFER_DMA, 0 }; ]]> DES Polling testing DES in polled mode loading the key with 8 byte size Encrypt Decrypt TDES CBC Polling testing TDES CBC in polled mode loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt TDES ECB Polling testing TDES ECB in polling mode loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt TDES CBC DMA testing TDES CBC in polled mode loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt TDES ECB DMA testing TDES ECB in DMA mode loading the key with 16 byte size Encrypt Decrypt loading the key with 24 byte size Encrypt Decrypt Internal Tests TRNG TRNG testing static const CRYConfig configTRNG_Polling= { TRANSFER_POLLING, 0 }; ]]> TRNG Polling testing TRNG in polled mode Random generation and test Internal Tests SHA SHA testing #include "ref_sha.h" /* Buffer size for each SHA transfer, size should be multiple of block size (block size: 64 for SHA_1/SHA_256/SHA_224, 128 for SHA_384/SHA_512) */ #define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN #define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4) #define shabuffer msg_decrypted #define MAX_DIGEST_SIZE_INBYTE TEST_MSG_DATA_BYTE_LEN #define MAX_DIGEST_SIZE_INWORD (MAX_DIGEST_SIZE_INBYTE/4) #define digest msg_encrypted static const CRYConfig configSHA_Polling= { TRANSFER_POLLING, 0 }; static cryerror_t crySHA1(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) { cryerror_t ret; SHA1Context shactxp; shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0]; shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE; ret = crySHA1Init(cryp,&shactxp); ret = crySHA1Update(cryp,&shactxp,size,in); ret = crySHA1Final(cryp,&shactxp,out); return ret; } static cryerror_t crySHA256(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) { cryerror_t ret; SHA256Context shactxp; shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0]; shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE; ret = crySHA256Init(cryp,&shactxp); ret = crySHA256Update(cryp,&shactxp,size,in); ret = crySHA256Final(cryp,&shactxp,out); return ret; } static cryerror_t crySHA512(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) { cryerror_t ret; SHA512Context shactxp; shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0]; shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE; ret = crySHA512Init(cryp,&shactxp); ret = crySHA512Update(cryp,&shactxp,size,in); ret = crySHA512Final(cryp,&shactxp,out); return ret; } ]]> SHA1 Polling testing SHA1 in polled mode Digest SHA256 Polling testing SHA256 in polled mode Digest SHA512 Polling testing SHA512 in polled mode Digest Internal Tests SHA SHA testing #include "ref_sha.h" /* Buffer size for each SHA transfer, size should be multiple of block size (block size: 64 for SHA_1/SHA_256/SHA_224, 128 for SHA_384/SHA_512) */ #define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN #define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4) #define shabuffer msg_decrypted #define MAX_DIGEST_SIZE_INBYTE TEST_MSG_DATA_BYTE_LEN #define MAX_DIGEST_SIZE_INWORD (MAX_DIGEST_SIZE_INBYTE/4) #define digest msg_encrypted static const CRYConfig configSHA_DMA= { TRANSFER_DMA, 0 }; static cryerror_t crySHA1(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) { cryerror_t ret; SHA1Context shactxp; shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0]; shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE; ret = crySHA1Init(cryp,&shactxp); ret = crySHA1Update(cryp,&shactxp,size,in); ret = crySHA1Final(cryp,&shactxp,out); return ret; } static cryerror_t crySHA256(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) { cryerror_t ret; SHA256Context shactxp; shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0]; shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE; ret = crySHA256Init(cryp,&shactxp); ret = crySHA256Update(cryp,&shactxp,size,in); ret = crySHA256Final(cryp,&shactxp,out); return ret; } static cryerror_t crySHA512(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) { cryerror_t ret; SHA512Context shactxp; shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0]; shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE; ret = crySHA512Init(cryp,&shactxp); ret = crySHA512Update(cryp,&shactxp,size,in); ret = crySHA512Final(cryp,&shactxp,out); return ret; } ]]> SHA1 DMA testing SHA1 in DMA mode Digest SHA256 DMA testing SHA256 in DMA mode Digest SHA512 DMA testing SHA512 in DMA mode Digest Internal Tests GCM GCM testing #include "ref_gcm.h" #define plaintext msg_clear #define cypher msg_encrypted #define authtag msg_decrypted static const CRYConfig config_Polling= { TRANSFER_POLLING, 0 }; static const CRYConfig config_DMA= { TRANSFER_DMA, 0 }; struct test_el_t { uint32_t size; const uint8_t * data; }; struct test_gcm_t { struct test_el_t key; struct test_el_t p; struct test_el_t iv; struct test_el_t aad; struct test_el_t c; struct test_el_t t; }; #define TEST_GCM_LEN 3 const struct test_gcm_t test_gcm_k[TEST_GCM_LEN]={ { {K3_LEN,K3},{P3_LEN,P3},{IV3_LEN,IV3},{AAD3_LEN,A3},{C3_LEN,C3},{T3_LEN,T3} }, { {K4_LEN,K4},{P4_LEN,P4},{IV4_LEN,IV4},{AAD4_LEN,A4},{C4_LEN,C4},{T4_LEN,T4} }, { {K5_LEN,K5},{P5_LEN,P5},{IV5_LEN,IV5},{AAD5_LEN,A5},{C5_LEN,C5},{T5_LEN,T5} } }; ]]> GCM Polling testing GCM in polled mode loading the key, encrypt and decrypt GCM DMA testing GCM in DMA mode loading the key, encrypt and decrypt