From: jbj Date: Tue, 3 Jun 2003 15:48:50 +0000 (+0000) Subject: Merge fix for DSA on 64bit platforms. X-Git-Tag: rpm-4.4-release~484 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=92dc678a0e5e4449da71ef342512973b8b878b0c;p=platform%2Fupstream%2Frpm.git Merge fix for DSA on 64bit platforms. CVS patchset: 6888 CVS date: 2003/06/03 15:48:50 --- diff --git a/beecrypt/dsa.c b/beecrypt/dsa.c index 738d13d..b9f8041 100644 --- a/beecrypt/dsa.c +++ b/beecrypt/dsa.c @@ -77,14 +77,14 @@ int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGen mpnfree(r); mpnsize(r, qsize); - /* get a random k, invertible modulo q */ + /* get a random k, invertible modulo q; store k @ qtemp, inv(k) @ qtemp+qsize */ mpbrndinv_w(q, rgc, qtemp, qtemp+qsize, qwksp); /* g^k mod p */ mpbpowmod_w(p, g->size, g->data, qsize, qtemp, ptemp, pwksp); /* (g^k mod p) mod q - simple modulo */ - mpnmod(qtemp+2*qsize, psize, ptemp, qsize, q->modl, pwksp); + mpmod(qtemp+2*qsize, psize, ptemp, qsize, q->modl, pwksp); mpcopy(qsize, r->data, qtemp+psize+qsize); /* allocate s */ @@ -201,7 +201,7 @@ if (_debug) fprintf(stderr, "\t multiply mod p: "), mpfprintln(stderr, psize, ptemp); /* modulo q */ - mpnmod(ptemp+psize, psize, ptemp, qsize, q->modl, pwksp); + mpmod(ptemp+psize, psize, ptemp, qsize, q->modl, pwksp); if (_debug) fprintf(stderr, "\tr : "), mpfprintln(stderr, r->size, r->data); diff --git a/beecrypt/gas/mpopt.x86.m4 b/beecrypt/gas/mpopt.x86.m4 index 98e9d21..f6d9651 100644 --- a/beecrypt/gas/mpopt.x86.m4 +++ b/beecrypt/gas/mpopt.x86.m4 @@ -409,3 +409,11 @@ LOCAL(mpaddsqrtrc_loop): popl %edi ret C_FUNCTION_END(mpaddsqrtrc) + + +C_FUNCTION_BEGIN(mppndiv) + movl 4(%esp),%edx + movl 8(%esp),%eax + divl 12(%esp) + ret +C_FUNCTION_END(mppndiv) diff --git a/beecrypt/mp.c b/beecrypt/mp.c index 03c0945..62c071f 100644 --- a/beecrypt/mp.c +++ b/beecrypt/mp.c @@ -822,7 +822,7 @@ void mpsqr(mpw* result, size_t size, const mpw* data) *(--result) = 0; - (void) mpmultwo(size*2, result); + (void) mpmultwo(size << 1, result); (void) mpaddsqrtrc(size, result, data); } @@ -1243,7 +1243,7 @@ mpw mppndiv(mpw xhi, mpw xlo, mpw y) if (((unsigned)carry) | (unsigned)(xhi >= y)) { xhi -= y; - result |= 1; + result++; } carry = (xhi >> (MP_WBITS-1)); xhi <<= 1; @@ -1254,78 +1254,51 @@ mpw mppndiv(mpw xhi, mpw xlo, mpw y) if (((unsigned)carry) | (unsigned)(xhi >= y)) { xhi -= y; - result |= 1; + result++; } return result; } #endif -#ifndef ASM_MPNMODW -mpw mpnmodw(mpw* result, size_t xsize, const mpw* xdata, mpw y, mpw* workspace) -{ - /* result size xsize, workspace size xsize+1 */ - register mpw q; - mpw qsize = xsize-1; - mpw* rdata = result; - - mpcopy(xsize, rdata, xdata); - /* - if (*rdata >= y) - *rdata -= y; - */ - if (mpge(1, rdata, &y)) - (void) mpsub(1, rdata, &y); - - while (qsize--) - { - q = mppndiv(rdata[0], rdata[1], y); - -/*@-evalorder@*/ - *workspace = mpsetmul(1, workspace+1, &y, q); -/*@=evalorder@*/ - - while (mplt(2, rdata, workspace)) - { - (void) mpsubx(2, workspace, 1, &y); - /* q--; */ - } - (void) mpsub(2, rdata, workspace); - rdata++; - } - - return *rdata; -} -#endif - -#ifndef ASM_MPNMOD -void mpnmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* workspace) +#ifndef ASM_MPMOD +void mpmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* workspace) { - /* result size xsize, workspace size xsize+1 */ - mpw q; - mpw msw = *ydata; - mpw qsize = xsize-ysize; + /* result size xsize, workspace size 2*ysize+1 */ + mpw q, msw; mpw* rdata = result; + mpw* ynorm = workspace+ysize+1; + size_t shift, qsize = xsize-ysize; + mpcopy(ysize, ynorm, ydata); + shift = mpnorm(ysize, ynorm); + msw = *ynorm; mpcopy(xsize, rdata, xdata); - if (mpge(ysize, rdata, ydata)) - (void) mpsub(ysize, rdata, ydata); + if (mpge(ysize, rdata, ynorm)) + (void) mpsub(ysize, rdata, ynorm); while (qsize--) { q = mppndiv(rdata[0], rdata[1], msw); /*@-evalorder@*/ - *workspace = mpsetmul(ysize, workspace+1, ydata, q); + *workspace = mpsetmul(ysize, workspace+1, ynorm, q); /*@=evalorder@*/ while (mplt(ysize+1, rdata, workspace)) { - (void) mpsubx(ysize+1, workspace, ysize, ydata); + (void) mpsubx(ysize+1, workspace, ysize, ynorm); q--; } (void) mpsub(ysize+1, rdata, workspace); rdata++; } + /* de-normalization steps */ + while (shift--) + { + mpdivtwo(ysize, ynorm); + if (mpge(ysize, rdata, ynorm)) + mpsub(ysize, rdata, ynorm); + } } #endif @@ -1378,10 +1351,11 @@ void mpprintln(size_t size, const mpw* data) void mpfprint(FILE * f, size_t size, const mpw* data) { - if (data == NULL) + if (data == (mpw*) 0) return; - if (f == NULL) + if (f == (FILE*) 0) f = stderr; + while (size--) { #if (MP_WBITS == 32) @@ -1398,16 +1372,16 @@ void mpfprint(FILE * f, size_t size, const mpw* data) # error #endif } - fprintf(f, "\n"); (void) fflush(f); } void mpfprintln(FILE * f, size_t size, const mpw* data) { - if (data == NULL) + if (data == (mpw*) 0) return; - if (f == NULL) + if (f == (FILE*) 0) f = stderr; + while (size--) { #if (MP_WBITS == 32) diff --git a/beecrypt/mp.h b/beecrypt/mp.h index 45ed7be..d0b765e 100644 --- a/beecrypt/mp.h +++ b/beecrypt/mp.h @@ -662,13 +662,7 @@ mpw mppndiv(mpw xhi, mpw xlo, mpw y) /** */ BEECRYPTAPI /*@unused@*/ -mpw mpnmodw(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, mpw y, /*@out@*/ mpw* workspace) - /*@modifies result, workspace @*/; - -/** - */ -BEECRYPTAPI -void mpnmod(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* workspace) +void mpmod(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* workspace) /*@modifies result, workspace @*/; /** diff --git a/beecrypt/mpopt.h b/beecrypt/mpopt.h index 27cde82..a6384ed 100644 --- a/beecrypt/mpopt.h +++ b/beecrypt/mpopt.h @@ -80,6 +80,7 @@ # define ASM_MPSETMUL # define ASM_MPADDMUL # define ASM_MPADDSQRTRC +# define ASM_MPPNDIV # elif defined(OPTIMIZE_IA64) # define ASM_MPZERO # define ASM_MPCOPY @@ -157,6 +158,7 @@ # define ASM_MPSETMUL # define ASM_MPADDMUL # define ASM_MPADDSQRTRC +# define ASM_MPPNDIV # endif #endif diff --git a/beecrypt/python/mpw-py.c b/beecrypt/python/mpw-py.c index 5ba26da..1f5dee8 100644 --- a/beecrypt/python/mpw-py.c +++ b/beecrypt/python/mpw-py.c @@ -1470,9 +1470,9 @@ fprintf(stderr, "sub ++: borrow\n"); zsize = asize; zdata = alloca(zsize * sizeof(*zdata)); zsign = x->ob_size * m->ob_size; - wksp = alloca((bsize+1) * sizeof(*wksp)); + wksp = alloca((2*bsize+1) * sizeof(*wksp)); - mpnmod(zdata, asize, adata, bsize, bdata, wksp); + mpmod(zdata, asize, adata, bsize, bdata, wksp); if (zsign < 0) { if (m->ob_size < 0) {