1package com.peachpasswords23import com.peachpasswords.sync.SASDerivation4import com.peachpasswords.sync.computeVaultId5import com.peachpasswords.vault.VaultCrypto6import org.junit.Assert.assertArrayEquals7import org.junit.Assert.assertEquals8import org.junit.Assert.assertFalse9import org.junit.Assert.assertNotEquals10import org.junit.Test11import java.text.Normalizer12131415161718192021class CrossPlatformKATTest {2223 private fun hex(b: ByteArray) = b.joinToString("") { "%02x".format(it) }2425 26 private val argonSalt = ByteArray(VaultCrypto.SALT_SIZE) { it.toByte() }2728 @Test fun argon2id_non_bmp_password_vector() {29 30 31 32 val key = VaultCrypto.deriveKey("test🔑", argonSalt)33 assertEquals("a519dd4e695d25c6cd69a2f89d51ddcabd952c979f5714ab29fb77f6d1ad3728", hex(key))34 }3536 @Test fun nfc_normalization_makes_composed_and_decomposed_match() {37 38 39 val nfd = Normalizer.normalize("café", Normalizer.Form.NFD)40 val nfc = Normalizer.normalize("café", Normalizer.Form.NFC)41 assertNotEquals(nfd, nfc)42 assertArrayEquals(VaultCrypto.deriveKey(nfd, argonSalt), VaultCrypto.deriveKey(nfc, argonSalt))43 }4445 @Test fun deriveKeyRaw_does_not_normalize() {46 val nfd = Normalizer.normalize("café", Normalizer.Form.NFD)47 val nfc = Normalizer.normalize("café", Normalizer.Form.NFC)48 assertFalse(49 VaultCrypto.deriveKeyRaw(nfd, argonSalt).contentEquals(VaultCrypto.deriveKeyRaw(nfc, argonSalt)),50 )51 }5253 @Test fun compute_vault_id_vector() {54 55 val masterKey = ByteArray(32) { it.toByte() }56 assertEquals("ae0ec54041c9ba3e20c0c2d33bdeb2552f3b9a3fb4be3286ec0ef0a61be2fc9c", computeVaultId(masterKey))57 }5859 @Test fun sas_derivation_vector() {60 61 val handshakeHash = byteArrayOf(0x12, 0x34, 0x56, 0x78) + ByteArray(28)62 assertEquals("419896", SASDerivation.derive(handshakeHash))63 }64}