1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

* mpi-bit.c (mpi_normalize): Replaced the check for protected by

is_opaque.
(mpi_get_nbits): Removed the special case for protected MPIs.
* mpicoder.c (do_get_buffer): Likewise.
(mpi_print): Removed the nbit_info printing.
This commit is contained in:
Werner Koch 2002-09-11 07:28:44 +00:00
parent c5445cc323
commit 7a71a26d59
5 changed files with 41 additions and 44 deletions

View File

@ -1,3 +1,9 @@
2002-09-10 Werner Koch <wk@gnupg.org>
* mpi.h (mpi_is_protected, mpi_set_protect_flag)
(mpi_clear_protect_flag): Removed.
(mpi_get_nbit_info, mpi_set_nbit_info): Removed.
2002-08-13 David Shaw <dshaw@jabberwocky.com> 2002-08-13 David Shaw <dshaw@jabberwocky.com>
* cipher.h: Add AES aliases for RIJNDAEL algo numbers. * cipher.h: Add AES aliases for RIJNDAEL algo numbers.

View File

@ -71,7 +71,7 @@ struct gcry_mpi {
int nbits; /* the real number of valid bits (info only) */ int nbits; /* the real number of valid bits (info only) */
int sign; /* indicates a negative number */ int sign; /* indicates a negative number */
unsigned flags; /* bit 0: array must be allocated in secure memory space */ unsigned flags; /* bit 0: array must be allocated in secure memory space */
/* bit 1: the mpi is encrypted */ /* bit 1: not used */
/* bit 2: the limb is a pointer to some m_alloced data */ /* bit 2: the limb is a pointer to some m_alloced data */
mpi_limb_t *d; /* array with the limbs */ mpi_limb_t *d; /* array with the limbs */
}; };
@ -81,8 +81,6 @@ typedef struct gcry_mpi *MPI;
#define MPI_NULL NULL #define MPI_NULL NULL
#define mpi_get_nlimbs(a) ((a)->nlimbs) #define mpi_get_nlimbs(a) ((a)->nlimbs)
#define mpi_get_nbit_info(a) ((a)->nbits)
#define mpi_set_nbit_info(a,b) ((a)->nbits = (b))
#define mpi_is_neg(a) ((a)->sign) #define mpi_is_neg(a) ((a)->sign)
/*-- mpiutil.c --*/ /*-- mpiutil.c --*/
@ -111,9 +109,6 @@ typedef struct gcry_mpi *MPI;
#define mpi_is_opaque(a) ((a) && ((a)->flags&4)) #define mpi_is_opaque(a) ((a) && ((a)->flags&4))
MPI mpi_set_opaque( MPI a, void *p, int len ); MPI mpi_set_opaque( MPI a, void *p, int len );
void *mpi_get_opaque( MPI a, int *len ); void *mpi_get_opaque( MPI a, int *len );
#define mpi_is_protected(a) ((a) && ((a)->flags&2))
#define mpi_set_protect_flag(a) ((a)->flags |= 2)
#define mpi_clear_protect_flag(a) ((a)->flags &= ~2)
#define mpi_is_secure(a) ((a) && ((a)->flags&1)) #define mpi_is_secure(a) ((a) && ((a)->flags&1))
void mpi_set_secure( MPI a ); void mpi_set_secure( MPI a );
void mpi_clear( MPI a ); void mpi_clear( MPI a );

View File

@ -1,3 +1,11 @@
2002-09-10 Werner Koch <wk@gnupg.org>
* mpi-bit.c (mpi_normalize): Replaced the check for protected by
is_opaque.
(mpi_get_nbits): Removed the special case for protected MPIs.
* mpicoder.c (do_get_buffer): Likewise.
(mpi_print): Removed the nbit_info printing.
2002-09-03 Werner Koch <wk@gnupg.org> 2002-09-03 Werner Koch <wk@gnupg.org>
* mpicoder.c (mpi_set_buffer): Cast all left operands of a shift * mpicoder.c (mpi_set_buffer): Cast all left operands of a shift

View File

