1.5.0 release #7
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user