1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

compress stuff implemented

This commit is contained in:
Werner Koch 1997-11-23 15:38:27 +00:00
parent 2f3cb7e30a
commit db19a27518
16 changed files with 445 additions and 227 deletions

View File

@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = util mpi cipher tools g10 psst
SUBDIRS = util mpi cipher tools g10
EXTRA_DIST =

View File

@ -38,15 +38,15 @@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
SUBDIRS = util mpi cipher tools g10 psst
SUBDIRS = util mpi cipher tools g10
EXTRA_DIST =
ACCONFIG = acconfig.h
CONFIG_HEADER_IN = config.h.in
mkinstalldirs = $(top_srcdir)/scripts/mkinstalldirs
CONFIG_HEADER = ./config.h
DIST_COMMON = README AUTHORS COPYING ChangeLog INSTALL Makefile.am \
Makefile.in NEWS README acconfig.h config.h.in configure configure.in \
stamp-h.in
Makefile.in NEWS README TODO acconfig.h config.h.in configure \
configure.in stamp-h.in
PACKAGE = @PACKAGE@

2
TODO
View File

@ -15,7 +15,6 @@
* add writing of signatures and checking of detached signatures.
* add option file handling.
* use correct ASN values for DEK encoding
* add compress handling
* add checking of armor trailers
* fix the memory stuff (secure memory)
* add real secure memory
@ -27,4 +26,5 @@
* remove all "Fixmes"
* add credits for the MPI lib.
* speed up the RIPE-MD-160
* enable a SIGSEGV handler while using zlib functions

View File

@ -62,4 +62,7 @@
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define if you have the <zlib.h> header file. */
#undef HAVE_ZLIB_H
#endif /*G10_CONFIG_H*/

View File

@ -37,6 +37,7 @@ dnl Checks for libraries.
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(zlib.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
@ -57,7 +58,7 @@ else
fi
AC_OUTPUT([ Makefile util/Makefile mpi/Makefile cipher/Makefile \
g10/Makefile tools/Makefile psst/Makefile ],
g10/Makefile tools/Makefile ],
[echo timestamp > stamp-h ])

View File

@ -6,7 +6,7 @@ bin_PROGRAMS = g10
g10_SOURCES = g10.c \
build-packet.c \
compressed.c \
compress.c \
encode.c \
encr-data.c \
filter.h \
@ -18,6 +18,7 @@ g10_SOURCES = g10.c \
mainproc.c \
armor.c \
mdfilter.c \
cipher.c \
options.h \
overwrite.c \
packet.h \
@ -30,7 +31,7 @@ g10_SOURCES = g10.c \
sig-check.c
LDADD = -L ../cipher -L ../mpi -L ../util -lcipher -lmpi -lutil
LDADD = -L ../cipher -L ../mpi -L ../util -lcipher -lmpi -lutil -lz
$(PROGRAMS): ../cipher/libcipher.a ../mpi/libmpi.a

View File

