Add a return value to crypter_t.encrypt

This commit is contained in:
Martin Willi
2012-07-16 14:53:37 +02:00
parent c3858662d2
commit e35abbe588
21 changed files with 233 additions and 143 deletions
@@ -59,18 +59,15 @@ struct private_gcrypt_crypter_t {
/**
* Set the IV for en/decryption
*/
static void set_iv(private_gcrypt_crypter_t *this, chunk_t iv)
static bool set_iv(private_gcrypt_crypter_t *this, chunk_t iv)
{
if (this->ctr_mode)
{
memcpy(this->ctr.iv, iv.ptr, sizeof(this->ctr.iv));
this->ctr.counter = htonl(1);
gcry_cipher_setctr(this->h, &this->ctr, sizeof(this->ctr));
}
else
{
gcry_cipher_setiv(this->h, iv.ptr, iv.len);
return gcry_cipher_setctr(this->h, &this->ctr, sizeof(this->ctr)) == 0;
}
return gcry_cipher_setiv(this->h, iv.ptr, iv.len) == 0;
}
METHOD(crypter_t, decrypt, void,
@@ -89,20 +86,20 @@ METHOD(crypter_t, decrypt, void,
}
}
METHOD(crypter_t, encrypt, void,
METHOD(crypter_t, encrypt, bool,
private_gcrypt_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *dst)
{
set_iv(this, iv);
if (!set_iv(this, iv))
{
return FALSE;
}
if (dst)
{
*dst = chunk_alloc(data.len);
gcry_cipher_encrypt(this->h, dst->ptr, dst->len, data.ptr, data.len);
}
else
{
gcry_cipher_encrypt(this->h, data.ptr, data.len, NULL, 0);
return gcry_cipher_encrypt(this->h, dst->ptr, dst->len,
data.ptr, data.len) == 0;
}
return gcry_cipher_encrypt(this->h, data.ptr, data.len, NULL, 0) == 0;
}
METHOD(crypter_t, get_block_size, size_t,