Revert "Workaround inline class not allowed in external interfaces in JS https://youtrack.jetbrains.com/issue/KT-43224 still need to verify there is no narrowing or truncation when not using unsinged inline classes"

Left the checks for UInt in password hash

This reverts commit ce868fc598612f759c130715bc1caa2b21546739.
This commit is contained in:
Ugljesa Jovanovic 2022-03-25 15:00:57 +01:00
parent 10f9a3226f
commit cdb6ecb8f9
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
7 changed files with 31 additions and 37 deletions

View File

@ -94,7 +94,7 @@ external object JsSodiumInterface {
@JsName("crypto_secretstream_xchacha20poly1305_init_push")
fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : dynamic
@JsName("crypto_secretstream_xchacha20poly1305_push")
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: Byte) : Uint8Array
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array
//decrypt
@JsName("crypto_secretstream_xchacha20poly1305_init_pull")
@ -262,7 +262,7 @@ external object JsSodiumInterface {
// ---- KDF ----
@JsName("crypto_kdf_derive_from_key")
fun crypto_kdf_derive_from_key(subkey_len: Int, subkeyId : Int, ctx: String, key: Uint8Array) : Uint8Array
fun crypto_kdf_derive_from_key(subkey_len: UInt, subkeyId : UInt, ctx: String, key: Uint8Array) : Uint8Array
@JsName("crypto_kdf_keygen")
fun crypto_kdf_keygen() : Uint8Array
@ -271,11 +271,11 @@ external object JsSodiumInterface {
// ---- Password hashing ----
@JsName("crypto_pwhash")
fun crypto_pwhash(keyLength : Int, password : Uint8Array, salt: Uint8Array, opsLimit: Int, memLimit: Int, algorithm: Int) : Uint8Array
fun crypto_pwhash(keyLength : UInt, password : Uint8Array, salt: Uint8Array, opsLimit: UInt, memLimit: UInt, algorithm: UInt) : Uint8Array
@JsName("crypto_pwhash_str")
fun crypto_pwhash_str(password: Uint8Array, opsLimit: Int, memLimit: Int) : String
fun crypto_pwhash_str(password: Uint8Array, opsLimit: UInt, memLimit: UInt) : String
@JsName("crypto_pwhash_str_needs_rehash")
fun crypto_pwhash_str_needs_rehash(hashedPassword: String, opsLimit: Int, memLimit: Int) : Boolean
fun crypto_pwhash_str_needs_rehash(hashedPassword: String, opsLimit: UInt, memLimit: UInt) : Boolean
@JsName("crypto_pwhash_str_verify")
fun crypto_pwhash_str_verify(hashedPassword: String, password: Uint8Array) : Boolean
@ -310,11 +310,11 @@ external object JsSodiumInterface {
@JsName("randombytes_buf")
fun randombytes_buf(length: Int) : Uint8Array
@JsName("randombytes_buf_deterministic")
fun randombytes_buf_deterministic(length: Int, seed : Uint8Array) : Uint8Array
fun randombytes_buf_deterministic(length: UInt, seed : Uint8Array) : Uint8Array
@JsName("randombytes_random")
fun randombytes_random() : Int
fun randombytes_random() : UInt
@JsName("randombytes_uniform")
fun randombytes_uniform(upper_bound: Int) : Int
fun randombytes_uniform(upper_bound: UInt) : UInt
// ---- Utils end ----
@ -332,24 +332,24 @@ external object JsSodiumInterface {
// -- Stream ----
@JsName("crypto_stream_chacha20")
fun crypto_stream_chacha20(outLength: Int, key: Uint8Array, nonce: Uint8Array) : Uint8Array
fun crypto_stream_chacha20(outLength: UInt, key: Uint8Array, nonce: Uint8Array) : Uint8Array
@JsName("crypto_stream_chacha20_ietf_xor")
fun crypto_stream_chacha20_ietf_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
@JsName("crypto_stream_chacha20_ietf_xor_ic")
fun crypto_stream_chacha20_ietf_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array
fun crypto_stream_chacha20_ietf_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array
@JsName("crypto_stream_chacha20_keygen")
fun crypto_stream_chacha20_keygen() : Uint8Array
@JsName("crypto_stream_chacha20_xor")
fun crypto_stream_chacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
@JsName("crypto_stream_chacha20_xor_ic")
fun crypto_stream_chacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array
fun crypto_stream_chacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array
@JsName("crypto_stream_xchacha20_keygen")
fun crypto_stream_xchacha20_keygen() : Uint8Array
@JsName("crypto_stream_xchacha20_xor")
fun crypto_stream_xchacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
@JsName("crypto_stream_xchacha20_xor_ic")
fun crypto_stream_xchacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array
fun crypto_stream_xchacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array
// ---- Stream end ----

View File

@ -1,13 +1,7 @@
package ext.libsodium.com.ionspin.kotlin.crypto
import com.ionspin.kotlin.crypto.getSodiumLoaded
import com.ionspin.kotlin.crypto.sodiumLoaded
import ext.libsodium._libsodiumPromise
import ext.libsodium.crypto_generichash
import ext.libsodium.crypto_hash_sha256
import ext.libsodium.crypto_hash_sha256_init
import ext.libsodium.crypto_hash_sha512
import ext.libsodium.sodium_init
import com.ionspin.kotlin.crypto.*
import ext.libsodium.*
import kotlin.coroutines.suspendCoroutine
/**

View File

@ -26,8 +26,8 @@ actual object Kdf {
masterKey: UByteArray
): UByteArray {
return getSodium().crypto_kdf_derive_from_key(
subkeyLength,
subkeyId.toInt(),
subkeyLength.toUInt(),
subkeyId.toUInt(),
context,
masterKey.toUInt8Array()
).toUByteArray()

View File

@ -26,12 +26,12 @@ actual object PasswordHash {
throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit")
}
return getSodium().crypto_pwhash(
outputLength,
outputLength.toUInt(),
password.encodeToUByteArray().toUInt8Array(),
salt.toUInt8Array(),
opsLimit.toInt(),
memLimit,
algorithm
opsLimit.toUInt(),
memLimit.toUInt(),
algorithm.toUInt()
).toUByteArray()
}
@ -51,8 +51,8 @@ actual object PasswordHash {
}
return getSodium().crypto_pwhash_str(
password.encodeToUByteArray().toUInt8Array(),
opslimit.toInt(),
memlimit
opslimit.toUInt(),
memlimit.toUInt()
).encodeToUByteArray()
}
@ -73,8 +73,8 @@ actual object PasswordHash {
return if (
getSodium().crypto_pwhash_str_needs_rehash(
passwordHash.asByteArray().decodeToString(),
opslimit.toInt(),
memlimit
opslimit.toUInt(),
memlimit.toUInt()
)
) {
1

View File

@ -20,7 +20,7 @@ actual object SecretStream {
tag: UByte
): UByteArray {
return getSodium().crypto_secretstream_xchacha20poly1305_push(
state, message.toUInt8Array(), associatedData.toUInt8Array(), tag.toByte()
state, message.toUInt8Array(), associatedData.toUInt8Array(), tag
).toUByteArray()
}

View File

@ -7,7 +7,7 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
actual object Stream {
actual fun chacha20(clen: Int, nonce: UByteArray, key: UByteArray): UByteArray {
//Note, unlike the other ones, here the positions of key and nonce are reversed.
val result = getSodium().crypto_stream_chacha20(clen, key.toUInt8Array(), nonce.toUInt8Array())
val result = getSodium().crypto_stream_chacha20(clen.toUInt(), key.toUInt8Array(), nonce.toUInt8Array())
return result.toUByteArray()
}
@ -35,7 +35,7 @@ actual object Stream {
val result = getSodium().crypto_stream_chacha20_ietf_xor_ic(
message.toUInt8Array(),
nonce.toUInt8Array(),
initialCounter.toInt(),
initialCounter.toUInt(),
key.toUInt8Array()
)
@ -74,7 +74,7 @@ actual object Stream {
val result = getSodium().crypto_stream_chacha20_xor_ic(
message.toUInt8Array(),
nonce.toUInt8Array(),
initialCounter.toInt(),
initialCounter.toUInt(),
key.toUInt8Array()
)

View File

@ -26,14 +26,14 @@ actual object LibsodiumRandom {
*
*/
actual fun bufDeterministic(size: Int, seed: UByteArray): UByteArray {
return getSodium().randombytes_buf_deterministic(size, seed.toUInt8Array()).toUByteArray()
return getSodium().randombytes_buf_deterministic(size.toUInt(), seed.toUInt8Array()).toUByteArray()
}
/**
* The randombytes_random() function returns an unpredictable value between 0 and 0xffffffff (included).
*/
actual fun random(): UInt {
return getSodium().randombytes_random().toUInt()
return getSodium().randombytes_random()
}
/**
@ -42,7 +42,7 @@ actual object LibsodiumRandom {
* upper_bound is not a power of 2. Note that an upper_bound < 2 leaves only a single element to be chosen, namely 0
*/
actual fun uniform(upperBound: UInt): UInt {
return getSodium().randombytes_uniform(upperBound.toInt()).toUInt()
return getSodium().randombytes_uniform(upperBound)
}
}