aboutsummaryrefslogtreecommitdiffstats
path: root/g10/sign.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2023-07-25 03:02:26 +0000
committerNIIBE Yutaka <[email protected]>2023-07-25 03:10:07 +0000
commit1ddd69935da629188dcf9215cd9e7a8f68b34a97 (patch)
tree3dd81fc60bf6b5ee9be63d1748f60afbb2df24d5 /g10/sign.c
parentsm: Use estream for I/O. (diff)
downloadgnupg-1ddd69935da629188dcf9215cd9e7a8f68b34a97.tar.gz
gnupg-1ddd69935da629188dcf9215cd9e7a8f68b34a97.zip
gpg: Add parallelized filter for hashing.
* g10/options.h (COMPAT_PARALLELIZED): New. * g10/filter.h (md_thd_filter_context_t): New type. (md_thd_filter_set_md, md_thd_filter): New. * g10/gpg.c (compatibility_flags): Update to support COMPAT_PARALLELIZED. * g10/mdfilter.c (struct md_thd_filter_context): New. (lock_md, unlock_md, get_buffer_to_hash, put_buffer_to_recv): New. (get_buffer_to_fill, put_buffer_to_send, md_thread): New. (md_thd_filter, md_thd_filter_set_md): New. * g10/sign.c (sign_file): Add support for md_thd_filter. (sign_symencrypt_file): Likewise. -- GnuPG-bug-id: 6570 Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'g10/sign.c')
-rw-r--r--g10/sign.c64
1 files changed, 49 insertions, 15 deletions
diff --git a/g10/sign.c b/g10/sign.c
index 5588557c8..f68ea3bc7 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -1020,7 +1020,9 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
const char *fname;
armor_filter_context_t *afx;
compress_filter_context_t zfx;
+ gcry_md_hd_t md;
md_filter_context_t mfx;
+ md_thd_filter_context_t mfx2 = NULL;
text_filter_context_t tfx;
progress_filter_context_t *pfx;
encrypt_filter_context_t efx;
@@ -1126,10 +1128,10 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
iobuf_push_filter (inp, text_filter, &tfx);
}
- if (gcry_md_open (&mfx.md, 0, 0))
+ if (gcry_md_open (&md, 0, 0))
BUG ();
if (DBG_HASHING)
- gcry_md_debug (mfx.md, "sign");
+ gcry_md_debug (md, "sign");
/* If we're encrypting and signing, it is reasonable to pick the
* hash algorithm to use out of the recipient key prefs. This is
@@ -1226,10 +1228,21 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
}
for (sk_rover = sk_list; sk_rover; sk_rover = sk_rover->next)
- gcry_md_enable (mfx.md, hash_for (sk_rover->pk));
+ gcry_md_enable (md, hash_for (sk_rover->pk));
if (!multifile)
- iobuf_push_filter (inp, md_filter, &mfx);
+ {
+ if (encryptflag && (opt.compat_flags & COMPAT_PARALLELIZED))
+ {
+ iobuf_push_filter (inp, md_thd_filter, &mfx2);
+ md_thd_filter_set_md (mfx2, md);
+ }
+ else
+ {
+ iobuf_push_filter (inp, md_filter, &mfx);
+ mfx.md = md;
+ }
+ }
if (detached && !encryptflag)
afx->what = 2;
@@ -1292,7 +1305,7 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
goto leave;
}
- write_status_begin_signing (mfx.md);
+ write_status_begin_signing (md);
/* Setup the inner packet. */
if (detached)
@@ -1332,7 +1345,16 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
memset (&tfx, 0, sizeof tfx);
iobuf_push_filter (inp, text_filter, &tfx);
}
- iobuf_push_filter (inp, md_filter, &mfx);
+ if (encryptflag && (opt.compat_flags & COMPAT_PARALLELIZED))
+ {
+ iobuf_push_filter (inp, md_thd_filter, &mfx2);
+ md_thd_filter_set_md (mfx2, md);
+ }
+ else
+ {
+ iobuf_push_filter (inp, md_filter, &mfx);
+ mfx.md = md;
+ }
while (iobuf_read (inp, NULL, iobuf_size) != -1)
;
iobuf_close (inp);
@@ -1361,7 +1383,7 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
goto leave;
/* Write the signatures. */
- rc = write_signature_packets (ctrl, sk_list, out, mfx.md, extrahash,
+ rc = write_signature_packets (ctrl, sk_list, out, md, extrahash,
opt.textmode && !outfile? 0x01 : 0x00,
0, duration, detached ? 'D':'S', NULL);
if (rc)
@@ -1378,7 +1400,7 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
write_status (STATUS_END_ENCRYPTION);
}
iobuf_close (inp);
- gcry_md_close (mfx.md);
+ gcry_md_close (md);
release_sk_list (sk_list);
release_pk_list (pk_list);
recipient_digest_algo = 0;
@@ -1561,6 +1583,8 @@ sign_symencrypt_file (ctrl_t ctrl, const char *fname, strlist_t locusr)
progress_filter_context_t *pfx;
compress_filter_context_t zfx;
md_filter_context_t mfx;
+ md_thd_filter_context_t mfx2 = NULL;
+ gcry_md_hd_t md;
text_filter_context_t tfx;
cipher_filter_context_t cfx;
iobuf_t inp = NULL;
@@ -1644,15 +1668,25 @@ sign_symencrypt_file (ctrl_t ctrl, const char *fname, strlist_t locusr)
/* Prepare to calculate the MD over the input. */
if (opt.textmode)
iobuf_push_filter (inp, text_filter, &tfx);
- if (gcry_md_open (&mfx.md, 0, 0))
+ if (gcry_md_open (&md, 0, 0))
BUG ();
if (DBG_HASHING)
- gcry_md_debug (mfx.md, "symc-sign");
+ gcry_md_debug (md, "symc-sign");
for (sk_rover = sk_list; sk_rover; sk_rover = sk_rover->next)
- gcry_md_enable (mfx.md, hash_for (sk_rover->pk));
+ gcry_md_enable (md, hash_for (sk_rover->pk));
+
+ if ((opt.compat_flags & COMPAT_PARALLELIZED))
+ {
+ iobuf_push_filter (inp, md_thd_filter, &mfx2);
+ md_thd_filter_set_md (mfx2, md);
+ }
+ else
+ {
+ iobuf_push_filter (inp, md_filter, &mfx);
+ mfx.md = md;
+ }
- iobuf_push_filter (inp, md_filter, &mfx);
/* Push armor output filter */
if (opt.armor)
@@ -1694,7 +1728,7 @@ sign_symencrypt_file (ctrl_t ctrl, const char *fname, strlist_t locusr)
if (rc)
goto leave;
- write_status_begin_signing (mfx.md);
+ write_status_begin_signing (md);
/* Pipe data through all filters; i.e. write the signed stuff. */
/* (current filters: zip - encrypt - armor) */
@@ -1706,7 +1740,7 @@ sign_symencrypt_file (ctrl_t ctrl, const char *fname, strlist_t locusr)
/* Write the signatures. */
/* (current filters: zip - encrypt - armor) */
- rc = write_signature_packets (ctrl, sk_list, out, mfx.md, extrahash,
+ rc = write_signature_packets (ctrl, sk_list, out, md, extrahash,
opt.textmode? 0x01 : 0x00,
0, duration, 'S', NULL);
if (rc)
@@ -1723,7 +1757,7 @@ sign_symencrypt_file (ctrl_t ctrl, const char *fname, strlist_t locusr)
}
iobuf_close (inp);
release_sk_list (sk_list);
- gcry_md_close (mfx.md);
+ gcry_md_close (md);
xfree (cfx.dek);
xfree (s2k);
release_progress_context (pfx);