Move mbedtls_cf_memcmp to a new public header

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
Gabor Mezei 2021-10-19 12:22:25 +02:00
parent 6e0e990544
commit e24dea8225
No known key found for this signature in database
GPG Key ID: 106F5A41ECC305BD
11 changed files with 56 additions and 24 deletions

View File

@ -0,0 +1,47 @@
/**
* Constant-time functions
*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBEDTLS_CONSTANT_TIME_H
#define MBEDTLS_CONSTANT_TIME_H
#include "common.h"
#include <stddef.h>
/** Constant-time buffer comparison without branches.
*
* This is equivalent to the standard memncmp function, but is likely to be
* compiled to code using bitwise operation rather than a branch.
*
* This function can be used to write constant-time code by replacing branches
* with bit operations using masks.
*
* \param a Pointer to the first buffer.
* \param b Pointer to the second buffer.
* \param n The number of bytes to compare in the buffer.
*
* \return Zero if the content of the two buffer is the same,
* otherwise non-zero.
*/
int mbedtls_cf_memcmp( const void *a,
const void *b,
size_t n );
#endif /* MBEDTLS_CONSTANT_TIME_H */

View File

@ -29,7 +29,7 @@
#include "mbedtls/cipher_internal.h"
#include "mbedtls/platform_util.h"
#include "mbedtls/error.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#include <stdlib.h>
#include <string.h>

View File

@ -24,6 +24,7 @@
#include "common.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#include "mbedtls/error.h"
#include "mbedtls/platform_util.h"

View File

@ -33,25 +33,6 @@
#include <stddef.h>
/** Constant-time buffer comparison without branches.
*
* This is equivalent to the standard memncmp function, but is likely to be
* compiled to code using bitwise operation rather than a branch.
*
* This function can be used to write constant-time code by replacing branches
* with bit operations using masks.
*
* \param a Pointer to the first buffer.
* \param b Pointer to the second buffer.
* \param n The number of bytes to compare in the buffer.
*
* \return Zero if the content of the two buffer is the same,
* otherwise non-zero.
*/
int mbedtls_cf_memcmp( const void *a,
const void *b,
size_t n );
/** Turn a value into a mask:
* - if \p value == 0, return the all-bits 0 mask, aka 0
* - otherwise, return the all-bits 1 mask, aka (unsigned) -1

View File

@ -34,7 +34,7 @@
#include "mbedtls/nist_kw.h"
#include "mbedtls/platform_util.h"
#include "mbedtls/error.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#include <stdint.h>
#include <string.h>

View File

@ -45,6 +45,7 @@
#include "mbedtls/platform_util.h"
#include "mbedtls/error.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#include <string.h>

View File

@ -33,7 +33,7 @@
#include "mbedtls/ssl_internal.h"
#include "mbedtls/debug.h"
#include "mbedtls/error.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#if defined(MBEDTLS_USE_PSA_CRYPTO)
#include "mbedtls/psa_util.h"

View File

@ -36,7 +36,7 @@
#include "mbedtls/ssl_internal.h"
#include "mbedtls/error.h"
#include "mbedtls/platform_util.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#include <string.h>

View File

@ -45,6 +45,7 @@
#include "mbedtls/platform_util.h"
#include "mbedtls/version.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#include <string.h>

View File

@ -35,6 +35,7 @@
#include "mbedtls/error.h"
#include "mbedtls/platform_util.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#include <string.h>

View File

@ -43,7 +43,7 @@
#include "mbedtls/error.h"
#include "mbedtls/platform_util.h"
#include "mbedtls/version.h"
#include "constant_time.h"
#include "mbedtls/constant_time.h"
#include <string.h>