summaryrefslogtreecommitdiff
path: root/implement_cbc_mode_s2.c
diff options
context:
space:
mode:
Diffstat (limited to 'implement_cbc_mode_s2.c')
-rw-r--r--implement_cbc_mode_s2.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/implement_cbc_mode_s2.c b/implement_cbc_mode_s2.c
new file mode 100644
index 0000000..6015717
--- /dev/null
+++ b/implement_cbc_mode_s2.c
@@ -0,0 +1,21 @@
+// https://cryptopals.com/sets/2/challenges/10
+#include "util/aes.h"
+#include "util/base64.h"
+#include "util/io.h"
+
+/*
+ * in CBC mode each ciphertext is added to the next plaintext block prior to
+ * next call to cipher core. first plaintext block is added to the "0th
+ * ciphertext block" called the initialization vector (IV).
+ */
+
+int main() {
+ size_t ciphertext_len;
+ uint8_t *ciphertext = base64_decode(read_non_space(stdin), &ciphertext_len);
+ unsigned char *key = (unsigned char *)"YELLOW SUBMARINE", iv[16] = {0};
+ unsigned char *decrypted = malloc(ciphertext_len + 16); // inl + block_size
+ int decrypted_len =
+ cbc_decrypt(ciphertext, ciphertext_len, key, iv, decrypted);
+ fwrite(decrypted, 1, decrypted_len, stdout);
+ return 0;
+}