summaryrefslogtreecommitdiffstats
path: root/mpi
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1998-06-16 17:13:28 +0200
committerWerner Koch <wk@gnupg.org>1998-06-16 17:13:28 +0200
commite6ac5acbbf56ed8995bfa4d5a28160fa3a5d825f (patch)
tree6ff27595e33dd57d3a8979d245236bd5f404c9b4 /mpi
parentextensions are now working and fixed a lot of bugs (diff)
downloadgnupg2-e6ac5acbbf56ed8995bfa4d5a28160fa3a5d825f.tar.xz
gnupg2-e6ac5acbbf56ed8995bfa4d5a28160fa3a5d825f.zip
some more internall structure changes
Diffstat (limited to 'mpi')
-rw-r--r--mpi/mpi-bit.c7
-rw-r--r--mpi/mpi-div.c6
-rw-r--r--mpi/mpi-mul.c10
-rw-r--r--mpi/mpi-pow.c8
-rw-r--r--mpi/mpicoder.c15
-rw-r--r--mpi/mpiutil.c18
6 files changed, 39 insertions, 25 deletions
diff --git a/mpi/mpi-bit.c b/mpi/mpi-bit.c
index d74abbf6d..2e420875b 100644
--- a/mpi/mpi-bit.c
+++ b/mpi/mpi-bit.c
@@ -60,6 +60,13 @@ mpi_get_nbits( MPI a )
{
unsigned n;
+ if( mpi_is_protected(a) ) {
+ n = mpi_get_nbit_info(a);
+ if( !n )
+ n = a->nlimbs * BITS_PER_MPI_LIMB;
+ return n;
+ }
+
if( a->nlimbs ) {
mpi_limb_t alimb = a->d[a->nlimbs-1];
if( alimb )
diff --git a/mpi/mpi-div.c b/mpi/mpi-div.c
index f057232a2..62ac87158 100644
--- a/mpi/mpi-div.c
+++ b/mpi/mpi-div.c
@@ -198,7 +198,7 @@ mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den)
/* Make sure QP and NP point to different objects. Otherwise the
* numerator would be gradually overwritten by the quotient limbs. */
if(qp == np) { /* Copy NP object to temporary space. */
- np = marker[markidx++] = mpi_alloc_limb_space(nsize,quot->secure);
+ np = marker[markidx++] = mpi_alloc_limb_space(nsize,mpi_is_secure(quot));
MPN_COPY(np, qp, nsize);
}
}
@@ -218,7 +218,7 @@ mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den)
/* Shift up the denominator setting the most significant bit of
* the most significant word. Use temporary storage not to clobber
* the original contents of the denominator. */
- tp = marker[markidx++] = mpi_alloc_limb_space(dsize,den->secure);
+ tp = marker[markidx++] = mpi_alloc_limb_space(dsize,mpi_is_secure(den));
mpihelp_lshift( tp, dp, dsize, normalization_steps );
dp = tp;
@@ -239,7 +239,7 @@ mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den)
if( dp == rp || (quot && (dp == qp))) {
mpi_ptr_t tp;
- tp = marker[markidx++] = mpi_alloc_limb_space(dsize, den->secure);
+ tp = marker[markidx++] = mpi_alloc_limb_space(dsize, mpi_is_secure(den));
MPN_COPY( tp, dp, dsize );
dp = tp;
}
diff --git a/mpi/mpi-mul.c b/mpi/mpi-mul.c
index bfca5d0d5..74967fa6b 100644
--- a/mpi/mpi-mul.c
+++ b/mpi/mpi-mul.c
@@ -123,21 +123,21 @@ mpi_mul( MPI w, MPI u, MPI v)
if( u->nlimbs < v->nlimbs ) { /* Swap U and V. */
usize = v->nlimbs;
usign = v->sign;
- usecure = v->secure;
+ usecure = mpi_is_secure(v);
up = v->d;
vsize = u->nlimbs;
vsign = u->sign;
- vsecure = u->secure;
+ vsecure = mpi_is_secure(u);
vp = u->d;
}
else {
usize = u->nlimbs;
usign = u->sign;
- usecure = u->secure;
+ usecure = mpi_is_secure(u);
up = u->d;
vsize = v->nlimbs;
vsign = v->sign;
- vsecure = v->secure;
+ vsecure = mpi_is_secure(v);
vp = v->d;
}
sign_product = usign ^ vsign;
@@ -147,7 +147,7 @@ mpi_mul( MPI w, MPI u, MPI v)
wsize = usize + vsize;
if( w->alloced < wsize ) {
if( wp == up || wp == vp ) {
- wp = mpi_alloc_limb_space( wsize, w->secure );
+ wp = mpi_alloc_limb_space( wsize, mpi_is_secure(w) );
assign_wp = 1;
}
else {
diff --git a/mpi/mpi-pow.c b/mpi/mpi-pow.c
index 2a0a4ef3b..24430489e 100644
--- a/mpi/mpi-pow.c
+++ b/mpi/mpi-pow.c
@@ -60,10 +60,10 @@ mpi_powm( MPI res, MPI base, MPI exp, MPI mod)
esign = exp->sign;
msign = mod->sign;
- esec = exp->secure;
- msec = mod->secure;
- bsec = base->secure;
- rsec = res->secure;
+ esec = mpi_is_secure(exp);
+ msec = mpi_is_secure(mod);
+ bsec = mpi_is_secure(base);
+ rsec = mpi_is_secure(res);
rp = res->d;
ep = exp->d;
diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c
index a868923fe..eba82a287 100644
--- a/mpi/mpicoder.c
+++ b/mpi/mpicoder.c
@@ -210,8 +210,15 @@ mpi_print( FILE *fp, MPI a, int mode )
if( a == MPI_NULL )
return fprintf(fp, "[MPI_NULL]");
- if( !mode )
- n += fprintf(fp, "[%u bits]", mpi_get_nbits(a) );
+ if( !mode ) {
+ unsigned n1, n2;
+ 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);
+ }
else {
if( a->sign )
putc('-', fp);
@@ -278,8 +285,8 @@ do_get_buffer( MPI a, unsigned *nbytes, int *sign, int force_secure )
if( sign )
*sign = a->sign;
*nbytes = a->nlimbs * BYTES_PER_MPI_LIMB;
- p = buffer = force_secure || a->secure ? m_alloc_secure( *nbytes)
- : m_alloc( *nbytes );
+ p = buffer = force_secure || mpi_is_secure(a) ? m_alloc_secure( *nbytes)
+ : m_alloc( *nbytes );
for(i=a->nlimbs-1; i >= 0; i-- ) {
alimb = a->d[i];
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index 7c661094f..92b16538f 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -63,7 +63,7 @@ mpi_alloc( unsigned nlimbs )
a->alloced = nlimbs;
a->nlimbs = 0;
a->sign = 0;
- a->secure = 0;
+ a->flags = 0;
return a;
}
@@ -93,7 +93,7 @@ mpi_alloc_secure( unsigned nlimbs )
a->d = nlimbs? mpi_alloc_limb_space( nlimbs, 1 ) : NULL;
#endif
a->alloced = nlimbs;
- a->secure = 1;
+ a->flags |= 1;
a->nlimbs = 0;
a->sign = 0;
return a;
@@ -204,9 +204,9 @@ mpi_set_secure( MPI a )
{
mpi_ptr_t ap, bp;
- if( a->secure )
+ if( (a->flags & 1) )
return;
- a->secure = 1;
+ a->flags |= 1;
ap = a->d;
if( !a->nlimbs ) {
assert(!ap);
@@ -243,15 +243,15 @@ mpi_copy( MPI a )
if( a ) {
#ifdef M_DEBUG
- b = a->secure? mpi_debug_alloc_secure( a->nlimbs, info )
- : mpi_debug_alloc( a->nlimbs, info );
+ b = mpi_is_secure(a)? mpi_debug_alloc_secure( a->nlimbs, info )
+ : mpi_debug_alloc( a->nlimbs, info );
#else
- b = a->secure? mpi_alloc_secure( a->nlimbs )
- : mpi_alloc( a->nlimbs );
+ b = mpi_is_secure(a)? mpi_alloc_secure( a->nlimbs )
+ : mpi_alloc( a->nlimbs );
#endif
b->nlimbs = a->nlimbs;
b->sign = a->sign;
- b->secure = a->secure;
+ b->flags = a->flags;
b->nbits = a->nbits;
for(i=0; i < b->nlimbs; i++ )
b->d[i] = a->d[i];