Skip to content

Commit 63e6c1d

Browse files
authored
ssh-cipher: improve Cipher docs (#529)
1 parent 956a519 commit 63e6c1d

2 files changed

Lines changed: 47 additions & 14 deletions

File tree

ssh-cipher/src/chacha20poly1305.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub type ChaChaKey = chacha20::Key;
2222
/// Nonce for `chacha20-poly1305@openssh.com`.
2323
pub type ChaChaNonce = chacha20::LegacyNonce;
2424

25-
/// OpenSSH variant of ChaCha20Poly1305: `chacha20-poly1305@openssh.com`
26-
/// as described in [PROTOCOL.chacha20poly1305].
25+
/// OpenSSH variant of ChaCha20Poly1305: `chacha20-poly1305@openssh.com` as described in
26+
/// [PROTOCOL.chacha20poly1305].
2727
///
2828
/// Differences from ChaCha20Poly1305-IETF as described in [RFC8439]:
2929
/// - Nonce is 64-bit instead of 96-bit (i.e. uses legacy "djb" ChaCha20 variant).
@@ -35,7 +35,7 @@ pub type ChaChaNonce = chacha20::LegacyNonce;
3535
/// - In the context of SSH packet encryption, AAD will be 4 bytes and contain the encrypted length.
3636
/// - In the context of SSH key encryption, AAD will be empty.
3737
///
38-
/// [PROTOCOL.chacha20poly1305]: https://cvsweb.openbsd.org/src/usr.bin/ssh/PROTOCOL.chacha20poly1305?annotate=HEAD
38+
/// [PROTOCOL.chacha20poly1305]: https://web.mit.edu/freebsd/head/crypto/openssh/PROTOCOL.chacha20poly1305
3939
/// [RFC8439]: https://datatracker.ietf.org/doc/html/rfc8439
4040
#[derive(Clone)]
4141
pub struct ChaCha20Poly1305 {

ssh-cipher/src/lib.rs

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,40 +78,73 @@ pub type AesGcmNonce = Array<u8, U12>;
7878
pub type Tag = Array<u8, U16>;
7979

8080
/// Cipher algorithms.
81+
///
82+
/// A "cipher" within the context of SSH was originally described in [RFC4253 § 6.3] in the context
83+
/// of the packet encryption protocol, where it refers to the combination of a symmetric block
84+
/// cipher, such as AES or 3DES, with a particular mode of operation, such as CBC or CTR.
85+
///
86+
/// This has been subsequently expanded by other standards documents, and now includes modern
87+
/// authenticated or "AEAD" modes such as AES-GCM and ChaCha20Poly1305, which we recommend and are
88+
/// marked with a ✅ in the table below.
89+
///
90+
/// Below is a table of the ciphers we support and what standards document defines them, along with
91+
/// which crate feature needs to be enabled to perform encryption with a given algorithm:
92+
///
93+
/// | Cipher name | Feature | AEAD | Algorithm | Standard
94+
/// |---------------------------------|---------|------|-------------|---------
95+
/// | `3des-cbc` | `tdes` | ⛔ | 3DES-CBC | [RFC4253 § 6.3]
96+
/// | `aes128‑cbc` | `aes` | ⛔ | AES-128-CBC | [RFC4253 § 6.3]
97+
/// | `aes192‑cbc` | `aes` | ⛔ | AES-192-CBC | [RFC4253 § 6.3]
98+
/// | `aes256‑cbc` | `aes` | ⛔ | AES-256-CBC | [RFC4253 § 6.3]
99+
/// | `aes128‑ctr` | `aes` | ⛔ | AES-128-CTR | [RFC4344]
100+
/// | `aes192‑ctr` | `aes` | ⛔ | AES-192-CTR | [RFC4344]
101+
/// | `aes256‑ctr` | `aes` | ⛔ | AES-256-CTR | [RFC4344]
102+
/// | `aes128‑gcm@openssh.com` | `aes` | ✅ | AES-128-GCM | [RFC5647]
103+
/// | `aes256‑gcm@openssh.com` | `aes` | ✅ | AES-256-GCM | [RFC5647]
104+
/// | `chacha20‑poly1305@openssh.com` | `chacha20poly1305` | ✅ | ChaCha20Poly1305† | [PROTOCOL.chacha20poly1305]
105+
///
106+
/// † The construction called "ChaCha20Poly1305" as used by OpenSSH is different from other
107+
/// constructions with that name including the one defined in RFC8439 and the one found in NaCl
108+
/// variants like libsodium. See [`ChaCha20Poly1305`] for more information.
109+
///
110+
/// [RFC4253 § 6.3]: https://datatracker.ietf.org/doc/html/rfc4253#section-6.3
111+
/// [RFC4344]: https://datatracker.ietf.org/doc/html/rfc4344
112+
/// [RFC5647]: https://datatracker.ietf.org/doc/html/rfc5647
113+
/// [PROTOCOL.chacha20poly1305]: https://web.mit.edu/freebsd/head/crypto/openssh/PROTOCOL.chacha20poly1305
81114
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
82115
#[non_exhaustive]
83116
pub enum Cipher {
84-
/// No cipher.
117+
/// `none`: no cipher.
85118
None,
86119

87-
/// AES-128 in cipher block chaining (CBC) mode.
120+
/// `aes128-cbc`: AES-128 in cipher block chaining (CBC) mode.
88121
Aes128Cbc,
89122

90-
/// AES-192 in cipher block chaining (CBC) mode.
123+
/// `aes192-cbc`: AES-192 in cipher block chaining (CBC) mode.
91124
Aes192Cbc,
92125

93-
/// AES-256 in cipher block chaining (CBC) mode.
126+
/// `aes256-cbc`: AES-256 in cipher block chaining (CBC) mode.
94127
Aes256Cbc,
95128

96-
/// AES-128 in counter (CTR) mode.
129+
/// `aes128-ctr`: AES-128 in counter (CTR) mode.
97130
Aes128Ctr,
98131

99-
/// AES-192 in counter (CTR) mode.
132+
/// `aes192-ctr`: AES-192 in counter (CTR) mode.
100133
Aes192Ctr,
101134

102-
/// AES-256 in counter (CTR) mode.
135+
/// `aes256-ctr`: AES-256 in counter (CTR) mode.
103136
Aes256Ctr,
104137

105-
/// AES-128 in Galois/Counter Mode (GCM).
138+
/// `aes128-gcm@openssh.com`: AES-128 in Galois/Counter Mode (GCM).
106139
Aes128Gcm,
107140

108-
/// AES-256 in Galois/Counter Mode (GCM).
141+
/// `aes256-gcm@openssh.com`: AES-256 in Galois/Counter Mode (GCM).
109142
Aes256Gcm,
110143

111-
/// ChaCha20-Poly1305
144+
/// `chacha20-poly1305@openssh.com`: ChaCha20-Poly1305
112145
ChaCha20Poly1305,
113146

114-
/// TripleDES in block chaining (CBC) mode
147+
/// `3des-cbc`: TripleDES in block chaining (CBC) mode
115148
TDesCbc,
116149
}
117150

0 commit comments

Comments
 (0)