diff options
Diffstat (limited to 'mpi')
-rw-r--r-- | mpi/ChangeLog | 12 | ||||
-rw-r--r-- | mpi/config.links | 2 | ||||
-rw-r--r-- | mpi/mpi-internal.h | 32 | ||||
-rw-r--r-- | mpi/mpicoder.c | 8 | ||||
-rw-r--r-- | mpi/mpiutil.c | 39 |
5 files changed, 87 insertions, 6 deletions
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 <[email protected]> + + * 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 <[email protected]> * 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; +} |