diff options
author | Werner Koch <wk@gnupg.org> | 1997-11-26 23:02:28 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1997-11-26 23:02:28 +0100 |
commit | 9479cf7e24abf0998ebbc083e28741038d535b68 (patch) | |
tree | 987fa4ffc48db5e94342901fa064f41bf1a7a2da /g10 | |
parent | added assembler modules (diff) | |
download | gnupg2-9479cf7e24abf0998ebbc083e28741038d535b68.tar.xz gnupg2-9479cf7e24abf0998ebbc083e28741038d535b68.zip |
How with some assembly support
Diffstat (limited to 'g10')
-rw-r--r-- | g10/Makefile.am | 2 | ||||
-rw-r--r-- | g10/Makefile.in | 2 | ||||
-rw-r--r-- | g10/compress.c | 33 | ||||
-rw-r--r-- | g10/encode.c | 2 | ||||
-rw-r--r-- | g10/g10.c | 71 | ||||
-rw-r--r-- | g10/mainproc.c | 326 | ||||
-rw-r--r-- | g10/pubkey-enc.c | 2 | ||||
-rw-r--r-- | g10/sig-check.c | 4 |
8 files changed, 425 insertions, 17 deletions
diff --git a/g10/Makefile.am b/g10/Makefile.am index bb0b96552..c6361004d 100644 --- a/g10/Makefile.am +++ b/g10/Makefile.am @@ -34,7 +34,7 @@ g10_SOURCES = g10.c \ sig-check.c -LDADD = -L ../cipher -L ../mpi -L ../util -lcipher -lmpi -lutil -lz +LDADD = -L ../cipher -L ../mpi -L ../util -lcipher -lmpi -lutil $(PROGRAMS): ../cipher/libcipher.a ../mpi/libmpi.a diff --git a/g10/Makefile.in b/g10/Makefile.in index 651fdf2dd..17a4df10b 100644 --- a/g10/Makefile.in +++ b/g10/Makefile.in @@ -71,7 +71,7 @@ g10_SOURCES = g10.c \ comment.c \ sig-check.c -LDADD = -L ../cipher -L ../mpi -L ../util -lcipher -lmpi -lutil -lz +LDADD = -L ../cipher -L ../mpi -L ../util -lcipher -lmpi -lutil mkinstalldirs = $(top_srcdir)/scripts/mkinstalldirs CONFIG_HEADER = ../config.h PROGRAMS = $(bin_PROGRAMS) diff --git a/g10/compress.c b/g10/compress.c index 980f5f976..38d23adf8 100644 --- a/g10/compress.c +++ b/g10/compress.c @@ -27,8 +27,6 @@ #include <errno.h> #ifdef HAVE_ZLIB_H #include <zlib.h> -#else - #error You need ZLIB to compile this module #endif #include "util.h" @@ -38,6 +36,7 @@ #include "options.h" +#ifdef HAVE_ZLIB_H static void init_compress( compress_filter_context_t *zfx, z_stream *zs ) { @@ -163,7 +162,6 @@ do_uncompress( compress_filter_context_t *zfx, z_stream *zs, return rc; } - int compress_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len) @@ -228,6 +226,35 @@ compress_filter( void *opaque, int control, *(char**)buf = "compress_filter"; return rc; } +#else /* No ZLIB */ +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; + int c, rc=0; + size_t n; + + if( control == IOBUFCTRL_UNDERFLOW ) { + for( n=0; n < size; n++ ) { + if( (c=iobuf_get(a)) == -1 ) + break; + buf[n] = c & 0xff; + } + if( !n ) + rc = -1; + *ret_len = n; + } + else if( control == IOBUFCTRL_FLUSH ) { + if( iobuf_write( a, buf, size ) ) + rc = G10ERR_WRITE_FILE; + } + else if( control == IOBUFCTRL_DESC ) + *(char**)buf = "dummy compress_filter"; + return rc; +} +#endif /*no ZLIB*/ /**************** * Handle a compressed packet diff --git a/g10/encode.c b/g10/encode.c index eb4875de9..75764fe1a 100644 --- a/g10/encode.c +++ b/g10/encode.c @@ -251,6 +251,7 @@ encode_crypt( const char *filename, STRLIST remusr ) m_free(ustr); } } + #ifdef HAVE_RSA_CIPHER else if( enc->pubkey_algo == PUBKEY_ALGO_RSA ) { RSA_public_key pkey; @@ -270,6 +271,7 @@ encode_crypt( const char *filename, STRLIST remusr ) m_free(ustr); } } + #endif/*HAVE_RSA_CIPHER*/ else { last_rc = rc = G10ERR_PUBKEY_ALGO; log_error("skipped '%s': %s\n", remusr->d, g10_errstr(rc) ); @@ -33,6 +33,7 @@ #include "cipher.h" #include "filter.h" +static void do_test(void); const char * strusage( int level ) @@ -41,7 +42,7 @@ strusage( int level ) switch( level ) { case 10: case 0: p = "g10 - v" VERSION "; " - "Copyright 1997 Werner Koch (dd9jn)" ; break; + "Copyright 1997 Werner Koch (dd9jn)\n" ; break; case 13: p = "g10"; break; case 14: p = VERSION; break; case 1: @@ -49,18 +50,25 @@ strusage( int level ) break; case 2: case 12: p = - "\nSyntax: g10 [options] [files]\n" + "Syntax: g10 [options] [files]\n" "sign, check, encrypt or decrypt\n" - "default operation depends on the input data\n" + "default operation depends on the input data\n"; break; + + case 26: + p = "Please report bugs to <g10-bugs@isil.d.shuttle.de>.\n"; + break; + + case 30: p = "" + #ifndef HAVE_ZLIB_H + " NOTE: This version is compiled without ZLIB support;\n" + " you are not able to process compresssed data!\n" + #endif #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 <g10-bugs@isil.d.shuttle.de>.\n"; - break; default: p = default_strusage(level); } return p; @@ -96,7 +104,7 @@ main( int argc, char **argv ) { 'o', "output", 2, "use as output file" }, { 501, "yes", 0, "assume yes on most questions"}, { 502, "no", 0, "assume no on most questions"}, - { 503, "make-key", 0, "generate a new key pair" }, + { 503, "gen-key", 0, "generate a new key pair" }, { 504, "add-key", 0, "add key to the public keyring" }, { 505, "delete-key",0, "remove key from public keyring" }, { 506, "sign-key" ,0, "make a signature on a key in the keyring" }, @@ -112,18 +120,20 @@ main( int argc, char **argv ) { 510, "debug" ,4|16, "set debugging flags" }, { 511, "debug-all" ,0, "enable full debugging"}, { 512, "cache-all" ,0, "hold everything in memory"}, - { 513, "gen-prime" , 1, "generate a prime of length n" }, - { 514, "gen-key" , 0, "generate a key pair" }, + { 513, "gen-prime" , 1, "\rgenerate a prime of length n" }, + { 514, "test" , 0, "\rdevelopment usage" }, {0} }; ARGPARSE_ARGS pargs = { &argc, &argv, 0 }; IOBUF a; int rc; enum { aNull, aSym, aStore, aEncr, aPrimegen, aKeygen, aSign, aSignEncr, + aTest, } action = aNull; const char *fname, *fname_print; STRLIST sl, remusr= NULL, locusr=NULL; int nrings=0; armor_filter_context_t afx; + const char *s; opt.compress = -1; /* defaults to default compression level */ while( arg_parse( &pargs, opts) ) { @@ -155,6 +165,7 @@ main( int argc, char **argv ) break; case 501: opt.answer_yes = 1; break; case 502: opt.answer_no = 1; break; + case 503: action = aKeygen; break; case 507: action = aStore; break; case 508: opt.check_sigs = 1; break; case 509: add_keyring(pargs.r.ret_str); nrings++; break; @@ -162,13 +173,18 @@ main( int argc, char **argv ) case 511: opt.debug = ~0; break; case 512: opt.cache_all = 1; break; case 513: action = aPrimegen; break; - case 514: action = aKeygen; break; + case 514: action = aTest; break; default : pargs.err = 2; break; } } set_debug(); if( opt.verbose > 1 ) set_packet_list_mode(1); + if( !opt.batch && *(s=strusage(10)) ) + fputs(s, stderr); + if( !opt.batch && *(s=strusage(30)) ) + fputs(s, stderr); + if( !nrings ) { /* add default rings */ add_keyring("../keys/ring.pgp"); @@ -230,6 +246,8 @@ main( int argc, char **argv ) generate_keypair(); break; + case aTest: do_test(); break; + default: if( argc > 1 ) usage(1); @@ -250,3 +268,36 @@ main( int argc, char **argv ) } + +static void +do_test() +{ + MPI t = mpi_alloc( 50 ); + MPI m = mpi_alloc( 50 ); + MPI a = mpi_alloc( 50 ); + MPI b = mpi_alloc( 50 ); + MPI p = mpi_alloc( 50 ); + MPI x = mpi_alloc( 50 ); + mpi_fromstr(a, "0xef45678343589854354a4545545454554545455" + "aaaaaaaaaaaaa44444fffdecb33434343443331" ); + mpi_fromstr(b, "0x8765765589854354a4545545454554545455" + "aaaaaaa466577778decb36666343443331" ); + mpi_fromstr(p, "0xcccddd456700000012222222222222254545455" + "aaaaaaaaaaaaa44444fffdecb33434343443337" ); + mpi_fromstr(x, "0x100004545543656456656545545454554545455" + "aaa33aaaa465456544fffdecb33434bbbac3331" ); + + /* output = b/(a^x) mod p */ + log_debug("powm ..\n"); + mpi_powm( t, a, x, p ); + log_debug("invm ..\n"); + mpi_invm( t, t, p ); + log_debug("mulm ..\n"); + mpi_mulm( m, b, t, p ); + + + m_check(NULL); + +} + + diff --git a/g10/mainproc.c b/g10/mainproc.c index 6c7e32f3c..c056ac0af 100644 --- a/g10/mainproc.c +++ b/g10/mainproc.c @@ -33,7 +33,331 @@ #include "main.h" static int opt_list=1; /* and list the data packets to stdout */ +#if 0 +static void +do_free_last_user_id( CTX c ) +{ + if( c->last_user_id ) { + free_user_id( c->last_user_id ); + c->last_user_id = NULL; + } +} +static void +do_free_last_pubkey( CTX c ) +{ + if( c->last_pubkey ) { + free_pubkey_cert( c->last_pubkey ); + c->last_pubkey = NULL; + } +} +static void +do_free_last_seckey( CTX c ) +{ + if( c->last_seckey ) { + free_seckey_cert( c->last_seckey ); + c->last_seckey = NULL; + } +} + +static void +proc_pubkey_cert( CTX c, PACKET *pkt ) +{ + do_free_last_user_id( c ); + do_free_last_seckey( c ); + if( opt.check_sigs ) { + char *ustr = get_user_id_string(sig->keyid); /* sig ???? */ + printstr(lvl0, "pub: %s\n", ustr ); + m_free(ustr); + } + else + fputs( "pub: [Public Key Cerificate]\n", stdout ); + c->last_pubkey = pkt->pkt.pubkey_cert; + pkt->pkt.pubkey_cert = NULL; + free_packet(pkt); + pkt->pkc_parent = c->last_pubkey; /* set this as parent */ +} + + +static void +proc_seckey_cert( CTX c, PACKET *pkt ) +{ + int rc; + + do_free_last_user_id( c ); + do_free_last_pubkey( c ); + if( opt_list ) + fputs( "sec: (secret key certificate)\n", stdout ); + rc = check_secret_key( pkt->pkt.seckey_cert ); + if( opt_list ) { + if( !rc ) + fputs( " Secret key is good", stdout ); + else + fputs( g10_errstr(rc), stdout); + putchar('\n'); + } + else if( rc ) + log_error("secret key certificate error: %s\n", g10_errstr(rc)); + c->last_seckey = pkt->pkt.seckey_cert; + pkt->pkt.seckey_cert = NULL; + free_packet(pkt); + pkt->skc_parent = c->last_seckey; /* set this as parent */ +} + + + + + +int +proc_packets( IOBUF a ) +{ + PACKET *pkt; + PKT_pubkey_cert *last_pubkey = NULL; + PKT_seckey_cert *last_seckey = NULL; + PKT_user_id *last_user_id = NULL; + DEK *dek = NULL; + PKT_signature *sig; /* CHECK: "might be used uninitialied" */ + int rc, result; + MD_HANDLE md_handle; /* union to pass handles */ + char *ustr; + int lvl0, lvl1; + int last_was_pubkey_enc = 0; + u32 keyid[2]; + md_filter_context_t mfx; + + memset( &mfx, 0, sizeof mfx ); + lvl0 = opt.check_sigs? 1:0; /* stdout or /dev/null */ + lvl1 = opt.check_sigs? 1:3; /* stdout or error */ + pkt = m_alloc( sizeof *pkt ); + init_packet(pkt); + while( (rc=parse_packet(a, pkt)) != -1 ) { + /* cleanup if we have an illegal data structure */ + if( dek && pkt->pkttype != PKT_ENCR_DATA ) { + log_error("oops: valid pubkey enc packet not followed by data\n"); + m_free(dek); dek = NULL; /* burn it */ + } + + if( rc ) { + free_packet(pkt); + continue; + } + switch( pkt->pkttype ) { + case PKT_PUBKEY_CERT: proc_pubkey_cert( c, pkt ); break; + case PKT_SECKEY_CERT: proc_seckey_cert( c, pkt ); break; + case PKT_USER_ID: + if( last_user_id ) { + free_user_id( last_user_id ); + last_user_id = NULL; + } + if( opt_list ) { + printf("uid: '%.*s'\n", pkt->pkt.user_id->len, + pkt->pkt.user_id->name ); + if( !pkt->pkc_parent && !pkt->skc_parent ) + puts(" (orphaned)"); + } + if( pkt->pkc_parent ) { + if( pkt->pkc_parent->pubkey_algo == PUBKEY_ALGO_ELGAMAL + || pkt->pkc_parent->pubkey_algo == PUBKEY_ALGO_RSA ) { + keyid_from_pkc( pkt->pkc_parent, keyid ); + cache_user_id( pkt->pkt.user_id, keyid ); + } + } + + last_user_id = pkt->pkt.user_id; /* save */ + pkt->pkt.user_id = NULL; + free_packet(pkt); /* fixme: free_packet is not a good name */ + pkt->user_parent = last_user_id; /* and set this as user */ + break; + + case PKT_SIGNATURE: + sig = pkt->pkt.signature; + ustr = get_user_id_string(sig->keyid); + result = -1; + if( sig->sig_class == 0x00 ) { + if( mfx.rmd160 ) + result = 0; + else + printstr(lvl1,"sig?: %s: no plaintext for signature\n", + ustr); + } + else if( sig->sig_class != 0x10 ) + printstr(lvl1,"sig?: %s: unknown signature class %02x\n", + ustr, sig->sig_class); + else if( !pkt->pkc_parent || !pkt->user_parent ) + printstr(lvl1,"sig?: %s: orphaned encoded packet\n", ustr); + else + result = 0; + + if( result ) + ; + else if( !opt.check_sigs && sig->sig_class != 0x00 ) { + result = -1; + printstr(lvl0, "sig: from %s\n", ustr ); + } + else if(sig->pubkey_algo == PUBKEY_ALGO_ELGAMAL ) { + md_handle.algo = sig->d.elg.digest_algo; + if( sig->d.elg.digest_algo == DIGEST_ALGO_RMD160 ) { + if( sig->sig_class == 0x00 ) + md_handle.u.rmd = rmd160_copy( mfx.rmd160 ); + else { + md_handle.u.rmd = rmd160_copy(pkt->pkc_parent->mfx.rmd160); + rmd160_write(md_handle.u.rmd, pkt->user_parent->name, + pkt->user_parent->len); + } + result = signature_check( sig, md_handle ); + rmd160_close(md_handle.u.rmd); + } + else if( sig->d.elg.digest_algo == DIGEST_ALGO_MD5 + && sig->sig_class != 0x00 ) { + md_handle.u.md5 = md5_copy(pkt->pkc_parent->mfx.md5); + md5_write(md_handle.u.md5, pkt->user_parent->name, + pkt->user_parent->len); + result = signature_check( sig, md_handle ); + md5_close(md_handle.u.md5); + } + else + result = G10ERR_DIGEST_ALGO; + } + else if(sig->pubkey_algo == PUBKEY_ALGO_RSA ) { + md_handle.algo = sig->d.rsa.digest_algo; + if( sig->d.rsa.digest_algo == DIGEST_ALGO_RMD160 ) { + if( sig->sig_class == 0x00 ) + md_handle.u.rmd = rmd160_copy( mfx.rmd160 ); + else { + md_handle.u.rmd = rmd160_copy(pkt->pkc_parent->mfx.rmd160); + rmd160_write(md_handle.u.rmd, pkt->user_parent->name, + pkt->user_parent->len); + } + result = signature_check( sig, md_handle ); + rmd160_close(md_handle.u.rmd); + } + else if( sig->d.rsa.digest_algo == DIGEST_ALGO_MD5 + && sig->sig_class != 0x00 ) { + md_handle.u.md5 = md5_copy(pkt->pkc_parent->mfx.md5); + md5_write(md_handle.u.md5, pkt->user_parent->name, + pkt->user_parent->len); + result = signature_check( sig, md_handle ); + md5_close(md_handle.u.md5); + } + else + result = G10ERR_DIGEST_ALGO; + } + else + result = G10ERR_PUBKEY_ALGO; + + if( result == -1 ) + ; + else if( !result && sig->sig_class == 0x00 ) + printstr(1, "sig: good signature from %s\n", ustr ); + else if( !result ) + printstr(lvl0, "sig: good signature from %s\n", ustr ); + else + printstr(lvl1, "sig? %s: %s\n", ustr, g10_errstr(result)); + free_packet(pkt); + m_free(ustr); + break; + + case PKT_PUBKEY_ENC: + PKT_pubkey_enc *enc; + + last_was_pubkey_enc = 1; + result = 0; + enc = pkt->pkt.pubkey_enc; + printf("enc: encrypted by a pubkey with keyid %08lX\n", + enc->keyid[1] ); + if( enc->pubkey_algo == PUBKEY_ALGO_ELGAMAL + || enc->pubkey_algo == PUBKEY_ALGO_RSA ) { + m_free(dek ); /* paranoid: delete a pending DEK */ + dek = m_alloc_secure( sizeof *dek ); + if( (result = get_session_key( enc, dek )) ) { + /* error: delete the DEK */ + m_free(dek); dek = NULL; + } + } + else + result = G10ERR_PUBKEY_ALGO; + + if( result == -1 ) + ; + else if( !result ) + fputs( " DEK is good", stdout ); + else + printf( " %s", g10_errstr(result)); + putchar('\n'); + free_packet(pkt); + break; + + case PKT_ENCR_DATA: + result = 0; + printf("dat: %sencrypted data\n", dek?"":"conventional "); + if( !dek && !last_was_pubkey_enc ) { + /* assume this is conventional encrypted data */ + dek = m_alloc_secure( sizeof *dek ); + dek->algo = DEFAULT_CIPHER_ALGO; + result = make_dek_from_passphrase( dek, 0 ); + } + else if( !dek ) + result = G10ERR_NO_SECKEY; + if( !result ) + result = decrypt_data( pkt->pkt.encr_data, dek ); + m_free(dek); dek = NULL; + if( result == -1 ) + ; + else if( !result ) + fputs( " encryption okay",stdout); + else + printf( " %s", g10_errstr(result)); + putchar('\n'); + free_packet(pkt); + last_was_pubkey_enc = 0; + break; + + case PKT_PLAINTEXT: + PKT_plaintext *pt = pkt->pkt.plaintext; + printf("txt: plain text data name='%.*s'\n", pt->namelen, pt->name); + free_md_filter_context( &mfx ); + mfx.rmd160 = rmd160_open(0); + result = handle_plaintext( pt, &mfx ); + if( !result ) + fputs( " okay",stdout); + else + printf( " %s", g10_errstr(result)); + putchar('\n'); + free_packet(pkt); + last_was_pubkey_enc = 0; + break; + + case PKT_COMPR_DATA: + PKT_compressed *zd = pkt->pkt.compressed; + printf("zip: compressed data packet\n"); + result = handle_compressed( zd ); + if( !result ) + fputs( " okay",stdout); + else + printf( " %s", g10_errstr(result)); + putchar('\n'); + free_packet(pkt); + last_was_pubkey_enc = 0; + break; + + default: + free_packet(pkt); + } + } + + if( last_user_id ) + free_user_id( last_user_id ); + if( last_seckey ) + free_seckey_cert( last_seckey ); + if( last_pubkey ) + free_pubkey_cert( last_pubkey ); + m_free(dek); + free_packet( pkt ); + m_free( pkt ); + free_md_filter_context( &mfx ); + return 0; +} +#else /* old */ int proc_packets( IOBUF a ) { @@ -317,5 +641,5 @@ proc_packets( IOBUF a ) free_md_filter_context( &mfx ); return 0; } - +#endif diff --git a/g10/pubkey-enc.c b/g10/pubkey-enc.c index 58da1aef8..183d91936 100644 --- a/g10/pubkey-enc.c +++ b/g10/pubkey-enc.c @@ -61,6 +61,7 @@ get_session_key( PKT_pubkey_enc *k, DEK *dek ) elg_decipher( dek_frame, k->d.elg.a, k->d.elg.b, &skey ); memset( &skey, 0, sizeof skey ); } + #ifdef HAVE_RSA_CIPHER else if( k->pubkey_algo == PUBKEY_ALGO_RSA ) { RSA_secret_key skey; @@ -76,6 +77,7 @@ get_session_key( PKT_pubkey_enc *k, DEK *dek ) rsa_secret( dek_frame, k->d.rsa.rsa_integer, &skey ); memset( &skey, 0, sizeof skey ); } + #endif/*HAVE_RSA_CIPHER*/ else { rc = G10ERR_PUBKEY_ALGO; /* unsupported algorithm */ goto leave; diff --git a/g10/sig-check.c b/g10/sig-check.c index ff212585c..fb3b409cf 100644 --- a/g10/sig-check.c +++ b/g10/sig-check.c @@ -66,7 +66,7 @@ signature_check( PKT_signature *sig, MD_HANDLE digest ) dp = rmd160_final( digest.u.rmd ); result = encode_rmd160_value( dp, 20, mpi_get_nbits(pkc->d.elg.p)); } - else if( sig->d.rsa.digest_algo == DIGEST_ALGO_MD5 ) { + else if( sig->d.elg.digest_algo == DIGEST_ALGO_MD5 ) { md5_putchar( digest.u.md5, sig->sig_class ); { u32 a = sig->timestamp; md5_putchar( digest.u.md5, (a >> 24) & 0xff ); @@ -89,6 +89,7 @@ signature_check( PKT_signature *sig, MD_HANDLE digest ) if( !elg_verify( sig->d.elg.a, sig->d.elg.b, result, &pkey ) ) rc = G10ERR_BAD_SIGN; } + #ifdef HAVE_RSA_CIPHER else if( pkc->pubkey_algo == PUBKEY_ALGO_RSA ) { RSA_public_key pkey; @@ -214,6 +215,7 @@ signature_check( PKT_signature *sig, MD_HANDLE digest ) goto leave; } } + #endif/*HAVE_RSA_CIPHER*/ else { log_debug("signature_check: unsupported pubkey algo %d\n", pkc->pubkey_algo ); |