#include "../lib/lib.h" #include "../lib/lib2.h" #include "../lib/lib3.h" #include "../lib/lib4.h" #include "../lib/lib5.h" #include int DH_smallnums() { srand(time(NULL)); // public prime numbers; everbody can know them, parameters of the // expoential function unsigned int p = 37; unsigned int g = 5; // exponents of the dicrect exponential function, should be kept secret unsigned int b; unsigned int a; generate_random_bytes((char *)&a,4); a = a % p; generate_random_bytes((char *)&b,4); b = b % p; // A and B are the public keys, sent to each other // one cannot infer a/b from A/B unsigned A = g ^ a % p; unsigned B = g ^ b % p; // both compute these number, s1 = s2; (g^a)^b = (g^b)^a unsigned int s1 = B ^ a % p; unsigned int s2 = A ^ b % p; printf("session key A: %i\n", s1); printf("session key B: %i\n", s2); // generate a key, 128 bit by hashing the session key } void DH_bignums() { struct dh_param_bignum dh; do_dh_key_exchange_bignum(&dh); printf("bignums: A: "); BN_print(out, dh.A); printf("\nbignums: session key 1: "); BN_print(out, dh.s1); printf("\nbignums: session key 2: "); BN_print(out, dh.s2); if(BN_cmp(dh.s1, dh.s2) == 0) printf("\nboth session keys are equal!\n"); } int main() { out = BIO_new(BIO_s_file()); BIO_set_fp(out, stdout, BIO_NOCLOSE); ctx = BN_CTX_new(); DH_smallnums(); DH_bignums(); }