mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-09 21:10:44 +00:00
change impl Drop for SharedSecret to use clear directly
This commit is contained in:
parent
cb18af7c1b
commit
4c6498ec69
1 changed files with 6 additions and 10 deletions
|
|
@ -12,7 +12,6 @@
|
|||
//! This implements x25519 key exchange as specified by Mike Hamburg
|
||||
//! and Adam Langley in [RFC7748](https://tools.ietf.org/html/rfc7748).
|
||||
|
||||
use core::mem;
|
||||
use core::ops::Mul;
|
||||
|
||||
use clear_on_drop::clear::Clear;
|
||||
|
|
@ -83,18 +82,15 @@ impl Ephemeral {
|
|||
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
/// A DH SharedSecret
|
||||
#[repr(C)]
|
||||
#[derive(Default)] // we derive Default in order to use the clear() method in Drop
|
||||
pub struct SharedSecret(pub (crate) MontgomeryPoint);
|
||||
|
||||
/// Overwrite shared secret material with null bytes when it goes out of scope.
|
||||
impl Drop for SharedSecret {
|
||||
fn drop(&mut self) {
|
||||
let bytes: &mut [u8; 32] = unsafe {
|
||||
mem::transmute::<&mut MontgomeryPoint, &mut [u8; 32]>
|
||||
(&mut self.0)
|
||||
};
|
||||
bytes.clear();
|
||||
self.0.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue