Introduce generic validation macros
Avoid duplicating source code for each module.
diff --git a/include/mbedtls/aes.h b/include/mbedtls/aes.h
index 62c1f92..cfb20c4 100644
--- a/include/mbedtls/aes.h
+++ b/include/mbedtls/aes.h
@@ -67,22 +67,6 @@
/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
-#if defined( MBEDTLS_CHECK_PARAMS )
-#define MBEDTLS_AES_VALIDATE_RET( cond ) do{ if( !(cond) ) { \
- MBEDTLS_PARAM_FAILED( #cond ); \
- return MBEDTLS_ERR_AES_BAD_INPUT_DATA;} \
- } while(0);
-
-#define MBEDTLS_AES_VALIDATE( cond ) do{ if( !(cond) ) { \
- MBEDTLS_PARAM_FAILED( #cond ); \
- return; } \
- } while(0);
-#else
-/* No validation of parameters will be performed */
-#define MBEDTLS_AES_VALIDATE_RET( cond )
-#define MBEDTLS_AES_VALIDATE( cond)
-#endif
-
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
!defined(inline) && !defined(__cplusplus)
#define inline __inline
diff --git a/include/mbedtls/platform_util.h b/include/mbedtls/platform_util.h
index ed21ffa..1ac16d4 100644
--- a/include/mbedtls/platform_util.h
+++ b/include/mbedtls/platform_util.h
@@ -81,6 +81,33 @@
const char *file,
int line );
#endif /* MBEDTLS_PARAM_FAILED */
+
+/* Internal macro meant to be called only from within the library. */
+#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \
+ do { \
+ if( !(cond) ) \
+ { \
+ MBEDTLS_PARAM_FAILED( #cond ); \
+ return( ret ); \
+ } \
+ } while( 0 )
+
+/* Internal macro meant to be called only from within the library. */
+#define MBEDTLS_INTERNAL_VALIDATE( cond ) \
+ do { \
+ if( !(cond) ) \
+ { \
+ MBEDTLS_PARAM_FAILED( #cond ); \
+ return; \
+ } \
+ } while( 0 )
+
+#else /* MBEDTLS_CHECK_PARAMS */
+
+/* Internal macros meant to be called only from within the library. */
+#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 )
+#define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 )
+
#endif /* MBEDTLS_CHECK_PARAMS */
/**