@@ -444,6 +444,13 @@ exit:
444
444
/* Other test helper functions */
445
445
/****************************************************************/
446
446
447
+ typedef enum
448
+ {
449
+ SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION,
450
+ SIGN_IN_DRIVER_AND_PARALLEL_CREATION,
451
+ SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC,
452
+ } sign_verify_method_t;
453
+
447
454
/* Check that the attributes of a key reported by psa_get_key_attributes()
448
455
* are consistent with the attributes used when creating the key. */
449
456
static int check_key_attributes(
@@ -1017,7 +1024,7 @@ exit:
1017
1024
/* END_CASE */
1018
1025
1019
1026
/* BEGIN_CASE */
1020
- void sign_verify( int sign_in_driver ,
1027
+ void sign_verify( int flow ,
1021
1028
int type_arg, int alg_arg,
1022
1029
int bits_arg, data_t *key_material,
1023
1030
data_t *input )
@@ -1036,75 +1043,121 @@ void sign_verify( int sign_in_driver,
1036
1043
psa_key_id_t id = 1;
1037
1044
psa_key_handle_t drv_handle = 0; /* key managed by the driver */
1038
1045
psa_key_handle_t sw_handle = 0; /* transparent key */
1039
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
1046
+ psa_key_attributes_t sw_attributes = PSA_KEY_ATTRIBUTES_INIT;
1047
+ psa_key_attributes_t drv_attributes;
1040
1048
uint8_t signature[PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE];
1041
1049
size_t signature_length;
1042
1050
1043
1051
memset( &driver, 0, sizeof( driver ) );
1044
1052
memset( &key_management, 0, sizeof( key_management ) );
1053
+ memset( &asymmetric, 0, sizeof( asymmetric ) );
1045
1054
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
1046
1055
driver.key_management = &key_management;
1047
1056
driver.asymmetric = &asymmetric;
1048
- driver.persistent_data_size = sizeof( psa_key_slot_number_t );
1049
1057
driver.persistent_data_size = sizeof( ram_slot_usage_t );
1050
1058
key_management.p_allocate = ram_allocate;
1051
1059
key_management.p_destroy = ram_destroy;
1052
1060
if( generating )
1053
1061
key_management.p_generate = ram_fake_generate;
1054
1062
else
1055
1063
key_management.p_import = ram_import;
1056
- if( sign_in_driver )
1057
- asymmetric.p_sign = ram_sign;
1064
+ switch( flow )
1065
+ {
1066
+ case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
1067
+ break;
1068
+ case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
1069
+ asymmetric.p_sign = ram_sign;
1070
+ break;
1071
+ case SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:
1072
+ asymmetric.p_sign = ram_sign;
1073
+ key_management.p_export_public = ram_export_public;
1074
+ break;
1075
+ default:
1076
+ TEST_ASSERT( ! "unsupported flow (should be SIGN_IN_xxx)" );
1077
+ break;
1078
+ }
1058
1079
asymmetric.p_verify = ram_verify;
1059
1080
1060
1081
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
1061
1082
PSA_ASSERT( psa_crypto_init( ) );
1062
1083
1063
- /* Create two keys with the same key material: a transparent key,
1064
- * and one that goes through the driver. */
1065
- psa_set_key_usage_flags( &attributes ,
1084
+ /* Prepare to create two keys with the same key material: a transparent
1085
+ * key, and one that goes through the driver. */
1086
+ psa_set_key_usage_flags( &sw_attributes ,
1066
1087
PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY );
1067
- psa_set_key_algorithm( &attributes , alg );
1068
- psa_set_key_type( &attributes , type );
1069
- PSA_ASSERT( psa_import_key( &attributes,
1070
- key_material->x, key_material->len,
1071
- &sw_handle ) );
1072
- psa_set_key_id( &attributes, id );
1073
- psa_set_key_lifetime( &attributes, lifetime );
1088
+ psa_set_key_algorithm( &sw_attributes , alg );
1089
+ psa_set_key_type( &sw_attributes , type );
1090
+ drv_attributes = sw_attributes;
1091
+ psa_set_key_id( &drv_attributes, id );
1092
+ psa_set_key_lifetime( &drv_attributes, lifetime );
1093
+
1094
+ /* Create the key in the driver. */
1074
1095
if( generating )
1075
1096
{
1076
- psa_set_key_bits( &attributes , bits );
1077
- PSA_ASSERT( psa_generate_key( &attributes , &drv_handle ) );
1097
+ psa_set_key_bits( &drv_attributes , bits );
1098
+ PSA_ASSERT( psa_generate_key( &drv_attributes , &drv_handle ) );
1078
1099
/* Since we called a generate method that does not actually
1079
1100
* generate material, store the desired result of generation in
1080
1101
* the mock secure element storage. */
1081
- PSA_ASSERT( psa_get_key_attributes( drv_handle, &attributes ) );
1102
+ PSA_ASSERT( psa_get_key_attributes( drv_handle, &drv_attributes ) );
1082
1103
TEST_ASSERT( key_material->len == PSA_BITS_TO_BYTES( bits ) );
1083
1104
memcpy( ram_slots[ram_min_slot].content, key_material->x,
1084
1105
key_material->len );
1085
1106
}
1086
1107
else
1087
1108
{
1088
- PSA_ASSERT( psa_import_key( &attributes ,
1109
+ PSA_ASSERT( psa_import_key( &drv_attributes ,
1089
1110
key_material->x, key_material->len,
1090
1111
&drv_handle ) );
1091
1112
}
1092
1113
1114
+ /* Either import the same key in software, or export the driver's
1115
+ * public key and import that. */
1116
+ switch( flow )
1117
+ {
1118
+ case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
1119
+ case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
1120
+ PSA_ASSERT( psa_import_key( &sw_attributes,
1121
+ key_material->x, key_material->len,
1122
+ &sw_handle ) );
1123
+ break;
1124
+ case SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:
1125
+ {
1126
+ uint8_t public_key[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE( PSA_VENDOR_ECC_MAX_CURVE_BITS )];
1127
+ size_t public_key_length;
1128
+ PSA_ASSERT( psa_export_public_key( drv_handle,
1129
+ public_key, sizeof( public_key ),
1130
+ &public_key_length ) );
1131
+ psa_set_key_type( &sw_attributes,
1132
+ PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( type ) );
1133
+ PSA_ASSERT( psa_import_key( &sw_attributes,
1134
+ public_key, public_key_length,
1135
+ &sw_handle ) );
1136
+ break;
1137
+ }
1138
+ }
1139
+
1093
1140
/* Sign with the chosen key. */
1094
- if( sign_in_driver )
1095
- PSA_ASSERT_VIA_DRIVER(
1096
- psa_asymmetric_sign( drv_handle,
1097
- alg,
1098
- input->x, input->len,
1099
- signature, sizeof( signature ),
1100
- &signature_length ),
1101
- PSA_SUCCESS );
1102
- else
1103
- PSA_ASSERT( psa_asymmetric_sign( sw_handle,
1104
- alg,
1105
- input->x, input->len,
1106
- signature, sizeof( signature ),
1107
- &signature_length ) );
1141
+ switch( flow )
1142
+ {
1143
+ case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
1144
+ case SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:
1145
+ PSA_ASSERT_VIA_DRIVER(
1146
+ psa_asymmetric_sign( drv_handle,
1147
+ alg,
1148
+ input->x, input->len,
1149
+ signature, sizeof( signature ),
1150
+ &signature_length ),
1151
+ PSA_SUCCESS );
1152
+ break;
1153
+ case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
1154
+ PSA_ASSERT( psa_asymmetric_sign( sw_handle,
1155
+ alg,
1156
+ input->x, input->len,
1157
+ signature, sizeof( signature ),
1158
+ &signature_length ) );
1159
+ break;
1160
+ }
1108
1161
1109
1162
/* Verify with both keys. */
1110
1163
PSA_ASSERT( psa_asymmetric_verify( sw_handle, alg,
0 commit comments