Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 1 | BEGIN_HEADER |
| 2 | #include <polarssl/sha1.h> |
Paul Bakker | d2681d8 | 2013-06-30 14:49:12 +0200 | [diff] [blame] | 3 | #include <polarssl/sha256.h> |
| 4 | #include <polarssl/sha512.h> |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 5 | END_HEADER |
| 6 | |
| 7 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 8 | sha1_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 9 | { |
| 10 | unsigned char src_str[10000]; |
| 11 | unsigned char key_str[10000]; |
| 12 | unsigned char hash_str[10000]; |
| 13 | unsigned char output[41]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 14 | int key_len, src_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 15 | |
| 16 | memset(src_str, 0x00, 10000); |
| 17 | memset(key_str, 0x00, 10000); |
| 18 | memset(hash_str, 0x00, 10000); |
| 19 | memset(output, 0x00, 41); |
| 20 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 21 | key_len = unhexify( key_str, {hex_key_string} ); |
| 22 | src_len = unhexify( src_str, {hex_src_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 23 | |
| 24 | sha1_hmac( key_str, key_len, src_str, src_len, output ); |
| 25 | hexify( hash_str, output, 20 ); |
| 26 | |
| 27 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 28 | } |
| 29 | END_CASE |
| 30 | |
| 31 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 32 | sha224_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 33 | { |
| 34 | unsigned char src_str[10000]; |
| 35 | unsigned char key_str[10000]; |
| 36 | unsigned char hash_str[10000]; |
| 37 | unsigned char output[57]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 38 | int key_len, src_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 39 | |
| 40 | memset(src_str, 0x00, 10000); |
| 41 | memset(key_str, 0x00, 10000); |
| 42 | memset(hash_str, 0x00, 10000); |
| 43 | memset(output, 0x00, 57); |
| 44 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 45 | key_len = unhexify( key_str, {hex_key_string} ); |
| 46 | src_len = unhexify( src_str, {hex_src_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 47 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 48 | sha256_hmac( key_str, key_len, src_str, src_len, output, 1 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 49 | hexify( hash_str, output, 28 ); |
| 50 | |
| 51 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 52 | } |
| 53 | END_CASE |
| 54 | |
| 55 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 56 | sha256_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 57 | { |
| 58 | unsigned char src_str[10000]; |
| 59 | unsigned char key_str[10000]; |
| 60 | unsigned char hash_str[10000]; |
| 61 | unsigned char output[65]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 62 | int key_len, src_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 63 | |
| 64 | memset(src_str, 0x00, 10000); |
| 65 | memset(key_str, 0x00, 10000); |
| 66 | memset(hash_str, 0x00, 10000); |
| 67 | memset(output, 0x00, 65); |
| 68 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 69 | key_len = unhexify( key_str, {hex_key_string} ); |
| 70 | src_len = unhexify( src_str, {hex_src_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 71 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 72 | sha256_hmac( key_str, key_len, src_str, src_len, output, 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 73 | hexify( hash_str, output, 32 ); |
| 74 | |
| 75 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 76 | } |
| 77 | END_CASE |
| 78 | |
| 79 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 80 | sha384_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 81 | { |
| 82 | unsigned char src_str[10000]; |
| 83 | unsigned char key_str[10000]; |
| 84 | unsigned char hash_str[10000]; |
| 85 | unsigned char output[97]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 86 | int key_len, src_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 87 | |
| 88 | memset(src_str, 0x00, 10000); |
| 89 | memset(key_str, 0x00, 10000); |
| 90 | memset(hash_str, 0x00, 10000); |
| 91 | memset(output, 0x00, 97); |
| 92 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 93 | key_len = unhexify( key_str, {hex_key_string} ); |
| 94 | src_len = unhexify( src_str, {hex_src_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 95 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 96 | sha512_hmac( key_str, key_len, src_str, src_len, output, 1 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 97 | hexify( hash_str, output, 48 ); |
| 98 | |
| 99 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 100 | } |
| 101 | END_CASE |
| 102 | |
| 103 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 104 | sha512_hmac:#trunc_size:hex_key_string:hex_src_string:hex_hash_string |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 105 | { |
| 106 | unsigned char src_str[10000]; |
| 107 | unsigned char key_str[10000]; |
| 108 | unsigned char hash_str[10000]; |
| 109 | unsigned char output[129]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 110 | int key_len, src_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 111 | |
| 112 | memset(src_str, 0x00, 10000); |
| 113 | memset(key_str, 0x00, 10000); |
| 114 | memset(hash_str, 0x00, 10000); |
| 115 | memset(output, 0x00, 129); |
| 116 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 117 | key_len = unhexify( key_str, {hex_key_string} ); |
| 118 | src_len = unhexify( src_str, {hex_src_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 119 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 120 | sha512_hmac( key_str, key_len, src_str, src_len, output, 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 121 | hexify( hash_str, output, 64 ); |
| 122 | |
| 123 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 124 | } |
| 125 | END_CASE |