-bool cipher_encrypt(cipher_t *cipher, void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) {
+bool cipher_counter_xor(cipher_t *cipher, const void *indata, size_t inlen, void *outdata) {
+ if(!cipher->counter) {
+ logger(LOG_ERR, "Counter not initialized");
+ return false;
+ }
+
+ const unsigned char *in = indata;
+ unsigned char *out = outdata;
+
+ while(inlen--) {
+ // Encrypt the new counter value if we need it
+ if(!cipher->counter->n) {
+ int len;
+ if(!EVP_EncryptUpdate(&cipher->ctx, cipher->counter->block, &len, cipher->counter->counter, cipher->cipher->block_size)) {
+ logger(LOG_ERR, "Error while encrypting: %s", ERR_error_string(ERR_get_error(), NULL));
+ return false;
+ }
+
+ // Increase the counter value
+ for(int i = 0; i < cipher->cipher->block_size; i++)
+ if(++cipher->counter->counter[i])
+ break;
+ }
+
+ *out++ = *in++ ^ cipher->counter->counter[cipher->counter->n++];
+
+ if(cipher->counter->n >= cipher->cipher->block_size)
+ cipher->counter->n = 0;
+ }
+
+ return true;
+}
+
+
+bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) {