aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorReto Buerki <reet@codelabs.ch>2012-06-12 10:54:02 +0200
committerMartin Willi <martin@revosec.ch>2012-07-16 14:53:34 +0200
commit605985d122cd854ea7c1b85ce3ec107752c9f103 (patch)
tree19325f83d0425f061b45cbbd0c3467b375501f41 /src
parentf3ca96b2bfd60a9896d89f5e84cb9e737f6f1784 (diff)
downloadstrongswan-605985d122cd854ea7c1b85ce3ec107752c9f103.tar.bz2
strongswan-605985d122cd854ea7c1b85ce3ec107752c9f103.tar.xz
Nonce: Let get_nonce, allocate_nonce return boolean
Diffstat (limited to 'src')
-rw-r--r--src/libcharon/sa/ikev1/phase1.c7
-rw-r--r--src/libcharon/sa/ikev1/tasks/quick_mode.c7
-rw-r--r--src/libcharon/sa/ikev2/tasks/child_create.c8
-rw-r--r--src/libcharon/sa/ikev2/tasks/ike_init.c14
-rw-r--r--src/libstrongswan/crypto/nonce_gen.h6
-rw-r--r--src/libstrongswan/plugins/nonce/nonce_nonceg.c6
6 files changed, 39 insertions, 9 deletions
diff --git a/src/libcharon/sa/ikev1/phase1.c b/src/libcharon/sa/ikev1/phase1.c
index 20abd0a02..6e062778b 100644
--- a/src/libcharon/sa/ikev1/phase1.c
+++ b/src/libcharon/sa/ikev1/phase1.c
@@ -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);
diff --git a/src/libcharon/sa/ikev1/tasks/quick_mode.c b/src/libcharon/sa/ikev1/tasks/quick_mode.c
index 9251e1a35..67d1b45f1 100644
--- a/src/libcharon/sa/ikev1/tasks/quick_mode.c
+++ b/src/libcharon/sa/ikev1/tasks/quick_mode.c
@@ -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);
diff --git a/src/libcharon/sa/ikev2/tasks/child_create.c b/src/libcharon/sa/ikev2/tasks/child_create.c
index 1148eba7d..5c5468dab 100644
--- a/src/libcharon/sa/ikev2/tasks/child_create.c
+++ b/src/libcharon/sa/ikev2/tasks/child_create.c
@@ -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;
}
diff --git a/src/libcharon/sa/ikev2/tasks/ike_init.c b/src/libcharon/sa/ikev2/tasks/ike_init.c
index bd1846e29..f2a06735e 100644
--- a/src/libcharon/sa/ikev2/tasks/ike_init.c
+++ b/src/libcharon/sa/ikev2/tasks/ike_init.c
@@ -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
diff --git a/src/libstrongswan/crypto/nonce_gen.h b/src/libstrongswan/crypto/nonce_gen.h
index 889d04a40..ffa82aa90 100644
--- a/src/libstrongswan/crypto/nonce_gen.h
+++ b/src/libstrongswan/crypto/nonce_gen.h
@@ -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.
diff --git a/src/libstrongswan/plugins/nonce/nonce_nonceg.c b/src/libstrongswan/plugins/nonce/nonce_nonceg.c
index 726f6e550..fd1bbe9d8 100644
--- a/src/libstrongswan/plugins/nonce/nonce_nonceg.c
+++ b/src/libstrongswan/plugins/nonce/nonce_nonceg.c
@@ -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,