aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/s2n/tls/s2n_kem_preferences.c
blob: 24ce8cb49e0d7c5615bc558c8c0022f1419132b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

#include "tls/s2n_kem_preferences.h"

/* Extension list for round 1 PQ KEMs, in order of preference */
const struct s2n_kem *pq_kems_r1[2] = {
    &s2n_bike1_l1_r1,
    &s2n_sike_p503_r1,
};

/* Extension list for round 2 and round 1 PQ KEMs, in order of preference.
 * s2n_sike_p434_r3 is compatible with, and has replaced, s2n_sike_p434_r2. */
const struct s2n_kem *pq_kems_r2r1[4] = {
    &s2n_bike1_l1_r2,
    &s2n_sike_p434_r3,
    &s2n_bike1_l1_r1,
    &s2n_sike_p503_r1,
};

/* s2n_sike_p434_r3 is compatible with, and has replaced, s2n_sike_p434_r2. */
const struct s2n_kem *pq_kems_r2r1_2020_07[5] = {
    &s2n_kyber_512_r2,
    &s2n_bike1_l1_r2,
    &s2n_sike_p434_r3,
    &s2n_bike1_l1_r1,
    &s2n_sike_p503_r1,
};

const struct s2n_kem *pq_kems_r3r2r1_2021_05[7] = {
    /* Round 3 Algorithms */
    &s2n_kyber_512_r3,
    &s2n_bike_l1_r3,

    /* Round 2 Algorithms */
    &s2n_kyber_512_r2,
    &s2n_bike1_l1_r2,
    &s2n_sike_p434_r3,

    /* Round 1 Algorithms */
    &s2n_bike1_l1_r1,
    &s2n_sike_p503_r1,
};

/* Extension list for SIKE P503 Round 1 only (for testing) */
const struct s2n_kem *pq_kems_sike_r1[1] = {
    &s2n_sike_p503_r1,
};

/* Extension list for SIKE P434 Round 2 and SIKE P503 Round 1 only (for testing),
 * in order of preference. s2n_sike_p434_r3 is compatible with, and has replaced,
 * s2n_sike_p434_r2. */
const struct s2n_kem *pq_kems_sike_r2r1[2] = {
    &s2n_sike_p434_r3,
    &s2n_sike_p503_r1,
};

/* sike_p434_r3 has replaced sike_p434_r2 in all KEM groups */
const struct s2n_kem_group *pq_kem_groups_r2[] = {
#if EVP_APIS_SUPPORTED
        &s2n_x25519_kyber_512_r2,
        &s2n_secp256r1_kyber_512_r2,
        &s2n_x25519_bike1_l1_r2,
        &s2n_secp256r1_bike1_l1_r2,
        &s2n_x25519_sike_p434_r3,
        &s2n_secp256r1_sike_p434_r3,
#else
        &s2n_secp256r1_kyber_512_r2,
        &s2n_secp256r1_bike1_l1_r2,
        &s2n_secp256r1_sike_p434_r3,
#endif
};


const struct s2n_kem_group *pq_kem_groups_r3r2[] = {
#if EVP_APIS_SUPPORTED
        &s2n_x25519_kyber_512_r3,
        &s2n_secp256r1_kyber_512_r3,
        &s2n_x25519_bike_l1_r3,
        &s2n_secp256r1_bike_l1_r3,
        &s2n_x25519_kyber_512_r2,
        &s2n_secp256r1_kyber_512_r2,
        &s2n_x25519_bike1_l1_r2,
        &s2n_secp256r1_bike1_l1_r2,
        &s2n_x25519_sike_p434_r3,
        &s2n_secp256r1_sike_p434_r3,
#else
        &s2n_secp256r1_kyber_512_r3,
        &s2n_secp256r1_bike_l1_r3,
        &s2n_secp256r1_kyber_512_r2,
        &s2n_secp256r1_bike1_l1_r2,
        &s2n_secp256r1_sike_p434_r3,
#endif
};

/* Includes only round 1 PQ KEM params */
const struct s2n_kem_preferences kem_preferences_kms_pq_tls_1_0_2019_06 = {
    .kem_count = s2n_array_len(pq_kems_r1),
    .kems = pq_kems_r1,
    .tls13_kem_group_count = 0,
    .tls13_kem_groups = NULL,
};

/* Includes round 1 and round 2 PQ KEM params. */
const struct s2n_kem_preferences kem_preferences_kms_pq_tls_1_0_2020_02 = {
    .kem_count = s2n_array_len(pq_kems_r2r1),
    .kems = pq_kems_r2r1,
    .tls13_kem_group_count = 0,
    .tls13_kem_groups = NULL,
};

const struct s2n_kem_preferences kem_preferences_kms_pq_tls_1_0_2020_07 = {
    .kem_count = s2n_array_len(pq_kems_r2r1_2020_07),
    .kems = pq_kems_r2r1_2020_07,
    .tls13_kem_group_count = 0,
    .tls13_kem_groups = NULL,
};

/* Includes only SIKE round 1 (for integration tests) */
const struct s2n_kem_preferences kem_preferences_pq_sike_test_tls_1_0_2019_11 = {
    .kem_count = s2n_array_len(pq_kems_sike_r1),
    .kems = pq_kems_sike_r1,
    .tls13_kem_group_count = 0,
    .tls13_kem_groups = NULL,
};

/* Includes only SIKE round 1 and round 2 (for integration tests). */
const struct s2n_kem_preferences kem_preferences_pq_sike_test_tls_1_0_2020_02 = {
    .kem_count = s2n_array_len(pq_kems_sike_r2r1),
    .kems = pq_kems_sike_r2r1,
    .tls13_kem_group_count = 0,
    .tls13_kem_groups = NULL,
};

const struct s2n_kem_preferences kem_preferences_pq_tls_1_0_2020_12 = {
    .kem_count = s2n_array_len(pq_kems_r2r1_2020_07),
    .kems = pq_kems_r2r1_2020_07,
    .tls13_kem_group_count = s2n_array_len(pq_kem_groups_r2),
    .tls13_kem_groups = pq_kem_groups_r2,
};

const struct s2n_kem_preferences kem_preferences_pq_tls_1_0_2021_05 = {
    .kem_count = s2n_array_len(pq_kems_r3r2r1_2021_05),
    .kems = pq_kems_r3r2r1_2021_05,
    .tls13_kem_group_count = s2n_array_len(pq_kem_groups_r3r2),
    .tls13_kem_groups = pq_kem_groups_r3r2,
};

const struct s2n_kem_preferences kem_preferences_null = {
    .kem_count = 0,
    .kems = NULL,
    .tls13_kem_group_count = 0,
    .tls13_kem_groups = NULL,
};

/* Determines if query_iana_id corresponds to a tls13_kem_group for these KEM preferences. */
bool s2n_kem_preferences_includes_tls13_kem_group(const struct s2n_kem_preferences *kem_preferences,
        uint16_t query_iana_id) {
    if (kem_preferences == NULL) {
        return false;
    }

    for (size_t i = 0; i < kem_preferences->tls13_kem_group_count; i++) {
        if (query_iana_id == kem_preferences->tls13_kem_groups[i]->iana_id) {
            return true;
        }
    }

    return false;
}