Skip to content

Commit 35a8fa7

Browse files
Move zeroize-as-memset into a config file under tests/
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
1 parent afd284c commit 35a8fa7

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

include/mbedtls/platform_util.h

+6-17
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,17 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
167167
* \param len Length of the buffer in bytes
168168
*
169169
*/
170-
#if defined(MBEDTLS_PLATFORM_ZEROIZE_CHECK_UNSAFE)
171-
#define MBEDTLS_PLATFORM_ZEROIZE_ALT
172-
#define mbedtls_platform_zeroize(buf, len) memset(buf, 0, len)
173-
#include <string.h>
174-
#else
170+
#if !defined(MBEDTLS_TEST_DEFINES_ZEROIZE)
175171
void mbedtls_platform_zeroize(void *buf, size_t len);
176172
#endif
177173

178-
/* MBEDTLS_PLATFORM_ZEROIZE_CHECK_UNSAFE
179-
*
180-
* Replaces calls to mbedtls_platform_zeroize() with calls to memset(),
181-
* to allow compiler analysis to check for invalid length arguments (e.g.
182-
* specifying sizeof(pointer) rather than sizeof(pointee)).
183-
*
184-
* Note that this option is meant for internal use only and must not be used
185-
* in production builds, because that would lead to zeroization calls being
186-
* optimised out by the compiler.
174+
/* MBEDTLS_TEST_DEFINES_ZEROIZE
187175
*
188-
* It is only intended to be used in CFLAGS, with -Wsizeof-pointer-memaccess,
189-
* to check for those incorrect calls to mbedtls_platform_zeroize().
176+
* Indicates that the library is being built by the test framework, and the
177+
* framework is going to provide a replacement mbedtls_platform_zeroize()
178+
* using a pre-processor macro, so the function declaration should be omitted.
190179
*/
191-
//#define MBEDTLS_PLATFORM_ZEROIZE_CHECK_UNSAFE
180+
//#define MBEDTLS_TEST_DEFINES_ZEROIZE
192181

193182
#if defined(MBEDTLS_HAVE_TIME_DATE)
194183
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* mbedtls_config.h wrapper that defines mbedtls_platform_zeroize() to be
2+
* memset(), so that the compile can check arguments for us.
3+
* Used for testing.
4+
*/
5+
/*
6+
* Copyright The Mbed TLS Contributors
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#include "mbedtls/mbedtls_config.h"
23+
24+
#include <string.h>
25+
26+
/* Define _ALT so we don't get the built-in implementation. The test code will
27+
* also need to define MBEDTLS_TEST_DEFINES_ZEROIZE so we don't get the
28+
* declaration. */
29+
#define MBEDTLS_PLATFORM_ZEROIZE_ALT
30+
31+
#define mbedtls_platform_zeroize(buf, len) memset(buf, 0, len)

tests/scripts/all.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5123,7 +5123,7 @@ component_build_zeroize_checks () {
51235123
scripts/config.py full
51245124
51255125
# Only compile - we're looking for sizeof-pointer-memaccess warnings
5126-
make CC=gcc CFLAGS='-Werror -DMBEDTLS_PLATFORM_ZEROIZE_CHECK_UNSAFE -Wsizeof-pointer-memaccess'
5126+
make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/config-wrapper-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
51275127
}
51285128
51295129

0 commit comments

Comments
 (0)