From 1fd84c7dc70a0a6e6d8651fafa50c51dd697ae77 Mon Sep 17 00:00:00 2001 From: Benedict Date: Thu, 2 Feb 2017 00:32:26 +0100 Subject: added random stuff which hasn't beend added because yeah --- set3/task17.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 set3/task17.c (limited to 'set3/task17.c') diff --git a/set3/task17.c b/set3/task17.c new file mode 100644 index 0000000..d2bb7e0 --- /dev/null +++ b/set3/task17.c @@ -0,0 +1,59 @@ +#include "../lib/lib.h" +#include "../lib/lib2.h" +#include "../lib/lib3.h" +#include + +/** + * First we try to break the last byte of a block. + * Do this by trying every byte + * + * Good description of the attack: + * https://blog.cloudflare.com/padding-oracles-and-the-decline-of-cbc-mode-ciphersuites/ + */ + +#define BLOCKSIZE 16 +int main() +{ + // intialize + srand(time(NULL)); + generate_random_bytes(key, 16); + generate_random_bytes(iv, 16); + + int length = 0, i; + char *encrypted = challenge17_encrypt(&length); + + // detecting the length of the padding (need at least two blocks) + int nr_blocks = length / BLOCKSIZE; + nr_blocks--; + + printf("length: %i, blocks: %i\n", length, nr_blocks); + + char *tmp = malloc(length); + char *decrypted = malloc(length);; + memset(decrypted, 0xAA, length); + // try to break the last byte of the first block + char j; + int k; + for(k=nr_blocks-1;k>=0;k--) { + memcpy(tmp, encrypted, length); + printf("k is %i\n", k); + for(j=1;j<=BLOCKSIZE;j++) { + // created the right padding for the last j bytes + for(i=1;i