This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.infendro.hash.blake
|
||||
|
||||
import com.infendro.bytes.intarray.copyInto
|
||||
import com.infendro.bytes.ulong.copyInto
|
||||
import com.infendro.bytes.long.copyInto
|
||||
import com.infendro.hash.HashFunction
|
||||
import com.infendro.hash.util.align
|
||||
|
||||
@@ -20,13 +20,13 @@ object `Blake-224` : HashFunction {
|
||||
)
|
||||
|
||||
override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
|
||||
val length = value.size.toULong() * 8UL
|
||||
val length = value.size * 8L
|
||||
val input = pad(value)
|
||||
val h = initial.copyOf()
|
||||
var t = 0U
|
||||
var t = 0
|
||||
|
||||
for (i in input.indices step block) {
|
||||
t += minOf(length - t, 512UL).toUInt()
|
||||
t += minOf(length - t, 512).toInt()
|
||||
val block = input.sliceArray(i..<(i + block))
|
||||
`Blake-256`.compress(h, block, t)
|
||||
}
|
||||
@@ -34,12 +34,12 @@ object `Blake-224` : HashFunction {
|
||||
}
|
||||
|
||||
private fun pad(value: ByteArray): ByteArray {
|
||||
val length = value.size.toULong() * 8UL
|
||||
val length = value.size * 8L
|
||||
|
||||
val size = (value.size + 9).align(block)
|
||||
return ByteArray(size).also {
|
||||
value.copyInto(it)
|
||||
it[value.size] = 0x80U.toByte()
|
||||
it[value.size] = -0x80
|
||||
length.copyInto(it, size - 8)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user