|
|
@@ -289,7 +289,7 @@ void static_checks( )
|
|
|
|
/* Check that the length for a truncated MAC always fits in the algorithm
|
|
|
|
/* Check that the length for a truncated MAC always fits in the algorithm
|
|
|
|
* encoding. The shifted mask is the maximum truncated value. The
|
|
|
|
* encoding. The shifted mask is the maximum truncated value. The
|
|
|
|
* untruncated algorithm may be one byte larger. */
|
|
|
|
* untruncated algorithm may be one byte larger. */
|
|
|
|
TEST_ASSERT( PSA_MAC_MAX_SIZE <= 1 + max_truncated_mac_size );
|
|
|
|
TEST_LE_U( PSA_MAC_MAX_SIZE, 1 + max_truncated_mac_size );
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_TEST_DEPRECATED)
|
|
|
|
#if defined(MBEDTLS_TEST_DEPRECATED)
|
|
|
|
/* Check deprecated constants. */
|
|
|
|
/* Check deprecated constants. */
|
|
|
@@ -591,7 +591,7 @@ void import_export( data_t *data,
|
|
|
|
* and export_size. On errors, the exported length must be 0. */
|
|
|
|
* and export_size. On errors, the exported length must be 0. */
|
|
|
|
TEST_ASSERT( exported_length != INVALID_EXPORT_LENGTH );
|
|
|
|
TEST_ASSERT( exported_length != INVALID_EXPORT_LENGTH );
|
|
|
|
TEST_ASSERT( status == PSA_SUCCESS || exported_length == 0 );
|
|
|
|
TEST_ASSERT( status == PSA_SUCCESS || exported_length == 0 );
|
|
|
|
TEST_ASSERT( exported_length <= export_size );
|
|
|
|
TEST_LE_U( exported_length, export_size );
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( mem_is_char( exported + exported_length, 0,
|
|
|
|
TEST_ASSERT( mem_is_char( exported + exported_length, 0,
|
|
|
|
export_size - exported_length ) );
|
|
|
|
export_size - exported_length ) );
|
|
|
@@ -626,7 +626,7 @@ void import_export( data_t *data,
|
|
|
|
TEST_ASSERT( exported_length <=
|
|
|
|
TEST_ASSERT( exported_length <=
|
|
|
|
PSA_EXPORT_KEY_OUTPUT_SIZE( type,
|
|
|
|
PSA_EXPORT_KEY_OUTPUT_SIZE( type,
|
|
|
|
psa_get_key_bits( &got_attributes ) ) );
|
|
|
|
psa_get_key_bits( &got_attributes ) ) );
|
|
|
|
TEST_ASSERT( exported_length <= PSA_EXPORT_KEY_PAIR_MAX_SIZE );
|
|
|
|
TEST_LE_U( exported_length, PSA_EXPORT_KEY_PAIR_MAX_SIZE );
|
|
|
|
|
|
|
|
|
|
|
|
destroy:
|
|
|
|
destroy:
|
|
|
|
/* Destroy the key */
|
|
|
|
/* Destroy the key */
|
|
|
@@ -685,11 +685,11 @@ void import_export_public_key( data_t *data,
|
|
|
|
size_t bits;
|
|
|
|
size_t bits;
|
|
|
|
PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
|
|
|
|
PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
|
|
|
|
bits = psa_get_key_bits( &attributes );
|
|
|
|
bits = psa_get_key_bits( &attributes );
|
|
|
|
TEST_ASSERT( expected_public_key->len <=
|
|
|
|
TEST_LE_U( expected_public_key->len,
|
|
|
|
PSA_EXPORT_KEY_OUTPUT_SIZE( public_type, bits ) );
|
|
|
|
PSA_EXPORT_KEY_OUTPUT_SIZE( public_type, bits ) );
|
|
|
|
TEST_ASSERT( expected_public_key->len <=
|
|
|
|
TEST_LE_U( expected_public_key->len,
|
|
|
|
PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( public_type, bits ) );
|
|
|
|
PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( public_type, bits ) );
|
|
|
|
TEST_ASSERT( expected_public_key->len <=
|
|
|
|
TEST_LE_U( expected_public_key->len,
|
|
|
|
PSA_EXPORT_PUBLIC_KEY_MAX_SIZE );
|
|
|
|
PSA_EXPORT_PUBLIC_KEY_MAX_SIZE );
|
|
|
|
ASSERT_COMPARE( expected_public_key->x, expected_public_key->len,
|
|
|
|
ASSERT_COMPARE( expected_public_key->x, expected_public_key->len,
|
|
|
|
exported, exported_length );
|
|
|
|
exported, exported_length );
|
|
|
@@ -983,8 +983,8 @@ void aead_key_policy( int policy_usage_arg,
|
|
|
|
size_t tag_length = tag_length_arg;
|
|
|
|
size_t tag_length = tag_length_arg;
|
|
|
|
size_t output_length;
|
|
|
|
size_t output_length;
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( nonce_length <= sizeof( nonce ) );
|
|
|
|
TEST_LE_U( nonce_length, sizeof( nonce ) );
|
|
|
|
TEST_ASSERT( tag_length <= sizeof( tag ) );
|
|
|
|
TEST_LE_U( tag_length, sizeof( tag ) );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
|
|
|
@@ -1576,7 +1576,7 @@ void hash_compute_fail( int alg_arg, data_t *input,
|
|
|
|
status = psa_hash_compute( alg, input->x, input->len,
|
|
|
|
status = psa_hash_compute( alg, input->x, input->len,
|
|
|
|
output, output_size, &output_length );
|
|
|
|
output, output_size, &output_length );
|
|
|
|
TEST_EQUAL( status, expected_status );
|
|
|
|
TEST_EQUAL( status, expected_status );
|
|
|
|
TEST_ASSERT( output_length <= output_size );
|
|
|
|
TEST_LE_U( output_length, output_size );
|
|
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
exit:
|
|
|
|
mbedtls_free( output );
|
|
|
|
mbedtls_free( output );
|
|
|
@@ -2132,7 +2132,7 @@ void mac_sign( int key_type_arg,
|
|
|
|
expected_mac->len + 1,
|
|
|
|
expected_mac->len + 1,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( mac_buffer_size <= PSA_MAC_MAX_SIZE );
|
|
|
|
TEST_LE_U( mac_buffer_size, PSA_MAC_MAX_SIZE );
|
|
|
|
/* We expect PSA_MAC_LENGTH to be exact. */
|
|
|
|
/* We expect PSA_MAC_LENGTH to be exact. */
|
|
|
|
TEST_ASSERT( expected_mac->len == mac_buffer_size );
|
|
|
|
TEST_ASSERT( expected_mac->len == mac_buffer_size );
|
|
|
|
|
|
|
|
|
|
|
@@ -2210,7 +2210,7 @@ void mac_verify( int key_type_arg,
|
|
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
|
|
uint8_t *perturbed_mac = NULL;
|
|
|
|
uint8_t *perturbed_mac = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( expected_mac->len <= PSA_MAC_MAX_SIZE );
|
|
|
|
TEST_LE_U( expected_mac->len, PSA_MAC_MAX_SIZE );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
|
|
|
@@ -2608,13 +2608,13 @@ void cipher_alg_without_iv( int alg_arg, int key_type_arg, data_t *key_data,
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
|
|
|
|
/* Validate size macros */
|
|
|
|
/* Validate size macros */
|
|
|
|
TEST_ASSERT( ciphertext->len <=
|
|
|
|
TEST_LE_U( ciphertext->len,
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, plaintext->len ) );
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, plaintext->len ) );
|
|
|
|
TEST_ASSERT( PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, plaintext->len ) <=
|
|
|
|
TEST_LE_U( PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, plaintext->len ),
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( plaintext->len ) );
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( plaintext->len ) );
|
|
|
|
TEST_ASSERT( plaintext->len <=
|
|
|
|
TEST_LE_U( plaintext->len,
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, ciphertext->len ) );
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, ciphertext->len ) );
|
|
|
|
TEST_ASSERT( PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, ciphertext->len ) <=
|
|
|
|
TEST_LE_U( PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, ciphertext->len ),
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( ciphertext->len ) );
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( ciphertext->len ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2655,7 +2655,7 @@ void cipher_alg_without_iv( int alg_arg, int key_type_arg, data_t *key_data,
|
|
|
|
plaintext->x, plaintext->len,
|
|
|
|
plaintext->x, plaintext->len,
|
|
|
|
output, output_buffer_size,
|
|
|
|
output, output_buffer_size,
|
|
|
|
&length ) );
|
|
|
|
&length ) );
|
|
|
|
TEST_ASSERT( length <= output_buffer_size );
|
|
|
|
TEST_LE_U( length, output_buffer_size );
|
|
|
|
output_length += length;
|
|
|
|
output_length += length;
|
|
|
|
PSA_ASSERT( psa_cipher_finish( &operation,
|
|
|
|
PSA_ASSERT( psa_cipher_finish( &operation,
|
|
|
|
output + output_length,
|
|
|
|
output + output_length,
|
|
|
@@ -2673,7 +2673,7 @@ void cipher_alg_without_iv( int alg_arg, int key_type_arg, data_t *key_data,
|
|
|
|
ciphertext->x, ciphertext->len,
|
|
|
|
ciphertext->x, ciphertext->len,
|
|
|
|
output, output_buffer_size,
|
|
|
|
output, output_buffer_size,
|
|
|
|
&length ) );
|
|
|
|
&length ) );
|
|
|
|
TEST_ASSERT( length <= output_buffer_size );
|
|
|
|
TEST_LE_U( length, output_buffer_size );
|
|
|
|
output_length += length;
|
|
|
|
output_length += length;
|
|
|
|
PSA_ASSERT( psa_cipher_finish( &operation,
|
|
|
|
PSA_ASSERT( psa_cipher_finish( &operation,
|
|
|
|
output + output_length,
|
|
|
|
output + output_length,
|
|
|
@@ -2786,9 +2786,9 @@ void cipher_encrypt_validation( int alg_arg,
|
|
|
|
the output is not possible. Validating with multipart encryption. */
|
|
|
|
the output is not possible. Validating with multipart encryption. */
|
|
|
|
PSA_ASSERT( psa_cipher_encrypt( key, alg, input->x, input->len, output1,
|
|
|
|
PSA_ASSERT( psa_cipher_encrypt( key, alg, input->x, input->len, output1,
|
|
|
|
output1_buffer_size, &output1_length ) );
|
|
|
|
output1_buffer_size, &output1_length ) );
|
|
|
|
TEST_ASSERT( output1_length <=
|
|
|
|
TEST_LE_U( output1_length,
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) );
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) );
|
|
|
|
TEST_ASSERT( output1_length <=
|
|
|
|
TEST_LE_U( output1_length,
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
|
|
|
|
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
|
|
|
@@ -2798,9 +2798,9 @@ void cipher_encrypt_validation( int alg_arg,
|
|
|
|
input->x, input->len,
|
|
|
|
input->x, input->len,
|
|
|
|
output2, output2_buffer_size,
|
|
|
|
output2, output2_buffer_size,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, input->len ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, input->len ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
output2_length += function_output_length;
|
|
|
|
output2_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -2808,9 +2808,9 @@ void cipher_encrypt_validation( int alg_arg,
|
|
|
|
output2 + output2_length,
|
|
|
|
output2 + output2_length,
|
|
|
|
output2_buffer_size - output2_length,
|
|
|
|
output2_buffer_size - output2_length,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
output2_length += function_output_length;
|
|
|
|
output2_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -2871,14 +2871,14 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
|
|
|
|
ASSERT_ALLOC( output, output_buffer_size );
|
|
|
|
ASSERT_ALLOC( output, output_buffer_size );
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( first_part_size <= input->len );
|
|
|
|
TEST_LE_U( first_part_size, input->len );
|
|
|
|
PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size,
|
|
|
|
PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size,
|
|
|
|
output, output_buffer_size,
|
|
|
|
output, output_buffer_size,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length == output1_length );
|
|
|
|
TEST_ASSERT( function_output_length == output1_length );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size) );
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -2892,11 +2892,11 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
|
|
|
|
output_buffer_size - total_output_length,
|
|
|
|
output_buffer_size - total_output_length,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length == output2_length );
|
|
|
|
TEST_ASSERT( function_output_length == output2_length );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
|
|
|
|
alg,
|
|
|
|
alg,
|
|
|
|
input->len - first_part_size ) );
|
|
|
|
input->len - first_part_size ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -2906,9 +2906,9 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
|
|
|
|
output + total_output_length ),
|
|
|
|
output + total_output_length ),
|
|
|
|
output_buffer_size - total_output_length,
|
|
|
|
output_buffer_size - total_output_length,
|
|
|
|
&function_output_length );
|
|
|
|
&function_output_length );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
TEST_EQUAL( status, expected_status );
|
|
|
|
TEST_EQUAL( status, expected_status );
|
|
|
@@ -2973,15 +2973,15 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
|
|
|
|
ASSERT_ALLOC( output, output_buffer_size );
|
|
|
|
ASSERT_ALLOC( output, output_buffer_size );
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( first_part_size <= input->len );
|
|
|
|
TEST_LE_U( first_part_size, input->len );
|
|
|
|
PSA_ASSERT( psa_cipher_update( &operation,
|
|
|
|
PSA_ASSERT( psa_cipher_update( &operation,
|
|
|
|
input->x, first_part_size,
|
|
|
|
input->x, first_part_size,
|
|
|
|
output, output_buffer_size,
|
|
|
|
output, output_buffer_size,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length == output1_length );
|
|
|
|
TEST_ASSERT( function_output_length == output1_length );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -2995,11 +2995,11 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
|
|
|
|
output_buffer_size - total_output_length,
|
|
|
|
output_buffer_size - total_output_length,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length == output2_length );
|
|
|
|
TEST_ASSERT( function_output_length == output2_length );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
|
|
|
|
alg,
|
|
|
|
alg,
|
|
|
|
input->len - first_part_size ) );
|
|
|
|
input->len - first_part_size ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -3009,9 +3009,9 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
|
|
|
|
output + total_output_length ),
|
|
|
|
output + total_output_length ),
|
|
|
|
output_buffer_size - total_output_length,
|
|
|
|
output_buffer_size - total_output_length,
|
|
|
|
&function_output_length );
|
|
|
|
&function_output_length );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
total_output_length += function_output_length;
|
|
|
|
TEST_EQUAL( status, expected_status );
|
|
|
|
TEST_EQUAL( status, expected_status );
|
|
|
@@ -3129,9 +3129,9 @@ void cipher_decrypt( int alg_arg,
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_cipher_decrypt( key, alg, input, input_buffer_size, output,
|
|
|
|
PSA_ASSERT( psa_cipher_decrypt( key, alg, input, input_buffer_size, output,
|
|
|
|
output_buffer_size, &output_length ) );
|
|
|
|
output_buffer_size, &output_length ) );
|
|
|
|
TEST_ASSERT( output_length <=
|
|
|
|
TEST_LE_U( output_length,
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, input_buffer_size ) );
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, input_buffer_size ) );
|
|
|
|
TEST_ASSERT( output_length <=
|
|
|
|
TEST_LE_U( output_length,
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( input_buffer_size ) );
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( input_buffer_size ) );
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_COMPARE( expected_output->x, expected_output->len,
|
|
|
|
ASSERT_COMPARE( expected_output->x, expected_output->len,
|
|
|
@@ -3175,9 +3175,9 @@ void cipher_verify_output( int alg_arg,
|
|
|
|
PSA_ASSERT( psa_cipher_encrypt( key, alg, input->x, input->len,
|
|
|
|
PSA_ASSERT( psa_cipher_encrypt( key, alg, input->x, input->len,
|
|
|
|
output1, output1_size,
|
|
|
|
output1, output1_size,
|
|
|
|
&output1_length ) );
|
|
|
|
&output1_length ) );
|
|
|
|
TEST_ASSERT( output1_length <=
|
|
|
|
TEST_LE_U( output1_length,
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) );
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) );
|
|
|
|
TEST_ASSERT( output1_length <=
|
|
|
|
TEST_LE_U( output1_length,
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
|
|
|
|
|
|
|
|
output2_size = output1_length;
|
|
|
|
output2_size = output1_length;
|
|
|
@@ -3186,9 +3186,9 @@ void cipher_verify_output( int alg_arg,
|
|
|
|
PSA_ASSERT( psa_cipher_decrypt( key, alg, output1, output1_length,
|
|
|
|
PSA_ASSERT( psa_cipher_decrypt( key, alg, output1, output1_length,
|
|
|
|
output2, output2_size,
|
|
|
|
output2, output2_size,
|
|
|
|
&output2_length ) );
|
|
|
|
&output2_length ) );
|
|
|
|
TEST_ASSERT( output2_length <=
|
|
|
|
TEST_LE_U( output2_length,
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, output1_length ) );
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, output1_length ) );
|
|
|
|
TEST_ASSERT( output2_length <=
|
|
|
|
TEST_LE_U( output2_length,
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( output1_length ) );
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( output1_length ) );
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_COMPARE( input->x, input->len, output2, output2_length );
|
|
|
|
ASSERT_COMPARE( input->x, input->len, output2, output2_length );
|
|
|
@@ -3246,18 +3246,18 @@ void cipher_verify_output_multipart( int alg_arg,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len );
|
|
|
|
output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len );
|
|
|
|
TEST_ASSERT( output1_buffer_size <=
|
|
|
|
TEST_LE_U( output1_buffer_size,
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
|
|
|
|
ASSERT_ALLOC( output1, output1_buffer_size );
|
|
|
|
ASSERT_ALLOC( output1, output1_buffer_size );
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( first_part_size <= input->len );
|
|
|
|
TEST_LE_U( first_part_size, input->len );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_cipher_update( &operation1, input->x, first_part_size,
|
|
|
|
PSA_ASSERT( psa_cipher_update( &operation1, input->x, first_part_size,
|
|
|
|
output1, output1_buffer_size,
|
|
|
|
output1, output1_buffer_size,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
|
|
|
|
output1_length += function_output_length;
|
|
|
|
output1_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -3266,11 +3266,11 @@ void cipher_verify_output_multipart( int alg_arg,
|
|
|
|
input->len - first_part_size,
|
|
|
|
input->len - first_part_size,
|
|
|
|
output1, output1_buffer_size,
|
|
|
|
output1, output1_buffer_size,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
|
|
|
|
alg,
|
|
|
|
alg,
|
|
|
|
input->len - first_part_size ) );
|
|
|
|
input->len - first_part_size ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len - first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len - first_part_size ) );
|
|
|
|
output1_length += function_output_length;
|
|
|
|
output1_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -3278,18 +3278,18 @@ void cipher_verify_output_multipart( int alg_arg,
|
|
|
|
output1 + output1_length,
|
|
|
|
output1 + output1_length,
|
|
|
|
output1_buffer_size - output1_length,
|
|
|
|
output1_buffer_size - output1_length,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
output1_length += function_output_length;
|
|
|
|
output1_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_cipher_abort( &operation1 ) );
|
|
|
|
PSA_ASSERT( psa_cipher_abort( &operation1 ) );
|
|
|
|
|
|
|
|
|
|
|
|
output2_buffer_size = output1_length;
|
|
|
|
output2_buffer_size = output1_length;
|
|
|
|
TEST_ASSERT( output2_buffer_size <=
|
|
|
|
TEST_LE_U( output2_buffer_size,
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, output1_length ) );
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, output1_length ) );
|
|
|
|
TEST_ASSERT( output2_buffer_size <=
|
|
|
|
TEST_LE_U( output2_buffer_size,
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( output1_length ) );
|
|
|
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( output1_length ) );
|
|
|
|
ASSERT_ALLOC( output2, output2_buffer_size );
|
|
|
|
ASSERT_ALLOC( output2, output2_buffer_size );
|
|
|
|
|
|
|
|
|
|
|
@@ -3302,9 +3302,9 @@ void cipher_verify_output_multipart( int alg_arg,
|
|
|
|
PSA_ASSERT( psa_cipher_update( &operation2, output1, first_part_size,
|
|
|
|
PSA_ASSERT( psa_cipher_update( &operation2, output1, first_part_size,
|
|
|
|
output2, output2_buffer_size,
|
|
|
|
output2, output2_buffer_size,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
|
|
|
|
output2_length += function_output_length;
|
|
|
|
output2_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -3313,11 +3313,11 @@ void cipher_verify_output_multipart( int alg_arg,
|
|
|
|
output1_length - first_part_size,
|
|
|
|
output1_length - first_part_size,
|
|
|
|
output2, output2_buffer_size,
|
|
|
|
output2, output2_buffer_size,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
|
|
|
|
alg,
|
|
|
|
alg,
|
|
|
|
output1_length - first_part_size ) );
|
|
|
|
output1_length - first_part_size ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( output1_length - first_part_size ) );
|
|
|
|
PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( output1_length - first_part_size ) );
|
|
|
|
output2_length += function_output_length;
|
|
|
|
output2_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -3325,9 +3325,9 @@ void cipher_verify_output_multipart( int alg_arg,
|
|
|
|
output2 + output2_length,
|
|
|
|
output2 + output2_length,
|
|
|
|
output2_buffer_size - output2_length,
|
|
|
|
output2_buffer_size - output2_length,
|
|
|
|
&function_output_length ) );
|
|
|
|
&function_output_length ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
|
|
|
|
TEST_ASSERT( function_output_length <=
|
|
|
|
TEST_LE_U( function_output_length,
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
|
|
|
|
output2_length += function_output_length;
|
|
|
|
output2_length += function_output_length;
|
|
|
|
|
|
|
|
|
|
|
@@ -3635,7 +3635,7 @@ void sign_hash_deterministic( int key_type_arg, data_t *key_data,
|
|
|
|
signature_size = PSA_SIGN_OUTPUT_SIZE( key_type,
|
|
|
|
signature_size = PSA_SIGN_OUTPUT_SIZE( key_type,
|
|
|
|
key_bits, alg );
|
|
|
|
key_bits, alg );
|
|
|
|
TEST_ASSERT( signature_size != 0 );
|
|
|
|
TEST_ASSERT( signature_size != 0 );
|
|
|
|
TEST_ASSERT( signature_size <= PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
TEST_LE_U( signature_size, PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
ASSERT_ALLOC( signature, signature_size );
|
|
|
|
ASSERT_ALLOC( signature, signature_size );
|
|
|
|
|
|
|
|
|
|
|
|
/* Perform the signature. */
|
|
|
|
/* Perform the signature. */
|
|
|
@@ -3706,7 +3706,7 @@ void sign_hash_fail( int key_type_arg, data_t *key_data,
|
|
|
|
* whatever it is, it should be less than signature_size, so that
|
|
|
|
* whatever it is, it should be less than signature_size, so that
|
|
|
|
* if the caller tries to read *signature_length bytes without
|
|
|
|
* if the caller tries to read *signature_length bytes without
|
|
|
|
* checking the error code then they don't overflow a buffer. */
|
|
|
|
* checking the error code then they don't overflow a buffer. */
|
|
|
|
TEST_ASSERT( signature_length <= signature_size );
|
|
|
|
TEST_LE_U( signature_length, signature_size );
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_TEST_DEPRECATED)
|
|
|
|
#if defined(MBEDTLS_TEST_DEPRECATED)
|
|
|
|
signature_length = INVALID_EXPORT_LENGTH;
|
|
|
|
signature_length = INVALID_EXPORT_LENGTH;
|
|
|
@@ -3715,7 +3715,7 @@ void sign_hash_fail( int key_type_arg, data_t *key_data,
|
|
|
|
signature, signature_size,
|
|
|
|
signature, signature_size,
|
|
|
|
&signature_length ),
|
|
|
|
&signature_length ),
|
|
|
|
expected_status );
|
|
|
|
expected_status );
|
|
|
|
TEST_ASSERT( signature_length <= signature_size );
|
|
|
|
TEST_LE_U( signature_length, signature_size );
|
|
|
|
#endif /* MBEDTLS_TEST_DEPRECATED */
|
|
|
|
#endif /* MBEDTLS_TEST_DEPRECATED */
|
|
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
exit:
|
|
|
@@ -3755,7 +3755,7 @@ void sign_verify_hash( int key_type_arg, data_t *key_data,
|
|
|
|
signature_size = PSA_SIGN_OUTPUT_SIZE( key_type,
|
|
|
|
signature_size = PSA_SIGN_OUTPUT_SIZE( key_type,
|
|
|
|
key_bits, alg );
|
|
|
|
key_bits, alg );
|
|
|
|
TEST_ASSERT( signature_size != 0 );
|
|
|
|
TEST_ASSERT( signature_size != 0 );
|
|
|
|
TEST_ASSERT( signature_size <= PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
TEST_LE_U( signature_size, PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
ASSERT_ALLOC( signature, signature_size );
|
|
|
|
ASSERT_ALLOC( signature, signature_size );
|
|
|
|
|
|
|
|
|
|
|
|
/* Perform the signature. */
|
|
|
|
/* Perform the signature. */
|
|
|
@@ -3764,7 +3764,7 @@ void sign_verify_hash( int key_type_arg, data_t *key_data,
|
|
|
|
signature, signature_size,
|
|
|
|
signature, signature_size,
|
|
|
|
&signature_length ) );
|
|
|
|
&signature_length ) );
|
|
|
|
/* Check that the signature length looks sensible. */
|
|
|
|
/* Check that the signature length looks sensible. */
|
|
|
|
TEST_ASSERT( signature_length <= signature_size );
|
|
|
|
TEST_LE_U( signature_length, signature_size );
|
|
|
|
TEST_ASSERT( signature_length > 0 );
|
|
|
|
TEST_ASSERT( signature_length > 0 );
|
|
|
|
|
|
|
|
|
|
|
|
/* Use the library to verify that the signature is correct. */
|
|
|
|
/* Use the library to verify that the signature is correct. */
|
|
|
@@ -3807,7 +3807,7 @@ void verify_hash( int key_type_arg, data_t *key_data,
|
|
|
|
psa_algorithm_t alg = alg_arg;
|
|
|
|
psa_algorithm_t alg = alg_arg;
|
|
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( signature_data->len <= PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
TEST_LE_U( signature_data->len, PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
|
|
|
@@ -3907,7 +3907,7 @@ void sign_message_deterministic( int key_type_arg,
|
|
|
|
|
|
|
|
|
|
|
|
signature_size = PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
signature_size = PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
TEST_ASSERT( signature_size != 0 );
|
|
|
|
TEST_ASSERT( signature_size != 0 );
|
|
|
|
TEST_ASSERT( signature_size <= PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
TEST_LE_U( signature_size, PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
ASSERT_ALLOC( signature, signature_size );
|
|
|
|
ASSERT_ALLOC( signature, signature_size );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_sign_message( key, alg,
|
|
|
|
PSA_ASSERT( psa_sign_message( key, alg,
|
|
|
@@ -3966,7 +3966,7 @@ void sign_message_fail( int key_type_arg,
|
|
|
|
* whatever it is, it should be less than signature_size, so that
|
|
|
|
* whatever it is, it should be less than signature_size, so that
|
|
|
|
* if the caller tries to read *signature_length bytes without
|
|
|
|
* if the caller tries to read *signature_length bytes without
|
|
|
|
* checking the error code then they don't overflow a buffer. */
|
|
|
|
* checking the error code then they don't overflow a buffer. */
|
|
|
|
TEST_ASSERT( signature_length <= signature_size );
|
|
|
|
TEST_LE_U( signature_length, signature_size );
|
|
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
exit:
|
|
|
|
psa_reset_key_attributes( &attributes );
|
|
|
|
psa_reset_key_attributes( &attributes );
|
|
|
@@ -4005,14 +4005,14 @@ void sign_verify_message( int key_type_arg,
|
|
|
|
|
|
|
|
|
|
|
|
signature_size = PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
signature_size = PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
TEST_ASSERT( signature_size != 0 );
|
|
|
|
TEST_ASSERT( signature_size != 0 );
|
|
|
|
TEST_ASSERT( signature_size <= PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
TEST_LE_U( signature_size, PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
ASSERT_ALLOC( signature, signature_size );
|
|
|
|
ASSERT_ALLOC( signature, signature_size );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_sign_message( key, alg,
|
|
|
|
PSA_ASSERT( psa_sign_message( key, alg,
|
|
|
|
input_data->x, input_data->len,
|
|
|
|
input_data->x, input_data->len,
|
|
|
|
signature, signature_size,
|
|
|
|
signature, signature_size,
|
|
|
|
&signature_length ) );
|
|
|
|
&signature_length ) );
|
|
|
|
TEST_ASSERT( signature_length <= signature_size );
|
|
|
|
TEST_LE_U( signature_length, signature_size );
|
|
|
|
TEST_ASSERT( signature_length > 0 );
|
|
|
|
TEST_ASSERT( signature_length > 0 );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_verify_message( key, alg,
|
|
|
|
PSA_ASSERT( psa_verify_message( key, alg,
|
|
|
@@ -4052,7 +4052,7 @@ void verify_message( int key_type_arg,
|
|
|
|
psa_algorithm_t alg = alg_arg;
|
|
|
|
psa_algorithm_t alg = alg_arg;
|
|
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT( signature_data->len <= PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
TEST_LE_U( signature_data->len, PSA_SIGNATURE_MAX_SIZE );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
|
|
|
@@ -4146,7 +4146,7 @@ void asymmetric_encrypt( int key_type_arg,
|
|
|
|
key_bits = psa_get_key_bits( &attributes );
|
|
|
|
key_bits = psa_get_key_bits( &attributes );
|
|
|
|
|
|
|
|
|
|
|
|
output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
TEST_ASSERT( output_size <= PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE );
|
|
|
|
TEST_LE_U( output_size, PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE );
|
|
|
|
ASSERT_ALLOC( output, output_size );
|
|
|
|
ASSERT_ALLOC( output, output_size );
|
|
|
|
|
|
|
|
|
|
|
|
/* Encrypt the input */
|
|
|
|
/* Encrypt the input */
|
|
|
@@ -4220,13 +4220,13 @@ void asymmetric_encrypt_decrypt( int key_type_arg,
|
|
|
|
key_bits = psa_get_key_bits( &attributes );
|
|
|
|
key_bits = psa_get_key_bits( &attributes );
|
|
|
|
|
|
|
|
|
|
|
|
output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
TEST_ASSERT( output_size <= PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE );
|
|
|
|
TEST_LE_U( output_size, PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE );
|
|
|
|
ASSERT_ALLOC( output, output_size );
|
|
|
|
ASSERT_ALLOC( output, output_size );
|
|
|
|
|
|
|
|
|
|
|
|
output2_size = input_data->len;
|
|
|
|
output2_size = input_data->len;
|
|
|
|
TEST_ASSERT( output2_size <=
|
|
|
|
TEST_LE_U( output2_size,
|
|
|
|
PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE( key_type, key_bits, alg ) );
|
|
|
|
PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE( key_type, key_bits, alg ) );
|
|
|
|
TEST_ASSERT( output2_size <= PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE );
|
|
|
|
TEST_LE_U( output2_size, PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE );
|
|
|
|
ASSERT_ALLOC( output2, output2_size );
|
|
|
|
ASSERT_ALLOC( output2, output2_size );
|
|
|
|
|
|
|
|
|
|
|
|
/* We test encryption by checking that encrypt-then-decrypt gives back
|
|
|
|
/* We test encryption by checking that encrypt-then-decrypt gives back
|
|
|
@@ -4239,7 +4239,7 @@ void asymmetric_encrypt_decrypt( int key_type_arg,
|
|
|
|
&output_length ) );
|
|
|
|
&output_length ) );
|
|
|
|
/* We don't know what ciphertext length to expect, but check that
|
|
|
|
/* We don't know what ciphertext length to expect, but check that
|
|
|
|
* it looks sensible. */
|
|
|
|
* it looks sensible. */
|
|
|
|
TEST_ASSERT( output_length <= output_size );
|
|
|
|
TEST_LE_U( output_length, output_size );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_asymmetric_decrypt( key, alg,
|
|
|
|
PSA_ASSERT( psa_asymmetric_decrypt( key, alg,
|
|
|
|
output, output_length,
|
|
|
|
output, output_length,
|
|
|
@@ -4294,7 +4294,7 @@ void asymmetric_decrypt( int key_type_arg,
|
|
|
|
|
|
|
|
|
|
|
|
/* Determine the maximum ciphertext length */
|
|
|
|
/* Determine the maximum ciphertext length */
|
|
|
|
output_size = PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
output_size = PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
|
|
|
|
TEST_ASSERT( output_size <= PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE );
|
|
|
|
TEST_LE_U( output_size, PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE );
|
|
|
|
ASSERT_ALLOC( output, output_size );
|
|
|
|
ASSERT_ALLOC( output, output_size );
|
|
|
|
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_asymmetric_decrypt( key, alg,
|
|
|
|
PSA_ASSERT( psa_asymmetric_decrypt( key, alg,
|
|
|
@@ -4367,7 +4367,7 @@ void asymmetric_decrypt_fail( int key_type_arg,
|
|
|
|
output, output_size,
|
|
|
|
output, output_size,
|
|
|
|
&output_length );
|
|
|
|
&output_length );
|
|
|
|
TEST_EQUAL( actual_status, expected_status );
|
|
|
|
TEST_EQUAL( actual_status, expected_status );
|
|
|
|
TEST_ASSERT( output_length <= output_size );
|
|
|
|
TEST_LE_U( output_length, output_size );
|
|
|
|
|
|
|
|
|
|
|
|
/* If the label is empty, the test framework puts a non-null pointer
|
|
|
|
/* If the label is empty, the test framework puts a non-null pointer
|
|
|
|
* in label->x. Test that a null pointer works as well. */
|
|
|
|
* in label->x. Test that a null pointer works as well. */
|
|
|
@@ -4382,7 +4382,7 @@ void asymmetric_decrypt_fail( int key_type_arg,
|
|
|
|
output, output_size,
|
|
|
|
output, output_size,
|
|
|
|
&output_length );
|
|
|
|
&output_length );
|
|
|
|
TEST_EQUAL( actual_status, expected_status );
|
|
|
|
TEST_EQUAL( actual_status, expected_status );
|
|
|
|
TEST_ASSERT( output_length <= output_size );
|
|
|
|
TEST_LE_U( output_length, output_size );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
exit:
|
|
|
@@ -5094,7 +5094,6 @@ void raw_key_agreement( int alg_arg,
|
|
|
|
size_t output_length = ~0;
|
|
|
|
size_t output_length = ~0;
|
|
|
|
size_t key_bits;
|
|
|
|
size_t key_bits;
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_ALLOC( output, expected_output->len );
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
|
|
|
|
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
|
|
|
|
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
|
|
|
@@ -5107,16 +5106,47 @@ void raw_key_agreement( int alg_arg,
|
|
|
|
PSA_ASSERT( psa_get_key_attributes( our_key, &attributes ) );
|
|
|
|
PSA_ASSERT( psa_get_key_attributes( our_key, &attributes ) );
|
|
|
|
key_bits = psa_get_key_bits( &attributes );
|
|
|
|
key_bits = psa_get_key_bits( &attributes );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Validate size macros */
|
|
|
|
|
|
|
|
TEST_LE_U( expected_output->len,
|
|
|
|
|
|
|
|
PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE( our_key_type, key_bits ) );
|
|
|
|
|
|
|
|
TEST_LE_U( PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE( our_key_type, key_bits ),
|
|
|
|
|
|
|
|
PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Good case with exact output size */
|
|
|
|
|
|
|
|
ASSERT_ALLOC( output, expected_output->len );
|
|
|
|
PSA_ASSERT( psa_raw_key_agreement( alg, our_key,
|
|
|
|
PSA_ASSERT( psa_raw_key_agreement( alg, our_key,
|
|
|
|
peer_key_data->x, peer_key_data->len,
|
|
|
|
peer_key_data->x, peer_key_data->len,
|
|
|
|
output, expected_output->len,
|
|
|
|
output, expected_output->len,
|
|
|
|
&output_length ) );
|
|
|
|
&output_length ) );
|
|
|
|
ASSERT_COMPARE( output, output_length,
|
|
|
|
ASSERT_COMPARE( output, output_length,
|
|
|
|
expected_output->x, expected_output->len );
|
|
|
|
expected_output->x, expected_output->len );
|
|
|
|
TEST_ASSERT( output_length <=
|
|
|
|
mbedtls_free( output );
|
|
|
|
PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE( our_key_type, key_bits ) );
|
|
|
|
output = NULL;
|
|
|
|
TEST_ASSERT( output_length <=
|
|
|
|
output_length = ~0;
|
|
|
|
PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE );
|
|
|
|
|
|
|
|
|
|
|
|
/* Larger buffer */
|
|
|
|
|
|
|
|
ASSERT_ALLOC( output, expected_output->len + 1 );
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_raw_key_agreement( alg, our_key,
|
|
|
|
|
|
|
|
peer_key_data->x, peer_key_data->len,
|
|
|
|
|
|
|
|
output, expected_output->len + 1,
|
|
|
|
|
|
|
|
&output_length ) );
|
|
|
|
|
|
|
|
ASSERT_COMPARE( output, output_length,
|
|
|
|
|
|
|
|
expected_output->x, expected_output->len );
|
|
|
|
|
|
|
|
mbedtls_free( output );
|
|
|
|
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
output_length = ~0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Buffer too small */
|
|
|
|
|
|
|
|
ASSERT_ALLOC( output, expected_output->len - 1 );
|
|
|
|
|
|
|
|
TEST_EQUAL( psa_raw_key_agreement( alg, our_key,
|
|
|
|
|
|
|
|
peer_key_data->x, peer_key_data->len,
|
|
|
|
|
|
|
|
output, expected_output->len - 1,
|
|
|
|
|
|
|
|
&output_length ),
|
|
|
|
|
|
|
|
PSA_ERROR_BUFFER_TOO_SMALL );
|
|
|
|
|
|
|
|
/* Not required by the spec, but good robustness */
|
|
|
|
|
|
|
|
TEST_LE_U( output_length, expected_output->len - 1 );
|
|
|
|
|
|
|
|
mbedtls_free( output );
|
|
|
|
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
exit:
|
|
|
|
mbedtls_free( output );
|
|
|
|
mbedtls_free( output );
|
|
|
|