aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-07 12:59:33 +0000
committerlloyd <[email protected]>2015-01-07 12:59:33 +0000
commit5fd3c7adffa9fe705e493f81def04d9d57db4442 (patch)
tree85c7c6056b0d6c2b3dd77678f36e4ed9911ccfa9
parent4903ac8b8724718c5b8aa96a10ec0c83277df016 (diff)
Use RtlSecureZeroMemory or memset_s if available
-rw-r--r--src/build-data/os/darwin.txt1
-rw-r--r--src/build-data/os/windows.txt1
-rw-r--r--src/lib/utils/zero_mem.cpp13
3 files changed, 15 insertions, 0 deletions
diff --git a/src/build-data/os/darwin.txt b/src/build-data/os/darwin.txt
index d2e5df062..d22b78b91 100644
--- a/src/build-data/os/darwin.txt
+++ b/src/build-data/os/darwin.txt
@@ -12,6 +12,7 @@ doc_dir doc
dlopen
gettimeofday
gmtime_r
+memset_s
</target_features>
<aliases>
diff --git a/src/build-data/os/windows.txt b/src/build-data/os/windows.txt
index 5afd2596b..3ac33a6ae 100644
--- a/src/build-data/os/windows.txt
+++ b/src/build-data/os/windows.txt
@@ -16,6 +16,7 @@ gmtime_s
loadlibrary
query_perf_counter
virtual_lock
+rtlsecurezeromemory
</target_features>
<aliases>
diff --git a/src/lib/utils/zero_mem.cpp b/src/lib/utils/zero_mem.cpp
index e812ced0c..833b54aca 100644
--- a/src/lib/utils/zero_mem.cpp
+++ b/src/lib/utils/zero_mem.cpp
@@ -7,14 +7,27 @@
#include <botan/mem_ops.h>
+#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 {
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);
+#else
volatile byte* p = reinterpret_cast<volatile byte*>(ptr);
for(size_t i = 0; i != n; ++i)
p[i] = 0;
+#endif
}
}