diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2018-11-05 20:42:58 +0200 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2018-11-05 20:42:58 +0200 |
commit | 4faeaa1cbd235a2560fa04a8ac3766a07029acd8 (patch) | |
tree | 890f3af72210750380bcf0cae77b29b9e6a7aa5b /src/misc.c | |
parent | 0068d41d9304ebcdb2caba1fa8848925e2bfaac7 (diff) | |
download | libgcrypt-4faeaa1cbd235a2560fa04a8ac3766a07029acd8.tar.gz |
wipememory: use memset for non-constant length or large buffer wipes
* src/g10lib.h (CONSTANT_P): New.
(_gcry_wipememory2): New prototype.
(wipememory2): Use _gcry_wipememory2 if _len not constant expression or
lenght is larger than 64 bytes.
(FASTWIPE_T, FASTWIPE_MULT, fast_wipememory2_unaligned_head): Remove.
(fast_wipememory2): Always handle buffer as unaligned.
* src/misc.c (__gcry_burn_stack): Move memset_ptr variable to...
(memset_ptr): ... here. New.
(_gcry_wipememory2): New.
--
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -32,6 +32,8 @@ static int verbosity_level = 0; +static void *(*volatile memset_ptr)(void *, int, size_t) = (void *)memset; + static void (*fatal_error_handler)(void*,int, const char*) = NULL; static void *fatal_error_handler_value = 0; static void (*log_handler)(void*,int, const char*, va_list) = NULL; @@ -498,22 +500,28 @@ _gcry_strtokenize (const char *string, const char *delim) void +_gcry_wipememory2 (void *ptr, int set, size_t len) +{ + memset_ptr (ptr, set, len); +} + + +void __gcry_burn_stack (unsigned int bytes) { #ifdef HAVE_VLA - static void *(*volatile memset_ptr)(void *, int, size_t) = (void *)memset; - /* (bytes == 0 ? 1 : bytes) == (!bytes + bytes) */ - unsigned int buflen = ((!bytes + bytes) + 63) & ~63; - char buf[buflen]; + /* (bytes == 0 ? 1 : bytes) == (!bytes + bytes) */ + unsigned int buflen = ((!bytes + bytes) + 63) & ~63; + char buf[buflen]; - memset_ptr (buf, 0, sizeof buf); + memset_ptr (buf, 0, buflen); #else - volatile char buf[64]; + volatile char buf[64]; - wipememory (buf, sizeof buf); + wipememory (buf, sizeof buf); - if (bytes > sizeof buf) - _gcry_burn_stack (bytes - sizeof buf); + if (bytes > sizeof buf) + _gcry_burn_stack (bytes - sizeof buf); #endif } |