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
@@ -90,7 +90,7 @@ static char* lookup_algorithm(u_int16_t ikev2_algo, size_t *key_size)
/**
* Do the actual en/decryption in an EVP context
*/
static void crypt(private_openssl_crypter_t *this, chunk_t data, chunk_t iv,
static bool crypt(private_openssl_crypter_t *this, chunk_t data, chunk_t iv,
chunk_t *dst, int enc)
{
int len;
@@ -104,13 +104,14 @@ static void crypt(private_openssl_crypter_t *this, chunk_t data, chunk_t iv,
}
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);
EVP_CipherInit_ex(&ctx, this->cipher, NULL, NULL, NULL, enc);
EVP_CIPHER_CTX_set_padding(&ctx, 0); /* disable padding */
EVP_CIPHER_CTX_set_key_length(&ctx, this->key.len);
EVP_CipherInit_ex(&ctx, NULL, NULL, this->key.ptr, iv.ptr, enc);
EVP_CipherUpdate(&ctx, out, &len, data.ptr, data.len);
EVP_CipherFinal_ex(&ctx, out + len, &len); /* since padding is disabled this does nothing */
EVP_CIPHER_CTX_cleanup(&ctx);
return EVP_CipherInit_ex(&ctx, this->cipher, NULL, NULL, NULL, enc) &&
EVP_CIPHER_CTX_set_padding(&ctx, 0) /* disable padding */ &&
EVP_CIPHER_CTX_set_key_length(&ctx, this->key.len) &&
EVP_CipherInit_ex(&ctx, NULL, NULL, this->key.ptr, iv.ptr, enc) &&
EVP_CipherUpdate(&ctx, out, &len, data.ptr, data.len) &&
/* since padding is disabled this does nothing */
EVP_CipherFinal_ex(&ctx, out + len, &len) &&
EVP_CIPHER_CTX_cleanup(&ctx);
}
METHOD(crypter_t, decrypt, void,
@@ -119,10 +120,10 @@ METHOD(crypter_t, decrypt, void,
crypt(this, data, iv, dst, 0);
}
METHOD(crypter_t, encrypt, void,
METHOD(crypter_t, encrypt, bool,
private_openssl_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *dst)
{
crypt(this, data, iv, dst, 1);
return crypt(this, data, iv, dst, 1);
}
METHOD(crypter_t, get_block_size, size_t,