1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

some more internall structure changes

This commit is contained in:
Werner Koch 1998-06-16 15:13:28 +00:00
parent 6e1ca6b80f
commit e6ac5acbbf
39 changed files with 814 additions and 400 deletions

View file

@ -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 )

View file

@ -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;
}

View file

@ -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 {

View file

@ -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;

View file

@ -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];

View file

@ -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];