beecrypt-3.0.0 merge: splint checks.
authorjbj <devnull@localhost>
Tue, 29 Apr 2003 08:15:16 +0000 (08:15 +0000)
committerjbj <devnull@localhost>
Tue, 29 Apr 2003 08:15:16 +0000 (08:15 +0000)
CVS patchset: 6787
CVS date: 2003/04/29 08:15:16

42 files changed:
beecrypt/.splintrc
beecrypt/aes.c
beecrypt/aes.h
beecrypt/base64.c
beecrypt/base64.h
beecrypt/beecrypt.c
beecrypt/beecrypt.h
beecrypt/blockmode.c
beecrypt/blowfish.c
beecrypt/blowfish.h
beecrypt/dhaes.c
beecrypt/dhaes.h
beecrypt/dldp.c
beecrypt/dldp.h
beecrypt/dlkp.h
beecrypt/dlsvdp-dh.c
beecrypt/dsa.c
beecrypt/dsa.h
beecrypt/elgamal.c
beecrypt/elgamal.h
beecrypt/entropy.h
beecrypt/fips186.c
beecrypt/hmac.c
beecrypt/hmac.h
beecrypt/md5.c
beecrypt/mp.c
beecrypt/mp.h
beecrypt/mpbarrett.c
beecrypt/mpbarrett.h
beecrypt/mpnumber.c
beecrypt/mpprime.c
beecrypt/mpprime.h
beecrypt/mtprng.c
beecrypt/mtprng.h
beecrypt/rsa.h
beecrypt/rsakp.c
beecrypt/rsakp.h
beecrypt/sha1.c
beecrypt/sha1.h
beecrypt/sha256.c
beecrypt/tests/beetest.c
beecrypt/types.h.in

index 6fb384bd9421edfb77ba019ff997d26bc1de0a47..64c80d55c57c8732b109a7a1f44f2711bb6a764a 100644 (file)
@@ -3,7 +3,7 @@
 #+partial
 +forcehints
 
--warnunixlib
+#-warnunixlib
 -warnposix
 
 +unixlib
 # --- in progress
 #+bounds
 -bufferoverflowhigh
+-aliasunique
+-mayaliasunique
+-elseifcomplete
+-exportheader
+-exportheadervar
+-exportlocal
+-fcnuse
+-typeuse
+-varuse
+-compdef
+-noeffectuncon
+-whileempty
 
 # --- not-yet at strict level
 -exportconst           # 4
index ccc29bc57612f6d386b38a7710bb4594766833ca..837c6db64de45daeadc29156bc53967549eae261 100644 (file)
@@ -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;
 }
-
 /*!\}
  */
index f3fbda900ada933c3f4256926472cfb17970e806..253aff2d6c5a475806c7f83d156a79539c4bfcd8 100644 (file)
@@ -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
index 9efe0287cb7cf2411cad46addb5a75b65ffb456e..07150a3e57efffcaef429132f4de66d0f35b74b1 100644 (file)
@@ -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;
 }
index b6d2df9b7db6c1783bf7f715b0e41d0c4e122ed3..139b3b54292b65cf7c09ed9cd332e3886dd85949 100644 (file)
@@ -17,7 +17,7 @@
  *
  */
 
-/*!\file base64.h      
+/*!\file base64.h
  * \brief Base64 encoding and decoding, headers.
  * \author Bob Deblier <bob@virtualunlimited.com>
  */
index ced52e6faf0bcaf6c8e85a1818b9448d60c3a80e..a850d702cbb21343911bc3ff78175b65430fa4b4 100644 (file)
@@ -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;
 }
 
index d373b79bbd0e94120231764e5b529af15f2bfe66..b709581a2d7b3a2bbb9f680d4d3f883b921538e9 100644 (file)
@@ -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
  */
