Skip to content

Commit

Permalink
aead: have NewAead borrow the key
Browse files Browse the repository at this point in the history
In many AEAD implementations we pass the key directly onto
`NewBlockCipher`, e.g. in the `aes-gcm` crate:

https://github.com/RustCrypto/AEADs/blob/af9926e/aes-gcm/src/lib.rs#L183

This makes an unnecessary copy of the key which therefore necessitates
zeroing it out.

If we borrow the key at the time the cipher is initialized, we can avoid
making this copy.
  • Loading branch information
tarcieri committed May 23, 2020
1 parent ac59f82 commit 11144cc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion aead/src/lib.rs
Expand Up @@ -74,7 +74,7 @@ pub trait NewAead {
type KeySize: ArrayLength<u8>;

/// Construct a new stateful instance for the given key.
fn new(key: GenericArray<u8, Self::KeySize>) -> Self;
fn new(key: &GenericArray<u8, Self::KeySize>) -> Self;
}

/// Authenticated Encryption with Associated Data (AEAD) algorithm.
Expand Down

0 comments on commit 11144cc

Please sign in to comment.