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
This commit is contained in:
parent
a77ba4cc8f
commit
ce868fc598
@ -94,7 +94,7 @@ external object JsSodiumInterface {
|
|||||||
@JsName("crypto_secretstream_xchacha20poly1305_init_push")
|
@JsName("crypto_secretstream_xchacha20poly1305_init_push")
|
||||||
fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : dynamic
|
fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : dynamic
|
||||||
@JsName("crypto_secretstream_xchacha20poly1305_push")
|
@JsName("crypto_secretstream_xchacha20poly1305_push")
|
||||||
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array
|
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: Byte) : Uint8Array
|
||||||
|
|
||||||
//decrypt
|
//decrypt
|
||||||
@JsName("crypto_secretstream_xchacha20poly1305_init_pull")
|
@JsName("crypto_secretstream_xchacha20poly1305_init_pull")
|
||||||
@ -262,7 +262,7 @@ external object JsSodiumInterface {
|
|||||||
// ---- KDF ----
|
// ---- KDF ----
|
||||||
|
|
||||||
@JsName("crypto_kdf_derive_from_key")
|
@JsName("crypto_kdf_derive_from_key")
|
||||||
fun crypto_kdf_derive_from_key(subkey_len: UInt, subkeyId : UInt, ctx: String, key: Uint8Array) : Uint8Array
|
fun crypto_kdf_derive_from_key(subkey_len: Int, subkeyId : Int, ctx: String, key: Uint8Array) : Uint8Array
|
||||||
@JsName("crypto_kdf_keygen")
|
@JsName("crypto_kdf_keygen")
|
||||||
fun crypto_kdf_keygen() : Uint8Array
|
fun crypto_kdf_keygen() : Uint8Array
|
||||||
|
|
||||||
@ -271,11 +271,11 @@ external object JsSodiumInterface {
|
|||||||
// ---- Password hashing ----
|
// ---- Password hashing ----
|
||||||
|
|
||||||
@JsName("crypto_pwhash")
|
@JsName("crypto_pwhash")
|
||||||
fun crypto_pwhash(keyLength : UInt, password : Uint8Array, salt: Uint8Array, opsLimit: UInt, memLimit: UInt, algorithm: UInt) : Uint8Array
|
fun crypto_pwhash(keyLength : Int, password : Uint8Array, salt: Uint8Array, opsLimit: Int, memLimit: Int, algorithm: Int) : Uint8Array
|
||||||
@JsName("crypto_pwhash_str")
|
@JsName("crypto_pwhash_str")
|
||||||
fun crypto_pwhash_str(password: Uint8Array, opsLimit: UInt, memLimit: UInt) : String
|
fun crypto_pwhash_str(password: Uint8Array, opsLimit: Int, memLimit: Int) : String
|
||||||
@JsName("crypto_pwhash_str_needs_rehash")
|
@JsName("crypto_pwhash_str_needs_rehash")
|
||||||
fun crypto_pwhash_str_needs_rehash(hashedPassword: String, opsLimit: UInt, memLimit: UInt) : Boolean
|
fun crypto_pwhash_str_needs_rehash(hashedPassword: String, opsLimit: Int, memLimit: Int) : Boolean
|
||||||
@JsName("crypto_pwhash_str_verify")
|
@JsName("crypto_pwhash_str_verify")
|
||||||
fun crypto_pwhash_str_verify(hashedPassword: String, password: Uint8Array) : Boolean
|
fun crypto_pwhash_str_verify(hashedPassword: String, password: Uint8Array) : Boolean
|
||||||
|
|
||||||
@ -310,11 +310,11 @@ external object JsSodiumInterface {
|
|||||||
@JsName("randombytes_buf")
|
@JsName("randombytes_buf")
|
||||||
fun randombytes_buf(length: Int) : Uint8Array
|
fun randombytes_buf(length: Int) : Uint8Array
|
||||||
@JsName("randombytes_buf_deterministic")
|
@JsName("randombytes_buf_deterministic")
|
||||||
fun randombytes_buf_deterministic(length: UInt, seed : Uint8Array) : Uint8Array
|
fun randombytes_buf_deterministic(length: Int, seed : Uint8Array) : Uint8Array
|
||||||
@JsName("randombytes_random")
|
@JsName("randombytes_random")
|
||||||
fun randombytes_random() : UInt
|
fun randombytes_random() : Int
|
||||||
@JsName("randombytes_uniform")
|
@JsName("randombytes_uniform")
|
||||||
fun randombytes_uniform(upper_bound: UInt) : UInt
|
fun randombytes_uniform(upper_bound: Int) : Int
|
||||||
|
|
||||||
// ---- Utils end ----
|
// ---- Utils end ----
|
||||||
|
|
||||||
@ -332,24 +332,24 @@ external object JsSodiumInterface {
|
|||||||
|
|
||||||
// -- Stream ----
|
// -- Stream ----
|
||||||
@JsName("crypto_stream_chacha20")
|
@JsName("crypto_stream_chacha20")
|
||||||
fun crypto_stream_chacha20(outLength: UInt, key: Uint8Array, nonce: Uint8Array) : Uint8Array
|
fun crypto_stream_chacha20(outLength: Int, key: Uint8Array, nonce: Uint8Array) : Uint8Array
|
||||||
@JsName("crypto_stream_chacha20_ietf_xor")
|
@JsName("crypto_stream_chacha20_ietf_xor")
|
||||||
fun crypto_stream_chacha20_ietf_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
fun crypto_stream_chacha20_ietf_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||||
@JsName("crypto_stream_chacha20_ietf_xor_ic")
|
@JsName("crypto_stream_chacha20_ietf_xor_ic")
|
||||||
fun crypto_stream_chacha20_ietf_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array
|
fun crypto_stream_chacha20_ietf_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array
|
||||||
@JsName("crypto_stream_chacha20_keygen")
|
@JsName("crypto_stream_chacha20_keygen")
|
||||||
fun crypto_stream_chacha20_keygen() : Uint8Array
|
fun crypto_stream_chacha20_keygen() : Uint8Array
|
||||||
@JsName("crypto_stream_chacha20_xor")
|
@JsName("crypto_stream_chacha20_xor")
|
||||||
fun crypto_stream_chacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
fun crypto_stream_chacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||||
@JsName("crypto_stream_chacha20_xor_ic")
|
@JsName("crypto_stream_chacha20_xor_ic")
|
||||||
fun crypto_stream_chacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array
|
fun crypto_stream_chacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array
|
||||||
|
|
||||||
@JsName("crypto_stream_xchacha20_keygen")
|
@JsName("crypto_stream_xchacha20_keygen")
|
||||||
fun crypto_stream_xchacha20_keygen() : Uint8Array
|
fun crypto_stream_xchacha20_keygen() : Uint8Array
|
||||||
@JsName("crypto_stream_xchacha20_xor")
|
@JsName("crypto_stream_xchacha20_xor")
|
||||||
fun crypto_stream_xchacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
fun crypto_stream_xchacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||||
@JsName("crypto_stream_xchacha20_xor_ic")
|
@JsName("crypto_stream_xchacha20_xor_ic")
|
||||||
fun crypto_stream_xchacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array
|
fun crypto_stream_xchacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array
|
||||||
|
|
||||||
// ---- Stream end ----
|
// ---- Stream end ----
|
||||||
|
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package ext.libsodium.com.ionspin.kotlin.crypto
|
package ext.libsodium.com.ionspin.kotlin.crypto
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.*
|
import com.ionspin.kotlin.crypto.getSodiumLoaded
|
||||||
import ext.libsodium.*
|
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 kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,8 +26,8 @@ actual object Kdf {
|
|||||||
masterKey: UByteArray
|
masterKey: UByteArray
|
||||||
): UByteArray {
|
): UByteArray {
|
||||||
return getSodium().crypto_kdf_derive_from_key(
|
return getSodium().crypto_kdf_derive_from_key(
|
||||||
subkeyLength.toUInt(),
|
subkeyLength,
|
||||||
subkeyId.toUInt(),
|
subkeyId.toInt(),
|
||||||
context,
|
context,
|
||||||
masterKey.toUInt8Array()
|
masterKey.toUInt8Array()
|
||||||
).toUByteArray()
|
).toUByteArray()
|
||||||
|
@ -23,12 +23,12 @@ actual object PasswordHash {
|
|||||||
algorithm: Int
|
algorithm: Int
|
||||||
): UByteArray {
|
): UByteArray {
|
||||||
return getSodium().crypto_pwhash(
|
return getSodium().crypto_pwhash(
|
||||||
outputLength.toUInt(),
|
outputLength,
|
||||||
password.encodeToUByteArray().toUInt8Array(),
|
password.encodeToUByteArray().toUInt8Array(),
|
||||||
salt.toUInt8Array(),
|
salt.toUInt8Array(),
|
||||||
opsLimit.toUInt(),
|
opsLimit.toInt(), // TODO check this narrowing
|
||||||
memLimit.toUInt(),
|
memLimit,
|
||||||
algorithm.toUInt()
|
algorithm
|
||||||
).toUByteArray()
|
).toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ actual object PasswordHash {
|
|||||||
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
|
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
|
||||||
return getSodium().crypto_pwhash_str(
|
return getSodium().crypto_pwhash_str(
|
||||||
password.encodeToUByteArray().toUInt8Array(),
|
password.encodeToUByteArray().toUInt8Array(),
|
||||||
opslimit.toUInt(),
|
opslimit.toInt(), // TODO check this narrowing
|
||||||
memlimit.toUInt()
|
memlimit
|
||||||
).encodeToUByteArray()
|
).encodeToUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +64,8 @@ actual object PasswordHash {
|
|||||||
return if (
|
return if (
|
||||||
getSodium().crypto_pwhash_str_needs_rehash(
|
getSodium().crypto_pwhash_str_needs_rehash(
|
||||||
passwordHash.asByteArray().decodeToString(),
|
passwordHash.asByteArray().decodeToString(),
|
||||||
opslimit.toUInt(),
|
opslimit.toInt(), // TODO check this narrowing
|
||||||
memlimit.toUInt()
|
memlimit
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
1
|
1
|
||||||
|
@ -20,7 +20,7 @@ actual object SecretStream {
|
|||||||
tag: UByte
|
tag: UByte
|
||||||
): UByteArray {
|
): UByteArray {
|
||||||
return getSodium().crypto_secretstream_xchacha20poly1305_push(
|
return getSodium().crypto_secretstream_xchacha20poly1305_push(
|
||||||
state, message.toUInt8Array(), associatedData.toUInt8Array(), tag
|
state, message.toUInt8Array(), associatedData.toUInt8Array(), tag.toByte()
|
||||||
).toUByteArray()
|
).toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
|||||||
actual object Stream {
|
actual object Stream {
|
||||||
actual fun chacha20(clen: Int, nonce: UByteArray, key: UByteArray): UByteArray {
|
actual fun chacha20(clen: Int, nonce: UByteArray, key: UByteArray): UByteArray {
|
||||||
//Note, unlike the other ones, here the positions of key and nonce are reversed.
|
//Note, unlike the other ones, here the positions of key and nonce are reversed.
|
||||||
val result = getSodium().crypto_stream_chacha20(clen.toUInt(), key.toUInt8Array(), nonce.toUInt8Array())
|
val result = getSodium().crypto_stream_chacha20(clen, key.toUInt8Array(), nonce.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ actual object Stream {
|
|||||||
val result = getSodium().crypto_stream_chacha20_ietf_xor_ic(
|
val result = getSodium().crypto_stream_chacha20_ietf_xor_ic(
|
||||||
message.toUInt8Array(),
|
message.toUInt8Array(),
|
||||||
nonce.toUInt8Array(),
|
nonce.toUInt8Array(),
|
||||||
initialCounter.toUInt(),
|
initialCounter.toInt(),
|
||||||
key.toUInt8Array()
|
key.toUInt8Array()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ actual object Stream {
|
|||||||
val result = getSodium().crypto_stream_chacha20_xor_ic(
|
val result = getSodium().crypto_stream_chacha20_xor_ic(
|
||||||
message.toUInt8Array(),
|
message.toUInt8Array(),
|
||||||
nonce.toUInt8Array(),
|
nonce.toUInt8Array(),
|
||||||
initialCounter.toUInt(),
|
initialCounter.toInt(),
|
||||||
key.toUInt8Array()
|
key.toUInt8Array()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,14 +26,14 @@ actual object LibsodiumRandom {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
actual fun bufDeterministic(size: Int, seed: UByteArray): UByteArray {
|
actual fun bufDeterministic(size: Int, seed: UByteArray): UByteArray {
|
||||||
return getSodium().randombytes_buf_deterministic(size.toUInt(), seed.toUInt8Array()).toUByteArray()
|
return getSodium().randombytes_buf_deterministic(size, seed.toUInt8Array()).toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The randombytes_random() function returns an unpredictable value between 0 and 0xffffffff (included).
|
* The randombytes_random() function returns an unpredictable value between 0 and 0xffffffff (included).
|
||||||
*/
|
*/
|
||||||
actual fun random(): UInt {
|
actual fun random(): UInt {
|
||||||
return getSodium().randombytes_random()
|
return getSodium().randombytes_random().toUInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -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
|
* 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 {
|
actual fun uniform(upperBound: UInt): UInt {
|
||||||
return getSodium().randombytes_uniform(upperBound)
|
return getSodium().randombytes_uniform(upperBound.toInt()).toUInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user