summaryrefslogtreecommitdiff
path: root/lib/lib4.c
diff options
context:
space:
mode:
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;
+}