zeroize 0.1.2

(Alpha quality preview) Securely zero memory while avoiding compiler optimizations: unified 'secure_zero_memory()' wrapper for secure intrinsic functions for zeroing memory, using FFI to invoke OS intrinsics on stable (with support for Linux, Windows, OS X/iOS, FreeBSD, OpenBSD, NetBSD, DragonflyBSD), or the unstable 'volatile_set_memory()` intrinsic on nightly. No insecure fallbacks, no dependencies, no std, no functionality besides securely zeroing memory.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
 * Backport of `explicit_bzero()` for Linux when using glibc versions earlier
 * than 2.2.5.
 */

#include <string.h>

#undef explicit_bzero

void explicit_bzero(void *dest, size_t n) {
    memset(dest, '\0', n);
    asm volatile ("" ::: "memory");
}