blob: 69df954d4b6f91ee82c32399a3b979ad2245a46d [file] [log] [blame]
Gabor Mezei765862c2021-10-19 12:22:25 +02001/**
2 * Constant-time functions
3 *
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#ifndef MBEDTLS_CONSTANT_TIME_H
21#define MBEDTLS_CONSTANT_TIME_H
22
23#include "common.h"
24
25#include <stddef.h>
26
27
28/** Constant-time buffer comparison without branches.
29 *
30 * This is equivalent to the standard memncmp function, but is likely to be
31 * compiled to code using bitwise operation rather than a branch.
32 *
33 * This function can be used to write constant-time code by replacing branches
34 * with bit operations using masks.
35 *
36 * \param a Pointer to the first buffer.
37 * \param b Pointer to the second buffer.
38 * \param n The number of bytes to compare in the buffer.
39 *
40 * \return Zero if the content of the two buffer is the same,
41 * otherwise non-zero.
42 */
43int mbedtls_cf_memcmp( const void *a,
44 const void *b,
45 size_t n );
46
47#endif /* MBEDTLS_CONSTANT_TIME_H */