pub struct ChaCha20Poly1305 { /* private fields */ }
chacha20poly1305
only.Expand description
OpenSSH variant of ChaCha20Poly1305: chacha20-poly1305@openssh.com
as described in PROTOCOL.chacha20poly1305.
Differences from ChaCha20Poly1305-IETF as described in RFC8439:
- Nonce is 64-bit instead of 96-bit (i.e. uses legacy “djb” ChaCha20 variant).
- The AAD and ciphertext inputs of Poly1305 are not padded.
- The lengths of ciphertext and AAD are not authenticated using Poly1305.
Implementations§
Source§impl ChaCha20Poly1305
impl ChaCha20Poly1305
Sourcepub fn encrypt(
&self,
nonce: &ChaChaNonce,
buffer: &mut [u8],
aad_len: usize,
) -> Result<Tag>
pub fn encrypt( &self, nonce: &ChaChaNonce, buffer: &mut [u8], aad_len: usize, ) -> Result<Tag>
Encrypt the provided buffer
in-place, returning the Poly1305 authentication tag.
The input buffer
should contain the concatenation of any additional associated data (AAD)
and the plaintext to be encrypted, where in the context of the SSH packet encryption
protocol the AAD represents an encrypted packet length, which is itself 4-bytes / 64-bits.
aad_len
is the length of the AAD in bytes:
- In the context of SSH packet encryption, this should be
4
. - In the context of SSH key encryption,
aad_len
should be0
.
The first aad_len
bytes of buffer
will be unmodified after encryption is completed.
Only the data after aad_len
will be encrypted.
The resulting Tag
authenticates both the AAD and the ciphertext in the buffer.
Sourcepub fn decrypt(
&self,
nonce: &ChaChaNonce,
buffer: &mut [u8],
tag: Tag,
aad_len: usize,
) -> Result<()>
pub fn decrypt( &self, nonce: &ChaChaNonce, buffer: &mut [u8], tag: Tag, aad_len: usize, ) -> Result<()>
Decrypt the provided buffer
in-place, verifying it against the provided Poly1305
authentication tag
.
The input buffer
should contain the concatenation of any additional associated data (AAD)
and the ciphertext to be authenticated, where in the context of the SSH packet encryption
protocol the AAD represents an encrypted packet length, which is itself 4-bytes / 64-bits.
aad_len
is the length of the AAD in bytes:
- In the context of SSH packet encryption, this should be
4
. - In the context of SSH key encryption,
aad_len
should be0
.
The first aad_len
bytes of buffer
will be unmodified after decryption completes
successfully. Only data after aad_len
will be decrypted.
Trait Implementations§
Source§impl AeadCore for ChaCha20Poly1305
impl AeadCore for ChaCha20Poly1305
Source§impl Clone for ChaCha20Poly1305
impl Clone for ChaCha20Poly1305
Source§fn clone(&self) -> ChaCha20Poly1305
fn clone(&self) -> ChaCha20Poly1305
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Drop for ChaCha20Poly1305
impl Drop for ChaCha20Poly1305
Source§impl KeyInit for ChaCha20Poly1305
impl KeyInit for ChaCha20Poly1305
Source§fn weak_key_test(_key: &Array<u8, Self::KeySize>) -> Result<(), WeakKeyError>
fn weak_key_test(_key: &Array<u8, Self::KeySize>) -> Result<(), WeakKeyError>
Source§fn new_checked(key: &Array<u8, Self::KeySize>) -> Result<Self, WeakKeyError>
fn new_checked(key: &Array<u8, Self::KeySize>) -> Result<Self, WeakKeyError>
Source§fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>
Source§impl KeySizeUser for ChaCha20Poly1305
impl KeySizeUser for ChaCha20Poly1305
impl ZeroizeOnDrop for ChaCha20Poly1305
zeroize
only.