diff options
Diffstat (limited to 'mpi')
-rw-r--r-- | mpi/mpi-bit.c | 3 | ||||
-rw-r--r-- | mpi/mpi-internal.h | 2 | ||||
-rw-r--r-- | mpi/mpi-pow.c | 2 | ||||
-rw-r--r-- | mpi/mpicoder.c | 52 | ||||
-rw-r--r-- | mpi/mpiutil.c | 4 |
5 files changed, 29 insertions, 34 deletions
diff --git a/mpi/mpi-bit.c b/mpi/mpi-bit.c index 1eb63a02d..864dc0236 100644 --- a/mpi/mpi-bit.c +++ b/mpi/mpi-bit.c @@ -32,8 +32,7 @@ unsigned mpi_get_nbits( MPI a ) { - unsigned nbits; - unsigned n, count = 0; + unsigned n; if( a->nlimbs ) { mpi_limb_t alimb = a->d[a->nlimbs-1]; diff --git a/mpi/mpi-internal.h b/mpi/mpi-internal.h index f084c7e8a..638d980b3 100644 --- a/mpi/mpi-internal.h +++ b/mpi/mpi-internal.h @@ -193,7 +193,7 @@ void mpih_sqr_n_basecase( mpi_ptr_t prodp, mpi_ptr_t up, mpi_size_t size ); void mpih_sqr_n( mpi_ptr_t prodp, mpi_ptr_t up, mpi_size_t size, mpi_ptr_t tspace); -/*-- mpihelp-mul_1.c (or xxx/cpu/*.S) --*/ +/*-- mpihelp-mul_1.c (or xxx/cpu/ *.S) --*/ mpi_limb_t mpihelp_mul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size, mpi_limb_t s2_limb); diff --git a/mpi/mpi-pow.c b/mpi/mpi-pow.c index fcf500c36..2df34b778 100644 --- a/mpi/mpi-pow.c +++ b/mpi/mpi-pow.c @@ -52,7 +52,7 @@ mpi_powm( MPI res, MPI base, MPI exp, MPI mod) mpi_ptr_t xp_marker=NULL; int assign_rp=0; mpi_ptr_t tspace = NULL; - mpi_size_t tsize; + mpi_size_t tsize=0; /* to avoid compiler warning, fixme: check */ esize = exp->nlimbs; msize = mod->nlimbs; diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c index 43b97beea..75583996d 100644 --- a/mpi/mpicoder.c +++ b/mpi/mpicoder.c @@ -41,36 +41,23 @@ int mpi_write( IOBUF out, MPI a ) { - int i; - unsigned nbits = a->nlimbs * BITS_PER_MPI_LIMB; - mpi_limb_t limb; + int rc; + unsigned nbits = mpi_get_nbits(a); + byte *p, *buf; + unsigned n; - /* fixme: use a->nbits if valid */ if( nbits > MAX_EXTERN_MPI_BITS ) log_bug("mpi_encode: mpi too large (%u bits)\n", nbits); + iobuf_put(out, (nbits >>8) ); iobuf_put(out, (nbits) ); - for(i=a->nlimbs-1; i >= 0; i-- ) { - limb = a->d[i]; - #if BYTES_PER_MPI_LIMB == 4 - iobuf_put(out, (limb >> 24) ); - iobuf_put(out, (limb >> 16) ); - iobuf_put(out, (limb >> 8) ); - iobuf_put(out, (limb ) ); - #elif BYTES_PER_MPI_LIMB == 8 - iobuf_put(out, (limb >> 56) ); - iobuf_put(out, (limb >> 48) ); - iobuf_put(out, (limb >> 40) ); - iobuf_put(out, (limb >> 32) ); - iobuf_put(out, (limb >> 24) ); - iobuf_put(out, (limb >> 16) ); - iobuf_put(out, (limb >> 8) ); - iobuf_put(out, (limb ) ); - #else - #error Make this function work with other LIMB sizes - #endif - } - return 0; + + p = buf = mpi_get_buffer( a, &n, NULL ); + for( ; !*p && n; p++, n-- ) + ; + rc = iobuf_write( out, p, n ); + m_free(buf); + return rc; } @@ -225,13 +212,22 @@ mpi_print( FILE *fp, MPI a, int mode ) if( a == MPI_NULL ) return fprintf(fp, "[MPI_NULL]"); if( !mode ) - n += fprintf(fp, "[%d bits]", a->nlimbs * BITS_PER_MPI_LIMB ); + n += fprintf(fp, "[%u bits]", mpi_get_nbits(a) ); else { if( a->sign ) putc('-', fp); + #if BYTES_PER_MPI_LIMB == 2 + #define X "4" + #elif BYTES_PER_MPI_LIMB == 4 + #define X "8" + #elif BYTES_PER_MPI_LIMB == 8 + #define X "16" + #else + #error please define the format here + #endif for(i=a->nlimbs; i > 0 ; i-- ) { - n += fprintf(fp, i!=a->nlimbs? "%0" STR2(BYTES_PER_MPI_LIMB2) - "lX":"%lX", (unsigned long)a->d[i-1] ); + n += fprintf(fp, i!=a->nlimbs? "%0" X "lX":"%lX", (ulong)a->d[i-1]); + #undef X } if( !a->nlimbs ) putc('0', fp ); diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c index 0c8e648b1..068a9a399 100644 --- a/mpi/mpiutil.c +++ b/mpi/mpiutil.c @@ -45,7 +45,7 @@ mpi_alloc( unsigned nlimbs ) MPI a; if( DBG_MEMORY ) - log_debug("mpi_alloc(%lu)\n", nlimbs*BITS_PER_MPI_LIMB ); + log_debug("mpi_alloc(%u)\n", nlimbs*BITS_PER_MPI_LIMB ); #ifdef M_DEBUG a = m_debug_alloc( sizeof *a, info ); a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 0, info ) : NULL; @@ -77,7 +77,7 @@ mpi_alloc_secure( unsigned nlimbs ) MPI a; if( DBG_MEMORY ) - log_debug("mpi_alloc_secure(%lu)\n", nlimbs*BITS_PER_MPI_LIMB ); + log_debug("mpi_alloc_secure(%u)\n", nlimbs*BITS_PER_MPI_LIMB ); #ifdef M_DEBUG a = m_debug_alloc( sizeof *a, info ); a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 1, info ) : NULL; |