Introduce generic validation macros
Avoid duplicating source code for each module.
diff --git a/library/aes.c b/library/aes.c
index 7a364a0..6ff39d7 100644
--- a/library/aes.c
+++ b/library/aes.c
@@ -56,6 +56,12 @@
#if !defined(MBEDTLS_AES_ALT)
+/* Parameter validation macros based on platform_util.h */
+#define AES_VALIDATE_RET( cond ) \
+ MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_AES_BAD_INPUT_DATA)
+#define AES_VALIDATE( cond ) \
+ MBEDTLS_INTERNAL_VALIDATE( cond )
+
/*
* 32-bit integer manipulation macros (little endian)
*/
@@ -511,7 +517,7 @@
void mbedtls_aes_init( mbedtls_aes_context *ctx )
{
- MBEDTLS_AES_VALIDATE( ctx != NULL );
+ AES_VALIDATE( ctx != NULL );
memset( ctx, 0, sizeof( mbedtls_aes_context ) );
}
@@ -527,7 +533,7 @@
#if defined(MBEDTLS_CIPHER_MODE_XTS)
void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx )
{
- MBEDTLS_AES_VALIDATE( ctx != NULL );
+ AES_VALIDATE( ctx != NULL );
mbedtls_aes_init( &ctx->crypt );
mbedtls_aes_init( &ctx->tweak );
@@ -535,7 +541,7 @@
void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx )
{
- MBEDTLS_AES_VALIDATE( ctx != NULL );
+ AES_VALIDATE( ctx != NULL );
mbedtls_aes_free( &ctx->crypt );
mbedtls_aes_free( &ctx->tweak );
@@ -552,7 +558,7 @@
unsigned int i;
uint32_t *RK;
- MBEDTLS_AES_VALIDATE_RET( ctx != NULL && key != NULL );
+ AES_VALIDATE_RET( ctx != NULL && key != NULL );
switch( keybits )
{
@@ -670,7 +676,7 @@
uint32_t *RK;
uint32_t *SK;
- MBEDTLS_AES_VALIDATE_RET( ctx != NULL && key != NULL );
+ AES_VALIDATE_RET( ctx != NULL && key != NULL );
mbedtls_aes_init( &cty );