mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-18 19:27:41 +00:00
WIP: Add asymmetric_encrypt test case
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
parent
7a58208809
commit
72373f3819
@ -704,3 +704,11 @@ asymmetric_decrypt:PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256):"3082025e02010002818100af05
|
||||
PSA decrypt transparent driver: fallback not available RSA OAEP-SHA-256
|
||||
depends_on:!MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP
|
||||
asymmetric_decrypt:PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256):"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b24":"13fd8220c266b34b894f916448d854f7438e075f55cc4df95edf7002bd88fd4b156305112f48362c1563a490ae56c29b546edb31dd5901db0c60197724d0a56ba1a33bfb0ed23bc806b0b2ca87ae9323ff86c7a06bf05108281a324b9f9af0bd50220aaf003606be1e5333fb53b97dff13261f8c6d2e4a5cefcd2b5589eb2a21":"":"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad":"":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED
|
||||
|
||||
PSA encrypt transparent driver: in-driver RSA OAEP-SHA-256
|
||||
depends_on:MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP
|
||||
asymmetric_encrypt:PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256):"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001":"00af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3":"010001":"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad":"":"":"":PSA_SUCCESS:PSA_SUCCESS
|
||||
|
||||
PSA encrypt transparent driver: in-driver RSA PKCS#1 v1.5
|
||||
depends_on:MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT
|
||||
asymmetric_encrypt:PSA_ALG_RSA_PKCS1V15_CRYPT:"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001":"00af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3":"010001":"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad":"":"":"":PSA_SUCCESS:PSA_SUCCESS
|
||||
|
@ -2025,3 +2025,105 @@ exit:
|
||||
PSA_DONE( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void asymmetric_encrypt( int alg_arg,
|
||||
data_t *key_data,
|
||||
data_t *key_modulus,
|
||||
data_t *key_exponent,
|
||||
data_t *input_data,
|
||||
data_t *label,
|
||||
data_t *expected_output_data,
|
||||
data_t *fake_output_encrypt,
|
||||
int forced_status_encrypt_arg,
|
||||
int expected_status_encrypt_arg )
|
||||
{
|
||||
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_PUBLIC_KEY;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
unsigned char *output = NULL;
|
||||
size_t output_size;
|
||||
size_t output_length = ~0;
|
||||
psa_status_t forced_status_encrypt = forced_status_encrypt_arg;
|
||||
psa_status_t expected_status_encrypt = expected_status_encrypt_arg;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
(void)expected_output_data;
|
||||
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks =
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks_init();
|
||||
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
|
||||
psa_set_key_algorithm( &attributes, alg );
|
||||
psa_set_key_type( &attributes, key_type );
|
||||
|
||||
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
|
||||
&key ) );
|
||||
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_status =
|
||||
forced_status_encrypt;
|
||||
|
||||
if ( fake_output_encrypt->len > 0 )
|
||||
{
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output =
|
||||
fake_output_encrypt->x;
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
|
||||
fake_output_encrypt->len;
|
||||
output_size = fake_output_encrypt->len;
|
||||
ASSERT_ALLOC( output, output_size );
|
||||
}
|
||||
else
|
||||
{
|
||||
output_size = key_data->len; // ???
|
||||
ASSERT_ALLOC( output, output_size );
|
||||
}
|
||||
|
||||
TEST_EQUAL( psa_asymmetric_encrypt( key, alg,
|
||||
input_data->x, input_data->len,
|
||||
label->x, label->len,
|
||||
output, output_size,
|
||||
&output_length ), expected_status_encrypt );
|
||||
if ( expected_status_encrypt == PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_mpi N, E, A, X;
|
||||
mbedtls_mpi_init( &N );
|
||||
mbedtls_mpi_init( &E );
|
||||
mbedtls_mpi_init( &A );
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &N, key_modulus->x, key_modulus->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &E, key_exponent->x, key_exponent->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &A, output, output_length ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_exp_mod( &X, &A, &E, &N, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_write_binary( &X, output, output_size ) == 0 );
|
||||
|
||||
mbedtls_fprintf( stderr, "\nInput: " );
|
||||
for( size_t i = 0; i < input_data->len; i++ ){
|
||||
if( input_data->x[i] < 16) mbedtls_fprintf( stderr, "%x", 0 );
|
||||
mbedtls_fprintf( stderr, "%x", input_data->x[i] );
|
||||
}
|
||||
mbedtls_fprintf( stderr, "\n" );
|
||||
|
||||
mbedtls_fprintf( stderr, "\nOutput: " );
|
||||
for( size_t i = 0; i < output_size; i++ ){
|
||||
if( output[i] < 16) mbedtls_fprintf( stderr, "%x", 0 );
|
||||
mbedtls_fprintf( stderr, "%x", output[i] );
|
||||
}
|
||||
mbedtls_fprintf( stderr, "\n" );
|
||||
|
||||
TEST_EQUAL( output_length, key_data->len );
|
||||
}
|
||||
exit:
|
||||
/*
|
||||
* Key attributes may have been returned by psa_get_key_attributes()
|
||||
* thus reset them as required.
|
||||
*/
|
||||
psa_reset_key_attributes( &attributes );
|
||||
|
||||
psa_destroy_key( key );
|
||||
mbedtls_free( output );
|
||||
PSA_DONE( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
x
Reference in New Issue
Block a user