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.h"
26 #include "edhoc/runtime_context.h"
27 
28 #include "common/oscore_edhoc_error.h"
29 
30 /**
31  * @brief Initializes the EDHOC runtime context
32  *
33  * @param c Pointer to the runtime context
34  */
35 void runtime_context_init(struct runtime_context *c);
36 
37 /**
38  * @brief 			Generates message 1.
39  *
40  * @param[in] c 		Initiator context.
41  * @param[in,out] rc 		Runtime context.
42  * @retval			Ok or error code.
43  */
44 enum err msg1_gen(const struct edhoc_initiator_context *c,
45 		  struct runtime_context *rc);
46 
47 /**
48  * @brief Generates message 3. This function should by used by on the
49  *        initiator side.
50  *
51  * @param c initiator context
52  * @param rc runtime context
53  * @param cred_r_array array of CRED_Rs
54  * @param num_cred_r Number of elements in CRED_R
55  * @param ead_2 EAD_2 contained in message 2
56  * @param ead_2_len length of EAD_2
57  * @param prk_out the derived secret (output)
58  * @param prk_out_len length of prk_4x3m
59  * @return enum err
60  */
61 enum err msg3_gen(const struct edhoc_initiator_context *c,
62 		  struct runtime_context *rc, struct cred_array *cred_r_array,
63 		  struct byte_array *c_r, struct byte_array *prk_out);
64 
65 /**
66  * @brief Processes message 4. This function should by used by on the initiator
67  *        side.
68  *
69  * @param c initiator context
70  * @param rc runtime context
71  * @param ead_4 EAD_4 (output)
72  * @param ead_4_len length of EAD_4
73  * @return enum err
74  */
75 enum err msg4_process(struct runtime_context *rc);
76 
77 /**
78  * @brief 		Generates message 2. This function should by used by on the
79  * 				responder side.
80  *
81  * @param 		c responder context
82  * @param 		rc runtime context
83  * @param[out] 	c_i_bytes connection identifier C_I
84  * @return 		error code
85  */
86 enum err msg2_gen(struct edhoc_responder_context *c, struct runtime_context *rc,
87 		  struct byte_array *c_i_bytes);
88 
89 /**
90  * @brief Processes message 3. This function should by used by on the responder
91  *        side. It produces prk_out to be used in the exporter interface.
92  *
93  * @param c responder context
94  * @param rc runtime context
95  * @param cred_i_array Array of CRED_Is
96  * @param num_cred_i Number of elements in cred_i_array
97  * @param ead_3 EAD_3 from message 3 (output)
98  * @param ead_3_len length of EAD_3
99  * @param prk_out the derived secret (output)
100  * @param prk_out_len length of prk_out
101  * @param public_key public key of initiator
102  * @param size of public key
103  * @return enum err
104  */
105 enum err msg3_process(struct edhoc_responder_context *c,
106 		      struct runtime_context *rc,
107 		      struct cred_array *cred_i_array,
108 		      struct byte_array *prk_out,
109 		      struct byte_array *initiator_pk);
110 
111 /**
112  * @brief Generates message 4. This function should by used by on the responder
113  *        side.
114  *
115  * @param c responder context
116  * @param rc runtime context
117  * @return enum err
118  */
119 enum err msg4_gen(struct edhoc_responder_context *c,
120 		  struct runtime_context *rc);
121 #endif
122