1 /* encrypt.c - Main encryption driver
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 * 2006, 2009 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
43 static int encrypt_simple( const char *filename, int mode, int use_seskey );
44 static int write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, iobuf_t out );
47 * Encrypt FILENAME with only the symmetric cipher. Take input from
48 * stdin if FILENAME is NULL.
51 encrypt_symmetric (const char *filename)
53 return encrypt_simple( filename, 1, 0 );
58 * Encrypt FILENAME as a literal data packet only. Take input from
59 * stdin if FILENAME is NULL.
62 encrypt_store (const char *filename)
64 return encrypt_simple( filename, 0, 0 );
69 encrypt_seskey (DEK *dek, DEK **seskey, byte *enckey)
74 assert ( dek->keylen <= 32 );
77 *seskey=xmalloc_clear(sizeof(DEK));
78 (*seskey)->keylen=dek->keylen;
79 (*seskey)->algo=dek->algo;
80 make_session_key(*seskey);
81 /*log_hexdump( "thekey", c->key, c->keylen );*/
84 /* The encrypted session key is prefixed with a one-octet algorithm id. */
85 buf[0] = (*seskey)->algo;
86 memcpy( buf + 1, (*seskey)->key, (*seskey)->keylen );
88 /* We only pass already checked values to the following fucntion,
89 thus we consider any failure as fatal. */
90 if (openpgp_cipher_open (&hd, dek->algo, GCRY_CIPHER_MODE_CFB, 1))
92 if (gcry_cipher_setkey (hd, dek->key, dek->keylen))
94 gcry_cipher_setiv (hd, NULL, 0);
95 gcry_cipher_encrypt (hd, buf, (*seskey)->keylen + 1, NULL, 0);
96 gcry_cipher_close (hd);
98 memcpy( enckey, buf, (*seskey)->keylen + 1 );
99 wipememory( buf, sizeof buf ); /* burn key */
103 /* We try very hard to use a MDC */
105 use_mdc(PK_LIST pk_list,int algo)
107 /* RFC-2440 don't has MDC */
111 /* --force-mdc overrides --disable-mdc */
118 /* Do the keys really support MDC? */
120 if(select_mdc_from_pklist(pk_list))
123 /* The keys don't support MDC, so now we do a bit of a hack - if any
124 of the AESes or TWOFISH are in the prefs, we assume that the user
125 can handle a MDC. This is valid for PGP 7, which can handle MDCs
126 though it will not generate them. 2440bis allows this, by the
129 if(select_algo_from_prefs(pk_list,PREFTYPE_SYM,
130 CIPHER_ALGO_AES,NULL)==CIPHER_ALGO_AES)
133 if(select_algo_from_prefs(pk_list,PREFTYPE_SYM,
134 CIPHER_ALGO_AES192,NULL)==CIPHER_ALGO_AES192)
137 if(select_algo_from_prefs(pk_list,PREFTYPE_SYM,
138 CIPHER_ALGO_AES256,NULL)==CIPHER_ALGO_AES256)
141 if(select_algo_from_prefs(pk_list,PREFTYPE_SYM,
142 CIPHER_ALGO_TWOFISH,NULL)==CIPHER_ALGO_TWOFISH)
145 /* Last try. Use MDC for the modern ciphers. */
147 if (openpgp_cipher_get_algo_blklen (algo) != 8)
151 warn_missing_mdc_from_pklist (pk_list);
153 return 0; /* No MDC */
157 /* We don't want to use use_seskey yet because older gnupg versions
158 can't handle it, and there isn't really any point unless we're
159 making a message that can be decrypted by a public key or
162 encrypt_simple (const char *filename, int mode, int use_seskey)
166 PKT_plaintext *pt = NULL;
167 STRING2KEY *s2k = NULL;
172 cipher_filter_context_t cfx;
173 armor_filter_context_t *afx = NULL;
174 compress_filter_context_t zfx;
175 text_filter_context_t tfx;
176 progress_filter_context_t *pfx;
177 int do_compress = !!default_compress_algo();
179 pfx = new_progress_context ();
180 memset( &cfx, 0, sizeof cfx);
181 memset( &zfx, 0, sizeof zfx);
182 memset( &tfx, 0, sizeof tfx);
185 /* Prepare iobufs. */
186 inp = iobuf_open(filename);
188 iobuf_ioctl (inp, IOBUF_IOCTL_NO_CACHE, 1, NULL);
189 if (inp && is_secured_file (iobuf_get_fd (inp)))
193 gpg_err_set_errno (EPERM);
197 rc = gpg_error_from_syserror ();
198 log_error(_("can't open '%s': %s\n"), filename? filename: "[stdin]",
200 release_progress_context (pfx);
204 handle_progress (pfx, inp, filename);
207 iobuf_push_filter( inp, text_filter, &tfx );
214 s2k = xmalloc_clear( sizeof *s2k );
215 s2k->mode = opt.s2k_mode;
216 s2k->hash_algo = S2K_DIGEST_ALGO;
217 cfx.dek = passphrase_to_dek (NULL, 0,
218 default_cipher_algo(), s2k, 4,
220 if ( !cfx.dek || !cfx.dek->keylen )
222 rc = gpg_error (canceled? GPG_ERR_CANCELED:GPG_ERR_INV_PASSPHRASE);
226 log_error (_("error creating passphrase: %s\n"), gpg_strerror (rc));
227 release_progress_context (pfx);
230 if (use_seskey && s2k->mode != 1 && s2k->mode != 3)
233 log_info (_("can't use a symmetric ESK packet "
234 "due to the S2K mode\n"));
241 seskeylen = openpgp_cipher_get_algo_keylen (default_cipher_algo ());
242 encrypt_seskey( cfx.dek, &dek, enckey );
243 xfree( cfx.dek ); cfx.dek = dek;
247 log_info(_("using cipher %s\n"),
248 openpgp_cipher_algo_name (cfx.dek->algo));
250 cfx.dek->use_mdc=use_mdc(NULL,cfx.dek->algo);
253 if (do_compress && cfx.dek && cfx.dek->use_mdc
254 && is_file_compressed(filename, &rc))
257 log_info(_("'%s' already compressed\n"), filename);
261 if ( rc || (rc = open_outfile (-1, filename, opt.armor? 1:0, 0, &out )))
266 release_progress_context (pfx);
272 afx = new_armor_context ();
273 push_armor_filter (afx, out);
278 PKT_symkey_enc *enc = xmalloc_clear( sizeof *enc + seskeylen + 1 );
280 enc->cipher_algo = cfx.dek->algo;
282 if ( use_seskey && seskeylen )
284 enc->seskeylen = seskeylen + 1; /* algo id */
285 memcpy (enc->seskey, enckey, seskeylen + 1 );
287 pkt.pkttype = PKT_SYMKEY_ENC;
288 pkt.pkt.symkey_enc = enc;
289 if ((rc = build_packet( out, &pkt )))
290 log_error("build symkey packet failed: %s\n", gpg_strerror (rc) );
295 pt = setup_plaintext_name (filename, inp);
297 /* Note that PGP 5 has problems decrypting symmetrically encrypted
298 data if the file length is in the inner packet. It works when
299 only partial length headers are use. In the past, we always used
300 partial body length here, but since PGP 2, PGP 6, and PGP 7 need
301 the file length, and nobody should be using PGP 5 nowadays
302 anyway, this is now set to the file length. Note also that this
303 only applies to the RFC-1991 style symmetric messages, and not
304 the RFC-2440 style. PGP 6 and 7 work with either partial length
305 or fixed length with the new style messages. */
307 if ( !iobuf_is_pipe_filename (filename) && *filename && !opt.textmode )
312 if ( !(tmpsize = iobuf_get_filelength(inp, &overflow))
313 && !overflow && opt.verbose)
314 log_info(_("WARNING: '%s' is an empty file\n"), filename );
315 /* We can't encode the length of very large files because
316 OpenPGP uses only 32 bit for file sizes. So if the the
317 size of a file is larger than 2^32 minus some bytes for
318 packet headers, we switch to partial length encoding. */
319 if ( tmpsize < (IOBUF_FILELENGTH_LIMIT - 65536) )
325 filesize = opt.set_filesize ? opt.set_filesize : 0; /* stdin */
329 pt->timestamp = make_timestamp();
330 pt->mode = opt.textmode? 't' : 'b';
332 pt->new_ctb = !pt->len;
334 pkt.pkttype = PKT_PLAINTEXT;
335 pkt.pkt.plaintext = pt;
336 cfx.datalen = filesize && !do_compress ? calc_packet_length( &pkt ) : 0;
340 cfx.datalen = filesize && !do_compress ? filesize : 0;
342 pkt.pkt.generic = NULL;
345 /* Register the cipher filter. */
347 iobuf_push_filter ( out, cipher_filter, &cfx );
349 /* Register the compress filter. */
352 if (cfx.dek && cfx.dek->use_mdc)
354 push_compress_filter (out, &zfx, default_compress_algo());
360 if ( (rc = build_packet( out, &pkt )) )
361 log_error("build_packet failed: %s\n", gpg_strerror (rc) );
365 /* User requested not to create a literal packet, so we copy the
367 byte copy_buffer[4096];
369 while ((bytes_copied = iobuf_read(inp, copy_buffer, 4096)) != -1)
370 if ( (rc=iobuf_write(out, copy_buffer, bytes_copied)) ) {
371 log_error ("copying input to output failed: %s\n",
375 wipememory (copy_buffer, 4096); /* burn buffer */
378 /* Finish the stuff. */
384 iobuf_close (out); /* fixme: check returncode */
386 write_status ( STATUS_END_ENCRYPTION );
393 release_armor_context (afx);
394 release_progress_context (pfx);
400 setup_symkey (STRING2KEY **symkey_s2k,DEK **symkey_dek)
404 *symkey_s2k=xmalloc_clear(sizeof(STRING2KEY));
405 (*symkey_s2k)->mode = opt.s2k_mode;
406 (*symkey_s2k)->hash_algo = S2K_DIGEST_ALGO;
408 *symkey_dek=passphrase_to_dek(NULL,0,opt.s2k_cipher_algo,
409 *symkey_s2k, 4, NULL, &canceled);
410 if(!*symkey_dek || !(*symkey_dek)->keylen)
414 return gpg_error (canceled?GPG_ERR_CANCELED:GPG_ERR_BAD_PASSPHRASE);
422 write_symkey_enc (STRING2KEY *symkey_s2k, DEK *symkey_dek, DEK *dek,
425 int rc, seskeylen = openpgp_cipher_get_algo_keylen (dek->algo);
431 enc=xmalloc_clear(sizeof(PKT_symkey_enc)+seskeylen+1);
432 encrypt_seskey(symkey_dek,&dek,enckey);
435 enc->cipher_algo = opt.s2k_cipher_algo;
436 enc->s2k = *symkey_s2k;
437 enc->seskeylen = seskeylen + 1; /* algo id */
438 memcpy( enc->seskey, enckey, seskeylen + 1 );
440 pkt.pkttype = PKT_SYMKEY_ENC;
441 pkt.pkt.symkey_enc = enc;
443 if ((rc=build_packet(out,&pkt)))
444 log_error("build symkey_enc packet failed: %s\n",gpg_strerror (rc));
452 * Encrypt the file with the given userids (or ask if none is
453 * supplied). Either FILENAME or FILEFD must be given, but not both.
454 * The caller may provide a checked list of public keys in
455 * PROVIDED_PKS; if not the function builds a list of keys on its own.
457 * Note that FILEFD is currently only used by cmd_encrypt in the the
458 * not yet finished server.c.
461 encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
462 strlist_t remusr, int use_symkey, pk_list_t provided_keys,
468 PKT_plaintext *pt = NULL;
469 DEK *symkey_dek = NULL;
470 STRING2KEY *symkey_s2k = NULL;
473 cipher_filter_context_t cfx;
474 armor_filter_context_t *afx = NULL;
475 compress_filter_context_t zfx;
476 text_filter_context_t tfx;
477 progress_filter_context_t *pfx;
481 if (filefd != -1 && filename)
482 return gpg_error (GPG_ERR_INV_ARG); /* Both given. */
484 do_compress = !!opt.compress_algo;
486 pfx = new_progress_context ();
487 memset( &cfx, 0, sizeof cfx);
488 memset( &zfx, 0, sizeof zfx);
489 memset( &tfx, 0, sizeof tfx);
493 && (rc=setup_symkey(&symkey_s2k,&symkey_dek)))
495 release_progress_context (pfx);
500 pk_list = provided_keys;
503 if ((rc = build_pk_list (ctrl, remusr, &pk_list, PUBKEY_USAGE_ENC)))
505 release_progress_context (pfx);
510 /* Prepare iobufs. */
511 #ifdef HAVE_W32_SYSTEM
513 inp = iobuf_open (filename);
517 gpg_err_set_errno (ENOSYS);
520 if (filefd == GNUPG_INVALID_FD)
521 inp = iobuf_open (filename);
523 inp = iobuf_fdopen_nc (FD2INT(filefd), "rb");
526 iobuf_ioctl (inp, IOBUF_IOCTL_NO_CACHE, 1, NULL);
527 if (inp && is_secured_file (iobuf_get_fd (inp)))
531 gpg_err_set_errno (EPERM);
537 rc = gpg_error_from_syserror ();
539 snprintf (xname, sizeof xname, "[fd %d]", filefd);
541 strcpy (xname, "[stdin]");
544 log_error (_("can't open '%s': %s\n"),
545 *xname? xname : filename, gpg_strerror (rc) );
550 log_info (_("reading from '%s'\n"), iobuf_get_fname_nonnull (inp));
552 handle_progress (pfx, inp, filename);
555 iobuf_push_filter (inp, text_filter, &tfx);
557 rc = open_outfile (outputfd, filename, opt.armor? 1:0, 0, &out);
563 afx = new_armor_context ();
564 push_armor_filter (afx, out);
567 /* Create a session key. */
568 cfx.dek = xmalloc_secure_clear (sizeof *cfx.dek);
569 if (!opt.def_cipher_algo)
571 /* Try to get it from the prefs. */
572 cfx.dek->algo = select_algo_from_prefs (pk_list, PREFTYPE_SYM, -1, NULL);
573 /* The only way select_algo_from_prefs can fail here is when
574 mixing v3 and v4 keys, as v4 keys have an implicit preference
575 entry for 3DES, and the pk_list cannot be empty. In this
576 case, use 3DES anyway as it's the safest choice - perhaps the
577 v3 key is being used in an OpenPGP implementation and we know
578 that the implementation behind any v4 key can handle 3DES. */
579 if (cfx.dek->algo == -1)
581 cfx.dek->algo = CIPHER_ALGO_3DES;
584 /* In case 3DES has been selected, print a warning if any key
585 does not have a preference for AES. This should help to
586 indentify why encrypting to several recipients falls back to
588 if (opt.verbose && cfx.dek->algo == CIPHER_ALGO_3DES)
589 warn_missing_aes_from_pklist (pk_list);
594 && (select_algo_from_prefs (pk_list, PREFTYPE_SYM,
595 opt.def_cipher_algo, NULL)
596 != opt.def_cipher_algo))
598 log_info(_("WARNING: forcing symmetric cipher %s (%d)"
599 " violates recipient preferences\n"),
600 openpgp_cipher_algo_name (opt.def_cipher_algo),
601 opt.def_cipher_algo);
604 cfx.dek->algo = opt.def_cipher_algo;
607 cfx.dek->use_mdc = use_mdc (pk_list,cfx.dek->algo);
609 /* Only do the is-file-already-compressed check if we are using a
610 MDC. This forces compressed files to be re-compressed if we do
611 not have a MDC to give some protection against chosen ciphertext
614 if (do_compress && cfx.dek->use_mdc && is_file_compressed(filename, &rc2))
617 log_info(_("'%s' already compressed\n"), filename);
626 make_session_key (cfx.dek);
628 log_printhex ("DEK is: ", cfx.dek->key, cfx.dek->keylen );
630 rc = write_pubkey_enc_from_list (pk_list, cfx.dek, out);
634 /* We put the passphrase (if any) after any public keys as this
635 seems to be the most useful on the recipient side - there is no
636 point in prompting a user for a passphrase if they have the
637 secret key needed to decrypt. */
638 if(use_symkey && (rc = write_symkey_enc(symkey_s2k,symkey_dek,cfx.dek,out)))
642 pt = setup_plaintext_name (filename, inp);
644 /* Get the size of the file if possible, i.e., if it is a real file. */
645 if (filename && *filename
646 && !iobuf_is_pipe_filename (filename) && !opt.textmode )
651 if ( !(tmpsize = iobuf_get_filelength(inp, &overflow))
652 && !overflow && opt.verbose)
653 log_info(_("WARNING: '%s' is an empty file\n"), filename );
654 /* We can't encode the length of very large files because
655 OpenPGP uses only 32 bit for file sizes. So if the the size
656 of a file is larger than 2^32 minus some bytes for packet
657 headers, we switch to partial length encoding. */
658 if (tmpsize < (IOBUF_FILELENGTH_LIMIT - 65536) )
664 filesize = opt.set_filesize ? opt.set_filesize : 0; /* stdin */
668 pt->timestamp = make_timestamp();
669 pt->mode = opt.textmode ? 't' : 'b';
671 pt->new_ctb = !pt->len;
673 pkt.pkttype = PKT_PLAINTEXT;
674 pkt.pkt.plaintext = pt;
675 cfx.datalen = filesize && !do_compress? calc_packet_length( &pkt ) : 0;
678 cfx.datalen = filesize && !do_compress ? filesize : 0;
680 /* Register the cipher filter. */
681 iobuf_push_filter (out, cipher_filter, &cfx);
683 /* Register the compress filter. */
686 int compr_algo = opt.compress_algo;
688 if (compr_algo == -1)
690 compr_algo = select_algo_from_prefs (pk_list, PREFTYPE_ZIP, -1, NULL);
691 if (compr_algo == -1)
692 compr_algo = DEFAULT_COMPRESS_ALGO;
693 /* Theoretically impossible to get here since uncompressed
697 && select_algo_from_prefs(pk_list, PREFTYPE_ZIP,
698 compr_algo, NULL) != compr_algo)
700 log_info (_("WARNING: forcing compression algorithm %s (%d)"
701 " violates recipient preferences\n"),
702 compress_algo_to_string(compr_algo), compr_algo);
705 /* Algo 0 means no compression. */
708 if (cfx.dek && cfx.dek->use_mdc)
710 push_compress_filter (out,&zfx,compr_algo);
717 if ((rc = build_packet( out, &pkt )))
718 log_error ("build_packet failed: %s\n", gpg_strerror (rc));
722 /* User requested not to create a literal packet, so we copy the
724 byte copy_buffer[4096];
726 while ((bytes_copied = iobuf_read (inp, copy_buffer, 4096)) != -1)
728 rc = iobuf_write (out, copy_buffer, bytes_copied);
731 log_error ("copying input to output failed: %s\n",
736 wipememory (copy_buffer, 4096); /* Burn the buffer. */
739 /* Finish the stuff. */
746 iobuf_close (out); /* fixme: check returncode */
747 write_status (STATUS_END_ENCRYPTION);
756 release_pk_list (pk_list);
757 release_armor_context (afx);
758 release_progress_context (pfx);
764 * Filter to do a complete public key encryption.
767 encrypt_filter (void *opaque, int control,
768 iobuf_t a, byte *buf, size_t *ret_len)
770 size_t size = *ret_len;
771 encrypt_filter_context_t *efx = opaque;
774 if (control == IOBUFCTRL_UNDERFLOW) /* decrypt */
776 BUG(); /* not used */
778 else if ( control == IOBUFCTRL_FLUSH ) /* encrypt */
780 if ( !efx->header_okay )
782 efx->cfx.dek = xmalloc_secure_clear ( sizeof *efx->cfx.dek );
783 if ( !opt.def_cipher_algo )
785 /* Try to get it from the prefs. */
787 select_algo_from_prefs (efx->pk_list, PREFTYPE_SYM, -1, NULL);
788 if (efx->cfx.dek->algo == -1 )
790 /* Because 3DES is implicitly in the prefs, this can
791 only happen if we do not have any public keys in
793 efx->cfx.dek->algo = DEFAULT_CIPHER_ALGO;
796 /* In case 3DES has been selected, print a warning if
797 any key does not have a preference for AES. This
798 should help to indentify why encrypting to several
799 recipients falls back to 3DES. */
801 && efx->cfx.dek->algo == CIPHER_ALGO_3DES)
802 warn_missing_aes_from_pklist (efx->pk_list);
807 && select_algo_from_prefs (efx->pk_list,PREFTYPE_SYM,
809 NULL) != opt.def_cipher_algo)
810 log_info(_("forcing symmetric cipher %s (%d) "
811 "violates recipient preferences\n"),
812 openpgp_cipher_algo_name (opt.def_cipher_algo),
813 opt.def_cipher_algo);
815 efx->cfx.dek->algo = opt.def_cipher_algo;
818 efx->cfx.dek->use_mdc = use_mdc (efx->pk_list,efx->cfx.dek->algo);
820 make_session_key ( efx->cfx.dek );
822 log_printhex ("DEK is: ", efx->cfx.dek->key, efx->cfx.dek->keylen);
824 rc = write_pubkey_enc_from_list (efx->pk_list, efx->cfx.dek, a);
828 if(efx->symkey_s2k && efx->symkey_dek)
830 rc=write_symkey_enc(efx->symkey_s2k,efx->symkey_dek,
836 iobuf_push_filter (a, cipher_filter, &efx->cfx);
838 efx->header_okay = 1;
840 rc = iobuf_write (a, buf, size);
843 else if (control == IOBUFCTRL_FREE)
845 xfree (efx->symkey_dek);
846 xfree (efx->symkey_s2k);
848 else if ( control == IOBUFCTRL_DESC )
850 *(char**)buf = "encrypt_filter";
857 * Write pubkey-enc packets from the list of PKs to OUT.
860 write_pubkey_enc_from_list (PK_LIST pk_list, DEK *dek, iobuf_t out)
867 for ( ; pk_list; pk_list = pk_list->next )
873 print_pubkey_algo_note ( pk->pubkey_algo );
874 enc = xmalloc_clear ( sizeof *enc );
875 enc->pubkey_algo = pk->pubkey_algo;
876 keyid_from_pk( pk, enc->keyid );
877 enc->throw_keyid = (opt.throw_keyids || (pk_list->flags&1));
879 if (opt.throw_keyids && (PGP6 || PGP7 || PGP8))
881 log_info(_("you may not use %s while in %s mode\n"),
882 "--throw-keyids",compliance_option_string());
883 compliance_failure();
886 /* Okay, what's going on: We have the session key somewhere in
887 * the structure DEK and want to encode this session key in an
888 * integer value of n bits. pubkey_nbits gives us the number of
889 * bits we have to use. We then encode the session key in some
890 * way and we get it back in the big intger value FRAME. Then
891 * we use FRAME, the public key PK->PKEY and the algorithm
892 * number PK->PUBKEY_ALGO and pass it to pubkey_encrypt which
893 * returns the encrypted value in the array ENC->DATA. This
894 * array has a size which depends on the used algorithm (e.g. 2
895 * for Elgamal). We don't need frame anymore because we have
896 * everything now in enc->data which is the passed to
898 frame = encode_session_key (pk->pubkey_algo, dek,
899 pubkey_nbits (pk->pubkey_algo, pk->pkey));
900 rc = pk_encrypt (pk->pubkey_algo, enc->data, frame, pk, pk->pkey);
901 gcry_mpi_release (frame);
903 log_error ("pubkey_encrypt failed: %s\n", gpg_strerror (rc) );
908 char *ustr = get_user_id_string_native (enc->keyid);
909 log_info (_("%s/%s encrypted for: \"%s\"\n"),
910 openpgp_pk_algo_name (enc->pubkey_algo),
911 openpgp_cipher_algo_name (dek->algo),
917 pkt.pkttype = PKT_PUBKEY_ENC;
918 pkt.pkt.pubkey_enc = enc;
919 rc = build_packet (out, &pkt);
921 log_error ("build_packet(pubkey_enc) failed: %s\n",
924 free_pubkey_enc(enc);
933 encrypt_crypt_files (ctrl_t ctrl, int nfiles, char **files, strlist_t remusr)
939 log_error(_("--output doesn't work for this command\n"));
946 unsigned int lno = 0;
947 while ( fgets(line, DIM(line), stdin) )
950 if (!*line || line[strlen(line)-1] != '\n')
952 log_error("input line %u too long or missing LF\n", lno);
955 line[strlen(line)-1] = '\0';
956 print_file_status(STATUS_FILE_START, line, 2);
957 rc = encrypt_crypt (ctrl, -1, line, remusr, 0, NULL, -1);
959 log_error ("encryption of '%s' failed: %s\n",
960 print_fname_stdin(line), gpg_strerror (rc) );
961 write_status( STATUS_FILE_DONE );
968 print_file_status(STATUS_FILE_START, *files, 2);
969 if ( (rc = encrypt_crypt (ctrl, -1, *files, remusr, 0, NULL, -1)) )
970 log_error("encryption of '%s' failed: %s\n",
971 print_fname_stdin(*files), gpg_strerror (rc) );
972 write_status( STATUS_FILE_DONE );