Hello Champs,
I'm looking for proven AES128 CBC example usnig CC26x2 driverlib in none RTOS enviroment.
Where can I find driverlib examples instead of TI-Drivers example designed for TI-RTOS enviroment?
Best Regards,
Richard Park
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello Champs,
I'm looking for proven AES128 CBC example usnig CC26x2 driverlib in none RTOS enviroment.
Where can I find driverlib examples instead of TI-Drivers example designed for TI-RTOS enviroment?
Best Regards,
Richard Park
Hi Richard,
There is no such example, what is is the TI Driver examples. Note that if you run using the NoRTOS DPL layer, you can re-use most/all of the TI Drivers provided in the SDK.
If you for some reason do not want to use the NoRTOS DPL layer, then you would need to put together the code yourself. In this case you could use the TI Driver as a a template on "how to use" the DriverLib API.
M-W,
I made simple example. Is this right way to use AES128 CBC with Driverlib? I got incorrect result from cryto. Maybe I miss something or make mistake in this souce code.
uint32_t aes128key[]={0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F}; uint32_t AES128nonce[]={0, 0, 0, 0}; uint32_t AES128input[]={0xD63D9304, 0x213DB5D6, 0x483A3D4E, 0xDE2AF431}; uint32_t AES128output[]={0x0, 0x0, 0x0, 0x0}; uint32_t result_AES128Enc[] ={0xA75BEC8A, 0xA618E1F2, 0x8A39EBD0, 0x4C2C2088}; uint32_t Des_AES128input[]= {0x11223344, 0x55667788, 0xAABBCCDD, 0x00FF00FF}; uint32_t Des_AES128output[]={0,0,0,0}; int Encrypt_strcmp =-1; int Decrypt_strcmp =-1; int crypto_ret = -1; PRCMPeripheralRunEnable(PRCM_PERIPH_CRYPTO); PRCMPeripheralSleepEnable(PRCM_PERIPH_CRYPTO); PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_CRYPTO); PRCMLoadSet(); while (!PRCMLoadGet()); //POWER ON CYPTO ENGINE// crypto_ret = CRYPTOAesLoadKey(aes128key, CRYPTO_KEY_AREA_0); if(crypto_ret == AES_SUCCESS){ while(CRYPTOAesCbc(AES128input, AES128output, 16, AES128nonce, CRYPTO_KEY_AREA_0, true, false)); Encrypt_strcmp = strcmp((char *)result_AES128Enc, (char *)AES128output); while(CRYPTOAesCbc(AES128output, Des_AES128output, 16, AES128nonce, CRYPTO_KEY_AREA_0, false, false)); Decrypt_strcmp = strcmp((char *) AES128input, (char *)Des_AES128output); } else while(1);
Best Regards,
Richard Park
Hi Richard,
I'm out of office today. I will check your code tomorrow and get back to you.
Hi Richard,
You should use the AES hardware that is available on the device, please see the example below for a DriverLib version of what you did above:
CryptoKey cryptoKey; // Test vector 0 from NIST CAPV set CBCMMT128 uint8_t iv[16] = {0x2f, 0xe2, 0xb3, 0x33, 0xce, 0xda, 0x8f, 0x98, 0xf4, 0xa9, 0x9b, 0x40, 0xd2, 0xcd, 0x34, 0xa8}; uint8_t plaintext[16] = {0x45, 0xcf, 0x12, 0x96, 0x4f, 0xc8, 0x24, 0xab, 0x76, 0x61, 0x6a, 0xe2, 0xf4, 0xbf, 0x08, 0x22}; uint8_t ciphertext[sizeof(plaintext)]; uint8_t keyingMaterial[16] = {0x1f, 0x8e, 0x49, 0x73, 0x95, 0x3f, 0x3f, 0xb0, 0xbd, 0x6b, 0x16, 0x66, 0x2e, 0x9a, 0x3c, 0x17}; // The cipher text should be the following after the encryption operation: uint8_t expected_cipherresult[16] = {0x0f, 0x61, 0xc4, 0xd4, 0x4c, 0x51, 0x47, 0xc0, 0x3c, 0x19, 0x5a, 0xd7, 0xe2, 0xcc, 0x12, 0xb2}; // The plain text should be the following after the decryption operation: uint8_t expected_plaintext[16] = {0x45, 0xcf, 0x12, 0x96, 0x4f, 0xc8, 0x24, 0xab, 0x76, 0x61, 0x6a, 0xe2, 0xf4, 0xbf, 0x08, 0x22}; int Encrypt_strcmp =-1; int Decrypt_strcmp =-1; PRCMPeripheralRunEnable(PRCM_PERIPH_CRYPTO); PRCMPeripheralSleepEnable(PRCM_PERIPH_CRYPTO); PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_CRYPTO); PRCMLoadSet(); while (!PRCMLoadGet()); //POWER ON CYPTO ENGINE// while(AESWriteToKeyStore(keyingMaterial, 16, AES_KEY_AREA_6) != AES_SUCCESS); AESSelectAlgorithm(AES_ALGSEL_AES); while(AESReadFromKeyStore(AES_KEY_AREA_6) != AES_SUCCESS); AESSetInitializationVector((uint32_t *)iv); /* Encrypt */ AESSetCtrl(CRYPTO_AESCTL_CBC | CRYPTO_AESCTL_SAVE_CONTEXT | CRYPTO_AESCTL_DIR); AESSetDataLength(sizeof(plaintext)); AESSetAuthLength(0); AESIntUnregister(); AESStartDMAOperation(plaintext, sizeof(plaintext), ciphertext, sizeof(plaintext)); /* Wait for it to finish */ if (AESWaitForIRQFlags(AES_RESULT_RDY | AES_DMA_BUS_ERR) & AES_DMA_BUS_ERR) { while(1); } AESIntClear(AES_RESULT_RDY | AES_DMA_IN_DONE | AES_DMA_BUS_ERR); /* Check result */ Encrypt_strcmp = memcmp((char *)ciphertext, (char *)expected_cipherresult, sizeof(plaintext)); /* Decrypt */ memset(plaintext, 0, sizeof(plaintext)); AESSetCtrl(CRYPTO_AESCTL_CBC | CRYPTO_AESCTL_SAVE_CONTEXT); AESSetInitializationVector((uint32_t *)iv); AESSetDataLength(sizeof(plaintext)); AESSetAuthLength(0); AESStartDMAOperation(ciphertext, sizeof(plaintext), plaintext, sizeof(plaintext)); /* Wait for it to finish */ while(AESWaitForIRQFlags(AES_RESULT_RDY | AES_DMA_BUS_ERR) & AES_DMA_BUS_ERR); /* Check result */ Decrypt_strcmp = memcmp((char *)plaintext, (char *)expected_plaintext, sizeof(plaintext)); while(1);