From b261a341dbb3241fa0c2e51e9d2d00821c23b5f5 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Wed, 18 Nov 2020 22:36:55 +0100 Subject: [PATCH] Added auth doc --- .../build.gradle.kts | 4 ++- .../com.ionspin.kotlin.crypto/CryptoModule.md | 9 +++++- ...thenticatedEncryptionWithAssociatedData.kt | 6 ++-- .../com.ionspin.kotlin.crypto/auth/Auth.kt | 30 ++++++++++++++++++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 5c00c55..1c28462 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -610,7 +610,9 @@ tasks { // displayName.set("common") // platform.set(Platform.common) moduleDisplayName.set("Kotlin Multiplatform Libsodium Bindings") - includes.from("src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md", + includes.from( + "src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md", + "src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.md", "src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md") displayName.set("Kotlin multiplatform") } diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md index 2c3c0a5..cffee3f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md @@ -1,3 +1,10 @@ # Module Kotlin Multiplatform Libsodium Bindings -Test test test +### What +Kotlin Multiplatform Libsodium Bindings is a library providing kotlin idiomatic API to libsodium implementations on various platforms + +### Why +To provide easy to use cryptographic library, based on a well-known and audited libsodium library. T +### How +By using built from source libsodium to provide native implementations, LazySodium (JNA wrapper around libsodium) to provide +JVM and Android implementations and libsodium.js to provide node and browser implementation 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 3562073..d5737a0 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 @@ -95,7 +95,7 @@ expect object AuthenticatedEncryptionWithAssociatedData { /** * Encrypt the message and return encrypted data and tag using xChaChaPoly1305 (192 bit nonce) as - * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag]) * * @param message message to encrypt * @param associatedData associated data the won't be encrypted, but will be authenticated @@ -165,7 +165,7 @@ expect object AuthenticatedEncryptionWithAssociatedData { ): UByteArray /** * Encrypt the message and return encrypted data and tag using ChaChaPoly1305-IETF (96 bit nonce) as - * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag]) * * @param message message to encrypt * @param associatedData associated data the won't be encrypted, but will be authenticated @@ -235,7 +235,7 @@ expect object AuthenticatedEncryptionWithAssociatedData { ): UByteArray /** * Encrypt the message and return encrypted data and tag using ChaChaPoly1305 (64 bit nonce) as - * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag]) * * @param message message to encrypt * @param associatedData associated data the won't be encrypted, but will be authenticated diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt index 69a2d70..5ea7429 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt @@ -34,17 +34,45 @@ val crypto_auth_hmacsha512_BYTES = 64 * - verify - verify that the authenticatoin data (tag/mac) is correct */ expect object Auth { - + /** + * Generate a secret key, meant to be used with auth function. + */ fun authKeygen() : UByteArray + + /** + * Generate a HMAC-SHA512-256 authentication data - Message Authentication Code - tag + */ fun auth(message: UByteArray, key: UByteArray) : UByteArray + + /** + * Verify that given message, secret key and tag, a newly calculated tag matches the received HMAC-SHA512-256 tag. + */ fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean + /** + * Generate a secret key, meant to be used with auth function. + */ fun authHmacSha256Keygen() : UByteArray + /** + * Generate a HMAC-SHA256 authentication data - Message Authentication Code - tag + */ fun authHmacSha256(message: UByteArray, key: UByteArray) : UByteArray + /** + * Verify that given message, secret key and tag, a newly calculated tag matches the received HMAC-SHA256 tag. + */ fun authHmacSha256Verify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean + /** + * Generate a secret key, meant to be used with auth function. + */ fun authHmacSha512Keygen() : UByteArray + /** + * Generate a HMAC-SHA512 authentication data - Message Authentication Code - tag + */ fun authHmacSha512(message: UByteArray, key: UByteArray) : UByteArray + /** + * Verify that given message, secret key and tag, a newly calculated tag matches the received HMAC-SHA512 tag. + */ fun authHmacSha512Verify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean }