mirror of
https://github.com/cuberite/polarssl.git
synced 2025-08-24 13:29:58 -04:00
Merge pull request #8145 from tom-cosgrove-arm/check-mbedtls_platform_zeroize-calls-2.28
Backport 2.28: Check mbedtls_platform_zeroize() calls
This commit is contained in:
commit
9302684155
@ -221,6 +221,11 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
|
|||||||
#define MBEDTLS_IGNORE_RETURN(result) ((void) !(result))
|
#define MBEDTLS_IGNORE_RETURN(result) ((void) !(result))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* If the following macro is defined, the library is being built by the test
|
||||||
|
* framework, and the framework is going to provide a replacement
|
||||||
|
* mbedtls_platform_zeroize() using a preprocessor macro, so the function
|
||||||
|
* declaration should be omitted. */
|
||||||
|
#if !defined(MBEDTLS_TEST_DEFINES_ZEROIZE) //no-check-names
|
||||||
/**
|
/**
|
||||||
* \brief Securely zeroize a buffer
|
* \brief Securely zeroize a buffer
|
||||||
*
|
*
|
||||||
@ -244,6 +249,7 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void mbedtls_platform_zeroize(void *buf, size_t len);
|
void mbedtls_platform_zeroize(void *buf, size_t len);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
||||||
/**
|
/**
|
||||||
|
29
tests/configs/user-config-zeroize-memset.h
Normal file
29
tests/configs/user-config-zeroize-memset.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* mbedtls_config.h modifier that defines mbedtls_platform_zeroize() to be
|
||||||
|
* memset(), so that the compile can check arguments for us.
|
||||||
|
* Used for testing.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* Define _ALT so we don't get the built-in implementation. The test code will
|
||||||
|
* also need to define MBEDTLS_TEST_DEFINES_ZEROIZE so we don't get the
|
||||||
|
* declaration. */
|
||||||
|
#define MBEDTLS_PLATFORM_ZEROIZE_ALT
|
||||||
|
|
||||||
|
#define mbedtls_platform_zeroize(buf, len) memset(buf, 0, len)
|
@ -3536,6 +3536,16 @@ support_build_cmake_custom_config_file () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
component_build_zeroize_checks () {
|
||||||
|
msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
|
||||||
|
|
||||||
|
scripts/config.py full
|
||||||
|
|
||||||
|
# Only compile - we're looking for sizeof-pointer-memaccess warnings
|
||||||
|
make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
component_test_zeroize () {
|
component_test_zeroize () {
|
||||||
# Test that the function mbedtls_platform_zeroize() is not optimized away by
|
# Test that the function mbedtls_platform_zeroize() is not optimized away by
|
||||||
# different combinations of compilers and optimization flags by using an
|
# different combinations of compilers and optimization flags by using an
|
||||||
|
@ -154,7 +154,7 @@ void pk_write_public_from_private(char *priv_key_file, char *pub_key_file)
|
|||||||
pub_key_raw, pub_key_len);
|
pub_key_raw, pub_key_len);
|
||||||
|
|
||||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
mbedtls_platform_zeroize(derived_key_raw, sizeof(derived_key_raw));
|
mbedtls_platform_zeroize(derived_key_raw, derived_key_len);
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_pk_wrap_as_opaque(&priv_key, &opaque_key_id,
|
TEST_EQUAL(mbedtls_pk_wrap_as_opaque(&priv_key, &opaque_key_id,
|
||||||
PSA_ALG_NONE), 0);
|
PSA_ALG_NONE), 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user