@ -44,7 +44,7 @@ bin_PROGRAMS = g10
g10_SOURCES = g10.c \
build-packet.c \
compressed.c \
compress.c \
encode.c \
encr-data.c \
filter.h \
@ -56,6 +56,7 @@ g10_SOURCES = g10.c \
mainproc.c \
armor.c \
mdfilter.c \
cipher.c \
options.h \
overwrite.c \
packet.h \
@ -67,7 +68,7 @@ g10_SOURCES = g10.c \
seskey.c \
sig-check.c
LDADD = -L ../cipher -L ../mpi -L ../util -lcipher -lmpi -lutil
LDADD = -L ../cipher -L ../mpi -L ../util -lcipher -lmpi -lutil -lz
mkinstalldirs = $(top_srcdir)/scripts/mkinstalldirs
CONFIG_HEADER = ../config.h
PROGRAMS = $(bin_PROGRAMS)
@ -85,8 +86,8 @@ LIBS = @LIBS@
COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
LINK = $(CC) $(LDFLAGS) -o $@
g10_OBJECTS = g10.o build-packet.o compressed.o encode.o encr-data.o \
free-packet.o getkey.o keygen.o mainproc.o armor.o mdfilter.o \
g10_OBJECTS = g10.o build-packet.o compress.o encode.o encr-data.o \
free-packet.o getkey.o keygen.o mainproc.o armor.o mdfilter.o cipher.o \
overwrite.o parse-packet.o passphrase.o plaintext.o pubkey-enc.o \
seckey-cert.o seskey.o sig-check.o
EXTRA_g10_SOURCES =
@ -104,9 +105,10 @@ DEP_DISTFILES = $(DIST_COMMON) $(SOURCES) $(BUILT_SOURCES) $(HEADERS) \
TAR = tar
DEP_FILES = $(srcdir)/.deps/armor.P $(srcdir)/.deps/build-packet.P \
$(srcdir)/.deps/compressed.P $(srcdir)/.deps/encode.P \
$(srcdir)/.deps/encr-data.P $(srcdir)/.deps/free-packet.P \
$(srcdir)/.deps/g10.P $(srcdir)/.deps/getkey.P $(srcdir)/.deps/keygen.P \
$(srcdir)/.deps/cipher.P $(srcdir)/.deps/compress.P \
$(srcdir)/.deps/encode.P $(srcdir)/.deps/encr-data.P \
$(srcdir)/.deps/free-packet.P $(srcdir)/.deps/g10.P \
$(srcdir)/.deps/getkey.P $(srcdir)/.deps/keygen.P \
$(srcdir)/.deps/mainproc.P $(srcdir)/.deps/mdfilter.P \
$(srcdir)/.deps/overwrite.P $(srcdir)/.deps/parse-packet.P \
$(srcdir)/.deps/passphrase.P $(srcdir)/.deps/plaintext.P \

View File

