Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

mem_ops.cpp
Go to the documentation of this file.
1 /*
2 * Memory Scrubbing
3 * (C) 2012,2015,2016 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/mem_ops.h>
9
10 #if defined(BOTAN_TARGET_OS_HAS_RTLSECUREZEROMEMORY)
11 #define NOMINMAX 1
12 #include <windows.h>
13 #endif
14
15 namespace Botan {
16
17 void secure_scrub_memory(void* ptr, size_t n)
18 {
19 #if defined(BOTAN_TARGET_OS_HAS_RTLSECUREZEROMEMORY)
20 ::RtlSecureZeroMemory(ptr, n);
21 #elif defined(BOTAN_USE_VOLATILE_MEMSET_FOR_ZERO) && (BOTAN_USE_VOLATILE_MEMSET_FOR_ZERO == 1)
22 /*
23 Call memset through a static volatile pointer, which the compiler
24 should not elide. This construct should be safe in conforming
25 compilers, but who knows. I did confirm that on x86-64 GCC 6.1 and
26 Clang 3.8 both create code that saves the memset address in the
27 data segment and uncondtionally loads and jumps to that address.
28 */
29 static void* (*const volatile memset_ptr)(void*, int, size_t) = std::memset;
30 (memset_ptr)(ptr, 0, n);
31 #else
32 volatile uint8_t* p = reinterpret_cast<volatile uint8_t*>(ptr);
33
34 for(size_t i = 0; i != n; ++i)
35 p[i] = 0;
36 #endif
37 }
38
39 }
Botan::secure_scrub_memory
void secure_scrub_memory(void *ptr, size_t n)
Definition: mem_ops.cpp:17
Botan
Definition: alg_id.cpp:13