diff options
Diffstat (limited to 'g10')
-rw-r--r-- | g10/Makefile.am | 1 | ||||
-rw-r--r-- | g10/Makefile.in | 15 | ||||
-rw-r--r-- | g10/encode.c | 167 | ||||
-rw-r--r-- | g10/filter.h | 15 | ||||
-rw-r--r-- | g10/g10.c | 14 | ||||
-rw-r--r-- | g10/parse-packet.c | 4 |
6 files changed, 39 insertions, 177 deletions
diff --git a/g10/Makefile.am b/g10/Makefile.am index 7da61f7eb..90c43ef7e 100644 --- a/g10/Makefile.am +++ b/g10/Makefile.am @@ -16,6 +16,7 @@ g10_SOURCES = g10.c \ keygen.c \ main.h \ mainproc.c \ + armor.c \ mdfilter.c \ options.h \ overwrite.c \ diff --git a/g10/Makefile.in b/g10/Makefile.in index b086d7c4d..97ff3035f 100644 --- a/g10/Makefile.in +++ b/g10/Makefile.in @@ -54,6 +54,7 @@ g10_SOURCES = g10.c \ keygen.c \ main.h \ mainproc.c \ + armor.c \ mdfilter.c \ options.h \ overwrite.c \ @@ -85,9 +86,9 @@ 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 mdfilter.o overwrite.o \ -parse-packet.o passphrase.o plaintext.o pubkey-enc.o seckey-cert.o \ -seskey.o sig-check.o +free-packet.o getkey.o keygen.o mainproc.o armor.o mdfilter.o \ +overwrite.o parse-packet.o passphrase.o plaintext.o pubkey-enc.o \ +seckey-cert.o seskey.o sig-check.o EXTRA_g10_SOURCES = g10_LDADD = $(LDADD) DIST_COMMON = Makefile.am Makefile.in @@ -102,10 +103,10 @@ DEP_DISTFILES = $(DIST_COMMON) $(SOURCES) $(BUILT_SOURCES) $(HEADERS) \ $(TEXINFOS) $(INFO_DEPS) $(MANS) $(EXTRA_DIST) $(DATA) TAR = tar -DEP_FILES = $(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 \ +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/mainproc.P $(srcdir)/.deps/mdfilter.P \ $(srcdir)/.deps/overwrite.P $(srcdir)/.deps/parse-packet.P \ $(srcdir)/.deps/passphrase.P $(srcdir)/.deps/plaintext.P \ diff --git a/g10/encode.c b/g10/encode.c index ad8d3f720..efa9fd230 100644 --- a/g10/encode.c +++ b/g10/encode.c @@ -33,14 +33,13 @@ #include "memory.h" #include "util.h" #include "main.h" +#include "filter.h" static int encode_simple( const char *filename, int mode ); static IOBUF open_outfile( const char *iname ); -static int armor_filter( void *opaque, int control, - IOBUF chain, byte *buf, size_t *ret_len); static int compress_filter( void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len); static int cipher_filter( void *opaque, int control, @@ -56,51 +55,6 @@ typedef struct { } cipher_filter_context_t; -typedef struct { - int status; - int what; - byte buf[3]; - int idx, idx2; - u32 crc; -} armor_filter_context_t; - - - -#define CRCINIT 0xB704CE -#define CRCPOLY 0X864CFB -#define CRCUPDATE(a,c) do { \ - a = ((a) << 8) ^ crc_table[((a)&0xff >> 16) ^ (c)]; \ - a &= 0x00ffffff; \ - } while(0) -static u32 crc_table[256]; -static int crc_table_initialized; - - - -static void -init_crc_table(void) -{ - int i, j; - u32 t; - - crc_table[0] = 0; - for(i=j=0; j < 128; j++ ) { - t = crc_table[j]; - if( t & 0x00800000 ) { - t <<= 1; - crc_table[i++] = t ^ CRCPOLY; - crc_table[i++] = t; - } - else { - t <<= 1; - crc_table[i++] = t; - crc_table[i++] = t ^ CRCPOLY; - } - } - - crc_table_initialized=1; -} - /**************** @@ -434,125 +388,6 @@ open_outfile( const char *iname ) return a; } -static int -armor_filter( void *opaque, int control, - IOBUF a, byte *buffer, size_t *ret_len) -{ - static byte bintoasc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - size_t size = *ret_len; - armor_filter_context_t *afx = opaque; - int rc=0, i, c; - byte buf[3]; - int idx, idx2; - u32 crc; - - - if( control == IOBUFCTRL_FLUSH ) { - if( !afx->status ) { /* write the header line */ - if( !afx->what ) - iobuf_writestr(a, "-----BEGIN PGP MESSAGE-----\n"); - else - iobuf_writestr(a, "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"); - iobuf_writestr(a, "Version: G10 pre-release " VERSION "\n"); - iobuf_writestr(a, "Comment: This is a alpha test version!\n\n"); - afx->status++; - afx->idx = 0; - afx->idx2 = 0; - afx->crc = CRCINIT; - } - crc = afx->crc; - idx = afx->idx; - idx2 = afx->idx2; - for(i=0; i < idx; i++ ) - buf[i] = afx->buf[i]; - - for(i=0; i < size; i++ ) - crc = (crc << 8) ^ crc_table[(crc >> 16)&0xff ^ buffer[i]]; - crc &= 0x00ffffff; - - for( ; size; buffer++, size-- ) { - buf[idx++] = *buffer; - if( idx > 2 ) { - idx = 0; - c = bintoasc[(*buf >> 2) & 077]; - iobuf_put(a, c); - c = bintoasc[(((*buf<<4)&060)|((buf[1] >> 4)&017))&077]; - iobuf_put(a, c); - c = bintoasc[(((buf[1]<<2)&074)|((buf[2]>>6)&03))&077]; - iobuf_put(a, c); - c = bintoasc[buf[2]&077]; - iobuf_put(a, c); - if( ++idx2 > (72/4) ) { - iobuf_put(a, '\n'); - idx2=0; - } - } - } - for(i=0; i < idx; i++ ) - afx->buf[i] = buf[i]; - afx->idx = idx; - afx->idx2 = idx2; - afx->crc = crc; - } - else if( control == IOBUFCTRL_INIT ) { - if( !crc_table_initialized ) - init_crc_table(); - } - else if( control == IOBUFCTRL_FREE ) { - if( afx->status ) { /* pad, write cecksum, and bottom line */ - crc = afx->crc; - idx = afx->idx; - idx2 = afx->idx2; - for(i=0; i < idx; i++ ) - buf[i] = afx->buf[i]; - if( idx ) { - c = bintoasc[(*buf>>2)&077]; - iobuf_put(a, c); - if( idx == 1 ) { - c = bintoasc[((*buf << 4) & 060) & 077]; - iobuf_put(a, c); - iobuf_put(a, '='); - iobuf_put(a, '='); - } - else { /* 2 */ - c = bintoasc[(((*buf<<4)&060)|((buf[1]>>4)&017))&077]; - iobuf_put(a, c); - c = bintoasc[((buf[1] << 2) & 074) & 077]; - iobuf_put(a, c); - iobuf_put(a, '='); - } - ++idx2; - } - /* may need a linefeed */ - if( idx2 < (72/4) ) - iobuf_put(a, '\n'); - /* write the CRC */ - iobuf_put(a, '='); - buf[0] = crc >>16; - buf[1] = crc >> 8; - buf[2] = crc; - c = bintoasc[(*buf >> 2) & 077]; - iobuf_put(a, c); - c = bintoasc[(((*buf<<4)&060)|((buf[1] >> 4)&017))&077]; - iobuf_put(a, c); - c = bintoasc[(((buf[1]<<2)&074)|((buf[2]>>6)&03))&077]; - iobuf_put(a, c); - c = bintoasc[buf[2]&077]; - iobuf_put(a, c); - iobuf_put(a, '\n'); - /* and the the trailer */ - if( !afx->what ) - iobuf_writestr(a, "-----END PGP MESSAGE-----\n"); - else - iobuf_writestr(a, "-----END PGP PUBLIC KEY BLOCK-----\n"); - } - } - else if( control == IOBUFCTRL_DESC ) - *(char**)buf = "armor_filter"; - return 0; -} static int compress_filter( void *opaque, int control, diff --git a/g10/filter.h b/g10/filter.h index 8cbb26af7..cb6802ff3 100644 --- a/g10/filter.h +++ b/g10/filter.h @@ -28,8 +28,23 @@ typedef struct { size_t maxbuf_size; } md_filter_context_t; +typedef struct { + int status; + int what; + byte radbuf[4]; + int idx, idx2; + u32 crc; + int inp_checked; /* set if inp has been checked */ + int inp_bypass; /* set if the input is not armored */ + int inp_eof; +} armor_filter_context_t; + /*-- mdfilter.c --*/ int md_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len); +/*-- armor.c --*/ +int armor_filter( void *opaque, int control, + IOBUF chain, byte *buf, size_t *ret_len); + #endif /*G10_FILTER_H*/ @@ -31,6 +31,7 @@ #include "keydb.h" #include "mpi.h" #include "cipher.h" +#include "filter.h" const char * @@ -51,11 +52,15 @@ strusage( int level ) "\nSyntax: g10 [options] [files]\n" "sign, check, encrypt or decrypt\n" "default operation depends on the input data\n" - #ifndef HAVE_RSA_CIPHER - "This version does not support RSA!\n" + #ifdef HAVE_RSA_CIPHER + "WARNING: This version has RSA support! Your are not allowed to\n" + " use it inside the Unites States until Sep 30, 2000!\n" #endif ; break; + case 26: + p = "Please report bugs to <[email protected]>.\n"; + break; default: p = default_strusage(level); } return p; @@ -75,6 +80,7 @@ set_debug(void) } + int main( int argc, char **argv ) { @@ -115,6 +121,7 @@ main( int argc, char **argv ) const char *fname, *fname_print; STRLIST sl, remusr= NULL; int nrings=0; + armor_filter_context_t afx; opt.compress = -1; /* defaults to default compression level */ while( arg_parse( &pargs, opts) ) { @@ -210,6 +217,9 @@ main( int argc, char **argv ) usage(1); if( !(a = iobuf_open(fname)) ) log_fatal("can't open '%s'\n", fname_print); + /* push the armor filter, so it can peek at the input data */ + memset( &afx, 0, sizeof afx); + iobuf_push_filter( a, armor_filter, &afx ); proc_packets( a ); iobuf_close(a); break; diff --git a/g10/parse-packet.c b/g10/parse-packet.c index 7c6b85782..68d02536d 100644 --- a/g10/parse-packet.c +++ b/g10/parse-packet.c @@ -432,12 +432,12 @@ parse_certificate( IOBUF inp, int pkttype, unsigned long pktlen, X(q); X(u); #undef X - log_mpidump("rsa n=", cert->d.rsa.rsa_n ); + /* log_mpidump("rsa n=", cert->d.rsa.rsa_n ); log_mpidump("rsa e=", cert->d.rsa.rsa_e ); log_mpidump("rsa d=", cert->d.rsa.rsa_d ); log_mpidump("rsa p=", cert->d.rsa.rsa_p ); log_mpidump("rsa q=", cert->d.rsa.rsa_q ); - log_mpidump("rsa u=", cert->d.rsa.rsa_u ); + log_mpidump("rsa u=", cert->d.rsa.rsa_u ); */ } } } |