diff options
42 files changed, 461 insertions, 389 deletions
diff --git a/beecrypt/.splintrc b/beecrypt/.splintrc index 6fb384bd9..64c80d55c 100644 --- a/beecrypt/.splintrc +++ b/beecrypt/.splintrc @@ -3,7 +3,7 @@ #+partial +forcehints --warnunixlib +#-warnunixlib -warnposix +unixlib @@ -15,6 +15,18 @@ # --- in progress #+bounds -bufferoverflowhigh +-aliasunique +-mayaliasunique +-elseifcomplete +-exportheader +-exportheadervar +-exportlocal +-fcnuse +-typeuse +-varuse +-compdef +-noeffectuncon +-whileempty # --- not-yet at strict level -exportconst # 4 diff --git a/beecrypt/aes.c b/beecrypt/aes.c index ccc29bc57..837c6db64 100644 --- a/beecrypt/aes.c +++ b/beecrypt/aes.c @@ -762,7 +762,7 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) ap->fdback[2] = 0; ap->fdback[3] = 0; - ap->nr = 6 + ((uint32_t)keybits >> 5); + ap->nr = 6 + (keybits >> 5); rk = ap->k; @@ -846,8 +846,6 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) rk += 8; } } - else - {}; if (op == DECRYPT) { @@ -1182,6 +1180,5 @@ uint32_t* aesFeedback(aesParam* ap) { return ap->fdback; } - /*!\} */ diff --git a/beecrypt/aes.h b/beecrypt/aes.h index f3fbda900..253aff2d6 100644 --- a/beecrypt/aes.h +++ b/beecrypt/aes.h @@ -112,9 +112,9 @@ int aesDecrypt(aesParam* ap, uint32_t* dst, const uint32_t* src) /** \ingroup BC_aes_m */ /*@-exportlocal@*/ -BEECRYPTAPI +BEECRYPTAPI /*@observer@*/ uint32_t* aesFeedback(aesParam* ap) - /*@modifies ap @*/; + /*@*/; /*@=exportlocal@*/ #ifdef __cplusplus diff --git a/beecrypt/base64.c b/beecrypt/base64.c index 9efe0287c..07150a3e5 100644 --- a/beecrypt/base64.c +++ b/beecrypt/base64.c @@ -198,8 +198,6 @@ memchunk* b64dec(const char* string) } else if (ch == '=') break; - else - {}; switch (qw++) { @@ -412,13 +410,13 @@ fprintf(stderr, "--- b64decode %c(%02x) %02x\n", *t, (unsigned)(*t & 0xff), (uns /* Get next 4 characters, ignoring whitespace. */ while ((a = b64dec[ (unsigned)*s++ ]) == 0x81) - {}; + ; while ((b = b64dec[ (unsigned)*s++ ]) == 0x81) - {}; + ; while ((c = b64dec[ (unsigned)*s++ ]) == 0x81) - {}; + ; while ((d = b64dec[ (unsigned)*s++ ]) == 0x81) - {}; + ; if (_debug) fprintf(stderr, "%7u %02x %02x %02x %02x -> %02x %02x %02x\n", @@ -446,8 +444,6 @@ fprintf(stderr, "%7u %02x %02x %02x %02x -> %02x %02x %02x\n", *datap = (void *)t; else if (t) free((void *)t); - else - {}; return 0; } diff --git a/beecrypt/base64.h b/beecrypt/base64.h index b6d2df9b7..139b3b542 100644 --- a/beecrypt/base64.h +++ b/beecrypt/base64.h @@ -17,7 +17,7 @@ * */ -/*!\file base64.h +/*!\file base64.h * \brief Base64 encoding and decoding, headers. * \author Bob Deblier <bob@virtualunlimited.com> */ diff --git a/beecrypt/beecrypt.c b/beecrypt/beecrypt.c index ced52e6fa..a850d702c 100644 --- a/beecrypt/beecrypt.c +++ b/beecrypt/beecrypt.c @@ -426,12 +426,12 @@ int hashFunctionContextUpdateMP(hashFunctionContext* ctxt, const mpnumber* n) if (mpmsbset(n->size, n->data)) { tmp[0] = 0; - i2osp(tmp+1, MP_WORDS_TO_BYTES(n->size), n->data, n->size); + (void) i2osp(tmp+1, MP_WORDS_TO_BYTES(n->size), n->data, n->size); rc = ctxt->algo->update(ctxt->param, tmp, MP_WORDS_TO_BYTES(n->size) + 1); } else { - i2osp(tmp, MP_WORDS_TO_BYTES(n->size), n->data, n->size); + (void) i2osp(tmp, MP_WORDS_TO_BYTES(n->size), n->data, n->size); rc = ctxt->algo->update(ctxt->param, tmp, MP_WORDS_TO_BYTES(n->size)); } free(tmp); @@ -918,7 +918,9 @@ int blockCipherContextFree(blockCipherContext* ctxt) /*@=nullstate@*/ } +static /*@unused@*/ int blockCipherContextECB(blockCipherContext* ctxt, void* dst, const void* src, int nblocks) + /*@modifies ctxt->param, dst @*/ { switch (ctxt->op) { @@ -930,10 +932,13 @@ int blockCipherContextECB(blockCipherContext* ctxt, void* dst, const void* src, case DECRYPT: return blockDecryptECB(ctxt->algo, ctxt->param, dst, src, nblocks); } + /*@notreached@*/ return -1; } +static /*@unused@*/ int blockCipherContextCBC(blockCipherContext* ctxt, void* dst, const void* src, int nblocks) + /*@modifies ctxt->param, dst @*/ { switch (ctxt->op) { @@ -945,6 +950,7 @@ int blockCipherContextCBC(blockCipherContext* ctxt, void* dst, const void* src, case DECRYPT: return blockDecryptCBC(ctxt->algo, ctxt->param, dst, src, nblocks); } + /*@notreached@*/ return -1; } diff --git a/beecrypt/beecrypt.h b/beecrypt/beecrypt.h index d373b79bb..b709581a2 100644 --- a/beecrypt/beecrypt.h +++ b/beecrypt/beecrypt.h @@ -438,13 +438,19 @@ int hashFunctionContextUpdateMP(hashFunctionContext* ctxt, const mpnumber* n) /** \ingroup HASH_m */ BEECRYPTAPI -int hashFunctionContextDigest(hashFunctionContext* ctxt, byte* dig) - /*@modifies ctxt, *dig */; +int hashFunctionContextDigest(hashFunctionContext* ctxt, byte* digest) + /*@modifies ctxt, *digest */; + +/** \ingroup HASH_m + */ +BEECRYPTAPI +int hashFunctionContextDigestMP(hashFunctionContext* ctxt, mpnumber* d) + /*@modifies ctxt, *d */; /** \ingroup HASH_m */ BEECRYPTAPI /*@unused@*/ -int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mpnumber* match) +int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mpnumber* d) /*@modifies ctxt */; #ifdef __cplusplus @@ -641,13 +647,17 @@ int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext* ctxt, const mpnum /** \ingroup HMAC_m */ BEECRYPTAPI -int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, byte* d) - /*@modifies ctxt, *d @*/; +int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, byte* digest) + /*@modifies ctxt, *digest @*/; + +BEECRYPTAPI +int keyedHashFunctionContextDigestMP(keyedHashFunctionContext* ctxt, const mpnumber* d) + /*@modifies ctxt, d @*/; /** \ingroup HMAC_m */ BEECRYPTAPI -int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mpnumber* match) +int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mpnumber* d) /*@modifies ctxt @*/; #ifdef __cplusplus @@ -836,7 +846,7 @@ extern "C" { */ BEECRYPTAPI int blockCipherContextInit(blockCipherContext* ctxt, /*@observer@*/ /*@dependent@*/ const blockCipher* ciph) - /*@modifies ctxt->algo, ctxt->param @*/; + /*@modifies ctxt->algo, ctxt->param, ctxt->op @*/; /** \ingroup BC_m */ diff --git a/beecrypt/blockmode.c b/beecrypt/blockmode.c index 2fe900d9f..07c3ce57a 100644 --- a/beecrypt/blockmode.c +++ b/beecrypt/blockmode.c @@ -39,7 +39,7 @@ int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, while (nblocks > 0) { - bc->encrypt(bp, dst, src); + (void) bc->encrypt(bp, dst, src); dst += blockwords; src += blockwords; @@ -55,7 +55,7 @@ int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, while (nblocks > 0) { - bc->decrypt(bp, dst, src); + (void) bc->decrypt(bp, dst, src); dst += blockwords; src += blockwords; @@ -67,7 +67,6 @@ int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, int nblocks) { - /* assumes that every blockcipher's blocksize is a multiple of 32 bits */ register int blockwords = bc->blocksize >> 2; register uint32_t* fdback = bc->getfb(bp); @@ -78,7 +77,7 @@ int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, for (i = 0; i < blockwords; i++) dst[i] = src[i] ^ fdback[i]; - bc->encrypt(bp, dst, dst); + (void) bc->encrypt(bp, dst, dst); dst += blockwords; src += blockwords; @@ -90,7 +89,7 @@ int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, for (i = 0; i < blockwords; i++) dst[i] = src[i] ^ dst[i-blockwords]; - bc->encrypt(bp, dst, dst); + (void) bc->encrypt(bp, dst, dst); dst += blockwords; src += blockwords; @@ -118,7 +117,7 @@ int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, register uint32_t tmp; register int i; - bc->decrypt(bp, buf, src); + (void) bc->decrypt(bp, buf, src); for (i = 0; i < blockwords; i++) { @@ -139,7 +138,7 @@ int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, } #ifdef DYING -int blockEncrypt(const blockCipher* bc, blockCipherParam* bp, cipherMode mode, int blocks, uint32* dst, const uint32* src) +int blockEncrypt(const blockCipher* bc, blockCipherParam* bp, cipherMode mode, int blocks, uint32_t* dst, const uint32_t* src) { if (bc->mode) { @@ -157,7 +156,7 @@ int blockEncrypt(const blockCipher* bc, blockCipherParam* bp, cipherMode mode, i return -1; } -int blockDecrypt(const blockCipher* bc, blockCipherParam* bp, cipherMode mode, int blocks, uint32* dst, const uint32* src) +int blockDecrypt(const blockCipher* bc, blockCipherParam* bp, cipherMode mode, int blocks, uint32_t* dst, const uint32_t* src) { if (bc->mode) { diff --git a/beecrypt/blowfish.c b/beecrypt/blowfish.c index 1bdcb06bd..7056e122b 100644 --- a/beecrypt/blowfish.c +++ b/beecrypt/blowfish.c @@ -1,8 +1,6 @@ /* * Copyright (c) 1999, 2000, 2002 Virtual Unlimited B.V. * - * Author: Bob Deblier <bob@virtualunlimited.com> - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -41,8 +39,8 @@ #include "debug.h" /*!\addtogroup BC_blowfish_m - * \{ - */ + * \{ + */ /** */ diff --git a/beecrypt/blowfish.h b/beecrypt/blowfish.h index 51bd017dc..4634c2f54 100644 --- a/beecrypt/blowfish.h +++ b/beecrypt/blowfish.h @@ -85,7 +85,7 @@ int blowfishDecrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* src) /** \ingroup BC_blowfish_m */ /*@-exportlocal@*/ -BEECRYPTAPI +BEECRYPTAPI /*@observer@*/ uint32_t* blowfishFeedback(blowfishParam* bp) /*@*/; /*@=exportlocal@*/ diff --git a/beecrypt/dhaes.c b/beecrypt/dhaes.c index acc07aa1a..d341beefa 100644 --- a/beecrypt/dhaes.c +++ b/beecrypt/dhaes.c @@ -1,7 +1,24 @@ -/** \ingroup DH_m - * \file dhaes.c +/* + * Copyright (c) 2000, 2001, 2002 Virtual Unlimited, B.V. * - * DHAES, code. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/*!\file dhaes.c + * \brief DHAES encryption scheme. * * This code implements the encryption scheme from the paper: * @@ -27,25 +44,6 @@ * - DHAES(SHA-256, Blowfish, HMAC-SHA-256) */ -/* - * Copyright (c) 2000, 2001, 2002 Virtual Unlimited, B.V. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - #include "system.h" #include "dhaes.h" #include "dlsvdp-dh.h" @@ -55,9 +53,9 @@ int dhaes_pUsable(const dhaes_pParameters* params) { - int keybits = (params->hash->digestsize << 3); /* digestsize in bytes times 8 bits */ - int cipherkeybits = params->cipherkeybits; - int mackeybits = params->mackeybits; + size_t keybits = (params->hash->digestsize << 3); /* digestsize in bytes times 8 bits */ + size_t cipherkeybits = params->cipherkeybits; + size_t mackeybits = params->mackeybits; /* test if keybits is a multiple of 32 */ if ((keybits & 31) != 0) @@ -70,7 +68,7 @@ int dhaes_pUsable(const dhaes_pParameters* params) if (mackeybits == 0) { if (cipherkeybits == 0) - cipherkeybits = mackeybits = (((uint32_t)keybits) >> 1); + cipherkeybits = mackeybits = (keybits >> 1); else mackeybits = keybits - cipherkeybits; } @@ -229,7 +227,7 @@ static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mpnumber* privkey, co if (ctxt->hash.algo->digestsize > 0) { byte* mackey = digest; - byte* cipherkey = digest + (((uint32_t)(ctxt->mackeybits + 7)) >> 3); + byte* cipherkey = digest + ((ctxt->mackeybits + 7) >> 3); if ((rc = keyedHashFunctionContextSetup(&ctxt->mac, mackey, ctxt->mackeybits))) goto setup_end; diff --git a/beecrypt/dhaes.h b/beecrypt/dhaes.h index 654e492b1..4cdc1d32d 100644 --- a/beecrypt/dhaes.h +++ b/beecrypt/dhaes.h @@ -37,8 +37,8 @@ typedef struct const hashFunction* hash; const blockCipher* cipher; const keyedHashFunction* mac; - int cipherkeybits; - int mackeybits; + size_t cipherkeybits; + size_t mackeybits; } dhaes_pParameters; /** @@ -51,8 +51,8 @@ typedef struct hashFunctionContext hash; blockCipherContext cipher; keyedHashFunctionContext mac; - int cipherkeybits; - int mackeybits; + size_t cipherkeybits; + size_t mackeybits; } dhaes_pContext; #ifdef __cplusplus diff --git a/beecrypt/dldp.c b/beecrypt/dldp.c index 3d4d6b5df..364c69d2b 100644 --- a/beecrypt/dldp.c +++ b/beecrypt/dldp.c @@ -29,6 +29,10 @@ #include "mpprime.h" #include "debug.h" +/*!\addtogroup DL_m + * \{ + */ + /** */ static int dldp_pgoqGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, /*@out@*/ mpw* wksp) @@ -88,7 +92,7 @@ int dldp_pEqual(const dldp_p* a, const dldp_p* b) static int dldp_pValidate(const dldp_p* dp, randomGeneratorContext* rgc) /*@*/ { - register size_t size = dp->p.size; + register size_t size = dp->p.size; register mpw* temp = (mpw*) malloc((8*size+2) * sizeof(*temp)); if (temp) @@ -173,7 +177,6 @@ int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t /* * Generate parameters as described by IEEE P1363, A.16.1 */ - register size_t psize = MP_BITS_TO_WORDS(pbits + MP_WBITS - 1); register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(*temp)); @@ -201,6 +204,7 @@ int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t return 0; } + return -1; } @@ -438,7 +442,7 @@ int dldp_pgonGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, mpw* wksp) int dldp_pgonGenerator(dldp_p* dp, randomGeneratorContext* rgc) { - register size_t psize = dp->p.size; + register size_t psize = dp->p.size; register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(*temp)); if (temp) @@ -456,3 +460,6 @@ int dldp_pgonValidate(const dldp_p* dp, randomGeneratorContext* rgc) { return dldp_pValidate((const dldp_p*) dp, rgc); } + +/*!\} + */ diff --git a/beecrypt/dldp.h b/beecrypt/dldp.h index edc0972d3..6d1d60831 100644 --- a/beecrypt/dldp.h +++ b/beecrypt/dldp.h @@ -123,7 +123,7 @@ int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t /** */ BEECRYPTAPI /*@unused@*/ -int dldp_pgoqMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits) +int dldp_pgoqMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t bits) /*@modifies dp->p, dp->q, dp->r, dp->g, dp->n, rgc @*/; /** diff --git a/beecrypt/dlkp.h b/beecrypt/dlkp.h index de134403e..7755afbc3 100644 --- a/beecrypt/dlkp.h +++ b/beecrypt/dlkp.h @@ -1,6 +1,4 @@ /* - * <conformance statement for IEEE P1363 needed here> - * * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. * * This library is free software; you can redistribute it and/or diff --git a/beecrypt/dlsvdp-dh.c b/beecrypt/dlsvdp-dh.c index 1e2476d7a..cb89e1863 100644 --- a/beecrypt/dlsvdp-dh.c +++ b/beecrypt/dlsvdp-dh.c @@ -1,9 +1,3 @@ -/** \ingroup DL_m DH_m - * \file dlsvdp-dh.c - * - * Discrete Logarithm Secret Value Derivation Primite - Diffie Hellman, code. - */ - /* * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V. * @@ -23,6 +17,16 @@ * */ +/*!\file dlsvdp-dh.c + * \brief Diffie-Hellman algorithm. + * + * The IEEE P.1363 designation is: + * Discrete Logarithm Secret Value Derivation Primitive, Diffie-Hellman style. + * + * \author Bob Deblier <bob.deblier@pandora.be> + * \ingroup DL_m DL_dh_m + */ + #include "system.h" #include "dlsvdp-dh.h" #include "debug.h" diff --git a/beecrypt/dsa.c b/beecrypt/dsa.c index 3e724bab5..f591211d4 100644 --- a/beecrypt/dsa.c +++ b/beecrypt/dsa.c @@ -1,29 +1,6 @@ -/** \ingroup DSA_m - * \file dsa.c - * - * Digital Signature Algorithm signature scheme, code. - * - * DSA Signature: - * - Signing equation: - * - r = (g^k mod p) mod q and - * - s = (inv(k) * (h(m) + x*r)) mod q - * - Verifying equation: - * - check 0 < r < q and 0 < s < q - * - w = inv(s) mod q - * - u1 = (h(m)*w) mod q - * - u2 = (r*w) mod q - * - v = ((g^u1 * y^u2) mod p) mod q - * - check v == r - * - * For more information on this algorithm, see: - * NIST FIPS 186-1 - */ - /* * Copyright (c) 2001, 2002 Virtual Unlimited B.V. * - * Author: Bob Deblier <bob@virtualunlimited.com> - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -41,6 +18,29 @@ * */ +/*!\file dsa.c + * \brief Digital Signature Algorithm, as specified by NIST FIPS 186. + * + * FIPS 186 specifies the DSA algorithm as having a large prime \f$p\f$, + * a cofactor \f$q\f$ and a generator \f$g\f$ of a subgroup of + * \f$\mathds{Z}^{*}_p\f$ with order \f$q\f$. The private and public key + * values are \f$x\f$ and \f$y\f$ respectively. + * + * \author Bob Deblier <bob.deblier@pandora.be> + * \ingroup DL_m DL_dsa_m + * + * - Signing equation: + * - r = (g^k mod p) mod q and + * - s = (inv(k) * (h(m) + x*r)) mod q + * - Verifying equation: + * - check 0 < r < q and 0 < s < q + * - w = inv(s) mod q + * - u1 = (h(m)*w) mod q + * - u2 = (r*w) mod q + * - v = ((g^u1 * y^u2) mod p) mod q + * - check v == r + */ + #include "system.h" #include "dsa.h" #include "dldp.h" @@ -63,6 +63,7 @@ int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGen ptemp = (mpw*) malloc((5*psize+2) * sizeof(*ptemp)); if (ptemp == (mpw*) 0) return rc; + qtemp = (mpw*) malloc((14*qsize+11) * sizeof(*qtemp)); if (qtemp == (mpw*) 0) { diff --git a/beecrypt/dsa.h b/beecrypt/dsa.h index 2e4721d37..e03ffba6c 100644 --- a/beecrypt/dsa.h +++ b/beecrypt/dsa.h @@ -1,9 +1,3 @@ -/** \ingroup DSA_m - * \file dsa.h - * - * Digital Signature Algorithm signature scheme, header. - */ - /* * Copyright (c) 2001, 2002 Virtual Unlimited B.V. * @@ -23,6 +17,11 @@ * */ +/*!\file dsa.h + * \brief Digital Signature Algorithm, headers. + * \author Bob Deblier <bob.deblier@pandora.be> + * \ingroup DL_m DL_dsa_m + */ #ifndef _DSA_H #define _DSA_H diff --git a/beecrypt/elgamal.c b/beecrypt/elgamal.c index 30401dc56..549fcb753 100644 --- a/beecrypt/elgamal.c +++ b/beecrypt/elgamal.c @@ -1,10 +1,36 @@ -/** \ingroup ELGAMAL_m - * \file elgamal.c +/* + * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ElGamal signature scheme, code + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/*!\file elgamal.c + * \brief ElGamal algorithm. * - * This code implements two of the six variants described: + * For more information on this algorithm, see: + * "Handbook of Applied Cryptography" + * 11.5.2 "The ElGamal signature scheme", p. 454-459 * + * Two of the signature variants in Note 11.70 are described. + * + * \todo Explore the possibility of using simultaneous multiple exponentiation, + * as described in HAC, 14.87 (iii). + * + * \author Bob Deblier <bob.deblier@pandora.be> + * \ingroup DL_m DL_elgamal_m * - ElGamal Signature variant 1: (i.e. the standard version) * - Signing equation: * - r = g^k mod p and @@ -28,30 +54,6 @@ * - v2 = y^r * r^h(m) mod p * - Simultaneous multiple exponentiation verification: * - y^r * r^h(m) * g^(p-1-s) mod p = 1 (one of the exponents is significantly smaller, i.e. h(m)) - * - * For more information on this algorithm, see: - * "Handbook of Applied Cryptography" - * 11.5.2 "The ElGamal signature scheme", p. 454-459 - */ - -/* - * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V. - * - * Author: Bob Deblier <bob@virtualunlimited.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "system.h" @@ -217,3 +219,6 @@ int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const m } return 0; } + +/*!\} + */ diff --git a/beecrypt/elgamal.h b/beecrypt/elgamal.h index 11cadaa27..5cab708a0 100644 --- a/beecrypt/elgamal.h +++ b/beecrypt/elgamal.h @@ -1,9 +1,3 @@ -/** \ingroup ELGAMAL_m - * \file elgamal.h - * - * ElGamal signature scheme, header. - */ - /* * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. * @@ -23,6 +17,12 @@ * */ +/*!\file elgamal.h + * \brief ElGamal algorithm, headers. + * \author Bob Deblier <bob.deblier@pandora.be> + * \ingroup DL_m DL_elgamal_m + */ + #ifndef _ELGAMAL_H #define _ELGAMAL_H diff --git a/beecrypt/entropy.h b/beecrypt/entropy.h index 482d2b3ef..686d45922 100644 --- a/beecrypt/entropy.h +++ b/beecrypt/entropy.h @@ -21,7 +21,7 @@ * \brief Entropy sources, headers. * \author Bob Deblier <bob.deblier@pandora.be> * \ingroup ES_m ES_audio_m ES_dsp_m ES_random_m ES_urandom_m ES_tty_m - */ + */ #ifndef _ENTROPY_H #define _ENTROPY_H diff --git a/beecrypt/fips186.c b/beecrypt/fips186.c index 149761171..18b11ee73 100644 --- a/beecrypt/fips186.c +++ b/beecrypt/fips186.c @@ -112,7 +112,7 @@ int fips186Seed(fips186Param* fp, const byte* data, size_t size) /* convert to multi-precision integer, and add to the state */ if (os2ip(seed, FIPS186_STATE_SIZE, data, size) == 0) - mpadd(FIPS186_STATE_SIZE, fp->state, seed); + (void) mpadd(FIPS186_STATE_SIZE, fp->state, seed); } #ifdef _REENTRANT # if WIN32 @@ -169,12 +169,12 @@ int fips186Next(fips186Param* fp, byte* data, size_t size) memcpy(fp->param.data, fp->state, MP_WORDS_TO_BYTES(FIPS186_STATE_SIZE)); /* process the data */ sha1Process(&fp->param); - encodeInts(fp->param.h, fp->digest, 5); + (void) encodeInts(fp->param.h, fp->digest, 5); if (os2ip(dig, FIPS186_STATE_SIZE, fp->digest, 20) == 0) { /* set state to state + digest + 1 mod 2^512 */ - mpadd (FIPS186_STATE_SIZE, fp->state, dig); - mpaddw(FIPS186_STATE_SIZE, fp->state, 1); + (void) mpadd (FIPS186_STATE_SIZE, fp->state, dig); + (void) mpaddw(FIPS186_STATE_SIZE, fp->state, 1); } /* else shouldn't occur */ /* we now have 5 words of pseudo-random data */ diff --git a/beecrypt/hmac.c b/beecrypt/hmac.c index bc9695b0d..8512a3791 100644 --- a/beecrypt/hmac.c +++ b/beecrypt/hmac.c @@ -42,9 +42,8 @@ int hmacSetup(byte* kxi, byte* kxo, const hashFunction* hash, hashFunctionParam* param, const byte* key, size_t keybits) { - register int i, rc; - - size_t keybytes = (((uint32_t)keybits ) >> 3); + register int i; + size_t keybytes = keybits >> 3; /* if the key is too large, hash it first */ if (keybytes > hash->blocksize) @@ -93,7 +92,6 @@ int hmacReset(const byte* kxi, const hashFunction* hash, hashFunctionParam* para return -1; if (hash->update(param, kxi, hash->blocksize)) return -1; - return 0; } diff --git a/beecrypt/hmac.h b/beecrypt/hmac.h index ed23ee62f..7e888e845 100644 --- a/beecrypt/hmac.h +++ b/beecrypt/hmac.h @@ -39,19 +39,19 @@ extern "C" { */ BEECRYPTAPI int hmacSetup (byte* kxi, byte* kxo, const hashFunction* hash, hashFunctionParam* param, const byte* key, size_t keybits) - /*@modifies kxi, kxo */; + /*@modifies kxi, kxo, param */; /** */ BEECRYPTAPI int hmacReset (const byte* kxi, const hashFunction* hash, hashFunctionParam* param) - /*@modifies hp */; + /*@modifies param */; /** */ BEECRYPTAPI int hmacUpdate(const hashFunction* hash, hashFunctionParam* param, const byte* data, size_t size) - /*@modifies hp */; + /*@modifies param */; /** */ diff --git a/beecrypt/md5.c b/beecrypt/md5.c index c98838d54..743a0227c 100644 --- a/beecrypt/md5.c +++ b/beecrypt/md5.c @@ -180,12 +180,12 @@ int md5Update(md5Param* p, const byte* data, size_t size) mpw add[1]; mpsetw(1, add, size); mplshift(1, add, 3); - mpadd(1, p->length, add); + (void) mpadd(1, p->length, add); #elif (MP_WBITS == 32) mpw add[2]; mpsetw(2, add, size); mplshift(2, add, 3); - mpadd(2, p->length, add); + (void) mpadd(2, p->length, add); #else # error #endif diff --git a/beecrypt/mp.c b/beecrypt/mp.c index 78e487f61..3e20b6f09 100644 --- a/beecrypt/mp.c +++ b/beecrypt/mp.c @@ -497,7 +497,9 @@ int mpaddx(register size_t xsize, register mpw* xdata, register size_t ysize, re if (xsize > ysize) { register size_t diff = xsize - ysize; +/*@-evalorder@*/ return mpaddw(diff, xdata, (mpw) mpadd(ysize, xdata+diff, ydata)); +/*@=evalorder@*/ } else { @@ -558,7 +560,9 @@ int mpsubx(register size_t xsize, register mpw* xdata, register size_t ysize, re if (xsize > ysize) { register size_t diff = xsize - ysize; +/*@-evalorder@*/ return mpsubw(diff, xdata, (mpw) mpsub(ysize, xdata+diff, ydata)); +/*@=evalorder@*/ } else { @@ -802,6 +806,7 @@ mpw mpaddsqrtrc(register size_t size, register mpw* result, register const mpw* #ifndef ASM_MPSQR void mpsqr(register mpw* result, register size_t size, register const mpw* data) { + register mpw rc; register size_t n = size-1; /*@-mods@*/ @@ -810,9 +815,13 @@ void mpsqr(register mpw* result, register size_t size, register const mpw* data) if (n) { - *(--result) = mpsetmul(n, result, data, data[n]); + rc = mpsetmul(n, result, data, data[n]); + *(--result) = rc; while (--n) - *(--result) = mpaddmul(n, result, data, data[n]); + { + rc = mpaddmul(n, result, data, data[n]); + *(--result) = rc; + } } *(--result) = 0; @@ -972,13 +981,13 @@ void mplshift(register size_t size, register mpw* data, size_t count) if (words < size) { - register short lbits = (short) (count & (MP_WBITS-1)); + register unsigned short lbits = (unsigned short) (count & (MP_WBITS-1)); /* first do the shifting, then do the moving */ if (lbits != 0) { register mpw temp, carry = 0; - register short rbits = MP_WBITS - lbits; + register unsigned short rbits = MP_WBITS - lbits; register size_t i = size; while (i > words) @@ -1006,13 +1015,13 @@ void mprshift(register size_t size, register mpw* data, size_t count) if (words < size) { - register short rbits = (short) (count & (MP_WBITS-1)); + register unsigned short rbits = (unsigned short) (count & (MP_WBITS-1)); /* first do the shifting, then do the moving */ if (rbits != 0) { register mpw temp, carry = 0; - register short lbits = MP_WBITS - rbits; + register unsigned short lbits = MP_WBITS - rbits; register size_t i = 0; while (i < size-words) @@ -1039,7 +1048,7 @@ size_t mprshiftlsz(register size_t size, register mpw* data) { register mpw* slide = data+size-1; register size_t zwords = 0; /* counter for 'all zero bit' words */ - register short lbits, rbits = 0; /* counter for 'least significant zero' bits */ + register unsigned short lbits, rbits = 0; /* counter for 'least significant zero' bits */ register mpw temp, carry = 0; data = slide; @@ -1194,20 +1203,22 @@ mpw mpnmodw(mpw* result, size_t xsize, const mpw* xdata, mpw y, mpw* workspace) *rdata -= y; */ if (mpge(1, rdata, &y)) - mpsub(1, rdata, &y); + (void) mpsub(1, rdata, &y); while (qsize--) { q = mppndiv(rdata[0], rdata[1], y); +/*@-evalorder@*/ *workspace = mpsetmul(1, workspace+1, &y, q); +/*@=evalorder@*/ while (mplt(2, rdata, workspace)) { - mpsubx(2, workspace, 1, &y); + (void) mpsubx(2, workspace, 1, &y); /* q--; */ } - mpsub(2, rdata, workspace); + (void) mpsub(2, rdata, workspace); rdata++; } @@ -1226,20 +1237,22 @@ void mpnmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw mpcopy(xsize, rdata, xdata); if (mpge(ysize, rdata, ydata)) - mpsub(ysize, rdata, ydata); + (void) mpsub(ysize, rdata, ydata); while (qsize--) { q = mppndiv(rdata[0], rdata[1], msw); +/*@-evalorder@*/ *workspace = mpsetmul(ysize, workspace+1, ydata, q); +/*@=evalorder@*/ while (mplt(ysize+1, rdata, workspace)) { - mpsubx(ysize+1, workspace, ysize, ydata); + (void) mpsubx(ysize+1, workspace, ysize, ydata); q--; } - mpsub(ysize+1, rdata, workspace); + (void) mpsub(ysize+1, rdata, workspace); rdata++; } } @@ -1258,7 +1271,7 @@ void mpndivmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpcopy(xsize, result+1, xdata); if (mpge(ysize, result+1, ydata)) { - mpsub(ysize, result+1, ydata); + (void) mpsub(ysize, result+1, ydata); *(result++) = 1; } else @@ -1268,14 +1281,16 @@ void mpndivmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const { q = mppndiv(result[0], result[1], msw); +/*@-evalorder@*/ *workspace = mpsetmul(ysize, workspace+1, ydata, q); +/*@=evalorder@*/ while (mplt(ysize+1, result, workspace)) { - mpsubx(ysize+1, workspace, ysize, ydata); + (void) mpsubx(ysize+1, workspace, ysize, ydata); q--; } - mpsub(ysize+1, result, workspace); + (void) mpsub(ysize+1, result, workspace); *(result++) = q; } } @@ -1291,7 +1306,7 @@ void mpprint(register FILE * fp, register size_t size, register const mpw* data) while (size--) { #if (MP_WBITS == 32) - fprintf(fp, "%08x", *(data++)); + fprintf(fp, "%08x", (unsigned) *(data++)); #elif (MP_WBITS == 64) # if WIN32 fprintf(fp, "%016I64x", *(data++)); @@ -1305,7 +1320,7 @@ void mpprint(register FILE * fp, register size_t size, register const mpw* data) #endif } fprintf(fp, "\n"); - fflush(fp); + (void) fflush(fp); } #endif @@ -1319,7 +1334,7 @@ void mpprintln(register FILE * fp, register size_t size, register const mpw* dat while (size--) { #if (MP_WBITS == 32) - fprintf(fp, "%08x", *(data++)); + fprintf(fp, "%08x", (unsigned) *(data++)); #elif (MP_WBITS == 64) # if WIN32 fprintf(fp, "%016I64x", *(data++)); @@ -1333,7 +1348,7 @@ void mpprintln(register FILE * fp, register size_t size, register const mpw* dat #endif } fprintf(fp, "\n"); - fflush(fp); + (void) fflush(fp); } #endif @@ -1358,7 +1373,7 @@ int i2osp(byte *osdata, size_t ossize, const mpw* idata, size_t isize) mpw w = *(idata++); byte shift = MP_WBITS; - while (shift) + while (shift != 0) { shift -= 8; *(osdata++) = (byte)(w >> shift); @@ -1374,7 +1389,7 @@ int i2osp(byte *osdata, size_t ossize, const mpw* idata, size_t isize) return -1; } -int os2ip(mpw* idata, size_t isize, const byte* osdata, size_t ossize) +int os2ip(mpw* idata, size_t isize, const byte* osdata, /*@unused@*/ size_t ossize) { size_t required = MP_BYTES_TO_WORDS(isize + MP_WBYTES - 1); diff --git a/beecrypt/mp.h b/beecrypt/mp.h index 2a4a2c39d..e053dbaab 100644 --- a/beecrypt/mp.h +++ b/beecrypt/mp.h @@ -300,7 +300,7 @@ void mpsetx(size_t xsize, /*@out@*/ mpw* xdata, size_t ysize, const mpw* ydata) /** */ BEECRYPTAPI -int mpaddw(size_t xsize, mpw* xdata, mpw y) +int mpaddw(size_t size, mpw* xdata, mpw y) /*@modifies xdata @*/; /** @@ -318,7 +318,7 @@ int mpaddx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) /** */ BEECRYPTAPI -int mpsubw(size_t xsize, mpw* xdata, mpw y) +int mpsubw(size_t size, mpw* xdata, mpw y) /*@modifies xdata @*/; /** @@ -373,7 +373,7 @@ size_t mpbitcnt(size_t size, const mpw* data) */ /*@-exportlocal@*/ BEECRYPTAPI /*@unused@*/ -size_t mplszcnt(size_t xsize, const mpw* xdata) +size_t mplszcnt(size_t size, const mpw* data) /*@*/; /*@=exportlocal@*/ @@ -418,20 +418,20 @@ void mpsdivtwo(size_t size, mpw* data) /** */ BEECRYPTAPI -mpw mpsetmul (size_t size, /*@out@*/ mpw* result, const mpw* xdata, mpw y) +mpw mpsetmul (size_t size, /*@out@*/ mpw* result, const mpw* data, mpw y) /*@modifies result @*/; /** */ BEECRYPTAPI -mpw mpaddmul (size_t size, /*@out@*/ mpw* result, const mpw* xdata, mpw y) +mpw mpaddmul (size_t size, /*@out@*/ mpw* result, const mpw* data, mpw y) /*@modifies result @*/; /** */ /*@-exportlocal@*/ BEECRYPTAPI -mpw mpaddsqrtrc(size_t size, /*@out@*/ mpw* result, const mpw* xdata) +mpw mpaddsqrtrc(size_t size, /*@out@*/ mpw* result, const mpw* data) /*@modifies result @*/; /*@=exportlocal@*/ @@ -444,7 +444,7 @@ void mpmul(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, /** */ BEECRYPTAPI -void mpsqr(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata) +void mpsqr(/*@out@*/ mpw* result, size_t size, const mpw* data) /*@modifies result @*/; /** @@ -462,32 +462,32 @@ mpw mppndiv(mpw xhi, mpw xlo, mpw y) /** */ BEECRYPTAPI /*@unused@*/ -mpw mpnmodw(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, mpw y, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +mpw mpnmodw(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, mpw y, /*@out@*/ mpw* workspace) + /*@modifies result, workspace @*/; /** */ BEECRYPTAPI /*@unused@*/ -void mpnmod(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +void mpnmod(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* workspace) + /*@modifies result, workspace @*/; /** */ BEECRYPTAPI -void mpndivmod(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +void mpndivmod(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* workspace) + /*@modifies result, workspace @*/; /** */ BEECRYPTAPI /*@unused@*/ -void mpprint(/*@null@*/ FILE * fp, size_t xsize, /*@null@*/ const mpw* xdata) +void mpprint(/*@null@*/ FILE * fp, size_t size, /*@null@*/ const mpw* data) /*@globals fileSystem @*/ /*@modifies *fp, fileSystem @*/; /** */ BEECRYPTAPI /*@unused@*/ -void mpprintln(/*@null@*/ FILE * fp, size_t xsize, /*@null@*/ const mpw* xdata) +void mpprintln(/*@null@*/ FILE * fp, size_t size, /*@null@*/ const mpw* data) /*@globals fileSystem @*/ /*@modifies *fp, fileSystem @*/; diff --git a/beecrypt/mpbarrett.c b/beecrypt/mpbarrett.c index 942104680..b46150c78 100644 --- a/beecrypt/mpbarrett.c +++ b/beecrypt/mpbarrett.c @@ -111,8 +111,6 @@ void mpbcopy(mpbarrett* b, const mpbarrett* copy) b->modl = (mpw*) 0; b->mu = (mpw*) 0; } - else - {}; } /*@=nullstate =compdef @*/ @@ -175,7 +173,7 @@ void mpbsethex(mpbarrett* b, const char* hex) b->size = size; b->mu = b->modl+size; - hs2ip(b->modl, size, hex, len); + (void) hs2ip(b->modl, size, hex, len); /*@-nullpass@*/ /* temp may be NULL */ mpbmu_w(b, temp); @@ -394,7 +392,7 @@ void mpbsubmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysiz /* xsize and ysize must be less than or equal to b->size */ register size_t size = b->size; register mpw* temp = wksp + size*2+2; - + mpsetx(2*size, temp, xsize, xdata); if (mpsubx(2*size, temp, ysize, ydata)) /* if there's carry, i.e. the result would be negative, add the modulus */ (void) mpaddx(2*size, temp, size, b->modl); @@ -457,7 +455,7 @@ void mpbsqrmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result * and finally do the number of squarings in column three. * * This table can be used for K=2,3,4 and can be extended - * + * * \verbatim 0 : - | - | - @@ -495,7 +493,7 @@ static void mpbslide_w(const mpbarrett* b, size_t xsize, const mpw* xdata, /*@ou } /*@observer@*/ /*@unchecked@*/ -static byte mpbslide_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@*/ @@ -520,7 +518,7 @@ void mpbpowmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t psiz */ /* K == 4 for the first try */ - + size_t size = b->size; mpw temp = 0; @@ -570,7 +568,7 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp /* if temp is still zero, then we're trying to raise x to power zero, and result stays one */ if (temp) { - short l = 0, n = 0, count = MP_WBITS; + unsigned short l = 0, n = 0, count = MP_WBITS; /* first skip bits until we reach a one */ while (count != 0) @@ -589,15 +587,13 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp n <<= 1; n += bit; - + if (n != 0) { if (l != 0) l++; else if (bit != 0) l = 1; - else - {}; if (l == 4) { @@ -607,7 +603,7 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp mpbsqrmod_w(b, size, result, result, wksp); mpbmulmod_w(b, size, result, size, slide+mpbslide_mulg[n]*size, result, wksp); - + s = mpbslide_postsq[n]; while (s--) @@ -642,7 +638,7 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp while (s--) mpbsqrmod_w(b, size, result, result, wksp); } - } + } } /** @@ -692,7 +688,7 @@ void mpbtwopowmod_w(const mpbarrett* b, size_t psize, const mpw* pdata, mpw* res { /* always square */ mpbsqrmod_w(b, size, result, result, wksp); - + /* multiply by two if bit is 1 */ if (temp & MP_MSBMASK) { @@ -1102,14 +1098,14 @@ int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* r, int t, mpw* wksp) { /* * Small prime factor test: - * + * * Tables in mpspprod contain multi-precision integers with products of small primes * If the greatest common divisor of this product and the candidate is not one, then * the candidate has small prime factors, or is a small prime. Neither is acceptable when * we are looking for large probable primes =) * */ - + if (size > SMALL_PRIMES_PRODUCT_MAX) { /*@-globs@*/ diff --git a/beecrypt/mpbarrett.h b/beecrypt/mpbarrett.h index ff2debbfe..e1321a44b 100644 --- a/beecrypt/mpbarrett.h +++ b/beecrypt/mpbarrett.h @@ -89,7 +89,7 @@ void mpbsubone(const mpbarrett* b, mpw* result) /** */ BEECRYPTAPI /*@unused@*/ -void mpbneg(const mpbarrett* b, const mpw* xdata, mpw* result) +void mpbneg(const mpbarrett* b, const mpw* data, mpw* result) /*@modifies result @*/; /** @@ -121,7 +121,7 @@ void mpbrndinv_w(const mpbarrett* b, randomGeneratorContext* rc, /*@out@*/ mpw* /** */ BEECRYPTAPI -void mpbmod_w(const mpbarrett* b, const mpw* xdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) +void mpbmod_w(const mpbarrett* b, const mpw* data, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) /*@modifies result, wksp @*/; /** @@ -192,7 +192,7 @@ void mpbsm3powmod(const mpbarrett* b, const mpw*, const mpw*, const mpw*, const /** */ BEECRYPTAPI /*@unused@*/ -int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* rc, int t, /*@out@*/ mpw* wksp) +int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* r, int t, /*@out@*/ mpw* wksp) /*@modifies wksp @*/; /** diff --git a/beecrypt/mpnumber.c b/beecrypt/mpnumber.c index 9d1b16c8e..53962eee4 100644 --- a/beecrypt/mpnumber.c +++ b/beecrypt/mpnumber.c @@ -62,8 +62,6 @@ void mpnsize(mpnumber* n, size_t size) n->data = (mpw*) 0; n->size = 0; } - else - {}; } /*@=compdef @*/ @@ -130,8 +128,6 @@ void mpnset(mpnumber* n, size_t size, const mpw* data) n->data = (mpw*) 0; n->size = 0; } - else - {}; } void mpnsetw(mpnumber* n, mpw val) @@ -174,7 +170,7 @@ void mpnsethex(mpnumber* n, const char* hex) { n->size = size; - hs2ip(n->data, size, hex, len); + (void) hs2ip(n->data, size, hex, len); } else { n->size = 0; diff --git a/beecrypt/mpprime.c b/beecrypt/mpprime.c index 9ea68fd1c..c750573dd 100644 --- a/beecrypt/mpprime.c +++ b/beecrypt/mpprime.c @@ -1159,8 +1159,6 @@ void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t { mpsetlsb(s.size, s.modl); } - else - {}; if (cofactor == 2) { diff --git a/beecrypt/mpprime.h b/beecrypt/mpprime.h index a35d0966c..db965c125 100644 --- a/beecrypt/mpprime.h +++ b/beecrypt/mpprime.h @@ -55,14 +55,14 @@ int mppmilrab_w (const mpbarrett* p, randomGeneratorContext* rc, int t, /*@ou /** */ BEECRYPTAPI -void mpprnd_w (mpbarrett* p, randomGeneratorContext* rc, size_t size, int t, /*@null@*/ const mpnumber* f, /*@out@*/ mpw* wksp) +void mpprnd_w (mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, /*@null@*/ const mpnumber* f, /*@out@*/ mpw* wksp) /*@globals mpspprod @*/ /*@modifies p, rc, wksp @*/; /** */ BEECRYPTAPI -void mpprndsafe_w (mpbarrett* p, randomGeneratorContext* rc, size_t size, int t, /*@out@*/ mpw* wksp) +void mpprndsafe_w (mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, /*@out@*/ mpw* wksp) /*@globals mpspprod @*/ /*@modifies p, rc, wksp @*/; @@ -77,7 +77,7 @@ void mpprndcon_w (mpbarrett* p, randomGeneratorContext* rc, size_t, int, const /** */ BEECRYPTAPI -void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t size, int t, const mpbarrett* q, /*@null@*/ const mpnumber* f, mpnumber* r, int cofactor, /*@out@*/ mpw* wksp) +void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, const mpbarrett* q, /*@null@*/ const mpnumber* f, mpnumber* r, int cofactor, /*@out@*/ mpw* wksp) /*@globals mpspprod @*/ /*@modifies p, rc, r, wksp @*/; diff --git a/beecrypt/mtprng.c b/beecrypt/mtprng.c index 7e19280ee..aa3ef18ab 100644 --- a/beecrypt/mtprng.c +++ b/beecrypt/mtprng.c @@ -101,11 +101,11 @@ int mtprngSetup(mtprngParam* mp) return -1; } -int mtprngSeed(mtprngParam* mp, const uint32_t* data, int size) +int mtprngSeed(mtprngParam* mp, const uint32_t* data, size_t size) { if (mp) { - int needed = N+1; + size_t needed = N+1; uint32_t* dest = mp->state; #ifdef _REENTRANT @@ -152,7 +152,7 @@ int mtprngSeed(mtprngParam* mp, const uint32_t* data, int size) return -1; } -int mtprngNext(mtprngParam* mp, uint32_t* data, int size) +int mtprngNext(mtprngParam* mp, uint32_t* data, size_t size) { if (mp) { diff --git a/beecrypt/mtprng.h b/beecrypt/mtprng.h index 6d7d4902d..3c746d05b 100644 --- a/beecrypt/mtprng.h +++ b/beecrypt/mtprng.h @@ -89,7 +89,7 @@ int mtprngSetup (mtprngParam* mp) */ /*@-exportlocal@*/ BEECRYPTAPI -int mtprngSeed (mtprngParam* mp, const uint32_t* data, int size) +int mtprngSeed (mtprngParam* mp, const uint32_t* data, size_t size) /*@modifies mp @*/; /*@=exportlocal@*/ @@ -97,7 +97,7 @@ int mtprngSeed (mtprngParam* mp, const uint32_t* data, int size) */ /*@-exportlocal@*/ BEECRYPTAPI -int mtprngNext (mtprngParam* mp, uint32_t* data, int size) +int mtprngNext (mtprngParam* mp, uint32_t* data, size_t size) /*@modifies mp, data @*/; /*@=exportlocal@*/ diff --git a/beecrypt/rsa.h b/beecrypt/rsa.h index 8c741d61c..b227388fb 100644 --- a/beecrypt/rsa.h +++ b/beecrypt/rsa.h @@ -46,7 +46,7 @@ extern "C" { * @retval 0 on success, -1 on failure */ int rsapub(const rsapk* pk, const mpnumber* m, mpnumber* c) - /*@*/; + /*@modifies c */; /** * The raw RSA private key operation. @@ -63,7 +63,7 @@ extern "C" { */ BEECRYPTAPI /*@unused@*/ int rsapri (const rsakp* kp, const mpnumber* c, mpnumber* m) - /*@modifies c */; + /*@modifies m */; /** * The raw RSA private key operation, with Chinese Remainder Theorem. @@ -81,7 +81,7 @@ int rsapri (const rsakp* kp, const mpnumber* c, mpnumber* m) */ BEECRYPTAPI /*@unused@*/ int rsapricrt(const rsakp* kp, const mpnumber* c, mpnumber* m) - /*@modifies c */; + /*@modifies m */; /** * Verify if ciphertext \e c was encrypted from cleartext \e m diff --git a/beecrypt/rsakp.c b/beecrypt/rsakp.c index 6f27df426..db82fc767 100644 --- a/beecrypt/rsakp.c +++ b/beecrypt/rsakp.c @@ -33,13 +33,13 @@ * \{ */ -int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, int nsize) +int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t nsize) { /* * Generates an RSA Keypair for use with the Chinese Remainder Theorem */ - register size_t pqsize = ((uint32_t)(nsize+1)) >> 1; + register size_t pqsize = (nsize+1) >> 1; register mpw* temp = (mpw*) malloc((16*pqsize+6) * sizeof(*temp)); register int newn = 1; diff --git a/beecrypt/rsakp.h b/beecrypt/rsakp.h index fe45a1894..9e96100ad 100644 --- a/beecrypt/rsakp.h +++ b/beecrypt/rsakp.h @@ -50,7 +50,7 @@ extern "C" { /** */ BEECRYPTAPI /*@unused@*/ -int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, int nsize) +int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t nsize) /*@modifies kp, rgc @*/; /** diff --git a/beecrypt/sha1.c b/beecrypt/sha1.c index 529b26ddf..4f46bc8fd 100644 --- a/beecrypt/sha1.c +++ b/beecrypt/sha1.c @@ -33,6 +33,7 @@ /*!\addtogroup HASH_sha1_m * \{ + */ /** \ingroup HASH_sha1_m */ @@ -206,12 +207,12 @@ int sha1Update(register sha1Param* p, const byte* data, size_t size) mpw add[1]; mpsetw(1, add, size); mplshift(1, add, 3); - mpadd(1, p->length, add); + (void) mpadd(1, p->length, add); #elif (MP_WBITS == 32) mpw add[2]; mpsetw(2, add, size); mplshift(2, add, 3); - mpadd(2, p->length, add); + (void) mpadd(2, p->length, add); #else # error #endif diff --git a/beecrypt/sha1.h b/beecrypt/sha1.h index 2c2ba7bd8..547d941c3 100644 --- a/beecrypt/sha1.h +++ b/beecrypt/sha1.h @@ -1,9 +1,3 @@ -/** \ingroup HASH_sha1_m HASH_m - * \file sha1.h - * - * SHA-1 hash function, header. - */ - /* * Copyright (c) 1997, 1998, 1999, 2000, 2002 Virtual Unlimited B.V. * @@ -23,6 +17,12 @@ * */ +/*!\file sha1.h + * \brief SHA-1 hash function, headers. + * \author Bob Deblier <bob.deblier@pandora.be> + * \ingroup HASH_m HASH_sha1_m + */ + #ifndef _SHA1_H #define _SHA1_H diff --git a/beecrypt/sha256.c b/beecrypt/sha256.c index 1bbafcaac..62b2f7813 100644 --- a/beecrypt/sha256.c +++ b/beecrypt/sha256.c @@ -29,6 +29,10 @@ #include "endianness.h" #include "debug.h" +/*!\addtogroup HASH_sha256_m + * \{ + */ + /** */ /*@observer@*/ /*@unchecked@*/ @@ -90,13 +94,17 @@ void sha256Process(register sha256Param* p) #else w = p->data; t = 16; - while (t--) - *(w++) = swapu32(*w); + while (t--) { + temp = swapu32(*w); + *(w++) = temp; + } #endif t = 48; - while (t--) - *(w++) = sig1(w[-2]) + w[-7] + sig0(w[-15]) + w[-16]; + while (t--) { + temp = sig1(w[-2]) + w[-7] + sig0(w[-15]) + w[-16]; + *(w++) = temp; + } w = p->data; @@ -187,12 +195,12 @@ int sha256Update(register sha256Param* p, const byte* data, size_t size) mpw add[1]; mpsetw(1, add, size); mplshift(1, add, 3); - mpadd(1, p->length, add); + (void) mpadd(1, p->length, add); #elif (MP_WBITS == 32) mpw add[2]; mpsetw(2, add, size); mplshift(2, add, 3); - mpadd(2, p->length, add); + (void) mpadd(2, p->length, add); #else # error #endif @@ -304,3 +312,6 @@ int sha256Digest(register sha256Param* p, byte* data) (void) sha256Reset(p); return 0; } + +/*!\} + */ diff --git a/beecrypt/tests/beetest.c b/beecrypt/tests/beetest.c index fd74730f5..86ecd6adb 100644 --- a/beecrypt/tests/beetest.c +++ b/beecrypt/tests/beetest.c @@ -27,7 +27,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" @@ -37,7 +37,7 @@ #include "rsa.h" #include "sha1.h" #include "sha256.h" -#include "mp32.h" +#include "mp.h" #if HAVE_STDLIB_H # include <stdlib.h> @@ -54,14 +54,21 @@ #include <stdio.h> +/*@unchecked@*/ /*@observer@*/ static const char* dsa_p = "8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291"; +/*@unchecked@*/ /*@observer@*/ static const char* dsa_q = "c773218c737ec8ee993b4f2ded30f48edace915f"; +/*@unchecked@*/ /*@observer@*/ static const char* dsa_g = "626d027839ea0a13413163a55b4cb500299d5522956cefcb3bff10f399ce2c2e71cb9de5fa24babf58e5b79521925c9cc42e9f6f464b088cc572af53e6d78802"; +/*@unchecked@*/ /*@observer@*/ static const char* dsa_x = "2070b3223dba372fde1c0ffc7b2e3b498b260614"; +/*@unchecked@*/ /*@observer@*/ static const char* dsa_y = "19131871d75b1612a819f29d78d1b0d7346f7aa77bb62a859bfd6c5675da9d212d3a36ef1672ef660b8c7c255cc0ec74858fba33f44c06699630a76b030ee333"; +/*@unchecked@*/ /*@observer@*/ static const char* elg_n = "8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80290"; -int testVectorInvMod(const dlkp_p* keypair) +static int testVectorInvMod(const dlkp_p* keypair) + /*@*/ { randomGeneratorContext rngc; @@ -69,41 +76,43 @@ int testVectorInvMod(const dlkp_p* keypair) { register int rc; - register uint32 size = keypair->param.p.size; - register uint32* temp = (uint32*) malloc((8*size+6) * sizeof(uint32)); + register size_t size = keypair->param.p.size; + register mpw* temp = (mpw*) malloc((8*size+6) * sizeof(*temp)); - 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); + rc = mpisone(size, temp); free(temp); - randomGeneratorContextFree(&rngc); + (void) randomGeneratorContextFree(&rngc); return rc; } return -1; } -int testVectorExpMod(const dlkp_p* keypair) +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); + mpbnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y); - rc = mp32eqx(y.size, y.data, keypair->y.size, keypair->y.data); + rc = mpeqx(y.size, y.data, keypair->y.size, keypair->y.data); - mp32nfree(&y); + mpnfree(&y); return rc; } -int testVectorElGamalV1(const dlkp_p* keypair) +static int testVectorElGamalV1(const dlkp_p* keypair) + /*@*/ { int rc = 0; @@ -111,30 +120,31 @@ 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); + (void) rngc.rng->next(rngc.param, digest.data, digest.size); - elgv1sign(&keypair->param.p, &keypair->param.n, &keypair->param.g, &rngc, &digest, &keypair->x, &r, &s); + (void) elgv1sign(&keypair->param.p, &keypair->param.n, &keypair->param.g, &rngc, &digest, &keypair->x, &r, &s); 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); + (void) randomGeneratorContextFree(&rngc); } return rc; } -int testVectorElGamalV3(const dlkp_p* keypair) +static int testVectorElGamalV3(const dlkp_p* keypair) + /*@*/ { int rc = 0; @@ -142,30 +152,31 @@ 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); + (void) rngc.rng->next(rngc.param, digest.data, digest.size); - elgv3sign(&keypair->param.p, &keypair->param.n, &keypair->param.g, &rngc, &digest, &keypair->x, &r, &s); + (void) elgv3sign(&keypair->param.p, &keypair->param.n, &keypair->param.g, &rngc, &digest, &keypair->x, &r, &s); 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); + (void) randomGeneratorContextFree(&rngc); } return rc; } -uint32 keyValue[] = +/*@unchecked@*/ /*@observer@*/ +static uint32_t keyValue[] = { 0x00010203, 0x04050607, @@ -185,14 +196,17 @@ uint32 keyValue[] = 0x3c3d3e3f }; -void testBlockInit(uint8* block, int length) +static void testBlockInit(uint8_t* block, int length) + /*@modifies block @*/ { register int i; for (i = 1; i <= length; i++) - *(block++) = (uint8) i; + *(block++) = (uint8_t) i; } -void testBlockCiphers() +static void testBlockCiphers(void) + /*@globals fileSystem @*/ + /*@modifies fileSystem @*/ { int i, k; @@ -204,12 +218,12 @@ void testBlockCiphers() if (tmp) { - uint32 blockwords = tmp->blocksize >> 2; + size_t blockwords = tmp->blocksize >> 2; - uint32* src_block = (uint32*) malloc(2 * blockwords * sizeof(uint32)); - uint32* enc_block = (uint32*) malloc(2 * blockwords * sizeof(uint32)); - uint32* dec_block = (uint32*) malloc(2 * blockwords * sizeof(uint32)); - uint32* spd_block = (uint32*) malloc(1024 * 1024 * blockwords * sizeof(uint32)); + mpw* src_block = (mpw*) malloc(2 * blockwords * sizeof(*src_block)); + mpw* enc_block = (mpw*) malloc(2 * blockwords * sizeof(*enc_block)); + mpw* dec_block = (mpw*) malloc(2 * blockwords * sizeof(*dec_block)); + mpw* spd_block = (mpw*) malloc(1024 * 1024 * blockwords * sizeof(*spd_block)); void* encrypt_param = (void*) malloc(tmp->paramsize); void* decrypt_param = (void*) malloc(tmp->paramsize); @@ -222,26 +236,26 @@ void testBlockCiphers() if (tmp->setup(encrypt_param, keyValue, k, ENCRYPT) < 0) { printf("failed\n"); - continue; + /*@innercontinue@*/ continue; } printf("ok\n"); printf(" setup decrypt (%d bits key): ", k); if (tmp->setup(decrypt_param, keyValue, k, DECRYPT) < 0) { printf("failed\n"); - continue; + /*@innercontinue@*/ continue; } printf("ok\n"); printf(" encrypt/decrypt test block: "); - testBlockInit((uint8*) src_block, tmp->blocksize >> 2); + testBlockInit((uint8_t*) src_block, tmp->blocksize >> 2); - blockEncrypt(tmp, encrypt_param, CBC, 2, enc_block, src_block); - blockDecrypt(tmp, decrypt_param, CBC, 2, dec_block, enc_block); + (void) blockEncryptCBC(tmp, encrypt_param, 2, enc_block, src_block); + (void) blockDecryptCBC(tmp, decrypt_param, 2, dec_block, enc_block); if (memcmp(dec_block, src_block, tmp->blocksize >> 2)) { printf("failed\n"); - continue; + /*@innercontinue@*/ continue; } printf("ok\n"); printf(" speed measurement:\n"); @@ -254,7 +268,7 @@ void testBlockCiphers() #if HAVE_TIME_H tstart = clock(); #endif - blockEncrypt(tmp, encrypt_param, ECB, 1024 * 1024, spd_block, spd_block); + (void) blockEncryptECB(tmp, encrypt_param, 1024 * 1024, spd_block, spd_block); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -263,7 +277,7 @@ void testBlockCiphers() #if HAVE_TIME_H tstart = clock(); #endif - blockDecrypt(tmp, decrypt_param, ECB, 1024 * 1024, spd_block, spd_block); + (void) blockDecryptECB(tmp, decrypt_param, 1024 * 1024, spd_block, spd_block); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -272,7 +286,7 @@ void testBlockCiphers() #if HAVE_TIME_H tstart = clock(); #endif - blockEncrypt(tmp, encrypt_param, CBC, 1024 * 1024, spd_block, spd_block); + (void) blockEncryptCBC(tmp, encrypt_param, 1024 * 1024, spd_block, spd_block); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -281,7 +295,7 @@ void testBlockCiphers() #if HAVE_TIME_H tstart = clock(); #endif - blockDecrypt(tmp, decrypt_param, CBC, 1024 * 1024, spd_block, spd_block); + (void) blockDecrypt(tmp, decrypt_param, CBC, 1024 * 1024, spd_block, spd_block); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; @@ -299,11 +313,13 @@ void testBlockCiphers() } } -void testHashFunctions() +static void testHashFunctions(void) + /*@globals fileSystem @*/ + /*@modifies fileSystem @*/ { int i, j; - uint8* data = (uint8*) malloc(32 * 1024 * 1024); + uint8_t* data = (uint8_t*) malloc(32 * 1024 * 1024); if (data) { @@ -321,9 +337,9 @@ void testHashFunctions() double ttime; clock_t tstart, tstop; #endif - mp32number digest; + mpnumber digest; - mp32nzero(&digest); + mpnzero(&digest); printf(" %s:\n", tmp->name); @@ -335,8 +351,8 @@ void testHashFunctions() tstart = clock(); #endif - hashFunctionContextUpdate(&hfc, data, 32 * 1024 * 1024); - hashFunctionContextDigest(&hfc, &digest); + (void) hashFunctionContextUpdate(&hfc, data, 32 * 1024 * 1024); + (void) hashFunctionContextDigest(&hfc, &digest); #if HAVE_TIME_H tstop = clock(); @@ -345,36 +361,41 @@ void testHashFunctions() #endif } - hashFunctionContextFree(&hfc); + (void) hashFunctionContextFree(&hfc); } - mp32nfree(&digest); + mpnfree(&digest); } } } } -void testExpMods() +static void testExpMods(void) + /*@globals fileSystem @*/ + /*@modifies fileSystem @*/ { + /*@unchecked@*/ /*@observer@*/ static const char* p_512 = "ffcf0a0767f18f9b659d92b9550351430737c3633dc6ae7d52445d937d8336e07a7ccdb119e9ab3e011a8f938151230e91187f84ac05c3220f335193fc5e351b"; + /*@unchecked@*/ /*@observer@*/ static const char* p_768 = "f9c3dc0b8e199094e3e69386e01de863908348196d6ad2557065e6ba36d10412579f394d1114c954ee647c84551d52f214e1e1682a75e7074b91085cfaf20b2888aa056bf760948a0b678bc253633eccfca86556ddb90f000ef93041b0d53171"; + /*@unchecked@*/ /*@observer@*/ static const char* p_1024 = "c615c47a56b47d869010256171ab164525f2ef4b887a4e0cdfc87043a9dd8894f2a18fa56729448e700f4b7420470b61257d11ecefa9ff518dc9fed5537ec6a9665ba73c948674320ff61b29c4cfa61e5baf47dfc1b80939e1bffb51787cc3252c4d1190a7f13d1b0f8d4aa986571ce5d4de5ecede1405e9bc0b5bf040a46d99"; randomGeneratorContext rngc; - mp32barrett p; - mp32number tmp; - mp32number g; - mp32number x; - mp32number y; + mpbarrett p; + mpnumber tmp; + mpnumber g; + mpnumber x; + mpnumber y; - mp32bzero(&p); - mp32nzero(&g); - mp32nzero(&x); - mp32nzero(&y); - mp32nzero(&tmp); + mpbzero(&p); + mpnzero(&g); + mpnzero(&x); + mpnzero(&y); + mpnzero(&tmp); if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) { @@ -386,94 +407,96 @@ void testExpMods() printf("Timing modular exponentiations:\n"); printf(" (512 bits ^ 512 bits) mod 512 bits:"); - mp32nsethex(&tmp, p_512); - mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpnsethex(&tmp, p_512); + mpbset(&p, tmp.size, tmp.data); + mpnsize(&g, p.size); + mpnsize(&x, p.size); + 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; printf(" 100x in %.3f seconds\n", ttime); #endif printf(" (768 bits ^ 768 bits) mod 768 bits:"); - mp32nsethex(&tmp, p_768); - mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpnsethex(&tmp, p_768); + mpbset(&p, tmp.size, tmp.data); + mpnsize(&g, p.size); + mpnsize(&x, p.size); + 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; printf(" 100x in %.3f seconds\n", ttime); #endif printf(" (1024 bits ^ 1024 bits) mod 1024 bits:"); - mp32nsethex(&tmp, p_1024); - mp32bset(&p, tmp.size, tmp.data); - mp32nsize(&g, p.size); - mp32nsize(&x, p.size); - mp32bnrnd(&p, &rngc, &g); - mp32bnrnd(&p, &rngc, &x); + mpnsethex(&tmp, p_1024); + mpbset(&p, tmp.size, tmp.data); + mpnsize(&g, p.size); + mpnsize(&x, p.size); + 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; printf(" 100x in %.3f seconds\n", ttime); #endif /* now run a test with x having 160 bits */ - mp32nsize(&x, 5); - rngc.rng->next(rngc.param, x.data, x.size); + mpnsize(&x, 5); + (void) rngc.rng->next(rngc.param, x.data, x.size); printf(" (1024 bits ^ 160 bits) mod 1024 bits:"); #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; printf(" 100x in %.3f seconds\n", ttime); #endif - mp32bfree(&p); - mp32nfree(&g); - mp32nfree(&x); - mp32nfree(&y); - mp32nfree(&tmp); + mpbfree(&p); + mpnfree(&g); + mpnfree(&x); + mpnfree(&y); + mpnfree(&tmp); - randomGeneratorContextFree(&rngc); + (void) randomGeneratorContextFree(&rngc); } else printf("random generator setup problem\n"); } -void testRSA() +static void testRSA(void) + /*@globals fileSystem @*/ + /*@modifies fileSystem @*/ { randomGeneratorContext rngc; - mp32number hm, s; + mpnumber hm, s; rsakp kp; - mp32nzero(&hm); - mp32nzero(&s); + mpnzero(&hm); + mpnzero(&s); printf("Timing RSA:\n"); - rsakpInit(&kp); + (void) rsakpInit(&kp); if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) { @@ -489,15 +512,15 @@ void testRSA() #if HAVE_TIME_H tstart = clock(); #endif - rsakpMake(&kp, &rngc, (1024 >> 5)); + (void) rsakpMake(&kp, &rngc, (1024 >> 5)); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; printf(" done in %.3f seconds\n", ttime); #endif - mp32nsize(&hm, 4); - rngc.rng->next(rngc.param, hm.data, hm.size); + mpnsize(&hm, 4); + (void) rngc.rng->next(rngc.param, hm.data, hm.size); printf(" RSA sign:"); #if HAVE_TIME_H @@ -505,7 +528,7 @@ void testRSA() #endif for (i = 0; i < 100; i++) { - rsapricrt(&kp, &hm, &s); + (void) rsapricrt(&kp, &hm, &s); } #if HAVE_TIME_H tstop = clock(); @@ -519,7 +542,7 @@ void testRSA() #endif for (i = 0; i < 1000; i++) { - rsavrfy((rsapk*) &kp, &hm, &s); + (void) rsavrfy((rsapk*) &kp, &hm, &s); } #if HAVE_TIME_H tstop = clock(); @@ -527,24 +550,26 @@ void testRSA() printf(" 1000x in %.3f seconds\n", ttime); #endif - rsakpFree(&kp); - randomGeneratorContextFree(&rngc); + (void) rsakpFree(&kp); + (void) randomGeneratorContextFree(&rngc); } } -void testDLAlgorithms() +static void testDLAlgorithms(void) + /*@globals fileSystem @*/ + /*@modifies fileSystem @*/ { randomGeneratorContext rngc; - mp32number hm, r, s; + mpnumber hm, r, s; dldp_p dp; dlkp_p kp; - mp32nzero(&hm); - mp32nzero(&r); - mp32nzero(&s); + mpnzero(&hm); + mpnzero(&r); + mpnzero(&s); - dldp_pInit(&dp); - dlkp_pInit(&kp); + (void) dldp_pInit(&dp); + (void) dlkp_pInit(&kp); printf("Timing Discrete Logarithm algorithms:\n"); @@ -560,27 +585,27 @@ void testDLAlgorithms() #if HAVE_TIME_H tstart = clock(); #endif - dldp_pgoqMake(&dp, &rngc, 1024 >> 5, 160 >> 5, 1); + (void) dldp_pgoqMake(&dp, &rngc, 1024 >> 5, 160 >> 5, 1); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; printf(" done in %.3f seconds\n", ttime); #endif - dlkp_pInit(&kp); + (void) dlkp_pInit(&kp); printf(" generating keypair\n"); #if HAVE_TIME_H tstart = clock(); #endif - dlkp_pPair(&kp, &rngc, &dp); + (void) dlkp_pPair(&kp, &rngc, &dp); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; printf(" done in %.3f seconds\n", ttime); #endif - mp32nsize(&hm, 5); - rngc.rng->next(rngc.param, hm.data, hm.size); + mpnsize(&hm, 5); + (void) rngc.rng->next(rngc.param, hm.data, hm.size); printf(" DSA sign:"); #if HAVE_TIME_H @@ -588,7 +613,7 @@ void testDLAlgorithms() #endif for (i = 0; i < 100; i++) { - dsasign(&kp.param.p, &kp.param.q, &kp.param.g, &rngc, &hm, &kp.x, &r, &s); + (void) dsasign(&kp.param.p, &kp.param.q, &kp.param.g, &rngc, &hm, &kp.x, &r, &s); } #if HAVE_TIME_H tstop = clock(); @@ -602,33 +627,35 @@ void testDLAlgorithms() #endif for (i = 0; i < 100; i++) { - dsavrfy(&kp.param.p, &kp.param.q, &kp.param.g, &hm, &kp.y, &r, &s); + (void) dsavrfy(&kp.param.p, &kp.param.q, &kp.param.g, &hm, &kp.y, &r, &s); } #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; printf(" 100x in %.3f seconds\n", ttime); #endif - dlkp_pFree(&kp); - dldp_pFree(&dp); + (void) dlkp_pFree(&kp); + (void) dldp_pFree(&dp); printf(" generating P (1024 bits) Q (768 bits) G with order (P-1)\n"); #if HAVE_TIME_H tstart = clock(); #endif - dldp_pgonMake(&dp, &rngc, 1024 >> 5, 768 >> 5); + (void) dldp_pgonMake(&dp, &rngc, 1024 >> 5, 768 >> 5); #if HAVE_TIME_H tstop = clock(); ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; printf(" done in %.3f seconds\n", ttime); #endif - dldp_pFree(&dp); + (void) dldp_pFree(&dp); - randomGeneratorContextFree(&rngc); + (void) randomGeneratorContextFree(&rngc); } } -int main() +int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[]) + /*@globals fileSystem @*/ + /*@modifies fileSystem @*/ { int i, j; diff --git a/beecrypt/types.h.in b/beecrypt/types.h.in index 3d4347e63..aa583090a 100644 --- a/beecrypt/types.h.in +++ b/beecrypt/types.h.in @@ -100,7 +100,7 @@ typedef int64_t javalong; typedef uint16_t javachar; -#define MP_WBITS 32 +#define MP_WBITS 32U #if (MP_WBITS == 64) typedef uint64_t mpw; |