-
Notifications
You must be signed in to change notification settings - Fork 154
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
#65
Comments
Just a quick note on this: will revisit it soon. It's a bit tricky as both of those ciphers have SIMD backends, and right now there are no |
Looks like |
Other way around: taking it by value can make a copy via a move, making the old version impossible to zero out. |
Yeah, looks like you are right. So this means currently there is no way to use |
FWIW, It felt much cleaner to accept a key by reference. No matter what, the caller needs to deal with the key somehow. In some of the other crates (notably |
I actually had in mind a case when we need to create |
On the second thought if a key is stored in a stack then it'll likely be moved, and |
That would still be a move which would copy the key to within the struct. Also as I mentioned earlier, often the key is transformed in some way prior to use, e.g. expanded into per-round keys as in AES. Since the |
Actually it won't, because this struct is a simple wrapper. The only case I can imagine of is when key is stored in a I also checked a case when we create a random buffer and pass it to a constructor by reference where we store it - rustc/llvm can optimize it to not to copy the buffer. Here what I wrote: https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=81662cc073f5ea50483d9e08f99826ae - rustc generates the same assembly when we pass parameter by value or by reference. So it means we don't need to zero key manually in such case. But still it can be moved later, if we store it in a heap, for example. Update: no, rust can't optimize it and copies memory :( |
Here found a blogpost on this: https://benma.github.io/2020/10/16/rust-zeroize-move.html |
It depends. The struct could be stored in a This is why using references provides better guarantees. You know any data passed by reference won't be copied. |
The type
ChaCha20Poly1305
should implementZeroize
. Also, I do not sure ifAesGcm
should implementZeroize
too. It will allow the user to implementZeroize
for types containing them.The text was updated successfully, but these errors were encountered: