blob: b6b85d9abab907520afacd4cb57bbcccbaa40559 [file] [log] [blame]
Janos Follath514e62c2024-08-22 18:30:06 +01001/** 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)
12int mbedtls_codepath_check = MBEDTLS_MPI_IS_TEST;
13
14void 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
21void mbedtls_codepath_take_unsafe(void)
22{
23 mbedtls_codepath_check = MBEDTLS_MPI_IS_PUBLIC;
24}
25
26void 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
32void 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 */
39