Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
| 2 | #include "mbedtls/aria.h" |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 3 | |
| 4 | /* Maxium size of data used by test vectors |
| 5 | * WARNING: to be adapted if and when adding larger test cases */ |
| 6 | #define ARIA_MAX_DATASIZE 160 |
| 7 | |
| 8 | /* Maximum sizes of hexified things */ |
| 9 | #define ARIA_MAX_KEY_STR ( 2 * MBEDTLS_ARIA_MAX_KEYSIZE + 1 ) |
| 10 | #define ARIA_BLOCK_STR ( 2 * MBEDTLS_ARIA_BLOCKSIZE + 1 ) |
| 11 | #define ARIA_MAX_DATA_STR ( 2 * ARIA_MAX_DATASIZE + 1 ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 12 | /* END_HEADER */ |
| 13 | |
| 14 | /* BEGIN_DEPENDENCIES |
| 15 | * depends_on:MBEDTLS_ARIA_C |
| 16 | * END_DEPENDENCIES |
| 17 | */ |
| 18 | |
| 19 | /* BEGIN_CASE */ |
| 20 | void aria_encrypt_ecb( char *hex_key_string, char *hex_src_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 21 | char *hex_dst_string, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 22 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 23 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 24 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 25 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 26 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 27 | mbedtls_aria_context ctx; |
| 28 | int key_len, data_len, i; |
| 29 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 30 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 31 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 32 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 33 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 34 | mbedtls_aria_init( &ctx ); |
| 35 | |
| 36 | key_len = unhexify( key_str, hex_key_string ); |
| 37 | data_len = unhexify( src_str, hex_src_string ); |
| 38 | |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 39 | TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ) |
| 40 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 41 | if( setkey_result == 0 ) |
| 42 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 43 | for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 44 | { |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 45 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, MBEDTLS_ARIA_ENCRYPT, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame^] | 46 | src_str + i, output + i ) |
| 47 | == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 48 | } |
| 49 | hexify( dst_str, output, data_len ); |
| 50 | |
| 51 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 52 | } |
| 53 | |
| 54 | exit: |
| 55 | mbedtls_aria_free( &ctx ); |
| 56 | } |
| 57 | /* END_CASE */ |
| 58 | |
| 59 | /* BEGIN_CASE */ |
| 60 | void aria_decrypt_ecb( char *hex_key_string, char *hex_src_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 61 | char *hex_dst_string, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 62 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 63 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 64 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 65 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 66 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 67 | mbedtls_aria_context ctx; |
| 68 | int key_len, data_len, i; |
| 69 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 70 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 71 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 72 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 73 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 74 | mbedtls_aria_init( &ctx ); |
| 75 | |
| 76 | key_len = unhexify( key_str, hex_key_string ); |
| 77 | data_len = unhexify( src_str, hex_src_string ); |
| 78 | |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 79 | TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 ) |
| 80 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 81 | if( setkey_result == 0 ) |
| 82 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 83 | for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 84 | { |
| 85 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, MBEDTLS_ARIA_DECRYPT, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame^] | 86 | src_str + i, output + i ) |
| 87 | == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 88 | } |
| 89 | hexify( dst_str, output, data_len ); |
| 90 | |
| 91 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 92 | } |
| 93 | |
| 94 | exit: |
| 95 | mbedtls_aria_free( &ctx ); |
| 96 | } |
| 97 | /* END_CASE */ |
| 98 | |
| 99 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
| 100 | void aria_encrypt_cbc( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 101 | char *hex_src_string, char *hex_dst_string, |
| 102 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 103 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 104 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 105 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 106 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 107 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 108 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 109 | mbedtls_aria_context ctx; |
| 110 | int key_len, data_len; |
| 111 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 112 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 113 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 114 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 115 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 116 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 117 | mbedtls_aria_init( &ctx ); |
| 118 | |
| 119 | key_len = unhexify( key_str, hex_key_string ); |
| 120 | unhexify( iv_str, hex_iv_string ); |
| 121 | data_len = unhexify( src_str, hex_src_string ); |
| 122 | |
| 123 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 124 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, data_len, |
| 125 | iv_str, src_str, output ) |
| 126 | == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 127 | if( cbc_result == 0 ) |
| 128 | { |
| 129 | hexify( dst_str, output, data_len ); |
| 130 | |
| 131 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 132 | } |
| 133 | |
| 134 | exit: |
| 135 | mbedtls_aria_free( &ctx ); |
| 136 | } |
| 137 | /* END_CASE */ |
| 138 | |
| 139 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
| 140 | void aria_decrypt_cbc( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 141 | char *hex_src_string, char *hex_dst_string, |
| 142 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 143 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 144 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 145 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 146 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 147 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 148 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 149 | mbedtls_aria_context ctx; |
| 150 | int key_len, data_len; |
| 151 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 152 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 153 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 154 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 155 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 156 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 157 | mbedtls_aria_init( &ctx ); |
| 158 | |
| 159 | key_len = unhexify( key_str, hex_key_string ); |
| 160 | unhexify( iv_str, hex_iv_string ); |
| 161 | data_len = unhexify( src_str, hex_src_string ); |
| 162 | |
| 163 | mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 164 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, data_len, |
| 165 | iv_str, src_str, output ) |
| 166 | == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 167 | if( cbc_result == 0 ) |
| 168 | { |
| 169 | hexify( dst_str, output, data_len ); |
| 170 | |
| 171 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 172 | } |
| 173 | |
| 174 | exit: |
| 175 | mbedtls_aria_free( &ctx ); |
| 176 | } |
| 177 | /* END_CASE */ |
| 178 | |
| 179 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
| 180 | void aria_encrypt_cfb128( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 181 | char *hex_src_string, char *hex_dst_string, |
| 182 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 183 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 184 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 185 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 186 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 187 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 188 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 189 | mbedtls_aria_context ctx; |
| 190 | size_t iv_offset = 0; |
| 191 | int key_len, data_len; |
| 192 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 193 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 194 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 195 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 196 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 197 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 198 | mbedtls_aria_init( &ctx ); |
| 199 | |
| 200 | key_len = unhexify( key_str, hex_key_string ); |
| 201 | unhexify( iv_str, hex_iv_string ); |
| 202 | data_len = unhexify( src_str, hex_src_string ); |
| 203 | |
| 204 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 205 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT, |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 206 | data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame^] | 207 | src_str, output ) |
| 208 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 209 | hexify( dst_str, output, data_len ); |
| 210 | |
| 211 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 212 | |
| 213 | exit: |
| 214 | mbedtls_aria_free( &ctx ); |
| 215 | } |
| 216 | /* END_CASE */ |
| 217 | |
| 218 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
| 219 | void aria_decrypt_cfb128( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 220 | char *hex_src_string, char *hex_dst_string, |
| 221 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 222 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 223 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 224 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 225 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 226 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 227 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 228 | mbedtls_aria_context ctx; |
| 229 | size_t iv_offset = 0; |
| 230 | int key_len, data_len; |
| 231 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 232 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 233 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 234 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 235 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 236 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 237 | mbedtls_aria_init( &ctx ); |
| 238 | |
| 239 | key_len = unhexify( key_str, hex_key_string ); |
| 240 | unhexify( iv_str, hex_iv_string ); |
| 241 | data_len = unhexify( src_str, hex_src_string ); |
| 242 | |
| 243 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 244 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT, |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 245 | data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame^] | 246 | src_str, output ) |
| 247 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 248 | hexify( dst_str, output, data_len ); |
| 249 | |
| 250 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 251 | |
| 252 | exit: |
| 253 | mbedtls_aria_free( &ctx ); |
| 254 | } |
| 255 | /* END_CASE */ |
| 256 | |
| 257 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
| 258 | void aria_encrypt_ctr( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 259 | char *hex_src_string, char *hex_dst_string, |
| 260 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 261 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 262 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 263 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 264 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 265 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 266 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 267 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 268 | mbedtls_aria_context ctx; |
| 269 | size_t iv_offset = 0; |
| 270 | int key_len, data_len; |
| 271 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 272 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 273 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 274 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 275 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 276 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 277 | mbedtls_aria_init( &ctx ); |
| 278 | |
| 279 | key_len = unhexify( key_str, hex_key_string ); |
| 280 | unhexify( iv_str, hex_iv_string ); |
| 281 | data_len = unhexify( src_str, hex_src_string ); |
| 282 | |
| 283 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 284 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame^] | 285 | blk, src_str, output ) |
| 286 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 287 | hexify( dst_str, output, data_len ); |
| 288 | |
| 289 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 290 | |
| 291 | exit: |
| 292 | mbedtls_aria_free( &ctx ); |
| 293 | } |
| 294 | /* END_CASE */ |
| 295 | |
| 296 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
| 297 | void aria_decrypt_ctr( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 298 | char *hex_src_string, char *hex_dst_string, |
| 299 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 300 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 301 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 302 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 303 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 304 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 305 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 306 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 307 | mbedtls_aria_context ctx; |
| 308 | size_t iv_offset = 0; |
| 309 | int key_len, data_len; |
| 310 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 311 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 312 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 313 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 314 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 315 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 316 | mbedtls_aria_init( &ctx ); |
| 317 | |
| 318 | key_len = unhexify( key_str, hex_key_string ); |
| 319 | unhexify( iv_str, hex_iv_string ); |
| 320 | data_len = unhexify( src_str, hex_src_string ); |
| 321 | |
| 322 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 323 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame^] | 324 | blk, src_str, output ) |
| 325 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 326 | hexify( dst_str, output, data_len ); |
| 327 | |
| 328 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 329 | |
| 330 | exit: |
| 331 | mbedtls_aria_free( &ctx ); |
| 332 | } |
| 333 | /* END_CASE */ |
| 334 | |
| 335 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
| 336 | void aria_selftest() |
| 337 | { |
| 338 | TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 ); |
| 339 | } |
| 340 | /* END_CASE */ |