summaryrefslogtreecommitdiff
path: root/beecrypt/mpbarrett.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-05-22 17:53:03 +0000
committerjbj <devnull@localhost>2003-05-22 17:53:03 +0000
commitf052bf8629523610f8061071ce7722b0a4ed706c (patch)
treed04534a969bb1647ec2ec127835b144c9a48ff30 /beecrypt/mpbarrett.c
parent8d73a1c5ebc7b62b312465f3f89d7b1c93dd680a (diff)
downloadlibrpm-tizen-f052bf8629523610f8061071ce7722b0a4ed706c.tar.gz
librpm-tizen-f052bf8629523610f8061071ce7722b0a4ed706c.tar.bz2
librpm-tizen-f052bf8629523610f8061071ce7722b0a4ed706c.zip
Yet Another Merge with beecrypt-3.0.0.
CVS patchset: 6869 CVS date: 2003/05/22 17:53:03
Diffstat (limited to 'beecrypt/mpbarrett.c')
-rw-r--r--beecrypt/mpbarrett.c150
1 files changed, 47 insertions, 103 deletions
diff --git a/beecrypt/mpbarrett.c b/beecrypt/mpbarrett.c
index f7f8f19a6..bdc127afd 100644
--- a/beecrypt/mpbarrett.c
+++ b/beecrypt/mpbarrett.c
@@ -721,6 +721,7 @@ int mpbinv_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result, mp
*/
register size_t size = b->size;
+ register int full;
mpw* udata = wksp;
mpw* vdata = udata+size+1;
@@ -734,128 +735,71 @@ int mpbinv_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result, mp
mpzero(size+1, bdata);
mpsetw(size+1, ddata, 1);
- if (mpodd(b->size, b->modl))
+ if ((full = mpeven(b->size, b->modl)))
{
- /* use simplified binary extended gcd algorithm */
+ mpsetw(size+1, adata, 1);
+ mpzero(size+1, cdata);
+ }
- while (1)
+ while (1)
+ {
+ while (mpeven(size+1, udata))
{
- while (mpeven(size+1, udata))
- {
- mpdivtwo(size+1, udata);
+ mpdivtwo(size+1, udata);
- if (mpodd(size+1, bdata))
- (void) mpsubx(size+1, bdata, size, b->modl);
-
- mpsdivtwo(size+1, bdata);
- }
- while (mpeven(size+1, vdata))
- {
- mpdivtwo(size+1, vdata);
-
- if (mpodd(size+1, ddata))
- (void) mpsubx(size+1, ddata, size, b->modl);
-
- mpsdivtwo(size+1, ddata);
- }
- if (mpge(size+1, udata, vdata))
+ if ((full && mpodd(size+1, adata)) || mpodd(size+1, bdata))
{
- (void) mpsub(size+1, udata, vdata);
- (void) mpsub(size+1, bdata, ddata);
- }
- else
- {
- (void) mpsub(size+1, vdata, udata);
- (void) mpsub(size+1, ddata, bdata);
+ if (full) (void) mpaddx(size+1, adata, xsize, xdata);
+ (void) mpsubx(size+1, bdata, size, b->modl);
}
- if (mpz(size+1, udata))
- {
- if (mpisone(size+1, vdata))
- {
- if (result)
- {
- mpsetx(size, result, size+1, ddata);
- /*@-usedef@*/
- if (*ddata & MP_MSBMASK)
- {
- /* keep adding the modulus until we get a carry */
- while (!mpadd(size, result, b->modl));
- }
- /*@=usedef@*/
- }
- return 1;
- }
- return 0;
- }
+ if (full) mpsdivtwo(size+1, adata);
+ mpsdivtwo(size+1, bdata);
}
- }
- else
- {
- /* use full binary extended gcd algorithm */
- mpsetw(size+1, adata, 1);
- mpzero(size+1, cdata);
-
- while (1)
+ while (mpeven(size+1, vdata))
{
- while (mpeven(size+1, udata))
- {
- mpdivtwo(size+1, udata);
-
- if (mpodd(size+1, adata) || mpodd(size+1, bdata))
- {
- (void) mpaddx(size+1, adata, xsize, xdata);
- (void) mpsubx(size+1, bdata, size, b->modl);
- }
+ mpdivtwo(size+1, vdata);
- mpsdivtwo(size+1, adata);
- mpsdivtwo(size+1, bdata);
- }
- while (mpeven(size+1, vdata))
+ if ((full && mpodd(size+1, cdata)) || mpodd(size+1, ddata))
{
- mpdivtwo(size+1, vdata);
-
- if (mpodd(size+1, cdata) || mpodd(size+1, ddata))
- {
- (void) mpaddx(size+1, cdata, xsize, xdata);
- (void) mpsubx(size+1, ddata, size, b->modl);
- }
-
- mpsdivtwo(size+1, cdata);
- mpsdivtwo(size+1, ddata);
- }
- if (mpge(size+1, udata, vdata))
- {
- (void) mpsub(size+1, udata, vdata);
- (void) mpsub(size+1, adata, cdata);
- (void) mpsub(size+1, bdata, ddata);
- }
- else
- {
- (void) mpsub(size+1, vdata, udata);
- (void) mpsub(size+1, cdata, adata);
- (void) mpsub(size+1, ddata, bdata);
+ if (full) (void) mpaddx(size+1, cdata, xsize, xdata);
+ (void) mpsubx(size+1, ddata, size, b->modl);
}
- if (mpz(size+1, udata))
+ if (full) mpsdivtwo(size+1, cdata);
+ mpsdivtwo(size+1, ddata);
+ }
+ if (mpge(size+1, udata, vdata))
+ {
+ (void) mpsub(size+1, udata, vdata);
+ if (full) (void) mpsub(size+1, adata, cdata);
+ (void) mpsub(size+1, bdata, ddata);
+ }
+ else
+ {
+ (void) mpsub(size+1, vdata, udata);
+ if (full) (void) mpsub(size+1, cdata, adata);
+ (void) mpsub(size+1, ddata, bdata);
+ }
+
+ if (mpz(size+1, udata))
+ {
+ if (mpisone(size+1, vdata))
{
- if (mpisone(size+1, vdata))
+ if (result)
{
- if (result)
+ mpsetx(size, result, size+1, ddata);
+ /*@-usedef@*/
+ if (*ddata & MP_MSBMASK)
{
- mpsetx(size, result, size+1, ddata);
- /*@-usedef@*/
- if (*ddata & MP_MSBMASK)
- {
- /* keep adding the modulus until we get a carry */
- while (!mpadd(size, result, b->modl));
- }
- /*@=usedef@*/
+ /* keep adding the modulus until we get a carry */
+ while (!mpadd(size, result, b->modl));
}
- return 1;
+ /*@=usedef@*/
}
- return 0;
+ return 1;
}
+ return 0;
}
}
}