Skip to content

Commit 553e6d0

Browse files
committed
Add parameter
1 parent 60be278 commit 553e6d0

7 files changed

Lines changed: 43 additions & 33 deletions

File tree

fuzz/fuzz_targets/client_initial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fuzz_target!(|data: &[u8]| {
1919
let Some((header, d_cid, s_cid, payload)) = decode_initial_header(&ci, Role::Client) else {
2020
return;
2121
};
22-
let (aead, hp) = initial_aead_and_hp(d_cid, Role::Client);
22+
let (aead, _, hp) = initial_aead_and_hp(d_cid, Role::Client);
2323
let (_, pn) = header_protection::remove(&hp, header, payload);
2424

2525
let mut payload_enc = Encoder::with_capacity(MIN_INITIAL_PACKET_SIZE);

fuzz/fuzz_targets/server_initial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fuzz_target!(|data: &[u8]| {
2525
let Some((header, d_cid, s_cid, payload)) = decode_initial_header(&si, Role::Server) else {
2626
return;
2727
};
28-
let (aead, hp) = initial_aead_and_hp(d_cid, Role::Server);
28+
let (aead, _, hp) = initial_aead_and_hp(d_cid, Role::Server);
2929
let (_, pn) = header_protection::remove(&hp, header, payload);
3030

3131
let mut payload_enc = Encoder::with_capacity(MIN_INITIAL_PACKET_SIZE);

neqo-transport/src/connection/tests/resumption.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ fn ticket_rtt(rtt: Duration) -> Duration {
108108
decode_initial_header(&server_initial, Role::Server).unwrap();
109109

110110
// Now decrypt the packet.
111-
let (aead, hp) = initial_aead_and_hp(&client_dcid, Role::Server);
111+
let (aead_enc, aead_dec, hp) = initial_aead_and_hp(&client_dcid, Role::Server);
112112
let (header, pn) = header_protection::remove(&hp, protected_header, payload);
113113
let pn_len = header.len() - protected_header.len();
114114
let mut buf = vec![0; payload.len()];
115-
let mut plaintext = aead
115+
let mut plaintext = aead_dec
116116
.decrypt(pn, &header, &payload[pn_len..], &mut buf)
117117
.unwrap()
118118
.to_owned();
@@ -130,7 +130,8 @@ fn ticket_rtt(rtt: Duration) -> Duration {
130130
// And rebuild a packet.
131131
let mut packet = header.clone();
132132
packet.resize(MIN_INITIAL_PACKET_SIZE, 0);
133-
aead.encrypt(pn, &header, &plaintext, &mut packet[header.len()..])
133+
aead_enc
134+
.encrypt(pn, &header, &plaintext, &mut packet[header.len()..])
134135
.unwrap();
135136
header_protection::apply(&hp, &mut packet, protected_header.len()..header.len());
136137
let si = Datagram::new(

neqo-transport/tests/connection.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ fn reorder_server_initial() {
109109
decode_initial_header(&server_initial, Role::Server).unwrap();
110110

111111
// Now decrypt the packet.
112-
let (aead, hp) = initial_aead_and_hp(&client_dcid, Role::Server);
112+
let (aead_enc, aead_dec, hp) = initial_aead_and_hp(&client_dcid, Role::Server);
113113
let (header, pn) = header_protection::remove(&hp, protected_header, payload);
114114
let pn_len = header.len() - protected_header.len();
115115
let mut buf = vec![0; payload.len()];
116-
let mut plaintext = aead
116+
let mut plaintext = aead_dec
117117
.decrypt(pn, &header, &payload[pn_len..], &mut buf)
118118
.unwrap()
119119
.to_owned();
@@ -132,7 +132,8 @@ fn reorder_server_initial() {
132132
// And rebuild a packet.
133133
let mut packet = header.clone();
134134
packet.resize(MIN_INITIAL_PACKET_SIZE, 0);
135-
aead.encrypt(pn, &header, &plaintext, &mut packet[header.len()..])
135+
aead_enc
136+
.encrypt(pn, &header, &plaintext, &mut packet[header.len()..])
136137
.unwrap();
137138
header_protection::apply(&hp, &mut packet, protected_header.len()..header.len());
138139
let reordered = Datagram::new(
@@ -165,7 +166,7 @@ fn set_payload(server_packet: Option<&Datagram>, client_dcid: &[u8], payload: &[
165166
decode_initial_header(&server_initial, Role::Server).unwrap();
166167

167168
// Now decrypt the packet.
168-
let (aead, hp) = initial_aead_and_hp(client_dcid, Role::Server);
169+
let (aead, _, hp) = initial_aead_and_hp(client_dcid, Role::Server);
169170
let (mut header, pn) = header_protection::remove(&hp, protected_header, orig_payload);
170171
// Re-encode the packet number as four bytes, so we have enough material for the header
171172
// protection sample if payload is empty.
@@ -253,7 +254,7 @@ fn overflow_crypto() {
253254

254255
// Now decrypt the server packet to get AEAD and HP instances.
255256
// We won't be using the packet, but making new ones.
256-
let (aead, hp) = initial_aead_and_hp(&client_dcid, Role::Server);
257+
let (aead, _, hp) = initial_aead_and_hp(&client_dcid, Role::Server);
257258
let (_, server_dcid, server_scid, _) =
258259
decode_initial_header(&server_initial, Role::Server).unwrap();
259260

@@ -346,7 +347,7 @@ fn client_initial_packet_number() {
346347
let client_initial = client.process_output(now());
347348
let (protected_header, client_dcid, _, payload) =
348349
decode_initial_header(client_initial.as_dgram_ref().unwrap(), Role::Client).unwrap();
349-
let (_, hp) = initial_aead_and_hp(client_dcid, Role::Client);
350+
let (_, _, hp) = initial_aead_and_hp(client_dcid, Role::Client);
350351
let (_, pn) = header_protection::remove(&hp, protected_header, payload);
351352
assert!(
352353
randomize && pn > 0 || !randomize && pn == 0,
@@ -377,7 +378,7 @@ fn server_initial_packet_number() {
377378
let (_protected_header, client_dcid, _scid, _payload) =
378379
decode_initial_header(client_initial.as_ref().unwrap(), Role::Client).unwrap();
379380

380-
let (_, hp) = initial_aead_and_hp(client_dcid, Role::Server);
381+
let (_, _, hp) = initial_aead_and_hp(client_dcid, Role::Server);
381382

382383
let server_initial = server.process(client_initial, now()).dgram();
383384
let (protected_header, _dcid, _scid, payload) =

neqo-transport/tests/retry.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,13 @@ fn mitm_retry() {
462462
decode_initial_header(&client_initial2, Role::Client).unwrap();
463463

464464
// Now we have enough information to make keys.
465-
let (aead, hp) = initial_aead_and_hp(d_cid, Role::Client);
465+
let (aead_enc, aead_dec, hp) = initial_aead_and_hp(d_cid, Role::Client);
466466
let (header, pn) = header_protection::remove(&hp, protected_header, payload);
467467
let pn_len = header.len() - protected_header.len();
468468

469469
// Decrypt.
470470
let mut plaintext_buf = vec![0; client_initial2.len()];
471-
let plaintext = aead
471+
let plaintext = aead_dec
472472
.decrypt(pn, &header, &payload[pn_len..], &mut plaintext_buf)
473473
.unwrap();
474474

@@ -489,13 +489,14 @@ fn mitm_retry() {
489489
.as_ref()
490490
.to_vec();
491491
notoken_packet.resize_with(MIN_INITIAL_PACKET_SIZE, u8::default);
492-
aead.encrypt(
493-
pn,
494-
&notoken_header,
495-
plaintext,
496-
&mut notoken_packet[notoken_header.len()..],
497-
)
498-
.unwrap();
492+
aead_enc
493+
.encrypt(
494+
pn,
495+
&notoken_header,
496+
plaintext,
497+
&mut notoken_packet[notoken_header.len()..],
498+
)
499+
.unwrap();
499500
// Unlike with decryption, don't truncate.
500501
// All MIN_INITIAL_PACKET_SIZE bytes are needed to reach the minimum datagram size.
501502

@@ -545,7 +546,7 @@ fn retry_short_dcid() {
545546
let short_dcid = &[0x01, 0x02, 0x03, 0x04];
546547

547548
// Decrypt with the original DCID.
548-
let (aead_orig, hp_orig) = initial_aead_and_hp(d_cid, Role::Client);
549+
let (_, aead_orig, hp_orig) = initial_aead_and_hp(d_cid, Role::Client);
549550
let (header, pn) = header_protection::remove(&hp_orig, protected_header, payload);
550551
let pn_len = header.len() - protected_header.len();
551552

@@ -565,7 +566,7 @@ fn retry_short_dcid() {
565566
let short_dcid_header = enc.encode_uint(pn_len, pn).as_ref().to_vec();
566567

567568
// Encrypt with keys derived from short DCID.
568-
let (aead_short, hp_short) = initial_aead_and_hp(short_dcid, Role::Client);
569+
let (aead_short, _, hp_short) = initial_aead_and_hp(short_dcid, Role::Client);
569570
let mut short_dcid_packet = Encoder::with_capacity(MIN_INITIAL_PACKET_SIZE)
570571
.encode(&short_dcid_header)
571572
.as_ref()

neqo-transport/tests/server.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,12 @@ fn bad_client_initial() {
439439

440440
let dgram = client.process_output(now()).dgram().expect("a datagram");
441441
let (header, d_cid, s_cid, payload) = decode_initial_header(&dgram, Role::Client).unwrap();
442-
let (aead, hp) = initial_aead_and_hp(d_cid, Role::Client);
442+
let (aead_enc, aead_dec, hp) = initial_aead_and_hp(d_cid, Role::Client);
443443
let (fixed_header, pn) = header_protection::remove(&hp, header, payload);
444444
let payload = &payload[(fixed_header.len() - header.len())..];
445445

446446
let mut plaintext_buf = vec![0; dgram.len()];
447-
let plaintext = aead
447+
let plaintext = aead_dec
448448
.decrypt(pn, &fixed_header, payload, &mut plaintext_buf)
449449
.unwrap();
450450

@@ -459,13 +459,16 @@ fn bad_client_initial() {
459459
.encode_vec(1, d_cid)
460460
.encode_vec(1, s_cid)
461461
.encode_vvec(&[])
462-
.encode_varint(u64::try_from(payload_enc.len() + aead.expansion() + PN_LEN).unwrap())
462+
.encode_varint(u64::try_from(payload_enc.len() + aead_enc.expansion() + PN_LEN).unwrap())
463463
.encode_byte(u8::try_from(pn >> 8).unwrap())
464464
.encode_byte(u8::try_from(pn & 0xff).unwrap());
465465

466466
let mut ciphertext = header_enc.as_ref().to_vec();
467-
ciphertext.resize(header_enc.len() + payload_enc.len() + aead.expansion(), 0);
468-
let v = aead
467+
ciphertext.resize(
468+
header_enc.len() + payload_enc.len() + aead_enc.expansion(),
469+
0,
470+
);
471+
let v = aead_enc
469472
.encrypt(
470473
pn,
471474
header_enc.as_ref(),
@@ -537,7 +540,7 @@ fn bad_client_initial_connection_close() {
537540

538541
let dgram = client.process_output(now()).dgram().expect("a datagram");
539542
let (header, d_cid, s_cid, payload) = decode_initial_header(&dgram, Role::Client).unwrap();
540-
let (aead, hp) = initial_aead_and_hp(d_cid, Role::Client);
543+
let (aead, _, hp) = initial_aead_and_hp(d_cid, Role::Client);
541544
let (_, pn) = header_protection::remove(&hp, header, payload);
542545

543546
let mut payload_enc = Encoder::with_capacity(MIN_INITIAL_PACKET_SIZE);

test-fixture/src/header_protection.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn decode_initial_header(dgram: &Datagram, role: Role) -> Option<(&[u8], &[u
6464
/// Generate an AEAD and header protection object for a client Initial.
6565
/// Note that this works for QUIC version 1 only.
6666
#[must_use]
67-
pub fn initial_aead_and_hp(dcid: &[u8], role: Role) -> (Aead, hp::Key) {
67+
pub fn initial_aead_and_hp(dcid: &[u8], role: Role) -> (Aead, Aead, hp::Key) {
6868
const INITIAL_SALT: &[u8] = &[
6969
0x38, 0x76, 0x2c, 0xf7, 0xf5, 0x59, 0x34, 0xb3, 0x4d, 0x17, 0x9a, 0xe6, 0xa4, 0xc8, 0x0c,
7070
0xad, 0xcc, 0xbb, 0x7f, 0x0a,
@@ -92,15 +92,19 @@ pub fn initial_aead_and_hp(dcid: &[u8], role: Role) -> (Aead, hp::Key) {
9292
},
9393
)
9494
.unwrap();
95-
(
95+
let make = |mode| {
9696
Aead::new(
9797
TLS_VERSION_1_3,
9898
TLS_AES_128_GCM_SHA256,
9999
&secret,
100100
"quic ",
101-
Mode::Encrypt,
101+
mode,
102102
)
103-
.unwrap(),
103+
.unwrap()
104+
};
105+
(
106+
make(Mode::Encrypt),
107+
make(Mode::Decrypt),
104108
hp::Key::extract(TLS_VERSION_1_3, TLS_AES_128_GCM_SHA256, &secret, "quic hp").unwrap(),
105109
)
106110
}

0 commit comments

Comments
 (0)