Add a return value to crypter_t.set_key()

This commit is contained in:
Martin Willi
2012-07-16 14:53:38 +02:00
parent 3b96189a2a
commit ce73fc19db
23 changed files with 87 additions and 57 deletions
+2 -7
View File
@@ -141,13 +141,8 @@ METHOD(aead_t, set_key, bool,
chunk_split(key, "mm", this->signer->get_key_size(this->signer), &sig,
this->crypter->get_key_size(this->crypter), &enc);
if (!this->signer->set_key(this->signer, sig))
{
return FALSE;
}
this->crypter->set_key(this->crypter, enc);
return TRUE;
return this->signer->set_key(this->signer, sig) &&
this->crypter->set_key(this->crypter, enc);
}
METHOD(aead_t, destroy, void,
+3 -1
View File
@@ -147,8 +147,10 @@ struct crypter_t {
* The length of the key must match get_key_size().
*
* @param key key to set
* @return TRUE if key set successfully
*/
void (*set_key) (crypter_t *this, chunk_t key);
__attribute__((warn_unused_result))
bool (*set_key) (crypter_t *this, chunk_t key);
/**
* Destroys a crypter_t object.
+8 -2
View File
@@ -151,7 +151,10 @@ static u_int bench_crypter(private_crypto_tester_t *this,
memset(iv, 0x56, sizeof(iv));
memset(key, 0x12, sizeof(key));
crypter->set_key(crypter, chunk_from_thing(key));
if (!crypter->set_key(crypter, chunk_from_thing(key)))
{
return 0;
}
buf = chunk_alloc(this->bench_size);
memset(buf.ptr, 0x34, buf.len);
@@ -214,7 +217,10 @@ METHOD(crypto_tester_t, test_crypter, bool,
tested++;
key = chunk_create(vector->key, crypter->get_key_size(crypter));
crypter->set_key(crypter, key);
if (!crypter->set_key(crypter, key))
{
failed = TRUE;
}
iv = chunk_create(vector->iv, crypter->get_iv_size(crypter));
/* allocated encryption */
+4 -4
View File
@@ -638,8 +638,8 @@ end:
success = FALSE;
/* decrypt the content */
crypter->set_key(crypter, symmetric_key);
if (!crypter->decrypt(crypter, encrypted_content, iv, &this->data))
if (!crypter->set_key(crypter, symmetric_key) ||
!crypter->decrypt(crypter, encrypted_content, iv, &this->data))
{
success = FALSE;
goto failed;
@@ -834,8 +834,8 @@ METHOD(pkcs7_t, build_envelopedData, bool,
DBG3(DBG_LIB, " padded unencrypted data: %B", &in);
/* symmetric encryption of data object */
crypter->set_key(crypter, symmetricKey);
if (!crypter->encrypt(crypter, in, iv, &out))
if (!crypter->set_key(crypter, symmetricKey) ||
!crypter->encrypt(crypter, in, iv, &out))
{
crypter->destroy(crypter);
chunk_clear(&in);