refactor keccak functions
This commit is contained in:
@@ -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..<min(bytes - size, 8))
|
||||
)
|
||||
}
|
||||
}.toUByteArray()
|
||||
|
||||
Reference in New Issue
Block a user