blob: a7e678574fffd6a0e1cc27e008ab2200bfe4b295 [file] [log] [blame]
Paul Bakkera9379c02012-07-04 11:02:11 +00001BEGIN_HEADER
2#include "polarssl/blowfish.h"
3END_HEADER
4
5BEGIN_DEPENDENCIES
6depends_on:POLARSSL_BLOWFISH_C
7END_DEPENDENCIES
8
9BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +020010blowfish_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
Paul Bakkera9379c02012-07-04 11:02:11 +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 blowfish_context ctx;
17 int key_len;
18
19 memset(key_str, 0x00, 100);
20 memset(src_str, 0x00, 100);
21 memset(dst_str, 0x00, 100);
22 memset(output, 0x00, 100);
23
24 key_len = unhexify( key_str, {hex_key_string} );
25 unhexify( src_str, {hex_src_string} );
26
27 TEST_ASSERT( blowfish_setkey( &ctx, key_str, key_len * 8 ) == {setkey_result} );
28 if( {setkey_result} == 0 )
29 {
30 TEST_ASSERT( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
31 hexify( dst_str, output, 8 );
32
33 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
34 }
35}
36END_CASE
37
38BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +020039blowfish_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result
Paul Bakkera9379c02012-07-04 11:02:11 +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 blowfish_context ctx;
46 int key_len;
47
48 memset(key_str, 0x00, 100);
49 memset(src_str, 0x00, 100);
50 memset(dst_str, 0x00, 100);
51 memset(output, 0x00, 100);
52
53 key_len = unhexify( key_str, {hex_key_string} );
54 unhexify( src_str, {hex_src_string} );
55
56 TEST_ASSERT( blowfish_setkey( &ctx, key_str, key_len * 8 ) == {setkey_result} );
57 if( {setkey_result} == 0 )
58 {
59 TEST_ASSERT( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
60 hexify( dst_str, output, 8 );
61
62 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
63 }
64}
65END_CASE
66
67BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +020068blowfish_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
Paul Bakkera9379c02012-07-04 11:02:11 +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 blowfish_context ctx;
76 int key_len, data_len;
77
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
84 key_len = unhexify( key_str, {hex_key_string} );
85 unhexify( iv_str, {hex_iv_string} );
86 data_len = unhexify( src_str, {hex_src_string} );
87
88 blowfish_setkey( &ctx, key_str, key_len * 8 );
89
90 TEST_ASSERT( blowfish_crypt_cbc( &ctx, BLOWFISH_ENCRYPT, data_len , iv_str, src_str, output ) == {cbc_result} );
91 if( {cbc_result} == 0 )
92 {
93 hexify( dst_str, output, data_len );
94
95 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
96 }
97}
98END_CASE
99
100BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200101blowfish_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result
Paul Bakkera9379c02012-07-04 11:02:11 +0000102{
103 unsigned char key_str[100];
104 unsigned char iv_str[100];
105 unsigned char src_str[100];
106 unsigned char dst_str[100];
107 unsigned char output[100];
108 blowfish_context ctx;
109 int key_len, data_len;
110
111 memset(key_str, 0x00, 100);
112 memset(iv_str, 0x00, 100);
113 memset(src_str, 0x00, 100);
114 memset(dst_str, 0x00, 100);
115 memset(output, 0x00, 100);
116
117 key_len = unhexify( key_str, {hex_key_string} );
118 unhexify( iv_str, {hex_iv_string} );
119 data_len = unhexify( src_str, {hex_src_string} );
120
121 blowfish_setkey( &ctx, key_str, key_len * 8 );
122 TEST_ASSERT( blowfish_crypt_cbc( &ctx, BLOWFISH_DECRYPT, data_len , iv_str, src_str, output ) == {cbc_result} );
123 if( {cbc_result} == 0)
124 {
125 hexify( dst_str, output, data_len );
126
127 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
128 }
129}
130END_CASE
131
132BEGIN_CASE
133blowfish_encrypt_cfb64:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
134{
135 unsigned char key_str[100];
136 unsigned char iv_str[100];
137 unsigned char src_str[100];
138 unsigned char dst_str[100];
139 unsigned char output[100];
140 blowfish_context ctx;
141 size_t iv_offset = 0;
142 int key_len, src_len;
143
144 memset(key_str, 0x00, 100);
145 memset(iv_str, 0x00, 100);
146 memset(src_str, 0x00, 100);
147 memset(dst_str, 0x00, 100);
148 memset(output, 0x00, 100);
149
150 key_len = unhexify( key_str, {hex_key_string} );
151 unhexify( iv_str, {hex_iv_string} );
152 src_len = unhexify( src_str, {hex_src_string} );
153
154 blowfish_setkey( &ctx, key_str, key_len * 8 );
155 TEST_ASSERT( blowfish_crypt_cfb64( &ctx, BLOWFISH_ENCRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 );
156 hexify( dst_str, output, src_len );
157
158 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
159}
160END_CASE
161
162BEGIN_CASE
163blowfish_decrypt_cfb64:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
164{
165 unsigned char key_str[100];
166 unsigned char iv_str[100];
167 unsigned char src_str[100];
168 unsigned char dst_str[100];
169 unsigned char output[100];
170 blowfish_context ctx;
171 size_t iv_offset = 0;
172 int key_len, src_len;
173
174 memset(key_str, 0x00, 100);
175 memset(iv_str, 0x00, 100);
176 memset(src_str, 0x00, 100);
177 memset(dst_str, 0x00, 100);
178 memset(output, 0x00, 100);
179
180 key_len = unhexify( key_str, {hex_key_string} );
181 unhexify( iv_str, {hex_iv_string} );
182 src_len = unhexify( src_str, {hex_src_string} );
183
184 blowfish_setkey( &ctx, key_str, key_len * 8 );
185 TEST_ASSERT( blowfish_crypt_cfb64( &ctx, BLOWFISH_DECRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 );
186 hexify( dst_str, output, src_len );
187
188 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
189}
190END_CASE
191
192BEGIN_CASE
193blowfish_encrypt_ctr:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
194{
195 unsigned char key_str[100];
196 unsigned char iv_str[100];
197 unsigned char stream_str[100];
198 unsigned char src_str[100];
199 unsigned char dst_str[100];
200 unsigned char output[100];
201 blowfish_context ctx;
202 size_t iv_offset = 0;
203 int key_len, src_len;
204
205 memset(key_str, 0x00, 100);
206 memset(iv_str, 0x00, 100);
207 memset(stream_str, 0x00, 100);
208 memset(src_str, 0x00, 100);
209 memset(dst_str, 0x00, 100);
210 memset(output, 0x00, 100);
211
212 key_len = unhexify( key_str, {hex_key_string} );
213 unhexify( iv_str, {hex_iv_string} );
214 src_len = unhexify( src_str, {hex_src_string} );
215
216 blowfish_setkey( &ctx, key_str, key_len * 8 );
217 TEST_ASSERT( blowfish_crypt_ctr( &ctx, src_len, &iv_offset, iv_str, stream_str, src_str, output ) == 0 );
218 hexify( dst_str, output, src_len );
219
220 TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
221}
222END_CASE