summaryrefslogtreecommitdiff
path: root/set2/task14.c
blob: 586d174901d1020a2e8a1ad67ab2ac1529f4f69f (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
34
35
36
37
38
39
40
41
42
43
44
45
#include "../lib/lib.h"
#include "../lib/lib2.h"
#include <time.h>

/**
 * This time there is a random amount of random data before our
 * data. This is that annoys us. If we would one where our data
 * would begin all would be fine, we would do the same as in task12
 * But since we are using ECB blocks din't change with the random data.
 * So we make a first request with our data empty and than make a second
 * request with one byte. Than we compere the results. The blocks which 
 * contain the random data keep the same, exceot the last, because we
 * probably append our byte into that block instead of the first byte of
 * our target string. Now we now how many blocks of random data are before 
 * our data.
 * To get the excat number of bytes, we add two blocksof A's. So one block is
 * for sure filled just with A's. Than we remove A's until the block of A's
 * change because our traget data get into it. Then blocksize-Removed A's
 * is the offset block where our data start.
 *	16*unchanged_blocks + BLOKCSIZE-RemovedA's
 *
 *
**/
#define BLOCKSIZE 16
int main(int argc, char **argv)
{
	srand(time(NULL));
	generate_random_bytes(key, 16);
	// cleartext + maybe an additional block
	
	int prepended_data_len = aes_ecb_detect_prepended_data();

	printf("prepended data len: %i\n", prepended_data_len);

	// so now we now the offset where our data get inserted
	// ignoring everything befor offset we now have to do the same 
	// as in task12
	// well in task13 we make the assumtion that we start at a fresh block
	// so maybe at some garbage to fill the rest block
	
	char *plaintext;
	crack_aes_ecb(&plaintext, 16, prepended_data_len);

	printf("recovered data:\n%s\n", plaintext);
}