-
Notifications
You must be signed in to change notification settings - Fork 130
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
aes: implement Zeroize
for aes keys
#310
Conversation
I could potentially add a feature to The necessary intrinsics were stabilized in Rust 1.59. |
In that case I could add the code required for that, but I wouldn't be able to test it. |
I have an M1 Mac Mini I can test on locally |
Great! I've updated the PR to include an implementation for that as well. Once zeroize is updated, only a version bump should be necessary for you to test it locally, assuming I didn't make any mistakes. |
Here's a PR to add support to Turns out I was wrong: only floating point NEON support was stabilized in Rust 1.59. So that feature is nightly-only, but that's fine, because the |
I released You'll need to enable the Pinning to it will be a bit tricky since it's a transitive dependency of Also note that there's a lot changing on I pinned to |
Alright, I've updated the code with the different approach to implementing I tried to at least test compiling for armv8, but I wasn't sure how to enable the |
Aah yeah, you'll probably want to use a direct dependency |
Alright, I did that. I guess this is ready for review then. It at least passes |
Hmm, weird, the CI workflow isn't running properly due to a syntax error: https://github.com/RustCrypto/block-ciphers/actions/runs/1998929396/workflow#L42 |
The other file that failed was - run: |
cargo build --target ${{ matrix.target }}
cargo build --target ${{ matrix.target }} --features hazmat syntax. - run: cargo build --target ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }} --features hazmat syntax instead? And should I do it in this PR or open a new one? |
Already fixed it: #311 Can you rebase? |
Done |
The tests all pass now. |
@@ -172,6 +175,16 @@ macro_rules! define_aes_impl { | |||
} | |||
} | |||
|
|||
impl Drop for $name_enc { | |||
fn drop(&mut self) { |
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.
It could be worth to add #[inline]
attribute here and in other Drop
impls. Otherwise, without LTO Rust will not be able to inline it.
Also, are we sure that Rust always handles empty Drop
impls in the same way as unimplemented Drop
? I vaguely remember that Rust has a special handling of Drop
-free types.
Personally, I think that having a Drop
impl gated on zeroize
is fine (I've used such approach in other crates), especially if we will use doc_cfg
to expose it in docs.
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.
As far as I'm aware the only difference between implementing Drop
and not implementing it is being able to implement Copy
. The reference also does not seem to say much more about that.
The only other differences I could think of are performance issues, such as not having to track drop flags and not running an empty destructor (though inlining should prevent that). I added the inline attribute to all drop
functions now.
In general I agree with @tarcieri that conditionally implementing Drop
(or any trait) based on a not obviously related feature could lead to problems.
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.
If nothing else the bounds are different, although whether Drop
bounds should be used/allowed at all is a matter of debate. Nevertheless, they do.
The other major difference is it's not possible to move fields out of a struct which impls Drop
, although that's not happening in the current implementation so it's not a major issue.
I think Drop
is magical enough conditionally dropping based on whether or not features are impl'd is a bit weird.
Thank you for the responses and help in getting this merged so quickly! |
The crate feature
zeroize
was previously present, but unused.This implements zeroization on drop for all aes types in the software and aesni implementations, if the
zeroize
feature is enabled.This PR does not include support for the armv8 implementation.
I do not have access to hardware to test it and a clean implementation is also likely blocked on the zeroize crate implementing
Zeroize
for the inneruint8x16_t
type used.Still I thought this might be a useful patch even without armv8 support.
If you'd prefer, I can also add some documentation describing this limitation to users.