-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement zeroize for secret values #6
Conversation
2950ede
to
9a4cb9c
Compare
This is a tricky situation because even when we implement impl Zeroize for SecretKey {
fn zeroize(&mut self) {
self.0 0.zeroize();
}
}
impl Drop for SecretKey {
fn drop(&mut self) {
self.zeroize();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn zeroize() {
let sk = SecretKey::from(BlsScalar::from(42));
let ptr = sk.as_ref().0.as_ptr();
drop(sk);
// We would expect that the memory is erased during `drop` but it is still there
unsafe {
assert_eq!(
core::slice::from_raw_parts(ptr, 4),
BlsScalar::from(42).0
);
};
// Let's try again and call zeroize explicitly:
let mut sk = SecretKey::from(BlsScalar::from(42));
let ptr = sk.as_ref().0.as_ptr();
sk.zeroize();
drop(sk);
// now the memory is zeroed
unsafe {
assert_eq!(core::slice::from_raw_parts(ptr, 4), [0; 4]);
};
}
} As this blogpost describes this has to do with the memory being copied under the hood
This means that the copied value in One solution, as suggested in the blogpost, is to The other is to leave it up to the user to call And in any case the |
0ba8be8
to
ab04a5e
Compare
ab04a5e
to
40a2a5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't the issue about adding zeroize to secret data?
Is there a reason to derive zeroize for public structure (like public key, apk etc)
the issue was regarding secret values indeed. But while implementing I figured that it also doesn't hurt to implement it for other types as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm totally fine with introducing this and remove the Copy
trait. I always found it strange that SecretKey
s would be Copy
. That said, while it does mitigate the problem, it doesn't solve it, since a move will produce the same results. It is, however, the best we can do for now.
Resolves #5
256b4ad
to
9c65d8a
Compare
In my opinion it doesn't make sense to have both the I understand that removing the If, at a later point, we decide that we need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Resolves #5