implement destination offset
All checks were successful
/ test (pull_request) Successful in 27s

This commit is contained in:
2026-01-22 12:18:22 +01:00
parent b00d231da5
commit 8535476674
16 changed files with 41 additions and 34 deletions

View File

@@ -36,7 +36,7 @@ open class Keccak(
intArrayOf(27, 20, 39, 8, 14),
)
override fun hashInto(value: ByteArray, destination: ByteArray) {
override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = pad(value)
val state = LongArray(25)
val w = LongArray(block / 8)
@@ -48,7 +48,7 @@ open class Keccak(
absorb(state, input, i, w)
permute(state, b, c, d)
}
squeeze(state, b, c, d, destination)
squeeze(state, b, c, d, destination, destinationOffset)
}
private fun pad(value: ByteArray): ByteArray {
@@ -67,7 +67,14 @@ open 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,
destinationOffset: Int,
) {
val buffer = ByteArray(8)
val threshold = rate / 8
@@ -81,7 +88,7 @@ open class Keccak(
val length = minOf(bytes - consumed, 8)
state[i].copyInto(buffer, order = LITTLE_ENDIAN)
buffer.copyInto(destination, consumed, endIndex = length)
buffer.copyInto(destination, destinationOffset + consumed, endIndex = length)
consumed += length
i++