Add a return value to aead_t.encrypt()
This commit is contained in:
@@ -70,10 +70,14 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
while (TRUE)
|
||||
{
|
||||
aead->encrypt(aead,
|
||||
if (!aead->encrypt(aead,
|
||||
chunk_create(buffer, sizeof(buffer) - aead->get_icv_size(aead)),
|
||||
chunk_from_thing(assoc),
|
||||
chunk_create(iv, aead->get_iv_size(aead)), NULL);
|
||||
chunk_create(iv, aead->get_iv_size(aead)), NULL))
|
||||
{
|
||||
fprintf(stderr, "aead encryption failed!\n");
|
||||
return 1;
|
||||
}
|
||||
if (!aead->decrypt(aead, chunk_create(buffer, sizeof(buffer)),
|
||||
chunk_from_thing(assoc),
|
||||
chunk_create(iv, aead->get_iv_size(aead)), NULL))
|
||||
|
||||
@@ -367,7 +367,11 @@ METHOD(encryption_payload_t, encrypt, bool,
|
||||
DBG3(DBG_ENC, "padding %B", &padding);
|
||||
DBG3(DBG_ENC, "assoc %B", &assoc);
|
||||
|
||||
this->aead->encrypt(this->aead, crypt, assoc, iv, NULL);
|
||||
if (!this->aead->encrypt(this->aead, crypt, assoc, iv, NULL))
|
||||
{
|
||||
free(assoc.ptr);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DBG3(DBG_ENC, "encrypted %B", &crypt);
|
||||
DBG3(DBG_ENC, "ICV %B", &icv);
|
||||
@@ -410,7 +414,11 @@ METHOD(encryption_payload_t, encrypt_v1, bool,
|
||||
DBG3(DBG_ENC, "plain %B", &plain);
|
||||
DBG3(DBG_ENC, "padding %B", &padding);
|
||||
|
||||
this->aead->encrypt(this->aead, this->encrypted, chunk_empty, iv, NULL);
|
||||
if (!this->aead->encrypt(this->aead, this->encrypted, chunk_empty, iv, NULL))
|
||||
{
|
||||
chunk_free(&iv);
|
||||
return FALSE;
|
||||
}
|
||||
chunk_free(&iv);
|
||||
|
||||
DBG3(DBG_ENC, "encrypted %B", &this->encrypted);
|
||||
|
||||
@@ -163,11 +163,12 @@ typedef struct {
|
||||
} private_aead_t;
|
||||
|
||||
|
||||
METHOD(aead_t, encrypt, void,
|
||||
METHOD(aead_t, encrypt, bool,
|
||||
private_aead_t *this, chunk_t plain, chunk_t assoc, chunk_t iv,
|
||||
chunk_t *encrypted)
|
||||
{
|
||||
this->crypter->encrypt(this->crypter, plain, iv, encrypted);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(aead_t, decrypt, bool,
|
||||
|
||||
@@ -40,7 +40,7 @@ struct private_aead_t {
|
||||
signer_t *signer;
|
||||
};
|
||||
|
||||
METHOD(aead_t, encrypt, void,
|
||||
METHOD(aead_t, encrypt, bool,
|
||||
private_aead_t *this, chunk_t plain, chunk_t assoc, chunk_t iv,
|
||||
chunk_t *encrypted)
|
||||
{
|
||||
@@ -60,6 +60,7 @@ METHOD(aead_t, encrypt, void,
|
||||
this->crypter->encrypt(this->crypter, plain, iv, NULL);
|
||||
this->signer->get_signature(this->signer, plain, plain.ptr + plain.len);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(aead_t, decrypt, bool,
|
||||
|
||||
@@ -45,8 +45,10 @@ struct aead_t {
|
||||
* @param assoc associated data to sign
|
||||
* @param iv initialization vector
|
||||
* @param encrypted allocated encryption result
|
||||
* @return TRUE if successfully encrypted
|
||||
*/
|
||||
void (*encrypt)(aead_t *this, chunk_t plain, chunk_t assoc, chunk_t iv,
|
||||
__attribute__((warn_unused_result))
|
||||
bool (*encrypt)(aead_t *this, chunk_t plain, chunk_t assoc, chunk_t iv,
|
||||
chunk_t *encrypted);
|
||||
|
||||
/**
|
||||
|
||||
@@ -317,12 +317,16 @@ static u_int bench_aead(private_crypto_tester_t *this,
|
||||
start_timing(&start);
|
||||
while (end_timing(&start) < this->bench_time)
|
||||
{
|
||||
aead->encrypt(aead, buf, chunk_from_thing(assoc),
|
||||
chunk_from_thing(iv), NULL);
|
||||
runs += 2;
|
||||
aead->decrypt(aead, chunk_create(buf.ptr, buf.len + icv),
|
||||
chunk_from_thing(assoc), chunk_from_thing(iv), NULL);
|
||||
runs += 2;
|
||||
if (aead->encrypt(aead, buf, chunk_from_thing(assoc),
|
||||
chunk_from_thing(iv), NULL))
|
||||
{
|
||||
runs += 2;
|
||||
}
|
||||
if (aead->decrypt(aead, chunk_create(buf.ptr, buf.len + icv),
|
||||
chunk_from_thing(assoc), chunk_from_thing(iv), NULL))
|
||||
{
|
||||
runs += 2;
|
||||
}
|
||||
}
|
||||
free(buf.ptr);
|
||||
aead->destroy(aead);
|
||||
@@ -377,7 +381,10 @@ METHOD(crypto_tester_t, test_aead, bool,
|
||||
|
||||
/* allocated encryption */
|
||||
plain = chunk_create(vector->plain, vector->len);
|
||||
aead->encrypt(aead, plain, assoc, iv, &cipher);
|
||||
if (!aead->encrypt(aead, plain, assoc, iv, &cipher))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
if (!memeq(vector->cipher, cipher.ptr, cipher.len))
|
||||
{
|
||||
failed = TRUE;
|
||||
@@ -405,7 +412,10 @@ METHOD(crypto_tester_t, test_aead, bool,
|
||||
}
|
||||
plain.ptr = realloc(plain.ptr, plain.len + icv);
|
||||
/* inline encryption */
|
||||
aead->encrypt(aead, plain, assoc, iv, NULL);
|
||||
if (!aead->encrypt(aead, plain, assoc, iv, NULL))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
if (!memeq(vector->cipher, plain.ptr, plain.len + icv))
|
||||
{
|
||||
failed = TRUE;
|
||||
|
||||
@@ -240,7 +240,7 @@ static bool verify_icv(private_ccm_aead_t *this, chunk_t plain, chunk_t assoc,
|
||||
return memeq(buf, icv, this->icv_size);
|
||||
}
|
||||
|
||||
METHOD(aead_t, encrypt, void,
|
||||
METHOD(aead_t, encrypt, bool,
|
||||
private_ccm_aead_t *this, chunk_t plain, chunk_t assoc, chunk_t iv,
|
||||
chunk_t *encrypted)
|
||||
{
|
||||
@@ -255,6 +255,7 @@ METHOD(aead_t, encrypt, void,
|
||||
create_icv(this, plain, assoc, iv, plain.ptr + plain.len);
|
||||
crypt_data(this, iv, plain, plain);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(aead_t, decrypt, bool,
|
||||
|
||||
@@ -267,7 +267,7 @@ static bool verify_icv(private_gcm_aead_t *this, chunk_t assoc, chunk_t crypt,
|
||||
return memeq(tmp, icv, this->icv_size);
|
||||
}
|
||||
|
||||
METHOD(aead_t, encrypt, void,
|
||||
METHOD(aead_t, encrypt, bool,
|
||||
private_gcm_aead_t *this, chunk_t plain, chunk_t assoc, chunk_t iv,
|
||||
chunk_t *encrypted)
|
||||
{
|
||||
@@ -288,6 +288,7 @@ METHOD(aead_t, encrypt, void,
|
||||
crypt(this, j, plain, plain);
|
||||
create_icv(this, assoc, plain, j, plain.ptr + plain.len);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(aead_t, decrypt, bool,
|
||||
|
||||
Reference in New Issue
Block a user