]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Common and shared functions used by multiple modules in the Mbed TLS | |
3 | * library. | |
4 | * | |
5 | * Copyright (C) 2018, Arm Limited, All Rights Reserved | |
6 | * SPDX-License-Identifier: GPL-2.0 | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License along | |
19 | * with this program; if not, write to the Free Software Foundation, Inc., | |
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | * | |
22 | * This file is part of Mbed TLS (https://tls.mbed.org) | |
23 | */ | |
24 | ||
25 | #if !defined(MBEDTLS_CONFIG_FILE) | |
26 | #include "mbedtls/config.h" | |
27 | #else | |
28 | #include MBEDTLS_CONFIG_FILE | |
29 | #endif | |
30 | ||
31 | #include "mbedtls/platform_util.h" | |
32 | ||
33 | #include <stddef.h> | |
34 | #include <string.h> | |
35 | ||
36 | #if !defined(MBEDTLS_PLATFORM_ZEROIZE_ALT) | |
37 | /* | |
38 | * This implementation should never be optimized out by the compiler | |
39 | * | |
40 | * This implementation for mbedtls_platform_zeroize() was inspired from Colin | |
41 | * Percival's blog article at: | |
42 | * | |
43 | * http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buffer.html | |
44 | * | |
45 | * It uses a volatile function pointer to the standard memset(). Because the | |
46 | * pointer is volatile the compiler expects it to change at | |
47 | * any time and will not optimize out the call that could potentially perform | |
48 | * other operations on the input buffer instead of just setting it to 0. | |
49 | * Nevertheless, as pointed out by davidtgoldblatt on Hacker News | |
50 | * (refer to http://www.daemonology.net/blog/2014-09-05-erratum.html for | |
51 | * details), optimizations of the following form are still possible: | |
52 | * | |
53 | * if( memset_func != memset ) | |
54 | * memset_func( buf, 0, len ); | |
55 | * | |
56 | * Note that it is extremely difficult to guarantee that | |
57 | * mbedtls_platform_zeroize() will not be optimized out by aggressive compilers | |
58 | * in a portable way. For this reason, Mbed TLS also provides the configuration | |
59 | * option MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure | |
60 | * mbedtls_platform_zeroize() to use a suitable implementation for their | |
61 | * platform and needs. | |
62 | */ | |
63 | ||
64 | void mbedtls_platform_zeroize( void *buf, size_t len ) | |
65 | { | |
66 | memset( buf, 0, len ); | |
67 | } | |
68 | #endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */ |