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.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.testBlocking import com.ionspin.kotlin.crypto.util.testBlocking
import kotlin.test.BeforeTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -15,13 +14,10 @@ import kotlin.test.assertTrue
*/ */
class SecretStreamTest { class SecretStreamTest {
@BeforeTest
fun initialize() = testBlocking {
LibsodiumInitializer.initialize()
}
@Test @Test
fun testSecretStream() = testBlocking { fun testSecretStream() = testBlocking {
LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "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, additionalData: UByteArray,
tag: UByte tag: UByte
): UByteArray { ): UByteArray {
val ciphertext = UByteArray(message.size) val ciphertext = UByteArray(message.size + 17)
sodium.crypto_secretstream_xchacha20poly1305_push( sodium.crypto_secretstream_xchacha20poly1305_push(
state, state,
ciphertext.asByteArray(), ciphertext.asByteArray(),
@ -47,7 +47,7 @@ actual object SecretStream {
ciphertext: UByteArray, ciphertext: UByteArray,
additionalData: UByteArray additionalData: UByteArray
): DecryptedDataAndTag { ): DecryptedDataAndTag {
val result = UByteArray(ciphertext.size) val result = UByteArray(ciphertext.size - 17)
val tagArray = UByteArray(1) { 0U } val tagArray = UByteArray(1) { 0U }
sodium.crypto_secretstream_xchacha20poly1305_pull( sodium.crypto_secretstream_xchacha20poly1305_pull(
state, state,