]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Add a return value to hasher_t.reset()
authorMartin Willi <martin@revosec.ch>
Mon, 9 Jul 2012 15:26:14 +0000 (17:26 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 Jul 2012 12:55:06 +0000 (14:55 +0200)
12 files changed:
src/libstrongswan/crypto/hashers/hasher.h
src/libstrongswan/plugins/af_alg/af_alg_hasher.c
src/libstrongswan/plugins/gcrypt/gcrypt_hasher.c
src/libstrongswan/plugins/hmac/hmac.c
src/libstrongswan/plugins/md4/md4_hasher.c
src/libstrongswan/plugins/md5/md5_hasher.c
src/libstrongswan/plugins/openssl/openssl_hasher.c
src/libstrongswan/plugins/padlock/padlock_sha1_hasher.c
src/libstrongswan/plugins/pkcs11/pkcs11_hasher.c
src/libstrongswan/plugins/sha1/sha1_hasher.c
src/libstrongswan/plugins/sha1/sha1_prf.c
src/libstrongswan/plugins/sha2/sha2_hasher.c

index 0480fc642e84adb0b327e676eafefca228fd7392..2685d44a9a2fd0cea894e08d10578c6eb583da4f 100644 (file)
@@ -108,8 +108,11 @@ struct hasher_t {
 
        /**
         * Resets the hasher's state.
+        *
+        * @return                      TRUE if hasher reset successfully
         */
-       void (*reset) (hasher_t *this);
+       __attribute__((warn_unused_result))
+       bool (*reset) (hasher_t *this);
 
        /**
         * Destroys a hasher object.
index 95cdc613c4d2d3c2ab5c87e075b9ec86ce6e652b..de3fbaaf942ab8751d017fedafe0cd504f4a3b9e 100644 (file)
@@ -99,10 +99,11 @@ METHOD(hasher_t, get_hash_size, size_t,
        return this->size;
 }
 
-METHOD(hasher_t, reset, void,
+METHOD(hasher_t, reset, bool,
        private_af_alg_hasher_t *this)
 {
        this->ops->reset(this->ops);
+       return TRUE;
 }
 
 METHOD(hasher_t, get_hash, bool,
index 5de5b118cd57b01572c33a41e84f2ef680e8d4ac..3155a4aa007c0f5a9596a31014ed6685808698bd 100644 (file)
@@ -43,10 +43,11 @@ METHOD(hasher_t, get_hash_size, size_t,
        return gcry_md_get_algo_dlen(gcry_md_get_algo(this->hd));
 }
 
-METHOD(hasher_t, reset, void,
+METHOD(hasher_t, reset, bool,
        private_gcrypt_hasher_t *this)
 {
        gcry_md_reset(this->hd);
+       return TRUE;
 }
 
 METHOD(hasher_t, get_hash, bool,
index c8cb0b828d8f56888effa8dfda855b6c206b7b14..44cb46b4d961f2ff61b57f8ebef28cbbda942499 100644 (file)
@@ -122,8 +122,8 @@ METHOD(mac_t, set_key, bool,
        }
 
        /* begin hashing of inner pad */
-       this->h->reset(this->h);
-       return this->h->get_hash(this->h, this->ipaded_key, NULL);
+       return this->h->reset(this->h) &&
+                  this->h->get_hash(this->h, this->ipaded_key, NULL);
 }
 
 METHOD(mac_t, destroy, void,
index bf934141a8a20d6ff7ef1f04f1f1c642b8ec1585..06c9ec2f8b805cd1ba6a578b0a1b8610b194c3c6 100644 (file)
@@ -266,6 +266,19 @@ static void MD4Final (private_md4_hasher_t *this, u_int8_t digest[16])
        }
 }
 
