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