This commit is contained in:
@@ -31,18 +31,14 @@ kotlin {
|
|||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain.dependencies {
|
commonMain.dependencies {
|
||||||
implementation(libs.mac)
|
|
||||||
implementation(libs.hash)
|
|
||||||
implementation(libs.bytes)
|
implementation(libs.bytes)
|
||||||
|
implementation(libs.hash)
|
||||||
|
implementation(libs.mac)
|
||||||
}
|
}
|
||||||
commonTest.dependencies {
|
commonTest.dependencies {
|
||||||
implementation(libs.test)
|
implementation(libs.test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compilerOptions {
|
|
||||||
freeCompilerArgs.add("-opt-in=kotlin.ExperimentalUnsignedTypes")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing.repositories {
|
publishing.repositories {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
[versions]
|
[versions]
|
||||||
infendro = "1.1.0"
|
infendro = "1.1.0"
|
||||||
kotlin = "2.3.0"
|
kotlin = "2.3.0"
|
||||||
mac = "1.3.0"
|
bytes = "1.4.0"
|
||||||
hash = "1.5.1"
|
hash = "1.6.0"
|
||||||
bytes = "1.3.4"
|
mac = "1.4.0"
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
infendro = { id = "com.infendro.plugin", version.ref = "infendro" }
|
infendro = { id = "com.infendro.plugin", version.ref = "infendro" }
|
||||||
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
mac = { module = "com.infendro:mac", version.ref = "mac" }
|
|
||||||
hash = { module = "com.infendro:hash", version.ref = "hash" }
|
|
||||||
bytes = { module = "com.infendro:bytes", version.ref = "bytes" }
|
bytes = { module = "com.infendro:bytes", version.ref = "bytes" }
|
||||||
|
hash = { module = "com.infendro:hash", version.ref = "hash" }
|
||||||
|
mac = { module = "com.infendro:mac", version.ref = "mac" }
|
||||||
test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
||||||
|
|||||||
@@ -7,18 +7,9 @@ interface KDF {
|
|||||||
|
|
||||||
fun hashInto(value: ByteArray, salt: ByteArray, destination: ByteArray, destinationOffset: Int = 0)
|
fun hashInto(value: ByteArray, salt: ByteArray, destination: ByteArray, destinationOffset: Int = 0)
|
||||||
|
|
||||||
fun hashInto(value: ByteArray, salt: ByteArray, destination: UByteArray, destinationOffset: Int = 0) =
|
fun hash(value: ByteArray, salt: ByteArray): ByteArray {
|
||||||
hashInto(value, salt, destination.asByteArray(), destinationOffset)
|
val result = ByteArray(bytes)
|
||||||
|
hashInto(value, salt, result)
|
||||||
fun hashInto(value: UByteArray, salt: UByteArray, destination: ByteArray, destinationOffset: Int = 0) =
|
return result
|
||||||
hashInto(value.asByteArray(), salt.asByteArray(), destination, destinationOffset)
|
}
|
||||||
|
|
||||||
fun hashInto(value: UByteArray, salt: UByteArray, destination: UByteArray, destinationOffset: Int = 0) =
|
|
||||||
hashInto(value.asByteArray(), salt.asByteArray(), destination.asByteArray(), destinationOffset)
|
|
||||||
|
|
||||||
fun hash(value: ByteArray, salt: ByteArray): ByteArray =
|
|
||||||
ByteArray(bytes).also { hashInto(value, salt, it) }
|
|
||||||
|
|
||||||
fun hash(value: UByteArray, salt: UByteArray): UByteArray =
|
|
||||||
UByteArray(bytes).also { hashInto(value, salt, it) }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ class PBKDF2(
|
|||||||
private val hmac = HMAC(function)
|
private val hmac = HMAC(function)
|
||||||
|
|
||||||
override fun hashInto(value: ByteArray, salt: ByteArray, destination: ByteArray, destinationOffset: Int) {
|
override fun hashInto(value: ByteArray, salt: ByteArray, destination: ByteArray, destinationOffset: Int) {
|
||||||
val buffer = ByteArray(hmac.bytes)
|
|
||||||
|
|
||||||
for (iteration in 1..bytes.ceilDiv(hmac.bytes)) {
|
for (iteration in 1..bytes.ceilDiv(hmac.bytes)) {
|
||||||
val offset = (iteration - 1) * hmac.bytes
|
val offset = (iteration - 1) * hmac.bytes
|
||||||
val block = minOf(bytes - offset, hmac.bytes)
|
val block = minOf(bytes - offset, hmac.bytes)
|
||||||
@@ -29,7 +27,7 @@ class PBKDF2(
|
|||||||
salt.copyInto(s)
|
salt.copyInto(s)
|
||||||
iteration.copyInto(s, salt.size)
|
iteration.copyInto(s, salt.size)
|
||||||
|
|
||||||
hmac.hashInto(value, s, buffer)
|
val buffer = hmac.hash(value, s)
|
||||||
buffer.copyInto(destination, destinationOffset + offset, endIndex = block)
|
buffer.copyInto(destination, destinationOffset + offset, endIndex = block)
|
||||||
repeat(iterations - 1) {
|
repeat(iterations - 1) {
|
||||||
hmac.hashInto(value, buffer, buffer)
|
hmac.hashInto(value, buffer, buffer)
|
||||||
|
|||||||
Reference in New Issue
Block a user