diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-02-15 12:21:36 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2022-02-15 12:46:50 +0100 |
commit | 8d60d90ce8200c91ca5f0123f66ed645f3321c7b (patch) | |
tree | 3bdbf9aa3771732f53dd1b9ff4dfa2df3e2009fe /openpgp/src | |
parent | bca427f72487f29a637dc1c243ee1b404be46516 (diff) |
openpgp: Fix crash converting nonce slices to arrays.
- Doing the conversion before matching on the algorithm tries to
convert nonces of different sizes to an array suitable for EAX,
leading to a panic.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/crypto/backend/cng/aead.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/openpgp/src/crypto/backend/cng/aead.rs b/openpgp/src/crypto/backend/cng/aead.rs index ff302dad..aaa9c854 100644 --- a/openpgp/src/crypto/backend/cng/aead.rs +++ b/openpgp/src/crypto/backend/cng/aead.rs @@ -27,12 +27,11 @@ impl AEADAlgorithm { op: CipherOp, ) -> Result<Box<dyn Aead>> { - let nonce = GenericArray::from_slice(nonce); - match self { AEADAlgorithm::EAX => match sym_algo { | SymmetricAlgorithm::AES128 => { let key = GenericArray::from_slice(key); + let nonce = GenericArray::from_slice(nonce); Ok(match op { CipherOp::Encrypt => Box::new(EaxOnline::<BlockCipherKey<Aes, U128>, Encrypt>::with_key_and_nonce(key, nonce)), @@ -42,6 +41,7 @@ impl AEADAlgorithm { } SymmetricAlgorithm::AES192 => { let key = GenericArray::from_slice(key); + let nonce = GenericArray::from_slice(nonce); Ok(match op { CipherOp::Encrypt => Box::new(EaxOnline::<BlockCipherKey<Aes, U192>, Encrypt>::with_key_and_nonce(key, nonce)), @@ -51,6 +51,7 @@ impl AEADAlgorithm { } SymmetricAlgorithm::AES256 => { let key = GenericArray::from_slice(key); + let nonce = GenericArray::from_slice(nonce); Ok(match op { CipherOp::Encrypt => Box::new(EaxOnline::<BlockCipherKey<Aes, U256>, Encrypt>::with_key_and_nonce(key, nonce)), |