Home GnuPG
Diffusion GnuPG 9116fd1e9a2d

g10: Avoid extra hash contexts when decrypting MDC input

Description

g10: Avoid extra hash contexts when decrypting MDC input

* g10/mainproc.c (mainproc_context): New member
'seen_pkt_encrypted_mdc'.
(release_list): Clear 'seen_pkt_encrypted_mdc'.
(proc_encrypted): Set 'seen_pkt_encrypted_mdc'.
(have_seen_pkt_encrypted_aead): Rename to...
(have_seen_pkt_encrypted_aead_or_mdc): ...this and add check for
'seen_pkt_encrypted_mdc'.
(proc_plaintext): Do not enable extra hash contexts when decrypting
MDC input.

Avoiding extra hash contexts speeds up CFB/MDC decryption quite
a lot. For example, decrypting symmetric-key AES-256 encrypted
4 GiB file from RAM to /dev/null sees ~3.4x speed increase on
AMD Ryzen 5800X:

AES256.CFB encryption: 783 MB/s
AES256.CFB decryption: 386 MB/s (before)
AES256.CFB encryption: 1.3 GB/s (after patch)

Note, AEAD is still significantly faster:

AES256.OCB encryption: 2.2 GB/s
AES256.OCB decryption: 3.0 GB/s

(cherry picked from commit ab177eed514f7f3432d78e7e6521ad24cc0f4762)

Even 2.2 with the older Libgcrypt 1.8 gets a threefold speedup; see
https://dev.gnupg.org/T5820#155447 (AES-128 vs. AES-256 does not make
a substanial difference)

  • GnuPG-bug-id: T5820
  • Signed-off-by: Werner Koch <wk@gnupg.org>

Details

Provenance
jukiviliAuthored on Feb 8 2022, 5:31 PM
wernerCommitted on Feb 24 2022, 2:14 PM
Parents
rGa2db490de547: scd:p15: Used extended mode already for RSA 2048
Branches
Unknown
Tags
Unknown
Tasks
T5820: Slow symmetric decryption speed