aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJussi Kivilinna <[email protected]>2022-02-10 17:53:53 +0000
committerWerner Koch <[email protected]>2022-11-29 10:48:55 +0000
commit15b8d100c9c8d0dc65706451d7edaef8b4abaafc (patch)
treea9a5dd15179907cbeda2eceec40d5fc1b950703d
parentgpg: Make --require-compliance work with out --status-fd (diff)
downloadgnupg-15b8d100c9c8d0dc65706451d7edaef8b4abaafc.tar.gz
gnupg-15b8d100c9c8d0dc65706451d7edaef8b4abaafc.zip
g10/plaintext: do_hash: use iobuf_read for higher performance
* g10/plaintext.c (do_hash): Use iobuf_read instead of iobuf_get for reading data; Use gcry_md_write instead of gcry_md_putc for hash data. -- This patch reduces iobuf_read per byte processing overhead and speeds up detached signature verifying. Detached verifying speed on AMD Ryzen 5800X (4.3GiB file, SHA256): gpg process user time before: 9.410s after: 1.913s (4.9x faster) GnuPG-bug-id: T5826 Signed-off-by: Jussi Kivilinna <[email protected]> (cherry picked from commit 4e27b9defc608f1fa31ca50f1ed1d5761b73b480)
-rw-r--r--g10/plaintext.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/g10/plaintext.c b/g10/plaintext.c
index 3bc86968b..10d567a8c 100644
--- a/g10/plaintext.c
+++ b/g10/plaintext.c
@@ -584,11 +584,16 @@ do_hash (gcry_md_hd_t md, gcry_md_hd_t md2, IOBUF fp, int textmode)
}
else
{
- while ((c = iobuf_get (fp)) != -1)
+ byte *buffer = xmalloc (32768);
+ int ret;
+
+ while ((ret = iobuf_read (fp, buffer, 32768)) != -1)
{
if (md)
- gcry_md_putc (md, c);
+ gcry_md_write (md, buffer, ret);
}
+
+ xfree (buffer);
}
}