Skip to main content

Kex

Trait Kex 

Source
pub trait Kex: Sized {
    type Hash: Digest;
    type Init: Decode<Error = Error> + Encode;
    type Reply: Decode<Error = Error> + Encode;
    type Secret: AsRef<[u8]> + Encode;
    type Error: Error;

    const NAME: &'static str;

    // Required methods
    fn start<R: CryptoRng + ?Sized>(
        rng: &mut R,
    ) -> Result<(Self, Self::Init), Self::Error>;
    fn respond<R: CryptoRng + ?Sized>(
        rng: &mut R,
        init: &Self::Init,
    ) -> Result<(Self::Reply, Self::Secret), Self::Error>;
    fn finish(self, reply: &Self::Reply) -> Result<Self::Secret, Self::Error>;
}
Expand description

An SSH key exchange with one client initiation and one server reply.

The method-specific fields must encode exactly as received. Implementations that accept multiple representations of a public key must retain the original encoding for the hash.

Implement this trait on the client’s ephemeral state. The server calls respond to generate its reply and shared secret in one step. The transport handles method negotiation, packet framing, and host authentication. DH group exchange (RFC 4419) requires additional negotiation and transcript fields.

Required Associated Constants§

Source

const NAME: &'static str

SSH method name to advertise in SSH_MSG_KEXINIT.

Required Associated Types§

Source

type Hash: Digest

Hash used for the exchange hash and SSH key derivation.

Source

type Init: Decode<Error = Error> + Encode

Client’s method-specific field, including its SSH wire framing.

Source

type Reply: Decode<Error = Error> + Encode

Server’s method-specific field, including its SSH wire framing.

Source

type Secret: AsRef<[u8]> + Encode

Shared secret K. AsRef borrows the raw bytes. Encode writes the method’s complete SSH representation for hashing and key derivation (e.g. string or mpint).

Source

type Error: Error

Error from key generation or peer key validation.

Required Methods§

Source

fn start<R: CryptoRng + ?Sized>( rng: &mut R, ) -> Result<(Self, Self::Init), Self::Error>

Generate a fresh client state and the public field to send.

§Errors

Returns a method-specific error if key generation fails.

Source

fn respond<R: CryptoRng + ?Sized>( rng: &mut R, init: &Self::Init, ) -> Result<(Self::Reply, Self::Secret), Self::Error>

Process the client’s public field and generate the server’s reply and shared secret.

§Errors

Returns a method-specific error if key generation or peer key validation fails.

Source

fn finish(self, reply: &Self::Reply) -> Result<Self::Secret, Self::Error>

Consume the client state and derive the shared secret from the server’s public field. The client authenticates the server by checking its host key and signature over H.

§Errors

Returns a method-specific error if key agreement fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Kex for MlKem768X25519

Available on crate feature mlkem768x25519-sha256 only.
Source§

const NAME: &'static str = "mlkem768x25519-sha256"

Source§

type Hash = Sha256

Source§

type Init = Init

Source§

type Reply = Reply

Source§

type Secret = Secret

Source§

type Error = Error