diff options
Diffstat (limited to 'cipher')
-rw-r--r-- | cipher/elgamal.c | 6 | ||||
-rw-r--r-- | cipher/elgamal.h | 3 | ||||
-rw-r--r-- | cipher/md.c | 14 | ||||
-rw-r--r-- | cipher/primegen.c | 11 | ||||
-rw-r--r-- | cipher/random.c | 5 |
5 files changed, 31 insertions, 8 deletions
diff --git a/cipher/elgamal.c b/cipher/elgamal.c index 9e6805d62..5e6bd0c84 100644 --- a/cipher/elgamal.c +++ b/cipher/elgamal.c @@ -113,9 +113,11 @@ gen_k( MPI p ) /**************** * Generate a key pair with a key of size NBITS * Returns: 2 structures filles with all needed values + * and an array with n-1 factors of (p-1) */ void -elg_generate( ELG_public_key *pk, ELG_secret_key *sk, unsigned nbits ) +elg_generate( ELG_public_key *pk, ELG_secret_key *sk, + unsigned nbits, MPI **ret_factors ) { MPI p; /* the prime */ MPI p_min1; @@ -136,7 +138,7 @@ elg_generate( ELG_public_key *pk, ELG_secret_key *sk, unsigned nbits ) else qbits = 240; g = mpi_alloc(1); - p = generate_elg_prime( nbits, qbits, g ); + p = generate_elg_prime( nbits, qbits, g, ret_factors ); mpi_sub_ui(p_min1, p, 1); diff --git a/cipher/elgamal.h b/cipher/elgamal.h index 15121f55c..26af1a007 100644 --- a/cipher/elgamal.h +++ b/cipher/elgamal.h @@ -39,7 +39,8 @@ typedef struct { void elg_free_public_key( ELG_public_key *pk ); void elg_free_secret_key( ELG_secret_key *sk ); -void elg_generate( ELG_public_key *pk, ELG_secret_key *sk, unsigned nbits ); +void elg_generate( ELG_public_key *pk, ELG_secret_key *sk, + unsigned nbits, MPI **factors ); int elg_check_secret_key( ELG_secret_key *sk ); void elg_encrypt(MPI a, MPI b, MPI input, ELG_public_key *pkey ); void elg_decrypt(MPI output, MPI a, MPI b, ELG_secret_key *skey ); diff --git a/cipher/md.c b/cipher/md.c index 221cf7199..c89c8bb95 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -28,6 +28,8 @@ #include "errors.h" +static FILE *dumpfp; + /**************** * Open a message digest handle for use with algorithm ALGO. * More algorithms may be added by md_enable(). The initial algorithm @@ -38,6 +40,12 @@ md_open( int algo, int secure ) { MD_HANDLE hd; + if( !dumpfp ) + dumpfp = fopen("md.out", "w"); + if( !dumpfp ) + BUG(); + { int i; for(i=0; i < 16; i++ ) putc('\xff', dumpfp ); } + hd = secure ? m_alloc_secure_clear( sizeof *hd ) : m_alloc_clear( sizeof *hd ); if( algo ) @@ -70,6 +78,7 @@ md_copy( MD_HANDLE a ) { MD_HANDLE b; + { int i; for(i=0; i < 16; i++ ) putc('\xee', dumpfp ); } b = m_is_secure(a)? m_alloc_secure( sizeof *b ) : m_alloc( sizeof *b ); memcpy( b, a, sizeof *a ); @@ -89,6 +98,10 @@ md_close(MD_HANDLE a) void md_write( MD_HANDLE a, byte *inbuf, size_t inlen) { + if( a->bufcount && fwrite(a->buffer, a->bufcount, 1, dumpfp ) != 1 ) + BUG(); + if( inlen && fwrite(inbuf, inlen, 1, dumpfp ) != 1 ) + BUG(); if( a->use_rmd160 ) { rmd160_write( &a->rmd160, a->buffer, a->bufcount ); rmd160_write( &a->rmd160, inbuf, inlen ); @@ -111,6 +124,7 @@ md_final(MD_HANDLE a) { if( a->bufcount ) md_write( a, NULL, 0 ); + { int i; for(i=0; i < 16; i++ ) putc('\xcc', dumpfp ); } if( a->use_rmd160 ) { byte *p; rmd160_final( &a->rmd160 ); diff --git a/cipher/primegen.c b/cipher/primegen.c index 9d91ae4df..3a2a91f7b 100644 --- a/cipher/primegen.c +++ b/cipher/primegen.c @@ -65,12 +65,12 @@ generate_public_prime( unsigned nbits ) * indeed a strong prime. */ MPI -generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) +generate_elg_prime( unsigned pbits, unsigned qbits, MPI g, MPI **ret_factors ) { int n; /* number of factors */ int m; /* number of primes in pool */ unsigned fbits; /* length of prime factors */ - MPI *factors; /* curent factors */ + MPI *factors; /* current factors */ MPI *pool; /* pool of primes */ MPI q; /* first prime factor */ MPI prime; /* prime test value */ @@ -167,7 +167,6 @@ generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) count2 = 0; } while( !(nprime == pbits && check_prime( prime )) ); - if( DBG_CIPHER ) { putc('\n', stderr); log_mpidump( "prime : ", prime ); @@ -180,6 +179,12 @@ generate_elg_prime( unsigned pbits, unsigned qbits, MPI g ) putc('\n', stderr); } + if( ret_factors ) { /* caller wants the factors */ + *ret_factors = m_alloc_clear( (n+1) * sizeof **ret_factors ); + for(i=0; i < n; i++ ) + (*ret_factors)[i] = mpi_copy( factors[i] ); + } + if( g ) { /* create a generator (start with 3)*/ MPI tmp = mpi_alloc( mpi_get_nlimbs(prime) ); MPI b = mpi_alloc( mpi_get_nlimbs(prime) ); diff --git a/cipher/random.c b/cipher/random.c index ac98f54c2..26777aa91 100644 --- a/cipher/random.c +++ b/cipher/random.c @@ -144,8 +144,9 @@ fill_buffer( byte *buffer, size_t length, int level ) if( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) ) { if( !warn ) tty_printf( _( -"\nNot enough random bytes available. Please do some other work to give -the OS a chance to collect more entropy! (Need %d more bytes)\n"), length ); +"\n" +"Not enough random bytes available. Please do some other work to give\n" +"the OS a chance to collect more entropy! (Need %d more bytes)\n"), length ); warn = 1; continue; } |