summaryrefslogtreecommitdiff
path: root/lib/lib3.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lib3.c')
-rw-r--r--lib/lib3.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/lib/lib3.c b/lib/lib3.c
index 150c6ea..149d3a3 100644
--- a/lib/lib3.c
+++ b/lib/lib3.c
@@ -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)
+{
+
+}