From 7046468a02cbc5bd49f40a055b2e60446671ab23 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 4 Jul 2023 14:38:06 +0100 Subject: [PATCH 01/26] Define the psa wrapper functions as static inline This is a commit from Thomas Daubney. Signed-off-by: Thomas Daubney Signed-off-by: Xiaokang Qian --- 3rdparty/p256-m/p256-m_driver_entrypoints.c | 1 - library/psa_crypto.c | 2 +- library/psa_crypto_driver_wrappers.h | 124 ++++++++--------- library/psa_crypto_slot_management.c | 2 +- .../psa_crypto_driver_wrappers.c.jinja | 125 +++++++++--------- 5 files changed, 127 insertions(+), 127 deletions(-) diff --git a/3rdparty/p256-m/p256-m_driver_entrypoints.c b/3rdparty/p256-m/p256-m_driver_entrypoints.c index 7709301b6..89b6ded93 100644 --- a/3rdparty/p256-m/p256-m_driver_entrypoints.c +++ b/3rdparty/p256-m/p256-m_driver_entrypoints.c @@ -22,7 +22,6 @@ #include "p256-m_driver_entrypoints.h" #include "p256-m/p256-m.h" #include "psa/crypto.h" -#include "psa_crypto_driver_wrappers.h" #include #include diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 3126379ee..19ac68c23 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -33,7 +33,7 @@ #include "psa_crypto_cipher.h" #include "psa_crypto_core.h" #include "psa_crypto_invasive.h" -#include "psa_crypto_driver_wrappers.h" +#include "psa_crypto_driver_wrappers.c" #include "psa_crypto_ecp.h" #include "psa_crypto_ffdh.h" #include "psa_crypto_hash.h" diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h index 0d20eaa66..c78403431 100644 --- a/library/psa_crypto_driver_wrappers.h +++ b/library/psa_crypto_driver_wrappers.h @@ -31,13 +31,13 @@ /* * Initialization and termination functions */ -psa_status_t psa_driver_wrapper_init(void); -void psa_driver_wrapper_free(void); +static inline psa_status_t psa_driver_wrapper_init(void); +static inline void psa_driver_wrapper_free(void); /* * Signature functions */ -psa_status_t psa_driver_wrapper_sign_message( +static inline psa_status_t psa_driver_wrapper_sign_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -48,7 +48,7 @@ psa_status_t psa_driver_wrapper_sign_message( size_t signature_size, size_t *signature_length); -psa_status_t psa_driver_wrapper_verify_message( +static inline psa_status_t psa_driver_wrapper_verify_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -58,13 +58,13 @@ psa_status_t psa_driver_wrapper_verify_message( const uint8_t *signature, size_t signature_length); -psa_status_t psa_driver_wrapper_sign_hash( +static inline psa_status_t psa_driver_wrapper_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, uint8_t *signature, size_t signature_size, size_t *signature_length); -psa_status_t psa_driver_wrapper_verify_hash( +static inline psa_status_t psa_driver_wrapper_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, @@ -74,79 +74,79 @@ psa_status_t psa_driver_wrapper_verify_hash( * Interruptible Signature functions */ -uint32_t psa_driver_wrapper_sign_hash_get_num_ops( +static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( psa_sign_hash_interruptible_operation_t *operation); -uint32_t psa_driver_wrapper_verify_hash_get_num_ops( +static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( psa_verify_hash_interruptible_operation_t *operation); -psa_status_t psa_driver_wrapper_sign_hash_start( +static inline psa_status_t psa_driver_wrapper_sign_hash_start( psa_sign_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length); -psa_status_t psa_driver_wrapper_sign_hash_complete( +static inline psa_status_t psa_driver_wrapper_sign_hash_complete( psa_sign_hash_interruptible_operation_t *operation, uint8_t *signature, size_t signature_size, size_t *signature_length); -psa_status_t psa_driver_wrapper_sign_hash_abort( +static inline psa_status_t psa_driver_wrapper_sign_hash_abort( psa_sign_hash_interruptible_operation_t *operation); -psa_status_t psa_driver_wrapper_verify_hash_start( +static inline psa_status_t psa_driver_wrapper_verify_hash_start( psa_verify_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length); -psa_status_t psa_driver_wrapper_verify_hash_complete( +static inline psa_status_t psa_driver_wrapper_verify_hash_complete( psa_verify_hash_interruptible_operation_t *operation); -psa_status_t psa_driver_wrapper_verify_hash_abort( +static inline psa_status_t psa_driver_wrapper_verify_hash_abort( psa_verify_hash_interruptible_operation_t *operation); /* * Key handling functions */ -psa_status_t psa_driver_wrapper_import_key( +static inline psa_status_t psa_driver_wrapper_import_key( const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length, size_t *bits); -psa_status_t psa_driver_wrapper_export_key( +static inline psa_status_t psa_driver_wrapper_export_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length); -psa_status_t psa_driver_wrapper_export_public_key( +static inline psa_status_t psa_driver_wrapper_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length); -psa_status_t psa_driver_wrapper_get_key_buffer_size( +static inline psa_status_t psa_driver_wrapper_get_key_buffer_size( const psa_key_attributes_t *attributes, size_t *key_buffer_size); -psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( +static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, size_t *key_buffer_size); -psa_status_t psa_driver_wrapper_generate_key( +static inline psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length); -psa_status_t psa_driver_wrapper_get_builtin_key( +static inline psa_status_t psa_driver_wrapper_get_builtin_key( psa_drv_slot_number_t slot_number, psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length); -psa_status_t psa_driver_wrapper_copy_key( +static inline psa_status_t psa_driver_wrapper_copy_key( psa_key_attributes_t *attributes, const uint8_t *source_key, size_t source_key_length, uint8_t *target_key_buffer, size_t target_key_buffer_size, @@ -154,7 +154,7 @@ psa_status_t psa_driver_wrapper_copy_key( /* * Cipher functions */ -psa_status_t psa_driver_wrapper_cipher_encrypt( +static inline psa_status_t psa_driver_wrapper_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -167,7 +167,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( size_t output_size, size_t *output_length); -psa_status_t psa_driver_wrapper_cipher_decrypt( +static inline psa_status_t psa_driver_wrapper_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -178,24 +178,24 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( size_t output_size, size_t *output_length); -psa_status_t psa_driver_wrapper_cipher_encrypt_setup( +static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg); -psa_status_t psa_driver_wrapper_cipher_decrypt_setup( +static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg); -psa_status_t psa_driver_wrapper_cipher_set_iv( +static inline psa_status_t psa_driver_wrapper_cipher_set_iv( psa_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length); -psa_status_t psa_driver_wrapper_cipher_update( +static inline psa_status_t psa_driver_wrapper_cipher_update( psa_cipher_operation_t *operation, const uint8_t *input, size_t input_length, @@ -203,19 +203,19 @@ psa_status_t psa_driver_wrapper_cipher_update( size_t output_size, size_t *output_length); -psa_status_t psa_driver_wrapper_cipher_finish( +static inline psa_status_t psa_driver_wrapper_cipher_finish( psa_cipher_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t psa_driver_wrapper_cipher_abort( +static inline psa_status_t psa_driver_wrapper_cipher_abort( psa_cipher_operation_t *operation); /* * Hashing functions */ -psa_status_t psa_driver_wrapper_hash_compute( +static inline psa_status_t psa_driver_wrapper_hash_compute( psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -223,33 +223,33 @@ psa_status_t psa_driver_wrapper_hash_compute( size_t hash_size, size_t *hash_length); -psa_status_t psa_driver_wrapper_hash_setup( +static inline psa_status_t psa_driver_wrapper_hash_setup( psa_hash_operation_t *operation, psa_algorithm_t alg); -psa_status_t psa_driver_wrapper_hash_clone( +static inline psa_status_t psa_driver_wrapper_hash_clone( const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation); -psa_status_t psa_driver_wrapper_hash_update( +static inline psa_status_t psa_driver_wrapper_hash_update( psa_hash_operation_t *operation, const uint8_t *input, size_t input_length); -psa_status_t psa_driver_wrapper_hash_finish( +static inline psa_status_t psa_driver_wrapper_hash_finish( psa_hash_operation_t *operation, uint8_t *hash, size_t hash_size, size_t *hash_length); -psa_status_t psa_driver_wrapper_hash_abort( +static inline psa_status_t psa_driver_wrapper_hash_abort( psa_hash_operation_t *operation); /* * AEAD functions */ -psa_status_t psa_driver_wrapper_aead_encrypt( +static inline psa_status_t psa_driver_wrapper_aead_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -258,7 +258,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt( const uint8_t *plaintext, size_t plaintext_length, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length); -psa_status_t psa_driver_wrapper_aead_decrypt( +static inline psa_status_t psa_driver_wrapper_aead_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -267,34 +267,34 @@ psa_status_t psa_driver_wrapper_aead_decrypt( const uint8_t *ciphertext, size_t ciphertext_length, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length); -psa_status_t psa_driver_wrapper_aead_encrypt_setup( +static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg); -psa_status_t psa_driver_wrapper_aead_decrypt_setup( +static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg); -psa_status_t psa_driver_wrapper_aead_set_nonce( +static inline psa_status_t psa_driver_wrapper_aead_set_nonce( psa_aead_operation_t *operation, const uint8_t *nonce, size_t nonce_length); -psa_status_t psa_driver_wrapper_aead_set_lengths( +static inline psa_status_t psa_driver_wrapper_aead_set_lengths( psa_aead_operation_t *operation, size_t ad_length, size_t plaintext_length); -psa_status_t psa_driver_wrapper_aead_update_ad( +static inline psa_status_t psa_driver_wrapper_aead_update_ad( psa_aead_operation_t *operation, const uint8_t *input, size_t input_length); -psa_status_t psa_driver_wrapper_aead_update( +static inline psa_status_t psa_driver_wrapper_aead_update( psa_aead_operation_t *operation, const uint8_t *input, size_t input_length, @@ -302,7 +302,7 @@ psa_status_t psa_driver_wrapper_aead_update( size_t output_size, size_t *output_length); -psa_status_t psa_driver_wrapper_aead_finish( +static inline psa_status_t psa_driver_wrapper_aead_finish( psa_aead_operation_t *operation, uint8_t *ciphertext, size_t ciphertext_size, @@ -311,7 +311,7 @@ psa_status_t psa_driver_wrapper_aead_finish( size_t tag_size, size_t *tag_length); -psa_status_t psa_driver_wrapper_aead_verify( +static inline psa_status_t psa_driver_wrapper_aead_verify( psa_aead_operation_t *operation, uint8_t *plaintext, size_t plaintext_size, @@ -319,13 +319,13 @@ psa_status_t psa_driver_wrapper_aead_verify( const uint8_t *tag, size_t tag_length); -psa_status_t psa_driver_wrapper_aead_abort( +static inline psa_status_t psa_driver_wrapper_aead_abort( psa_aead_operation_t *operation); /* * MAC functions */ -psa_status_t psa_driver_wrapper_mac_compute( +static inline psa_status_t psa_driver_wrapper_mac_compute( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -336,43 +336,43 @@ psa_status_t psa_driver_wrapper_mac_compute( size_t mac_size, size_t *mac_length); -psa_status_t psa_driver_wrapper_mac_sign_setup( +static inline psa_status_t psa_driver_wrapper_mac_sign_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg); -psa_status_t psa_driver_wrapper_mac_verify_setup( +static inline psa_status_t psa_driver_wrapper_mac_verify_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg); -psa_status_t psa_driver_wrapper_mac_update( +static inline psa_status_t psa_driver_wrapper_mac_update( psa_mac_operation_t *operation, const uint8_t *input, size_t input_length); -psa_status_t psa_driver_wrapper_mac_sign_finish( +static inline psa_status_t psa_driver_wrapper_mac_sign_finish( psa_mac_operation_t *operation, uint8_t *mac, size_t mac_size, size_t *mac_length); -psa_status_t psa_driver_wrapper_mac_verify_finish( +static inline psa_status_t psa_driver_wrapper_mac_verify_finish( psa_mac_operation_t *operation, const uint8_t *mac, size_t mac_length); -psa_status_t psa_driver_wrapper_mac_abort( +static inline psa_status_t psa_driver_wrapper_mac_abort( psa_mac_operation_t *operation); /* * Asymmetric cryptography */ -psa_status_t psa_driver_wrapper_asymmetric_encrypt( +static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -385,7 +385,7 @@ psa_status_t psa_driver_wrapper_asymmetric_encrypt( size_t output_size, size_t *output_length); -psa_status_t psa_driver_wrapper_asymmetric_decrypt( +static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -401,7 +401,7 @@ psa_status_t psa_driver_wrapper_asymmetric_decrypt( /* * Raw Key Agreement */ -psa_status_t psa_driver_wrapper_key_agreement( +static inline psa_status_t psa_driver_wrapper_key_agreement( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -415,29 +415,29 @@ psa_status_t psa_driver_wrapper_key_agreement( /* * PAKE functions. */ -psa_status_t psa_driver_wrapper_pake_setup( +static inline psa_status_t psa_driver_wrapper_pake_setup( psa_pake_operation_t *operation, const psa_crypto_driver_pake_inputs_t *inputs); -psa_status_t psa_driver_wrapper_pake_output( +static inline psa_status_t psa_driver_wrapper_pake_output( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t psa_driver_wrapper_pake_input( +static inline psa_status_t psa_driver_wrapper_pake_input( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, const uint8_t *input, size_t input_length); -psa_status_t psa_driver_wrapper_pake_get_implicit_key( +static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( psa_pake_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t psa_driver_wrapper_pake_abort( +static inline psa_status_t psa_driver_wrapper_pake_abort( psa_pake_operation_t *operation); #endif /* PSA_CRYPTO_DRIVER_WRAPPERS_H */ diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index ef285acb1..46daf1682 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -25,7 +25,7 @@ #include "psa/crypto.h" #include "psa_crypto_core.h" -#include "psa_crypto_driver_wrappers.h" +#include "psa_crypto_driver_wrappers.c" #include "psa_crypto_slot_management.h" #include "psa_crypto_storage.h" #if defined(MBEDTLS_PSA_CRYPTO_SE_C) diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja index 63540617d..1e0951b3d 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja @@ -82,7 +82,7 @@ #include "psa_crypto_se.h" #endif -psa_status_t psa_driver_wrapper_init( void ) +static inline psa_status_t psa_driver_wrapper_init( void ) { psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; @@ -106,7 +106,7 @@ psa_status_t psa_driver_wrapper_init( void ) return( PSA_SUCCESS ); } -void psa_driver_wrapper_free( void ) +static inline void psa_driver_wrapper_free( void ) { #if defined(MBEDTLS_PSA_CRYPTO_SE_C) /* Unregister all secure element drivers, so that we restart from @@ -121,7 +121,7 @@ void psa_driver_wrapper_free( void ) } /* Start delegation functions */ -psa_status_t psa_driver_wrapper_sign_message( +static inline psa_status_t psa_driver_wrapper_sign_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -196,7 +196,7 @@ psa_status_t psa_driver_wrapper_sign_message( signature_length ) ); } -psa_status_t psa_driver_wrapper_verify_message( +static inline psa_status_t psa_driver_wrapper_verify_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -267,7 +267,7 @@ psa_status_t psa_driver_wrapper_verify_message( signature_length ) ); } -psa_status_t psa_driver_wrapper_sign_hash( +static inline psa_status_t psa_driver_wrapper_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, @@ -371,7 +371,7 @@ psa_status_t psa_driver_wrapper_sign_hash( } } -psa_status_t psa_driver_wrapper_verify_hash( +static inline psa_status_t psa_driver_wrapper_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, @@ -472,7 +472,7 @@ psa_status_t psa_driver_wrapper_verify_hash( } } -uint32_t psa_driver_wrapper_sign_hash_get_num_ops( +static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( psa_sign_hash_interruptible_operation_t *operation ) { switch( operation->id ) @@ -495,7 +495,7 @@ uint32_t psa_driver_wrapper_sign_hash_get_num_ops( return( PSA_ERROR_INVALID_ARGUMENT ); } -uint32_t psa_driver_wrapper_verify_hash_get_num_ops( +static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( psa_verify_hash_interruptible_operation_t *operation ) { switch( operation->id ) @@ -519,7 +519,7 @@ uint32_t psa_driver_wrapper_verify_hash_get_num_ops( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_sign_hash_start( +static inline psa_status_t psa_driver_wrapper_sign_hash_start( psa_sign_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -572,7 +572,7 @@ psa_status_t psa_driver_wrapper_sign_hash_start( return( status ); } -psa_status_t psa_driver_wrapper_sign_hash_complete( +static inline psa_status_t psa_driver_wrapper_sign_hash_complete( psa_sign_hash_interruptible_operation_t *operation, uint8_t *signature, size_t signature_size, size_t *signature_length ) @@ -599,7 +599,7 @@ psa_status_t psa_driver_wrapper_sign_hash_complete( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_sign_hash_abort( +static inline psa_status_t psa_driver_wrapper_sign_hash_abort( psa_sign_hash_interruptible_operation_t *operation ) { switch( operation->id ) @@ -618,7 +618,7 @@ psa_status_t psa_driver_wrapper_sign_hash_abort( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_verify_hash_start( +static inline psa_status_t psa_driver_wrapper_verify_hash_start( psa_verify_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -676,7 +676,7 @@ psa_status_t psa_driver_wrapper_verify_hash_start( return( status ); } -psa_status_t psa_driver_wrapper_verify_hash_complete( +static inline psa_status_t psa_driver_wrapper_verify_hash_complete( psa_verify_hash_interruptible_operation_t *operation ) { switch( operation->id ) @@ -697,7 +697,7 @@ psa_status_t psa_driver_wrapper_verify_hash_complete( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_verify_hash_abort( +static inline psa_status_t psa_driver_wrapper_verify_hash_abort( psa_verify_hash_interruptible_operation_t *operation ) { switch( operation->id ) @@ -729,7 +729,7 @@ psa_status_t psa_driver_wrapper_verify_hash_abort( * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription */ -psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( +static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, @@ -773,7 +773,7 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( * \retval #PSA_ERROR_INVALID_ARGUMENT * The key is declared with a lifetime not known to us. */ -psa_status_t psa_driver_wrapper_get_key_buffer_size( +static inline psa_status_t psa_driver_wrapper_get_key_buffer_size( const psa_key_attributes_t *attributes, size_t *key_buffer_size ) { @@ -809,7 +809,7 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size( } } -psa_status_t psa_driver_wrapper_generate_key( +static inline psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) { @@ -895,7 +895,7 @@ psa_status_t psa_driver_wrapper_generate_key( return( status ); } -psa_status_t psa_driver_wrapper_import_key( +static inline psa_status_t psa_driver_wrapper_import_key( const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, @@ -976,7 +976,7 @@ bits {% endwith %} } -psa_status_t psa_driver_wrapper_export_key( +static inline psa_status_t psa_driver_wrapper_export_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length ) @@ -1038,7 +1038,7 @@ data_length {% endwith %} } -psa_status_t psa_driver_wrapper_export_public_key( +static inline psa_status_t psa_driver_wrapper_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length ) @@ -1108,7 +1108,7 @@ data_length {% endwith %} } -psa_status_t psa_driver_wrapper_get_builtin_key( +static inline psa_status_t psa_driver_wrapper_get_builtin_key( psa_drv_slot_number_t slot_number, psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) @@ -1139,7 +1139,7 @@ key_buffer_length {% endwith %} } -psa_status_t psa_driver_wrapper_copy_key( +static inline psa_status_t psa_driver_wrapper_copy_key( psa_key_attributes_t *attributes, const uint8_t *source_key, size_t source_key_length, uint8_t *target_key_buffer, size_t target_key_buffer_size, @@ -1191,7 +1191,7 @@ target_key_buffer_length /* * Cipher functions */ -psa_status_t psa_driver_wrapper_cipher_encrypt( +static inline psa_status_t psa_driver_wrapper_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1283,7 +1283,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( } } -psa_status_t psa_driver_wrapper_cipher_decrypt( +static inline psa_status_t psa_driver_wrapper_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1365,7 +1365,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( } } -psa_status_t psa_driver_wrapper_cipher_encrypt_setup( +static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1438,7 +1438,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( } } -psa_status_t psa_driver_wrapper_cipher_decrypt_setup( +static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1511,7 +1511,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( } } -psa_status_t psa_driver_wrapper_cipher_set_iv( +static inline psa_status_t psa_driver_wrapper_cipher_set_iv( psa_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length ) @@ -1546,7 +1546,7 @@ psa_status_t psa_driver_wrapper_cipher_set_iv( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_cipher_update( +static inline psa_status_t psa_driver_wrapper_cipher_update( psa_cipher_operation_t *operation, const uint8_t *input, size_t input_length, @@ -1592,7 +1592,7 @@ psa_status_t psa_driver_wrapper_cipher_update( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_cipher_finish( +static inline psa_status_t psa_driver_wrapper_cipher_finish( psa_cipher_operation_t *operation, uint8_t *output, size_t output_size, @@ -1630,7 +1630,7 @@ psa_status_t psa_driver_wrapper_cipher_finish( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_cipher_abort( +static inline psa_status_t psa_driver_wrapper_cipher_abort( psa_cipher_operation_t *operation ) { psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; @@ -1670,7 +1670,7 @@ psa_status_t psa_driver_wrapper_cipher_abort( /* * Hashing functions */ -psa_status_t psa_driver_wrapper_hash_compute( +static inline psa_status_t psa_driver_wrapper_hash_compute( psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1706,7 +1706,7 @@ psa_status_t psa_driver_wrapper_hash_compute( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t psa_driver_wrapper_hash_setup( +static inline psa_status_t psa_driver_wrapper_hash_setup( psa_hash_operation_t *operation, psa_algorithm_t alg ) { @@ -1739,7 +1739,7 @@ psa_status_t psa_driver_wrapper_hash_setup( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t psa_driver_wrapper_hash_clone( +static inline psa_status_t psa_driver_wrapper_hash_clone( const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation ) { @@ -1764,7 +1764,7 @@ psa_status_t psa_driver_wrapper_hash_clone( } } -psa_status_t psa_driver_wrapper_hash_update( +static inline psa_status_t psa_driver_wrapper_hash_update( psa_hash_operation_t *operation, const uint8_t *input, size_t input_length ) @@ -1789,7 +1789,7 @@ psa_status_t psa_driver_wrapper_hash_update( } } -psa_status_t psa_driver_wrapper_hash_finish( +static inline psa_status_t psa_driver_wrapper_hash_finish( psa_hash_operation_t *operation, uint8_t *hash, size_t hash_size, @@ -1816,7 +1816,7 @@ psa_status_t psa_driver_wrapper_hash_finish( } } -psa_status_t psa_driver_wrapper_hash_abort( +static inline psa_status_t psa_driver_wrapper_hash_abort( psa_hash_operation_t *operation ) { switch( operation->id ) @@ -1835,7 +1835,7 @@ psa_status_t psa_driver_wrapper_hash_abort( } } -psa_status_t psa_driver_wrapper_aead_encrypt( +static inline psa_status_t psa_driver_wrapper_aead_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -1887,7 +1887,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt( } } -psa_status_t psa_driver_wrapper_aead_decrypt( +static inline psa_status_t psa_driver_wrapper_aead_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -1939,7 +1939,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt( } } -psa_status_t psa_driver_wrapper_aead_encrypt_setup( +static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1987,7 +1987,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup( } } -psa_status_t psa_driver_wrapper_aead_decrypt_setup( +static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -2037,7 +2037,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup( } } -psa_status_t psa_driver_wrapper_aead_set_nonce( +static inline psa_status_t psa_driver_wrapper_aead_set_nonce( psa_aead_operation_t *operation, const uint8_t *nonce, size_t nonce_length ) @@ -2071,7 +2071,7 @@ psa_status_t psa_driver_wrapper_aead_set_nonce( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_aead_set_lengths( +static inline psa_status_t psa_driver_wrapper_aead_set_lengths( psa_aead_operation_t *operation, size_t ad_length, size_t plaintext_length ) @@ -2105,7 +2105,7 @@ psa_status_t psa_driver_wrapper_aead_set_lengths( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_aead_update_ad( +static inline psa_status_t psa_driver_wrapper_aead_update_ad( psa_aead_operation_t *operation, const uint8_t *input, size_t input_length ) @@ -2139,7 +2139,7 @@ psa_status_t psa_driver_wrapper_aead_update_ad( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_aead_update( +static inline psa_status_t psa_driver_wrapper_aead_update( psa_aead_operation_t *operation, const uint8_t *input, size_t input_length, @@ -2181,7 +2181,7 @@ psa_status_t psa_driver_wrapper_aead_update( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_aead_finish( +static inline psa_status_t psa_driver_wrapper_aead_finish( psa_aead_operation_t *operation, uint8_t *ciphertext, size_t ciphertext_size, @@ -2226,7 +2226,7 @@ psa_status_t psa_driver_wrapper_aead_finish( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_aead_verify( +static inline psa_status_t psa_driver_wrapper_aead_verify( psa_aead_operation_t *operation, uint8_t *plaintext, size_t plaintext_size, @@ -2289,7 +2289,7 @@ psa_status_t psa_driver_wrapper_aead_verify( return( PSA_ERROR_INVALID_ARGUMENT ); } -psa_status_t psa_driver_wrapper_aead_abort( +static inline psa_status_t psa_driver_wrapper_aead_abort( psa_aead_operation_t *operation ) { switch( operation->id ) @@ -2318,7 +2318,7 @@ psa_status_t psa_driver_wrapper_aead_abort( /* * MAC functions */ -psa_status_t psa_driver_wrapper_mac_compute( +static inline psa_status_t psa_driver_wrapper_mac_compute( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -2386,7 +2386,7 @@ psa_status_t psa_driver_wrapper_mac_compute( } } -psa_status_t psa_driver_wrapper_mac_sign_setup( +static inline psa_status_t psa_driver_wrapper_mac_sign_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -2458,7 +2458,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup( } } -psa_status_t psa_driver_wrapper_mac_verify_setup( +static inline psa_status_t psa_driver_wrapper_mac_verify_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -2530,7 +2530,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup( } } -psa_status_t psa_driver_wrapper_mac_update( +static inline psa_status_t psa_driver_wrapper_mac_update( psa_mac_operation_t *operation, const uint8_t *input, size_t input_length ) @@ -2563,7 +2563,7 @@ psa_status_t psa_driver_wrapper_mac_update( } } -psa_status_t psa_driver_wrapper_mac_sign_finish( +static inline psa_status_t psa_driver_wrapper_mac_sign_finish( psa_mac_operation_t *operation, uint8_t *mac, size_t mac_size, @@ -2598,7 +2598,7 @@ psa_status_t psa_driver_wrapper_mac_sign_finish( } } -psa_status_t psa_driver_wrapper_mac_verify_finish( +static inline psa_status_t psa_driver_wrapper_mac_verify_finish( psa_mac_operation_t *operation, const uint8_t *mac, size_t mac_length ) @@ -2631,7 +2631,7 @@ psa_status_t psa_driver_wrapper_mac_verify_finish( } } -psa_status_t psa_driver_wrapper_mac_abort( +static inline psa_status_t psa_driver_wrapper_mac_abort( psa_mac_operation_t *operation ) { switch( operation->id ) @@ -2659,7 +2659,7 @@ psa_status_t psa_driver_wrapper_mac_abort( /* * Asymmetric cryptography */ -psa_status_t psa_driver_wrapper_asymmetric_encrypt( +static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *salt, size_t salt_length, @@ -2717,7 +2717,7 @@ psa_status_t psa_driver_wrapper_asymmetric_encrypt( } } -psa_status_t psa_driver_wrapper_asymmetric_decrypt( +static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *salt, size_t salt_length, @@ -2775,7 +2775,7 @@ psa_status_t psa_driver_wrapper_asymmetric_decrypt( } } -psa_status_t psa_driver_wrapper_key_agreement( +static inline psa_status_t psa_driver_wrapper_key_agreement( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -2862,7 +2862,7 @@ psa_status_t psa_driver_wrapper_key_agreement( } } -psa_status_t psa_driver_wrapper_pake_setup( +static inline psa_status_t psa_driver_wrapper_pake_setup( psa_pake_operation_t *operation, const psa_crypto_driver_pake_inputs_t *inputs ) { @@ -2905,7 +2905,8 @@ psa_status_t psa_driver_wrapper_pake_setup( return( PSA_ERROR_INVALID_ARGUMENT ); } } -psa_status_t psa_driver_wrapper_pake_output( + +static inline psa_status_t psa_driver_wrapper_pake_output( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, uint8_t *output, @@ -2937,7 +2938,7 @@ psa_status_t psa_driver_wrapper_pake_output( } } -psa_status_t psa_driver_wrapper_pake_input( +static inline psa_status_t psa_driver_wrapper_pake_input( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, const uint8_t *input, @@ -2969,7 +2970,7 @@ psa_status_t psa_driver_wrapper_pake_input( } } -psa_status_t psa_driver_wrapper_pake_get_implicit_key( +static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( psa_pake_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length ) @@ -2998,7 +2999,7 @@ psa_status_t psa_driver_wrapper_pake_get_implicit_key( } } -psa_status_t psa_driver_wrapper_pake_abort( +static inline psa_status_t psa_driver_wrapper_pake_abort( psa_pake_operation_t * operation ) { switch( operation->id ) From b862031afabb286d4031c626b16a65885fc14553 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 25 Jul 2023 03:56:36 +0000 Subject: [PATCH 02/26] Remove useless declaration Signed-off-by: Xiaokang Qian --- library/psa_crypto_driver_wrappers.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h index c78403431..a8cb87e2e 100644 --- a/library/psa_crypto_driver_wrappers.h +++ b/library/psa_crypto_driver_wrappers.h @@ -28,12 +28,6 @@ #include "../3rdparty/p256-m/p256-m_driver_entrypoints.h" #endif /* MBEDTLS_PSA_P256M_DRIVER_ENABLED */ -/* - * Initialization and termination functions - */ -static inline psa_status_t psa_driver_wrapper_init(void); -static inline void psa_driver_wrapper_free(void); - /* * Signature functions */ From 5cb930ff8a8712caa1b0e0aa5c72ccc9e73b3624 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 25 Jul 2023 03:57:22 +0000 Subject: [PATCH 03/26] Surpress the unsed function warnings Signed-off-by: Xiaokang Qian --- .../psa_crypto_driver_wrappers.c.jinja | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja index 1e0951b3d..4e13fc53c 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja @@ -82,6 +82,7 @@ #include "psa_crypto_se.h" #endif +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_init( void ) { psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; @@ -106,6 +107,7 @@ static inline psa_status_t psa_driver_wrapper_init( void ) return( PSA_SUCCESS ); } +__attribute__((unused)) static inline void psa_driver_wrapper_free( void ) { #if defined(MBEDTLS_PSA_CRYPTO_SE_C) @@ -121,6 +123,7 @@ static inline void psa_driver_wrapper_free( void ) } /* Start delegation functions */ +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_sign_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -196,6 +199,7 @@ static inline psa_status_t psa_driver_wrapper_sign_message( signature_length ) ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_verify_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -267,6 +271,7 @@ static inline psa_status_t psa_driver_wrapper_verify_message( signature_length ) ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -371,6 +376,7 @@ static inline psa_status_t psa_driver_wrapper_sign_hash( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -472,6 +478,7 @@ static inline psa_status_t psa_driver_wrapper_verify_hash( } } +__attribute__((unused)) static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( psa_sign_hash_interruptible_operation_t *operation ) { @@ -495,6 +502,7 @@ static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( psa_verify_hash_interruptible_operation_t *operation ) { @@ -519,6 +527,7 @@ static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_sign_hash_start( psa_sign_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -572,6 +581,7 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_start( return( status ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_sign_hash_complete( psa_sign_hash_interruptible_operation_t *operation, uint8_t *signature, size_t signature_size, @@ -599,6 +609,7 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_complete( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_sign_hash_abort( psa_sign_hash_interruptible_operation_t *operation ) { @@ -618,6 +629,7 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_abort( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_verify_hash_start( psa_verify_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -676,6 +688,7 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_start( return( status ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_verify_hash_complete( psa_verify_hash_interruptible_operation_t *operation ) { @@ -697,6 +710,7 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_complete( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_verify_hash_abort( psa_verify_hash_interruptible_operation_t *operation ) { @@ -729,6 +743,7 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_abort( * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription */ + __attribute__((unused)) static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( const psa_key_attributes_t *attributes, const uint8_t *data, @@ -773,6 +788,7 @@ static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( * \retval #PSA_ERROR_INVALID_ARGUMENT * The key is declared with a lifetime not known to us. */ +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_get_key_buffer_size( const psa_key_attributes_t *attributes, size_t *key_buffer_size ) @@ -809,6 +825,7 @@ static inline psa_status_t psa_driver_wrapper_get_key_buffer_size( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) @@ -895,6 +912,7 @@ static inline psa_status_t psa_driver_wrapper_generate_key( return( status ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_import_key( const psa_key_attributes_t *attributes, const uint8_t *data, @@ -976,6 +994,7 @@ bits {% endwith %} } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_export_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1038,6 +1057,7 @@ data_length {% endwith %} } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1108,6 +1128,7 @@ data_length {% endwith %} } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_get_builtin_key( psa_drv_slot_number_t slot_number, psa_key_attributes_t *attributes, @@ -1139,6 +1160,7 @@ key_buffer_length {% endwith %} } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_copy_key( psa_key_attributes_t *attributes, const uint8_t *source_key, size_t source_key_length, @@ -1191,6 +1213,7 @@ target_key_buffer_length /* * Cipher functions */ +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -1283,6 +1306,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -1365,6 +1389,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1438,6 +1463,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1511,6 +1537,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_cipher_set_iv( psa_cipher_operation_t *operation, const uint8_t *iv, @@ -1546,6 +1573,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_set_iv( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_cipher_update( psa_cipher_operation_t *operation, const uint8_t *input, @@ -1592,6 +1620,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_update( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_cipher_finish( psa_cipher_operation_t *operation, uint8_t *output, @@ -1630,6 +1659,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_finish( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_cipher_abort( psa_cipher_operation_t *operation ) { @@ -1670,6 +1700,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_abort( /* * Hashing functions */ +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_hash_compute( psa_algorithm_t alg, const uint8_t *input, @@ -1706,6 +1737,7 @@ static inline psa_status_t psa_driver_wrapper_hash_compute( return( PSA_ERROR_NOT_SUPPORTED ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_hash_setup( psa_hash_operation_t *operation, psa_algorithm_t alg ) @@ -1739,6 +1771,7 @@ static inline psa_status_t psa_driver_wrapper_hash_setup( return( PSA_ERROR_NOT_SUPPORTED ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_hash_clone( const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation ) @@ -1764,6 +1797,7 @@ static inline psa_status_t psa_driver_wrapper_hash_clone( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_hash_update( psa_hash_operation_t *operation, const uint8_t *input, @@ -1789,6 +1823,7 @@ static inline psa_status_t psa_driver_wrapper_hash_update( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_hash_finish( psa_hash_operation_t *operation, uint8_t *hash, @@ -1816,6 +1851,7 @@ static inline psa_status_t psa_driver_wrapper_hash_finish( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_hash_abort( psa_hash_operation_t *operation ) { @@ -1835,6 +1871,7 @@ static inline psa_status_t psa_driver_wrapper_hash_abort( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1887,6 +1924,7 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1939,6 +1977,7 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1987,6 +2026,7 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, @@ -2037,6 +2077,7 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_set_nonce( psa_aead_operation_t *operation, const uint8_t *nonce, @@ -2071,6 +2112,7 @@ static inline psa_status_t psa_driver_wrapper_aead_set_nonce( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_set_lengths( psa_aead_operation_t *operation, size_t ad_length, @@ -2105,6 +2147,7 @@ static inline psa_status_t psa_driver_wrapper_aead_set_lengths( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_update_ad( psa_aead_operation_t *operation, const uint8_t *input, @@ -2139,6 +2182,7 @@ static inline psa_status_t psa_driver_wrapper_aead_update_ad( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_update( psa_aead_operation_t *operation, const uint8_t *input, @@ -2181,6 +2225,7 @@ static inline psa_status_t psa_driver_wrapper_aead_update( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_finish( psa_aead_operation_t *operation, uint8_t *ciphertext, @@ -2226,6 +2271,7 @@ static inline psa_status_t psa_driver_wrapper_aead_finish( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_verify( psa_aead_operation_t *operation, uint8_t *plaintext, @@ -2289,6 +2335,7 @@ static inline psa_status_t psa_driver_wrapper_aead_verify( return( PSA_ERROR_INVALID_ARGUMENT ); } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_aead_abort( psa_aead_operation_t *operation ) { @@ -2318,6 +2365,7 @@ static inline psa_status_t psa_driver_wrapper_aead_abort( /* * MAC functions */ +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_mac_compute( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -2386,6 +2434,7 @@ static inline psa_status_t psa_driver_wrapper_mac_compute( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_mac_sign_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, @@ -2458,6 +2507,7 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_setup( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_mac_verify_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, @@ -2530,6 +2580,7 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_setup( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_mac_update( psa_mac_operation_t *operation, const uint8_t *input, @@ -2563,6 +2614,7 @@ static inline psa_status_t psa_driver_wrapper_mac_update( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_mac_sign_finish( psa_mac_operation_t *operation, uint8_t *mac, @@ -2598,6 +2650,7 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_finish( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_mac_verify_finish( psa_mac_operation_t *operation, const uint8_t *mac, @@ -2631,6 +2684,7 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_finish( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_mac_abort( psa_mac_operation_t *operation ) { @@ -2659,6 +2713,7 @@ static inline psa_status_t psa_driver_wrapper_mac_abort( /* * Asymmetric cryptography */ +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, @@ -2717,6 +2772,7 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, @@ -2775,6 +2831,7 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_key_agreement( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -2862,6 +2919,7 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_pake_setup( psa_pake_operation_t *operation, const psa_crypto_driver_pake_inputs_t *inputs ) @@ -2906,6 +2964,7 @@ static inline psa_status_t psa_driver_wrapper_pake_setup( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_pake_output( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, @@ -2938,6 +2997,7 @@ static inline psa_status_t psa_driver_wrapper_pake_output( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_pake_input( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, @@ -2970,6 +3030,7 @@ static inline psa_status_t psa_driver_wrapper_pake_input( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( psa_pake_operation_t *operation, uint8_t *output, size_t output_size, @@ -2999,6 +3060,7 @@ static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( } } +__attribute__((unused)) static inline psa_status_t psa_driver_wrapper_pake_abort( psa_pake_operation_t * operation ) { From 077ffc09918f6c2b43b3338b10d3ff6f18685112 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 8 Aug 2023 03:41:07 +0000 Subject: [PATCH 04/26] Ensure build of P256 pass Signed-off-by: Xiaokang Qian --- 3rdparty/p256-m/p256-m_driver_entrypoints.c | 1 + library/psa_crypto_driver_wrappers.h | 2 +- .../driver_templates/psa_crypto_driver_wrappers.c.jinja | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/3rdparty/p256-m/p256-m_driver_entrypoints.c b/3rdparty/p256-m/p256-m_driver_entrypoints.c index 89b6ded93..dab8bed9e 100644 --- a/3rdparty/p256-m/p256-m_driver_entrypoints.c +++ b/3rdparty/p256-m/p256-m_driver_entrypoints.c @@ -24,6 +24,7 @@ #include "psa/crypto.h" #include #include +#include "psa_crypto_driver_wrappers.h" #if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED) diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h index a8cb87e2e..623cc667e 100644 --- a/library/psa_crypto_driver_wrappers.h +++ b/library/psa_crypto_driver_wrappers.h @@ -116,7 +116,7 @@ static inline psa_status_t psa_driver_wrapper_export_key( const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length); -static inline psa_status_t psa_driver_wrapper_export_public_key( +psa_status_t psa_driver_wrapper_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length); diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja index 4e13fc53c..337e16453 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja @@ -1057,8 +1057,7 @@ data_length {% endwith %} } -__attribute__((unused)) -static inline psa_status_t psa_driver_wrapper_export_public_key( +psa_status_t psa_driver_wrapper_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length ) From 5db65c72ec1db4cae8cdde43faf67d94f52f81bb Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Wed, 9 Aug 2023 08:47:51 +0000 Subject: [PATCH 05/26] Remove static inline functions declare and make it only in c file Signed-off-by: Xiaokang Qian --- library/psa_crypto_driver_wrappers.h | 399 --------------------------- 1 file changed, 399 deletions(-) diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h index 623cc667e..42b14b92c 100644 --- a/library/psa_crypto_driver_wrappers.h +++ b/library/psa_crypto_driver_wrappers.h @@ -28,411 +28,12 @@ #include "../3rdparty/p256-m/p256-m_driver_entrypoints.h" #endif /* MBEDTLS_PSA_P256M_DRIVER_ENABLED */ -/* - * Signature functions - */ -static inline psa_status_t psa_driver_wrapper_sign_message( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *input, - size_t input_length, - uint8_t *signature, - size_t signature_size, - size_t *signature_length); - -static inline psa_status_t psa_driver_wrapper_verify_message( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *input, - size_t input_length, - const uint8_t *signature, - size_t signature_length); - -static inline psa_status_t psa_driver_wrapper_sign_hash( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, - uint8_t *signature, size_t signature_size, size_t *signature_length); - -static inline psa_status_t psa_driver_wrapper_verify_hash( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, - const uint8_t *signature, size_t signature_length); - -/* - * Interruptible Signature functions - */ - -static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( - psa_sign_hash_interruptible_operation_t *operation); - -static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( - psa_verify_hash_interruptible_operation_t *operation); - -static inline psa_status_t psa_driver_wrapper_sign_hash_start( - psa_sign_hash_interruptible_operation_t *operation, - const psa_key_attributes_t *attributes, const uint8_t *key_buffer, - size_t key_buffer_size, psa_algorithm_t alg, - const uint8_t *hash, size_t hash_length); - -static inline psa_status_t psa_driver_wrapper_sign_hash_complete( - psa_sign_hash_interruptible_operation_t *operation, - uint8_t *signature, size_t signature_size, - size_t *signature_length); - -static inline psa_status_t psa_driver_wrapper_sign_hash_abort( - psa_sign_hash_interruptible_operation_t *operation); - -static inline psa_status_t psa_driver_wrapper_verify_hash_start( - psa_verify_hash_interruptible_operation_t *operation, - const psa_key_attributes_t *attributes, const uint8_t *key_buffer, - size_t key_buffer_size, psa_algorithm_t alg, - const uint8_t *hash, size_t hash_length, - const uint8_t *signature, size_t signature_length); - -static inline psa_status_t psa_driver_wrapper_verify_hash_complete( - psa_verify_hash_interruptible_operation_t *operation); - -static inline psa_status_t psa_driver_wrapper_verify_hash_abort( - psa_verify_hash_interruptible_operation_t *operation); - -/* - * Key handling functions - */ - -static inline psa_status_t psa_driver_wrapper_import_key( - const psa_key_attributes_t *attributes, - const uint8_t *data, size_t data_length, - uint8_t *key_buffer, size_t key_buffer_size, - size_t *key_buffer_length, size_t *bits); - -static inline psa_status_t psa_driver_wrapper_export_key( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - uint8_t *data, size_t data_size, size_t *data_length); psa_status_t psa_driver_wrapper_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length); -static inline psa_status_t psa_driver_wrapper_get_key_buffer_size( - const psa_key_attributes_t *attributes, - size_t *key_buffer_size); - -static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( - const psa_key_attributes_t *attributes, - const uint8_t *data, - size_t data_length, - size_t *key_buffer_size); - -static inline psa_status_t psa_driver_wrapper_generate_key( - const psa_key_attributes_t *attributes, - uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length); - -static inline psa_status_t psa_driver_wrapper_get_builtin_key( - psa_drv_slot_number_t slot_number, - psa_key_attributes_t *attributes, - uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length); - -static inline psa_status_t psa_driver_wrapper_copy_key( - psa_key_attributes_t *attributes, - const uint8_t *source_key, size_t source_key_length, - uint8_t *target_key_buffer, size_t target_key_buffer_size, - size_t *target_key_buffer_length); -/* - * Cipher functions - */ -static inline psa_status_t psa_driver_wrapper_cipher_encrypt( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *iv, - size_t iv_length, - const uint8_t *input, - size_t input_length, - uint8_t *output, - size_t output_size, - size_t *output_length); - -static inline psa_status_t psa_driver_wrapper_cipher_decrypt( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *input, - size_t input_length, - uint8_t *output, - size_t output_size, - size_t *output_length); - -static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( - psa_cipher_operation_t *operation, - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - psa_algorithm_t alg); - -static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( - psa_cipher_operation_t *operation, - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - psa_algorithm_t alg); - -static inline psa_status_t psa_driver_wrapper_cipher_set_iv( - psa_cipher_operation_t *operation, - const uint8_t *iv, - size_t iv_length); - -static inline psa_status_t psa_driver_wrapper_cipher_update( - psa_cipher_operation_t *operation, - const uint8_t *input, - size_t input_length, - uint8_t *output, - size_t output_size, - size_t *output_length); - -static inline psa_status_t psa_driver_wrapper_cipher_finish( - psa_cipher_operation_t *operation, - uint8_t *output, - size_t output_size, - size_t *output_length); - -static inline psa_status_t psa_driver_wrapper_cipher_abort( - psa_cipher_operation_t *operation); - -/* - * Hashing functions - */ -static inline psa_status_t psa_driver_wrapper_hash_compute( - psa_algorithm_t alg, - const uint8_t *input, - size_t input_length, - uint8_t *hash, - size_t hash_size, - size_t *hash_length); - -static inline psa_status_t psa_driver_wrapper_hash_setup( - psa_hash_operation_t *operation, - psa_algorithm_t alg); - -static inline psa_status_t psa_driver_wrapper_hash_clone( - const psa_hash_operation_t *source_operation, - psa_hash_operation_t *target_operation); - -static inline psa_status_t psa_driver_wrapper_hash_update( - psa_hash_operation_t *operation, - const uint8_t *input, - size_t input_length); - -static inline psa_status_t psa_driver_wrapper_hash_finish( - psa_hash_operation_t *operation, - uint8_t *hash, - size_t hash_size, - size_t *hash_length); - -static inline psa_status_t psa_driver_wrapper_hash_abort( - psa_hash_operation_t *operation); - -/* - * AEAD functions - */ - -static inline psa_status_t psa_driver_wrapper_aead_encrypt( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *nonce, size_t nonce_length, - const uint8_t *additional_data, size_t additional_data_length, - const uint8_t *plaintext, size_t plaintext_length, - uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length); - -static inline psa_status_t psa_driver_wrapper_aead_decrypt( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *nonce, size_t nonce_length, - const uint8_t *additional_data, size_t additional_data_length, - const uint8_t *ciphertext, size_t ciphertext_length, - uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length); - -static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( - psa_aead_operation_t *operation, - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - psa_algorithm_t alg); - -static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( - psa_aead_operation_t *operation, - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - psa_algorithm_t alg); - -static inline psa_status_t psa_driver_wrapper_aead_set_nonce( - psa_aead_operation_t *operation, - const uint8_t *nonce, - size_t nonce_length); - -static inline psa_status_t psa_driver_wrapper_aead_set_lengths( - psa_aead_operation_t *operation, - size_t ad_length, - size_t plaintext_length); - -static inline psa_status_t psa_driver_wrapper_aead_update_ad( - psa_aead_operation_t *operation, - const uint8_t *input, - size_t input_length); - -static inline psa_status_t psa_driver_wrapper_aead_update( - psa_aead_operation_t *operation, - const uint8_t *input, - size_t input_length, - uint8_t *output, - size_t output_size, - size_t *output_length); - -static inline psa_status_t psa_driver_wrapper_aead_finish( - psa_aead_operation_t *operation, - uint8_t *ciphertext, - size_t ciphertext_size, - size_t *ciphertext_length, - uint8_t *tag, - size_t tag_size, - size_t *tag_length); - -static inline psa_status_t psa_driver_wrapper_aead_verify( - psa_aead_operation_t *operation, - uint8_t *plaintext, - size_t plaintext_size, - size_t *plaintext_length, - const uint8_t *tag, - size_t tag_length); - -static inline psa_status_t psa_driver_wrapper_aead_abort( - psa_aead_operation_t *operation); - -/* - * MAC functions - */ -static inline psa_status_t psa_driver_wrapper_mac_compute( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *input, - size_t input_length, - uint8_t *mac, - size_t mac_size, - size_t *mac_length); - -static inline psa_status_t psa_driver_wrapper_mac_sign_setup( - psa_mac_operation_t *operation, - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg); - -static inline psa_status_t psa_driver_wrapper_mac_verify_setup( - psa_mac_operation_t *operation, - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg); - -static inline psa_status_t psa_driver_wrapper_mac_update( - psa_mac_operation_t *operation, - const uint8_t *input, - size_t input_length); - -static inline psa_status_t psa_driver_wrapper_mac_sign_finish( - psa_mac_operation_t *operation, - uint8_t *mac, - size_t mac_size, - size_t *mac_length); - -static inline psa_status_t psa_driver_wrapper_mac_verify_finish( - psa_mac_operation_t *operation, - const uint8_t *mac, - size_t mac_length); - -static inline psa_status_t psa_driver_wrapper_mac_abort( - psa_mac_operation_t *operation); - -/* - * Asymmetric cryptography - */ -static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *input, - size_t input_length, - const uint8_t *salt, - size_t salt_length, - uint8_t *output, - size_t output_size, - size_t *output_length); - -static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *input, - size_t input_length, - const uint8_t *salt, - size_t salt_length, - uint8_t *output, - size_t output_size, - size_t *output_length); - -/* - * Raw Key Agreement - */ -static inline psa_status_t psa_driver_wrapper_key_agreement( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, - size_t key_buffer_size, - psa_algorithm_t alg, - const uint8_t *peer_key, - size_t peer_key_length, - uint8_t *shared_secret, - size_t shared_secret_size, - size_t *shared_secret_length); - -/* - * PAKE functions. - */ -static inline psa_status_t psa_driver_wrapper_pake_setup( - psa_pake_operation_t *operation, - const psa_crypto_driver_pake_inputs_t *inputs); - -static inline psa_status_t psa_driver_wrapper_pake_output( - psa_pake_operation_t *operation, - psa_crypto_driver_pake_step_t step, - uint8_t *output, - size_t output_size, - size_t *output_length); - -static inline psa_status_t psa_driver_wrapper_pake_input( - psa_pake_operation_t *operation, - psa_crypto_driver_pake_step_t step, - const uint8_t *input, - size_t input_length); - -static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( - psa_pake_operation_t *operation, - uint8_t *output, size_t output_size, - size_t *output_length); - -static inline psa_status_t psa_driver_wrapper_pake_abort( - psa_pake_operation_t *operation); #endif /* PSA_CRYPTO_DRIVER_WRAPPERS_H */ From e518eeada917a957acb166bac66f6a908fd26bb5 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Wed, 9 Aug 2023 08:49:34 +0000 Subject: [PATCH 06/26] Move function psa_driver_wrapper_export_public_key out of auto-generated Signed-off-by: Xiaokang Qian --- .../psa_crypto_driver_wrappers_no_static.c | 165 ++++++++++++++++++ .../psa_crypto_driver_wrappers.c.jinja | 70 -------- 2 files changed, 165 insertions(+), 70 deletions(-) create mode 100644 library/psa_crypto_driver_wrappers_no_static.c diff --git a/library/psa_crypto_driver_wrappers_no_static.c b/library/psa_crypto_driver_wrappers_no_static.c new file mode 100644 index 000000000..18c1b4dbf --- /dev/null +++ b/library/psa_crypto_driver_wrappers_no_static.c @@ -0,0 +1,165 @@ +/* + * Functions to delegate cryptographic operations to an available + * and appropriate accelerator. + * Warning: This file is now auto-generated. + */ +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/* BEGIN-common headers */ +#include "common.h" +#include "psa_crypto_aead.h" +#include "psa_crypto_cipher.h" +#include "psa_crypto_core.h" +#include "psa_crypto_driver_wrappers.h" +#include "psa_crypto_hash.h" +#include "psa_crypto_mac.h" +#include "psa_crypto_pake.h" +#include "psa_crypto_rsa.h" + +#include "mbedtls/platform.h" +/* END-common headers */ + +#if defined(MBEDTLS_PSA_CRYPTO_C) + +/* BEGIN-driver headers */ +/* Headers for mbedtls_test opaque driver */ +#if defined(PSA_CRYPTO_DRIVER_TEST) +#include "test/drivers/test_driver.h" + +#endif +/* Headers for mbedtls_test transparent driver */ +#if defined(PSA_CRYPTO_DRIVER_TEST) +#include "test/drivers/test_driver.h" + +#endif + +/* END-driver headers */ + +/* Auto-generated values depending on which drivers are registered. + * ID 0 is reserved for unallocated operations. + * ID 1 is reserved for the Mbed TLS software driver. */ +/* BEGIN-driver id definition */ +#define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1) +#define MBEDTLS_TEST_OPAQUE_DRIVER_ID (2) +#define MBEDTLS_TEST_TRANSPARENT_DRIVER_ID (3) + +/* END-driver id */ + +/* BEGIN-Common Macro definitions */ + +/* END-Common Macro definitions */ + +/* Support the 'old' SE interface when asked to */ +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) +/* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style + * SE driver is present, to avoid unused argument errors at compile time. */ +#ifndef PSA_CRYPTO_DRIVER_PRESENT +#define PSA_CRYPTO_DRIVER_PRESENT +#endif +#include "psa_crypto_se.h" +#endif + + +psa_status_t psa_driver_wrapper_export_public_key( + const psa_key_attributes_t *attributes, + const uint8_t *key_buffer, size_t key_buffer_size, + uint8_t *data, size_t data_size, size_t *data_length ) + +{ + + psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; + psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( + psa_get_key_lifetime( attributes ) ); + + /* Try dynamically-registered SE interface first */ +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) + const psa_drv_se_t *drv; + psa_drv_se_context_t *drv_context; + + if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) + { + if( ( drv->key_management == NULL ) || + ( drv->key_management->p_export_public == NULL ) ) + { + return( PSA_ERROR_NOT_SUPPORTED ); + } + + return( drv->key_management->p_export_public( + drv_context, + *( (psa_key_slot_number_t *)key_buffer ), + data, data_size, data_length ) ); + } +#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ + + switch( location ) + { + case PSA_KEY_LOCATION_LOCAL_STORAGE: + /* Key is stored in the slot in export representation, so + * cycle through all known transparent accelerators */ +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) + +#if (defined(PSA_CRYPTO_DRIVER_TEST) ) + status = mbedtls_test_transparent_export_public_key + (attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length + ); + + if( status != PSA_ERROR_NOT_SUPPORTED ) + return( status ); +#endif + + +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ + /* Fell through, meaning no accelerator supports this operation */ + return( psa_export_public_key_internal( attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length ) ); + + /* Add cases for opaque driver here */ +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) + +#if (defined(PSA_CRYPTO_DRIVER_TEST) ) + case 0x7fffff: + return( mbedtls_test_opaque_export_public_key + (attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length + )); +#endif + + +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ + default: + /* Key is declared with a lifetime not known to us */ + return( status ); + } + +} + + +#endif /* MBEDTLS_PSA_CRYPTO_C */ diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja index 337e16453..39d69684e 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja @@ -1057,76 +1057,6 @@ data_length {% endwith %} } -psa_status_t psa_driver_wrapper_export_public_key( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - uint8_t *data, size_t data_size, size_t *data_length ) - -{ -{% with entry_point = "export_public_key" -%} -{% macro entry_point_param(driver) -%} -attributes, -key_buffer, -key_buffer_size, -data, -data_size, -data_length -{% endmacro %} - psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; - psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( - psa_get_key_lifetime( attributes ) ); - - /* Try dynamically-registered SE interface first */ -#if defined(MBEDTLS_PSA_CRYPTO_SE_C) - const psa_drv_se_t *drv; - psa_drv_se_context_t *drv_context; - - if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) - { - if( ( drv->key_management == NULL ) || - ( drv->key_management->p_export_public == NULL ) ) - { - return( PSA_ERROR_NOT_SUPPORTED ); - } - - return( drv->key_management->p_export_public( - drv_context, - *( (psa_key_slot_number_t *)key_buffer ), - data, data_size, data_length ) ); - } -#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ - - switch( location ) - { - case PSA_KEY_LOCATION_LOCAL_STORAGE: - /* Key is stored in the slot in export representation, so - * cycle through all known transparent accelerators */ -#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -{% with nest_indent=12 %} -{% include "OS-template-transparent.jinja" -%} -{% endwith -%} -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ - /* Fell through, meaning no accelerator supports this operation */ - return( psa_export_public_key_internal( attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length ) ); - - /* Add cases for opaque driver here */ -#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -{% with nest_indent=8 %} -{% include "OS-template-opaque.jinja" -%} -{% endwith -%} -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ - default: - /* Key is declared with a lifetime not known to us */ - return( status ); - } -{% endwith %} -} - __attribute__((unused)) static inline psa_status_t psa_driver_wrapper_get_builtin_key( psa_drv_slot_number_t slot_number, From e9c39c42fdccf12e6155f2696e5f013a9642ef35 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Wed, 9 Aug 2023 08:50:19 +0000 Subject: [PATCH 07/26] Enable build of non-static psa wrapper functions Signed-off-by: Xiaokang Qian --- library/CMakeLists.txt | 2 ++ library/Makefile | 1 + library/psa_crypto.c | 1 + 3 files changed, 4 insertions(+) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 62150779c..17154a427 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -68,6 +68,7 @@ set(src_crypto psa_crypto_cipher.c psa_crypto_client.c psa_crypto_driver_wrappers.c + psa_crypto_driver_wrappers_no_static.c psa_crypto_ecp.c psa_crypto_ffdh.c psa_crypto_hash.c @@ -190,6 +191,7 @@ else() link_to_source(version_features.c) link_to_source(ssl_debug_helpers_generated.c) link_to_source(psa_crypto_driver_wrappers.c) + link_to_source(psa_crypto_driver_wrappers_no_static.c) endif() if(CMAKE_COMPILER_IS_GNUCC) diff --git a/library/Makefile b/library/Makefile index c3d8615cb..3018c5bf4 100644 --- a/library/Makefile +++ b/library/Makefile @@ -137,6 +137,7 @@ OBJS_CRYPTO= \ psa_crypto_cipher.o \ psa_crypto_client.o \ psa_crypto_driver_wrappers.o \ + psa_crypto_driver_wrappers_no_static.o \ psa_crypto_ecp.o \ psa_crypto_ffdh.o \ psa_crypto_hash.o \ diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 19ac68c23..4d3399deb 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -34,6 +34,7 @@ #include "psa_crypto_core.h" #include "psa_crypto_invasive.h" #include "psa_crypto_driver_wrappers.c" +#include "psa_crypto_driver_wrappers.h" #include "psa_crypto_ecp.h" #include "psa_crypto_ffdh.h" #include "psa_crypto_hash.h" From b7cc2e2d3b7d2b0815adcf9413c9f46adbe1b5ad Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 15 Aug 2023 03:31:15 +0000 Subject: [PATCH 08/26] Disable unused warning on visual studio and generate files before lib Signed-off-by: Xiaokang Qian --- Makefile | 2 +- .../psa_crypto_driver_wrappers.c.jinja | 134 ++++++++++-------- 2 files changed, 74 insertions(+), 62 deletions(-) diff --git a/Makefile b/Makefile index 885948c11..650a97daa 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ no_test: programs programs: lib mbedtls_test $(MAKE) -C programs -lib: +lib: generated_files $(MAKE) -C library tests: lib mbedtls_test diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja index 39d69684e..d02bbc594 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja @@ -82,7 +82,15 @@ #include "psa_crypto_se.h" #endif -__attribute__((unused)) +#if defined(_MSC_VER) +#pragma warning( push ) +#pragma warning( disable : 4100) +#define UN_USED_DISABLE +#else +#define UN_USED_DISABLE __attribute__((unused)) +#endif + +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_init( void ) { psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; @@ -107,7 +115,7 @@ static inline psa_status_t psa_driver_wrapper_init( void ) return( PSA_SUCCESS ); } -__attribute__((unused)) +UN_USED_DISABLE static inline void psa_driver_wrapper_free( void ) { #if defined(MBEDTLS_PSA_CRYPTO_SE_C) @@ -123,7 +131,7 @@ static inline void psa_driver_wrapper_free( void ) } /* Start delegation functions */ -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -199,7 +207,7 @@ static inline psa_status_t psa_driver_wrapper_sign_message( signature_length ) ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -271,7 +279,7 @@ static inline psa_status_t psa_driver_wrapper_verify_message( signature_length ) ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -376,7 +384,7 @@ static inline psa_status_t psa_driver_wrapper_sign_hash( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -478,7 +486,7 @@ static inline psa_status_t psa_driver_wrapper_verify_hash( } } -__attribute__((unused)) +UN_USED_DISABLE static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( psa_sign_hash_interruptible_operation_t *operation ) { @@ -502,7 +510,7 @@ static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( psa_verify_hash_interruptible_operation_t *operation ) { @@ -527,7 +535,7 @@ static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_hash_start( psa_sign_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -581,7 +589,7 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_start( return( status ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_hash_complete( psa_sign_hash_interruptible_operation_t *operation, uint8_t *signature, size_t signature_size, @@ -609,7 +617,7 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_complete( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_hash_abort( psa_sign_hash_interruptible_operation_t *operation ) { @@ -629,7 +637,7 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_abort( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_hash_start( psa_verify_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -688,7 +696,7 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_start( return( status ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_hash_complete( psa_verify_hash_interruptible_operation_t *operation ) { @@ -710,7 +718,7 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_complete( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_hash_abort( psa_verify_hash_interruptible_operation_t *operation ) { @@ -743,7 +751,7 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_abort( * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription */ - __attribute__((unused)) + UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( const psa_key_attributes_t *attributes, const uint8_t *data, @@ -788,7 +796,7 @@ static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( * \retval #PSA_ERROR_INVALID_ARGUMENT * The key is declared with a lifetime not known to us. */ -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_get_key_buffer_size( const psa_key_attributes_t *attributes, size_t *key_buffer_size ) @@ -825,7 +833,7 @@ static inline psa_status_t psa_driver_wrapper_get_key_buffer_size( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) @@ -912,7 +920,7 @@ static inline psa_status_t psa_driver_wrapper_generate_key( return( status ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_import_key( const psa_key_attributes_t *attributes, const uint8_t *data, @@ -994,7 +1002,7 @@ bits {% endwith %} } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_export_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1057,7 +1065,7 @@ data_length {% endwith %} } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_get_builtin_key( psa_drv_slot_number_t slot_number, psa_key_attributes_t *attributes, @@ -1089,7 +1097,7 @@ key_buffer_length {% endwith %} } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_copy_key( psa_key_attributes_t *attributes, const uint8_t *source_key, size_t source_key_length, @@ -1142,7 +1150,7 @@ target_key_buffer_length /* * Cipher functions */ -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -1235,7 +1243,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -1318,7 +1326,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1392,7 +1400,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1466,7 +1474,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_set_iv( psa_cipher_operation_t *operation, const uint8_t *iv, @@ -1502,7 +1510,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_set_iv( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_update( psa_cipher_operation_t *operation, const uint8_t *input, @@ -1549,7 +1557,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_update( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_finish( psa_cipher_operation_t *operation, uint8_t *output, @@ -1588,7 +1596,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_finish( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_abort( psa_cipher_operation_t *operation ) { @@ -1629,7 +1637,7 @@ static inline psa_status_t psa_driver_wrapper_cipher_abort( /* * Hashing functions */ -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_compute( psa_algorithm_t alg, const uint8_t *input, @@ -1666,7 +1674,7 @@ static inline psa_status_t psa_driver_wrapper_hash_compute( return( PSA_ERROR_NOT_SUPPORTED ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_setup( psa_hash_operation_t *operation, psa_algorithm_t alg ) @@ -1700,7 +1708,7 @@ static inline psa_status_t psa_driver_wrapper_hash_setup( return( PSA_ERROR_NOT_SUPPORTED ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_clone( const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation ) @@ -1726,7 +1734,7 @@ static inline psa_status_t psa_driver_wrapper_hash_clone( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_update( psa_hash_operation_t *operation, const uint8_t *input, @@ -1752,7 +1760,7 @@ static inline psa_status_t psa_driver_wrapper_hash_update( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_finish( psa_hash_operation_t *operation, uint8_t *hash, @@ -1780,7 +1788,7 @@ static inline psa_status_t psa_driver_wrapper_hash_finish( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_abort( psa_hash_operation_t *operation ) { @@ -1800,7 +1808,7 @@ static inline psa_status_t psa_driver_wrapper_hash_abort( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1853,7 +1861,7 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1906,7 +1914,7 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1955,7 +1963,7 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, @@ -2006,7 +2014,7 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_set_nonce( psa_aead_operation_t *operation, const uint8_t *nonce, @@ -2041,7 +2049,7 @@ static inline psa_status_t psa_driver_wrapper_aead_set_nonce( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_set_lengths( psa_aead_operation_t *operation, size_t ad_length, @@ -2076,7 +2084,7 @@ static inline psa_status_t psa_driver_wrapper_aead_set_lengths( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_update_ad( psa_aead_operation_t *operation, const uint8_t *input, @@ -2111,7 +2119,7 @@ static inline psa_status_t psa_driver_wrapper_aead_update_ad( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_update( psa_aead_operation_t *operation, const uint8_t *input, @@ -2154,7 +2162,7 @@ static inline psa_status_t psa_driver_wrapper_aead_update( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_finish( psa_aead_operation_t *operation, uint8_t *ciphertext, @@ -2200,7 +2208,7 @@ static inline psa_status_t psa_driver_wrapper_aead_finish( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_verify( psa_aead_operation_t *operation, uint8_t *plaintext, @@ -2264,7 +2272,7 @@ static inline psa_status_t psa_driver_wrapper_aead_verify( return( PSA_ERROR_INVALID_ARGUMENT ); } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_abort( psa_aead_operation_t *operation ) { @@ -2294,7 +2302,7 @@ static inline psa_status_t psa_driver_wrapper_aead_abort( /* * MAC functions */ -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_compute( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -2363,7 +2371,7 @@ static inline psa_status_t psa_driver_wrapper_mac_compute( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_sign_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, @@ -2436,7 +2444,7 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_setup( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_verify_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, @@ -2509,7 +2517,7 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_setup( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_update( psa_mac_operation_t *operation, const uint8_t *input, @@ -2543,7 +2551,7 @@ static inline psa_status_t psa_driver_wrapper_mac_update( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_sign_finish( psa_mac_operation_t *operation, uint8_t *mac, @@ -2579,7 +2587,7 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_finish( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_verify_finish( psa_mac_operation_t *operation, const uint8_t *mac, @@ -2613,7 +2621,7 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_finish( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_abort( psa_mac_operation_t *operation ) { @@ -2642,7 +2650,7 @@ static inline psa_status_t psa_driver_wrapper_mac_abort( /* * Asymmetric cryptography */ -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, @@ -2701,7 +2709,7 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, @@ -2760,7 +2768,7 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_key_agreement( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -2848,7 +2856,7 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_setup( psa_pake_operation_t *operation, const psa_crypto_driver_pake_inputs_t *inputs ) @@ -2893,7 +2901,7 @@ static inline psa_status_t psa_driver_wrapper_pake_setup( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_output( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, @@ -2926,7 +2934,7 @@ static inline psa_status_t psa_driver_wrapper_pake_output( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_input( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, @@ -2959,7 +2967,7 @@ static inline psa_status_t psa_driver_wrapper_pake_input( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( psa_pake_operation_t *operation, uint8_t *output, size_t output_size, @@ -2989,7 +2997,7 @@ static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( } } -__attribute__((unused)) +UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_abort( psa_pake_operation_t * operation ) { @@ -3012,4 +3020,8 @@ static inline psa_status_t psa_driver_wrapper_pake_abort( } } +#if defined(_MSC_VER) +#pragma warning( pop ) +#endif + #endif /* MBEDTLS_PSA_CRYPTO_C */ From cad99fa998c2ab0225f3598c25466569ac401efc Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Fri, 1 Sep 2023 11:17:11 +0000 Subject: [PATCH 09/26] Change code style Signed-off-by: Xiaokang Qian --- .../psa_crypto_driver_wrappers_no_static.c | 79 +++++++++---------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/library/psa_crypto_driver_wrappers_no_static.c b/library/psa_crypto_driver_wrappers_no_static.c index 18c1b4dbf..22e679eb5 100644 --- a/library/psa_crypto_driver_wrappers_no_static.c +++ b/library/psa_crypto_driver_wrappers_no_static.c @@ -78,85 +78,80 @@ psa_status_t psa_driver_wrapper_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, - uint8_t *data, size_t data_size, size_t *data_length ) + uint8_t *data, size_t data_size, size_t *data_length) { psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( - psa_get_key_lifetime( attributes ) ); + psa_get_key_lifetime(attributes)); /* Try dynamically-registered SE interface first */ #if defined(MBEDTLS_PSA_CRYPTO_SE_C) const psa_drv_se_t *drv; psa_drv_se_context_t *drv_context; - if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) - { - if( ( drv->key_management == NULL ) || - ( drv->key_management->p_export_public == NULL ) ) - { - return( PSA_ERROR_NOT_SUPPORTED ); + if (psa_get_se_driver(attributes->core.lifetime, &drv, &drv_context)) { + if ((drv->key_management == NULL) || + (drv->key_management->p_export_public == NULL)) { + return PSA_ERROR_NOT_SUPPORTED; } - return( drv->key_management->p_export_public( - drv_context, - *( (psa_key_slot_number_t *)key_buffer ), - data, data_size, data_length ) ); + return drv->key_management->p_export_public( + drv_context, + *((psa_key_slot_number_t *) key_buffer), + data, data_size, data_length); } #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ - switch( location ) - { + switch (location) { case PSA_KEY_LOCATION_LOCAL_STORAGE: /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -#if (defined(PSA_CRYPTO_DRIVER_TEST) ) - status = mbedtls_test_transparent_export_public_key - (attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length - ); +#if (defined(PSA_CRYPTO_DRIVER_TEST)) + status = mbedtls_test_transparent_export_public_key( + attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length); - if( status != PSA_ERROR_NOT_SUPPORTED ) - return( status ); + if (status != PSA_ERROR_NOT_SUPPORTED) { + return status; + } #endif #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* Fell through, meaning no accelerator supports this operation */ - return( psa_export_public_key_internal( attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length ) ); + return psa_export_public_key_internal(attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length); - /* Add cases for opaque driver here */ + /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -#if (defined(PSA_CRYPTO_DRIVER_TEST) ) +#if (defined(PSA_CRYPTO_DRIVER_TEST)) case 0x7fffff: - return( mbedtls_test_opaque_export_public_key - (attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length - )); + return mbedtls_test_opaque_export_public_key(attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length); #endif #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: /* Key is declared with a lifetime not known to us */ - return( status ); + return status; } } From 9345b2e98f24c451242a3e6fa91c4cba56ab9c88 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Mon, 4 Sep 2023 10:57:55 +0000 Subject: [PATCH 10/26] Move functions out of the static file Move get_key_buf_size/get_builtin_key out of the psa wrapper auto generated file Slot_management.c include the head file instead of the source file Signed-off-by: Xiaokang Qian --- library/psa_crypto_driver_wrappers.h | 8 ++ .../psa_crypto_driver_wrappers_no_static.c | 81 ++++++++++++++++++ library/psa_crypto_slot_management.c | 2 +- .../psa_crypto_driver_wrappers.c.jinja | 84 ------------------- 4 files changed, 90 insertions(+), 85 deletions(-) diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h index 42b14b92c..0449ad02c 100644 --- a/library/psa_crypto_driver_wrappers.h +++ b/library/psa_crypto_driver_wrappers.h @@ -34,6 +34,14 @@ psa_status_t psa_driver_wrapper_export_public_key( const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length); +psa_status_t psa_driver_wrapper_get_key_buffer_size( + const psa_key_attributes_t *attributes, + size_t *key_buffer_size); + +psa_status_t psa_driver_wrapper_get_builtin_key( + psa_drv_slot_number_t slot_number, + psa_key_attributes_t *attributes, + uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length); #endif /* PSA_CRYPTO_DRIVER_WRAPPERS_H */ diff --git a/library/psa_crypto_driver_wrappers_no_static.c b/library/psa_crypto_driver_wrappers_no_static.c index 22e679eb5..b50017c14 100644 --- a/library/psa_crypto_driver_wrappers_no_static.c +++ b/library/psa_crypto_driver_wrappers_no_static.c @@ -156,5 +156,86 @@ psa_status_t psa_driver_wrapper_export_public_key( } +/** Get the key buffer size required to store the key material of a key + * associated with an opaque driver. + * + * \param[in] attributes The key attributes. + * \param[out] key_buffer_size Minimum buffer size to contain the key material + * + * \retval #PSA_SUCCESS + * The minimum size for a buffer to contain the key material has been + * returned successfully. + * \retval #PSA_ERROR_NOT_SUPPORTED + * The type and/or the size in bits of the key or the combination of + * the two is not supported. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The key is declared with a lifetime not known to us. + */ + +psa_status_t psa_driver_wrapper_get_key_buffer_size( + const psa_key_attributes_t *attributes, + size_t *key_buffer_size) +{ + psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->core.lifetime); + psa_key_type_t key_type = attributes->core.type; + size_t key_bits = attributes->core.bits; + + *key_buffer_size = 0; + switch (location) { +#if defined(PSA_CRYPTO_DRIVER_TEST) + case PSA_CRYPTO_TEST_DRIVER_LOCATION: +#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) + /* Emulate property 'builtin_key_size' */ + if (psa_key_id_is_builtin( + MBEDTLS_SVC_KEY_ID_GET_KEY_ID( + psa_get_key_id(attributes)))) { + *key_buffer_size = sizeof(psa_drv_slot_number_t); + return PSA_SUCCESS; + } +#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ + *key_buffer_size = mbedtls_test_opaque_size_function(key_type, + key_bits); + return (*key_buffer_size != 0) ? + PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED; +#endif /* PSA_CRYPTO_DRIVER_TEST */ + + default: + (void) key_type; + (void) key_bits; + return PSA_ERROR_INVALID_ARGUMENT; + } +} + +psa_status_t psa_driver_wrapper_get_builtin_key( + psa_drv_slot_number_t slot_number, + psa_key_attributes_t *attributes, + uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length) +{ + + psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->core.lifetime); + switch (location) { +#if defined(PSA_CRYPTO_DRIVER_TEST) + +#if (defined(PSA_CRYPTO_DRIVER_TEST)) + case 0x7fffff: + return mbedtls_test_opaque_get_builtin_key( + slot_number, + attributes, + key_buffer, + key_buffer_size, + key_buffer_length); +#endif + + +#endif /* PSA_CRYPTO_DRIVER_TEST */ + default: + (void) slot_number; + (void) key_buffer; + (void) key_buffer_size; + (void) key_buffer_length; + return PSA_ERROR_DOES_NOT_EXIST; + } + +} #endif /* MBEDTLS_PSA_CRYPTO_C */ diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index 46daf1682..ef285acb1 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -25,7 +25,7 @@ #include "psa/crypto.h" #include "psa_crypto_core.h" -#include "psa_crypto_driver_wrappers.c" +#include "psa_crypto_driver_wrappers.h" #include "psa_crypto_slot_management.h" #include "psa_crypto_storage.h" #if defined(MBEDTLS_PSA_CRYPTO_SE_C) diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja index d02bbc594..6af68ab78 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja @@ -781,58 +781,6 @@ static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( } } -/** Get the key buffer size required to store the key material of a key - * associated with an opaque driver. - * - * \param[in] attributes The key attributes. - * \param[out] key_buffer_size Minimum buffer size to contain the key material - * - * \retval #PSA_SUCCESS - * The minimum size for a buffer to contain the key material has been - * returned successfully. - * \retval #PSA_ERROR_NOT_SUPPORTED - * The type and/or the size in bits of the key or the combination of - * the two is not supported. - * \retval #PSA_ERROR_INVALID_ARGUMENT - * The key is declared with a lifetime not known to us. - */ -UN_USED_DISABLE -static inline psa_status_t psa_driver_wrapper_get_key_buffer_size( - const psa_key_attributes_t *attributes, - size_t *key_buffer_size ) -{ - psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); - psa_key_type_t key_type = attributes->core.type; - size_t key_bits = attributes->core.bits; - - *key_buffer_size = 0; - switch( location ) - { -#if defined(PSA_CRYPTO_DRIVER_TEST) - case PSA_CRYPTO_TEST_DRIVER_LOCATION: -#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) - /* Emulate property 'builtin_key_size' */ - if( psa_key_id_is_builtin( - MBEDTLS_SVC_KEY_ID_GET_KEY_ID( - psa_get_key_id( attributes ) ) ) ) - { - *key_buffer_size = sizeof( psa_drv_slot_number_t ); - return( PSA_SUCCESS ); - } -#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ - *key_buffer_size = mbedtls_test_opaque_size_function( key_type, - key_bits ); - return( ( *key_buffer_size != 0 ) ? - PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED ); -#endif /* PSA_CRYPTO_DRIVER_TEST */ - - default: - (void)key_type; - (void)key_bits; - return( PSA_ERROR_INVALID_ARGUMENT ); - } -} - UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attributes, @@ -1065,38 +1013,6 @@ data_length {% endwith %} } -UN_USED_DISABLE -static inline psa_status_t psa_driver_wrapper_get_builtin_key( - psa_drv_slot_number_t slot_number, - psa_key_attributes_t *attributes, - uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) -{ -{% with entry_point = "get_builtin_key" -%} -{% macro entry_point_param(driver) -%} -slot_number, -attributes, -key_buffer, -key_buffer_size, -key_buffer_length -{% endmacro %} - psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); - switch( location ) - { -#if defined(PSA_CRYPTO_DRIVER_TEST) -{% with nest_indent=8 %} -{% include "OS-template-opaque.jinja" -%} -{% endwith -%} -#endif /* PSA_CRYPTO_DRIVER_TEST */ - default: - (void) slot_number; - (void) key_buffer; - (void) key_buffer_size; - (void) key_buffer_length; - return( PSA_ERROR_DOES_NOT_EXIST ); - } -{% endwith %} -} - UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_copy_key( psa_key_attributes_t *attributes, From 42266dd670337a4d133033c82bc777a4672e0e7c Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 5 Sep 2023 10:54:26 +0000 Subject: [PATCH 11/26] Revert the Makefile to remove the dependency of generate_files Signed-off-by: Xiaokang Qian --- Makefile | 2 +- library/Makefile | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 650a97daa..885948c11 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ no_test: programs programs: lib mbedtls_test $(MAKE) -C programs -lib: generated_files +lib: $(MAKE) -C library tests: lib mbedtls_test diff --git a/library/Makefile b/library/Makefile index 3018c5bf4..a5abf821f 100644 --- a/library/Makefile +++ b/library/Makefile @@ -136,7 +136,6 @@ OBJS_CRYPTO= \ psa_crypto_aead.o \ psa_crypto_cipher.o \ psa_crypto_client.o \ - psa_crypto_driver_wrappers.o \ psa_crypto_driver_wrappers_no_static.o \ psa_crypto_ecp.o \ psa_crypto_ffdh.o \ @@ -209,6 +208,8 @@ else all: shared static endif +psa_crypto.o:psa_crypto_driver_wrappers.c + static: libmbedcrypto.a libmbedx509.a libmbedtls.a cd ../tests && echo "This is a seedfile that contains 64 bytes (65 on Windows)......" > seedfile From 4792b204a11649b9d100ea9889e14de93c6a85a4 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Thu, 7 Sep 2023 07:19:06 +0000 Subject: [PATCH 12/26] Revert 3rd party p-256 entry file Signed-off-by: Xiaokang Qian --- 3rdparty/p256-m/p256-m_driver_entrypoints.c | 1 + 1 file changed, 1 insertion(+) diff --git a/3rdparty/p256-m/p256-m_driver_entrypoints.c b/3rdparty/p256-m/p256-m_driver_entrypoints.c index dab8bed9e..f8eeb6767 100644 --- a/3rdparty/p256-m/p256-m_driver_entrypoints.c +++ b/3rdparty/p256-m/p256-m_driver_entrypoints.c @@ -25,6 +25,7 @@ #include #include #include "psa_crypto_driver_wrappers.h" +#include #if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED) From 97d1ccb7819cb851594664dc1394582e08f27527 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Thu, 7 Sep 2023 09:17:43 +0000 Subject: [PATCH 13/26] Dont't generate object file for file only include static functions Signed-off-by: Xiaokang Qian --- library/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 17154a427..865cacc83 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -67,7 +67,6 @@ set(src_crypto psa_crypto_aead.c psa_crypto_cipher.c psa_crypto_client.c - psa_crypto_driver_wrappers.c psa_crypto_driver_wrappers_no_static.c psa_crypto_ecp.c psa_crypto_ffdh.c @@ -190,7 +189,6 @@ else() link_to_source(error.c) link_to_source(version_features.c) link_to_source(ssl_debug_helpers_generated.c) - link_to_source(psa_crypto_driver_wrappers.c) link_to_source(psa_crypto_driver_wrappers_no_static.c) endif() From 54a4fdfe915e3996cc1437477fca39ebfc64b819 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Mon, 11 Sep 2023 02:39:27 +0000 Subject: [PATCH 14/26] Automaticly generate psa_crypto_driver_wrappers_no_static.c Signed-off-by: Xiaokang Qian --- library/Makefile | 11 +- ...a_crypto_driver_wrappers_no_static.c.jinja | 254 +++++++++--------- scripts/generate_driver_wrappers.py | 20 +- 3 files changed, 145 insertions(+), 140 deletions(-) rename library/psa_crypto_driver_wrappers_no_static.c => scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja (61%) diff --git a/library/Makefile b/library/Makefile index a5abf821f..3d5cdb83a 100644 --- a/library/Makefile +++ b/library/Makefile @@ -354,10 +354,13 @@ version_features.c: echo " Gen $@" $(PERL) ../scripts/generate_features.pl -psa_crypto_driver_wrappers.c: $(gen_file_dep) ../scripts/generate_driver_wrappers.py -psa_crypto_driver_wrappers.c: $(gen_file_dep) ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja -psa_crypto_driver_wrappers.c: - echo " Gen $@" +GENERATED_WRAPPER_FILES = \ + psa_crypto_driver_wrappers.c \ + psa_crypto_driver_wrappers_no_static.c +$(GENERATED_WRAPPER_FILES): ../scripts/generate_driver_wrappers.py +$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +$(GENERATED_WRAPPER_FILES): + echo " Gen $(GENERATED_WRAPPER_FILES)" $(PYTHON) ../scripts/generate_driver_wrappers.py clean: diff --git a/library/psa_crypto_driver_wrappers_no_static.c b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja similarity index 61% rename from library/psa_crypto_driver_wrappers_no_static.c rename to scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja index b50017c14..6c580167c 100644 --- a/library/psa_crypto_driver_wrappers_no_static.c +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja @@ -37,17 +37,18 @@ #if defined(MBEDTLS_PSA_CRYPTO_C) /* BEGIN-driver headers */ -/* Headers for mbedtls_test opaque driver */ -#if defined(PSA_CRYPTO_DRIVER_TEST) -#include "test/drivers/test_driver.h" - +{% for driver in drivers -%} +/* Headers for {{driver.prefix}} {{driver.type}} driver */ +{% if driver['mbedtls/h_condition'] is defined -%} +#if {{ driver['mbedtls/h_condition'] }} +{% endif -%} +{% for header in driver.headers -%} +#include "{{ header }}" +{% endfor %} +{% if driver['mbedtls/h_condition'] is defined -%} #endif -/* Headers for mbedtls_test transparent driver */ -#if defined(PSA_CRYPTO_DRIVER_TEST) -#include "test/drivers/test_driver.h" - -#endif - +{% endif -%} +{% endfor %} /* END-driver headers */ /* Auto-generated values depending on which drivers are registered. @@ -55,13 +56,19 @@ * ID 1 is reserved for the Mbed TLS software driver. */ /* BEGIN-driver id definition */ #define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1) -#define MBEDTLS_TEST_OPAQUE_DRIVER_ID (2) -#define MBEDTLS_TEST_TRANSPARENT_DRIVER_ID (3) - +{% for driver in drivers -%} +#define {{(driver.prefix + "_" + driver.type + "_driver_id").upper()}} ({{ loop.index + 1 }}) +{% endfor %} /* END-driver id */ /* BEGIN-Common Macro definitions */ - +{% macro entry_point_name(capability, entry_point, driver) -%} + {% if capability.name is defined and entry_point in capability.names.keys() -%} + {{ capability.names[entry_point]}} + {% else -%} + {{driver.prefix}}_{{driver.type}}_{{entry_point}} + {% endif -%} +{% endmacro %} /* END-Common Macro definitions */ /* Support the 'old' SE interface when asked to */ @@ -74,88 +81,6 @@ #include "psa_crypto_se.h" #endif - -psa_status_t psa_driver_wrapper_export_public_key( - const psa_key_attributes_t *attributes, - const uint8_t *key_buffer, size_t key_buffer_size, - uint8_t *data, size_t data_size, size_t *data_length) - -{ - - psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; - psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( - psa_get_key_lifetime(attributes)); - - /* Try dynamically-registered SE interface first */ -#if defined(MBEDTLS_PSA_CRYPTO_SE_C) - const psa_drv_se_t *drv; - psa_drv_se_context_t *drv_context; - - if (psa_get_se_driver(attributes->core.lifetime, &drv, &drv_context)) { - if ((drv->key_management == NULL) || - (drv->key_management->p_export_public == NULL)) { - return PSA_ERROR_NOT_SUPPORTED; - } - - return drv->key_management->p_export_public( - drv_context, - *((psa_key_slot_number_t *) key_buffer), - data, data_size, data_length); - } -#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ - - switch (location) { - case PSA_KEY_LOCATION_LOCAL_STORAGE: - /* Key is stored in the slot in export representation, so - * cycle through all known transparent accelerators */ -#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) - -#if (defined(PSA_CRYPTO_DRIVER_TEST)) - status = mbedtls_test_transparent_export_public_key( - attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length); - - if (status != PSA_ERROR_NOT_SUPPORTED) { - return status; - } -#endif - - -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ - /* Fell through, meaning no accelerator supports this operation */ - return psa_export_public_key_internal(attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length); - - /* Add cases for opaque driver here */ -#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) - -#if (defined(PSA_CRYPTO_DRIVER_TEST)) - case 0x7fffff: - return mbedtls_test_opaque_export_public_key(attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length); -#endif - - -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ - default: - /* Key is declared with a lifetime not known to us */ - return status; - } - -} - /** Get the key buffer size required to store the key material of a key * associated with an opaque driver. * @@ -171,71 +96,142 @@ psa_status_t psa_driver_wrapper_export_public_key( * \retval #PSA_ERROR_INVALID_ARGUMENT * The key is declared with a lifetime not known to us. */ - psa_status_t psa_driver_wrapper_get_key_buffer_size( const psa_key_attributes_t *attributes, - size_t *key_buffer_size) + size_t *key_buffer_size ) { - psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->core.lifetime); + psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); psa_key_type_t key_type = attributes->core.type; size_t key_bits = attributes->core.bits; *key_buffer_size = 0; - switch (location) { + switch( location ) + { #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: #if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) /* Emulate property 'builtin_key_size' */ - if (psa_key_id_is_builtin( + if( psa_key_id_is_builtin( MBEDTLS_SVC_KEY_ID_GET_KEY_ID( - psa_get_key_id(attributes)))) { - *key_buffer_size = sizeof(psa_drv_slot_number_t); - return PSA_SUCCESS; + psa_get_key_id( attributes ) ) ) ) + { + *key_buffer_size = sizeof( psa_drv_slot_number_t ); + return( PSA_SUCCESS ); } #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ - *key_buffer_size = mbedtls_test_opaque_size_function(key_type, - key_bits); - return (*key_buffer_size != 0) ? - PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED; + *key_buffer_size = mbedtls_test_opaque_size_function( key_type, + key_bits ); + return( ( *key_buffer_size != 0 ) ? + PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED ); #endif /* PSA_CRYPTO_DRIVER_TEST */ default: - (void) key_type; - (void) key_bits; - return PSA_ERROR_INVALID_ARGUMENT; + (void)key_type; + (void)key_bits; + return( PSA_ERROR_INVALID_ARGUMENT ); } } +psa_status_t psa_driver_wrapper_export_public_key( + const psa_key_attributes_t *attributes, + const uint8_t *key_buffer, size_t key_buffer_size, + uint8_t *data, size_t data_size, size_t *data_length ) + +{ +{% with entry_point = "export_public_key" -%} +{% macro entry_point_param(driver) -%} +attributes, +key_buffer, +key_buffer_size, +data, +data_size, +data_length +{% endmacro %} + psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; + psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( + psa_get_key_lifetime( attributes ) ); + + /* Try dynamically-registered SE interface first */ +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) + const psa_drv_se_t *drv; + psa_drv_se_context_t *drv_context; + + if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) + { + if( ( drv->key_management == NULL ) || + ( drv->key_management->p_export_public == NULL ) ) + { + return( PSA_ERROR_NOT_SUPPORTED ); + } + + return( drv->key_management->p_export_public( + drv_context, + *( (psa_key_slot_number_t *)key_buffer ), + data, data_size, data_length ) ); + } +#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ + + switch( location ) + { + case PSA_KEY_LOCATION_LOCAL_STORAGE: + /* Key is stored in the slot in export representation, so + * cycle through all known transparent accelerators */ +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) +{% with nest_indent=12 %} +{% include "OS-template-transparent.jinja" -%} +{% endwith -%} +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ + /* Fell through, meaning no accelerator supports this operation */ + return( psa_export_public_key_internal( attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length ) ); + + /* Add cases for opaque driver here */ +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) +{% with nest_indent=8 %} +{% include "OS-template-opaque.jinja" -%} +{% endwith -%} +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ + default: + /* Key is declared with a lifetime not known to us */ + return( status ); + } +{% endwith %} +} + psa_status_t psa_driver_wrapper_get_builtin_key( psa_drv_slot_number_t slot_number, psa_key_attributes_t *attributes, - uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length) + uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) { - - psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->core.lifetime); - switch (location) { +{% with entry_point = "get_builtin_key" -%} +{% macro entry_point_param(driver) -%} +slot_number, +attributes, +key_buffer, +key_buffer_size, +key_buffer_length +{% endmacro %} + psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); + switch( location ) + { #if defined(PSA_CRYPTO_DRIVER_TEST) - -#if (defined(PSA_CRYPTO_DRIVER_TEST)) - case 0x7fffff: - return mbedtls_test_opaque_get_builtin_key( - slot_number, - attributes, - key_buffer, - key_buffer_size, - key_buffer_length); -#endif - - +{% with nest_indent=8 %} +{% include "OS-template-opaque.jinja" -%} +{% endwith -%} #endif /* PSA_CRYPTO_DRIVER_TEST */ default: (void) slot_number; (void) key_buffer; (void) key_buffer_size; (void) key_buffer_length; - return PSA_ERROR_DOES_NOT_EXIST; + return( PSA_ERROR_DOES_NOT_EXIST ); } - +{% endwith %} } + #endif /* MBEDTLS_PSA_CRYPTO_C */ diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index e0c479350..5e2e5a9c0 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 -"""Generate library/psa_crypto_driver_wrappers.c +"""Generate library/psa_crypto_driver_wrappers.h + library/psa_crypto_driver_wrappers_no_static.c This module is invoked by the build scripts to auto generate the - psa_crypto_driver_wrappers.c based on template files in - script/data_files/driver_templates/. + psa_crypto_driver_wrappers.h and psa_crypto_driver_wrappers_no_static + based on template files in script/data_files/driver_templates/. """ # Copyright The Mbed TLS Contributors # SPDX-License-Identifier: Apache-2.0 @@ -59,19 +60,19 @@ def render(template_path: str, driver_jsoncontext: list) -> str: return template.render(drivers=driver_jsoncontext) - def generate_driver_wrapper_file(template_dir: str, output_dir: str, + template_file_name: str, driver_jsoncontext: list) -> None: """ Generate the file psa_crypto_driver_wrapper.c. """ driver_wrapper_template_filename = \ - os.path.join(template_dir, "psa_crypto_driver_wrappers.c.jinja") + os.path.join(template_dir, template_file_name) result = render(driver_wrapper_template_filename, driver_jsoncontext) - with open(file=os.path.join(output_dir, "psa_crypto_driver_wrappers.c"), + with open(file=os.path.join(output_dir, template_file_name.rsplit(".", 1)[0]), mode='w', encoding='UTF-8') as out_file: out_file.write(result) @@ -167,6 +168,9 @@ def trace_exception(e: Exception, file=sys.stderr) -> None: ), file) +TEMPLATE_FILENAMES = ["psa_crypto_driver_wrappers.c.jinja", + "psa_crypto_driver_wrappers_no_static.c.jinja"] + def main() -> int: """ Main with command line arguments. @@ -207,7 +211,9 @@ def main() -> int: except DriverReaderException as e: trace_exception(e) return 1 - generate_driver_wrapper_file(template_directory, output_directory, merged_driver_json) + for template_filename in TEMPLATE_FILENAMES: + generate_driver_wrapper_file(template_directory, output_directory, + template_filename, merged_driver_json) return 0 From fe9666b8c037a515281764c140b4aaf7c3174231 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Mon, 11 Sep 2023 10:36:20 +0000 Subject: [PATCH 15/26] Change the extension type of the file psa_crypto_driver_wrapper Signed-off-by: Xiaokang Qian --- 3rdparty/p256-m/p256-m_driver_entrypoints.c | 3 +-- library/CMakeLists.txt | 6 ++++-- library/Makefile | 10 ++++++---- library/psa_crypto.c | 2 +- ...appers.h => psa_crypto_driver_wrappers_no_static.h} | 0 library/psa_crypto_slot_management.c | 2 +- ...pers.c.jinja => psa_crypto_driver_wrappers.h.jinja} | 2 +- .../psa_crypto_driver_wrappers_no_static.c.jinja | 2 +- scripts/generate_driver_wrappers.py | 2 +- tests/scripts/check-generated-files.sh | 2 +- tests/scripts/check_names.py | 2 +- 11 files changed, 18 insertions(+), 15 deletions(-) rename library/{psa_crypto_driver_wrappers.h => psa_crypto_driver_wrappers_no_static.h} (100%) rename scripts/data_files/driver_templates/{psa_crypto_driver_wrappers.c.jinja => psa_crypto_driver_wrappers.h.jinja} (99%) diff --git a/3rdparty/p256-m/p256-m_driver_entrypoints.c b/3rdparty/p256-m/p256-m_driver_entrypoints.c index f8eeb6767..61310a87b 100644 --- a/3rdparty/p256-m/p256-m_driver_entrypoints.c +++ b/3rdparty/p256-m/p256-m_driver_entrypoints.c @@ -24,8 +24,7 @@ #include "psa/crypto.h" #include #include -#include "psa_crypto_driver_wrappers.h" -#include +#include "psa_crypto_driver_wrappers_no_static.h" #if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 865cacc83..65b957abf 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -174,14 +174,16 @@ if(GEN_FILES) add_custom_command( OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers.c + ${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers.h + ${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers_no_static.c COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_driver_wrappers.py ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_driver_wrappers.py - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja ) diff --git a/library/Makefile b/library/Makefile index 3d5cdb83a..15816385d 100644 --- a/library/Makefile +++ b/library/Makefile @@ -208,7 +208,7 @@ else all: shared static endif -psa_crypto.o:psa_crypto_driver_wrappers.c +psa_crypto.o:psa_crypto_driver_wrappers.h static: libmbedcrypto.a libmbedx509.a libmbedtls.a cd ../tests && echo "This is a seedfile that contains 64 bytes (65 on Windows)......" > seedfile @@ -318,7 +318,8 @@ libmbedcrypto.dll: $(OBJS_CRYPTO) GENERATED_FILES = \ error.c version_features.c \ ssl_debug_helpers_generated.c \ - psa_crypto_driver_wrappers.c + psa_crypto_driver_wrappers.h \ + psa_crypto_driver_wrappers_no_static.c generated_files: $(GENERATED_FILES) # See root Makefile @@ -355,10 +356,11 @@ version_features.c: $(PERL) ../scripts/generate_features.pl GENERATED_WRAPPER_FILES = \ - psa_crypto_driver_wrappers.c \ + psa_crypto_driver_wrappers.h \ psa_crypto_driver_wrappers_no_static.c $(GENERATED_WRAPPER_FILES): ../scripts/generate_driver_wrappers.py -$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja +$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja $(GENERATED_WRAPPER_FILES): echo " Gen $(GENERATED_WRAPPER_FILES)" $(PYTHON) ../scripts/generate_driver_wrappers.py diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 4d3399deb..9ad9c5c8c 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -33,8 +33,8 @@ #include "psa_crypto_cipher.h" #include "psa_crypto_core.h" #include "psa_crypto_invasive.h" -#include "psa_crypto_driver_wrappers.c" #include "psa_crypto_driver_wrappers.h" +#include "psa_crypto_driver_wrappers_no_static.h" #include "psa_crypto_ecp.h" #include "psa_crypto_ffdh.h" #include "psa_crypto_hash.h" diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers_no_static.h similarity index 100% rename from library/psa_crypto_driver_wrappers.h rename to library/psa_crypto_driver_wrappers_no_static.h diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index ef285acb1..92646c07c 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -25,7 +25,7 @@ #include "psa/crypto.h" #include "psa_crypto_core.h" -#include "psa_crypto_driver_wrappers.h" +#include "psa_crypto_driver_wrappers_no_static.h" #include "psa_crypto_slot_management.h" #include "psa_crypto_storage.h" #if defined(MBEDTLS_PSA_CRYPTO_SE_C) diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja similarity index 99% rename from scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja rename to scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja index 6af68ab78..a446d4ad1 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja @@ -25,7 +25,7 @@ #include "psa_crypto_aead.h" #include "psa_crypto_cipher.h" #include "psa_crypto_core.h" -#include "psa_crypto_driver_wrappers.h" +#include "psa_crypto_driver_wrappers_no_static.h" #include "psa_crypto_hash.h" #include "psa_crypto_mac.h" #include "psa_crypto_pake.h" diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja index 6c580167c..9e23a5da2 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja @@ -25,7 +25,7 @@ #include "psa_crypto_aead.h" #include "psa_crypto_cipher.h" #include "psa_crypto_core.h" -#include "psa_crypto_driver_wrappers.h" +#include "psa_crypto_driver_wrappers_no_static.h" #include "psa_crypto_hash.h" #include "psa_crypto_mac.h" #include "psa_crypto_pake.h" diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index 5e2e5a9c0..ba5c4c27a 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -168,7 +168,7 @@ def trace_exception(e: Exception, file=sys.stderr) -> None: ), file) -TEMPLATE_FILENAMES = ["psa_crypto_driver_wrappers.c.jinja", +TEMPLATE_FILENAMES = ["psa_crypto_driver_wrappers.h.jinja", "psa_crypto_driver_wrappers_no_static.c.jinja"] def main() -> int: diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index a1c37e9f1..9140b4c25 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -128,7 +128,7 @@ check() check scripts/generate_errors.pl library/error.c check scripts/generate_query_config.pl programs/test/query_config.c -check scripts/generate_driver_wrappers.py library/psa_crypto_driver_wrappers.c +check scripts/generate_driver_wrappers.py library/psa_crypto_driver_wrappers.h check scripts/generate_features.pl library/version_features.c check scripts/generate_ssl_debug_helpers.py library/ssl_debug_helpers_generated.c # generate_visualc_files enumerates source files (library/*.c). It doesn't diff --git a/tests/scripts/check_names.py b/tests/scripts/check_names.py index e6a38ba3e..f812929c7 100755 --- a/tests/scripts/check_names.py +++ b/tests/scripts/check_names.py @@ -284,7 +284,7 @@ class CodeParser(): "library/*.c", "3rdparty/everest/library/everest.c", "3rdparty/everest/library/x25519.c" - ], ["library/psa_crypto_driver_wrappers.c"]) + ], ["library/psa_crypto_driver_wrappers.h"]) symbols = self.parse_symbols() # Remove identifier macros like mbedtls_printf or mbedtls_calloc From 845693c5130c92ecdb9a6030b211941027930c8e Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 12 Sep 2023 03:14:54 +0000 Subject: [PATCH 16/26] Change comments to psa_crypto_driver_wrappers.h Signed-off-by: Xiaokang Qian --- docs/architecture/psa-crypto-implementation-structure.md | 2 +- include/psa/crypto_driver_contexts_composites.h | 2 +- include/psa/crypto_driver_contexts_primitives.h | 2 +- library/.gitignore | 3 ++- scripts/make_generated_files.bat | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/architecture/psa-crypto-implementation-structure.md b/docs/architecture/psa-crypto-implementation-structure.md index a5aac404c..80bac6e23 100644 --- a/docs/architecture/psa-crypto-implementation-structure.md +++ b/docs/architecture/psa-crypto-implementation-structure.md @@ -49,7 +49,7 @@ psa_status_t psa_api( ... ) ``` The code of most PSA APIs is expected to match precisely the above layout. However, it is likely that the code structure of some APIs will be more complicated with several calls to the driver interface, mainly to encompass a larger variety of hardware designs. For example, to encompass hardware accelerators that are capable of verifying a MAC and those that are only capable of computing a MAC, the psa_mac_verify() API could call first psa_driver_wrapper_mac_verify() and then fallback to psa_driver_wrapper_mac_compute(). -The implementations of `psa_driver_wrapper_` functions are generated by the build system based on the JSON driver description files of the various PSA drivers making up the Mbed TLS PSA Cryptography API implementation. The implementations are generated in a psa_crypto_driver_wrappers.c C file and the function prototypes declared in a psa_crypto_driver_wrappers.h header file. +The implementations of `psa_driver_wrapper_` functions are generated by the build system based on the JSON driver description files of the various PSA drivers making up the Mbed TLS PSA Cryptography API implementation. The implementations are generated in a psa_crypto_driver_wrappers.c C file and the function prototypes declared in a psa_crypto_driver_wrappers_no_static.h header file. The psa_driver_wrapper_() functions dispatch cryptographic operations to accelerator drivers, secure element drivers as well as to the software implementations of cryptographic operations. diff --git a/include/psa/crypto_driver_contexts_composites.h b/include/psa/crypto_driver_contexts_composites.h index 068a193bc..d0188647f 100644 --- a/include/psa/crypto_driver_contexts_composites.h +++ b/include/psa/crypto_driver_contexts_composites.h @@ -121,7 +121,7 @@ typedef mbedtls_psa_pake_operation_t * * The union members are the driver's context structures, and the member names * are formatted as `'drivername'_ctx`. This allows for procedural generation - * of both this file and the content of psa_crypto_driver_wrappers.c */ + * of both this file and the content of psa_crypto_driver_wrappers.h */ typedef union { unsigned dummy; /* Make sure this union is always non-empty */ diff --git a/include/psa/crypto_driver_contexts_primitives.h b/include/psa/crypto_driver_contexts_primitives.h index 7f81f6240..b27a768e8 100644 --- a/include/psa/crypto_driver_contexts_primitives.h +++ b/include/psa/crypto_driver_contexts_primitives.h @@ -94,7 +94,7 @@ typedef struct { * * The union members are the driver's context structures, and the member names * are formatted as `'drivername'_ctx`. This allows for procedural generation - * of both this file and the content of psa_crypto_driver_wrappers.c */ + * of both this file and the content of psa_crypto_driver_wrappers.h */ typedef union { unsigned dummy; /* Make sure this union is always non-empty */ diff --git a/library/.gitignore b/library/.gitignore index 5a29a43b7..c6a39f5c0 100644 --- a/library/.gitignore +++ b/library/.gitignore @@ -6,5 +6,6 @@ libmbed* /error.c /version_features.c /ssl_debug_helpers_generated.c -/psa_crypto_driver_wrappers.c +/psa_crypto_driver_wrappers.h +/psa_crypto_driver_wrappers_no_static.c ###END_GENERATED_FILES### diff --git a/scripts/make_generated_files.bat b/scripts/make_generated_files.bat index 9cf34f6fd..abcfc3945 100644 --- a/scripts/make_generated_files.bat +++ b/scripts/make_generated_files.bat @@ -1,7 +1,7 @@ @rem Generate automatically-generated configuration-independent source files @rem and build scripts. @rem Perl and Python 3 must be on the PATH. -@rem psa_crypto_driver_wrappers.c needs to be generated prior to +@rem psa_crypto_driver_wrappers.h needs to be generated prior to @rem generate_visualc_files.pl being invoked. python scripts\generate_driver_wrappers.py || exit /b 1 perl scripts\generate_errors.pl || exit /b 1 From 1b61d6e13f79e9725a0acae1f6b07bae5a6b72b5 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 12 Sep 2023 10:25:43 +0000 Subject: [PATCH 17/26] Change include guards of psa_crypto_driver_wrappers_no_static.h Signed-off-by: Xiaokang Qian --- library/psa_crypto_driver_wrappers_no_static.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/psa_crypto_driver_wrappers_no_static.h b/library/psa_crypto_driver_wrappers_no_static.h index 0449ad02c..4d2c73e00 100644 --- a/library/psa_crypto_driver_wrappers_no_static.h +++ b/library/psa_crypto_driver_wrappers_no_static.h @@ -18,8 +18,8 @@ * limitations under the License. */ -#ifndef PSA_CRYPTO_DRIVER_WRAPPERS_H -#define PSA_CRYPTO_DRIVER_WRAPPERS_H +#ifndef PSA_CRYPTO_DRIVER_WRAPPERS_NO_STATIC_H +#define PSA_CRYPTO_DRIVER_WRAPPERS_NO_STATIC_H #include "psa/crypto.h" #include "psa/crypto_driver_common.h" @@ -43,6 +43,6 @@ psa_status_t psa_driver_wrapper_get_builtin_key( psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length); -#endif /* PSA_CRYPTO_DRIVER_WRAPPERS_H */ +#endif /* PSA_CRYPTO_DRIVER_WRAPPERS_NO_STATIC_H */ /* End of automatically generated file. */ From 0e5b53c7e4e17a9796502c70ebd698b01ec1670a Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 12 Sep 2023 10:31:20 +0000 Subject: [PATCH 18/26] Move the dependency adjacent to the generated file Signed-off-by: Xiaokang Qian --- library/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Makefile b/library/Makefile index 15816385d..8a86a5595 100644 --- a/library/Makefile +++ b/library/Makefile @@ -208,8 +208,6 @@ else all: shared static endif -psa_crypto.o:psa_crypto_driver_wrappers.h - static: libmbedcrypto.a libmbedx509.a libmbedtls.a cd ../tests && echo "This is a seedfile that contains 64 bytes (65 on Windows)......" > seedfile @@ -365,6 +363,8 @@ $(GENERATED_WRAPPER_FILES): echo " Gen $(GENERATED_WRAPPER_FILES)" $(PYTHON) ../scripts/generate_driver_wrappers.py +psa_crypto.o:psa_crypto_driver_wrappers.h + clean: ifndef WINDOWS rm -f *.o libmbed* From 7d546c7c88f0e4e0a8dde947a64d6f702281e5a9 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 12 Sep 2023 10:45:55 +0000 Subject: [PATCH 19/26] Change to os.path functions base on comment Signed-off-by: Xiaokang Qian --- scripts/generate_driver_wrappers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index ba5c4c27a..e0f282792 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -72,7 +72,7 @@ def generate_driver_wrapper_file(template_dir: str, result = render(driver_wrapper_template_filename, driver_jsoncontext) - with open(file=os.path.join(output_dir, template_file_name.rsplit(".", 1)[0]), + with open(file=os.path.join(output_dir, os.path.splitext(template_file_name)[0]), mode='w', encoding='UTF-8') as out_file: out_file.write(result) From c23c351732776b85d9b7d24f24dd6299bd9a29f3 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Wed, 13 Sep 2023 10:05:30 +0000 Subject: [PATCH 20/26] Remove the UN_USED_DISABLE attribute Signed-off-by: Xiaokang Qian --- .../psa_crypto_driver_wrappers.h.jinja | 75 +------------------ 1 file changed, 2 insertions(+), 73 deletions(-) diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja index a446d4ad1..3d116b396 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja @@ -82,15 +82,6 @@ #include "psa_crypto_se.h" #endif -#if defined(_MSC_VER) -#pragma warning( push ) -#pragma warning( disable : 4100) -#define UN_USED_DISABLE -#else -#define UN_USED_DISABLE __attribute__((unused)) -#endif - -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_init( void ) { psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; @@ -115,7 +106,6 @@ static inline psa_status_t psa_driver_wrapper_init( void ) return( PSA_SUCCESS ); } -UN_USED_DISABLE static inline void psa_driver_wrapper_free( void ) { #if defined(MBEDTLS_PSA_CRYPTO_SE_C) @@ -131,7 +121,6 @@ static inline void psa_driver_wrapper_free( void ) } /* Start delegation functions */ -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -207,7 +196,6 @@ static inline psa_status_t psa_driver_wrapper_sign_message( signature_length ) ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_message( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -279,7 +267,6 @@ static inline psa_status_t psa_driver_wrapper_verify_message( signature_length ) ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -384,7 +371,6 @@ static inline psa_status_t psa_driver_wrapper_sign_hash( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -486,7 +472,6 @@ static inline psa_status_t psa_driver_wrapper_verify_hash( } } -UN_USED_DISABLE static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( psa_sign_hash_interruptible_operation_t *operation ) { @@ -510,7 +495,6 @@ static inline uint32_t psa_driver_wrapper_sign_hash_get_num_ops( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( psa_verify_hash_interruptible_operation_t *operation ) { @@ -535,7 +519,6 @@ static inline uint32_t psa_driver_wrapper_verify_hash_get_num_ops( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_hash_start( psa_sign_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -589,7 +572,6 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_start( return( status ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_hash_complete( psa_sign_hash_interruptible_operation_t *operation, uint8_t *signature, size_t signature_size, @@ -617,7 +599,6 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_complete( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_sign_hash_abort( psa_sign_hash_interruptible_operation_t *operation ) { @@ -637,7 +618,6 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_abort( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_hash_start( psa_verify_hash_interruptible_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -696,7 +676,6 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_start( return( status ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_hash_complete( psa_verify_hash_interruptible_operation_t *operation ) { @@ -718,7 +697,6 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_complete( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_verify_hash_abort( psa_verify_hash_interruptible_operation_t *operation ) { @@ -751,7 +729,6 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_abort( * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription */ - UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( const psa_key_attributes_t *attributes, const uint8_t *data, @@ -781,7 +758,6 @@ static inline psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) @@ -868,7 +844,6 @@ static inline psa_status_t psa_driver_wrapper_generate_key( return( status ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_import_key( const psa_key_attributes_t *attributes, const uint8_t *data, @@ -950,7 +925,6 @@ bits {% endwith %} } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_export_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1013,7 +987,6 @@ data_length {% endwith %} } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_copy_key( psa_key_attributes_t *attributes, const uint8_t *source_key, size_t source_key_length, @@ -1066,7 +1039,6 @@ target_key_buffer_length /* * Cipher functions */ -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -1159,7 +1131,6 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -1242,7 +1213,6 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1316,7 +1286,6 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( psa_cipher_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1390,7 +1359,6 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_set_iv( psa_cipher_operation_t *operation, const uint8_t *iv, @@ -1426,7 +1394,6 @@ static inline psa_status_t psa_driver_wrapper_cipher_set_iv( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_update( psa_cipher_operation_t *operation, const uint8_t *input, @@ -1473,7 +1440,6 @@ static inline psa_status_t psa_driver_wrapper_cipher_update( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_finish( psa_cipher_operation_t *operation, uint8_t *output, @@ -1512,7 +1478,6 @@ static inline psa_status_t psa_driver_wrapper_cipher_finish( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_cipher_abort( psa_cipher_operation_t *operation ) { @@ -1553,7 +1518,6 @@ static inline psa_status_t psa_driver_wrapper_cipher_abort( /* * Hashing functions */ -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_compute( psa_algorithm_t alg, const uint8_t *input, @@ -1590,7 +1554,6 @@ static inline psa_status_t psa_driver_wrapper_hash_compute( return( PSA_ERROR_NOT_SUPPORTED ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_setup( psa_hash_operation_t *operation, psa_algorithm_t alg ) @@ -1624,7 +1587,6 @@ static inline psa_status_t psa_driver_wrapper_hash_setup( return( PSA_ERROR_NOT_SUPPORTED ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_clone( const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation ) @@ -1650,7 +1612,6 @@ static inline psa_status_t psa_driver_wrapper_hash_clone( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_update( psa_hash_operation_t *operation, const uint8_t *input, @@ -1676,7 +1637,6 @@ static inline psa_status_t psa_driver_wrapper_hash_update( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_finish( psa_hash_operation_t *operation, uint8_t *hash, @@ -1704,7 +1664,6 @@ static inline psa_status_t psa_driver_wrapper_hash_finish( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_hash_abort( psa_hash_operation_t *operation ) { @@ -1724,7 +1683,6 @@ static inline psa_status_t psa_driver_wrapper_hash_abort( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1777,7 +1735,6 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, @@ -1830,7 +1787,6 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1879,7 +1835,6 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( psa_aead_operation_t *operation, const psa_key_attributes_t *attributes, @@ -1930,7 +1885,6 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_set_nonce( psa_aead_operation_t *operation, const uint8_t *nonce, @@ -1965,7 +1919,6 @@ static inline psa_status_t psa_driver_wrapper_aead_set_nonce( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_set_lengths( psa_aead_operation_t *operation, size_t ad_length, @@ -2000,7 +1953,6 @@ static inline psa_status_t psa_driver_wrapper_aead_set_lengths( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_update_ad( psa_aead_operation_t *operation, const uint8_t *input, @@ -2035,7 +1987,6 @@ static inline psa_status_t psa_driver_wrapper_aead_update_ad( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_update( psa_aead_operation_t *operation, const uint8_t *input, @@ -2078,7 +2029,6 @@ static inline psa_status_t psa_driver_wrapper_aead_update( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_finish( psa_aead_operation_t *operation, uint8_t *ciphertext, @@ -2124,7 +2074,6 @@ static inline psa_status_t psa_driver_wrapper_aead_finish( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_verify( psa_aead_operation_t *operation, uint8_t *plaintext, @@ -2188,7 +2137,6 @@ static inline psa_status_t psa_driver_wrapper_aead_verify( return( PSA_ERROR_INVALID_ARGUMENT ); } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_aead_abort( psa_aead_operation_t *operation ) { @@ -2218,7 +2166,6 @@ static inline psa_status_t psa_driver_wrapper_aead_abort( /* * MAC functions */ -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_compute( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -2287,7 +2234,6 @@ static inline psa_status_t psa_driver_wrapper_mac_compute( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_sign_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, @@ -2360,7 +2306,6 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_setup( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_verify_setup( psa_mac_operation_t *operation, const psa_key_attributes_t *attributes, @@ -2433,7 +2378,6 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_setup( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_update( psa_mac_operation_t *operation, const uint8_t *input, @@ -2467,7 +2411,6 @@ static inline psa_status_t psa_driver_wrapper_mac_update( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_sign_finish( psa_mac_operation_t *operation, uint8_t *mac, @@ -2503,7 +2446,6 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_finish( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_verify_finish( psa_mac_operation_t *operation, const uint8_t *mac, @@ -2537,7 +2479,6 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_finish( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_mac_abort( psa_mac_operation_t *operation ) { @@ -2566,7 +2507,6 @@ static inline psa_status_t psa_driver_wrapper_mac_abort( /* * Asymmetric cryptography */ -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, @@ -2625,7 +2565,6 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, @@ -2684,7 +2623,6 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_key_agreement( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, @@ -2696,7 +2634,7 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( size_t shared_secret_size, size_t *shared_secret_length ) - { +{ psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); @@ -2770,9 +2708,8 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( return( PSA_ERROR_NOT_SUPPORTED ); } - } +} -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_setup( psa_pake_operation_t *operation, const psa_crypto_driver_pake_inputs_t *inputs ) @@ -2817,7 +2754,6 @@ static inline psa_status_t psa_driver_wrapper_pake_setup( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_output( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, @@ -2850,7 +2786,6 @@ static inline psa_status_t psa_driver_wrapper_pake_output( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_input( psa_pake_operation_t *operation, psa_crypto_driver_pake_step_t step, @@ -2883,7 +2818,6 @@ static inline psa_status_t psa_driver_wrapper_pake_input( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( psa_pake_operation_t *operation, uint8_t *output, size_t output_size, @@ -2913,7 +2847,6 @@ static inline psa_status_t psa_driver_wrapper_pake_get_implicit_key( } } -UN_USED_DISABLE static inline psa_status_t psa_driver_wrapper_pake_abort( psa_pake_operation_t * operation ) { @@ -2936,8 +2869,4 @@ static inline psa_status_t psa_driver_wrapper_pake_abort( } } -#if defined(_MSC_VER) -#pragma warning( pop ) -#endif - #endif /* MBEDTLS_PSA_CRYPTO_C */ From 9e11126a1b9629ee7af543b37a23f10cceb80a63 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Wed, 13 Sep 2023 10:07:09 +0000 Subject: [PATCH 21/26] Remove useless empty line Signed-off-by: Xiaokang Qian --- .../psa_crypto_driver_wrappers_no_static.c.jinja | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja index 9e23a5da2..dbe424c03 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja @@ -233,5 +233,4 @@ key_buffer_length {% endwith %} } - #endif /* MBEDTLS_PSA_CRYPTO_C */ From b909aeafa3dd301d0bca7a8eacc497f7e289c73c Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Mon, 25 Sep 2023 03:26:57 +0000 Subject: [PATCH 22/26] Remove useless spaces in Makefile Signed-off-by: Xiaokang Qian --- library/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Makefile b/library/Makefile index 8a86a5595..a5b1ef02b 100644 --- a/library/Makefile +++ b/library/Makefile @@ -136,7 +136,7 @@ OBJS_CRYPTO= \ psa_crypto_aead.o \ psa_crypto_cipher.o \ psa_crypto_client.o \ - psa_crypto_driver_wrappers_no_static.o \ + psa_crypto_driver_wrappers_no_static.o \ psa_crypto_ecp.o \ psa_crypto_ffdh.o \ psa_crypto_hash.o \ @@ -316,7 +316,7 @@ libmbedcrypto.dll: $(OBJS_CRYPTO) GENERATED_FILES = \ error.c version_features.c \ ssl_debug_helpers_generated.c \ - psa_crypto_driver_wrappers.h \ + psa_crypto_driver_wrappers.h \ psa_crypto_driver_wrappers_no_static.c generated_files: $(GENERATED_FILES) From 1198e43644c9b1af50ce0cad12ae3ec991d69ce2 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Mon, 25 Sep 2023 07:02:49 +0000 Subject: [PATCH 23/26] Change the description of auto-generated driver dispatch files Signed-off-by: Xiaokang Qian --- docs/architecture/psa-crypto-implementation-structure.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture/psa-crypto-implementation-structure.md b/docs/architecture/psa-crypto-implementation-structure.md index 80bac6e23..905072aca 100644 --- a/docs/architecture/psa-crypto-implementation-structure.md +++ b/docs/architecture/psa-crypto-implementation-structure.md @@ -49,7 +49,7 @@ psa_status_t psa_api( ... ) ``` The code of most PSA APIs is expected to match precisely the above layout. However, it is likely that the code structure of some APIs will be more complicated with several calls to the driver interface, mainly to encompass a larger variety of hardware designs. For example, to encompass hardware accelerators that are capable of verifying a MAC and those that are only capable of computing a MAC, the psa_mac_verify() API could call first psa_driver_wrapper_mac_verify() and then fallback to psa_driver_wrapper_mac_compute(). -The implementations of `psa_driver_wrapper_` functions are generated by the build system based on the JSON driver description files of the various PSA drivers making up the Mbed TLS PSA Cryptography API implementation. The implementations are generated in a psa_crypto_driver_wrappers.c C file and the function prototypes declared in a psa_crypto_driver_wrappers_no_static.h header file. +The implementations of `psa_driver_wrapper_` functions are generated by the build system based on the JSON driver description files of the various PSA drivers making up the Mbed TLS PSA Cryptography API implementation. The implementations are splited into two parts. The static ones are generated in a psa_crypto_driver_wrappers.h head file, the non-static ones are generated in a psa_crypto_driver_wrappers_no_static.c C file and the function prototypes declared in a psa_crypto_driver_wrappers_no_static.h header file. The psa_driver_wrapper_() functions dispatch cryptographic operations to accelerator drivers, secure element drivers as well as to the software implementations of cryptographic operations. From e9dc63e069db546830e8185309e54a8db5ba4a88 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Mon, 25 Sep 2023 07:19:39 +0000 Subject: [PATCH 24/26] No need to include the 3rd party entry point head file Signed-off-by: Xiaokang Qian --- library/psa_crypto_driver_wrappers_no_static.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/library/psa_crypto_driver_wrappers_no_static.h b/library/psa_crypto_driver_wrappers_no_static.h index 4d2c73e00..4985403cd 100644 --- a/library/psa_crypto_driver_wrappers_no_static.h +++ b/library/psa_crypto_driver_wrappers_no_static.h @@ -24,11 +24,6 @@ #include "psa/crypto.h" #include "psa/crypto_driver_common.h" -#if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED) -#include "../3rdparty/p256-m/p256-m_driver_entrypoints.h" -#endif /* MBEDTLS_PSA_P256M_DRIVER_ENABLED */ - - psa_status_t psa_driver_wrapper_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, From 76e55a20dd5d12767eab9760ee90f06c57ea1071 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Mon, 25 Sep 2023 09:00:24 +0000 Subject: [PATCH 25/26] Change the documenti about psa_crypto_driver_wrappers.c{h} Signed-off-by: Xiaokang Qian --- .../psa-crypto-implementation-structure.md | 2 +- .../psa-driver-wrappers-codegen-migration-guide.md | 12 ++++++------ docs/psa-driver-example-and-guide.md | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/architecture/psa-crypto-implementation-structure.md b/docs/architecture/psa-crypto-implementation-structure.md index 905072aca..34faf3aa9 100644 --- a/docs/architecture/psa-crypto-implementation-structure.md +++ b/docs/architecture/psa-crypto-implementation-structure.md @@ -139,7 +139,7 @@ Some mechanisms require other mechanisms. For example, you can't do GCM without The general structure of a cryptographic operation function is: 1. API function defined in `library/psa_crypto.c`. The entry point performs generic checks that don't depend on whether the mechanism is implemented in software or in a driver and looks up keys in the key store. -2. Driver dispatch code in `scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja` or files included from there. +2. Driver dispatch code in `scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja`, `scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja` or files included from there. 3. Built-in implementation in `library/psa_crypto_*.c` (with function declarations in the corresponding `.h` file). These files typically contain the implementation of modes of operation over basic building blocks that are defined elsewhere. For example, HMAC is implemented in `library/psa_crypto_mac.c` but the underlying hash functions are implemented in `library/sha*.c` and `library/md*.c`. 4. Basic cryptographic building blocks in `library/*.c`. diff --git a/docs/proposed/psa-driver-wrappers-codegen-migration-guide.md b/docs/proposed/psa-driver-wrappers-codegen-migration-guide.md index 67157e5f7..8875921b2 100644 --- a/docs/proposed/psa-driver-wrappers-codegen-migration-guide.md +++ b/docs/proposed/psa-driver-wrappers-codegen-migration-guide.md @@ -1,7 +1,7 @@ -Migrating to an auto generated psa_crypto_driver_wrappers.c file +Migrating to an auto generated psa_crypto_driver_wrappers.h file ================================================================ -This document describes how to migrate to the auto generated psa_crypto_driver_wrappers.c file. +This document describes how to migrate to the auto generated psa_crypto_driver_wrappers.h file. It is meant to give the library user migration guidelines while the Mbed TLS project tides over multiple minor revs of version 1.0, after which this will be merged into psa-driver-interface.md. For a practical guide with a description of the current state of drivers Mbed TLS, see our [PSA Cryptoprocessor driver development examples](../psa-driver-example-and-guide.html). @@ -27,10 +27,10 @@ While that is the larger goal, for version 1.1 here's what's changed #### What's changed -(1) psa_crypto_driver_wrappers.c will from this point on be auto generated. -(2) The auto generation is based on the template file at **scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja**. -(3) The driver JSONS to be used for generating the psa_crypto_driver_wrappers.c file can be found at **scripts/data_files/driver_jsons/** as their default location, this path includes the schemas against which the driver schemas will be validated (driver_opaque_schema.json, driver_transparent_schema.json) and a driverlist.json which specifies the drivers to be considered and the order in which they want to be called into. The default location for driverlist.json and driver JSONS can be overloaded by passing an argument --json-dir while running the script generate_driver_wrappers.py. -(4) While the complete driver wrapper templating support is yet to come in, if the library user sees a need to patch psa_crypto_driver_wrappers.c file, the user will need to patch into the template file as needed (psa_crypto_driver_wrappers.c.jinja). +(1) psa_crypto_driver_wrappers.h will from this point on be auto generated. +(2) The auto generation is based on the template file at **scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja**. +(3) The driver JSONS to be used for generating the psa_crypto_driver_wrappers.h file can be found at **scripts/data_files/driver_jsons/** as their default location, this path includes the schemas against which the driver schemas will be validated (driver_opaque_schema.json, driver_transparent_schema.json) and a driverlist.json which specifies the drivers to be considered and the order in which they want to be called into. The default location for driverlist.json and driver JSONS can be overloaded by passing an argument --json-dir while running the script generate_driver_wrappers.py. +(4) While the complete driver wrapper templating support is yet to come in, if the library user sees a need to patch psa_crypto_driver_wrappers.h file, the user will need to patch into the template file as needed (psa_crypto_driver_wrappers.h.jinja). #### How to set your driver up diff --git a/docs/psa-driver-example-and-guide.md b/docs/psa-driver-example-and-guide.md index eb100d702..8bda60f93 100644 --- a/docs/psa-driver-example-and-guide.md +++ b/docs/psa-driver-example-and-guide.md @@ -74,7 +74,7 @@ Include any header files required by the driver in `psa_crypto_driver_wrappers.h **4. For each operation being accelerated, locate the function in the driver dispatch layer that corresponds to the entry point of that operation.** \ -The file `psa_crypto_driver_wrappers.c.jinja` contains the driver wrapper functions. For the entry points that have driver wrapper auto-generation implemented, the functions have been replaced with `jinja` templating logic. While the file has a `.jinja` extension, the driver wrapper functions for the remaining entry points are simple C functions. The names of these functions are of the form `psa_driver_wrapper` followed by the entry point name. So, for example, the function `psa_driver_wrapper_sign_hash()` corresponds to the `sign_hash` entry point. +The file `psa_crypto_driver_wrappers.h.jinja` and `psa_crypto_driver_wrappers_no_static.c.jinja` contains the driver wrapper functions. For the entry points that have driver wrapper auto-generation implemented, the functions have been replaced with `jinja` templating logic. While the file has a `.jinja` extension, the driver wrapper functions for the remaining entry points are simple C functions. The names of these functions are of the form `psa_driver_wrapper` followed by the entry point name. So, for example, the function `psa_driver_wrapper_sign_hash()` corresponds to the `sign_hash` entry point. **5. If a driver entry point function has been provided then ensure it has the same signature as the driver wrapper function.** \ If one has not been provided then write one. Its name should begin with the driver prefix, followed by transparent/opaque (depending on driver type), and end with the entry point name. It should have the same signature as the driver wrapper function. The purpose of the entry point function is to take arguments in PSA format for the implemented operation and return outputs/status codes in PSA format. \ @@ -153,7 +153,7 @@ The p256-m driver implements four entry points: `generate_key`, `key_agreement`, There are no entry points for `sign_message` and `verify_message`, which are not necessary for a sign-and-hash algorithm. The core still implements these functions by doing the hashes and then calling the sign/verify-hash entry points. The driver entry point functions can be found in `p256m_driver_entrypoints.[hc]`. These functions act as an interface between Mbed TLS and p256-m; converting between PSA and p256-m argument formats and performing sanity checks. If the driver's status codes differ from PSA's, it is recommended to implement a status code translation function. The function `p256_to_psa_error()` converts error codes returned by p256-m into PSA error codes. -The driver wrapper functions in `psa_crypto_driver_wrappers.c.jinja` for all four entry points have also been modified. The code block below shows the additions made to `psa_driver_wrapper_sign_hash()`. In adherence to the defined process, all code related to the driver call is placed within a check for `MBEDTLS_PSA_P256M_DRIVER_ENABLED`. p256-m only supports non-deterministic ECDSA using keys based on NIST P256; these constraints are enforced through checks (see the `if` statement). Checks that involve accessing key attributes, (e.g. checking key type or bits) **must** be performed in the driver wrapper. This is because this information is marked private and may not be accessed outside the library. Other checks can be performed here or in the entry point function. The status returned by the driver is propagated up the call hierarchy **unless** the driver does not support the operation (i.e. return `PSA_ERROR_NOT_SUPPORTED`). In that case the next available driver/built-in implementation is called. +The driver wrapper functions in `psa_crypto_driver_wrappers.h.jinja` for all four entry points have also been modified. The code block below shows the additions made to `psa_driver_wrapper_sign_hash()`. In adherence to the defined process, all code related to the driver call is placed within a check for `MBEDTLS_PSA_P256M_DRIVER_ENABLED`. p256-m only supports non-deterministic ECDSA using keys based on NIST P256; these constraints are enforced through checks (see the `if` statement). Checks that involve accessing key attributes, (e.g. checking key type or bits) **must** be performed in the driver wrapper. This is because this information is marked private and may not be accessed outside the library. Other checks can be performed here or in the entry point function. The status returned by the driver is propagated up the call hierarchy **unless** the driver does not support the operation (i.e. return `PSA_ERROR_NOT_SUPPORTED`). In that case the next available driver/built-in implementation is called. ``` #if defined (MBEDTLS_PSA_P256M_DRIVER_ENABLED) From db3035b8bc4e5fe95da51b45a492142d8e5a741e Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 26 Sep 2023 03:26:06 +0000 Subject: [PATCH 26/26] Fix a typo in psa-crypto-implementation-structure.md Signed-off-by: Xiaokang Qian --- docs/architecture/psa-crypto-implementation-structure.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture/psa-crypto-implementation-structure.md b/docs/architecture/psa-crypto-implementation-structure.md index 34faf3aa9..d7e4f9c48 100644 --- a/docs/architecture/psa-crypto-implementation-structure.md +++ b/docs/architecture/psa-crypto-implementation-structure.md @@ -49,7 +49,7 @@ psa_status_t psa_api( ... ) ``` The code of most PSA APIs is expected to match precisely the above layout. However, it is likely that the code structure of some APIs will be more complicated with several calls to the driver interface, mainly to encompass a larger variety of hardware designs. For example, to encompass hardware accelerators that are capable of verifying a MAC and those that are only capable of computing a MAC, the psa_mac_verify() API could call first psa_driver_wrapper_mac_verify() and then fallback to psa_driver_wrapper_mac_compute(). -The implementations of `psa_driver_wrapper_` functions are generated by the build system based on the JSON driver description files of the various PSA drivers making up the Mbed TLS PSA Cryptography API implementation. The implementations are splited into two parts. The static ones are generated in a psa_crypto_driver_wrappers.h head file, the non-static ones are generated in a psa_crypto_driver_wrappers_no_static.c C file and the function prototypes declared in a psa_crypto_driver_wrappers_no_static.h header file. +The implementations of `psa_driver_wrapper_` functions are generated by the build system based on the JSON driver description files of the various PSA drivers making up the Mbed TLS PSA Cryptography API implementation. The implementations are splited into two parts. The static ones are generated in a psa_crypto_driver_wrappers.h header file, the non-static ones are generated in a psa_crypto_driver_wrappers_no_static.c C file and the function prototypes declared in a psa_crypto_driver_wrappers_no_static.h header file. The psa_driver_wrapper_() functions dispatch cryptographic operations to accelerator drivers, secure element drivers as well as to the software implementations of cryptographic operations.