Merge pull request #248 from ARMmbed/dreemkiller_rename_driver

Various Changes for the PSA Driver Model
This commit is contained in:
Jaeden Amero 2019-03-06 18:59:46 +00:00 committed by GitHub
commit 03a60301d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 604 additions and 574 deletions

View file

@ -38,12 +38,13 @@
extern "C" { extern "C" {
#endif #endif
/** \defgroup driver_digest Message Digests /** \defgroup driver_digest Hardware-Accelerated Message Digests
* *
* Generation and authentication of Message Digests (aka hashes) must be done * Generation and authentication of Message Digests (aka hashes) must be done
* in parts using the following sequence: * in parts using the following sequence:
* - `psa_drv_hash_setup_t` * - `psa_drv_hash_setup_t`
* - `psa_drv_hash_update_t` * - `psa_drv_hash_update_t`
* - `psa_drv_hash_update_t`
* - ... * - ...
* - `psa_drv_hash_finish_t` * - `psa_drv_hash_finish_t`
* *
@ -64,7 +65,7 @@ typedef struct psa_drv_hash_context_s psa_drv_hash_context_t;
/** \brief The function prototype for the start operation of a hash (message /** \brief The function prototype for the start operation of a hash (message
* digest) operation * digest) operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_hash_<ALGO>_setup * psa_drv_hash_<ALGO>_setup
@ -81,7 +82,7 @@ typedef psa_status_t (*psa_drv_hash_setup_t)(psa_drv_hash_context_t *p_context);
/** \brief The function prototype for the update operation of a hash (message /** \brief The function prototype for the update operation of a hash (message
* digest) operation * digest) operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_hash_<ALGO>_update * psa_drv_hash_<ALGO>_update
@ -99,10 +100,10 @@ typedef psa_status_t (*psa_drv_hash_update_t)(psa_drv_hash_context_t *p_context,
const uint8_t *p_input, const uint8_t *p_input,
size_t input_length); size_t input_length);
/** \brief The prototype for the finish operation of a hash (message digest) /** \brief The function prototype for the finish operation of a hash (message
* operation * digest) operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_hash_<ALGO>_finish * psa_drv_hash_<ALGO>_finish
@ -130,7 +131,7 @@ typedef psa_status_t (*psa_drv_hash_finish_t)(psa_drv_hash_context_t *p_context,
/** \brief The function prototype for the abort operation of a hash (message /** \brief The function prototype for the abort operation of a hash (message
* digest) operation * digest) operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_hash_<ALGO>_abort * psa_drv_hash_<ALGO>_abort
@ -144,39 +145,39 @@ typedef void (*psa_drv_hash_abort_t)(psa_drv_hash_context_t *p_context);
/**@}*/ /**@}*/
/** \defgroup transparent_mac Transparent Message Authentication Code /** \defgroup accel_mac Hardware-Accelerated Message Authentication Code
* Generation and authentication of Message Authentication Codes (MACs) using * Generation and authentication of Message Authentication Codes (MACs) using
* transparent keys can be done either as a single function call (via the * cryptographic accelerators can be done either as a single function call (via the
* `psa_drv_mac_transparent_generate_t` or `psa_drv_mac_transparent_verify_t` * `psa_drv_accel_mac_generate_t` or `psa_drv_accel_mac_verify_t`
* functions), or in parts using the following sequence: * functions), or in parts using the following sequence:
* - `psa_drv_mac_transparent_setup_t` * - `psa_drv_accel_mac_setup_t`
* - `psa_drv_mac_transparent_update_t` * - `psa_drv_accel_mac_update_t`
* - `psa_drv_mac_transparent_update_t` * - `psa_drv_accel_mac_update_t`
* - ... * - ...
* - `psa_drv_mac_transparent_finish_t` or `psa_drv_mac_transparent_finish_verify_t` * - `psa_drv_accel_mac_finish_t` or `psa_drv_accel_mac_finish_verify_t`
* *
* If a previously started Transparent MAC operation needs to be terminated, it * If a previously started MAC operation needs to be terminated, it
* should be done so by the `psa_drv_mac_transparent_abort_t`. Failure to do so may * should be done so by the `psa_drv_accel_mac_abort_t`. Failure to do so may
* result in allocated resources not being freed or in other undefined * result in allocated resources not being freed or in other undefined
* behavior. * behavior.
* *
*/ */
/**@{*/ /**@{*/
/** \brief The hardware-specific transparent-key MAC context structure /** \brief The hardware-accelerator-specific MAC context structure
* *
* The contents of this structure are implementation dependent and are * The contents of this structure are implementation dependent and are
* therefore not described here. * therefore not described here.
*/ */
typedef struct psa_drv_mac_transparent_context_s psa_drv_mac_transparent_context_t; typedef struct psa_drv_accel_mac_context_s psa_drv_accel_mac_context_t;
/** \brief The function prototype for the setup operation of a /** \brief The function prototype for the setup operation of a
* transparent-key MAC operation * hardware-accelerated MAC operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_setup * psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_setup
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the underlying primitive, and `MAC_VARIANT` * Where `ALGO` is the name of the underlying primitive, and `MAC_VARIANT`
* is the specific variant of a MAC operation (such as HMAC or CMAC) * is the specific variant of a MAC operation (such as HMAC or CMAC)
@ -190,17 +191,17 @@ typedef struct psa_drv_mac_transparent_context_s psa_drv_mac_transparent_context
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
* Success. * Success.
*/ */
typedef psa_status_t (*psa_drv_mac_transparent_setup_t)(psa_drv_mac_transparent_context_t *p_context, typedef psa_status_t (*psa_drv_accel_mac_setup_t)(psa_drv_accel_mac_context_t *p_context,
const uint8_t *p_key, const uint8_t *p_key,
size_t key_length); size_t key_length);
/** \brief The function prototype for the update operation of a /** \brief The function prototype for the update operation of a
* transparent-key MAC operation * hardware-accelerated MAC operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_update * psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_update
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT`
* is the specific variant of a MAC operation (such as HMAC or CMAC) * is the specific variant of a MAC operation (such as HMAC or CMAC)
@ -212,17 +213,17 @@ typedef psa_status_t (*psa_drv_mac_transparent_setup_t)(psa_drv_mac_transparent_
* to the MAC operation * to the MAC operation
* \param[in] input_length The size in bytes of the input message buffer * \param[in] input_length The size in bytes of the input message buffer
*/ */
typedef psa_status_t (*psa_drv_mac_transparent_update_t)(psa_drv_mac_transparent_context_t *p_context, typedef psa_status_t (*psa_drv_accel_mac_update_t)(psa_drv_accel_mac_context_t *p_context,
const uint8_t *p_input, const uint8_t *p_input,
size_t input_length); size_t input_length);
/** \brief The function prototype for the finish operation of a /** \brief The function prototype for the finish operation of a
* transparent-key MAC operation * hardware-accelerated MAC operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish * psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_finish
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
* the specific variant of a MAC operation (such as HMAC or CMAC) * the specific variant of a MAC operation (such as HMAC or CMAC)
@ -237,17 +238,17 @@ typedef psa_status_t (*psa_drv_mac_transparent_update_t)(psa_drv_mac_transparent
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
* Success. * Success.
*/ */
typedef psa_status_t (*psa_drv_mac_transparent_finish_t)(psa_drv_mac_transparent_context_t *p_context, typedef psa_status_t (*psa_drv_accel_mac_finish_t)(psa_drv_accel_mac_context_t *p_context,
uint8_t *p_mac, uint8_t *p_mac,
size_t mac_length); size_t mac_length);
/** \brief The function prototype for the finish and verify operation of a /** \brief The function prototype for the finish and verify operation of a
* transparent-key MAC operation * hardware-accelerated MAC operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish_verify * psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_finish_verify
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
* the specific variant of a MAC operation (such as HMAC or CMAC) * the specific variant of a MAC operation (such as HMAC or CMAC)
@ -263,17 +264,17 @@ typedef psa_status_t (*psa_drv_mac_transparent_finish_t)(psa_drv_mac_transparent
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
* The operation completed successfully and the comparison matched * The operation completed successfully and the comparison matched
*/ */
typedef psa_status_t (*psa_drv_mac_transparent_finish_verify_t)(psa_drv_mac_transparent_context_t *p_context, typedef psa_status_t (*psa_drv_accel_mac_finish_verify_t)(psa_drv_accel_mac_context_t *p_context,
const uint8_t *p_mac, const uint8_t *p_mac,
size_t mac_length); size_t mac_length);
/** \brief The function prototype for the abort operation for a previously /** \brief The function prototype for the abort operation for a previously
* started transparent-key MAC operation * started hardware-accelerated MAC operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_abort * psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_abort
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
* the specific variant of a MAC operation (such as HMAC or CMAC) * the specific variant of a MAC operation (such as HMAC or CMAC)
@ -283,15 +284,15 @@ typedef psa_status_t (*psa_drv_mac_transparent_finish_verify_t)(psa_drv_mac_tran
* aborted * aborted
* *
*/ */
typedef psa_status_t (*psa_drv_mac_transparent_abort_t)(psa_drv_mac_transparent_context_t *p_context); typedef psa_status_t (*psa_drv_accel_mac_abort_t)(psa_drv_accel_mac_context_t *p_context);
/** \brief The function prototype for a one-shot operation of a transparent-key /** \brief The function prototype for the one-shot operation of a
* MAC operation * hardware-accelerated MAC operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT> * psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
* the specific variant of a MAC operation (such as HMAC or CMAC) * the specific variant of a MAC operation (such as HMAC or CMAC)
@ -306,21 +307,21 @@ typedef psa_status_t (*psa_drv_mac_transparent_abort_t)(psa_drv_mac_transparent_
* upon success * upon success
* \param[in] mac_length The length in bytes of the `p_mac` buffer * \param[in] mac_length The length in bytes of the `p_mac` buffer
*/ */
typedef psa_status_t (*psa_drv_mac_transparent_t)(const uint8_t *p_input, typedef psa_status_t (*psa_drv_accel_mac_t)(const uint8_t *p_input,
size_t input_length, size_t input_length,
const uint8_t *p_key, const uint8_t *p_key,
size_t key_length, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
uint8_t *p_mac, uint8_t *p_mac,
size_t mac_length); size_t mac_length);
/** \brief The function prototype for a one-shot operation of a transparent-key /** \brief The function prototype for the one-shot hardware-accelerated MAC
* MAC Verify operation * Verify operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_verify * psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_verify
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
* the specific variant of a MAC operation (such as HMAC or CMAC) * the specific variant of a MAC operation (such as HMAC or CMAC)
@ -337,51 +338,53 @@ typedef psa_status_t (*psa_drv_mac_transparent_t)(const uint8_t *p_input,
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
* The operation completed successfully and the comparison matched * The operation completed successfully and the comparison matched
*/ */
typedef psa_status_t (*psa_drv_mac_transparent_verify_t)(const uint8_t *p_input, typedef psa_status_t (*psa_drv_accel_mac_verify_t)(const uint8_t *p_input,
size_t input_length, size_t input_length,
const uint8_t *p_key, const uint8_t *p_key,
size_t key_length, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *p_mac, const uint8_t *p_mac,
size_t mac_length); size_t mac_length);
/**@}*/ /**@}*/
/** \defgroup transparent_cipher Transparent Block Cipher /** \defgroup accel_cipher Hardware-Accelerated Block Ciphers
* Encryption and Decryption using transparent keys in block modes other than * Encryption and Decryption using hardware-acceleration in block modes other
* ECB must be done in multiple parts, using the following flow: * than ECB must be done in multiple parts, using the following flow:
* - `psa_drv_cipher_transparent_setup_t` * - `psa_drv_accel_ciphersetup_t`
* - `psa_drv_cipher_transparent_set_iv_t` (optional depending upon block mode) * - `psa_drv_accel_cipher_set_iv_t` (optional depending upon block mode)
* - `psa_drv_cipher_transparent_update_t` * - `psa_drv_accel_cipher_update_t`
* - `psa_drv_accel_cipher_update_t`
* - ... * - ...
* - `psa_drv_cipher_transparent_finish_t` * - `psa_drv_accel_cipher_finish_t`
*
* If a previously started Transparent Cipher operation needs to be terminated, * If a previously started hardware-accelerated Cipher operation needs to be
* it should be done so by the `psa_drv_cipher_transparent_abort_t`. Failure to do * terminated, it should be done so by the `psa_drv_accel_cipher_abort_t`.
* so may result in allocated resources not being freed or in other undefined * Failure to do so may result in allocated resources not being freed or in
* behavior. * other undefined behavior.
*/ */
/**@{*/ /**@{*/
/** \brief The hardware-specific transparent-key Cipher context structure /** \brief The hardware-accelerator-specific cipher context structure
* *
* The contents of this structure are implementation dependent and are * The contents of this structure are implementation dependent and are
* therefore not described here. * therefore not described here.
*/ */
typedef struct psa_drv_cipher_transparent_context_s psa_drv_cipher_transparent_context_t; typedef struct psa_drv_accel_cipher_context_s psa_drv_accel_cipher_context_t;
/** \brief The function prototype for the setup operation of transparent-key /** \brief The function prototype for the setup operation of
* block cipher operations. * hardware-accelerated block cipher operations.
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* conventions: * conventions:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_cipher_transparent_setup_<CIPHER_NAME>_<MODE> * psa_drv_accel_cipher_setup_<CIPHER_NAME>_<MODE>
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where * Where
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
* - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
* or for stream ciphers: *
* For stream ciphers:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_cipher_transparent_setup_<CIPHER_NAME> * psa_drv_accel_cipher_setup_<CIPHER_NAME>
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `CIPHER_NAME` is the name of a stream cipher (i.e. RC4) * Where `CIPHER_NAME` is the name of a stream cipher (i.e. RC4)
* *
@ -395,17 +398,17 @@ typedef struct psa_drv_cipher_transparent_context_s psa_drv_cipher_transparent_c
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_cipher_transparent_setup_t)(psa_drv_cipher_transparent_context_t *p_context, typedef psa_status_t (*psa_drv_accel_cipher_setup_t)(psa_drv_accel_cipher_context_t *p_context,
psa_encrypt_or_decrypt_t direction, psa_encrypt_or_decrypt_t direction,
const uint8_t *p_key_data, const uint8_t *p_key_data,
size_t key_data_size); size_t key_data_size);
/** \brief The function prototype for the set initialization vector operation /** \brief The function prototype for the set initialization vector operation
* of transparent-key block cipher operations * of hardware-accelerated block cipher operations
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_cipher_transparent_set_iv_<CIPHER_NAME>_<MODE> * psa_drv_accel_cipher_set_iv_<CIPHER_NAME>_<MODE>
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where * Where
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
@ -418,17 +421,17 @@ typedef psa_status_t (*psa_drv_cipher_transparent_setup_t)(psa_drv_cipher_transp
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_cipher_transparent_set_iv_t)(psa_drv_cipher_transparent_context_t *p_context, typedef psa_status_t (*psa_drv_accel_cipher_set_iv_t)(psa_drv_accel_cipher_context_t *p_context,
const uint8_t *p_iv, const uint8_t *p_iv,
size_t iv_length); size_t iv_length);
/** \brief The function prototype for the update operation of transparent-key /** \brief The function prototype for the update operation of
* block cipher operations. * hardware-accelerated block cipher operations.
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_cipher_transparent_update_<CIPHER_NAME>_<MODE> * psa_drv_accel_cipher_update_<CIPHER_NAME>_<MODE>
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where * Where
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
@ -447,20 +450,20 @@ typedef psa_status_t (*psa_drv_cipher_transparent_set_iv_t)(psa_drv_cipher_trans
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_cipher_transparent_update_t)(psa_drv_cipher_transparent_context_t *p_context, typedef psa_status_t (*psa_drv_accel_cipher_update_t)(psa_drv_accel_cipher_context_t *p_context,
const uint8_t *p_input, const uint8_t *p_input,
size_t input_size, size_t input_size,
uint8_t *p_output, uint8_t *p_output,
size_t output_size, size_t output_size,
size_t *p_output_length); size_t *p_output_length);
/** \brief The function prototype for the finish operation of transparent-key /** \brief The function prototype for the finish operation of
* block cipher operations. * hardware-accelerated block cipher operations.
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_cipher_transparent_finish_<CIPHER_NAME>_<MODE> * psa_drv_accel_cipher_finish_<CIPHER_NAME>_<MODE>
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where * Where
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
@ -476,18 +479,18 @@ typedef psa_status_t (*psa_drv_cipher_transparent_update_t)(psa_drv_cipher_trans
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_cipher_transparent_finish_t)(psa_drv_cipher_transparent_context_t *p_context, typedef psa_status_t (*psa_drv_accel_cipher_finish_t)(psa_drv_accel_cipher_context_t *p_context,
uint8_t *p_output, uint8_t *p_output,
size_t output_size, size_t output_size,
size_t *p_output_length); size_t *p_output_length);
/** \brief The function prototype for the abort operation of transparent-key /** \brief The function prototype for the abort operation of
* block cipher operations. * hardware-accelerated block cipher operations.
* *
* Functions that implement the following prototype should be named in the * Functions that implement the following prototype should be named in the
* following convention: * following convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_cipher_transparent_abort_<CIPHER_NAME>_<MODE> * psa_drv_accel_cipher_abort_<CIPHER_NAME>_<MODE>
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where * Where
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
@ -498,27 +501,27 @@ typedef psa_status_t (*psa_drv_cipher_transparent_finish_t)(psa_drv_cipher_trans
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_cipher_transparent_abort_t)(psa_drv_cipher_transparent_context_t *p_context); typedef psa_status_t (*psa_drv_accel_cipher_abort_t)(psa_drv_accel_cipher_context_t *p_context);
/**@}*/ /**@}*/
/** \defgroup aead_transparent AEAD Transparent /** \defgroup accel_aead Hardware-Accelerated Authenticated Encryption with Additional Data
* *
* Authenticated Encryption with Additional Data (AEAD) operations with * Hardware-accelerated Authenticated Encryption with Additional Data (AEAD)
* transparent keys must be done in one function call. While this creates a * operations must be done in one function call. While this creates a burden
* burden for implementers as there must be sufficient space in memory for the * for implementers as there must be sufficient space in memory for the entire
* entire message, it prevents decrypted data from being made available before * message, it prevents decrypted data from being made available before the
* the authentication operation is complete and the data is known to be * authentication operation is complete and the data is known to be authentic.
* authentic.
*/ */
/**@{*/ /**@{*/
/** Process an authenticated encryption operation using an opaque key. /** \brief The function prototype for the hardware-accelerated authenticated
* encryption operation.
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_aead_<ALGO>_encrypt * psa_drv_accel_aead_<ALGO>_encrypt
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the AEAD algorithm * Where `ALGO` is the name of the AEAD algorithm
* *
@ -551,27 +554,28 @@ typedef psa_status_t (*psa_drv_cipher_transparent_abort_t)(psa_drv_cipher_transp
* the `ciphertext` buffer * the `ciphertext` buffer
* *
* \retval #PSA_SUCCESS * \retval #PSA_SUCCESS
*/
typedef psa_status_t (*psa_drv_aead_transparent_encrypt_t)(const uint8_t *p_key,
size_t key_length,
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);
/** Process an authenticated decryption operation using an opaque key.
* *
* Functions that implement the prototype should be named in the following */
typedef psa_status_t (*psa_drv_accel_aead_encrypt_t)(const uint8_t *p_key,
size_t key_length,
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);
/** \brief The function prototype for the hardware-accelerated authenticated
* decryption operation.
*
* Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_aead_<ALGO>_decrypt * psa_drv_accel_aead_<ALGO>_decrypt
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the AEAD algorithm * Where `ALGO` is the name of the AEAD algorithm
* \param[in] p_key A pointer to the key material * \param[in] p_key A pointer to the key material
@ -604,41 +608,45 @@ typedef psa_status_t (*psa_drv_aead_transparent_encrypt_t)(const uint8_t *p_key,
* \retval #PSA_SUCCESS * \retval #PSA_SUCCESS
* Success. * Success.
*/ */
typedef psa_status_t (*psa_drv_aead_transparent_decrypt_t)(const uint8_t *p_key, typedef psa_status_t (*psa_drv_accel_aead_decrypt_t)(const uint8_t *p_key,
size_t key_length, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *nonce, const uint8_t *nonce,
size_t nonce_length, size_t nonce_length,
const uint8_t *additional_data, const uint8_t *additional_data,
size_t additional_data_length, size_t additional_data_length,
const uint8_t *ciphertext, const uint8_t *ciphertext,
size_t ciphertext_length, size_t ciphertext_length,
uint8_t *plaintext, uint8_t *plaintext,
size_t plaintext_size, size_t plaintext_size,
size_t *plaintext_length); size_t *plaintext_length);
/**@}*/ /**@}*/
/** \defgroup transparent_asymmetric Transparent Asymmetric Cryptography /** \defgroup accel_asymmetric Hardware-Accelerated Asymmetric Cryptography
* *
* Since the amount of data that can (or should) be encrypted or signed using * Since the amount of data that can (or should) be encrypted or signed using
* asymmetric keys is limited by the key size, asymmetric key operations using * asymmetric keys is limited by the key size, hardware-accelerated asymmetric
* transparent keys must be done in single function calls. * key operations must be done in single function calls.
*/ */
/**@{*/ /**@{*/
/** /**
* \brief A function that signs a hash or short message with a transparent * \brief The function prototype for the hardware-accelerated asymmetric sign
* asymmetric private key * operation.
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_asymmetric_<ALGO>_sign * psa_drv_accel_asymmetric_<ALGO>_sign
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the signing algorithm * Where `ALGO` is the name of the signing algorithm
* *
* This function supports any asymmetric-key output from psa_export_key() as
* the buffer in \p p_key. Refer to the documentation of \ref
* psa_export_key() for the formats.
*
* \param[in] p_key A buffer containing the private key * \param[in] p_key A buffer containing the private key
* material * material
* \param[in] key_size The size in bytes of the `p_key` data * \param[in] key_size The size in bytes of the `p_key` data
@ -653,26 +661,32 @@ typedef psa_status_t (*psa_drv_aead_transparent_decrypt_t)(const uint8_t *p_key,
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_asymmetric_transparent_sign_t)(const uint8_t *p_key, typedef psa_status_t (*psa_drv_accel_asymmetric_sign_t)(const uint8_t *p_key,
size_t key_size, size_t key_size,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *p_hash, psa_key_type_t key_type,
size_t hash_length, const uint8_t *p_hash,
uint8_t *p_signature, size_t hash_length,
size_t signature_size, uint8_t *p_signature,
size_t *p_signature_length); size_t signature_size,
size_t *p_signature_length);
/** /**
* \brief A function that verifies the signature a hash or short message using * \brief The function prototype for the hardware-accelerated signature verify
* a transparent asymmetric public key * operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_asymmetric_<ALGO>_verify * psa_drv_accel_asymmetric_<ALGO>_verify
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the signing algorithm * Where `ALGO` is the name of the signing algorithm
* *
* This function supports any output from \ref psa_export_public_key() as the
* buffer in \p p_key. Refer to the documentation of \ref
* psa_export_public_key() for the format of public keys and to the
* documentation of \ref psa_export_key() for the format for other key types.
*
* \param[in] p_key A buffer containing the public key material * \param[in] p_key A buffer containing the public key material
* \param[in] key_size The size in bytes of the `p_key` data * \param[in] key_size The size in bytes of the `p_key` data
* \param[in] alg A signature algorithm that is compatible with * \param[in] alg A signature algorithm that is compatible with
@ -686,25 +700,31 @@ typedef psa_status_t (*psa_drv_asymmetric_transparent_sign_t)(const uint8_t *p_k
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
* The signature is valid. * The signature is valid.
*/ */
typedef psa_status_t (*psa_drv_asymmetric_transparent_verify_t)(const uint8_t *p_key, typedef psa_status_t (*psa_drv_accel_asymmetric_verify_t)(const uint8_t *p_key,
size_t key_size, size_t key_size,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *p_hash, psa_key_type_t key_type,
size_t hash_length, const uint8_t *p_hash,
const uint8_t *p_signature, size_t hash_length,
size_t signature_length); const uint8_t *p_signature,
size_t signature_length);
/** /**
* \brief A function that encrypts a short message with a transparent * \brief The function prototype for the hardware-accelerated asymmetric
* asymmetric public key * encrypt operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_asymmetric_<ALGO>_encrypt * psa_drv_accel_asymmetric_<ALGO>_encrypt
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the encryption algorithm * Where `ALGO` is the name of the encryption algorithm
* *
* This function supports any output from \ref psa_export_public_key() as the
* buffer in \p p_key. Refer to the documentation of \ref
* psa_export_public_key() for the format of public keys and to the
* documentation of \ref psa_export_key() for the format for other key types.
*
* \param[in] p_key A buffer containing the public key material * \param[in] p_key A buffer containing the public key material
* \param[in] key_size The size in bytes of the `p_key` data * \param[in] key_size The size in bytes of the `p_key` data
* \param[in] alg An asymmetric encryption algorithm that is * \param[in] alg An asymmetric encryption algorithm that is
@ -730,27 +750,33 @@ typedef psa_status_t (*psa_drv_asymmetric_transparent_verify_t)(const uint8_t *p
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_asymmetric_transparent_encrypt_t)(const uint8_t *p_key, typedef psa_status_t (*psa_drv_accel_asymmetric_encrypt_t)(const uint8_t *p_key,
size_t key_size, size_t key_size,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *p_input, psa_key_type_t key_type,
size_t input_length, const uint8_t *p_input,
const uint8_t *p_salt, size_t input_length,
size_t salt_length, const uint8_t *p_salt,
uint8_t *p_output, size_t salt_length,
size_t output_size, uint8_t *p_output,
size_t *p_output_length); size_t output_size,
size_t *p_output_length);
/** /**
* \brief Decrypt a short message with a transparent asymmetric private key * \brief The function prototype for the hardware=acce;erated asymmetric
* decrypt operation
* *
* Functions that implement the prototype should be named in the following * Functions that implement this prototype should be named in the following
* convention: * convention:
* ~~~~~~~~~~~~~{.c} * ~~~~~~~~~~~~~{.c}
* psa_drv_asymmetric_<ALGO>_decrypt * psa_drv_accel_asymmetric_<ALGO>_decrypt
* ~~~~~~~~~~~~~ * ~~~~~~~~~~~~~
* Where `ALGO` is the name of the encryption algorithm * Where `ALGO` is the name of the encryption algorithm
* *
* This function supports any asymmetric-key output from psa_export_key() as
* the buffer in \p p_key. Refer to the documentation of \ref
* psa_export_key() for the formats.
*
* \param[in] p_key A buffer containing the private key material * \param[in] p_key A buffer containing the private key material
* \param[in] key_size The size in bytes of the `p_key` data * \param[in] key_size The size in bytes of the `p_key` data
* \param[in] alg An asymmetric encryption algorithm that is * \param[in] alg An asymmetric encryption algorithm that is
@ -776,16 +802,17 @@ typedef psa_status_t (*psa_drv_asymmetric_transparent_encrypt_t)(const uint8_t *
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_asymmetric_transparent_decrypt_t)(const uint8_t *p_key, typedef psa_status_t (*psa_drv_accel_asymmetric_decrypt_t)(const uint8_t *p_key,
size_t key_size, size_t key_size,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *p_input, psa_key_type_t key_type,
size_t input_length, const uint8_t *p_input,
const uint8_t *p_salt, size_t input_length,
size_t salt_length, const uint8_t *p_salt,
uint8_t *p_output, size_t salt_length,
size_t output_size, uint8_t *p_output,
size_t *p_output_length); size_t output_size,
size_t *p_output_length);
/**@}*/ /**@}*/

View file

@ -40,10 +40,6 @@ extern "C" {
*/ */
/**@{*/ /**@{*/
/** \brief A hardware-specific structure for a entropy providing hardware
*/
typedef struct psa_drv_entropy_context_s psa_drv_entropy_context_t;
/** \brief Initialize an entropy driver /** \brief Initialize an entropy driver
* *
* *
@ -53,7 +49,7 @@ typedef struct psa_drv_entropy_context_s psa_drv_entropy_context_t;
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_entropy_init_t)(psa_drv_entropy_context_t *p_context); typedef psa_status_t (*psa_drv_entropy_init_t)(void *p_context);
/** \brief Get a specified number of bits from the entropy source /** \brief Get a specified number of bits from the entropy source
* *
@ -81,7 +77,7 @@ typedef psa_status_t (*psa_drv_entropy_init_t)(psa_drv_entropy_context_t *p_cont
* *
* \retval PSA_SUCCESS * \retval PSA_SUCCESS
*/ */
typedef psa_status_t (*psa_drv_entropy_get_bits_t)(psa_drv_entropy_context_t *p_context, typedef psa_status_t (*psa_drv_entropy_get_bits_t)(void *p_context,
uint8_t *p_buffer, uint8_t *p_buffer,
uint32_t buffer_size, uint32_t buffer_size,
uint32_t *p_received_entropy_bits); uint32_t *p_received_entropy_bits);
@ -96,11 +92,12 @@ typedef psa_status_t (*psa_drv_entropy_get_bits_t)(psa_drv_entropy_context_t *p_
* If one of the functions is not implemented, it should be set to NULL. * If one of the functions is not implemented, it should be set to NULL.
*/ */
typedef struct { typedef struct {
/** The driver-specific size of the entropy context */
const size_t context_size;
/** Function that performs initialization for the entropy source */ /** Function that performs initialization for the entropy source */
psa_drv_entropy_init_t *p_init; psa_drv_entropy_init_t p_init;
/** Function that performs the get_bits operation for the entropy source /** Function that performs the get_bits operation for the entropy source */
*/ psa_drv_entropy_get_bits_t p_get_bits;
psa_drv_entropy_get_bits_t *p_get_bits;
} psa_drv_entropy_t; } psa_drv_entropy_t;
/**@}*/ /**@}*/

File diff suppressed because it is too large Load diff