crypto_se_driver.h
crypto_driver_common.h
mbedtls/check_config.h
mbedtls/config.h
mbedtls/config_psa.h
crypto_driver_common.h
crypto_platform.h
crypto_se_driver.h
psa/crypto_sizes.h
crypto_types.h
crypto_values.h
limits.h
stddef.h
stdint.h
psa_drv_se_context_t
psa_drv_se_mac_t
psa_drv_se_cipher_t
psa_drv_se_asymmetric_t
psa_drv_se_aead_t
psa_drv_se_key_management_t
psa_drv_se_key_derivation_t
psa_drv_se_t
- PSA_DRV_SE_HAL_VERSION
- psa_key_creation_method_t
- psa_drv_se_init_t
- psa_key_slot_number_t
- psa_drv_se_mac_setup_t
- psa_drv_se_mac_update_t
- psa_drv_se_mac_finish_t
- psa_drv_se_mac_finish_verify_t
- psa_drv_se_mac_abort_t
- psa_drv_se_mac_generate_t
- psa_drv_se_mac_verify_t
- psa_drv_se_cipher_setup_t
- psa_drv_se_cipher_set_iv_t
- psa_drv_se_cipher_update_t
- psa_drv_se_cipher_finish_t
- psa_drv_se_cipher_abort_t
- psa_drv_se_cipher_ecb_t
- psa_drv_se_asymmetric_sign_t
- psa_drv_se_asymmetric_verify_t
- psa_drv_se_asymmetric_encrypt_t
- psa_drv_se_asymmetric_decrypt_t
- psa_drv_se_aead_encrypt_t
- psa_drv_se_aead_decrypt_t
- psa_drv_se_allocate_key_t
- psa_drv_se_validate_slot_number_t
- psa_drv_se_import_key_t
- psa_drv_se_destroy_key_t
- psa_drv_se_export_key_t
- psa_drv_se_generate_key_t
- psa_drv_se_key_derivation_setup_t
- psa_drv_se_key_derivation_collateral_t
- psa_drv_se_key_derivation_derive_t
- psa_drv_se_key_derivation_export_t
- psa_register_se_driver

PSA external cryptoprocessor driver module.

This header declares types and function signatures for cryptography drivers that access key material via opaque references. This is meant for cryptoprocessors that have a separate key storage from the space in which the PSA Crypto implementation runs, typically secure elements (SEs).

