diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2018-11-13 22:08:50 +0200 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2018-11-20 21:18:01 +0200 |
commit | 168668228c7c49e70612cb4d602d6d603a2add2c (patch) | |
tree | d7a1b88ae32ece2ab9c8fd9b184a848756b996b7 /src/g10lib.h | |
parent | 9d9c4fd18b445ff414d11678285d54af3afdb222 (diff) | |
download | libgcrypt-168668228c7c49e70612cb4d602d6d603a2add2c.tar.gz |
Use explicit_bzero for wipememory
* configure.ac (AC_CHECK_FUNCS): Check for 'explicit_bzero'.
* src/g10lib.h (wipememory2): Use _gcry_fast_wipememory if _SET is
zero.
(_gcry_fast_wipememory): New.
(_gcry_wipememory2): Rename to...
(_gcry_fast_wipememory2): ...this.
* src/misc.c (_gcry_wipememory): New.
(_gcry_wipememory2): Rename to...
(_gcry_fast_wipememory2): ...this.
(_gcry_fast_wipememory2) [HAVE_EXPLICIT_BZERO]: Use explicit_bzero if
SET is zero.
(_gcry_burn_stack): Use _gcry_fast_wipememory.
--
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'src/g10lib.h')
-rw-r--r-- | src/g10lib.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/g10lib.h b/src/g10lib.h index 9b214781..694c2d83 100644 --- a/src/g10lib.h +++ b/src/g10lib.h @@ -334,15 +334,16 @@ void __gcry_burn_stack (unsigned int bytes); do { __gcry_burn_stack (bytes); \ __gcry_burn_stack_dummy (); } while(0) - /* To avoid that a compiler optimizes certain memset calls away, these macros may be used instead. For small constant length buffers, memory wiping is inlined. For non-constant or large length buffers, - memory is wiped with memset through _gcry_wipememory. */ -void _gcry_wipememory2(void *ptr, int set, size_t len); + memory is wiped with memset through _gcry_fast_wipememory. */ #define wipememory2(_ptr,_set,_len) do { \ if (!CONSTANT_P(_len) || _len > 64) { \ - _gcry_wipememory2((void *)_ptr, _set, _len); \ + if (CONSTANT_P(_set) && (_set) == 0) \ + _gcry_fast_wipememory((void *)_ptr, _len); \ + else \ + _gcry_fast_wipememory2((void *)_ptr, _set, _len); \ } else {\ volatile char *_vptr = (volatile char *)(_ptr); \ size_t _vlen = (_len); \ @@ -353,6 +354,9 @@ void _gcry_wipememory2(void *ptr, int set, size_t len); } while(0) #define wipememory(_ptr,_len) wipememory2(_ptr,0,_len) +void _gcry_fast_wipememory(void *ptr, size_t len); +void _gcry_fast_wipememory2(void *ptr, int set, size_t len); + #if defined(HAVE_GCC_ATTRIBUTE_PACKED) && \ defined(HAVE_GCC_ATTRIBUTE_ALIGNED) && \ defined(HAVE_GCC_ATTRIBUTE_MAY_ALIAS) |