1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

See ChangeLog: Mon Nov 15 21:36:02 CET 1999 Werner Koch

This commit is contained in:
Werner Koch 1999-11-15 20:32:25 +00:00
parent 881e513237
commit 37f3c09edb
17 changed files with 67 additions and 60 deletions

View file

@ -1,3 +1,10 @@
Mon Nov 15 21:36:02 CET 1999 Werner Koch <wk@gnupg.de>
* elgamal.c (gen_k): Use the new random API.
(generate): Ditto.
* dsa.c (gen_k): Ditto.
(generate): Ditto.
Sat Nov 13 17:44:23 CET 1999 Werner Koch <wk@gnupg.de>
* pubkey.c (disable_pubkey_algo): Made static.

View file

@ -79,13 +79,14 @@ gen_k( MPI q )
if( !rndbuf || nbits < 32 ) {
g10_free(rndbuf);
rndbuf = get_random_bits( nbits, 1, 1 );
rndbuf = gcry_random_bytes_secure( (nbits+7)/8,
GCRY_STRONG_RANDOM );
}
else { /* change only some of the higher bits */
/* we could imporove this by directly requesting more memory
* at the first call to get_random_bits() and use this the here
* at the first call to get_random_bytes() and use this the here
* maybe it is easier to do this directly in random.c */
char *pp = get_random_bits( 32, 1, 1 );
char *pp = gcry_random_bytes_secure( 4, GCRY_STRONG_RANDOM );
memcpy( rndbuf,pp, 4 );
g10_free(pp);
}
@ -129,8 +130,7 @@ test_keys( DSA_secret_key *sk, unsigned qbits )
pk.q = sk->q;
pk.g = sk->g;
pk.y = sk->y;
/*mpi_set_bytes( test, qbits, get_random_byte, 0 );*/
{ char *p = get_random_bits( qbits, 0, 0 );
{ char *p = gcry_random_bytes( (qbits+7)/8, GCRY_WEAK_RANDOM );
mpi_set_buffer( test, p, (qbits+7)/8, 0 );
g10_free(p);
}
@ -199,10 +199,12 @@ generate( DSA_secret_key *sk, unsigned nbits, MPI **ret_factors )
if( DBG_CIPHER )
progress('.');
if( !rndbuf )
rndbuf = get_random_bits( qbits, 2, 1 );
rndbuf = gcry_random_bytes_secure( (qbits+7)/8,
GCRY_VERY_STRONG_RANDOM );
else { /* change only some of the higher bits (= 2 bytes)*/
char *r = get_random_bits( 16, 2, 1 );
memcpy(rndbuf, r, 16/8 );
char *r = gcry_random_bytes_secure( 2,
GCRY_VERY_STRONG_RANDOM );
memcpy(rndbuf, r, 2 );
g10_free(r);
}
mpi_set_buffer( x, rndbuf, (qbits+7)/8, 0 );
@ -454,7 +456,7 @@ dsa_get_info( int algo, int *npkey, int *nskey, int *nenc, int *nsig,
*nsig = 2;
switch( algo ) {
case PUBKEY_ALGO_DSA: *use = PUBKEY_USAGE_SIG; return "DSA";
case PUBKEY_ALGO_DSA: *use = GCRY_PK_USAGE_SIGN; return "DSA";
default: *use = 0; return NULL;
}
}

View file

@ -78,11 +78,12 @@ test_keys( ELG_secret_key *sk, unsigned nbits )
pk.y = sk->y;
/*mpi_set_bytes( test, nbits, get_random_byte, 0 );*/
{ char *p = get_random_bits( nbits, 0, 0 );
{ char *p = gcry_random_bytes( (nbits+7)/8, GCRY_WEAK_RANDOM );
mpi_set_buffer( test, p, (nbits+7)/8, 0 );
g10_free(p);
}
encrypt( out1_a, out1_b, test, &pk );
decrypt( out2, out1_a, out1_b, sk );
if( mpi_cmp( test, out2 ) )
@ -121,14 +122,14 @@ gen_k( MPI p )
progress('.');
if( !rndbuf || nbits < 32 ) {
g10_free(rndbuf);
rndbuf = get_random_bits( nbits, 1, 1 );
rndbuf = gcry_random_bytes_secure( nbytes, GCRY_STRONG_RANDOM );
}
else { /* change only some of the higher bits */
/* we could imporove this by directly requesting more memory
* at the first call to get_random_bits() and use this the here
* at the first call to get_random_bytes() and use this the here
* maybe it is easier to do this directly in random.c */
char *pp = get_random_bits( 32, 1, 1 );
memcpy( rndbuf,pp, 4 );
char *pp = gcry_random_bytes_secure( 4, GCRY_STRONG_RANDOM );
memcpy( rndbuf, pp, 4 );
g10_free(pp);
}
mpi_set_buffer( k, rndbuf, nbytes, 0 );
@ -214,16 +215,20 @@ generate( ELG_secret_key *sk, unsigned nbits, MPI **ret_factors )
if( rndbuf ) { /* change only some of the higher bits */
if( nbits < 16 ) {/* should never happen ... */
g10_free(rndbuf);
rndbuf = get_random_bits( nbits, 2, 1 );
rndbuf = gcry_random_bytes_secure( (nbits+7)/8,
GCRY_VERY_STRONG_RANDOM );
}
else {
char *r = get_random_bits( 16, 2, 1 );
memcpy(rndbuf, r, 16/8 );
char *r = gcry_random_bytes_secure( 2,
GCRY_VERY_STRONG_RANDOM );
memcpy(rndbuf, r, 2 );
g10_free(r);
}
}
else
rndbuf = get_random_bits( nbits, 2, 1 );
else {
rndbuf = gcry_random_bytes_secure( (nbits+7)/8,
GCRY_VERY_STRONG_RANDOM );
}
mpi_set_buffer( x, rndbuf, (nbits+7)/8, 0 );
mpi_clear_highbit( x, nbits+1 );
} while( !( mpi_cmp_ui( x, 0 )>0 && mpi_cmp( x, p_min1 )<0 ) );
@ -589,10 +594,10 @@ elg_get_info( int algo, int *npkey, int *nskey, int *nenc, int *nsig,
switch( algo ) {
case PUBKEY_ALGO_ELGAMAL:
*use = PUBKEY_USAGE_SIG|PUBKEY_USAGE_ENC;
*use = GCRY_PK_USAGE_SIGN|GCRY_PK_USAGE_ENCR;
return "ELG";
case PUBKEY_ALGO_ELGAMAL_E:
*use = PUBKEY_USAGE_SIG|PUBKEY_USAGE_ENC;
*use = GCRY_PK_USAGE_SIGN|GCRY_PK_USAGE_ENCR;
return "ELG-E";
default: *use = 0; return NULL;
}

View file

@ -326,7 +326,7 @@ md_enable( GCRY_MD_HD hd, int algo )
- sizeof(r->context) )
: g10_malloc( sizeof *ac + r->contextsize
- sizeof(r->context) );
if( !rc )
if( !ac )
return set_lasterr( GCRYERR_NO_MEM );
*ac = *r;

View file

@ -122,7 +122,7 @@ generate_elg_prime( int mode, unsigned pbits, unsigned qbits,
q_factor = mode==1? gen_prime( req_qbits, 0, 1 ) : NULL;
/* allocate an array to hold the factors + 2 for later usage */
factors = g10_xcalloc_clear( n+2, sizeof *factors );
factors = g10_xcalloc( n+2, sizeof *factors );
/* make a pool of 3n+5 primes (this is an arbitrary value) */
m = n*3+5;

View file

@ -670,7 +670,7 @@ sexp_to_key( GCRY_SEXP sexp, int want_private, MPI **retarray, int *retalgo)
elems1 = algo_info_table[i].common_elements;
elems2 = want_private? algo_info_table[i].secret_elements
: algo_info_table[i].public_elements;
array = g10_calloc( (strlen(elems1)+strlen(elems2)+1, sizeof *array );
array = g10_calloc( strlen(elems1)+strlen(elems2)+1, sizeof *array );
if( !array )
return GCRYERR_NO_MEM;
@ -825,7 +825,7 @@ gcry_pk_sign( GCRY_SEXP *r_sig, GCRY_SEXP s_hash, GCRY_SEXP s_skey )
release_mpi_array( skey );
return -1; /* fixme: get a real errorcode for this */
}
result = g10_xcalloc_clear( (strlen(algo_elems)+1) , sizeof *result );
result = g10_xcalloc( (strlen(algo_elems)+1) , sizeof *result );
rc = pubkey_sign( algo, result, hash, skey );
release_mpi_array( skey );
mpi_free( hash );

View file

@ -49,7 +49,6 @@
#include "util.h"
#include "rmd.h"
#include "ttyio.h"
#include "i18n.h"
#include "random.h"
#include "rand-internal.h"
#include "dynload.h"

View file

@ -37,12 +37,6 @@
#include "dynload.h"
#include "cipher.h"
#ifdef IS_MODULE
#define _(a) (a)
#else
#include "i18n.h"
#endif
#ifndef offsetof
#define offsetof(type, member) ((size_t) &((type *)0)->member)
#endif

View file

@ -41,16 +41,11 @@
#endif
#endif
#include "types.h"
#include "g10lib.h" /* need this for i18n */
#include "util.h"
#include "ttyio.h"
#include "dynload.h"
#ifdef IS_MODULE
#define _(a) (a)
#else
#include "i18n.h"
#endif
static int open_device( const char *name, int minor );
static int gather_random( void (*add)(const void*, size_t, int), int requester,
size_t length, int level );

View file

@ -44,8 +44,8 @@
code base to be maintained */
/* Fixme: We use plain mallocs here beucase it may be used as a module
* should be changed. *
/* Fixme: We use plain mallocs here beucase it may be used as a module
* should be changed. */
/* General includes */