Add a return value to crypter_t.encrypt
This commit is contained in:
@@ -54,17 +54,21 @@ METHOD(aead_t, encrypt, bool,
|
||||
|
||||
if (encrypted)
|
||||
{
|
||||
this->crypter->encrypt(this->crypter, plain, iv, &encr);
|
||||
if (!this->crypter->encrypt(this->crypter, plain, iv, &encr))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (!this->signer->allocate_signature(this->signer, encr, &sig))
|
||||
{
|
||||
free(encr.ptr);
|
||||
return FALSE;
|
||||
}
|
||||
*encrypted = chunk_cat("cmm", iv, encr, sig);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->crypter->encrypt(this->crypter, plain, iv, NULL);
|
||||
if (!this->signer->get_signature(this->signer,
|
||||
if (!this->crypter->encrypt(this->crypter, plain, iv, NULL) ||
|
||||
!this->signer->get_signature(this->signer,
|
||||
plain, plain.ptr + plain.len))
|
||||
{
|
||||
return FALSE;
|
||||
|
||||
@@ -90,8 +90,10 @@ struct crypter_t {
|
||||
* @param data data to encrypt
|
||||
* @param iv initializing vector
|
||||
* @param encrypted chunk to allocate encrypted data, or NULL
|
||||
* @return TRUE if encryption successful
|
||||
*/
|
||||
void (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv,
|
||||
__attribute__((warn_unused_result))
|
||||
bool (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv,
|
||||
chunk_t *encrypted);
|
||||
|
||||
/**
|
||||
|
||||
@@ -160,8 +160,10 @@ static u_int bench_crypter(private_crypto_tester_t *this,
|
||||
start_timing(&start);
|
||||
while (end_timing(&start) < this->bench_time)
|
||||
{
|
||||
crypter->encrypt(crypter, buf, chunk_from_thing(iv), NULL);
|
||||
runs++;
|
||||
if (crypter->encrypt(crypter, buf, chunk_from_thing(iv), NULL))
|
||||
{
|
||||
runs++;
|
||||
}
|
||||
crypter->decrypt(crypter, buf, chunk_from_thing(iv), NULL);
|
||||
runs++;
|
||||
}
|
||||
@@ -215,7 +217,10 @@ METHOD(crypto_tester_t, test_crypter, bool,
|
||||
|
||||
/* allocated encryption */
|
||||
plain = chunk_create(vector->plain, vector->len);
|
||||
crypter->encrypt(crypter, plain, iv, &cipher);
|
||||
if (!crypter->encrypt(crypter, plain, iv, &cipher))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
if (!memeq(vector->cipher, cipher.ptr, cipher.len))
|
||||
{
|
||||
failed = TRUE;
|
||||
@@ -235,7 +240,10 @@ METHOD(crypto_tester_t, test_crypter, bool,
|
||||
failed = TRUE;
|
||||
}
|
||||
/* inline encryption */
|
||||
crypter->encrypt(crypter, plain, iv, NULL);
|
||||
if (!crypter->encrypt(crypter, plain, iv, NULL))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
if (!memeq(vector->cipher, plain.ptr, plain.len))
|
||||
{
|
||||
failed = TRUE;
|
||||
|
||||
@@ -831,7 +831,14 @@ METHOD(pkcs7_t, build_envelopedData, bool,
|
||||
|
||||
/* symmetric encryption of data object */
|
||||
crypter->set_key(crypter, symmetricKey);
|
||||
crypter->encrypt(crypter, in, iv, &out);
|
||||
if (!crypter->encrypt(crypter, in, iv, &out))
|
||||
{
|
||||
crypter->destroy(crypter);
|
||||
chunk_clear(&in);
|
||||
chunk_clear(&symmetricKey);
|
||||
chunk_free(&iv);
|
||||
return FALSE;
|
||||
}
|
||||
crypter->destroy(crypter);
|
||||
chunk_clear(&in);
|
||||
DBG3(DBG_LIB, " encrypted data: %B", &out);
|
||||
|
||||
Reference in New Issue
Block a user