blob: ce1cb7d0a44bd2116638f06369af7f0aae5a4605 [file] [log] [blame]
Paul Bakker367dae42009-06-28 21:50:27 +00001BEGIN_HEADER
2#include <polarssl/aes.h>
3END_HEADER
4
Paul Bakker5690efc2011-05-26 13:16:06 +00005BEGIN_DEPENDENCIES
6depends_on:POLARSSL_AES_C
7END_DEPENDENCIES
8
Paul Bakker367dae42009-06-28 21:50:27 +00009BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +020010aes_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
Paul Bakker367dae42009-06-28 21:50:27 +000011{
12 unsigned char key_str[100];
13 unsigned char src_str[100];
14 unsigned char dst_str[100];
15 unsigned char output[100];
16 aes_context ctx;
Paul Bakker69998dd2009-07-11 19:15:20 +000017 int key_len;
Paul Bakker367dae42009-06-28 21:50:27 +000018
19 memset(key_str, 0x00, 100);
20 memset(src_str, 0x00, 100);
21 memset(dst_str, 0x00, 100);
22 memset(output, 0x00, 100);
23
Paul Bakker69998dd2009-07-11 19:15:20 +000024 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakker367dae42009-06-28 21:50:27 +000025 unhexify( src_str, {hex_src_string} );
26
Paul Bakker2b222c82009-07-27 21:03:45 +000027 TEST_ASSERT( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == {setkey_result} );
28 if( {setkey_result} == 0 )
29 {
Paul Bakkerf3ccc682010-03-18 21:21:02 +000030 TEST_ASSERT( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
Paul Bakker2b222c82009-07-27 21:03:45 +000031 hexify( dst_str, output, 16 );
Paul Bakker367dae42009-06-28 21:50:27 +000032
Paul Bakker2b222c82009-07-27 21:03:45 +000033 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
34 }
Paul Bakker367dae42009-06-28 21:50:27 +000035}
36END_CASE
37
38BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +020039aes_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
Paul Bakker367dae42009-06-28 21:50:27 +000040{
41 unsigned char key_str[100];
42 unsigned char src_str[100];
43 unsigned char dst_str[100];
44 unsigned char output[100];
45 aes_context ctx;
Paul Bakker69998dd2009-07-11 19:15:20 +000046 int key_len;
Paul Bakker367dae42009-06-28 21:50:27 +000047
48 memset(key_str, 0x00, 100);
49 memset(src_str, 0x00, 100);
50 memset(dst_str, 0x00, 100);
51 memset(output, 0x00, 100);
52
Paul Bakker69998dd2009-07-11 19:15:20 +000053 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakker367dae42009-06-28 21:50:27 +000054 unhexify( src_str, {hex_src_string} );
55
Paul Bakker2b222c82009-07-27 21:03:45 +000056 TEST_ASSERT( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == {setkey_result} );
57 if( {setkey_result} == 0 )
58 {
Paul Bakkerf3ccc682010-03-18 21:21:02 +000059 TEST_ASSERT( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
Paul Bakker2b222c82009-07-27 21:03:45 +000060 hexify( dst_str, output, 16 );
Paul Bakker367dae42009-06-28 21:50:27 +000061
Paul Bakker2b222c82009-07-27 21:03:45 +000062 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
63 }
Paul Bakker367dae42009-06-28 21:50:27 +000064}
65END_CASE
66
67BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +020068aes_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
Paul Bakker367dae42009-06-28 21:50:27 +000069{
70 unsigned char key_str[100];
71 unsigned char iv_str[100];
72 unsigned char src_str[100];
73 unsigned char dst_str[100];
74 unsigned char output[100];
75 aes_context ctx;
Paul Bakkerf3ccc682010-03-18 21:21:02 +000076 int key_len, data_len;
Paul Bakker367dae42009-06-28 21:50:27 +000077
78 memset(key_str, 0x00, 100);
79 memset(iv_str, 0x00, 100);
80 memset(src_str, 0x00, 100);
81 memset(dst_str, 0x00, 100);
82 memset(output, 0x00, 100);
83
Paul Bakker69998dd2009-07-11 19:15:20 +000084 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakker367dae42009-06-28 21:50:27 +000085 unhexify( iv_str, {hex_iv_string} );
Paul Bakkerf3ccc682010-03-18 21:21:02 +000086 data_len = unhexify( src_str, {hex_src_string} );
Paul Bakker367dae42009-06-28 21:50:27 +000087
88 aes_setkey_enc( &ctx, key_str, key_len * 8 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +000089 TEST_ASSERT( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == {cbc_result} );
90 if( {cbc_result} == 0 )
91 {
92 hexify( dst_str, output, data_len );
Paul Bakker367dae42009-06-28 21:50:27 +000093
Paul Bakkerf3ccc682010-03-18 21:21:02 +000094 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
95 }
Paul Bakker367dae42009-06-28 21:50:27 +000096}
97END_CASE
98
99BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200100aes_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
Paul Bakker367dae42009-06-28 21:50:27 +0000101{
102 unsigned char key_str[100];
103 unsigned char iv_str[100];
104 unsigned char src_str[100];
105 unsigned char dst_str[100];
106 unsigned char output[100];
107 aes_context ctx;
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000108 int key_len, data_len;
Paul Bakker367dae42009-06-28 21:50:27 +0000109
110 memset(key_str, 0x00, 100);
111 memset(iv_str, 0x00, 100);
112 memset(src_str, 0x00, 100);
113 memset(dst_str, 0x00, 100);
114 memset(output, 0x00, 100);
115
Paul Bakker69998dd2009-07-11 19:15:20 +0000116 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakker367dae42009-06-28 21:50:27 +0000117 unhexify( iv_str, {hex_iv_string} );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000118 data_len = unhexify( src_str, {hex_src_string} );
Paul Bakker367dae42009-06-28 21:50:27 +0000119
120 aes_setkey_dec( &ctx, key_str, key_len * 8 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000121 TEST_ASSERT( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == {cbc_result} );
122 if( {cbc_result} == 0)
123 {
124 hexify( dst_str, output, data_len );
Paul Bakker367dae42009-06-28 21:50:27 +0000125
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000126 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
127 }
Paul Bakker367dae42009-06-28 21:50:27 +0000128}
129END_CASE
130
131BEGIN_CASE
132aes_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
133{
134 unsigned char key_str[100];
135 unsigned char iv_str[100];
136 unsigned char src_str[100];
137 unsigned char dst_str[100];
138 unsigned char output[100];
139 aes_context ctx;
Paul Bakkercd43a0b2011-06-09 13:55:44 +0000140 size_t iv_offset = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +0000141 int key_len;
Paul Bakker367dae42009-06-28 21:50:27 +0000142
143 memset(key_str, 0x00, 100);
144 memset(iv_str, 0x00, 100);
145 memset(src_str, 0x00, 100);
146 memset(dst_str, 0x00, 100);
147 memset(output, 0x00, 100);
148
Paul Bakker69998dd2009-07-11 19:15:20 +0000149 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakker367dae42009-06-28 21:50:27 +0000150 unhexify( iv_str, {hex_iv_string} );
151 unhexify( src_str, {hex_src_string} );
152
153 aes_setkey_enc( &ctx, key_str, key_len * 8 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000154 TEST_ASSERT( aes_crypt_cfb128( &ctx, AES_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +0000155 hexify( dst_str, output, 16 );
156
157 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
158}
159END_CASE
160
161BEGIN_CASE
162aes_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
163{
164 unsigned char key_str[100];
165 unsigned char iv_str[100];
166 unsigned char src_str[100];
167 unsigned char dst_str[100];
168 unsigned char output[100];
169 aes_context ctx;
Paul Bakkercd43a0b2011-06-09 13:55:44 +0000170 size_t iv_offset = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +0000171 int key_len;
Paul Bakker367dae42009-06-28 21:50:27 +0000172
173 memset(key_str, 0x00, 100);
174 memset(iv_str, 0x00, 100);
175 memset(src_str, 0x00, 100);
176 memset(dst_str, 0x00, 100);
177 memset(output, 0x00, 100);
178
Paul Bakker69998dd2009-07-11 19:15:20 +0000179 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakker367dae42009-06-28 21:50:27 +0000180 unhexify( iv_str, {hex_iv_string} );
181 unhexify( src_str, {hex_src_string} );
182
183 aes_setkey_enc( &ctx, key_str, key_len * 8 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000184 TEST_ASSERT( aes_crypt_cfb128( &ctx, AES_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +0000185 hexify( dst_str, output, 16 );
186
187 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
188}
189END_CASE
190
Paul Bakker3d360822009-07-05 11:29:38 +0000191BEGIN_CASE
192aes_selftest:
193{
194 TEST_ASSERT( aes_self_test( 0 ) == 0 );
195}
196END_CASE