From 098c9de2af28eeaf66e260e0fa384ff225b6beb8 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 9 Nov 2018 16:10:57 +0000 Subject: [PATCH] Add declaration and dummy-definition of mbedtls_cipher_setup_psa() --- include/mbedtls/cipher.h | 20 ++++++++++++++++++++ library/cipher.c | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/mbedtls/cipher.h b/include/mbedtls/cipher.h index 5051c1241..e7e222c4e 100644 --- a/include/mbedtls/cipher.h +++ b/include/mbedtls/cipher.h @@ -413,6 +413,26 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ); int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ); +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/** + * \brief This function initializes a cipher context for + * PSA-based use with the given cipher primitive. + * + * \note See #MBEDTLS_USE_PSA_CRYPTO for information on PSA. + * + * \param ctx The context to initialize. May not be \c NULL. + * \param cipher_info The cipher to use. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the + * cipher-specific context fails. + */ +int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx, + const mbedtls_cipher_info_t *cipher_info ); +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + /** * \brief This function returns the block size of the given cipher. * diff --git a/library/cipher.c b/library/cipher.c index 7a012f9eb..34a8170bc 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -58,6 +58,10 @@ #include "mbedtls/cmac.h" #endif +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#include "psa/crypto.h" +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else @@ -204,6 +208,14 @@ int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, return( 0 ); } +#if defined(MBEDTLS_USE_PSA_CRYPTO) +int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx, + const mbedtls_cipher_info_t *cipher_info ) +{ + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); +} +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *key, int key_bitlen,