Closed spinningarrow closed 10 years ago
"AES is a variant of Rijndael which has a fixed block size of 128 bits, and a key size of 128, 192, or 256 bits." (http://en.wikipedia.org/wiki/Advanced_Encryption_Standard)
You will have to update the data in blocks of 128 bits.
Try something like this:
// data[32]
aes256_encrypt_ecb(&ctxt, data); // encrypt first block of 128 bits in place
aes256_encrypt_ecb(&ctxt, data+16); // encrypt second block of 128 bits in place
DUMP("Encrypted data: ", i, data, sizeof(data));
aes256_decrypt_ecb(&ctxt, data); // decrypt first block of 128 bits in place
aes256_decrypt_ecb(&ctxt, data+16); // decrypt second block of 128 bits in place
DUMP("Back decrypted data: ", i, data, sizeof(data));
That helps; thank you!
Please be aware though that the described method performs ECB mode encryption.
Have a look at http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_.28ECB.29 for more details.
If I change the
data
in the examples to 32 bytes, for instance:the output on the serial monitor is:
As you can see, only the first 16 bytes are being encrypted (
7EE7EF984D51B1E3E1A31F8559988CF2
); the rest is still cleartext. Why is that?