lovesh / amcl_rust_wrapper

Convenience wrapper over Apache Milagro
Apache License 2.0
11 stars 4 forks source link

Replace ClearOnDrop with Zeroize #2

Open burdges opened 5 years ago

burdges commented 5 years ago

The clear_on_drop crate is no longer maintained and uses fragile techniques. We expected it to break as linker optimizations work their way into rustc, etc. You should expose zeroing with the zeroize and if your dependencies do not yet support zeroing then you can implement the Zeroize trait using a function like

#[inline(always)]
fn zeroize_hack<Z: Default>(z: &mut Z) {
    use core::{ptr, sync::atomic};
    unsafe { ptr::write_volatile(z, Z::default()); }
    atomic::compiler_fence(atomic::Ordering::SeqCst);
}
lovesh commented 5 years ago

@burdges Thanks. Fixed in https://github.com/lovesh/amcl_rust_wrapper/commit/9e86347a7c21a146e364f5c26fb0c621ab6fc795

burdges commented 5 years ago

I think that commit works but actually does not use zeroize. ;)

You could just depend upon Drop of course, but if you impl Zeroize for .. and then call .zeroize() form drop, then anyone downstream with opinions about when to zero can use it. Also it looks like zeroize 0.9.3 fixed zeroize_derive

lovesh commented 5 years ago

Done in https://github.com/lovesh/amcl_rust_wrapper/commit/0c78a11310635a00ac0cdfa5f6607bc6950513f1