blob: 7507feac8811799e818d66923d1aa6aca0dc526e [file] [log] [blame]
Paul Bakkere896fea2009-07-06 06:40:23 +00001BEGIN_HEADER
2#include <polarssl/camellia.h>
3END_HEADER
4
5BEGIN_CASE
6camellia_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
7{
8 unsigned char key_str[100];
9 unsigned char src_str[100];
10 unsigned char dst_str[100];
11 unsigned char output[100];
12 camellia_context ctx;
Paul Bakker69998dd2009-07-11 19:15:20 +000013 int key_len;
Paul Bakkere896fea2009-07-06 06:40:23 +000014
15 memset(key_str, 0x00, 100);
16 memset(src_str, 0x00, 100);
17 memset(dst_str, 0x00, 100);
18 memset(output, 0x00, 100);
19
Paul Bakker69998dd2009-07-11 19:15:20 +000020 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +000021 unhexify( src_str, {hex_src_string} );
22
23 camellia_setkey_enc( &ctx, key_str, key_len * 8 );
24 camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output );
25 hexify( dst_str, output, 16 );
26
27 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
28}
29END_CASE
30
31BEGIN_CASE
32camellia_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
33{
34 unsigned char key_str[100];
35 unsigned char src_str[100];
36 unsigned char dst_str[100];
37 unsigned char output[100];
38 camellia_context ctx;
Paul Bakker69998dd2009-07-11 19:15:20 +000039 int key_len;
Paul Bakkere896fea2009-07-06 06:40:23 +000040
41 memset(key_str, 0x00, 100);
42 memset(src_str, 0x00, 100);
43 memset(dst_str, 0x00, 100);
44 memset(output, 0x00, 100);
45
Paul Bakker69998dd2009-07-11 19:15:20 +000046 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +000047 unhexify( src_str, {hex_src_string} );
48
49 camellia_setkey_dec( &ctx, key_str, key_len * 8 );
50 camellia_crypt_ecb( &ctx, CAMELLIA_DECRYPT, src_str, output );
51 hexify( dst_str, output, 16 );
52
53 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
54}
55END_CASE
56
57BEGIN_CASE
58camellia_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
59{
60 unsigned char key_str[100];
61 unsigned char iv_str[100];
62 unsigned char src_str[100];
63 unsigned char dst_str[100];
64 unsigned char output[100];
65 camellia_context ctx;
Paul Bakker69998dd2009-07-11 19:15:20 +000066 int key_len;
Paul Bakkere896fea2009-07-06 06:40:23 +000067
68 memset(key_str, 0x00, 100);
69 memset(iv_str, 0x00, 100);
70 memset(src_str, 0x00, 100);
71 memset(dst_str, 0x00, 100);
72 memset(output, 0x00, 100);
73
Paul Bakker69998dd2009-07-11 19:15:20 +000074 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +000075 unhexify( iv_str, {hex_iv_string} );
76 unhexify( src_str, {hex_src_string} );
77
78 camellia_setkey_enc( &ctx, key_str, key_len * 8 );
79 camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, 16, iv_str, src_str, output );
80 hexify( dst_str, output, 16 );
81
82 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
83}
84END_CASE
85
86BEGIN_CASE
87camellia_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
88{
89 unsigned char key_str[100];
90 unsigned char iv_str[100];
91 unsigned char src_str[100];
92 unsigned char dst_str[100];
93 unsigned char output[100];
94 camellia_context ctx;
Paul Bakker69998dd2009-07-11 19:15:20 +000095 int key_len;
Paul Bakkere896fea2009-07-06 06:40:23 +000096
97 memset(key_str, 0x00, 100);
98 memset(iv_str, 0x00, 100);
99 memset(src_str, 0x00, 100);
100 memset(dst_str, 0x00, 100);
101 memset(output, 0x00, 100);
102
Paul Bakker69998dd2009-07-11 19:15:20 +0000103 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +0000104 unhexify( iv_str, {hex_iv_string} );
105 unhexify( src_str, {hex_src_string} );
106
107 camellia_setkey_dec( &ctx, key_str, key_len * 8 );
108 camellia_crypt_cbc( &ctx, CAMELLIA_DECRYPT, 16, iv_str, src_str, output );
109 hexify( dst_str, output, 16 );
110
111 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
112}
113END_CASE
114
115BEGIN_CASE
116camellia_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
117{
118 unsigned char key_str[100];
119 unsigned char iv_str[100];
120 unsigned char src_str[100];
121 unsigned char dst_str[100];
122 unsigned char output[100];
123 camellia_context ctx;
124 int iv_offset = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +0000125 int key_len;
Paul Bakkere896fea2009-07-06 06:40:23 +0000126
127 memset(key_str, 0x00, 100);
128 memset(iv_str, 0x00, 100);
129 memset(src_str, 0x00, 100);
130 memset(dst_str, 0x00, 100);
131 memset(output, 0x00, 100);
132
Paul Bakker69998dd2009-07-11 19:15:20 +0000133 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +0000134 unhexify( iv_str, {hex_iv_string} );
135 unhexify( src_str, {hex_src_string} );
136
137 camellia_setkey_enc( &ctx, key_str, key_len * 8 );
138 camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output );
139 hexify( dst_str, output, 16 );
140
141 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
142}
143END_CASE
144
145BEGIN_CASE
146camellia_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
147{
148 unsigned char key_str[100];
149 unsigned char iv_str[100];
150 unsigned char src_str[100];
151 unsigned char dst_str[100];
152 unsigned char output[100];
153 camellia_context ctx;
154 int iv_offset = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +0000155 int key_len;
Paul Bakkere896fea2009-07-06 06:40:23 +0000156
157 memset(key_str, 0x00, 100);
158 memset(iv_str, 0x00, 100);
159 memset(src_str, 0x00, 100);
160 memset(dst_str, 0x00, 100);
161 memset(output, 0x00, 100);
162
Paul Bakker69998dd2009-07-11 19:15:20 +0000163 key_len = unhexify( key_str, {hex_key_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +0000164 unhexify( iv_str, {hex_iv_string} );
165 unhexify( src_str, {hex_src_string} );
166
167 camellia_setkey_enc( &ctx, key_str, key_len * 8 );
168 camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output );
169 hexify( dst_str, output, 16 );
170
171 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
172}
173END_CASE
174
175BEGIN_CASE
176camellia_selftest:
177{
178 TEST_ASSERT( camellia_self_test( 0 ) == 0 );
179}
180END_CASE