diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-11-04 15:58:03 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-11-04 16:23:48 +0100 |
commit | 17cd68fc56385a1db2bd0ddbb43cda5bd012e7c1 (patch) | |
tree | 057e17393ee2fd26447247c6818e7da0c595ea0e /openpgp/src/parse.rs | |
parent | 62be3957d51efb2191b56c97c732583d02caf1ae (diff) |
openpgp: Use XXH3 to hash packet bodies.
- When we stream packet bodies, we hash their contents so that we
can compare them later on, even if we no longer have the data.
Previously, we used the fasted hash from the SHA2 family, either
SHA256 or SHA512 depending on the architecture.
- That, however, turned out to be a major performance problem. When
decrypting a non-compressed, binary file on amd64, we spent
roughly a third of the time just to compute the hash.
- Using the non-cryptographic hash function XXH3, we can greatly
improve the performance. On my system, it is 30x as fast as SHA3,
and reduces the overhead of computing the body hash considerably:
% time ./sq-sha512 decrypt --recipient-key juliet.key.pgp 3g-for-juliet.binary.pgp >/dev/null 2>&1
13.931 total
% time ./sq-xxh3 decrypt --recipient-key juliet.key.pgp 3g-for-juliet.binary.pgp >/dev/null 2>&1
9.264 total
- See #771.
Diffstat (limited to 'openpgp/src/parse.rs')
-rw-r--r-- | openpgp/src/parse.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 55489be7..326793fb 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -183,6 +183,8 @@ use std::fmt; use std::path::Path; use std::result::Result as StdResult; +use xxhash_rust::xxh3::Xxh3; + use ::buffered_reader::*; use crate::{ @@ -3309,7 +3311,7 @@ pub struct PacketParser<'a> { /// We compute a hashsum over the body to implement comparison on /// containers that have been streamed. - body_hash: Option<Box<dyn crate::crypto::hash::Digest>>, + body_hash: Option<Box<Xxh3>>, state: PacketParserState, } |