Adding secretstream push definition and neccessary changes

This commit is contained in:
Ugljesa Jovanovic committed 2020-08-14 16:00:30 +02:00
1 parent efe9661c30
commit 28995c065f
9 files changed
+195 -31

No files matched your search

@@ -5,6 +5,7 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
import kotlin.Any
import kotlin.Int
import kotlin.UByte
import kotlin.UByteArray
import org.khronos.webgl.Uint8Array
@@ -58,6 +59,10 @@ actual class Crypto internal actual constructor() {
return getSodium().crypto_generichash_init(key.toUInt8Array(), outlen)
}
/**
* Initialize a state and generate a random header. Both are returned inside
* `SecretStreamStateAndHeader` object
*/
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): dynamic {
println("Debug crypto_secretstream_xchacha20poly1305_init_push")
val stateAndHeader =
@@ -66,4 +71,18 @@ actual class Crypto internal actual constructor() {
val header = (stateAndHeader.header as Uint8Array).toUByteArray()
return SecretStreamStateAndHeader(state, header)
}
/**
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
*/
actual fun crypto_secretstream_xchacha20poly1305_push(
state: SecretStreamState,
m: UByteArray,
ad: UByteArray,
tag: UByte
): UByteArray {
println("Debug crypto_secretstream_xchacha20poly1305_push")
return getSodium().crypto_secretstream_xchacha20poly1305_push(state, m.toUInt8Array(), ,
ad.toUInt8Array(), , tag).toUByteArray()
}
}