diff --git a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt index adfbbed..0daec9d 100644 --- a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt +++ b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt @@ -39,11 +39,6 @@ interface UpdatableHash : Hash { interface StatelessHash : Hash { - fun digest( - inputMessage: UByteArray = ubyteArrayOf(), - key: UByteArray = ubyteArrayOf(), - hashLength: Int = MAX_HASH_BYTES - ): UByteArray } fun String.encodeToUByteArray() : UByteArray{ diff --git a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2b.kt b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2b.kt index 29d461b..cac59c5 100644 --- a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2b.kt +++ b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2b.kt @@ -21,5 +21,11 @@ interface Blake2b : UpdatableHash { interface Blake2bStateless : StatelessHash { override val MAX_HASH_BYTES: Int get() = Blake2bProperties.MAX_HASH_BYTES + + fun digest( + inputMessage: UByteArray = ubyteArrayOf(), + key: UByteArray = ubyteArrayOf(), + hashLength: Int = MAX_HASH_BYTES + ): UByteArray } diff --git a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256.kt b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256.kt index 9940846..6097f3a 100644 --- a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256.kt +++ b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256.kt @@ -19,4 +19,8 @@ interface Sha256 : UpdatableHash { interface StatelessSha256 : StatelessHash { override val MAX_HASH_BYTES: Int get() = Sha256Properties.MAX_HASH_BYTES + + fun digest( + inputMessage: UByteArray = ubyteArrayOf() + ): UByteArray } \ No newline at end of file diff --git a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512.kt b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512.kt index 1cba4c9..b77b567 100644 --- a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512.kt +++ b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512.kt @@ -18,4 +18,8 @@ interface Sha512 : UpdatableHash { interface StatelessSha512 : StatelessHash { override val MAX_HASH_BYTES: Int get() = Sha256Properties.MAX_HASH_BYTES + + fun digest( + inputMessage: UByteArray = ubyteArrayOf() + ): UByteArray } \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt index 22185a0..88aeb14 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt @@ -24,7 +24,7 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In actual object Sha256StatelessDelegated : StatelessSha256 { - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { + override fun digest(inputMessage: UByteArray): UByteArray { TODO("not implemented yet") } } \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index fa313ca..e009d55 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -24,7 +24,7 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In actual object Sha512StatelessDelegated : StatelessSha512 { - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { + override fun digest(inputMessage: UByteArray): UByteArray { TODO("not implemented yet") } } \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt index 81e110f..29a3d57 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt @@ -26,7 +26,7 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In actual object Sha256StatelessDelegated : StatelessSha256 { - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { + override fun digest(inputMessage: UByteArray): UByteArray { TODO("not implemented yet") } } \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index fa313ca..e009d55 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -24,7 +24,7 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In actual object Sha512StatelessDelegated : StatelessSha512 { - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { + override fun digest(inputMessage: UByteArray): UByteArray { TODO("not implemented yet") } } \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt index 0f3e0a6..89736f8 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt @@ -1,5 +1,8 @@ package com.ionspin.kotlin.crypto.hash.sha +import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegatedStateless +import kotlinx.cinterop.pin + /** * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com @@ -27,7 +30,9 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In } actual object Sha256StatelessDelegated : StatelessSha256 { - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { + override fun digest(inputMessage: UByteArray): UByteArray { + val hashResult = UByteArray(Blake2bDelegatedStateless.MAX_HASH_BYTES) + val hashResultPinned = hashResult.pin() TODO("not implemented yet") } diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index fa313ca..e009d55 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -24,7 +24,7 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In actual object Sha512StatelessDelegated : StatelessSha512 { - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { + override fun digest(inputMessage: UByteArray): UByteArray { TODO("not implemented yet") } } \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt index 8e8dd3a..9425620 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt @@ -64,14 +64,7 @@ class Sha256Pure : Sha256 { ) - fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { - return digest( - inputString.encodeToByteArray().toUByteArray(), - key?.run { encodeToByteArray().toUByteArray()} ?: ubyteArrayOf(), - hashLength) - } - - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { + override fun digest(inputMessage: UByteArray): UByteArray { var h = iv.copyOf() diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt index 170609c..3c839d6 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt @@ -132,7 +132,7 @@ class Sha512Pure : Sha512 { ) - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { + override fun digest(inputMessage: UByteArray): UByteArray { var h = iv.copyOf()