Gabor Mezei | 46f79c3 | 2021-11-15 16:13:01 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file constant_time_invasive.h |
| 3 | * |
| 4 | * \brief Constant-time module: interfaces for invasive testing only. |
| 5 | * |
| 6 | * The interfaces in this file are intended for testing purposes only. |
| 7 | * They SHOULD NOT be made available in library integrations except when |
| 8 | * building the library for testing. |
| 9 | */ |
| 10 | /* |
| 11 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 12 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gabor Mezei | 46f79c3 | 2021-11-15 16:13:01 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef MBEDTLS_CONSTANT_TIME_INVASIVE_H |
| 16 | #define MBEDTLS_CONSTANT_TIME_INVASIVE_H |
| 17 | |
| 18 | #include "common.h" |
| 19 | |
| 20 | #if defined(MBEDTLS_TEST_HOOKS) |
| 21 | |
Gabor Mezei | 3a755f5 | 2021-11-24 16:26:33 +0100 | [diff] [blame] | 22 | /** Turn a value into a mask: |
| 23 | * - if \p low <= \p c <= \p high, |
| 24 | * return the all-bits 1 mask, aka (unsigned) -1 |
| 25 | * - otherwise, return the all-bits 0 mask, aka 0 |
Gabor Mezei | 46f79c3 | 2021-11-15 16:13:01 +0100 | [diff] [blame] | 26 | * |
Gabor Mezei | 3a755f5 | 2021-11-24 16:26:33 +0100 | [diff] [blame] | 27 | * \param low The value to analyze. |
| 28 | * \param high The value to analyze. |
| 29 | * \param c The value to analyze. |
| 30 | * |
| 31 | * \return All-bits-one if \p low <= \p c <= \p high, otherwise zero. |
Gabor Mezei | 46f79c3 | 2021-11-15 16:13:01 +0100 | [diff] [blame] | 32 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 33 | unsigned char mbedtls_ct_uchar_mask_of_range(unsigned char low, |
| 34 | unsigned char high, |
| 35 | unsigned char c); |
Gabor Mezei | 46f79c3 | 2021-11-15 16:13:01 +0100 | [diff] [blame] | 36 | |
| 37 | #endif /* MBEDTLS_TEST_HOOKS */ |
| 38 | |
| 39 | #endif /* MBEDTLS_CONSTANT_TIME_INVASIVE_H */ |