Hello Mohan,
Please find below an explanation for each of the functions mentioned by you.
initFlashForCsecOperation(void):
- checks if the Flash was partitioned for CSEc operation;
- if not, partition the Flash and select the number of user keys - FLASH_DRV_DEFlashPartition(&flashSSDConfig, 0x2, 0x4, 0x3, false, true);
- the 0x3 parameter specifies that there will be 24 available user keys; for more details, please see the documentation of the FLASH_DRV_DEFlashPartition function.
setAuthKey(void):
- this function sets the MASTER_ECU key with the value of g_authIdKey (in the csec_utils.c source file);
- in order to be able to configure a non-volatile key, a secret (the value of the key) must be known; in this case, we will use the MASTER_ECU key (which can be used for updating any of the keys) as our secret when setting up the user keys;
- this function will compute the M1-M3 values according to the SHE specification and then load the key by passing the computed values to the CSEC_DRV_LoadKey function;
- in order to compute the values, the computeM1M2M3 function is used, receiving as first parameter g_emptyKey, as the first time we load the MASTER_ECU key, coming from a clean state, the slot will be empty.
loadKey(CSEC_KEY_1, key, 1):
- this function will load the first user key with the value specified by the key parameter;
- the last parameter, the counter, needs to be incremented each time you update the key; the CSEc module will not update the key if the counter is <= the previous counter used when storing the key;
- this function will also compute the M1-M3 values according to the SHE specification and then load the key by passing the computed values to the CSEC_DRV_LoadKey function;
- the first parameter of computeM1M2M3 will be g_authIdKey, as we are using the value of MASTER_ECU as the secret needed when updating the key.
CSEC_DRV_EncryptECB(CSEC_KEY_1, plainText, 16, cipherText):
- this function will encrypt the plainText using the user key loaded previously and output the result into the cipherText parameter;
- the plain text will be encrypted using AES-128 with the ECB mode of chaining.
Please note that if you plan to use another MASTER_ECU key, you should first erase the keys by updating the value of the ERASE_ALL_KEYS macro to 1.
I hope this answers your question. If not, let me know and I will go into more detail.
Best regards,
Veronica