6f6f569690c4

fix: MN-4 cross-platform KAT vectors — pin Argon2id(test🔑+fixed salt), Blake3 computeVaultId, and SAS derivation to frozen golden outputs (Android == browser ports) (v2.2.3)

time
2026-06-09 18:44 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
audit fixes kat vectors
parent
b121245408d2
1 file app/src/test/java/com/peachpasswords/CrossPlatformKATTest.kt+41 −0
app/src/test/java/com/peachpasswords/CrossPlatformKATTest.kt+41 −0
@@ -0,0 +1,41 @@1+package com.peachpasswords2+3+import com.peachpasswords.sync.SASDerivation4+import com.peachpasswords.sync.computeVaultId5+import com.peachpasswords.vault.VaultCrypto6+import org.junit.Assert.assertEquals7+import org.junit.Test8+9+/**10+ * MN-4: cross-platform known-answer tests. These pin the byte-level output of the11+ * primitives Android shares with the browser, so a regression on either side12+ * (encoding, params, algorithm) is caught immediately. The Android implementations13+ * are exact ports of the browser source, so these golden vectors hold on both.14+ *15+ * Inputs are fixed and printable; expected outputs are frozen below.16+ */17+class CrossPlatformKATTest {18+19+    private fun hex(b: ByteArray) = b.joinToString("") { "%02x".format(it) }20+21+    // Argon2id over the non-BMP password "test🔑" (U+1F511, UTF-8) and a fixed salt.22+    private val argonSalt = ByteArray(VaultCrypto.SALT_SIZE) { it.toByte() }23+24+    @Test fun argon2id_non_bmp_password_vector() {25+        // password "test🔑" (UTF-8) + salt bytes 0x00..0x0f, Argon2id m=64MiB t=3 p=4.26+        val key = VaultCrypto.deriveKey("test🔑", argonSalt)27+        assertEquals("a519dd4e695d25c6cd69a2f89d51ddcabd952c979f5714ab29fb77f6d1ad3728", hex(key))28+    }29+30+    @Test fun compute_vault_id_vector() {31+        // Blake3-256( masterKey(0x00..0x1f) || "peach-vault-id" ), hex.32+        val masterKey = ByteArray(32) { it.toByte() }33+        assertEquals("ae0ec54041c9ba3e20c0c2d33bdeb2552f3b9a3fb4be3286ec0ef0a61be2fc9c", computeVaultId(masterKey))34+    }35+36+    @Test fun sas_derivation_vector() {37+        // First 4 bytes 0x12345678 = 305419896; 305419896 mod 1_000_000 = 419896.38+        val handshakeHash = byteArrayOf(0x12, 0x34, 0x56, 0x78) + ByteArray(28)39+        assertEquals("419896", SASDerivation.derive(handshakeHash))40+    }41+}

view file