index 2fe900d9ffd744f4b47a4d5c29d6a2b2c01e0936..07c3ce57ab47eaec874315dfcd7f0c1e10d2b0a2 100644 (file)
@@ -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)
        {
index 1bdcb06bdbea10d227916bf29cc3c98d45890d01..7056e122b91fc9a7de94dcff1f6f0d4ed9d03b00 100644 (file)
@@ -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
- * \{          
- */            
+ * \{
+ */
 
 /**
  */
index 51bd017dcf182494864f5cd6c017bae742c0a674..4634c2f54b938d0121ed943a6d447f13af40a472 100644 (file)
@@ -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@*/
index acc07aa1ae546006636f1f225d8ccab25eb04df7..d341beefadf1d691d01f34bfef532b64dff39dca 100644 (file)
@@ -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:
  *
  *     - 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;
index 654e492b15c9a5b5b2fa20c5e71db05a9f316d1d..4cdc1d32d1b43be06e7486f4f6954a15aeff8e8f 100644 (file)
@@ -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
index 3d4d6b5dfe8cfdc606bd4e006fa612d8d4a14d24..364c69d2b025cba3286f9e6d61672731067dfe41 100644 (file)
 #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);
 }
+
+/*!\}
+ */
index edc0972d3cd9784422d2936e451bad8810bb2f8f..6d1d60831f19cf68fa86173dc9bca812d2fdc0a2 100644 (file)
@@ -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 @*/;
 
 /**
index de134403e9752d90981ed4d2d504a0a9b2bf5044..7755afbc39d6f0541125f398afbbf5a81eab67d4 100644 (file)
@@ -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
index 1e2476d7a7d340395aaf1edfaf683af7731edc9c..cb89e1863f1023e52639cc77a35a3eba8da820b8 100644 (file)
@@ -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.
  *
  *
  */
 
+/*!\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"
index 3e724bab5c626ccd68ecc733e2aae1aae7905979..f591211d41319f312ad9ded8682cfa303107c756 100644 (file)
@@ -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
  *
  */
  
+/*!\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)
        {
index 2e4721d37408bf23ab295b4620b2736697a46b4f..e03ffba6c91a6943df20b593a435471eb1090284 100644 (file)
@@ -1,9 +1,3 @@
-/** \ingroup DSA_m
- * \file dsa.h
- *
- * Digital Signature Algorithm signature scheme, header.
- */
-
 /*
  * Copyright (c) 2001, 2002 Virtual Unlimited B.V.
  *
  *
  */
 
+/*!\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
 
index 30401dc563824f759604d44ae27f523b8771e7f0..549fcb7536d9edc54258edae85f36a2f39ab1366 100644 (file)
@@ -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
  *   - 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;
 }
+
+/*!\}
+ */
index 11cadaa27e9ef0706df78bc2c65d23aae1d0a72e..5cab708a09deaa30e393bced39a43eda5f32c026 100644 (file)
@@ -1,9 +1,3 @@
-/** \ingroup ELGAMAL_m
- * \file elgamal.h
- *
- * ElGamal signature scheme, header.
- */
-
 /*
  * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V.
  *
  *
  */
 
+/*!\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
 
index 482d2b3ef326ed8a40b3e6c3c007320d808ba871..686d4592288af5ddde53c59b7c47a0235ec1e5cc 100644 (file)
@@ -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
index 149761171caa76f394d4289f3d230445208ed3dc..18b11ee736ee4741b87cd0b553b7f6c969670be2 100644 (file)
@@ -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 */
index bc9695b0dbe7f9d97a6733f389bc07ee91aa2939..8512a3791d4a1ec72f4c97609bd0bd181311cf36 100644 (file)
@@ -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;
 }
 
index ed23ee62fcf39e9c4a016a0cb676a775ee400c6a..7e888e845a7299ee5d55c09d58a0bba732784d02 100644 (file)
@@ -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 */;
 
 /**
  */
index c98838d54f5691d3f81768c73c2935ad546d55f2..743a0227cf0b0c92a6153e6b97abee10a3285d6f 100644 (file)
@@ -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
index 78e487f61c27bbb3bcc03d9a8204f4fcae8ab3f5..3e20b6f097ba6d7ec99e78c791e4fa0d6c9768e5 100644 (file)
@@ -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);
 
index 2a4a2c39df88978969be1da046bd9182306b0d4a..e053dbaab404e315c58609ae22da12034566a680 100644 (file)
@@ -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 @*/;
 
index 942104680bf9b26ef15fe537ffba25dd0e4e7c93..b46150c786ad82a7d6f6ddba878a80dd109e7c39 100644 (file)
@@ -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@*/
index ff2debbfe9c15359152c2d4a58da376db3cfc0d5..e1321a44b7e8d0b7dd487339edb2802a662dbb5e 100644 (file)
@@ -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 @*/;
 
 /**
index 9d1b16c8e6e3265652f82238305c5780426f6a4b..53962eee421f4e2387d28ef6fc7b2d7208bf9cdc 100644 (file)
@@ -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;
index 9ea68fd1c51e2548d75f4e5a4b53594c28ac4f39..c750573dd7f6c7fe2bb7cd8fb949b42ed15bf296 100644 (file)
@@ -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)
                        {
index a35d0966c0844f6e800c1b5f4fbf60a1542e8cd1..db965c12535894b61e9bac46135208f7fc072f7d 100644 (file)
@@ -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 @*/;
 
index 7e19280ee5dfe4e8d1dbafb508cd5e16363daf76..aa3ef18abb586ea272b3a5a996250e332cf77405 100644 (file)
@@ -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)
        {
index 6d7d4902dbcadcecbb46f73d6ef38f5a0731208b..3c746d05b76ceabb47f5ebc45e21522d68fe17f6 100644 (file)
@@ -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@*/
 
index 8c741d61c372d24c14169e80d2d0affb68fb19df..b227388fb71b98f40a80e6d711b3ae01361dc876 100644 (file)
@@ -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
index 6f27df426c4b28eb166f779787adf51293e5b666..db82fc7676ea15c64881d3ca8ca4803bb8b7c775 100644 (file)
  * \{
  */
 
-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;
 
index fe45a189413aab09d3927c80a4e6fb30a4322f24..9e96100ad5dc13162742431524a0f848105e98e8 100644 (file)
@@ -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 @*/;
 
 /**
index 529b26ddf9f90cde4e69e0380dad46392a6b4a71..4f46bc8fd74a9ee57cc78572f447551e33f861cd 100644 (file)
@@ -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
index 2c2ba7bd80322c11eec4e5030bca77037cc9f9c1..547d941c356538804bc6ba646f663250b0cb5efb 100644 (file)
@@ -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.
  *
  *
  */
 
+/*!\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
 
index 1bbafcaac4aef1706adf98640654fdbd942ddaba..62b2f78136656d206059456b6c868698eaf10ebc 100644 (file)
 #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;
 }
+
+/*!\}
+ */
index fd74730f55678badf4f0b6c3860a619652a6220d..86ecd6adb338d997515059c3440dae6b18b5d101 100644 (file)
@@ -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>
 
 #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;
 
index 3d4347e6346b4cbb2e2b8c100203dad2d4556543..aa583090a7d5d8800e61f8f26c9397286c6de934 100644 (file)
@@ -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;