Hi Keane,
The best way is to use "Csec_GenerateMacAddrMode" together with "Csec_VerifyMacAddrMode" when generating/checking a MAC on Program Flash. Those won’t work on Data Flash or on RAM. Due to nature of these commands, you will achieve better performance because “non-AddrMode” functions will be slower due to software overhead.
And similarly, use "Csec_GenerateMac" and "Csec_VerifyMac" when your data are in Data Flash or in RAM.
So yes, use them in a pair.
There could be a problem with endianness. SHE specification provides test vectors which can be used for comparison of the results
For CMAC, the values are:
KEY 2b7e151628aed2a6abf7158809cf4f3c
MESSAGE 6bc1bee22e409f96e93d7e117393172a
OUTPUT 070a16b46b4d4144f79bdd9dd04a287c
AN5401SW expects that the numbers are provided in this form:
uint32_t key[4] = {0x2b7e1516, 0x28aed2a6, 0xabf71588, 0x09cf4f3c};
uint32_t data[4] = {0x6bc1bee2, 0x2e409f96, 0xe93d7e11, 0x7393172a};
And SDK driver expect this format:
uint8_t key[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
uint8_t data[16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
The data are then stored in different order in the memory.
AN5401SW then works with the data as with 32bit words, SDK driver works with the data as with 8bit words, so the input data are swapped by the driver and the result is then also swapped.
Regards,
Lukas