Added _steam_ jvm and js implementations
This commit is contained in:
4 files changed
+230
-32
No files matched your search
+10
@@ -222,6 +222,16 @@ interface JsSodiumInterface {
|
||||
fun crypto_kx_seed_keypair(seed: Uint8Array) : dynamic
|
||||
fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : dynamic
|
||||
|
||||
// ---- Key exchange end ----
|
||||
|
||||
// -- Stream ----
|
||||
fun crypto_stream_chacha20(outLength: UInt, key: Uint8Array, nonce: Uint8Array) : Uint8Array
|
||||
fun crypto_stream_chacha20_ietf_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_stream_chacha20_ietf_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array
|
||||
fun crypto_stream_chacha20_keygen() : Uint8Array
|
||||
fun crypto_stream_chacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_stream_chacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.ionspin.kotlin.crypto.stream
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
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.toUInt(), key.toUInt8Array(), nonce.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chacha20IetfXor(
|
||||
message: UByteArray,
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
val result = getSodium().crypto_stream_chacha20_ietf_xor(
|
||||
message.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
)
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chacha20IetfXorIc(
|
||||
message: UByteArray,
|
||||
nonce: UByteArray,
|
||||
initialCounter: ULong,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
|
||||
val result = getSodium().crypto_stream_chacha20_ietf_xor_ic(
|
||||
message.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
initialCounter.toUInt(),
|
||||
key.toUInt8Array()
|
||||
)
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chacha20Keygen(): UByteArray {
|
||||
val result = getSodium().crypto_stream_chacha20_keygen()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chacha20Xor(
|
||||
message: UByteArray,
|
||||
nonce: UByteArray,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
val result = getSodium().crypto_stream_chacha20_xor(
|
||||
message.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
)
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun chacha20XorIc(
|
||||
message: UByteArray,
|
||||
nonce: UByteArray,
|
||||
initialCounter: ULong,
|
||||
key: UByteArray
|
||||
): UByteArray {
|
||||
val result = getSodium().crypto_stream_chacha20_xor_ic(
|
||||
message.toUInt8Array(),
|
||||
nonce.toUInt8Array(),
|
||||
initialCounter.toUInt(),
|
||||
key.toUInt8Array()
|
||||
)
|
||||
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user