This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.infendro.hash.blake
|
||||
|
||||
import com.infendro.bytes.bytearray.copyInto
|
||||
import com.infendro.bytes.bytearray.toLongArray
|
||||
import com.infendro.bytes.longarray.copyInto
|
||||
import com.infendro.bytes.ulong.copyInto
|
||||
import com.infendro.hash.HashFunction
|
||||
@@ -13,23 +13,23 @@ object `Blake-512` : HashFunction {
|
||||
override val block: Int
|
||||
get() = 128
|
||||
|
||||
private val initial = ulongArrayOf(
|
||||
0x6a09e667f3bcc908UL, 0xbb67ae8584caa73bUL,
|
||||
0x3c6ef372fe94f82bUL, 0xa54ff53a5f1d36f1UL,
|
||||
0x510e527fade682d1UL, 0x9b05688c2b3e6c1fUL,
|
||||
0x1f83d9abfb41bd6bUL, 0x5be0cd19137e2179UL,
|
||||
).asLongArray()
|
||||
private val initial = longArrayOf(
|
||||
+0x6a09e667f3bcc908L, -0x4498517a7b3558c5L,
|
||||
+0x3c6ef372fe94f82bL, -0x5ab00ac5a0e2c90fL,
|
||||
+0x510e527fade682d1L, -0x64fa9773d4c193e1L,
|
||||
+0x1f83d9abfb41bd6bL, +0x5be0cd19137e2179L,
|
||||
)
|
||||
|
||||
private val c = ulongArrayOf(
|
||||
0x243f6a8885a308d3UL, 0x13198a2e03707344UL,
|
||||
0xa4093822299f31d0UL, 0x082efa98ec4e6c89UL,
|
||||
0x452821e638d01377UL, 0xbe5466cf34e90c6cUL,
|
||||
0xc0ac29b7c97c50ddUL, 0x3f84d5b5b5470917UL,
|
||||
0x9216d5d98979fb1bUL, 0xd1310ba698dfb5acUL,
|
||||
0x2ffd72dbd01adfb7UL, 0xb8e1afed6a267e96UL,
|
||||
0xba7c9045f12c7f99UL, 0x24a19947b3916cf7UL,
|
||||
0x0801f2e2858efc16UL, 0x636920d871574e69UL,
|
||||
).asLongArray()
|
||||
private val c = longArrayOf(
|
||||
+0x243f6a8885a308d3L, +0x13198a2e03707344L,
|
||||
-0x5bf6c7ddd660ce30L, +0x082efa98ec4e6c89L,
|
||||
+0x452821e638d01377L, -0x41ab9930cb16f394L,
|
||||
-0x3f53d6483683af23L, +0x3f84d5b5b5470917L,
|
||||
-0x6de92a26768604e5L, -0x2ecef45967204a54L,
|
||||
+0x2ffd72dbd01adfb7L, -0x471e501295d9816aL,
|
||||
-0x45836fba0ed38067L, +0x24a19947b3916cf7L,
|
||||
+0x0801f2e2858efc16L, +0x636920d871574e69L,
|
||||
)
|
||||
|
||||
private val sigma = arrayOf(
|
||||
intArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15),
|
||||
@@ -48,13 +48,12 @@ object `Blake-512` : HashFunction {
|
||||
val length = value.size.toULong() * 8UL
|
||||
val input = pad(value)
|
||||
val h = initial.copyOf()
|
||||
val m = LongArray(16)
|
||||
val v = LongArray(16)
|
||||
var t = 0UL
|
||||
|
||||
for (i in input.indices step block) {
|
||||
t += minOf(length - t, 1024UL)
|
||||
compress(h, input, i, m, v, t)
|
||||
val block = input.sliceArray(i..<(i + block))
|
||||
compress(h, block, t)
|
||||
}
|
||||
h.copyInto(destination, destinationOffset)
|
||||
}
|
||||
@@ -71,8 +70,9 @@ object `Blake-512` : HashFunction {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun compress(h: LongArray, value: ByteArray, offset: Int, m: LongArray, v: LongArray, t: ULong) {
|
||||
value.copyInto(m, startIndex = offset, endIndex = offset + block)
|
||||
internal fun compress(h: LongArray, block: ByteArray, t: ULong) {
|
||||
val m = block.toLongArray()
|
||||
val v = LongArray(16)
|
||||
for (i in 0..<8) v[i] = h[i]
|
||||
for (i in 0..<4) v[i + 8] = c[i]
|
||||
for (i in 0..<2) v[i + 12] = c[i + 4] xor t.toLong()
|
||||
|
||||
Reference in New Issue
Block a user