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 #ifndef SUITES_H
12 #define SUITES_H
13 
14 #include <stdint.h>
15 
16 #include "common/oscore_edhoc_error.h"
17 
18 /*see https://www.iana.org/assignments/cose/cose.xhtml#algorithms for algorithm number reference*/
19 
20 enum suite_label {
21 	SUITE_0 = 0,
22 	SUITE_1 = 1,
23 	SUITE_2 = 2,
24 	SUITE_3 = 3,
25 };
26 
27 enum aead_alg {
28 	AES_CCM_16_64_128 = 10,
29 	AES_CCM_16_128_128 = 30,
30 };
31 
32 enum hash_alg { SHA_256 = -16 };
33 
34 enum ecdh_alg {
35 	P256 = 1,
36 	X25519 = 4,
37 };
38 
39 enum sign_alg {
40 	ES256 = -7,
41 	EdDSA = -8,
42 };
43 
44 enum mac_len {
45 	MAC8 = 8,
46 	MAC16 = 16,
47 };
48 
49 struct suite {
50 	enum suite_label suite_label;
51 	enum aead_alg edhoc_aead;
52 	enum hash_alg edhoc_hash;
53 	enum mac_len edhoc_mac_len_static_dh;
54 	enum ecdh_alg edhoc_ecdh;
55 	enum sign_alg edhoc_sign;
56 	enum aead_alg app_aead;
57 	enum hash_alg app_hash;
58 };
59 
60 /**
61  * @brief   			Retrieves the algorithms corrsponding to a
62  * 				given suite label.
63  *
64  * @param label 		The label of the suite.
65  * @param suite 		The algorithms corrsponding to label.
66  * @retval			Ok or error.
67  */
68 enum err get_suite(enum suite_label label, struct suite *suite);
69 
70 /**
71  * @brief 			Gets the length of the hash.
72  *
73  * @param alg 			The used hash algorithm.
74  * @retval			The length.
75  */
76 uint32_t get_hash_len(enum hash_alg alg);
77 
78 /**
79  * @brief 			Gets the length of the MAC.
80  *
81  * @param alg 			The used AEAD algorithm.
82  * @retval 			The length.
83  */
84 uint32_t get_aead_mac_len(enum aead_alg alg);
85 
86 /**
87  * @brief 			Gets the length of KEY.
88  *
89  * @param alg 			The used AEAD algorithm.
90  * @retval 			The length.
91  */
92 uint32_t get_aead_key_len(enum aead_alg alg);
93 
94 /**
95  * @brief 			Gets the length of IV.
96  *
97  * @param alg 			The used AEAD algorithm.
98  * @retval 			The length.
99  */
100 uint32_t get_aead_iv_len(enum aead_alg alg);
101 
102 /**
103  * @brief 			Gets the length of the signature.
104  *
105  * @param alg 			The used signature algorithm.
106  * @retval			The length.
107  */
108 uint32_t get_signature_len(enum sign_alg alg);
109 
110 /**
111  * @brief 			Gets the length of the ECDH public key.
112  *
113  * @param alg 			The used ECDH algorithm.
114  * @retval 			The length.
115  */
116 uint32_t get_ecdh_pk_len(enum ecdh_alg alg);
117 
118 #endif
119