diff options
| author | Benedict <benedict@0xb8000.de> | 2017-02-02 00:41:15 +0100 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:27 +0100 |
| commit | 7e4bf7c593c4db94905bad2216ed28bd086b44b3 (patch) | |
| tree | 30083b60171caaf763a25bf94a6c35a1d316dacd /set5/task35.c | |
| parent | ab7279c6d43c39fd1887c093b37025a7e40ffc8f (diff) | |
Diffstat (limited to 'set5/task35.c')
| -rw-r--r-- | set5/task35.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/set5/task35.c b/set5/task35.c new file mode 100644 index 0000000..8f31199 --- /dev/null +++ b/set5/task35.c @@ -0,0 +1,46 @@ +#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; + + dh_init(&dh); + // 1^X is always one; so the modulo will always be one for p > 1 + // g = p; p^X mod p is always 0 because its a multiple of p + // g = p-1; (p-1)^X mod p; not all rest groups are used, or some + // much more likely? + dh.p = "8"; + dh.g = "7"; + int i; + for(i=0;i<10000;i++) { + dh_generate_secret_keys(&dh); + dh_generate_public_keys(&dh); + dh_get_session_key(&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); + + + +} |
