Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
| 2 | #include "psa/crypto.h" |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 3 | |
| 4 | #include "mbedtls/md.h" |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 5 | /* END_HEADER */ |
| 6 | |
| 7 | /* BEGIN_DEPENDENCIES |
| 8 | * depends_on:MBEDTLS_PSA_CRYPTO_C |
| 9 | * END_DEPENDENCIES |
| 10 | */ |
| 11 | |
| 12 | /* BEGIN_CASE */ |
| 13 | void init_deinit() |
| 14 | { |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 15 | psa_status_t status; |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 16 | int i; |
| 17 | for( i = 0; i <= 1; i++ ) |
| 18 | { |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 19 | status = psa_crypto_init( ); |
| 20 | TEST_ASSERT( status == PSA_SUCCESS ); |
| 21 | status = psa_crypto_init( ); |
| 22 | TEST_ASSERT( status == PSA_SUCCESS ); |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 23 | mbedtls_psa_crypto_free( ); |
| 24 | } |
| 25 | } |
| 26 | /* END_CASE */ |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 27 | |
| 28 | /* BEGIN_CASE */ |
| 29 | void import( char *hex, int type, int expected_status ) |
| 30 | { |
| 31 | int slot = 1; |
| 32 | psa_status_t status; |
| 33 | unsigned char *data = NULL; |
| 34 | size_t data_size; |
| 35 | |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 36 | data = unhexify_alloc( hex, &data_size ); |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 37 | TEST_ASSERT( data != NULL ); |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 38 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 39 | |
| 40 | status = psa_import_key( slot, type, data, data_size ); |
| 41 | TEST_ASSERT( status == (psa_status_t) expected_status ); |
| 42 | if( status == PSA_SUCCESS ) |
| 43 | TEST_ASSERT( psa_destroy_key( slot ) == PSA_SUCCESS ); |
| 44 | |
| 45 | exit: |
| 46 | mbedtls_free( data ); |
| 47 | mbedtls_psa_crypto_free( ); |
| 48 | } |
| 49 | /* END_CASE */ |
| 50 | |
| 51 | /* BEGIN_CASE */ |
Moran Peker | a964a8f | 2018-06-04 18:42:36 +0300 | [diff] [blame] | 52 | void import_export( char *hex, |
| 53 | int type_arg, |
| 54 | int alg_arg, |
| 55 | int usage_arg, |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 56 | int expected_bits, |
| 57 | int export_size_delta, |
| 58 | int expected_export_status, |
| 59 | int canonical_input ) |
| 60 | { |
| 61 | int slot = 1; |
| 62 | int slot2 = slot + 1; |
| 63 | psa_key_type_t type = type_arg; |
| 64 | psa_status_t status; |
| 65 | unsigned char *data = NULL; |
| 66 | unsigned char *exported = NULL; |
| 67 | unsigned char *reexported = NULL; |
| 68 | size_t data_size; |
| 69 | size_t export_size; |
| 70 | size_t exported_length; |
| 71 | size_t reexported_length; |
| 72 | psa_key_type_t got_type; |
| 73 | size_t got_bits; |
mohammad1603 | a97cb8c | 2018-03-28 03:46:26 -0700 | [diff] [blame] | 74 | psa_key_policy_t policy = {0}; |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 75 | |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 76 | data = unhexify_alloc( hex, &data_size ); |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 77 | TEST_ASSERT( data != NULL ); |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 78 | export_size = (ssize_t) data_size + export_size_delta; |
| 79 | exported = mbedtls_calloc( 1, export_size ); |
| 80 | TEST_ASSERT( exported != NULL ); |
| 81 | if( ! canonical_input ) |
| 82 | { |
| 83 | reexported = mbedtls_calloc( 1, export_size ); |
| 84 | TEST_ASSERT( reexported != NULL ); |
| 85 | } |
| 86 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 87 | |
mohammad1603 | a97cb8c | 2018-03-28 03:46:26 -0700 | [diff] [blame] | 88 | psa_key_policy_init( &policy ); |
| 89 | |
Moran Peker | a964a8f | 2018-06-04 18:42:36 +0300 | [diff] [blame] | 90 | psa_key_policy_set_usage( &policy, usage_arg, alg_arg ); |
mohammad1603 | a97cb8c | 2018-03-28 03:46:26 -0700 | [diff] [blame] | 91 | |
| 92 | TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS ); |
| 93 | |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 94 | /* Import the key */ |
| 95 | TEST_ASSERT( psa_import_key( slot, type, |
| 96 | data, data_size ) == PSA_SUCCESS ); |
| 97 | |
| 98 | /* Test the key information */ |
| 99 | TEST_ASSERT( psa_get_key_information( slot, |
| 100 | &got_type, &got_bits ) == |
| 101 | PSA_SUCCESS ); |
| 102 | TEST_ASSERT( got_type == type ); |
| 103 | TEST_ASSERT( got_bits == (size_t) expected_bits ); |
| 104 | |
| 105 | /* Export the key */ |
| 106 | status = psa_export_key( slot, |
| 107 | exported, export_size, |
| 108 | &exported_length ); |
| 109 | TEST_ASSERT( status == (psa_status_t) expected_export_status ); |
| 110 | if( status != PSA_SUCCESS ) |
| 111 | goto destroy; |
| 112 | |
| 113 | if( canonical_input ) |
| 114 | { |
| 115 | TEST_ASSERT( exported_length == data_size ); |
| 116 | TEST_ASSERT( memcmp( exported, data, data_size ) == 0 ); |
| 117 | } |
| 118 | else |
| 119 | { |
mohammad1603 | a97cb8c | 2018-03-28 03:46:26 -0700 | [diff] [blame] | 120 | TEST_ASSERT( psa_set_key_policy( slot2, &policy ) == PSA_SUCCESS ); |
| 121 | |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 122 | TEST_ASSERT( psa_import_key( slot2, type, |
| 123 | exported, export_size ) == |
| 124 | PSA_SUCCESS ); |
| 125 | TEST_ASSERT( psa_export_key( slot2, |
| 126 | reexported, export_size, |
| 127 | &reexported_length ) == |
| 128 | PSA_SUCCESS ); |
| 129 | TEST_ASSERT( reexported_length == exported_length ); |
| 130 | TEST_ASSERT( memcmp( reexported, exported, |
| 131 | exported_length ) == 0 ); |
| 132 | } |
| 133 | |
| 134 | destroy: |
| 135 | /* Destroy the key */ |
| 136 | TEST_ASSERT( psa_destroy_key( slot ) == PSA_SUCCESS ); |
| 137 | TEST_ASSERT( psa_get_key_information( |
| 138 | slot, NULL, NULL ) == PSA_ERROR_EMPTY_SLOT ); |
| 139 | |
| 140 | exit: |
| 141 | mbedtls_free( data ); |
| 142 | mbedtls_psa_crypto_free( ); |
| 143 | } |
| 144 | /* END_CASE */ |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 145 | |
Moran Peker | f709f4a | 2018-06-06 17:26:04 +0300 | [diff] [blame] | 146 | |
| 147 | /* BEGIN_CASE */ |
| 148 | void import_export_public_key( char *hex, |
| 149 | int type_arg, |
| 150 | int alg_arg, |
| 151 | int expected_bits, |
| 152 | int public_key_expected_length, |
| 153 | int expected_export_status ) |
| 154 | { |
| 155 | int slot = 1; |
| 156 | psa_key_type_t type = type_arg; |
| 157 | psa_status_t status; |
| 158 | unsigned char *data = NULL; |
| 159 | unsigned char *exported = NULL; |
| 160 | size_t data_size; |
| 161 | size_t export_size; |
| 162 | size_t exported_length; |
| 163 | psa_key_type_t got_type; |
| 164 | size_t got_bits; |
| 165 | psa_key_policy_t policy = {0}; |
| 166 | |
| 167 | data = unhexify_alloc( hex, &data_size ); |
| 168 | TEST_ASSERT( data != NULL ); |
| 169 | export_size = (ssize_t) data_size ; |
| 170 | exported = mbedtls_calloc( 1, export_size ); |
| 171 | TEST_ASSERT( exported != NULL ); |
| 172 | |
| 173 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 174 | |
| 175 | psa_key_policy_init( &policy ); |
| 176 | |
| 177 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT, |
| 178 | alg_arg ); |
| 179 | |
| 180 | TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS ); |
| 181 | |
| 182 | /* Import the key */ |
| 183 | TEST_ASSERT( psa_import_key( slot, type, |
| 184 | data, data_size ) == PSA_SUCCESS ); |
| 185 | |
| 186 | /* Test the key information */ |
| 187 | TEST_ASSERT( psa_get_key_information( slot, |
| 188 | &got_type, &got_bits ) == PSA_SUCCESS ); |
| 189 | TEST_ASSERT( got_type == type ); |
| 190 | TEST_ASSERT( got_bits == (size_t) expected_bits ); |
| 191 | |
| 192 | /* Export the key */ |
| 193 | status = psa_export_public_key( slot, |
| 194 | exported, export_size, |
| 195 | &exported_length ); |
| 196 | TEST_ASSERT( status == (psa_status_t) expected_export_status ); |
| 197 | if( status != PSA_SUCCESS ) |
| 198 | goto destroy; |
| 199 | |
| 200 | TEST_ASSERT( exported_length == (size_t) public_key_expected_length ); |
| 201 | |
| 202 | destroy: |
| 203 | /* Destroy the key */ |
| 204 | TEST_ASSERT( psa_destroy_key( slot ) == PSA_SUCCESS ); |
| 205 | TEST_ASSERT( psa_get_key_information( |
| 206 | slot, NULL, NULL ) == PSA_ERROR_EMPTY_SLOT ); |
| 207 | |
| 208 | exit: |
| 209 | mbedtls_free( data ); |
| 210 | mbedtls_psa_crypto_free( ); |
| 211 | } |
| 212 | /* END_CASE */ |
| 213 | |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 214 | /* BEGIN_CASE */ |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 215 | void hash_finish( int alg_arg, char *input_hex, char *hash_hex ) |
| 216 | { |
| 217 | psa_algorithm_t alg = alg_arg; |
| 218 | unsigned char *input = NULL; |
| 219 | size_t input_size; |
| 220 | unsigned char expected_hash[MBEDTLS_MD_MAX_SIZE]; |
| 221 | size_t expected_hash_length; |
| 222 | unsigned char actual_hash[MBEDTLS_MD_MAX_SIZE]; |
| 223 | size_t actual_hash_length; |
| 224 | psa_hash_operation_t operation; |
| 225 | |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 226 | input = unhexify_alloc( input_hex, &input_size ); |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 227 | TEST_ASSERT( input != NULL ); |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 228 | expected_hash_length = unhexify( expected_hash, hash_hex ); |
| 229 | |
| 230 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 231 | |
| 232 | TEST_ASSERT( psa_hash_start( &operation, alg ) == PSA_SUCCESS ); |
| 233 | TEST_ASSERT( psa_hash_update( &operation, |
| 234 | input, input_size ) == PSA_SUCCESS ); |
| 235 | TEST_ASSERT( psa_hash_finish( &operation, |
| 236 | actual_hash, sizeof( actual_hash ), |
| 237 | &actual_hash_length ) == PSA_SUCCESS ); |
| 238 | TEST_ASSERT( actual_hash_length == expected_hash_length ); |
| 239 | TEST_ASSERT( memcmp( expected_hash, actual_hash, |
| 240 | expected_hash_length ) == 0 ); |
| 241 | |
| 242 | exit: |
| 243 | mbedtls_free( input ); |
| 244 | mbedtls_psa_crypto_free( ); |
| 245 | } |
| 246 | /* END_CASE */ |
| 247 | |
| 248 | /* BEGIN_CASE */ |
| 249 | void hash_verify( int alg_arg, char *input_hex, char *hash_hex ) |
| 250 | { |
| 251 | psa_algorithm_t alg = alg_arg; |
| 252 | unsigned char *input = NULL; |
| 253 | size_t input_size; |
| 254 | unsigned char expected_hash[MBEDTLS_MD_MAX_SIZE]; |
| 255 | size_t expected_hash_length; |
| 256 | psa_hash_operation_t operation; |
| 257 | |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 258 | input = unhexify_alloc( input_hex, &input_size ); |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 259 | TEST_ASSERT( input != NULL ); |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 260 | expected_hash_length = unhexify( expected_hash, hash_hex ); |
| 261 | |
| 262 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 263 | |
| 264 | TEST_ASSERT( psa_hash_start( &operation, alg ) == PSA_SUCCESS ); |
| 265 | TEST_ASSERT( psa_hash_update( &operation, |
| 266 | input, input_size ) == PSA_SUCCESS ); |
| 267 | TEST_ASSERT( psa_hash_verify( &operation, |
| 268 | expected_hash, |
| 269 | expected_hash_length ) == PSA_SUCCESS ); |
| 270 | |
| 271 | exit: |
| 272 | mbedtls_free( input ); |
| 273 | mbedtls_psa_crypto_free( ); |
| 274 | } |
| 275 | /* END_CASE */ |
| 276 | |
| 277 | /* BEGIN_CASE */ |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 278 | void mac_verify( int key_type_arg, char *key_hex, |
| 279 | int alg_arg, char *iv_hex, |
| 280 | char *input_hex, char *mac_hex ) |
| 281 | { |
| 282 | int key_slot = 1; |
| 283 | psa_key_type_t key_type = key_type_arg; |
| 284 | psa_algorithm_t alg = alg_arg; |
| 285 | unsigned char *key = NULL; |
| 286 | size_t key_size; |
| 287 | unsigned char *iv = NULL; |
| 288 | size_t iv_size; |
| 289 | unsigned char *input = NULL; |
| 290 | size_t input_size; |
| 291 | unsigned char *expected_mac = NULL; |
| 292 | size_t expected_mac_size; |
| 293 | psa_mac_operation_t operation; |
mohammad1603 | 6df908f | 2018-04-02 08:34:15 -0700 | [diff] [blame] | 294 | psa_key_policy_t policy; |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 295 | |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 296 | key = unhexify_alloc( key_hex, &key_size ); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 297 | TEST_ASSERT( key != NULL ); |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 298 | if( iv_hex[0] != 0 ) |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 299 | { |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 300 | iv = unhexify_alloc( iv_hex, &iv_size ); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 301 | TEST_ASSERT( iv != NULL ); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 302 | } |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 303 | input = unhexify_alloc( input_hex, &input_size ); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 304 | TEST_ASSERT( input != NULL ); |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 305 | expected_mac = unhexify_alloc( mac_hex, &expected_mac_size ); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 306 | TEST_ASSERT( expected_mac != NULL ); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 307 | |
| 308 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 309 | |
mohammad1603 | 6df908f | 2018-04-02 08:34:15 -0700 | [diff] [blame] | 310 | psa_key_policy_init( &policy ); |
| 311 | |
| 312 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, alg_arg ); |
| 313 | |
| 314 | TEST_ASSERT( psa_set_key_policy( key_slot, &policy ) == PSA_SUCCESS ); |
| 315 | |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 316 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 317 | key, key_size ) == PSA_SUCCESS ); |
| 318 | // TODO: support IV |
| 319 | TEST_ASSERT( psa_mac_start( &operation, key_slot, alg ) == PSA_SUCCESS ); |
| 320 | TEST_ASSERT( psa_destroy_key( key_slot ) == PSA_SUCCESS ); |
| 321 | TEST_ASSERT( psa_mac_update( &operation, |
| 322 | input, input_size ) == PSA_SUCCESS ); |
| 323 | TEST_ASSERT( psa_mac_verify( &operation, |
| 324 | expected_mac, |
| 325 | expected_mac_size ) == PSA_SUCCESS ); |
| 326 | |
| 327 | exit: |
| 328 | mbedtls_free( key ); |
| 329 | mbedtls_free( iv ); |
| 330 | mbedtls_free( input ); |
| 331 | mbedtls_free( expected_mac ); |
| 332 | psa_destroy_key( key_slot ); |
| 333 | mbedtls_psa_crypto_free( ); |
| 334 | } |
| 335 | /* END_CASE */ |
| 336 | |
Moran Peker | 7f87850 | 2018-06-06 17:09:40 +0300 | [diff] [blame] | 337 | |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 338 | /* BEGIN_CASE */ |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 339 | void cipher_encrypt( int alg_arg, int key_type_arg, |
| 340 | char *key_hex, |
| 341 | char *input_hex, char *output_hex, |
| 342 | int expected_status ) |
| 343 | { |
| 344 | int key_slot = 1; |
| 345 | psa_status_t status; |
| 346 | psa_key_type_t key_type = key_type_arg; |
| 347 | psa_algorithm_t alg = alg_arg; |
| 348 | unsigned char *key = NULL; |
| 349 | size_t key_size; |
| 350 | unsigned char iv[16] = {0}; |
| 351 | unsigned char *input = NULL; |
| 352 | size_t input_size = 0; |
| 353 | unsigned char *output; |
| 354 | unsigned char *expected_output; |
| 355 | size_t expected_output_size; |
| 356 | size_t output_buffer_size = 0; |
| 357 | size_t function_output_length = 0; |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 358 | size_t total_output_length = 0; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 359 | psa_cipher_operation_t operation; |
| 360 | |
| 361 | |
| 362 | key = unhexify_alloc( key_hex, &key_size ); |
| 363 | TEST_ASSERT( key != NULL ); |
| 364 | |
| 365 | input = unhexify_alloc( input_hex, &input_size ); |
| 366 | TEST_ASSERT( input != NULL ); |
| 367 | |
| 368 | expected_output = unhexify_alloc( output_hex, &expected_output_size ); |
| 369 | TEST_ASSERT( expected_output != NULL ); |
| 370 | |
| 371 | memset( iv, 0x2a, sizeof( iv ) ); |
| 372 | |
| 373 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 374 | |
| 375 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 376 | key, key_size ) == PSA_SUCCESS ); |
| 377 | |
| 378 | TEST_ASSERT( psa_encrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS ); |
| 379 | |
| 380 | TEST_ASSERT( psa_encrypt_set_iv( &operation, |
| 381 | iv, sizeof( iv ) ) == PSA_SUCCESS ); |
| 382 | output_buffer_size = input_size + operation.block_size; |
| 383 | output = mbedtls_calloc( 1, output_buffer_size ); |
| 384 | |
| 385 | TEST_ASSERT( psa_cipher_update( &operation, input, input_size, |
| 386 | output, output_buffer_size, |
| 387 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 388 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 389 | status = psa_cipher_finish( &operation, |
| 390 | output + function_output_length, |
| 391 | output_buffer_size, |
| 392 | &function_output_length ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 393 | total_output_length += function_output_length; |
| 394 | |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 395 | TEST_ASSERT( status == (psa_status_t) expected_status ); |
| 396 | if( expected_status == PSA_SUCCESS ) |
| 397 | { |
| 398 | TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 399 | TEST_ASSERT( total_output_length == expected_output_size ); |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 400 | TEST_ASSERT( memcmp( expected_output, output, |
| 401 | expected_output_size ) == 0 ); |
| 402 | } |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 403 | |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 404 | exit: |
| 405 | mbedtls_free( key ); |
| 406 | mbedtls_free( input ); |
| 407 | psa_destroy_key( key_slot ); |
| 408 | mbedtls_psa_crypto_free( ); |
| 409 | } |
| 410 | /* END_CASE */ |
| 411 | |
| 412 | /* BEGIN_CASE */ |
| 413 | void cipher_encrypt_multipart( int alg_arg, int key_type_arg, |
| 414 | char *key_hex, |
| 415 | char *input_hex, |
| 416 | int first_part_size, char *output_hex ) |
| 417 | { |
| 418 | int key_slot = 1; |
| 419 | psa_key_type_t key_type = key_type_arg; |
| 420 | psa_algorithm_t alg = alg_arg; |
| 421 | unsigned char *key = NULL; |
| 422 | size_t key_size; |
| 423 | unsigned char iv[16] = {0}; |
| 424 | unsigned char *input = NULL; |
| 425 | size_t input_size = 0; |
| 426 | unsigned char *output; |
| 427 | unsigned char *expected_output; |
| 428 | size_t expected_output_size; |
| 429 | size_t output_buffer_size = 0; |
| 430 | size_t function_output_length = 0; |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 431 | size_t total_output_length = 0; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 432 | psa_cipher_operation_t operation; |
| 433 | |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 434 | key = unhexify_alloc( key_hex, &key_size ); |
| 435 | TEST_ASSERT( key != NULL ); |
| 436 | |
| 437 | input = unhexify_alloc( input_hex, &input_size ); |
| 438 | TEST_ASSERT( input != NULL ); |
| 439 | |
| 440 | expected_output = unhexify_alloc( output_hex, &expected_output_size ); |
| 441 | TEST_ASSERT( expected_output != NULL ); |
| 442 | |
| 443 | memset( iv, 0x2a, sizeof( iv ) ); |
| 444 | |
| 445 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 446 | |
| 447 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 448 | key, key_size ) == PSA_SUCCESS ); |
| 449 | |
| 450 | TEST_ASSERT( psa_encrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS ); |
| 451 | |
| 452 | TEST_ASSERT( psa_encrypt_set_iv( &operation, |
| 453 | iv, sizeof( iv ) ) == PSA_SUCCESS ); |
| 454 | output_buffer_size = input_size + operation.block_size; |
| 455 | output = mbedtls_calloc( 1, output_buffer_size ); |
| 456 | |
| 457 | TEST_ASSERT( (unsigned int) first_part_size < input_size ); |
| 458 | TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size, |
| 459 | output, output_buffer_size, |
| 460 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 461 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 462 | TEST_ASSERT( psa_cipher_update( &operation, |
| 463 | input + first_part_size, |
| 464 | input_size - first_part_size, |
| 465 | output, output_buffer_size, |
| 466 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 467 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 468 | TEST_ASSERT( psa_cipher_finish( &operation, |
| 469 | output + function_output_length, |
| 470 | output_buffer_size, |
| 471 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 472 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 473 | TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); |
| 474 | |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 475 | TEST_ASSERT( total_output_length == expected_output_size ); |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 476 | TEST_ASSERT( memcmp( expected_output, output, expected_output_size ) == 0 ); |
| 477 | |
| 478 | exit: |
| 479 | mbedtls_free( key ); |
| 480 | mbedtls_free( input ); |
| 481 | psa_destroy_key( key_slot ); |
| 482 | mbedtls_psa_crypto_free( ); |
| 483 | } |
| 484 | /* END_CASE */ |
| 485 | |
| 486 | /* BEGIN_CASE */ |
| 487 | void cipher_decrypt_multipart( int alg_arg, int key_type_arg, |
| 488 | char *key_hex, |
| 489 | char *input_hex, |
| 490 | int first_part_size, char *output_hex ) |
| 491 | { |
| 492 | int key_slot = 1; |
| 493 | |
| 494 | psa_key_type_t key_type = key_type_arg; |
| 495 | psa_algorithm_t alg = alg_arg; |
| 496 | unsigned char *key = NULL; |
| 497 | size_t key_size; |
| 498 | unsigned char iv[16] = {0}; |
| 499 | unsigned char *input = NULL; |
| 500 | size_t input_size = 0; |
| 501 | unsigned char *output; |
| 502 | unsigned char *expected_output; |
| 503 | size_t expected_output_size; |
| 504 | size_t output_buffer_size = 0; |
| 505 | size_t function_output_length = 0; |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 506 | size_t total_output_length = 0; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 507 | psa_cipher_operation_t operation; |
| 508 | |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 509 | key = unhexify_alloc( key_hex, &key_size ); |
| 510 | TEST_ASSERT( key != NULL ); |
| 511 | |
| 512 | input = unhexify_alloc( input_hex, &input_size ); |
| 513 | TEST_ASSERT( input != NULL ); |
| 514 | |
| 515 | expected_output = unhexify_alloc( output_hex, &expected_output_size ); |
| 516 | TEST_ASSERT( expected_output != NULL ); |
| 517 | |
| 518 | memset( iv, 0x2a, sizeof( iv ) ); |
| 519 | |
| 520 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 521 | |
| 522 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 523 | key, key_size ) == PSA_SUCCESS ); |
| 524 | |
| 525 | TEST_ASSERT( psa_decrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS ); |
| 526 | |
| 527 | TEST_ASSERT( psa_encrypt_set_iv( &operation, |
| 528 | iv, sizeof( iv ) ) == PSA_SUCCESS ); |
| 529 | |
| 530 | output_buffer_size = input_size + operation.block_size; |
| 531 | output = mbedtls_calloc( 1, output_buffer_size ); |
| 532 | |
| 533 | TEST_ASSERT( (unsigned int) first_part_size < input_size ); |
| 534 | TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size, |
| 535 | output, output_buffer_size, |
| 536 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 537 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 538 | TEST_ASSERT( psa_cipher_update( &operation, |
| 539 | input + first_part_size, |
| 540 | input_size - first_part_size, |
| 541 | output, output_buffer_size, |
| 542 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 543 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 544 | TEST_ASSERT( psa_cipher_finish( &operation, |
| 545 | output + function_output_length, |
| 546 | output_buffer_size, |
| 547 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 548 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 549 | TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); |
| 550 | |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 551 | TEST_ASSERT( total_output_length == expected_output_size ); |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 552 | TEST_ASSERT( memcmp( expected_output, output, expected_output_size ) == 0 ); |
| 553 | |
| 554 | exit: |
| 555 | mbedtls_free( key ); |
| 556 | mbedtls_free( input ); |
| 557 | psa_destroy_key( key_slot ); |
| 558 | mbedtls_psa_crypto_free( ); |
| 559 | } |
| 560 | /* END_CASE */ |
| 561 | |
| 562 | |
| 563 | /* BEGIN_CASE */ |
| 564 | void cipher_decrypt( int alg_arg, int key_type_arg, |
| 565 | char *key_hex, |
| 566 | char *input_hex, char *output_hex, |
| 567 | int expected_status ) |
| 568 | { |
| 569 | int key_slot = 1; |
| 570 | psa_status_t status; |
| 571 | psa_key_type_t key_type = key_type_arg; |
| 572 | psa_algorithm_t alg = alg_arg; |
| 573 | unsigned char *key = NULL; |
| 574 | size_t key_size; |
| 575 | unsigned char iv[16] = {0}; |
| 576 | unsigned char *input = NULL; |
| 577 | size_t input_size = 0; |
| 578 | unsigned char *output; |
| 579 | unsigned char *expected_output; |
| 580 | size_t expected_output_size; |
| 581 | size_t output_buffer_size = 0; |
| 582 | size_t function_output_length = 0; |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 583 | size_t total_output_length = 0; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 584 | psa_cipher_operation_t operation; |
| 585 | |
| 586 | |
| 587 | key = unhexify_alloc( key_hex, &key_size ); |
| 588 | TEST_ASSERT( key != NULL ); |
| 589 | |
| 590 | input = unhexify_alloc( input_hex, &input_size ); |
| 591 | TEST_ASSERT( input != NULL ); |
| 592 | |
| 593 | expected_output = unhexify_alloc( output_hex, &expected_output_size ); |
| 594 | TEST_ASSERT( expected_output != NULL ); |
| 595 | |
| 596 | memset( iv, 0x2a, sizeof( iv ) ); |
| 597 | |
| 598 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 599 | |
| 600 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 601 | key, key_size ) == PSA_SUCCESS ); |
| 602 | |
| 603 | TEST_ASSERT( psa_decrypt_setup( &operation, key_slot, alg ) == PSA_SUCCESS ); |
| 604 | |
| 605 | TEST_ASSERT( psa_encrypt_set_iv( &operation, |
| 606 | iv, sizeof( iv ) ) == PSA_SUCCESS ); |
| 607 | |
| 608 | output_buffer_size = input_size + operation.block_size; |
| 609 | output = mbedtls_calloc( 1, output_buffer_size ); |
| 610 | |
| 611 | TEST_ASSERT( psa_cipher_update( &operation, input, input_size, |
| 612 | output, output_buffer_size, |
| 613 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 614 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 615 | status = psa_cipher_finish( &operation, |
| 616 | output + function_output_length, |
| 617 | output_buffer_size, |
| 618 | &function_output_length ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 619 | total_output_length += function_output_length; |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 620 | TEST_ASSERT( status == (psa_status_t) expected_status ); |
| 621 | |
| 622 | if( expected_status == PSA_SUCCESS ) |
| 623 | { |
| 624 | TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); |
Gilles Peskine | a7ec95f | 2018-06-08 14:40:59 +0200 | [diff] [blame] | 625 | TEST_ASSERT( total_output_length == expected_output_size ); |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 626 | TEST_ASSERT( memcmp( expected_output, output, |
| 627 | expected_output_size ) == 0 ); |
| 628 | } |
| 629 | |
| 630 | |
| 631 | exit: |
| 632 | mbedtls_free( key ); |
| 633 | mbedtls_free( input ); |
| 634 | psa_destroy_key( key_slot ); |
| 635 | mbedtls_psa_crypto_free( ); |
| 636 | } |
| 637 | /* END_CASE */ |
| 638 | |
| 639 | |
| 640 | /* BEGIN_CASE */ |
| 641 | void cipher_verify_output( int alg_arg, int key_type_arg, |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 642 | char *key_hex, |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 643 | char *input_hex ) |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 644 | { |
| 645 | int key_slot = 1; |
| 646 | psa_key_type_t key_type = key_type_arg; |
| 647 | psa_algorithm_t alg = alg_arg; |
| 648 | unsigned char *key = NULL; |
| 649 | size_t key_size; |
mohammad1603 | e6b67a1 | 2018-03-12 10:38:49 -0700 | [diff] [blame] | 650 | unsigned char iv[16] = {0}; |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 651 | size_t iv_size = 16; |
| 652 | size_t iv_length = 0; |
| 653 | unsigned char *input = NULL; |
| 654 | size_t input_size = 0; |
Moran Peker | 3205a65 | 2018-03-20 17:09:59 +0200 | [diff] [blame] | 655 | unsigned char *output1; |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 656 | size_t output1_size = 0; |
| 657 | size_t output1_length = 0; |
Moran Peker | 3205a65 | 2018-03-20 17:09:59 +0200 | [diff] [blame] | 658 | unsigned char *output2; |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 659 | size_t output2_size = 0; |
| 660 | size_t output2_length = 0; |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 661 | size_t function_output_length = 0; |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 662 | psa_cipher_operation_t operation1; |
| 663 | psa_cipher_operation_t operation2; |
| 664 | |
| 665 | key = unhexify_alloc( key_hex, &key_size ); |
| 666 | TEST_ASSERT( key != NULL ); |
| 667 | |
| 668 | input = unhexify_alloc( input_hex, &input_size ); |
| 669 | TEST_ASSERT( input != NULL ); |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 670 | |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 671 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 672 | |
| 673 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 674 | key, key_size ) == PSA_SUCCESS ); |
| 675 | |
Moran Peker | f55e804 | 2018-05-29 16:28:28 +0300 | [diff] [blame] | 676 | TEST_ASSERT( psa_encrypt_setup( &operation1, key_slot, alg ) == PSA_SUCCESS ); |
| 677 | TEST_ASSERT( psa_decrypt_setup( &operation2, key_slot, alg ) == PSA_SUCCESS ); |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 678 | |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 679 | TEST_ASSERT( psa_encrypt_generate_iv( &operation1, |
| 680 | iv, iv_size, |
| 681 | &iv_length ) == PSA_SUCCESS ); |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 682 | output1_size = input_size + operation1.block_size; |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 683 | output1 = mbedtls_calloc( 1, output1_size ); |
| 684 | TEST_ASSERT( output1 != NULL ); |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 685 | |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 686 | TEST_ASSERT( psa_cipher_update( &operation1, input, input_size, |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 687 | output1, output1_size, |
| 688 | &output1_length ) == PSA_SUCCESS ); |
| 689 | TEST_ASSERT( psa_cipher_finish( &operation1, |
| 690 | output1 + output1_length, output1_size, |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 691 | &function_output_length ) == PSA_SUCCESS ); |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 692 | |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 693 | output1_length += function_output_length; |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 694 | |
| 695 | TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS ); |
| 696 | |
| 697 | output2_size = output1_length; |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 698 | output2 = mbedtls_calloc( 1, output2_size ); |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 699 | |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 700 | TEST_ASSERT( psa_encrypt_set_iv( &operation2, |
| 701 | iv, iv_length ) == PSA_SUCCESS ); |
| 702 | TEST_ASSERT( psa_cipher_update( &operation2, output1, output1_length, |
| 703 | output2, output2_size, |
| 704 | &output2_length ) == PSA_SUCCESS ); |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 705 | function_output_length = 0; |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 706 | TEST_ASSERT( psa_cipher_finish( &operation2, |
| 707 | output2 + output2_length, |
| 708 | output2_size, |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 709 | &function_output_length ) == PSA_SUCCESS ); |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 710 | |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 711 | output2_length += function_output_length; |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 712 | |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 713 | TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS ); |
| 714 | |
| 715 | TEST_ASSERT( input_size == output2_length ); |
| 716 | TEST_ASSERT( memcmp( input, output2, input_size ) == 0 ); |
| 717 | |
| 718 | exit: |
| 719 | mbedtls_free( key ); |
| 720 | mbedtls_free( input ); |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 721 | psa_destroy_key( key_slot ); |
| 722 | mbedtls_psa_crypto_free( ); |
| 723 | } |
| 724 | /* END_CASE */ |
| 725 | |
| 726 | /* BEGIN_CASE */ |
Gilles Peskine | 50e586b | 2018-06-08 14:28:46 +0200 | [diff] [blame] | 727 | void cipher_verify_output_multipart( int alg_arg, |
| 728 | int key_type_arg, |
| 729 | char *key_hex, |
| 730 | char *input_hex, |
| 731 | int first_part_size ) |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 732 | { |
| 733 | int key_slot = 1; |
| 734 | psa_key_type_t key_type = key_type_arg; |
| 735 | psa_algorithm_t alg = alg_arg; |
| 736 | unsigned char *key = NULL; |
| 737 | size_t key_size; |
| 738 | unsigned char iv[16] = {0}; |
| 739 | size_t iv_size = 16; |
| 740 | size_t iv_length = 0; |
| 741 | unsigned char *input = NULL; |
| 742 | size_t input_size = 0; |
| 743 | unsigned char *output1; |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 744 | size_t output1_buffer_size = 0; |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 745 | size_t output1_length = 0; |
| 746 | unsigned char *output2; |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 747 | size_t output2_buffer_size = 0; |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 748 | size_t output2_length = 0; |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 749 | size_t function_output_length; |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 750 | psa_cipher_operation_t operation1; |
| 751 | psa_cipher_operation_t operation2; |
| 752 | |
| 753 | key = unhexify_alloc( key_hex, &key_size ); |
| 754 | TEST_ASSERT( key != NULL ); |
| 755 | |
| 756 | input = unhexify_alloc( input_hex, &input_size ); |
| 757 | TEST_ASSERT( input != NULL ); |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 758 | |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 759 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 760 | |
| 761 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 762 | key, key_size ) == PSA_SUCCESS ); |
| 763 | |
| 764 | TEST_ASSERT( psa_encrypt_setup( &operation1, key_slot, alg ) == PSA_SUCCESS ); |
| 765 | TEST_ASSERT( psa_decrypt_setup( &operation2, key_slot, alg ) == PSA_SUCCESS ); |
| 766 | |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 767 | TEST_ASSERT( psa_encrypt_generate_iv( &operation1, |
| 768 | iv, iv_size, |
| 769 | &iv_length ) == PSA_SUCCESS ); |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 770 | output1_buffer_size = input_size + operation1.block_size; |
| 771 | output1 = mbedtls_calloc( 1, output1_buffer_size ); |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 772 | |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 773 | TEST_ASSERT( (unsigned int) first_part_size < input_size ); |
| 774 | |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 775 | TEST_ASSERT( psa_cipher_update( &operation1, input, first_part_size, |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 776 | output1, output1_buffer_size, |
| 777 | &function_output_length ) == PSA_SUCCESS ); |
| 778 | output1_length += function_output_length; |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 779 | |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 780 | TEST_ASSERT( psa_cipher_update( &operation1, |
| 781 | input + first_part_size, |
| 782 | input_size - first_part_size, |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 783 | output1, output1_buffer_size, |
| 784 | &function_output_length ) == PSA_SUCCESS ); |
| 785 | output1_length += function_output_length; |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 786 | |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 787 | TEST_ASSERT( psa_cipher_finish( &operation1, |
| 788 | output1 + output1_length, |
| 789 | output1_buffer_size - output1_length, |
| 790 | &function_output_length ) == PSA_SUCCESS ); |
| 791 | output1_length += function_output_length; |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 792 | |
| 793 | TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS ); |
| 794 | |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 795 | output2_buffer_size = output1_length; |
| 796 | output2 = mbedtls_calloc( 1, output2_buffer_size ); |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 797 | |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 798 | TEST_ASSERT( psa_encrypt_set_iv( &operation2, |
| 799 | iv, iv_length ) == PSA_SUCCESS ); |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 800 | |
| 801 | TEST_ASSERT( psa_cipher_update( &operation2, output1, first_part_size, |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 802 | output2, output2_buffer_size, |
| 803 | &function_output_length ) == PSA_SUCCESS ); |
| 804 | output2_length += function_output_length; |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 805 | |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 806 | TEST_ASSERT( psa_cipher_update( &operation2, |
| 807 | output1 + first_part_size, |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 808 | output1_length - first_part_size, |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 809 | output2, output2_buffer_size, |
| 810 | &function_output_length ) == PSA_SUCCESS ); |
| 811 | output2_length += function_output_length; |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 812 | |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 813 | TEST_ASSERT( psa_cipher_finish( &operation2, |
| 814 | output2 + output2_length, |
Gilles Peskine | 048b7f0 | 2018-06-08 14:20:49 +0200 | [diff] [blame] | 815 | output2_buffer_size - output2_length, |
| 816 | &function_output_length ) == PSA_SUCCESS ); |
| 817 | output2_length += function_output_length; |
Gilles Peskine | 4ca9c3f | 2018-06-06 18:44:09 +0200 | [diff] [blame] | 818 | |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 819 | TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS ); |
| 820 | |
Moran Peker | ded8440 | 2018-06-06 16:36:50 +0300 | [diff] [blame] | 821 | TEST_ASSERT( input_size == output2_length ); |
mohammad1603 | e6b67a1 | 2018-03-12 10:38:49 -0700 | [diff] [blame] | 822 | TEST_ASSERT( memcmp( input, output2, input_size ) == 0 ); |
mohammad1603 | d7d7ba5 | 2018-03-12 18:51:53 +0200 | [diff] [blame] | 823 | |
| 824 | exit: |
| 825 | mbedtls_free( key ); |
| 826 | mbedtls_free( input ); |
| 827 | psa_destroy_key( key_slot ); |
| 828 | mbedtls_psa_crypto_free( ); |
| 829 | } |
| 830 | /* END_CASE */ |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 831 | |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 832 | /* BEGIN_CASE */ |
| 833 | void signature_size( int type_arg, int bits, int alg_arg, int expected_size_arg ) |
| 834 | { |
Gilles Peskine | 0189e75 | 2018-02-03 23:57:22 +0100 | [diff] [blame] | 835 | psa_key_type_t type = type_arg; |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 836 | psa_algorithm_t alg = alg_arg; |
| 837 | size_t actual_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(type, bits, alg); |
| 838 | TEST_ASSERT( actual_size == (size_t) expected_size_arg ); |
| 839 | exit: |
| 840 | ; |
| 841 | } |
| 842 | /* END_CASE */ |
| 843 | |
| 844 | /* BEGIN_CASE */ |
| 845 | void sign_deterministic( int key_type_arg, char *key_hex, |
| 846 | int alg_arg, char *input_hex, char *output_hex ) |
| 847 | { |
| 848 | int slot = 1; |
| 849 | psa_key_type_t key_type = key_type_arg; |
| 850 | psa_algorithm_t alg = alg_arg; |
| 851 | unsigned char *key_data = NULL; |
| 852 | size_t key_size; |
| 853 | size_t key_bits; |
| 854 | unsigned char *input_data = NULL; |
Gilles Peskine | 93aa033 | 2018-02-03 23:58:03 +0100 | [diff] [blame] | 855 | size_t input_size; |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 856 | unsigned char *output_data = NULL; |
| 857 | size_t output_size; |
| 858 | unsigned char *signature = NULL; |
| 859 | size_t signature_size; |
| 860 | size_t signature_length = 0xdeadbeef; |
mohammad1603 | a97cb8c | 2018-03-28 03:46:26 -0700 | [diff] [blame] | 861 | psa_key_policy_t policy = {0}; |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 862 | |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 863 | key_data = unhexify_alloc( key_hex, &key_size ); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 864 | TEST_ASSERT( key_data != NULL ); |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 865 | input_data = unhexify_alloc( input_hex, &input_size ); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 866 | TEST_ASSERT( input_data != NULL ); |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 867 | output_data = unhexify_alloc( output_hex, &output_size ); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 868 | TEST_ASSERT( output_data != NULL ); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 869 | |
| 870 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 871 | |
mohammad1603 | a97cb8c | 2018-03-28 03:46:26 -0700 | [diff] [blame] | 872 | psa_key_policy_init( &policy ); |
| 873 | |
| 874 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg_arg ); |
| 875 | |
| 876 | TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS ); |
| 877 | |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 878 | TEST_ASSERT( psa_import_key( slot, key_type, |
| 879 | key_data, key_size ) == PSA_SUCCESS ); |
| 880 | TEST_ASSERT( psa_get_key_information( slot, |
| 881 | NULL, |
| 882 | &key_bits ) == PSA_SUCCESS ); |
| 883 | |
| 884 | signature_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, alg, key_bits ); |
| 885 | TEST_ASSERT( signature_size != 0 ); |
| 886 | signature = mbedtls_calloc( 1, signature_size ); |
| 887 | TEST_ASSERT( signature != NULL ); |
| 888 | |
| 889 | TEST_ASSERT( psa_asymmetric_sign( slot, alg, |
| 890 | input_data, input_size, |
| 891 | NULL, 0, |
| 892 | signature, signature_size, |
| 893 | &signature_length ) == PSA_SUCCESS ); |
| 894 | TEST_ASSERT( signature_length == output_size ); |
| 895 | TEST_ASSERT( memcmp( signature, output_data, output_size ) == 0 ); |
| 896 | |
| 897 | exit: |
| 898 | psa_destroy_key( slot ); |
| 899 | mbedtls_free( key_data ); |
| 900 | mbedtls_free( input_data ); |
| 901 | mbedtls_free( output_data ); |
| 902 | mbedtls_free( signature ); |
| 903 | mbedtls_psa_crypto_free( ); |
| 904 | } |
| 905 | /* END_CASE */ |
| 906 | |
| 907 | /* BEGIN_CASE */ |
| 908 | void sign_fail( int key_type_arg, char *key_hex, |
| 909 | int alg_arg, char *input_hex, |
| 910 | int signature_size, int expected_status_arg ) |
| 911 | { |
| 912 | int slot = 1; |
| 913 | psa_key_type_t key_type = key_type_arg; |
| 914 | psa_algorithm_t alg = alg_arg; |
| 915 | unsigned char *key_data = NULL; |
| 916 | size_t key_size; |
| 917 | unsigned char *input_data = NULL; |
| 918 | size_t input_size; |
| 919 | psa_status_t actual_status; |
| 920 | psa_status_t expected_status = expected_status_arg; |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 921 | unsigned char *signature = NULL; |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 922 | size_t signature_length = 0xdeadbeef; |
mohammad1603 | a97cb8c | 2018-03-28 03:46:26 -0700 | [diff] [blame] | 923 | psa_key_policy_t policy = {0}; |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 924 | |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 925 | key_data = unhexify_alloc( key_hex, &key_size ); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 926 | TEST_ASSERT( key_data != NULL ); |
Gilles Peskine | 40f68b9 | 2018-03-07 16:43:36 +0100 | [diff] [blame] | 927 | input_data = unhexify_alloc( input_hex, &input_size ); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 928 | TEST_ASSERT( input_data != NULL ); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 929 | signature = mbedtls_calloc( 1, signature_size ); |
| 930 | TEST_ASSERT( signature != NULL ); |
| 931 | |
| 932 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 933 | |
mohammad1603 | a97cb8c | 2018-03-28 03:46:26 -0700 | [diff] [blame] | 934 | psa_key_policy_init( &policy ); |
| 935 | |
| 936 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg_arg ); |
| 937 | |
| 938 | TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS ); |
| 939 | |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 940 | TEST_ASSERT( psa_import_key( slot, key_type, |
| 941 | key_data, key_size ) == PSA_SUCCESS ); |
| 942 | |
| 943 | actual_status = psa_asymmetric_sign( slot, alg, |
| 944 | input_data, input_size, |
| 945 | NULL, 0, |
| 946 | signature, signature_size, |
| 947 | &signature_length ); |
| 948 | TEST_ASSERT( actual_status == expected_status ); |
Gilles Peskine | 93aa033 | 2018-02-03 23:58:03 +0100 | [diff] [blame] | 949 | TEST_ASSERT( signature_length == 0 ); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 950 | |
| 951 | exit: |
| 952 | psa_destroy_key( slot ); |
| 953 | mbedtls_free( key_data ); |
| 954 | mbedtls_free( input_data ); |
| 955 | mbedtls_free( signature ); |
| 956 | mbedtls_psa_crypto_free( ); |
| 957 | } |
| 958 | /* END_CASE */ |
mohammad1603 | 8cc1cee | 2018-03-28 01:21:33 +0300 | [diff] [blame] | 959 | |
| 960 | /* BEGIN_CASE */ |
| 961 | void key_policy( int usage_arg, int alg_arg ) |
| 962 | { |
| 963 | int key_slot = 1; |
mohammad1603 | 4eed757 | 2018-03-28 05:14:59 -0700 | [diff] [blame] | 964 | psa_key_type_t key_type = PSA_KEY_TYPE_AES; |
mohammad1603 | 8cc1cee | 2018-03-28 01:21:33 +0300 | [diff] [blame] | 965 | unsigned char key[32] = {0}; |
| 966 | psa_key_policy_t policy_set = {0}; |
| 967 | psa_key_policy_t policy_get = {0}; |
| 968 | |
| 969 | memset( key, 0x2a, sizeof( key ) ); |
| 970 | |
| 971 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 972 | |
| 973 | psa_key_policy_init(& policy_set ); |
| 974 | psa_key_policy_init(& policy_get ); |
| 975 | |
| 976 | psa_key_policy_set_usage( &policy_set, usage_arg, alg_arg ); |
| 977 | |
| 978 | TEST_ASSERT( psa_key_policy_get_usage( &policy_set ) == ( psa_key_usage_t )usage_arg ); |
| 979 | |
| 980 | TEST_ASSERT( psa_key_policy_get_algorithm( &policy_set) == ( psa_algorithm_t )alg_arg ); |
| 981 | |
| 982 | TEST_ASSERT( psa_set_key_policy( key_slot, &policy_set ) == PSA_SUCCESS ); |
| 983 | |
| 984 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 985 | key, sizeof( key ) ) == PSA_SUCCESS ); |
| 986 | |
| 987 | TEST_ASSERT( psa_get_key_policy( key_slot, &policy_get ) == PSA_SUCCESS ); |
| 988 | |
| 989 | TEST_ASSERT( policy_get.usage == policy_set.usage ); |
| 990 | TEST_ASSERT( policy_get.alg == policy_set.alg ); |
| 991 | |
| 992 | exit: |
| 993 | psa_destroy_key( key_slot ); |
| 994 | mbedtls_psa_crypto_free( ); |
| 995 | } |
| 996 | /* END_CASE */ |
| 997 | |
mohammad1603 | 4eed757 | 2018-03-28 05:14:59 -0700 | [diff] [blame] | 998 | /* BEGIN_CASE */ |
| 999 | void key_policy_fail( int usage_arg, int alg_arg, int expected_status, char *key_hex ) |
| 1000 | { |
| 1001 | int key_slot = 1; |
mohammad1603 | 4eed757 | 2018-03-28 05:14:59 -0700 | [diff] [blame] | 1002 | unsigned char* keypair = NULL; |
| 1003 | size_t key_size = 0; |
| 1004 | size_t signature_length = 0; |
| 1005 | psa_key_policy_t policy = {0}; |
| 1006 | int actual_status = PSA_SUCCESS; |
mohammad1603 | 4eed757 | 2018-03-28 05:14:59 -0700 | [diff] [blame] | 1007 | |
| 1008 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 1009 | |
| 1010 | psa_key_policy_init( &policy ); |
| 1011 | |
| 1012 | psa_key_policy_set_usage( &policy, usage_arg, alg_arg ); |
| 1013 | |
| 1014 | TEST_ASSERT( psa_set_key_policy( key_slot, &policy ) == PSA_SUCCESS ); |
| 1015 | |
mohammad1603 | 6df908f | 2018-04-02 08:34:15 -0700 | [diff] [blame] | 1016 | if( usage_arg & PSA_KEY_USAGE_EXPORT ) |
mohammad1603 | 4eed757 | 2018-03-28 05:14:59 -0700 | [diff] [blame] | 1017 | { |
mohammad1603 | 6df908f | 2018-04-02 08:34:15 -0700 | [diff] [blame] | 1018 | keypair = unhexify_alloc( key_hex, &key_size ); |
| 1019 | TEST_ASSERT( keypair != NULL ); |
| 1020 | TEST_ASSERT( psa_import_key( key_slot, PSA_KEY_TYPE_RSA_KEYPAIR, |
| 1021 | keypair, key_size ) == PSA_SUCCESS ); |
| 1022 | actual_status = psa_asymmetric_sign( key_slot, |
| 1023 | ( psa_algorithm_t )alg_arg, NULL, 0, NULL, 0, |
| 1024 | NULL, 0, &signature_length ); |
| 1025 | } |
| 1026 | |
| 1027 | if( usage_arg & PSA_KEY_USAGE_SIGN ) |
| 1028 | { |
mohammad1603 | d926b88 | 2018-04-16 01:53:20 -0700 | [diff] [blame] | 1029 | keypair = unhexify_alloc( key_hex, &key_size ); |
| 1030 | TEST_ASSERT( keypair != NULL ); |
mohammad1603 | 6df908f | 2018-04-02 08:34:15 -0700 | [diff] [blame] | 1031 | TEST_ASSERT( psa_import_key( key_slot, PSA_KEY_TYPE_RSA_KEYPAIR, |
mohammad1603 | d926b88 | 2018-04-16 01:53:20 -0700 | [diff] [blame] | 1032 | keypair, key_size ) == PSA_SUCCESS ); |
mohammad1603 | 6df908f | 2018-04-02 08:34:15 -0700 | [diff] [blame] | 1033 | actual_status = psa_export_key( key_slot, NULL, 0, NULL ); |
mohammad1603 | 4eed757 | 2018-03-28 05:14:59 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | TEST_ASSERT( actual_status == expected_status ); |
| 1037 | |
| 1038 | exit: |
| 1039 | psa_destroy_key( key_slot ); |
mohammad1603 | d926b88 | 2018-04-16 01:53:20 -0700 | [diff] [blame] | 1040 | mbedtls_free( keypair ); |
mohammad1603 | 4eed757 | 2018-03-28 05:14:59 -0700 | [diff] [blame] | 1041 | mbedtls_psa_crypto_free( ); |
| 1042 | } |
| 1043 | /* END_CASE */ |
Gilles Peskine | a0655c3 | 2018-04-30 17:06:50 +0200 | [diff] [blame] | 1044 | |
| 1045 | /* BEGIN_CASE */ |
| 1046 | void key_lifetime( int lifetime_arg ) |
| 1047 | { |
| 1048 | int key_slot = 1; |
| 1049 | psa_key_type_t key_type = PSA_ALG_CBC_BASE; |
| 1050 | unsigned char key[32] = {0}; |
| 1051 | psa_key_lifetime_t lifetime_set = (psa_key_lifetime_t) lifetime_arg; |
| 1052 | psa_key_lifetime_t lifetime_get; |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 1053 | |
Gilles Peskine | a0655c3 | 2018-04-30 17:06:50 +0200 | [diff] [blame] | 1054 | memset( key, 0x2a, sizeof( key ) ); |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 1055 | |
Gilles Peskine | a0655c3 | 2018-04-30 17:06:50 +0200 | [diff] [blame] | 1056 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 1057 | |
Gilles Peskine | a0655c3 | 2018-04-30 17:06:50 +0200 | [diff] [blame] | 1058 | TEST_ASSERT( psa_set_key_lifetime( key_slot, |
| 1059 | lifetime_set ) == PSA_SUCCESS ); |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 1060 | |
Gilles Peskine | a0655c3 | 2018-04-30 17:06:50 +0200 | [diff] [blame] | 1061 | TEST_ASSERT( psa_import_key( key_slot, key_type, |
| 1062 | key, sizeof( key ) ) == PSA_SUCCESS ); |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 1063 | |
Gilles Peskine | a0655c3 | 2018-04-30 17:06:50 +0200 | [diff] [blame] | 1064 | TEST_ASSERT( psa_get_key_lifetime( key_slot, |
| 1065 | &lifetime_get ) == PSA_SUCCESS ); |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 1066 | |
Gilles Peskine | a0655c3 | 2018-04-30 17:06:50 +0200 | [diff] [blame] | 1067 | TEST_ASSERT( lifetime_get == lifetime_set ); |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 1068 | |
Gilles Peskine | a0655c3 | 2018-04-30 17:06:50 +0200 | [diff] [blame] | 1069 | exit: |
| 1070 | psa_destroy_key( key_slot ); |
| 1071 | mbedtls_psa_crypto_free( ); |
| 1072 | } |
| 1073 | /* END_CASE */ |
mohammad1603 | 804cd71 | 2018-03-20 22:44:08 +0200 | [diff] [blame] | 1074 | |
Gilles Peskine | 7268afc | 2018-06-06 15:19:24 +0200 | [diff] [blame] | 1075 | |
mohammad1603 | 804cd71 | 2018-03-20 22:44:08 +0200 | [diff] [blame] | 1076 | /* BEGIN_CASE */ |
| 1077 | void key_lifetime_set_fail( int key_slot_arg, int lifetime_arg, int expected_status_arg ) |
| 1078 | { |
| 1079 | int key_slot = 1; |
mohammad1603 | 804cd71 | 2018-03-20 22:44:08 +0200 | [diff] [blame] | 1080 | psa_key_lifetime_t lifetime_set = (psa_key_lifetime_t) lifetime_arg; |
| 1081 | psa_status_t actual_status; |
| 1082 | psa_status_t expected_status = expected_status_arg; |
| 1083 | |
mohammad1603 | 804cd71 | 2018-03-20 22:44:08 +0200 | [diff] [blame] | 1084 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 1085 | |
mohammad1603 | 804cd71 | 2018-03-20 22:44:08 +0200 | [diff] [blame] | 1086 | actual_status = psa_set_key_lifetime( key_slot_arg, lifetime_set ); |
| 1087 | |
| 1088 | if( actual_status == PSA_SUCCESS ) |
| 1089 | actual_status = psa_set_key_lifetime( key_slot_arg, lifetime_set ); |
| 1090 | |
| 1091 | TEST_ASSERT( expected_status == actual_status ); |
| 1092 | |
| 1093 | exit: |
mohammad1603 | 804cd71 | 2018-03-20 22:44:08 +0200 | [diff] [blame] | 1094 | psa_destroy_key( key_slot ); |
| 1095 | mbedtls_psa_crypto_free( ); |
| 1096 | } |
| 1097 | /* END_CASE */ |
itayzafrir | 5c75339 | 2018-05-08 11:18:38 +0300 | [diff] [blame] | 1098 | |
| 1099 | /* BEGIN_CASE */ |
| 1100 | void asymmetric_verify( int key_type_arg, char *key_hex, |
| 1101 | int alg_arg, char *hash_hex, char *signature_hex ) |
| 1102 | { |
| 1103 | int slot = 1; |
| 1104 | psa_key_type_t key_type = key_type_arg; |
| 1105 | psa_algorithm_t alg = alg_arg; |
| 1106 | unsigned char *key_data = NULL; |
| 1107 | size_t key_size; |
| 1108 | unsigned char *hash_data = NULL; |
| 1109 | size_t hash_size; |
| 1110 | unsigned char *signature_data = NULL; |
| 1111 | size_t signature_size; |
| 1112 | psa_key_policy_t policy = {0}; |
| 1113 | |
| 1114 | key_data = unhexify_alloc( key_hex, &key_size ); |
| 1115 | TEST_ASSERT( key_data != NULL ); |
| 1116 | hash_data = unhexify_alloc( hash_hex, &hash_size ); |
| 1117 | TEST_ASSERT( hash_data != NULL ); |
| 1118 | signature_data = unhexify_alloc( signature_hex, &signature_size ); |
| 1119 | TEST_ASSERT( signature_data != NULL ); |
| 1120 | |
| 1121 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 1122 | |
| 1123 | psa_key_policy_init( &policy ); |
| 1124 | |
| 1125 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, alg_arg ); |
| 1126 | |
| 1127 | TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS ); |
| 1128 | |
| 1129 | TEST_ASSERT( psa_import_key( slot, key_type, |
| 1130 | key_data, key_size ) == PSA_SUCCESS ); |
| 1131 | |
| 1132 | TEST_ASSERT( psa_asymmetric_verify( slot, alg, |
| 1133 | hash_data, hash_size, |
| 1134 | NULL, 0, |
| 1135 | signature_data, signature_size ) == |
| 1136 | PSA_SUCCESS ); |
| 1137 | exit: |
| 1138 | psa_destroy_key( slot ); |
| 1139 | mbedtls_free( key_data ); |
| 1140 | mbedtls_free( hash_data ); |
| 1141 | mbedtls_free( signature_data ); |
| 1142 | mbedtls_psa_crypto_free( ); |
| 1143 | } |
| 1144 | /* END_CASE */ |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1145 | |
| 1146 | /* BEGIN_CASE */ |
mohammad1603 | bdd892a | 2018-05-09 02:26:51 -0700 | [diff] [blame] | 1147 | void aead_encrypt_decrypt( int key_type_arg, char * key_hex, |
mohammad1603 | 3158564 | 2018-06-07 11:45:03 +0300 | [diff] [blame] | 1148 | int alg_arg, char * input_hex, char * nonce_hex, |
mohammad1603 | 4b26850 | 2018-06-03 19:01:25 +0300 | [diff] [blame] | 1149 | char * add_data, int expected_result_arg ) |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1150 | { |
| 1151 | int slot = 1; |
| 1152 | psa_key_type_t key_type = key_type_arg; |
| 1153 | psa_algorithm_t alg = alg_arg; |
| 1154 | unsigned char *key_data = NULL; |
| 1155 | size_t key_size; |
| 1156 | unsigned char *input_data = NULL; |
| 1157 | size_t input_size; |
| 1158 | unsigned char *output_data = NULL; |
mohammad1603 | d973472 | 2018-05-09 04:59:26 -0700 | [diff] [blame] | 1159 | size_t output_size = 0; |
mohammad1603 | e797945 | 2018-06-01 04:41:03 -0700 | [diff] [blame] | 1160 | size_t output_length = 0; |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1161 | unsigned char *output_data2 = NULL; |
mohammad1603 | e797945 | 2018-06-01 04:41:03 -0700 | [diff] [blame] | 1162 | size_t output_length2 = 0; |
mohammad1603 | 3158564 | 2018-06-07 11:45:03 +0300 | [diff] [blame] | 1163 | uint8_t* nonce; |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1164 | size_t nonce_length = 16; |
| 1165 | size_t tag_length = 16; |
mohammad1603 | bdd892a | 2018-05-09 02:26:51 -0700 | [diff] [blame] | 1166 | unsigned char *additional_data = NULL; |
| 1167 | size_t additional_data_length = 0; |
mohammad1603 | 9b07132 | 2018-05-31 03:18:45 -0700 | [diff] [blame] | 1168 | psa_status_t expected_result = (psa_status_t) expected_result_arg; |
mohammad1603 | f14394b | 2018-06-04 14:33:19 +0300 | [diff] [blame] | 1169 | psa_key_policy_t policy = {0}; |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1170 | |
| 1171 | |
| 1172 | key_data = unhexify_alloc( key_hex, &key_size ); |
| 1173 | TEST_ASSERT( key_data != NULL ); |
| 1174 | input_data = unhexify_alloc( input_hex, &input_size ); |
| 1175 | TEST_ASSERT( input_data != NULL ); |
mohammad1603 | bdd892a | 2018-05-09 02:26:51 -0700 | [diff] [blame] | 1176 | additional_data = unhexify_alloc( add_data, &additional_data_length ); |
| 1177 | TEST_ASSERT( input_data != NULL ); |
mohammad1603 | d973472 | 2018-05-09 04:59:26 -0700 | [diff] [blame] | 1178 | output_size = input_size + tag_length; |
| 1179 | output_data = mbedtls_calloc( 1, output_size ); |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1180 | TEST_ASSERT( output_data != NULL ); |
mohammad1603 | 3158564 | 2018-06-07 11:45:03 +0300 | [diff] [blame] | 1181 | nonce = unhexify_alloc( nonce_hex, &nonce_length ); |
| 1182 | TEST_ASSERT( nonce != NULL ); |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1183 | |
| 1184 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 1185 | |
mohammad1603 | f14394b | 2018-06-04 14:33:19 +0300 | [diff] [blame] | 1186 | psa_key_policy_init( &policy ); |
| 1187 | |
| 1188 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT , alg ); |
| 1189 | |
| 1190 | TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS ); |
| 1191 | |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1192 | TEST_ASSERT( psa_import_key( slot, key_type, |
| 1193 | key_data, key_size ) == PSA_SUCCESS ); |
| 1194 | |
| 1195 | TEST_ASSERT( psa_aead_encrypt( slot, alg, |
| 1196 | nonce, nonce_length, |
| 1197 | additional_data, additional_data_length, |
| 1198 | input_data, input_size, output_data, |
mohammad1603 | 9b07132 | 2018-05-31 03:18:45 -0700 | [diff] [blame] | 1199 | output_size, &output_length ) == expected_result ); |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1200 | |
mohammad1603 | 9b07132 | 2018-05-31 03:18:45 -0700 | [diff] [blame] | 1201 | if( PSA_SUCCESS == expected_result ) |
mohammad1603 | f07db2e | 2018-05-09 05:41:08 -0700 | [diff] [blame] | 1202 | { |
mohammad1603 | e797945 | 2018-06-01 04:41:03 -0700 | [diff] [blame] | 1203 | output_data2 = mbedtls_calloc( 1, output_length ); |
| 1204 | TEST_ASSERT( output_data2 != NULL ); |
| 1205 | |
| 1206 | TEST_ASSERT( psa_aead_decrypt( slot, alg, |
| 1207 | nonce, nonce_length, |
| 1208 | additional_data, additional_data_length, |
Gilles Peskine | ee652a3 | 2018-06-01 19:23:52 +0200 | [diff] [blame] | 1209 | output_data, output_length, output_data2, |
mohammad1603 | e797945 | 2018-06-01 04:41:03 -0700 | [diff] [blame] | 1210 | output_length, &output_length2 ) == expected_result ); |
| 1211 | |
| 1212 | |
mohammad1603 | f07db2e | 2018-05-09 05:41:08 -0700 | [diff] [blame] | 1213 | TEST_ASSERT( memcmp( input_data, output_data2, |
mohammad1603 | e797945 | 2018-06-01 04:41:03 -0700 | [diff] [blame] | 1214 | input_size ) == 0 ); |
mohammad1603 | f07db2e | 2018-05-09 05:41:08 -0700 | [diff] [blame] | 1215 | } |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1216 | |
| 1217 | |
| 1218 | exit: |
| 1219 | psa_destroy_key( slot ); |
| 1220 | mbedtls_free( key_data ); |
| 1221 | mbedtls_free( input_data ); |
mohammad1603 | f07db2e | 2018-05-09 05:41:08 -0700 | [diff] [blame] | 1222 | mbedtls_free( additional_data ); |
| 1223 | mbedtls_free( output_data ); |
mohammad1603 | 9b07132 | 2018-05-31 03:18:45 -0700 | [diff] [blame] | 1224 | mbedtls_free( output_data2 ); |
mohammad1603 | 9112693 | 2018-04-30 11:10:16 +0300 | [diff] [blame] | 1225 | mbedtls_psa_crypto_free( ); |
| 1226 | } |
| 1227 | /* END_CASE */ |
mohammad1603 | f2525eb | 2018-06-03 19:13:34 +0300 | [diff] [blame] | 1228 | |
| 1229 | /* BEGIN_CASE */ |
| 1230 | void aead_encrypt( int key_type_arg, char * key_hex, |
| 1231 | int alg_arg, char * input_hex, |
| 1232 | char * add_data, char * nonce_hex, |
| 1233 | char * expected_result_hex ) |
| 1234 | { |
| 1235 | int slot = 1; |
| 1236 | psa_key_type_t key_type = key_type_arg; |
| 1237 | psa_algorithm_t alg = alg_arg; |
| 1238 | unsigned char *key_data = NULL; |
| 1239 | size_t key_size; |
| 1240 | unsigned char *input_data = NULL; |
| 1241 | size_t input_size; |
| 1242 | unsigned char *output_data = NULL; |
| 1243 | size_t output_size = 0; |
| 1244 | size_t output_length = 0; |
| 1245 | unsigned char *expected_result = NULL; |
| 1246 | size_t expected_result_length = 0; |
| 1247 | uint8_t* nonce = NULL; |
| 1248 | size_t nonce_length = 0; |
| 1249 | size_t tag_length = 16; |
| 1250 | unsigned char *additional_data = NULL; |
| 1251 | size_t additional_data_length = 0; |
mohammad1603 | f14394b | 2018-06-04 14:33:19 +0300 | [diff] [blame] | 1252 | psa_key_policy_t policy = {0}; |
mohammad1603 | f2525eb | 2018-06-03 19:13:34 +0300 | [diff] [blame] | 1253 | |
| 1254 | |
| 1255 | key_data = unhexify_alloc( key_hex, &key_size ); |
| 1256 | TEST_ASSERT( key_data != NULL ); |
| 1257 | input_data = unhexify_alloc( input_hex, &input_size ); |
| 1258 | TEST_ASSERT( input_data != NULL ); |
| 1259 | additional_data = unhexify_alloc( add_data, &additional_data_length ); |
| 1260 | TEST_ASSERT( input_data != NULL ); |
| 1261 | output_size = input_size + tag_length; |
| 1262 | output_data = mbedtls_calloc( 1, output_size ); |
| 1263 | TEST_ASSERT( output_data != NULL ); |
| 1264 | nonce = unhexify_alloc( nonce_hex, &nonce_length ); |
| 1265 | TEST_ASSERT( nonce != NULL ); |
| 1266 | expected_result = unhexify_alloc( expected_result_hex, &expected_result_length ); |
| 1267 | TEST_ASSERT( expected_result != NULL ); |
| 1268 | |
| 1269 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 1270 | |
mohammad1603 | f14394b | 2018-06-04 14:33:19 +0300 | [diff] [blame] | 1271 | psa_key_policy_init( &policy ); |
| 1272 | |
| 1273 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT , alg ); |
| 1274 | |
| 1275 | TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS ); |
| 1276 | |
mohammad1603 | f2525eb | 2018-06-03 19:13:34 +0300 | [diff] [blame] | 1277 | TEST_ASSERT( psa_import_key( slot, key_type, |
| 1278 | key_data, key_size ) == PSA_SUCCESS ); |
| 1279 | |
| 1280 | TEST_ASSERT( psa_aead_encrypt( slot, alg, |
| 1281 | nonce, nonce_length, |
| 1282 | additional_data, additional_data_length, |
| 1283 | input_data, input_size, output_data, |
| 1284 | output_size, &output_length ) == PSA_SUCCESS ); |
| 1285 | |
| 1286 | |
| 1287 | TEST_ASSERT( memcmp( output_data, expected_result, |
| 1288 | output_length ) == 0 ); |
| 1289 | |
| 1290 | |
| 1291 | exit: |
| 1292 | psa_destroy_key( slot ); |
| 1293 | mbedtls_free( key_data ); |
| 1294 | mbedtls_free( input_data ); |
| 1295 | mbedtls_free( additional_data ); |
| 1296 | mbedtls_free( output_data ); |
| 1297 | mbedtls_free( nonce ); |
| 1298 | mbedtls_free( expected_result ); |
| 1299 | mbedtls_psa_crypto_free( ); |
| 1300 | } |
| 1301 | /* END_CASE */ |
mohammad1603 | 371a6e4 | 2018-06-04 15:11:08 +0300 | [diff] [blame] | 1302 | |
| 1303 | /* BEGIN_CASE */ |
| 1304 | void aead_decrypt( int key_type_arg, char * key_hex, |
| 1305 | int alg_arg, char * input_hex, |
| 1306 | char * add_data, char * nonce_hex, |
mohammad1603 | f7f72da | 2018-06-04 16:32:11 +0300 | [diff] [blame] | 1307 | char * expected_result_hex, int expected_result_arg ) |
mohammad1603 | 371a6e4 | 2018-06-04 15:11:08 +0300 | [diff] [blame] | 1308 | { |
| 1309 | int slot = 1; |
| 1310 | psa_key_type_t key_type = key_type_arg; |
| 1311 | psa_algorithm_t alg = alg_arg; |
| 1312 | unsigned char *key_data = NULL; |
| 1313 | size_t key_size; |
| 1314 | unsigned char *input_data = NULL; |
| 1315 | size_t input_size; |
| 1316 | unsigned char *output_data = NULL; |
| 1317 | size_t output_size = 0; |
| 1318 | size_t output_length = 0; |
mohammad1603 | f7f72da | 2018-06-04 16:32:11 +0300 | [diff] [blame] | 1319 | unsigned char *expected_data = NULL; |
mohammad1603 | 371a6e4 | 2018-06-04 15:11:08 +0300 | [diff] [blame] | 1320 | size_t expected_result_length = 0; |
| 1321 | uint8_t* nonce = NULL; |
| 1322 | size_t nonce_length = 0; |
| 1323 | size_t tag_length = 16; |
| 1324 | unsigned char *additional_data = NULL; |
| 1325 | size_t additional_data_length = 0; |
| 1326 | psa_key_policy_t policy = {0}; |
mohammad1603 | f7f72da | 2018-06-04 16:32:11 +0300 | [diff] [blame] | 1327 | psa_status_t expected_result = (psa_status_t) expected_result_arg; |
mohammad1603 | 371a6e4 | 2018-06-04 15:11:08 +0300 | [diff] [blame] | 1328 | |
| 1329 | |
| 1330 | key_data = unhexify_alloc( key_hex, &key_size ); |
| 1331 | TEST_ASSERT( key_data != NULL ); |
| 1332 | input_data = unhexify_alloc( input_hex, &input_size ); |
| 1333 | TEST_ASSERT( input_data != NULL ); |
| 1334 | additional_data = unhexify_alloc( add_data, &additional_data_length ); |
| 1335 | TEST_ASSERT( input_data != NULL ); |
| 1336 | output_size = input_size + tag_length; |
| 1337 | output_data = mbedtls_calloc( 1, output_size ); |
| 1338 | TEST_ASSERT( output_data != NULL ); |
| 1339 | nonce = unhexify_alloc( nonce_hex, &nonce_length ); |
| 1340 | TEST_ASSERT( nonce != NULL ); |
mohammad1603 | f7f72da | 2018-06-04 16:32:11 +0300 | [diff] [blame] | 1341 | expected_data = unhexify_alloc( expected_result_hex, &expected_result_length ); |
| 1342 | TEST_ASSERT( expected_data != NULL ); |
mohammad1603 | 371a6e4 | 2018-06-04 15:11:08 +0300 | [diff] [blame] | 1343 | |
| 1344 | TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 1345 | |
| 1346 | psa_key_policy_init( &policy ); |
| 1347 | |
| 1348 | psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT , alg ); |
| 1349 | |
| 1350 | TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS ); |
| 1351 | |
| 1352 | TEST_ASSERT( psa_import_key( slot, key_type, |
| 1353 | key_data, key_size ) == PSA_SUCCESS ); |
| 1354 | |
| 1355 | TEST_ASSERT( psa_aead_decrypt( slot, alg, |
| 1356 | nonce, nonce_length, |
| 1357 | additional_data, additional_data_length, |
| 1358 | input_data, input_size, output_data, |
mohammad1603 | f7f72da | 2018-06-04 16:32:11 +0300 | [diff] [blame] | 1359 | output_size, &output_length ) == expected_result ); |
mohammad1603 | 371a6e4 | 2018-06-04 15:11:08 +0300 | [diff] [blame] | 1360 | |
| 1361 | |
mohammad1603 | f7f72da | 2018-06-04 16:32:11 +0300 | [diff] [blame] | 1362 | if ( expected_result == PSA_SUCCESS ) |
| 1363 | { |
| 1364 | TEST_ASSERT( memcmp( output_data, expected_data, |
| 1365 | output_length ) == 0 ); |
| 1366 | } |
| 1367 | |
mohammad1603 | 371a6e4 | 2018-06-04 15:11:08 +0300 | [diff] [blame] | 1368 | |
| 1369 | |
| 1370 | exit: |
| 1371 | psa_destroy_key( slot ); |
| 1372 | mbedtls_free( key_data ); |
| 1373 | mbedtls_free( input_data ); |
| 1374 | mbedtls_free( additional_data ); |
| 1375 | mbedtls_free( output_data ); |
| 1376 | mbedtls_free( nonce ); |
mohammad1603 | f7f72da | 2018-06-04 16:32:11 +0300 | [diff] [blame] | 1377 | mbedtls_free( expected_data ); |
mohammad1603 | 371a6e4 | 2018-06-04 15:11:08 +0300 | [diff] [blame] | 1378 | mbedtls_psa_crypto_free( ); |
| 1379 | } |
| 1380 | /* END_CASE */ |