#+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
ap->fdback[2] = 0;
ap->fdback[3] = 0;
- ap->nr = 6 + ((uint32_t)keybits >> 5);
+ ap->nr = 6 + (keybits >> 5);
rk = ap->k;
rk += 8;
}
}
- else
- {};
if (op == DECRYPT)
{
{
return ap->fdback;
}
-
/*!\}
*/
/** \ingroup BC_aes_m
*/
/*@-exportlocal@*/
-BEECRYPTAPI
+BEECRYPTAPI /*@observer@*/
uint32_t* aesFeedback(aesParam* ap)
- /*@modifies ap @*/;
+ /*@*/;
/*@=exportlocal@*/
#ifdef __cplusplus
}
else if (ch == '=')
break;
- else
- {};
switch (qw++)
{
/* 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",
*datap = (void *)t;
else
if (t) free((void *)t);
- else
- {};
return 0;
}
*
*/
-/*!\file base64.h
+/*!\file base64.h
* \brief Base64 encoding and decoding, headers.
* \author Bob Deblier <bob@virtualunlimited.com>
*/
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);
/*@=nullstate@*/
}
+static /*@unused@*/
int blockCipherContextECB(blockCipherContext* ctxt, void* dst, const void* src, int nblocks)
+ /*@modifies ctxt->param, dst @*/
{
switch (ctxt->op)
{
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)
{
case DECRYPT:
return blockDecryptCBC(ctxt->algo, ctxt->param, dst, src, nblocks);
}
+ /*@notreached@*/
return -1;
}
/** \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
/** \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
*/
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
*/
while (nblocks > 0)
{
- bc->encrypt(bp, dst, src);
+ (void) bc->encrypt(bp, dst, src);
dst += blockwords;
src += blockwords;
while (nblocks > 0)
{
- bc->decrypt(bp, dst, src);
+ (void) bc->decrypt(bp, dst, src);
dst += blockwords;
src += blockwords;
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);
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;
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;
register uint32_t tmp;
register int i;
- bc->decrypt(bp, buf, src);
+ (void) bc->decrypt(bp, buf, src);
for (i = 0; i < blockwords; i++)
{
}
#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)
{
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)
{
/*
* 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
#include "debug.h"
/*!\addtogroup BC_blowfish_m
- * \{
- */
+ * \{
+ */
/**
*/
/** \ingroup BC_blowfish_m
*/
/*@-exportlocal@*/
-BEECRYPTAPI
+BEECRYPTAPI /*@observer@*/
uint32_t* blowfishFeedback(blowfishParam* bp)
/*@*/;
/*@=exportlocal@*/
-/** \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"
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)
if (mackeybits == 0)
{
if (cipherkeybits == 0)
- cipherkeybits = mackeybits = (((uint32_t)keybits) >> 1);
+ cipherkeybits = mackeybits = (keybits >> 1);
else
mackeybits = keybits - cipherkeybits;
}
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;
const hashFunction* hash;
const blockCipher* cipher;
const keyedHashFunction* mac;
- int cipherkeybits;
- int mackeybits;
+ size_t cipherkeybits;
+ size_t mackeybits;
} dhaes_pParameters;
/**
hashFunctionContext hash;
blockCipherContext cipher;
keyedHashFunctionContext mac;
- int cipherkeybits;
- int mackeybits;
+ size_t cipherkeybits;
+ size_t mackeybits;
} dhaes_pContext;
#ifdef __cplusplus
#include "mpprime.h"
#include "debug.h"
+/*!\addtogroup DL_m
+ * \{
+ */
+
/**
*/
static int dldp_pgoqGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, /*@out@*/ mpw* wksp)
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)
/*
* 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));
return 0;
}
+
return -1;
}
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)
{
return dldp_pValidate((const dldp_p*) dp, rgc);
}
+
+/*!\}
+ */
/**
*/
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 @*/;
/**
/*
- * <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
-/** \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"
-/** \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"
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)
{
-/** \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
-/** \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"
}
return 0;
}
+
+/*!\}
+ */
-/** \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
* \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
/* 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
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 */
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)
return -1;
if (hash->update(param, kxi, hash->blocksize))
return -1;
-
return 0;
}
*/
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 */;
/**
*/
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
if (xsize > ysize)
{
register size_t diff = xsize - ysize;
+/*@-evalorder@*/
return mpaddw(diff, xdata, (mpw) mpadd(ysize, xdata+diff, ydata));
+/*@=evalorder@*/
}
else
{
if (xsize > ysize)
{
register size_t diff = xsize - ysize;
+/*@-evalorder@*/
return mpsubw(diff, xdata, (mpw) mpsub(ysize, xdata+diff, ydata));
+/*@=evalorder@*/
}
else
{
#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@*/
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;
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)
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)
{
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;
*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++;
}
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++;
}
}
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
{
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;
}
}
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++));
#endif
}
fprintf(fp, "\n");
- fflush(fp);
+ (void) fflush(fp);
}
#endif
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++));
#endif
}
fprintf(fp, "\n");
- fflush(fp);
+ (void) fflush(fp);
}
#endif
mpw w = *(idata++);
byte shift = MP_WBITS;
- while (shift)
+ while (shift != 0)
{
shift -= 8;
*(osdata++) = (byte)(w >> shift);
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);
/**
*/
BEECRYPTAPI
-int mpaddw(size_t xsize, mpw* xdata, mpw y)
+int mpaddw(size_t size, mpw* xdata, mpw y)
/*@modifies xdata @*/;
/**
/**
*/
BEECRYPTAPI
-int mpsubw(size_t xsize, mpw* xdata, mpw y)
+int mpsubw(size_t size, mpw* xdata, mpw y)
/*@modifies xdata @*/;
/**
*/
/*@-exportlocal@*/
BEECRYPTAPI /*@unused@*/
-size_t mplszcnt(size_t xsize, const mpw* xdata)
+size_t mplszcnt(size_t size, const mpw* data)
/*@*/;
/*@=exportlocal@*/
/**
*/
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@*/
/**
*/
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 @*/;
/**
/**
*/
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 @*/;
b->modl = (mpw*) 0;
b->mu = (mpw*) 0;
}
- else
- {};
}
/*@=nullstate =compdef @*/
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);
/* 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);
* 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 : - | - | -
}
/*@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@*/
*/
/* K == 4 for the first try */
-
+
size_t size = b->size;
mpw temp = 0;
/* 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)
n <<= 1;
n += bit;
-
+
if (n != 0)
{
if (l != 0)
l++;
else if (bit != 0)
l = 1;
- else
- {};
if (l == 4)
{
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--)
while (s--)
mpbsqrmod_w(b, size, result, result, wksp);
}
- }
+ }
}
/**
{
/* always square */
mpbsqrmod_w(b, size, result, result, wksp);
-
+
/* multiply by two if bit is 1 */
if (temp & MP_MSBMASK)
{
{
/*
* 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@*/
/**
*/
BEECRYPTAPI /*@unused@*/
-void mpbneg(const mpbarrett* b, const mpw* xdata, mpw* result)
+void mpbneg(const mpbarrett* b, const mpw* data, mpw* result)
/*@modifies result @*/;
/**
/**
*/
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 @*/;
/**
/**
*/
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 @*/;
/**
n->data = (mpw*) 0;
n->size = 0;
}
- else
- {};
}
/*@=compdef @*/
n->data = (mpw*) 0;
n->size = 0;
}
- else
- {};
}
void mpnsetw(mpnumber* n, mpw val)
{
n->size = size;
- hs2ip(n->data, size, hex, len);
+ (void) hs2ip(n->data, size, hex, len);
}
else {
n->size = 0;
{
mpsetlsb(s.size, s.modl);
}
- else
- {};
if (cofactor == 2)
{
/**
*/
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 @*/;
/**
*/
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 @*/;
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
return -1;
}
-int mtprngNext(mtprngParam* mp, uint32_t* data, int size)
+int mtprngNext(mtprngParam* mp, uint32_t* data, size_t size)
{
if (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@*/
*/
/*@-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@*/
* @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.
*/
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.
*/
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
* \{
*/
-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;
/**
*/
BEECRYPTAPI /*@unused@*/
-int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, int nsize)
+int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t nsize)
/*@modifies kp, rgc @*/;
/**
/*!\addtogroup HASH_sha1_m
* \{
+ */
/** \ingroup HASH_sha1_m
*/
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
-/** \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
#include "endianness.h"
#include "debug.h"
+/*!\addtogroup HASH_sha256_m
+ * \{
+ */
+
/**
*/
/*@observer@*/ /*@unchecked@*/
#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;
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
(void) sha256Reset(p);
return 0;
}
+
+/*!\}
+ */
#include "blockmode.h"
#include "aes.h"
#include "blowfish.h"
-#include "mp32barrett.h"
+#include "mpbarrett.h"
#include "dhaes.h"
#include "dlkp.h"
#include "dsa.h"
#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;
{
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;
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;
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,
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;
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);
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");
#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;
#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;
#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;
#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;
}
}
-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)
{
double ttime;
clock_t tstart, tstop;
#endif
- mp32number digest;
+ mpnumber digest;
- mp32nzero(&digest);
+ mpnzero(&digest);
printf(" %s:\n", tmp->name);
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();
#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)
{
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)
{
#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
#endif
for (i = 0; i < 100; i++)
{
- rsapricrt(&kp, &hm, &s);
+ (void) rsapricrt(&kp, &hm, &s);
}
#if HAVE_TIME_H
tstop = clock();
#endif
for (i = 0; i < 1000; i++)
{
- rsavrfy((rsapk*) &kp, &hm, &s);
+ (void) rsavrfy((rsapk*) &kp, &hm, &s);
}
#if HAVE_TIME_H
tstop = clock();
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");
#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
#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();
#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;
typedef uint16_t javachar;
-#define MP_WBITS 32
+#define MP_WBITS 32U
#if (MP_WBITS == 64)
typedef uint64_t mpw;