This file is part of the PSA Crypto Driver HAL (hardware abstraction layer), containing functions for driver developers to implement to enable hardware to be called in a standardized way by a PSA Cryptography API implementation. The functions comprising the driver HAL, which driver authors implement, are not intended to be called by application developers.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */
    #ifndefPSA_CRYPTO_SE_DRIVER_H
    #definePSA_CRYPTO_SE_DRIVER_H

    #include"crypto_driver_common.h"

    #ifdef__cplusplus
    extern"C"{
    #endif

    typedefstruct{
    constvoid*constpersistent_data;

    constsize_tpersistent_data_size;

    uintptr_ttransient_data;
    }psa_drv_se_context_t;

    typedefpsa_status_t(*psa_drv_se_init_t)(psa_drv_se_context_t*drv_context,
    void*persistent_data,
    psa_key_location_tlocation);

    #ifdefined(__DOXYGEN_ONLY__)||!defined(MBEDTLS_PSA_CRYPTO_SE_C)
    /*MbedTLSwithsecureelementsupportenableddefinesthistypein
    *crypto_types.hbecauseitisalsovisibletoapplicationsthroughan
    *implementation-specificextension.
    *ForthePSACryptographyspecification,thistypeisonlyvisible
    *viacrypto_se_driver.h.*/
    typedefuint64_tpsa_key_slot_number_t;
    #endif/*__DOXYGEN_ONLY__||!MBEDTLS_PSA_CRYPTO_SE_C*/

    typedefpsa_status_t(*psa_drv_se_mac_setup_t)(psa_drv_se_context_t*drv_context,
    void*op_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talgorithm);

    typedefpsa_status_t(*psa_drv_se_mac_update_t)(void*op_context,
    constuint8_t*p_input,
    size_tinput_length);

    typedefpsa_status_t(*psa_drv_se_mac_finish_t)(void*op_context,
    uint8_t*p_mac,
    size_tmac_size,
    size_t*p_mac_length);

    typedefpsa_status_t(*psa_drv_se_mac_finish_verify_t)(void*op_context,
    constuint8_t*p_mac,
    size_tmac_length);

    typedefpsa_status_t(*psa_drv_se_mac_abort_t)(void*op_context);

    typedefpsa_status_t(*psa_drv_se_mac_generate_t)(psa_drv_se_context_t*drv_context,
    constuint8_t*p_input,
    size_tinput_length,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talg,
    uint8_t*p_mac,
    size_tmac_size,
    size_t*p_mac_length);

    typedefpsa_status_t(*psa_drv_se_mac_verify_t)(psa_drv_se_context_t*drv_context,
    constuint8_t*p_input,
    size_tinput_length,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talg,
    constuint8_t*p_mac,
    size_tmac_length);

    typedefstruct{
    size_tcontext_size;
    psa_drv_se_mac_setup_tp_setup;
    psa_drv_se_mac_update_tp_update;
    psa_drv_se_mac_finish_tp_finish;
    psa_drv_se_mac_finish_verify_tp_finish_verify;
    psa_drv_se_mac_abort_tp_abort;
    psa_drv_se_mac_generate_tp_mac;
    psa_drv_se_mac_verify_tp_mac_verify;
    }psa_drv_se_mac_t;
    typedefpsa_status_t(*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t*drv_context,
    void*op_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talgorithm,
    psa_encrypt_or_decrypt_tdirection);

    typedefpsa_status_t(*psa_drv_se_cipher_set_iv_t)(void*op_context,
    constuint8_t*p_iv,
    size_tiv_length);

    typedefpsa_status_t(*psa_drv_se_cipher_update_t)(void*op_context,
    constuint8_t*p_input,
    size_tinput_size,
    uint8_t*p_output,
    size_toutput_size,
    size_t*p_output_length);

    typedefpsa_status_t(*psa_drv_se_cipher_finish_t)(void*op_context,
    uint8_t*p_output,
    size_toutput_size,
    size_t*p_output_length);

    typedefpsa_status_t(*psa_drv_se_cipher_abort_t)(void*op_context);

    typedefpsa_status_t(*psa_drv_se_cipher_ecb_t)(psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talgorithm,
    psa_encrypt_or_decrypt_tdirection,
    constuint8_t*p_input,
    size_tinput_size,
    uint8_t*p_output,
    size_toutput_size);

    typedefstruct{
    size_tcontext_size;
    psa_drv_se_cipher_setup_tp_setup;
    psa_drv_se_cipher_set_iv_tp_set_iv;
    psa_drv_se_cipher_update_tp_update;
    psa_drv_se_cipher_finish_tp_finish;
    psa_drv_se_cipher_abort_tp_abort;
    psa_drv_se_cipher_ecb_tp_ecb;
    }psa_drv_se_cipher_t;

    typedefpsa_status_t(*psa_drv_se_asymmetric_sign_t)(psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talg,
    constuint8_t*p_hash,
    size_thash_length,
    uint8_t*p_signature,
    size_tsignature_size,
    size_t*p_signature_length);

    typedefpsa_status_t(*psa_drv_se_asymmetric_verify_t)(psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talg,
    constuint8_t*p_hash,
    size_thash_length,
    constuint8_t*p_signature,
    size_tsignature_length);

    typedefpsa_status_t(*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talg,
    constuint8_t*p_input,
    size_tinput_length,
    constuint8_t*p_salt,
    size_tsalt_length,
    uint8_t*p_output,
    size_toutput_size,
    size_t*p_output_length);

    typedefpsa_status_t(*psa_drv_se_asymmetric_decrypt_t)(psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talg,
    constuint8_t*p_input,
    size_tinput_length,
    constuint8_t*p_salt,
    size_tsalt_length,
    uint8_t*p_output,
    size_toutput_size,
    size_t*p_output_length);

    typedefstruct{
    psa_drv_se_asymmetric_sign_tp_sign;
    psa_drv_se_asymmetric_verify_tp_verify;
    psa_drv_se_asymmetric_encrypt_tp_encrypt;
    psa_drv_se_asymmetric_decrypt_tp_decrypt;
    }psa_drv_se_asymmetric_t;

    typedefpsa_status_t(*psa_drv_se_aead_encrypt_t)(psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talgorithm,
    constuint8_t*p_nonce,
    size_tnonce_length,
    constuint8_t*p_additional_data,
    size_tadditional_data_length,
    constuint8_t*p_plaintext,
    size_tplaintext_length,
    uint8_t*p_ciphertext,
    size_tciphertext_size,
    size_t*p_ciphertext_length);

    typedefpsa_status_t(*psa_drv_se_aead_decrypt_t)(psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    psa_algorithm_talgorithm,
    constuint8_t*p_nonce,
    size_tnonce_length,
    constuint8_t*p_additional_data,
    size_tadditional_data_length,
    constuint8_t*p_ciphertext,
    size_tciphertext_length,
    uint8_t*p_plaintext,
    size_tplaintext_size,
    size_t*p_plaintext_length);

    typedefstruct{
    psa_drv_se_aead_encrypt_tp_encrypt;
    psa_drv_se_aead_decrypt_tp_decrypt;
    }psa_drv_se_aead_t;
    typedefenum{
    PSA_KEY_CREATION_IMPORT,
    PSA_KEY_CREATION_GENERATE,
    PSA_KEY_CREATION_DERIVE,
    PSA_KEY_CREATION_COPY,
    #ifndef__DOXYGEN_ONLY__
    PSA_KEY_CREATION_REGISTER,
    #endif
    }psa_key_creation_method_t;

    typedefpsa_status_t(*psa_drv_se_allocate_key_t)(
    psa_drv_se_context_t*drv_context,
    void*persistent_data,
    constpsa_key_attributes_t*attributes,
    psa_key_creation_method_tmethod,
    psa_key_slot_number_t*key_slot);

    typedefpsa_status_t(*psa_drv_se_validate_slot_number_t)(
    psa_drv_se_context_t*drv_context,
    void*persistent_data,
    constpsa_key_attributes_t*attributes,
    psa_key_creation_method_tmethod,
    psa_key_slot_number_tkey_slot);

    typedefpsa_status_t(*psa_drv_se_import_key_t)(
    psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    constpsa_key_attributes_t*attributes,
    constuint8_t*data,
    size_tdata_length,
    size_t*bits);

    typedefpsa_status_t(*psa_drv_se_destroy_key_t)(
    psa_drv_se_context_t*drv_context,
    void*persistent_data,
    psa_key_slot_number_tkey_slot);

    typedefpsa_status_t(*psa_drv_se_export_key_t)(psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey,
    uint8_t*p_data,
    size_tdata_size,
    size_t*p_data_length);

    typedefpsa_status_t(*psa_drv_se_generate_key_t)(
    psa_drv_se_context_t*drv_context,
    psa_key_slot_number_tkey_slot,
    constpsa_key_attributes_t*attributes,
    uint8_t*pubkey,size_tpubkey_size,size_t*pubkey_length);

    typedefstruct{
    psa_drv_se_allocate_key_tp_allocate;
    psa_drv_se_validate_slot_number_tp_validate_slot_number;
    psa_drv_se_import_key_tp_import;
    psa_drv_se_generate_key_tp_generate;
    psa_drv_se_destroy_key_tp_destroy;
    psa_drv_se_export_key_tp_export;
    psa_drv_se_export_key_tp_export_public;
    }psa_drv_se_key_management_t;

    typedefpsa_status_t(*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t*drv_context,
    void*op_context,
    psa_algorithm_tkdf_alg,
    psa_key_slot_number_tsource_key);

    typedefpsa_status_t(*psa_drv_se_key_derivation_collateral_t)(void*op_context,
    uint32_tcollateral_id,
    constuint8_t*p_collateral,
    size_tcollateral_size);

    typedefpsa_status_t(*psa_drv_se_key_derivation_derive_t)(void*op_context,
    psa_key_slot_number_tdest_key);

    typedefpsa_status_t(*psa_drv_se_key_derivation_export_t)(void*op_context,
    uint8_t*p_output,
    size_toutput_size,
    size_t*p_output_length);

    typedefstruct{
    size_tcontext_size;
    psa_drv_se_key_derivation_setup_tp_setup;
    psa_drv_se_key_derivation_collateral_tp_collateral;
    psa_drv_se_key_derivation_derive_tp_derive;
    psa_drv_se_key_derivation_export_tp_export;
    }psa_drv_se_key_derivation_t;

    typedefstruct{
    uint32_thal_version;

    size_tpersistent_data_size;

    psa_drv_se_init_tp_init;

    constpsa_drv_se_key_management_t*key_management;
    constpsa_drv_se_mac_t*mac;
    constpsa_drv_se_cipher_t*cipher;
    constpsa_drv_se_aead_t*aead;
    constpsa_drv_se_asymmetric_t*asymmetric;
    constpsa_drv_se_key_derivation_t*derivation;
    }psa_drv_se_t;

    /*0.0.0patchlevel5*/
    #definePSA_DRV_SE_HAL_VERSION0x00000005

    psa_status_tpsa_register_se_driver(
    psa_key_location_tlocation,
    constpsa_drv_se_t*methods);

    #ifdef__cplusplus
    }
    #endif

    #endif/*PSA_CRYPTO_SE_DRIVER_H*/