/* * Copyright (c) 2025. Sergey S. Chernov - All Rights Reserved * * You may use, distribute and modify this code under the * terms of the private license, which you must obtain from the author * * To obtain the license, contact the author: https://t.me/real_sergeych or email to * real dot sergeych at gmail. */ import kotlinx.coroutines.test.runTest import net.sergeych.crypto2.PBKD import net.sergeych.crypto2.initCrypto import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull class PBKDTest { @Test fun testDerive() = runTest { initCrypto() val (k1, k2, k3) = PBKD.deriveMultipleKeys("foobar", 3) PBKD.clearCache() println(k1) println(k2) println(k3) // println("------------------- Secret ket encryption!") // val s = UniversalKey.newSecretKey() // println(s) // println(s.publicKey) // println("------------------- public key signing") // val i = UniversalKey.newSigningKey() // println(i) // println(i.verifyingKey) // println("------------------- symmetric") // println(UniversalKey.newSymmetricKey()) for( k in listOf(k1,k2,k3)) { val i = k.id val kx = i.kdp!!.deriveKey("foobar") assertEquals(k, kx) assertEquals(i, kx.id) assertEquals(i.kdp, kx.id.kdp) } val (y1,y2,y3) = k1.id.kdp!!.kdf.deriveMultipleKeys("foobar", 3) for( (a,b) in listOf(y1,y2,y3).zip(listOf(k1,k2,k3))) { assertEquals(a,b) assertNotNull(a.id.kdp) assertNotNull(b.id.kdp) assertEquals(a.id.kdp, b.id.kdp) assertEquals(a.id, b.id) } assertEquals(k1, y1) assertEquals(k2, y2) assertEquals(k3, y3) } }