Add a return value to aead_t.set_key()
authorMartin Willi <martin@revosec.ch>
Thu, 5 Jul 2012 15:19:23 +0000 (17:19 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 Jul 2012 12:53:32 +0000 (14:53 +0200)
src/libcharon/sa/ikev1/keymat_v1.c
src/libcharon/sa/ikev2/keymat_v2.c
src/libstrongswan/crypto/aead.c
src/libstrongswan/crypto/aead.h
src/libstrongswan/crypto/crypto_tester.c
src/libstrongswan/plugins/ccm/ccm_aead.c
src/libstrongswan/plugins/gcm/gcm_aead.c

index 9b566b1..11f7c93 100644 (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,
index 1f25257..2275aad 100644 (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)
index 417c0b5..10bcfea 100644 (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,
index 8536110..522996e 100644 (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.
index 7ee1a7a..2b195b3 100644 (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);
index f03440f..8f2e132 100644 (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,
index 8552f5c..7436e13 100644 (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,