metalssh 0.0.1

Experimental SSH implementation
//! Symmetric-key cryptographic algorithms.

// Block sizes: https://github.com/openssh/openssh-portable/blob/master/cipher.c

use crate::types::Result;
use crate::wire::Packet;

pub mod aes128gcm;
pub mod aes256gcm;
pub mod chacha20poly1305;
pub mod none;

pub trait Cipher {
    const AEAD_LENGTH: Option<usize>;

    /// Encrypts an SSH packet in place.
    fn encrypt_packet<'buf, B>(
        &self,
        packet: &'buf mut Packet<&'buf mut B>,
        sequence_number: u32,
    ) -> Result<()>
    where
        B: AsRef<[u8]> + AsMut<[u8]> + ?Sized;

    /// Decrypts the packet length field of an SSH packet.
    ///
    /// This is for ciphers such as `chacha20-poly1305@openssh.com` that encrypt
    /// the packet length. Ciphers whose packet length field is not encrypted
    /// (such as `aes256-gcm@openssh.com`) should just return the packet length
    /// directly.
    fn decrypt_packet_length<B>(&self, packet: &Packet<B>, sequence_number: u32) -> Result<u32>
    where
        B: AsRef<[u8]>;

    /// Decrypts an SSH packet in place.
    fn decrypt_packet<'buf, B>(
        &self,
        packet: &'buf mut Packet<&'buf mut B>,
        sequence_number: u32,
    ) -> Result<()>
    where
        B: AsRef<[u8]> + AsMut<[u8]> + ?Sized;
}