summaryrefslogtreecommitdiff
path: root/set4/task30.c
diff options
context:
space:
mode:
authorBenedict <benedict@0xb8000.de>2017-02-02 00:32:26 +0100
committerBenedict <benedict@0xb8000.de>2017-02-21 13:00:27 +0100
commit1fd84c7dc70a0a6e6d8651fafa50c51dd697ae77 (patch)
treeaf5de3c7952e071c8e27800c41d9f945fa86c9e7 /set4/task30.c
parent9dcc7348ad53cab8fd9396699de0177bac6729d5 (diff)
added random stuff which hasn't beend added because yeah
Diffstat (limited to 'set4/task30.c')
-rw-r--r--set4/task30.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/set4/task30.c b/set4/task30.c
new file mode 100644
index 0000000..e0b2906
--- /dev/null
+++ b/set4/task30.c
@@ -0,0 +1,58 @@
+#include "../lib/lib.h"
+#include "../lib/lib2.h"
+#include "../lib/lib3.h"
+#include "../lib/lib4.h"
+#include <time.h>
+
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ if(argc != 2)
+ printf("Please provide ONE key as argument!\n");
+ uint32_t *hex;
+ uint32_t *hex2;
+ char *text = "comment1=cooking%20MCs;userdata=foo;comment2=%20like%20a%20pound%20of%20bacon";
+ char *append = ";admin=true";
+ char *key = argv[1];
+
+ printf("Using secret key: %s\n", key);
+
+ unsigned char *padded;
+ // padding in MD4 is the same as in SHA1
+ int padding_len = sha1_padding(strlen(text), &padded);
+
+ md4_prefix_key_mac(&hex, text, strlen(text), key, strlen(key));
+ printf("MAC of original message:\n");
+ for(i=0;i<5;i++)
+ printf("%02x", hex[i]);
+
+ printf("\n");
+
+ /*
+ * We are appending a text to the original message without knowign the
+ * key. Actually we don't know the message here, just the length of
+ * the message.
+ */
+ md4_prefix_key_forge(&hex2, append, strlen(append), hex);
+ printf("MAC of forged message:\n");
+ for(i=0;i<5;i++)
+ printf("%02x", hex2[i]);
+
+ printf("\n");
+
+ /*
+ * create the message we forged. Send this plus the hmac to the
+ * victim. He knows the secret and test and will think that
+ * this is a message from Alice
+ */
+ unsigned int new_msg_len = strlen(text)+strlen(append)+padding_len;
+ char *new_msg = malloc(new_msg_len);
+ memcpy(new_msg, text, strlen(text));
+ memcpy(&new_msg[strlen(text)], padded, padding_len);
+ memcpy(&new_msg[strlen(text)+padding_len], append, strlen(append));
+
+ if(md4_prefix_key_verify(hex2, new_msg, new_msg_len, key, strlen(key)))
+ printf("Forged MAC got accepted!\n");
+}