summaryrefslogtreecommitdiff
path: root/lib/lib4.c
diff options
context:
space:
mode:
authorBenedict <benedict@0xb8000.de>2016-08-15 12:22:31 +0200
committerBenedict <benedict@0xb8000.de>2017-02-21 13:00:25 +0100
commit8911c9595b9d553100951ff2653464ef5868b81d (patch)
treec7e8c428ad3af16c41e699850edc82f617a6e121 /lib/lib4.c
parentcb990c73c478c1bb40d749d0f4e52c10a9ac80fd (diff)
set4, completed challenge 25
Diffstat (limited to 'lib/lib4.c')
-rw-r--r--lib/lib4.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/lib4.c b/lib/lib4.c
new file mode 100644
index 0000000..475efe9
--- /dev/null
+++ b/lib/lib4.c
@@ -0,0 +1,22 @@
+#include "lib4.h"
+#include "lib3.h"
+#include "lib2.h"
+#include "lib.h"
+/**
+ * encrypt always with the same key, same nonce?
+ *
+ **/
+int aes_ctr_edit(char *ciphertext, int ciphertext_length, int offset, char *newtext)
+{
+ // do not allow greater ciphertexts
+ if((strlen(newtext)+offset) > ciphertext_length)
+ return 1;
+
+ // insert newtext at offset and reencrpyt
+ char *plaintext = malloc(ciphertext_length);
+ aes_ctr(ciphertext, ciphertext_length, plaintext, key, nonce);
+ memcpy(&plaintext[offset], newtext, strlen(newtext));
+
+ aes_ctr(plaintext, ciphertext_length, ciphertext, key, nonce);
+ return 0;
+}