mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Removed the use of g10defs.h.
This required some code cleanups and the introduction of a few accessor ducntions in mpi.
This commit is contained in:
parent
d382fece03
commit
9f433cccca
29 changed files with 267 additions and 157 deletions
|
@ -1,3 +1,19 @@
|
|||
2006-12-11 Werner Koch <wk@g10code.com>
|
||||
|
||||
|
||||
* elgamal.c (test_keys): Use new mpi_nlimb_hint_from_nbits
|
||||
function. This also rounds up the value.
|
||||
(generate): Use new mpi_nlimb_hint_from_nbits function.
|
||||
* rsa.c (test_keys): Ditto.
|
||||
(generate): Ditto.
|
||||
(rsa_verify): Ditto.
|
||||
* primegen.c (generate_elg_prime): Ditto.
|
||||
(gen_prime): Ditto.
|
||||
* dsa.c (test_keys): Ditto. This also rounds up the value.
|
||||
|
||||
* Makefile.am (AM_CPPFLAGS): Use instead of INCLUDES. define
|
||||
GNUPG_LIBDIR.
|
||||
|
||||
2006-11-03 Werner Koch <wk@g10code.com>
|
||||
|
||||
* random.c [HAVE_GETTIMEOFDAY]: Included sys/time.h and not
|
||||
|
|
|
@ -19,7 +19,12 @@
|
|||
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
INCLUDES = -I.. -I$(top_srcdir)/include -I$(top_srcdir)/intl
|
||||
AM_CPPFLAGS = -I.. -I$(top_srcdir)/include -I$(top_srcdir)/intl
|
||||
|
||||
if ! HAVE_DOSISH_SYSTEM
|
||||
AM_CPPFLAGS += -DGNUPG_LIBDIR="\"$(libdir)/@PACKAGE@\""
|
||||
endif
|
||||
|
||||
|
||||
noinst_LIBRARIES = libcipher.a
|
||||
|
||||
|
|
|
@ -138,9 +138,9 @@ static void
|
|||
test_keys( DSA_secret_key *sk, unsigned qbits )
|
||||
{
|
||||
DSA_public_key pk;
|
||||
MPI test = mpi_alloc( qbits / BITS_PER_MPI_LIMB );
|
||||
MPI out1_a = mpi_alloc( qbits / BITS_PER_MPI_LIMB );
|
||||
MPI out1_b = mpi_alloc( qbits / BITS_PER_MPI_LIMB );
|
||||
MPI test = mpi_alloc ( mpi_nlimb_hint_from_nbits (qbits) );
|
||||
MPI out1_a = mpi_alloc ( mpi_nlimb_hint_from_nbits (qbits) );
|
||||
MPI out1_b = mpi_alloc( mpi_nlimb_hint_from_nbits (qbits) );
|
||||
|
||||
pk.p = sk->p;
|
||||
pk.q = sk->q;
|
||||
|
|
|
@ -118,13 +118,13 @@ wiener_map( unsigned int n )
|
|||
}
|
||||
|
||||
static void
|
||||
test_keys( ELG_secret_key *sk, unsigned nbits )
|
||||
test_keys( ELG_secret_key *sk, unsigned int nbits )
|
||||
{
|
||||
ELG_public_key pk;
|
||||
MPI test = mpi_alloc( 0 );
|
||||
MPI out1_a = mpi_alloc( nbits / BITS_PER_MPI_LIMB );
|
||||
MPI out1_b = mpi_alloc( nbits / BITS_PER_MPI_LIMB );
|
||||
MPI out2 = mpi_alloc( nbits / BITS_PER_MPI_LIMB );
|
||||
MPI out1_a = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
MPI out1_b = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
MPI out2 = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
|
||||
pk.p = sk->p;
|
||||
pk.g = sk->g;
|
||||
|
@ -244,9 +244,9 @@ generate( ELG_secret_key *sk, unsigned int nbits, MPI **ret_factors )
|
|||
unsigned int xbits;
|
||||
byte *rndbuf;
|
||||
|
||||
p_min1 = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
temp = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
qbits = wiener_map( nbits );
|
||||
p_min1 = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
temp = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
qbits = wiener_map ( nbits );
|
||||
if( qbits & 1 ) /* better have a even one */
|
||||
qbits++;
|
||||
g = mpi_alloc(1);
|
||||
|
@ -271,7 +271,7 @@ generate( ELG_secret_key *sk, unsigned int nbits, MPI **ret_factors )
|
|||
xbits = qbits * 3 / 2;
|
||||
if( xbits >= nbits )
|
||||
BUG();
|
||||
x = mpi_alloc_secure( xbits/BITS_PER_MPI_LIMB );
|
||||
x = mpi_alloc_secure ( mpi_nlimb_hint_from_nbits (xbits) );
|
||||
if( DBG_CIPHER )
|
||||
log_debug("choosing a random x of size %u", xbits );
|
||||
rndbuf = NULL;
|
||||
|
@ -296,7 +296,7 @@ generate( ELG_secret_key *sk, unsigned int nbits, MPI **ret_factors )
|
|||
} while( !( mpi_cmp_ui( x, 0 )>0 && mpi_cmp( x, p_min1 )<0 ) );
|
||||
xfree(rndbuf);
|
||||
|
||||
y = mpi_alloc(nbits/BITS_PER_MPI_LIMB);
|
||||
y = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
mpi_powm( y, g, x, p );
|
||||
|
||||
if( DBG_CIPHER ) {
|
||||
|
|
|
@ -132,7 +132,7 @@ generate_elg_prime( int mode, unsigned pbits, unsigned qbits,
|
|||
if( DBG_CIPHER )
|
||||
log_debug("gen prime: pbits=%u qbits=%u fbits=%u/%u n=%d\n",
|
||||
pbits, req_qbits, qbits, fbits, n );
|
||||
prime = mpi_alloc( (pbits + BITS_PER_MPI_LIMB - 1) / BITS_PER_MPI_LIMB );
|
||||
prime = mpi_alloc ( mpi_nlimb_hint_from_nbits (pbits) );
|
||||
q = gen_prime( qbits, 0, 0 );
|
||||
q_factor = mode==1? gen_prime( req_qbits, 0, 0 ) : NULL;
|
||||
|
||||
|
@ -318,8 +318,8 @@ gen_prime( unsigned int nbits, int secret, int randomlevel )
|
|||
no_of_small_prime_numbers++;
|
||||
}
|
||||
mods = xmalloc( no_of_small_prime_numbers * sizeof *mods );
|
||||
/* make nbits fit into MPI implementation */
|
||||
nlimbs = (nbits + BITS_PER_MPI_LIMB - 1) / BITS_PER_MPI_LIMB;
|
||||
/* Make nbits fit into MPI implementation. */
|
||||
nlimbs = mpi_nlimb_hint_from_nbits (nbits);
|
||||
val_2 = mpi_alloc_set_ui( 2 );
|
||||
val_3 = mpi_alloc_set_ui( 3);
|
||||
prime = secret? mpi_alloc_secure( nlimbs ): mpi_alloc( nlimbs );
|
||||
|
|
22
cipher/rsa.c
22
cipher/rsa.c
|
@ -62,9 +62,9 @@ static void
|
|||
test_keys( RSA_secret_key *sk, unsigned nbits )
|
||||
{
|
||||
RSA_public_key pk;
|
||||
MPI test = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
MPI out1 = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
MPI out2 = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
MPI test = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
MPI out1 = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
MPI out2 = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
|
||||
pk.n = sk->n;
|
||||
pk.e = sk->e;
|
||||
|
@ -107,7 +107,7 @@ generate( RSA_secret_key *sk, unsigned nbits )
|
|||
if ( (nbits&1) )
|
||||
nbits++;
|
||||
|
||||
n = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
n = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
|
||||
p = q = NULL;
|
||||
do {
|
||||
|
@ -127,9 +127,9 @@ generate( RSA_secret_key *sk, unsigned nbits )
|
|||
/* calculate Euler totient: phi = (p-1)(q-1) */
|
||||
t1 = mpi_alloc_secure( mpi_get_nlimbs(p) );
|
||||
t2 = mpi_alloc_secure( mpi_get_nlimbs(p) );
|
||||
phi = mpi_alloc_secure( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
g = mpi_alloc_secure( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
f = mpi_alloc_secure( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
phi = mpi_alloc_secure ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
g = mpi_alloc_secure ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
f = mpi_alloc_secure ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
mpi_sub_ui( t1, p, 1 );
|
||||
mpi_sub_ui( t2, q, 1 );
|
||||
mpi_mul( phi, t1, t2 );
|
||||
|
@ -147,16 +147,16 @@ generate( RSA_secret_key *sk, unsigned nbits )
|
|||
This code used 41 until 2006-06-28 when it was changed to use
|
||||
65537 as the new best practice. See FIPS-186-3.
|
||||
*/
|
||||
e = mpi_alloc( (32+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
e = mpi_alloc ( mpi_nlimb_hint_from_nbits (32) );
|
||||
mpi_set_ui( e, 65537);
|
||||
while( !mpi_gcd(t1, e, phi) ) /* (while gcd is not 1) */
|
||||
mpi_add_ui( e, e, 2);
|
||||
|
||||
/* calculate the secret key d = e^1 mod phi */
|
||||
d = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
d = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
mpi_invm(d, e, f );
|
||||
/* calculate the inverse of p and q (used for chinese remainder theorem)*/
|
||||
u = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
|
||||
u = mpi_alloc ( mpi_nlimb_hint_from_nbits (nbits) );
|
||||
mpi_invm(u, p, q );
|
||||
|
||||
if( DBG_CIPHER ) {
|
||||
|
@ -443,7 +443,7 @@ rsa_verify( int algo, MPI hash, MPI *data, MPI *pkey )
|
|||
return G10ERR_PUBKEY_ALGO;
|
||||
pk.n = pkey[0];
|
||||
pk.e = pkey[1];
|
||||
result = mpi_alloc( (160+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB);
|
||||
result = mpi_alloc ( mpi_nlimb_hint_from_nbits (160) );
|
||||
public( result, data[0], &pk );
|
||||
rc = mpi_cmp( result, hash )? G10ERR_BAD_SIGN:0;
|
||||
mpi_free(result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue