summaryrefslogtreecommitdiffstats
path: root/g10/cipher.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1999-05-17 22:03:24 +0200
committerWerner Koch <wk@gnupg.org>1999-05-17 22:03:24 +0200
commit3983f30bd2f671d4f7c5bbe39a1d6a7b191f2af5 (patch)
treeef2ea1a332a2e954d1c5c86b66570da8fa6935b6 /g10/cipher.c
parentSee ChangeLog: Sat May 8 19:28:33 CEST 1999 Werner Koch (diff)
downloadgnupg2-3983f30bd2f671d4f7c5bbe39a1d6a7b191f2af5.tar.xz
gnupg2-3983f30bd2f671d4f7c5bbe39a1d6a7b191f2af5.zip
See ChangeLog: Mon May 17 21:54:43 CEST 1999 Werner Koch
Diffstat (limited to 'g10/cipher.c')
-rw-r--r--g10/cipher.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/g10/cipher.c b/g10/cipher.c
index f0564e36d..0de2a9d90 100644
--- a/g10/cipher.c
+++ b/g10/cipher.c
@@ -46,12 +46,18 @@ write_header( cipher_filter_context_t *cfx, IOBUF a )
byte temp[18];
unsigned blocksize;
unsigned nprefix;
+ int use_mdc = opt.force_mdc;
memset( &ed, 0, sizeof ed );
ed.len = cfx->datalen;
ed.new_ctb = !ed.len && !opt.rfc1991;
+ if( use_mdc ) {
+ ed.mdc_method = DIGEST_ALGO_SHA1;
+ cfx->mdc_hash = md_open( DIGEST_ALGO_SHA1, 0 );
+ md_start_debug( cfx->mdc_hash, "mdccreat" );
+ }
init_packet( &pkt );
- pkt.pkttype = PKT_ENCRYPTED;
+ pkt.pkttype = use_mdc? PKT_ENCRYPTED_MDC : PKT_ENCRYPTED;
pkt.pkt.encrypted = &ed;
if( build_packet( a, &pkt ))
log_bug("build_packet(ENCR_DATA) failed\n");
@@ -68,6 +74,8 @@ write_header( cipher_filter_context_t *cfx, IOBUF a )
cipher_setkey( cfx->cipher_hd, cfx->dek->key, cfx->dek->keylen );
cipher_setiv( cfx->cipher_hd, NULL, 0 );
/* log_hexdump( "prefix", temp, nprefix+2 ); */
+ if( cfx->mdc_hash )
+ md_write( cfx->mdc_hash, temp, nprefix+2 );
cipher_encrypt( cfx->cipher_hd, temp, temp, nprefix+2);
cipher_sync( cfx->cipher_hd );
iobuf_write(a, temp, nprefix+2);
@@ -75,6 +83,7 @@ write_header( cipher_filter_context_t *cfx, IOBUF a )
}
+
/****************
* This filter is used to en/de-cipher data with a conventional algorithm
*/
@@ -94,11 +103,23 @@ cipher_filter( void *opaque, int control,
if( !cfx->header ) {
write_header( cfx, a );
}
+ if( cfx->mdc_hash )
+ md_write( cfx->mdc_hash, buf, size );
cipher_encrypt( cfx->cipher_hd, buf, buf, size);
if( iobuf_write( a, buf, size ) )
rc = G10ERR_WRITE_FILE;
}
else if( control == IOBUFCTRL_FREE ) {
+ if( cfx->mdc_hash ) {
+ byte *hash;
+ int hashlen = md_digest_length( md_get_algo( cfx->mdc_hash ) );
+ md_final( cfx->mdc_hash );
+ hash = md_read( cfx->mdc_hash, 0 );
+ cipher_encrypt( cfx->cipher_hd, hash, hash, hashlen );
+ if( iobuf_write( a, hash, hashlen ) )
+ rc = G10ERR_WRITE_FILE;
+ md_close( cfx->mdc_hash ); cfx->mdc_hash = NULL;
+ }
cipher_close(cfx->cipher_hd);
}
else if( control == IOBUFCTRL_DESC ) {
@@ -108,5 +129,3 @@ cipher_filter( void *opaque, int control,
}
-
-