Contiki 3.x
tsch-security.h
1 /*
2  * Copyright (c) 2014, SICS Swedish ICT.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 #ifndef __TSCH_SECURITY_H__
34 #define __TSCH_SECURITY_H__
35 
36 /********** Includes **********/
37 
38 #include "contiki.h"
39 #include "net/mac/tsch/tsch-asn.h"
41 #include "net/mac/frame802154.h"
42 #include "net/llsec/llsec802154.h"
44 
45 /******** Configuration *******/
46 
47 /* To enable TSCH security:
48  * - set LLSEC802154_CONF_ENABLED
49  * - set LLSEC802154_CONF_USES_EXPLICIT_KEYS
50  * - unset LLSEC802154_CONF_USES_FRAME_COUNTER
51  * */
52 
53 #if LLSEC802154_ENABLED && !LLSEC802154_USES_EXPLICIT_KEYS
54 #error LLSEC802154_ENABLED set but LLSEC802154_USES_EXPLICIT_KEYS unset
55 #endif /* LLSEC802154_ENABLED */
56 #if LLSEC802154_ENABLED && LLSEC802154_USES_FRAME_COUNTER
57 #error LLSEC802154_ENABLED set but LLSEC802154_USES_FRAME_COUNTER set
58 #endif /* LLSEC802154_ENABLED */
59 
60 /* K1, defined in 6TiSCH minimal, is well-known (offers no security) and used for EBs only */
61 #ifdef TSCH_SECURITY_CONF_K1
62 #define TSCH_SECURITY_K1 TSCH_SECURITY_CONF_K1
63 #else /* TSCH_SECURITY_CONF_K1 */
64 #define TSCH_SECURITY_K1 { 0x36, 0x54, 0x69, 0x53, 0x43, 0x48, 0x20, 0x6D, 0x69, 0x6E, 0x69, 0x6D, 0x61, 0x6C, 0x31, 0x35 }
65 #endif /* TSCH_SECURITY_CONF_K1 */
66 
67 /* K2, defined in 6TiSCH minimal, is used for all but EB traffic */
68 #ifdef TSCH_SECURITY_CONF_K2
69 #define TSCH_SECURITY_K2 TSCH_SECURITY_CONF_K2
70 #else /* TSCH_SECURITY_CONF_K2 */
71 #define TSCH_SECURITY_K2 { 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xca, 0xfe, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xca, 0xfe }
72 #endif /* TSCH_SECURITY_CONF_K2 */
73 
74 /* Key used for EBs */
75 #ifdef TSCH_SECURITY_CONF_KEY_INDEX_EB
76 #define TSCH_SECURITY_KEY_INDEX_EB TSCH_SECURITY_CONF_KEY_INDEX_EB
77 #else
78 #define TSCH_SECURITY_KEY_INDEX_EB 1 /* Use K1 as per 6TiSCH minimal */
79 #endif
80 
81 /* Security level for EBs */
82 #ifdef TSCH_SECURITY_CONF_SEC_LEVEL_EB
83 #define TSCH_SECURITY_KEY_SEC_LEVEL_EB TSCH_SECURITY_CONF_SEC_LEVEL_EB
84 #else
85 #define TSCH_SECURITY_KEY_SEC_LEVEL_EB 1 /* MIC-32, as per 6TiSCH minimal */
86 #endif
87 
88 /* Key used for ACK */
89 #ifdef TSCH_SECURITY_CONF_KEY_INDEX_ACK
90 #define TSCH_SECURITY_KEY_INDEX_ACK TSCH_SECURITY_CONF_KEY_INDEX_ACK
91 #else
92 #define TSCH_SECURITY_KEY_INDEX_ACK 2 /* Use K2 as per 6TiSCH minimal */
93 #endif
94 
95 /* Security level for ACKs */
96 #ifdef TSCH_SECURITY_CONF_SEC_LEVEL_ACK
97 #define TSCH_SECURITY_KEY_SEC_LEVEL_ACK TSCH_SECURITY_CONF_SEC_LEVEL_ACK
98 #else
99 #define TSCH_SECURITY_KEY_SEC_LEVEL_ACK 5 /* Encryption + MIC-32, as per 6TiSCH minimal */
100 #endif
101 
102 /* Key used for Other (Data, Cmd) */
103 #ifdef TSCH_SECURITY_CONF_KEY_INDEX_OTHER
104 #define TSCH_SECURITY_KEY_INDEX_OTHER TSCH_SECURITY_CONF_KEY_INDEX_OTHER
105 #else
106 #define TSCH_SECURITY_KEY_INDEX_OTHER 2 /* Use K2 as per 6TiSCH minimal */
107 #endif
108 
109 /* Security level for Other (Data, Cmd) */
110 #ifdef TSCH_SECURITY_CONF_SEC_LEVEL_OTHER
111 #define TSCH_SECURITY_KEY_SEC_LEVEL_OTHER TSCH_SECURITY_CONF_SEC_LEVEL_OTHER
112 #else
113 #define TSCH_SECURITY_KEY_SEC_LEVEL_OTHER 5 /* Encryption + MIC-32, as per 6TiSCH minimal */
114 #endif
115 
116 /************ Types ***********/
117 
118 typedef uint8_t aes_key[16];
119 
120 /********** Functions *********/
121 
122 int tsch_security_mic_len(const frame802154_t *frame);
123 int tsch_security_secure_frame(uint8_t *hdr, uint8_t *outbuf,
124  int hdrlen, int datalen, struct asn_t *asn);
125 int tsch_security_parse_frame(const uint8_t *hdr, int hdrlen, int datalen,
126  const frame802154_t *frame, const linkaddr_t *sender, struct asn_t *asn);
127 
128 #endif /* __TSCH_SECURITY_H__ */
Private TSCH definitions (meant for use by TSCH implementation files only) ...
Common functionality of 802.15.4-compliant llsec_drivers.
TSCH 5-Byte Absolute Slot Number (ASN) management
IEEE 802.15.4e Information Element (IE) creation and parsing.
802.15.4 frame creation and parsing functions
Parameters used by the frame802154_create() function.
Definition: frame802154.h:192