diff --git a/ChangeLog b/ChangeLog index a2bd775d3..e62b672bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-12-11 Werner Koch + + * Makefile.am (DISTCLEANFILES): Removed g10defs.h. + + * configure.ac (AC_CONFIG_COMMANDS): Removed creation of + g10defs.h. + (AH_BOTTOM): Moved stuff from g10defs.h to config.h. + 2006-12-07 David Shaw * configure.ac: AM_CONDITIONAL must not be used inside an if/then. diff --git a/Makefile.am b/Makefile.am index 3f1d670b8..3423e70ff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,7 @@ endif SUBDIRS = m4 intl zlib util mpi cipher tools g10 keyserver po doc ${checks} EXTRA_DIST = scripts/config.rpath PROJECTS BUGS config.h.in autogen.sh -DISTCLEANFILES = g10defs.h +DISTCLEANFILES = # Add all the files listed in "distfiles" files to the distribution, # apply version numbers to some files and create a VERSION file which diff --git a/checks/ChangeLog b/checks/ChangeLog index b338d45f4..790d4b691 100644 --- a/checks/ChangeLog +++ b/checks/ChangeLog @@ -1,3 +1,7 @@ +2006-12-11 Werner Koch + + * verify.test (msg_clsclss_asc): Work around a bug in OpenBSD. + 2006-04-19 David Shaw * sigs.test, mds.test: Add tests for SHA-224, SHA-384, and diff --git a/checks/verify.test b/checks/verify.test index bfd7baa0d..4f53b9707 100755 --- a/checks/verify.test +++ b/checks/verify.test @@ -226,6 +226,9 @@ ${msg_clss_asc}" # # Now run the tests. # +# Note that we need to use set +x/-x for the base case check +# to work around a bug in OpenBSD's sh +# for i in $tests ; do info "checking: $i" eval "(IFS=; echo \"\$$i\")" >x @@ -236,10 +239,14 @@ for i in $tests ; do msg_*_asc_multisig) $GPG --verify --allow-multisig-verification x \ || error "verify of $i failed" + set +x $GPG --verify x && error "verify of $i succeeded but should not" + set -x ;; bad_*_asc) + set +x $GPG --verify x && error "verify of $i succeeded but should not" + set -x ;; *) error "No handler for test case $i" diff --git a/cipher/ChangeLog b/cipher/ChangeLog index d504a16f8..9f7d3b366 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,19 @@ +2006-12-11 Werner Koch + + + * 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 * random.c [HAVE_GETTIMEOFDAY]: Included sys/time.h and not diff --git a/cipher/Makefile.am b/cipher/Makefile.am index 0aef60579..3e12c1f18 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -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 diff --git a/cipher/dsa.c b/cipher/dsa.c index 9745656f4..e32d90564 100644 --- a/cipher/dsa.c +++ b/cipher/dsa.c @@ -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; diff --git a/cipher/elgamal.c b/cipher/elgamal.c index 3c37a283e..eb701164d 100644 --- a/cipher/elgamal.c +++ b/cipher/elgamal.c @@ -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 ) { diff --git a/cipher/primegen.c b/cipher/primegen.c index 0662d39e0..7eccea674 100644 --- a/cipher/primegen.c +++ b/cipher/primegen.c @@ -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 ); diff --git a/cipher/rsa.c b/cipher/rsa.c index 0b00e215e..b6d7603da 100644 --- a/cipher/rsa.c +++ b/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); diff --git a/configure.ac b/configure.ac index 89e745064..4ff3412d3 100644 --- a/configure.ac +++ b/configure.ac @@ -417,24 +417,65 @@ AH_BOTTOM([ /* We didn't define endianness above, so get it from OS macros. This is intended for making fat binary builds on OS X. */ #if !defined(BIG_ENDIAN_HOST) && !defined(LITTLE_ENDIAN_HOST) -#if defined(__BIG_ENDIAN__) -#define BIG_ENDIAN_HOST 1 -#elif defined(__LITTLE_ENDIAN__) -#define LITTLE_ENDIAN_HOST 1 -#else -#error "No endianness found" -#endif +# if defined(__BIG_ENDIAN__) +# define BIG_ENDIAN_HOST 1 +# elif defined(__LITTLE_ENDIAN__) +# define LITTLE_ENDIAN_HOST 1 +# else +# error "No endianness found" +# endif #endif #if !(defined(HAVE_FORK) && defined(HAVE_PIPE) && defined(HAVE_WAITPID)) -#define EXEC_TEMPFILE_ONLY +# define EXEC_TEMPFILE_ONLY #endif +/* Please note that the string version must not contain more + than one character because the using code assumes strlen()==1 */ +#ifdef HAVE_DOSISH_SYSTEM +# define DIRSEP_C '\\' +# define EXTSEP_C '.' +# define DIRSEP_S "\\" +# define EXTSEP_S "." +# define PATHSEP_C ';' +# define PATHSEP_S ";" +#else +# define DIRSEP_C '/' +# define EXTSEP_C '.' +# define DIRSEP_S "/" +# define EXTSEP_S "." +# define PATHSEP_C ':' +# define PATHSEP_S ":" +#endif + + +/* For some OSes we need to use fixed strings for certain directories. */ +#ifdef HAVE_DRIVE_LETTERS +# define LOCALEDIR "c:\\\\lib\\\\gnupg\\\\locale" +# define GNUPG_LIBDIR "c:\\\\lib\\\\gnupg" +# define GNUPG_LIBEXECDIR "c:\\\\lib\\\\gnupg" +# define GNUPG_DATADIR "c:\\\\lib\\\\gnupg" +# define GNUPG_HOMEDIR "c:\\\\gnupg" +#else +# ifdef __VMS +# define GNUPG_HOMEDIR "/SYS\$LOGIN/gnupg" +# else +# define GNUPG_HOMEDIR "~/.gnupg" +# endif +#endif + + /* This is the major version number of GnuPG so that source included files can test for this. */ #define GNUPG_MAJOR_VERSION 1 -#include "g10defs.h" +/* This is the same as VERSION, but should be overridden if the + platform cannot handle things like dots'.' in filenames. Set + SAFE_VERSION_DOT and SAFE_VERSION_DASH to whatever SAFE_VERSION + uses for dots and dashes. */ +#define SAFE_VERSION VERSION +#define SAFE_VERSION_DOT '.' +#define SAFE_VERSION_DASH '-' #endif /*GNUPG_CONFIG_H_INCLUDED*/ ]) @@ -1333,71 +1374,6 @@ if test "$print_egd_warning" = yes; then ***]]) fi -# Note the \\\\ for backslashes. Autoconf eats one layer, leaving \\ - -AC_CONFIG_COMMANDS(g10defs.h,[[ -cat >g10defs.tmp <>g10defs.tmp -if cmp -s g10defs.h g10defs.tmp 2>/dev/null; then - echo "g10defs.h is unchanged" - rm -f g10defs.tmp -else - rm -f g10defs.h - mv g10defs.tmp g10defs.h - echo "g10defs.h created" -fi -]],[[ -prefix=$prefix -exec_prefix=$exec_prefix -libdir=$libdir -libexecdir=$libexecdir -datadir=$datadir -DATADIRNAME=$DATADIRNAME -]]) - - AC_CONFIG_FILES([ Makefile m4/Makefile diff --git a/g10/ChangeLog b/g10/ChangeLog index fb12dc708..cc7c7e27b 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,13 @@ +2006-12-11 Werner Koch + + * seskey.c (encode_session_key, do_encode_md): Use new + mpi_nlimb_hint_from_nbytes function. + * sign.c (do_sign): Ditto. + + * Makefile.am (AM_CPPFLAGS): Define GNUPG_LIBDIR. + * gpgv.c (i18n_init): s/G10_LOCALEDIR/LOCALEDIR/. + * gpg.c (i18n_init): Ditto. + 2006-12-07 Werner Koch * Makefile.am (AM_CPPFLAGS): Define GNUPG_DATADIR. @@ -31,6 +41,11 @@ re-prompt for a passphrase to ensure the user has typed it correctly. Defaults to 1. +2006-12-02 Werner Koch + + * encr-data.c: Allocate DFX context on the heap and not on the + stack. Changes at several places. Fixes CVE-2006-6235. + 2006-11-27 Werner Koch * openfile.c (ask_outfile_name): Fixed buffer overflow occurring diff --git a/g10/Makefile.am b/g10/Makefile.am index 0e7886190..86a629ea9 100644 --- a/g10/Makefile.am +++ b/g10/Makefile.am @@ -26,8 +26,10 @@ EXTRA_DIST = options.skel #OMIT_DEPENDENCIES = zlib.h zconf.h if ! HAVE_DOSISH_SYSTEM +AM_CPPFLAGS += -DLOCALEDIR="\"$(localedir)\"" AM_CPPFLAGS += -DGNUPG_LIBEXECDIR="\"$(libexecdir)/@PACKAGE@\"" AM_CPPFLAGS += -DGNUPG_DATADIR="\"$(pkgdatadir)\"" +AM_CPPFLAGS += -DGNUPG_LIBDIR="\"$(libdir)/@PACKAGE@\"" endif needed_libs = ../cipher/libcipher.a ../mpi/libmpi.a ../util/libutil.a diff --git a/g10/gpg.c b/g10/gpg.c index 691cfffa2..1d15d8f03 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -886,7 +886,7 @@ i18n_init(void) #else #ifdef ENABLE_NLS setlocale( LC_ALL, "" ); - bindtextdomain( PACKAGE, G10_LOCALEDIR ); + bindtextdomain (PACKAGE, LOCALEDIR); textdomain( PACKAGE ); #endif #endif diff --git a/g10/gpgv.c b/g10/gpgv.c index 5192c26fc..b643f0c9e 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -122,7 +122,7 @@ i18n_init(void) #else #ifdef ENABLE_NLS setlocale( LC_ALL, "" ); - bindtextdomain( PACKAGE, G10_LOCALEDIR ); + bindtextdomain (PACKAGE, LOCALEDIR); textdomain( PACKAGE ); #endif #endif diff --git a/g10/seskey.c b/g10/seskey.c index dd4dc0b6d..b25980312 100644 --- a/g10/seskey.c +++ b/g10/seskey.c @@ -138,7 +138,7 @@ encode_session_key( DEK *dek, unsigned nbits ) frame[n++] = csum >>8; frame[n++] = csum; assert( n == nframe ); - a = mpi_alloc_secure( (nframe+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB ); + a = mpi_alloc_secure ( mpi_nlimb_hint_from_nbytes (nframe) ); mpi_set_buffer( a, frame, nframe, 0 ); xfree(frame); return a; @@ -175,9 +175,9 @@ do_encode_md( MD_HANDLE md, int algo, size_t len, unsigned nbits, memcpy( frame+n, asn, asnlen ); n += asnlen; memcpy( frame+n, md_read(md, algo), len ); n += len; assert( n == nframe ); - a = md_is_secure(md)? - mpi_alloc_secure( (nframe+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB ) - : mpi_alloc( (nframe+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB ); + a = (md_is_secure(md) + ? mpi_alloc_secure ( mpi_nlimb_hint_from_nbytes (nframe) ) + : mpi_alloc ( mpi_nlimb_hint_from_nbytes (nframe ))); mpi_set_buffer( a, frame, nframe, 0 ); xfree(frame); @@ -250,9 +250,9 @@ encode_md_value( PKT_public_key *pk, PKT_secret_key *sk, return NULL; } - frame = md_is_secure(md)? mpi_alloc_secure((qbytes+BYTES_PER_MPI_LIMB-1) - / BYTES_PER_MPI_LIMB ) - : mpi_alloc((qbytes+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB ); + frame = (md_is_secure(md) + ? mpi_alloc_secure (mpi_nlimb_hint_from_nbytes (qbytes) ) + : mpi_alloc ( mpi_nlimb_hint_from_nbytes (qbytes) )); mpi_set_buffer( frame, md_read(md, hash_algo), qbytes, 0 ); } diff --git a/g10/sign.c b/g10/sign.c index 82076d78d..59d9fa204 100644 --- a/g10/sign.c +++ b/g10/sign.c @@ -308,8 +308,7 @@ do_sign( PKT_secret_key *sk, PKT_signature *sig, xfree (snbuf); if (!rc) { - sig->data[0] = mpi_alloc ( (rbuflen+BYTES_PER_MPI_LIMB-1) - / BYTES_PER_MPI_LIMB ); + sig->data[0] = mpi_alloc ( mpi_nlimb_hint_from_nbytes (rbuflen) ); mpi_set_buffer (sig->data[0], rbuf, rbuflen, 0); xfree (rbuf); } diff --git a/include/ChangeLog b/include/ChangeLog index b73f0cb1c..206d43692 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,12 @@ +2006-12-11 Werner Koch + + * mpi.h (mpi_is_neg, mpi_get_nlimbs): Replaced macros by function + prototypes. + (struct gcry_mpi): Changed to a forward declaration. + (mpi_limb_t): Moved to ../mpi/mpi-internal.h. + (MPI_NULL): Removed. + (mpi_is_opaque, mpi_is_secure): Implement in terms of mpi_get_flags. + 2006-12-04 Werner Koch * iobuf.h (iobuf_t): New. That is the name we use in 2.0. diff --git a/include/mpi.h b/include/mpi.h index bec37ce6c..81061d39c 100644 --- a/include/mpi.h +++ b/include/mpi.h @@ -37,23 +37,6 @@ #include "types.h" #include "memory.h" -#if BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_INT - typedef unsigned int mpi_limb_t; - typedef signed int mpi_limb_signed_t; -#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_LONG - typedef unsigned long int mpi_limb_t; - typedef signed long int mpi_limb_signed_t; -#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_LONG_LONG - typedef unsigned long long int mpi_limb_t; - typedef signed long long int mpi_limb_signed_t; -#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_SHORT - typedef unsigned short int mpi_limb_t; - typedef signed short int mpi_limb_signed_t; -#else -#error BYTES_PER_MPI_LIMB does not match any C type -#endif -#define BITS_PER_MPI_LIMB (8*BYTES_PER_MPI_LIMB) - #ifndef EXTERN_UNLESS_MAIN_MODULE #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) #define EXTERN_UNLESS_MAIN_MODULE extern @@ -66,23 +49,9 @@ EXTERN_UNLESS_MAIN_MODULE int mpi_debug_mode; -struct gcry_mpi { - int alloced; /* array size (# of allocated limbs) */ - int nlimbs; /* number of valid limbs */ - unsigned int nbits; /* the real number of valid bits (info only) */ - int sign; /* indicates a negative number */ - unsigned flags; /* bit 0: array must be allocated in secure memory space */ - /* bit 1: not used */ - /* bit 2: the limb is a pointer to some xmalloced data */ - mpi_limb_t *d; /* array with the limbs */ -}; - +struct gcry_mpi; typedef struct gcry_mpi *MPI; -#define MPI_NULL NULL - -#define mpi_get_nlimbs(a) ((a)->nlimbs) -#define mpi_is_neg(a) ((a)->sign) /*-- mpiutil.c --*/ @@ -107,10 +76,10 @@ void mpi_free( MPI a ); void mpi_resize( MPI a, unsigned nlimbs ); MPI mpi_copy( MPI a ); #endif -#define mpi_is_opaque(a) ((a) && ((a)->flags&4)) +#define mpi_is_opaque(a) ((a) && (mpi_get_flags (a)&4)) MPI mpi_set_opaque( MPI a, void *p, unsigned int len ); void *mpi_get_opaque( MPI a, unsigned int *len ); -#define mpi_is_secure(a) ((a) && ((a)->flags&1)) +#define mpi_is_secure(a) ((a) && (mpi_get_flags (a)&1)) void mpi_set_secure( MPI a ); void mpi_clear( MPI a ); void mpi_set( MPI w, MPI u); @@ -118,6 +87,11 @@ void mpi_set_ui( MPI w, ulong u); MPI mpi_alloc_set_ui( unsigned long u); void mpi_m_check( MPI a ); void mpi_swap( MPI a, MPI b); +int mpi_get_nlimbs (MPI a); +int mpi_is_neg (MPI a); +unsigned int mpi_nlimb_hint_from_nbytes (unsigned int nbytes); +unsigned int mpi_nlimb_hint_from_nbits (unsigned int nbits); +unsigned int mpi_get_flags (MPI a); /*-- mpicoder.c --*/ int mpi_write( IOBUF out, MPI a ); diff --git a/mpi/ChangeLog b/mpi/ChangeLog index a2af9f303..40032293a 100644 --- a/mpi/ChangeLog +++ b/mpi/ChangeLog @@ -1,3 +1,15 @@ +2006-12-11 Werner Koch + + * mpi-internal.h: Include mpi-asm-defs.h. + (mpi_limb_t): Moved definition from mpi.h to here. + (struct gcry_mpi): Moved from mpi.h to here. + * mpiutil.c (mpi_get_nlimbs, mpi_is_neg): New. To replace the + macros. This helps hiding details of the MPI implementation. + (mpi_nlimb_hint_from_nbytes, mpi_nlimb_hint_from_nbits): Ditto. + (mpi_get_flags): Ditto. + * mpicoder.c (mpi_read, mpi_read_from_buffer, mpi_print): + s/MPI_NULL/NULL/. + 2005-09-01 David Shaw * mpicoder.c (mpi_read): Fix minor bug in reading a zero-length diff --git a/mpi/config.links b/mpi/config.links index 451a5bf69..b69ad68d0 100644 --- a/mpi/config.links +++ b/mpi/config.links @@ -1,4 +1,4 @@ -# config.links - helper for ../configure +# config.links - helper for ../configure -*- sh -*- # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 # 2004 Free Software Foundation, Inc. # diff --git a/mpi/mpi-internal.h b/mpi/mpi-internal.h index 4676fcd59..468037428 100644 --- a/mpi/mpi-internal.h +++ b/mpi/mpi-internal.h @@ -32,6 +32,38 @@ #define G10_MPI_INTERNAL_H #include "mpi.h" +#include "mpi-asm-defs.h" + +#if BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_INT + typedef unsigned int mpi_limb_t; + typedef signed int mpi_limb_signed_t; +#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_LONG + typedef unsigned long int mpi_limb_t; + typedef signed long int mpi_limb_signed_t; +#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_LONG_LONG + typedef unsigned long long int mpi_limb_t; + typedef signed long long int mpi_limb_signed_t; +#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_SHORT + typedef unsigned short int mpi_limb_t; + typedef signed short int mpi_limb_signed_t; +#else +#error BYTES_PER_MPI_LIMB does not match any C type +#endif +#define BITS_PER_MPI_LIMB (8*BYTES_PER_MPI_LIMB) + + +struct gcry_mpi { + int alloced; /* array size (# of allocated limbs) */ + int nlimbs; /* number of valid limbs */ + unsigned int nbits; /* the real number of valid bits (info only) */ + int sign; /* indicates a negative number */ + unsigned flags; /* bit 0: array must be allocated in secure memory space */ + /* bit 1: not used */ + /* bit 2: the limb is a pointer to some xmalloced data */ + mpi_limb_t *d; /* array with the limbs */ +}; + + /* If KARATSUBA_THRESHOLD is not already defined, define it to a * value which is good on most machines. */ diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c index d5ce99971..ce60cdee2 100644 --- a/mpi/mpicoder.c +++ b/mpi/mpicoder.c @@ -78,7 +78,7 @@ mpi_read(IOBUF inp, unsigned *ret_nread, int secure) unsigned int nmax = *ret_nread; unsigned nbits, nbytes, nlimbs, nread=0; mpi_limb_t a; - MPI val = MPI_NULL; + MPI val = NULL; if (nread == nmax) goto overflow; @@ -148,7 +148,7 @@ mpi_read_from_buffer(byte *buffer, unsigned int *ret_nread, int secure) int i, j; unsigned nbits, nbytes, nlimbs, nread=0; mpi_limb_t a; - MPI val = MPI_NULL; + MPI val = NULL; if( *ret_nread < 2 ) goto leave; @@ -180,7 +180,7 @@ mpi_read_from_buffer(byte *buffer, unsigned int *ret_nread, int secure) checksum didn't caught it. */ log_info ("mpi larger than buffer\n"); mpi_free (val); - val = MPI_NULL; + val = NULL; goto leave; } a <<= 8; @@ -280,7 +280,7 @@ mpi_print( FILE *fp, MPI a, int mode ) { int i, n=0; - if( a == MPI_NULL ) + if( a == NULL ) return fprintf(fp, "[MPI_NULL]"); if( !mode ) { unsigned int n1; diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c index fdbd354f2..91960f8dd 100644 --- a/mpi/mpiutil.c +++ b/mpi/mpiutil.c @@ -379,7 +379,7 @@ mpi_copy( MPI a ) /**************** * This function allocates an MPI which is optimized to hold - * a value as large as the one given in the arhgument and allocates it + * a value as large as the one given in the argument and allocates it * with the same flags as A. */ MPI @@ -468,3 +468,40 @@ mpi_swap( MPI a, MPI b) tmp = *a; *a = *b; *b = tmp; } + + +int +mpi_get_nlimbs (MPI a) +{ + return a->nlimbs; +} + + +int +mpi_is_neg (MPI a) +{ + return a->sign; +} + + +/* Return the number of limbs to store an MPI which is specified by + the number of bytes to represent it. */ +unsigned int +mpi_nlimb_hint_from_nbytes (unsigned int nbytes) +{ + return (nbytes+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB; +} + +/* Return the number of limbs to store an MPI which is specified by + the number of bytes to represent it. */ +unsigned int +mpi_nlimb_hint_from_nbits (unsigned int nbits) +{ + return (nbits+BITS_PER_MPI_LIMB-1) / BITS_PER_MPI_LIMB; +} + +unsigned int +mpi_get_flags (MPI a) +{ + return a->flags; +} diff --git a/tools/ChangeLog b/tools/ChangeLog index 00455c619..00fe0b79d 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,3 +1,10 @@ +2006-12-11 Werner Koch + + * Makefile.am (AM_CPPFLAGS): Use in place of INCLUDES. Define + LOCALEDIR. + * shmtest.c (i18n_init): s/G10_LOCALEDIR/LOCALEDIR/. + * mpicalc.c (i18n_init): Ditto. + 2006-04-20 David Shaw * make-dns-cert.c (main): Small exit code tweak from Peter diff --git a/tools/Makefile.am b/tools/Makefile.am index 5efe2c1a6..8a9c03560 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -20,10 +20,17 @@ ## Process this file with automake to produce Makefile.in EXTRA_DIST = lspgpot ring-a-party mail-signed-keys convert-from-106 -INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/intl + +AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/intl + +if ! HAVE_DOSISH_SYSTEM +AM_CPPFLAGS += -DLOCALEDIR="\"$(localedir)\"" +endif + needed_libs = ../cipher/libcipher.a ../mpi/libmpi.a ../util/libutil.a other_libs = $(LIBICONV) $(LIBINTL) $(CAPLIBS) + bin_PROGRAMS = gpgsplit noinst_PROGRAMS = mpicalc bftest clean-sat mk-tdata shmtest make-dns-cert diff --git a/tools/bftest.c b/tools/bftest.c index 829c429a0..73a1196ae 100644 --- a/tools/bftest.c +++ b/tools/bftest.c @@ -50,7 +50,7 @@ i18n_init(void) { #ifdef ENABLE_NLS setlocale( LC_ALL, "" ); - bindtextdomain( PACKAGE, G10_LOCALEDIR ); + bindtextdomain (PACKAGE, LOCALEDIR); textdomain( PACKAGE ); #endif } diff --git a/tools/mpicalc.c b/tools/mpicalc.c index 915dcc32a..1df27d9d3 100644 --- a/tools/mpicalc.c +++ b/tools/mpicalc.c @@ -68,7 +68,7 @@ i18n_init(void) { #ifdef ENABLE_NLS setlocale( LC_ALL, "" ); - bindtextdomain( PACKAGE, G10_LOCALEDIR ); + bindtextdomain (PACKAGE, LOCALEDIR); textdomain( PACKAGE ); #endif } diff --git a/tools/shmtest.c b/tools/shmtest.c index f48340508..76513cbcd 100644 --- a/tools/shmtest.c +++ b/tools/shmtest.c @@ -57,7 +57,7 @@ i18n_init(void) { #ifdef ENABLE_NLS setlocale( LC_ALL, "" ); - bindtextdomain( PACKAGE, G10_LOCALEDIR ); + bindtextdomain (PACKAGE, LOCALEDIR); textdomain( PACKAGE ); #endif }