aboutsummaryrefslogtreecommitdiff
path: root/openssl/utility.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-10-15 21:08:04 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-10-17 15:02:42 +0300
commitde91921561092689369b56c54950474e0a86e66f (patch)
treea9949058021d911db1106b1a2e4d9e0e9281de16 /openssl/utility.cxx
parentfb65c93daaf369157bd712f2c4c20161c4840b94 (diff)
Add implementation
Diffstat (limited to 'openssl/utility.cxx')
-rw-r--r--openssl/utility.cxx41
1 files changed, 41 insertions, 0 deletions
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 <openssl/utility.hxx>
+
+#include <strings.h> // explicit_bzero()
+
+#include <cstdlib> // exit()
+#include <cstring> // 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<char*> (p)), *e (i + n); i != e; ++i)
+ {
+ if (*i != '\0')
+ exit (*i);
+ }
+
+#endif
+ }
+}