diff options
Diffstat (limited to 'src/libstrongswan/crypto')
-rw-r--r-- | src/libstrongswan/crypto/aead.c | 9 | ||||
-rw-r--r-- | src/libstrongswan/crypto/crypters/crypter.h | 4 | ||||
-rw-r--r-- | src/libstrongswan/crypto/crypto_tester.c | 10 | ||||
-rw-r--r-- | src/libstrongswan/crypto/pkcs7.c | 8 |
4 files changed, 17 insertions, 14 deletions
diff --git a/src/libstrongswan/crypto/aead.c b/src/libstrongswan/crypto/aead.c index 595b75f87..02fb8d50a 100644 --- a/src/libstrongswan/crypto/aead.c +++ b/src/libstrongswan/crypto/aead.c @@ -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, diff --git a/src/libstrongswan/crypto/crypters/crypter.h b/src/libstrongswan/crypto/crypters/crypter.h index a615c0e22..4c273059b 100644 --- a/src/libstrongswan/crypto/crypters/crypter.h +++ b/src/libstrongswan/crypto/crypters/crypter.h @@ -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. diff --git a/src/libstrongswan/crypto/crypto_tester.c b/src/libstrongswan/crypto/crypto_tester.c index 812e94914..4e5e840b5 100644 --- a/src/libstrongswan/crypto/crypto_tester.c +++ b/src/libstrongswan/crypto/crypto_tester.c @@ -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 */ diff --git a/src/libstrongswan/crypto/pkcs7.c b/src/libstrongswan/crypto/pkcs7.c index e422dae0e..ded388181 100644 --- a/src/libstrongswan/crypto/pkcs7.c +++ b/src/libstrongswan/crypto/pkcs7.c @@ -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); |