Diffie-Hellman Key exchange tools(3BM)

NAME
genDiffieHellmanSet, DiffieHellmanInit, DiffieHellmanGneKey, freeDiffieHellmanSet, randBytesNeededForDHSet, randBytesNeededForDHInit

SYNOPSIS
#include <libcrypt.h>
typedef struct {
	int qbits;
	BigInt alpha, p, q;
	Table *alphatab;
} DiffieHellmanSet;

int randByteNeededForDHSet (int pbits, int qbits);

DiffieHellmanSet *GenDiffieHellmanSet (int pbits, int qbits, BigInt randomStart);

int randBytesNeededForDHInit (int qbits);

void DiffieHellmanInit (DiffieHellmanSet *myDHset, BigInt my_exponent, BigInt my_msg1, BigInt randomStart);

void quantized_DiffieHellmanInit (DiffieHellmanSet *myDHset, BigInt my_exponent, BigInt my_msg1);

void DiffieHellmanGenKey (DiffieHellmanSet *myDHset, BigInt recd_msg1,
				BigInt my_exponent, BigInt DH_key));

void quantized_DiffieHellmanGenKey (DiffieHellmanSet *myDHset, BigInt recd_msg1,
				BigInt my_exponent, BigInt DH_key));

void freeDiffieHellmanSet (DiffieHellmanSet *DHset);

DESCRIPTION

An implementation of Diffie-Hellman key exchange. If $randomStart$ is not to be NULL in $genDiffieHellmanSet$ use $randBytesNeededForDHSet$ with the length of p and q in bits to determine the amount of random data needed for parameter generation. Generate a DiffieHellmanSet which contains a base, a prime p, a prime factor of p-1, and a table for using Brickell's speedup for exponentiation.

This Set must be agreed upon by the participants in the exchange. my_exponent should usually be initialized to 0 unless you want to use a prespecified value.

$DiffieHellmanInit$ is then called in which the caller's exponent is used to calculate his half of the exchange. If $randomStart$ is not NULL, use $randBytesNeededForDHInit$ with the legnth of the sub-prime, q, in bits as its argument, to find the number of random bytes needed to initialize the search for a proper exponent. After this function call, my_exponent should be protected (say using BignumDESEncrypt()) and my_msg1 sent to the other party in the exchange.

After receiving the other party's message, recd_msg1, uncover your exponent and proceed. DH_key will contain the full pbits worth of Diffie Hellman key material for you to process as necessary.

The quantized version use STD_QUANTUM milliseconds as the quantum for execution to defend against Kocher-style timing attacks. STD_QUANTUM is defined in libcrypt.h and should be tuned to your environment.

SEE ALSO
bigInit(3BM), bigTest(3BM), bigBits(3BM), bigBytes(3BM), bigToBuf(3BM), bufToBig(3BM), fBigPrint(3BM), atobig(3BM), bigPow(3BM), bignumDES[En/De]crypt(3BM) start_quantize(3BM) end_quantize(3BM)