1 /*
2    Copyright (c) 2022 Fraunhofer AISEC. See the COPYRIGHT
3    file at the top-level directory of this distribution.
4 
5    Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6    http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7    <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8    option. This file may not be copied, modified, or distributed
9    except according to those terms.
10 */
11 
12 /*
13  * In the most general case the user of this library should use only the
14  * functions exposed in edhoc.h. Some more advance users may want to manage the
15  * edhoc state by themself. The functions in this file are meant to be used by
16  * such users. An example how the functions in this file can be used can be
17  * found in responder.c and initiator.c
18  */
19 
20 #ifndef EDHOC_INTERNAL_H
21 #define EDHOC_INTERNAL_H
22 
23 #include <stdint.h>
24 
25 #include "edhoc/runtime_context.h"
26 
27 #include "common/oscore_edhoc_error.h"
28 
29 /**
30  * @brief Initializes the EDHOC runtime context
31  *
32  * @param c Pointer to the runtime context
33  */
34 void runtime_context_init(struct runtime_context *c);
35 
36 /**
37  * @brief Generates message 1. This function should by used by on the
38  *        initiator side.
39  *
40  * @param c initiator context
41  * @param rc runtime context
42  */
43 enum err msg1_gen(const struct edhoc_initiator_context *c,
44 		  struct runtime_context *rc);
45 
46 /**
47  * @brief Generates message 3. This function should by used by on the
48  *        initiator side.
49  *
50  * @param c initiator context
51  * @param rc runtime context
52  * @param cred_r_array array of CRED_Rs
53  * @param num_cred_r Number of elements in CRED_R
54  * @param ead_2 EAD_2 contained in message 2
55  * @param ead_2_len length of EAD_2
56  * @param prk_4x3m the derived secret (output)
57  * @param prk_4x3m_len length of prk_4x3m
58  * @param th4 the transcript hash 4 (output)
59  * @param th4_len length of th4
60  * @return enum err
61  */
62 enum err msg3_gen(const struct edhoc_initiator_context *c,
63 		  struct runtime_context *rc,
64 		  struct other_party_cred *cred_r_array, uint16_t num_cred_r,
65 		  uint8_t *ead_2, uint32_t *ead_2_len, uint8_t *prk_4x3m,
66 		  uint32_t prk_4x3m_len, uint8_t *th4);
67 
68 /**
69  * @brief Processes message 4. This function should by used by on the initiator
70  *        side.
71  *
72  * @param c initiator context
73  * @param rc runtime context
74  * @param ead_4 EAD_4 (output)
75  * @param ead_4_len lenhgt of EAD_4
76  * @param prk_4x3m the derived secret
77  * @param prk_4x3m_len length of prk_4x3m
78  * @param th4 the transcript hash 4
79  * @param th4_len length of th4
80  * @return enum err
81  */
82 enum err msg4_process(struct runtime_context *rc, uint8_t *ead_4,
83 		      uint32_t *ead_4_len, uint8_t *prk_4x3m,
84 		      uint32_t prk_4x3m_len, uint8_t *th4, uint32_t th4_len);
85 
86 /**
87  * @brief Generates message 2. This function should by used by on the responder
88  *        side.
89  *
90  * @param c responder context
91  * @param rc runtime context
92  * @param ead_1 EAD_1 from message 1 (output)
93  * @param ead_1_len length of EAD_1
94  * @return enum err
95  */
96 enum err msg2_gen(struct edhoc_responder_context *c, struct runtime_context *rc,
97 		  uint8_t *ead_1, uint32_t *ead_1_len);
98 
99 /**
100  * @brief Processes message 3. This function should by used by on the responder
101  *        side. prk_4x3m and th4 are the outpus used in the exporter interface.
102  *
103  * @param c responder context
104  * @param rc runtime context
105  * @param cred_i_array Array of CRED_Is
106  * @param num_cred_i Number of elements in cred_i_array
107  * @param ead_3 EAD_3 from message 3 (output)
108  * @param ead_3_len length of EAD_3
109  * @param prk_4x3m the derived secret (output)
110  * @param prk_4x3m_len length of prk_4x3m
111  * @param th4 the transcript hash 4 (output)
112  * @param th4_len length of th4
113  * @return enum err
114  */
115 enum err msg3_process(struct edhoc_responder_context *c,
116 		      struct runtime_context *rc,
117 		      struct other_party_cred *cred_i_array,
118 		      uint16_t num_cred_i, uint8_t *ead_3, uint32_t *ead_3_len,
119 		      uint8_t *prk_4x3m, uint32_t prk_4x3m_len, uint8_t *th4);
120 
121 /**
122  * @brief Generates message 4. This function should by used by on the responder
123  *        side.
124  *
125  * @param c responder context
126  * @param rc runtime context
127  * @param prk_4x3m the derived secret
128  * @param prk_4x3m_len length of prk_4x3m
129  * @param th4 the transcript hash 4
130  * @param th4_len length of th4
131  * @return enum err
132  */
133 enum err msg4_gen(struct edhoc_responder_context *c, struct runtime_context *rc,
134 		  uint8_t *prk_4x3m, uint32_t prk_4x3m_len, uint8_t *th4,
135 		  uint32_t th4_len);
136 #endif
137