diff options
author | Werner Koch <wk@gnupg.org> | 1999-01-07 17:05:44 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1999-01-07 17:05:44 +0000 |
commit | 37cdf7d88bad91e9b6d66bad7dc91082142cccc2 (patch) | |
tree | a91d15d325d26afd60e6416905de0df6b1199388 /mpi | |
parent | af1719288e56347975b751fe1ab2384982bf8b07 (diff) | |
download | libgcrypt-37cdf7d88bad91e9b6d66bad7dc91082142cccc2.tar.gz |
See ChangeLog: Thu Jan 7 18:00:58 CET 1999 Werner Koch
Diffstat (limited to 'mpi')
-rw-r--r-- | mpi/ChangeLog | 7 | ||||
-rw-r--r-- | mpi/mpi-bit.c | 13 | ||||
-rw-r--r-- | mpi/mpi-cmp.c | 23 |
3 files changed, 32 insertions, 11 deletions
diff --git a/mpi/ChangeLog b/mpi/ChangeLog index 2b0d99ec..9d79660e 100644 --- a/mpi/ChangeLog +++ b/mpi/ChangeLog @@ -1,3 +1,10 @@ +Thu Jan 7 18:00:58 CET 1999 Werner Koch <wk@isil.d.shuttle.de> + + * mpi-bit.c (mpi_normalize): New. + (mpi_get_nbits): Normalize the MPI. + * mpi-bit.c (mpi_cmp): Normalize the MPI before the compare. + + Tue Dec 8 13:15:16 CET 1998 Werner Koch <wk@isil.d.shuttle.de> * config.links: Moved the case for powerpc*linux diff --git a/mpi/mpi-bit.c b/mpi/mpi-bit.c index 8ca5c57d..227a929b 100644 --- a/mpi/mpi-bit.c +++ b/mpi/mpi-bit.c @@ -48,7 +48,19 @@ __clz_tab[] = #define A_LIMB_1 ((mpi_limb_t)1) +/**************** + * Sometimes we have MSL (most significant limbs) which are 0; + * this is for some reasons not good, so this function removes them. + */ +void +mpi_normalize( MPI a ) +{ + if( mpi_is_protected(a) ) + return; + for( ; a->nlimbs && !a->d[a->nlimbs-1]; a->nlimbs-- ) + ; +} @@ -67,6 +79,7 @@ mpi_get_nbits( MPI a ) return n; } + mpi_normalize( a ); if( a->nlimbs ) { mpi_limb_t alimb = a->d[a->nlimbs-1]; if( alimb ) diff --git a/mpi/mpi-cmp.c b/mpi/mpi-cmp.c index f4dd70e9..3c3c76b7 100644 --- a/mpi/mpi-cmp.c +++ b/mpi/mpi-cmp.c @@ -46,27 +46,28 @@ mpi_cmp_ui( MPI u, unsigned long v ) int mpi_cmp( MPI u, MPI v ) { - mpi_size_t usize = u->nlimbs; - mpi_size_t vsize = v->nlimbs; + mpi_size_t usize, vsize; int cmp; - /* FIXME: are the numbers always normalized? */ + mpi_normalize( u ); + mpi_normalize( v ); + usize = u->nlimbs; + vsize = v->nlimbs; if( !u->sign && v->sign ) return 1; - else if( u->sign && !v->sign ) + if( u->sign && !v->sign ) return -1; - else if( usize != vsize && !u->sign && !v->sign ) + if( usize != vsize && !u->sign && !v->sign ) return usize - vsize; - else if( usize != vsize && u->sign && v->sign ) + if( usize != vsize && u->sign && v->sign ) return vsize + usize; - else if( !usize ) + if( !usize ) return 0; - else if( !(cmp=mpihelp_cmp( u->d, v->d, usize )) ) + if( !(cmp=mpihelp_cmp( u->d, v->d, usize )) ) return 0; - else if( (cmp < 0?1:0) == (u->sign?1:0)) + if( (cmp < 0?1:0) == (u->sign?1:0)) return 1; - else - return -1; + return -1; } |