Use memset_s() if available

This commit is contained in:
Frank Denis 2014-03-02 19:05:14 -08:00
parent 12281a7312
commit 9f2e0ba803
2 changed files with 8 additions and 0 deletions

View File

@ -381,6 +381,7 @@ AC_CHECK_FUNC(clock_gettime, , [AC_CHECK_LIB(rt, clock_gettime)])
AC_CHECK_FUNC(fegetenv, , [AC_CHECK_LIB(m, fegetenv)])
AC_CHECK_FUNCS([SecureZeroMemory arc4random arc4random_buf posix_memalign])
AC_CHECK_FUNCS([memset_s])
AC_SUBST([LIBTOOL_EXTRA_FLAGS])

View File

@ -1,4 +1,7 @@
#ifndef __STDC_WANT_LIB_EXT1__
# define __STDC_WANT_LIB_EXT1__ 1
#endif
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
@ -17,6 +20,10 @@ sodium_memzero(void * const pnt, const size_t len)
{
#ifdef HAVE_SECUREZEROMEMORY
SecureZeroMemory(pnt, len);
#elif defined(HAVE_MEMSET_S)
if (memset_s(pnt, (rsize_t) len, 0, (rsize_t) len) != 0) {
abort();
}
#else
volatile unsigned char *pnt_ = (volatile unsigned char *) pnt;
size_t i = (size_t) 0U;