Upgrade bytes-kt
All checks were successful
/ test (pull_request) Successful in 44s

This commit is contained in:
2026-02-14 16:32:50 +01:00
parent 902cb060a1
commit cb3ff7ec6c
13 changed files with 91 additions and 91 deletions

View File

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

View File

@@ -2,7 +2,7 @@ package com.infendro.hash.blake
import com.infendro.bytes.bytearray.toIntArray
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
@@ -45,13 +45,13 @@ object `Blake-256` : 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))
compress(h, block, t)
}
@@ -59,23 +59,23 @@ object `Blake-256` : HashFunction {
}
private fun pad(value: ByteArray): ByteArray {
val length = value.size.toULong() * 8UL
val length = value.size * 8L
val size = (value.size + 10).align(block)
return ByteArray(size).also {
value.copyInto(it)
it[value.size] = 0x80U.toByte()
it[value.size] = -0x80
it[size - 9] = 0x01
length.copyInto(it, size - 8)
}
}
internal fun compress(h: IntArray, block: ByteArray, t: UInt) {
internal fun compress(h: IntArray, block: ByteArray, t: Int) {
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()
for (i in 0..<2) v[i + 12] = c[i + 4] xor t
for (i in 0..<2) v[i + 14] = c[i + 6]
repeat(14) { r ->

View File

@@ -1,7 +1,7 @@
package com.infendro.hash.blake
import com.infendro.bytes.long.copyInto
import com.infendro.bytes.longarray.copyInto
import com.infendro.bytes.ulong.copyInto
import com.infendro.hash.HashFunction
import com.infendro.hash.util.align
@@ -20,13 +20,13 @@ object `Blake-384` : 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 = 0UL
var t = 0L
for (i in input.indices step block) {
t += minOf(length - t, 1024UL)
t += minOf(length - t, 1024)
val block = input.sliceArray(i..<(i + block))
`Blake-512`.compress(h, block, t)
}
@@ -34,12 +34,12 @@ object `Blake-384` : HashFunction {
}
private fun pad(value: ByteArray): ByteArray {
val length = value.size.toULong() * 8UL
val length = value.size * 8L
val size = (value.size + 17).align(block)
return ByteArray(size).also {
value.copyInto(it)
it[value.size] = 0x80U.toByte()
it[value.size] = -0x80
length.copyInto(it, size - 8)
}
}

View File

@@ -1,8 +1,8 @@
package com.infendro.hash.blake
import com.infendro.bytes.bytearray.toLongArray
import com.infendro.bytes.long.copyInto
import com.infendro.bytes.longarray.copyInto
import com.infendro.bytes.ulong.copyInto
import com.infendro.hash.HashFunction
import com.infendro.hash.util.align
@@ -45,13 +45,13 @@ object `Blake-512` : 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 = 0UL
var t = 0L
for (i in input.indices step block) {
t += minOf(length - t, 1024UL)
t += minOf(length - t, 1024)
val block = input.sliceArray(i..<(i + block))
compress(h, block, t)
}
@@ -59,23 +59,23 @@ object `Blake-512` : HashFunction {
}
private fun pad(value: ByteArray): ByteArray {
val length = value.size.toULong() * 8UL
val length = value.size * 8L
val size = (value.size + 18).align(block)
return ByteArray(size).also {
value.copyInto(it)
it[value.size] = 0x80U.toByte()
it[value.size] = -0x80
it[size - 17] = 0x01
length.copyInto(it, size - 8)
}
}
internal fun compress(h: LongArray, block: ByteArray, t: ULong) {
internal fun compress(h: LongArray, block: ByteArray, t: Long) {
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()
for (i in 0..<2) v[i + 12] = c[i + 4] xor t
for (i in 0..<2) v[i + 14] = c[i + 6]
repeat(16) { r ->