summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/cp/cco/action/src/cco_action.c3
-rw-r--r--cesar/cp/cco/action/test/src/action-test.c3
-rw-r--r--cesar/cp/cco/action/test/utest/src/secu.c6
-rw-r--r--cesar/cp/secu/secu.h6
-rw-r--r--cesar/cp/secu/src/secu.c7
-rw-r--r--cesar/cp/secu/stub/src/secu.c4
-rw-r--r--cesar/cp/secu/test/src/test-prun.c22
-rw-r--r--cesar/cp/sta/action/src/assoc.c6
-rw-r--r--cesar/cp/sta/action/src/sc.c3
9 files changed, 34 insertions, 26 deletions
diff --git a/cesar/cp/cco/action/src/cco_action.c b/cesar/cp/cco/action/src/cco_action.c
index 9f35079c49..0b0e4b9182 100644
--- a/cesar/cp/cco/action/src/cco_action.c
+++ b/cesar/cp/cco/action/src/cco_action.c
@@ -1239,8 +1239,7 @@ cp_cco_action_nek_change_start_transaction (cp_t *ctx, cp_sta_t *sta)
/* Initialise the protocol run. */
cp_secu_protocol_run_new (&ctx->cco_action.eks_prun, 1,
- lib_rnd32 (&ctx->rnd),
- lib_rnd32 (&ctx->rnd));
+ &ctx->rnd);
/* Fill the data structure with key type == NONCE_ONLY. */
memset (&data, 0, sizeof (cp_msg_cm_set_key_req_t));
diff --git a/cesar/cp/cco/action/test/src/action-test.c b/cesar/cp/cco/action/test/src/action-test.c
index 2e4dfc7054..2c77b89ab0 100644
--- a/cesar/cp/cco/action/test/src/action-test.c
+++ b/cesar/cp/cco/action/test/src/action-test.c
@@ -755,6 +755,7 @@ test_case_sta_authentication (test_t test)
test_begin (test, "assoc")
{
cp_t cp;
+ lib_rnd_init (&cp.rnd, 1234);
cp_net_t *net;
mfs_rx_t mfs;
bitstream_t bitstream;
@@ -836,7 +837,7 @@ test_case_sta_authentication (test_t test)
mme.p_mme = buffer;
mme.peer.tei = 0x2;
mfs.common.tei = 0x1;
- cp_secu_protocol_run_new (&mme.prun, 0, 0, 0);
+ cp_secu_protocol_run_new (&mme.prun, 0, &cp.rnd);
cp_cco_action__cco__cm_get_key_req_pid0 (&cp, &mme);
diff --git a/cesar/cp/cco/action/test/utest/src/secu.c b/cesar/cp/cco/action/test/utest/src/secu.c
index 7189e2da07..7a114e6ac5 100644
--- a/cesar/cp/cco/action/test/utest/src/secu.c
+++ b/cesar/cp/cco/action/test/utest/src/secu.c
@@ -17,13 +17,13 @@
void
cp_secu_protocol_run_new (cp_secu_protocol_run_t *prun, u8 pid,
- uint prn_rand, uint rand)
+ lib_rnd_t *rnd)
{
memset (prun, 0, sizeof (cp_secu_protocol_run_t));
prun->pmn = 1;
prun->pid = pid;
- prun->prn = prn_rand;
- prun->my_nonce = rand;
+ prun->prn = lib_rnd32 (rnd);
+ prun->my_nonce = lib_rnd32 (rnd);
}
void
diff --git a/cesar/cp/secu/secu.h b/cesar/cp/secu/secu.h
index bd5a943c73..d1eed0d3f1 100644
--- a/cesar/cp/secu/secu.h
+++ b/cesar/cp/secu/secu.h
@@ -18,6 +18,7 @@
#include "cp/secu/defs.h"
#include "cp/secu/pbkdf1.h"
#include "cp/secu/inc/openssl_aes.h"
+#include "lib/rnd.h"
#include <string.h>
#define GET_UINT32(n,b,i) \
@@ -72,12 +73,11 @@ BEGIN_DECLS
* Start a new protocol run and initialise the protocol run structure.
* \param prun protocol run to initialise.
* \param pid protocol identifier
- * \param prun_rand the random number for the PRN.
- * \param rand a random number.
+ * \param rnd the lib random context to generate random number.
*/
void
cp_secu_protocol_run_new (cp_secu_protocol_run_t *prun, u8 pid,
- uint prn_rand, uint rand);
+ lib_rnd_t *rnd);
/**
* Check a received protocol run against the current one.
diff --git a/cesar/cp/secu/src/secu.c b/cesar/cp/secu/src/secu.c
index 5bceee28f4..7cf1359a84 100644
--- a/cesar/cp/secu/src/secu.c
+++ b/cesar/cp/secu/src/secu.c
@@ -27,16 +27,17 @@
void
cp_secu_protocol_run_new (cp_secu_protocol_run_t *prun, u8 pid,
- uint prn_rand, uint rand)
+ lib_rnd_t *rnd)
{
dbg_assert (prun);
dbg_assert (pid <= 4);
+ dbg_assert (rnd);
memset (prun, 0, sizeof (cp_secu_protocol_run_t));
prun->pmn = 1;
prun->pid = pid;
- prun->prn = prn_rand;
- prun->my_nonce = rand;
+ prun->prn = lib_rnd32 (rnd);
+ prun->my_nonce = lib_rnd32 (rnd);
}
enum cp_secu_protocol_run_check_result_t
diff --git a/cesar/cp/secu/stub/src/secu.c b/cesar/cp/secu/stub/src/secu.c
index 103d277476..27b4bcf485 100644
--- a/cesar/cp/secu/stub/src/secu.c
+++ b/cesar/cp/secu/stub/src/secu.c
@@ -17,7 +17,7 @@
void
cp_secu_protocol_run_new (cp_secu_protocol_run_t *prun, u8 pid,
- uint prn_rand, uint rand) __attribute__((weak));
+ lib_rnd_t *rnd) __attribute__((weak));
enum cp_secu_protocol_run_check_result_t
cp_secu_protocol_check (const cp_secu_protocol_run_t *prun,
@@ -34,7 +34,7 @@ cp_secu_nmk2nid(cp_t*ctx, cp_key_t nmk, u8 security_level) __attribute__((weak))
void
cp_secu_protocol_run_new (cp_secu_protocol_run_t *prun, u8 pid,
- uint prn_rand, uint rand) {}
+ lib_rnd_t *rnd) {}
enum cp_secu_protocol_run_check_result_t
cp_secu_protocol_check (const cp_secu_protocol_run_t *prun,
diff --git a/cesar/cp/secu/test/src/test-prun.c b/cesar/cp/secu/test/src/test-prun.c
index bf53fe81c9..2940b674ad 100644
--- a/cesar/cp/secu/test/src/test-prun.c
+++ b/cesar/cp/secu/test/src/test-prun.c
@@ -20,8 +20,11 @@ void
test_case_secu_prun_init (test_t test)
{
cp_secu_protocol_run_t prun;
+ lib_rnd_t rnd;
+ const uint seed = 0x4242;
+ lib_rnd_init (&rnd, seed);
- cp_secu_protocol_run_new (&prun, 0x1, 0x54, 0x34);
+ cp_secu_protocol_run_new (&prun, 0x1, &rnd);
test_case_begin (test, "Protocol Run");
@@ -29,8 +32,9 @@ test_case_secu_prun_init (test_t test)
{
test_fail_if (prun.pmn != 0x1, "Wrong PMN");
test_fail_if (prun.pid != 0x1, "Wrong protocol run PID");
- test_fail_if (prun.prn != 0x54, "Wrong PRN");
- test_fail_if (prun.my_nonce != 0x34);
+ lib_rnd_init (&rnd, seed);
+ test_fail_if (prun.prn != (u16) lib_rnd32 (&rnd), "Wrong PRN");
+ test_fail_if (prun.my_nonce != lib_rnd32 (&rnd));
}
test_end;
}
@@ -41,9 +45,13 @@ test_case_secu_protocol_check (test_t test)
uint result;
cp_secu_protocol_run_t prun;
cp_secu_protocol_run_t prun_recv;
+ lib_rnd_t rnd;
+ const uint seed = 0x4242;
- cp_secu_protocol_run_new (&prun, 0x1, 0x54, 0x34);
- cp_secu_protocol_run_new (&prun_recv, 0x1, 0x54, 0x34);
+ lib_rnd_init (&rnd, seed);
+ cp_secu_protocol_run_new (&prun, 0x1, &rnd);
+ lib_rnd_init (&rnd, seed);
+ cp_secu_protocol_run_new (&prun_recv, 0x1, &rnd);
prun.my_nonce = 0x12345;
prun.your_nonce = 0x3456;
@@ -174,8 +182,10 @@ void
test_case_secu_protocol_next (test_t test)
{
cp_secu_protocol_run_t prun;
+ lib_rnd_t rnd;
+ lib_rnd_init (&rnd, 0x4242);
- cp_secu_protocol_run_new (&prun, 0x1, 0x54, 0x34);
+ cp_secu_protocol_run_new (&prun, 0x1, &rnd);
test_case_begin (test, "Protocol run next");
diff --git a/cesar/cp/sta/action/src/assoc.c b/cesar/cp/sta/action/src/assoc.c
index de2f32d252..59d7fa4fbe 100644
--- a/cesar/cp/sta/action/src/assoc.c
+++ b/cesar/cp/sta/action/src/assoc.c
@@ -210,8 +210,7 @@ cp_sta_action_assoc__wait_assoc_cnf__cc_assoc_cnf__common (cp_t *ctx,
.relayed = false, .key_type = CP_MSG_KEY_NEK,
.nid = cp_sta_own_data_get_nid (ctx) };
cp_secu_protocol_run_new (&ctx->sta_action.assoc.prun, 0,
- lib_rnd32 (&ctx->rnd),
- lib_rnd32 (&ctx->rnd));
+ &ctx->rnd);
cp_msg_cm_get_key_req_send (ctx, &mme->peer, CP_MME_PEKS_NMK,
&ctx->sta_action.assoc.prun, &get_key);
/* Change state. */
@@ -461,8 +460,7 @@ cp_sta_action_assoc__sc_tek_exchanged__cm_set_key_req_pid_3 (cp_t *ctx,
.relayed = false, .key_type = CP_MSG_KEY_NEK,
.nid = cp_sta_own_data_get_nid (ctx) };
cp_secu_protocol_run_new (&ctx->sta_action.assoc.prun, 0,
- lib_rnd32 (&ctx->rnd),
- lib_rnd32 (&ctx->rnd));
+ &ctx->rnd);
cp_msg_cm_get_key_req_send (ctx, &ctx->sta_action.assoc.peer,
CP_MME_PEKS_NMK,
&ctx->sta_action.assoc.prun, &get_key);
diff --git a/cesar/cp/sta/action/src/sc.c b/cesar/cp/sta/action/src/sc.c
index 109379d3cb..d1d3d31bde 100644
--- a/cesar/cp/sta/action/src/sc.c
+++ b/cesar/cp/sta/action/src/sc.c
@@ -298,8 +298,7 @@ cp_sta_action_sc__sc_wait_peer_associated__new_sta_associated (cp_t *ctx,
/* Keep a copy of the hash key. */
memcpy (ctx->sta_action.sc.hash_key, req.hash_key, CP_HASH_KEY_SIZE);
cp_secu_protocol_run_new (&ctx->sta_action.sc.prun, 3,
- lib_rnd32 (&ctx->rnd),
- lib_rnd32 (&ctx->rnd));
+ &ctx->rnd);
/* Send GET_KEY_REQ_PID3. */
cp_msg_cm_get_key_req_send (ctx, &ctx->sta_action.sc.peer,
CP_MME_PEKS_SPC_NOT_EMBEDDED, /* Not encrypted! */