Compare commits

...

2 Commits

Author SHA1 Message Date
9b93fbd093 bump version to 1.3.1
All checks were successful
/ publish (push) Successful in 2m42s
2025-11-10 14:44:55 +01:00
2051c3fcbd implement block property 2025-11-10 14:44:32 +01:00
9 changed files with 25 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
group = "com.infendro"
version = "1.3.0"
version = "1.3.1"
repositories {
maven("https://git.infendro.com/api/packages/Infendro/maven")

View File

@@ -7,6 +7,8 @@ abstract class HashFunction {
val bits: Int
get() = bytes * 8
abstract val block: Int
abstract fun hash(
value: UByteArray,
): UByteArray

View File

@@ -9,7 +9,7 @@ import kotlin.math.min
@Suppress("UNUSED")
open class Keccak internal constructor(
override val bytes: Int,
private val rate: Int,
override val block: Int,
private val domain: UByte,
) : HashFunction() {
private val rc = ulongArrayOf(
@@ -35,7 +35,7 @@ open class Keccak internal constructor(
val paddedValue = buildList {
addAll(value)
add(domain)
while ((size % rate) != (rate - 1)) {
while ((size % block) != (block - 1)) {
add(0x00U)
}
add(0x80U)
@@ -45,7 +45,7 @@ open class Keccak internal constructor(
// absorb
val chunks = paddedValue
.chunked(rate) { it.toUByteArray() }
.chunked(block) { it.toUByteArray() }
for (chunk in chunks) {
val numbers = chunk.toULongArray(LITTLE_ENDIAN)
for ((i, number) in numbers.withIndex()) {
@@ -58,7 +58,7 @@ open class Keccak internal constructor(
return buildList {
var i = 0
while (size < bytes) {
if (i == rate / 8) {
if (i == block / 8) {
permute(state)
i = 0
}

View File

@@ -10,6 +10,9 @@ object MD5 : HashFunction() {
override val bytes: Int
get() = 16
override val block: Int
get() = 64
private val s = intArrayOf(
7, 12, 17, 22,
7, 12, 17, 22,

View File

@@ -9,6 +9,9 @@ object SHA1 : HashFunction() {
override val bytes: Int
get() = 20
override val block: Int
get() = 64
override fun hash(
value: UByteArray,
): UByteArray {

View File

@@ -9,6 +9,9 @@ object `SHA-224` : HashFunction() {
override val bytes: Int
get() = 28
override val block: Int
get() = 64
private val k = uintArrayOf(
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U,
0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U,

View File

@@ -9,6 +9,9 @@ object `SHA-256` : HashFunction() {
override val bytes: Int
get() = 32
override val block: Int
get() = 64
private val k = uintArrayOf(
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U,
0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U,

View File

@@ -9,6 +9,9 @@ object `SHA-384` : HashFunction() {
override val bytes: Int
get() = 48
override val block: Int
get() = 128
private val k = ulongArrayOf(
0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL, 0x3956c25bf348b538UL,
0x59f111f1b605d019UL, 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL, 0xd807aa98a3030242UL, 0x12835b0145706fbeUL,

View File

@@ -9,6 +9,9 @@ object `SHA-512` : HashFunction() {
override val bytes: Int
get() = 64
override val block: Int
get() = 128
private val k = ulongArrayOf(
0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL, 0x3956c25bf348b538UL,
0x59f111f1b605d019UL, 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL, 0xd807aa98a3030242UL, 0x12835b0145706fbeUL,