From 05ac345f895098657cf44d419b5d572161ebaf43 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 15 Jun 2018 13:30:09 +0000 Subject: add explicit_bzero implementation maintainer's note: past sentiment was that, despite being imperfect and unable to force clearing of all possible copies of sensitive data (e.g. in registers, register spills, signal contexts left on the stack, etc.) this function would be added if major implementations agreed on it, which has happened -- several BSDs and glibc all include it. --- include/string.h | 1 + src/string/explicit_bzero.c | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 src/string/explicit_bzero.c diff --git a/include/string.h b/include/string.h index ce1dc300..795a2abc 100644 --- a/include/string.h +++ b/include/string.h @@ -82,6 +82,7 @@ void *memccpy (void *__restrict, const void *__restrict, int, size_t); char *strsep(char **, const char *); size_t strlcat (char *, const char *, size_t); size_t strlcpy (char *, const char *, size_t); +void explicit_bzero (void *, size_t); #endif #ifdef _GNU_SOURCE diff --git a/src/string/explicit_bzero.c b/src/string/explicit_bzero.c new file mode 100644 index 00000000..3d270040 --- /dev/null +++ b/src/string/explicit_bzero.c @@ -0,0 +1,8 @@ +#define _BSD_SOURCE +#include + +void explicit_bzero(void *d, size_t n) +{ + memset(d, 0, n); + __asm__ __volatile__ ("" : : "r"(d) : "memory"); +} -- cgit v1.2.1