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