summaryrefslogtreecommitdiff
path: root/cesar/cp/secu/src/secu.c
diff options
context:
space:
mode:
authordufour2009-11-03 14:32:14 +0000
committerdufour2009-11-03 14:32:14 +0000
commit7c55065f0ee124e74254d5aba08233d0b5a7bb35 (patch)
treec08290823f0b8be348ebe8cbe8aa10da29679af7 /cesar/cp/secu/src/secu.c
parentc7ff098f67039172fcddbc9ce8a35f9c0384f1fc (diff)
cesar/cp/secu: make expected result of PRUN check as argument, closes #722
In order to prevent wrong checking of the returned result of cp_secu_protocol_check, we now must give the expected result. It then returns a boolean to know if the check failed or succeed. Replace CP_SECU_PROTOCOL_RUN_CHECK_RESULT_FAILURE by CP_SECU_PROTOCOL_RUN_CHECK_RESULT_NB to know the size of the enum. Add a typedef for enum cp_secu_protocol_run_check_result_t. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6315 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp/secu/src/secu.c')
-rw-r--r--cesar/cp/secu/src/secu.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/cesar/cp/secu/src/secu.c b/cesar/cp/secu/src/secu.c
index 58a1535584..490260119f 100644
--- a/cesar/cp/secu/src/secu.c
+++ b/cesar/cp/secu/src/secu.c
@@ -40,28 +40,36 @@ cp_secu_protocol_run_new (cp_secu_protocol_run_t *prun, u8 pid,
prun->my_nonce = lib_rnd32 (rnd);
}
-enum cp_secu_protocol_run_check_result_t
+bool
cp_secu_protocol_check (const cp_secu_protocol_run_t *prun,
- const cp_secu_protocol_run_t *prun_recv)
+ const cp_secu_protocol_run_t *prun_recv,
+ const cp_secu_protocol_run_check_result_t expected_result)
{
+ /* Check parameters. */
dbg_assert (prun_recv);
+ dbg_assert (expected_result < CP_SECU_PROTOCOL_RUN_CHECK_RESULT_NB);
+ /* First exchange of PRUN. */
if (prun_recv->pmn == 1)
- return CP_SECU_PROTOCOL_RUN_CHECK_RESULT_NEW;
+ return expected_result == CP_SECU_PROTOCOL_RUN_CHECK_RESULT_NEW;
else if (prun)
{
+ /* Check PRN, PID and nonce. */
if (prun->prn == prun_recv->prn
&& prun->pmn != 0xff
&& prun->pid == prun_recv->pid
&& prun->my_nonce == prun_recv->my_nonce)
{
+ /* Not first nor last exchange. */
if (prun->pmn + 1 == prun_recv->pmn)
- return CP_SECU_PROTOCOL_RUN_CHECK_RESULT_NEXT;
+ return expected_result == CP_SECU_PROTOCOL_RUN_CHECK_RESULT_NEXT;
+ /* Last exchange. */
else if (prun_recv->pmn == 0xff)
- return CP_SECU_PROTOCOL_RUN_CHECK_RESULT_LAST;
+ return expected_result == CP_SECU_PROTOCOL_RUN_CHECK_RESULT_LAST;
}
}
- return CP_SECU_PROTOCOL_RUN_CHECK_RESULT_FAILURE;
+ /* Error while checking. */
+ return false;
}
void