Branch data Line data Source code
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 "oscore.h"
13 : :
14 : : #include "oscore/aad.h"
15 : : #include "oscore/option.h"
16 : :
17 : : #include "common/print_util.h"
18 : : #include "common/oscore_edhoc_error.h"
19 : : #include "common/memcpy_s.h"
20 : :
21 : : #include "cbor/oscore_aad_array.h"
22 : :
23 : 28 : enum err create_aad(struct o_coap_option *options, uint16_t opt_num,
24 : : enum AEAD_algorithm aead_alg, struct byte_array *kid,
25 : : struct byte_array *piv, struct byte_array *out)
26 : : {
27 : : struct aad_array aad_array;
28 : :
29 : 28 : aad_array.aad_array_oscore_version = 1;
30 : 28 : aad_array.aad_array_algorithms_alg_aead_choice =
31 : : aad_array_algorithms_alg_aead_int_c;
32 : 28 : aad_array.aad_array_algorithms_alg_aead_int = (int32_t)aead_alg;
33 : 28 : aad_array.aad_array_request_kid.value = kid->ptr;
34 : 28 : aad_array.aad_array_request_kid.len = kid->len;
35 : 28 : aad_array.aad_array_request_piv.value = piv->ptr;
36 : 28 : aad_array.aad_array_request_piv.len = piv->len;
37 : :
38 : 28 : PRINT_ARRAY("request_piv", piv->ptr, piv->len);
39 : 28 : PRINT_ARRAY("request_kid", kid->ptr, kid->len);
40 : :
41 : : /*
42 : : * Currently there are no I options defined.
43 : : * If at some later time I options are defined this implementation
44 : : * must be extended here.
45 : : */
46 : 28 : aad_array.aad_array_options.len = 0;
47 : 28 : aad_array.aad_array_options.value = NULL;
48 : :
49 : : size_t payload_len_out;
50 [ - + ]: 28 : TRY_EXPECT(cbor_encode_aad_array(out->ptr, out->len, &aad_array,
51 : : &payload_len_out),
52 : : 0);
53 : :
54 : 28 : out->len = (uint32_t)payload_len_out;
55 : 28 : PRINT_ARRAY("AAD", out->ptr, out->len);
56 : 28 : return ok;
57 : : }
|