Same thing for JVM, forgot about tag length

This commit is contained in:
Ugljesa Jovanovic 2020-08-27 22:09:42 +02:00 committed by Ugljesa Jovanovic
parent 89e5ae62e4
commit 86611453ea
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
2 changed files with 56 additions and 59 deletions

View File

@ -4,7 +4,6 @@ import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.testBlocking
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertTrue
@ -15,13 +14,10 @@ import kotlin.test.assertTrue
*/
class SecretStreamTest {
@BeforeTest
fun initialize() = testBlocking {
LibsodiumInitializer.initialize()
}
@Test
fun testSecretStream() = testBlocking {
LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
"only one tip for the future, sunscreen would be it.").encodeToUByteArray()
@ -80,6 +76,7 @@ class SecretStreamTest {
}
}
}

View File

@ -19,7 +19,7 @@ actual object SecretStream {
additionalData: UByteArray,
tag: UByte
): UByteArray {
val ciphertext = UByteArray(message.size)
val ciphertext = UByteArray(message.size + 17)
sodium.crypto_secretstream_xchacha20poly1305_push(
state,
ciphertext.asByteArray(),
@ -47,7 +47,7 @@ actual object SecretStream {
ciphertext: UByteArray,
additionalData: UByteArray
): DecryptedDataAndTag {
val result = UByteArray(ciphertext.size)
val result = UByteArray(ciphertext.size - 17)
val tagArray = UByteArray(1) { 0U }
sodium.crypto_secretstream_xchacha20poly1305_pull(
state,