Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 2 | #include <polarssl/aes.h> |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 3 | /* END_HEADER */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 4 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 5 | /* BEGIN_DEPENDENCIES |
| 6 | * depends_on:POLARSSL_AES_C |
| 7 | * END_DEPENDENCIES |
| 8 | */ |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 9 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 10 | /* BEGIN_CASE */ |
| 11 | void aes_encrypt_ecb( char *hex_key_string, char *hex_src_string, |
| 12 | char *hex_dst_string, int setkey_result ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 13 | { |
| 14 | unsigned char key_str[100]; |
| 15 | unsigned char src_str[100]; |
| 16 | unsigned char dst_str[100]; |
| 17 | unsigned char output[100]; |
| 18 | aes_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 19 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 20 | |
| 21 | memset(key_str, 0x00, 100); |
| 22 | memset(src_str, 0x00, 100); |
| 23 | memset(dst_str, 0x00, 100); |
| 24 | memset(output, 0x00, 100); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 25 | aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 26 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 27 | key_len = unhexify( key_str, hex_key_string ); |
| 28 | unhexify( src_str, hex_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 29 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 30 | TEST_ASSERT( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == setkey_result ); |
| 31 | if( setkey_result == 0 ) |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 32 | { |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 33 | TEST_ASSERT( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 ); |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 34 | hexify( dst_str, output, 16 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 35 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 36 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 37 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 38 | |
| 39 | aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 40 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 41 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 42 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 43 | /* BEGIN_CASE */ |
| 44 | void aes_decrypt_ecb( char *hex_key_string, char *hex_src_string, |
| 45 | char *hex_dst_string, int setkey_result ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 46 | { |
| 47 | unsigned char key_str[100]; |
| 48 | unsigned char src_str[100]; |
| 49 | unsigned char dst_str[100]; |
| 50 | unsigned char output[100]; |
| 51 | aes_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 52 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 53 | |
| 54 | memset(key_str, 0x00, 100); |
| 55 | memset(src_str, 0x00, 100); |
| 56 | memset(dst_str, 0x00, 100); |
| 57 | memset(output, 0x00, 100); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 58 | aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 59 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 60 | key_len = unhexify( key_str, hex_key_string ); |
| 61 | unhexify( src_str, hex_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 62 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 63 | TEST_ASSERT( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == setkey_result ); |
| 64 | if( setkey_result == 0 ) |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 65 | { |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 66 | TEST_ASSERT( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 ); |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 67 | hexify( dst_str, output, 16 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 68 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 69 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 70 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 71 | |
| 72 | aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 73 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 74 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 75 | |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 76 | /* BEGIN_CASE depends_on:POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 77 | void aes_encrypt_cbc( char *hex_key_string, char *hex_iv_string, |
| 78 | char *hex_src_string, char *hex_dst_string, |
| 79 | int cbc_result ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 80 | { |
| 81 | unsigned char key_str[100]; |
| 82 | unsigned char iv_str[100]; |
| 83 | unsigned char src_str[100]; |
| 84 | unsigned char dst_str[100]; |
| 85 | unsigned char output[100]; |
| 86 | aes_context ctx; |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 87 | int key_len, data_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 88 | |
| 89 | memset(key_str, 0x00, 100); |
| 90 | memset(iv_str, 0x00, 100); |
| 91 | memset(src_str, 0x00, 100); |
| 92 | memset(dst_str, 0x00, 100); |
| 93 | memset(output, 0x00, 100); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 94 | aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 95 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 96 | key_len = unhexify( key_str, hex_key_string ); |
| 97 | unhexify( iv_str, hex_iv_string ); |
| 98 | data_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 99 | |
| 100 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 101 | TEST_ASSERT( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == cbc_result ); |
| 102 | if( cbc_result == 0 ) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 103 | { |
| 104 | hexify( dst_str, output, data_len ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 105 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 106 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 107 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 108 | |
| 109 | aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 110 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 111 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 112 | |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 113 | /* BEGIN_CASE depends_on:POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 114 | void aes_decrypt_cbc( char *hex_key_string, char *hex_iv_string, |
| 115 | char *hex_src_string, char *hex_dst_string, |
| 116 | int cbc_result ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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; |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 124 | int key_len, data_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 125 | |
| 126 | memset(key_str, 0x00, 100); |
| 127 | memset(iv_str, 0x00, 100); |
| 128 | memset(src_str, 0x00, 100); |
| 129 | memset(dst_str, 0x00, 100); |
| 130 | memset(output, 0x00, 100); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 131 | aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 132 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 133 | key_len = unhexify( key_str, hex_key_string ); |
| 134 | unhexify( iv_str, hex_iv_string ); |
| 135 | data_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 136 | |
| 137 | aes_setkey_dec( &ctx, key_str, key_len * 8 ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 138 | TEST_ASSERT( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == cbc_result ); |
| 139 | if( cbc_result == 0) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 140 | { |
| 141 | hexify( dst_str, output, data_len ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 142 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 143 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 144 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 145 | |
| 146 | aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 147 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 148 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 149 | |
Manuel Pégourié-Gonnard | 387a211 | 2013-09-18 18:54:01 +0200 | [diff] [blame] | 150 | /* BEGIN_CASE depends_on:POLARSSL_CIPHER_MODE_CFB */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 151 | void aes_encrypt_cfb128( char *hex_key_string, char *hex_iv_string, |
| 152 | char *hex_src_string, char *hex_dst_string ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 153 | { |
| 154 | unsigned char key_str[100]; |
| 155 | unsigned char iv_str[100]; |
| 156 | unsigned char src_str[100]; |
| 157 | unsigned char dst_str[100]; |
| 158 | unsigned char output[100]; |
| 159 | aes_context ctx; |
Paul Bakker | cd43a0b | 2011-06-09 13:55:44 +0000 | [diff] [blame] | 160 | size_t iv_offset = 0; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 161 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 162 | |
| 163 | memset(key_str, 0x00, 100); |
| 164 | memset(iv_str, 0x00, 100); |
| 165 | memset(src_str, 0x00, 100); |
| 166 | memset(dst_str, 0x00, 100); |
| 167 | memset(output, 0x00, 100); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 168 | aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 169 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 170 | key_len = unhexify( key_str, hex_key_string ); |
| 171 | unhexify( iv_str, hex_iv_string ); |
| 172 | unhexify( src_str, hex_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 173 | |
| 174 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 175 | TEST_ASSERT( aes_crypt_cfb128( &ctx, AES_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 176 | hexify( dst_str, output, 16 ); |
| 177 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 178 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 179 | |
| 180 | aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 181 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 182 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 183 | |
Manuel Pégourié-Gonnard | 387a211 | 2013-09-18 18:54:01 +0200 | [diff] [blame] | 184 | /* BEGIN_CASE depends_on:POLARSSL_CIPHER_MODE_CFB */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 185 | void aes_decrypt_cfb128( char *hex_key_string, char *hex_iv_string, |
| 186 | char *hex_src_string, char *hex_dst_string ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 187 | { |
| 188 | unsigned char key_str[100]; |
| 189 | unsigned char iv_str[100]; |
| 190 | unsigned char src_str[100]; |
| 191 | unsigned char dst_str[100]; |
| 192 | unsigned char output[100]; |
| 193 | aes_context ctx; |
Paul Bakker | cd43a0b | 2011-06-09 13:55:44 +0000 | [diff] [blame] | 194 | size_t iv_offset = 0; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 195 | int key_len; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 196 | |
| 197 | memset(key_str, 0x00, 100); |
| 198 | memset(iv_str, 0x00, 100); |
| 199 | memset(src_str, 0x00, 100); |
| 200 | memset(dst_str, 0x00, 100); |
| 201 | memset(output, 0x00, 100); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 202 | aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 203 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 204 | key_len = unhexify( key_str, hex_key_string ); |
| 205 | unhexify( iv_str, hex_iv_string ); |
| 206 | unhexify( src_str, hex_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 207 | |
| 208 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 209 | TEST_ASSERT( aes_crypt_cfb128( &ctx, AES_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 210 | hexify( dst_str, output, 16 ); |
| 211 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 212 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 213 | |
| 214 | aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 215 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 216 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 217 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 218 | /* BEGIN_CASE depends_on:POLARSSL_CIPHER_MODE_CFB */ |
| 219 | void aes_encrypt_cfb8( char *hex_key_string, char *hex_iv_string, |
| 220 | char *hex_src_string, char *hex_dst_string ) |
| 221 | { |
| 222 | unsigned char key_str[100]; |
| 223 | unsigned char iv_str[100]; |
| 224 | unsigned char src_str[100]; |
| 225 | unsigned char dst_str[100]; |
| 226 | unsigned char output[100]; |
| 227 | aes_context ctx; |
| 228 | int key_len, src_len; |
| 229 | |
| 230 | memset(key_str, 0x00, 100); |
| 231 | memset(iv_str, 0x00, 100); |
| 232 | memset(src_str, 0x00, 100); |
| 233 | memset(dst_str, 0x00, 100); |
| 234 | memset(output, 0x00, 100); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 235 | aes_init( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 236 | |
| 237 | key_len = unhexify( key_str, hex_key_string ); |
| 238 | unhexify( iv_str, hex_iv_string ); |
| 239 | src_len = unhexify( src_str, hex_src_string ); |
| 240 | |
| 241 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 242 | TEST_ASSERT( aes_crypt_cfb8( &ctx, AES_ENCRYPT, src_len, iv_str, src_str, output ) == 0 ); |
| 243 | hexify( dst_str, output, src_len ); |
| 244 | |
| 245 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 246 | |
| 247 | aes_free( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 248 | } |
| 249 | /* END_CASE */ |
| 250 | |
| 251 | /* BEGIN_CASE depends_on:POLARSSL_CIPHER_MODE_CFB */ |
| 252 | void aes_decrypt_cfb8( char *hex_key_string, char *hex_iv_string, |
| 253 | char *hex_src_string, char *hex_dst_string ) |
| 254 | { |
| 255 | unsigned char key_str[100]; |
| 256 | unsigned char iv_str[100]; |
| 257 | unsigned char src_str[100]; |
| 258 | unsigned char dst_str[100]; |
| 259 | unsigned char output[100]; |
| 260 | aes_context ctx; |
| 261 | int key_len, src_len; |
| 262 | |
| 263 | memset(key_str, 0x00, 100); |
| 264 | memset(iv_str, 0x00, 100); |
| 265 | memset(src_str, 0x00, 100); |
| 266 | memset(dst_str, 0x00, 100); |
| 267 | memset(output, 0x00, 100); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 268 | aes_init( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 269 | |
| 270 | key_len = unhexify( key_str, hex_key_string ); |
| 271 | unhexify( iv_str, hex_iv_string ); |
| 272 | src_len = unhexify( src_str, hex_src_string ); |
| 273 | |
| 274 | aes_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 275 | TEST_ASSERT( aes_crypt_cfb8( &ctx, AES_DECRYPT, src_len, iv_str, src_str, output ) == 0 ); |
| 276 | hexify( dst_str, output, src_len ); |
| 277 | |
| 278 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame^] | 279 | |
| 280 | aes_free( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 281 | } |
| 282 | /* END_CASE */ |
| 283 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 284 | /* BEGIN_CASE depends_on:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 285 | void aes_selftest() |
Paul Bakker | 3d36082 | 2009-07-05 11:29:38 +0000 | [diff] [blame] | 286 | { |
| 287 | TEST_ASSERT( aes_self_test( 0 ) == 0 ); |
| 288 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 289 | /* END_CASE */ |