blob: 9619eb3c8fc8a3bb6cd0262680e83f7e9c333174 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// file : openssl/utility.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2019 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
}
}
|