diff options
author | Martin Willi <martin@revosec.ch> | 2012-07-06 14:40:04 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-07-16 14:53:37 +0200 |
commit | 6ac8d861d9a6353bae7f3be0a032da282ee13309 (patch) | |
tree | 28e1e56191151f5f636013699eaddf333713c9f1 | |
parent | 27e1eabbb5c4beaedab832d6a7aceb49a86a3061 (diff) | |
download | strongswan-6ac8d861d9a6353bae7f3be0a032da282ee13309.tar.bz2 strongswan-6ac8d861d9a6353bae7f3be0a032da282ee13309.tar.xz |
Add a return value to mac_t.set_key()
-rw-r--r-- | src/libstrongswan/crypto/mac.h | 4 | ||||
-rw-r--r-- | src/libstrongswan/crypto/prfs/mac_prf.c | 3 | ||||
-rw-r--r-- | src/libstrongswan/crypto/signers/mac_signer.c | 3 | ||||
-rw-r--r-- | src/libstrongswan/plugins/cmac/cmac.c | 11 | ||||
-rw-r--r-- | src/libstrongswan/plugins/hmac/hmac.c | 4 | ||||
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_hmac.c | 4 | ||||
-rw-r--r-- | src/libstrongswan/plugins/xcbc/xcbc.c | 11 |
7 files changed, 26 insertions, 14 deletions
diff --git a/src/libstrongswan/crypto/mac.h b/src/libstrongswan/crypto/mac.h index 10e789c22..4f952a2ad 100644 --- a/src/libstrongswan/crypto/mac.h +++ b/src/libstrongswan/crypto/mac.h @@ -62,8 +62,10 @@ struct mac_t { * Any key length must be accepted. * * @param key key to set + * @return TRUE if key set successfully */ - void (*set_key) (mac_t *this, chunk_t key); + __attribute__((warn_unused_result)) + bool (*set_key) (mac_t *this, chunk_t key); /** * Destroys a mac_t object. diff --git a/src/libstrongswan/crypto/prfs/mac_prf.c b/src/libstrongswan/crypto/prfs/mac_prf.c index 600dbd155..b5f6be982 100644 --- a/src/libstrongswan/crypto/prfs/mac_prf.c +++ b/src/libstrongswan/crypto/prfs/mac_prf.c @@ -68,8 +68,7 @@ METHOD(prf_t, get_key_size, size_t, METHOD(prf_t, set_key, bool, private_prf_t *this, chunk_t key) { - this->mac->set_key(this->mac, key); - return TRUE; + return this->mac->set_key(this->mac, key); } METHOD(prf_t, destroy, void, diff --git a/src/libstrongswan/crypto/signers/mac_signer.c b/src/libstrongswan/crypto/signers/mac_signer.c index 8798bde55..7c52aa305 100644 --- a/src/libstrongswan/crypto/signers/mac_signer.c +++ b/src/libstrongswan/crypto/signers/mac_signer.c @@ -103,8 +103,7 @@ METHOD(signer_t, get_block_size, size_t, METHOD(signer_t, set_key, bool, private_signer_t *this, chunk_t key) { - this->mac->set_key(this->mac, key); - return TRUE; + return this->mac->set_key(this->mac, key); } METHOD(signer_t, destroy, void, diff --git a/src/libstrongswan/plugins/cmac/cmac.c b/src/libstrongswan/plugins/cmac/cmac.c index b36d41387..619ab0d8b 100644 --- a/src/libstrongswan/plugins/cmac/cmac.c +++ b/src/libstrongswan/plugins/cmac/cmac.c @@ -226,7 +226,7 @@ static void derive_key(chunk_t chunk) } } -METHOD(mac_t, set_key, void, +METHOD(mac_t, set_key, bool, private_mac_t *this, chunk_t key) { chunk_t resized, iv, l; @@ -240,8 +240,11 @@ METHOD(mac_t, set_key, void, { /* use cmac recursively to resize longer or shorter keys */ resized = chunk_alloca(this->b); memset(resized.ptr, 0, resized.len); - set_key(this, resized); - get_mac(this, key, resized.ptr); + if (!set_key(this, resized) || + !get_mac(this, key, resized.ptr)) + { + return FALSE; + } } /* @@ -267,6 +270,8 @@ METHOD(mac_t, set_key, void, derive_key(l); memcpy(this->k2, l.ptr, l.len); memwipe(l.ptr, l.len); + + return TRUE; } METHOD(mac_t, destroy, void, diff --git a/src/libstrongswan/plugins/hmac/hmac.c b/src/libstrongswan/plugins/hmac/hmac.c index 85ad31776..4f1226505 100644 --- a/src/libstrongswan/plugins/hmac/hmac.c +++ b/src/libstrongswan/plugins/hmac/hmac.c @@ -99,7 +99,7 @@ METHOD(mac_t, get_mac_size, size_t, return this->h->get_hash_size(this->h); } -METHOD(mac_t, set_key, void, +METHOD(mac_t, set_key, bool, private_mac_t *this, chunk_t key) { int i; @@ -128,6 +128,8 @@ METHOD(mac_t, set_key, void, /* begin hashing of inner pad */ this->h->reset(this->h); this->h->get_hash(this->h, this->ipaded_key, NULL); + + return TRUE; } METHOD(mac_t, destroy, void, diff --git a/src/libstrongswan/plugins/openssl/openssl_hmac.c b/src/libstrongswan/plugins/openssl/openssl_hmac.c index 21b1cd88b..feeecf539 100644 --- a/src/libstrongswan/plugins/openssl/openssl_hmac.c +++ b/src/libstrongswan/plugins/openssl/openssl_hmac.c @@ -99,12 +99,12 @@ METHOD(mac_t, get_mac_size, size_t, return EVP_MD_size(this->hasher); } -METHOD(mac_t, set_key, void, +METHOD(mac_t, set_key, bool, private_mac_t *this, chunk_t key) { chunk_clear(&this->key); this->key = chunk_clone(key); - reset(this); + return reset(this); } METHOD(mac_t, destroy, void, diff --git a/src/libstrongswan/plugins/xcbc/xcbc.c b/src/libstrongswan/plugins/xcbc/xcbc.c index 776f15109..26979ace1 100644 --- a/src/libstrongswan/plugins/xcbc/xcbc.c +++ b/src/libstrongswan/plugins/xcbc/xcbc.c @@ -198,7 +198,7 @@ METHOD(mac_t, get_mac_size, size_t, return this->b; } -METHOD(mac_t, set_key, void, +METHOD(mac_t, set_key, bool, private_mac_t *this, chunk_t key) { chunk_t iv, k1, lengthened; @@ -218,8 +218,11 @@ METHOD(mac_t, set_key, void, { /* shorten key using xcbc */ lengthened = chunk_alloca(this->b); memset(lengthened.ptr, 0, lengthened.len); - set_key(this, lengthened); - get_mac(this, key, lengthened.ptr); + if (!set_key(this, lengthened) || + !get_mac(this, key, lengthened.ptr)) + { + return FALSE; + } } k1 = chunk_alloca(this->b); @@ -243,6 +246,8 @@ METHOD(mac_t, set_key, void, this->k1->set_key(this->k1, k1); memwipe(k1.ptr, k1.len); + + return TRUE; } METHOD(mac_t, destroy, void, |