Update kotlin to 1.9.10, update library versions, use latest libsodium stable, clean up Deps, remove deprecated targets, change PasswordHash str related functions to use String
This commit is contained in:
14 files changed
+76
-123
No files matched your search
@@ -56,10 +56,10 @@ version = ReleaseInfo.bindingsVersion
|
||||
val ideaActive = isInIdea()
|
||||
println("Idea active: $ideaActive")
|
||||
android {
|
||||
compileSdkVersion(AndroidPluginConfiguration.sdkVersion)
|
||||
compileSdk = AndroidPluginConfiguration.sdkVersion
|
||||
defaultConfig {
|
||||
minSdkVersion(AndroidPluginConfiguration.minVersion)
|
||||
targetSdkVersion(AndroidPluginConfiguration.sdkVersion)
|
||||
minSdk = AndroidPluginConfiguration.minVersion
|
||||
targetSdk = AndroidPluginConfiguration.sdkVersion
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
@@ -83,7 +83,7 @@ android {
|
||||
|
||||
kotlin {
|
||||
val hostOsName = getHostOsName()
|
||||
android() {
|
||||
androidTarget() {
|
||||
publishLibraryVariants("release", "debug")
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ kotlin {
|
||||
println("Configuring Linux X86-64 targets")
|
||||
|
||||
|
||||
js(IR) {
|
||||
js {
|
||||
browser {
|
||||
testTask {
|
||||
useKarma {
|
||||
@@ -133,15 +133,6 @@ kotlin {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Linux 32 is using target-sysroot-2-raspberrypi which is missing getrandom and explicit_bzero in stdlib
|
||||
// so konanc can't build klib because getrandom missing will cause sodium_misuse()
|
||||
// ld.lld: error: undefined symbol: explicit_bzero
|
||||
// >>> referenced by utils.c
|
||||
// >>> libsodium_la-utils.o:(sodium_memzero) in archive /tmp/included11051337748775083797/libsodium.a
|
||||
//
|
||||
// ld.lld: error: undefined symbol: getrandom
|
||||
// >>> referenced by randombytes_sysrandom.c
|
||||
// >>> libsodium_la-randombytes_sysrandom.o:(_randombytes_linux_getrandom) in archive /tmp/included11051337748775083797/libsodium.a
|
||||
}
|
||||
|
||||
}
|
||||
@@ -171,13 +162,7 @@ kotlin {
|
||||
}
|
||||
}
|
||||
}
|
||||
iosArm32() {
|
||||
binaries {
|
||||
framework {
|
||||
optimized = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iosSimulatorArm64() {
|
||||
binaries {
|
||||
framework {
|
||||
@@ -237,13 +222,7 @@ kotlin {
|
||||
}
|
||||
}
|
||||
}
|
||||
watchosX86() {
|
||||
binaries {
|
||||
framework {
|
||||
optimized = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
watchosSimulatorArm64() {
|
||||
binaries {
|
||||
framework {
|
||||
@@ -351,9 +330,6 @@ kotlin {
|
||||
""
|
||||
}
|
||||
)
|
||||
val linux32Bit = setOf(
|
||||
"" // "linuxArm32Hfp"
|
||||
)
|
||||
|
||||
//iosArm32, iosArm64, iosX64, macosX64, metadata, tvosArm64, tvosX64, watchosArm32, watchosArm64, watchosX86
|
||||
val macos64Bit = setOf(
|
||||
@@ -377,10 +353,10 @@ kotlin {
|
||||
)
|
||||
|
||||
val watchosArm = setOf(
|
||||
"watchosArm32", "watchosArm64"
|
||||
"watchosArm64"
|
||||
)
|
||||
val watchosSimulator = setOf(
|
||||
"watchosX86", "watchosSimulatorArm64"
|
||||
"watchosSimulatorArm64"
|
||||
)
|
||||
|
||||
targets.withType<KotlinNativeTarget> {
|
||||
@@ -408,14 +384,7 @@ kotlin {
|
||||
)
|
||||
}
|
||||
}
|
||||
if (linux32Bit.contains(this@withType.name)) {
|
||||
defaultSourceSet.dependsOn(
|
||||
createWorkaroundNativeMainSourceSet(
|
||||
this@withType.name,
|
||||
nativeDependencies
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (macos64Bit.contains(this@withType.name)) {
|
||||
defaultSourceSet.dependsOn(
|
||||
createWorkaroundNativeMainSourceSet(
|
||||
@@ -640,10 +609,6 @@ kotlin {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
val watchosX86Main by getting {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
val watchosArm64Main by getting {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
+3
-3
@@ -55,7 +55,7 @@ expect object PasswordHash {
|
||||
* and other data stores. No extra information has to be stored in order to verify the password.
|
||||
* The function returns 0 on success and -1 if it didn't complete successfully.
|
||||
*/
|
||||
fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray
|
||||
fun str(password: String, opslimit: ULong, memlimit: Int): String
|
||||
|
||||
/**
|
||||
* Check if a password verification string str matches the parameters opslimit and memlimit, and the current default algorithm.
|
||||
@@ -63,13 +63,13 @@ expect object PasswordHash {
|
||||
* The function returns 0 if the parameters already match the given ones.
|
||||
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
|
||||
*/
|
||||
fun strNeedsRehash(passwordHash: UByteArray, opslimit: ULong, memlimit: Int): Int
|
||||
fun strNeedsRehash(passwordHash: String, opslimit: ULong, memlimit: Int): Int
|
||||
|
||||
/**
|
||||
* his function verifies that str is a valid password verification string (as generated by crypto_pwhash_str()) for passwd whose length is passwdlen.
|
||||
* str has to be zero-terminated.
|
||||
* It returns 0 if the verification succeeds, and -1 on error.
|
||||
*/
|
||||
fun strVerify(passwordHash: UByteArray, password: String): Boolean
|
||||
fun strVerify(passwordHash: String, password: String): Boolean
|
||||
|
||||
}
|
||||
+1
-1
@@ -44,7 +44,7 @@ class PasswordHashTest {
|
||||
crypto_pwhash_OPSLIMIT_MIN,
|
||||
crypto_pwhash_MEMLIMIT_MIN
|
||||
)
|
||||
println("Hashed password for storage: ${hashedPassword.toHexString()}")
|
||||
println("Hashed password for storage: ${hashedPassword}")
|
||||
|
||||
assertTrue {
|
||||
PasswordHash.strVerify(
|
||||
|
||||
+6
-6
@@ -45,7 +45,7 @@ actual object PasswordHash {
|
||||
* and other data stores. No extra information has to be stored in order to verify the password.
|
||||
* The function returns 0 on success and -1 if it didn't complete successfully.
|
||||
*/
|
||||
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
|
||||
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
|
||||
if (opslimit > UInt.MAX_VALUE) {
|
||||
throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit")
|
||||
}
|
||||
@@ -53,7 +53,7 @@ actual object PasswordHash {
|
||||
password.encodeToUByteArray().toUInt8Array(),
|
||||
opslimit.toUInt(),
|
||||
memlimit.toUInt()
|
||||
).encodeToUByteArray()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ actual object PasswordHash {
|
||||
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
|
||||
*/
|
||||
actual fun strNeedsRehash(
|
||||
passwordHash: UByteArray,
|
||||
passwordHash: String,
|
||||
opslimit: ULong,
|
||||
memlimit: Int
|
||||
): Int {
|
||||
@@ -72,7 +72,7 @@ actual object PasswordHash {
|
||||
}
|
||||
return if (
|
||||
getSodium().crypto_pwhash_str_needs_rehash(
|
||||
passwordHash.asByteArray().decodeToString(),
|
||||
passwordHash,
|
||||
opslimit.toUInt(),
|
||||
memlimit.toUInt()
|
||||
)
|
||||
@@ -88,9 +88,9 @@ actual object PasswordHash {
|
||||
* str has to be zero-terminated.
|
||||
* It returns 0 if the verification succeeds, and -1 on error.
|
||||
*/
|
||||
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
|
||||
actual fun strVerify(passwordHash: String, password: String): Boolean {
|
||||
return getSodium().crypto_pwhash_str_verify(
|
||||
passwordHash.asByteArray().decodeToString(),
|
||||
passwordHash,
|
||||
password.encodeToUByteArray().toUInt8Array()
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -1108,7 +1108,7 @@ interface JnaLibsodiumInterface : Library {
|
||||
// int crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES],
|
||||
// unsigned long long opslimit, size_t memlimit)
|
||||
fun crypto_pwhash_str_needs_rehash(
|
||||
output: ByteArray,
|
||||
output: String,
|
||||
opslimit: Long,
|
||||
memlimit: Long
|
||||
) : Int
|
||||
@@ -1116,7 +1116,7 @@ interface JnaLibsodiumInterface : Library {
|
||||
// const char * const passwd,
|
||||
// unsigned long long passwdlen)
|
||||
fun crypto_pwhash_str_verify(
|
||||
hash: ByteArray,
|
||||
hash: String,
|
||||
password: String,
|
||||
passwordLength: Long
|
||||
) : Int
|
||||
|
||||
+6
-7
@@ -1,7 +1,6 @@
|
||||
package com.ionspin.kotlin.crypto.pwhash
|
||||
|
||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
||||
import com.sun.jna.NativeLong
|
||||
|
||||
actual object PasswordHash {
|
||||
/**
|
||||
@@ -46,7 +45,7 @@ actual object PasswordHash {
|
||||
* and other data stores. No extra information has to be stored in order to verify the password.
|
||||
* The function returns 0 on success and -1 if it didn't complete successfully.
|
||||
*/
|
||||
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
|
||||
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
|
||||
val output = ByteArray(crypto_pwhash_STRBYTES)
|
||||
sodiumJna.crypto_pwhash_str(
|
||||
output,
|
||||
@@ -55,7 +54,7 @@ actual object PasswordHash {
|
||||
opslimit.toLong(),
|
||||
memlimit.toLong()
|
||||
)
|
||||
return output.asUByteArray()
|
||||
return output.decodeToString()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,12 +64,12 @@ actual object PasswordHash {
|
||||
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
|
||||
*/
|
||||
actual fun strNeedsRehash(
|
||||
passwordHash: UByteArray,
|
||||
passwordHash: String,
|
||||
opslimit: ULong,
|
||||
memlimit: Int
|
||||
): Int {
|
||||
return sodiumJna.crypto_pwhash_str_needs_rehash(
|
||||
passwordHash.asByteArray(),
|
||||
passwordHash,
|
||||
opslimit.toLong(),
|
||||
memlimit.toLong()
|
||||
)
|
||||
@@ -81,9 +80,9 @@ actual object PasswordHash {
|
||||
* str has to be zero-terminated.
|
||||
* It returns 0 if the verification succeeds, and -1 on error.
|
||||
*/
|
||||
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
|
||||
actual fun strVerify(passwordHash: String, password: String): Boolean {
|
||||
val result = sodiumJna.crypto_pwhash_str_verify(
|
||||
passwordHash.asByteArray(),
|
||||
passwordHash,
|
||||
password,
|
||||
password.length.toLong()
|
||||
)
|
||||
|
||||
+6
-7
@@ -4,7 +4,6 @@ import com.ionspin.kotlin.crypto.util.toPtr
|
||||
import kotlinx.cinterop.addressOf
|
||||
import kotlinx.cinterop.convert
|
||||
import kotlinx.cinterop.pin
|
||||
import kotlinx.cinterop.toCValues
|
||||
import libsodium.crypto_pwhash
|
||||
import libsodium.crypto_pwhash_str
|
||||
import libsodium.crypto_pwhash_str_needs_rehash
|
||||
@@ -61,7 +60,7 @@ actual object PasswordHash {
|
||||
* and other data stores. No extra information has to be stored in order to verify the password.
|
||||
* The function returns 0 on success and -1 if it didn't complete successfully.
|
||||
*/
|
||||
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
|
||||
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
|
||||
val output = ByteArray(crypto_pwhash_STRBYTES)
|
||||
val outputPinned = output.pin()
|
||||
crypto_pwhash_str(
|
||||
@@ -73,7 +72,7 @@ actual object PasswordHash {
|
||||
)
|
||||
outputPinned.unpin()
|
||||
|
||||
return output.asUByteArray()
|
||||
return output.decodeToString()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,12 +82,12 @@ actual object PasswordHash {
|
||||
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
|
||||
*/
|
||||
actual fun strNeedsRehash(
|
||||
passwordHash: UByteArray,
|
||||
passwordHash: String,
|
||||
opslimit: ULong,
|
||||
memlimit: Int
|
||||
): Int {
|
||||
val result = crypto_pwhash_str_needs_rehash(
|
||||
passwordHash.asByteArray().toCValues(),
|
||||
passwordHash,
|
||||
opslimit,
|
||||
memlimit.convert()
|
||||
)
|
||||
@@ -102,9 +101,9 @@ actual object PasswordHash {
|
||||
* str has to be zero-terminated.
|
||||
* It returns 0 if the verification succeeds, and -1 on error.
|
||||
*/
|
||||
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
|
||||
actual fun strVerify(passwordHash: String, password: String): Boolean {
|
||||
val result = crypto_pwhash_str_verify(
|
||||
passwordHash.asByteArray().toCValues(),
|
||||
passwordHash,
|
||||
password,
|
||||
password.length.convert()
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user