mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
See ChangeLog: Mon Jun 5 12:37:43 CEST 2000 Werner Koch
This commit is contained in:
parent
a74c85b4a0
commit
b65f9a8b0d
21 changed files with 201 additions and 82 deletions
31
g10/cipher.c
31
g10/cipher.c
|
@ -49,22 +49,27 @@ write_header( cipher_filter_context_t *cfx, IOBUF a )
|
|||
unsigned nprefix;
|
||||
int use_mdc = opt.force_mdc;
|
||||
|
||||
blocksize = cipher_get_blocksize( cfx->dek->algo );
|
||||
if( blocksize < 8 || blocksize > 16 )
|
||||
log_fatal("unsupported blocksize %u\n", blocksize );
|
||||
if( blocksize != 8 )
|
||||
use_mdc = 1; /* enable it for all modern ciphers */
|
||||
if( opt.rfc2440 )
|
||||
use_mdc = 0; /* override - rfc2440 does not know about 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" );*/
|
||||
/*md_start_debug( cfx->mdc_hash, "creatmdc" );*/
|
||||
}
|
||||
init_packet( &pkt );
|
||||
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");
|
||||
blocksize = cipher_get_blocksize( cfx->dek->algo );
|
||||
if( blocksize < 8 || blocksize > 16 )
|
||||
log_fatal("unsupported blocksize %u\n", blocksize );
|
||||
nprefix = blocksize;
|
||||
randomize_buffer( temp, nprefix, 1 );
|
||||
temp[nprefix] = temp[nprefix-2];
|
||||
|
@ -75,8 +80,6 @@ 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);
|
||||
|
@ -115,12 +118,22 @@ cipher_filter( void *opaque, int control,
|
|||
if( cfx->mdc_hash ) {
|
||||
byte *hash;
|
||||
int hashlen = md_digest_length( md_get_algo( cfx->mdc_hash ) );
|
||||
byte temp[22];
|
||||
|
||||
assert( hashlen == 20 );
|
||||
/* we must hash the prefix of the MDC packet here */
|
||||
temp[0] = 0xd3;
|
||||
temp[1] = 0x14;
|
||||
md_putc( cfx->mdc_hash, temp[0] );
|
||||
md_putc( cfx->mdc_hash, temp[1] );
|
||||
|
||||
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;
|
||||
memcpy(temp+2, hash, 20);
|
||||
cipher_encrypt( cfx->cipher_hd, temp, temp, 22 );
|
||||
md_close( cfx->mdc_hash ); cfx->mdc_hash = NULL;
|
||||
if( iobuf_write( a, temp, 22 ) )
|
||||
log_error("writing MDC packet failed\n" );
|
||||
}
|
||||
cipher_close(cfx->cipher_hd);
|
||||
write_status( STATUS_END_ENCRYPTION );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue