aboutsummaryrefslogtreecommitdiff
path: root/openssl/utility.cxx
blob: 68852f86e3a062d20742699a3c797e6701beed7b (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
// file      : openssl/utility.cxx -*- C++ -*-
// 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
  }
}