Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 1 | BEGIN_HEADER |
| 2 | #include <polarssl/aes.h> |
| 3 | END_HEADER |
| 4 | |
| 5 | BEGIN_CASE |
| 6 | aes_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 | aes_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 13 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 14 | |
| 15 | memset(key_str, 0x00, 100); |
| 16 | memset(src_str, 0x00, 100); |
| 17 | memset(dst_str, 0x00, 100); |
| 18 | memset(output, 0x00, 100); |
| 19 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 20 | key_len = unhexify( key_str, {hex_key_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 21 | unhexify( src_str, {hex_src_string} ); |
| 22 | |
| 23 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 24 | aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ); |
| 25 | hexify( dst_str, output, 16 ); |
| 26 | |
| 27 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 28 | } |
| 29 | END_CASE |
| 30 | |
| 31 | BEGIN_CASE |
| 32 | aes_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string |
| 33 | { |
| 34 | unsigned char key_str[100]; |
| 35 | unsigned char src_str[100]; |
| 36 | unsigned char dst_str[100]; |
| 37 | unsigned char output[100]; |
| 38 | aes_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 39 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 40 | |
| 41 | memset(key_str, 0x00, 100); |
| 42 | memset(src_str, 0x00, 100); |
| 43 | memset(dst_str, 0x00, 100); |
| 44 | memset(output, 0x00, 100); |
| 45 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 46 | key_len = unhexify( key_str, {hex_key_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 47 | unhexify( src_str, {hex_src_string} ); |
| 48 | |
| 49 | aes_setkey_dec( &ctx, key_str, key_len * 8 ); |
| 50 | aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ); |
| 51 | hexify( dst_str, output, 16 ); |
| 52 | |
| 53 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 54 | } |
| 55 | END_CASE |
| 56 | |
| 57 | BEGIN_CASE |
| 58 | aes_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string |
| 59 | { |
| 60 | unsigned char key_str[100]; |
| 61 | unsigned char iv_str[100]; |
| 62 | unsigned char src_str[100]; |
| 63 | unsigned char dst_str[100]; |
| 64 | unsigned char output[100]; |
| 65 | aes_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 66 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 67 | |
| 68 | memset(key_str, 0x00, 100); |
| 69 | memset(iv_str, 0x00, 100); |
| 70 | memset(src_str, 0x00, 100); |
| 71 | memset(dst_str, 0x00, 100); |
| 72 | memset(output, 0x00, 100); |
| 73 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 74 | key_len = unhexify( key_str, {hex_key_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 75 | unhexify( iv_str, {hex_iv_string} ); |
| 76 | unhexify( src_str, {hex_src_string} ); |
| 77 | |
| 78 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 79 | aes_crypt_cbc( &ctx, AES_ENCRYPT, 16, iv_str, src_str, output ); |
| 80 | hexify( dst_str, output, 16 ); |
| 81 | |
| 82 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 83 | } |
| 84 | END_CASE |
| 85 | |
| 86 | BEGIN_CASE |
| 87 | aes_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string |
| 88 | { |
| 89 | unsigned char key_str[100]; |
| 90 | unsigned char iv_str[100]; |
| 91 | unsigned char src_str[100]; |
| 92 | unsigned char dst_str[100]; |
| 93 | unsigned char output[100]; |
| 94 | aes_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 95 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 96 | |
| 97 | memset(key_str, 0x00, 100); |
| 98 | memset(iv_str, 0x00, 100); |
| 99 | memset(src_str, 0x00, 100); |
| 100 | memset(dst_str, 0x00, 100); |
| 101 | memset(output, 0x00, 100); |
| 102 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 103 | key_len = unhexify( key_str, {hex_key_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 104 | unhexify( iv_str, {hex_iv_string} ); |
| 105 | unhexify( src_str, {hex_src_string} ); |
| 106 | |
| 107 | aes_setkey_dec( &ctx, key_str, key_len * 8 ); |
| 108 | aes_crypt_cbc( &ctx, AES_DECRYPT, 16, iv_str, src_str, output ); |
| 109 | hexify( dst_str, output, 16 ); |
| 110 | |
| 111 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 112 | } |
| 113 | END_CASE |
| 114 | |
| 115 | BEGIN_CASE |
| 116 | aes_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string |
| 117 | { |
| 118 | unsigned char key_str[100]; |
| 119 | unsigned char iv_str[100]; |
| 120 | unsigned char src_str[100]; |
| 121 | unsigned char dst_str[100]; |
| 122 | unsigned char output[100]; |
| 123 | aes_context ctx; |
| 124 | int iv_offset = 0; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 125 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 126 | |
| 127 | memset(key_str, 0x00, 100); |
| 128 | memset(iv_str, 0x00, 100); |
| 129 | memset(src_str, 0x00, 100); |
| 130 | memset(dst_str, 0x00, 100); |
| 131 | memset(output, 0x00, 100); |
| 132 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 133 | key_len = unhexify( key_str, {hex_key_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 134 | unhexify( iv_str, {hex_iv_string} ); |
| 135 | unhexify( src_str, {hex_src_string} ); |
| 136 | |
| 137 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 138 | aes_crypt_cfb128( &ctx, AES_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ); |
| 139 | hexify( dst_str, output, 16 ); |
| 140 | |
| 141 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 142 | } |
| 143 | END_CASE |
| 144 | |
| 145 | BEGIN_CASE |
| 146 | aes_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string |
| 147 | { |
| 148 | unsigned char key_str[100]; |
| 149 | unsigned char iv_str[100]; |
| 150 | unsigned char src_str[100]; |
| 151 | unsigned char dst_str[100]; |
| 152 | unsigned char output[100]; |
| 153 | aes_context ctx; |
| 154 | int iv_offset = 0; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 155 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 156 | |
| 157 | memset(key_str, 0x00, 100); |
| 158 | memset(iv_str, 0x00, 100); |
| 159 | memset(src_str, 0x00, 100); |
| 160 | memset(dst_str, 0x00, 100); |
| 161 | memset(output, 0x00, 100); |
| 162 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 163 | key_len = unhexify( key_str, {hex_key_string} ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 164 | unhexify( iv_str, {hex_iv_string} ); |
| 165 | unhexify( src_str, {hex_src_string} ); |
| 166 | |
| 167 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 168 | aes_crypt_cfb128( &ctx, AES_DECRYPT, 16, &iv_offset, iv_str, src_str, output ); |
| 169 | hexify( dst_str, output, 16 ); |
| 170 | |
| 171 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 172 | } |
| 173 | END_CASE |
| 174 | |
Paul Bakker | 3d36082 | 2009-07-05 11:29:38 +0000 | [diff] [blame] | 175 | BEGIN_CASE |
| 176 | aes_selftest: |
| 177 | { |
| 178 | TEST_ASSERT( aes_self_test( 0 ) == 0 ); |
| 179 | } |
| 180 | END_CASE |