|
Packit Service |
4684c1 |
/* Erasure of sensitive data, generic implementation.
|
|
Packit Service |
4684c1 |
Copyright (C) 2016-2020 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
This file is part of the GNU C Library.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
4684c1 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
4684c1 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
4684c1 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
4684c1 |
License along with the GNU C Library; if not, see
|
|
Packit Service |
4684c1 |
<https://www.gnu.org/licenses/>. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* An assembler implementation of explicit_bzero can be created as an
|
|
Packit Service |
4684c1 |
assembler alias of an optimized bzero implementation.
|
|
Packit Service |
4684c1 |
Architecture-specific implementations also need to define
|
|
Packit Service |
4684c1 |
__explicit_bzero_chk. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#if !_LIBC
|
|
Packit Service |
4684c1 |
# include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* memset_s need this define */
|
|
Packit Service |
4684c1 |
#if HAVE_MEMSET_S
|
|
Packit Service |
4684c1 |
# define __STDC_WANT_LIB_EXT1__ 1
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <string.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#if defined _WIN32 && !defined __CYGWIN__
|
|
Packit Service |
4684c1 |
# define WIN32_LEAN_AND_MEAN
|
|
Packit Service |
4684c1 |
# include <windows.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#if _LIBC
|
|
Packit Service |
4684c1 |
/* glibc-internal users use __explicit_bzero_chk, and explicit_bzero
|
|
Packit Service |
4684c1 |
redirects to that. */
|
|
Packit Service |
4684c1 |
# undef explicit_bzero
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Set LEN bytes of S to 0. The compiler will not delete a call to
|
|
Packit Service |
4684c1 |
this function, even if S is dead after the call. */
|
|
Packit Service |
4684c1 |
void
|
|
Packit Service |
4684c1 |
explicit_bzero (void *s, size_t len)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
#if defined _WIN32 && !defined __CYGWIN__
|
|
Packit Service |
4684c1 |
(void) SecureZeroMemory (s, len);
|
|
Packit Service |
4684c1 |
#elif HAVE_EXPLICIT_MEMSET
|
|
Packit Service |
4684c1 |
explicit_memset (s, '\0', len);
|
|
Packit Service |
4684c1 |
#elif HAVE_MEMSET_S
|
|
Packit Service |
4684c1 |
(void) memset_s (s, len, '\0', len);
|
|
Packit Service |
4684c1 |
#else
|
|
Packit Service |
4684c1 |
memset (s, '\0', len);
|
|
Packit Service |
4684c1 |
# if defined __GNUC__ && !defined __clang__
|
|
Packit Service |
4684c1 |
/* Compiler barrier. */
|
|
Packit Service |
4684c1 |
asm volatile ("" ::: "memory");
|
|
Packit Service |
4684c1 |
# endif
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
}
|