]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Nonce: Let get_nonce, allocate_nonce return boolean
authorReto Buerki <reet@codelabs.ch>
Tue, 12 Jun 2012 08:54:02 +0000 (10:54 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 Jul 2012 12:53:34 +0000 (14:53 +0200)
src/libcharon/sa/ikev1/phase1.c
src/libcharon/sa/ikev1/tasks/quick_mode.c
src/libcharon/sa/ikev2/tasks/child_create.c
src/libcharon/sa/ikev2/tasks/ike_init.c
src/libstrongswan/crypto/nonce_gen.h
src/libstrongswan/plugins/nonce/nonce_nonceg.c

index 20abd0a02bdc0fbc46b740b14695f6738c592264..6e062778b7d783ba465b23d1ee98e7d8ca528e5e 100644 (file)
@@ -651,7 +651,12 @@ METHOD(phase1_t, add_nonce_ke, bool,
                DBG1(DBG_IKE, "no nonce generator found to create nonce");
                return FALSE;
        }
-       nonceg->allocate_nonce(nonceg, NONCE_SIZE, &nonce);
+       if (!nonceg->allocate_nonce(nonceg, NONCE_SIZE, &nonce))
+       {
+               DBG1(DBG_IKE, "nonce allocation failed");
+               nonceg->destroy(nonceg);
+               return FALSE;
+       }
        nonceg->destroy(nonceg);
 
        nonce_payload = nonce_payload_create(NONCE_V1);
index 9251e1a35e77abd5dca088d4bc8832345a0962ad..67d1b45f10cf1298f7af52f013fd98c6aef09628 100644 (file)
@@ -328,7 +328,12 @@ static bool add_nonce(private_quick_mode_t *this, chunk_t *nonce,
                DBG1(DBG_IKE, "no nonce generator found to create nonce");
                return FALSE;
        }
-       nonceg->allocate_nonce(nonceg, NONCE_SIZE, nonce);
+       if (!nonceg->allocate_nonce(nonceg, NONCE_SIZE, nonce))
+       {
+               DBG1(DBG_IKE, "nonce allocation failed");
+               nonceg->destroy(nonceg);
+               return FALSE;
+       }
        nonceg->destroy(nonceg);
 
        nonce_payload = nonce_payload_create(NONCE_V1);
index 1148eba7d0865b4d612ed39355950cf4b1582557..5c5468dab12b9d89ee4ab20325d0ed7540770ee9 100644 (file)
@@ -207,8 +207,14 @@ static status_t generate_nonce(private_child_create_t *this)
                DBG1(DBG_IKE, "no nonce generator found to create nonce");
                return FAILED;
        }
-       nonceg->allocate_nonce(nonceg, NONCE_SIZE, &this->my_nonce);
+       if (!nonceg->allocate_nonce(nonceg, NONCE_SIZE, &this->my_nonce))
+       {
+               DBG1(DBG_IKE, "nonce allocation failed");
+               nonceg->destroy(nonceg);
+               return FAILED;
+       }
        nonceg->destroy(nonceg);
+
        return SUCCESS;
 }
 
index bd1846e29e8fa262db9d66898aa5a4e8ef3e325a..f2a06735e799aa5f002783fd3d811109133c7bbc 100644 (file)
@@ -263,7 +263,12 @@ METHOD(task_t, build_i, status_t,
                        DBG1(DBG_IKE, "no nonce generator found to create nonce");
                        return FAILED;
                }
-               nonceg->allocate_nonce(nonceg, NONCE_SIZE, &this->my_nonce);
+               if (!nonceg->allocate_nonce(nonceg, NONCE_SIZE, &this->my_nonce))
+               {
+                       DBG1(DBG_IKE, "nonce allocation failed");
+                       nonceg->destroy(nonceg);
+                       return FAILED;
+               }
                nonceg->destroy(nonceg);
        }
 
@@ -302,7 +307,12 @@ METHOD(task_t, process_r,  status_t,
                DBG1(DBG_IKE, "no nonce generator found to create nonce");
                return FAILED;
        }
-       nonceg->allocate_nonce(nonceg, NONCE_SIZE, &this->my_nonce);
+       if (!nonceg->allocate_nonce(nonceg, NONCE_SIZE, &this->my_nonce))
+       {
+               DBG1(DBG_IKE, "nonce allocation failed");
+               nonceg->destroy(nonceg);
+               return FAILED;
+       }
        nonceg->destroy(nonceg);
 
 #ifdef ME
index 889d04a40f42db1facdbf78076208afe174bd5a8..ffa82aa904cd28b14d2fd66cda7edd1a1a07f771 100644 (file)
@@ -35,16 +35,18 @@ struct nonce_gen_t {
         *
         * @param size          size of nonce in bytes
         * @param buffer        pointer where the generated nonce will be written
+        * @return              TRUE if nonce allocation was succesful, FALSE otherwise
         */
-       void (*get_nonce) (nonce_gen_t *this, size_t size, u_int8_t *buffer);
+       bool (*get_nonce) (nonce_gen_t *this, size_t size, u_int8_t *buffer);
 
        /**
         * Generates a nonce and allocates space for it.
         *
         * @param size          size of nonce in bytes
         * @param chunk         chunk which will hold the generated nonce
+        * @return              TRUE if nonce allocation was succesful, FALSE otherwise
         */
-       void (*allocate_nonce) (nonce_gen_t *this, size_t size, chunk_t *chunk);
+       bool (*allocate_nonce) (nonce_gen_t *this, size_t size, chunk_t *chunk);
 
        /**
         * Destroys a nonce generator object.
index 726f6e55018bfa9b0f9aa065dadff3782af29b84..fd1bbe9d822498ef56e7411382be536cc454a7b0 100644 (file)
@@ -35,16 +35,18 @@ struct private_nonce_nonceg_t {
        rng_t* rng;
 };
 
-METHOD(nonce_gen_t, get_nonce, void,
+METHOD(nonce_gen_t, get_nonce, bool,
        private_nonce_nonceg_t *this, size_t size, u_int8_t *buffer)
 {
        this->rng->get_bytes(this->rng, size, buffer);
+       return TRUE;
 }
 
-METHOD(nonce_gen_t, allocate_nonce, void,
+METHOD(nonce_gen_t, allocate_nonce, bool,
        private_nonce_nonceg_t *this, size_t size, chunk_t *chunk)
 {
        this->rng->allocate_bytes(this->rng, size, chunk);
+       return TRUE;
 }
 
 METHOD(nonce_gen_t, destroy, void,