BSHA3
0.17.99
P2P Blockchain, based on Bitcoin
src
support
cleanse.cpp
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-2018 The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#include <
support/cleanse.h
>
7
8
#include <cstring>
9
10
#if defined(_MSC_VER)
11
#include <Windows.h>
// For SecureZeroMemory.
12
#endif
13
14
/* Compilers have a bad habit of removing "superfluous" memset calls that
15
* are trying to zero memory. For example, when memset()ing a buffer and
16
* then free()ing it, the compiler might decide that the memset is
17
* unobservable and thus can be removed.
18
*
19
* Previously we used OpenSSL which tried to stop this by a) implementing
20
* memset in assembly on x86 and b) putting the function in its own file
21
* for other platforms.
22
*
23
* This change removes those tricks in favour of using asm directives to
24
* scare the compiler away. As best as our compiler folks can tell, this is
25
* sufficient and will continue to be so.
26
*
27
* Adam Langley <agl@google.com>
28
* Commit: ad1907fe73334d6c696c8539646c21b11178f20f
29
* BoringSSL (LICENSE: ISC)
30
*/
31
void
memory_cleanse
(
void
*ptr,
size_t
len)
32
{
33
std::memset(ptr, 0, len);
34
35
/* As best as we can tell, this is sufficient to break any optimisations that
36
might try to eliminate "superfluous" memsets. If there's an easy way to
37
detect memset_s, it would be better to use that. */
38
#if defined(_MSC_VER)
39
SecureZeroMemory(ptr, len);
40
#else
41
__asm__ __volatile__(
""
: :
"r"
(ptr) :
"memory"
);
42
#endif
43
}
memory_cleanse
void memory_cleanse(void *ptr, size_t len)
Definition:
cleanse.cpp:31
cleanse.h
Generated on Wed Nov 28 2018 15:30:29 for BSHA3 by
1.8.14