summaryrefslogtreecommitdiff
path: root/set5/task34.c
blob: 31fc8768907a9e06329757d780611a33b1ae9243 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "../lib/lib.h"
#include "../lib/lib2.h"
#include "../lib/lib3.h"
#include "../lib/lib4.h"
#include "../lib/lib5.h"
#include <time.h>

int main()
{
	// sha1 key
	srand(time(NULL));
	char key[20];
	char hex_key[40];
	char *encrypted;
	char *msg = "Hallo verschlüssele mich bitte";
	struct dh_param dh;
	//do_dh_key_exchange(&dh);
	dh_mitm(&dh);
	sha1_key_from_dh(&dh, key);
	hex_binary_to_string(key, hex_key, 20);
	printf("key is: %s\n", hex_key);

	// encrypt a message with AES-CBC
	generate_random_bytes(iv, 16);

	int enc_length = aes_cbc_padded(msg, strlen(msg), &encrypted, key, iv, 1);
	char *hex_enc = malloc(enc_length + 16);
	hex_binary_to_string(encrypted, hex_enc, enc_length);
	printf("encryted message: %s\n", hex_enc);



}