From: Reto Buerki Date: Tue, 12 Jun 2012 08:54:02 +0000 (+0200) Subject: Nonce: Let get_nonce, allocate_nonce return boolean X-Git-Tag: 5.0.1~355 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=605985d122cd854ea7c1b85ce3ec107752c9f103;p=thirdparty%2Fstrongswan.git Nonce: Let get_nonce, allocate_nonce return boolean --- diff --git a/src/libcharon/sa/ikev1/phase1.c b/src/libcharon/sa/ikev1/phase1.c index 20abd0a02b..6e062778b7 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 9251e1a35e..67d1b45f10 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 1148eba7d0..5c5468dab1 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 bd1846e29e..f2a06735e7 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 889d04a40f..ffa82aa904 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 726f6e5501..fd1bbe9d82 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,