I'm using the AES library posted here and a curiosity to me is that the plaintext is:
byte plain[64] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
But after a run of encryption and decryption, this is what I see as decrypted:
decrypt 0
00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 E0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Done one block
97
D7 E9 62 F2 08 AD E0 52 C3 98 13 39 E4 E7 A1 31
F6 70 B0 7B 19 44 87 27 D6 4F CF 64 DB 69 7D FE
A9 0C 99 38 07 EF 99 59 47 BF BB C7 7A C2 12 9B
2A 90 B6 A3 42 75 01 9D 2E 8D 5C A8 F9 CB 69
Done one block
00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 E0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Done one block
9B
2A 90 B6 A3 42 75 01 9D 2E 8D 5C A8 F9 CB 69
Done one block
I've edited the example to print a little differently and some of the comments are mine but this is the output.
The relevant section of the code is this:
if (blocks == 1)
succ = aes.decrypt (cipher, plain) ;
else
{
for (byte i = 0 ; i < 16 ; i++)
iv[i] = my_iv[i] ;
succ = aes.cbc_decrypt (cipher, check, blocks, iv) ;
}
//t1 = micros () - t0 ;
Serial.println ("decrypt ") ; Serial.print ((int) succ) ;
//Serial.print (" took ") ; Serial.print (t1) ; Serial.println ("us") ;
for (byte ph = 0 ; ph < (blocks == 1 ? 3 : 4) ; ph++)
{
for (byte i = 0 ; i < (ph < 3 ? blocks*N_BLOCK : N_BLOCK) ; i++)
{
byte val = ph == 0 ? plain[i] : ph == 1 ? cipher[i] : ph == 2 ? check[i] : iv[i] ;
Serial.print (val>>4, HEX) ; Serial.print (val&15, HEX) ; Serial.print (" ") ;
// One byte finished decrypting at this point.
if( i % 16 == 0)
{
Serial.println();
}
}
Serial.println () ;
// One block finished decrypting.
Serial.print("Done one block");
Serial.println () ;
}
Serial.print("Done decrypt!");
I don't understand why it decrypts one 'block' as the correct plaintext, some random text in between and again the plaintext and some more random stuff after.
Also, I thought a 'block' in AES is the size of the table initially used, 16 bytes. So how is it that a 'block' here seems to be the entire 64 bytes of plaintext? And where is the other information even coming from?