Compare commits

...

2 Commits

Author SHA1 Message Date
56f1316e43 bump version to 1.2.0
All checks were successful
/ publish (push) Successful in 4m42s
2025-07-20 10:04:49 +02:00
ab3cded991 implement hash size property 2025-07-20 10:04:23 +02:00
8 changed files with 23 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
group = "com.infendro"
version = "1.1.0"
version = "1.2.0"
repositories {
mavenCentral()

View File

@@ -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

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,