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
+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