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 "edhoc/suites.h"
13 : :
14 : : #include "common/oscore_edhoc_error.h"
15 : :
16 : 6 : enum err get_suite(enum suite_label label, struct suite *suite)
17 : : {
18 [ + - + - : 6 : switch (label) {
- ]
19 : 2 : case SUITE_0:
20 : 2 : suite->suite_label = SUITE_0;
21 : 2 : suite->edhoc_aead = AES_CCM_16_64_128;
22 : 2 : suite->edhoc_hash = SHA_256;
23 : 2 : suite->edhoc_mac_len_static_dh = MAC8;
24 : 2 : suite->edhoc_ecdh = X25519;
25 : 2 : suite->edhoc_sign = EdDSA;
26 : 2 : suite->app_aead = AES_CCM_16_64_128;
27 : 2 : suite->app_hash = SHA_256;
28 : 2 : break;
29 : 0 : case SUITE_1:
30 : 0 : suite->suite_label = SUITE_1;
31 : 0 : suite->edhoc_aead = AES_CCM_16_128_128;
32 : 0 : suite->edhoc_hash = SHA_256;
33 : 0 : suite->edhoc_mac_len_static_dh = MAC16;
34 : 0 : suite->edhoc_ecdh = X25519;
35 : 0 : suite->edhoc_sign = EdDSA;
36 : 0 : suite->app_aead = AES_CCM_16_64_128;
37 : 0 : suite->app_hash = SHA_256;
38 : 0 : break;
39 : 4 : case SUITE_2:
40 : 4 : suite->suite_label = SUITE_2;
41 : 4 : suite->edhoc_aead = AES_CCM_16_64_128;
42 : 4 : suite->edhoc_hash = SHA_256;
43 : 4 : suite->edhoc_mac_len_static_dh = MAC8;
44 : 4 : suite->edhoc_ecdh = P256;
45 : 4 : suite->edhoc_sign = ES256;
46 : 4 : suite->app_aead = AES_CCM_16_64_128;
47 : 4 : suite->app_hash = SHA_256;
48 : 4 : break;
49 : 0 : case SUITE_3:
50 : 0 : suite->suite_label = SUITE_3;
51 : 0 : suite->edhoc_aead = AES_CCM_16_128_128;
52 : 0 : suite->edhoc_hash = SHA_256;
53 : 0 : suite->edhoc_mac_len_static_dh = MAC16;
54 : 0 : suite->edhoc_ecdh = P256;
55 : 0 : suite->edhoc_sign = ES256;
56 : 0 : suite->app_aead = AES_CCM_16_64_128;
57 : 0 : suite->app_hash = SHA_256;
58 : 0 : break;
59 : 0 : default:
60 : 0 : return unsupported_cipher_suite;
61 : : break;
62 : : }
63 : 6 : return ok;
64 : : }
65 : :
66 : 138 : uint32_t get_hash_len(enum hash_alg alg)
67 : : {
68 [ + - ]: 138 : switch (alg) {
69 : 138 : case SHA_256:
70 : 138 : return 32;
71 : : break;
72 : : }
73 : 0 : return 0;
74 : : }
75 : :
76 : 39 : uint32_t get_aead_mac_len(enum aead_alg alg)
77 : : {
78 [ - + - ]: 39 : switch (alg) {
79 : 0 : case AES_CCM_16_128_128:
80 : 0 : return 16;
81 : : break;
82 : 39 : case AES_CCM_16_64_128:
83 : 39 : return 8;
84 : : break;
85 : : }
86 : 0 : return 0;
87 : : }
88 : :
89 : 6 : uint32_t get_aead_key_len(enum aead_alg alg)
90 : : {
91 [ + - ]: 6 : switch (alg) {
92 : 6 : case AES_CCM_16_128_128:
93 : : case AES_CCM_16_64_128:
94 : 6 : return 16;
95 : : break;
96 : : }
97 : 0 : return 0;
98 : : }
99 : :
100 : 36 : uint32_t get_aead_iv_len(enum aead_alg alg)
101 : : {
102 [ + - ]: 36 : switch (alg) {
103 : 36 : case AES_CCM_16_128_128:
104 : : case AES_CCM_16_64_128:
105 : 36 : return 13;
106 : : break;
107 : : }
108 : 0 : return 0;
109 : : }
110 : :
111 : 21 : uint32_t get_signature_len(enum sign_alg alg)
112 : : {
113 [ + - ]: 21 : switch (alg) {
114 : 21 : case ES256:
115 : : case EdDSA:
116 : 21 : return 64;
117 : : break;
118 : : }
119 : 0 : return 0;
120 : : }
121 : :
122 : 9 : uint32_t get_ecdh_pk_len(enum ecdh_alg alg)
123 : : {
124 [ + + - ]: 9 : switch (alg) {
125 : 6 : case P256:
126 : : /*the x coordinate of the public key*/
127 : 6 : return 32;
128 : : break;
129 : 3 : case X25519:
130 : 3 : return 32;
131 : : break;
132 : : }
133 : 0 : return 0;
134 : : }
|