blob: 4670c79c7802e89cbda1bd72b3133950e186c166 [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;
13
14 memset(key_str, 0x00, 100);
15 memset(src_str, 0x00, 100);
16 memset(dst_str, 0x00, 100);
17 memset(output, 0x00, 100);
18
19 int key_len = unhexify( key_str, {hex_key_string} );
20 unhexify( src_str, {hex_src_string} );
21
22 camellia_setkey_enc( &ctx, key_str, key_len * 8 );
23 camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output );
24 hexify( dst_str, output, 16 );
25
26 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
27}
28END_CASE
29
30BEGIN_CASE
31camellia_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
32{
33 unsigned char key_str[100];
34 unsigned char src_str[100];
35 unsigned char dst_str[100];
36 unsigned char output[100];
37 camellia_context ctx;
38
39 memset(key_str, 0x00, 100);
40 memset(src_str, 0x00, 100);
41 memset(dst_str, 0x00, 100);
42 memset(output, 0x00, 100);
43
44 int key_len = unhexify( key_str, {hex_key_string} );
45 unhexify( src_str, {hex_src_string} );
46
47 camellia_setkey_dec( &ctx, key_str, key_len * 8 );
48 camellia_crypt_ecb( &ctx, CAMELLIA_DECRYPT, src_str, output );
49 hexify( dst_str, output, 16 );
50
51 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
52}
53END_CASE
54
55BEGIN_CASE
56camellia_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
57{
58 unsigned char key_str[100];
59 unsigned char iv_str[100];
60 unsigned char src_str[100];
61 unsigned char dst_str[100];
62 unsigned char output[100];
63 camellia_context ctx;
64
65 memset(key_str, 0x00, 100);
66 memset(iv_str, 0x00, 100);
67 memset(src_str, 0x00, 100);
68 memset(dst_str, 0x00, 100);
69 memset(output, 0x00, 100);
70
71 int key_len = unhexify( key_str, {hex_key_string} );
72 unhexify( iv_str, {hex_iv_string} );
73 unhexify( src_str, {hex_src_string} );
74
75 camellia_setkey_enc( &ctx, key_str, key_len * 8 );
76 camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, 16, iv_str, src_str, output );
77 hexify( dst_str, output, 16 );
78
79 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
80}
81END_CASE
82
83BEGIN_CASE
84camellia_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
85{
86 unsigned char key_str[100];
87 unsigned char iv_str[100];
88 unsigned char src_str[100];
89 unsigned char dst_str[100];
90 unsigned char output[100];
91 camellia_context ctx;
92
93 memset(key_str, 0x00, 100);
94 memset(iv_str, 0x00, 100);
95 memset(src_str, 0x00, 100);
96 memset(dst_str, 0x00, 100);
97 memset(output, 0x00, 100);
98
99 int key_len = unhexify( key_str, {hex_key_string} );
100 unhexify( iv_str, {hex_iv_string} );
101 unhexify( src_str, {hex_src_string} );
102
103 camellia_setkey_dec( &ctx, key_str, key_len * 8 );
104 camellia_crypt_cbc( &ctx, CAMELLIA_DECRYPT, 16, iv_str, src_str, output );
105 hexify( dst_str, output, 16 );
106
107 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
108}
109END_CASE
110
111BEGIN_CASE
112camellia_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
113{
114 unsigned char key_str[100];
115 unsigned char iv_str[100];
116 unsigned char src_str[100];
117 unsigned char dst_str[100];
118 unsigned char output[100];
119 camellia_context ctx;
120 int iv_offset = 0;
121
122 memset(key_str, 0x00, 100);
123 memset(iv_str, 0x00, 100);
124 memset(src_str, 0x00, 100);
125 memset(dst_str, 0x00, 100);
126 memset(output, 0x00, 100);
127
128 int key_len = unhexify( key_str, {hex_key_string} );
129 unhexify( iv_str, {hex_iv_string} );
130 unhexify( src_str, {hex_src_string} );
131
132 camellia_setkey_enc( &ctx, key_str, key_len * 8 );
133 camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output );
134 hexify( dst_str, output, 16 );
135
136 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
137}
138END_CASE
139
140BEGIN_CASE
141camellia_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
142{
143 unsigned char key_str[100];
144 unsigned char iv_str[100];
145 unsigned char src_str[100];
146 unsigned char dst_str[100];
147 unsigned char output[100];
148 camellia_context ctx;
149 int iv_offset = 0;
150
151 memset(key_str, 0x00, 100);
152 memset(iv_str, 0x00, 100);
153 memset(src_str, 0x00, 100);
154 memset(dst_str, 0x00, 100);
155 memset(output, 0x00, 100);
156
157 int key_len = unhexify( key_str, {hex_key_string} );
158 unhexify( iv_str, {hex_iv_string} );
159 unhexify( src_str, {hex_src_string} );
160
161 camellia_setkey_enc( &ctx, key_str, key_len * 8 );
162 camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output );
163 hexify( dst_str, output, 16 );
164
165 TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
166}
167END_CASE
168
169BEGIN_CASE
170camellia_selftest:
171{
172 TEST_ASSERT( camellia_self_test( 0 ) == 0 );
173}
174END_CASE