From 0d2300c47f021372549c2e3af1e3425172ebb8f5 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Sat, 7 Dec 2024 19:12:57 +0300 Subject: [PATCH] Add chacha20poly1305EncryptDetachedResult return type to corresponding functions (mac and ciphertext were fixed) --- .../com/ionspin/kotlin/crypto/JsSodiumInterface.kt | 10 +++++++--- .../kotlin/com/ionspin/kotlin/crypto/JsUtil.kt | 1 - .../aead/AuthenticatedEncryptionWithAssociatedData.kt | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index 7be5d75..b5fd28f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -13,6 +13,10 @@ import org.khronos.webgl.Uint8Array typealias UByte = Int typealias UInt = Long +external object chacha20poly1305EncryptDetachedResult : JsAny { + val ciphertext: Uint8Array + var mac: Uint8Array +} @JsModule("libsodium-wrappers-sumo") external object JsSodiumInterface { @@ -139,7 +143,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_chacha20poly1305_encrypt") fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_encrypt_detached") - fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny + fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_chacha20poly1305_ietf_decrypt") fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_decrypt_detached") @@ -147,7 +151,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_chacha20poly1305_ietf_encrypt") fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny + fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_chacha20poly1305_ietf_keygen") fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array @JsName("crypto_aead_chacha20poly1305_keygen") @@ -159,7 +163,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt") fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny + fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_xchacha20poly1305_ietf_keygen") fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt index 776af6d..2adfe0f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt @@ -9,7 +9,6 @@ import org.khronos.webgl.get * on 02-Aug-2020 */ fun UByteArray.toByteArray() : ByteArray { -// val uint8Result = ByteArray(toTypedArray()) return toByteArray() } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index c74369b..0c5ee80 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -8,7 +8,6 @@ import org.khronos.webgl.Uint8Array actual object AuthenticatedEncryptionWithAssociatedData { // Ietf - // Original chacha20poly1305 actual fun xChaCha20Poly1305IetfEncrypt( message: UByteArray, @@ -58,8 +57,8 @@ actual object AuthenticatedEncryptionWithAssociatedData { key.toUInt8Array(), ) return AeadEncryptedDataAndTag( - (result.ciphertext as Uint8Array).toUByteArray(), - (result.mac as Uint8Array).toUByteArray() + (result.ciphertext).toUByteArray(), + (result.mac).toUByteArray() ) }