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
//! nightly: use the `volatile_set_memory` intrinsic

use core::intrinsics::volatile_set_memory;

/// Zero out memory using `core::intrinsics::volatile_set_memory`
///
/// The volatile parameter is set to true, so it will not be optimized out
/// unless size is equal to zero.
pub fn secure_zero_memory(bytes: &mut [u8]) {
    unsafe { volatile_set_memory(bytes.as_mut_ptr(), 0, bytes.len()) }
}