MCPcopy Create free account
hub / github.com/ElementsProject/elements / memory_cleanse

Function memory_cleanse

src/support/cleanse.cpp:14–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#endif
13
14void memory_cleanse(void *ptr, size_t len)
15{
16#if defined(_MSC_VER)
17 /* SecureZeroMemory is guaranteed not to be optimized out by MSVC. */
18 SecureZeroMemory(ptr, len);
19#else
20 std::memset(ptr, 0, len);
21
22 /* Memory barrier that scares the compiler away from optimizing out the memset.
23 *
24 * Quoting Adam Langley <agl@google.com> in commit ad1907fe73334d6c696c8539646c21b11178f20f
25 * in BoringSSL (ISC License):
26 * As best as we can tell, this is sufficient to break any optimisations that
27 * might try to eliminate "superfluous" memsets.
28 * This method is used in memzero_explicit() the Linux kernel, too. Its advantage is that it
29 * is pretty efficient because the compiler can still implement the memset() efficiently,
30 * just not remove it entirely. See "Dead Store Elimination (Still) Considered Harmful" by
31 * Yang et al. (USENIX Security 2017) for more background.
32 */
33 __asm__ __volatile__("" : : "r"(ptr) : "memory");
34#endif
35}

Callers 15

StrengthenFunction · 0.85
MixExtractMethod · 0.85
DecodeSecretFunction · 0.85
EncodeSecretFunction · 0.85
EncodeExtKeyFunction · 0.85
SignSchnorrMethod · 0.85
RandAddSeedPerfmonFunction · 0.85
CryptMethod · 0.85
CleanKeyMethod · 0.85
~SafeDbtMethod · 0.85
BytesToKeySHA512AESMethod · 0.85
SetKeyFromPassphraseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected