} cipher_counter_t;
static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) {
- cipher_t *cipher = xmalloc_and_zero(sizeof *cipher);
+ cipher_t *cipher = xzalloc(sizeof *cipher);
cipher->cipher = evp_cipher;
EVP_CIPHER_CTX_init(&cipher->ctx);
}
size_t cipher_keylength(const cipher_t *cipher) {
+ if(!cipher || !cipher->cipher)
+ return 0;
+
return cipher->cipher->key_len + cipher->cipher->block_size;
}
}
if(!cipher->counter)
- cipher->counter = xmalloc_and_zero(sizeof *cipher->counter);
+ cipher->counter = xzalloc(sizeof *cipher->counter);
else
cipher->counter->n = 0;
break;
}
- *out++ = *in++ ^ cipher->counter->counter[cipher->counter->n++];
+ *out++ = *in++ ^ cipher->counter->block[cipher->counter->n++];
if(cipher->counter->n >= cipher->cipher->block_size)
cipher->counter->n = 0;
}
int cipher_get_nid(const cipher_t *cipher) {
- return cipher->cipher ? cipher->cipher->nid : 0;
+ if(!cipher || !cipher->cipher)
+ return 0;
+
+ return cipher->cipher->nid;
}
bool cipher_active(const cipher_t *cipher) {