implement block property
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user