From 11144cc6d5af35b42c7477095420735912462092 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 23 May 2020 12:27:30 -0700 Subject: [PATCH] aead: have NewAead borrow the key 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. --- aead/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aead/src/lib.rs b/aead/src/lib.rs index cd358a88..f19290a1 100644 --- a/aead/src/lib.rs +++ b/aead/src/lib.rs @@ -74,7 +74,7 @@ pub trait NewAead { type KeySize: ArrayLength; /// Construct a new stateful instance for the given key. - fn new(key: GenericArray) -> Self; + fn new(key: &GenericArray) -> Self; } /// Authenticated Encryption with Associated Data (AEAD) algorithm.