Skip to content

Commit 0c055f6

Browse files
committed
Integrate psa_key_agreement() with SPM code
1 parent af85964 commit 0c055f6

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/crypto_platform_spe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ typedef enum psa_sec_function_s
8585
PSA_GENERATOR_READ,
8686
PSA_GENERATOR_IMPORT_KEY,
8787
PSA_GENERATOR_ABORT,
88-
PSA_KEY_DERIVATION
88+
PSA_KEY_DERIVATION,
89+
PSA_KEY_AGREEMENT
8990
}psa_sec_function_t;
9091

9192
/**@}*/

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/psa_crypto_spm.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,32 @@ psa_status_t psa_key_derivation( psa_crypto_generator_t *generator,
10281028

10291029
}
10301030

1031+
psa_status_t psa_key_agreement( psa_crypto_generator_t *generator,
1032+
psa_key_slot_t private_key,
1033+
const uint8_t *peer_key,
1034+
size_t peer_key_length,
1035+
psa_algorithm_t alg )
1036+
{
1037+
psa_error_t err_call;
1038+
psa_crypto_derivation_ipc_t psa_crypto_ipc = { 0, 0, 0, 0 };
1039+
psa_crypto_ipc.key = private_key;
1040+
psa_crypto_ipc.alg = alg;
1041+
psa_crypto_ipc.func = PSA_KEY_AGREEMENT;
1042+
1043+
psa_invec_t in_vec[2] = { { &psa_crypto_ipc, sizeof( psa_crypto_ipc ) },
1044+
{ peer_key, peer_key_length }};
1045+
1046+
generator->handle = psa_connect( PSA_GENERATOR_ID, MINOR_VER );
1047+
if( generator->handle <= 0 )
1048+
return( PSA_ERROR_COMMUNICATION_FAILURE );
1049+
1050+
err_call = psa_call( generator->handle, in_vec, 2, NULL, 0 );
1051+
1052+
if( err_call < 0 )
1053+
err_call = ( psa_error_t ) PSA_ERROR_COMMUNICATION_FAILURE;
1054+
return( ( psa_status_t ) err_call );
1055+
}
1056+
10311057
psa_status_t psa_generator_abort( psa_crypto_generator_t *generator )
10321058
{
10331059
psa_error_t err_call = PSA_SUCCESS;

components/TARGET_PSA/services/crypto/COMPONENT_SPE/crypto_spe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extern "C" {
5757
#define psa_generator_import_key psa_sec_generator_import_key
5858
#define mbedtls_psa_crypto_free mbedtls_psa_sec_crypto_free
5959
#define psa_key_derivation psa_sec_key_derivation
60+
#define psa_key_agreement psa_sec_key_agreement
6061
#define psa_generator_abort psa_sec_generator_abort
6162
#define mbedtls_psa_inject_entropy mbedtls_psa_sec_inject_entropy
6263

components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,33 @@ void psa_crypto_generator_operations( void )
13671367

13681368
break;
13691369
}
1370+
case PSA_KEY_AGREEMENT:
1371+
{
1372+
1373+
uint8_t *private_key = mbedtls_calloc( 1, msg.in_size[1] );
1374+
if ( private_key == NULL )
1375+
{
1376+
status = PSA_ERROR_INSUFFICIENT_MEMORY;
1377+
break;
1378+
}
1379+
1380+
bytes_read = psa_read( msg.handle, 1, private_key,
1381+
msg.in_size[1] );
1382+
if( bytes_read != msg.in_size[1] )
1383+
{
1384+
SPM_PANIC("SPM read length mismatch");
1385+
}
1386+
1387+
status = check_spm_key_acl(msg.handle, psa_crypto_ipc.key);
1388+
if (status == PSA_SUCCESS) {
1389+
status = psa_key_agreement( msg.rhandle, psa_crypto_ipc.key,
1390+
private_key,
1391+
msg.in_size[1],//private_key length
1392+
psa_crypto_ipc.alg );
1393+
}
1394+
1395+
break;
1396+
}
13701397
default:
13711398
{
13721399
status = PSA_ERROR_NOT_SUPPORTED;

0 commit comments

Comments
 (0)