make Keccak an open class
All checks were successful
/ test (pull_request) Successful in 45s

This commit is contained in:
2026-01-15 22:36:58 +01:00
parent d06674c28c
commit 681f2146b4

View File

@@ -6,11 +6,16 @@ import com.infendro.bytes.long.copyInto
import com.infendro.hash.HashFunction import com.infendro.hash.HashFunction
import com.infendro.hash.util.ceil import com.infendro.hash.util.ceil
abstract class Keccak( open class Keccak(
override val bytes: Int, override val bytes: Int,
private val rate: Int, private val rate: Int,
private val domain: Byte, private val domain: Byte,
) : HashFunction { ) : HashFunction {
init {
require(bytes > 0)
require(rate in 8..192 step 8)
}
override val block: Int override val block: Int
get() = rate get() = rate
@@ -64,10 +69,12 @@ abstract class Keccak(
private fun squeeze(state: LongArray, b: LongArray, c: LongArray, d: LongArray, destination: ByteArray) { private fun squeeze(state: LongArray, b: LongArray, c: LongArray, d: LongArray, destination: ByteArray) {
val buffer = ByteArray(8) val buffer = ByteArray(8)
val threshold = rate / 8
var consumed = 0 var consumed = 0
var i = 0 var i = 0
while (consumed < bytes) { while (consumed < bytes) {
if (i == rate / 8) { if (i == threshold) {
permute(state, b, c, d) permute(state, b, c, d)
i = 0 i = 0
} }