blob: 14e0bec5ea7a4b744b32aea408e56c2d9ecb3ada [file] [log] [blame]
Gabor Mezei46f79c32021-11-15 16:13:01 +01001/**
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 Rodgman7ff79652023-11-03 12:04:52 +000012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gabor Mezei46f79c32021-11-15 16:13:01 +010013 */
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 Mezei3a755f52021-11-24 16:26:33 +010022/** 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 Mezei46f79c32021-11-15 16:13:01 +010026 *
Gabor Mezei3a755f52021-11-24 16:26:33 +010027 * \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 Mezei46f79c32021-11-15 16:13:01 +010032 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010033unsigned char mbedtls_ct_uchar_mask_of_range(unsigned char low,
34 unsigned char high,
35 unsigned char c);
Gabor Mezei46f79c32021-11-15 16:13:01 +010036
37#endif /* MBEDTLS_TEST_HOOKS */
38
39#endif /* MBEDTLS_CONSTANT_TIME_INVASIVE_H */