- 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(DEBUG_ALWAYS, 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;