Skip to main content

Crate nivalis

Crate nivalis 

Source
Expand description

§nivalis

A typestate-driven, pure-Rust implementation of the Noise Protocol Framework (revision 34).

§Overview

Nivalis uses Rust’s type system to enforce the Noise handshake state machine at compile time, making it impossible to call handshake methods out of order or reuse a completed session.

§Quick start

The following example shows you how to create the builders for the IK pattern:

use nivalis::{
   builder::NewBuilder,
   crypto::{cipher::chacha20::ChaChaPoly, dh::{DH, DHKeypair, x25519::X25519dh}, hash::blake2s::Blake2s},
   patterns::{IK, roles::{Initiator, Responder}},
};
use rand::rng;

let mut rng = rng();
let init_static = X25519dh::generate_keypair(&mut rng);
let resp_static = X25519dh::generate_keypair(&mut rng);

let initiator = NewBuilder::<IK, Initiator, X25519dh, ChaChaPoly, Blake2s>::new()
       .local_static_key(init_static.private().to_owned())
       .remote_static_key(resp_static.public())
       .build()
       .expect("failed to build initiator handshake state");

let responder = NewBuilder::<IK, Responder, X25519dh, ChaChaPoly, Blake2s>::new()
       .local_static_key(resp_static.private().to_owned())
       .build()
       .expect("failed to build responder handshake state");
// ...

§Modules

  • builder — typestate builder for the Noise handshake
  • crypto — cryptographic primitives (AEAD, hashing, DH)
  • patterns — the standard Noise patterns (NN, XX, IK, etc.)
  • state — handshake/session state types
  • error / types — shared error and data types

Modules§

builder
Typestate builder for the Noise handshake
crypto
Cryptographic primitives used by the Noise handshake (AEAD ciphers, DH and hash functions)
error
Types used by other modules
patterns
Noise patterns presented on NoiseExplorer https://noiseexplorer.com/patterns/
state
The state objects driving the Noise handshake and transport phases: CipherState, SymmetricState, HandshakeState, and TransportState.
types
Types used by other modules