summaryrefslogtreecommitdiff
path: root/lib/lib4.c
blob: 475efe94d3c08ab6b470bc7efdcbf1d0a628d0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
}