Lines Matching refs:slot

705 psa_status_t psa_allocate_buffer_to_slot(psa_key_slot_t *slot,  in psa_allocate_buffer_to_slot()  argument
713 if (slot->key.data != NULL) { in psa_allocate_buffer_to_slot()
717 slot->key.data = mbedtls_calloc(1, buffer_length); in psa_allocate_buffer_to_slot()
718 if (slot->key.data == NULL) { in psa_allocate_buffer_to_slot()
723 slot->key.bytes = buffer_length; in psa_allocate_buffer_to_slot()
727 psa_status_t psa_copy_key_material_into_slot(psa_key_slot_t *slot, in psa_copy_key_material_into_slot() argument
731 psa_status_t status = psa_allocate_buffer_to_slot(slot, in psa_copy_key_material_into_slot()
737 memcpy(slot->key.data, data, data_length); in psa_copy_key_material_into_slot()
1104 psa_key_slot_t *slot = NULL; in psa_get_and_lock_key_slot_with_policy() local
1110 slot = *p_slot; in psa_get_and_lock_key_slot_with_policy()
1116 if (PSA_KEY_TYPE_IS_PUBLIC_KEY(slot->attr.type)) { in psa_get_and_lock_key_slot_with_policy()
1120 if ((slot->attr.policy.usage & usage) != usage) { in psa_get_and_lock_key_slot_with_policy()
1127 status = psa_key_policy_permits(&slot->attr.policy, in psa_get_and_lock_key_slot_with_policy()
1128 slot->attr.type, in psa_get_and_lock_key_slot_with_policy()
1139 psa_unregister_read_under_mutex(slot); in psa_get_and_lock_key_slot_with_policy()
1184 psa_status_t psa_remove_key_data_from_memory(psa_key_slot_t *slot) in psa_remove_key_data_from_memory() argument
1187 if (slot->key.bytes > 0) { in psa_remove_key_data_from_memory()
1188 mbedtls_platform_zeroize(slot->key.data, MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE); in psa_remove_key_data_from_memory()
1191 if (slot->key.data != NULL) { in psa_remove_key_data_from_memory()
1192 mbedtls_zeroize_and_free(slot->key.data, slot->key.bytes); in psa_remove_key_data_from_memory()
1195 slot->key.data = NULL; in psa_remove_key_data_from_memory()
1198 slot->key.bytes = 0; in psa_remove_key_data_from_memory()
1205 psa_status_t psa_wipe_key_slot(psa_key_slot_t *slot) in psa_wipe_key_slot() argument
1207 psa_status_t status = psa_remove_key_data_from_memory(slot); in psa_wipe_key_slot()
1219 switch (slot->state) { in psa_wipe_key_slot()
1226 if (slot->var.occupied.registered_readers != 1) { in psa_wipe_key_slot()
1227 MBEDTLS_TEST_HOOK_TEST_ASSERT(slot->var.occupied.registered_readers == 1); in psa_wipe_key_slot()
1233 if (slot->var.occupied.registered_readers != 0) { in psa_wipe_key_slot()
1234 MBEDTLS_TEST_HOOK_TEST_ASSERT(slot->var.occupied.registered_readers == 0); in psa_wipe_key_slot()
1240 MBEDTLS_TEST_HOOK_TEST_ASSERT(slot->state != PSA_SLOT_EMPTY); in psa_wipe_key_slot()
1249 size_t slice_index = slot->slice_index; in psa_wipe_key_slot()
1262 memset(slot, 0, sizeof(*slot)); in psa_wipe_key_slot()
1270 status = psa_free_key_slot(slice_index, slot); in psa_wipe_key_slot()
1279 psa_key_slot_t *slot; in psa_destroy_key() local
1297 status = psa_get_and_lock_key_slot(key, &slot); in psa_destroy_key()
1310 if (slot->state == PSA_SLOT_PENDING_DELETION) { in psa_destroy_key()
1314 status = psa_unregister_read(slot); in psa_destroy_key()
1329 overall_status = psa_key_slot_state_transition(slot, PSA_SLOT_FULL, in psa_destroy_key()
1336 if (PSA_KEY_LIFETIME_IS_READ_ONLY(slot->attr.lifetime)) { in psa_destroy_key()
1347 driver = psa_get_se_driver_entry(slot->attr.lifetime); in psa_destroy_key()
1355 psa_crypto_transaction.key.lifetime = slot->attr.lifetime; in psa_destroy_key()
1356 psa_crypto_transaction.key.slot = psa_key_slot_get_slot_number(slot); in psa_destroy_key()
1357 psa_crypto_transaction.key.id = slot->attr.id; in psa_destroy_key()
1373 psa_key_slot_get_slot_number(slot)); in psa_destroy_key()
1381 if (!PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)) { in psa_destroy_key()
1385 status = psa_destroy_persistent_key(slot->attr.id); in psa_destroy_key()
1408 status = psa_unregister_read(slot); in psa_destroy_key()
1431 psa_key_slot_t *slot; in psa_get_key_attributes() local
1435 status = psa_get_and_lock_key_slot_with_policy(key, &slot, 0, 0); in psa_get_key_attributes()
1440 *attributes = slot->attr; in psa_get_key_attributes()
1443 if (psa_get_se_driver_entry(slot->attr.lifetime) != NULL) { in psa_get_key_attributes()
1445 psa_key_slot_get_slot_number(slot)); in psa_get_key_attributes()
1449 return psa_unregister_read_under_mutex(slot); in psa_get_key_attributes()
1511 psa_key_slot_t *slot; in psa_export_key() local
1531 status = psa_get_and_lock_key_slot_with_policy(key, &slot, in psa_export_key()
1539 status = psa_driver_wrapper_export_key(&slot->attr, in psa_export_key()
1540 slot->key.data, slot->key.bytes, in psa_export_key()
1546 unlock_status = psa_unregister_read_under_mutex(slot); in psa_export_key()
1626 psa_key_slot_t *slot; in psa_export_public_key() local
1644 status = psa_get_and_lock_key_slot_with_policy(key, &slot, 0, 0); in psa_export_public_key()
1651 if (!PSA_KEY_TYPE_IS_ASYMMETRIC(slot->attr.type)) { in psa_export_public_key()
1657 &slot->attr, slot->key.data, slot->key.bytes, in psa_export_public_key()
1661 unlock_status = psa_unregister_read_under_mutex(slot); in psa_export_public_key()
1811 psa_key_slot_t *slot = *p_slot; in psa_start_key_creation() local
1821 slot->attr = *attributes; in psa_start_key_creation()
1824 slot->attr.id = volatile_key_id; in psa_start_key_creation()
1826 slot->attr.id.key_id = volatile_key_id; in psa_start_key_creation()
1858 psa_crypto_transaction.key.lifetime = slot->attr.lifetime; in psa_start_key_creation()
1859 psa_crypto_transaction.key.slot = slot_number; in psa_start_key_creation()
1860 psa_crypto_transaction.key.id = slot->attr.id; in psa_start_key_creation()
1869 slot, (uint8_t *) (&slot_number), sizeof(slot_number)); in psa_start_key_creation()
1915 psa_key_slot_t *slot, in psa_finish_key_creation() argument
1920 (void) slot; in psa_finish_key_creation()
1929 if (!PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)) { in psa_finish_key_creation()
1934 psa_key_slot_get_slot_number(slot); in psa_finish_key_creation()
1941 status = psa_save_persistent_key(&slot->attr, in psa_finish_key_creation()
1949 status = psa_save_persistent_key(&slot->attr, in psa_finish_key_creation()
1950 slot->key.data, in psa_finish_key_creation()
1951 slot->key.bytes); in psa_finish_key_creation()
1966 psa_destroy_persistent_key(slot->attr.id); in psa_finish_key_creation()
1979 *key = slot->attr.id; in psa_finish_key_creation()
1980 status = psa_key_slot_state_transition(slot, PSA_SLOT_FILLING, in psa_finish_key_creation()
2006 static void psa_fail_key_creation(psa_key_slot_t *slot, in psa_fail_key_creation() argument
2011 if (slot == NULL) { in psa_fail_key_creation()
2039 psa_wipe_key_slot(slot); in psa_fail_key_creation()
2056 const psa_key_slot_t *slot, in psa_validate_optional_attributes() argument
2060 if (attributes->type != slot->attr.type) { in psa_validate_optional_attributes()
2066 if (attributes->bits != slot->attr.bits) { in psa_validate_optional_attributes()
2081 psa_key_slot_t *slot = NULL; in psa_import_key() local
2103 &slot, &driver); in psa_import_key()
2112 if (slot->key.bytes == 0) { in psa_import_key()
2120 status = psa_allocate_buffer_to_slot(slot, storage_size); in psa_import_key()
2126 bits = slot->attr.bits; in psa_import_key()
2129 slot->key.data, in psa_import_key()
2130 slot->key.bytes, in psa_import_key()
2131 &slot->key.bytes, &bits); in psa_import_key()
2136 if (slot->attr.bits == 0) { in psa_import_key()
2137 slot->attr.bits = (psa_key_bits_t) bits; in psa_import_key()
2138 } else if (bits != slot->attr.bits) { in psa_import_key()
2149 status = psa_validate_optional_attributes(slot, attributes); in psa_import_key()
2154 status = psa_finish_key_creation(slot, driver, key); in psa_import_key()
2158 psa_fail_key_creation(slot, driver); in psa_import_key()
2169 psa_key_slot_t *slot = NULL; in mbedtls_psa_register_se_key() local
2193 &slot, &driver); in mbedtls_psa_register_se_key()
2198 status = psa_finish_key_creation(slot, driver, &key); in mbedtls_psa_register_se_key()
2202 psa_fail_key_creation(slot, driver); in mbedtls_psa_register_se_key()
2698 psa_key_slot_t *slot = NULL; in psa_mac_setup() local
2715 &slot, in psa_mac_setup()
2722 status = psa_mac_finalize_alg_and_key_validation(alg, &slot->attr, in psa_mac_setup()
2732 &slot->attr, in psa_mac_setup()
2733 slot->key.data, in psa_mac_setup()
2734 slot->key.bytes, in psa_mac_setup()
2738 &slot->attr, in psa_mac_setup()
2739 slot->key.data, in psa_mac_setup()
2740 slot->key.bytes, in psa_mac_setup()
2749 unlock_status = psa_unregister_read_under_mutex(slot); in psa_mac_setup()
2906 psa_key_slot_t *slot; in psa_mac_compute_internal() local
2911 &slot, in psa_mac_compute_internal()
2918 status = psa_mac_finalize_alg_and_key_validation(alg, &slot->attr, in psa_mac_compute_internal()
2930 &slot->attr, in psa_mac_compute_internal()
2931 slot->key.data, slot->key.bytes, in psa_mac_compute_internal()
2950 unlock_status = psa_unregister_read_under_mutex(slot); in psa_mac_compute_internal()
3088 psa_key_slot_t *slot; in psa_sign_internal() local
3106 key, &slot, in psa_sign_internal()
3115 if (!PSA_KEY_TYPE_IS_KEY_PAIR(slot->attr.type)) { in psa_sign_internal()
3122 &slot->attr, slot->key.data, slot->key.bytes, in psa_sign_internal()
3128 &slot->attr, slot->key.data, slot->key.bytes, in psa_sign_internal()
3138 unlock_status = psa_unregister_read_under_mutex(slot); in psa_sign_internal()
3153 psa_key_slot_t *slot; in psa_verify_internal() local
3161 key, &slot, in psa_verify_internal()
3172 &slot->attr, slot->key.data, slot->key.bytes, in psa_verify_internal()
3177 &slot->attr, slot->key.data, slot->key.bytes, in psa_verify_internal()
3182 unlock_status = psa_unregister_read_under_mutex(slot); in psa_verify_internal()
3465 psa_key_slot_t *slot; in psa_asymmetric_encrypt() local
3484 key, &slot, PSA_KEY_USAGE_ENCRYPT, alg); in psa_asymmetric_encrypt()
3488 if (!(PSA_KEY_TYPE_IS_PUBLIC_KEY(slot->attr.type) || in psa_asymmetric_encrypt()
3489 PSA_KEY_TYPE_IS_KEY_PAIR(slot->attr.type))) { in psa_asymmetric_encrypt()
3499 &slot->attr, slot->key.data, slot->key.bytes, in psa_asymmetric_encrypt()
3503 unlock_status = psa_unregister_read_under_mutex(slot); in psa_asymmetric_encrypt()
3524 psa_key_slot_t *slot; in psa_asymmetric_decrypt() local
3543 key, &slot, PSA_KEY_USAGE_DECRYPT, alg); in psa_asymmetric_decrypt()
3547 if (!PSA_KEY_TYPE_IS_KEY_PAIR(slot->attr.type)) { in psa_asymmetric_decrypt()
3557 &slot->attr, slot->key.data, slot->key.bytes, in psa_asymmetric_decrypt()
3562 unlock_status = psa_unregister_read_under_mutex(slot); in psa_asymmetric_decrypt()
3629 psa_key_slot_t *slot; in psa_sign_hash_start() local
3652 status = psa_get_and_lock_key_slot_with_policy(key, &slot, in psa_sign_hash_start()
3660 if (!PSA_KEY_TYPE_IS_KEY_PAIR(slot->attr.type)) { in psa_sign_hash_start()
3670 status = psa_driver_wrapper_sign_hash_start(operation, &slot->attr, in psa_sign_hash_start()
3671 slot->key.data, in psa_sign_hash_start()
3672 slot->key.bytes, alg, in psa_sign_hash_start()
3681 unlock_status = psa_unregister_read_under_mutex(slot); in psa_sign_hash_start()
3795 psa_key_slot_t *slot; in psa_verify_hash_start() local
3819 status = psa_get_and_lock_key_slot_with_policy(key, &slot, in psa_verify_hash_start()
3834 status = psa_driver_wrapper_verify_hash_start(operation, &slot->attr, in psa_verify_hash_start()
3835 slot->key.data, in psa_verify_hash_start()
3836 slot->key.bytes, in psa_verify_hash_start()
3848 unlock_status = psa_unregister_read_under_mutex(slot); in psa_verify_hash_start()
4447 psa_key_slot_t *slot = NULL; in psa_cipher_setup() local
4463 status = psa_get_and_lock_key_slot_with_policy(key, &slot, usage, alg); in psa_cipher_setup()
4478 operation->default_iv_length = PSA_CIPHER_IV_LENGTH(slot->attr.type, alg); in psa_cipher_setup()
4491 &slot->attr, in psa_cipher_setup()
4492 slot->key.data, in psa_cipher_setup()
4493 slot->key.bytes, in psa_cipher_setup()
4497 &slot->attr, in psa_cipher_setup()
4498 slot->key.data, in psa_cipher_setup()
4499 slot->key.bytes, in psa_cipher_setup()
4508 unlock_status = psa_unregister_read_under_mutex(slot); in psa_cipher_setup()
4735 psa_key_slot_t *slot = NULL; in psa_cipher_encrypt() local
4747 status = psa_get_and_lock_key_slot_with_policy(key, &slot, in psa_cipher_encrypt()
4754 default_iv_length = PSA_CIPHER_IV_LENGTH(slot->attr.type, alg); in psa_cipher_encrypt()
4776 &slot->attr, slot->key.data, slot->key.bytes, in psa_cipher_encrypt()
4782 unlock_status = psa_unregister_read_under_mutex(slot); in psa_cipher_encrypt()
4812 psa_key_slot_t *slot = NULL; in psa_cipher_decrypt() local
4822 status = psa_get_and_lock_key_slot_with_policy(key, &slot, in psa_cipher_decrypt()
4829 if (input_length < PSA_CIPHER_IV_LENGTH(slot->attr.type, alg)) { in psa_cipher_decrypt()
4838 &slot->attr, slot->key.data, slot->key.bytes, in psa_cipher_decrypt()
4843 unlock_status = psa_unregister_read_under_mutex(slot); in psa_cipher_decrypt()
4935 psa_key_slot_t *slot; in psa_aead_encrypt() local
4950 key, &slot, PSA_KEY_USAGE_ENCRYPT, alg); in psa_aead_encrypt()
4966 &slot->attr, slot->key.data, slot->key.bytes, in psa_aead_encrypt()
4983 psa_unregister_read_under_mutex(slot); in psa_aead_encrypt()
5001 psa_key_slot_t *slot; in psa_aead_decrypt() local
5016 key, &slot, PSA_KEY_USAGE_DECRYPT, alg); in psa_aead_decrypt()
5033 &slot->attr, slot->key.data, slot->key.bytes, in psa_aead_decrypt()
5050 psa_unregister_read_under_mutex(slot); in psa_aead_decrypt()
5102 psa_key_slot_t *slot = NULL; in psa_aead_setup() local
5134 status = psa_get_and_lock_key_slot_with_policy(key, &slot, key_usage, in psa_aead_setup()
5146 &slot->attr, in psa_aead_setup()
5147 slot->key.data, in psa_aead_setup()
5148 slot->key.bytes, in psa_aead_setup()
5152 &slot->attr, in psa_aead_setup()
5153 slot->key.data, in psa_aead_setup()
5154 slot->key.bytes, in psa_aead_setup()
5161 operation->key_type = psa_get_key_type(&slot->attr); in psa_aead_setup()
5164 unlock_status = psa_unregister_read_under_mutex(slot); in psa_aead_setup()
6379 psa_key_slot_t *slot, in psa_generate_derived_ecc_key_weierstrass_helper() argument
6397 slot->attr.type); in psa_generate_derived_ecc_key_weierstrass_helper()
6538 psa_key_slot_t *slot, size_t bits, in psa_generate_derived_ecc_key_weierstrass_helper() argument
6541 (void) slot; in psa_generate_derived_ecc_key_weierstrass_helper()
6560 psa_key_slot_t *slot, in psa_generate_derived_key_internal() argument
6569 if (PSA_KEY_TYPE_IS_PUBLIC_KEY(slot->attr.type)) { in psa_generate_derived_key_internal()
6575 if (PSA_KEY_TYPE_IS_ECC(slot->attr.type)) { in psa_generate_derived_key_internal()
6576 psa_ecc_family_t curve = PSA_KEY_TYPE_ECC_GET_FAMILY(slot->attr.type); in psa_generate_derived_key_internal()
6579 status = psa_generate_derived_ecc_key_weierstrass_helper(slot, bits, operation, &data); in psa_generate_derived_key_internal()
6593 if (key_type_is_raw_bytes(slot->attr.type)) { in psa_generate_derived_key_internal()
6607 if (slot->attr.type == PSA_KEY_TYPE_DES) { in psa_generate_derived_key_internal()
6615 slot->attr.bits = (psa_key_bits_t) bits; in psa_generate_derived_key_internal()
6617 if (psa_key_lifetime_is_external(slot->attr.lifetime)) { in psa_generate_derived_key_internal()
6618 status = psa_driver_wrapper_get_key_buffer_size(&slot->attr, in psa_generate_derived_key_internal()
6624 status = psa_allocate_buffer_to_slot(slot, storage_size); in psa_generate_derived_key_internal()
6629 status = psa_driver_wrapper_import_key(&slot->attr, in psa_generate_derived_key_internal()
6631 slot->key.data, in psa_generate_derived_key_internal()
6632 slot->key.bytes, in psa_generate_derived_key_internal()
6633 &slot->key.bytes, &bits); in psa_generate_derived_key_internal()
6634 if (bits != slot->attr.bits) { in psa_generate_derived_key_internal()
6668 psa_key_slot_t *slot = NULL; in psa_key_derivation_output_key_custom() local
6693 &slot, &driver); in psa_key_derivation_output_key_custom()
6701 status = psa_generate_derived_key_internal(slot, in psa_key_derivation_output_key_custom()
6706 status = psa_finish_key_creation(slot, driver, key); in psa_key_derivation_output_key_custom()
6709 psa_fail_key_creation(slot, driver); in psa_key_derivation_output_key_custom()
7689 psa_key_slot_t *slot; in psa_key_derivation_input_key() local
7692 key, &slot, PSA_KEY_USAGE_DERIVE, operation->alg); in psa_key_derivation_input_key()
7706 step, slot->attr.type, in psa_key_derivation_input_key()
7707 slot->key.data, in psa_key_derivation_input_key()
7708 slot->key.bytes); in psa_key_derivation_input_key()
7710 unlock_status = psa_unregister_read_under_mutex(slot); in psa_key_derivation_input_key()
7840 psa_key_slot_t *slot; in psa_key_derivation_key_agreement() local
7847 private_key, &slot, PSA_KEY_USAGE_DERIVE, operation->alg); in psa_key_derivation_key_agreement()
7854 slot, in psa_key_derivation_key_agreement()
7870 unlock_status = psa_unregister_read_under_mutex(slot); in psa_key_derivation_key_agreement()
7886 psa_key_slot_t *slot = NULL; in psa_raw_key_agreement() local
7897 private_key, &slot, PSA_KEY_USAGE_DERIVE, alg); in psa_raw_key_agreement()
7911 PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(slot->attr.type, slot->attr.bits); in psa_raw_key_agreement()
7918 status = psa_key_agreement_raw_internal(alg, slot, in psa_raw_key_agreement()
7943 unlock_status = psa_unregister_read_under_mutex(slot); in psa_raw_key_agreement()
8192 psa_key_slot_t *slot = NULL; in psa_generate_key_custom() local
8221 &slot, &driver); in psa_generate_key_custom()
8230 if (slot->key.bytes == 0) { in psa_generate_key_custom()
8250 status = psa_allocate_buffer_to_slot(slot, key_buffer_size); in psa_generate_key_custom()
8259 slot->key.data, slot->key.bytes, in psa_generate_key_custom()
8260 &slot->key.bytes); in psa_generate_key_custom()
8262 psa_remove_key_data_from_memory(slot); in psa_generate_key_custom()
8267 status = psa_finish_key_creation(slot, driver, key); in psa_generate_key_custom()
8270 psa_fail_key_creation(slot, driver); in psa_generate_key_custom()
8743 psa_key_slot_t *slot = NULL; in psa_pake_set_password_key() local
8751 status = psa_get_and_lock_key_slot_with_policy(password, &slot, in psa_pake_set_password_key()
8758 type = psa_get_key_type(&slot->attr); in psa_pake_set_password_key()
8766 operation->data.inputs.password = mbedtls_calloc(1, slot->key.bytes); in psa_pake_set_password_key()
8772 memcpy(operation->data.inputs.password, slot->key.data, slot->key.bytes); in psa_pake_set_password_key()
8773 operation->data.inputs.password_len = slot->key.bytes; in psa_pake_set_password_key()
8774 operation->data.inputs.attributes = slot->attr; in psa_pake_set_password_key()
8780 unlock_status = psa_unregister_read_under_mutex(slot); in psa_pake_set_password_key()