-
Notifications
You must be signed in to change notification settings - Fork 75
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
zeroize: how to signal "safeness" to crate's users? #757
Comments
It's a good question, and one I've encountered quite a bit. See also RustCrypto/AEADs#65. The biggest problem is types which want to maintain some kind of invariant which having a Indeed it would seem a marker trait like |
Another interesting thing: this could be used with the custom derive support in lieu of the current (and somewhat awkward):
Instead it could just be:
As these crates are post-1.0, we'd still need to retain support for And of course, |
Oh, didn't realize you have two github accounts :) As you may have guessed, I was asking this in relation to RustCrypto/traits#671. Currently, if I want to wrap struct SecretKeyInner(BackendSecretKey<CurveType>);
impl Zeroize for SecretKeyInner {
fn zeroize(&mut self) {
// BackendSecretKey is zeroized on drop, nothing to do
}
}
impl Zeroize for Box<SecretKeyInner> {
fn zeroize(&mut self) {
// BackendSecretKey is zeroized on drop, nothing to do
}
}
pub struct SecretKey(Secret<Box<BackendSecretKey<CurveType>>>); because |
Moved to RustCrypto/utils#652 |
Person A creates a crate with a type that has some secret data inside, say,
SecretKey { inner: SecretDataType }
. They implementZeroize
andDrop
(or#[zeroize(drop)]
) forSecretDataType
, and stop at that - the secret data is now safe (to the extend Rust can guarantee it), thedrop()
ofSecretKey
will call the zeroizingdrop()
ofSecretDataType
, so there's no need to define anything forSecretKey
itself.Person B uses A's crate and wants to use
Secret<SecretKey>
. But they cannot, becauseSecretKey
does not implementZeroize
- so they have to wrap it in a newtype and implement an emptyZeroize
for it. And they still cannot assert in code thatSecretKey
keeps its secret - they have to rely on the docs.So what are the responsibilities of A here? Should they define an (empty)
Zeroize
forSecretKey
? Should they export aSecret<Box<SecretKey>>
? What's the convention?I wonder if it would be more convenient to have a marker trait
ZeroizedOnDrop
, that A could implement forSecretKey
, andSecret
could require?The text was updated successfully, but these errors were encountered: