Skip to content

Commit 0264c11

Browse files
committed
Test against the HPKE PQ test vectors
1 parent 0a2df86 commit 0264c11

File tree

6 files changed

+2215
-2
lines changed

6 files changed

+2215
-2
lines changed

lib/hpke/scripts/go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module main
22

3-
go 1.16
3+
go 1.23.0
4+
5+
toolchain go1.24.10
46

57
require (
68
github.com/cisco/go-tls-syntax v0.0.0-20200617162716-46b0cfb76b9b

lib/hpke/test/common.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,40 @@ supported_kem(KEM::ID id)
114114
}
115115
}
116116

117+
bool
118+
supported_kdf(KDF::ID id)
119+
{
120+
switch (id) {
121+
case KDF::ID::HKDF_SHA256:
122+
case KDF::ID::HKDF_SHA384:
123+
case KDF::ID::HKDF_SHA512:
124+
return true;
125+
126+
default:
127+
return false;
128+
}
129+
}
130+
131+
bool
132+
supported_aead(AEAD::ID id)
133+
{
134+
switch (id) {
135+
case AEAD::ID::AES_128_GCM:
136+
case AEAD::ID::AES_256_GCM:
137+
case AEAD::ID::CHACHA20_POLY1305:
138+
case AEAD::ID::export_only:
139+
return true;
140+
141+
default:
142+
return false;
143+
}
144+
}
145+
146+
bool
147+
supported(KEM::ID kem, KDF::ID kdf, AEAD::ID aead) {
148+
return supported_kem(kem) && supported_kdf(kdf) && supported_aead(aead);
149+
}
150+
117151
const KEM&
118152
select_kem(KEM::ID id)
119153
{

lib/hpke/test/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ select_signature(Signature::ID id);
2121
bool
2222
supported_kem(KEM::ID id);
2323

24+
bool
25+
supported_kdf(KDF::ID id);
26+
27+
bool
28+
supported_aead(AEAD::ID id);
29+
30+
bool
31+
supported(KEM::ID kem, KDF::ID kdf, AEAD::ID aead);
32+
2433
const KEM&
2534
select_kem(KEM::ID id);
2635

lib/hpke/test/hpke.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test_context(ReceiverContext& ctxR, const HPKETestVector& tv)
4545
static void
4646
test_base_vector(const HPKETestVector& tv)
4747
{
48-
if (!supported_kem(tv.kem_id)) {
48+
if (!supported(tv.kem_id, tv.kdf_id, tv.aead_id)) {
4949
return;
5050
}
5151

@@ -180,6 +180,34 @@ TEST_CASE("HPKE Test Vectors")
180180
}
181181
}
182182

183+
TEST_CASE("HPKE PQ Test Vectors")
184+
{
185+
ensure_fips_if_required();
186+
187+
auto test_vector_bytes = bytes(test_vector_data_pq);
188+
auto test_vectors =
189+
MLS_NAMESPACE::tls::get<HPKETestVectors>(test_vector_bytes);
190+
191+
for (const auto& tv : test_vectors.vectors) {
192+
if (fips() && fips_disable(tv.aead_id)) {
193+
continue;
194+
}
195+
196+
switch (tv.mode) {
197+
case HPKE::Mode::base:
198+
test_base_vector(tv);
199+
break;
200+
201+
case HPKE::Mode::psk:
202+
test_psk_vector(tv);
203+
break;
204+
205+
default:
206+
REQUIRE(false);
207+
}
208+
}
209+
}
210+
183211
TEST_CASE("HPKE Round-Trip")
184212
{
185213
ensure_fips_if_required();

lib/hpke/test/test_vectors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,4 @@ struct HPKETestVectors
8787
};
8888

8989
extern const std::array<uint8_t, 2555172> test_vector_data;
90+
extern const std::array<uint8_t, 34137> test_vector_data_pq;

0 commit comments

Comments
 (0)