/ tests / test-aes.cpp
test-aes.cpp
 1  #include <cassert>
 2  #include <inttypes.h>
 3  #include <string.h>
 4  
 5  #include "Crypto.h"
 6  
 7  uint8_t ecb_key1[32] =
 8  {
 9      0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
10      0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
11  };
12  
13  uint8_t ecb_plain1[16] =
14  {
15      0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
16  };
17  
18  uint8_t ecb_cipher1[16] = 
19  {
20      0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c, 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8
21  };
22  
23  uint8_t cbc_key1[32] =
24  {
25      0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
26      0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
27  };
28  
29  uint8_t cbc_iv1[16] =
30  {
31      0xF5, 0x8C, 0x4C, 0x04, 0xD6, 0xE5, 0xF1, 0xBA, 0x77, 0x9E, 0xAB, 0xFB, 0x5F, 0x7B, 0xFB, 0xD6
32  };
33  
34  uint8_t cbc_plain1[16] =
35  {
36      0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51
37  };
38  
39  uint8_t cbc_cipher1[16] = 
40  {
41      0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d, 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d
42  };
43  
44  int main ()
45  {
46      // ECB encrypt test1
47      i2p::crypto::ECBEncryption ecbencryption;
48      ecbencryption.SetKey (ecb_key1);
49      uint8_t out[16];
50      ecbencryption.Encrypt (ecb_plain1, out);
51      assert (memcmp (ecb_cipher1, out, 16) == 0);
52  
53      // ECB decrypt test1
54      i2p::crypto::ECBDecryption ecbdecryption;
55      ecbdecryption.SetKey (ecb_key1);
56      ecbdecryption.Decrypt (ecb_cipher1, out);
57      assert (memcmp (ecb_plain1, out, 16) == 0);
58      // CBC encrypt test
59      i2p::crypto::CBCEncryption cbcencryption;
60      cbcencryption.SetKey (cbc_key1);
61      cbcencryption.Encrypt (cbc_plain1, 16, cbc_iv1, out);
62      assert (memcmp (cbc_cipher1, out, 16) == 0);
63      // CBC decrypt test
64      i2p::crypto::CBCDecryption cbcdecryption;
65      cbcdecryption.SetKey (cbc_key1);
66      cbcdecryption.Decrypt (cbc_cipher1, 16, cbc_iv1, out);
67      assert (memcmp (cbc_plain1, out, 16) == 0);
68  }
69