Botan  1.11.15
src/lib/utils/zero_mem.cpp
Go to the documentation of this file.
00001  /*
00002 * Zero Memory
00003 * (C) 2012,2015 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #include <botan/mem_ops.h>
00009 
00010 #if defined(BOTAN_TARGET_OS_HAS_RTLSECUREZEROMEMORY)
00011   #include <windows.h>
00012 #endif
00013 
00014 namespace Botan {
00015 
00016 void zero_mem(void* ptr, size_t n)
00017    {
00018 #if defined(BOTAN_TARGET_OS_HAS_RTLSECUREZEROMEMORY)
00019    ::RtlSecureZeroMemory(ptr, n);
00020 #elif defined(BOTAN_USE_VOLATILE_MEMSET) && (BOTAN_USE_VOLATILE_MEMSET == 1)
00021    static void* (*const volatile memset_ptr)(void*, int, size_t) = std::memset;
00022    (memset_ptr)(p, 0, n);
00023 #else
00024    volatile byte* p = reinterpret_cast<volatile byte*>(ptr);
00025 
00026    for(size_t i = 0; i != n; ++i)
00027       p[i] = 0;
00028 #endif
00029    }
00030 
00031 }