Use Knuth algorithm Y for computing DSA "w = inv(s) mod q".
CVS patchset: 5339 CVS date: 2002/02/28 15:48:39
This commit is contained in:
parent
87a411ddf2
commit
9aa5bedac7
|
@ -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;
|
||||
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);
|
||||
randomGeneratorContext rngc;
|
||||
|
||||
mp32nset(&y, p.size, p.data);
|
||||
|
||||
mp32nsethex(&tmp, dsa_y);
|
||||
if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0)
|
||||
{
|
||||
register int rc;
|
||||
|
||||
return mp32eqx(y.size, y.data, tmp.size, tmp.data);
|
||||
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 testVectorSHA()
|
||||
int testVectorExpMod(const dlkp_p* keypair)
|
||||
{
|
||||
int rc;
|
||||
mp32number y;
|
||||
|
||||
mp32nzero(&y);
|
||||
|
||||
mp32bnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y);
|
||||
|
||||
rc = mp32eqx(y.size, y.data, keypair->y.size, keypair->y.data);
|
||||
|
||||
mp32nfree(&y);
|
||||
|
||||
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);
|
||||
|
||||
randomGeneratorContextFree(&rngc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
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(¶m);
|
||||
md5Update(¶m, (const unsigned char*) "abc", 3);
|
||||
md5Digest(¶m, digest);
|
||||
|
||||
return mp32eq(4, expect, digest);
|
||||
}
|
||||
|
||||
int testVectorSHA1()
|
||||
{
|
||||
uint32 expect[5] = { 0xA9993E36, 0x4706816A, 0xBA3E2571, 0x7850C26C, 0x9CD0D89D };
|
||||
uint32 digest[5];
|
||||
sha1Param param;
|
||||
|
||||
sha1Reset(¶m);
|
||||
sha1Update(¶m, (const unsigned char *) "abc", 3);
|
||||
sha1Update(¶m, (const unsigned char*) "abc", 3);
|
||||
sha1Digest(¶m, 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(¶m);
|
||||
sha256Update(¶m, (const unsigned char*) "abc", 3);
|
||||
sha256Digest(¶m, 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);
|
||||
fprintf(stdout, "\t\tsetup encrypt (%d bits key): ", k);
|
||||
if (tmp->setup(encrypt_param, keyValue, k, ENCRYPT) < 0)
|
||||
{
|
||||
fprintf(stdout, "failed\n");
|
||||
continue;
|
||||
}
|
||||
fprintf(stdout, "ok\n");
|
||||
fprintf(stdout, "\t\tsetup decrypt (%d bits key): ", k);
|
||||
if (tmp->setup(decrypt_param, keyValue, k, DECRYPT) < 0)
|
||||
{
|
||||
fprintf(stdout, "failed\n");
|
||||
continue;
|
||||
}
|
||||
fprintf(stdout, "ok\n");
|
||||
fprintf(stdout, "\t\tencrypt/decrypt test block: ");
|
||||
testBlockInit((uint8*) src_block, tmp->blocksize >> 2);
|
||||
|
||||
testBlockInit((uint8*) key, k >> 3);
|
||||
blockEncrypt(tmp, encrypt_param, CBC, 2, enc_block, src_block);
|
||||
blockDecrypt(tmp, decrypt_param, CBC, 2, dec_block, enc_block);
|
||||
|
||||
printf("\t\tsetup encrypt (%d bits key): ", k);
|
||||
if (tmp->setup(encrypt_param, key, k, ENCRYPT) < 0)
|
||||
if (memcmp(dec_block, src_block, tmp->blocksize >> 2))
|
||||
{
|
||||
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)
|
||||
{
|
||||
free(key);
|
||||
printf("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))
|
||||
{
|
||||
free(key);
|
||||
printf("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(&rc);
|
||||
randomGeneratorContextFree(&rngc);
|
||||
}
|
||||
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);
|
||||
|
||||
randomGeneratorContextFree(&rc);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 @*/;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -828,6 +828,7 @@ verifyGPGSignature(rpmTransactionSet ts, /*@out@*/ char * t)
|
|||
|
||||
xx = rpmDigestUpdate(ctx, digp->hash, digp->hashlen);
|
||||
xx = rpmDigestFinal(ctx, (void **)&ts->dig->sha1, &ts->dig->sha1len, 1);
|
||||
|
||||
mp32nzero(&ts->dig->hm); mp32nsethex(&ts->dig->hm, ts->dig->sha1);
|
||||
}
|
||||
/*@=type@*/
|
||||
|
@ -837,6 +838,8 @@ verifyGPGSignature(rpmTransactionSet ts, /*@out@*/ char * t)
|
|||
/*@-globs -internalglobs -mods -modfilesys@*/
|
||||
if (gpgpk == NULL) {
|
||||
const char * pkfn = rpmExpand("%{_gpg_pubkey}", NULL);
|
||||
int printing = 0; /* XXX was rpmIsDebug() */
|
||||
|
||||
if (pgpReadPkts(pkfn, &gpgpk, &gpgpklen) != PGPARMOR_PUBKEY) {
|
||||
pkfn = _free(pkfn);
|
||||
res = RPMSIG_NOKEY;
|
||||
|
@ -844,7 +847,7 @@ verifyGPGSignature(rpmTransactionSet ts, /*@out@*/ char * t)
|
|||
}
|
||||
rpmMessage(RPMMESS_DEBUG,
|
||||
"========== GPG DSA pubkey %s\n", pkfn);
|
||||
xx = pgpPrtPkts(gpgpk, gpgpklen, NULL, rpmIsDebug());
|
||||
xx = pgpPrtPkts(gpgpk, gpgpklen, NULL, printing);
|
||||
pkfn = _free(pkfn);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
AUTOMAKE_OPTIONS = 1.4 foreign
|
||||
|
||||
EXTRA_DIST = tdigest.c tdir.c tficl.c tfts.c tglob.c tkey.c trpmio.c
|
||||
EXTRA_DIST = tdigest.c tdir.c tficl.c tfts.c tglob.c tinv.c tkey.c trpmio.c
|
||||
|
||||
EXTRA_PROGRAMS = tdigest tdir tfts tglob tkey tring trpmio dumpasn1
|
||||
EXTRA_PROGRAMS = tdigest tdir tfts tglob tinv tkey tring trpmio dumpasn1
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir) \
|
||||
|
@ -66,17 +66,21 @@ tglob_SOURCES = tglob.c
|
|||
tglob_LDFLAGS = -all-static
|
||||
tglob_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la
|
||||
|
||||
tinv_SOURCES = tinv.c
|
||||
tinv_LDFLAGS = -all-static
|
||||
tinv_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la
|
||||
|
||||
tkey_SOURCES = tkey.c
|
||||
tkey_LDFLAGS = -all-static
|
||||
tkey_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la
|
||||
|
||||
trpmio_SOURCES = trpmio.c
|
||||
trpmio_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la
|
||||
|
||||
tring_SOURCES = tring.c
|
||||
tring_LDFLAGS = -all-static
|
||||
tring_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la
|
||||
|
||||
trpmio_SOURCES = trpmio.c
|
||||
trpmio_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la
|
||||
|
||||
dumpasn1_SOURCES = dumpasn1.c
|
||||
|
||||
.PHONY: sources
|
||||
|
|
|
@ -335,7 +335,7 @@ fprintf(stderr, "*** %s %s\n", pre, t);
|
|||
mp32nsethex(mpn, t);
|
||||
t = _free(t);
|
||||
if (_debug && _print)
|
||||
printf("\t %s ", pre), mp32println(mpn->size, mpn->data);
|
||||
fprintf(stderr, "\t %s ", pre), mp32println(stderr, mpn->size, mpn->data);
|
||||
}
|
||||
|
||||
int pgpPrtSubType(const byte *h, unsigned int hlen)
|
||||
|
@ -459,7 +459,7 @@ static int pgpPrtSigParams(/*@unused@*/ pgpTag tag, byte pubkey_algo, byte sigty
|
|||
case 0: /* m**d */
|
||||
mp32nsethex(&_dig->c, pgpMpiHex(p));
|
||||
if (_debug && _print)
|
||||
printf("\t m**d = "), mp32println(_dig->c.size, _dig->c.data);
|
||||
fprintf(stderr, "\t m**d = "), mp32println(stderr, _dig->c.size, _dig->c.data);
|
||||
/*@switchbreak@*/ break;
|
||||
default:
|
||||
/*@switchbreak@*/ break;
|
||||
|
@ -679,12 +679,12 @@ static const byte * pgpPrtPubkeyParams(byte pubkey_algo,
|
|||
memcpy(_digp->signid, keyid, sizeof(_digp->signid));
|
||||
}
|
||||
if (_debug && _print)
|
||||
printf("\t n = "), mp32println(_dig->rsa_pk.n.size, _dig->rsa_pk.n.modl);
|
||||
fprintf(stderr, "\t n = "), mp32println(stderr, _dig->rsa_pk.n.size, _dig->rsa_pk.n.modl);
|
||||
/*@switchbreak@*/ break;
|
||||
case 1: /* e */
|
||||
mp32nsethex(&_dig->rsa_pk.e, pgpMpiHex(p));
|
||||
if (_debug && _print)
|
||||
printf("\t e = "), mp32println(_dig->rsa_pk.e.size, _dig->rsa_pk.e.data);
|
||||
fprintf(stderr, "\t e = "), mp32println(stderr, _dig->rsa_pk.e.size, _dig->rsa_pk.e.data);
|
||||
/*@switchbreak@*/ break;
|
||||
default:
|
||||
/*@switchbreak@*/ break;
|
||||
|
@ -700,22 +700,22 @@ printf("\t e = "), mp32println(_dig->rsa_pk.e.size, _dig->rsa_pk.e.data);
|
|||
case 0: /* p */
|
||||
mp32bsethex(&_dig->p, pgpMpiHex(p));
|
||||
if (_debug && _print)
|
||||
printf("\t p = "), mp32println(_dig->p.size, _dig->p.modl);
|
||||
fprintf(stderr, "\t p = "), mp32println(stderr, _dig->p.size, _dig->p.modl);
|
||||
/*@switchbreak@*/ break;
|
||||
case 1: /* q */
|
||||
mp32bsethex(&_dig->q, pgpMpiHex(p));
|
||||
if (_debug && _print)
|
||||
printf("\t q = "), mp32println(_dig->q.size, _dig->q.modl);
|
||||
fprintf(stderr, "\t q = "), mp32println(stderr, _dig->q.size, _dig->q.modl);
|
||||
/*@switchbreak@*/ break;
|
||||
case 2: /* g */
|
||||
mp32nsethex(&_dig->g, pgpMpiHex(p));
|
||||
if (_debug && _print)
|
||||
printf("\t g = "), mp32println(_dig->g.size, _dig->g.data);
|
||||
fprintf(stderr, "\t g = "), mp32println(stderr, _dig->g.size, _dig->g.data);
|
||||
/*@switchbreak@*/ break;
|
||||
case 3: /* y */
|
||||
mp32nsethex(&_dig->y, pgpMpiHex(p));
|
||||
if (_debug && _print)
|
||||
printf("\t y = "), mp32println(_dig->y.size, _dig->y.data);
|
||||
fprintf(stderr, "\t y = "), mp32println(stderr, _dig->y.size, _dig->y.data);
|
||||
/*@switchbreak@*/ break;
|
||||
default:
|
||||
/*@switchbreak@*/ break;
|
||||
|
|
|
@ -92,7 +92,6 @@ static void ftsWalk(const char * path)
|
|||
{
|
||||
const char * ftsSet[2];
|
||||
FTS * ftsp;
|
||||
int ftsOpts = (FTS_NOSTAT);
|
||||
FTSENT * fts;
|
||||
int xx;
|
||||
|
||||
|
|
320
rpmio/tinv.c
320
rpmio/tinv.c
|
@ -26,7 +26,6 @@ static int Zmp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata,
|
|||
mp32zero(ysize, C);
|
||||
mp32setw(ysize, D, 1);
|
||||
|
||||
#ifdef NOTYET
|
||||
for (k = 0; mp32even(ysize, u) && mp32even(ysize, v); k++) {
|
||||
mp32divtwo(ysize, u);
|
||||
mp32divtwo(ysize, v);
|
||||
|
@ -34,19 +33,18 @@ static int Zmp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata,
|
|||
|
||||
if (mp32even(ysize, u))
|
||||
(void) mp32add(ysize, u, v);
|
||||
#endif
|
||||
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u: "), mp32println(stderr, ysize, u);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v: "), mp32println(stderr, ysize, v);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " A: "), mp32println(stderr, ysize, A);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " B: "), mp32println(stderr, ysize, B);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " C: "), mp32println(stderr, ysize, C);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " D: "), mp32println(stderr, ysize, D);
|
||||
|
||||
ubits = vbits = 32 * (ysize);
|
||||
|
@ -61,7 +59,7 @@ fprintf(stderr, " D: "), mp32println(stderr, ysize, D);
|
|||
}
|
||||
mp32sdivtwo(ysize, C);
|
||||
mp32sdivtwo(ysize, D);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "-->> v: "), mp32println(stderr, ysize, v);
|
||||
}
|
||||
|
||||
|
@ -69,7 +67,7 @@ fprintf(stderr, "-->> v: "), mp32println(stderr, ysize, v);
|
|||
uint32* swapu;
|
||||
uint32 swapi;
|
||||
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "--> (swap u <-> v)\n");
|
||||
swapu = u; u = v; v = swapu;
|
||||
swapi = ubits; ubits = vbits; vbits = swapi;
|
||||
|
@ -78,37 +76,40 @@ fprintf(stderr, "--> (swap u <-> v)\n");
|
|||
}
|
||||
|
||||
if (!((u[ysize-1] + v[ysize-1]) & 0x3)) {
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "--> (even parity)\n");
|
||||
mp32add(ysize, v, u);
|
||||
mp32add(ysize, C, A);
|
||||
mp32add(ysize, D, B);
|
||||
} else {
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "--> (odd parity)\n");
|
||||
mp32sub(ysize, v, u);
|
||||
mp32sub(ysize, C, A);
|
||||
mp32sub(ysize, D, B);
|
||||
}
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v: "), mp32println(stderr, ysize, v);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " C: "), mp32println(stderr, ysize, C);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " D: "), mp32println(stderr, ysize, D);
|
||||
vbits++;
|
||||
} while (mp32nz(ysize, v));
|
||||
|
||||
if (result) {
|
||||
#ifdef NOTYET
|
||||
if (!mp32isone(ysize, u))
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (result) {
|
||||
mp32setx(b->size, result, ysize, A);
|
||||
/*@-usedef@*/
|
||||
if (*A & 0x80000000)
|
||||
(void) mp32neg(ysize, A);
|
||||
(void) mp32neg(b->size, result);
|
||||
/*@=usedef@*/
|
||||
while (--k > 0)
|
||||
mp32add(ysize, A, A);
|
||||
#endif
|
||||
mp32setx(b->size, result, ysize, A);
|
||||
mp32add(b->size, result, result);
|
||||
}
|
||||
|
||||
fprintf(stderr, "=== EXIT: "), mp32println(stderr, b->size, result);
|
||||
|
@ -147,55 +148,55 @@ static int Ymp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata,
|
|||
mp32divtwo(ysize, v);
|
||||
}
|
||||
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u: "), mp32println(stderr, ysize, u);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v: "), mp32println(stderr, ysize, v);
|
||||
|
||||
/* Y2. Initialize. */
|
||||
mp32setw(ysize, u1, 1);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u1: "), mp32println(stderr, ysize, u1);
|
||||
mp32zero(ysize, u2);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u2: "), mp32println(stderr, ysize, u2);
|
||||
mp32setx(ysize, u3, ysize, u);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u3: "), mp32println(stderr, ysize, u3);
|
||||
|
||||
mp32setx(ysize, v1, ysize, v);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v1: "), mp32println(stderr, ysize, v1);
|
||||
mp32setw(ysize, v2, 1);
|
||||
(void) mp32sub(ysize, v2, u);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v2: "), mp32println(stderr, ysize, v2);
|
||||
mp32setx(ysize, v3, ysize, v);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v3: "), mp32println(stderr, ysize, v3);
|
||||
|
||||
if (mp32odd(ysize, u)) {
|
||||
mp32zero(ysize, t1);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " t1: "), mp32println(stderr, ysize, t1);
|
||||
mp32zero(ysize, t2);
|
||||
mp32subw(ysize, t2, 1);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " t2: "), mp32println(stderr, ysize, t2);
|
||||
mp32zero(ysize, t3);
|
||||
mp32sub(ysize, t3, v);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " t3: "), mp32println(stderr, ysize, t3);
|
||||
goto Y4;
|
||||
} else {
|
||||
mp32setw(ysize, t1, 1);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " t1: "), mp32println(stderr, ysize, t1);
|
||||
mp32zero(ysize, t2);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " t2: "), mp32println(stderr, ysize, t2);
|
||||
mp32setx(ysize, t3, ysize, u);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " t3: "), mp32println(stderr, ysize, t3);
|
||||
}
|
||||
|
||||
|
@ -209,38 +210,38 @@ fprintf(stderr, " t3: "), mp32println(stderr, ysize, t3);
|
|||
mp32sdivtwo(ysize, t2);
|
||||
mp32sdivtwo(ysize, t3);
|
||||
Y4:
|
||||
if (_debug)
|
||||
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)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "--> Y5 (t3 > 0)\n");
|
||||
mp32setx(ysize, u1, ysize, t1);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u1: "), mp32println(stderr, ysize, u1);
|
||||
mp32setx(ysize, u2, ysize, t2);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u2: "), mp32println(stderr, ysize, u2);
|
||||
mp32setx(ysize, u3, ysize, t3);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u3: "), mp32println(stderr, ysize, u3);
|
||||
} else {
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "--> Y5 (t3 <= 0)\n");
|
||||
mp32setx(ysize, v1, ysize, v);
|
||||
mp32sub(ysize, v1, t1);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v1: "), mp32println(stderr, ysize, v1);
|
||||
mp32setx(ysize, v2, ysize, u);
|
||||
mp32neg(ysize, v2);
|
||||
mp32sub(ysize, v2, t2);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v2: "), mp32println(stderr, ysize, v2);
|
||||
mp32zero(ysize, v3);
|
||||
mp32sub(ysize, v3, t3);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v3: "), mp32println(stderr, ysize, v3);
|
||||
}
|
||||
|
||||
|
@ -257,15 +258,18 @@ fprintf(stderr, " v3: "), mp32println(stderr, ysize, v3);
|
|||
mp32sub(ysize, t2, u);
|
||||
}
|
||||
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "-->Y6 t1: "), mp32println(stderr, ysize, t1);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " t2: "), mp32println(stderr, ysize, t2);
|
||||
if (_debug)
|
||||
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);
|
||||
|
@ -316,147 +320,89 @@ static int Xmp32binv_w(const mp32barrett* b, uint32 xsize, const uint32* xdata,
|
|||
mp32zero(ysize, C);
|
||||
mp32setw(ysize, D, 1);
|
||||
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u: "), mp32println(stderr, ysize, u);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v: "), mp32println(stderr, ysize, v);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " A: "), mp32println(stderr, ysize, A);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " B: "), mp32println(stderr, ysize, B);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " C: "), mp32println(stderr, ysize, C);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " D: "), mp32println(stderr, ysize, D);
|
||||
|
||||
#ifdef NOTNOW
|
||||
if (mp32odd(b->size, b->modl) && mp32even(xsize, xdata))
|
||||
{
|
||||
/* use simplified binary extended gcd algorithm */
|
||||
|
||||
while (1)
|
||||
do {
|
||||
while (mp32even(ysize, u))
|
||||
{
|
||||
while (mp32even(ysize, u))
|
||||
{
|
||||
mp32divtwo(ysize, u);
|
||||
mp32divtwo(ysize, u);
|
||||
|
||||
if (mp32odd(ysize, B))
|
||||
(void) mp32subx(ysize, B, b->size, b->modl);
|
||||
|
||||
mp32sdivtwo(ysize, B);
|
||||
}
|
||||
while (mp32even(ysize, v))
|
||||
if (mp32odd(ysize, A) || mp32odd(ysize, B))
|
||||
{
|
||||
mp32divtwo(ysize, v);
|
||||
|
||||
if (mp32odd(ysize, D))
|
||||
(void) mp32subx(ysize, D, b->size, b->modl);
|
||||
|
||||
mp32sdivtwo(ysize, D);
|
||||
}
|
||||
if (mp32ge(ysize, u, v))
|
||||
{
|
||||
(void) mp32sub(ysize, u, v);
|
||||
(void) mp32sub(ysize, B, D);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void) mp32sub(ysize, v, u);
|
||||
(void) mp32sub(ysize, D, B);
|
||||
(void) mp32addx(ysize, A, xsize, xdata);
|
||||
(void) mp32subx(ysize, B, b->size, b->modl);
|
||||
}
|
||||
|
||||
if (mp32z(ysize, u))
|
||||
{
|
||||
if (mp32isone(ysize, v))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
mp32setx(size, result, ysize, D);
|
||||
/*@-usedef@*/
|
||||
if (*D & 0x80000000)
|
||||
(void) mp32add(b->size, result, b->modl);
|
||||
/*@=usedef@*/
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
mp32sdivtwo(ysize, A);
|
||||
mp32sdivtwo(ysize, B);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* use full binary extended gcd algorithm */
|
||||
|
||||
while (1)
|
||||
while (mp32even(ysize, v))
|
||||
{
|
||||
while (mp32even(ysize, u))
|
||||
mp32divtwo(ysize, v);
|
||||
|
||||
if (mp32odd(ysize, C) || mp32odd(ysize, D))
|
||||
{
|
||||
mp32divtwo(ysize, u);
|
||||
|
||||
if (mp32odd(ysize, A) || mp32odd(ysize, B))
|
||||
{
|
||||
(void) mp32addx(ysize, A, xsize, xdata);
|
||||
(void) mp32subx(ysize, B, b->size, b->modl);
|
||||
}
|
||||
|
||||
mp32sdivtwo(ysize, A);
|
||||
mp32sdivtwo(ysize, B);
|
||||
(void) mp32addx(ysize, C, xsize, xdata);
|
||||
(void) mp32subx(ysize, D, b->size, b->modl);
|
||||
}
|
||||
while (mp32even(ysize, v))
|
||||
{
|
||||
mp32divtwo(ysize, v);
|
||||
|
||||
if (mp32odd(ysize, C) || mp32odd(ysize, D))
|
||||
{
|
||||
(void) mp32addx(ysize, C, xsize, xdata);
|
||||
(void) mp32subx(ysize, D, b->size, b->modl);
|
||||
}
|
||||
|
||||
mp32sdivtwo(ysize, C);
|
||||
mp32sdivtwo(ysize, D);
|
||||
}
|
||||
if (mp32ge(ysize, u, v))
|
||||
{
|
||||
if (_debug)
|
||||
mp32sdivtwo(ysize, C);
|
||||
mp32sdivtwo(ysize, D);
|
||||
}
|
||||
if (mp32ge(ysize, u, v))
|
||||
{
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "--> 5 (u >= v)\n");
|
||||
(void) mp32sub(ysize, u, v);
|
||||
(void) mp32sub(ysize, A, C);
|
||||
(void) mp32sub(ysize, B, D);
|
||||
if (_debug)
|
||||
(void) mp32sub(ysize, u, v);
|
||||
(void) mp32sub(ysize, A, C);
|
||||
(void) mp32sub(ysize, B, D);
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " u: "), mp32println(stderr, ysize, u);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " A: "), mp32println(stderr, ysize, A);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " B: "), mp32println(stderr, ysize, B);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_debug)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, "--> 5 (u < v)\n");
|
||||
(void) mp32sub(ysize, v, u);
|
||||
(void) mp32sub(ysize, C, A);
|
||||
(void) mp32sub(ysize, D, B);
|
||||
if (_debug)
|
||||
(void) mp32sub(ysize, v, u);
|
||||
(void) mp32sub(ysize, C, A);
|
||||
(void) mp32sub(ysize, D, B);
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " v: "), mp32println(stderr, ysize, v);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " C: "), mp32println(stderr, ysize, C);
|
||||
if (_debug)
|
||||
if (_debug < 0)
|
||||
fprintf(stderr, " D: "), mp32println(stderr, ysize, D);
|
||||
}
|
||||
}
|
||||
|
||||
} while (mp32nz(ysize, u));
|
||||
|
||||
if (!mp32isone(ysize, v))
|
||||
return 0;
|
||||
|
||||
if (result)
|
||||
{
|
||||
mp32setx(b->size, result, ysize, D);
|
||||
/*@-usedef@*/
|
||||
if (*D & 0x80000000)
|
||||
(void) mp32add(b->size, result, b->modl);
|
||||
/*@=usedef@*/
|
||||
}
|
||||
|
||||
if (mp32z(ysize, u))
|
||||
{
|
||||
if (mp32isone(ysize, v))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
mp32setx(b->size, result, ysize, D);
|
||||
/*@-usedef@*/
|
||||
if (*D & 0x80000000)
|
||||
(void) mp32add(b->size, result, b->modl);
|
||||
/*@=usedef@*/
|
||||
}
|
||||
fprintf(stderr, "=== EXIT: "), mp32println(stderr, b->size, result);
|
||||
fprintf(stderr, " u: "), mp32println(stderr, ysize, u);
|
||||
fprintf(stderr, " v: "), mp32println(stderr, ysize, v);
|
||||
|
@ -464,30 +410,49 @@ fprintf(stderr, " A: "), mp32println(stderr, ysize, A);
|
|||
fprintf(stderr, " B: "), mp32println(stderr, ysize, B);
|
||||
fprintf(stderr, " C: "), mp32println(stderr, ysize, C);
|
||||
fprintf(stderr, " D: "), mp32println(stderr, ysize, D);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char * dsa_q = "a1b35510319a59825c721e73e41d687ffe351bc9";
|
||||
static const char * dsa_s[] = {
|
||||
"0a73e678141aea7b4e5195afb7db3e9ec00f9f85", /* time-1.7-14.i386.rpm */
|
||||
"22e917d8a47462c09748e00aebbab5fd93793495", /* samba-2.2.1a-4.i386.rpm */
|
||||
"0476b30eb86899c6785fad4f7a62e43d59481273", /* gtkhtml-devel-0.9.2-9.i386.rpm */
|
||||
"8adbca132a0e6a2d2ee5bb2cd837b350c9f8db42", /* lha-1.00-17.i386.rpm */
|
||||
|
||||
"026efa7a5a60d29921ec93f503b5c483d131d8c4", /* jed-0.99.14-2.i386.rpm */
|
||||
"2e4ec3c986b5a1f8f77b0b9f911d4e1b0ed8d869", /* ttfonts-zh_TW-2.11-5.noarch.rpm */
|
||||
|
||||
"259e4859e65c2528d3c35eaf2717d8963c834e94", /* libxml2-2.4.2-1.i386.rpm */
|
||||
"45462b3534c2ff7a13f232a4e6e4460c61b2e232", /* slang-1.4.4-4.i386.rpm */
|
||||
"0a73e678141aea7b4e5195afb7db3e9ec00f9f85", /* time-1.7-14.i386.rpm */
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char * dsa_w_good[]= {
|
||||
"2659140a40cb05e85c536a299327addb0a762b8a", /* time-1.7-14.i386.rpm */
|
||||
"8b2eeda5fd34067c248bc3262e28f5668e64500b", /* samba-2.2.1a-4.i386.rpm */
|
||||
"98f6a05c5cc17c2e48faad178d2c21c0bcca694b", /* gtkhtml-devel-0.9.2-9.i386.rpm */
|
||||
"8ec91350f3237ee249ea009143f692d4cc2f8d2e", /* lha-1.00-17.i386.rpm */
|
||||
|
||||
"7db9e81c6f60fdd29243f67b70af7d1d14c9c703", /* jed-0.99.14-2.i386.rpm */
|
||||
"6bdc316aef981e45c47dabab904a31747d349eec", /* ttfonts-zh_TW-2.11-5.noarch.rpm */
|
||||
|
||||
"6d1eaa6c78ad945a1de7bc369f7992e9df3735d9", /* libxml2-2.4.2-1.i386.rpm */
|
||||
"79dc6adee7817e7dc248cfeb4b358e933af6de01", /* slang-1.4.4-4.i386.rpm */
|
||||
"2659140a40cb05e85c536a299327addb0a762b8a", /* time-1.7-14.i386.rpm */
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char * dsa_w_bad[] = {
|
||||
"2659140a40cb05e85c536a299327addb0a762b8a", /* time-1.7-14.i386.rpm */
|
||||
"e97b9895cb99acf9c819a4b24a0b8ce6902f3442", /* samba-2.2.1a-4.i386.rpm */
|
||||
"f7434b4c2b2722abec888ea3a90eb940be954d82", /* gtkhtml-devel-0.9.2-9.i386.rpm */
|
||||
"ed15be40c189255fed77e21d5fd92a54cdfa7165", /* lha-1.00-17.i386.rpm */
|
||||
|
||||
"dc06930c3dc6a45035d1d8078c92149d1694ab3a", /* jed-0.99.14-2.i386.rpm */
|
||||
"ca28dc5abdfdc4c3680b8d37ac2cc8f47eff8323", /* ttfonts-zh_TW-2.11-5.noarch.rpm */
|
||||
|
||||
"cb6b555c47133ad7c1759dc2bb5c2a69e1021a10", /* libxml2-2.4.2-1.i386.rpm */
|
||||
"d82915ceb5e724fb65d6b177671826133cc1c238", /* slang-1.4.4-4.i386.rpm */
|
||||
"2659140a40cb05e85c536a299327addb0a762b8a", /* time-1.7-14.i386.rpm */
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -521,26 +486,25 @@ main(int argc, const char * argv[])
|
|||
qtemp = malloc((13*qsize+13) * sizeof(*qtemp));
|
||||
qwksp = qtemp+2*qsize;
|
||||
|
||||
for (i = 0; i < 1; i++) {
|
||||
fprintf(stderr, "====================================\n");
|
||||
for (i = 0; i < 9; i++) {
|
||||
if (dsa_s[i] == NULL) break;
|
||||
fprintf(stderr, "================================================== %d\n", i);
|
||||
fprintf(stderr, " s: %s\n", dsa_s[i]);
|
||||
mp32nzero(&s); mp32nsethex(&s, dsa_s[i]);
|
||||
|
||||
fprintf(stderr, "------------------------------------\n");
|
||||
fprintf(stderr, "-------------------------------------------------- %d\n", i);
|
||||
rc = Xmp32binv_w(&q, s.size, s.data, qtemp, qwksp);
|
||||
fprintf(stderr, "beecrypt: "); mp32println(stderr, qsize, qtemp);
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "------------------------------------\n");
|
||||
fprintf(stderr, "-------------------------------------------------- %d\n", i);
|
||||
rc = Ymp32binv_w(&q, s.size, s.data, qtemp, qwksp);
|
||||
fprintf(stderr, " Knuth: "); mp32println(stderr, qsize, qtemp);
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "------------------------------------\n");
|
||||
fprintf(stderr, "-------------------------------------------------- %d\n", i);
|
||||
rc = Zmp32binv_w(&q, s.size, s.data, qtemp, qwksp);
|
||||
fprintf(stderr, " Brent: "); mp32println(stderr, qsize, qtemp);
|
||||
|
||||
fprintf(stderr, "------------------------------------\n");
|
||||
fprintf(stderr, "-------------------------------------------------- %d\n", i);
|
||||
fprintf(stderr, " q: %s\n", dsa_q);
|
||||
fprintf(stderr, " s: %s\n", dsa_s[i]);
|
||||
fprintf(stderr, " GOOD: %s\n", dsa_w_good[i]);
|
||||
|
|
|
@ -18,12 +18,15 @@ extern int _ftp_debug;
|
|||
/*@unchecked@*/
|
||||
extern int _rpmio_debug;
|
||||
|
||||
static int verify_legacy = 0;
|
||||
|
||||
static char ** ftsSet;
|
||||
static int ftsOpts = 0;
|
||||
|
||||
const char * bhpath;
|
||||
int bhpathlen = 0;
|
||||
int bhlvl = -1;
|
||||
|
||||
static char ** ftsSet;
|
||||
|
||||
struct ftsglob_s {
|
||||
const char ** patterns;
|
||||
int fnflags;
|
||||
|
@ -97,6 +100,7 @@ static int ftsStashLatest(FTSENT * fts, rpmTransactionSet ts)
|
|||
if (fd) xx = Fclose(fd);
|
||||
return ec; /* XXX -1 */
|
||||
}
|
||||
|
||||
rc = rpmReadPackageFile(ts, fd, fts->fts_path, &h);
|
||||
xx = Fclose(fd);
|
||||
if (rc != RPMRC_OK)
|
||||
|
@ -377,7 +381,27 @@ static void initGlobs(const char ** argv)
|
|||
}
|
||||
|
||||
static struct poptOption optionsTable[] = {
|
||||
{ "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL },
|
||||
{ "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL },
|
||||
|
||||
{ "verifylegacy", '\0', POPT_ARG_VAL, &verify_legacy, -1, NULL, NULL },
|
||||
|
||||
{ "comfollow", '\0', POPT_BIT_SET, &ftsOpts, FTS_COMFOLLOW,
|
||||
N_("follow command line symlinks"), NULL },
|
||||
{ "logical", '\0', POPT_BIT_SET, &ftsOpts, FTS_LOGICAL,
|
||||
N_("logical walk"), NULL },
|
||||
{ "nochdir", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOCHDIR,
|
||||
N_("don't change directories"), NULL },
|
||||
{ "nostat", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOSTAT,
|
||||
N_("don't get stat info"), NULL },
|
||||
{ "physical", '\0', POPT_BIT_SET, &ftsOpts, FTS_PHYSICAL,
|
||||
N_("physical walk"), NULL },
|
||||
{ "seedot", '\0', POPT_BIT_SET, &ftsOpts, FTS_SEEDOT,
|
||||
N_("return dot and dot-dot"), NULL },
|
||||
{ "xdev", '\0', POPT_BIT_SET, &ftsOpts, FTS_XDEV,
|
||||
N_("don't cross devices"), NULL },
|
||||
{ "whiteout", '\0', POPT_BIT_SET, &ftsOpts, FTS_WHITEOUT,
|
||||
N_("return whiteout information"), NULL },
|
||||
|
||||
{ "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
|
||||
N_("debug protocol data stream"), NULL},
|
||||
{ "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
|
||||
|
@ -397,7 +421,6 @@ main(int argc, const char *argv[])
|
|||
rpmdb db = NULL;
|
||||
rpmTransactionSet ts = NULL;
|
||||
FTS * ftsp;
|
||||
int ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
|
||||
FTSENT * fts;
|
||||
const char ** av;
|
||||
int rc;
|
||||
|
@ -423,11 +446,18 @@ main(int argc, const char *argv[])
|
|||
|
||||
ts = rpmtransCreateSet(db, rootDir);
|
||||
(void) rpmtsOpenDB(ts, O_RDONLY);
|
||||
if (verify_legacy) {
|
||||
ts->dig = pgpNewDig();
|
||||
ts->verify_legacy = 1;
|
||||
}
|
||||
|
||||
av = poptGetArgs(optCon);
|
||||
|
||||
initGlobs(av);
|
||||
|
||||
if (ftsOpts == 0)
|
||||
ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
|
||||
|
||||
ftsp = Fts_open(ftsSet, ftsOpts, NULL);
|
||||
while((fts = Fts_read(ftsp)) != NULL)
|
||||
xx = ftsPrint(ftsp, fts, ts);
|
||||
|
|
Loading…
Reference in New Issue