wacore_binary/consts.rs
1use crate::token::DICT_VERSION;
2
3/// Noise XX pattern name, zero-padded to HASHLEN (32 bytes) per Noise ยง 5.2.
4/// Used on the first connect / pairing where the client has no cached server
5/// static key. Mirrors WA Web's `M` constant in `WAWebOpenChatSocket`.
6pub const NOISE_PATTERN_XX: &str = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00";
7
8/// Noise IK pattern name, zero-padded to HASHLEN (32 bytes).
9/// Used on reconnect when the client has a valid cached `serverStaticPublic`
10/// (from a previous XX handshake). Saves one round trip and ships a 0-RTT
11/// payload. Mirrors WA Web's `w` constant.
12pub const NOISE_PATTERN_IK: &str = "Noise_IK_25519_AESGCM_SHA256\x00\x00\x00\x00";
13
14/// Noise XXfallback pattern name (36 bytes, hashed by Noise spec).
15/// Used to recover gracefully when an in-flight IK handshake is rejected by
16/// the server (server's static rotated, cached pub key is stale). The client
17/// reuses the ephemeral it already sent in the IK ClientHello and processes
18/// the server's XX-style ServerHello. Mirrors WA Web's `A` constant.
19pub const NOISE_PATTERN_XXFALLBACK: &str = "Noise_XXfallback_25519_AESGCM_SHA256";
20
21pub const WA_MAGIC_VALUE: u8 = 6;
22pub const WA_CONN_HEADER: [u8; 4] = [b'W', b'A', WA_MAGIC_VALUE, DICT_VERSION];
23
24#[cfg(test)]
25mod pattern_length_tests {
26 use super::*;
27
28 #[test]
29 fn xx_is_padded_to_hashlen() {
30 assert_eq!(NOISE_PATTERN_XX.len(), 32);
31 }
32
33 #[test]
34 fn ik_is_padded_to_hashlen() {
35 assert_eq!(NOISE_PATTERN_IK.len(), 32);
36 }
37
38 #[test]
39 fn xxfallback_is_unpadded_36_bytes() {
40 // Longer than HASHLEN -> Noise spec hashes it; padding here would be
41 // a correctness bug on the wire. Lock the length explicitly.
42 assert_eq!(NOISE_PATTERN_XXFALLBACK.len(), 36);
43 }
44}