@ -42,11 +42,13 @@ static int do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc );
static u32 calc_plaintext( PKT_plaintext *pt );
static int do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt );
static int do_encr_data( IOBUF out, int ctb, PKT_encr_data *ed );
static int do_compressed( IOBUF out, int ctb, PKT_compressed *cd );
static int calc_header_length( u32 len );
static int write_16(IOBUF inp, u16 a);
static int write_32(IOBUF inp, u32 a);
static int write_header( IOBUF out, int ctb, u32 len );
static int write_header2( IOBUF out, int ctb, u32 len, int blkmode );
static int write_version( IOBUF out, int ctb );
/****************
@ -86,9 +88,11 @@ build_packet( IOBUF out, PACKET *pkt )
case PKT_ENCR_DATA:
rc = do_encr_data( out, ctb, pkt->pkt.encr_data );
break;
case PKT_COMPR_DATA:
rc = do_compressed( out, ctb, pkt->pkt.compressed );
break;
case PKT_SIGNATURE:
case PKT_RING_TRUST:
case PKT_COMPR_DATA:
default:
log_bug("invalid packet type in build_packet()");
break;
@ -304,6 +308,20 @@ do_encr_data( IOBUF out, int ctb, PKT_encr_data *ed )
return rc;
}
static int
do_compressed( IOBUF out, int ctb, PKT_compressed *cd )
{
int rc = 0;
/* we must use the old convention and don't use blockmode */
write_header2(out, ctb, 0, 0 );
iobuf_put(out, cd->algorithm );
/* This is all. The caller has to write the real data */
return rc;
}
@ -349,6 +367,12 @@ calc_header_length( u32 len )
*/
static int
write_header( IOBUF out, int ctb, u32 len )
{
return write_header2( out, ctb, len, 1 );
}
static int
write_header2( IOBUF out, int ctb, u32 len, int blkmode )
{
if( !len )
ctb |= 3;
@ -361,6 +385,7 @@ write_header( IOBUF out, int ctb, u32 len )
if( iobuf_put(out, ctb ) )
return -1;
if( !len ) {
if( blkmode )
iobuf_set_block_mode(out, 8196 );
}
else {

100
g10/cipher.c Normal file
View File

@ -0,0 +1,100 @@
/* cipher.c - En-/De-ciphering filter
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include "errors.h"
#include "iobuf.h"
#include "memory.h"
#include "util.h"
#include "filter.h"
#include "packet.h"
#include "options.h"
/****************
* This filter is used to en/de-cipher data.
*/
int
cipher_filter( void *opaque, int control,
IOBUF a, byte *buf, size_t *ret_len)
{
size_t size = *ret_len;
cipher_filter_context_t *cfx = opaque;
int rc=0;
if( control == IOBUFCTRL_UNDERFLOW ) { /* decipher */
rc = -1; /* FIXME:*/
}
else if( control == IOBUFCTRL_FLUSH ) { /* encipher */
assert(a);
if( !cfx->header ) {
PACKET pkt;
PKT_encr_data ed;
byte temp[10];
memset( &ed, 0, sizeof ed );
ed.len = cfx->datalen;
init_packet( &pkt );
pkt.pkttype = PKT_ENCR_DATA;
pkt.pkt.encr_data = &ed;
if( build_packet( a, &pkt ))
log_bug("build_packet(ENCR_DATA) failed\n");
randomize_buffer( temp, 8, 1 );
temp[8] = temp[6];
temp[9] = temp[7];
if( cfx->dek->algo == CIPHER_ALGO_BLOWFISH ) {
cfx->bf_ctx = m_alloc_secure( sizeof *cfx->bf_ctx );
blowfish_setkey( cfx->bf_ctx, cfx->dek->key, cfx->dek->keylen );
blowfish_setiv( cfx->bf_ctx, NULL );
blowfish_encode_cfb( cfx->bf_ctx, temp, temp, 10);
}
else
log_bug("no cipher algo %d\n", cfx->dek->algo);
iobuf_write(a, temp, 10);
cfx->header=1;
}
if( cfx->dek->algo == CIPHER_ALGO_BLOWFISH )
blowfish_encode_cfb( cfx->bf_ctx, buf, buf, size);
if( iobuf_write( a, buf, size ) )
rc = G10ERR_WRITE_FILE;
}
else if( control == IOBUFCTRL_FREE ) {
if( cfx->dek->algo == CIPHER_ALGO_BLOWFISH )
m_free(cfx->bf_ctx);
}
else if( control == IOBUFCTRL_DESC ) {
*(char**)buf = "cipher_filter";
}
return rc;
}

253
g10/compress.c Normal file
View File

@ -0,0 +1,253 @@
/* compress.c - compress filter
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#ifdef HAVE_ZLIB_H
#include <zlib.h>
#else
#error You need ZLIB to compile this module
#endif
#include "util.h"
#include "memory.h"
#include "packet.h"
#include "filter.h"
#include "options.h"
static void
init_compress( compress_filter_context_t *zfx, z_stream *zs )
{
int rc;
byte *inbuf, *outbuf;
int level;
if( opt.compress >= 0 && opt.compress <= 9 )
level = opt.compress;
else if( opt.compress == -1 )
level = Z_DEFAULT_COMPRESSION;
else if( opt.compress == 10 ) /* remove this ! */
level = 0;
else {
log_error("invalid compression level; using default level\n");
level = Z_DEFAULT_COMPRESSION;
}
if( (rc = deflateInit( zs, level )) != Z_OK ) {
log_fatal("zlib problem: %s\n", zs->msg? zs->msg :
rc == Z_MEM_ERROR ? "out of core" :
rc == Z_VERSION_ERROR ? "invalid lib version" :
"unknown error" );
}
zfx->outbufsize = 4096;
zfx->outbuf = m_alloc( zfx->outbufsize );
}
static int
do_compress( compress_filter_context_t *zfx, z_stream *zs, int flush, IOBUF a )
{
int zrc;
unsigned n;
do {
zs->next_out = zfx->outbuf;
zs->avail_out = zfx->outbufsize;
zrc = deflate( zs, flush );
if( zrc == Z_STREAM_END && flush == Z_FINISH )
;
else if( zrc != Z_OK ) {
if( zs->msg )
log_fatal("zlib deflate problem: %s\n", zs->msg );
else
log_fatal("zlib deflate problem: rc=%d\n", zrc );
}
n = zfx->outbufsize - zs->avail_out;
if( DBG_FILTER )
log_debug("deflate returned: avail_in=%u, avail_out=%u, n=%u\n",
(unsigned)zs->avail_in, (unsigned)zs->avail_out, (unsigned)n );
if( iobuf_write( a, zfx->outbuf, n ) ) {
log_debug("deflate: iobuf_write failed\n");
return G10ERR_WRITE_FILE;
}
} while( zs->avail_in || (flush == Z_FINISH && zrc != Z_STREAM_END) );
return 0;
}
static void
init_uncompress( compress_filter_context_t *zfx, z_stream *zs )
{
int rc;
byte *inbuf, *outbuf;
int level;
if( (rc = inflateInit( zs )) != Z_OK ) {
log_fatal("zlib problem: %s\n", zs->msg? zs->msg :
rc == Z_MEM_ERROR ? "out of core" :
rc == Z_VERSION_ERROR ? "invalid lib version" :
"unknown error" );
}
zfx->inbufsize = 1024;
zfx->inbuf = m_alloc( zfx->inbufsize );
zs->avail_in = 0;
}
static int
do_uncompress( compress_filter_context_t *zfx, z_stream *zs,
IOBUF a, size_t *ret_len )
{
int zrc;
size_t n;
byte *p;
int c;
if( DBG_FILTER )
log_debug("do_uncompress: avail_in=%u, avail_out=%u\n",
(unsigned)zs->avail_in, (unsigned)zs->avail_out);
do {
if( zs->avail_in < zfx->inbufsize ) {
n = zs->avail_in;
if( !n )
zs->next_in = zfx->inbuf;
for( p=zfx->inbuf+n; n < zfx->inbufsize; n++, p++ ) {
if( (c=iobuf_get(a)) == -1 )
break;
*p = c & 0xff;
}
zs->avail_in = n;
}
zrc = inflate( zs, Z_PARTIAL_FLUSH );
if( DBG_FILTER )
log_debug("inflate returned: avail_in=%u, avail_out=%u, zrc=%d\n",
(unsigned)zs->avail_in, (unsigned)zs->avail_out, zrc);
if( zrc != Z_OK && zrc != Z_STREAM_END ) {
if( zs->msg )
log_fatal("zlib inflate problem: %s\n", zs->msg );
else
log_fatal("zlib inflate problem: rc=%d\n", zrc );
}
} while( zs->avail_out && zrc != Z_STREAM_END );
*ret_len = zfx->outbufsize - zs->avail_out;
if( DBG_FILTER )
log_debug("do_uncompress: returning %u bytes\n", (unsigned)*ret_len );
return 0;
}
int
compress_filter( void *opaque, int control,
IOBUF a, byte *buf, size_t *ret_len)
{
size_t size = *ret_len;
compress_filter_context_t *zfx = opaque;
z_stream *zs = zfx->opaque;
int zrc, rc=0;
if( control == IOBUFCTRL_UNDERFLOW ) {
if( !zfx->status ) {
zs = zfx->opaque = m_alloc_clear( sizeof *zs );
init_uncompress( zfx, zs );
zfx->status = 1;
}
zs->next_out = buf;
zs->avail_out = size;
zfx->outbufsize = size; /* needed only for calculation */
rc = do_uncompress( zfx, zs, a, ret_len );
}
else if( control == IOBUFCTRL_FLUSH ) {
if( !zfx->status ) {
PACKET pkt;
PKT_compressed cd;
memset( &cd, 0, sizeof cd );
cd.len = 0;
cd.algorithm = 2; /* zlib */
init_packet( &pkt );
pkt.pkttype = PKT_COMPR_DATA;
pkt.pkt.compressed = &cd;
if( build_packet( a, &pkt ))
log_bug("build_packet(COMPRESSED) failed\n");
zs = zfx->opaque = m_alloc_clear( sizeof *zs );
init_compress( zfx, zs );
zfx->status = 2;
}
zs->next_in = buf;
zs->avail_in = size;
rc = do_compress( zfx, zs, Z_NO_FLUSH, a );
}
else if( control == IOBUFCTRL_FREE ) {
if( zfx->status == 1 ) {
inflateEnd(zs);
m_free(zs);
zfx->opaque = NULL;
m_free(zfx->outbuf); zfx->outbuf = NULL;
}
else if( zfx->status == 2 ) {
zs->next_in = buf;
zs->avail_in = 0;
do_compress( zfx, zs, Z_FINISH, a );
deflateEnd(zs);
m_free(zs);
zfx->opaque = NULL;
m_free(zfx->outbuf); zfx->outbuf = NULL;
}
}
else if( control == IOBUFCTRL_DESC )
*(char**)buf = "compress_filter";
return rc;
}
/****************
* Handle a compressed packet
*/
int
handle_compressed( PKT_compressed *cd )
{
compress_filter_context_t cfx;
memset( &cfx, 0, sizeof cfx );
if( cd->algorithm != 2 )
return G10ERR_COMPR_ALGO;
iobuf_push_filter( cd->buf, compress_filter, &cfx );
proc_packets(cd->buf);
iobuf_pop_filter( cd->buf, compress_filter, &cfx );
#if 0
if( cd->len )
iobuf_set_limit( cd->buf, 0 ); /* disable the readlimit */
else
iobuf_clear_eof( cd->buf );
#endif
cd->buf = NULL;
return 0;
}

View File

@ -1,114 +0,0 @@
/* compressed.c - process an compressed packet
* Copyright (c) 1997 by Werner Koch (dd9jn)
*
* This file is part of G10.
*
* G10 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* G10 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
/*#include <zlib.h>*/
#include "util.h"
#include "memory.h"
#include "packet.h"
/****************
* Handle a compressed packet
*/
int
handle_compressed( PKT_compressed *zd )
{
return -1;
#if 0
int c, zrc, rc = 0;
z_stream *zs = NULL;
unsigned inbufsize = 4096;
unsigned outbufsize = 16384;
unsigned n;
byte *inbuf = NULL;
byte *outbuf = NULL;
if( zd->algorithm != 1 ) {
rc =G10ERR_COMPR_ALGO;
goto leave;
}
zs = m_alloc_clear( sizeof *zs );
if( (zrc = inflateInit( zs )) != Z_OK ) {
log_fatal("zlib problem: %s\n", zs->msg? zs->msg :
zrc == Z_MEM_ERROR ? "out of core" :
zrc == Z_VERSION_ERROR ? "invalid lib version" :
"unknown error" );
}
inbuf = m_alloc( inbufsize );
outbuf = m_alloc( outbufsize ); /* Fixme: put it in secure space? */
zs->next_in = inbuf;
zs->avail_in = inbufsize;
zs->next_out = outbuf;
zs->avail_out = outbufsize;
n = 0;
inbuf[n++] = 0x58;
inbuf[n++] = 0x09;
for(; n < inbufsize && (c=iobuf_get(zd->buf)) != -1 ; n++ )
inbuf[n] = c;
if( n ) {
{ int i;
printf("start of compressed packet (n=%u):\n", n);
for(i=0; i < 32 && i < n; i++ )
printf(" %02x", inbuf[i] );
putchar('\n');
}
zrc = inflate( zs, Z_PARTIAL_FLUSH );
switch( zrc ) {
case Z_OK:
log_info("inflate returned okay\n");
break;
case Z_STREAM_END:
log_info("inflate returned stream-end\n");
break;
case Z_NEED_DICT:
case Z_DATA_ERROR:
case Z_STREAM_ERROR:
case Z_MEM_ERROR:
case Z_BUF_ERROR:
default:
if( zs->msg )
log_error("zlib inflate problem: %s\n", zs->msg );
else
log_error("zlib inflate problem: rc=%d\n", zrc );
break;
}
}
leave:
if( zs ) {
inflateEnd(zs);
m_free(zs);
}
m_free(inbuf);
m_free(outbuf);
return rc;
#endif
}

View File

@ -40,21 +40,6 @@
static int encode_simple( const char *filename, int mode );
static IOBUF open_outfile( const char *iname );
static int compress_filter( void *opaque, int control,
IOBUF chain, byte *buf, size_t *ret_len);
static int cipher_filter( void *opaque, int control,
IOBUF chain, byte *buf, size_t *ret_len);
typedef struct {
DEK *dek;
PKT_encr_data ed;
BLOWFISH_context *bf_ctx;
int header;
} cipher_filter_context_t;
/****************
@ -104,9 +89,11 @@ encode_simple( const char *filename, int mode )
u32 filesize;
cipher_filter_context_t cfx;
armor_filter_context_t afx;
compress_filter_context_t zfx;
memset( &cfx, 0, sizeof cfx);
memset( &afx, 0, sizeof afx);
memset( &zfx, 0, sizeof zfx);
/* prepare iobufs */
if( !(inp = iobuf_open(filename)) ) {
@ -139,7 +126,7 @@ encode_simple( const char *filename, int mode )
write_comment( out, "#Created by G10 pre-release " VERSION );
if( opt.compress )
iobuf_push_filter( out, compress_filter, NULL );
iobuf_push_filter( out, compress_filter, &zfx );
/* setup the inner packet */
@ -161,8 +148,7 @@ encode_simple( const char *filename, int mode )
pt->buf = inp;
pkt.pkttype = PKT_PLAINTEXT;
pkt.pkt.plaintext = pt;
cfx.ed.len = filesize? calc_packet_length( &pkt ) : 0;
cfx.ed.buf = NULL; /* not used! */
cfx.datalen = filesize? calc_packet_length( &pkt ) : 0;
/* register the cipher filter */
if( mode )
@ -197,12 +183,14 @@ encode_crypt( const char *filename, STRLIST remusr )
u32 filesize;
cipher_filter_context_t cfx;
armor_filter_context_t afx;
compress_filter_context_t zfx;
int any_names = 0;
STRLIST local_remusr = NULL;
char *ustr;
memset( &cfx, 0, sizeof cfx);
memset( &afx, 0, sizeof afx);
memset( &zfx, 0, sizeof zfx);
if( !remusr ) {
remusr = NULL; /* fixme: ask */
@ -231,7 +219,7 @@ encode_crypt( const char *filename, STRLIST remusr )
write_comment( out, "#Created by G10 pre-release " VERSION );
if( opt.compress )
iobuf_push_filter( out, compress_filter, NULL );
iobuf_push_filter( out, compress_filter, &zfx );
/* create a session key */
cfx.dek = m_alloc_secure( sizeof *cfx.dek );
@ -327,8 +315,7 @@ encode_crypt( const char *filename, STRLIST remusr )
init_packet(&pkt);
pkt.pkttype = PKT_PLAINTEXT;
pkt.pkt.plaintext = pt;
cfx.ed.len = filesize? calc_packet_length( &pkt ) : 0;
cfx.ed.buf = NULL; /* not used! */
cfx.datalen = filesize? calc_packet_length( &pkt ) : 0;
/* register the cipher filter */
iobuf_push_filter( out, cipher_filter, &cfx );
@ -389,74 +376,3 @@ open_outfile( const char *iname )
}
static int
compress_filter( void *opaque, int control,
IOBUF a, byte *buf, size_t *ret_len)
{
size_t size = *ret_len;
int rc=0;
if( control == IOBUFCTRL_FLUSH ) {
assert(a);
if( iobuf_write( a, buf, size ) )
rc = G10ERR_WRITE_FILE;
}
else if( control == IOBUFCTRL_DESC ) {
*(char**)buf = "compress_filter";
}
return rc;
}
/****************
* The filter is used to encipher data.
*/
static int
cipher_filter( void *opaque, int control,
IOBUF a, byte *buf, size_t *ret_len)
{
size_t size = *ret_len;
cipher_filter_context_t *cfx = opaque;
int rc=0;
if( control == IOBUFCTRL_FLUSH ) {
assert(a);
if( !cfx->header ) {
PACKET pkt;
byte temp[10];
pkt.pkttype = PKT_ENCR_DATA;
pkt.pkt.encr_data = &cfx->ed;
if( build_packet( a, &pkt ))
log_bug("build_packet(ENCR_DATA) failed\n");
randomize_buffer( temp, 8, 1 );
temp[8] = temp[6];
temp[9] = temp[7];
if( cfx->dek->algo == CIPHER_ALGO_BLOWFISH ) {
cfx->bf_ctx = m_alloc_secure( sizeof *cfx->bf_ctx );
blowfish_setkey( cfx->bf_ctx, cfx->dek->key, cfx->dek->keylen );
blowfish_setiv( cfx->bf_ctx, NULL );
blowfish_encode_cfb( cfx->bf_ctx, temp, temp, 10);
}
else
log_bug("no cipher algo %d\n", cfx->dek->algo);
iobuf_write(a, temp, 10);
cfx->header=1;
}
if( cfx->dek->algo == CIPHER_ALGO_BLOWFISH )
blowfish_encode_cfb( cfx->bf_ctx, buf, buf, size);
if( iobuf_write( a, buf, size ) )
rc = G10ERR_WRITE_FILE;
}
else if( control == IOBUFCTRL_FREE ) {
if( cfx->dek->algo == CIPHER_ALGO_BLOWFISH )
m_free(cfx->bf_ctx);
}
else if( control == IOBUFCTRL_DESC ) {
*(char**)buf = "cipher_filter";
}
return rc;
}

View File

@ -40,6 +40,25 @@ typedef struct {
} armor_filter_context_t;
typedef struct {
int status;
void *opaque; /* (used for z_stream) */
byte *inbuf;
unsigned inbufsize;
byte *outbuf;
unsigned outbufsize;
} compress_filter_context_t;
typedef struct {
DEK *dek;
u32 datalen;
BLOWFISH_context *bf_ctx;
int header;
} cipher_filter_context_t;
/*-- mdfilter.c --*/
int md_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len);
@ -47,4 +66,14 @@ int md_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len);
int armor_filter( void *opaque, int control,
IOBUF chain, byte *buf, size_t *ret_len);
/*-- compress.c --*/
int compress_filter( void *opaque, int control,
IOBUF chain, byte *buf, size_t *ret_len);
/*-- cipher.c --*/
int cipher_filter( void *opaque, int control,
IOBUF chain, byte *buf, size_t *ret_len);
#endif /*G10_FILTER_H*/

