Contiki-NG
Loading...
Searching...
No Matches
edhoc-msg-generators.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/**
33 * \file
34 * Declarations for EDHOC message generators.
35 * \author
36 * Lidia Pocero <pocero@isi.gr>, Peter A Jonsson, Rikard Höglund, Marco Tiloca
37 * Christos Koulamas <cklm@isi.gr>, Niclas Finne <niclas.finne@ri.se>,
38 * Nicolas Tsiftes <nicolas.tsiftes@ri.se>
39 */
40
41/**
42 * \addtogroup edhoc
43 * @{
44 */
45
46#ifndef EDHOC_MSG_GENERATORS_H_
47#define EDHOC_MSG_GENERATORS_H_
48
49#include "edhoc.h"
50#include "edhoc-error.h"
51
52/**
53 * \brief Generate the EDHOC Message 1 and set it in the EDHOC context
54 * \param ctx EDHOC Context struct
55 * \param ad Application data to include in MSG1
56 * \param ad_sz Application data length
57 * \param suite_array If true, MSG1 includes an array of cipher suites when more than one is supported.
58 * If false, MSG1 includes a single unsigned suite value regardless of the number
59 * of suites supported by the initiator.
60 * \return EDHOC_SUCCESS on success, error code on failure
61 *
62 * Composes EDHOC Message 1 as described in RFC9528 for EDHOC authentication with
63 * asymmetric keys, encoded as a CBOR sequence in the MSG1 element of the context struct.
64 * Uses the ephemeral key, cipher suite, and connection identifier already set in the
65 * context (they are established by the caller, not by this function). Used by the
66 * Initiator EDHOC role.
67 *
68 * - ctx->MSG1 = (METHOD:unsigned, SUITES_I, G_X, C_I_identifier)
69 *
70 */
71edhoc_error_t edhoc_generate_message_1(edhoc_context_t *ctx, uint8_t *ad, size_t ad_sz, bool suite_array);
72
73/**
74 * \brief Generate the EDHOC Message 2 and set it in the EDHOC context
75 * \param ctx EDHOC Context struct
76 * \param auth_data Application data to include in MSG2
77 * \param auth_data_size Application data length
78 * \return EDHOC_SUCCESS on success, error code on failure
79 *
80 * Used by the EDHOC Responder role to generate message 2.
81 * Computes the transcript hash TH_2 = H(ctx->MSG1, data_2),
82 * computes MAC_2 (Message Authentication Code), computes CIPHERTEXT_2,
83 * and composes EDHOC Message 2 as described in RFC9528
84 * for EDHOC authentication with asymmetric keys, encoded as a CBOR sequence
85 * in the MSG2 element of the context struct. Uses the ephemeral key and
86 * connection identifier already set in the context.
87 *
88 * - ctx->MSG2 = a single CBOR byte string containing G_Y || CIPHERTEXT_2
89 * - where: data_2 = G_Y (C_R is carried inside the plaintext of CIPHERTEXT_2, not in data_2)
90 */
91edhoc_error_t edhoc_generate_message_2(edhoc_context_t *ctx, const uint8_t *auth_data, size_t auth_data_size);
92
93/**
94 * \brief Generate the EDHOC Message 3 and set it in the EDHOC context
95 * \param ctx EDHOC Context struct
96 * \param auth_data Application data to include in MSG3
97 * \param auth_data_size Application data length
98 * \return EDHOC_SUCCESS on success, error code on failure
99 *
100 * Used by the EDHOC Initiator role to generate message 3.
101 * Computes the transcript hash TH_3 = H(TH_2, PLAINTEXT_2, data_3),
102 * computes MAC_3 (Message Authentication Code), computes CIPHERTEXT_3,
103 * and composes EDHOC Message 3 as described in RFC9528
104 * for EDHOC authentication with asymmetric keys, encoded as a CBOR sequence
105 * in the MSG3 element of the context struct.
106 *
107 * - ctx->MSG3 = (data_3, CIPHERTEXT_3)
108 * - where: data_3 = (?C_R_identifier)
109 */
110edhoc_error_t edhoc_generate_message_3(edhoc_context_t *ctx, const uint8_t *auth_data, size_t auth_data_size);
111
112#endif /* EDHOC_MSG_GENERATORS_H_ */
113/** @} */
Error handling module header for EDHOC.
edhoc_error_t
Unified error type for EDHOC operations.
Definition edhoc-error.h:60
An implementation of Ephemeral Diffie-Hellman Over COSE (EDHOC) (RFC9528).
edhoc_error_t edhoc_generate_message_1(edhoc_context_t *ctx, uint8_t *ad, size_t ad_sz, bool suite_array)
Generate the EDHOC Message 1 and set it in the EDHOC context.
edhoc_error_t edhoc_generate_message_3(edhoc_context_t *ctx, const uint8_t *auth_data, size_t auth_data_size)
Generate the EDHOC Message 3 and set it in the EDHOC context.
edhoc_error_t edhoc_generate_message_2(edhoc_context_t *ctx, const uint8_t *auth_data, size_t auth_data_size)
Generate the EDHOC Message 2 and set it in the EDHOC context.