diff --git a/configure.ac b/configure.ac index 6e4d41ac..be7edddb 100644 --- a/configure.ac +++ b/configure.ac @@ -94,7 +94,7 @@ AC_SUBST(UUID_LIBS, $LIBS) LIBS=$saved_LIBS AC_SEARCH_LIBS([clock_gettime],[rt posix4]) -AC_CHECK_FUNCS([posix_memalign clock_gettime posix_fallocate]) +AC_CHECK_FUNCS([posix_memalign clock_gettime posix_fallocate explicit_bzero]) if test "x$enable_largefile" = "xno"; then AC_MSG_ERROR([Building with --disable-largefile is not supported, it can cause data corruption.]) diff --git a/lib/crypto_backend/crypto_backend.h b/lib/crypto_backend/crypto_backend.h index d99063af..e4dd0daf 100644 --- a/lib/crypto_backend/crypto_backend.h +++ b/lib/crypto_backend/crypto_backend.h @@ -124,8 +124,12 @@ int crypt_storage_encrypt(struct crypt_storage *ctx, uint64_t sector, /* Memzero helper (memset on stack can be optimized out) */ static inline void crypt_backend_memzero(void *s, size_t n) { +#ifdef HAVE_EXPLICIT_BZERO + explicit_bzero(s, n); +#else volatile uint8_t *p = (volatile uint8_t *)s; while(n--) *p++ = 0; +#endif } #endif /* _CRYPTO_BACKEND_H */ diff --git a/lib/utils_crypt.c b/lib/utils_crypt.c index d49fee8b..e5f4621d 100644 --- a/lib/utils_crypt.c +++ b/lib/utils_crypt.c @@ -155,10 +155,14 @@ int crypt_parse_pbkdf(const char *s, const char **pbkdf) */ void crypt_memzero(void *s, size_t n) { +#ifdef HAVE_EXPLICIT_BZERO + explicit_bzero(s, n); +#else volatile uint8_t *p = (volatile uint8_t *)s; while(n--) *p++ = 0; +#endif } /* safe allocations */