summaryrefslogtreecommitdiff
path: root/beecrypt/mpbarrett.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-05-23 15:55:57 +0000
committerjbj <devnull@localhost>2003-05-23 15:55:57 +0000
commit0baf05de865499764c4d9ff82c56679737432a0d (patch)
treeb948541cfc4e6190a63a907fdc5989231403d208 /beecrypt/mpbarrett.c
parentdac695e290b95514115d68dbfe21209eeb66ee82 (diff)
downloadlibrpm-tizen-0baf05de865499764c4d9ff82c56679737432a0d.tar.gz
librpm-tizen-0baf05de865499764c4d9ff82c56679737432a0d.tar.bz2
librpm-tizen-0baf05de865499764c4d9ff82c56679737432a0d.zip
Another merge to beecrypt-3.0.0.
CVS patchset: 6872 CVS date: 2003/05/23 15:55:57
Diffstat (limited to 'beecrypt/mpbarrett.c')
-rw-r--r--beecrypt/mpbarrett.c102
1 files changed, 2 insertions, 100 deletions
diff --git a/beecrypt/mpbarrett.c b/beecrypt/mpbarrett.c
index bdc127afd..3c18c0595 100644
--- a/beecrypt/mpbarrett.c
+++ b/beecrypt/mpbarrett.c
@@ -30,6 +30,7 @@
#include "system.h"
#include "mp.h"
#include "mpprime.h"
+#include "mpnumber.h"
#include "mpbarrett.h"
#include "debug.h"
@@ -283,7 +284,7 @@ void mpbrndinv_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mp
else
mpbrnd_w(b, rc, result, wksp);
- } while (mpbinv_w(b, size, result, inverse, wksp) == 0);
+ } while (mpextgcd_w(size, result, b->modl, inverse, wksp) == 0);
}
/**
@@ -706,105 +707,6 @@ void mpbtwopowmod_w(const mpbarrett* b, size_t psize, const mpw* pdata, mpw* res
}
#ifdef DYING
-/**
- * Computes the inverse (modulo b) of x, and returns 1 if x was invertible.
- * needs workspace of (6*size+6) words
- * @note xdata and result cannot point to the same area
- */
-int mpbinv_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result, mpw* wksp)
-{
- /*
- * Fact: if a element of Zn, then a is invertible if and only if gcd(a,n) = 1
- * Hence: if b->modl is even, then x must be odd, otherwise the gcd(x,n) >= 2
- *
- * The calling routine must guarantee this condition.
- */
-
- register size_t size = b->size;
- register int full;
-
- mpw* udata = wksp;
- mpw* vdata = udata+size+1;
- mpw* adata = vdata+size+1;
- mpw* bdata = adata+size+1;
- mpw* cdata = bdata+size+1;
- mpw* ddata = cdata+size+1;
-
- mpsetx(size+1, udata, size, b->modl);
- mpsetx(size+1, vdata, xsize, xdata);
- mpzero(size+1, bdata);
- mpsetw(size+1, ddata, 1);
-
- if ((full = mpeven(b->size, b->modl)))
- {
- mpsetw(size+1, adata, 1);
- mpzero(size+1, cdata);
- }
-
- while (1)
- {
- while (mpeven(size+1, udata))
- {
- mpdivtwo(size+1, udata);
-
- if ((full && mpodd(size+1, adata)) || mpodd(size+1, bdata))
- {
- if (full) (void) mpaddx(size+1, adata, xsize, xdata);
- (void) mpsubx(size+1, bdata, size, b->modl);
- }
-
- if (full) mpsdivtwo(size+1, adata);
- mpsdivtwo(size+1, bdata);
- }
- while (mpeven(size+1, vdata))
- {
- mpdivtwo(size+1, vdata);
-
- if ((full && mpodd(size+1, cdata)) || mpodd(size+1, ddata))
- {
- if (full) (void) mpaddx(size+1, cdata, xsize, xdata);
- (void) mpsubx(size+1, ddata, size, b->modl);
- }
-
- 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 (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;
- }
- }
-}
-#else
-
/*@unchecked@*/
static int _debug = 0;