From f057893035d0106488c66c3f1b319ce084194a57 Mon Sep 17 00:00:00 2001 From: Max Fillinger Date: Tue, 9 Nov 2021 21:48:08 +0100 Subject: [PATCH] Allow checking variable IV/key size in cipher_info Signed-off-by: Max Fillinger --- include/mbedtls/cipher.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/mbedtls/cipher.h b/include/mbedtls/cipher.h index 78d31498b4..a99a50ff61 100644 --- a/include/mbedtls/cipher.h +++ b/include/mbedtls/cipher.h @@ -542,6 +542,42 @@ static inline unsigned int mbedtls_cipher_info_get_block_size( return( info->MBEDTLS_PRIVATE(block_size) ); } +/** + * \brief This function returns a non-zero value if the key length for + * the given cipher is variable. + * + * \param info The cipher info structure. This may be \c NULL. + * + * \return Non-zero if the key length is variable, \c 0 otherwise. + * \return \c 0 if the given pointer is \c NULL. + */ +static inline int mbedtls_cipher_info_has_variable_key_bitlen( + const mbedtls_cipher_info_t *info ) +{ + if( info == NULL ) + return( 0 ); + + return( info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ); +} + +/** + * \brief This function returns a non-zero value if the IV size for + * the given cipher is variable. + * + * \param info The cipher info structure. This may be \c NULL. + * + * \return Non-zero if the IV size is variable, \c 0 otherwise. + * \return \c 0 if the given pointer is \c NULL. + */ +static inline int mbedtls_cipher_info_has_variable_iv_size( + const mbedtls_cipher_info_t *info ) +{ + if( info == NULL ) + return( 0 ); + + return( info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_IV_LEN ); +} + /** * \brief This function initializes a \p cipher_context as NONE. *