From 3ff0ad1b91f35cc5492f4e8f1aa807b118f57c56 Mon Sep 17 00:00:00 2001 From: Infendro Date: Tue, 2 Dec 2025 19:13:52 +0100 Subject: [PATCH] refactor keccak functions --- .../kotlin/com/infendro/hash/keccak/Keccak.kt | 10 ++++++++-- .../kotlin/com/infendro/hash/keccak/sha3/SHA3-224.kt | 5 +---- .../kotlin/com/infendro/hash/keccak/sha3/SHA3-256.kt | 5 +---- .../kotlin/com/infendro/hash/keccak/sha3/SHA3-384.kt | 5 +---- .../kotlin/com/infendro/hash/keccak/sha3/SHA3-512.kt | 5 +---- .../kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt | 4 ++-- .../kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt | 4 ++-- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/commonMain/kotlin/com/infendro/hash/keccak/Keccak.kt b/src/commonMain/kotlin/com/infendro/hash/keccak/Keccak.kt index 0c382eb..0365c8c 100644 --- a/src/commonMain/kotlin/com/infendro/hash/keccak/Keccak.kt +++ b/src/commonMain/kotlin/com/infendro/hash/keccak/Keccak.kt @@ -6,10 +6,16 @@ import com.infendro.bytearray.toULongArray import com.infendro.hash.HashFunction import kotlin.math.min -abstract class Keccak internal constructor( +open class Keccak( + override val bytes: Int, private val rate: Int, private val domain: UByte, ) : HashFunction() { + init { + if (bytes < 1) throw IllegalArgumentException() + if (rate !in 8..168) throw IllegalArgumentException() + } + override val block: Int get() = rate @@ -67,7 +73,7 @@ abstract class Keccak internal constructor( addAll( state[i++].toUByteArray(LITTLE_ENDIAN) - .take(min(bytes - size, 8)) + .sliceArray(0..