diff options
-rw-r--r-- | beecrypt/beecrypt.c | 36 | ||||
-rw-r--r-- | beecrypt/beecrypt.h | 12 | ||||
-rw-r--r-- | beecrypt/beetest.c | 112 | ||||
-rw-r--r-- | beecrypt/dhaes.c | 46 | ||||
-rw-r--r-- | beecrypt/dhaes.h | 12 | ||||
-rw-r--r-- | beecrypt/dldp.c | 40 | ||||
-rw-r--r-- | beecrypt/dldp.h | 10 | ||||
-rw-r--r-- | beecrypt/dlkp.c | 12 | ||||
-rw-r--r-- | beecrypt/dlkp.h | 4 | ||||
-rw-r--r-- | beecrypt/dlpk.c | 6 | ||||
-rw-r--r-- | beecrypt/dlpk.h | 2 | ||||
-rw-r--r-- | beecrypt/dlsvdp-dh.c | 2 | ||||
-rw-r--r-- | beecrypt/dlsvdp-dh.h | 2 | ||||
-rw-r--r-- | beecrypt/dsa.c | 12 | ||||
-rw-r--r-- | beecrypt/dsa.h | 4 | ||||
-rw-r--r-- | beecrypt/elgamal.c | 24 | ||||
-rw-r--r-- | beecrypt/elgamal.h | 8 | ||||
-rw-r--r-- | beecrypt/mp.h | 44 | ||||
-rw-r--r-- | beecrypt/mpbarrett.c | 30 | ||||
-rw-r--r-- | beecrypt/mpbarrett.h | 20 | ||||
-rw-r--r-- | beecrypt/mpnumber.c | 70 | ||||
-rw-r--r-- | beecrypt/mpnumber.h | 24 | ||||
-rw-r--r-- | beecrypt/mpprime.c | 10 | ||||
-rw-r--r-- | beecrypt/mpprime.h | 6 | ||||
-rw-r--r-- | beecrypt/rsa.c | 10 | ||||
-rw-r--r-- | beecrypt/rsa.h | 6 | ||||
-rw-r--r-- | beecrypt/rsakp.c | 40 | ||||
-rw-r--r-- | beecrypt/rsakp.h | 10 | ||||
-rw-r--r-- | beecrypt/rsapk.c | 6 | ||||
-rw-r--r-- | beecrypt/rsapk.h | 2 | ||||
-rw-r--r-- | beecrypt/tests/beetest.c | 158 | ||||
-rw-r--r-- | beecrypt/tests/testdldp.c | 8 | ||||
-rw-r--r-- | beecrypt/tests/testdsa.c | 38 |
33 files changed, 390 insertions, 436 deletions
diff --git a/beecrypt/beecrypt.c b/beecrypt/beecrypt.c index 4cb6389b9..6e0c6ad4e 100644 --- a/beecrypt/beecrypt.c +++ b/beecrypt/beecrypt.c @@ -405,7 +405,7 @@ int hashFunctionContextUpdateMC(hashFunctionContext* ctxt, const memchunk* m) } /*@-boundswrite@*/ -int hashFunctionContextUpdateMP32(hashFunctionContext* ctxt, const mp32number* n) +int hashFunctionContextUpdateMP32(hashFunctionContext* ctxt, const mpnumber* n) { if (ctxt == (hashFunctionContext*) 0) return -1; @@ -416,7 +416,7 @@ int hashFunctionContextUpdateMP32(hashFunctionContext* ctxt, const mp32number* n if (ctxt->param == (hashFunctionParam*) 0) return -1; - if (n != (mp32number*) 0) + if (n != (mpnumber*) 0) { register int rc = -1; register byte* temp = (byte*) malloc((n->size << 2) + 1); @@ -442,7 +442,7 @@ int hashFunctionContextUpdateMP32(hashFunctionContext* ctxt, const mp32number* n } /*@=boundswrite@*/ -int hashFunctionContextDigest(hashFunctionContext* ctxt, mp32number* dig) +int hashFunctionContextDigest(hashFunctionContext* ctxt, mpnumber* dig) { if (ctxt == (hashFunctionContext*) 0) return -1; @@ -453,28 +453,28 @@ int hashFunctionContextDigest(hashFunctionContext* ctxt, mp32number* dig) if (ctxt->param == (hashFunctionParam*) 0) return -1; - if (dig != (mp32number*) 0) + if (dig != (mpnumber*) 0) { - mp32nsize(dig, (ctxt->algo->digestsize + 3) >> 2); + mpnsize(dig, (ctxt->algo->digestsize + 3) >> 2); return ctxt->algo->digest(ctxt->param, dig->data); } return -1; } -int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mp32number* match) +int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mpnumber* match) { register int rc = 0; - mp32number dig; + mpnumber dig; - mp32nzero(&dig); + mpnzero(&dig); if (hashFunctionContextDigest(ctxt, &dig) == 0) if (dig.size == match->size) rc = mp32eq(dig.size, dig.data, match->data); - mp32nfree(&dig); + mpnfree(&dig); /*@-mustfree@*/ /* dig.data is OK */ return rc; @@ -647,7 +647,7 @@ int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext* ctxt, const memch } /*@-boundswrite@*/ -int keyedHashFunctionContextUpdateMP32(keyedHashFunctionContext* ctxt, const mp32number* n) +int keyedHashFunctionContextUpdateMP32(keyedHashFunctionContext* ctxt, const mpnumber* n) { if (ctxt == (keyedHashFunctionContext*) 0) return -1; @@ -658,7 +658,7 @@ int keyedHashFunctionContextUpdateMP32(keyedHashFunctionContext* ctxt, const mp3 if (ctxt->param == (keyedHashFunctionParam*) 0) return -1; - if (n != (mp32number*) 0) + if (n != (mpnumber*) 0) { register int rc; register byte* temp = (byte*) malloc((n->size << 2) + 1); @@ -684,7 +684,7 @@ int keyedHashFunctionContextUpdateMP32(keyedHashFunctionContext* ctxt, const mp3 } /*@=boundswrite@*/ -int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, mp32number* dig) +int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, mpnumber* dig) { if (ctxt == (keyedHashFunctionContext*) 0) return -1; @@ -695,29 +695,29 @@ int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, mp32number* d if (ctxt->param == (keyedHashFunctionParam*) 0) return -1; - if (dig != (mp32number*) 0) + if (dig != (mpnumber*) 0) { - mp32nsize(dig, (ctxt->algo->digestsize + 3) >> 2); + mpnsize(dig, (ctxt->algo->digestsize + 3) >> 2); return ctxt->algo->digest(ctxt->param, dig->data); } return -1; } -int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mp32number* match) +int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mpnumber* match) { register int rc = 0; - mp32number dig; + mpnumber dig; - mp32nzero(&dig); + mpnzero(&dig); if (keyedHashFunctionContextDigest(ctxt, &dig) == 0) if (dig.size == match->size) rc = mp32eq(dig.size, dig.data, match->data); - mp32nfree(&dig); + mpnfree(&dig); /*@-mustfree@*/ /* dig.data is OK */ return rc; diff --git a/beecrypt/beecrypt.h b/beecrypt/beecrypt.h index bdb050595..b89652287 100644 --- a/beecrypt/beecrypt.h +++ b/beecrypt/beecrypt.h @@ -433,19 +433,19 @@ int hashFunctionContextUpdateMC(hashFunctionContext* ctxt, const memchunk* m) /** \ingroup HASH_m */ BEECRYPTAPI -int hashFunctionContextUpdateMP32(hashFunctionContext* ctxt, const mp32number* n) +int hashFunctionContextUpdateMP32(hashFunctionContext* ctxt, const mpnumber* n) /*@modifies ctxt */; /** \ingroup HASH_m */ BEECRYPTAPI -int hashFunctionContextDigest(hashFunctionContext* ctxt, mp32number* dig) +int hashFunctionContextDigest(hashFunctionContext* ctxt, mpnumber* dig) /*@modifies ctxt, *dig */; /** \ingroup HASH_m */ BEECRYPTAPI /*@unused@*/ -int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mp32number* match) +int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mpnumber* match) /*@modifies ctxt */; #ifdef __cplusplus @@ -636,19 +636,19 @@ int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext* ctxt, const memch /** \ingroup HMAC_m */ BEECRYPTAPI /*@unused@*/ -int keyedHashFunctionContextUpdateMP32(keyedHashFunctionContext* ctxt, const mp32number* n) +int keyedHashFunctionContextUpdateMP32(keyedHashFunctionContext* ctxt, const mpnumber* n) /*@modifies ctxt @*/; /** \ingroup HMAC_m */ BEECRYPTAPI -int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, mp32number* dig) +int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, mpnumber* dig) /*@modifies ctxt, *dig @*/; /** \ingroup HMAC_m */ BEECRYPTAPI -int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mp32number* match) +int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mpnumber* match) /*@modifies ctxt @*/; #ifdef __cplusplus diff --git a/beecrypt/beetest.c b/beecrypt/beetest.c index ad0bc829c..dd1729bfe 100644 --- a/beecrypt/beetest.c +++ b/beecrypt/beetest.c @@ -74,15 +74,15 @@ int testVectorInvMod(const dlkp_p* keypair) int testVectorExpMod(const dlkp_p* keypair) { int rc; - mp32number y; + mpnumber y; - mp32nzero(&y); + mpnzero(&y); mp32bnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y); rc = mp32eqx(y.size, y.data, keypair->y.size, keypair->y.data); - mp32nfree(&y); + mpnfree(&y); return rc; } @@ -95,13 +95,13 @@ int testVectorElGamalV1(const dlkp_p* keypair) if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) { - mp32number digest, r, s; + mpnumber digest, r, s; - mp32nzero(&digest); - mp32nzero(&r); - mp32nzero(&s); + mpnzero(&digest); + mpnzero(&r); + mpnzero(&s); - mp32nsize(&digest, 5); + mpnsize(&digest, 5); rngc.rng->next(rngc.param, digest.data, digest.size); @@ -109,9 +109,9 @@ int testVectorElGamalV1(const dlkp_p* keypair) rc = elgv1vrfy(&keypair->param.p, &keypair->param.n, &keypair->param.g, &digest, &keypair->y, &r, &s); - mp32nfree(&digest); - mp32nfree(&r); - mp32nfree(&s); + mpnfree(&digest); + mpnfree(&r); + mpnfree(&s); randomGeneratorContextFree(&rngc); } @@ -126,13 +126,13 @@ int testVectorElGamalV3(const dlkp_p* keypair) if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) { - mp32number digest, r, s; + mpnumber digest, r, s; - mp32nzero(&digest); - mp32nzero(&r); - mp32nzero(&s); + mpnzero(&digest); + mpnzero(&r); + mpnzero(&s); - mp32nsize(&digest, 5); + mpnsize(&digest, 5); rngc.rng->next(rngc.param, digest.data, digest.size); @@ -140,9 +140,9 @@ int testVectorElGamalV3(const dlkp_p* keypair) rc = elgv3vrfy(&keypair->param.p, &keypair->param.n, &keypair->param.g, &digest, &keypair->y, &r, &s); - mp32nfree(&digest); - mp32nfree(&r); - mp32nfree(&s); + mpnfree(&digest); + mpnfree(&r); + mpnfree(&s); randomGeneratorContextFree(&rngc); } @@ -160,7 +160,7 @@ int testVectorDHAES(const dlkp_p* keypair) /* incomplete */ if (dhaes_pInit(&dh, &keypair->param, &blowfish, &hmacmd5, &md5, randomGeneratorDefault()) == 0) { - mp32number mkey, mac; + mpnumber mkey, mac; memchunk src, *dst, *cmp; @@ -170,8 +170,8 @@ int testVectorDHAES(const dlkp_p* keypair) memset(src.data, 1, src.size); /* initialize the message key and mac */ - mp32nzero(&mkey); - mp32nzero(&mac); + mpnzero(&mkey); + mpnzero(&mac); /* encrypt the message */ dst = dhaes_pEncrypt(&dh, &keypair->y, &mkey, &mac, &src); @@ -211,15 +211,15 @@ int testVectorRSA() if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) { rsakp kp; - mp32number digest, s; + mpnumber digest, s; rsakpInit(&kp); fprintf(stdout, "making RSA CRT keypair\n"); rsakpMake(&kp, &rngc, 32); fprintf(stdout, "RSA CRT keypair generated\n"); - mp32nzero(&digest); - mp32nzero(&s); + mpnzero(&digest); + mpnzero(&s); mp32bnrnd(&kp.n, &rngc, &digest); @@ -227,8 +227,8 @@ int testVectorRSA() rc = rsavrfy((rsapk*) &kp, &digest, &s); - mp32nfree(&digest); - mp32nfree(&s); + mpnfree(&digest); + mpnfree(&s); rsakpFree(&kp); @@ -250,17 +250,17 @@ int testVectorDLDP() if (randomGeneratorContextInit(&rc, randomGeneratorDefault()) == 0) { register int result; - mp32number gq; + mpnumber gq; - mp32nzero(&gq); + mpnzero(&gq); dldp_pgoqMake(&dp, &rc, 768 >> 5, 512 >> 5, 1); /* we have the parameters, now see if g^q == 1 */ - mp32bnpowmod(&dp.p, &dp.g, (mp32number*) &dp.q, &gq); + mp32bnpowmod(&dp.p, &dp.g, (mpnumber*) &dp.q, &gq); result = mp32isone(gq.size, gq.data); - mp32nfree(&gq); + mpnfree(&gq); dldp_pFree(&dp); randomGeneratorContextFree(&rc); @@ -510,16 +510,16 @@ void testExpMods() randomGeneratorContext rngc; mp32barrett p; - mp32number tmp; - mp32number g; - mp32number x; - mp32number y; + mpnumber tmp; + mpnumber g; + mpnumber x; + mpnumber y; mp32bzero(&p); - mp32nzero(&g); - mp32nzero(&x); - mp32nzero(&y); - mp32nzero(&tmp); + mpnzero(&g); + mpnzero(&x); + mpnzero(&y); + mpnzero(&tmp); if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) { @@ -531,10 +531,10 @@ void testExpMods() fprintf(stdout, "Timing modular exponentiations\n"); fprintf(stdout, "\t(512 bits ^ 512 bits) mod 512 bits:"); - mp32nsethex(&tmp, p_512); + mpnsethex(&tmp, p_512); mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); + mpnsize(&g, p.size); + mpnsize(&x, p.size); mp32bnrnd(&p, &rngc, &g); mp32bnrnd(&p, &rngc, &x); #if HAVE_TIME_H @@ -548,10 +548,10 @@ void testExpMods() fprintf(stdout, "\t 100x in %.3f seconds\n", ttime); #endif fprintf(stdout, "\t(768 bits ^ 768 bits) mod 768 bits:"); - mp32nsethex(&tmp, p_768); + mpnsethex(&tmp, p_768); mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); + mpnsize(&g, p.size); + mpnsize(&x, p.size); mp32bnrnd(&p, &rngc, &g); mp32bnrnd(&p, &rngc, &x); #if HAVE_TIME_H @@ -565,10 +565,10 @@ void testExpMods() fprintf(stdout, "\t 100x in %.3f seconds\n", ttime); #endif fprintf(stdout, "\t(1024 bits ^ 1024 bits) mod 1024 bits:"); - mp32nsethex(&tmp, p_1024); + mpnsethex(&tmp, p_1024); mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); + mpnsize(&g, p.size); + mpnsize(&x, p.size); mp32bnrnd(&p, &rngc, &g); mp32bnrnd(&p, &rngc, &x); #if HAVE_TIME_H @@ -582,7 +582,7 @@ void testExpMods() fprintf(stdout, "\t 100x in %.3f seconds\n", ttime); #endif /* now run a test with x having 160 bits */ - mp32nsize(&x, 5); + mpnsize(&x, 5); rngc.rng->next(rngc.param, x.data, x.size); fprintf(stdout, "\t(1024 bits ^ 160 bits) mod 1024 bits:"); #if HAVE_TIME_H @@ -596,10 +596,10 @@ void testExpMods() fprintf(stdout, "\t 100x in %.3f seconds\n", ttime); #endif mp32bfree(&p); - mp32nfree(&g); - mp32nfree(&x); - mp32nfree(&y); - mp32nfree(&tmp); + mpnfree(&g); + mpnfree(&x); + mpnfree(&y); + mpnfree(&tmp); randomGeneratorContextFree(&rngc); } @@ -679,10 +679,10 @@ int main() mp32bsethex(&keypair.param.p, dsa_p); mp32bsethex(&keypair.param.q, dsa_q); - mp32nsethex(&keypair.param.g, dsa_g); + mpnsethex(&keypair.param.g, dsa_g); mp32bsethex(&keypair.param.n, elg_n); - mp32nsethex(&keypair.y, dsa_y); - mp32nsethex(&keypair.x, dsa_x); + mpnsethex(&keypair.y, dsa_y); + mpnsethex(&keypair.x, dsa_x); if (testVectorInvMod(&keypair)) fprintf(stdout, "InvMod works!\n"); diff --git a/beecrypt/dhaes.c b/beecrypt/dhaes.c index 4a31736a1..71b06b015 100644 --- a/beecrypt/dhaes.c +++ b/beecrypt/dhaes.c @@ -122,8 +122,8 @@ int dhaes_pContextInit(dhaes_pContext* ctxt, const dhaes_pParameters* params) (void) dldp_pInit(&ctxt->param); (void) dldp_pCopy(&ctxt->param, params->param); - mp32nzero(&ctxt->pub); - mp32nzero(&ctxt->pri); + mpnzero(&ctxt->pub); + mpnzero(&ctxt->pri); /*@-modobserver@*/ if (hashFunctionContextInit(&ctxt->hash, params->hash)) @@ -142,22 +142,22 @@ int dhaes_pContextInit(dhaes_pContext* ctxt, const dhaes_pParameters* params) return 0; } -int dhaes_pContextInitDecrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mp32number* pri) +int dhaes_pContextInitDecrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mpnumber* pri) { if (dhaes_pContextInit(ctxt, params)) return -1; - mp32ncopy(&ctxt->pri, pri); + mpncopy(&ctxt->pri, pri); return 0; } -int dhaes_pContextInitEncrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mp32number* pub) +int dhaes_pContextInitEncrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mpnumber* pub) { if (dhaes_pContextInit(ctxt, params)) return -1; - mp32ncopy(&ctxt->pub, pub); + mpncopy(&ctxt->pub, pub); return 0; } @@ -166,8 +166,8 @@ int dhaes_pContextFree(dhaes_pContext* ctxt) { (void) dldp_pFree(&ctxt->param); - mp32nfree(&ctxt->pub); - mp32nfree(&ctxt->pri); + mpnfree(&ctxt->pub); + mpnfree(&ctxt->pri); /*@-mustfree -modobserver @*/ /* ctxt is OK */ if (hashFunctionContextFree(&ctxt->hash)) @@ -185,31 +185,31 @@ int dhaes_pContextFree(dhaes_pContext* ctxt) /** */ -static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mp32number* privkey, const mp32number* pubkey, const mp32number* message, cipherOperation op) +static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mpnumber* privkey, const mpnumber* pubkey, const mpnumber* message, cipherOperation op) /*@modifies ctxt @*/ { register int rc; - mp32number secret; - mp32number digest; + mpnumber secret; + mpnumber digest; /* compute the shared secret, Diffie-Hellman style */ - mp32nzero(&secret); + mpnzero(&secret); if (dlsvdp_pDHSecret(&ctxt->param, privkey, pubkey, &secret)) /*@-mustfree@*/ /* FIX: secret.data leak? */ return -1; /*@=mustfree@*/ /* compute the hash of the message (ephemeral public) key and the shared secret */ - mp32nzero(&digest); + mpnzero(&digest); (void) hashFunctionContextReset (&ctxt->hash); (void) hashFunctionContextUpdateMP32(&ctxt->hash, message); (void) hashFunctionContextUpdateMP32(&ctxt->hash, &secret); (void) hashFunctionContextDigest (&ctxt->hash, &digest); /* we don't need the secret anymore */ - mp32nwipe(&secret); - mp32nfree(&secret); + mpnwipe(&secret); + mpnfree(&secret); /** * NOTE: blockciphers and keyed hash functions take keys with sizes @@ -241,23 +241,23 @@ static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mp32number* privkey, /*@=usedef@*/ setup_end: - mp32nwipe(&digest); - mp32nfree(&digest); + mpnwipe(&digest); + mpnfree(&digest); /*@-mustfree@*/ /* {secret,digest}.data are OK */ return rc; /*@=mustfree@*/ } -memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mp32number* ephemeralPublicKey, mp32number* mac, const memchunk* cleartext, randomGeneratorContext* rng) +memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mpnumber* ephemeralPublicKey, mpnumber* mac, const memchunk* cleartext, randomGeneratorContext* rng) { memchunk* ciphertext = (memchunk*) 0; memchunk* paddedtext; - mp32number ephemeralPrivateKey; + mpnumber ephemeralPrivateKey; /* make the ephemeral keypair */ - mp32nzero(&ephemeralPrivateKey); + mpnzero(&ephemeralPrivateKey); (void) dldp_pPair(&ctxt->param, rng, &ephemeralPrivateKey, ephemeralPublicKey); /* Setup the key and initialize the mac and the blockcipher */ @@ -295,15 +295,15 @@ memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mp32number* ephemeralPubli ciphertext = paddedtext; encrypt_end: - mp32nwipe(&ephemeralPrivateKey); - mp32nfree(&ephemeralPrivateKey); + mpnwipe(&ephemeralPrivateKey); + mpnfree(&ephemeralPrivateKey); /*@-mustfree@*/ /* ephemeralPrivateKey.data is OK */ return ciphertext; /*@=mustfree@*/ } -memchunk* dhaes_pContextDecrypt(dhaes_pContext* ctxt, const mp32number* ephemeralPublicKey, const mp32number* mac, const memchunk* ciphertext) +memchunk* dhaes_pContextDecrypt(dhaes_pContext* ctxt, const mpnumber* ephemeralPublicKey, const mpnumber* mac, const memchunk* ciphertext) { memchunk* cleartext = (memchunk*) 0; memchunk* paddedtext; diff --git a/beecrypt/dhaes.h b/beecrypt/dhaes.h index 8d2df4290..ed6eaa496 100644 --- a/beecrypt/dhaes.h +++ b/beecrypt/dhaes.h @@ -48,8 +48,8 @@ typedef struct typedef struct { dldp_p param; - mp32number pub; - mp32number pri; + mpnumber pub; + mpnumber pri; hashFunctionContext hash; blockCipherContext cipher; keyedHashFunctionContext mac; @@ -80,13 +80,13 @@ int dhaes_pContextInit (dhaes_pContext* ctxt, const dhaes_pParameters* par /** */ BEECRYPTAPI /*@unused@*/ -int dhaes_pContextInitDecrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mp32number* pri) +int dhaes_pContextInitDecrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mpnumber* pri) /*@modifies ctxt */; /** */ BEECRYPTAPI /*@unused@*/ -int dhaes_pContextInitEncrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mp32number* pub) +int dhaes_pContextInitEncrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mpnumber* pub) /*@modifies ctxt */; /** @@ -98,13 +98,13 @@ int dhaes_pContextFree (/*@only@*/ dhaes_pContext* ctxt) /** */ BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mp32number* ephemeralPublicKey, mp32number* mac, const memchunk* cleartext, randomGeneratorContext* rng) +memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mpnumber* ephemeralPublicKey, mpnumber* mac, const memchunk* cleartext, randomGeneratorContext* rng) /*@modifies ctxt, ephemeralPublicKey, mac, rng */; /** */ BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -memchunk* dhaes_pContextDecrypt(dhaes_pContext* ctxt, const mp32number* ephemeralPublicKey, const mp32number* mac, const memchunk* ciphertext) +memchunk* dhaes_pContextDecrypt(dhaes_pContext* ctxt, const mpnumber* ephemeralPublicKey, const mpnumber* mac, const memchunk* ciphertext) /*@modifies ctxt */; #ifdef __cplusplus diff --git a/beecrypt/dldp.c b/beecrypt/dldp.c index e315949c5..57ebc004e 100644 --- a/beecrypt/dldp.c +++ b/beecrypt/dldp.c @@ -43,7 +43,7 @@ static int dldp_pgoqGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, /*@out@ static int dldp_pgonGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, /*@out@*/ uint32* wksp) /*@modifies dp->g, wksp @*/; -int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mp32number* x) +int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x) { /* * Note: the private key is randomly selected to be smaller than q @@ -56,7 +56,7 @@ int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mp32number* x) return 0; } -int dldp_pPublic(const dldp_p* dp, const mp32number* x, mp32number* y) +int dldp_pPublic(const dldp_p* dp, const mpnumber* x, mpnumber* y) { /* * Public key y is computed as g^x mod p @@ -67,7 +67,7 @@ int dldp_pPublic(const dldp_p* dp, const mp32number* x, mp32number* y) return 0; } -int dldp_pPair(const dldp_p* dp, randomGeneratorContext* rgc, mp32number* x, mp32number* y) +int dldp_pPair(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x, mpnumber* y) { /* * Combination of the two previous functions @@ -141,8 +141,8 @@ int dldp_pInit(dldp_p* dp) { mp32bzero(&dp->p); mp32bzero(&dp->q); - mp32nzero(&dp->g); - mp32nzero(&dp->r); + mpnzero(&dp->g); + mpnzero(&dp->r); mp32bzero(&dp->n); return 0; @@ -153,8 +153,8 @@ int dldp_pFree(dldp_p* dp) /*@-usedef -compdef@*/ mp32bfree(&dp->p); mp32bfree(&dp->q); - mp32nfree(&dp->g); - mp32nfree(&dp->r); + mpnfree(&dp->g); + mpnfree(&dp->r); mp32bfree(&dp->n); /*@=usedef =compdef@*/ @@ -165,8 +165,8 @@ int dldp_pCopy(dldp_p* dst, const dldp_p* src) { mp32bcopy(&dst->p, &src->p); mp32bcopy(&dst->q, &src->q); - mp32ncopy(&dst->r, &src->r); - mp32ncopy(&dst->g, &src->g); + mpncopy(&dst->r, &src->r); + mpncopy(&dst->g, &src->g); mp32bcopy(&dst->n, &src->n); return 0; @@ -184,19 +184,19 @@ int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, uint32 psize, uint32 { /* first generate q */ /*@-globs@*/ - mp32prnd_w(&dp->q, rgc, qsize, mp32ptrials(qsize << 5), (const mp32number*) 0, temp); + mp32prnd_w(&dp->q, rgc, qsize, mp32ptrials(qsize << 5), (const mpnumber*) 0, temp); /*@=globs@*/ /* generate p with the appropriate congruences */ /*@-globs@*/ - mp32prndconone_w(&dp->p, rgc, psize, mp32ptrials(psize << 5), &dp->q, (const mp32number*) 0, &dp->r, cofactor, temp); + mp32prndconone_w(&dp->p, rgc, psize, mp32ptrials(psize << 5), &dp->q, (const mpnumber*) 0, &dp->r, cofactor, temp); /*@=globs@*/ /* clear n */ mp32bzero(&dp->n); /* clear g */ - mp32nzero(&dp->g); + mpnzero(&dp->g); (void) dldp_pgoqGenerator_w(dp, rgc, temp); @@ -230,7 +230,7 @@ int dldp_pgoqMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, uint32 psize) mp32bset(&dp->q, psize, temp); /* set r = 2 */ - mp32nsetw(&dp->r, 2); + mpnsetw(&dp->r, 2); /* clear n */ mp32bzero(&dp->n); @@ -253,8 +253,8 @@ int dldp_pgoqGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, uint32* wksp) register uint32 size = dp->p.size; - mp32nfree(&dp->g); - mp32nsize(&dp->g, size); + mpnfree(&dp->g); + mpnsize(&dp->g, size); while (1) { @@ -316,12 +316,12 @@ int dldp_pgonMake(dldp_p* dp, randomGeneratorContext* rgc, uint32 psize, uint32 { /* generate q */ /*@-globs@*/ - mp32prnd_w(&dp->q, rgc, qsize, mp32ptrials(qsize << 5), (const mp32number*) 0, temp); + mp32prnd_w(&dp->q, rgc, qsize, mp32ptrials(qsize << 5), (const mpnumber*) 0, temp); /*@=globs@*/ /* generate p with the appropriate congruences */ /*@-globs@*/ - mp32prndconone_w(&dp->p, rgc, psize, mp32ptrials(psize << 5), &dp->q, (const mp32number*) 0, &dp->r, 2, temp); + mp32prndconone_w(&dp->p, rgc, psize, mp32ptrials(psize << 5), &dp->q, (const mpnumber*) 0, &dp->r, 2, temp); /*@=globs@*/ /* set n */ @@ -362,7 +362,7 @@ int dldp_pgonMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, uint32 psize) mp32bset(&dp->q, psize, temp); /* set r = 2 */ - mp32nsetw(&dp->r, 2); + mpnsetw(&dp->r, 2); (void) dldp_pgonGenerator_w(dp, rgc, temp); @@ -377,8 +377,8 @@ int dldp_pgonGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, uint32* wksp) { register uint32 size = dp->p.size; - mp32nfree(&dp->g); - mp32nsize(&dp->g, size); + mpnfree(&dp->g); + mpnsize(&dp->g, size); while (1) { diff --git a/beecrypt/dldp.h b/beecrypt/dldp.h index ce2a5e049..0b9c96cd2 100644 --- a/beecrypt/dldp.h +++ b/beecrypt/dldp.h @@ -52,8 +52,8 @@ typedef struct { mp32barrett p; mp32barrett q; - mp32number r; - mp32number g; + mpnumber r; + mpnumber g; mp32barrett n; } dldp_p; @@ -87,19 +87,19 @@ int dldp_pCopy(dldp_p* dst, const dldp_p* src) /** */ BEECRYPTAPI /*@unused@*/ -int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mp32number* x) +int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x) /*@modifies rgc, x @*/; /** */ BEECRYPTAPI /*@unused@*/ -int dldp_pPublic(const dldp_p* dp, const mp32number* x, mp32number* y) +int dldp_pPublic(const dldp_p* dp, const mpnumber* x, mpnumber* y) /*@modifies y @*/; /** */ BEECRYPTAPI -int dldp_pPair(const dldp_p* dp, randomGeneratorContext* rgc, mp32number* x, mp32number* y) +int dldp_pPair(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x, mpnumber* y) /*@modifies rgc, x, y @*/; /* diff --git a/beecrypt/dlkp.c b/beecrypt/dlkp.c index 0d29d0d34..e8e1dd720 100644 --- a/beecrypt/dlkp.c +++ b/beecrypt/dlkp.c @@ -48,8 +48,8 @@ int dlkp_pInit(dlkp_p* kp) if (dldp_pInit(&kp->param) < 0) return -1; - mp32nzero(&kp->y); - mp32nzero(&kp->x); + mpnzero(&kp->y); + mpnzero(&kp->x); return 0; } @@ -60,8 +60,8 @@ int dlkp_pFree(dlkp_p* kp) if (dldp_pFree(&kp->param) < 0) return -1; - mp32nfree(&kp->y); - mp32nfree(&kp->x); + mpnfree(&kp->y); + mpnfree(&kp->x); return 0; /*@=usereleased =compdef @*/ @@ -72,8 +72,8 @@ int dlkp_pCopy(dlkp_p* dst, const dlkp_p* src) if (dldp_pCopy(&dst->param, &src->param) < 0) return -1; - mp32ncopy(&dst->y, &src->y); - mp32ncopy(&dst->x, &src->x); + mpncopy(&dst->y, &src->y); + mpncopy(&dst->x, &src->x); return 0; } diff --git a/beecrypt/dlkp.h b/beecrypt/dlkp.h index e2929bfdf..5336b268a 100644 --- a/beecrypt/dlkp.h +++ b/beecrypt/dlkp.h @@ -37,8 +37,8 @@ typedef struct { dldp_p param; - mp32number y; - mp32number x; + mpnumber y; + mpnumber x; } dlkp_p; #ifdef __cplusplus diff --git a/beecrypt/dlpk.c b/beecrypt/dlpk.c index 4453befab..fb1635f2c 100644 --- a/beecrypt/dlpk.c +++ b/beecrypt/dlpk.c @@ -35,7 +35,7 @@ int dlpk_pInit(dlpk_p* pk) if (dldp_pInit(&pk->param) < 0) return -1; - mp32nzero(&pk->y); + mpnzero(&pk->y); return 0; } @@ -46,7 +46,7 @@ int dlpk_pFree(dlpk_p* pk) if (dldp_pFree(&pk->param) < 0) return -1; - mp32nfree(&pk->y); + mpnfree(&pk->y); return 0; /*@=usereleased =compdef @*/ @@ -57,7 +57,7 @@ int dlpk_pCopy(dlpk_p* dst, const dlpk_p* src) if (dldp_pCopy(&dst->param, &src->param) < 0) return -1; - mp32ncopy(&dst->y, &src->y); + mpncopy(&dst->y, &src->y); return 0; } diff --git a/beecrypt/dlpk.h b/beecrypt/dlpk.h index 67e64d35d..9fa0a64e7 100644 --- a/beecrypt/dlpk.h +++ b/beecrypt/dlpk.h @@ -35,7 +35,7 @@ typedef struct { dldp_p param; - mp32number y; + mpnumber y; } dlpk_p; #ifdef __cplusplus diff --git a/beecrypt/dlsvdp-dh.c b/beecrypt/dlsvdp-dh.c index 0082130fb..47a17f1e5 100644 --- a/beecrypt/dlsvdp-dh.c +++ b/beecrypt/dlsvdp-dh.c @@ -29,7 +29,7 @@ #include "dlsvdp-dh.h" #include "debug.h" -int dlsvdp_pDHSecret(const dldp_p* dp, const mp32number* x, const mp32number* y, mp32number* s) +int dlsvdp_pDHSecret(const dldp_p* dp, const mpnumber* x, const mpnumber* y, mpnumber* s) { mp32bnpowmod(&dp->p, y, x, s); diff --git a/beecrypt/dlsvdp-dh.h b/beecrypt/dlsvdp-dh.h index 3693dd983..ea5588f56 100644 --- a/beecrypt/dlsvdp-dh.h +++ b/beecrypt/dlsvdp-dh.h @@ -37,7 +37,7 @@ extern "C" { /** */ BEECRYPTAPI -int dlsvdp_pDHSecret(const dldp_p* dp, const mp32number* x, const mp32number* y, mp32number* s) +int dlsvdp_pDHSecret(const dldp_p* dp, const mpnumber* x, const mpnumber* y, mpnumber* s) /*@modifies s */; #ifdef __cplusplus diff --git a/beecrypt/dsa.c b/beecrypt/dsa.c index 75e6c533a..a3d1cb882 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 mp32number* g, randomGeneratorContext* rgc, const mp32number* hm, const mp32number* x, mp32number* r, mp32number* s) +int dsasign(const mp32barrett* p, const mp32barrett* 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; @@ -74,8 +74,8 @@ int dsasign(const mp32barrett* p, const mp32barrett* q, const mp32number* g, ran qwksp = qtemp+3*qsize; /* allocate r */ - mp32nfree(r); - mp32nsize(r, qsize); + mpnfree(r); + mpnsize(r, qsize); /* get a random k, invertible modulo q */ mp32brndinv_w(q, rgc, qtemp, qtemp+qsize, qwksp); @@ -98,8 +98,8 @@ int dsasign(const mp32barrett* p, const mp32barrett* q, const mp32number* g, ran mp32copy(qsize, r->data, qtemp+psize+qsize); /* allocate s */ - mp32nfree(s); - mp32nsize(s, qsize); + mpnfree(s); + mpnsize(s, qsize); /* x*r mod q */ mp32bmulmod_w(q, x->size, x->data, r->size, r->data, qtemp, qwksp); @@ -119,7 +119,7 @@ int dsasign(const mp32barrett* p, const mp32barrett* q, const mp32number* g, ran } /*@=boundswrite@*/ -int dsavrfy(const mp32barrett* p, const mp32barrett* q, const mp32number* g, const mp32number* hm, const mp32number* y, const mp32number* r, const mp32number* s) +int dsavrfy(const mp32barrett* p, const mp32barrett* 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; diff --git a/beecrypt/dsa.h b/beecrypt/dsa.h index dc47fc01e..4774fc632 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 mp32number* g, randomGeneratorContext* rgc, const mp32number* hm, const mp32number* x, mp32number* r, mp32number* s) +int dsasign(const mp32barrett* p, const mp32barrett* 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 mp32number* g, const mp32number* hm, const mp32number* y, const mp32number* r, const mp32number* s) +int dsavrfy(const mp32barrett* p, const mp32barrett* 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 6d02926e9..fcd688b2d 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 mp32number* g, randomGeneratorContext* rgc, const mp32number* hm, const mp32number* x, mp32number* r, mp32number* s) +int elgv1sign(const mp32barrett* p, const mp32barrett* 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)); @@ -71,8 +71,8 @@ int elgv1sign(const mp32barrett* p, const mp32barrett* n, const mp32number* g, r mp32brndinv_w(n, rgc, temp, temp+size, temp+2*size); /* compute r = g^k mod p */ - mp32nfree(r); - mp32nsize(r, size); + mpnfree(r); + mpnsize(r, size); mp32bpowmod_w(p, g->size, g->data, size, temp, r->data, temp+2*size); /* compute x*r mod n */ @@ -86,8 +86,8 @@ int elgv1sign(const mp32barrett* p, const mp32barrett* n, const mp32number* g, r mp32baddmod_w(n, hm->size, hm->data, size, temp, temp, temp+2*size); /* compute s = inv(k)*(h(m) - x*r) mod n */ - mp32nfree(s); - mp32nsize(s, size); + mpnfree(s); + mpnsize(s, size); mp32bmulmod_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 mp32number* g, r return -1; } -int elgv1vrfy(const mp32barrett* p, const mp32barrett* n, const mp32number* g, const mp32number* hm, const mp32number* y, const mp32number* r, const mp32number* s) +int elgv1vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) { register uint32 size = p->size; register uint32* temp; @@ -141,7 +141,7 @@ int elgv1vrfy(const mp32barrett* p, const mp32barrett* n, const mp32number* g, c return 0; } -int elgv3sign(const mp32barrett* p, const mp32barrett* n, const mp32number* g, randomGeneratorContext* rgc, const mp32number* hm, const mp32number* x, mp32number* r, mp32number* s) +int elgv3sign(const mp32barrett* p, const mp32barrett* 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)); @@ -152,8 +152,8 @@ int elgv3sign(const mp32barrett* p, const mp32barrett* n, const mp32number* g, r mp32brnd_w(p, rgc, temp, temp+2*size); /* compute r = g^k mod p */ - mp32nfree(r); - mp32nsize(r, size); + mpnfree(r); + mpnsize(r, size); mp32bpowmod_w(p, g->size, g->data, size, temp, r->data, temp+2*size); /* compute u1 = x*r mod n */ @@ -163,8 +163,8 @@ int elgv3sign(const mp32barrett* p, const mp32barrett* n, const mp32number* g, r mp32bmulmod_w(n, size, temp, hm->size, hm->data, temp, temp+2*size); /* compute s = u1+u2 mod n */ - mp32nfree(s); - mp32nsize(s, n->size); + mpnfree(s); + mpnsize(s, n->size); mp32baddmod_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 mp32number* g, r return -1; } -int elgv3vrfy(const mp32barrett* p, const mp32barrett* n, const mp32number* g, const mp32number* hm, const mp32number* y, const mp32number* r, const mp32number* s) +int elgv3vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) { register uint32 size = p->size; register uint32* temp; diff --git a/beecrypt/elgamal.h b/beecrypt/elgamal.h index 4db376ef3..1b5d6a3f3 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 mp32number* g, randomGeneratorContext*, const mp32number* hm, const mp32number* x, mp32number* r, mp32number* s) +int elgv1sign(const mp32barrett* p, const mp32barrett* 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 mp32number* g, randomGeneratorContext*, const mp32number* hm, const mp32number* x, mp32number* r, mp32number* s) +int elgv3sign(const mp32barrett* p, const mp32barrett* 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 mp32number* g, const mp32number* hm, const mp32number* y, const mp32number* r, const mp32number* s) +int elgv1vrfy(const mp32barrett* p, const mp32barrett* 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 mp32number* g, const mp32number* hm, const mp32number* y, const mp32number* r, const mp32number* s) +int elgv3vrfy(const mp32barrett* p, const mp32barrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) /*@*/; #ifdef __cplusplus diff --git a/beecrypt/mp.h b/beecrypt/mp.h index 5bceef0b0..bedb21d8c 100644 --- a/beecrypt/mp.h +++ b/beecrypt/mp.h @@ -37,50 +37,6 @@ #include "mpopt.h" -#include <stdint.h> /* XXX scaffolding. */ -#define MP_WBITS 32 /* XXX scaffolding. */ -#define HAVE_UINT64_T 1 /* XXX scaffolding. */ - -#define MP_HWBITS (MP_WBITS >> 1) -#define MP_WBYTES (MP_WBITS >> 3) -#define MP_WNIBBLES (MP_WBITS >> 2) - -#if (MP_WBITS == 64) -# define MP_WORDS_TO_BITS(x) ((x) << 6) -# define MP_WORDS_TO_NIBBLES(x) ((x) << 4) -# define MP_WORDS_TO_BYTES(x) ((x) << 3) -# define MP_BITS_TO_WORDS(x) ((x) >> 6) -# define MP_NIBBLES_TO_WORDS(x) ((x) >> 4) -# define MP_BYTES_TO_WORDS(x) ((x) >> 3) -#elif (MP_WBITS == 32) -# define MP_WORDS_TO_BITS(x) ((x) << 5) -# define MP_WORDS_TO_NIBBLES(x) ((x) << 3) -# define MP_WORDS_TO_BYTES(x) ((x) << 2) -# define MP_BITS_TO_WORDS(x) ((x) >> 5) -# define MP_NIBBLES_TO_WORDS(x) ((x) >> 3) -# define MP_BYTES_TO_WORDS(x) ((x) >> 2) -#else -# error -#endif - -#if (MP_WBITS == 64) -typedef uint64_t mpw; -typedef uint32_t mphw; -#elif (MP_WBITS == 32) -# if HAVE_UINT64_T -# define HAVE_MPDW 1 -typedef uint64_t mpdw; -# endif -typedef uint32_t mpw; -typedef uint16_t mphw; -#else -# error -#endif - -#define MP_MSBMASK (((mpw) 0x1) << (MP_WBITS-1)) -#define MP_LSBMASK ((mpw) 0x1) -#define MP_ALLMASK ~((mpw) 0x0) - #ifdef __cplusplus extern "C" { #endif diff --git a/beecrypt/mpbarrett.c b/beecrypt/mpbarrett.c index f38f28e24..80653ae3e 100644 --- a/beecrypt/mpbarrett.c +++ b/beecrypt/mpbarrett.c @@ -1199,13 +1199,13 @@ int mp32bpprime_w(const mp32barrett* b, randomGeneratorContext* rc, int t, uint3 } /*@=boundsread@*/ -void mp32bnrnd(const mp32barrett* b, randomGeneratorContext* rc, mp32number* result) +void mp32bnrnd(const mp32barrett* b, randomGeneratorContext* rc, mpnumber* result) { register uint32 size = b->size; register uint32* temp = (uint32*) malloc(size * sizeof(uint32)); - mp32nfree(result); - mp32nsize(result, size); + mpnfree(result); + mpnsize(result, size); /*@-nullpass@*/ /* temp may be NULL */ /*@-usedef@*/ /* result->data unallocated? */ mp32brnd_w(b, rc, result->data, temp); @@ -1215,7 +1215,7 @@ void mp32bnrnd(const mp32barrett* b, randomGeneratorContext* rc, mp32number* res /*@=nullpass@*/ } -void mp32bnmulmod(const mp32barrett* b, const mp32number* x, const mp32number* y, mp32number* result) +void mp32bnmulmod(const mp32barrett* b, const mpnumber* x, const mpnumber* y, mpnumber* result) { register uint32 size = b->size; register uint32* temp = (uint32*) malloc((4*size+2) * sizeof(uint32)); @@ -1226,8 +1226,8 @@ void mp32bnmulmod(const mp32barrett* b, const mp32number* x, const mp32number* y register uint32* opnd = temp+size*2+2; /*@=nullptrarith@*/ - mp32nfree(result); - mp32nsize(result, size); + mpnfree(result); + mpnsize(result, size); if (fill) mp32zero(fill, opnd); @@ -1242,7 +1242,7 @@ void mp32bnmulmod(const mp32barrett* b, const mp32number* x, const mp32number* y /*@=nullpass@*/ } -void mp32bnsqrmod(const mp32barrett* b, const mp32number* x, mp32number* result) +void mp32bnsqrmod(const mp32barrett* b, const mpnumber* x, mpnumber* result) { register uint32 size = b->size; register uint32* temp = (uint32*) malloc(size * sizeof(uint32)); @@ -1253,8 +1253,8 @@ void mp32bnsqrmod(const mp32barrett* b, const mp32number* x, mp32number* result) register uint32* opnd = temp + size*2+2; /*@=nullptrarith@*/ - mp32nfree(result); - mp32nsize(result, size); + mpnfree(result); + mpnsize(result, size); if (fill) mp32zero(fill, opnd); @@ -1269,13 +1269,13 @@ void mp32bnsqrmod(const mp32barrett* b, const mp32number* x, mp32number* result) /*@=nullpass@*/ } -void mp32bnpowmod(const mp32barrett* b, const mp32number* x, const mp32number* pow, mp32number* y) +void mp32bnpowmod(const mp32barrett* b, const mpnumber* x, const mpnumber* pow, mpnumber* y) { register uint32 size = b->size; register uint32* temp = (uint32*) malloc((4*size+2) * sizeof(uint32)); - mp32nfree(y); - mp32nsize(y, size); + mpnfree(y); + mpnsize(y, size); /*@-nullpass@*/ /* temp may be NULL */ mp32bpowmod_w(b, x->size, x->data, pow->size, pow->data, y->data, temp); @@ -1284,13 +1284,13 @@ void mp32bnpowmod(const mp32barrett* b, const mp32number* x, const mp32number* p /*@=nullpass@*/ } -void mp32bnpowmodsld(const mp32barrett* b, const uint32* slide, const mp32number* pow, mp32number* y) +void mp32bnpowmodsld(const mp32barrett* b, const uint32* slide, const mpnumber* pow, mpnumber* y) { register uint32 size = b->size; register uint32* temp = (uint32*) malloc((4*size+2) * sizeof(uint32)); - mp32nfree(y); - mp32nsize(y, size); + mpnfree(y); + mpnsize(y, size); /*@-nullpass@*/ /* temp may be NULL */ /*@-internalglobs -mods@*/ /* noisy */ diff --git a/beecrypt/mpbarrett.h b/beecrypt/mpbarrett.h index 587ab0c51..fb4e4ab84 100644 --- a/beecrypt/mpbarrett.h +++ b/beecrypt/mpbarrett.h @@ -198,38 +198,38 @@ int mp32bpprime_w(const mp32barrett* b, randomGeneratorContext* rc, int t, /*@o /*@modifies wksp @*/; /** - * @note Takes mp32number as parameter. + * @note Takes mpnumber as parameter. */ BEECRYPTAPI -void mp32bnrnd(const mp32barrett* b, randomGeneratorContext* rc, mp32number* result) +void mp32bnrnd(const mp32barrett* b, randomGeneratorContext* rc, mpnumber* result) /*@modifies result @*/; /** - * @note Takes mp32number as parameter. + * @note Takes mpnumber as parameter. */ BEECRYPTAPI /*@unused@*/ -void mp32bnmulmod(const mp32barrett* b, const mp32number* x, const mp32number* y, mp32number* result) +void mp32bnmulmod(const mp32barrett* b, const mpnumber* x, const mpnumber* y, mpnumber* result) /*@modifies result @*/; /** - * @note Takes mp32number as parameter. + * @note Takes mpnumber as parameter. */ BEECRYPTAPI /*@unused@*/ -void mp32bnsqrmod(const mp32barrett* b, const mp32number* x, mp32number* result) +void mp32bnsqrmod(const mp32barrett* b, const mpnumber* x, mpnumber* result) /*@modifies result @*/; /** - * @note Takes mp32number as parameter. + * @note Takes mpnumber as parameter. */ BEECRYPTAPI -void mp32bnpowmod (const mp32barrett* b, const mp32number* x, const mp32number* pow, mp32number* y) +void mp32bnpowmod (const mp32barrett* b, const mpnumber* x, const mpnumber* pow, mpnumber* y) /*@modifies y @*/; /** - * @note Takes mp32number as parameter. + * @note Takes mpnumber as parameter. */ BEECRYPTAPI /*@unused@*/ -void mp32bnpowmodsld(const mp32barrett* b, const uint32* slide, const mp32number* pow, mp32number* y) +void mp32bnpowmodsld(const mp32barrett* b, const uint32* slide, const mpnumber* pow, mpnumber* y) /*@modifies y @*/; #ifdef __cplusplus diff --git a/beecrypt/mpnumber.c b/beecrypt/mpnumber.c index f40f4728f..afa1d4f99 100644 --- a/beecrypt/mpnumber.c +++ b/beecrypt/mpnumber.c @@ -1,4 +1,3 @@ -/*@-sizeoftype@*/ /** \ingroup MP_m * \file mpnumber.c * @@ -32,39 +31,39 @@ #include "mp.h" #include "debug.h" -void mp32nzero(mp32number* n) +void mpnzero(mpnumber* n) { n->size = 0; - n->data = (uint32*) 0; + n->data = (mpw*) 0; } /*@-compdef @*/ /* n->data not initialized */ -void mp32nsize(mp32number* n, uint32 size) +void mpnsize(mpnumber* n, size_t size) { if (size) { if (n->data) { if (n->size != size) - n->data = (uint32*) realloc(n->data, size * sizeof(uint32)); + n->data = (mpw*) realloc(n->data, size * sizeof(*n->data)); } else - n->data = (uint32*) malloc(size * sizeof(uint32)); + n->data = (mpw*) malloc(size * sizeof(*n->data)); if (n->data) n->size = size; else { n->size = 0; - n->data = (uint32*) 0; + n->data = (mpw*) 0; } } else if (n->data) { free(n->data); + n->data = (mpw*) 0; n->size = 0; - n->data = (uint32*) 0; } else {}; @@ -72,54 +71,54 @@ void mp32nsize(mp32number* n, uint32 size) /*@=compdef @*/ /*@-boundswrite@*/ -void mp32ninit(mp32number* n, uint32 size, const uint32* data) +void mpninit(mpnumber* n, size_t size, const mpw* data) { n->size = size; if (n->data) { free(n->data); - n->data = (uint32*) 0; + n->data = (mpw*) 0; } - n->data = (uint32*) malloc(size * sizeof(uint32)); + n->data = (mpw*) malloc(size * sizeof(*n->data)); if (n->data && data) mp32copy(size, n->data, data); } /*@=boundswrite@*/ -void mp32nfree(mp32number* n) +void mpnfree(mpnumber* n) { if (n->data) { free(n->data); - n->data = (uint32*) 0; + n->data = (mpw*) 0; } n->size = 0; } -void mp32ncopy(mp32number* n, const mp32number* copy) +void mpncopy(mpnumber* n, const mpnumber* copy) { - mp32nset(n, copy->size, copy->data); + mpnset(n, copy->size, copy->data); } -void mp32nwipe(mp32number* n) +void mpnwipe(mpnumber* n) { if (n->data) mp32zero(n->size, n->data); } /*@-boundswrite@*/ -void mp32nset(mp32number* n, uint32 size, const uint32* data) +void mpnset(mpnumber* n, size_t size, const mpw* data) { if (size) { if (n->data) { if (n->size != size) - n->data = (uint32*) realloc(n->data, size * sizeof(uint32)); + n->data = (mpw*) realloc(n->data, size * sizeof(*n->data)); } else - n->data = (uint32*) malloc(size * sizeof(uint32)); + n->data = (mpw*) malloc(size * sizeof(*n->data)); if (n->data && data) /*@-nullpass@*/ /* data is notnull */ @@ -128,13 +127,13 @@ void mp32nset(mp32number* n, uint32 size, const uint32* data) else { n->size = 0; - n->data = (uint32*) 0; + n->data = (mpw*) 0; } } else if (n->data) { free(n->data); - n->data = (uint32*) 0; + n->data = (mpw*) 0; n->size = 0; } else @@ -143,15 +142,15 @@ void mp32nset(mp32number* n, uint32 size, const uint32* data) /*@=boundswrite@*/ /*@-boundswrite@*/ -void mp32nsetw(mp32number* n, uint32 val) +void mpnsetw(mpnumber* n, mpw val) { if (n->data) { if (n->size != 1) - n->data = (uint32*) realloc(n->data, sizeof(uint32)); + n->data = (mpw*) realloc(n->data, 1 * sizeof(*n->data)); } else - n->data = (uint32*) malloc(sizeof(uint32)); + n->data = (mpw*) malloc(1 * sizeof(*n->data)); if (n->data) { @@ -161,36 +160,36 @@ void mp32nsetw(mp32number* n, uint32 val) else { n->size = 0; - n->data = (uint32*) 0; + n->data = (mpw*) 0; } } /*@=boundswrite@*/ /*@-boundswrite@*/ /*@-usedef @*/ /* n->data may be NULL */ -void mp32nsethex(mp32number* n, const char* hex) +void mpnsethex(mpnumber* n, const char* hex) { - uint32 length = strlen(hex); - uint32 size = (length+7) >> 3; - uint8 rem = (uint8)(length & 0x7); + register size_t len = strlen(hex); + register size_t size = (len+7) >> 3; + uint8 rem = (uint8)(len & 0x7); if (n->data) { if (n->size != size) - n->data = (uint32*) realloc(n->data, size * sizeof(uint32)); + n->data = (mpw*) realloc(n->data, size * sizeof(*n->data)); } else - n->data = (uint32*) malloc(size * sizeof(uint32)); + n->data = (mpw*) malloc(size * sizeof(*n->data)); if (n->data) { - register uint32 val = 0; - register uint32* dst = n->data; + register size_t val = 0; + register mpw* dst = n->data; register char ch; n->size = size; - while (length-- > 0) + while (len-- > 0) { ch = *(hex++); val <<= 4; @@ -203,7 +202,7 @@ void mp32nsethex(mp32number* n, const char* hex) else {}; - if ((length & 0x7) == 0) + if ((len & 0x7) == 0) { *(dst++) = val; val = 0; @@ -221,5 +220,4 @@ void mp32nsethex(mp32number* n, const char* hex) } } /*@=usedef @*/ -/*@=sizeoftype@*/ /*@=boundswrite@*/ diff --git a/beecrypt/mpnumber.h b/beecrypt/mpnumber.h index 9d5061a61..8ef95d75b 100644 --- a/beecrypt/mpnumber.h +++ b/beecrypt/mpnumber.h @@ -34,10 +34,10 @@ */ typedef struct { - uint32 size; + size_t size; /*@owned@*/ /*@relnull@*/ - uint32* data; -} mp32number; + mpw* data; +} mpnumber; #ifdef __cplusplus extern "C" { @@ -46,55 +46,55 @@ extern "C" { /** */ BEECRYPTAPI -void mp32nzero(/*@out@*/ mp32number* n) +void mpnzero(/*@out@*/ mpnumber* n) /*@modifies n->size, n->data @*/; /** */ BEECRYPTAPI -void mp32nsize(mp32number* n, uint32 size) +void mpnsize(mpnumber* n, size_t size) /*@modifies n->size, n->data @*/; /** */ BEECRYPTAPI /*@unused@*/ -void mp32ninit(mp32number* n, uint32 size, const uint32* data) +void mpninit(mpnumber* n, size_t size, const mpw* data) /*@modifies n->size, n->data @*/; /** */ BEECRYPTAPI -void mp32nfree(mp32number* n) +void mpnfree(mpnumber* n) /*@modifies n->size, n->data @*/; /** */ BEECRYPTAPI -void mp32ncopy(mp32number* n, const mp32number* copy) +void mpncopy(mpnumber* n, const mpnumber* copy) /*@modifies n->size, n->data @*/; /** */ BEECRYPTAPI -void mp32nwipe(mp32number* n) +void mpnwipe(mpnumber* n) /*@modifies n->size, n->data @*/; /** */ BEECRYPTAPI -void mp32nset (mp32number* n, uint32 size, /*@null@*/ const uint32* data) +void mpnset (mpnumber* n, size_t size, /*@null@*/ const mpw* data) /*@modifies n->size, n->data @*/; /** */ BEECRYPTAPI -void mp32nsetw (mp32number* n, uint32 val) +void mpnsetw (mpnumber* n, mpw val) /*@modifies n->size, n->data @*/; /** */ BEECRYPTAPI /*@unused@*/ -void mp32nsethex(/*@out@*/ mp32number* n, const char* hex) +void mpnsethex(/*@out@*/ mpnumber* n, const char* hex) /*@modifies n->size, n->data @*/; #ifdef __cplusplus diff --git a/beecrypt/mpprime.c b/beecrypt/mpprime.c index aea55e2e0..ebf8a57d5 100644 --- a/beecrypt/mpprime.c +++ b/beecrypt/mpprime.c @@ -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 mp32number* f, uint32* wksp) +void mp32prnd_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, const mpnumber* f, uint32* wksp) { /* * Generate a prime into p with (size*32) bits @@ -1247,7 +1247,7 @@ void mp32prnd_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, continue; /* if we have an f, do the congruence test */ - if (f != (mp32number*) 0) + if (f != (mpnumber*) 0) { mp32copy(size, wksp, p->modl); (void) mp32subw(size, wksp, 1); @@ -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 mp32number* f, mp32number* r, int cofactor, uint32* wksp) +void mp32prndconone_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, const mp32barrett* 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 @@ -1342,7 +1342,7 @@ void mp32prndconone_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, i continue; /* if we have an f, do the congruence test */ - if (f != (mp32number*) 0) + if (f != (mpnumber*) 0) { mp32copy(size, wksp, p->modl); (void) mp32subw(size, wksp, 1); @@ -1367,7 +1367,7 @@ void mp32prndconone_w(mp32barrett* p, randomGeneratorContext* rc, uint32 size, i if (!mp32pmilrab_w(p, rc, t, wksp)) continue; - mp32nset(r, s.size, s.modl); + mpnset(r, s.size, s.modl); (void) mp32multwo(r->size, r->data); mp32bfree(&s); diff --git a/beecrypt/mpprime.h b/beecrypt/mpprime.h index cb9f8fac9..8f99a88fb 100644 --- a/beecrypt/mpprime.h +++ b/beecrypt/mpprime.h @@ -57,7 +57,7 @@ int mp32pmilrab_w (const mp32barrett* p, randomGeneratorContext* rc, int t, / /** */ BEECRYPTAPI -void mp32prnd_w (mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, /*@null@*/ const mp32number* f, /*@out@*/ uint32* wksp) +void mp32prnd_w (mp32barrett* p, randomGeneratorContext* rc, uint32 size, int t, /*@null@*/ const mpnumber* f, /*@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 mp32number*, const mp32number*, const mp32number*, mp32number*, /*@out@*/ uint32* wksp) +void mp32prndcon_w (mp32barrett* 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 mp32number* f, mp32number* r, int cofactor, /*@out@*/ uint32* wksp) +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) /*@globals mp32spprod @*/ /*@modifies p, rc, r, wksp @*/; diff --git a/beecrypt/rsa.c b/beecrypt/rsa.c index 8c8dcb531..6d0045e75 100644 --- a/beecrypt/rsa.c +++ b/beecrypt/rsa.c @@ -30,14 +30,14 @@ #include "mp.h" #include "debug.h" -int rsapri(const rsakp* kp, const mp32number* m, mp32number* c) +int rsapri(const rsakp* kp, const mpnumber* m, mpnumber* c) { register uint32 size = kp->n.size; register uint32* temp = (uint32*) malloc((4*size+2) * sizeof(*temp)); if (temp) { - mp32nsize(c, size); + mpnsize(c, size); mp32bpowmod_w(&kp->n, m->size, m->data, kp->d.size, kp->d.data, c->data, temp); free(temp); @@ -48,7 +48,7 @@ int rsapri(const rsakp* kp, const mp32number* m, mp32number* c) } -int rsapricrt(const rsakp* kp, const mp32number* m, mp32number* c) +int rsapricrt(const rsakp* kp, const mpnumber* m, mpnumber* c) { register uint32 nsize = kp->n.size; register uint32 psize = kp->p.size; @@ -93,7 +93,7 @@ int rsapricrt(const rsakp* kp, const mp32number* m, mp32number* c) mp32bmulmod_w(&kp->p, psize, ptemp, psize, kp->c.data, ptemp, ptemp+2*psize); /* make sure the signature gets the proper size */ - mp32nsize(c, nsize); + mpnsize(c, nsize); /* compute s = h*q + j2 */ mp32mul(c->data, psize, ptemp, qsize, kp->q.modl); @@ -108,7 +108,7 @@ int rsapricrt(const rsakp* kp, const mp32number* m, mp32number* c) /** * @return 1 if signature verifies, 0 otherwise (can also indicate errors) */ -int rsavrfy(const rsapk* pk, const mp32number* m, const mp32number* c) +int rsavrfy(const rsapk* pk, const mpnumber* m, const mpnumber* c) { int rc; register uint32 size = pk->n.size; diff --git a/beecrypt/rsa.h b/beecrypt/rsa.h index c4a97754b..2bf2f2861 100644 --- a/beecrypt/rsa.h +++ b/beecrypt/rsa.h @@ -37,19 +37,19 @@ extern "C" { /** */ BEECRYPTAPI /*@unused@*/ -int rsapri (const rsakp* kp, const mp32number* m, mp32number* c) +int rsapri (const rsakp* kp, const mpnumber* m, mpnumber* c) /*@modifies c */; /** */ BEECRYPTAPI /*@unused@*/ -int rsapricrt(const rsakp* kp, const mp32number* m, mp32number* c) +int rsapricrt(const rsakp* kp, const mpnumber* m, mpnumber* c) /*@modifies c */; /** */ BEECRYPTAPI /*@unused@*/ -int rsavrfy (const rsapk* pk, const mp32number* m, const mp32number* c) +int rsavrfy (const rsapk* pk, const mpnumber* m, const mpnumber* c) /*@*/; #ifdef __cplusplus diff --git a/beecrypt/rsakp.c b/beecrypt/rsakp.c index 1e121dd1b..27f179216 100644 --- a/beecrypt/rsakp.c +++ b/beecrypt/rsakp.c @@ -51,7 +51,7 @@ int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, int nsize) nsize = pqsize << 1; /* set e */ - mp32nsetw(&kp->e, 65535); + mpnsetw(&kp->e, 65535); /* generate a random prime p and q */ /*@-globs@*/ @@ -131,19 +131,19 @@ int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, int nsize) mp32bset(&phi, nsize, temp); /* compute d = inv(e) mod phi */ - mp32nsize(&kp->d, nsize); + mpnsize(&kp->d, nsize); (void) mp32binv_w(&phi, kp->e.size, kp->e.data, kp->d.data, temp); /* compute d1 = d mod (p-1) */ - mp32nsize(&kp->d1, pqsize); + mpnsize(&kp->d1, pqsize); mp32bmod_w(&psubone, kp->d.data, kp->d1.data, temp); /* compute d2 = d mod (q-1) */ - mp32nsize(&kp->d2, pqsize); + mpnsize(&kp->d2, pqsize); mp32bmod_w(&qsubone, kp->d.data, kp->d2.data, temp); /* compute c = inv(q) mod p */ - mp32nsize(&kp->c, pqsize); + mpnsize(&kp->c, pqsize); (void) mp32binv_w(&kp->p, pqsize, kp->q.modl, kp->c.data, temp); free(temp); @@ -161,13 +161,13 @@ int rsakpInit(rsakp* kp) memset(kp, 0, sizeof(*kp)); /* or mp32bzero(&kp->n); - mp32nzero(&kp->e); - mp32nzero(&kp->d); + mpnzero(&kp->e); + mpnzero(&kp->d); mp32bzero(&kp->p); mp32bzero(&kp->q); - mp32nzero(&kp->d1); - mp32nzero(&kp->d2); - mp32nzero(&kp->c); + mpnzero(&kp->d1); + mpnzero(&kp->d2); + mpnzero(&kp->c); */ return 0; @@ -178,13 +178,13 @@ int rsakpFree(rsakp* kp) { /*@-usereleased -compdef @*/ /* kp->param.{n,p,q}.modl is OK */ mp32bfree(&kp->n); - mp32nfree(&kp->e); - mp32nfree(&kp->d); + mpnfree(&kp->e); + mpnfree(&kp->d); mp32bfree(&kp->p); mp32bfree(&kp->q); - mp32nfree(&kp->d1); - mp32nfree(&kp->d2); - mp32nfree(&kp->c); + mpnfree(&kp->d1); + mpnfree(&kp->d2); + mpnfree(&kp->c); return 0; /*@=usereleased =compdef @*/ @@ -193,13 +193,13 @@ int rsakpFree(rsakp* kp) int rsakpCopy(rsakp* dst, const rsakp* src) { mp32bcopy(&dst->n, &src->n); - mp32ncopy(&dst->e, &src->e); - mp32ncopy(&dst->d, &src->d); + mpncopy(&dst->e, &src->e); + mpncopy(&dst->d, &src->d); mp32bcopy(&dst->p, &src->p); mp32bcopy(&dst->q, &src->q); - mp32ncopy(&dst->d1, &src->d1); - mp32ncopy(&dst->d2, &src->d2); - mp32ncopy(&dst->c, &src->c); + mpncopy(&dst->d1, &src->d1); + mpncopy(&dst->d2, &src->d2); + mpncopy(&dst->c, &src->c); return 0; } diff --git a/beecrypt/rsakp.h b/beecrypt/rsakp.h index 843352dae..0f2dcec28 100644 --- a/beecrypt/rsakp.h +++ b/beecrypt/rsakp.h @@ -35,13 +35,13 @@ typedef struct { mp32barrett n; - mp32number e; - mp32number d; + mpnumber e; + mpnumber d; mp32barrett p; mp32barrett q; - mp32number d1; - mp32number d2; - mp32number c; + mpnumber d1; + mpnumber d2; + mpnumber c; } rsakp; #ifdef __cplusplus diff --git a/beecrypt/rsapk.c b/beecrypt/rsapk.c index de9f394de..39685097f 100644 --- a/beecrypt/rsapk.c +++ b/beecrypt/rsapk.c @@ -37,7 +37,7 @@ int rsapkInit(rsapk* pk) memset(pk, 0, sizeof(*pk)); /* or mp32bzero(&pk->n); - mp32nzero(&pk->e); + mpnzero(&pk->e); */ return 0; @@ -48,7 +48,7 @@ int rsapkFree(rsapk* pk) { /*@-usereleased -compdef @*/ /* pk->n.modl is OK */ mp32bfree(&pk->n); - mp32nfree(&pk->e); + mpnfree(&pk->e); return 0; /*@=usereleased =compdef @*/ @@ -57,7 +57,7 @@ int rsapkFree(rsapk* pk) int rsapkCopy(rsapk* dst, const rsapk* src) { mp32bcopy(&dst->n, &src->n); - mp32ncopy(&dst->e, &src->e); + mpncopy(&dst->e, &src->e); return 0; } diff --git a/beecrypt/rsapk.h b/beecrypt/rsapk.h index 81b8a0995..682146b4c 100644 --- a/beecrypt/rsapk.h +++ b/beecrypt/rsapk.h @@ -35,7 +35,7 @@ typedef struct { mp32barrett n; - mp32number e; + mpnumber e; } rsapk; #ifdef __cplusplus diff --git a/beecrypt/tests/beetest.c b/beecrypt/tests/beetest.c index a53fcdcc8..f57fb29ed 100644 --- a/beecrypt/tests/beetest.c +++ b/beecrypt/tests/beetest.c @@ -98,15 +98,15 @@ static int testVectorExpMod(const dlkp_p* keypair) /*@*/ { int rc; - mp32number y; + mpnumber y; - mp32nzero(&y); + mpnzero(&y); mp32bnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y); rc = mp32eqx(y.size, y.data, keypair->y.size, keypair->y.data); - mp32nfree(&y); + mpnfree(&y); return rc; } @@ -125,13 +125,13 @@ static int testVectorDSA(const dlkp_p* keypair) if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) /*@=nullpass =modobserver @*/ { - mp32number digest, r, s; + mpnumber digest, r, s; - mp32nzero(&digest); - mp32nzero(&r); - mp32nzero(&s); + mpnzero(&digest); + mpnzero(&r); + mpnzero(&s); - mp32nsize(&digest, 5); + mpnsize(&digest, 5); /*@-noeffectuncon@*/ /* LCL: ??? */ (void) rngc.rng->next(rngc.param, digest.data, digest.size); @@ -141,9 +141,9 @@ static int testVectorDSA(const dlkp_p* keypair) rc = dsavrfy(&keypair->param.p, &keypair->param.q, &keypair->param.g, &digest, &keypair->y, &r, &s); - mp32nfree(&digest); - mp32nfree(&r); - mp32nfree(&s); + mpnfree(&digest); + mpnfree(&r); + mpnfree(&s); /*@-modobserver@*/ (void) randomGeneratorContextFree(&rngc); @@ -166,13 +166,13 @@ static int testVectorElGamalV1(const dlkp_p* keypair) if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) /*@=nullpass =modobserver @*/ { - mp32number digest, r, s; + mpnumber digest, r, s; - mp32nzero(&digest); - mp32nzero(&r); - mp32nzero(&s); + mpnzero(&digest); + mpnzero(&r); + mpnzero(&s); - mp32nsize(&digest, 5); + mpnsize(&digest, 5); /*@-noeffectuncon@*/ /* LCL: ??? */ (void) rngc.rng->next(rngc.param, digest.data, digest.size); @@ -182,9 +182,9 @@ static int testVectorElGamalV1(const dlkp_p* keypair) rc = elgv1vrfy(&keypair->param.p, &keypair->param.n, &keypair->param.g, &digest, &keypair->y, &r, &s); - mp32nfree(&digest); - mp32nfree(&r); - mp32nfree(&s); + mpnfree(&digest); + mpnfree(&r); + mpnfree(&s); /*@-modobserver@*/ (void) randomGeneratorContextFree(&rngc); @@ -207,13 +207,13 @@ static int testVectorElGamalV3(const dlkp_p* keypair) if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) /*@=nullpass =modobserver @*/ { - mp32number digest, r, s; + mpnumber digest, r, s; - mp32nzero(&digest); - mp32nzero(&r); - mp32nzero(&s); + mpnzero(&digest); + mpnzero(&r); + mpnzero(&s); - mp32nsize(&digest, 5); + mpnsize(&digest, 5); /*@-noeffectuncon@*/ /* LCL: ??? */ (void) rngc.rng->next(rngc.param, digest.data, digest.size); @@ -223,9 +223,9 @@ static int testVectorElGamalV3(const dlkp_p* keypair) rc = elgv3vrfy(&keypair->param.p, &keypair->param.n, &keypair->param.g, &digest, &keypair->y, &r, &s); - mp32nfree(&digest); - mp32nfree(&r); - mp32nfree(&s); + mpnfree(&digest); + mpnfree(&r); + mpnfree(&s); /*@-modobserver@*/ (void) randomGeneratorContextFree(&rngc); @@ -247,7 +247,7 @@ static int testVectorDHAES(const dlkp_p* keypair) /* incomplete */ if (dhaes_pInit(&dh, &keypair->param) == 0) { - mp32number mkey, mac; + mpnumber mkey, mac; memchunk src, *dst, *cmp; @@ -258,8 +258,8 @@ static int testVectorDHAES(const dlkp_p* keypair) memset(src.data, 1, src.size); /* initialize the message key and mac */ - mp32nzero(&mkey); - mp32nzero(&mac); + mpnzero(&mkey); + mpnzero(&mac); /* encrypt the message */ dst = dhaes_pEncrypt(&dh, &keypair->y, &mkey, &mac, &src); @@ -308,7 +308,7 @@ static int testVectorRSA(void) /*@=nullpass =modobserver @*/ { rsakp kp; - mp32number digest, s; + mpnumber digest, s; memset(&kp, 0, sizeof(rsakp)); @@ -317,8 +317,8 @@ static int testVectorRSA(void) (void) rsakpMake(&kp, &rngc, 32); fprintf(stdout, "RSA CRT keypair generated\n"); - mp32nzero(&digest); - mp32nzero(&s); + mpnzero(&digest); + mpnzero(&s); mp32bnrnd(&kp.n, &rngc, &digest); @@ -326,8 +326,8 @@ static int testVectorRSA(void) rc = rsavrfy((rsapk*) &kp, &digest, &s); - mp32nfree(&digest); - mp32nfree(&s); + mpnfree(&digest); + mpnfree(&s); (void) rsakpFree(&kp); @@ -356,17 +356,17 @@ static int testVectorDLDP(void) /*@=nullpass =modobserver @*/ { register int result; - mp32number gq; + mpnumber gq; - mp32nzero(&gq); + mpnzero(&gq); (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, (mp32number*) &dp.q, &gq); + mp32bnpowmod(&dp.p, &dp.g, (mpnumber*) &dp.q, &gq); result = mp32isone(gq.size, gq.data); - mp32nfree(&gq); + mpnfree(&gq); (void) dldp_pFree(&dp); /*@-modobserver@*/ @@ -605,9 +605,9 @@ static void testHashFunctions(void) double ttime; clock_t tstart, tstop; #endif - mp32number digest; + mpnumber digest; - mp32nzero(&digest); + mpnzero(&digest); fprintf(stdout, " %s:\n", tmp->name); @@ -638,7 +638,7 @@ static void testHashFunctions(void) /*@=modobserver@*/ } - mp32nfree(&digest); + mpnfree(&digest); } } /*@=branchstate@*/ @@ -659,18 +659,18 @@ static void testExpMods(void) randomGeneratorContext rngc; mp32barrett p; - mp32number tmp; - mp32number g; - mp32number x; - mp32number y; + mpnumber tmp; + mpnumber g; + mpnumber x; + mpnumber y; memset(&rngc, 0, sizeof(randomGeneratorContext)); mp32bzero(&p); - mp32nzero(&g); - mp32nzero(&x); - mp32nzero(&y); - mp32nzero(&tmp); + mpnzero(&g); + mpnzero(&x); + mpnzero(&y); + mpnzero(&tmp); /*@-nullpass -modobserver @*/ if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) @@ -684,10 +684,10 @@ static void testExpMods(void) fprintf(stdout, "Timing modular exponentiations\n"); fprintf(stdout, " (%4d bits ^ %4d bits) mod %4d bits:", 512, 512, 512); - mp32nsethex(&tmp, p_512); + mpnsethex(&tmp, p_512); mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); + mpnsize(&g, p.size); + mpnsize(&x, p.size); mp32bnrnd(&p, &rngc, &g); mp32bnrnd(&p, &rngc, &x); #if HAVE_TIME_H @@ -701,10 +701,10 @@ static void testExpMods(void) fprintf(stdout, " 100x in %.3f seconds\n", ttime); #endif fprintf(stdout, " (%4d bits ^ %4d bits) mod %4d bits:", 768, 768, 768); - mp32nsethex(&tmp, p_768); + mpnsethex(&tmp, p_768); mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); + mpnsize(&g, p.size); + mpnsize(&x, p.size); mp32bnrnd(&p, &rngc, &g); mp32bnrnd(&p, &rngc, &x); #if HAVE_TIME_H @@ -718,10 +718,10 @@ static void testExpMods(void) fprintf(stdout, " 100x in %.3f seconds\n", ttime); #endif fprintf(stdout, " (%4d bits ^ %4d bits) mod %4d bits:", 1024, 1024, 1024); - mp32nsethex(&tmp, p_1024); + mpnsethex(&tmp, p_1024); mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); + mpnsize(&g, p.size); + mpnsize(&x, p.size); mp32bnrnd(&p, &rngc, &g); mp32bnrnd(&p, &rngc, &x); #if HAVE_TIME_H @@ -735,7 +735,7 @@ static void testExpMods(void) fprintf(stdout, " 100x in %.3f seconds\n", ttime); #endif /* now run a test with x having 160 bits */ - mp32nsize(&x, 5); + mpnsize(&x, 5); /*@-noeffectuncon@*/ /* LCL: ??? */ (void) rngc.rng->next(rngc.param, x.data, x.size); /*@=noeffectuncon@*/ @@ -751,10 +751,10 @@ static void testExpMods(void) fprintf(stdout, " 100x in %.3f seconds\n", ttime); #endif mp32bfree(&p); - mp32nfree(&g); - mp32nfree(&x); - mp32nfree(&y); - mp32nfree(&tmp); + mpnfree(&g); + mpnfree(&x); + mpnfree(&y); + mpnfree(&tmp); /*@-modobserver@*/ (void) randomGeneratorContextFree(&rngc); @@ -770,12 +770,12 @@ static void testRSA(void) /*@modifies fileSystem, internalState */ { randomGeneratorContext rngc; - mp32number hm, s; + mpnumber hm, s; rsakp kp; memset(&rngc, 0, sizeof(randomGeneratorContext)); - mp32nzero(&hm); - mp32nzero(&s); + mpnzero(&hm); + mpnzero(&s); fprintf(stdout, "Timing RSA:\n"); @@ -804,7 +804,7 @@ static void testRSA(void) fprintf(stdout, " done in %.3f seconds\n", ttime); #endif - mp32nsize(&hm, 4); + mpnsize(&hm, 4); rngc.rng->next(rngc.param, hm.data, hm.size); fprintf(stdout, " RSA sign:"); @@ -846,7 +846,7 @@ static void testDLAlgorithms(void) /*@modifies fileSystem, internalState */ { randomGeneratorContext rngc; - mp32number hm, r, s; + mpnumber hm, r, s; dldp_p dp; dlkp_p kp; @@ -854,9 +854,9 @@ static void testDLAlgorithms(void) memset(&dp, 0, sizeof(dldp_p)); memset(&kp, 0, sizeof(dlkp_p)); - mp32nzero(&hm); - mp32nzero(&r); - mp32nzero(&s); + mpnzero(&hm); + mpnzero(&r); + mpnzero(&s); (void) dldp_pInit(&dp); (void) dlkp_pInit(&kp); @@ -896,7 +896,7 @@ static void testDLAlgorithms(void) fprintf(stdout, " done in %.3f seconds\n", ttime); #endif - mp32nsize(&hm, 5); + mpnsize(&hm, 5); /*@-noeffectuncon@*/ /* LCL: ??? */ (void) rngc.rng->next(rngc.param, hm.data, hm.size); /*@=noeffectuncon@*/ @@ -978,10 +978,10 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[]) mp32bsethex(&keypair.param.p, dsa_p); mp32bsethex(&keypair.param.q, dsa_q); - mp32nsethex(&keypair.param.g, dsa_g); + mpnsethex(&keypair.param.g, dsa_g); mp32bsethex(&keypair.param.n, elg_n); - mp32nsethex(&keypair.y, dsa_y); - mp32nsethex(&keypair.x, dsa_x); + mpnsethex(&keypair.y, dsa_y); + mpnsethex(&keypair.x, dsa_x); if (testVectorInvMod(&keypair)) fprintf(stdout, "InvMod works!\n"); @@ -1126,10 +1126,10 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[]) mp32bsethex(&keypair.param.p, dsa_p); mp32bsethex(&keypair.param.q, dsa_q); - mp32nsethex(&keypair.param.g, dsa_g); + mpnsethex(&keypair.param.g, dsa_g); mp32bsethex(&keypair.param.n, elg_n); - mp32nsethex(&keypair.y, dsa_y); - mp32nsethex(&keypair.x, dsa_x); + mpnsethex(&keypair.y, dsa_y); + mpnsethex(&keypair.x, dsa_x); if (testVectorInvMod(&keypair)) fprintf(stdout, "InvMod works!\n"); diff --git a/beecrypt/tests/testdldp.c b/beecrypt/tests/testdldp.c index 0a507e99e..f032e0e8c 100644 --- a/beecrypt/tests/testdldp.c +++ b/beecrypt/tests/testdldp.c @@ -39,21 +39,21 @@ int main() if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) { - mp32number gq; + mpnumber gq; - mp32nzero(&gq); + mpnzero(&gq); /* make parameters with p = 512 bits, q = 160 bits, g of order (q) */ dldp_pgoqMake(¶ms, &rngc, 512 >> 5, 160 >> 5, 1); /* we have the parameters, now see if g^q == 1 */ - mp32bnpowmod(¶ms.p, ¶ms.g, (mp32number*) ¶ms.q, &gq); + mp32bnpowmod(¶ms.p, ¶ms.g, (mpnumber*) ¶ms.q, &gq); if (mp32isone(gq.size, gq.data)) printf("ok\n"); else failures++; - mp32nfree(&gq); + mpnfree(&gq); dldp_pFree(¶ms); diff --git a/beecrypt/tests/testdsa.c b/beecrypt/tests/testdsa.c index bd0167468..918ab7170 100644 --- a/beecrypt/tests/testdsa.c +++ b/beecrypt/tests/testdsa.c @@ -54,14 +54,14 @@ int fake_seed(randomGeneratorParam* p, const uint32* data, int size) int fake_next(randomGeneratorParam* p, uint32* data, int size) { - mp32number tmp; + mpnumber tmp; - mp32nzero(&tmp); - mp32nsethex(&tmp, dsa_k); + mpnzero(&tmp); + mpnsethex(&tmp, dsa_k); mp32setx(size, data, tmp.size, tmp.data); - mp32nfree(&tmp); + mpnfree(&tmp); return 0; } @@ -78,7 +78,7 @@ int main() int failures = 0; dlkp_p keypair; - mp32number hm, r, s; + mpnumber hm, r, s; randomGeneratorContext rngc; memset(&rngc, 0, sizeof(rngc)); @@ -87,16 +87,16 @@ int main() mp32bsethex(&keypair.param.p, dsa_p); mp32bsethex(&keypair.param.q, dsa_q); - mp32nsethex(&keypair.param.g, dsa_g); - mp32nsethex(&keypair.y, dsa_y); - mp32nsethex(&keypair.x, dsa_x); + mpnsethex(&keypair.param.g, dsa_g); + mpnsethex(&keypair.y, dsa_y); + mpnsethex(&keypair.x, dsa_x); - mp32nzero(&hm); - mp32nsethex(&hm, dsa_hm); + mpnzero(&hm); + mpnsethex(&hm, dsa_hm); /* first test, from NIST FIPS 186-1 */ - mp32nzero(&r); - mp32nzero(&s); + mpnzero(&r); + mpnzero(&s); if (randomGeneratorContextInit(&rngc, &fakeprng)) return -1; @@ -112,12 +112,12 @@ int main() if (randomGeneratorContextFree(&rngc)) return -1; - mp32nfree(&s); - mp32nfree(&r); + mpnfree(&s); + mpnfree(&r); /* second test, sign a hash and verify the signature */ - mp32nzero(&s); - mp32nzero(&r); + mpnzero(&s); + mpnzero(&r); if (randomGeneratorContextInit(&rngc, randomGeneratorDefault())) return -1; @@ -133,10 +133,10 @@ int main() if (randomGeneratorContextFree(&rngc)) return -1; - mp32nfree(&s); - mp32nfree(&r); + mpnfree(&s); + mpnfree(&r); - mp32nfree(&hm); + mpnfree(&hm); dlkp_pFree(&keypair); |