+METHOD(hasher_t, reset, bool,
+       private_md4_hasher_t *this)
+{
+       this->state[0] = 0x67452301;
+       this->state[1] = 0xefcdab89;
+       this->state[2] = 0x98badcfe;
+       this->state[3] = 0x10325476;
+       this->count[0] = 0;
+       this->count[1] = 0;
+
+       return TRUE;
+}
+
 METHOD(hasher_t, get_hash, bool,
        private_md4_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
 {
@@ -273,7 +286,7 @@ METHOD(hasher_t, get_hash, bool,
        if (buffer != NULL)
        {
                MD4Final(this, buffer);
-               this->public.hasher_interface.reset(&(this->public.hasher_interface));
+               reset(this);
        }
        return TRUE;
 }
@@ -290,7 +303,7 @@ METHOD(hasher_t, allocate_hash, bool,
                allocated_hash.len = HASH_SIZE_MD4;
 
                MD4Final(this, allocated_hash.ptr);
-               this->public.hasher_interface.reset(&(this->public.hasher_interface));
+               reset(this);
 
                *hash = allocated_hash;
        }
@@ -303,17 +316,6 @@ METHOD(hasher_t, get_hash_size, size_t,
        return HASH_SIZE_MD4;
 }
 
-METHOD(hasher_t, reset, void,
-       private_md4_hasher_t *this)
-{
-       this->state[0] = 0x67452301;
-       this->state[1] = 0xefcdab89;
-       this->state[2] = 0x98badcfe;
-       this->state[3] = 0x10325476;
-       this->count[0] = 0;
-       this->count[1] = 0;
-}
-
 METHOD(hasher_t, destroy, void,
        private_md4_hasher_t *this)
 {
index ea8c45010d8747e4c0e453798ea45124e0106085..99b505e5880c00bd42b2b1f1e9d73952655e1f2f 100644 (file)
@@ -299,6 +299,19 @@ static void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
        }
 }
 
+METHOD(hasher_t, reset, bool,
+       private_md5_hasher_t *this)
+{
+       this->state[0] = 0x67452301;
+       this->state[1] = 0xefcdab89;
+       this->state[2] = 0x98badcfe;
+       this->state[3] = 0x10325476;
+       this->count[0] = 0;
+       this->count[1] = 0;
+
+       return TRUE;
+}
+
 METHOD(hasher_t, get_hash, bool,
        private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
 {
@@ -306,7 +319,7 @@ METHOD(hasher_t, get_hash, bool,
        if (buffer != NULL)
        {
                MD5Final(this, buffer);
-               this->public.hasher_interface.reset(&(this->public.hasher_interface));
+               reset(this);
        }
        return TRUE;
 }
@@ -314,18 +327,12 @@ METHOD(hasher_t, get_hash, bool,
 METHOD(hasher_t, allocate_hash, bool,
        private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
 {
-       chunk_t allocated_hash;
-
        MD5Update(this, chunk.ptr, chunk.len);
        if (hash != NULL)
        {
-               allocated_hash.ptr = malloc(HASH_SIZE_MD5);
-               allocated_hash.len = HASH_SIZE_MD5;
-
-               MD5Final(this, allocated_hash.ptr);
-               this->public.hasher_interface.reset(&(this->public.hasher_interface));
-
-               *hash = allocated_hash;
+               *hash = chunk_alloc(HASH_SIZE_MD5);
+               MD5Final(this, hash->ptr);
+               reset(this);
        }
        return TRUE;
 }
@@ -336,17 +343,6 @@ METHOD(hasher_t, get_hash_size, size_t,
        return HASH_SIZE_MD5;
 }
 
-METHOD(hasher_t, reset, void,
-       private_md5_hasher_t *this)
-{
-       this->state[0] = 0x67452301;
-       this->state[1] = 0xefcdab89;
-       this->state[2] = 0x98badcfe;
-       this->state[3] = 0x10325476;
-       this->count[0] = 0;
-       this->count[1] = 0;
-}
-
 METHOD(hasher_t, destroy, void,
        private_md5_hasher_t *this)
 {
index 67b49c186161244d7c76aa0ea7bce1b2c118e37a..bf5ff1f27894fa7c513ec463d68493ba5b79ec22 100644 (file)
@@ -96,10 +96,10 @@ METHOD(hasher_t, get_hash_size, size_t,
        return this->hasher->md_size;
 }
 
-METHOD(hasher_t, reset, void,
+METHOD(hasher_t, reset, bool,
        private_openssl_hasher_t *this)
 {
-       EVP_DigestInit_ex(this->ctx, this->hasher, NULL);
+       return EVP_DigestInit_ex(this->ctx, this->hasher, NULL) == 1;
 }
 
 METHOD(hasher_t, get_hash, bool,
@@ -115,7 +115,7 @@ METHOD(hasher_t, get_hash, bool,
                {
                        return FALSE;
                }
-               reset(this);
+               return reset(this);
        }
        return TRUE;
 }
@@ -175,7 +175,11 @@ openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
        this->ctx = EVP_MD_CTX_create();
 
        /* initialization */
-       reset(this);
+       if (!reset(this))
+       {
+               destroy(this);
+               return NULL;
+       }
 
        return &this->public;
 }
index 406daad1e031ab90be005ed56585d611a6071e5c..4489b902a06e157e9a5ee73f859746b9df3b8aa7 100644 (file)
@@ -83,10 +83,11 @@ static void append_data(private_padlock_sha1_hasher_t *this, chunk_t data)
        this->data.len += data.len;
 }
 
-METHOD(hasher_t, reset, void,
+METHOD(hasher_t, reset, bool,
        private_padlock_sha1_hasher_t *this)
 {
        chunk_free(&this->data);
+       return TRUE;
 }
 
 METHOD(hasher_t, get_hash, bool,
index 29b7fb7a2c564e5a6db4ce529af32cefdde02f93..53a2bfca7123056d5813b474c7a37695eed35c4c 100644 (file)
@@ -138,10 +138,11 @@ static bool load_state(private_pkcs11_hasher_t *this)
        return TRUE;
 }
 
-METHOD(hasher_t, reset, void,
+METHOD(hasher_t, reset, bool,
        private_pkcs11_hasher_t *this)
 {
        this->have_state = FALSE;
+       return TRUE;
 }
 
 METHOD(hasher_t, get_hash, bool,
index ceb8fc0b51bc5ac036a5abdc2f3a57553ddd659b..b0efbae7d750bb1b7ac89706ff8892f92a22eebe 100644 (file)
@@ -175,7 +175,7 @@ static void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
        }
 }
 
-METHOD(hasher_t, reset, void,
+METHOD(hasher_t, reset, bool,
        private_sha1_hasher_t *this)
 {
        this->state[0] = 0x67452301;
@@ -185,6 +185,8 @@ METHOD(hasher_t, reset, void,
        this->state[4] = 0xC3D2E1F0;
        this->count[0] = 0;
        this->count[1] = 0;
+
+       return TRUE;
 }
 
 METHOD(hasher_t, get_hash, bool,
index 5907a0fd217d4926ce5b124312db15e04b73df2f..cdc494b3473a927d564ccdec3446ec2691b16050 100644 (file)
@@ -100,7 +100,11 @@ METHOD(prf_t, set_key, bool,
        int i, rounds;
        u_int32_t *iv = (u_int32_t*)key.ptr;
 
-       this->hasher->public.hasher_interface.reset(&this->hasher->public.hasher_interface);
+       if (!this->hasher->public.hasher_interface.reset(
+                                                                               &this->hasher->public.hasher_interface))
+       {
+               return FALSE;
+       }
        rounds = min(key.len/sizeof(u_int32_t), sizeof(this->hasher->state));
        for (i = 0; i < rounds; i++)
        {
index 607e329e0c598416d6bdbd7f3e830549cd2502a7..1c6dd253366ab9917d6c82436eee4132cf0e1b65 100644 (file)
@@ -426,38 +426,46 @@ static void sha512_final(private_sha512_hasher_t *ctx)
        } while(++j < 8);
 }
 
-METHOD(hasher_t, reset224, void,
+METHOD(hasher_t, reset224, bool,
        private_sha256_hasher_t *this)
 {
        memcpy(&this->sha_H[0], &sha224_hashInit[0], sizeof(this->sha_H));
        this->sha_blocks = 0;
        this->sha_bufCnt = 0;
+
+       return TRUE;
 }
 
-METHOD(hasher_t, reset256, void,
+METHOD(hasher_t, reset256, bool,
        private_sha256_hasher_t *this)
 {
        memcpy(&this->sha_H[0], &sha256_hashInit[0], sizeof(this->sha_H));
        this->sha_blocks = 0;
        this->sha_bufCnt = 0;
+
+       return TRUE;
 }
 
-METHOD(hasher_t, reset384, void,
+METHOD(hasher_t, reset384, bool,
        private_sha512_hasher_t *this)
 {
        memcpy(&this->sha_H[0], &sha384_hashInit[0], sizeof(this->sha_H));
        this->sha_blocks = 0;
        this->sha_blocksMSB = 0;
        this->sha_bufCnt = 0;
+
+       return TRUE;
 }
 
-METHOD(hasher_t, reset512, void,
+METHOD(hasher_t, reset512, bool,
        private_sha512_hasher_t *this)
 {
        memcpy(&this->sha_H[0], &sha512_hashInit[0], sizeof(this->sha_H));
        this->sha_blocks = 0;
        this->sha_blocksMSB = 0;
        this->sha_bufCnt = 0;
+
+       return TRUE;
 }
 
 METHOD(hasher_t, get_hash224, bool,