Skip to main content

wacore_noise/
lib.rs

1//! Noise Protocol implementation for WhatsApp with AES-256-GCM.
2//!
3//! This crate provides both a generic Noise Protocol XX state machine and
4//! WhatsApp-specific handshake utilities.
5//!
6//! # Structure
7//!
8//! - `NoiseState` - Generic Noise XX protocol state machine
9//! - `NoiseHandshake` - WhatsApp-specific wrapper with libsignal DH
10//! - `HandshakeUtils` - WhatsApp protocol message building/parsing
11//!
12//! # Example (Generic)
13//!
14//! ```ignore
15//! use wacore_noise::{NoiseState, generate_iv};
16//!
17//! let mut noise = NoiseState::new(b"Noise_XX_25519_AESGCM_SHA256\0\0\0\0", &prologue)?;
18//! noise.authenticate(&my_ephemeral_public);
19//! noise.mix_key(&shared_secret)?;
20//! let ciphertext = noise.encrypt(plaintext)?;
21//! let keys = noise.split()?;
22//! ```
23//!
24//! # Example (WhatsApp)
25//!
26//! ```ignore
27//! use wacore_noise::{NoiseHandshake, HandshakeUtils};
28//!
29//! let mut nh = NoiseHandshake::new(NOISE_START_PATTERN, &WA_CONN_HEADER)?;
30//! nh.authenticate(&ephemeral_public);
31//! nh.mix_shared_secret(&private_key, &their_public)?;
32//! let (write_key, read_key) = nh.finish()?;
33//! ```
34
35mod edge_routing;
36mod error;
37pub mod framing;
38mod handshake;
39mod state;
40
41pub use aes_gcm::Aes256Gcm;
42pub use edge_routing::{
43    EdgeRoutingError, MAX_EDGE_ROUTING_LEN, build_edge_routing_preintro, build_handshake_header,
44};
45pub use error::{NoiseError, Result};
46pub use handshake::{
47    HandshakeError, HandshakeState, HandshakeUtils, NoiseHandshake, Result as HandshakeResult,
48    WA_CERT_PUB_KEY,
49};
50pub use state::{NoiseCipher, NoiseKeys, NoiseState, generate_iv};