implement tests
Some checks failed
/ publish (push) Has been cancelled

also fix MD5
This commit is contained in:
2025-11-10 17:42:15 +01:00
parent 9b93fbd093
commit d033d895da
28 changed files with 469 additions and 30 deletions

View File

@@ -6,12 +6,13 @@ import com.infendro.bytearray.toULongArray
import com.infendro.hash.HashFunction
import kotlin.math.min
@Suppress("UNUSED")
open class Keccak internal constructor(
override val bytes: Int,
override val block: Int,
abstract class Keccak internal constructor(
private val rate: Int,
private val domain: UByte,
) : HashFunction() {
override val block: Int
get() = rate
private val rc = ulongArrayOf(
0x0000000000000001UL, 0x0000000000008082UL, 0x800000000000808aUL, 0x8000000080008000UL,
0x000000000000808bUL, 0x0000000080000001UL, 0x8000000080008081UL, 0x8000000000008009UL,
@@ -35,7 +36,7 @@ open class Keccak internal constructor(
val paddedValue = buildList {
addAll(value)
add(domain)
while ((size % block) != (block - 1)) {
while ((size % rate) != (rate - 1)) {
add(0x00U)
}
add(0x80U)
@@ -45,7 +46,7 @@ open class Keccak internal constructor(
// absorb
val chunks = paddedValue
.chunked(block) { it.toUByteArray() }
.chunked(rate) { it.toUByteArray() }
for (chunk in chunks) {
val numbers = chunk.toULongArray(LITTLE_ENDIAN)
for ((i, number) in numbers.withIndex()) {
@@ -58,7 +59,7 @@ open class Keccak internal constructor(
return buildList {
var i = 0
while (size < bytes) {
if (i == block / 8) {
if (i == rate / 8) {
permute(state)
i = 0
}