This commit is contained in:
@@ -37,18 +37,18 @@ class Blake2b(
|
||||
)
|
||||
|
||||
override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
|
||||
val length = value.size.toULong()
|
||||
val length = value.size.toLong()
|
||||
val input = pad(value)
|
||||
val h = initial.copyOf()
|
||||
h[0] = h[0] xor (0x01010000L or bytes.toLong())
|
||||
var t = 0UL
|
||||
var t = 0L
|
||||
|
||||
for (i in input.indices step block) {
|
||||
t += minOf(length - t, 128UL)
|
||||
t += minOf(length - t, 128)
|
||||
val block = input.sliceArray(i..<(i + block))
|
||||
compress(h, block, t, t < 1024UL)
|
||||
compress(h, block, t, t < 1024)
|
||||
}
|
||||
h.toByteArray(LITTLE_ENDIAN).copyInto(destination, destinationOffset, endIndex = bytes)
|
||||
h.toByteArray(order = LITTLE_ENDIAN).copyInto(destination, destinationOffset, endIndex = bytes)
|
||||
}
|
||||
|
||||
private fun pad(value: ByteArray): ByteArray {
|
||||
@@ -58,12 +58,12 @@ class Blake2b(
|
||||
}
|
||||
}
|
||||
|
||||
private fun compress(h: LongArray, block: ByteArray, t: ULong, last: Boolean) {
|
||||
private fun compress(h: LongArray, block: ByteArray, t: Long, last: Boolean) {
|
||||
val m = block.toLongArray()
|
||||
val v = LongArray(16)
|
||||
for (i in 0..<8) v[i] = h[i]
|
||||
for (i in 0..<8) v[i + 8] = initial[i]
|
||||
v[12] = v[12] xor t.toLong()
|
||||
v[12] = v[12] xor t
|
||||
if (last) v[14] = v[14].inv()
|
||||
|
||||
repeat(12) { r ->
|
||||
|
||||
@@ -37,18 +37,18 @@ class Blake2s(
|
||||
)
|
||||
|
||||
override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
|
||||
val length = value.size.toULong()
|
||||
val length = value.size.toLong()
|
||||
val input = pad(value)
|
||||
val h = initial.copyOf()
|
||||
h[0] = h[0] xor (0x01010000 or bytes)
|
||||
var t = 0U
|
||||
var t = 0
|
||||
|
||||
for (i in input.indices step block) {
|
||||
t += minOf(length - t, 64UL).toUInt()
|
||||
t += minOf(length - t, 64).toInt()
|
||||
val block = input.sliceArray(i..<(i + block))
|
||||
compress(h, block, t, t < 1024UL)
|
||||
compress(h, block, t, t < 1024)
|
||||
}
|
||||
h.toByteArray(LITTLE_ENDIAN).copyInto(destination, destinationOffset, endIndex = bytes)
|
||||
h.toByteArray(order = LITTLE_ENDIAN).copyInto(destination, destinationOffset, endIndex = bytes)
|
||||
}
|
||||
|
||||
private fun pad(value: ByteArray): ByteArray {
|
||||
@@ -58,12 +58,12 @@ class Blake2s(
|
||||
}
|
||||
}
|
||||
|
||||
private fun compress(h: IntArray, block: ByteArray, t: UInt, last: Boolean) {
|
||||
private fun compress(h: IntArray, block: ByteArray, t: Int, last: Boolean) {
|
||||
val m = block.toIntArray()
|
||||
val v = IntArray(16)
|
||||
for (i in 0..<8) v[i] = h[i]
|
||||
for (i in 0..<8) v[i + 8] = initial[i]
|
||||
v[12] = v[12] xor t.toInt()
|
||||
v[12] = v[12] xor t
|
||||
if (last) v[14] = v[14].inv()
|
||||
|
||||
repeat(10) { r ->
|
||||
|
||||
Reference in New Issue
Block a user