diff --git a/src/commonMain/kotlin/com/infendro/hash/HashFunction.kt b/src/commonMain/kotlin/com/infendro/hash/HashFunction.kt index d7aef53..47d6013 100644 --- a/src/commonMain/kotlin/com/infendro/hash/HashFunction.kt +++ b/src/commonMain/kotlin/com/infendro/hash/HashFunction.kt @@ -1,6 +1,10 @@ package com.infendro.hash sealed class HashFunction { + abstract val bytes: Int + val bits: Int + get() = bytes * 8 + abstract fun hash( value: ByteArray, ): ByteArray diff --git a/src/commonMain/kotlin/com/infendro/hash/MD5.kt b/src/commonMain/kotlin/com/infendro/hash/MD5.kt index c2eea38..0a51ced 100644 --- a/src/commonMain/kotlin/com/infendro/hash/MD5.kt +++ b/src/commonMain/kotlin/com/infendro/hash/MD5.kt @@ -6,6 +6,9 @@ import com.infendro.hash.util.toByteArray import com.infendro.hash.util.toUIntArray object MD5 : HashFunction() { + override val bytes: Int + get() = 16 + private val s = arrayOf( 7, 12, 17, 22, 7, 12, 17, 22, diff --git a/src/commonMain/kotlin/com/infendro/hash/SHA1.kt b/src/commonMain/kotlin/com/infendro/hash/SHA1.kt index d2ca6cb..744cabd 100644 --- a/src/commonMain/kotlin/com/infendro/hash/SHA1.kt +++ b/src/commonMain/kotlin/com/infendro/hash/SHA1.kt @@ -5,6 +5,9 @@ import com.infendro.hash.util.toByteArray import com.infendro.hash.util.toUIntArray object SHA1 : HashFunction() { + override val bytes: Int + get() = 20 + override fun hash( value: ByteArray, ): ByteArray { diff --git a/src/commonMain/kotlin/com/infendro/hash/SHA224.kt b/src/commonMain/kotlin/com/infendro/hash/SHA224.kt index 31b29ef..9cb74bb 100644 --- a/src/commonMain/kotlin/com/infendro/hash/SHA224.kt +++ b/src/commonMain/kotlin/com/infendro/hash/SHA224.kt @@ -5,6 +5,9 @@ import com.infendro.hash.util.toByteArray import com.infendro.hash.util.toUIntArray object SHA224 : HashFunction() { + override val bytes: Int + get() = 28 + private val k = arrayOf( 0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U, 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U, diff --git a/src/commonMain/kotlin/com/infendro/hash/SHA256.kt b/src/commonMain/kotlin/com/infendro/hash/SHA256.kt index 46f69a6..bbed26d 100644 --- a/src/commonMain/kotlin/com/infendro/hash/SHA256.kt +++ b/src/commonMain/kotlin/com/infendro/hash/SHA256.kt @@ -5,6 +5,9 @@ import com.infendro.hash.util.toByteArray import com.infendro.hash.util.toUIntArray object SHA256 : HashFunction() { + override val bytes: Int + get() = 32 + private val k = arrayOf( 0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U, 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U, diff --git a/src/commonMain/kotlin/com/infendro/hash/SHA384.kt b/src/commonMain/kotlin/com/infendro/hash/SHA384.kt index d069bd4..93a2bea 100644 --- a/src/commonMain/kotlin/com/infendro/hash/SHA384.kt +++ b/src/commonMain/kotlin/com/infendro/hash/SHA384.kt @@ -5,6 +5,9 @@ import com.infendro.hash.util.toByteArray import com.infendro.hash.util.toULongArray object SHA384 : HashFunction() { + override val bytes: Int + get() = 48 + private val k = arrayOf( 0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL, 0x3956c25bf348b538UL, 0x59f111f1b605d019UL, 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL, 0xd807aa98a3030242UL, 0x12835b0145706fbeUL, diff --git a/src/commonMain/kotlin/com/infendro/hash/SHA512.kt b/src/commonMain/kotlin/com/infendro/hash/SHA512.kt index b3f45ad..92b5404 100644 --- a/src/commonMain/kotlin/com/infendro/hash/SHA512.kt +++ b/src/commonMain/kotlin/com/infendro/hash/SHA512.kt @@ -5,6 +5,9 @@ import com.infendro.hash.util.toByteArray import com.infendro.hash.util.toULongArray object SHA512 : HashFunction() { + override val bytes: Int + get() = 64 + private val k = arrayOf( 0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL, 0x3956c25bf348b538UL, 0x59f111f1b605d019UL, 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL, 0xd807aa98a3030242UL, 0x12835b0145706fbeUL,