diff options
Diffstat (limited to 'g10/encr-data.c')
-rw-r--r-- | g10/encr-data.c | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/g10/encr-data.c b/g10/encr-data.c index c559299ff..602ae55aa 100644 --- a/g10/encr-data.c +++ b/g10/encr-data.c @@ -1,6 +1,6 @@ /* encr-data.c - process an encrypted data packet * Copyright (C) 1998, 1999, 2000, 2001, 2005, - * 2006, 2009 Free Software Foundation, Inc. + * 2006, 2009, 2012 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -30,6 +30,7 @@ #include "cipher.h" #include "options.h" #include "i18n.h" +#include "status.h" static int mdc_decode_filter ( void *opaque, int control, IOBUF a, @@ -80,7 +81,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) byte temp[32]; unsigned blocksize; unsigned nprefix; - + dfx = xtrycalloc (1, sizeof *dfx); if (!dfx) return gpg_error_from_syserror (); @@ -89,12 +90,20 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) if ( opt.verbose && !dek->algo_info_printed ) { if (!openpgp_cipher_test_algo (dek->algo)) - log_info (_("%s encrypted data\n"), + log_info (_("%s encrypted data\n"), openpgp_cipher_algo_name (dek->algo)); else log_info (_("encrypted with unknown algorithm %d\n"), dek->algo ); dek->algo_info_printed = 1; } + + { + char buf[20]; + + snprintf (buf, sizeof buf, "%d %d", ed->mdc_method, dek->algo); + write_status_text (STATUS_DECRYPTION_INFO, buf); + } + rc = openpgp_cipher_test_algo (dek->algo); if (rc) goto leave; @@ -105,7 +114,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) if ( ed->len && ed->len < (nprefix+2) ) BUG(); - if ( ed->mdc_method ) + if ( ed->mdc_method ) { if (gcry_md_open (&dfx->mdc_hash, ed->mdc_method, 0 )) BUG (); @@ -140,7 +149,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) goto leave; } - if (!ed->buf) + if (!ed->buf) { log_error(_("problem handling encrypted packet\n")); goto leave; @@ -150,7 +159,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) if ( ed->len ) { - for (i=0; i < (nprefix+2) && ed->len; i++, ed->len-- ) + for (i=0; i < (nprefix+2) && ed->len; i++, ed->len-- ) { if ( (c=iobuf_get(ed->buf)) == -1 ) break; @@ -158,7 +167,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) temp[i] = c; } } - else + else { for (i=0; i < (nprefix+2); i++ ) if ( (c=iobuf_get(ed->buf)) == -1 ) @@ -166,7 +175,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) else temp[i] = c; } - + gcry_cipher_decrypt (dfx->cipher_hd, temp, nprefix+2, NULL, 0); gcry_cipher_sync (dfx->cipher_hd); p = temp; @@ -177,7 +186,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) rc = gpg_error (GPG_ERR_BAD_KEY); goto leave; } - + if ( dfx->mdc_hash ) gcry_md_write (dfx->mdc_hash, temp, nprefix+2); @@ -192,7 +201,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) if ( ed->mdc_method && dfx->eof_seen == 2 ) rc = gpg_error (GPG_ERR_INV_PACKET); else if ( ed->mdc_method ) - { + { /* We used to let parse-packet.c handle the MDC packet but this turned out to be a problem with compressed packets: With old style packets there is no length information available and @@ -226,8 +235,8 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) /* log_printhex("MDC message:", dfx->defer, 22); */ /* log_printhex("MDC calc:", gcry_md_read (dfx->mdc_hash,0), datalen); */ } - - + + leave: release_dfx_context (dfx); return rc; @@ -244,7 +253,7 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, size_t n, size = *ret_len; int rc = 0; int c; - + if ( control == IOBUFCTRL_UNDERFLOW && dfx->eof_seen ) { *ret_len = 0; @@ -254,7 +263,7 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, { assert (a); assert ( size > 44 ); - + /* Get at least 22 bytes and put it somewhere ahead in the buffer. */ for (n=22; n < 44 ; n++ ) { @@ -262,7 +271,7 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, break; buf[n] = c; } - if ( n == 44 ) + if ( n == 44 ) { /* We have enough stuff - flush the deferred stuff. */ /* (we asserted that the buffer is large enough) */ @@ -276,7 +285,7 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, memcpy (buf, dfx->defer, 22 ); } /* Now fill up. */ - for (; n < size; n++ ) + for (; n < size; n++ ) { if ( (c = iobuf_get(a)) == -1 ) break; @@ -317,11 +326,11 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, } *ret_len = n; } - else if ( control == IOBUFCTRL_FREE ) + else if ( control == IOBUFCTRL_FREE ) { release_dfx_context (dfx); } - else if ( control == IOBUFCTRL_DESC ) + else if ( control == IOBUFCTRL_DESC ) { *(char**)buf = "mdc_decode_filter"; } @@ -335,8 +344,8 @@ decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len) decode_filter_ctx_t fc = opaque; size_t n, size = *ret_len; int rc = 0; - - if ( control == IOBUFCTRL_UNDERFLOW ) + + if ( control == IOBUFCTRL_UNDERFLOW ) { assert(a); n = iobuf_read ( a, buf, size ); @@ -351,7 +360,7 @@ decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len) rc = -1; /* EOF */ *ret_len = n; } - else if ( control == IOBUFCTRL_FREE ) + else if ( control == IOBUFCTRL_FREE ) { release_dfx_context (fc); } |