Add a return value to tls_prf_t.set_key()
authorMartin Willi <martin@revosec.ch>
Fri, 6 Jul 2012 07:49:25 +0000 (09:49 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 Jul 2012 12:53:33 +0000 (14:53 +0200)
src/libtls/tls_crypto.c
src/libtls/tls_prf.c
src/libtls/tls_prf.h

index 5f7002c..fde03b8 100644 (file)
@@ -1483,13 +1483,14 @@ static bool derive_master(private_tls_crypto_t *this, chunk_t premaster,
 
        /* derive master secret */
        seed = chunk_cata("cc", client_random, server_random);
-       this->prf->set_key(this->prf, premaster);
-       if (!this->prf->get_bytes(this->prf, "master secret", seed,
-                                                sizeof(master), master))
+
+       if (!this->prf->set_key(this->prf, premaster) ||
+               !this->prf->get_bytes(this->prf, "master secret", seed,
+                                                         sizeof(master), master) ||
+               !this->prf->set_key(this->prf, chunk_from_thing(master)))
        {
                return FALSE;
        }
-       this->prf->set_key(this->prf, chunk_from_thing(master));
 
        if (this->cache && session.len)
        {
@@ -1624,8 +1625,8 @@ METHOD(tls_crypto_t, resume_session, tls_cipher_suite_t,
                        this->suite = select_cipher_suite(this, &this->suite, 1, KEY_ANY);
                        if (this->suite)
                        {
-                               this->prf->set_key(this->prf, master);
-                               if (!expand_keys(this, client_random, server_random))
+                               if (!this->prf->set_key(this->prf, master) ||
+                                       !expand_keys(this, client_random, server_random))
                                {
                                        this->suite = 0;
                                }
index 0ef4418..09f6934 100644 (file)
@@ -33,10 +33,11 @@ struct private_tls_prf12_t {
        prf_t *prf;
 };
 
-METHOD(tls_prf_t, set_key12, void,
+METHOD(tls_prf_t, set_key12, bool,
        private_tls_prf12_t *this, chunk_t key)
 {
        this->prf->set_key(this->prf, key);
+       return TRUE;
 }
 
 /**
@@ -136,13 +137,14 @@ struct private_tls_prf10_t {
        prf_t *sha1;
 };
 
-METHOD(tls_prf_t, set_key10, void,
+METHOD(tls_prf_t, set_key10, bool,
        private_tls_prf10_t *this, chunk_t key)
 {
        size_t len = key.len / 2 + key.len % 2;
 
        this->md5->set_key(this->md5, chunk_create(key.ptr, len));
        this->sha1->set_key(this->sha1, chunk_create(key.ptr + key.len - len, len));
+       return TRUE;
 }
 
 METHOD(tls_prf_t, get_bytes10, bool,
index c78842e..095eaea 100644 (file)
@@ -34,8 +34,9 @@ struct tls_prf_t {
         * Set the key of the PRF function.
         *
         * @param key           key to set
+        * @return                      TRUE if key set successfully
         */
-       void (*set_key)(tls_prf_t *this, chunk_t key);
+       bool (*set_key)(tls_prf_t *this, chunk_t key);
 
        /**
         * Generate a series of bytes using a label and a seed.