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