When you're done with a cryptographic key, you must erase it from memory. If you don't, it may persist in memory long after use — readable from a core dump, a memory disclosure vulnerability, or a cold-boot attack.

The optimiser problem

The compiler is allowed to remove writes to memory that are never read again. A naive zero:

let mut key: [u8; 32] = generate_key();
use_key(&key);
key = [0u8; 32]; // Compiler may optimise this away — never read after

Correct approach in Rust

Using the zeroize crate:

use zeroize::Zeroize;

let mut key: [u8; 32] = generate_key();
use_key(&key);
key.zeroize(); // Uses volatile writes — compiler cannot optimise away

The zeroize crate uses write_volatile or compiler barriers to prevent the zero from being optimised out. It also implements Drop via ZeroizeOnDrop so keys are automatically erased when they go out of scope.

In Q-Safe, all key material types implement ZeroizeOnDrop. This is a hard invariant: no secret can outlive its intended scope. The RP2040's RAM is zeroed after each key operation — the key lives in RAM only for the duration of the operation.