From 3a782a0fe4ac004d5645be9a82b19af916b1ee3a Mon Sep 17 00:00:00 2001 From: Max Fillinger Date: Sun, 7 Nov 2021 14:01:16 +0100 Subject: [PATCH] Add IV and block size getters for cipher_info Signed-off-by: Max Fillinger --- include/mbedtls/cipher.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/mbedtls/cipher.h b/include/mbedtls/cipher.h index 892771e638..78d31498b4 100644 --- a/include/mbedtls/cipher.h +++ b/include/mbedtls/cipher.h @@ -507,6 +507,41 @@ static inline const char *mbedtls_cipher_info_get_name( return( info->MBEDTLS_PRIVATE(name) ); } +/** + * \brief This function returns the size of the IV or nonce + * for the cipher info structure, in bytes. + * + * \param info The cipher info structure. This may be \c NULL. + * + * \return The recommended IV size. + * \return \c 0 for ciphers not using an IV or a nonce. + */ +static inline int mbedtls_cipher_info_get_iv_size( + const mbedtls_cipher_info_t *info ) +{ + if( info == NULL ) + return( 0 ); + + return( (int) info->MBEDTLS_PRIVATE(iv_size) ); +} + +/** + * \brief This function returns the block size of the given + * cipher info structure. + * + * \param info The cipher info structure. This may be \c NULL. + * + * \return The block size of the cipher. + */ +static inline unsigned int mbedtls_cipher_info_get_block_size( + const mbedtls_cipher_info_t *info ) +{ + if( info == NULL ) + return( 0 ); + + return( info->MBEDTLS_PRIVATE(block_size) ); +} + /** * \brief This function initializes a \p cipher_context as NONE. *