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,15 @@
|
|||
2006-12-11 Werner Koch <wk@g10code.com>
|
||||
|
||||
* 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 <dshaw@jabberwocky.com>
|
||||
|
||||
* mpicoder.c (mpi_read): Fix minor bug in reading a zero-length
|
||||
|
|
|
@ -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.
|
||||
#
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue