Tizen 2.0 Release
[external/nettle.git] / testsuite / ctr-test.c
1 #include "testutils.h"
2 #include "aes.h"
3 #include "ctr.h"
4
5 int
6 test_main(void)
7 {
8   /* From NIST spec 800-38a on AES modes,
9    *
10    * http://csrc.nist.gov/CryptoToolkit/modes/800-38_Series_Publications/SP800-38A.pdf
11    *
12    * F.5  CTR Example Vectors
13    */
14
15   /* F.5.1  CTR-AES128.Encrypt */
16   test_cipher_ctr(&nettle_aes128,
17                   HL("2b7e151628aed2a6abf7158809cf4f3c"),
18                   HL("6bc1bee22e409f96e93d7e117393172a"
19                      "ae2d8a571e03ac9c9eb76fac45af8e51"
20                      "30c81c46a35ce411e5fbc1191a0a52ef"
21                      "f69f2445df4f9b17ad2b417be66c3710"),
22                   H("874d6191b620e3261bef6864990db6ce"
23                     "9806f66b7970fdff8617187bb9fffdff"
24                     "5ae4df3edbd5d35e5b4f09020db03eab"
25                     "1e031dda2fbe03d1792170a0f3009cee"),
26                   H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"));
27
28   /* F.5.3  CTR-AES192.Encrypt */
29   test_cipher_ctr(&nettle_aes192,
30                   HL("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"),
31                   HL("6bc1bee22e409f96e93d7e117393172a"
32                      "ae2d8a571e03ac9c9eb76fac45af8e51"
33                      "30c81c46a35ce411e5fbc1191a0a52ef"
34                      "f69f2445df4f9b17ad2b417be66c3710"),
35                   H("1abc932417521ca24f2b0459fe7e6e0b"
36                      "090339ec0aa6faefd5ccc2c6f4ce8e94"
37                      "1e36b26bd1ebc670d1bd1d665620abf7"
38                      "4f78a7f6d29809585a97daec58c6b050"),
39                   H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"));
40
41   /* F.5.5  CTR-AES256.Encrypt */
42   test_cipher_ctr(&nettle_aes256,
43                   HL("603deb1015ca71be2b73aef0857d7781"
44                      "1f352c073b6108d72d9810a30914dff4"),
45                   HL("6bc1bee22e409f96e93d7e117393172a"
46                      "ae2d8a571e03ac9c9eb76fac45af8e51"
47                      "30c81c46a35ce411e5fbc1191a0a52ef"
48                      "f69f2445df4f9b17ad2b417be66c3710"),
49                   H("601ec313775789a5b7a7f504bbf3d228"
50                      "f443e3ca4d62b59aca84e990cacaf5c5"
51                      "2b0930daa23de94ce87017ba2d84988d"
52                      "dfc9c58db67aada613c2dd08457941a6"),
53                   H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"));
54
55   SUCCESS();
56 }
57
58 /*
59   F.5.1  CTR-AES128.Encrypt
60   Key            2b7e151628aed2a6abf7158809cf4f3c
61   Init. Counter f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
62   Block #1
63   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
64   Output Block   ec8cdf7398607cb0f2d21675ea9ea1e4
65   Plaintext      6bc1bee22e409f96e93d7e117393172a
66   Ciphertext     874d6191b620e3261bef6864990db6ce
67   Block #2
68   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff00
69   Output Block   362b7c3c6773516318a077d7fc5073ae
70   Plaintext      ae2d8a571e03ac9c9eb76fac45af8e51
71   Ciphertext     9806f66b7970fdff8617187bb9fffdff
72   Block #3
73   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff01
74   Output Block   6a2cc3787889374fbeb4c81b17ba6c44
75   Plaintext      30c81c46a35ce411e5fbc1191a0a52ef
76   Ciphertext     5ae4df3edbd5d35e5b4f09020db03eab
77   Block #4
78   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff02
79   Output Block   e89c399ff0f198c6d40a31db156cabfe
80   Plaintext      f69f2445df4f9b17ad2b417be66c3710
81   Ciphertext     1e031dda2fbe03d1792170a0f3009cee
82   
83   F.5.2  CTR-AES128.Decrypt
84   Key            2b7e151628aed2a6abf7158809cf4f3c
85   Init. Counter f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
86   Block #1
87   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
88   Output Block   ec8cdf7398607cb0f2d21675ea9ea1e4
89   Ciphertext     874d6191b620e3261bef6864990db6ce
90   Plaintext      6bc1bee22e409f96e93d7e117393172a
91   Block #2
92   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff00
93   Output Block   362b7c3c6773516318a077d7fc5073ae
94   Ciphertext     9806f66b7970fdff8617187bb9fffdff
95   Plaintext      ae2d8a571e03ac9c9eb76fac45af8e51
96   Block #3
97   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff01
98   Output Block   6a2cc3787889374fbeb4c81b17ba6c44
99   Ciphertext     5ae4df3edbd5d35e5b4f09020db03eab
100   Plaintext      30c81c46a35ce411e5fbc1191a0a52ef
101   Block #4
102   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff02
103   Output Block   e89c399ff0f198c6d40a31db156cabfe
104   Ciphertext     1e031dda2fbe03d1792170a0f3009cee
105   Plaintext      f69f2445df4f9b17ad2b417be66c3710
106   
107   F.5.3  CTR-AES192.Encrypt
108   Key            8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b
109   Init. Counter f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
110   Block #1
111   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
112   Output Block   717d2dc639128334a6167a488ded7921
113   Plaintext      6bc1bee22e409f96e93d7e117393172a
114   Ciphertext     1abc932417521ca24f2b0459fe7e6e0b
115   Block #2
116   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff00
117   Output Block   a72eb3bb14a556734b7bad6ab16100c5
118   Plaintext      ae2d8a571e03ac9c9eb76fac45af8e51
119   Ciphertext     090339ec0aa6faefd5ccc2c6f4ce8e94
120   Block #3
121   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff01
122   Output Block   2efeae2d72b722613446dc7f4c2af918
123   Plaintext      30c81c46a35ce411e5fbc1191a0a52ef
124   Ciphertext     1e36b26bd1ebc670d1bd1d665620abf7
125   Block #4
126   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff02
127   Output Block   b9e783b30dd7924ff7bc9b97beaa8740
128   Plaintext      f69f2445df4f9b17ad2b417be66c3710
129   Ciphertext     4f78a7f6d29809585a97daec58c6b050
130   
131   F.5.4  CTR-AES192.Decrypt
132   Key            8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b
133   Init. Counter f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
134   Block #1
135   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
136   Output Block   717d2dc639128334a6167a488ded7921
137   Ciphertext     1abc932417521ca24f2b0459fe7e6e0b
138   Plaintext      6bc1bee22e409f96e93d7e117393172a
139   Block #2
140   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff00
141   Output Block   a72eb3bb14a556734b7bad6ab16100c5
142   Ciphertext     090339ec0aa6faefd5ccc2c6f4ce8e94
143   Plaintext      ae2d8a571e03ac9c9eb76fac45af8e51
144   Block #3
145   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff01
146   Output Block   2efeae2d72b722613446dc7f4c2af918
147   Ciphertext     1e36b26bd1ebc670d1bd1d665620abf7
148   Plaintext      30c81c46a35ce411e5fbc1191a0a52ef
149   Block #4
150   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff02
151   Output Block   b9e783b30dd7924ff7bc9b97beaa8740
152   Ciphertext     4f78a7f6d29809585a97daec58c6b050
153   Plaintext      f69f2445df4f9b17ad2b417be66c3710
154   
155   F.5.5  CTR-AES256.Encrypt
156   Key            603deb1015ca71be2b73aef0857d7781
157                  1f352c073b6108d72d9810a30914dff4
158   Init. Counter f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
159   Block #1
160   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
161   Output Block   0bdf7df1591716335e9a8b15c860c502
162   Plaintext      6bc1bee22e409f96e93d7e117393172a
163   Ciphertext     601ec313775789a5b7a7f504bbf3d228
164   Block #2
165   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff00
166   Output Block   5a6e699d536119065433863c8f657b94
167   Plaintext      ae2d8a571e03ac9c9eb76fac45af8e51
168   Ciphertext     f443e3ca4d62b59aca84e990cacaf5c5
169   Block #3
170   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff01
171   Output Block   1bc12c9c01610d5d0d8bd6a3378eca62
172   Plaintext      30c81c46a35ce411e5fbc1191a0a52ef
173   Ciphertext     2b0930daa23de94ce87017ba2d84988d
174   Block #4
175   Input Block    f0f1f2f3f4f5f6f7f8f9fafbfcfdff02
176   Output Block   2956e1c8693536b1bee99c73a31576b6
177   Plaintext      f69f2445df4f9b17ad2b417be66c3710
178   Ciphertext     dfc9c58db67aada613c2dd08457941a6
179   
180   F.5.6  CTR-AES256.Decrypt
181   Key            603deb1015ca71be2b73aef0857d7781
182                  1f352c073b6108d72d9810a30914dff4
183   Init. Counter f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
184   Block #1
185   Input Block  f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
186   Output Block 0bdf7df1591716335e9a8b15c860c502
187   Ciphertext   601ec313775789a5b7a7f504bbf3d228
188   Plaintext    6bc1bee22e409f96e93d7e117393172a
189   Block #2
190   Input Block  f0f1f2f3f4f5f6f7f8f9fafbfcfdff00
191   Output Block 5a6e699d536119065433863c8f657b94
192   Ciphertext   f443e3ca4d62b59aca84e990cacaf5c5
193   Plaintext    ae2d8a571e03ac9c9eb76fac45af8e51
194   Block #3
195   Input Block  f0f1f2f3f4f5f6f7f8f9fafbfcfdff01
196   Output Block 1bc12c9c01610d5d0d8bd6a3378eca62
197   Ciphertext   2b0930daa23de94ce87017ba2d84988d
198   Plaintext    30c81c46a35ce411e5fbc1191a0a52ef
199   Block #4
200   Input Block  f0f1f2f3f4f5f6f7f8f9fafbfcfdff02
201   Output Block 2956e1c8693536b1bee99c73a31576b6
202   Ciphertext   dfc9c58db67aada613c2dd08457941a6
203   Plaintext    f69f2445df4f9b17ad2b417be66c3710
204 */