diff options
author | jbj <devnull@localhost> | 2003-04-25 20:36:06 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2003-04-25 20:36:06 +0000 |
commit | 68b7bd7ebafa868590effdcefa97e8be57d64b3b (patch) | |
tree | 4b3a91f9507581c541f028a173cc9b642089a9a9 | |
parent | 6718ac9b84f8c3ddad6e5bb7b9716ee4cb894594 (diff) | |
download | librpm-tizen-68b7bd7ebafa868590effdcefa97e8be57d64b3b.tar.gz librpm-tizen-68b7bd7ebafa868590effdcefa97e8be57d64b3b.tar.bz2 librpm-tizen-68b7bd7ebafa868590effdcefa97e8be57d64b3b.zip |
beecrypt-3.0.0 merge: grand renaming, mp32barret et al.
CVS patchset: 6779
CVS date: 2003/04/25 20:36:06
-rw-r--r-- | beecrypt/beetest.c | 48 | ||||
-rw-r--r-- | beecrypt/dldp.c | 62 | ||||
-rw-r--r-- | beecrypt/dldp.h | 6 | ||||
-rw-r--r-- | beecrypt/dlsvdp-dh.c | 2 | ||||
-rw-r--r-- | beecrypt/dsa.c | 28 | ||||
-rw-r--r-- | beecrypt/dsa.h | 4 | ||||
-rw-r--r-- | beecrypt/elgamal.c | 44 | ||||
-rw-r--r-- | beecrypt/elgamal.h | 8 | ||||
-rw-r--r-- | beecrypt/mpbarrett.c | 322 | ||||
-rw-r--r-- | beecrypt/mpbarrett.h | 66 | ||||
-rw-r--r-- | beecrypt/mpprime.c | 62 | ||||
-rw-r--r-- | beecrypt/mpprime.h | 10 | ||||
-rw-r--r-- | beecrypt/rsa.c | 12 | ||||
-rw-r--r-- | beecrypt/rsakp.c | 70 | ||||
-rw-r--r-- | beecrypt/rsakp.h | 6 | ||||
-rw-r--r-- | beecrypt/rsapk.c | 6 | ||||
-rw-r--r-- | beecrypt/rsapk.h | 2 | ||||
-rw-r--r-- | beecrypt/tests/beetest.c | 56 | ||||
-rw-r--r-- | beecrypt/tests/testdldp.c | 2 | ||||
-rw-r--r-- | beecrypt/tests/testdsa.c | 4 |
20 files changed, 410 insertions, 410 deletions
diff --git a/beecrypt/beetest.c b/beecrypt/beetest.c index dd1729bfe..f19222da1 100644 --- a/beecrypt/beetest.c +++ b/beecrypt/beetest.c @@ -56,9 +56,9 @@ int testVectorInvMod(const dlkp_p* keypair) register uint32 size = keypair->param.p.size; register uint32* temp = (uint32*) malloc((13*size+11) * sizeof(uint32)); - mp32brndinv_w(&keypair->param.n, &rngc, temp, temp+size, temp+2*size); + mpbrndinv_w(&keypair->param.n, &rngc, temp, temp+size, temp+2*size); - mp32bmulmod_w(&keypair->param.n, size, temp, size, temp+size, temp, temp+2*size); + mpbmulmod_w(&keypair->param.n, size, temp, size, temp+size, temp, temp+2*size); rc = mp32isone(size, temp); @@ -78,7 +78,7 @@ int testVectorExpMod(const dlkp_p* keypair) mpnzero(&y); - mp32bnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y); + mpbnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y); rc = mp32eqx(y.size, y.data, keypair->y.size, keypair->y.data); @@ -221,7 +221,7 @@ int testVectorRSA() mpnzero(&digest); mpnzero(&s); - mp32bnrnd(&kp.n, &rngc, &digest); + mpbnrnd(&kp.n, &rngc, &digest); rsapri(&kp, &digest, &s); @@ -257,7 +257,7 @@ int testVectorDLDP() dldp_pgoqMake(&dp, &rc, 768 >> 5, 512 >> 5, 1); /* we have the parameters, now see if g^q == 1 */ - mp32bnpowmod(&dp.p, &dp.g, (mpnumber*) &dp.q, &gq); + mpbnpowmod(&dp.p, &dp.g, (mpnumber*) &dp.q, &gq); result = mp32isone(gq.size, gq.data); mpnfree(&gq); @@ -509,13 +509,13 @@ void testExpMods() randomGeneratorContext rngc; - mp32barrett p; + mpbarrett p; mpnumber tmp; mpnumber g; mpnumber x; mpnumber y; - mp32bzero(&p); + mpbzero(&p); mpnzero(&g); mpnzero(&x); mpnzero(&y); @@ -532,16 +532,16 @@ void testExpMods() fprintf(stdout, "Timing modular exponentiations\n"); fprintf(stdout, "\t(512 bits ^ 512 bits) mod 512 bits:"); mpnsethex(&tmp, p_512); - mp32bset(&p, tmp.size, tmp.data); + mpbset(&p, tmp.size, tmp.data); mpnsize(&g, p.size); mpnsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpbnrnd(&p, &rngc, &g); + mpbnrnd(&p, &rngc, &x); #if HAVE_TIME_H tstart = clock(); #endif for (i = 0; i < 100; i++) - mp32bnpowmod(&p, &g, &x, &y); + mpbnpowmod(&p, &g, &x, &y); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -549,16 +549,16 @@ void testExpMods() #endif fprintf(stdout, "\t(768 bits ^ 768 bits) mod 768 bits:"); mpnsethex(&tmp, p_768); - mp32bset(&p, tmp.size, tmp.data); + mpbset(&p, tmp.size, tmp.data); mpnsize(&g, p.size); mpnsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpbnrnd(&p, &rngc, &g); + mpbnrnd(&p, &rngc, &x); #if HAVE_TIME_H tstart = clock(); #endif for (i = 0; i < 100; i++) - mp32bnpowmod(&p, &g, &x, &y); + mpbnpowmod(&p, &g, &x, &y); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -566,16 +566,16 @@ void testExpMods() #endif fprintf(stdout, "\t(1024 bits ^ 1024 bits) mod 1024 bits:"); mpnsethex(&tmp, p_1024); - mp32bset(&p, tmp.size, tmp.data); + mpbset(&p, tmp.size, tmp.data); mpnsize(&g, p.size); mpnsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpbnrnd(&p, &rngc, &g); + mpbnrnd(&p, &rngc, &x); #if HAVE_TIME_H tstart = clock(); #endif for (i = 0; i < 100; i++) - mp32bnpowmod(&p, &g, &x, &y); + mpbnpowmod(&p, &g, &x, &y); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -589,13 +589,13 @@ void testExpMods() tstart = clock(); #endif for (i = 0; i < 100; i++) - mp32bnpowmod(&p, &g, &x, &y); + mpbnpowmod(&p, &g, &x, &y); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; fprintf(stdout, "\t 100x in %.3f seconds\n", ttime); #endif - mp32bfree(&p); + mpbfree(&p); mpnfree(&g); mpnfree(&x); mpnfree(&y); @@ -677,10 +677,10 @@ int main() dlkp_pInit(&keypair); - mp32bsethex(&keypair.param.p, dsa_p); - mp32bsethex(&keypair.param.q, dsa_q); + mpbsethex(&keypair.param.p, dsa_p); + mpbsethex(&keypair.param.q, dsa_q); mpnsethex(&keypair.param.g, dsa_g); - mp32bsethex(&keypair.param.n, elg_n); + mpbsethex(&keypair.param.n, elg_n); mpnsethex(&keypair.y, dsa_y); mpnsethex(&keypair.x, dsa_x); diff --git a/beecrypt/dldp.c b/beecrypt/dldp.c index 57ebc004e..12d587a74 100644 --- a/beecrypt/dldp.c +++ b/beecrypt/dldp.c @@ -51,7 +51,7 @@ int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x) * This is the variant of Diffie-Hellman as described in IEEE P1363 */ - mp32bnrnd(&dp->q, rgc, x); + mpbnrnd(&dp->q, rgc, x); return 0; } @@ -62,7 +62,7 @@ int dldp_pPublic(const dldp_p* dp, const mpnumber* x, mpnumber* y) * Public key y is computed as g^x mod p */ - mp32bnpowmod(&dp->p, &dp->g, x, y); + mpbnpowmod(&dp->p, &dp->g, x, y); return 0; } @@ -73,8 +73,8 @@ int dldp_pPair(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x, mpnum * Combination of the two previous functions */ - mp32bnrnd(&dp->q, rgc, x); - mp32bnpowmod(&dp->p, &dp->g, x, y); + mpbnrnd(&dp->q, rgc, x); + mpbnpowmod(&dp->p, &dp->g, x, y); return 0; } @@ -139,11 +139,11 @@ static int dldp_pValidate(const dldp_p* dp, randomGeneratorContext* rgc) int dldp_pInit(dldp_p* dp) { - mp32bzero(&dp->p); - mp32bzero(&dp->q); + mpbzero(&dp->p); + mpbzero(&dp->q); mpnzero(&dp->g); mpnzero(&dp->r); - mp32bzero(&dp->n); + mpbzero(&dp->n); return 0; } @@ -151,11 +151,11 @@ int dldp_pInit(dldp_p* dp) int dldp_pFree(dldp_p* dp) { /*@-usedef -compdef@*/ - mp32bfree(&dp->p); - mp32bfree(&dp->q); + mpbfree(&dp->p); + mpbfree(&dp->q); mpnfree(&dp->g); mpnfree(&dp->r); - mp32bfree(&dp->n); + mpbfree(&dp->n); /*@=usedef =compdef@*/ return 0; @@ -163,11 +163,11 @@ int dldp_pFree(dldp_p* dp) int dldp_pCopy(dldp_p* dst, const dldp_p* src) { - mp32bcopy(&dst->p, &src->p); - mp32bcopy(&dst->q, &src->q); + mpbcopy(&dst->p, &src->p); + mpbcopy(&dst->q, &src->q); mpncopy(&dst->r, &src->r); mpncopy(&dst->g, &src->g); - mp32bcopy(&dst->n, &src->n); + mpbcopy(&dst->n, &src->n); return 0; } @@ -193,7 +193,7 @@ int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, uint32 psize, uint32 /*@=globs@*/ /* clear n */ - mp32bzero(&dp->n); + mpbzero(&dp->n); /* clear g */ mpnzero(&dp->g); @@ -227,13 +227,13 @@ int dldp_pgoqMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, uint32 psize) /* set q */ mp32copy(psize, temp, dp->p.modl); mp32divtwo(psize, temp); - mp32bset(&dp->q, psize, temp); + mpbset(&dp->q, psize, temp); /* set r = 2 */ mpnsetw(&dp->r, 2); /* clear n */ - mp32bzero(&dp->n); + mpbzero(&dp->n); (void) dldp_pgoqGenerator_w(dp, rgc, temp); @@ -259,10 +259,10 @@ int dldp_pgoqGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, uint32* wksp) while (1) { /* get a random value h (stored into g) */ - mp32brnd_w(&dp->p, rgc, dp->g.data, wksp); + mpbrnd_w(&dp->p, rgc, dp->g.data, wksp); /* first compute h^r mod p (stored in g) */ - mp32bpowmod_w(&dp->p, size, dp->g.data, dp->r.size, dp->r.data, dp->g.data, wksp); + mpbpowmod_w(&dp->p, size, dp->g.data, dp->r.size, dp->r.data, dp->g.data, wksp); if (mp32isone(size, dp->g.data)) continue; @@ -325,8 +325,8 @@ int dldp_pgonMake(dldp_p* dp, randomGeneratorContext* rgc, uint32 psize, uint32 /*@=globs@*/ /* set n */ - mp32bsubone(&dp->p, temp); - mp32bset(&dp->n, psize, temp); + mpbsubone(&dp->p, temp); + mpbset(&dp->n, psize, temp); (void) dldp_pgonGenerator_w(dp, rgc, temp); @@ -353,13 +353,13 @@ int dldp_pgonMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, uint32 psize) /*@=globs@*/ /* set n */ - mp32bsubone(&dp->p, temp); - mp32bset(&dp->n, psize, temp); + mpbsubone(&dp->p, temp); + mpbset(&dp->n, psize, temp); /* set q */ mp32copy(psize, temp, dp->p.modl); mp32divtwo(psize, temp); - mp32bset(&dp->q, psize, temp); + mpbset(&dp->q, psize, temp); /* set r = 2 */ mpnsetw(&dp->r, 2); @@ -382,7 +382,7 @@ int dldp_pgonGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, uint32* wksp) while (1) { - mp32brnd_w(&dp->p, rgc, dp->g.data, wksp); + mpbrnd_w(&dp->p, rgc, dp->g.data, wksp); if (mp32istwo(dp->r.size, dp->r.data)) { @@ -390,11 +390,11 @@ int dldp_pgonGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, uint32* wksp) * A little math here: the only element in the group which has order 2 is (p-1); * the two group elements raised to power two which result in 1 (mod p) are thus (p-1) and 1 * - * mp32brnd_w doesn't return 1 or (p-1), so the test where g^2 mod p = 1 can be safely skipped + * mpbrnd_w doesn't return 1 or (p-1), so the test where g^2 mod p = 1 can be safely skipped */ /* check g^q mod p*/ - mp32bpowmod_w(&dp->p, size, dp->g.data, dp->q.size, dp->q.modl, wksp, wksp+size); + mpbpowmod_w(&dp->p, size, dp->g.data, dp->q.size, dp->q.modl, wksp, wksp+size); if (mp32isone(size, wksp)) continue; } @@ -414,20 +414,20 @@ int dldp_pgonGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, uint32* wksp) mp32divtwo(size, wksp); /* compute t = g^s mod p */ - mp32bpowmod_w(&dp->p, size, dp->g.data, size, wksp, wksp+size, wksp+2*size); + mpbpowmod_w(&dp->p, size, dp->g.data, size, wksp, wksp+size, wksp+2*size); /* compute t^2 mod p = g^2s mod p = g^r mod p*/ - mp32bsqrmod_w(&dp->p, size, wksp+size, wksp+size, wksp+2*size); + mpbsqrmod_w(&dp->p, size, wksp+size, wksp+size, wksp+2*size); if (mp32isone(size, wksp+size)) continue; /* compute t^q mod p = g^qs mod p */ - mp32bpowmod_w(&dp->p, size, wksp, dp->q.size, dp->q.modl, wksp+size, wksp+2*size); + mpbpowmod_w(&dp->p, size, wksp, dp->q.size, dp->q.modl, wksp+size, wksp+2*size); if (mp32isone(size, wksp+size)) continue; /* compute g^2q mod p */ - mp32bpowmod_w(&dp->p, size, dp->g.data, dp->q.size, dp->q.modl, wksp, wksp+size); - mp32bsqrmod_w(&dp->p, size, wksp, wksp+size, wksp+2*size); + mpbpowmod_w(&dp->p, size, dp->g.data, dp->q.size, dp->q.modl, wksp, wksp+size); + mpbsqrmod_w(&dp->p, size, wksp, wksp+size, wksp+2*size); if (mp32isone(size, wksp+size)) continue; } diff --git a/beecrypt/dldp.h b/beecrypt/dldp.h index 0b9c96cd2..7efc5dfd3 100644 --- a/beecrypt/dldp.h +++ b/beecrypt/dldp.h @@ -50,11 +50,11 @@ */ typedef struct { - mp32barrett p; - mp32barrett q; + mpbarrett p; + mpbarrett q; mpnumber r; mpnumber g; - mp32barrett n; + mpbarrett n; } dldp_p; #ifdef __cplusplus diff --git a/beecrypt/dlsvdp-dh.c b/beecrypt/dlsvdp-dh.c index 47a17f1e5..19339611a 100644 --- a/beecrypt/dlsvdp-dh.c +++ b/beecrypt/dlsvdp-dh.c @@ -31,7 +31,7 @@ int dlsvdp_pDHSecret(const dldp_p* dp, const mpnumber* x, const mpnumber* y, mpnumber* s) { - mp32bnpowmod(&dp->p, y, x, s); + mpbnpowmod(&dp->p, y, x, s); return 0; } diff --git a/beecrypt/dsa.c b/beecrypt/dsa.c index a3d1cb882..a3e4f7933 100644 --- a/beecrypt/dsa.c +++ b/beecrypt/dsa.c @@ -48,7 +48,7 @@ #include "debug.h" /*@-boundswrite@*/ -int dsasign(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) +int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) { register uint32 psize = p->size; register uint32 qsize = q->size; @@ -78,7 +78,7 @@ int dsasign(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, rando mpnsize(r, qsize); /* get a random k, invertible modulo q */ - mp32brndinv_w(q, rgc, qtemp, qtemp+qsize, qwksp); + mpbrndinv_w(q, rgc, qtemp, qtemp+qsize, qwksp); /* FIPS 186 test vectors qtemp[0] = 0x358dad57; @@ -87,11 +87,11 @@ int dsasign(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, rando qtemp[3] = 0x1a376b2b; qtemp[4] = 0xdeaadfbf; - mp32binv_w(q, qsize, qtemp, qtemp+qsize, qwksp); + mpbinv_w(q, qsize, qtemp, qtemp+qsize, qwksp); */ /* g^k mod p */ - mp32bpowmod_w(p, g->size, g->data, qsize, qtemp, ptemp, pwksp); + mpbpowmod_w(p, g->size, g->data, qsize, qtemp, ptemp, pwksp); /* (g^k mod p) mod q - simple modulo */ mp32nmod(qtemp+2*qsize, psize, ptemp, qsize, q->modl, pwksp); @@ -102,13 +102,13 @@ int dsasign(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, rando mpnsize(s, qsize); /* x*r mod q */ - mp32bmulmod_w(q, x->size, x->data, r->size, r->data, qtemp, qwksp); + mpbmulmod_w(q, x->size, x->data, r->size, r->data, qtemp, qwksp); /* add h(m) mod q */ - mp32baddmod_w(q, qsize, qtemp, hm->size, hm->data, qtemp+2*qsize, qwksp); + mpbaddmod_w(q, qsize, qtemp, hm->size, hm->data, qtemp+2*qsize, qwksp); /* multiply inv(k) mod q */ - mp32bmulmod_w(q, qsize, qtemp+qsize, qsize, qtemp+2*qsize, s->data, qwksp); + mpbmulmod_w(q, qsize, qtemp+qsize, qsize, qtemp+2*qsize, s->data, qwksp); rc = 0; @@ -119,7 +119,7 @@ int dsasign(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, rando } /*@=boundswrite@*/ -int dsavrfy(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) +int dsavrfy(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) { register uint32 psize = p->size; register uint32 qsize = q->size; @@ -158,22 +158,22 @@ int dsavrfy(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, const qwksp = qtemp+2*qsize; /* compute w = inv(s) mod q */ - if (mp32binv_w(q, s->size, s->data, qtemp, qwksp)) + if (mpbinv_w(q, s->size, s->data, qtemp, qwksp)) { /* compute u1 = h(m)*w mod q */ - mp32bmulmod_w(q, hm->size, hm->data, qsize, qtemp, qtemp+qsize, qwksp); + mpbmulmod_w(q, hm->size, hm->data, qsize, qtemp, qtemp+qsize, qwksp); /* compute u2 = r*w mod q */ - mp32bmulmod_w(q, r->size, r->data, qsize, qtemp, qtemp, qwksp); + mpbmulmod_w(q, r->size, r->data, qsize, qtemp, qtemp, qwksp); /* compute g^u1 mod p */ - mp32bpowmod_w(p, g->size, g->data, qsize, qtemp+qsize, ptemp, pwksp); + mpbpowmod_w(p, g->size, g->data, qsize, qtemp+qsize, ptemp, pwksp); /* compute y^u2 mod p */ - mp32bpowmod_w(p, y->size, y->data, qsize, qtemp, ptemp+psize, pwksp); + mpbpowmod_w(p, y->size, y->data, qsize, qtemp, ptemp+psize, pwksp); /* multiply mod p */ - mp32bmulmod_w(p, psize, ptemp, psize, ptemp+psize, ptemp, pwksp); + mpbmulmod_w(p, psize, ptemp, psize, ptemp+psize, ptemp, pwksp); /* modulo q */ mp32nmod(ptemp+psize, psize, ptemp, qsize, q->modl, pwksp); diff --git a/beecrypt/dsa.h b/beecrypt/dsa.h index 4774fc632..e445da45a 100644 --- a/beecrypt/dsa.h +++ b/beecrypt/dsa.h @@ -37,13 +37,13 @@ extern "C" { /** */ BEECRYPTAPI /*@unused@*/ -int dsasign(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) +int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) /*@modifies r->size, r->data, *r->data, s->size, s->data @*/; /** */ BEECRYPTAPI /*@unused@*/ -int dsavrfy(const mp32barrett* p, const mp32barrett* q, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) +int dsavrfy(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) /*@*/; #ifdef __cplusplus diff --git a/beecrypt/elgamal.c b/beecrypt/elgamal.c index fcd688b2d..dcae10390 100644 --- a/beecrypt/elgamal.c +++ b/beecrypt/elgamal.c @@ -60,7 +60,7 @@ #include "mp.h" #include "debug.h" -int elgv1sign(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) +int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) { register uint32 size = p->size; register uint32* temp = (uint32*) malloc((13*size+11) * sizeof(*temp)); @@ -68,27 +68,27 @@ int elgv1sign(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, ran if (temp) { /* get a random k, invertible modulo (p-1) */ - mp32brndinv_w(n, rgc, temp, temp+size, temp+2*size); + mpbrndinv_w(n, rgc, temp, temp+size, temp+2*size); /* compute r = g^k mod p */ mpnfree(r); mpnsize(r, size); - mp32bpowmod_w(p, g->size, g->data, size, temp, r->data, temp+2*size); + mpbpowmod_w(p, g->size, g->data, size, temp, r->data, temp+2*size); /* compute x*r mod n */ - mp32bmulmod_w(n, x->size, x->data, r->size, r->data, temp, temp+2*size); + mpbmulmod_w(n, x->size, x->data, r->size, r->data, temp, temp+2*size); /* compute -(x*r) mod n */ mp32neg(size, temp); (void) mp32add(size, temp, n->modl); /* compute h(m) - x*r mod n */ - mp32baddmod_w(n, hm->size, hm->data, size, temp, temp, temp+2*size); + mpbaddmod_w(n, hm->size, hm->data, size, temp, temp, temp+2*size); /* compute s = inv(k)*(h(m) - x*r) mod n */ mpnfree(s); mpnsize(s, size); - mp32bmulmod_w(n, size, temp, size, temp+size, s->data, temp+2*size); + mpbmulmod_w(n, size, temp, size, temp+size, s->data, temp+2*size); free(temp); @@ -97,7 +97,7 @@ int elgv1sign(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, ran return -1; } -int elgv1vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) +int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) { register uint32 size = p->size; register uint32* temp; @@ -121,16 +121,16 @@ int elgv1vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, con register int rc; /* compute u1 = y^r mod p */ - mp32bpowmod_w(p, y->size, y->data, r->size, r->data, temp, temp+2*size); + mpbpowmod_w(p, y->size, y->data, r->size, r->data, temp, temp+2*size); /* compute u2 = r^s mod p */ - mp32bpowmod_w(p, r->size, r->data, s->size, s->data, temp+size, temp+2*size); + mpbpowmod_w(p, r->size, r->data, s->size, s->data, temp+size, temp+2*size); /* compute v2 = u1*u2 mod p */ - mp32bmulmod_w(p, size, temp, size, temp+size, temp+size, temp+2*size); + mpbmulmod_w(p, size, temp, size, temp+size, temp+size, temp+2*size); /* compute v1 = g^h(m) mod p */ - mp32bpowmod_w(p, g->size, g->data, hm->size, hm->data, temp, temp+2*size); + mpbpowmod_w(p, g->size, g->data, hm->size, hm->data, temp, temp+2*size); rc = mp32eq(size, temp, temp+size); @@ -141,7 +141,7 @@ int elgv1vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, con return 0; } -int elgv3sign(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) +int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) { register uint32 size = p->size; register uint32* temp = (uint32*) malloc((6*size+2) * sizeof(*temp)); @@ -149,23 +149,23 @@ int elgv3sign(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, ran if (temp) { /* get a random k */ - mp32brnd_w(p, rgc, temp, temp+2*size); + mpbrnd_w(p, rgc, temp, temp+2*size); /* compute r = g^k mod p */ mpnfree(r); mpnsize(r, size); - mp32bpowmod_w(p, g->size, g->data, size, temp, r->data, temp+2*size); + mpbpowmod_w(p, g->size, g->data, size, temp, r->data, temp+2*size); /* compute u1 = x*r mod n */ - mp32bmulmod_w(n, x->size, x->data, size, r->data, temp+size, temp+2*size); + mpbmulmod_w(n, x->size, x->data, size, r->data, temp+size, temp+2*size); /* compute u2 = k*h(m) mod n */ - mp32bmulmod_w(n, size, temp, hm->size, hm->data, temp, temp+2*size); + mpbmulmod_w(n, size, temp, hm->size, hm->data, temp, temp+2*size); /* compute s = u1+u2 mod n */ mpnfree(s); mpnsize(s, n->size); - mp32baddmod_w(n, size, temp, size, temp+size, s->data, temp+2*size); + mpbaddmod_w(n, size, temp, size, temp+size, s->data, temp+2*size); free(temp); @@ -174,7 +174,7 @@ int elgv3sign(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, ran return -1; } -int elgv3vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) +int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) { register uint32 size = p->size; register uint32* temp; @@ -198,16 +198,16 @@ int elgv3vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, con register int rc; /* compute u1 = y^r mod p */ - mp32bpowmod_w(p, y->size, y->data, r->size, r->data, temp, temp+2*size); + mpbpowmod_w(p, y->size, y->data, r->size, r->data, temp, temp+2*size); /* compute u2 = r^h(m) mod p */ - mp32bpowmod_w(p, r->size, r->data, hm->size, hm->data, temp+size, temp+2*size); + mpbpowmod_w(p, r->size, r->data, hm->size, hm->data, temp+size, temp+2*size); /* compute v2 = u1*u2 mod p */ - mp32bmulmod_w(p, size, temp, size, temp+size, temp+size, temp+2*size); + mpbmulmod_w(p, size, temp, size, temp+size, temp+size, temp+2*size); /* compute v1 = g^s mod p */ - mp32bpowmod_w(p, g->size, g->data, s->size, s->data, temp, temp+2*size); + mpbpowmod_w(p, g->size, g->data, s->size, s->data, temp, temp+2*size); rc = mp32eq(size, temp, temp+size); diff --git a/beecrypt/elgamal.h b/beecrypt/elgamal.h index 1b5d6a3f3..69dfdbff1 100644 --- a/beecrypt/elgamal.h +++ b/beecrypt/elgamal.h @@ -37,25 +37,25 @@ extern "C" { /** */ BEECRYPTAPI /*@unused@*/ -int elgv1sign(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, randomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) +int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) /*@modifies r, s */; /** */ BEECRYPTAPI /*@unused@*/ -int elgv3sign(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, randomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) +int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) /*@modifies r, s */; /** */ BEECRYPTAPI /*@unused@*/ -int elgv1vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) +int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) /*@*/; /** */ BEECRYPTAPI /*@unused@*/ -int elgv3vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) +int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) /*@*/; #ifdef __cplusplus diff --git a/beecrypt/mpbarrett.c b/beecrypt/mpbarrett.c index 80653ae3e..463d2bb40 100644 --- a/beecrypt/mpbarrett.c +++ b/beecrypt/mpbarrett.c @@ -38,63 +38,63 @@ #include "debug.h" /** - * mp32bzero + * mpbzero */ -void mp32bzero(mp32barrett* b) +void mpbzero(mpbarrett* b) { b->size = 0; - b->modl = (uint32*) 0; - b->mu = (uint32*) 0; + b->modl = (mpw*) 0; + b->mu = (mpw*) 0; } /*@-nullstate@*/ /* b->modl may be null @*/ /** - * Allocates the data words for an mp32barrett structure. + * Allocates the data words for an mpbarrett structure. * will allocate 2*size+1 words */ -void mp32binit(mp32barrett* b, uint32 size) +void mpbinit(mpbarrett* b, size_t size) { b->size = size; if (b->modl) free(b->modl); - b->modl = (uint32*) calloc(2*size+1, sizeof(uint32)); + b->modl = (mpw*) calloc(2*size+1, sizeof(*b->modl)); - if (b->modl != (uint32*) 0) + if (b->modl != (mpw*) 0) b->mu = b->modl+size; else - b->mu = (uint32*) 0; + b->mu = (mpw*) 0; } /*@=nullstate@*/ /** - * mp32bfree + * mpbfree */ -void mp32bfree(mp32barrett* b) +void mpbfree(mpbarrett* b) { - if (b->modl != (uint32*) 0) + if (b->modl != (mpw*) 0) { free(b->modl); - b->modl = (uint32*) 0; - b->mu = (uint32*) 0; + b->modl = (mpw*) 0; + b->mu = (mpw*) 0; } b->size = 0; } /*@-boundswrite@*/ /*@-nullstate -compdef @*/ /* b->modl may be null @*/ -void mp32bcopy(mp32barrett* b, const mp32barrett* copy) +void mpbcopy(mpbarrett* b, const mpbarrett* copy) { - register uint32 size = copy->size; + register size_t size = copy->size; if (size) { if (b->modl) { if (b->size != size) - b->modl = (uint32*) realloc(b->modl, (2*size+1) * sizeof(uint32)); + b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(*b->modl)); } else - b->modl = (uint32*) malloc((2*size+1) * sizeof(uint32)); + b->modl = (mpw*) malloc((2*size+1) * sizeof(*b->modl)); if (b->modl) { @@ -105,15 +105,15 @@ void mp32bcopy(mp32barrett* b, const mp32barrett* copy) else { b->size = 0; - b->mu = (uint32*) 0; + b->mu = (mpw*) 0; } } else if (b->modl) { free(b->modl); b->size = 0; - b->modl = (uint32*) 0; - b->mu = (uint32*) 0; + b->modl = (mpw*) 0; + b->mu = (mpw*) 0; } else {}; @@ -124,29 +124,29 @@ void mp32bcopy(mp32barrett* b, const mp32barrett* copy) /*@-boundswrite@*/ /*@-nullstate -compdef @*/ /* b->modl may be null @*/ /** - * mp32bset + * mpbset */ -void mp32bset(mp32barrett* b, uint32 size, const uint32 *data) +void mpbset(mpbarrett* b, size_t size, const mpw* data) { if (size > 0) { if (b->modl) { if (b->size != size) - b->modl = (uint32*) realloc(b->modl, (2*size+1) * sizeof(uint32)); + b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(*b->modl)); } else - b->modl = (uint32*) malloc((2*size+1) * sizeof(uint32)); + b->modl = (mpw*) malloc((2*size+1) * sizeof(*b->modl)); if (b->modl) { - uint32* temp = (uint32*) malloc((6*size+4) * sizeof(uint32)); + mpw* temp = (mpw*) malloc((6*size+4) * sizeof(*temp)); b->size = size; b->mu = b->modl+size; mp32copy(size, b->modl, data); /*@-nullpass@*/ /* temp may be NULL */ - mp32bmu_w(b, temp); + mpbmu_w(b, temp); free(temp); /*@=nullpass@*/ @@ -154,7 +154,7 @@ void mp32bset(mp32barrett* b, uint32 size, const uint32 *data) else { b->size = 0; - b->mu = (uint32*) 0; + b->mu = (mpw*) 0; } } } @@ -163,25 +163,25 @@ void mp32bset(mp32barrett* b, uint32 size, const uint32 *data) /*@-boundswrite@*/ /*@-nullstate -compdef @*/ /* b->modl may be null @*/ -void mp32bsethex(mp32barrett* b, const char* hex) +void mpbsethex(mpbarrett* b, const char* hex) { - uint32 length = strlen(hex); - uint32 size = (length+7) >> 3; + size_t length = strlen(hex); + size_t size = (length+7) >> 3; uint8 rem = (uint8)(length & 0x7); if (b->modl) { if (b->size != size) - b->modl = (uint32*) realloc(b->modl, (2*size+1) * sizeof(uint32)); + b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(*b->modl)); } else - b->modl = (uint32*) malloc((2*size+1) * sizeof(uint32)); + b->modl = (mpw*) malloc((2*size+1) * sizeof(*b->modl)); - if (b->modl != (uint32*) 0) + if (b->modl != (mpw*) 0) { - register uint32 val = 0; - register uint32* dst = b->modl; - register uint32* temp = (uint32*) malloc((6*size+4) * sizeof(uint32)); + register size_t val = 0; + register mpw* dst = b->modl; + register mpw* temp = (mpw*) malloc((6*size+4) * sizeof(*temp)); register char ch; b->size = size; @@ -210,7 +210,7 @@ void mp32bsethex(mp32barrett* b, const char* hex) *dst = val; /*@-nullpass@*/ /* temp may be NULL */ - mp32bmu_w(b, temp); + mpbmu_w(b, temp); free(temp); /*@=nullpass@*/ @@ -229,18 +229,18 @@ void mp32bsethex(mp32barrett* b, const char* hex) * needs workspace of (6*size+4) words */ /*@-boundswrite@*/ -void mp32bmu_w(mp32barrett* b, uint32* wksp) +void mpbmu_w(mpbarrett* b, mpw* wksp) { - register uint32 size = b->size; - register uint32* divmod = wksp; - register uint32* dividend = divmod+(size*2+2); - register uint32* workspace = dividend+(size*2+1); - register uint32 shift; + register size_t size = b->size; + register mpw* divmod = wksp; + register mpw* dividend = divmod+(size*2+2); + register mpw* workspace = dividend+(size*2+1); + register size_t shift; /* normalize modulus before division */ shift = mp32norm(size, b->modl); /* make the dividend, initialize first word to 1 (shifted); the rest is zero */ - *dividend = (uint32) (1 << shift); + *dividend = (mpw) (1 << shift); mp32zero(size*2, dividend+1); mp32ndivmod(divmod, size*2+1, dividend, size, b->modl, workspace); /*@-nullpass@*/ /* b->mu may be NULL */ @@ -256,7 +256,7 @@ void mp32bmu_w(mp32barrett* b, uint32* wksp) * need workspace of (size) words */ /*@-boundswrite@*/ -void mp32brnd_w(const mp32barrett* b, randomGeneratorContext* rc, uint32* result, uint32* wksp) +void mpbrnd_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mpw* wksp) { uint32 msz = mp32mszcnt(b->size, b->modl); @@ -284,7 +284,7 @@ void mp32brnd_w(const mp32barrett* b, randomGeneratorContext* rc, uint32* result * needs workspace of (size) words */ /*@-boundswrite@*/ -void mp32brndodd_w(const mp32barrett* b, randomGeneratorContext* rc, uint32* result, uint32* wksp) +void mpbrndodd_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mpw* wksp) { uint32 msz = mp32mszcnt(b->size, b->modl); @@ -315,18 +315,18 @@ void mp32brndodd_w(const mp32barrett* b, randomGeneratorContext* rc, uint32* res * Generates a random invertible (modulo b) in the range 1 < r < b-1. * needs workspace of (6*size+6) words */ -void mp32brndinv_w(const mp32barrett* b, randomGeneratorContext* rc, uint32* result, uint32* inverse, uint32* wksp) +void mpbrndinv_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mpw* inverse, mpw* wksp) { - register uint32 size = b->size; + register size_t size = b->size; do { if (mp32even(size, b->modl)) - mp32brndodd_w(b, rc, result, wksp); + mpbrndodd_w(b, rc, result, wksp); else - mp32brnd_w(b, rc, result, wksp); + mpbrnd_w(b, rc, result, wksp); - } while (mp32binv_w(b, size, result, inverse, wksp) == 0); + } while (mpbinv_w(b, size, result, inverse, wksp) == 0); } /** @@ -334,12 +334,12 @@ void mp32brndinv_w(const mp32barrett* b, randomGeneratorContext* rc, uint32* res * needs workspace of (2*size+2) words */ /*@-boundswrite@*/ -void mp32bmod_w(const mp32barrett* b, const uint32* xdata, uint32* result, uint32* wksp) +void mpbmod_w(const mpbarrett* b, const mpw* xdata, mpw* result, mpw* wksp) { register uint32 rc; register uint32 sp = 2; - register const uint32* src = xdata+b->size+1; - register uint32* dst = wksp +b->size+1; + register const mpw* src = xdata+b->size+1; + register mpw* dst = wksp +b->size+1; /*@-nullpass@*/ /* b->mu may be NULL */ rc = mp32setmul(sp, dst, b->mu, *(--src)); @@ -398,9 +398,9 @@ void mp32bmod_w(const mp32barrett* b, const uint32* xdata, uint32* result, uint3 * Copies (b-1) into result. */ /*@-boundswrite@*/ -void mp32bsubone(const mp32barrett* b, uint32* result) +void mpbsubone(const mpbarrett* b, mpw* result) { - register uint32 size = b->size; + register size_t size = b->size; mp32copy(size, result, b->modl); (void) mp32subw(size, result, 1); @@ -411,9 +411,9 @@ void mp32bsubone(const mp32barrett* b, uint32* result) * Computes the negative (modulo b) of x, where x must contain a value between 0 and b-1. */ /*@-boundswrite@*/ -void mp32bneg(const mp32barrett* b, const uint32* xdata, uint32* result) +void mpbneg(const mpbarrett* b, const mpw* xdata, mpw* result) { - register uint32 size = b->size; + register size_t size = b->size; mp32copy(size, result, xdata); mp32neg(size, result); @@ -425,52 +425,52 @@ void mp32bneg(const mp32barrett* b, const uint32* xdata, uint32* result) * Computes the sum (modulo b) of x and y. * needs a workspace of (4*size+2) words */ -void mp32baddmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32 ysize, const uint32* ydata, uint32* result, uint32* wksp) +void mpbaddmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* result, mpw* wksp) { /* xsize and ysize must be less than or equal to b->size */ - register uint32 size = b->size; - register uint32* temp = wksp + size*2+2; + register size_t size = b->size; + register mpw* temp = wksp + size*2+2; mp32setx(2*size, temp, xsize, xdata); (void) mp32addx(2*size, temp, ysize, ydata); - mp32bmod_w(b, temp, result, wksp); + mpbmod_w(b, temp, result, wksp); } /** * Computes the difference (modulo b) of x and y. * needs a workspace of (4*size+2) words */ -void mp32bsubmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32 ysize, const uint32* ydata, uint32* result, uint32* wksp) +void mpbsubmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* result, mpw* wksp) { /* xsize and ysize must be less than or equal to b->size */ - register uint32 size = b->size; - register uint32* temp = wksp + size*2+2; + register size_t size = b->size; + register mpw* temp = wksp + size*2+2; mp32setx(2*size, temp, xsize, xdata); if (mp32subx(2*size, temp, ysize, ydata)) /* if there's carry, i.e. the result would be negative, add the modulus */ (void) mp32addx(2*size, temp, size, b->modl); - mp32bmod_w(b, temp, result, wksp); + mpbmod_w(b, temp, result, wksp); } /** * Computes the product (modulo b) of x and y. * needs a workspace of (4*size+2) words */ -void mp32bmulmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32 ysize, const uint32* ydata, uint32* result, uint32* wksp) +void mpbmulmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* result, mpw* wksp) { /* xsize and ysize must be <= b->size */ - register uint32 size = b->size; - register uint32* temp = wksp + size*2+2; - register uint32 fill = size*2-xsize-ysize; + register size_t size = b->size; + register mpw* temp = wksp + size*2+2; + register size_t fill = size*2-xsize-ysize; if (fill) mp32zero(fill, temp); mp32mul(temp+fill, xsize, xdata, ysize, ydata); /*@-compdef@*/ /* *temp undefined */ - mp32bmod_w(b, temp, result, wksp); + mpbmod_w(b, temp, result, wksp); /*@=compdef@*/ } @@ -478,19 +478,19 @@ void mp32bmulmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint * Computes the square (modulo b) of x. * needs a workspace of (4*size+2) words */ -void mp32bsqrmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32* result, uint32* wksp) +void mpbsqrmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result, mpw* wksp) { /* xsize must be <= b->size */ - register uint32 size = b->size; - register uint32* temp = wksp + size*2+2; - register uint32 fill = 2*(size-xsize); + register size_t size = b->size; + register mpw* temp = wksp + size*2+2; + register size_t fill = 2*(size-xsize); if (fill) mp32zero(fill, temp); mp32sqr(temp+fill, xsize, xdata); /*@-compdef@*/ /* *temp undefined */ - mp32bmod_w(b, temp, result, wksp); + mpbmod_w(b, temp, result, wksp); /*@=compdef@*/ } @@ -531,39 +531,39 @@ void mp32bsqrmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint \endverbatim * */ -static void mp32bslide_w(const mp32barrett* b, const uint32 xsize, const uint32* xdata, /*@out@*/ uint32* slide, /*@out@*/ uint32* wksp) +static void mpbslide_w(const mpbarrett* b, const size_t xsize, const mpw* xdata, /*@out@*/ mpw* slide, /*@out@*/ mpw* wksp) /*@modifies slide, wksp @*/ { - register uint32 size = b->size; - mp32bsqrmod_w(b, xsize, xdata, slide , wksp); /* x^2 mod b, temp */ - mp32bmulmod_w(b, xsize, xdata, size, slide , slide+size , wksp); /* x^3 mod b */ - mp32bmulmod_w(b, size, slide, size, slide+size , slide+2*size, wksp); /* x^5 mod b */ - mp32bmulmod_w(b, size, slide, size, slide+2*size, slide+3*size, wksp); /* x^7 mod b */ - mp32bmulmod_w(b, size, slide, size, slide+3*size, slide+4*size, wksp); /* x^9 mod b */ - mp32bmulmod_w(b, size, slide, size, slide+4*size, slide+5*size, wksp); /* x^11 mod b */ - mp32bmulmod_w(b, size, slide, size, slide+5*size, slide+6*size, wksp); /* x^13 mod b */ - mp32bmulmod_w(b, size, slide, size, slide+6*size, slide+7*size, wksp); /* x^15 mod b */ + register size_t size = b->size; + mpbsqrmod_w(b, xsize, xdata, slide , wksp); /* x^2 mod b, temp */ + mpbmulmod_w(b, xsize, xdata, size, slide , slide+size , wksp); /* x^3 mod b */ + mpbmulmod_w(b, size, slide, size, slide+size , slide+2*size, wksp); /* x^5 mod b */ + mpbmulmod_w(b, size, slide, size, slide+2*size, slide+3*size, wksp); /* x^7 mod b */ + mpbmulmod_w(b, size, slide, size, slide+3*size, slide+4*size, wksp); /* x^9 mod b */ + mpbmulmod_w(b, size, slide, size, slide+4*size, slide+5*size, wksp); /* x^11 mod b */ + mpbmulmod_w(b, size, slide, size, slide+5*size, slide+6*size, wksp); /* x^13 mod b */ + mpbmulmod_w(b, size, slide, size, slide+6*size, slide+7*size, wksp); /* x^15 mod b */ mp32setx(size, slide, xsize, xdata); /* x^1 mod b */ } /*@observer@*/ /*@unchecked@*/ -static byte mp32bslide_presq[16] = +static byte mpbslide_presq[16] = { 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 4, 2, 4, 3, 4 }; /*@observer@*/ /*@unchecked@*/ -static byte mp32bslide_mulg[16] = +static byte mpbslide_mulg[16] = { 0, 0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7 }; /*@observer@*/ /*@unchecked@*/ -static byte mp32bslide_postsq[16] = +static byte mpbslide_postsq[16] = { 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 }; /** - * mp32bpowmod_w + * mpbpowmod_w * needs workspace of 4*size+2 words */ /*@-boundsread@*/ -void mp32bpowmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32 psize, const uint32* pdata, uint32* result, uint32* wksp) +void mpbpowmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t psize, const mpw* pdata, mpw* result, mpw* wksp) { /* * Modular exponention @@ -574,7 +574,7 @@ void mp32bpowmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint /* K == 4 for the first try */ - uint32 size = b->size; + size_t size = b->size; uint32 temp = 0; while (psize) @@ -587,13 +587,13 @@ void mp32bpowmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint /* if temp is still zero, then we're trying to raise x to power zero, and result stays one */ if (temp) { - uint32* slide = (uint32*) malloc((8*size)*sizeof(uint32)); + mpw* slide = (mpw*) malloc((8*size)*sizeof(*slide)); /*@-nullpass@*/ /* slide may be NULL */ - mp32bslide_w(b, xsize, xdata, slide, wksp); + mpbslide_w(b, xsize, xdata, slide, wksp); /*@-internalglobs -mods@*/ /* noisy */ - mp32bpowmodsld_w(b, slide, psize, pdata-1, result, wksp); + mpbpowmodsld_w(b, slide, psize, pdata-1, result, wksp); /*@=internalglobs =mods@*/ free(slide); @@ -603,14 +603,14 @@ void mp32bpowmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint /*@=boundsread@*/ /*@-boundsread@*/ -void mp32bpowmodsld_w(const mp32barrett* b, const uint32* slide, uint32 psize, const uint32* pdata, uint32* result, uint32* wksp) +void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mpw* pdata, mpw* result, mpw* wksp) { /* * Modular exponentiation with precomputed sliding window table, so no x is required * */ - uint32 size = b->size; + size_t size = b->size; uint32 temp = 0; mp32setw(size, result, 1); @@ -657,23 +657,23 @@ void mp32bpowmodsld_w(const mp32barrett* b, const uint32* slide, uint32 psize, c if (l == 4) { - uint8 s = mp32bslide_presq[n]; + uint8 s = mpbslide_presq[n]; while (s--) - mp32bsqrmod_w(b, size, result, result, wksp); + mpbsqrmod_w(b, size, result, result, wksp); - mp32bmulmod_w(b, size, result, size, slide+mp32bslide_mulg[n]*size, result, wksp); + mpbmulmod_w(b, size, result, size, slide+mpbslide_mulg[n]*size, result, wksp); - s = mp32bslide_postsq[n]; + s = mpbslide_postsq[n]; while (s--) - mp32bsqrmod_w(b, size, result, result, wksp); + mpbsqrmod_w(b, size, result, result, wksp); l = n = 0; } } else - mp32bsqrmod_w(b, size, result, result, wksp); + mpbsqrmod_w(b, size, result, result, wksp); temp <<= 1; count--; @@ -687,16 +687,16 @@ void mp32bpowmodsld_w(const mp32barrett* b, const uint32* slide, uint32 psize, c if (n != 0) { - uint8 s = mp32bslide_presq[n]; + uint8 s = mpbslide_presq[n]; while (s--) - mp32bsqrmod_w(b, size, result, result, wksp); + mpbsqrmod_w(b, size, result, result, wksp); - mp32bmulmod_w(b, size, result, size, slide+mp32bslide_mulg[n]*size, result, wksp); + mpbmulmod_w(b, size, result, size, slide+mpbslide_mulg[n]*size, result, wksp); - s = mp32bslide_postsq[n]; + s = mpbslide_postsq[n]; while (s--) - mp32bsqrmod_w(b, size, result, result, wksp); + mpbsqrmod_w(b, size, result, result, wksp); } } /*@=charindex@*/ @@ -704,11 +704,11 @@ void mp32bpowmodsld_w(const mp32barrett* b, const uint32* slide, uint32 psize, c /*@=boundsread@*/ /** - * mp32btwopowmod_w + * mpbtwopowmod_w * needs workspace of (4*size+2) words */ /*@-boundsread@*/ -void mp32btwopowmod_w(const mp32barrett* b, uint32 psize, const uint32* pdata, uint32* result, uint32* wksp) +void mpbtwopowmod_w(const mpbarrett* b, size_t psize, const mpw* pdata, mpw* result, mpw* wksp) { /* * Modular exponention, 2^p mod modulus, special optimization @@ -717,9 +717,9 @@ void mp32btwopowmod_w(const mp32barrett* b, uint32 psize, const uint32* pdata, u * */ - /* this routine calls mp32bmod, which needs (size*2+2), this routine needs (size*2) for sdata */ + /* this routine calls mpbmod, which needs (size*2+2), this routine needs (size*2) for sdata */ - register uint32 size = b->size; + register size_t size = b->size; register uint32 temp = 0; mp32setw(size, result, 1); @@ -750,7 +750,7 @@ void mp32btwopowmod_w(const mp32barrett* b, uint32 psize, const uint32* pdata, u while (count) { /* always square */ - mp32bsqrmod_w(b, size, result, result, wksp); + mpbsqrmod_w(b, size, result, result, wksp); /* multiply by two if bit is 1 */ if (temp & 0x80000000) @@ -778,7 +778,7 @@ void mp32btwopowmod_w(const mp32barrett* b, uint32 psize, const uint32* pdata, u * needs workspace of (6*size+6) words * @note xdata and result cannot point to the same area */ -int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32* result, uint32* wksp) +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 @@ -787,14 +787,14 @@ int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32* * The calling routine must guarantee this condition. */ - register uint32 size = b->size; + register size_t size = b->size; - uint32* udata = wksp; - uint32* vdata = udata+size+1; - uint32* adata = vdata+size+1; - uint32* bdata = adata+size+1; - uint32* cdata = bdata+size+1; - uint32* ddata = cdata+size+1; + 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; mp32setx(size+1, udata, size, b->modl); mp32setx(size+1, vdata, xsize, xdata); @@ -937,23 +937,23 @@ static int _debug = 0; * Computes the inverse (modulo b) of x, and returns 1 if x was invertible. */ /*@-boundsread@*/ -int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32* result, uint32* wksp) +int mpbinv_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result, mpw* wksp) { - uint32 ysize = b->size+1; + size_t ysize = b->size+1; int k; - uint32* u = wksp; - uint32* v = u+ysize; - uint32* u1 = v+ysize; - uint32* v1 = u1+ysize; - uint32* t1 = v1+ysize; - uint32* u3 = t1+ysize; - uint32* v3 = u3+ysize; - uint32* t3 = v3+ysize; + mpw* u = wksp; + mpw* v = u+ysize; + mpw* u1 = v+ysize; + mpw* v1 = u1+ysize; + mpw* t1 = v1+ysize; + mpw* u3 = t1+ysize; + mpw* v3 = u3+ysize; + mpw* t3 = v3+ysize; #ifdef FULL_BINARY_EXTENDED_GCD - uint32* u2 = t3+ysize; - uint32* v2 = u2+ysize; - uint32* t2 = v2+ysize; + mpw* u2 = t3+ysize; + mpw* v2 = u2+ysize; + mpw* t2 = v2+ysize; #endif mp32setx(ysize, u, xsize, xdata); @@ -1148,7 +1148,7 @@ fprintf(stderr, " t3: "), mp32println(stderr, ysize, t3); * needs workspace of (7*size+2) words */ /*@-boundsread@*/ -int mp32bpprime_w(const mp32barrett* b, randomGeneratorContext* rc, int t, uint32* wksp) +int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* rc, int t, mpw* wksp) { /* * This test works for candidate probable primes >= 3, which are also not small primes. @@ -1157,7 +1157,7 @@ int mp32bpprime_w(const mp32barrett* b, randomGeneratorContext* rc, int t, uint3 * */ - uint32 size = b->size; + size_t size = b->size; /* first test if modl is odd */ @@ -1199,31 +1199,31 @@ int mp32bpprime_w(const mp32barrett* b, randomGeneratorContext* rc, int t, uint3 } /*@=boundsread@*/ -void mp32bnrnd(const mp32barrett* b, randomGeneratorContext* rc, mpnumber* result) +void mpbnrnd(const mpbarrett* b, randomGeneratorContext* rc, mpnumber* result) { - register uint32 size = b->size; - register uint32* temp = (uint32*) malloc(size * sizeof(uint32)); + register size_t size = b->size; + register mpw* temp = (mpw*) malloc(size * sizeof(*temp)); mpnfree(result); mpnsize(result, size); /*@-nullpass@*/ /* temp may be NULL */ /*@-usedef@*/ /* result->data unallocated? */ - mp32brnd_w(b, rc, result->data, temp); + mpbrnd_w(b, rc, result->data, temp); /*@=usedef@*/ free(temp); /*@=nullpass@*/ } -void mp32bnmulmod(const mp32barrett* b, const mpnumber* x, const mpnumber* y, mpnumber* result) +void mpbnmulmod(const mpbarrett* b, const mpnumber* x, const mpnumber* y, mpnumber* result) { - register uint32 size = b->size; - register uint32* temp = (uint32*) malloc((4*size+2) * sizeof(uint32)); + register size_t size = b->size; + register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(*temp)); /* xsize and ysize must be <= b->size */ - register uint32 fill = 2*size-x->size-y->size; + register size_t fill = 2*size-x->size-y->size; /*@-nullptrarith@*/ /* temp may be NULL */ - register uint32* opnd = temp+size*2+2; + register mpw* opnd = temp+size*2+2; /*@=nullptrarith@*/ mpnfree(result); @@ -1235,22 +1235,22 @@ void mp32bnmulmod(const mp32barrett* b, const mpnumber* x, const mpnumber* y, mp mp32mul(opnd+fill, x->size, x->data, y->size, y->data); /*@-nullpass@*/ /* temp may be NULL */ /*@-usedef -compdef @*/ /* result->data unallocated? */ - mp32bmod_w(b, opnd, result->data, temp); + mpbmod_w(b, opnd, result->data, temp); /*@=usedef =compdef @*/ free(temp); /*@=nullpass@*/ } -void mp32bnsqrmod(const mp32barrett* b, const mpnumber* x, mpnumber* result) +void mpbnsqrmod(const mpbarrett* b, const mpnumber* x, mpnumber* result) { - register uint32 size = b->size; - register uint32* temp = (uint32*) malloc(size * sizeof(uint32)); + register size_t size = b->size; + register mpw* temp = (mpw*) malloc(size * sizeof(*temp)); /* xsize must be <= b->size */ - register uint32 fill = 2*(size-x->size); + register size_t fill = 2*(size-x->size); /*@-nullptrarith@*/ /* temp may be NULL */ - register uint32* opnd = temp + size*2+2; + register mpw* opnd = temp + size*2+2; /*@=nullptrarith@*/ mpnfree(result); @@ -1262,39 +1262,39 @@ void mp32bnsqrmod(const mp32barrett* b, const mpnumber* x, mpnumber* result) mp32sqr(opnd+fill, x->size, x->data); /*@-nullpass@*/ /* temp may be NULL */ /*@-usedef -compdef @*/ /* result->data unallocated? */ - mp32bmod_w(b, opnd, result->data, temp); + mpbmod_w(b, opnd, result->data, temp); /*@=usedef =compdef @*/ free(temp); /*@=nullpass@*/ } -void mp32bnpowmod(const mp32barrett* b, const mpnumber* x, const mpnumber* pow, mpnumber* y) +void mpbnpowmod(const mpbarrett* b, const mpnumber* x, const mpnumber* pow, mpnumber* y) { - register uint32 size = b->size; - register uint32* temp = (uint32*) malloc((4*size+2) * sizeof(uint32)); + register size_t size = b->size; + register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(*temp)); mpnfree(y); mpnsize(y, size); /*@-nullpass@*/ /* temp may be NULL */ - mp32bpowmod_w(b, x->size, x->data, pow->size, pow->data, y->data, temp); + mpbpowmod_w(b, x->size, x->data, pow->size, pow->data, y->data, temp); free(temp); /*@=nullpass@*/ } -void mp32bnpowmodsld(const mp32barrett* b, const uint32* slide, const mpnumber* pow, mpnumber* y) +void mpbnpowmodsld(const mpbarrett* b, const mpw* slide, const mpnumber* pow, mpnumber* y) { - register uint32 size = b->size; - register uint32* temp = (uint32*) malloc((4*size+2) * sizeof(uint32)); + register size_t size = b->size; + register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(*temp)); mpnfree(y); mpnsize(y, size); /*@-nullpass@*/ /* temp may be NULL */ /*@-internalglobs -mods@*/ /* noisy */ - mp32bpowmodsld_w(b, slide, pow->size, pow->data, y->data, temp); + mpbpowmodsld_w(b, slide, pow->size, pow->data, y->data, temp); /*@=internalglobs =mods@*/ free(temp); diff --git a/beecrypt/mpbarrett.h b/beecrypt/mpbarrett.h index fb4e4ab84..8dec07759 100644 --- a/beecrypt/mpbarrett.h +++ b/beecrypt/mpbarrett.h @@ -33,12 +33,12 @@ typedef struct { - uint32 size; + size_t size; /*@owned@*/ - uint32* modl; /* (size) words */ + mpw* modl; /* (size) words */ /*@dependent@*/ /*@null@*/ - uint32* mu; /* (size+1) words */ -} mp32barrett; + mpw* mu; /* (size+1) words */ +} mpbarrett; #ifdef __cplusplus extern "C" { @@ -47,19 +47,19 @@ extern "C" { /** */ BEECRYPTAPI -void mp32bzero(/*@out@*/ mp32barrett* b) +void mpbzero(/*@out@*/ mpbarrett* b) /*@modifies b->size, b->modl, b->mu @*/; /** */ BEECRYPTAPI -void mp32binit(mp32barrett* b, uint32 size) +void mpbinit(mpbarrett* b, size_t size) /*@modifies b->size, b->modl, b->mu @*/; /** */ BEECRYPTAPI -void mp32bfree(/*@special@*/ mp32barrett* b) +void mpbfree(/*@special@*/ mpbarrett* b) /*@uses b->size, b->modl @*/ /*@releases b->modl @*/ /*@modifies b->size, b->modl, b->mu @*/; @@ -67,100 +67,100 @@ void mp32bfree(/*@special@*/ mp32barrett* b) /** */ BEECRYPTAPI -void mp32bcopy(mp32barrett* b, const mp32barrett* copy) +void mpbcopy(mpbarrett* b, const mpbarrett* copy) /*@modifies b->size, b->modl, b->mu @*/; /** */ BEECRYPTAPI -void mp32bset(mp32barrett* b, uint32 size, const uint32* data) +void mpbset(mpbarrett* b, size_t size, const mpw* data) /*@modifies b->size, b->modl, b->mu @*/; /** */ BEECRYPTAPI /*@unused@*/ -void mp32bsethex(mp32barrett* b, const char* hex) +void mpbsethex(mpbarrett* b, const char* hex) /*@modifies b->size, b->modl, b->mu @*/; /** */ BEECRYPTAPI -void mp32bsubone(const mp32barrett* b, uint32* result) +void mpbsubone(const mpbarrett* b, mpw* result) /*@modifies result @*/; /** */ BEECRYPTAPI /*@unused@*/ -void mp32bneg(const mp32barrett* b, const uint32* xdata, uint32* result) +void mpbneg(const mpbarrett* b, const mpw* xdata, mpw* result) /*@modifies result @*/; /** */ BEECRYPTAPI -void mp32bmu_w(mp32barrett* b, /*@out@*/ uint32* wksp) +void mpbmu_w(mpbarrett* b, /*@out@*/ mpw* wksp) /*@modifies b->size, b->modl, b->mu, wksp @*/; /** */ BEECRYPTAPI -void mp32brnd_w (const mp32barrett* b, randomGeneratorContext* rc, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbrnd_w (const mpbarrett* b, randomGeneratorContext* rc, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** */ /*@-exportlocal@*/ BEECRYPTAPI -void mp32brndodd_w(const mp32barrett* b, randomGeneratorContext* rc, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbrndodd_w(const mpbarrett* b, randomGeneratorContext* rc, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /*@=exportlocal@*/ /** */ BEECRYPTAPI -void mp32brndinv_w(const mp32barrett* b, randomGeneratorContext* rc, /*@out@*/ uint32* result, /*@out@*/ uint32* inverse, /*@out@*/ uint32* wksp) +void mpbrndinv_w(const mpbarrett* b, randomGeneratorContext* rc, /*@out@*/ mpw* result, /*@out@*/ mpw* inverse, /*@out@*/ mpw* wksp) /*@modifies result, inverse, wksp @*/; /** */ BEECRYPTAPI -void mp32bmod_w(const mp32barrett* b, const uint32* xdata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbmod_w(const mpbarrett* b, const mpw* xdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** */ BEECRYPTAPI -void mp32baddmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32 ysize, const uint32* ydata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbaddmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** */ BEECRYPTAPI /*@unused@*/ -void mp32bsubmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32 ysize, const uint32* ydata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbsubmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** */ BEECRYPTAPI -void mp32bmulmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32 ysize, const uint32* ydata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbmulmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** */ BEECRYPTAPI -void mp32bsqrmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbsqrmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** */ BEECRYPTAPI -void mp32bpowmod_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32 psize, const uint32* pdata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbpowmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t psize, const mpw* pdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** */ /*@-exportlocal@*/ BEECRYPTAPI -void mp32bpowmodsld_w(const mp32barrett* b, const uint32* slide, uint32 psize, const uint32* pdata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mpw* pdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@globals internalState @*/ /*@modifies result, wksp, internalState @*/; /*@=exportlocal@*/ @@ -168,13 +168,13 @@ void mp32bpowmodsld_w(const mp32barrett* b, const uint32* slide, uint32 psize, c /** */ BEECRYPTAPI -void mp32btwopowmod_w(const mp32barrett* b, uint32 psize, const uint32* pdata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +void mpbtwopowmod_w(const mpbarrett* b, size_t psize, const mpw* pdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** */ BEECRYPTAPI -int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, /*@out@*/ uint32* result, /*@out@*/ uint32* wksp) +int mpbinv_w(const mpbarrett* b, size_t xsize, const mpw* xdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; #ifdef NOTYET @@ -183,53 +183,53 @@ int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, /*@out@ * signature verification. */ BEECRYPTAPI /*@unused@*/ -void mp32bsm2powmod(const mp32barrett* b, const uint32*, const uint32*, const uint32*, const uint32*); +void mpbsm2powmod(const mpbarrett* b, const mpw*, const mpw*, const mpw*, const mpw*); /** */ BEECRYPTAPI /*@unused@*/ -void mp32bsm3powmod(const mp32barrett* b, const uint32*, const uint32*, const uint32*, const uint32*, const uint32*, const uint32*); +void mpbsm3powmod(const mpbarrett* b, const mpw*, const mpw*, const mpw*, const mpw*, const mpw*, const mpw*); #endif /* NOTYET */ /** */ BEECRYPTAPI /*@unused@*/ -int mp32bpprime_w(const mp32barrett* b, randomGeneratorContext* rc, int t, /*@out@*/ uint32* wksp) +int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* rc, int t, /*@out@*/ mpw* wksp) /*@modifies wksp @*/; /** * @note Takes mpnumber as parameter. */ BEECRYPTAPI -void mp32bnrnd(const mp32barrett* b, randomGeneratorContext* rc, mpnumber* result) +void mpbnrnd(const mpbarrett* b, randomGeneratorContext* rc, mpnumber* result) /*@modifies result @*/; /** * @note Takes mpnumber as parameter. */ BEECRYPTAPI /*@unused@*/ -void mp32bnmulmod(const mp32barrett* b, const mpnumber* x, const mpnumber* y, mpnumber* result) +void mpbnmulmod(const mpbarrett* b, const mpnumber* x, const mpnumber* y, mpnumber* result) /*@modifies result @*/; /** * @note Takes mpnumber as parameter. */ BEECRYPTAPI /*@unused@*/ -void mp32bnsqrmod(const mp32barrett* b, const mpnumber* x, mpnumber* result) +void mpbnsqrmod(const mpbarrett* b, const mpnumber* x, mpnumber* result) /*@modifies result @*/; /** * @note Takes mpnumber as parameter. */ BEECRYPTAPI -void mp32bnpowmod (const mp32barrett* b, const mpnumber* x, const mpnumber* pow, mpnumber* y) +void mpbnpowmod (const mpbarrett* b, const mpnumber* x, const mpnumber* pow, mpnumber* y) /*@modifies y @*/; /** * @note Takes mpnumber as parameter. */ BEECRYPTAPI /*@unused@*/ -void mp32bnpowmodsld(const mp32barrett* b, const uint32* slide, const mpnumber* pow, mpnumber* y) +void mpbnpowmodsld(const mpbarrett* b, const mpw* slide, const mpnumber* pow, mpnumber* y) /*@modifies y @*/; #ifdef __cplusplus diff --git a/beecrypt/mpprime.c b/beecrypt/mpprime.c index ebf8a57d5..91fce1014 100644 --- a/beecrypt/mpprime.c +++ b/beecrypt/mpprime.c @@ -1053,12 +1053,12 @@ int mp32ptrials(uint32 bits) /** */ /*@-boundsread@*/ -static void mp32prndbits(mp32barrett* p, uint8 msbclr, uint8 lsbset, randomGeneratorContext* rc) +static void mp32prndbits(mpbarrett* p, uint8 msbclr, uint8 lsbset, randomGeneratorContext* rc) /*@modifies p @*/ { register uint32 size; - if (p == (mp32barrett*) 0 || p->modl == (uint32*) 0) + if (p == (mpbarrett*) 0 || p->modl == (uint32*) 0) return; size = p->size; @@ -1083,7 +1083,7 @@ static void mp32prndbits(mp32barrett* p, uint8 msbclr, uint8 lsbset, randomGener * needs workspace of (3*size) words */ /*@-boundsread@*/ -static int mp32psppdiv_w(const mp32barrett* p, /*@out@*/ uint32* wksp) +static int mp32psppdiv_w(const mpbarrett* p, /*@out@*/ uint32* wksp) /*@globals mp32spprod @*/ /*@modifies wksp @*/ { @@ -1110,13 +1110,13 @@ static int mp32psppdiv_w(const mp32barrett* p, /*@out@*/ uint32* wksp) * mp32pmilrabtwo_w * needs workspace of (5*size+2) */ -static int mp32pmilrabtwo_w(const mp32barrett* p, uint32 s, const uint32* rdata, const uint32* ndata, /*@out@*/ uint32* wksp) +static int mp32pmilrabtwo_w(const mpbarrett* p, uint32 s, const uint32* rdata, const uint32* ndata, /*@out@*/ uint32* wksp) /*@modifies wksp @*/ { register uint32 size = p->size; register uint32 j = 0; - mp32btwopowmod_w(p, size, rdata, wksp, wksp+size); + mpbtwopowmod_w(p, size, rdata, wksp, wksp+size); while (1) { @@ -1127,7 +1127,7 @@ static int mp32pmilrabtwo_w(const mp32barrett* p, uint32 s, const uint32* rdata, return 1; if (++j < s) - mp32bsqrmod_w(p, size, wksp, wksp, wksp+size); + mpbsqrmod_w(p, size, wksp, wksp, wksp+size); else return 0; } @@ -1137,13 +1137,13 @@ static int mp32pmilrabtwo_w(const mp32barrett* p, uint32 s, const uint32* rdata, * mp32pmilraba_w * needs workspace of (5*size+2) words */ -static int mp32pmilraba_w(const mp32barrett* p, const uint32* adata, uint32 s, const uint32* rdata, const uint32* ndata, /*@out@*/ uint32* wksp) +static int mp32pmilraba_w(const mpbarrett* p, const uint32* adata, uint32 s, const uint32* rdata, const uint32* ndata, /*@out@*/ uint32* wksp) /*@modifies wksp @*/ { register uint32 size = p->size; register uint32 j = 0; - mp32bpowmod_w(p, size, adata, size, rdata, wksp, wksp+size); + mpbpowmod_w(p, size, adata, size, rdata, wksp, wksp+size); while (1) { @@ -1154,7 +1154,7 @@ static int mp32pmilraba_w(const mp32barrett* p, const uint32* adata, uint32 s, c return 1; if (++j < s) - mp32bsqrmod_w(p, size, wksp, wksp, wksp+size); + mpbsqrmod_w(p, size, wksp, wksp, wksp+size); else return 0; } @@ -1164,7 +1164,7 @@ static int mp32pmilraba_w(const mp32barrett* p, const uint32* adata, uint32 s, c * needs workspace of (8*size+2) words */ /*@-boundswrite@*/ -int mp32pmilrab_w(const mp32barrett* p, randomGeneratorContext* rc, int t, uint32* wksp) +int mp32pmilrab_w(const mpbarrett* p, randomGeneratorContext* rc, int t, uint32* wksp) { /* * Miller-Rabin probabilistic primality test, with modification @@ -1177,7 +1177,7 @@ int mp32pmilrab_w(const mp32barrett* p, randomGeneratorContext* rc, int t, uint3 * The first value of a is not obtained randomly, but set to two */ - /* this routine uses (size*3) storage, and calls mp32bpowmod, which needs (size*4+2) */ + /* this routine uses (size*3) storage, and calls mpbpowmod, which needs (size*4+2) */ /* (size) for a, (size) for r, (size) for n-1 */ register uint32 size = p->size; @@ -1205,7 +1205,7 @@ int mp32pmilrab_w(const mp32barrett* p, randomGeneratorContext* rc, int t, uint3 while (t-- > 0) { /* generate a random 'a' into b->data */ - mp32brnd_w(p, rc, adata, wksp); + mpbrnd_w(p, rc, adata, wksp); if (!mp32pmilraba_w(p, adata, s, rdata, ndata, wksp+3*size)) return 0; @@ -1219,7 +1219,7 @@ int mp32pmilrab_w(const mp32barrett* p, randomGeneratorContext* rc, int t, uint3 * needs workspace of (7*size+2) words */ /*@-boundswrite@*/ -void mp32prnd_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, const mpnumber* f, uint32* wksp) +void mp32prnd_w(mpbarrett* p, randomGeneratorContext* rc, uint32 size, int t, const mpnumber* f, uint32* wksp) { /* * Generate a prime into p with (size*32) bits @@ -1229,7 +1229,7 @@ void mp32prnd_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, * Optional input f: if f is not null, then search p so that GCD(p-1,f) = 1 */ - mp32binit(p, size); + mpbinit(p, size); if (p->modl != (uint32*) 0) { @@ -1259,7 +1259,7 @@ void mp32prnd_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, } /* candidate has passed so far, now we do the probabilistic test */ - mp32bmu_w(p, wksp); + mpbmu_w(p, wksp); if (mp32pmilrab_w(p, rc, t, wksp)) return; @@ -1272,7 +1272,7 @@ void mp32prnd_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, * needs workspace of (7*size+2) words */ /*@-boundswrite@*/ -void mp32prndconone_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, const mp32barrett* q, const mpnumber* f, mpnumber* r, int cofactor, uint32* wksp) +void mp32prndconone_w(mpbarrett* p, randomGeneratorContext* rc, uint32 size, int t, const mpbarrett* q, const mpnumber* f, mpnumber* r, int cofactor, uint32* wksp) { /* * Generate a prime p with n bits such that p mod q = 1, and p = qr+1; r = 2s @@ -1289,14 +1289,14 @@ void mp32prndconone_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, i * Optional input f: if f is not null, then search p so that GCD(p-1,f) = 1 */ - mp32binit(p, size); + mpbinit(p, size); if (p->modl != (uint32*) 0) { - mp32barrett s; + mpbarrett s; - mp32bzero(&s); - mp32binit(&s, p->size - q->size); + mpbzero(&s); + mpbinit(&s, p->size - q->size); while (1) { @@ -1355,21 +1355,21 @@ void mp32prndconone_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, i /* if cofactor is two, test if s is prime */ if (cofactor == 2) { - mp32bmu_w(&s, wksp); + mpbmu_w(&s, wksp); if (!mp32pmilrab_w(&s, rc, mp32ptrials(s.size << 5), wksp)) continue; } /* candidate has passed so far, now we do the probabilistic test on p */ - mp32bmu_w(p, wksp); + mpbmu_w(p, wksp); if (!mp32pmilrab_w(p, rc, t, wksp)) continue; mpnset(r, s.size, s.modl); (void) mp32multwo(r->size, r->data); - mp32bfree(&s); + mpbfree(&s); return; /*@=usedef@*/ @@ -1379,7 +1379,7 @@ void mp32prndconone_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, i /*@=boundswrite@*/ /*@-boundswrite@*/ -void mp32prndsafe_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, uint32* wksp) +void mp32prndsafe_w(mpbarrett* p, randomGeneratorContext* rc, uint32 size, int t, uint32* wksp) { /* * Initialize with a probable safe prime of 'size' words, with probability factor t @@ -1388,14 +1388,14 @@ void mp32prndsafe_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int * Use for ElGamal type schemes, where a generator of order (p-1) is required */ - mp32binit(p, size); + mpbinit(p, size); if (p->modl != (uint32*) 0) { - mp32barrett q; + mpbarrett q; - mp32bzero(&q); - mp32binit(&q, size); + mpbzero(&q); + mpbinit(&q, size); /*@-usedef@*/ /* q is set */ while (1) @@ -1419,17 +1419,17 @@ void mp32prndsafe_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int continue; /* candidate prime has passed small prime division test for p and q */ - mp32bmu_w(&q, wksp); + mpbmu_w(&q, wksp); if (!mp32pmilrab_w(&q, rc, t, wksp)) continue; - mp32bmu_w(p, wksp); + mpbmu_w(p, wksp); if (!mp32pmilrab_w(p, rc, t, wksp)) continue; - mp32bfree(&q); + mpbfree(&q); return; } diff --git a/beecrypt/mpprime.h b/beecrypt/mpprime.h index 8f99a88fb..f27fac602 100644 --- a/beecrypt/mpprime.h +++ b/beecrypt/mpprime.h @@ -51,20 +51,20 @@ int mp32ptrials (uint32 bits) /** */ BEECRYPTAPI -int mp32pmilrab_w (const mp32barrett* p, randomGeneratorContext* rc, int t, /*@out@*/ uint32* wksp) +int mp32pmilrab_w (const mpbarrett* p, randomGeneratorContext* rc, int t, /*@out@*/ uint32* wksp) /*@modifies wksp @*/; /** */ BEECRYPTAPI -void mp32prnd_w (mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, /*@null@*/ const mpnumber* f, /*@out@*/ uint32* wksp) +void mp32prnd_w (mpbarrett* p, randomGeneratorContext* rc, uint32 size, int t, /*@null@*/ const mpnumber* f, /*@out@*/ uint32* wksp) /*@globals mp32spprod @*/ /*@modifies p, rc, wksp @*/; /** */ BEECRYPTAPI -void mp32prndsafe_w (mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, /*@out@*/ uint32* wksp) +void mp32prndsafe_w (mpbarrett* p, randomGeneratorContext* rc, uint32 size, int t, /*@out@*/ uint32* wksp) /*@globals mp32spprod @*/ /*@modifies p, rc, wksp @*/; @@ -72,14 +72,14 @@ void mp32prndsafe_w (mp32barrett* p, randomGeneratorContext* rc, uint32 size, i /** */ BEECRYPTAPI /*@unused@*/ -void mp32prndcon_w (mp32barrett* p, randomGeneratorContext* rc, uint32, int, const mpnumber*, const mpnumber*, const mpnumber*, mpnumber*, /*@out@*/ uint32* wksp) +void mp32prndcon_w (mpbarrett* p, randomGeneratorContext* rc, uint32, int, const mpnumber*, const mpnumber*, const mpnumber*, mpnumber*, /*@out@*/ uint32* wksp) /*@modifies wksp @*/; #endif /** */ BEECRYPTAPI -void mp32prndconone_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, const mp32barrett* q, /*@null@*/ const mpnumber* f, mpnumber* r, int cofactor, /*@out@*/ uint32* wksp) +void mp32prndconone_w(mpbarrett* p, randomGeneratorContext* rc, uint32 size, int t, const mpbarrett* q, /*@null@*/ const mpnumber* f, mpnumber* r, int cofactor, /*@out@*/ uint32* wksp) /*@globals mp32spprod @*/ /*@modifies p, rc, r, wksp @*/; diff --git a/beecrypt/rsa.c b/beecrypt/rsa.c index 6d0045e75..9437ba0c0 100644 --- a/beecrypt/rsa.c +++ b/beecrypt/rsa.c @@ -38,7 +38,7 @@ int rsapri(const rsakp* kp, const mpnumber* m, mpnumber* c) if (temp) { mpnsize(c, size); - mp32bpowmod_w(&kp->n, m->size, m->data, kp->d.size, kp->d.data, c->data, temp); + mpbpowmod_w(&kp->n, m->size, m->data, kp->d.size, kp->d.data, c->data, temp); free(temp); @@ -77,20 +77,20 @@ int rsapricrt(const rsakp* kp, const mpnumber* m, mpnumber* c) /* compute j1 = m^d1 mod p, store @ ptemp */ /*@-compdef@*/ - mp32bpowmod_w(&kp->p, psize, ptemp+psize, kp->d1.size, kp->d1.data, ptemp, ptemp+2*psize); + mpbpowmod_w(&kp->p, psize, ptemp+psize, kp->d1.size, kp->d1.data, ptemp, ptemp+2*psize); /* resize m for powmod p */ mp32setx(qsize, qtemp+psize, m->size, m->data); /* compute j2 = m^d2 mod q, store @ qtemp */ - mp32bpowmod_w(&kp->q, qsize, qtemp+psize, kp->d2.size, kp->d2.data, qtemp, qtemp+2*qsize); + mpbpowmod_w(&kp->q, qsize, qtemp+psize, kp->d2.size, kp->d2.data, qtemp, qtemp+2*qsize); /*@=compdef@*/ /* compute j1-j2 mod p, store @ ptemp */ - mp32bsubmod_w(&kp->p, psize, ptemp, qsize, qtemp, ptemp, ptemp+2*psize); + mpbsubmod_w(&kp->p, psize, ptemp, qsize, qtemp, ptemp, ptemp+2*psize); /* compute h = c*(j1-j2) mod p, store @ ptemp */ - mp32bmulmod_w(&kp->p, psize, ptemp, psize, kp->c.data, ptemp, ptemp+2*psize); + mpbmulmod_w(&kp->p, psize, ptemp, psize, kp->c.data, ptemp, ptemp+2*psize); /* make sure the signature gets the proper size */ mpnsize(c, nsize); @@ -116,7 +116,7 @@ int rsavrfy(const rsapk* pk, const mpnumber* m, const mpnumber* c) if (temp) { - mp32bpowmod_w(&pk->n, c->size, c->data, pk->e.size, pk->e.data, temp, temp+size); + mpbpowmod_w(&pk->n, c->size, c->data, pk->e.size, pk->e.data, temp, temp+size); rc = mp32eqx(size, temp, m->size, m->data); diff --git a/beecrypt/rsakp.c b/beecrypt/rsakp.c index 27f179216..96f0e4465 100644 --- a/beecrypt/rsakp.c +++ b/beecrypt/rsakp.c @@ -46,7 +46,7 @@ int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, int nsize) if (temp) { - mp32barrett r, psubone, qsubone, phi; + mpbarrett r, psubone, qsubone, phi; nsize = pqsize << 1; @@ -63,16 +63,16 @@ int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, int nsize) if (mp32le(pqsize, kp->p.modl, kp->q.modl)) { /*@-sizeoftype@*/ - memcpy(&r, &kp->q, sizeof(mp32barrett)); - memcpy(&kp->q, &kp->p, sizeof(mp32barrett)); - memcpy(&kp->p, &r, sizeof(mp32barrett)); + memcpy(&r, &kp->q, sizeof(r)); + memcpy(&kp->q, &kp->p, sizeof(kp->q)); + memcpy(&kp->p, &r, sizeof(kp->p)); /*@=sizeoftype@*/ } - mp32bzero(&r); - mp32bzero(&psubone); - mp32bzero(&qsubone); - mp32bzero(&phi); + mpbzero(&r); + mpbzero(&psubone); + mpbzero(&qsubone); + mpbzero(&phi); while (1) { @@ -90,61 +90,61 @@ int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, int nsize) /*@-usedef -branchstate @*/ /* r is set */ if (mp32le(pqsize, kp->p.modl, r.modl)) { - mp32bfree(&kp->q); + mpbfree(&kp->q); /*@-sizeoftype@*/ - memcpy(&kp->q, &kp->p, sizeof(mp32barrett)); - memcpy(&kp->p, &r, sizeof(mp32barrett)); + memcpy(&kp->q, &kp->p, sizeof(kp->q)); + memcpy(&kp->p, &r, sizeof(kp->p)); /*@=sizeoftype@*/ - mp32bzero(&r); + mpbzero(&r); newn = 1; } else if (mp32le(pqsize, kp->q.modl, r.modl)) { - mp32bfree(&kp->q); + mpbfree(&kp->q); /*@-sizeoftype@*/ - memcpy(&kp->q, &r, sizeof(mp32barrett)); + memcpy(&kp->q, &r, sizeof(kp->q)); /*@=sizeoftype@*/ - mp32bzero(&r); + mpbzero(&r); newn = 1; } else { - mp32bfree(&r); + mpbfree(&r); newn = 0; } /*@=usedef =branchstate @*/ } - mp32bset(&kp->n, nsize, temp); + mpbset(&kp->n, nsize, temp); /* compute p-1 */ - mp32bsubone(&kp->p, temp); - mp32bset(&psubone, pqsize, temp); + mpbsubone(&kp->p, temp); + mpbset(&psubone, pqsize, temp); /* compute q-1 */ - mp32bsubone(&kp->q, temp); - mp32bset(&qsubone, pqsize, temp); + mpbsubone(&kp->q, temp); + mpbset(&qsubone, pqsize, temp); /*@-usedef@*/ /* psubone/qsubone are set */ /* compute phi = (p-1)*(q-1) */ mp32mul(temp, pqsize, psubone.modl, pqsize, qsubone.modl); - mp32bset(&phi, nsize, temp); + mpbset(&phi, nsize, temp); /* compute d = inv(e) mod phi */ mpnsize(&kp->d, nsize); - (void) mp32binv_w(&phi, kp->e.size, kp->e.data, kp->d.data, temp); + (void) mpbinv_w(&phi, kp->e.size, kp->e.data, kp->d.data, temp); /* compute d1 = d mod (p-1) */ mpnsize(&kp->d1, pqsize); - mp32bmod_w(&psubone, kp->d.data, kp->d1.data, temp); + mpbmod_w(&psubone, kp->d.data, kp->d1.data, temp); /* compute d2 = d mod (q-1) */ mpnsize(&kp->d2, pqsize); - mp32bmod_w(&qsubone, kp->d.data, kp->d2.data, temp); + mpbmod_w(&qsubone, kp->d.data, kp->d2.data, temp); /* compute c = inv(q) mod p */ mpnsize(&kp->c, pqsize); - (void) mp32binv_w(&kp->p, pqsize, kp->q.modl, kp->c.data, temp); + (void) mpbinv_w(&kp->p, pqsize, kp->q.modl, kp->c.data, temp); free(temp); /*@=usedef@*/ @@ -160,11 +160,11 @@ int rsakpInit(rsakp* kp) { memset(kp, 0, sizeof(*kp)); /* or - mp32bzero(&kp->n); + mpbzero(&kp->n); mpnzero(&kp->e); mpnzero(&kp->d); - mp32bzero(&kp->p); - mp32bzero(&kp->q); + mpbzero(&kp->p); + mpbzero(&kp->q); mpnzero(&kp->d1); mpnzero(&kp->d2); mpnzero(&kp->c); @@ -177,11 +177,11 @@ int rsakpInit(rsakp* kp) int rsakpFree(rsakp* kp) { /*@-usereleased -compdef @*/ /* kp->param.{n,p,q}.modl is OK */ - mp32bfree(&kp->n); + mpbfree(&kp->n); mpnfree(&kp->e); mpnfree(&kp->d); - mp32bfree(&kp->p); - mp32bfree(&kp->q); + mpbfree(&kp->p); + mpbfree(&kp->q); mpnfree(&kp->d1); mpnfree(&kp->d2); mpnfree(&kp->c); @@ -192,11 +192,11 @@ int rsakpFree(rsakp* kp) int rsakpCopy(rsakp* dst, const rsakp* src) { - mp32bcopy(&dst->n, &src->n); + mpbcopy(&dst->n, &src->n); mpncopy(&dst->e, &src->e); mpncopy(&dst->d, &src->d); - mp32bcopy(&dst->p, &src->p); - mp32bcopy(&dst->q, &src->q); + mpbcopy(&dst->p, &src->p); + mpbcopy(&dst->q, &src->q); mpncopy(&dst->d1, &src->d1); mpncopy(&dst->d2, &src->d2); mpncopy(&dst->c, &src->c); diff --git a/beecrypt/rsakp.h b/beecrypt/rsakp.h index 0f2dcec28..ad0a8cd3e 100644 --- a/beecrypt/rsakp.h +++ b/beecrypt/rsakp.h @@ -34,11 +34,11 @@ typedef struct { - mp32barrett n; + mpbarrett n; mpnumber e; mpnumber d; - mp32barrett p; - mp32barrett q; + mpbarrett p; + mpbarrett q; mpnumber d1; mpnumber d2; mpnumber c; diff --git a/beecrypt/rsapk.c b/beecrypt/rsapk.c index 39685097f..155299a0d 100644 --- a/beecrypt/rsapk.c +++ b/beecrypt/rsapk.c @@ -36,7 +36,7 @@ int rsapkInit(rsapk* pk) { memset(pk, 0, sizeof(*pk)); /* or - mp32bzero(&pk->n); + mpbzero(&pk->n); mpnzero(&pk->e); */ @@ -47,7 +47,7 @@ int rsapkInit(rsapk* pk) int rsapkFree(rsapk* pk) { /*@-usereleased -compdef @*/ /* pk->n.modl is OK */ - mp32bfree(&pk->n); + mpbfree(&pk->n); mpnfree(&pk->e); return 0; @@ -56,7 +56,7 @@ int rsapkFree(rsapk* pk) int rsapkCopy(rsapk* dst, const rsapk* src) { - mp32bcopy(&dst->n, &src->n); + mpbcopy(&dst->n, &src->n); mpncopy(&dst->e, &src->e); return 0; diff --git a/beecrypt/rsapk.h b/beecrypt/rsapk.h index 682146b4c..e4d71c453 100644 --- a/beecrypt/rsapk.h +++ b/beecrypt/rsapk.h @@ -34,7 +34,7 @@ */ typedef struct { - mp32barrett n; + mpbarrett n; mpnumber e; } rsapk; diff --git a/beecrypt/tests/beetest.c b/beecrypt/tests/beetest.c index f57fb29ed..547696779 100644 --- a/beecrypt/tests/beetest.c +++ b/beecrypt/tests/beetest.c @@ -30,7 +30,7 @@ #include "blockmode.h" #include "aes.h" #include "blowfish.h" -#include "mp32barrett.h" +#include "mpbarrett.h" #include "dhaes.h" #include "dlkp.h" #include "dsa.h" @@ -75,9 +75,9 @@ static int testVectorInvMod(const dlkp_p* keypair) register uint32* temp = (uint32*) malloc((13*size+11) * sizeof(uint32)); /*@-nullpass -nullptrarith @*/ /* temp may be NULL */ - mp32brndinv_w(&keypair->param.n, &rngc, temp, temp+size, temp+2*size); + mpbrndinv_w(&keypair->param.n, &rngc, temp, temp+size, temp+2*size); - mp32bmulmod_w(&keypair->param.n, size, temp, size, temp+size, temp, temp+2*size); + mpbmulmod_w(&keypair->param.n, size, temp, size, temp+size, temp, temp+2*size); rc = mp32isone(size, temp); @@ -102,7 +102,7 @@ static int testVectorExpMod(const dlkp_p* keypair) mpnzero(&y); - mp32bnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y); + mpbnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y); rc = mp32eqx(y.size, y.data, keypair->y.size, keypair->y.data); @@ -320,7 +320,7 @@ static int testVectorRSA(void) mpnzero(&digest); mpnzero(&s); - mp32bnrnd(&kp.n, &rngc, &digest); + mpbnrnd(&kp.n, &rngc, &digest); (void) rsapri(&kp, &digest, &s); @@ -363,7 +363,7 @@ static int testVectorDLDP(void) (void) dldp_pgoqMake(&dp, &rc, 768 >> 5, 512 >> 5, 1); /* we have the parameters, now see if g^q == 1 */ - mp32bnpowmod(&dp.p, &dp.g, (mpnumber*) &dp.q, &gq); + mpbnpowmod(&dp.p, &dp.g, (mpnumber*) &dp.q, &gq); result = mp32isone(gq.size, gq.data); mpnfree(&gq); @@ -658,7 +658,7 @@ static void testExpMods(void) randomGeneratorContext rngc; - mp32barrett p; + mpbarrett p; mpnumber tmp; mpnumber g; mpnumber x; @@ -666,7 +666,7 @@ static void testExpMods(void) memset(&rngc, 0, sizeof(randomGeneratorContext)); - mp32bzero(&p); + mpbzero(&p); mpnzero(&g); mpnzero(&x); mpnzero(&y); @@ -685,16 +685,16 @@ static void testExpMods(void) fprintf(stdout, "Timing modular exponentiations\n"); fprintf(stdout, " (%4d bits ^ %4d bits) mod %4d bits:", 512, 512, 512); mpnsethex(&tmp, p_512); - mp32bset(&p, tmp.size, tmp.data); + mpbset(&p, tmp.size, tmp.data); mpnsize(&g, p.size); mpnsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpbnrnd(&p, &rngc, &g); + mpbnrnd(&p, &rngc, &x); #if HAVE_TIME_H tstart = clock(); #endif for (i = 0; i < 100; i++) - mp32bnpowmod(&p, &g, &x, &y); + mpbnpowmod(&p, &g, &x, &y); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -702,16 +702,16 @@ static void testExpMods(void) #endif fprintf(stdout, " (%4d bits ^ %4d bits) mod %4d bits:", 768, 768, 768); mpnsethex(&tmp, p_768); - mp32bset(&p, tmp.size, tmp.data); + mpbset(&p, tmp.size, tmp.data); mpnsize(&g, p.size); mpnsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpbnrnd(&p, &rngc, &g); + mpbnrnd(&p, &rngc, &x); #if HAVE_TIME_H tstart = clock(); #endif for (i = 0; i < 100; i++) - mp32bnpowmod(&p, &g, &x, &y); + mpbnpowmod(&p, &g, &x, &y); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -719,16 +719,16 @@ static void testExpMods(void) #endif fprintf(stdout, " (%4d bits ^ %4d bits) mod %4d bits:", 1024, 1024, 1024); mpnsethex(&tmp, p_1024); - mp32bset(&p, tmp.size, tmp.data); + mpbset(&p, tmp.size, tmp.data); mpnsize(&g, p.size); mpnsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpbnrnd(&p, &rngc, &g); + mpbnrnd(&p, &rngc, &x); #if HAVE_TIME_H tstart = clock(); #endif for (i = 0; i < 100; i++) - mp32bnpowmod(&p, &g, &x, &y); + mpbnpowmod(&p, &g, &x, &y); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -744,13 +744,13 @@ static void testExpMods(void) tstart = clock(); #endif for (i = 0; i < 100; i++) - mp32bnpowmod(&p, &g, &x, &y); + mpbnpowmod(&p, &g, &x, &y); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; fprintf(stdout, " 100x in %.3f seconds\n", ttime); #endif - mp32bfree(&p); + mpbfree(&p); mpnfree(&g); mpnfree(&x); mpnfree(&y); @@ -976,10 +976,10 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[]) dlkp_pInit(&keypair); - mp32bsethex(&keypair.param.p, dsa_p); - mp32bsethex(&keypair.param.q, dsa_q); + mpbsethex(&keypair.param.p, dsa_p); + mpbsethex(&keypair.param.q, dsa_q); mpnsethex(&keypair.param.g, dsa_g); - mp32bsethex(&keypair.param.n, elg_n); + mpbsethex(&keypair.param.n, elg_n); mpnsethex(&keypair.y, dsa_y); mpnsethex(&keypair.x, dsa_x); @@ -1124,10 +1124,10 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[]) memset(&keypair, 0, sizeof(dlkp_p)); (void) dlkp_pInit(&keypair); - mp32bsethex(&keypair.param.p, dsa_p); - mp32bsethex(&keypair.param.q, dsa_q); + mpbsethex(&keypair.param.p, dsa_p); + mpbsethex(&keypair.param.q, dsa_q); mpnsethex(&keypair.param.g, dsa_g); - mp32bsethex(&keypair.param.n, elg_n); + mpbsethex(&keypair.param.n, elg_n); mpnsethex(&keypair.y, dsa_y); mpnsethex(&keypair.x, dsa_x); diff --git a/beecrypt/tests/testdldp.c b/beecrypt/tests/testdldp.c index f032e0e8c..8c0938e70 100644 --- a/beecrypt/tests/testdldp.c +++ b/beecrypt/tests/testdldp.c @@ -47,7 +47,7 @@ int main() dldp_pgoqMake(¶ms, &rngc, 512 >> 5, 160 >> 5, 1); /* we have the parameters, now see if g^q == 1 */ - mp32bnpowmod(¶ms.p, ¶ms.g, (mpnumber*) ¶ms.q, &gq); + mpbnpowmod(¶ms.p, ¶ms.g, (mpnumber*) ¶ms.q, &gq); if (mp32isone(gq.size, gq.data)) printf("ok\n"); else diff --git a/beecrypt/tests/testdsa.c b/beecrypt/tests/testdsa.c index 918ab7170..c40152232 100644 --- a/beecrypt/tests/testdsa.c +++ b/beecrypt/tests/testdsa.c @@ -85,8 +85,8 @@ int main() dlkp_pInit(&keypair); - mp32bsethex(&keypair.param.p, dsa_p); - mp32bsethex(&keypair.param.q, dsa_q); + mpbsethex(&keypair.param.p, dsa_p); + mpbsethex(&keypair.param.q, dsa_q); mpnsethex(&keypair.param.g, dsa_g); mpnsethex(&keypair.y, dsa_y); mpnsethex(&keypair.x, dsa_x); |