Add a return value to aead_t.set_key()

This commit is contained in:
Martin Willi
2012-07-16 14:53:32 +02:00
parent e2ed7bfd22
commit ad08730a4b
7 changed files with 30 additions and 9 deletions
+2 -1
View File
@@ -204,10 +204,11 @@ METHOD(aead_t, get_key_size, size_t,
return this->crypter->get_key_size(this->crypter);
}
METHOD(aead_t, set_key, void,
METHOD(aead_t, set_key, bool,
private_aead_t *this, chunk_t key)
{
this->crypter->set_key(this->crypter, key);
return TRUE;
}
METHOD(aead_t, aead_destroy, void,
+10 -2
View File
@@ -112,12 +112,20 @@ static bool derive_ike_aead(private_keymat_v2_t *this, u_int16_t alg,
prf_plus->allocate_bytes(prf_plus, key_size, &key);
DBG4(DBG_IKE, "Sk_ei secret %B", &key);
aead_i->set_key(aead_i, key);
if (!aead_i->set_key(aead_i, key))
{
chunk_clear(&key);
return FALSE;
}
chunk_clear(&key);
prf_plus->allocate_bytes(prf_plus, key_size, &key);
DBG4(DBG_IKE, "Sk_er secret %B", &key);
aead_r->set_key(aead_r, key);
if (!aead_r->set_key(aead_r, key))
{
chunk_clear(&key);
return FALSE;
}
chunk_clear(&key);
if (this->initiator)
+3 -1
View File
@@ -117,7 +117,7 @@ METHOD(aead_t, get_key_size, size_t,
this->signer->get_key_size(this->signer);
}
METHOD(aead_t, set_key, void,
METHOD(aead_t, set_key, bool,
private_aead_t *this, chunk_t key)
{
chunk_t sig, enc;
@@ -127,6 +127,8 @@ METHOD(aead_t, set_key, void,
this->signer->set_key(this->signer, sig);
this->crypter->set_key(this->crypter, enc);
return TRUE;
}
METHOD(aead_t, destroy, void,
+3 -1
View File
@@ -100,8 +100,10 @@ struct aead_t {
* Set the key for encryption and authentication.
*
* @param key encryption and authentication key
* @return TRUE if key set successfully
*/
void (*set_key)(aead_t *this, chunk_t key);
__attribute__((warn_unused_result))
bool (*set_key)(aead_t *this, chunk_t key);
/**
* Destroy a aead_t.
+8 -2
View File
@@ -306,7 +306,10 @@ static u_int bench_aead(private_crypto_tester_t *this,
memset(iv, 0x56, sizeof(iv));
memset(key, 0x12, sizeof(key));
memset(assoc, 0x78, sizeof(assoc));
aead->set_key(aead, chunk_from_thing(key));
if (!aead->set_key(aead, chunk_from_thing(key)))
{
return 0;
}
icv = aead->get_icv_size(aead);
buf = chunk_alloc(this->bench_size + icv);
@@ -374,7 +377,10 @@ METHOD(crypto_tester_t, test_aead, bool,
tested++;
key = chunk_create(vector->key, aead->get_key_size(aead));
aead->set_key(aead, key);
if (!aead->set_key(aead, key))
{
failed = TRUE;
}
iv = chunk_create(vector->iv, aead->get_iv_size(aead));
assoc = chunk_create(vector->adata, vector->alen);
icv = aead->get_icv_size(aead);
+2 -1
View File
@@ -306,12 +306,13 @@ METHOD(aead_t, get_key_size, size_t,
return this->crypter->get_key_size(this->crypter) + SALT_SIZE;
}
METHOD(aead_t, set_key, void,
METHOD(aead_t, set_key, bool,
private_ccm_aead_t *this, chunk_t key)
{
memcpy(this->salt, key.ptr + key.len - SALT_SIZE, SALT_SIZE);
key.len -= SALT_SIZE;
this->crypter->set_key(this->crypter, key);
return TRUE;
}
METHOD(aead_t, destroy, void,
+2 -1
View File
@@ -345,13 +345,14 @@ METHOD(aead_t, get_key_size, size_t,
return this->crypter->get_key_size(this->crypter) + SALT_SIZE;
}
METHOD(aead_t, set_key, void,
METHOD(aead_t, set_key, bool,
private_gcm_aead_t *this, chunk_t key)
{
memcpy(this->salt, key.ptr + key.len - SALT_SIZE, SALT_SIZE);
key.len -= SALT_SIZE;
this->crypter->set_key(this->crypter, key);
create_h(this, this->h);
return TRUE;
}
METHOD(aead_t, destroy, void,