From 124f6a21a3b7308d7ac9cd7dec7218de5d1293b0 Mon Sep 17 00:00:00 2001 From: Infendro Date: Mon, 16 Feb 2026 19:52:47 +0100 Subject: [PATCH] Upgrade dependencies --- build.gradle.kts | 8 ++------ gradle/libs.versions.toml | 10 +++++----- src/commonMain/kotlin/com/infendro/kdf/KDF.kt | 19 +++++-------------- .../kotlin/com/infendro/kdf/PBKDF2.kt | 4 +--- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ee45012..2c3eb7b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,18 +31,14 @@ kotlin { sourceSets { commonMain.dependencies { - implementation(libs.mac) - implementation(libs.hash) implementation(libs.bytes) + implementation(libs.hash) + implementation(libs.mac) } commonTest.dependencies { implementation(libs.test) } } - - compilerOptions { - freeCompilerArgs.add("-opt-in=kotlin.ExperimentalUnsignedTypes") - } } publishing.repositories { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fe31bde..3dd3ae9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,16 +1,16 @@ [versions] infendro = "1.1.0" kotlin = "2.3.0" -mac = "1.3.0" -hash = "1.5.1" -bytes = "1.3.4" +bytes = "1.4.0" +hash = "1.6.0" +mac = "1.4.0" [plugins] infendro = { id = "com.infendro.plugin", version.ref = "infendro" } multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } [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" } +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" } diff --git a/src/commonMain/kotlin/com/infendro/kdf/KDF.kt b/src/commonMain/kotlin/com/infendro/kdf/KDF.kt index c0c6c61..96870b8 100644 --- a/src/commonMain/kotlin/com/infendro/kdf/KDF.kt +++ b/src/commonMain/kotlin/com/infendro/kdf/KDF.kt @@ -7,18 +7,9 @@ interface KDF { fun hashInto(value: ByteArray, salt: ByteArray, destination: ByteArray, destinationOffset: Int = 0) - fun hashInto(value: ByteArray, salt: ByteArray, destination: UByteArray, destinationOffset: Int = 0) = - hashInto(value, salt, destination.asByteArray(), destinationOffset) - - fun hashInto(value: UByteArray, salt: UByteArray, destination: ByteArray, destinationOffset: Int = 0) = - 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) } + fun hash(value: ByteArray, salt: ByteArray): ByteArray { + val result = ByteArray(bytes) + hashInto(value, salt, result) + return result + } } diff --git a/src/commonMain/kotlin/com/infendro/kdf/PBKDF2.kt b/src/commonMain/kotlin/com/infendro/kdf/PBKDF2.kt index 6557d20..a44b6a6 100644 --- a/src/commonMain/kotlin/com/infendro/kdf/PBKDF2.kt +++ b/src/commonMain/kotlin/com/infendro/kdf/PBKDF2.kt @@ -19,8 +19,6 @@ class PBKDF2( private val hmac = HMAC(function) override fun hashInto(value: ByteArray, salt: ByteArray, destination: ByteArray, destinationOffset: Int) { - val buffer = ByteArray(hmac.bytes) - for (iteration in 1..bytes.ceilDiv(hmac.bytes)) { val offset = (iteration - 1) * hmac.bytes val block = minOf(bytes - offset, hmac.bytes) @@ -29,7 +27,7 @@ class PBKDF2( salt.copyInto(s) iteration.copyInto(s, salt.size) - hmac.hashInto(value, s, buffer) + val buffer = hmac.hash(value, s) buffer.copyInto(destination, destinationOffset + offset, endIndex = block) repeat(iterations - 1) { hmac.hashInto(value, buffer, buffer)