mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-28 00:21:48 +03:00
Make it possible to enable CTR_DRBG/PSA without a PSA AES driver
Make it possible, but not officially supported, to switch the CTR_DRBG module to PSA mode even if MBEDTLS_AES_C is defined. This is not really useful in practice, but is convenient to test the PSA mode without setting up drivers. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@ -32,9 +32,24 @@
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
/* In case AES_C is defined then it is the primary option for backward
|
||||
* compatibility purposes. If that's not available, PSA is used instead */
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
/* The CTR_DRBG implementation can either directly call the low-level AES
|
||||
* module (gated by MBEDTLS_AES_C) or call the PSA API to perform AES
|
||||
* operations. Calling the AES module directly is the default, both for
|
||||
* maximum backward compatibility and because it's a bit more efficient
|
||||
* (less glue code).
|
||||
*
|
||||
* When MBEDTLS_AES_C is disabled, the CTR_DRBG module calls PSA crypto and
|
||||
* thus benefits from the PSA AES accelerator driver.
|
||||
* It is technically possible to enable MBEDTLS_CTR_DRBG_USE_PSA_CRYPTO
|
||||
* to use PSA even when MBEDTLS_AES_C is disabled, but there is very little
|
||||
* reason to do so other than testing purposes and this is not officially
|
||||
* supported.
|
||||
*/
|
||||
#if !defined(MBEDTLS_AES_C)
|
||||
#define MBEDTLS_CTR_DRBG_USE_PSA_CRYPTO
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_CTR_DRBG_USE_PSA_CRYPTO)
|
||||
#include "mbedtls/aes.h"
|
||||
#else
|
||||
#include "psa/crypto.h"
|
||||
@ -157,7 +172,7 @@ extern "C" {
|
||||
#define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN (MBEDTLS_CTR_DRBG_ENTROPY_LEN + 1) / 2
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_AES_C)
|
||||
#if defined(MBEDTLS_CTR_DRBG_USE_PSA_CRYPTO)
|
||||
typedef struct mbedtls_ctr_drbg_psa_context {
|
||||
mbedtls_svc_key_id_t key_id;
|
||||
psa_cipher_operation_t operation;
|
||||
@ -189,7 +204,7 @@ typedef struct mbedtls_ctr_drbg_context {
|
||||
* This is the maximum number of requests
|
||||
* that can be made between reseedings. */
|
||||
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
#if !defined(MBEDTLS_CTR_DRBG_USE_PSA_CRYPTO)
|
||||
mbedtls_aes_context MBEDTLS_PRIVATE(aes_ctx); /*!< The AES context. */
|
||||
#else
|
||||
mbedtls_ctr_drbg_psa_context MBEDTLS_PRIVATE(psa_ctx); /*!< The PSA context. */
|
||||
|
Reference in New Issue
Block a user