From 8d60d90ce8200c91ca5f0123f66ed645f3321c7b Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 15 Feb 2022 12:21:36 +0100 Subject: 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. --- openpgp/src/crypto/backend/cng/aead.rs | 5 +++-- 1 file 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> { - 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::, 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::, 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::, Encrypt>::with_key_and_nonce(key, nonce)), -- cgit v1.2.3