Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,13 @@ impl Default for SecretKey {

impl Into<Scalar> for SecretKey {
fn into(self) -> Scalar {
self.0
self.0.clone()
}
}

impl Drop for SecretKey {
fn drop(&mut self) {
self.0.clear();
}
}

Expand Down Expand Up @@ -573,6 +579,7 @@ impl SharedSecret {

Ok(SharedSecret(inner))
}

}

impl AsRef<[u8]> for SharedSecret {
Expand All @@ -581,6 +588,14 @@ impl AsRef<[u8]> for SharedSecret {
}
}

impl Drop for SharedSecret {
fn drop(&mut self) {
unsafe {
core::ptr::write_volatile(&mut self.0, [0u8; 32]);
}
}
}

/// Check signature is a valid message signed by public key.
pub fn verify(message: &Message, signature: &Signature, pubkey: &PublicKey) -> bool {
ECMULT_CONTEXT.verify_raw(&signature.r, &signature.s, &pubkey.0, &message.0)
Expand Down
4 changes: 3 additions & 1 deletion src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ pub struct Scalar(pub [u32; 8]);
impl Scalar {
/// Clear a scalar to prevent the leak of sensitive data.
pub fn clear(&mut self) {
self.0 = [0u32; 8];
unsafe {
core::ptr::write_volatile(&mut self.0, [0u32; 8]);
}
}

/// Set a scalar to an unsigned integer.
Expand Down