diff options
| author | Benedict <benedict@0xb8000.de> | 2016-09-23 11:36:08 +0200 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:26 +0100 |
| commit | 723222e769785563babdda5f78a0ce21a276cb9f (patch) | |
| tree | 660d7312f7e85206daad7de6912ce63bee5f4b36 /lib/lib3.c | |
| parent | 111642369ba778d5b8d18f1a9d8acf379ab45c13 (diff) | |
completed set 4, task 31
Diffstat (limited to 'lib/lib3.c')
| -rw-r--r-- | lib/lib3.c | 43 |
1 files changed, 30 insertions, 13 deletions
@@ -8,36 +8,46 @@ char *challenge17_encrypt(int *length) { int i, t; - char **string; - char **decoded; - string = malloc(sizeof(char *)*NR_STIRNGS_CHALLENGE17); - decoded = malloc(sizeof(char *)*NR_STIRNGS_CHALLENGE17); + char *string[NR_STIRNGS_CHALLENGE17]; + char *decoded[NR_STIRNGS_CHALLENGE17]; char filename[] = "task17_0"; - for(i=0;i<10;i++) { + for(i=0;i<NR_STIRNGS_CHALLENGE17;i++) { filename[strlen(filename)-1] = (char) (i+'0'); t = read_base64_file(filename, &string[i]); decoded[i] = malloc(t); - length[i] = decode_base64(string[i], decoded[i]); - printf("read: %s\n", string[i]); + *length = decode_base64(string[i], decoded[i]); + printf("read: %s\n", decoded[i]); } + // choose one randomly int random = rand() % NR_STIRNGS_CHALLENGE17; int padding; - printf("plaintext: %s\n", string[random]); + + //random = 1; *length = strlen(string[random]); - char *padded_string = __pkcs7_padding(string[random], *length, 16, &padding); + char *padded_string = __pkcs7_padding(decoded[random], *length, 16, &padding); + char *hex_tmp = malloc((padding+strlen(decoded[random]))*2); + hex_binary_to_string(padded_string, hex_tmp, padding+strlen(decoded[random])); + printf("plaintext: %s\n", decoded[random]); + printf("plaintext: %s\n", hex_tmp); char *encrypted = malloc(strlen(padded_string)); *length += padding; aes_cbc(padded_string, strlen(padded_string), encrypted, key, iv, 1); + for(i=0;i<NR_STIRNGS_CHALLENGE17;i++) + free(decoded[i]); return encrypted; + } int cbc_padding_oracle(char *encrypted, int length) { char *decrypted = malloc(length); char *unpadded= malloc(length); - + + if(!decrypted || !unpadded) + return -1; + aes_cbc(encrypted, length, decrypted, key, iv, 0); int valid = valid_pkcs7_padding(decrypted, length, unpadded, 16); @@ -184,9 +194,6 @@ int unshift_right_xor(int number, int shifts) return restore; } -/*** - * why the fuck is the reverse AND working? - **/ int unshift_left_xor(int number, int shifts, unsigned int mask) { int rounds = 0; @@ -281,3 +288,13 @@ int mt_19937_password_token_time_based(unsigned int password_token, int time_win } return 0; } +/** + * Given the actual state, restore the previous state of the MT + * This is useful, when you want to determine the previous random numbers + * you may not have observed. + * + **/ +int mt_19937_restore_previous_state(struct mt_19937_state *mt_state) +{ + +} |
