Skip to main content

Crate kevy_noise

Crate kevy_noise 

Source
Expand description

The Noise IK handshake (Noise_IK_25519_ChaChaPoly_BLAKE2s) and the transport it establishes, without I/O.

The initiator knows the responder’s static public key in advance; the responder learns the initiator’s static key from the first message and can decide there whether to accept it. One round trip, then each side holds a Transport. Messages travel length-prefixed (frame, Frames) on whatever stream the caller owns.

Ephemeral keys are passed in rather than drawn here, so the crate never touches an entropy source: every handshake needs a fresh one from the operating system.

use kevy_noise::{Initiator, Keypair, Responder};

let server = Keypair::from_secret([1; 32]);
let client = Keypair::from_secret([2; 32]);

let (m1, init) =
    Initiator::start(&client, &server.public(), Keypair::from_secret([3; 32]), b"kevy", b"")?;
let (_, resp) = Responder::accept(&server, Keypair::from_secret([4; 32]), b"kevy", &m1)?;
assert_eq!(resp.remote_static(), client.public());
let (m2, mut server_t) = resp.finish(b"")?;
let (_, mut client_t) = init.finish(&m2)?;

let msg = client_t.seal(b"SET k v")?;
assert_eq!(server_t.open(&msg)?, b"SET k v");

Structs§

Frames
Reassembles length-prefixed messages from a byte stream that arrives in arbitrary pieces.
Initiator
The initiator after sending the first message, waiting for the reply.
Keypair
An X25519 key pair.
Opener
The receiving half of a Transport, from Transport::split.
Responder
The responder after reading the first message, before replying.
Sealer
The sending half of a Transport, from Transport::split.
Transport
The two directions of an established session.

Enums§

Error
Why a handshake or transport message was refused.

Constants§

MAX_MESSAGE
The largest Noise message: 65,535 bytes, tag included.

Functions§

frame
Prefix msg with its length as two big-endian bytes.