diff options
author | lloyd <[email protected]> | 2015-01-23 15:53:44 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-23 15:53:44 +0000 |
commit | 9a0da0565c042c0f0a09caed036621c47e3f494e (patch) | |
tree | 85d2e78787506882f54bbff497f802c2eb0a186e /src/lib/utils/zero_mem.cpp | |
parent | 7e6ac35931ed073d01c96d212bba5c7674cba505 (diff) |
Remove memset_s, not implemented on any machine I can test on and
problematic for requiring a special define before the first include of
string.h. Instead optionally call memset via a volatile function
pointer as a faster alternative to byte at a time writes.
Github 42, 45
Diffstat (limited to 'src/lib/utils/zero_mem.cpp')
-rw-r--r-- | src/lib/utils/zero_mem.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/lib/utils/zero_mem.cpp b/src/lib/utils/zero_mem.cpp index d8c438435..1dbf6e213 100644 --- a/src/lib/utils/zero_mem.cpp +++ b/src/lib/utils/zero_mem.cpp @@ -1,6 +1,6 @@ -/* + /* * Zero Memory -* (C) 2012 Jack Lloyd +* (C) 2012,2015 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -9,9 +9,6 @@ #if defined(BOTAN_TARGET_OS_HAS_RTLSECUREZEROMEMORY) #include <windows.h> -#elif defined(BOTAN_TARGET_OS_HAS_MEMSET_S) - #define __STDC_WANT_LIB_EXT1__ 1 - #include <string.h> #endif namespace Botan { @@ -20,8 +17,9 @@ void zero_mem(void* ptr, size_t n) { #if defined(BOTAN_TARGET_OS_HAS_RTLSECUREZEROMEMORY) ::RtlSecureZeroMemory(ptr, n); -#elif defined(BOTAN_TARGET_OS_HAS_MEMSET_S) - ::memset_s(ptr, n, 0, n); +#elif defined(BOTAN_USE_VOLATILE_MEMSET) && (BOTAN_USE_VOLATILE_MEMSET == 1) + static void* (*const volatile memset_ptr)(void*, int, size_t) = memset; + (memset_ptr)(p, 0, n); #else volatile byte* p = reinterpret_cast<volatile byte*>(ptr); |