summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2022-03-04 18:16:23 +0100
committerJustus Winter <justus@sequoia-pgp.org>2022-03-22 11:40:50 +0100
commit55f4826df1ae6491bfc214dabb7160ac8a24b070 (patch)
tree7a994df929675af7519e8bce5316a83ea7ce2e1c
parentb58648c954613e5c736f7d741f04b6c364bfdd59 (diff)
openpgp: Delay creating the AEAD context until it is needed.
- We don't always actually need it, so it is nice to defer creating it until we do.
-rw-r--r--openpgp/src/crypto/aead.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs
index a087d4c1..05560135 100644
--- a/openpgp/src/crypto/aead.rs
+++ b/openpgp/src/crypto/aead.rs
@@ -452,15 +452,6 @@ impl<'a, S: Schedule> Decryptor<'a, S> {
let final_digest_size = self.digest_size;
for _ in 0..n_chunks {
- let mut aead = self.schedule.next_chunk(self.chunk_index, |iv, ad| {
- self.aead.context(self.sym_algo, &self.key, iv,
- CipherOp::Decrypt)
- .map(|mut aead| {
- aead.update(ad);
- aead
- })
- })?;
-
// Do a little dance to avoid exclusively locking
// `self.source`.
let to_read = chunk_digest_size + final_digest_size;
@@ -500,6 +491,17 @@ impl<'a, S: Schedule> Decryptor<'a, S> {
// A chunk has to include at least one byte and a tag.
return Err(Error::ManipulatedMessage.into());
} else {
+ let mut aead = self.schedule.next_chunk(
+ self.chunk_index,
+ |iv, ad| {
+ self.aead.context(self.sym_algo, &self.key, iv,
+ CipherOp::Decrypt)
+ .map(|mut aead| {
+ aead.update(ad);
+ aead
+ })
+ })?;
+
// Decrypt the chunk and check the tag.
let to_decrypt = chunk.len() - self.digest_size;