1 /*
2 Copyright (c) 2021 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 #include <stdio.h>
13 #include <zephyr/zephyr.h>
14 #include <zephyr/ztest.h>
15
16 #include <edhoc.h>
17 #include "txrx_wrapper.h"
18 #include "edhoc_tests.h"
19 //#include "edhoc_test_vectors_v14.h"
20
21 struct messages m;
22
23 //todo check that as well that the AD are correct
test_edhoc(enum role p,uint8_t vec_num)24 int test_edhoc(enum role p, uint8_t vec_num)
25 {
26
27
28 // rx_init();
29
30 // m.m1_len = test_vectors[vec_num].message_1_len;
31 // m.m1 = (uint8_t *)test_vectors[vec_num].message_1;
32 // m.m2_len = test_vectors[vec_num].message_2_len;
33 // m.m2 = (uint8_t *)test_vectors[vec_num].message_2;
34 // m.m3_len = test_vectors[vec_num].message_3_len;
35 // m.m3 = (uint8_t *)test_vectors[vec_num].message_3;
36 // m.m4_len = test_vectors[vec_num].message_4_len;
37 // m.m4 = (uint8_t *)test_vectors[vec_num].message_4;
38
39 // if (p == INITIATOR) {
40 // uint16_t cred_num = 1;
41 // struct other_party_cred cred_r;
42 // struct edhoc_initiator_context c_i;
43
44 // rx_initiator_switch = true;
45 // cred_r.id_cred.len = test_vectors[vec_num].id_cred_r_len;
46 // cred_r.id_cred.ptr = (uint8_t *)test_vectors[vec_num].id_cred_r;
47 // cred_r.cred.len = test_vectors[vec_num].cred_r_len;
48 // cred_r.cred.ptr = (uint8_t *)test_vectors[vec_num].cred_r;
49 // cred_r.g.len = test_vectors[vec_num].g_r_raw_len;
50 // cred_r.g.ptr = (uint8_t *)test_vectors[vec_num].g_r_raw;
51 // cred_r.pk.len = test_vectors[vec_num].pk_r_raw_len;
52 // cred_r.pk.ptr = (uint8_t *)test_vectors[vec_num].pk_r_raw;
53 // cred_r.ca.len = test_vectors[vec_num].ca_len;
54 // cred_r.ca.ptr = (uint8_t *)test_vectors[vec_num].ca;
55 // cred_r.ca_pk.len = test_vectors[vec_num].ca_pk_len;
56 // cred_r.ca_pk.ptr = (uint8_t *)test_vectors[vec_num].ca_pk;
57
58 // if (test_vectors[vec_num].c_i_raw != NULL) {
59 // c_i.c_i.type = BSTR;
60 // c_i.c_i.mem.c_x_bstr.len =
61 // test_vectors[vec_num].c_i_raw_len;
62 // c_i.c_i.mem.c_x_bstr.ptr =
63 // (uint8_t *)test_vectors[vec_num].c_i_raw;
64 // } else {
65 // c_i.c_i.type = INT;
66 // c_i.c_i.mem.c_x_int =
67 // *test_vectors[vec_num].c_i_raw_int;
68 // }
69 // c_i.msg4 = true;
70 // c_i.method = *test_vectors[vec_num].method;
71 // c_i.suites_i.len = test_vectors[vec_num].suites_i_len;
72 // c_i.suites_i.ptr = (uint8_t *)test_vectors[vec_num].suites_i;
73 // c_i.ead_1.len = test_vectors[vec_num].ead_1_len;
74 // c_i.ead_1.ptr = (uint8_t *)test_vectors[vec_num].ead_1;
75 // c_i.ead_3.len = test_vectors[vec_num].ead_3_len;
76 // c_i.ead_3.ptr = (uint8_t *)test_vectors[vec_num].ead_3;
77 // c_i.id_cred_i.len = test_vectors[vec_num].id_cred_i_len;
78 // c_i.id_cred_i.ptr = (uint8_t *)test_vectors[vec_num].id_cred_i;
79 // c_i.cred_i.len = test_vectors[vec_num].cred_i_len;
80 // c_i.cred_i.ptr = (uint8_t *)test_vectors[vec_num].cred_i;
81 // c_i.g_x.len = test_vectors[vec_num].g_x_raw_len;
82 // c_i.g_x.ptr = (uint8_t *)test_vectors[vec_num].g_x_raw;
83 // c_i.x.len = test_vectors[vec_num].x_raw_len;
84 // c_i.x.ptr = (uint8_t *)test_vectors[vec_num].x_raw;
85 // c_i.g_i.len = test_vectors[vec_num].g_i_raw_len;
86 // c_i.g_i.ptr = (uint8_t *)test_vectors[vec_num].g_i_raw;
87 // c_i.i.len = test_vectors[vec_num].i_raw_len;
88 // c_i.i.ptr = (uint8_t *)test_vectors[vec_num].i_raw;
89 // c_i.sk_i.len = test_vectors[vec_num].sk_i_raw_len;
90 // c_i.sk_i.ptr = (uint8_t *)test_vectors[vec_num].sk_i_raw;
91 // c_i.pk_i.len = test_vectors[vec_num].pk_i_raw_len;
92 // c_i.pk_i.ptr = (uint8_t *)test_vectors[vec_num].pk_i_raw;
93
94 // err = edhoc_initiator_run(&c_i, &cred_r, cred_num, err_msg,
95 // &err_msg_len, ad_2, &ad_2_len, ad_4,
96 // &ad_4_len, PRK_4x3m, sizeof(PRK_4x3m),
97 // th4, sizeof(th4), tx, rx);
98 // zassert_true(err == 0, "edhoc_initiator_run failed");
99
100 // } else {
101 // const uint16_t num_cred_i_elements = 1;
102 // struct other_party_cred cred_i;
103 // struct edhoc_responder_context c_r;
104
105 // rx_initiator_switch = false;
106 // cred_i.id_cred.len = test_vectors[vec_num].id_cred_i_len;
107 // cred_i.id_cred.ptr = (uint8_t *)test_vectors[vec_num].id_cred_i;
108 // cred_i.cred.len = test_vectors[vec_num].cred_i_len;
109 // cred_i.cred.ptr = (uint8_t *)test_vectors[vec_num].cred_i;
110 // cred_i.g.len = test_vectors[vec_num].g_i_raw_len;
111 // cred_i.g.ptr = (uint8_t *)test_vectors[vec_num].g_i_raw;
112 // cred_i.pk.len = test_vectors[vec_num].pk_i_raw_len;
113 // cred_i.pk.ptr = (uint8_t *)test_vectors[vec_num].pk_i_raw;
114 // cred_i.ca.len = test_vectors[vec_num].ca_len;
115 // cred_i.ca.ptr = (uint8_t *)test_vectors[vec_num].ca;
116 // cred_i.ca_pk.len = test_vectors[vec_num].ca_pk_len;
117 // cred_i.ca_pk.ptr = (uint8_t *)test_vectors[vec_num].ca_pk;
118
119 // if (test_vectors[vec_num].c_r_raw != NULL) {
120 // c_r.c_r.type = BSTR;
121 // c_r.c_r.mem.c_x_bstr.len =
122 // test_vectors[vec_num].c_r_raw_len;
123 // c_r.c_r.mem.c_x_bstr.ptr =
124 // (uint8_t *)test_vectors[vec_num].c_r_raw;
125 // } else {
126 // c_r.c_r.type = INT;
127 // c_r.c_r.mem.c_x_int =
128 // *test_vectors[vec_num].c_r_raw_int;
129 // }
130 // c_r.msg4 = true; /*we allways test message 4 */
131 // c_r.suites_r.len = test_vectors[vec_num].suites_r_len;
132 // c_r.suites_r.ptr = (uint8_t *)test_vectors[vec_num].suites_r;
133
134 // c_r.ead_2.len = test_vectors[vec_num].ead_2_len;
135 // c_r.ead_2.ptr = (uint8_t *)test_vectors[vec_num].ead_2;
136
137 // c_r.ead_4.len = test_vectors[vec_num].ead_4_len;
138 // c_r.ead_4.ptr = (uint8_t *)test_vectors[vec_num].ead_4;
139
140 // c_r.id_cred_r.len = test_vectors[vec_num].id_cred_r_len;
141 // c_r.id_cred_r.ptr = (uint8_t *)test_vectors[vec_num].id_cred_r;
142
143 // c_r.cred_r.len = test_vectors[vec_num].cred_r_len;
144 // c_r.cred_r.ptr = (uint8_t *)test_vectors[vec_num].cred_r;
145
146 // c_r.g_y.len = test_vectors[vec_num].g_y_raw_len;
147 // c_r.g_y.ptr = (uint8_t *)test_vectors[vec_num].g_y_raw;
148
149 // c_r.y.len = test_vectors[vec_num].y_raw_len;
150 // c_r.y.ptr = (uint8_t *)test_vectors[vec_num].y_raw;
151
152 // c_r.g_r.len = test_vectors[vec_num].g_r_raw_len;
153 // c_r.g_r.ptr = (uint8_t *)test_vectors[vec_num].g_r_raw;
154
155 // c_r.r.len = test_vectors[vec_num].r_raw_len;
156 // c_r.r.ptr = (uint8_t *)test_vectors[vec_num].r_raw;
157
158 // c_r.sk_r.len = test_vectors[vec_num].sk_r_raw_len;
159 // c_r.sk_r.ptr = (uint8_t *)test_vectors[vec_num].sk_r_raw;
160
161 // c_r.pk_r.len = test_vectors[vec_num].pk_r_raw_len;
162 // c_r.pk_r.ptr = (uint8_t *)test_vectors[vec_num].pk_r_raw;
163
164 // err = edhoc_responder_run(&c_r, &cred_i, num_cred_i_elements,
165 // err_msg, &err_msg_len,
166 // (uint8_t *)&ad_1, &ad_1_len,
167 // (uint8_t *)&ad_3, &ad_3_len, PRK_4x3m,
168 // sizeof(PRK_4x3m), th4, sizeof(th4),
169 // tx, rx);
170 // zassert_true(err == 0, "edhoc_responder_run failed");
171 // }
172
173 // // err = edhoc_exporter(SHA_256, PRK_4x3m, sizeof(PRK_4x3m), th4,
174 // // sizeof(th4), "OSCORE_Master_Secret",
175 // // oscore_master_secret, 16);
176
177 // // zassert_true(err == 0, "edhoc_exporter failed");
178
179 // // err = edhoc_exporter(SHA_256, PRK_4x3m, sizeof(PRK_4x3m), th4,
180 // // sizeof(th4), "OSCORE_Master_Salt",
181 // // oscore_master_salt, 8);
182
183 // // zassert_true(err == 0, "edhoc_exporter failed");
184
185 // /* check th4, PRK_4x3m, OSCORE Master secret and salt are correct */
186 // zassert_mem_equal__(&PRK_4x3m, test_vectors[vec_num].prk_4x3m_raw,
187 // sizeof(PRK_4x3m), "wrong PRK_4x3m");
188
189 // zassert_mem_equal__(&th4, test_vectors[vec_num].th_4_raw, sizeof(th4),
190 // "wrong TH4");
191
192 // zassert_mem_equal__(&oscore_master_secret,
193 // test_vectors[vec_num].oscore_secret_raw,
194 // sizeof(oscore_master_secret),
195 // "wrong OSCORE Master Secret");
196
197 // zassert_mem_equal__(&oscore_master_salt,
198 // test_vectors[vec_num].oscore_salt_raw,
199 // sizeof(oscore_master_salt),
200 // "wrong OSCORE Master Salt");
201 return 0;
202 }
203