From de91921561092689369b56c54950474e0a86e66f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 15 Oct 2018 21:08:04 +0300 Subject: Add implementation --- openssl/utility.cxx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 openssl/utility.cxx (limited to 'openssl/utility.cxx') diff --git a/openssl/utility.cxx b/openssl/utility.cxx new file mode 100644 index 0000000..b9c974d --- /dev/null +++ b/openssl/utility.cxx @@ -0,0 +1,41 @@ +// file : openssl/utility.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include // explicit_bzero() + +#include // exit() +#include // memset() + +namespace openssl +{ + using namespace std; + + void + mem_clear (void* p, size_t n) + { + // Note that explicit_bzero() is only available in glibc starting 2.25. + // +#if defined (__GLIBC__) && \ + defined (__GLIBC_MINOR__) && \ + (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 25) + + explicit_bzero (p, n); + +#else + + memset (p, 0, n); + + // Make sure the function is not optimized out. + // + for (char *i (reinterpret_cast (p)), *e (i + n); i != e; ++i) + { + if (*i != '\0') + exit (*i); + } + +#endif + } +} -- cgit v1.1