@ -55,7 +55,7 @@ __clz_tab[] =
void void
mpi_normalize( MPI a ) mpi_normalize( MPI a )
{ {
if( mpi_is_protected(a) ) if( mpi_is_opaque (a) )
return; return;
for( ; a->nlimbs && !a->d[a->nlimbs-1]; a->nlimbs-- ) for( ; a->nlimbs && !a->d[a->nlimbs-1]; a->nlimbs-- )
@ -72,13 +72,6 @@ mpi_get_nbits( MPI a )
{ {
unsigned n; unsigned n;
if( mpi_is_protected(a) ) {
n = mpi_get_nbit_info(a);
if( !n )
n = a->nlimbs * BITS_PER_MPI_LIMB;
return n;
}
mpi_normalize( a ); mpi_normalize( a );
if( a->nlimbs ) { if( a->nlimbs ) {
mpi_limb_t alimb = a->d[a->nlimbs-1]; mpi_limb_t alimb = a->d[a->nlimbs-1];

View File

@ -255,29 +255,26 @@ mpi_print( FILE *fp, MPI a, int mode )
if( a == MPI_NULL ) if( a == MPI_NULL )
return fprintf(fp, "[MPI_NULL]"); return fprintf(fp, "[MPI_NULL]");
if( !mode ) { if( !mode ) {
unsigned n1, n2; unsigned int n1;
n1 = mpi_get_nbits(a); n1 = mpi_get_nbits(a);
n2 = mpi_get_nbit_info(a);
if( n2 && n2 != n1 )
n += fprintf(fp, "[%u bits (%u)]", n1, n2 );
else
n += fprintf(fp, "[%u bits]", n1); n += fprintf(fp, "[%u bits]", n1);
} }
else { else {
if( a->sign ) if( a->sign )
putc('-', fp); putc('-', fp);
#if BYTES_PER_MPI_LIMB == 2 #if BYTES_PER_MPI_LIMB == 2
#define X "4" #define X "4"
#elif BYTES_PER_MPI_LIMB == 4 #elif BYTES_PER_MPI_LIMB == 4
#define X "8" #define X "8"
#elif BYTES_PER_MPI_LIMB == 8 #elif BYTES_PER_MPI_LIMB == 8
#define X "16" #define X "16"
#else #else
#error please define the format here #error please define the format here
#endif #endif
for(i=a->nlimbs; i > 0 ; i-- ) { for(i=a->nlimbs; i > 0 ; i-- ) {
n += fprintf(fp, i!=a->nlimbs? "%0" X "lX":"%lX", (ulong)a->d[i-1]); n += fprintf(fp, i!=a->nlimbs? "%0" X "lX":"%lX", (ulong)a->d[i-1]);
#undef X #undef X
} }
if( !a->nlimbs ) if( !a->nlimbs )
putc('0', fp ); putc('0', fp );
@ -344,12 +341,12 @@ do_get_buffer( MPI a, unsigned *nbytes, int *sign, int force_secure )
for(i=a->nlimbs-1; i >= 0; i-- ) { for(i=a->nlimbs-1; i >= 0; i-- ) {
alimb = a->d[i]; alimb = a->d[i];
#if BYTES_PER_MPI_LIMB == 4 #if BYTES_PER_MPI_LIMB == 4
*p++ = alimb >> 24; *p++ = alimb >> 24;
*p++ = alimb >> 16; *p++ = alimb >> 16;
*p++ = alimb >> 8; *p++ = alimb >> 8;
*p++ = alimb ; *p++ = alimb ;
#elif BYTES_PER_MPI_LIMB == 8 #elif BYTES_PER_MPI_LIMB == 8
*p++ = alimb >> 56; *p++ = alimb >> 56;
*p++ = alimb >> 48; *p++ = alimb >> 48;
*p++ = alimb >> 40; *p++ = alimb >> 40;
@ -358,20 +355,18 @@ do_get_buffer( MPI a, unsigned *nbytes, int *sign, int force_secure )
*p++ = alimb >> 16; *p++ = alimb >> 16;
*p++ = alimb >> 8; *p++ = alimb >> 8;
*p++ = alimb ; *p++ = alimb ;
#else #else
#error please implement for this limb size. #error please implement for this limb size.
#endif #endif
} }
if (!mpi_is_protected (a))
{
/* this is sub-optimal but we need to do the shift operation /* this is sub-optimal but we need to do the shift operation
* because the caller has to free the returned buffer */ * because the caller has to free the returned buffer */
for(p=buffer; !*p && *nbytes; p++, --*nbytes ) for(p=buffer; !*p && *nbytes; p++, --*nbytes )
; ;
if( p != buffer ) if( p != buffer )
memmove(buffer,p, *nbytes); memmove(buffer,p, *nbytes);
}
return buffer; return buffer;
} }