Add a return value to aead_t.set_key()
This commit is contained in:
@@ -204,10 +204,11 @@ METHOD(aead_t, get_key_size, size_t,
|
|||||||
return this->crypter->get_key_size(this->crypter);
|
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)
|
private_aead_t *this, chunk_t key)
|
||||||
{
|
{
|
||||||
this->crypter->set_key(this->crypter, key);
|
this->crypter->set_key(this->crypter, key);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(aead_t, aead_destroy, void,
|
METHOD(aead_t, aead_destroy, void,
|
||||||
|
|||||||
@@ -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);
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
||||||
DBG4(DBG_IKE, "Sk_ei secret %B", &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);
|
chunk_clear(&key);
|
||||||
|
|
||||||
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
||||||
DBG4(DBG_IKE, "Sk_er secret %B", &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);
|
chunk_clear(&key);
|
||||||
|
|
||||||
if (this->initiator)
|
if (this->initiator)
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ METHOD(aead_t, get_key_size, size_t,
|
|||||||
this->signer->get_key_size(this->signer);
|
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)
|
private_aead_t *this, chunk_t key)
|
||||||
{
|
{
|
||||||
chunk_t sig, enc;
|
chunk_t sig, enc;
|
||||||
@@ -127,6 +127,8 @@ METHOD(aead_t, set_key, void,
|
|||||||
|
|
||||||
this->signer->set_key(this->signer, sig);
|
this->signer->set_key(this->signer, sig);
|
||||||
this->crypter->set_key(this->crypter, enc);
|
this->crypter->set_key(this->crypter, enc);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(aead_t, destroy, void,
|
METHOD(aead_t, destroy, void,
|
||||||
|
|||||||
@@ -100,8 +100,10 @@ struct aead_t {
|
|||||||
* Set the key for encryption and authentication.
|
* Set the key for encryption and authentication.
|
||||||
*
|
*
|
||||||
* @param key encryption and authentication key
|
* @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.
|
* Destroy a aead_t.
|
||||||
|
|||||||
@@ -306,7 +306,10 @@ static u_int bench_aead(private_crypto_tester_t *this,
|
|||||||
memset(iv, 0x56, sizeof(iv));
|
memset(iv, 0x56, sizeof(iv));
|
||||||
memset(key, 0x12, sizeof(key));
|
memset(key, 0x12, sizeof(key));
|
||||||
memset(assoc, 0x78, sizeof(assoc));
|
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);
|
icv = aead->get_icv_size(aead);
|
||||||
|
|
||||||
buf = chunk_alloc(this->bench_size + icv);
|
buf = chunk_alloc(this->bench_size + icv);
|
||||||
@@ -374,7 +377,10 @@ METHOD(crypto_tester_t, test_aead, bool,
|
|||||||
tested++;
|
tested++;
|
||||||
|
|
||||||
key = chunk_create(vector->key, aead->get_key_size(aead));
|
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));
|
iv = chunk_create(vector->iv, aead->get_iv_size(aead));
|
||||||
assoc = chunk_create(vector->adata, vector->alen);
|
assoc = chunk_create(vector->adata, vector->alen);
|
||||||
icv = aead->get_icv_size(aead);
|
icv = aead->get_icv_size(aead);
|
||||||
|
|||||||
@@ -306,12 +306,13 @@ METHOD(aead_t, get_key_size, size_t,
|
|||||||
return this->crypter->get_key_size(this->crypter) + SALT_SIZE;
|
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)
|
private_ccm_aead_t *this, chunk_t key)
|
||||||
{
|
{
|
||||||
memcpy(this->salt, key.ptr + key.len - SALT_SIZE, SALT_SIZE);
|
memcpy(this->salt, key.ptr + key.len - SALT_SIZE, SALT_SIZE);
|
||||||
key.len -= SALT_SIZE;
|
key.len -= SALT_SIZE;
|
||||||
this->crypter->set_key(this->crypter, key);
|
this->crypter->set_key(this->crypter, key);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(aead_t, destroy, void,
|
METHOD(aead_t, destroy, void,
|
||||||
|
|||||||
@@ -345,13 +345,14 @@ METHOD(aead_t, get_key_size, size_t,
|
|||||||
return this->crypter->get_key_size(this->crypter) + SALT_SIZE;
|
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)
|
private_gcm_aead_t *this, chunk_t key)
|
||||||
{
|
{
|
||||||
memcpy(this->salt, key.ptr + key.len - SALT_SIZE, SALT_SIZE);
|
memcpy(this->salt, key.ptr + key.len - SALT_SIZE, SALT_SIZE);
|
||||||
key.len -= SALT_SIZE;
|
key.len -= SALT_SIZE;
|
||||||
this->crypter->set_key(this->crypter, key);
|
this->crypter->set_key(this->crypter, key);
|
||||||
create_h(this, this->h);
|
create_h(this, this->h);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(aead_t, destroy, void,
|
METHOD(aead_t, destroy, void,
|
||||||
|
|||||||
Reference in New Issue
Block a user