This is starting to get extremely confusing. I've switched to a fresh MPC5777C and started over, but I'm completely failing to get results out of it. I've listed the code I've tried below. The CSE is displaying inconsistent behavior and most of the time ignoring commands and not throwing error codes about them.
ramkey and myMsg are 128-bit arrays initialized beforehand.
cipher and final are empty 128-bit arrays.
/* Load RAM key */
CSE.P1.R = (uint32_t)ramkey;
CSE.CMD.R = 0x08u;
waitCSE();
/* Encrypt message */
CSE.P1.R = 0xeu;
CSE.P2.R = 1u;
CSE.P3.R = (uint32_t)myMsg;
CSE.P4.R = (uint32_t)cipher;
CSE.CMD.R = 1u;
waitCSE();
/* Decrypt message */
CSE.P1.R = 0xeu;
CSE.P2.R = 1u;
CSE.P3.R = (uint32_t)cipher;
CSE.P4.R = (uint32_t)final;
CSE.CMD.R = 3u;
waitCSE();
waitCSE() is a stub function that just loops until the SR.BSY bit goes low. Here's one sequence of events that demonstrates what I'm trying to get at.
- I tried including the INIT command, but it gave an error code (0x2) for issuing an INIT after a secure boot or other initialization. This makes sense because the device is configured to try a secure boot. With this INIT command present, the encrypt and decrypt commands did not work.
- I removed the INIT command. The encrypt command failed, but the decrypt command executed and apparently "decrypted" the empty result from the encryption command.
- I made various changes that had nothing to do with the CSE (e.g. I modified some DCF records for the secure boot but there was no net change in the configuration). Now the encrypt command processes 64 bits of the message and the decrypt command does nothing.
I'm completely at a loss for what I'm missing; I'm doing nothing different from earlier successful experiments. What could be causing this behavior?