diff --git a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/JnaLibsodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/JnaLibsodiumInterface.kt index 71879e2..1496a43 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/JnaLibsodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/JnaLibsodiumInterface.kt @@ -564,19 +564,66 @@ interface JnaLibsodiumInterface : Library { // ---- Secret stream end ----- // // // ---- SecretBox ---- -// fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic -// fun crypto_secretbox_easy(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array -// fun crypto_secretbox_keygen() : Uint8Array -// fun crypto_secretbox_open_detached(ciphertext : Uint8Array, tag : Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic -// fun crypto_secretbox_open_easy(ciphertext : Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic -// -// -// // ---- SecretBox End ---- -// -// -// // ---- AEAD ---- -// + // int crypto_secretbox_detached( + // unsigned char *c, unsigned char *mac, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *n, + // const unsigned char *k) + fun crypto_secretbox_detached( + ciphertext: ByteArray, + mac: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int + + // int crypto_secretbox_easy( + // unsigned char *c, const unsigned char *m, + // unsigned long long mlen, const unsigned char *n, + // const unsigned char *k) + fun crypto_secretbox_easy( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int + + // void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES]) + fun crypto_secretbox_keygen(key: ByteArray) + + // int crypto_secretbox_open_detached( + // unsigned char *m, + // const unsigned char *c, + // const unsigned char *mac, + // unsigned long long clen, + // const unsigned char *n, + // const unsigned char *k) + fun crypto_secretbox_open_detached( + message: ByteArray, + ciphertext: ByteArray, + mac: ByteArray, + ciphertextLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int + // int crypto_secretbox_open_easy( + // unsigned char *m, const unsigned char *c, + // unsigned long long clen, const unsigned char *n, + // const unsigned char *k) + fun crypto_secretbox_open_easy( + message: ByteArray, + ciphertext: ByteArray, + ciphertextLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int + +// // ---- SecretBox End ---- + // // ---- Auth ---- // // fun crypto_auth(message: Uint8Array, key: Uint8Array) : Uint8Array diff --git a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt index 8f113e6..c2e63b9 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt @@ -1,11 +1,11 @@ package com.ionspin.kotlin.crypto.secretbox -import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium +import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna actual object SecretBox { actual fun easy(message: UByteArray, nonce: UByteArray, key: UByteArray): UByteArray { val ciphertext = UByteArray(message.size + crypto_secretbox_MACBYTES) - sodium.crypto_secretbox_easy( + sodiumJna.crypto_secretbox_easy( ciphertext.asByteArray(), message.asByteArray(), message.size.toLong(), @@ -21,7 +21,7 @@ actual object SecretBox { key: UByteArray ): UByteArray { val decrypted = UByteArray(ciphertext.size - crypto_secretbox_MACBYTES) - val validationResult = sodium.crypto_secretbox_open_easy( + val validationResult = sodiumJna.crypto_secretbox_open_easy( decrypted.asByteArray(), ciphertext.asByteArray(), ciphertext.size.toLong(), @@ -41,7 +41,7 @@ actual object SecretBox { ): SecretBoxEncryptedDataAndTag { val ciphertext = UByteArray(message.size) val authenticationTag = UByteArray(crypto_secretbox_MACBYTES) - sodium.crypto_secretbox_detached( + sodiumJna.crypto_secretbox_detached( ciphertext.asByteArray(), authenticationTag.asByteArray(), message.asByteArray(), @@ -59,7 +59,7 @@ actual object SecretBox { key: UByteArray ): UByteArray { val message = UByteArray(ciphertext.size) - val validationResult = sodium.crypto_secretbox_open_detached( + val validationResult = sodiumJna.crypto_secretbox_open_detached( message.asByteArray(), ciphertext.asByteArray(), tag.asByteArray(), @@ -75,7 +75,7 @@ actual object SecretBox { actual fun keygen() : UByteArray { val generatedKey = UByteArray(crypto_secretbox_KEYBYTES) - sodium.crypto_secretbox_keygen(generatedKey.asByteArray()) + sodiumJna.crypto_secretbox_keygen(generatedKey.asByteArray()) return generatedKey }