blob: a6b0fe6c551e82d1c4e0dc0cc06b5a537f8039a3 [file] [log] [blame]
Paul Bakker367dae42009-06-28 21:50:27 +00001BEGIN_HEADER
2#include <polarssl/sha1.h>
3#include <polarssl/sha2.h>
4#include <polarssl/sha4.h>
5END_HEADER
6
7BEGIN_CASE
8sha1:hex_src_string:hex_hash_string
9{
10 unsigned char src_str[10000];
11 unsigned char hash_str[10000];
12 unsigned char output[41];
13
14 memset(src_str, 0x00, 10000);
15 memset(hash_str, 0x00, 10000);
16 memset(output, 0x00, 41);
17
18 int src_len = unhexify( src_str, {hex_src_string} );
19
20 sha1( src_str, src_len, output );
21 hexify( hash_str, output, 20 );
22
23 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
24}
25END_CASE
26
27BEGIN_CASE
28sha224:hex_src_string:hex_hash_string
29{
30 unsigned char src_str[10000];
31 unsigned char hash_str[10000];
32 unsigned char output[57];
33
34 memset(src_str, 0x00, 10000);
35 memset(hash_str, 0x00, 10000);
36 memset(output, 0x00, 57);
37
38 int src_len = unhexify( src_str, {hex_src_string} );
39
40 sha2( src_str, src_len, output, 1 );
41 hexify( hash_str, output, 28 );
42
43 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
44}
45END_CASE
46
47BEGIN_CASE
48sha256:hex_src_string:hex_hash_string
49{
50 unsigned char src_str[10000];
51 unsigned char hash_str[10000];
52 unsigned char output[65];
53
54 memset(src_str, 0x00, 10000);
55 memset(hash_str, 0x00, 10000);
56 memset(output, 0x00, 65);
57
58 int src_len = unhexify( src_str, {hex_src_string} );
59
60 sha2( src_str, src_len, output, 0 );
61 hexify( hash_str, output, 32 );
62
63 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
64}
65END_CASE
66
67BEGIN_CASE
68sha384:hex_src_string:hex_hash_string
69{
70 unsigned char src_str[10000];
71 unsigned char hash_str[10000];
72 unsigned char output[97];
73
74 memset(src_str, 0x00, 10000);
75 memset(hash_str, 0x00, 10000);
76 memset(output, 0x00, 97);
77
78 int src_len = unhexify( src_str, {hex_src_string} );
79
80 sha4( src_str, src_len, output, 1 );
81 hexify( hash_str, output, 48 );
82
83 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
84}
85END_CASE
86
87BEGIN_CASE
88sha512:hex_src_string:hex_hash_string
89{
90 unsigned char src_str[10000];
91 unsigned char hash_str[10000];
92 unsigned char output[129];
93
94 memset(src_str, 0x00, 10000);
95 memset(hash_str, 0x00, 10000);
96 memset(output, 0x00, 129);
97
98 int src_len = unhexify( src_str, {hex_src_string} );
99
100 sha4( src_str, src_len, output, 0);
101 hexify( hash_str, output, 64 );
102
103 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
104}
105END_CASE
Paul Bakkerf3eedce2009-07-05 11:30:16 +0000106
107BEGIN_CASE
108sha1_file:filename:hex_hash_string
109{
110 unsigned char hash_str[41];
111 unsigned char output[21];
112
113 memset(hash_str, 0x00, 41);
114 memset(output, 0x00, 21);
115
116 sha1_file( {filename}, output);
117 hexify( hash_str, output, 20 );
118
119 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
120}
121END_CASE
122
123BEGIN_CASE
124sha224_file:filename:hex_hash_string
125{
126 unsigned char hash_str[57];
127 unsigned char output[29];
128
129 memset(hash_str, 0x00, 57);
130 memset(output, 0x00, 29);
131
132 sha2_file( {filename}, output, 1);
133 hexify( hash_str, output, 28 );
134
135 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
136}
137END_CASE
138
139BEGIN_CASE
140sha256_file:filename:hex_hash_string
141{
142 unsigned char hash_str[65];
143 unsigned char output[33];
144
145 memset(hash_str, 0x00, 65);
146 memset(output, 0x00, 33);
147
148 sha2_file( {filename}, output, 0);
149 hexify( hash_str, output, 32 );
150
151 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
152}
153END_CASE
154
155BEGIN_CASE
156sha384_file:filename:hex_hash_string
157{
158 unsigned char hash_str[97];
159 unsigned char output[49];
160
161 memset(hash_str, 0x00, 97);
162 memset(output, 0x00, 49);
163
164 sha4_file( {filename}, output, 1);
165 hexify( hash_str, output, 48 );
166
167 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
168}
169END_CASE
170
171BEGIN_CASE
172sha512_file:filename:hex_hash_string
173{
174 unsigned char hash_str[129];
175 unsigned char output[65];
176
177 memset(hash_str, 0x00, 129);
178 memset(output, 0x00, 65);
179
180 sha4_file( {filename}, output, 0);
181 hexify( hash_str, output, 64 );
182
183 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
184}
185END_CASE
186
187BEGIN_CASE
188sha1_selftest:
189{
190 TEST_ASSERT( sha1_self_test( 0 ) == 0 );
191}
192END_CASE
193
194BEGIN_CASE
195sha2_selftest:
196{
197 TEST_ASSERT( sha2_self_test( 0 ) == 0 );
198}
199END_CASE
200
201BEGIN_CASE
202sha4_selftest:
203{
204 TEST_ASSERT( sha4_self_test( 0 ) == 0 );
205}
206END_CASE