mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Prepare codepath tests for early termination
Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
committed by
Manuel Pégourié-Gonnard
parent
e9cc10d2af
commit
0a75adcf4e
@ -43,6 +43,49 @@ static inline void mbedtls_codepath_reset(void)
|
||||
mbedtls_codepath_check = MBEDTLS_MPI_IS_TEST;
|
||||
}
|
||||
|
||||
/** Check the codepath taken and fail if it doesn't match.
|
||||
*
|
||||
* When a function returns with an error, it can do so before reaching any interesting codepath. The
|
||||
* same can happen if a parameter to the function is zero. In these cases we need to allow
|
||||
* uninitialised value for the codepath tracking variable.
|
||||
*
|
||||
* This macro expands to an instruction, not an expression.
|
||||
* It may jump to the \c exit label.
|
||||
*
|
||||
* \param path The expected codepath.
|
||||
* This expression may be evaluated multiple times.
|
||||
* \param ret The expected return value.
|
||||
* \param E The MPI parameter that can cause shortcuts.
|
||||
*/
|
||||
#define ASSERT_BIGNUM_CODEPATH(path, ret, E) \
|
||||
do { \
|
||||
if((ret)!=0 || (E).n == 0) \
|
||||
TEST_ASSERT(mbedtls_codepath_check == (path) || \
|
||||
mbedtls_codepath_check == MBEDTLS_MPI_IS_TEST); \
|
||||
else \
|
||||
TEST_EQUAL(mbedtls_codepath_check, (path)); \
|
||||
} while (0)
|
||||
|
||||
/** Check the codepath taken and fail if it doesn't match.
|
||||
*
|
||||
* When a function returns with an error, it can do so before reaching any interesting codepath. In
|
||||
* this case we need to allow uninitialised value for the codepath tracking variable.
|
||||
*
|
||||
* This macro expands to an instruction, not an expression.
|
||||
* It may jump to the \c exit label.
|
||||
*
|
||||
* \param path The expected codepath.
|
||||
* This expression may be evaluated multiple times.
|
||||
* \param ret The expected return value.
|
||||
*/
|
||||
#define ASSERT_RSA_CODEPATH(path, ret) \
|
||||
do { \
|
||||
if((ret)!=0) \
|
||||
TEST_ASSERT(mbedtls_codepath_check == (path) || \
|
||||
mbedtls_codepath_check == MBEDTLS_MPI_IS_TEST); \
|
||||
else \
|
||||
TEST_EQUAL(mbedtls_codepath_check, (path)); \
|
||||
} while (0)
|
||||
#endif /* MBEDTLS_TEST_HOOKS && !MBEDTLS_THREADING_C */
|
||||
|
||||
#endif /* BIGNUM_CODEPATH_CHECK_H */
|
||||
|
Reference in New Issue
Block a user