diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 1064f29..6388806 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -120,4 +120,9 @@ expect object AuthenticatedEncryptionWithAssociatedData { key: UByteArray ): UByteArray + + fun xChaCha20Poly1305IetfKeygen() : UByteArray + fun chaCha20Poly1305IetfKeygen() : UByteArray + fun chaCha20Poly1305Keygen() : UByteArray + } diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index c821572..e214503 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -44,9 +44,9 @@ interface JsSodiumInterface { fun crypto_hash_sha512_final(state: dynamic): Uint8Array - //XChaCha20Poly1305 - fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array - fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, associatedData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array + //XChaCha20Poly1305 - also in bindings + //fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array + //fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, associatedData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array //XChaCha20Poly1305 //encrypt @@ -71,6 +71,26 @@ interface JsSodiumInterface { // ---- SecretBox End ---- + + // ---- AEAD ---- + fun crypto_aead_chacha20poly1305_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array + fun crypto_aead_chacha20poly1305_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array + fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array + fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array + fun crypto_aead_chacha20poly1305_ietf_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array + fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array + fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array + fun crypto_aead_chacha20poly1305_keygen() : Uint8Array + fun crypto_aead_xchacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array + fun crypto_aead_xchacha20poly1305_ietf_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array + fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array + fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array + + // ---- AEAD end ---- + //util fun memzero(array: Uint8Array) diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 332f9a4..846ccb7 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -1,5 +1,10 @@ package com.ionspin.kotlin.crypto.aead +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +import org.khronos.webgl.Uint8Array + actual object AuthenticatedEncryptionWithAssociatedData { // Ietf @@ -11,7 +16,13 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + return getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ).toUByteArray() } actual fun xChaCha20Poly1305IetfDecrypt( @@ -20,7 +31,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + try { + return getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt( + null, + ciphertext.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } } actual fun xChaCha20Poly1305IetfEncryptDetached( @@ -29,7 +50,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): AeadEncryptedDataAndTag { - TODO("not implemented yet") + val result = getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt_detached( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ) + return AeadEncryptedDataAndTag( + (result.ciphertext as Uint8Array).toUByteArray(), + (result.mac as Uint8Array).toUByteArray() + ) } actual fun xChaCha20Poly1305IetfDecryptDetached( @@ -39,7 +70,18 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + try { + return getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt_detached( + null, + ciphertext.toUInt8Array(), + tag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } } actual fun chaCha20Poly1305IetfEncrypt( @@ -48,7 +90,13 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + return getSodium().crypto_aead_chacha20poly1305_ietf_encrypt( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ).toUByteArray() } actual fun chaCha20Poly1305IetfDecrypt( @@ -57,7 +105,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + try { + return getSodium().crypto_aead_chacha20poly1305_ietf_decrypt( + null, + ciphertext.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } } actual fun chaCha20Poly1305IetfEncryptDetached( @@ -66,7 +124,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): AeadEncryptedDataAndTag { - TODO("not implemented yet") + val result = getSodium().crypto_aead_chacha20poly1305_ietf_encrypt_detached( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ) + return AeadEncryptedDataAndTag( + (result.ciphertext as Uint8Array).toUByteArray(), + (result.mac as Uint8Array).toUByteArray() + ) } actual fun chaCha20Poly1305IetfDecryptDetached( @@ -76,7 +144,18 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + try { + return getSodium().crypto_aead_chacha20poly1305_ietf_decrypt_detached( + null, + ciphertext.toUInt8Array(), + tag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } } actual fun chaCha20Poly1305Encrypt( @@ -85,7 +164,13 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + return getSodium().crypto_aead_chacha20poly1305_encrypt( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ).toUByteArray() } actual fun chaCha20Poly1305Decrypt( @@ -94,7 +179,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + try { + return getSodium().crypto_aead_chacha20poly1305_decrypt( + null, + ciphertext.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } } actual fun chaCha20Poly1305EncryptDetached( @@ -103,7 +198,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): AeadEncryptedDataAndTag { - TODO("not implemented yet") + val result = getSodium().crypto_aead_chacha20poly1305_encrypt_detached( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ) + return AeadEncryptedDataAndTag( + (result.ciphertext as Uint8Array).toUByteArray(), + (result.mac as Uint8Array).toUByteArray() + ) } actual fun chaCha20Poly1305DecryptDetached( @@ -113,7 +218,30 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + try { + return getSodium().crypto_aead_chacha20poly1305_decrypt_detached( + null, + ciphertext.toUInt8Array(), + tag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } + } + + actual fun xChaCha20Poly1305IetfKeygen(): UByteArray { + return getSodium().crypto_aead_xchacha20poly1305_ietf_keygen().toUByteArray() + } + + actual fun chaCha20Poly1305IetfKeygen(): UByteArray { + return getSodium().crypto_aead_chacha20poly1305_ietf_keygen().toUByteArray() + } + + actual fun chaCha20Poly1305Keygen(): UByteArray { + return getSodium().crypto_aead_chacha20poly1305_keygen().toUByteArray() } } diff --git a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 332f9a4..8fa92fd 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -1,5 +1,7 @@ package com.ionspin.kotlin.crypto.aead +import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium + actual object AuthenticatedEncryptionWithAssociatedData { // Ietf @@ -11,7 +13,19 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val ciphertext = UByteArray(message.size + crypto_aead_xchacha20poly1305_ietf_ABYTES) + sodium.crypto_aead_xchacha20poly1305_ietf_encrypt( + ciphertext.asByteArray(), + null, + message.asByteArray(), + message.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + null, + nonce.asByteArray(), + key.asByteArray(), + ) + return ciphertext } actual fun xChaCha20Poly1305IetfDecrypt( @@ -20,7 +34,22 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val message = UByteArray(ciphertext.size - crypto_aead_xchacha20poly1305_ietf_ABYTES) + val validationResult = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt( + message.asByteArray(), + null, + null, + ciphertext.asByteArray(), + ciphertext.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + nonce.asByteArray(), + key.asByteArray(), + ) + if (validationResult != 0) { + throw AeadCorrupedOrTamperedDataException() + } + return message } actual fun xChaCha20Poly1305IetfEncryptDetached( @@ -29,7 +58,21 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): AeadEncryptedDataAndTag { - TODO("not implemented yet") + val ciphertext = UByteArray(message.size) + val authenticationTag = UByteArray(crypto_aead_xchacha20poly1305_ietf_ABYTES) + sodium.crypto_aead_xchacha20poly1305_ietf_encrypt_detached( + ciphertext.asByteArray(), + authenticationTag.asByteArray(), + null, + message.asByteArray(), + message.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + null, + nonce.asByteArray(), + key.asByteArray(), + ) + return AeadEncryptedDataAndTag(ciphertext, authenticationTag) } actual fun xChaCha20Poly1305IetfDecryptDetached( @@ -39,7 +82,22 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val message = UByteArray(ciphertext.size) + val validationResult = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt_detached( + message.asByteArray(), + null, + ciphertext.asByteArray(), + ciphertext.size.toLong(), + tag.asByteArray(), + associatedData.asByteArray(), + associatedData.size.toLong(), + nonce.asByteArray(), + key.asByteArray(), + ) + if (validationResult != 0) { + throw AeadCorrupedOrTamperedDataException() + } + return message } actual fun chaCha20Poly1305IetfEncrypt( @@ -48,7 +106,19 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val ciphertext = UByteArray(message.size + crypto_aead_chacha20poly1305_ietf_ABYTES) + sodium.crypto_aead_chacha20poly1305_ietf_encrypt( + ciphertext.asByteArray(), + null, + message.asByteArray(), + message.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + null, + nonce.asByteArray(), + key.asByteArray(), + ) + return ciphertext } actual fun chaCha20Poly1305IetfDecrypt( @@ -57,7 +127,22 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val message = UByteArray(ciphertext.size - crypto_aead_chacha20poly1305_ietf_ABYTES) + val validationResult = sodium.crypto_aead_chacha20poly1305_ietf_decrypt( + message.asByteArray(), + null, + null, + ciphertext.asByteArray(), + ciphertext.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + nonce.asByteArray(), + key.asByteArray(), + ) + if (validationResult != 0) { + throw AeadCorrupedOrTamperedDataException() + } + return message } actual fun chaCha20Poly1305IetfEncryptDetached( @@ -66,7 +151,21 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): AeadEncryptedDataAndTag { - TODO("not implemented yet") + val ciphertext = UByteArray(message.size) + val authenticationTag = UByteArray(crypto_aead_chacha20poly1305_ietf_ABYTES) + sodium.crypto_aead_chacha20poly1305_ietf_encrypt_detached( + ciphertext.asByteArray(), + authenticationTag.asByteArray(), + null, + message.asByteArray(), + message.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + null, + nonce.asByteArray(), + key.asByteArray(), + ) + return AeadEncryptedDataAndTag(ciphertext, authenticationTag) } actual fun chaCha20Poly1305IetfDecryptDetached( @@ -76,7 +175,22 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val message = UByteArray(ciphertext.size) + val validationResult = sodium.crypto_aead_chacha20poly1305_ietf_decrypt_detached( + message.asByteArray(), + null, + ciphertext.asByteArray(), + ciphertext.size.toLong(), + tag.asByteArray(), + associatedData.asByteArray(), + associatedData.size.toLong(), + nonce.asByteArray(), + key.asByteArray(), + ) + if (validationResult != 0) { + throw AeadCorrupedOrTamperedDataException() + } + return message } actual fun chaCha20Poly1305Encrypt( @@ -85,7 +199,19 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val ciphertext = UByteArray(message.size + crypto_aead_chacha20poly1305_ABYTES) + sodium.crypto_aead_chacha20poly1305_encrypt( + ciphertext.asByteArray(), + null, + message.asByteArray(), + message.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + null, + nonce.asByteArray(), + key.asByteArray(), + ) + return ciphertext } actual fun chaCha20Poly1305Decrypt( @@ -94,7 +220,22 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val message = UByteArray(ciphertext.size - crypto_aead_chacha20poly1305_ABYTES) + val validationResult = sodium.crypto_aead_chacha20poly1305_decrypt( + message.asByteArray(), + null, + null, + ciphertext.asByteArray(), + ciphertext.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + nonce.asByteArray(), + key.asByteArray(), + ) + if (validationResult != 0) { + throw AeadCorrupedOrTamperedDataException() + } + return message } actual fun chaCha20Poly1305EncryptDetached( @@ -103,7 +244,21 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): AeadEncryptedDataAndTag { - TODO("not implemented yet") + val ciphertext = UByteArray(message.size) + val authenticationTag = UByteArray(crypto_aead_chacha20poly1305_ABYTES) + sodium.crypto_aead_chacha20poly1305_encrypt_detached( + ciphertext.asByteArray(), + authenticationTag.asByteArray(), + null, + message.asByteArray(), + message.size.toLong(), + associatedData.asByteArray(), + associatedData.size.toLong(), + null, + nonce.asByteArray(), + key.asByteArray(), + ) + return AeadEncryptedDataAndTag(ciphertext, authenticationTag) } actual fun chaCha20Poly1305DecryptDetached( @@ -113,7 +268,40 @@ actual object AuthenticatedEncryptionWithAssociatedData { nonce: UByteArray, key: UByteArray ): UByteArray { - TODO("not implemented yet") + val message = UByteArray(ciphertext.size) + val validationResult = sodium.crypto_aead_chacha20poly1305_decrypt_detached( + message.asByteArray(), + null, + ciphertext.asByteArray(), + ciphertext.size.toLong(), + tag.asByteArray(), + associatedData.asByteArray(), + associatedData.size.toLong(), + nonce.asByteArray(), + key.asByteArray(), + ) + if (validationResult != 0) { + throw AeadCorrupedOrTamperedDataException() + } + return message + } + + actual fun xChaCha20Poly1305IetfKeygen(): UByteArray { + val generatedKey = UByteArray(crypto_aead_xchacha20poly1305_ietf_KEYBYTES) + sodium.crypto_aead_xchacha20poly1305_ietf_keygen(generatedKey.asByteArray()) + return generatedKey + } + + actual fun chaCha20Poly1305IetfKeygen(): UByteArray { + val generatedKey = UByteArray(crypto_aead_chacha20poly1305_ietf_KEYBYTES) + sodium.crypto_aead_chacha20poly1305_ietf_keygen(generatedKey.asByteArray()) + return generatedKey + } + + actual fun chaCha20Poly1305Keygen(): UByteArray { + val generatedKey = UByteArray(crypto_aead_chacha20poly1305_KEYBYTES) + sodium.crypto_aead_chacha20poly1305_keygen(generatedKey.asByteArray()) + return generatedKey } } diff --git a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 71c127c..6d0531d 100644 --- a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -11,10 +11,13 @@ import libsodium.crypto_aead_chacha20poly1305_ietf_decrypt import libsodium.crypto_aead_chacha20poly1305_ietf_decrypt_detached import libsodium.crypto_aead_chacha20poly1305_ietf_encrypt import libsodium.crypto_aead_chacha20poly1305_ietf_encrypt_detached +import libsodium.crypto_aead_chacha20poly1305_ietf_keygen +import libsodium.crypto_aead_chacha20poly1305_keygen import libsodium.crypto_aead_xchacha20poly1305_ietf_decrypt import libsodium.crypto_aead_xchacha20poly1305_ietf_decrypt_detached import libsodium.crypto_aead_xchacha20poly1305_ietf_encrypt import libsodium.crypto_aead_xchacha20poly1305_ietf_encrypt_detached +import libsodium.crypto_aead_xchacha20poly1305_ietf_keygen actual object AuthenticatedEncryptionWithAssociatedData { @@ -504,4 +507,28 @@ actual object AuthenticatedEncryptionWithAssociatedData { return message } + actual fun xChaCha20Poly1305IetfKeygen(): UByteArray { + val generatedKey = UByteArray(crypto_aead_xchacha20poly1305_ietf_KEYBYTES) + val generatedKeyPinned = generatedKey.pin() + crypto_aead_xchacha20poly1305_ietf_keygen(generatedKeyPinned.toPtr()) + generatedKeyPinned.unpin() + return generatedKey + } + + actual fun chaCha20Poly1305IetfKeygen(): UByteArray { + val generatedKey = UByteArray(crypto_aead_chacha20poly1305_ietf_KEYBYTES) + val generatedKeyPinned = generatedKey.pin() + crypto_aead_chacha20poly1305_ietf_keygen(generatedKeyPinned.toPtr()) + generatedKeyPinned.unpin() + return generatedKey + } + + actual fun chaCha20Poly1305Keygen(): UByteArray { + val generatedKey = UByteArray(crypto_aead_chacha20poly1305_KEYBYTES) + val generatedKeyPinned = generatedKey.pin() + crypto_aead_chacha20poly1305_keygen(generatedKeyPinned.toPtr()) + generatedKeyPinned.unpin() + return generatedKey + } + }