bignum_codepath_check.c (1007B)
1 /** Support for path tracking in optionally safe bignum functions 2 */ 3 /* 4 * Copyright The Mbed TLS Contributors 5 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 6 */ 7 8 #include "test/bignum_codepath_check.h" 9 #include "bignum_core_invasive.h" 10 11 #if defined(MBEDTLS_TEST_HOOKS) && !defined(MBEDTLS_THREADING_C) 12 int mbedtls_codepath_check = MBEDTLS_MPI_IS_TEST; 13 14 static void mbedtls_codepath_take_safe(void) 15 { 16 if (mbedtls_codepath_check == MBEDTLS_MPI_IS_TEST) { 17 mbedtls_codepath_check = MBEDTLS_MPI_IS_SECRET; 18 } 19 } 20 21 static void mbedtls_codepath_take_unsafe(void) 22 { 23 mbedtls_codepath_check = MBEDTLS_MPI_IS_PUBLIC; 24 } 25 26 void mbedtls_codepath_test_hooks_setup(void) 27 { 28 mbedtls_safe_codepath_hook = mbedtls_codepath_take_safe; 29 mbedtls_unsafe_codepath_hook = mbedtls_codepath_take_unsafe; 30 } 31 32 void mbedtls_codepath_test_hooks_teardown(void) 33 { 34 mbedtls_safe_codepath_hook = NULL; 35 mbedtls_unsafe_codepath_hook = NULL; 36 } 37 38 #endif /* MBEDTLS_TEST_HOOKS && !MBEDTLS_THREADING_C */