The Crypto header file should be included in an application as follows:
The crypto/include/reg_xxx.h has the register layer definitons for the Crypto Module.
Operation
The Crypto driver is used for AES and HMAC Hash functions. This driver provides API for
- AES Encrypt and Decrypt.
- HMAC hash Sign and Verify.
The application initializes the Crypto driver by calling Crypto_init() and is then ready to open a Crypto by calling Crypto_open().
The APIs in this driver serve as an interface to a typical TI-RTOS application. The specific peripheral implementations are responsible to create all the OSAL specific primitives to allow for thread-safe operation.
Opening the driver
if (!handle)
{
System_printf("Crypto driver open failed\n");
}
AES data encryption
Crypto_Params params;
unsigned char plainData[16] = "whatsoever123456";
unsigned int plainDataLen = sizeof(plainData);
unsigned char cipherData[16];
unsigned int cipherDataLen;
params.aes.keySize = desiredKeySize;
params.aes.ptrKey = (Crypto_KeyPtr)desiredKey;
params.aes.pIV = (void *)pointerToInitVector;
ret =
Crypto_encrypt(handle, mode , plainData, plainDataLen, cipherData , &cipherDataLen , ¶ms);
Generate HMAC Hash signature
Crypto_Params params;
unsigned char dataBuff[] = "whatsoever";
unsigned int dataLength = sizeof(dataBuff);
unsigned char signatureBuff[32];
params.ptrKey = pointerToHMACkey;
params.moreData = 0;
ret =
Crypto_sign(handle, mode, &dataBuff, dataLength, &signatureBuff, ¶ms);
Implementation
The Crypto driver interface module is joined (at link time) to a NULL-terminated array of Crypto_Config data structures named Crypto_config. Crypto_config is implemented in the application with each entry being an instance of a Crypto peripheral. Each entry in Crypto_config contains a:
- (void *) data object that is pointed to Crypto_Object