Contiki-NG
Loading...
Searching...
No Matches
edhoc-config.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, RISE Research Institutes of Sweden AB
3 * Copyright (c) 2020, Industrial Systems Institute (ISI), Patras, Greece
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the copyright holder nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31/**
32 * \file
33 * EDHOC configuration file
34 * \author
35 * Lidia Pocero <pocero@isi.gr>, Rikard Höglund, Marco Tiloca,
36 * Niclas Finne <niclas.finne@ri.se>, and Nicolas Tsiftes <nicolas.tsiftes@ri.se>
37 */
38
39/**
40 * \addtogroup edhoc
41 * @{
42 */
43
44#ifndef _EDHOC_CONFIG_H_
45#define _EDHOC_CONFIG_H_
46
47/**
48 * \brief The max size of the buffers
49 */
50#define EDHOC_MAX_BUFFER 256
51
52/**
53 * \brief Optimized buffer sizes for credentials based on COSE standard analysis
54 * CRED_X: 84-120 bytes typical → 128 bytes (safe margin)
55 * ID_CRED_X: 4-7 bytes (KID mode) or 84-120 bytes (include mode)
56 */
57#define EDHOC_MAX_CRED_LEN 128
58
59#if EDHOC_AUTHENT_TYPE == EDHOC_CRED_KID
60#define EDHOC_MAX_ID_CRED_LEN 16 /* KID mode: 4-7 bytes typical → 16 bytes (safe) */
61#else
62#define EDHOC_MAX_ID_CRED_LEN 128 /* Include mode: same as credential size */
63#endif
64
65/**
66 * \brief The max number of suites
67 *
68 * There are nine suites that are defined at the time of
69 * writing (0-6 and 24-25). We select just a slightly larger
70 * value to avoid using too much unnecessary space for
71 * the array of suites.
72 */
73#define EDHOC_SUITES_MAX_COUNT 10
74
75/**
76 * \brief Set EDHOC connection identifier
77 */
78#ifndef EDHOC_CID
79#ifdef EDHOC_CONF_CID
80#define EDHOC_CID EDHOC_CONF_CID
81#else
82#define EDHOC_CID 0x1
83#endif
84#endif /* EDHOC_CID */
85
86/* Variable-length CID support for testing */
87#ifdef EDHOC_CONF_CID_BYTES
88#define EDHOC_CID_BYTES EDHOC_CONF_CID_BYTES
89#endif
90
91/*---------------------------------------------------------------------------*/
92/*
93 * Configurable Buffer Sizes for Credential Handling
94 *
95 * These buffer sizes control memory usage for EDHOC credential storage.
96 * All can be overridden in project-conf.h using EDHOC_CONF_* variants.
97 *
98 * Example project-conf.h configuration:
99 *
100 * // Increase KID buffer to support longer key identifiers
101 * #define EDHOC_CONF_MAX_KID_LEN 8
102 *
103 * // Increase identity buffer for longer credential names
104 * #define EDHOC_CONF_MAX_IDENTITY_LEN 64
105 *
106 * // Increase CID buffer for applications using longer connection IDs
107 * #define EDHOC_CONF_MAX_CID_LEN 16
108 */
109
110/**
111 * \brief Maximum length of connection identifiers
112 * RFC 9528 allows variable-length CIDs including negative integers
113 *
114 * To override in project-conf.h:
115 * \code
116 * #define EDHOC_CONF_MAX_CID_LEN 16
117 * \endcode
118 */
119#ifdef EDHOC_CONF_MAX_CID_LEN
120#define EDHOC_MAX_CID_LEN EDHOC_CONF_MAX_CID_LEN
121#else
122#define EDHOC_MAX_CID_LEN 8
123#endif
124
125/**
126 * \brief Default CID length for backward compatibility
127 */
128#define EDHOC_DEFAULT_CID_LEN 1
129
130/**
131 * \brief Maximum length of Key Identifiers (KID) in credentials
132 * COSE Key IDs can be 1-4 bytes typically, but allowing larger for flexibility
133 *
134 * To override in project-conf.h:
135 * \code
136 * #define EDHOC_CONF_MAX_KID_LEN 8
137 * \endcode
138 */
139#ifdef EDHOC_CONF_MAX_KID_LEN
140#define EDHOC_MAX_KID_LEN EDHOC_CONF_MAX_KID_LEN
141#else
142#define EDHOC_MAX_KID_LEN 4
143#endif
144
145/**
146 * \brief Maximum length of identity strings in credentials
147 * Used for human-readable credential identities (e.g., "example.edu")
148 *
149 * To override in project-conf.h:
150 * \code
151 * #define EDHOC_CONF_MAX_IDENTITY_LEN 64
152 * \endcode
153 */
154#ifdef EDHOC_CONF_MAX_IDENTITY_LEN
155#define EDHOC_MAX_IDENTITY_LEN EDHOC_CONF_MAX_IDENTITY_LEN
156#else
157#define EDHOC_MAX_IDENTITY_LEN 32
158#endif
159
160/* EDHOC Role definitions */
161#define EDHOC_RESPONDER 0 /* The Responder of the EDHOC protocol */
162#define EDHOC_INITIATOR 1 /* The Initiator of the EDHOC protocol */
163
164/**
165 * \brief Set the EDHOC Protocol role
166 */
167#ifdef EDHOC_CONF_ROLE
168#define EDHOC_ROLE EDHOC_CONF_ROLE
169#else
170#define EDHOC_ROLE EDHOC_INITIATOR
171#endif
172
173/* EDHOC Authentication Method Types: Initiator (I) | Responder (R) */
174#define EDHOC_METHOD0 0 /* Signature Key | Signature Key */
175#define EDHOC_METHOD1 1 /* Signature Key | Static DH Key */
176#define EDHOC_METHOD2 2 /* Static DH Key | Signature Key */
177#define EDHOC_METHOD3 3 /* Static DH Key | Static DH Key */
178
179/**
180 * \brief Set the Authentication method
181 */
182#ifndef EDHOC_METHOD
183#ifdef EDHOC_CONF_METHOD
184#define EDHOC_METHOD EDHOC_CONF_METHOD
185#else
186#define EDHOC_METHOD EDHOC_METHOD0
187#endif
188#endif /* EDHOC_METHOD */
189
190/**
191 * \brief Buffer size for mac_or_sig
192 */
193#if EDHOC_METHOD == EDHOC_METHOD3
194#define EDHOC_MAC_OR_SIG_BUF_LEN EDHOC_MAX_MAC_LEN
195#else
196#define EDHOC_MAC_OR_SIG_BUF_LEN P256_SIGNATURE_LEN
197#endif
198
199/**
200 * \brief Helper defines for method handling on msg. reception
201 */
202#define INITIATOR_METHOD2 \
203 (EDHOC_METHOD == EDHOC_METHOD2 && EDHOC_ROLE == EDHOC_INITIATOR)
204#define RESPONDER_METHOD1 \
205 (EDHOC_METHOD == EDHOC_METHOD1 && EDHOC_ROLE == EDHOC_RESPONDER)
206#define INITIATOR_METHOD1 \
207 (EDHOC_METHOD == EDHOC_METHOD1 && EDHOC_ROLE == EDHOC_INITIATOR)
208#define RESPONDER_METHOD2 \
209 (EDHOC_METHOD == EDHOC_METHOD2 && EDHOC_ROLE == EDHOC_RESPONDER)
210
211/* Credential type/usage */
212#define EDHOC_CRED_KID 2
213#define EDHOC_CRED_INCLUDE 3
214
215/* COSE header labels for ID_CRED_X identification methods */
216#define COSE_HEADER_LABEL_COMPACT_ENCODING 0 /* Compact encoding (bare KID) */
217#define COSE_HEADER_LABEL_CRED_FULL 1 /* Full credential inclusion */
218#define COSE_HEADER_LABEL_KID 4 /* Key ID in map format {4: kid} */
219
220/**
221 * \brief Set the authentication credential type/usage
222 */
223#ifdef EDHOC_CONF_AUTHENT_TYPE
224#define EDHOC_AUTHENT_TYPE EDHOC_CONF_AUTHENT_TYPE
225#else
226#define EDHOC_AUTHENT_TYPE EDHOC_CRED_KID
227#endif
228
229/* cipher suites */
230#define EDHOC_CIPHERSUITE_0 0 /* AES-CCM-16-64-128, (HMAC 256/256) SHA-256, MAC LEN 8, X25519, EdDSA, Ed25519, AES-CCM-16-64-128, SHA-256 */
231#define EDHOC_CIPHERSUITE_1 1 /* AES-CCM-16-128-128, (HMAC 256/256) SHA-256, MAC LEN 16, X25519, EdDSA, Ed25519, AES-CCM-16-64-128, SHA-256 */
232#define EDHOC_CIPHERSUITE_2 2 /* AES-CCM-16-64-128, (HMAC 256/256) SHA-256, MAC LEN 8, P-256, ES256, P-256, AES-CCM-16-64-128, SHA-256 */ /* Supported */
233#define EDHOC_CIPHERSUITE_3 3 /* AES-CCM-16-128-128, (HMAC 256/256) SHA-256, MAC LEN 16, P-256, ES256, P-256, AES-CCM-16-64-128, SHA-256 */ /* Supported */
234#define EDHOC_CIPHERSUITE_4 4 /* ChaCha20/Poly1305, (HMAC 256/256) SHA-256, MAC LEN 16, X25519, EdDSA, Ed25519, ChaCha20/Poly1305, SHA-256 */
235#define EDHOC_CIPHERSUITE_5 5 /* ChaCha20/Poly1305, (HMAC 256/256) SHA-256, MAC LEN 16, P-256, ES256, P-256, ChaCha20/Poly1305, SHA-256 */
236#define EDHOC_CIPHERSUITE_6 6 /* A128GCM, (HMAC 256/256) SHA-256, MAC LEN 16, X25519, ES256, P-256, A128GCM, SHA-256 */
237#define EDHOC_CIPHERSUITE_24 24 /* A256GCM, (HMAC 384/384) SHA-384, MAC LEN 16, P-384, ES384, P-384, A256GCM, SHA-384 */
238#define EDHOC_CIPHERSUITE_25 25 /* ChaCha20/Poly1305, (HMAC 256/256) SHAKE256, MAC LEN 16, X448, EdDSA, Ed448, ChaCha20/Poly1305, SHAKE256 */
239
240/* EDHOC MAC lengths */
241#define EDHOC_MAC_LEN_16 16
242#define EDHOC_MAC_LEN_8 8
243#define EDHOC_MAX_MAC_LEN 16
244
245/* Curves for EDHOC key exchange algorithm (ECDH curve) */
246#define EDHOC_CURVE_P256 1
247
248/* Common settings for supported cipher suites */
249#define ECC_KEY_LEN 32
250#define HASH_LEN 32
251
252/**
253 * \brief Length of signatures
254 */
255#define P256_SIGNATURE_LEN 64
256#define ED25519_SIGNATURE_LEN 64
257#define ED448_SIGNATURE_LEN 114
258#define P384_SIGNATURE_LEN 96
259
260/**
261 * \brief Set EDHOC cipher suite config
262 */
263#ifdef EDHOC_CONF_SUPPORTED_SUITE_1
264#define EDHOC_SUPPORTED_SUITE_1 EDHOC_CONF_SUPPORTED_SUITE_1
265#else
266#define EDHOC_SUPPORTED_SUITE_1 -1
267#endif
268
269#ifdef EDHOC_CONF_SUPPORTED_SUITE_2
270#define EDHOC_SUPPORTED_SUITE_2 EDHOC_CONF_SUPPORTED_SUITE_2
271#else
272#define EDHOC_SUPPORTED_SUITE_2 -1
273#endif
274
275#ifdef EDHOC_CONF_SUPPORTED_SUITE_3
276#define EDHOC_SUPPORTED_SUITE_3 EDHOC_CONF_SUPPORTED_SUITE_3
277#else
278#define EDHOC_SUPPORTED_SUITE_3 -1
279#endif
280
281#ifdef EDHOC_CONF_SUPPORTED_SUITE_4
282#define EDHOC_SUPPORTED_SUITE_4 EDHOC_CONF_SUPPORTED_SUITE_4
283#else
284#define EDHOC_SUPPORTED_SUITE_4 -1
285#endif
286
287/* Handle settings for test vectors */
288#define EDHOC_NO_TEST 0
289#define EDHOC_TEST_VECTOR_TRACE_DH 1
290#define EDHOC_TEST_VECTOR_TRACE_SIG 2
291
292#ifdef EDHOC_CONF_TEST
293#define EDHOC_TEST EDHOC_CONF_TEST
294#else
295#define EDHOC_TEST EDHOC_NO_TEST
296#endif
297
298/**
299 * \brief The number of attempts to try to connect with the EDHOC server successfully
300 */
301#ifndef EDHOC_CONF_ATTEMPTS
302#define EDHOC_CONF_ATTEMPTS 2
303#endif
304
305/**
306 * \brief The max length of the EDHOC message
307 */
308#ifdef EDHOC_CONF_MAX_PAYLOAD_LEN
309#define EDHOC_MAX_PAYLOAD_LEN EDHOC_CONF_MAX_PAYLOAD_LEN
310#else
311#define EDHOC_MAX_PAYLOAD_LEN 256
312#endif
313
314/**
315 * \brief The max length of the Application Data
316 */
317#ifdef EDHOC_CONF_MAX_AD_SZ
318#define EDHOC_MAX_AD_SZ EDHOC_CONF_MAX_AD_SZ
319#else
320#define EDHOC_MAX_AD_SZ 8
321#endif
322
323/**
324 * \brief Enable/disable External Authorization Data (EAD) processing
325 *
326 * When enabled, the implementation will process EAD items according to RFC 9528 Section 6:
327 * - Critical EAD items (negative ead_label) that cannot be processed will trigger an error
328 * - Non-critical EAD items (non-negative ead_label) will be ignored if not recognized
329 *
330 * To disable in project-conf.h:
331 * \code
332 * #define EDHOC_CONF_EAD_PROCESSING 0
333 * \endcode
334 */
335#ifdef EDHOC_CONF_EAD_PROCESSING
336#define EDHOC_EAD_PROCESSING EDHOC_CONF_EAD_PROCESSING
337#else
338#define EDHOC_EAD_PROCESSING 1
339#endif
340
341/**
342 * \brief EDHOC resource CoAP URI path
343 */
344#define EDHOC_COAP_URI_PATH ".well-known/edhoc"
345
346#endif /* _EDHOC_CONFIG_H_ */
347
348/** @} */