Skip to content

Commit 1ff3a9c

Browse files
authored
chore: import 8/29 version (#2311)
1 parent b6ca57b commit 1ff3a9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2322
-1587
lines changed

dc/s2n-quic-dc/src/crypto.rs

+96-30
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::credentials::Credentials;
54
pub use bytes::buf::UninitSlice;
65
use core::fmt;
76
pub use s2n_quic_core::packet::KeyPhase;
87

98
pub mod awslc;
10-
#[cfg(any(test, feature = "testing"))]
11-
pub mod testing;
129

13-
pub mod encrypt {
10+
pub mod seal {
1411
use super::*;
1512

16-
pub trait Key {
17-
fn credentials(&self) -> &Credentials;
18-
13+
pub trait Application {
1914
fn key_phase(&self) -> KeyPhase;
2015

2116
fn tag_len(&self) -> usize;
2217

2318
/// Encrypt a payload
24-
fn encrypt<N: IntoNonce>(
19+
fn encrypt(
2520
&self,
26-
nonce: N,
21+
packet_number: u64,
2722
header: &[u8],
2823
extra_payload: Option<&[u8]>,
2924
payload_and_tag: &mut [u8],
3025
);
26+
}
3127

32-
fn retransmission_tag(
33-
&self,
34-
original_packet_number: u64,
35-
retransmission_packet_number: u64,
36-
tag_out: &mut [u8],
37-
);
28+
pub trait Control {
29+
fn tag_len(&self) -> usize;
30+
31+
fn sign(&self, header: &[u8], tag: &mut [u8]);
32+
}
33+
34+
pub mod control {
35+
use super::*;
36+
37+
/// Marker trait for keys to be used with stream control packets
38+
pub trait Stream: Control {
39+
fn retransmission_tag(
40+
&self,
41+
original_packet_number: u64,
42+
retransmission_packet_number: u64,
43+
tag_out: &mut [u8],
44+
);
45+
}
46+
47+
/// Marker trait for keys to be used with secret control packets
48+
pub trait Secret: Control {}
3849
}
3950
}
4051

41-
pub mod decrypt {
52+
pub mod open {
4253
use super::*;
4354

4455
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
@@ -47,6 +58,10 @@ pub mod decrypt {
4758
ReplayPotentiallyDetected { gap: Option<u64> },
4859
ReplayDefinitelyDetected,
4960
InvalidTag,
61+
SingleUseKey,
62+
UnsupportedOperation,
63+
MacOnly,
64+
RotationNotSupported,
5065
}
5166

5267
impl fmt::Display for Error {
@@ -61,6 +76,12 @@ pub mod decrypt {
6176
write!(f, "key replay potentially detected: unknown gap")
6277
}
6378
Self::InvalidTag => "invalid tag".fmt(f),
79+
Self::SingleUseKey => "this key can only be used once".fmt(f),
80+
Self::UnsupportedOperation => {
81+
"this key cannot be used with the given operation".fmt(f)
82+
}
83+
Self::MacOnly => "this key is only capable of generating MACs".fmt(f),
84+
Self::RotationNotSupported => "this key does not support key rotation".fmt(f),
6485
}
6586
}
6687
}
@@ -69,38 +90,83 @@ pub mod decrypt {
6990

7091
pub type Result<T = (), E = Error> = core::result::Result<T, E>;
7192

72-
pub trait Key {
73-
fn credentials(&self) -> &Credentials;
74-
93+
pub trait Application {
7594
fn tag_len(&self) -> usize;
7695

7796
/// Decrypt a payload
78-
fn decrypt<N: IntoNonce>(
97+
fn decrypt(
7998
&self,
8099
key_phase: KeyPhase,
81-
nonce: N,
100+
packet_number: u64,
82101
header: &[u8],
83102
payload_in: &[u8],
84103
tag: &[u8],
85104
payload_out: &mut UninitSlice,
86105
) -> Result;
87106

88107
/// Decrypt a payload
89-
fn decrypt_in_place<N: IntoNonce>(
108+
fn decrypt_in_place(
90109
&self,
91110
key_phase: KeyPhase,
92-
nonce: N,
111+
packet_number: u64,
93112
header: &[u8],
94113
payload_and_tag: &mut [u8],
95114
) -> Result;
115+
}
96116

97-
fn retransmission_tag(
98-
&self,
99-
key_phase: KeyPhase,
100-
original_packet_number: u64,
101-
retransmission_packet_number: u64,
102-
tag_out: &mut [u8],
103-
);
117+
pub trait Control {
118+
fn tag_len(&self) -> usize;
119+
120+
fn verify(&self, header: &[u8], tag: &[u8]) -> Result;
121+
}
122+
123+
pub mod control {
124+
use super::*;
125+
126+
/// Marker trait for keys to be used with stream control packets
127+
pub trait Stream: Control {
128+
fn retransmission_tag(
129+
&self,
130+
original_packet_number: u64,
131+
retransmission_packet_number: u64,
132+
tag_out: &mut [u8],
133+
) -> Result;
134+
}
135+
136+
pub mod stream {
137+
/// A no-op implementation for reliable transports
138+
#[derive(Clone, Default)]
139+
pub struct Reliable(());
140+
141+
impl super::Control for Reliable {
142+
#[inline]
143+
fn tag_len(&self) -> usize {
144+
16
145+
}
146+
147+
#[inline]
148+
fn verify(&self, _header: &[u8], _tag: &[u8]) -> super::Result {
149+
// this method should not be used on reliable transports
150+
Err(super::Error::UnsupportedOperation)
151+
}
152+
}
153+
154+
impl super::Stream for Reliable {
155+
#[inline]
156+
fn retransmission_tag(
157+
&self,
158+
_original_packet_number: u64,
159+
_retransmission_packet_number: u64,
160+
_tag_out: &mut [u8],
161+
) -> super::Result {
162+
// this method should not be used on reliable transports
163+
Err(super::Error::UnsupportedOperation)
164+
}
165+
}
166+
}
167+
168+
/// Marker trait for keys to be used with secret control packets
169+
pub trait Secret: Control {}
104170
}
105171
}
106172

0 commit comments

Comments
 (0)