forked from sergeych/crypto2
fix #10 KDF.Complexity derivation functions now require salt
This commit is contained in:
parent
fe6190eb8d
commit
875c0f7a50
@ -44,7 +44,8 @@ sealed class KDF {
|
||||
*
|
||||
* 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
|
||||
@ -58,13 +59,13 @@ sealed class KDF {
|
||||
* to change with time.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
fun deriveMultiple(password: String, count: Int): List<SymmetricKey> =
|
||||
kdfForSize(count).deriveMultipleKeys(password, count)
|
||||
fun deriveMultiple(password: String, count: Int,salt: UByteArray): List<SymmetricKey> =
|
||||
kdfForSize(count, salt).deriveMultipleKeys(password, count)
|
||||
|
||||
/**
|
||||
* 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()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -442,7 +442,7 @@ class KeysTest {
|
||||
assertContentEquals(k2.keyBytes, k2.id.id.body)
|
||||
|
||||
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) {
|
||||
val s = k.toString()
|
||||
|
Loading…
x
Reference in New Issue
Block a user