View File

@ -319,7 +319,9 @@ scan_keyring( PKT_pubkey_cert *pkc, u32 *keyid,
return G10ERR_KEYRING_OPEN;
}
if( name )
if( !DBG_CACHE )
;
else if( name )
log_debug("scan_keyring %s for '%s'\n", filename, name );
else if( keyid )
log_debug("scan_keyring %s for %08lx %08lx\n", filename,

View File

@ -201,7 +201,7 @@ int check_secret_key( PKT_seckey_cert *cert );
/*-- pubkey-enc.c --*/
int get_session_key( PKT_pubkey_enc *k, DEK *dek );
/*-- compressed.c --*/
/*-- compress.c --*/
int handle_compressed( PKT_compressed *zd );
/*-- encr-data.c --*/

View File

@ -127,6 +127,7 @@ parse_packet( IOBUF inp, PACKET *pkt )
pktlen = 0;
if( !lenbytes ) {
pktlen = 0; /* don't know the value */
if( pkttype != PKT_COMPR_DATA )
iobuf_set_block_mode(inp, 1);
}
else {
@ -626,7 +627,6 @@ parse_compressed( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *pkt )
zd->len = 0; /* not yet used */
zd->algorithm = iobuf_get_noeof(inp);
zd->buf = inp;
algorithm = iobuf_get_noeof(inp);
if( list_mode )
printf(":compressed packet: algo=%d\n", zd->algorithm);
return 0;