1 /*!
2  * \file      se-identity.h
3  *
4  * \brief     Secure Element identity and keys
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2020 Semtech
16  *
17  *               ___ _____ _   ___ _  _____ ___  ___  ___ ___
18  *              / __|_   _/_\ / __| |/ / __/ _ \| _ \/ __| __|
19  *              \__ \ | |/ _ \ (__| ' <| _| (_) |   / (__| _|
20  *              |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
21  *              embedded.connectivity.solutions===============
22  *
23  * \endcode
24  *
25  */
26 #ifndef __SOFT_SE_IDENTITY_H__
27 #define __SOFT_SE_IDENTITY_H__
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*!
34  ******************************************************************************
35  ********************************** WARNING ***********************************
36  ******************************************************************************
37   The secure-element implementation supports both 1.0.x and 1.1.x LoRaWAN
38   versions of the specification.
39   Thus it has been decided to use the 1.1.x keys and EUI name definitions.
40   The below table shows the names equivalence between versions:
41                +---------------------+-------------------------+
42                |       1.0.x         |          1.1.x          |
43                +=====================+=========================+
44                | LORAWAN_DEVICE_EUI  | LORAWAN_DEVICE_EUI      |
45                +---------------------+-------------------------+
46                | LORAWAN_APP_EUI     | LORAWAN_JOIN_EUI        |
47                +---------------------+-------------------------+
48                | LORAWAN_GEN_APP_KEY | LORAWAN_APP_KEY         |
49                +---------------------+-------------------------+
50                | LORAWAN_APP_KEY     | LORAWAN_NWK_KEY         |
51                +---------------------+-------------------------+
52                | LORAWAN_NWK_S_KEY   | LORAWAN_F_NWK_S_INT_KEY |
53                +---------------------+-------------------------+
54                | LORAWAN_NWK_S_KEY   | LORAWAN_S_NWK_S_INT_KEY |
55                +---------------------+-------------------------+
56                | LORAWAN_NWK_S_KEY   | LORAWAN_NWK_S_ENC_KEY   |
57                +---------------------+-------------------------+
58                | LORAWAN_APP_S_KEY   | LORAWAN_APP_S_KEY       |
59                +---------------------+-------------------------+
60  ******************************************************************************
61  ******************************************************************************
62  ******************************************************************************
63  */
64 
65 /*!
66  * Secure-element pin
67  */
68 #define SECURE_ELEMENT_PIN     \
69     {                          \
70         0x00, 0x00, 0x00, 0x00 \
71     }
72 
73 /*!
74  * When set to 1 DevAdd is LORAWAN_DEVICE_ADDRESS
75  * When set to 0 DevAdd is automatically generated using a pseudo random generator
76  */
77 #define STATIC_DEVICE_ADDRESS 0
78 
79 /*!
80  * Device address on the network (big endian)
81  *
82  * \remark In this application the value is automatically generated using
83  *         a pseudo random generator seeded with a value derived from
84  *         BoardUniqueId value if LORAWAN_DEVICE_ADDRESS is set to 0
85  */
86 #define LORAWAN_DEVICE_ADDRESS ( uint32_t ) 0x00000000
87 
88 /*
89  * =============================================================================
90  * BELOW LINES SHOULDN'T BE MODIFIED
91  * =============================================================================
92  */
93 
94 /*!
95  * ATECC608A predefined key slots setup
96  */
97 #define TNGLORA_DEV_EUI_SLOT 10U
98 #define TNGLORA_JOIN_EUI_SLOT 9U
99 #define TNGLORA_ROOT_KEYS_SLOT 0U
100 #define TNGLORA_S_NWK_S_INT_KEY_SLOT 4U
101 #define TNGLORA_F_NWK_S_INT_KEY_SLOT 5U
102 #define TNGLORA_J_S_INT_KEY_SLOT 6U
103 #define TNGLORA_J_S_ENC_KEY_SLOT 7U
104 #define TNGLORA_APP_S_KEY_SLOT 2U
105 #define TNGLORA_NWK_S_ENC_KEY_SLOT 3U
106 #define TNGLORA_MC_APP_S_KEY_0_SLOT 11U
107 #define TNGLORA_MC_NWK_S_KEY_0_SLOT 12U
108 #define TNGLORA_APP_KEY_BLOCK_INDEX 0U
109 #define TNGLORA_NWK_KEY_BLOCK_INDEX 1U
110 #define TNGLORA_REMAINING_KEYS_BLOCK_INDEX 0U
111 
112 #define ATECC608A_SE_KEY_LIST                                                                                          \
113     {                                                                                                                  \
114         {                                                                                                              \
115             /*!                                                                                                        \
116              * Application root key                                                                                    \
117              * WARNING: FOR 1.0.x DEVICES IT IS THE \ref LORAWAN_GEN_APP_KEY                                           \
118              */                                                                                                        \
119             .KeyID         = APP_KEY,                                                                                  \
120             .KeySlotNumber = TNGLORA_ROOT_KEYS_SLOT,                                                                     \
121             .KeyBlockIndex = TNGLORA_APP_KEY_BLOCK_INDEX,                                                              \
122         },                                                                                                             \
123         {                                                                                                              \
124             /*!                                                                                                        \
125              * Network root key                                                                                        \
126              * WARNING: FOR 1.0.x DEVICES IT IS THE \ref LORAWAN_APP_KEY                                               \
127              */                                                                                                        \
128             .KeyID         = NWK_KEY,                                                                                  \
129             .KeySlotNumber = TNGLORA_ROOT_KEYS_SLOT,                                                                     \
130             .KeyBlockIndex = TNGLORA_NWK_KEY_BLOCK_INDEX,                                                              \
131         },                                                                                                             \
132         {                                                                                                              \
133             /*!                                                                                                        \
134              * Join Server integrity key (Dynamically updated)                                                         \
135              * WARNING: NOT USED FOR 1.0.x DEVICES                                                                     \
136              */                                                                                                        \
137             .KeyID         = J_S_INT_KEY,                                                                              \
138             .KeySlotNumber = TNGLORA_J_S_INT_KEY_SLOT,                                                                 \
139             .KeyBlockIndex = TNGLORA_REMAINING_KEYS_BLOCK_INDEX,                                                       \
140         },                                                                                                             \
141         {                                                                                                              \
142             /*!                                                                                                        \
143              * Join Server encryption key (Dynamically updated)                                                        \
144              * WARNING: NOT USED FOR 1.0.x DEVICES                                                                     \
145              */                                                                                                        \
146             .KeyID         = J_S_ENC_KEY,                                                                              \
147             .KeySlotNumber = TNGLORA_J_S_ENC_KEY_SLOT,                                                                 \
148             .KeyBlockIndex = TNGLORA_REMAINING_KEYS_BLOCK_INDEX,                                                       \
149         },                                                                                                             \
150         {                                                                                                              \
151             /*!                                                                                                        \
152              * Forwarding Network session integrity key                                                                \
153              * WARNING: NWK_S_KEY FOR 1.0.x DEVICES                                                                    \
154              */                                                                                                        \
155             .KeyID         = F_NWK_S_INT_KEY,                                                                          \
156             .KeySlotNumber = TNGLORA_F_NWK_S_INT_KEY_SLOT,                                                             \
157             .KeyBlockIndex = TNGLORA_REMAINING_KEYS_BLOCK_INDEX,                                                       \
158         },                                                                                                             \
159         {                                                                                                              \
160             /*!                                                                                                        \
161              * Serving Network session integrity key                                                                   \
162              * WARNING: NOT USED FOR 1.0.x DEVICES. MUST BE THE SAME AS \ref LORAWAN_F_NWK_S_INT_KEY                   \
163              */                                                                                                        \
164             .KeyID         = S_NWK_S_INT_KEY,                                                                          \
165             .KeySlotNumber = TNGLORA_S_NWK_S_INT_KEY_SLOT,                                                             \
166             .KeyBlockIndex = TNGLORA_REMAINING_KEYS_BLOCK_INDEX,                                                       \
167         },                                                                                                             \
168         {                                                                                                              \
169             /*!                                                                                                        \
170              * Network session encryption key                                                                          \
171              * WARNING: NOT USED FOR 1.0.x DEVICES. MUST BE THE SAME AS \ref LORAWAN_F_NWK_S_INT_KEY                   \
172              */                                                                                                        \
173             .KeyID         = NWK_S_ENC_KEY,                                                                            \
174             .KeySlotNumber = TNGLORA_NWK_S_ENC_KEY_SLOT,                                                               \
175             .KeyBlockIndex = TNGLORA_REMAINING_KEYS_BLOCK_INDEX,                                                       \
176         },                                                                                                             \
177         {                                                                                                              \
178             /*!                                                                                                        \
179              * Application session key                                                                                 \
180              */                                                                                                        \
181             .KeyID         = APP_S_KEY,                                                                                \
182             .KeySlotNumber = TNGLORA_APP_S_KEY_SLOT,                                                                   \
183             .KeyBlockIndex = TNGLORA_REMAINING_KEYS_BLOCK_INDEX,                                                       \
184         },                                                                                                             \
185         {                                                                                                              \
186             /*!                                                                                                        \
187              * Multicast root key (Dynamically updated)                                                                \
188              * WARNING: NOT CURRENTLY SUPPORTED BY ATECC608A                                                           \
189              * TODO: Add support                                                                                       \
190              */                                                                                                        \
191             .KeyID         = MC_ROOT_KEY,                                                                              \
192             .KeySlotNumber = 0,                                                                                        \
193             .KeyBlockIndex = 0,                                                                                        \
194         },                                                                                                             \
195         {                                                                                                              \
196             /*!                                                                                                        \
197              * Multicast key encryption key (Dynamically updated)                                                      \
198              * WARNING: NOT CURRENTLY SUPPORTED BY ATECC608A                                                           \
199              * TODO: Add support                                                                                       \
200              */                                                                                                        \
201             .KeyID         = MC_KE_KEY,                                                                                \
202             .KeySlotNumber = 0,                                                                                        \
203             .KeyBlockIndex = 0,                                                                                        \
204         },                                                                                                             \
205         {                                                                                                              \
206             /*!                                                                                                        \
207              * Multicast group #0 root key (Dynamically updated)                                                       \
208              * WARNING: NOT CURRENTLY SUPPORTED BY ATECC608A                                                           \
209              * TODO: Add support                                                                                       \
210              */                                                                                                        \
211             .KeyID         = MC_KEY_0,                                                                                 \
212             .KeySlotNumber = 0,                                                                                        \
213             .KeyBlockIndex = 0,                                                                                        \
214         },                                                                                                             \
215         {                                                                                                              \
216             /*!                                                                                                        \
217              * Multicast group #0 application session key (Dynamically updated)                                        \
218              */                                                                                                        \
219             .KeyID         = MC_APP_S_KEY_0,                                                                           \
220             .KeySlotNumber = TNGLORA_MC_APP_S_KEY_0_SLOT,                                                              \
221             .KeyBlockIndex = TNGLORA_REMAINING_KEYS_BLOCK_INDEX,                                                       \
222         },                                                                                                             \
223         {                                                                                                              \
224             /*!                                                                                                        \
225              * Multicast group #0 network session key (Dynamically updated)                                            \
226              */                                                                                                        \
227             .KeyID         = MC_NWK_S_KEY_0,                                                                           \
228             .KeySlotNumber = TNGLORA_MC_NWK_S_KEY_0_SLOT,                                                              \
229             .KeyBlockIndex = TNGLORA_REMAINING_KEYS_BLOCK_INDEX,                                                       \
230         },                                                                                                             \
231         {                                                                                                              \
232             /*!                                                                                                        \
233              * All zeros key. (ClassB usage)(constant)                                                                 \
234              * WARNING: NOT CURRENTLY SUPPORTED BY ATECC608A                                                           \
235              * TODO: Add support                                                                                       \
236              *       SE should provide a slot for SLOT_RAND_ZERO_KEY.                                                  \
237              *       .KeyValue = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
238              *                     0x00, 0x00 }                                                                                            \
239              */                                                                                                        \
240             .KeyID         = SLOT_RAND_ZERO_KEY,                                                                       \
241             .KeySlotNumber = 0,                                                                                        \
242             .KeyBlockIndex = 0,                                                                                        \
243         },                                                                                                             \
244     }
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif  //  __SOFT_SE_IDENTITY_H__
251