1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! Cross-language compatibility verification.
//!
//! These tests use hardcoded ciphertext vectors produced by the JavaScript
//! implementation (libsodium-wrappers-sumo + @noble/post-quantum) to verify
//! that the Rust crypto core can decrypt production data.
//!
//! To regenerate vectors, paste the JS snippets into a browser console with
//! the Metamorphic app loaded (libsodium is already initialized).
//!
//! ## Status
//!
//! | Operation | Cross-compatible? | Notes |
//! |-----------|-------------------|-------|
//! | secretbox | ✅ Yes | Same XSalsa20-Poly1305, same nonce||ct format |
//! | box_seal | ✅ Yes | Same ephemeral_pk||ct, same BLAKE2b nonce |
//! | Argon2id | ✅ Yes | Same params (ops=2, mem=64MB, Argon2id v1.3) |
//! | Hybrid PQ | ❌ Not yet | JS uses ml_kem768_x25519 combiner, Rust uses pure ML-KEM-768 |
//!
//! The hybrid PQ incompatibility is expected and documented in
//! `docs/NATIVE_PLATFORM_STRATEGY.md`. During migration, a re-seal pass will
//! normalize all hybrid blobs from the noble format to the Rust format.
use ;
// ============================================================================
// Secretbox: verify Rust can decrypt a known nonce||ciphertext blob
// ============================================================================
/// This vector was produced by the JS implementation:
///
/// ```js
/// const sodium = await import("libsodium-wrappers-sumo");
/// await sodium.ready;
/// const key = new Uint8Array(32).fill(0x42); // fixed key
/// const nonce = new Uint8Array(24).fill(0xAA); // fixed nonce
/// const pt = sodium.from_string("hello from javascript");
/// const ct = sodium.crypto_secretbox_easy(pt, nonce, key);
/// const combined = new Uint8Array(24 + ct.length);
/// combined.set(nonce);
/// combined.set(ct, 24);
/// console.log(btoa(String.fromCharCode(...combined)));
/// ```
///
/// We can verify this by encrypting with the Rust code using the same key,
/// then decrypting — and also by constructing the expected format manually.
/// Verify the exact byte layout matches what libsodium produces:
/// The ciphertext is `nonce (24) || crypto_secretbox_easy output (pt_len + 16)`
///
/// crypto_secretbox_easy output = MAC (16) || encrypted_plaintext
/// (but from our perspective it's opaque — we just need nonce prepended)
// ============================================================================
// Argon2id: verify deterministic output matches libsodium
// ============================================================================
/// Verify Argon2id with known inputs produces a deterministic key.
///
/// The JS uses:
/// ```js
/// sodium.crypto_pwhash(
/// 32, // key length
/// password,
/// salt, // 16 bytes
/// sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, // 2
/// sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE, // 67108864
/// sodium.crypto_pwhash_ALG_DEFAULT // Argon2id v1.3
/// )
/// ```
///
/// The Rust uses the same: Argon2id v0x13, t=2, m=65536 KiB, p=1, output=32 bytes.
/// With identical password + salt, both must produce the same key.
// ============================================================================
// base64 encoding: verify matches JS btoa/atob
// ============================================================================
// ============================================================================
// key_hash format: verify parsing matches JS split
// ============================================================================
// ============================================================================
// Hybrid PQ: verify compatibility with noble's ml_kem768_x25519
// ============================================================================