diff options
| author | Benedict <benedict@0xb8000.de> | 2017-02-02 00:40:49 +0100 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:27 +0100 |
| commit | 52d8878621c08c6a091603f5ca2f17b0f7f2847e (patch) | |
| tree | dc1fbd5827099a3b0da85442248cfde29622c00d | |
| parent | 1fd84c7dc70a0a6e6d8651fafa50c51dd697ae77 (diff) | |
set5: task33
| -rw-r--r-- | set5/task33.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/set5/task33.c b/set5/task33.c new file mode 100644 index 0000000..9fbdcdd --- /dev/null +++ b/set5/task33.c @@ -0,0 +1,62 @@ +#include "../lib/lib.h" +#include "../lib/lib2.h" +#include "../lib/lib3.h" +#include "../lib/lib4.h" +#include "../lib/lib5.h" +#include <time.h> + + +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(); +} |
