Removed digest from stateless has interface and pushed it down, as some hashes don't support keys or different hash lengths
This commit is contained in:
parent
03275dd44c
commit
9c9383d54f
@ -39,11 +39,6 @@ interface UpdatableHash : Hash {
|
|||||||
|
|
||||||
interface StatelessHash : Hash {
|
interface StatelessHash : Hash {
|
||||||
|
|
||||||
fun digest(
|
|
||||||
inputMessage: UByteArray = ubyteArrayOf(),
|
|
||||||
key: UByteArray = ubyteArrayOf(),
|
|
||||||
hashLength: Int = MAX_HASH_BYTES
|
|
||||||
): UByteArray
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.encodeToUByteArray() : UByteArray{
|
fun String.encodeToUByteArray() : UByteArray{
|
||||||
|
@ -21,5 +21,11 @@ interface Blake2b : UpdatableHash {
|
|||||||
interface Blake2bStateless : StatelessHash {
|
interface Blake2bStateless : StatelessHash {
|
||||||
override val MAX_HASH_BYTES: Int
|
override val MAX_HASH_BYTES: Int
|
||||||
get() = Blake2bProperties.MAX_HASH_BYTES
|
get() = Blake2bProperties.MAX_HASH_BYTES
|
||||||
|
|
||||||
|
fun digest(
|
||||||
|
inputMessage: UByteArray = ubyteArrayOf(),
|
||||||
|
key: UByteArray = ubyteArrayOf(),
|
||||||
|
hashLength: Int = MAX_HASH_BYTES
|
||||||
|
): UByteArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,4 +19,8 @@ interface Sha256 : UpdatableHash {
|
|||||||
interface StatelessSha256 : StatelessHash {
|
interface StatelessSha256 : StatelessHash {
|
||||||
override val MAX_HASH_BYTES: Int
|
override val MAX_HASH_BYTES: Int
|
||||||
get() = Sha256Properties.MAX_HASH_BYTES
|
get() = Sha256Properties.MAX_HASH_BYTES
|
||||||
|
|
||||||
|
fun digest(
|
||||||
|
inputMessage: UByteArray = ubyteArrayOf()
|
||||||
|
): UByteArray
|
||||||
}
|
}
|
@ -18,4 +18,8 @@ interface Sha512 : UpdatableHash {
|
|||||||
interface StatelessSha512 : StatelessHash {
|
interface StatelessSha512 : StatelessHash {
|
||||||
override val MAX_HASH_BYTES: Int
|
override val MAX_HASH_BYTES: Int
|
||||||
get() = Sha256Properties.MAX_HASH_BYTES
|
get() = Sha256Properties.MAX_HASH_BYTES
|
||||||
|
|
||||||
|
fun digest(
|
||||||
|
inputMessage: UByteArray = ubyteArrayOf()
|
||||||
|
): UByteArray
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
|
|
||||||
actual object Sha256StatelessDelegated : StatelessSha256 {
|
actual object Sha256StatelessDelegated : StatelessSha256 {
|
||||||
|
|
||||||
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
override fun digest(inputMessage: UByteArray): UByteArray {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
|
|
||||||
actual object Sha512StatelessDelegated : StatelessSha512 {
|
actual object Sha512StatelessDelegated : StatelessSha512 {
|
||||||
|
|
||||||
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
override fun digest(inputMessage: UByteArray): UByteArray {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,7 +26,7 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
|
|
||||||
actual object Sha256StatelessDelegated : StatelessSha256 {
|
actual object Sha256StatelessDelegated : StatelessSha256 {
|
||||||
|
|
||||||
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
override fun digest(inputMessage: UByteArray): UByteArray {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
|
|
||||||
actual object Sha512StatelessDelegated : StatelessSha512 {
|
actual object Sha512StatelessDelegated : StatelessSha512 {
|
||||||
|
|
||||||
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
override fun digest(inputMessage: UByteArray): UByteArray {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package com.ionspin.kotlin.crypto.hash.sha
|
package com.ionspin.kotlin.crypto.hash.sha
|
||||||
|
|
||||||
|
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegatedStateless
|
||||||
|
import kotlinx.cinterop.pin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ugljesa Jovanovic
|
* Created by Ugljesa Jovanovic
|
||||||
* ugljesa.jovanovic@ionspin.com
|
* ugljesa.jovanovic@ionspin.com
|
||||||
@ -27,7 +30,9 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
}
|
}
|
||||||
actual object Sha256StatelessDelegated : StatelessSha256 {
|
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")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
|
|
||||||
actual object Sha512StatelessDelegated : StatelessSha512 {
|
actual object Sha512StatelessDelegated : StatelessSha512 {
|
||||||
|
|
||||||
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
override fun digest(inputMessage: UByteArray): UByteArray {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -64,14 +64,7 @@ class Sha256Pure : Sha256 {
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
fun digest(inputString: String, key: String?, hashLength: Int): UByteArray {
|
override fun digest(inputMessage: UByteArray): UByteArray {
|
||||||
return digest(
|
|
||||||
inputString.encodeToByteArray().toUByteArray(),
|
|
||||||
key?.run { encodeToByteArray().toUByteArray()} ?: ubyteArrayOf(),
|
|
||||||
hashLength)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
|
||||||
|
|
||||||
var h = iv.copyOf()
|
var h = iv.copyOf()
|
||||||
|
|
||||||
|
@ -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()
|
var h = iv.copyOf()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user