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

@@ -13,25 +13,24 @@ object SHA1 : HashFunction {
override val block: Int
get() = 64
private val initial = uintArrayOf(
0x67452301U, 0xefcdaB89U,
0x98badcfeU, 0x10325476U,
0xc3d2e1f0U,
).asIntArray()
private val initial = intArrayOf(
+0x67452301, -0x10325477,
-0x67452302, +0x10325476,
-0x3c2d1e10,
)
private val k = uintArrayOf(
0x5a827999U, 0x6ed9eba1U,
0x8f1bbcdcU, 0xca62c1d6U,
).asIntArray()
private val k = intArrayOf(
+0x5a827999, +0x6ed9eba1,
-0x70e44324, -0x359d3e2a,
)
override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = pad(value)
val h = initial.copyOf()
val w = IntArray(80)
val v = IntArray(5)
for (i in input.indices step block) {
process(h, input, i, w, v)
val block = input.sliceArray(i..<(i + block))
process(h, block)
}
h.copyInto(destination, destinationOffset)
}
@@ -47,12 +46,13 @@ object SHA1 : HashFunction {
}
}
private fun process(h: IntArray, value: ByteArray, offset: Int, w: IntArray, v: IntArray) {
value.copyInto(w, startIndex = offset, endIndex = offset + block)
private fun process(h: IntArray, block: ByteArray) {
val w = IntArray(80)
block.copyInto(w)
for (i in 16..<80) {
w[i] = (w[i - 3] xor w[i - 8] xor w[i - 14] xor w[i - 16]).rotateLeft(1)
}
h.copyInto(v)
val v = h.copyOf()
repeat(80) { i ->
val f = when (i) {