diff options
| author | Benedict <benedict@0xb8000.de> | 2016-08-15 12:22:31 +0200 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:25 +0100 |
| commit | 8911c9595b9d553100951ff2653464ef5868b81d (patch) | |
| tree | c7e8c428ad3af16c41e699850edc82f617a6e121 /lib | |
| parent | cb990c73c478c1bb40d749d0f4e52c10a9ac80fd (diff) | |
set4, completed challenge 25
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/lib4.c | 22 | ||||
| -rw-r--r-- | lib/lib4.h | 7 |
2 files changed, 29 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; +} diff --git a/lib/lib4.h b/lib/lib4.h new file mode 100644 index 0000000..dee52a7 --- /dev/null +++ b/lib/lib4.h @@ -0,0 +1,7 @@ +#ifndef __LIB_4__ +#define __LIB_4__ + + +int aes_ctr_edit(char *ciphertext, int ciphertext_length, int offset, char *newtext); + +#endif |
