implement block property

This commit is contained in:
2025-11-10 14:44:32 +01:00
parent e5bbd9730c
commit 2051c3fcbd
8 changed files with 24 additions and 4 deletions

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
}