llsec: Permit dynamic security levels
This commit is contained in:
parent
0379af3624
commit
10d8b05bc6
22 changed files with 137 additions and 122 deletions
|
@ -37,4 +37,4 @@
|
|||
* Konrad Krentz <konrad.krentz@gmail.com>
|
||||
*/
|
||||
|
||||
#define LLSEC802154_CONF_SECURITY_LEVEL 6
|
||||
#define LLSEC802154_CONF_ENABLED 1
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SEC_LVL 6
|
||||
#define MIC_LEN LLSEC802154_MIC_LEN(6)
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Test vector C.2.1.2 from IEEE 802.15.4-2006 */
|
||||
static void
|
||||
|
@ -70,8 +73,8 @@ test_sec_lvl_6()
|
|||
/* Frame Counter */
|
||||
0x05 , 0x00 , 0x00 , 0x00 ,
|
||||
0x01 , 0xCE };
|
||||
uint8_t oracle[LLSEC802154_MIC_LENGTH] = { 0x4F , 0xDE , 0x52 , 0x90 ,
|
||||
0x61 , 0xF9 , 0xC6 , 0xF1 };
|
||||
uint8_t oracle[MIC_LEN] = { 0x4F , 0xDE , 0x52 , 0x90 ,
|
||||
0x61 , 0xF9 , 0xC6 , 0xF1 };
|
||||
uint8_t nonce[13];
|
||||
frame802154_frame_counter_t counter;
|
||||
|
||||
|
@ -84,7 +87,7 @@ test_sec_lvl_6()
|
|||
counter.u32 = 5;
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, counter.u16[0]);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, counter.u16[1]);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, LLSEC802154_SECURITY_LEVEL);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, SEC_LVL);
|
||||
packetbuf_hdrreduce(29);
|
||||
|
||||
CCM_STAR.set_key(key);
|
||||
|
@ -92,10 +95,10 @@ test_sec_lvl_6()
|
|||
CCM_STAR.aead(nonce,
|
||||
packetbuf_dataptr(), packetbuf_datalen(),
|
||||
packetbuf_hdrptr(), packetbuf_hdrlen(),
|
||||
((uint8_t *) packetbuf_hdrptr()) + 30, LLSEC802154_MIC_LENGTH,
|
||||
((uint8_t *) packetbuf_hdrptr()) + 30, MIC_LEN,
|
||||
1);
|
||||
|
||||
if(memcmp(((uint8_t *) packetbuf_hdrptr()) + 30, oracle, LLSEC802154_MIC_LENGTH) == 0) {
|
||||
if(memcmp(((uint8_t *) packetbuf_hdrptr()) + 30, oracle, MIC_LEN) == 0) {
|
||||
printf("Success\n");
|
||||
} else {
|
||||
printf("Failure\n");
|
||||
|
@ -115,7 +118,7 @@ test_sec_lvl_6()
|
|||
CCM_STAR.aead(nonce,
|
||||
packetbuf_dataptr(), packetbuf_datalen(),
|
||||
packetbuf_hdrptr(), packetbuf_hdrlen(),
|
||||
((uint8_t *) packetbuf_hdrptr()) + 30, LLSEC802154_MIC_LENGTH,
|
||||
((uint8_t *) packetbuf_hdrptr()) + 30, MIC_LEN,
|
||||
0);
|
||||
if(((uint8_t *) packetbuf_hdrptr())[29] == 0xCE) {
|
||||
printf("Success\n");
|
||||
|
|
|
@ -37,4 +37,4 @@
|
|||
* Konrad Krentz <konrad.krentz@gmail.com>
|
||||
*/
|
||||
|
||||
#define LLSEC802154_CONF_SECURITY_LEVEL 2
|
||||
#define LLSEC802154_CONF_ENABLED 1
|
||||
|
|
|
@ -48,6 +48,9 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SEC_LVL 2
|
||||
#define MIC_LEN LLSEC802154_MIC_LEN(2)
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Test vector C.1 from FIPS Pub 197 */
|
||||
static void
|
||||
|
@ -97,10 +100,10 @@ test_sec_lvl_2()
|
|||
0x05 , 0x00 , 0x00 , 0x00 ,
|
||||
/* Payload */
|
||||
0x55 , 0xCF , 0x00 , 0x00 , 0x51 , 0x52 , 0x53 , 0x54 };
|
||||
uint8_t oracle[LLSEC802154_MIC_LENGTH] = { 0x22 , 0x3B , 0xC1 , 0xEC ,
|
||||
0x84 , 0x1A , 0xB5 , 0x53 };
|
||||
uint8_t oracle[MIC_LEN] = { 0x22 , 0x3B , 0xC1 , 0xEC ,
|
||||
0x84 , 0x1A , 0xB5 , 0x53 };
|
||||
frame802154_frame_counter_t counter;
|
||||
uint8_t mic[LLSEC802154_MIC_LENGTH];
|
||||
uint8_t mic[MIC_LEN];
|
||||
uint8_t nonce[13];
|
||||
|
||||
printf("Testing verification ... ");
|
||||
|
@ -112,7 +115,7 @@ test_sec_lvl_2()
|
|||
counter.u32 = 5;
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, counter.u16[0]);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, counter.u16[1]);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, LLSEC802154_SECURITY_LEVEL);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, SEC_LVL);
|
||||
packetbuf_hdrreduce(18);
|
||||
|
||||
CCM_STAR.set_key(key);
|
||||
|
@ -120,10 +123,10 @@ test_sec_lvl_2()
|
|||
CCM_STAR.aead(nonce,
|
||||
NULL, 0,
|
||||
packetbuf_hdrptr(), packetbuf_totlen(),
|
||||
((uint8_t *) packetbuf_dataptr()) + packetbuf_datalen(), LLSEC802154_MIC_LENGTH,
|
||||
((uint8_t *) packetbuf_dataptr()) + packetbuf_datalen(), MIC_LEN,
|
||||
1);
|
||||
|
||||
if(memcmp(((uint8_t *) packetbuf_dataptr()) + packetbuf_datalen(), oracle, LLSEC802154_MIC_LENGTH) == 0) {
|
||||
if(memcmp(((uint8_t *) packetbuf_dataptr()) + packetbuf_datalen(), oracle, MIC_LEN) == 0) {
|
||||
printf("Success\n");
|
||||
} else {
|
||||
printf("Failure\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue