fix #10 KDF.Complexity derivation functions now require salt

This commit is contained in:
Sergey Chernov 2025-03-12 23:39:26 +03:00
parent fe6190eb8d
commit 875c0f7a50
2 changed files with 6 additions and 5 deletions

View File

@ -44,7 +44,8 @@ sealed class KDF {
* *
* Random salt of proper size is used * Random salt of proper size is used
*/ */
fun kdfForSize(numberOfKeys: Int): KDF = creteDefault(SymmetricKey.keyLength * numberOfKeys, this) fun kdfForSize(numberOfKeys: Int,salt: UByteArray = Argon.randomSalt()): KDF =
creteDefault(SymmetricKey.keyLength * numberOfKeys, this, salt)
/** /**
* Derive multiple keys from the password. Derivation params will be included in the key ids, see * Derive multiple keys from the password. Derivation params will be included in the key ids, see
@ -58,13 +59,13 @@ sealed class KDF {
* to change with time. * to change with time.
*/ */
@Suppress("unused") @Suppress("unused")
fun deriveMultiple(password: String, count: Int): List<SymmetricKey> = fun deriveMultiple(password: String, count: Int,salt: UByteArray): List<SymmetricKey> =
kdfForSize(count).deriveMultipleKeys(password, count) kdfForSize(count, salt).deriveMultipleKeys(password, count)
/** /**
* Derive single key from password, same as [deriveMultiple] with count=1. * Derive single key from password, same as [deriveMultiple] with count=1.
*/ */
fun derive(password: String): SymmetricKey = deriveMultiple(password, 1).first() fun derive(password: String, salt: UByteArray): SymmetricKey = deriveMultiple(password, 1, salt).first()
} }
/** /**

View File

@ -442,7 +442,7 @@ class KeysTest {
assertContentEquals(k2.keyBytes, k2.id.id.body) assertContentEquals(k2.keyBytes, k2.id.id.body)
val k7 = SymmetricKey.new() val k7 = SymmetricKey.new()
val k8 = KDF.Complexity.Interactive.derive("super") val k8 = KDF.Complexity.Interactive.derive("super", KDF.Argon.randomSalt())
fun testToString(k: UniversalKey) { fun testToString(k: UniversalKey) {
val s = k.toString() val s = k.toString()