Added rekey and keygen to secretstream

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-29 17:25:59 +02:00
1 parent 91cd41c8c1
commit d5b1e7f7f3
5 files changed
+49 -2

No files matched your search

@@ -10,8 +10,10 @@ import libsodium.crypto_secretstream_xchacha20poly1305_ABYTES
import libsodium.crypto_secretstream_xchacha20poly1305_headerbytes
import libsodium.crypto_secretstream_xchacha20poly1305_init_pull
import libsodium.crypto_secretstream_xchacha20poly1305_init_push
import libsodium.crypto_secretstream_xchacha20poly1305_keygen
import libsodium.crypto_secretstream_xchacha20poly1305_pull
import libsodium.crypto_secretstream_xchacha20poly1305_push
import libsodium.crypto_secretstream_xchacha20poly1305_rekey
import platform.posix.malloc
actual typealias SecretStreamState = libsodium.crypto_secretstream_xchacha20poly1305_state
@@ -119,4 +121,16 @@ actual object SecretStream {
return DecryptedDataAndTag(message, tag[0])
}
actual fun xChaCha20Poly1305Keygen(): UByteArray {
val generatedKey = UByteArray(crypto_secretstream_xchacha20poly1305_KEYBYTES)
val generatedKeyPinned = generatedKey.pin()
crypto_secretstream_xchacha20poly1305_keygen(generatedKeyPinned.toPtr())
generatedKeyPinned.unpin()
return generatedKey
}
actual fun xChaCha20Poly1305Rekey(state: SecretStreamState) {
crypto_secretstream_xchacha20poly1305_rekey(state.ptr)
}
}