summaryrefslogtreecommitdiffstats
path: root/cipher
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2000-11-14 17:04:16 +0100
committerWerner Koch <wk@gnupg.org>2000-11-14 17:04:16 +0100
commit986649bea0798cb6509069d046197f9628932c01 (patch)
treeabfbefbde834a919bba8e3ada10c0d864715ec0a /cipher
parentAdd features packet and fixes MIPS3. (diff)
downloadgnupg2-986649bea0798cb6509069d046197f9628932c01.tar.xz
gnupg2-986649bea0798cb6509069d046197f9628932c01.zip
Some configuration changes
Diffstat (limited to 'cipher')
-rw-r--r--cipher/ChangeLog14
-rw-r--r--cipher/Makefile.am5
-rw-r--r--cipher/dsa.c13
-rw-r--r--cipher/elgamal.c28
-rw-r--r--cipher/primegen.c6
-rw-r--r--cipher/rsa.c40
6 files changed, 61 insertions, 45 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 38045bb1c..2a861c035 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,17 @@
+2000-11-14 Werner Koch <wk@gnupg.org>
+
+ * dsa.c (test_keys): Replaced mpi_alloc by gcry_mpi_new and
+ mpi_free by gcry_mpi_release.
+ * elgamal.c (test_keys,generate): Ditto, also for mpi_alloc_secure.
+ * rsa.c (test_keys,generate,rsa_verify): Ditto.
+ * primegen.c (generate_elg_prime): Ditto.
+ (gen_prime): Ditto and removed nlimbs.
+
+ * rsa.c (generate): Allocate 2 more vars in secure memory.
+
+ * Makefile.am (OMIT_DEPENDENCIES): Hack to work around dependency
+ problems.
+
2000-10-09 Werner Koch <wk@gnupg.org>
* arcfour.c, arcfour.h: New.
diff --git a/cipher/Makefile.am b/cipher/Makefile.am
index 0a9b10b4c..2fadfb363 100644
--- a/cipher/Makefile.am
+++ b/cipher/Makefile.am
@@ -1,10 +1,13 @@
# Process this file with automake to produce Makefile.in
-INCLUDES = -I$(top_srcdir)/gcrypt
+INCLUDES = -I$(top_srcdir)/gcrypt -I$(top_srcdir)/mpi
noinst_LTLIBRARIES = libcipher.la
+OMIT_DEPENDENCIES = types.h gcrypt.h
+
+
# The configure script greps the module names from the EXTRA_PROGRAMS line
EXTRA_PROGRAMS = rndlinux rndunix rndegd rndw32 sha1 rmd160 md5 tiger
diff --git a/cipher/dsa.c b/cipher/dsa.c
index 255fa372c..6e41dd8b1 100644
--- a/cipher/dsa.c
+++ b/cipher/dsa.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+
#include "g10lib.h"
#include "mpi.h"
#include "cipher.h"
@@ -136,9 +137,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 = gcry_mpi_new ( qbits );
+ MPI out1_a = gcry_mpi_new ( qbits );
+ MPI out1_b = gcry_mpi_new ( qbits );
pk.p = sk->p;
pk.q = sk->q;
@@ -150,9 +151,9 @@ test_keys( DSA_secret_key *sk, unsigned qbits )
if( !verify( out1_a, out1_b, test, &pk ) )
log_fatal("DSA:: sign, verify failed\n");
- mpi_free( test );
- mpi_free( out1_a );
- mpi_free( out1_b );
+ gcry_mpi_release ( test );
+ gcry_mpi_release ( out1_a );
+ gcry_mpi_release ( out1_b );
}
diff --git a/cipher/elgamal.c b/cipher/elgamal.c
index f2c029b36..c2c2c6e1a 100644
--- a/cipher/elgamal.c
+++ b/cipher/elgamal.c
@@ -121,10 +121,10 @@ static void
test_keys( ELG_secret_key *sk, unsigned 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 test = gcry_mpi_new ( 0 );
+ MPI out1_a = gcry_mpi_new ( nbits );
+ MPI out1_b = gcry_mpi_new ( nbits );
+ MPI out2 = gcry_mpi_new ( nbits );
pk.p = sk->p;
pk.g = sk->g;
@@ -141,10 +141,10 @@ test_keys( ELG_secret_key *sk, unsigned nbits )
if( !verify( out1_a, out1_b, test, &pk ) )
log_fatal("ElGamal operation: sign, verify failed\n");
- mpi_free( test );
- mpi_free( out1_a );
- mpi_free( out1_b );
- mpi_free( out2 );
+ gcry_mpi_release ( test );
+ gcry_mpi_release ( out1_a );
+ gcry_mpi_release ( out1_b );
+ gcry_mpi_release ( out2 );
}
@@ -241,8 +241,8 @@ 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 );
+ p_min1 = gcry_mpi_new ( nbits );
+ temp = gcry_mpi_new( nbits );
qbits = wiener_map( nbits );
if( qbits & 1 ) /* better have a even one */
qbits++;
@@ -265,7 +265,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 = gcry_mpi_snew ( xbits );
if( DBG_CIPHER )
log_debug("choosing a random x of size %u", xbits );
rndbuf = NULL;
@@ -294,7 +294,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 ) );
g10_free(rndbuf);
- y = mpi_alloc(nbits/BITS_PER_MPI_LIMB);
+ y = gcry_mpi_new (nbits);
gcry_mpi_powm( y, g, x, p );
if( DBG_CIPHER ) {
@@ -314,8 +314,8 @@ generate( ELG_secret_key *sk, unsigned int nbits, MPI **ret_factors )
/* now we can test our keys (this should never fail!) */
test_keys( sk, nbits - 64 );
- mpi_free( p_min1 );
- mpi_free( temp );
+ gcry_mpi_release ( p_min1 );
+ gcry_mpi_release ( temp );
}
diff --git a/cipher/primegen.c b/cipher/primegen.c
index f5dca8592..03c3c8a53 100644
--- a/cipher/primegen.c
+++ b/cipher/primegen.c
@@ -129,7 +129,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 = gcry_mpi_new ( pbits );
q = gen_prime( qbits, 0, 0 );
q_factor = mode==1? gen_prime( req_qbits, 0, 0 ) : NULL;
@@ -292,7 +292,6 @@ generate_elg_prime( int mode, unsigned pbits, unsigned qbits,
static MPI
gen_prime( unsigned nbits, int secret, int randomlevel )
{
- unsigned nlimbs;
MPI prime, ptest, pminus1, val_2, val_3, result;
int i;
unsigned x, step;
@@ -308,10 +307,9 @@ gen_prime( unsigned nbits, int secret, int randomlevel )
}
mods = g10_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;
val_2 = mpi_alloc_set_ui( 2 );
val_3 = mpi_alloc_set_ui( 3);
- prime = secret? mpi_alloc_secure( nlimbs ): mpi_alloc( nlimbs );
+ prime = secret? gcry_mpi_snew ( nbits ): gcry_mpi_new ( nbits );
result = mpi_alloc_like( prime );
pminus1= mpi_alloc_like( prime );
ptest = mpi_alloc_like( prime );
diff --git a/cipher/rsa.c b/cipher/rsa.c
index f342e3c35..e7ecccbc2 100644
--- a/cipher/rsa.c
+++ b/cipher/rsa.c
@@ -61,9 +61,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 = gcry_mpi_new ( nbits );
+ MPI out1 = gcry_mpi_new ( nbits );
+ MPI out2 = gcry_mpi_new ( nbits );
pk.n = sk->n;
pk.e = sk->e;
@@ -77,9 +77,9 @@ test_keys( RSA_secret_key *sk, unsigned nbits )
public( out2, out1, &pk );
if( mpi_cmp( test, out2 ) )
log_fatal("RSA operation: secret, public failed\n");
- mpi_free( test );
- mpi_free( out1 );
- mpi_free( out2 );
+ gcry_mpi_release ( test );
+ gcry_mpi_release ( out1 );
+ gcry_mpi_release ( out2 );
}
/****************
@@ -107,27 +107,27 @@ 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 = gcry_mpi_snew ( nbits );
+ g = gcry_mpi_snew ( nbits );
+ f = gcry_mpi_snew ( nbits );
mpi_sub_ui( t1, p, 1 );
mpi_sub_ui( t2, q, 1 );
mpi_mul( phi, t1, t2 );
mpi_gcd(g, t1, t2);
mpi_fdiv_q(f, phi, g);
/* multiply them to make the private key */
- n = mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
+ n = gcry_mpi_new ( nbits );
mpi_mul( n, p, q );
/* find a public exponent */
- e = mpi_alloc( (6+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
+ e = gcry_mpi_new ( 6 );
mpi_set_ui( e, 17); /* start with 17 */
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 = gcry_mpi_snew ( 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 = gcry_mpi_snew ( nbits );
mpi_invm(u, p, q );
if( DBG_CIPHER ) {
@@ -142,11 +142,11 @@ generate( RSA_secret_key *sk, unsigned nbits )
log_mpidump(" u= ", u );
}
- mpi_free(t1);
- mpi_free(t2);
- mpi_free(phi);
- mpi_free(f);
- mpi_free(g);
+ gcry_mpi_release (t1);
+ gcry_mpi_release (t2);
+ gcry_mpi_release (phi);
+ gcry_mpi_release (f);
+ gcry_mpi_release (g);
sk->n = n;
sk->e = e;
@@ -416,11 +416,11 @@ rsa_verify( int algo, MPI hash, MPI *data, MPI *pkey,
return GCRYERR_INV_PK_ALGO;
pk.n = pkey[0];
pk.e = pkey[1];
- result = mpi_alloc( (160+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB);
+ result = gcry_mpi_new ( 160 );
public( result, data[0], &pk );
/*rc = (*cmp)( opaquev, result );*/
rc = mpi_cmp( result, hash )? GCRYERR_BAD_SIGNATURE:0;
- mpi_free(result);
+ gcry_mpi_release (result);
return rc;
}