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]; |
| 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 | } |
| 25 | END_CASE |
| 26 | |
| 27 | BEGIN_CASE |
| 28 | sha224: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 | } |
| 45 | END_CASE |
| 46 | |
| 47 | BEGIN_CASE |
| 48 | sha256: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 | } |
| 65 | END_CASE |
| 66 | |
| 67 | BEGIN_CASE |
| 68 | sha384: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 | } |
| 85 | END_CASE |
| 86 | |
| 87 | BEGIN_CASE |
| 88 | sha512: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 | } |
| 105 | END_CASE |
Paul Bakker | f3eedce | 2009-07-05 11:30:16 +0000 | [diff] [blame] | 106 | |
| 107 | BEGIN_CASE |
| 108 | sha1_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 | } |
| 121 | END_CASE |
| 122 | |
| 123 | BEGIN_CASE |
| 124 | sha224_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 | } |
| 137 | END_CASE |
| 138 | |
| 139 | BEGIN_CASE |
| 140 | sha256_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 | } |
| 153 | END_CASE |
| 154 | |
| 155 | BEGIN_CASE |
| 156 | sha384_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 | } |
| 169 | END_CASE |
| 170 | |
| 171 | BEGIN_CASE |
| 172 | sha512_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 | } |
| 185 | END_CASE |
| 186 | |
| 187 | BEGIN_CASE |
| 188 | sha1_selftest: |
| 189 | { |
| 190 | TEST_ASSERT( sha1_self_test( 0 ) == 0 ); |
| 191 | } |
| 192 | END_CASE |
| 193 | |
| 194 | BEGIN_CASE |
| 195 | sha2_selftest: |
| 196 | { |
| 197 | TEST_ASSERT( sha2_self_test( 0 ) == 0 ); |
| 198 | } |
| 199 | END_CASE |
| 200 | |
| 201 | BEGIN_CASE |
| 202 | sha4_selftest: |
| 203 | { |
| 204 | TEST_ASSERT( sha4_self_test( 0 ) == 0 ); |
| 205 | } |
| 206 | END_CASE |