14.2.3.3.2 AES Engine

AES engine can be used to encrypt/decrypt stream of bytes. With APIs provided by HAL, it is possible to perform CBC/ECB - encryption/decryption the APIs HAL_AES_EncryptReq() and inputs are explained below with example

void HAL_AES_EncryptReq(HAL_AES_EncryptReq_t *reqParams_s)

The following actions in the enum, can be performed with the above API

/** Defines HAL AES commands such as setkey, cbc encrypt, cbc decrypt etc */
typedef enum
{
  SM_SET_KEY_COMMAND = 0,
  SM_ECB_ENCRYPT_COMMAND,
  SM_CBC_ENCRYPT_COMMAND,
  SM_ECB_DECRYPT_COMMAND,
  SM_CBC_DECRYPT_COMMAND,
} HAL_AesCmd_t;

1. To set the key in the AES engine before performing encryption/decryption

/* Declare a memory for Encrypt request*/
HAL_AES_EncryptReq_t  appSetKeyReq;

/* define a callback after key is set*/
void setAesKeyConf(void)
{
    .. 
}
appSetKeyReq.aesCmd = SM_SET_KEY_COMMAND;
appSetKeyReq.text = &key; // 16 bytes of key
appSetKeyReq.blockcount = 1; // 128-bit block
appSetKeyReq.encryptConf = setAesKeyConf;

HAL_AES_EncryptReq(&appSetKeyReq);

2. To perform ECB encryption after setting the key

/* Declare a memory for Encrypt request*/
HAL_AES_EncryptReq_t  appEncryptReq;

/* define a callback after key is set*/
void aesEncryptConf(void)
{
  // Action to be taken after the encryption is completed for a block
  ..
  .. 
}
appEncryptReq.aesCmd = SM_ECB_ENCRYPT_COMMAND;
appEncryptReq.text = &text; // 16 bytes of text to encrypt
appEncryptReq.blockcount = 1; // 128-bit block
appEncryptReq.encryptConf = aesEncryptConf;

HAL_AES_EncryptReq(&appEncryptReq);