remove unsigned support
All checks were successful
/ test (pull_request) Successful in 1m45s

This commit is contained in:
2026-02-08 14:04:41 +01:00
parent e138ec0b6d
commit 902cb060a1
38 changed files with 455 additions and 696 deletions

View File

@@ -12,24 +12,23 @@ object `Blake-224` : HashFunction {
override val block: Int
get() = 64
private val initial = uintArrayOf(
0xc1059ed8U, 0x367cd507U,
0x3070dd17U, 0xf70e5939U,
0xffc00b31U, 0x68581511U,
0x64f98fa7U, 0xbefa4fa4U,
).asIntArray()
private val initial = intArrayOf(
-0x3efa6128, +0x367cd507,
+0x3070dd17, -0x08f1a6c7,
-0x003ff4cf, +0x68581511,
+0x64f98fa7, -0x4105b05c,
)
override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val length = value.size.toULong() * 8UL
val input = pad(value)
val h = initial.copyOf()
val m = IntArray(16)
val v = IntArray(16)
var t = 0U
for (i in input.indices step block) {
t += minOf(length - t, 512UL).toUInt()
`Blake-256`.compress(h, input, i, m, v, t)
val block = input.sliceArray(i..<(i + block))
`Blake-256`.compress(h, block, t)
}
h.copyInto(destination, destinationOffset, endIndex = 7)
}

View File

@@ -1,6 +1,6 @@
package com.infendro.hash.blake
import com.infendro.bytes.bytearray.copyInto
import com.infendro.bytes.bytearray.toIntArray
import com.infendro.bytes.intarray.copyInto
import com.infendro.bytes.ulong.copyInto
import com.infendro.hash.HashFunction
@@ -13,23 +13,23 @@ object `Blake-256` : HashFunction {
override val block: Int
get() = 64
private val initial = uintArrayOf(
0x6a09e667U, 0xbb67ae85U,
0x3c6ef372U, 0xa54ff53aU,
0x510e527fU, 0x9b05688cU,
0x1f83d9abU, 0x5be0cd19U,
).asIntArray()
private val initial = intArrayOf(
+0x6a09e667, -0x4498517b,
+0x3c6ef372, -0x5ab00ac6,
+0x510e527f, -0x64fa9774,
+0x1f83d9ab, +0x5be0cd19,
)
private val c = uintArrayOf(
0x243f6a88U, 0x85a308d3U,
0x13198a2eU, 0x03707344U,
0xa4093822U, 0x299f31d0U,
0x082efa98U, 0xec4e6c89U,
0x452821e6U, 0x38d01377U,
0xbe5466cfU, 0x34e90c6cU,
0xc0ac29b7U, 0xc97c50ddU,
0x3f84d5b5U, 0xb5470917U,
).asIntArray()
private val c = intArrayOf(
+0x243f6a88, -0x7a5cf72d,
+0x13198a2e, +0x03707344,
-0x5bf6c7de, +0x299f31d0,
+0x082efa98, -0x13b19377,
+0x452821e6, +0x38d01377,
-0x41ab9931, +0x34e90c6c,
-0x3f53d649, -0x3683af23,
+0x3f84d5b5, -0x4ab8f6e9,
)
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-256` : HashFunction {
val length = value.size.toULong() * 8UL
val input = pad(value)
val h = initial.copyOf()
val m = IntArray(16)
val v = IntArray(16)
var t = 0U
for (i in input.indices step block) {
t += minOf(length - t, 512UL).toUInt()
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-256` : HashFunction {
}
}
internal fun compress(h: IntArray, value: ByteArray, offset: Int, m: IntArray, v: IntArray, t: UInt) {
value.copyInto(m, startIndex = offset, endIndex = offset + block)
internal fun compress(h: IntArray, block: ByteArray, t: UInt) {
val m = block.toIntArray()
val v = IntArray(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.toInt()

View File

@@ -12,24 +12,23 @@ object `Blake-384` : HashFunction {
override val block: Int
get() = 128
private val initial = ulongArrayOf(
0xcbbb9d5dc1059ed8U, 0x629a292a367cd507U,
0x9159015a3070dd17U, 0x152fecd8f70e5939U,
0x67332667ffc00b31U, 0x8eb44a8768581511U,
0xdb0c2e0d64f98fa7U, 0x47b5481dbefa4fa4U,
).asLongArray()
private val initial = longArrayOf(
-0x344462a23efa6128, +0x629a292a367cd507,
-0x6ea6fea5cf8f22e9, +0x152fecd8f70e5939,
+0x67332667ffc00b31, -0x714bb57897a7eaef,
-0x24f3d1f29b067059, +0x47b5481dbefa4fa4,
)
override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
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)
`Blake-512`.compress(h, input, i, m, v, t)
val block = input.sliceArray(i..<(i + block))
`Blake-512`.compress(h, block, t)
}
h.copyInto(destination, destinationOffset, endIndex = 6)
}

View File

@@ -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()