summaryrefslogtreecommitdiff
path: root/beecrypt
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2002-02-28 15:48:39 +0000
committerjbj <devnull@localhost>2002-02-28 15:48:39 +0000
commit9aa5bedac729594138d9320ee291f3dce5f5b6b1 (patch)
tree0784f539b813a0fa12ad732516a195df7f50d7af /beecrypt
parent87a411ddf244ef13225ccb42c0bbc4fe191ab146 (diff)
downloadrpm-9aa5bedac729594138d9320ee291f3dce5f5b6b1.tar.gz
rpm-9aa5bedac729594138d9320ee291f3dce5f5b6b1.tar.bz2
rpm-9aa5bedac729594138d9320ee291f3dce5f5b6b1.zip
Use Knuth algorithm Y for computing DSA "w = inv(s) mod q".
CVS patchset: 5339 CVS date: 2002/02/28 15:48:39
Diffstat (limited to 'beecrypt')
-rw-r--r--beecrypt/beetest.c767
-rw-r--r--beecrypt/dsa.c20
-rw-r--r--beecrypt/elgamal.c2
-rw-r--r--beecrypt/mp32.c58
-rw-r--r--beecrypt/mp32.h5
-rw-r--r--beecrypt/mp32barrett.c193
-rw-r--r--beecrypt/tests/beetest.c166
7 files changed, 858 insertions, 353 deletions
diff --git a/beecrypt/beetest.c b/beecrypt/beetest.c
index c2f1d62e7..cb2ddc894 100644
--- a/beecrypt/beetest.c
+++ b/beecrypt/beetest.c
@@ -3,7 +3,7 @@
*
* BeeCrypt test and benchmark application
*
- * Copyright (c) 1999-2000 Virtual Unlimited B.V.
+ * Copyright (c) 1999, 2000, 2001 Virtual Unlimited B.V.
*
* Author: Bob Deblier <bob@virtualunlimited.com>
*
@@ -25,9 +25,16 @@
#include "beecrypt.h"
#include "blockmode.h"
+#include "blowfish.h"
#include "mp32barrett.h"
-#include "dldp.h"
+#include "dhaes.h"
+#include "dlkp.h"
+#include "elgamal.h"
#include "fips180.h"
+#include "hmacmd5.h"
+#include "md5.h"
+#include "rsa.h"
+#include "sha256.h"
#if HAVE_STDLIB_H
#include <stdlib.h>
@@ -46,52 +53,292 @@ static const char* dsa_q = "c773218c737ec8ee993b4f2ded30f48edace915f";
static const char* dsa_g = "626d027839ea0a13413163a55b4cb500299d5522956cefcb3bff10f399ce2c2e71cb9de5fa24babf58e5b79521925c9cc42e9f6f464b088cc572af53e6d78802";
static const char* dsa_x = "2070b3223dba372fde1c0ffc7b2e3b498b260614";
static const char* dsa_y = "19131871d75b1612a819f29d78d1b0d7346f7aa77bb62a859bfd6c5675da9d212d3a36ef1672ef660b8c7c255cc0ec74858fba33f44c06699630a76b030ee333";
+static const char* elg_n = "8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80290";
-int testVectorExpMod()
+int testVectorInvMod(const dlkp_p* keypair)
{
- mp32barrett p;
- mp32number g;
- mp32number x;
+ randomGeneratorContext rngc;
+
+ if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0)
+ {
+ register int rc;
+
+ register uint32 size = keypair->param.p.size;
+ register uint32* temp = (uint32*) malloc((13*size+11) * sizeof(uint32));
+
+ mp32brndinv_w(&keypair->param.n, &rngc, temp, temp+size, temp+2*size);
+
+ mp32bmulmod_w(&keypair->param.n, size, temp, size, temp+size, temp, temp+2*size);
+
+ rc = mp32isone(size, temp);
+
+ free(temp);
+
+ randomGeneratorContextFree(&rngc);
+
+ return rc;
+ }
+ return -1;
+}
+
+int testVectorExpMod(const dlkp_p* keypair)
+{
+ int rc;
mp32number y;
- mp32number tmp;
-
- mp32bzero(&p);
- mp32nzero(&g);
- mp32nzero(&x);
mp32nzero(&y);
- mp32nzero(&tmp);
-
- mp32nsethex(&tmp, dsa_p);
-
- mp32bset(&p, tmp.size, tmp.data);
-
- mp32nsethex(&g, dsa_g);
- mp32nsethex(&x, dsa_x);
-
- mp32bnpowmod(&p, &g, &x);
+ mp32bnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y);
- mp32nset(&y, p.size, p.data);
-
- mp32nsethex(&tmp, dsa_y);
+ rc = mp32eqx(y.size, y.data, keypair->y.size, keypair->y.data);
+
+ mp32nfree(&y);
+
+ return rc;
+}
+
+int testVectorElGamalV1(const dlkp_p* keypair)
+{
+ int rc = 0;
+
+ randomGeneratorContext rngc;
+
+ if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0)
+ {
+ mp32number digest, r, s;
+
+ mp32nzero(&digest);
+ mp32nzero(&r);
+ mp32nzero(&s);
+
+ mp32nsize(&digest, 5);
+
+ 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);
+
+ rc = elgv1vrfy(&keypair->param.p, &keypair->param.n, &keypair->param.g, &digest, &keypair->y, &r, &s);
+
+ mp32nfree(&digest);
+ mp32nfree(&r);
+ mp32nfree(&s);
+
+ randomGeneratorContextFree(&rngc);
+ }
+ return rc;
+}
+
+int testVectorElGamalV3(const dlkp_p* keypair)
+{
+ int rc = 0;
+
+ randomGeneratorContext rngc;
+
+ if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0)
+ {
+ mp32number digest, r, s;
+
+ mp32nzero(&digest);
+ mp32nzero(&r);
+ mp32nzero(&s);
+
+ mp32nsize(&digest, 5);
+
+ 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);
+
+ rc = elgv3vrfy(&keypair->param.p, &keypair->param.n, &keypair->param.g, &digest, &keypair->y, &r, &s);
+
+ mp32nfree(&digest);
+ mp32nfree(&r);
+ mp32nfree(&s);
+
+ randomGeneratorContextFree(&rngc);
+ }
+ return rc;
+}
+
+int testVectorDHAES(const dlkp_p* keypair)
+{
+ /* try encrypting and decrypting a randomly generated message */
+
+ int rc = 0;
+
+ dhaes_p dh;
+
+ /* incomplete */
+ if (dhaes_pInit(&dh, &keypair->param, &blowfish, &hmacmd5, &md5, randomGeneratorDefault()) == 0)
+ {
+ mp32number mkey, mac;
+
+ memchunk src, *dst, *cmp;
+
+ /* make a random message of 2K size */
+ src.size = 2048;
+ src.data = (byte*) malloc(src.size);
+ memset(src.data, 1, src.size);
+
+ /* initialize the message key and mac */
+ mp32nzero(&mkey);
+ mp32nzero(&mac);
+
+ /* encrypt the message */
+ dst = dhaes_pEncrypt(&dh, &keypair->y, &mkey, &mac, &src);
+ /* decrypt the message */
+ cmp = dhaes_pDecrypt(&dh, &keypair->x, &mkey, &mac, dst);
+
+ if (cmp != (memchunk*) 0)
+ {
+ if (src.size == cmp->size)
+ {
+ if (memcmp(src.data, cmp->data, src.size) == 0)
+ rc = 1;
+ }
+
+ free(cmp->data);
+ free(cmp);
+ }
+
+ free(dst->data);
+ free(dst);
+ free(src.data);
+
+ dhaes_pFree(&dh);
+
+ return rc;
+ }
+
+ return -1;
+}
+
+int testVectorRSA()
+{
+ int rc = 0;
+
+ randomGeneratorContext rngc;
+
+ if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0)
+ {
+ rsakp kp;
+ mp32number digest, s;
+
+ rsakpInit(&kp);
+ fprintf(stdout, "making RSA CRT keypair\n");
+ rsakpMake(&kp, &rngc, 32);
+ fprintf(stdout, "RSA CRT keypair generated\n");
+
+ mp32nzero(&digest);
+ mp32nzero(&s);
+
+ mp32bnrnd(&kp.n, &rngc, &digest);
+
+ rsapri(&kp, &digest, &s);
+
+ rc = rsavrfy((rsapk*) &kp, &digest, &s);
+
+ mp32nfree(&digest);
+ mp32nfree(&s);
+
+ rsakpFree(&kp);
- return mp32eqx(y.size, y.data, tmp.size, tmp.data);
+ randomGeneratorContextFree(&rngc);
+
+ return rc;
+ }
+ return -1;
}
-int testVectorSHA()
+int testVectorDLDP()
+{
+ /* try generating dldp_p parameters, then see if the order of the generator is okay */
+ randomGeneratorContext rc;
+ dldp_p dp;
+
+ memset(&dp, 0, sizeof(dldp_p));
+
+ if (randomGeneratorContextInit(&rc, randomGeneratorDefault()) == 0)
+ {
+ register int result;
+ mp32number gq;
+
+ mp32nzero(&gq);
+
+ dldp_pgoqMake(&dp, &rc, 768 >> 5, 512 >> 5, 1);
+
+ /* we have the parameters, now see if g^q == 1 */
+ mp32bnpowmod(&dp.p, &dp.g, (mp32number*) &dp.q, &gq);
+ result = mp32isone(gq.size, gq.data);
+
+ mp32nfree(&gq);
+ dldp_pFree(&dp);
+
+ randomGeneratorContextFree(&rc);
+
+ return result;
+ }
+ return 0;
+}
+
+int testVectorMD5()
+{
+ uint32 expect[4] = { 0x90015098, 0x3cd24fb0, 0xd6963f7d, 0x28e17f72 };
+ uint32 digest[4];
+ md5Param param;
+
+ md5Reset(&param);
+ md5Update(&param, (const unsigned char*) "abc", 3);
+ md5Digest(&param, digest);
+
+ return mp32eq(4, expect, digest);
+}
+
+int testVectorSHA1()
{
uint32 expect[5] = { 0xA9993E36, 0x4706816A, 0xBA3E2571, 0x7850C26C, 0x9CD0D89D };
uint32 digest[5];
sha1Param param;
sha1Reset(&param);
- sha1Update(&param, (const unsigned char *) "abc", 3);
+ sha1Update(&param, (const unsigned char*) "abc", 3);
sha1Digest(&param, digest);
return mp32eq(5, expect, digest);
}
+int testVectorSHA256()
+{
+ uint32 expect[8] = { 0xba7816bf, 0x8f01cfea, 0x414140de, 0x5dae2223, 0xb00361a3, 0x96177a9c, 0xb410ff61, 0xf20015ad };
+ uint32 digest[8];
+ sha256Param param;
+
+ sha256Reset(&param);
+ sha256Update(&param, (const unsigned char*) "abc", 3);
+ sha256Digest(&param, digest);
+
+ return mp32eq(8, expect, digest);
+}
+
+uint32 keyValue[] =
+{
+ 0x00010203,
+ 0x04050607,
+ 0x08090a0b,
+ 0x0c0d0e0f,
+ 0x10111213,
+ 0x14151617,
+ 0x18191a1b,
+ 0x1c1d1e1f,
+ 0x20212223,
+ 0x24252627,
+ 0x28292a2b,
+ 0x2c2d2e2f,
+ 0x30313233,
+ 0x34353637,
+ 0x38393a3b,
+ 0x3c3d3e3f
+};
+
void testBlockInit(uint8* block, int length)
{
register int i;
@@ -103,7 +350,7 @@ void testBlockCiphers()
{
int i, k;
- printf("\tTesting the blockciphers:\n");
+ fprintf(stdout, "\tTesting the blockciphers:\n");
for (i = 0; i < blockCipherCount(); i++)
{
@@ -111,60 +358,47 @@ void testBlockCiphers()
if (tmp)
{
- uint32 blockwords = tmp->blockbits >> 5;
+ uint32 blockwords = tmp->blocksize >> 2;
- uint32* src_block = (uint32*) malloc(blockwords * sizeof(uint32));
- uint32* dst_block = (uint32*) malloc(blockwords * sizeof(uint32));
+ 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));
void* encrypt_param = (void*) malloc(tmp->paramsize);
void* decrypt_param = (void*) malloc(tmp->paramsize);
- printf("\t%s:\n", tmp->name);
+ fprintf(stdout, "\t%s:\n", tmp->name);
for (k = tmp->keybitsmin; k <= tmp->keybitsmax; k += tmp->keybitsinc)
{
- void* key = (void*) malloc(k >> 3);
-
- testBlockInit((uint8*) key, k >> 3);
-
- printf("\t\tsetup encrypt (%d bits key): ", k);
- if (tmp->setup(encrypt_param, key, k, ENCRYPT) < 0)
+ fprintf(stdout, "\t\tsetup encrypt (%d bits key): ", k);
+ if (tmp->setup(encrypt_param, keyValue, k, ENCRYPT) < 0)
{
- free(key);
- printf("failed\n");
+ fprintf(stdout, "failed\n");
continue;
}
- printf("ok\n");
- printf("\t\tsetup decrypt (%d bits key): ", k);
- if (tmp->setup(decrypt_param, key, k, DECRYPT) < 0)
+ fprintf(stdout, "ok\n");
+ fprintf(stdout, "\t\tsetup decrypt (%d bits key): ", k);
+ if (tmp->setup(decrypt_param, keyValue, k, DECRYPT) < 0)
{
- free(key);
- printf("failed\n");
+ fprintf(stdout, "failed\n");
continue;
}
- printf("ok\n");
- printf("\t\tencrypt/decrypt test block: ");
- testBlockInit((uint8*) src_block, tmp->blockbits >> 3);
- memcpy(dst_block, src_block, tmp->blockbits >> 3);
- tmp->encrypt(encrypt_param, dst_block);
- /*
- for (j = 0; j < (tmp->blockbits >> 3); j++)
- {
- printf("%02x", *(((uint8*)dst_block)+j));
- }
- printf(" ");
- */
- tmp->decrypt(decrypt_param, dst_block);
- if (memcmp(src_block, dst_block, tmp->blockbits >> 3))
+ fprintf(stdout, "ok\n");
+ fprintf(stdout, "\t\tencrypt/decrypt test block: ");
+ testBlockInit((uint8*) 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);
+
+ if (memcmp(dec_block, src_block, tmp->blocksize >> 2))
{
- free(key);
- printf("failed\n");
+ fprintf(stdout, "failed\n");
continue;
}
- free(key);
- printf("ok\n");
- printf("\t\tspeed measurement:\n");
+ fprintf(stdout, "ok\n");
+ fprintf(stdout, "\t\tspeed measurement:\n");
{
#if HAVE_TIME_H
double ttime;
@@ -174,43 +408,44 @@ void testBlockCiphers()
#if HAVE_TIME_H
tstart = clock();
#endif
- blockEncrypt(tmp, encrypt_param, ECB, 1024 * 1024, spd_block, spd_block, 0);
+ blockEncrypt(tmp, encrypt_param, ECB, 1024 * 1024, spd_block, spd_block);
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t\t\tECB encrypts 1M blocks of %d bits in %.3f seconds\n", tmp->blockbits, ttime);
+ fprintf(stdout, "\t\t\tECB encrypts 1M blocks of %d bits in %.3f seconds\n", tmp->blocksize << 3, ttime);
#endif
#if HAVE_TIME_H
tstart = clock();
#endif
- blockDecrypt(tmp, decrypt_param, ECB, 1024 * 1024, spd_block, spd_block, 0);
+ blockDecrypt(tmp, decrypt_param, ECB, 1024 * 1024, spd_block, spd_block);
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t\t\tECB decrypts 1M blocks of %d bits in %.3f seconds\n", tmp->blockbits, ttime);
+ fprintf(stdout, "\t\t\tECB decrypts 1M blocks of %d bits in %.3f seconds\n", tmp->blocksize << 3, ttime);
#endif
#if HAVE_TIME_H
tstart = clock();
#endif
- blockEncrypt(tmp, encrypt_param, CBC, 1024 * 1024, spd_block, spd_block, 0);
+ blockEncrypt(tmp, encrypt_param, CBC, 1024 * 1024, spd_block, spd_block);
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t\t\tCBC encrypts 1M blocks of %d bits in %.3f seconds\n", tmp->blockbits, ttime);
+ fprintf(stdout, "\t\t\tCBC encrypts 1M blocks of %d bits in %.3f seconds\n", tmp->blocksize << 3, ttime);
#endif
#if HAVE_TIME_H
tstart = clock();
#endif
- blockEncrypt(tmp, decrypt_param, CBC, 1024 * 1024, spd_block, spd_block, 0);
+ blockEncrypt(tmp, decrypt_param, CBC, 1024 * 1024, spd_block, spd_block);
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t\t\tCBC decrypts 1M blocks of %d bits in %.3f seconds\n", tmp->blockbits, ttime);
+ fprintf(stdout, "\t\t\tCBC decrypts 1M blocks of %d bits in %.3f seconds\n", tmp->blocksize << 3, ttime);
#endif
}
}
free(spd_block);
- free(dst_block);
+ free(dec_block);
+ free(enc_block);
free(src_block);
free(decrypt_param);
free(encrypt_param);
@@ -220,15 +455,15 @@ void testBlockCiphers()
void testHashFunctions()
{
- int i;
+ int i, j;
- uint8* data = (uint8*) malloc(16 * 1024 * 1024);
+ uint8* data = (uint8*) malloc(32 * 1024 * 1024);
if (data)
{
hashFunctionContext hfc;
- printf("\tTesting the hash functions:\n");
+ fprintf(stdout, "\tTesting the hash functions:\n");
for (i = 0; i < hashFunctionCount(); i++)
{
@@ -236,9 +471,9 @@ void testHashFunctions()
if (tmp)
{
- uint8* digest = (uint8*) malloc(tmp->digestsize);
+ uint8* digest = (uint8*) calloc(tmp->digestsize, 1);
- printf("\t%s:\n", tmp->name);
+ fprintf(stdout, "\t%s:\n", tmp->name);
if (digest)
{
@@ -249,31 +484,23 @@ void testHashFunctions()
hashFunctionContextInit(&hfc, tmp);
- #if HAVE_TIME_H
- tstart = clock();
- #endif
- hfc.hash->reset(hfc.param);
- hfc.hash->update(hfc.param, data, 16 * 1024 * 1024);
- hfc.hash->digest(hfc.param, (uint32*) digest);
+ for (j = 0; j < 4; j++)
+ {
+ #if HAVE_TIME_H
+ tstart = clock();
+ #endif
- #if HAVE_TIME_H
- tstop = clock();
- ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t\thashes 16MB in %.3f seconds\n", ttime);
- #endif
+ hfc.hash->reset(hfc.param);
+ hfc.hash->update(hfc.param, data, 32 * 1024 * 1024);
+ hfc.hash->digest(hfc.param, (uint32*) digest);
- #if HAVE_TIME_H
- tstart = clock();
- #endif
- hfc.hash->reset(hfc.param);
- hfc.hash->update(hfc.param, data, 16 * 1024 * 1024);
- hfc.hash->digest(hfc.param, (uint32*) digest);
+ #if HAVE_TIME_H
+ tstop = clock();
+ ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
+ fprintf(stdout, "\t\thashes 32 MB in %.3f seconds\n", ttime);
+ #endif
+ }
- #if HAVE_TIME_H
- tstop = clock();
- ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t\thashes 16MB in %.3f seconds\n", ttime);
- #endif
free(digest);
}
hashFunctionContextFree(&hfc);
@@ -290,104 +517,104 @@ void testExpMods()
static const char* p_1024 = "c615c47a56b47d869010256171ab164525f2ef4b887a4e0cdfc87043a9dd8894f2a18fa56729448e700f4b7420470b61257d11ecefa9ff518dc9fed5537ec6a9665ba73c948674320ff61b29c4cfa61e5baf47dfc1b80939e1bffb51787cc3252c4d1190a7f13d1b0f8d4aa986571ce5d4de5ecede1405e9bc0b5bf040a46d99";
- randomGeneratorContext rc;
+ randomGeneratorContext rngc;
mp32barrett p;
mp32number tmp;
mp32number g;
mp32number x;
+ mp32number y;
mp32bzero(&p);
mp32nzero(&g);
mp32nzero(&x);
+ mp32nzero(&y);
mp32nzero(&tmp);
- randomGeneratorContextInit(&rc, randomGeneratorDefault());
-
- if (rc.rng && rc.param)
+ if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0)
{
- if (rc.rng->setup(rc.param) == 0)
- {
- int i;
- #if HAVE_TIME_H
- double ttime;
- clock_t tstart, tstop;
- #endif
-
- printf("Timing modular exponentiations\n");
- printf("\t(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);
- mp32brndres(&p, g.data, &rc);
- mp32brndres(&p, x.data, &rc);
- #if HAVE_TIME_H
- tstart = clock();
- #endif
- for (i = 0; i < 100; i++)
- mp32bnpowmod(&p, &g, &x);
- #if HAVE_TIME_H
- tstop = clock();
- ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t 100x in %.3f seconds\n", ttime);
- #endif
- printf("\t(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);
- mp32brndres(&p, g.data, &rc);
- mp32brndres(&p, x.data, &rc);
- #if HAVE_TIME_H
- tstart = clock();
- #endif
- for (i = 0; i < 100; i++)
- mp32bnpowmod(&p, &g, &x);
- #if HAVE_TIME_H
- tstop = clock();
- ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t 100x in %.3f seconds\n", ttime);
- #endif
- printf("\t(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);
- mp32brndres(&p, g.data, &rc);
- mp32brndres(&p, x.data, &rc);
- #if HAVE_TIME_H
- tstart = clock();
- #endif
- for (i = 0; i < 100; i++)
- mp32bnpowmod(&p, &g, &x);
- #if HAVE_TIME_H
- tstop = clock();
- ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t 100x in %.3f seconds\n", ttime);
- #endif
- /* now run a test with x having 160 bits */
- mp32nsize(&x, 5);
- rc.rng->next(rc.param, x.data, x.size);
- printf("\t(1024 bits ^ 160 bits) mod 1024 bits:");
- #if HAVE_TIME_H
- tstart = clock();
- #endif
- for (i = 0; i < 100; i++)
- mp32bnpowmod(&p, &g, &x);
- #if HAVE_TIME_H
- tstop = clock();
- ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\t 100x in %.3f seconds\n", ttime);
- #endif
- mp32bfree(&p);
- mp32nfree(&g);
- mp32nfree(&x);
- mp32nfree(&tmp);
- }
+ int i;
+ #if HAVE_TIME_H
+ double ttime;
+ clock_t tstart, tstop;
+ #endif
+
+ fprintf(stdout, "Timing modular exponentiations\n");
+ fprintf(stdout, "\t(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);
+ #if HAVE_TIME_H
+ tstart = clock();
+ #endif
+ for (i = 0; i < 100; i++)
+ mp32bnpowmod(&p, &g, &x, &y);
+ #if HAVE_TIME_H
+ tstop = clock();
+ ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
+ fprintf(stdout, "\t 100x in %.3f seconds\n", ttime);
+ #endif
+ fprintf(stdout, "\t(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);
+ #if HAVE_TIME_H
+ tstart = clock();
+ #endif
+ for (i = 0; i < 100; i++)
+ mp32bnpowmod(&p, &g, &x, &y);
+ #if HAVE_TIME_H
+ tstop = clock();
+ ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
+ fprintf(stdout, "\t 100x in %.3f seconds\n", ttime);
+ #endif
+ fprintf(stdout, "\t(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);
+ #if HAVE_TIME_H
+ tstart = clock();
+ #endif
+ for (i = 0; i < 100; i++)
+ mp32bnpowmod(&p, &g, &x, &y);
+ #if HAVE_TIME_H
+ tstop = clock();
+ ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
+ fprintf(stdout, "\t 100x in %.3f seconds\n", ttime);
+ #endif
+ /* now run a test with x having 160 bits */
+ mp32nsize(&x, 5);
+ rngc.rng->next(rngc.param, x.data, x.size);
+ fprintf(stdout, "\t(1024 bits ^ 160 bits) mod 1024 bits:");
+ #if HAVE_TIME_H
+ tstart = clock();
+ #endif
+ for (i = 0; i < 100; i++)
+ mp32bnpowmod(&p, &g, &x, &y);
+ #if HAVE_TIME_H
+ tstop = clock();
+ ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
+ fprintf(stdout, "\t 100x in %.3f seconds\n", ttime);
+ #endif
+ mp32bfree(&p);
+ mp32nfree(&g);
+ mp32nfree(&x);
+ mp32nfree(&y);
+ mp32nfree(&tmp);
+
+ randomGeneratorContextFree(&rngc);
}
-
- randomGeneratorContextFree(&rc);
+ else
+ fprintf(stdout, "random generator setup problem\n");
}
void testDLParams()
@@ -397,100 +624,184 @@ void testDLParams()
memset(&dp, 0, sizeof(dldp_p));
- randomGeneratorContextInit(&rc, randomGeneratorDefault());
-
- if (rc.rng && rc.param)
+ if (randomGeneratorContextInit(&rc, randomGeneratorDefault()) == 0)
{
- if (rc.rng->setup(rc.param) == 0)
- {
- #if HAVE_TIME_H
- double ttime;
- clock_t tstart, tstop;
- #endif
- #if HAVE_TIME_H
- tstart = clock();
- #endif
- printf("Generating P (768 bits) Q (512 bits) G with order Q\n");
- dldp_pgoqMake(&dp, &rc, 768 >> 5, 512 >> 5, 1);
- #if HAVE_TIME_H
- tstop = clock();
- ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf("\tdone in %.3f seconds\n", ttime);
- #endif
- }
+ #if HAVE_TIME_H
+ double ttime;
+ clock_t tstart, tstop;
+ #endif
+ fprintf(stdout, "Generating P (768 bits) Q (512 bits) G with order Q\n");
+ #if HAVE_TIME_H
+ tstart = clock();
+ #endif
+ dldp_pgoqMake(&dp, &rc, 768 >> 5, 512 >> 5, 1);
+ #if HAVE_TIME_H
+ tstop = clock();
+ ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
+ fprintf(stdout, "\tdone in %.3f seconds\n", ttime);
+ #endif
+ fprintf(stdout, "P = "); fflush(stdout); mp32println(stdout, dp.p.size, dp.p.modl);
+ fprintf(stdout, "Q = "); fflush(stdout); mp32println(stdout, dp.q.size, dp.q.modl);
+ fprintf(stdout, "G = "); fflush(stdout); mp32println(stdout, dp.g.size, dp.g.data);
+ dldp_pFree(&dp);
+
+ fprintf(stdout, "Generating P (768 bits) Q (512 bits) G with order (P-1)\n");
+ #if HAVE_TIME_H
+ tstart = clock();
+ #endif
+ dldp_pgonMake(&dp, &rc, 768 >> 5, 512 >> 5);
+ #if HAVE_TIME_H
+ tstop = clock();
+ ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
+ fprintf(stdout, "\tdone in %.3f seconds\n", ttime);
+ #endif
+ fprintf(stdout, "P = "); fflush(stdout); mp32println(stdout, dp.p.size, dp.p.modl);
+ fprintf(stdout, "Q = "); fflush(stdout); mp32println(stdout, dp.q.size, dp.q.modl);
+ fprintf(stdout, "G = "); fflush(stdout); mp32println(stdout, dp.g.size, dp.g.data);
+ fprintf(stdout, "N = "); fflush(stdout); mp32println(stdout, dp.n.size, dp.n.modl);
+ dldp_pFree(&dp);
+
+ randomGeneratorContextFree(&rc);
}
-
- randomGeneratorContextFree(&rc);
}
+#if 0
int main()
{
+ dlkp_p keypair;
+
+ if (testVectorMD5())
+ fprintf(stdout, "MD5 works!\n");
+ else
+ exit(1);
+
+ if (testVectorSHA1())
+ fprintf(stdout, "SHA-1 works!\n");
+ else
+ exit(1);
+
+ if (testVectorSHA256())
+ fprintf(stdout, "SHA-256 works!\n");
+ else
+ exit(1);
+
+ dlkp_pInit(&keypair);
+
+ mp32bsethex(&keypair.param.p, dsa_p);
+ mp32bsethex(&keypair.param.q, dsa_q);
+ mp32nsethex(&keypair.param.g, dsa_g);
+ mp32bsethex(&keypair.param.n, elg_n);
+ mp32nsethex(&keypair.y, dsa_y);
+ mp32nsethex(&keypair.x, dsa_x);
+
+ if (testVectorInvMod(&keypair))
+ fprintf(stdout, "InvMod works!\n");
+ else
+ exit(1);
+
+ if (testVectorExpMod(&keypair))
+ fprintf(stdout, "ExpMod works!\n");
+ else
+ exit(1);
+
+ if (testVectorElGamalV1(&keypair))
+ fprintf(stdout, "ElGamal v1 works!\n");
+ else
+ exit(1);
+
+ if (testVectorElGamalV3(&keypair))
+ fprintf(stdout, "ElGamal v3 works!\n");
+ else
+ exit(1);
+
+ if (testVectorDHAES(&keypair))
+ fprintf(stdout, "DHAES works!\n");
+ else
+ exit(1);
+
+ dlkp_pFree(&keypair);
+
+ if (testVectorRSA())
+ fprintf(stdout, "RSA works!\n");
+ else
+ exit(1);
+/*
+ if (testVectorDLDP())
+ fprintf(stdout, "dldp with generator of order q works!\n");
+ else
+ exit(1);
+*/
+ return 0;
+}
+#else
+int main()
+{
int i, j;
- printf("the beecrypt library implements:\n");
- printf("\t%d entropy source%s:\n", entropySourceCount(), entropySourceCount() == 1 ? "" : "s");
+ fprintf(stdout, "the beecrypt library implements:\n");
+ fprintf(stdout, "\t%d entropy source%s:\n", entropySourceCount(), entropySourceCount() == 1 ? "" : "s");
for (i = 0; i < entropySourceCount(); i++)
{
const entropySource* tmp = entropySourceGet(i);
if (tmp)
- printf("\t\t%s\n", tmp->name);
+ fprintf(stdout, "\t\t%s\n", tmp->name);
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
- printf("\t%d random generator%s:\n", randomGeneratorCount(), randomGeneratorCount() == 1 ? "" : "s");
+ fprintf(stdout, "\t%d random generator%s:\n", randomGeneratorCount(), randomGeneratorCount() == 1 ? "" : "s");
for (i = 0; i < randomGeneratorCount(); i++)
{
const randomGenerator* tmp = randomGeneratorGet(i);
if (tmp)
- printf("\t\t%s\n", tmp->name);
+ fprintf(stdout, "\t\t%s\n", tmp->name);
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
- printf("\t%d hash function%s:\n", hashFunctionCount(), hashFunctionCount() == 1 ? "" : "s");
+ fprintf(stdout, "\t%d hash function%s:\n", hashFunctionCount(), hashFunctionCount() == 1 ? "" : "s");
for (i = 0; i < hashFunctionCount(); i++)
{
const hashFunction* tmp = hashFunctionGet(i);
if (tmp)
- printf("\t\t%s\n", tmp->name);
+ fprintf(stdout, "\t\t%s\n", tmp->name);
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
- printf("\t%d keyed hash function%s:\n", keyedHashFunctionCount(), keyedHashFunctionCount() == 1 ? "" : "s");
+ fprintf(stdout, "\t%d keyed hash function%s:\n", keyedHashFunctionCount(), keyedHashFunctionCount() == 1 ? "" : "s");
for (i = 0; i < keyedHashFunctionCount(); i++)
{
const keyedHashFunction* tmp = keyedHashFunctionGet(i);
if (tmp)
- printf("\t\t%s\n", tmp->name);
+ fprintf(stdout, "\t\t%s\n", tmp->name);
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
- printf("\t%d blockcipher%s:\n", blockCipherCount(), blockCipherCount() == 1 ? "" : "s");
+ fprintf(stdout, "\t%d blockcipher%s:\n", blockCipherCount(), blockCipherCount() == 1 ? "" : "s");
for (i = 0; i < blockCipherCount(); i++)
{
const blockCipher* tmp = blockCipherGet(i);
if (tmp)
{
- printf("\t\t%s ", tmp->name);
+ fprintf(stdout, "\t\t%s ", tmp->name);
for (j = tmp->keybitsmin; j <= tmp->keybitsmax; j += tmp->keybitsinc)
{
- printf("%d", j);
+ fprintf(stdout, "%d", j);
if (j < tmp->keybitsmax)
- printf("/");
+ fprintf(stdout, "/");
else
- printf(" bit keys\n");
+ fprintf(stdout, " bit keys\n");
}
}
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
-
testBlockCiphers();
testHashFunctions();
testExpMods();
testDLParams();
- printf("done\n");
+ fprintf(stdout, "done\n");
return 0;
}
+#endif
diff --git a/beecrypt/dsa.c b/beecrypt/dsa.c
index 5d21d5049..3084c1784 100644
--- a/beecrypt/dsa.c
+++ b/beecrypt/dsa.c
@@ -54,6 +54,8 @@
# include <malloc.h>
#endif
+static int _debug = 0;
+
int dsasign(const mp32barrett* p, const mp32barrett* q, const mp32number* g, randomGeneratorContext* rgc, const mp32number* hm, const mp32number* x, mp32number* r, mp32number* s)
{
register uint32 psize = p->size;
@@ -148,7 +150,7 @@ int dsavrfy(const mp32barrett* p, const mp32barrett* q, const mp32number* g, con
if (ptemp == NULL)
return rc;
- qtemp = (uint32*) malloc((8*qsize+6) * sizeof(*qtemp));
+ qtemp = (uint32*) malloc((13*qsize+11) * sizeof(*qtemp));
if (qtemp == NULL) {
free(ptemp);
return rc;
@@ -158,26 +160,42 @@ int dsavrfy(const mp32barrett* p, const mp32barrett* q, const mp32number* g, con
register uint32* pwksp = ptemp+2*psize;
register uint32* qwksp = qtemp+2*qsize;
+if (_debug)
+fprintf(stderr, "\t q: "), mp32println(stderr, q->size, q->modl);
// compute w = inv(s) mod q
if (mp32binv_w(q, s->size, s->data, qtemp, qwksp))
{
+if (_debug)
+fprintf(stderr, "\t w = inv(s) mod q: "), mp32println(stderr, qsize, qtemp);
// compute u1 = h(m)*w mod q
mp32bmulmod_w(q, hm->size, hm->data, qsize, qtemp, qtemp+qsize, qwksp);
+if (_debug)
+fprintf(stderr, "\tu1 = h(m)*w mod q: "), mp32println(stderr, qsize, qtemp+qsize);
// compute u2 = r*w mod q
mp32bmulmod_w(q, r->size, r->data, qsize, qtemp, qtemp, qwksp);
+if (_debug)
+fprintf(stderr, "\tu2 = r*w mod q : "), mp32println(stderr, qsize, qtemp);
// compute g^u1 mod p
mp32bpowmod_w(p, g->size, g->data, qsize, qtemp+qsize, ptemp, pwksp);
+if (_debug)
+fprintf(stderr, "\t g^u1 mod p: "), mp32println(stderr, psize, ptemp);
// compute y^u2 mod p
mp32bpowmod_w(p, y->size, y->data, qsize, qtemp, ptemp+psize, pwksp);
+if (_debug)
+fprintf(stderr, "\t y^u2 mod p: "), mp32println(stderr, psize, ptemp+psize);
// multiply mod p
mp32bmulmod_w(p, psize, ptemp, psize, ptemp+psize, ptemp, pwksp);
+if (_debug)
+fprintf(stderr, "\t multiply mod p: "), mp32println(stderr, psize, ptemp);
// modulo q
mp32nmod(ptemp+psize, psize, ptemp, qsize, q->modl, pwksp);
+if (_debug)
+fprintf(stderr, "\tr' mod q : "), mp32println(stderr, psize, ptemp+psize);
rc = mp32eqx(r->size, r->data, psize, ptemp+psize);
}
diff --git a/beecrypt/elgamal.c b/beecrypt/elgamal.c
index 1d172fc66..768f59c6e 100644
--- a/beecrypt/elgamal.c
+++ b/beecrypt/elgamal.c
@@ -70,7 +70,7 @@
int elgv1sign(const mp32barrett* p, const mp32barrett* n, const mp32number* g, randomGeneratorContext* rgc, const mp32number* hm, const mp32number* x, mp32number* r, mp32number* s)
{
register uint32 size = p->size;
- register uint32* temp = (uint32*) malloc((8*size+6) * sizeof(*temp));
+ register uint32* temp = (uint32*) malloc((13*size+11) * sizeof(*temp));
if (temp)
{
diff --git a/beecrypt/mp32.c b/beecrypt/mp32.c
index 39bea0bea..8a203bf9d 100644
--- a/beecrypt/mp32.c
+++ b/beecrypt/mp32.c
@@ -969,12 +969,12 @@ uint32 mp32nmodw(uint32* result, uint32 xsize, const uint32* xdata, uint32 y, ui
while (qsize--)
{
- /* printf("result = "); MP32println(xsize+1, result); */
+ /* fprintf(stderr, "result = "); MP32println(stderr, xsize+1, result); */
/* get the two high words of r into temp */
temp = rdata[0];
temp <<= 32;
temp += rdata[1];
- /* printf("q = %016llx / %08lx\n", temp, msw); */
+ /* fprintf(stderr, "q = %016llx / %08lx\n", temp, msw); */
temp /= y;
/*
temp *= y;
@@ -983,20 +983,20 @@ uint32 mp32nmodw(uint32* result, uint32 xsize, const uint32* xdata, uint32 y, ui
*/
q = (uint32) temp;
- /* printf("q = %08x\n", q); */
+ /* fprintf(stderr, "q = %08x\n", q); */
/*@-evalorder@*/
*wksp = mp32setmul(1, wksp+1, &y, q);
/*@=evalorder@*/
- /* printf("mplt "); mp32print(2, rdata); printf(" < "); mp32println(2, wksp); */
+ /* fprintf(stderr, "mplt "); mp32print(2, rdata); fprintf(stderr, " < "); mp32println(stderr, 2, wksp); */
while (mp32lt(2, rdata, wksp))
{
- /* printf("mp32lt! "); mp32print(2, rdata); printf(" < "); mp32println(2, wksp); */
- /* printf("decreasing q\n"); */
+ /* fprintf(stderr, "mp32lt! "); mp32print(2, rdata); fprintf(stderr, " < "); mp32println(stderr, 2, wksp); */
+ /* fprintf(stderr, "decreasing q\n"); */
(void) mp32subx(2, wksp, 1, &y);
/* q--; */
}
- /* printf("subtracting\n"); */
+ /* fprintf(stderr, "subtracting\n"); */
(void) mp32sub(2, rdata, wksp);
rdata++;
}
@@ -1021,29 +1021,29 @@ void mp32nmod(uint32* result, uint32 xsize, const uint32* xdata, uint32 ysize, c
while (qsize--)
{
- /* printf("result = "); mp32println(xsize+1, result); */
+ /* fprintf(stderr, "result = "); mp32println(stderr, xsize+1, result); */
/* get the two high words of r into temp */
temp = rdata[0];
temp <<= 32;
temp += rdata[1];
- /* printf("q = %016llx / %08lx\n", temp, msw); */
+ /* fprintf(stderr, "q = %016llx / %08lx\n", temp, msw); */
temp /= msw;
q = (uint32) temp;
- /* printf("q = %08x\n", q); */
+ /* fprintf(stderr, "q = %08x\n", q); */
/*@-evalorder@*/
*wksp = mp32setmul(ysize, wksp+1, ydata, q);
/*@=evalorder@*/
- /* printf("mp32lt "); mp32print(ysize+1, rdata); printf(" < "); mp32println(ysize+1, wksp); */
+ /* fprintf(stderr, "mp32lt "); mp32print(ysize+1, rdata); fprintf(stderr, " < "); mp32println(stderr, ysize+1, wksp); */
while (mp32lt(ysize+1, rdata, wksp))
{
- /* printf("mp32lt! "); mp32print(ysize+1, rdata); printf(" < "); mp32println(ysize+1, wksp); */
- /* printf("decreasing q\n"); */
+ /* fprintf(stderr, "mp32lt! "); mp32print(ysize+1, rdata); fprintf(stderr, " < "); mp32println(stderr, ysize+1, wksp); */
+ /* fprintf(stderr, "decreasing q\n"); */
(void) mp32subx(ysize+1, wksp, ysize, ydata);
q--;
}
- /* printf("subtracting\n"); */
+ /* fprintf(stderr, "subtracting\n"); */
(void) mp32sub(ysize+1, rdata, wksp);
rdata++;
}
@@ -1065,7 +1065,7 @@ void mp32ndivmod(uint32* result, uint32 xsize, const uint32* xdata, uint32 ysize
/*@-compdef@*/ /* LCL: result+1 undefined */
if (mp32ge(ysize, result+1, ydata))
{
- /* printf("subtracting\n"); */
+ /* fprintf(stderr, "subtracting\n"); */
(void) mp32sub(ysize, result+1, ydata);
*(result++) = 1;
}
@@ -1076,30 +1076,30 @@ void mp32ndivmod(uint32* result, uint32 xsize, const uint32* xdata, uint32 ysize
/*@-usedef@*/ /* LCL: result[0] is set */
while (qsize--)
{
- /* printf("result = "); mp32println(xsize+1, result); */
+ /* fprintf(stderr, "result = "); mp32println(stderr, xsize+1, result); */
/* get the two high words of r into temp */
temp = result[0];
temp <<= 32;
temp += result[1];
- /* printf("q = %016llx / %08lx\n", temp, msw); */
+ /* fprintf(stderr, "q = %016llx / %08lx\n", temp, msw); */
temp /= msw;
q = (uint32) temp;
- /* printf("q = %08x\n", q); */
+ /* fprintf(stderr, "q = %08x\n", q); */
/*@-evalorder@*/
*wksp = mp32setmul(ysize, wksp+1, ydata, q);
/*@=evalorder@*/
- /* printf("mp32lt "); mp32print(ysize+1, result); printf(" < "); mp32println(ysize+1, wksp); */
+ /* fprintf(stderr, "mp32lt "); mp32print(ysize+1, result); fprintf(stderr, " < "); mp32println(stderr, ysize+1, wksp); */
while (mp32lt(ysize+1, result, wksp))
{
- /* printf("mp32lt! "); mp32print(ysize+1, result); printf(" < "); mp32println(ysize+1, wksp); */
- /* printf("decreasing q\n"); */
+ /* fprintf(stderr, "mp32lt! "); mp32print(ysize+1, result); fprintf(stderr, " < "); mp32println(stderr, ysize+1, wksp); */
+ /* fprintf(stderr, "decreasing q\n"); */
(void) mp32subx(ysize+1, wksp, ysize, ydata);
q--;
}
- /* printf("subtracting\n"); */
+ /* fprintf(stderr, "subtracting\n"); */
(void) mp32sub(ysize+1, result, wksp);
*(result++) = q;
}
@@ -1128,20 +1128,20 @@ void mp32unpack(uint32 size, uint8* bytes, const uint32* bits)
*/
#ifndef ASM_MP32PRINT
-void mp32print(register uint32 xsize, register const uint32* xdata)
+void mp32print(register FILE * fp, register uint32 xsize, register const uint32* xdata)
{
while (xsize--)
- printf("%08x", *(xdata++));
- (void) fflush(stdout);
+ fprintf(fp, "%08x", *(xdata++));
+ (void) fflush(fp);
}
#endif
#ifndef ASM_MP32PRINTLN
-void mp32println(register uint32 xsize, register const uint32* xdata)
+void mp32println(register FILE * fp, register uint32 xsize, register const uint32* xdata)
{
while (xsize--)
- printf("%08x", *(xdata++));
- printf("\n");
- (void) fflush(stdout);
+ fprintf(fp, "%08x", *(xdata++));
+ fprintf(fp, "\n");
+ (void) fflush(fp);
}
#endif
diff --git a/beecrypt/mp32.h b/beecrypt/mp32.h
index c4e0cee53..25625bba2 100644
--- a/beecrypt/mp32.h
+++ b/beecrypt/mp32.h
@@ -33,6 +33,7 @@
#if HAVE_STRING_H
# include <string.h>
#endif
+#include <stdio.h>
#include "mp32opt.h"
@@ -433,14 +434,14 @@ void mp32ndivmod(/*@out@*/ uint32* result, uint32 xsize, const uint32* xdata, ui
/**
*/
BEECRYPTAPI /*@unused@*/
-void mp32print(uint32 xsize, const uint32* xdata)
+void mp32print(FILE * fp, uint32 xsize, const uint32* xdata)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
/**
*/
BEECRYPTAPI /*@unused@*/
-void mp32println(uint32 xsize, const uint32* xdata)
+void mp32println(FILE * fp, uint32 xsize, const uint32* xdata)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
diff --git a/beecrypt/mp32barrett.c b/beecrypt/mp32barrett.c
index 9cd82e587..508c1771d 100644
--- a/beecrypt/mp32barrett.c
+++ b/beecrypt/mp32barrett.c
@@ -757,6 +757,7 @@ void mp32btwopowmod_w(const mp32barrett* b, uint32 psize, const uint32* pdata, u
}
}
+#ifdef DYING
/**
* Computes the inverse (modulo b) of x, and returns 1 if x was invertible.
* needs workspace of (6*size+6) words
@@ -780,13 +781,14 @@ int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32*
uint32* cdata = bdata+size+1;
uint32* ddata = cdata+size+1;
- if (mp32odd(b->size, b->modl) && mp32even(xsize, xdata))
+ mp32setx(size+1, udata, size, b->modl);
+ mp32setx(size+1, vdata, xsize, xdata);
+ mp32zero(size+1, bdata);
+ mp32setw(size+1, ddata, 1);
+
+ if (mp32odd(size, b->modl) && mp32even(xsize, xdata))
{
/* use simplified binary extended gcd algorithm */
- mp32setx(size+1, udata, size, b->modl);
- mp32setx(size+1, vdata, xsize, xdata);
- mp32zero(size+1, bdata);
- mp32setw(size+1, ddata, 1);
while (1)
{
@@ -840,12 +842,8 @@ int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32*
else
{
/* use full binary extended gcd algorithm */
- mp32setx(size+1, udata, size, b->modl);
- mp32setx(size+1, vdata, xsize, xdata);
mp32setw(size+1, adata, 1);
- mp32zero(size+1, bdata);
mp32zero(size+1, cdata);
- mp32setw(size+1, ddata, 1);
while (1)
{
@@ -907,6 +905,183 @@ int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32*
}
}
}
+#else
+
+static int _debug = 0;
+
+/**
+ * Computes the inverse (modulo b) of x, and returns 1 if x was invertible.
+ */
+int mp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata, uint32* result, uint32* wksp)
+{
+ uint32 ysize = b->size+1;
+ int k;
+ uint32* u1 = wksp;
+ uint32* u2 = u1+ysize;
+ uint32* u3 = u2+ysize;
+ uint32* v1 = u3+ysize;
+ uint32* v2 = v1+ysize;
+ uint32* v3 = v2+ysize;
+ uint32* t1 = v3+ysize;
+ uint32* t2 = t1+ysize;
+ uint32* t3 = t2+ysize;
+ uint32* u = t3+ysize;
+ uint32* v = u+ysize;
+
+ mp32setx(ysize, u, xsize, xdata);
+ mp32setx(ysize, v, b->size, b->modl);
+
+ /* Y1. Find power of 2. */
+ for (k = 0; mp32even(ysize, u) && mp32even(ysize, v); k++) {
+ mp32divtwo(ysize, u);
+ mp32divtwo(ysize, v);
+ }
+
+if (_debug < 0)
+fprintf(stderr, " u: "), mp32println(stderr, ysize, u);
+if (_debug < 0)
+fprintf(stderr, " v: "), mp32println(stderr, ysize, v);
+
+ /* Y2. Initialize. */
+ mp32setw(ysize, u1, 1);
+if (_debug < 0)
+fprintf(stderr, " u1: "), mp32println(stderr, ysize, u1);
+ mp32zero(ysize, u2);
+if (_debug < 0)
+fprintf(stderr, " u2: "), mp32println(stderr, ysize, u2);
+ mp32setx(ysize, u3, ysize, u);
+if (_debug < 0)
+fprintf(stderr, " u3: "), mp32println(stderr, ysize, u3);
+
+ mp32setx(ysize, v1, ysize, v);
+if (_debug < 0)
+fprintf(stderr, " v1: "), mp32println(stderr, ysize, v1);
+ mp32setw(ysize, v2, 1);
+ (void) mp32sub(ysize, v2, u);
+if (_debug < 0)
+fprintf(stderr, " v2: "), mp32println(stderr, ysize, v2);
+ mp32setx(ysize, v3, ysize, v);
+if (_debug < 0)
+fprintf(stderr, " v3: "), mp32println(stderr, ysize, v3);
+
+ if (mp32odd(ysize, u)) {
+ mp32zero(ysize, t1);
+if (_debug < 0)
+fprintf(stderr, " t1: "), mp32println(stderr, ysize, t1);
+ mp32zero(ysize, t2);
+ mp32subw(ysize, t2, 1);
+if (_debug < 0)
+fprintf(stderr, " t2: "), mp32println(stderr, ysize, t2);
+ mp32zero(ysize, t3);
+ mp32sub(ysize, t3, v);
+if (_debug < 0)
+fprintf(stderr, " t3: "), mp32println(stderr, ysize, t3);
+ goto Y4;
+ } else {
+ mp32setw(ysize, t1, 1);
+if (_debug < 0)
+fprintf(stderr, " t1: "), mp32println(stderr, ysize, t1);
+ mp32zero(ysize, t2);
+if (_debug < 0)
+fprintf(stderr, " t2: "), mp32println(stderr, ysize, t2);
+ mp32setx(ysize, t3, ysize, u);
+if (_debug < 0)
+fprintf(stderr, " t3: "), mp32println(stderr, ysize, t3);
+ }
+
+ do {
+ do {
+ if (mp32odd(ysize, t1) || mp32odd(ysize, t2)) {
+ mp32add(ysize, t1, v);
+ mp32sub(ysize, t2, u);
+ }
+ mp32sdivtwo(ysize, t1);
+ mp32sdivtwo(ysize, t2);
+ mp32sdivtwo(ysize, t3);
+Y4:
+if (_debug < 0)
+fprintf(stderr, " Y4 t3: "), mp32println(stderr, ysize, t3);
+ } while (mp32even(ysize, t3));
+
+ /* Y5. Reset max(u3,v3). */
+ if (!(*t3 & 0x80000000)) {
+if (_debug < 0)
+fprintf(stderr, "--> Y5 (t3 > 0)\n");
+ mp32setx(ysize, u1, ysize, t1);
+if (_debug < 0)
+fprintf(stderr, " u1: "), mp32println(stderr, ysize, u1);
+ mp32setx(ysize, u2, ysize, t2);
+if (_debug < 0)
+fprintf(stderr, " u2: "), mp32println(stderr, ysize, u2);
+ mp32setx(ysize, u3, ysize, t3);
+if (_debug < 0)
+fprintf(stderr, " u3: "), mp32println(stderr, ysize, u3);
+ } else {
+if (_debug < 0)
+fprintf(stderr, "--> Y5 (t3 <= 0)\n");
+ mp32setx(ysize, v1, ysize, v);
+ mp32sub(ysize, v1, t1);
+if (_debug < 0)
+fprintf(stderr, " v1: "), mp32println(stderr, ysize, v1);
+ mp32setx(ysize, v2, ysize, u);
+ mp32neg(ysize, v2);
+ mp32sub(ysize, v2, t2);
+if (_debug < 0)
+fprintf(stderr, " v2: "), mp32println(stderr, ysize, v2);
+ mp32zero(ysize, v3);
+ mp32sub(ysize, v3, t3);
+if (_debug < 0)
+fprintf(stderr, " v3: "), mp32println(stderr, ysize, v3);
+ }
+
+ /* Y6. Subtract. */
+ mp32setx(ysize, t1, ysize, u1);
+ mp32sub(ysize, t1, v1);
+ mp32setx(ysize, t2, ysize, u2);
+ mp32sub(ysize, t2, v2);
+ mp32setx(ysize, t3, ysize, u3);
+ mp32sub(ysize, t3, v3);
+
+ if (*t1 & 0x80000000) {
+ mp32add(ysize, t1, v);
+ mp32sub(ysize, t2, u);
+ }
+
+if (_debug < 0)
+fprintf(stderr, "-->Y6 t1: "), mp32println(stderr, ysize, t1);
+if (_debug < 0)
+fprintf(stderr, " t2: "), mp32println(stderr, ysize, t2);
+if (_debug < 0)
+fprintf(stderr, " t3: "), mp32println(stderr, ysize, t3);
+
+ } while (mp32nz(ysize, t3));
+
+ if (!(mp32isone(ysize, u3) && mp32isone(ysize, v3)))
+ return 0;
+
+ if (result) {
+ while (--k > 0)
+ mp32add(ysize, u1, u1);
+ mp32setx(b->size, result, ysize, u1);
+ }
+
+if (_debug) {
+fprintf(stderr, "=== EXIT: "), mp32println(stderr, b->size, result);
+fprintf(stderr, " u1: "), mp32println(stderr, ysize, u1);
+fprintf(stderr, " u2: "), mp32println(stderr, ysize, u2);
+fprintf(stderr, " u3: "), mp32println(stderr, ysize, u3);
+fprintf(stderr, " v1: "), mp32println(stderr, ysize, v1);
+fprintf(stderr, " v2: "), mp32println(stderr, ysize, v2);
+fprintf(stderr, " v3: "), mp32println(stderr, ysize, v3);
+fprintf(stderr, " t1: "), mp32println(stderr, ysize, t1);
+fprintf(stderr, " t2: "), mp32println(stderr, ysize, t2);
+fprintf(stderr, " t3: "), mp32println(stderr, ysize, t3);
+}
+
+ return 1;
+}
+
+#endif
/**
* needs workspace of (7*size+2) words
diff --git a/beecrypt/tests/beetest.c b/beecrypt/tests/beetest.c
index 098500cb0..56b03546a 100644
--- a/beecrypt/tests/beetest.c
+++ b/beecrypt/tests/beetest.c
@@ -80,7 +80,7 @@ static const char* elg_n = "8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8
register int rc;
register uint32 size = keypair->param.p.size;
- register uint32* temp = (uint32*) malloc((8*size+6) * sizeof(uint32));
+ register uint32* temp = (uint32*) malloc((13*size+11) * sizeof(uint32));
/*@-nullpass -nullptrarith @*/ /* temp may be NULL */
mp32brndinv_w(&keypair->param.n, &rngc, temp, temp+size, temp+2*size);
@@ -316,9 +316,9 @@ static int testVectorDHAES(const dlkp_p* keypair)
memset(&kp, 0, sizeof(rsakp));
(void) rsakpInit(&kp);
- printf("making RSA CRT keypair\n");
+ fprintf(stdout, "making RSA CRT keypair\n");
(void) rsakpMake(&kp, &rngc, 32);
- printf("RSA CRT keypair generated\n");
+ fprintf(stdout, "RSA CRT keypair generated\n");
mp32nzero(&digest);
mp32nzero(&s);
@@ -466,7 +466,7 @@ static void testBlockCiphers(void)
{
int i, k;
- printf(" Testing the blockciphers:\n");
+ fprintf(stdout, " Testing the blockciphers:\n");
for (i = 0; i < blockCipherCount(); i++)
{
@@ -489,26 +489,26 @@ static void testBlockCiphers(void)
if (decrypt_param)
memset(decrypt_param, 0, tmp->paramsize);
- printf(" %s:\n", tmp->name);
+ fprintf(stdout, " %s:\n", tmp->name);
/*@-nullpass@*/ /* malloc can return NULL */
for (k = tmp->keybitsmin; k <= tmp->keybitsmax; k += tmp->keybitsinc)
{
- printf(" setup encrypt (%d bits key): ", k);
+ fprintf(stdout, " setup encrypt (%d bits key): ", k);
if (tmp->setup(encrypt_param, keyValue, k, ENCRYPT) < 0)
{
- printf("failed\n");
+ fprintf(stdout, "failed\n");
/*@innercontinue@*/ continue;
}
- printf("ok\n");
- printf(" setup decrypt (%d bits key): ", k);
+ fprintf(stdout, "ok\n");
+ fprintf(stdout, " setup decrypt (%d bits key): ", k);
if (tmp->setup(decrypt_param, keyValue, k, DECRYPT) < 0)
{
- printf("failed\n");
+ fprintf(stdout, "failed\n");
/*@innercontinue@*/ continue;
}
- printf("ok\n");
- printf(" encrypt/decrypt test block: ");
+ fprintf(stdout, "ok\n");
+ fprintf(stdout, " encrypt/decrypt test block: ");
testBlockInit((uint8*) src_block, tmp->blocksize >> 2);
(void) blockEncrypt(tmp, encrypt_param, CBC, 2, enc_block, src_block);
@@ -516,11 +516,11 @@ static void testBlockCiphers(void)
if (memcmp(dec_block, src_block, tmp->blocksize >> 2))
{
- printf("failed\n");
+ fprintf(stdout, "failed\n");
/*@innercontinue@*/ continue;
}
- printf("ok\n");
- printf(" speed measurement:\n");
+ fprintf(stdout, "ok\n");
+ fprintf(stdout, " speed measurement:\n");
{
#if HAVE_TIME_H
double ttime;
@@ -536,7 +536,7 @@ static void testBlockCiphers(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" ECB encrypts 1M blocks of %d bits in %.3f seconds (%.3f MB/s)\n", (int)(tmp->blocksize << 3), ttime, (tmp->blocksize) / ttime);
+ fprintf(stdout, " ECB encrypts 1M blocks of %d bits in %.3f seconds (%.3f MB/s)\n", (int)(tmp->blocksize << 3), ttime, (tmp->blocksize) / ttime);
#endif
#if HAVE_TIME_H
tstart = clock();
@@ -545,7 +545,7 @@ static void testBlockCiphers(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" ECB decrypts 1M blocks of %d bits in %.3f seconds (%.3f MB/s)\n", (int)(tmp->blocksize << 3), ttime, (tmp->blocksize) / ttime);
+ fprintf(stdout, " ECB decrypts 1M blocks of %d bits in %.3f seconds (%.3f MB/s)\n", (int)(tmp->blocksize << 3), ttime, (tmp->blocksize) / ttime);
#endif
#if HAVE_TIME_H
tstart = clock();
@@ -554,7 +554,7 @@ static void testBlockCiphers(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" CBC encrypts 1M blocks of %d bits in %.3f seconds (%.3f MB/s)\n", (int)(tmp->blocksize << 3), ttime, (tmp->blocksize) / ttime);
+ fprintf(stdout, " CBC encrypts 1M blocks of %d bits in %.3f seconds (%.3f MB/s)\n", (int)(tmp->blocksize << 3), ttime, (tmp->blocksize) / ttime);
#endif
#if HAVE_TIME_H
tstart = clock();
@@ -563,7 +563,7 @@ static void testBlockCiphers(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" CBC decrypts 1M blocks of %d bits in %.3f seconds (%.3f MB/s)\n", (int)(tmp->blocksize << 3), ttime, (tmp->blocksize) / ttime);
+ fprintf(stdout, " CBC decrypts 1M blocks of %d bits in %.3f seconds (%.3f MB/s)\n", (int)(tmp->blocksize << 3), ttime, (tmp->blocksize) / ttime);
#endif
}
}
@@ -591,7 +591,7 @@ static void testHashFunctions(void)
hashFunctionContext hfc;
memset(&hfc, 0, sizeof(hashFunctionContext));
- printf(" Testing the hash functions:\n");
+ fprintf(stdout, " Testing the hash functions:\n");
/*@-branchstate@*/ /* FIX: hfc.param released */
for (i = 0; i < hashFunctionCount(); i++)
@@ -608,7 +608,7 @@ static void testHashFunctions(void)
mp32nzero(&digest);
- printf(" %s:\n", tmp->name);
+ fprintf(stdout, " %s:\n", tmp->name);
/*@-nullpass -modobserver @*/
if (hashFunctionContextInit(&hfc, tmp) == 0)
@@ -628,7 +628,7 @@ static void testHashFunctions(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" hashes 32 MB in %.3f seconds (%.3f MB/s)\n", ttime, 32.0 / ttime);
+ fprintf(stdout, " hashes 32 MB in %.3f seconds (%.3f MB/s)\n", ttime, 32.0 / ttime);
#endif
}
@@ -681,8 +681,8 @@ static void testExpMods(void)
clock_t tstart, tstop;
#endif
- printf("Timing modular exponentiations\n");
- printf(" (512 bits ^ 512 bits) mod 512 bits:");
+ fprintf(stdout, "Timing modular exponentiations\n");
+ fprintf(stdout, " (512 bits ^ 512 bits) mod 512 bits:");
mp32nsethex(&tmp, p_512);
mp32bset(&p, tmp.size, tmp.data);
mp32nsize(&g, p.size);
@@ -697,9 +697,9 @@ static void testExpMods(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" 100x in %.3f seconds\n", ttime);
+ fprintf(stdout, " 100x in %.3f seconds\n", ttime);
#endif
- printf(" (768 bits ^ 768 bits) mod 768 bits:");
+ fprintf(stdout, " (768 bits ^ 768 bits) mod 768 bits:");
mp32nsethex(&tmp, p_768);
mp32bset(&p, tmp.size, tmp.data);
mp32nsize(&g, p.size);
@@ -714,9 +714,9 @@ static void testExpMods(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" 100x in %.3f seconds\n", ttime);
+ fprintf(stdout, " 100x in %.3f seconds\n", ttime);
#endif
- printf(" (1024 bits ^ 1024 bits) mod 1024 bits:");
+ fprintf(stdout, " (1024 bits ^ 1024 bits) mod 1024 bits:");
mp32nsethex(&tmp, p_1024);
mp32bset(&p, tmp.size, tmp.data);
mp32nsize(&g, p.size);
@@ -731,14 +731,14 @@ static void testExpMods(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" 100x in %.3f seconds\n", ttime);
+ fprintf(stdout, " 100x in %.3f seconds\n", ttime);
#endif
/* now run a test with x having 160 bits */
mp32nsize(&x, 5);
/*@-noeffectuncon@*/ /* LCL: ??? */
(void) rngc.rng->next(rngc.param, x.data, x.size);
/*@=noeffectuncon@*/
- printf(" (1024 bits ^ 160 bits) mod 1024 bits:");
+ fprintf(stdout, " (1024 bits ^ 160 bits) mod 1024 bits:");
#if HAVE_TIME_H
tstart = clock();
#endif
@@ -747,7 +747,7 @@ static void testExpMods(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" 100x in %.3f seconds\n", ttime);
+ fprintf(stdout, " 100x in %.3f seconds\n", ttime);
#endif
mp32bfree(&p);
mp32nfree(&g);
@@ -760,7 +760,7 @@ static void testExpMods(void)
/*@=modobserver@*/
}
else
- printf("random generator setup problem\n");
+ fprintf(stdout, "random generator setup problem\n");
}
static void testDLAlgorithms(void)
@@ -793,7 +793,7 @@ static void testDLAlgorithms(void)
double ttime;
clock_t tstart, tstop;
#endif
- printf("Generating P (1024 bits) Q (160 bits) G with order Q\n");
+ fprintf(stdout, "Generating P (1024 bits) Q (160 bits) G with order Q\n");
#if HAVE_TIME_H
tstart = clock();
#endif
@@ -801,11 +801,11 @@ static void testDLAlgorithms(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" done in %.3f seconds\n", ttime);
+ fprintf(stdout, " done in %.3f seconds\n", ttime);
#endif
(void) dlkp_pInit(&kp);
- printf("Generating keypair\n");
+ fprintf(stdout, "Generating keypair\n");
#if HAVE_TIME_H
tstart = clock();
#endif
@@ -813,7 +813,7 @@ static void testDLAlgorithms(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" done in %.3f seconds\n", ttime);
+ fprintf(stdout, " done in %.3f seconds\n", ttime);
#endif
mp32nsize(&hm, 5);
@@ -821,7 +821,7 @@ static void testDLAlgorithms(void)
(void) rngc.rng->next(rngc.param, hm.data, hm.size);
/*@=noeffectuncon@*/
- printf("DSA signing (%u bits)\n", kp.param.p.size << 5);
+ fprintf(stdout, "DSA signing (%u bits)\n", kp.param.p.size << 5);
#if HAVE_TIME_H
tstart = clock();
#endif
@@ -832,10 +832,10 @@ static void testDLAlgorithms(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" 100x in %.3f seconds\n", ttime);
+ fprintf(stdout, " 100x in %.3f seconds\n", ttime);
#endif
- printf("DSA verification (%u bits)\n", kp.param.p.size << 5);
+ fprintf(stdout, "DSA verification (%u bits)\n", kp.param.p.size << 5);
#if HAVE_TIME_H
tstart = clock();
#endif
@@ -848,14 +848,14 @@ static void testDLAlgorithms(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" 100x in %.3f seconds\n", ttime);
+ fprintf(stdout, " 100x in %.3f seconds\n", ttime);
#endif
(void) dlkp_pFree(&kp);
memset(&kp, 0, sizeof(dlkp_p));
(void) dldp_pFree(&dp);
memset(&dp, 0, sizeof(dldp_p));
- printf("Generating P (1024 bits) Q (768 bits) G with order (P-1)\n");
+ fprintf(stdout, "Generating P (1024 bits) Q (768 bits) G with order (P-1)\n");
#if HAVE_TIME_H
tstart = clock();
#endif
@@ -863,7 +863,7 @@ static void testDLAlgorithms(void)
#if HAVE_TIME_H
tstop = clock();
ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC;
- printf(" done in %.3f seconds\n", ttime);
+ fprintf(stdout, " done in %.3f seconds\n", ttime);
#endif
(void) dldp_pFree(&dp);
memset(&dp, 0, sizeof(dldp_p));
@@ -880,17 +880,17 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[])
dlkp_p keypair;
if (testVectorMD5())
- printf("MD5 works!\n");
+ fprintf(stdout, "MD5 works!\n");
else
exit(1);
if (testVectorSHA1())
- printf("SHA-1 works!\n");
+ fprintf(stdout, "SHA-1 works!\n");
else
exit(1);
if (testVectorSHA256())
- printf("SHA-256 works!\n");
+ fprintf(stdout, "SHA-256 works!\n");
else
exit(1);
@@ -904,33 +904,33 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[])
mp32nsethex(&keypair.x, dsa_x);
if (testVectorInvMod(&keypair))
- printf("InvMod works!\n");
+ fprintf(stdout, "InvMod works!\n");
else
exit(1);
if (testVectorExpMod(&keypair))
- printf("ExpMod works!\n");
+ fprintf(stdout, "ExpMod works!\n");
else
exit(1);
if (testVectorDSA(&keypair))
- printf("DSA works!\n");
+ fprintf(stdout, "DSA works!\n");
else
exit(1);
if (testVectorElGamalV1(&keypair))
- printf("ElGamal v1 works!\n");
+ fprintf(stdout, "ElGamal v1 works!\n");
else
exit(1);
if (testVectorElGamalV3(&keypair))
- printf("ElGamal v3 works!\n");
+ fprintf(stdout, "ElGamal v3 works!\n");
else
exit(1);
/*
if (testVectorDHAES(&keypair))
- printf("DHAES works!\n");
+ fprintf(stdout, "DHAES works!\n");
else
exit(1);
*/
@@ -938,12 +938,12 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[])
dlkp_pFree(&keypair);
if (testVectorRSA())
- printf("RSA works!\n");
+ fprintf(stdout, "RSA works!\n");
else
exit(1);
/*
if (testVectorDLDP())
- printf("dldp with generator of order q works!\n");
+ fprintf(stdout, "dldp with generator of order q works!\n");
else
exit(1);
*/
@@ -959,61 +959,61 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[])
int i, j;
- printf("the beecrypt library implements:\n");
- printf(" %d entropy source%s:\n", entropySourceCount(), entropySourceCount() == 1 ? "" : "s");
+ fprintf(stdout, "the beecrypt library implements:\n");
+ fprintf(stdout, " %d entropy source%s:\n", entropySourceCount(), entropySourceCount() == 1 ? "" : "s");
for (i = 0; i < entropySourceCount(); i++)
{
const entropySource* tmp = entropySourceGet(i);
if (tmp)
- printf(" %s\n", tmp->name);
+ fprintf(stdout, " %s\n", tmp->name);
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
- printf(" %d random generator%s:\n", randomGeneratorCount(), randomGeneratorCount() == 1 ? "" : "s");
+ fprintf(stdout, " %d random generator%s:\n", randomGeneratorCount(), randomGeneratorCount() == 1 ? "" : "s");
for (i = 0; i < randomGeneratorCount(); i++)
{
const randomGenerator* tmp = randomGeneratorGet(i);
if (tmp)
- printf(" %s\n", tmp->name);
+ fprintf(stdout, " %s\n", tmp->name);
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
- printf(" %d hash function%s:\n", hashFunctionCount(), hashFunctionCount() == 1 ? "" : "s");
+ fprintf(stdout, " %d hash function%s:\n", hashFunctionCount(), hashFunctionCount() == 1 ? "" : "s");
for (i = 0; i < hashFunctionCount(); i++)
{
const hashFunction* tmp = hashFunctionGet(i);
if (tmp)
- printf(" %s\n", tmp->name);
+ fprintf(stdout, " %s\n", tmp->name);
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
- printf(" %d keyed hash function%s:\n", keyedHashFunctionCount(), keyedHashFunctionCount() == 1 ? "" : "s");
+ fprintf(stdout, " %d keyed hash function%s:\n", keyedHashFunctionCount(), keyedHashFunctionCount() == 1 ? "" : "s");
for (i = 0; i < keyedHashFunctionCount(); i++)
{
const keyedHashFunction* tmp = keyedHashFunctionGet(i);
if (tmp)
- printf(" %s\n", tmp->name);
+ fprintf(stdout, " %s\n", tmp->name);
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
- printf(" %d blockcipher%s:\n", blockCipherCount(), blockCipherCount() == 1 ? "" : "s");
+ fprintf(stdout, " %d blockcipher%s:\n", blockCipherCount(), blockCipherCount() == 1 ? "" : "s");
for (i = 0; i < blockCipherCount(); i++)
{
const blockCipher* tmp = blockCipherGet(i);
if (tmp)
{
- printf(" %s ", tmp->name);
+ fprintf(stdout, " %s ", tmp->name);
for (j = tmp->keybitsmin; j <= tmp->keybitsmax; j += tmp->keybitsinc)
{
- printf("%d", j);
+ fprintf(stdout, "%d", j);
if (j < tmp->keybitsmax)
- printf("/");
+ fprintf(stdout, "/");
else
- printf(" bit keys\n");
+ fprintf(stdout, " bit keys\n");
}
}
else
- printf("*** error: library corrupt\n");
+ fprintf(stdout, "*** error: library corrupt\n");
}
/*@-modnomods@*/ /* LCL: ??? */
testBlockCiphers();
@@ -1024,17 +1024,17 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[])
/*@=modnomods@*/
if (testVectorMD5())
- printf("MD5 works!\n");
+ fprintf(stdout, "MD5 works!\n");
else
exit(EXIT_FAILURE);
if (testVectorSHA1())
- printf("SHA-1 works!\n");
+ fprintf(stdout, "SHA-1 works!\n");
else
exit(EXIT_FAILURE);
if (testVectorSHA256())
- printf("SHA-256 works!\n");
+ fprintf(stdout, "SHA-256 works!\n");
else
exit(EXIT_FAILURE);
@@ -1049,28 +1049,28 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[])
mp32nsethex(&keypair.x, dsa_x);
if (testVectorInvMod(&keypair))
- printf("InvMod works!\n");
+ fprintf(stdout, "InvMod works!\n");
else
exit(EXIT_FAILURE);
if (testVectorExpMod(&keypair))
- printf("ExpMod works!\n");
+ fprintf(stdout, "ExpMod works!\n");
else
exit(EXIT_FAILURE);
if (testVectorElGamalV1(&keypair))
- printf("ElGamal v1 works!\n");
+ fprintf(stdout, "ElGamal v1 works!\n");
else
exit(EXIT_FAILURE);
if (testVectorElGamalV3(&keypair))
- printf("ElGamal v3 works!\n");
+ fprintf(stdout, "ElGamal v3 works!\n");
else
exit(EXIT_FAILURE);
#if 0
if (testVectorDHAES(&keypair))
- printf("DHAES works!\n");
+ fprintf(stdout, "DHAES works!\n");
else
exit(EXIT_FAILURE);
#endif
@@ -1078,17 +1078,17 @@ int main(/*@unused@*/int argc, /*@unused@*/char *argv[])
(void) dlkp_pFree(&keypair);
if (testVectorRSA())
- printf("RSA works!\n");
+ fprintf(stdout, "RSA works!\n");
else
exit(EXIT_FAILURE);
#if 1
if (testVectorDLDP())
- printf("dldp with generator of order q works!\n");
+ fprintf(stdout, "dldp with generator of order q works!\n");
else
exit(EXIT_FAILURE);
#endif
- printf("done\n");
+ fprintf(stdout, "done\n");
return 0;
}