diff --git a/README.md b/README.md index f5cce9f..69e1318 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ repositories { } dependencies { - implementation("com.infendro:hash:1.5.1") + implementation("com.infendro:hash:1.6.0") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 3f374f9..1a61ef3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ import com.infendro.plugin.token import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl group = "com.infendro" -version = "1.5.1" +version = "1.6.0" plugins { alias(libs.plugins.infendro) @@ -37,10 +37,6 @@ kotlin { implementation(libs.test) } } - - compilerOptions { - freeCompilerArgs.add("-opt-in=kotlin.ExperimentalUnsignedTypes") - } } publishing.repositories { diff --git a/src/commonMain/kotlin/com/infendro/hash/HashFunction.kt b/src/commonMain/kotlin/com/infendro/hash/HashFunction.kt index 294d0ad..f7d5ae7 100644 --- a/src/commonMain/kotlin/com/infendro/hash/HashFunction.kt +++ b/src/commonMain/kotlin/com/infendro/hash/HashFunction.kt @@ -9,18 +9,9 @@ interface HashFunction { fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int = 0) - fun hashInto(value: ByteArray, destination: UByteArray, destinationOffset: Int = 0) = - hashInto(value, destination.asByteArray()) - - fun hashInto(value: UByteArray, destination: UByteArray, destinationOffset: Int = 0) = - hashInto(value.asByteArray(), destination.asByteArray()) - - fun hashInto(value: UByteArray, destination: ByteArray, destinationOffset: Int = 0) = - hashInto(value.asByteArray(), destination) - - fun hash(value: ByteArray): ByteArray = - ByteArray(bytes).also { hashInto(value, it) } - - fun hash(value: UByteArray): UByteArray = - UByteArray(bytes).also { hashInto(value, it) } + fun hash(value: ByteArray): ByteArray { + val result = ByteArray(bytes) + hashInto(value, result) + return result + } } diff --git a/src/commonMain/kotlin/com/infendro/hash/blake/Blake-224.kt b/src/commonMain/kotlin/com/infendro/hash/blake/Blake-224.kt index a4a1d1a..52e892c 100644 --- a/src/commonMain/kotlin/com/infendro/hash/blake/Blake-224.kt +++ b/src/commonMain/kotlin/com/infendro/hash/blake/Blake-224.kt @@ -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) } diff --git a/src/commonMain/kotlin/com/infendro/hash/blake/Blake-256.kt b/src/commonMain/kotlin/com/infendro/hash/blake/Blake-256.kt index fdee71d..d58d947 100644 --- a/src/commonMain/kotlin/com/infendro/hash/blake/Blake-256.kt +++ b/src/commonMain/kotlin/com/infendro/hash/blake/Blake-256.kt @@ -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() diff --git a/src/commonMain/kotlin/com/infendro/hash/blake/Blake-384.kt b/src/commonMain/kotlin/com/infendro/hash/blake/Blake-384.kt index 5fb9ee9..74b38e8 100644 --- a/src/commonMain/kotlin/com/infendro/hash/blake/Blake-384.kt +++ b/src/commonMain/kotlin/com/infendro/hash/blake/Blake-384.kt @@ -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) } diff --git a/src/commonMain/kotlin/com/infendro/hash/blake/Blake-512.kt b/src/commonMain/kotlin/com/infendro/hash/blake/Blake-512.kt index e8d7964..3bef540 100644 --- a/src/commonMain/kotlin/com/infendro/hash/blake/Blake-512.kt +++ b/src/commonMain/kotlin/com/infendro/hash/blake/Blake-512.kt @@ -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() diff --git a/src/commonMain/kotlin/com/infendro/hash/blake2/Blake2b.kt b/src/commonMain/kotlin/com/infendro/hash/blake2/Blake2b.kt index 6471859..66771c4 100644 --- a/src/commonMain/kotlin/com/infendro/hash/blake2/Blake2b.kt +++ b/src/commonMain/kotlin/com/infendro/hash/blake2/Blake2b.kt @@ -1,7 +1,7 @@ package com.infendro.hash.blake2 import com.infendro.bytes.ByteOrder.LITTLE_ENDIAN -import com.infendro.bytes.bytearray.copyInto +import com.infendro.bytes.bytearray.toLongArray import com.infendro.bytes.longarray.toByteArray import com.infendro.hash.HashFunction import com.infendro.hash.util.align @@ -16,12 +16,12 @@ class Blake2b( 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 sigma = arrayOf( intArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), @@ -41,13 +41,12 @@ class Blake2b( val input = pad(value) val h = initial.copyOf() h[0] = h[0] xor (0x01010000L or bytes.toLong()) - val m = LongArray(16) - val v = LongArray(16) var t = 0UL for (i in input.indices step block) { t += minOf(length - t, 128UL) - compress(h, input, i, m, v, t, t < 1024UL) + val block = input.sliceArray(i..<(i + block)) + compress(h, block, t, t < 1024UL) } h.toByteArray(LITTLE_ENDIAN).copyInto(destination, destinationOffset, endIndex = bytes) } @@ -59,16 +58,9 @@ class Blake2b( } } - private fun compress( - h: LongArray, - value: ByteArray, - offset: Int, - m: LongArray, - v: LongArray, - t: ULong, - last: Boolean, - ) { - value.copyInto(m, startIndex = offset, endIndex = offset + block) + private fun compress(h: LongArray, block: ByteArray, t: ULong, 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() diff --git a/src/commonMain/kotlin/com/infendro/hash/blake2/Blake2s.kt b/src/commonMain/kotlin/com/infendro/hash/blake2/Blake2s.kt index 9af74fd..ec8d128 100644 --- a/src/commonMain/kotlin/com/infendro/hash/blake2/Blake2s.kt +++ b/src/commonMain/kotlin/com/infendro/hash/blake2/Blake2s.kt @@ -1,7 +1,7 @@ package com.infendro.hash.blake2 import com.infendro.bytes.ByteOrder.LITTLE_ENDIAN -import com.infendro.bytes.bytearray.copyInto +import com.infendro.bytes.bytearray.toIntArray import com.infendro.bytes.intarray.toByteArray import com.infendro.hash.HashFunction import com.infendro.hash.util.align @@ -16,12 +16,12 @@ class Blake2s( 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 sigma = arrayOf( intArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), @@ -41,13 +41,12 @@ class Blake2s( val input = pad(value) val h = initial.copyOf() h[0] = h[0] xor (0x01010000 or bytes) - val m = IntArray(16) - val v = IntArray(16) var t = 0U for (i in input.indices step block) { t += minOf(length - t, 64UL).toUInt() - compress(h, input, i, m, v, t, t < 1024UL) + val block = input.sliceArray(i..<(i + block)) + compress(h, block, t, t < 1024UL) } h.toByteArray(LITTLE_ENDIAN).copyInto(destination, destinationOffset, endIndex = bytes) } @@ -59,16 +58,9 @@ class Blake2s( } } - private fun compress( - h: IntArray, - value: ByteArray, - offset: Int, - m: IntArray, - v: IntArray, - t: UInt, - last: Boolean, - ) { - value.copyInto(m, startIndex = offset, endIndex = offset + block) + private fun compress(h: IntArray, block: ByteArray, t: UInt, 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() diff --git a/src/commonMain/kotlin/com/infendro/hash/keccak/Keccak.kt b/src/commonMain/kotlin/com/infendro/hash/keccak/Keccak.kt index be49a2a..c5fd79b 100644 --- a/src/commonMain/kotlin/com/infendro/hash/keccak/Keccak.kt +++ b/src/commonMain/kotlin/com/infendro/hash/keccak/Keccak.kt @@ -19,14 +19,14 @@ open class Keccak( override val block: Int get() = rate - private val rc = ulongArrayOf( - 0x0000000000000001UL, 0x0000000000008082UL, 0x800000000000808aUL, 0x8000000080008000UL, - 0x000000000000808bUL, 0x0000000080000001UL, 0x8000000080008081UL, 0x8000000000008009UL, - 0x000000000000008aUL, 0x0000000000000088UL, 0x0000000080008009UL, 0x000000008000000aUL, - 0x000000008000808bUL, 0x800000000000008bUL, 0x8000000000008089UL, 0x8000000000008003UL, - 0x8000000000008002UL, 0x8000000000000080UL, 0x000000000000800aUL, 0x800000008000000aUL, - 0x8000000080008081UL, 0x8000000000008080UL, 0x0000000080000001UL, 0x8000000080008008UL, - ).asLongArray() + private val rc = longArrayOf( + +0x0000000000000001L, +0x0000000000008082L, -0x7fffffffffff7f76L, -0x7fffffff7fff8000L, + +0x000000000000808bL, +0x0000000080000001L, -0x7fffffff7fff7f7fL, -0x7fffffffffff7ff7L, + +0x000000000000008aL, +0x0000000000000088L, +0x0000000080008009L, +0x000000008000000aL, + +0x000000008000808bL, -0x7fffffffffffff75L, -0x7fffffffffff7f77L, -0x7fffffffffff7ffdL, + -0x7fffffffffff7ffeL, -0x7fffffffffffff80L, +0x000000000000800aL, -0x7fffffff7ffffff6L, + -0x7fffffff7fff7f7fL, -0x7fffffffffff7f80L, +0x0000000080000001L, -0x7fffffff7fff7ff8L, + ) private val rotation = arrayOf( intArrayOf(0, 36, 3, 41, 18), @@ -39,16 +39,13 @@ open class Keccak( override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) { val input = pad(value) val state = LongArray(25) - val w = LongArray(block / 8) - val b = LongArray(25) - val c = LongArray(5) - val d = LongArray(5) for (i in input.indices step block) { - absorb(state, input, i, w) - permute(state, b, c, d) + val block = input.sliceArray(i..<(i + block)) + absorb(state, block) + permute(state) } - squeeze(state, b, c, d, destination, destinationOffset) + squeeze(state, destination, destinationOffset) } private fun pad(value: ByteArray): ByteArray { @@ -60,21 +57,15 @@ open class Keccak( } } - private fun absorb(state: LongArray, value: ByteArray, offset: Int, w: LongArray) { - value.copyInto(w, startIndex = offset, endIndex = offset + block, order = LITTLE_ENDIAN) + private fun absorb(state: LongArray, block: ByteArray) { + val w = LongArray(this.block / 8) + block.copyInto(w, order = LITTLE_ENDIAN) for (i in w.indices) { state[i] = state[i] xor w[i] } } - private fun squeeze( - state: LongArray, - b: LongArray, - c: LongArray, - d: LongArray, - destination: ByteArray, - destinationOffset: Int, - ) { + private fun squeeze(state: LongArray, destination: ByteArray, destinationOffset: Int) { val buffer = ByteArray(8) val threshold = rate / 8 @@ -82,7 +73,7 @@ open class Keccak( var i = 0 while (consumed < bytes) { if (i == threshold) { - permute(state, b, c, d) + permute(state) i = 0 } @@ -95,7 +86,11 @@ open class Keccak( } } - private fun permute(a: LongArray, b: LongArray, c: LongArray, d: LongArray) = repeat(24) { round -> + private fun permute(a: LongArray) = repeat(24) { round -> + val b = LongArray(25) + val c = LongArray(5) + val d = LongArray(5) + // θ for (x in 0..4) { c[x] = a[x] xor a[x + 5] xor a[x + 10] xor a[x + 15] xor a[x + 20] diff --git a/src/commonMain/kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt b/src/commonMain/kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt index c154631..59403d7 100644 --- a/src/commonMain/kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt +++ b/src/commonMain/kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt @@ -2,6 +2,4 @@ package com.infendro.hash.keccak.shake import com.infendro.hash.keccak.Keccak -class SHAKE128( - bytes: Int, -) : Keccak(bytes, 168, 0x1F) +class SHAKE128(bytes: Int) : Keccak(bytes, 168, 0x1F) diff --git a/src/commonMain/kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt b/src/commonMain/kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt index 46a9107..299115e 100644 --- a/src/commonMain/kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt +++ b/src/commonMain/kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt @@ -2,6 +2,4 @@ package com.infendro.hash.keccak.shake import com.infendro.hash.keccak.Keccak -class SHAKE256( - bytes: Int, -) : Keccak(bytes, 136, 0x1F) +class SHAKE256(bytes: Int) : Keccak(bytes, 136, 0x1F) diff --git a/src/commonMain/kotlin/com/infendro/hash/md/MD5.kt b/src/commonMain/kotlin/com/infendro/hash/md/MD5.kt index c3e7cdc..c0f5535 100644 --- a/src/commonMain/kotlin/com/infendro/hash/md/MD5.kt +++ b/src/commonMain/kotlin/com/infendro/hash/md/MD5.kt @@ -1,7 +1,7 @@ package com.infendro.hash.md import com.infendro.bytes.ByteOrder.LITTLE_ENDIAN -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 @@ -14,29 +14,29 @@ object MD5 : HashFunction { override val block: Int get() = 64 - private val initial = uintArrayOf( - 0x67452301U, 0xefcdab89U, - 0x98badcfeU, 0x10325476U, - ).asIntArray() + private val initial = intArrayOf( + +0x67452301, -0x10325477, + -0x67452302, +0x10325476, + ) - private val c = uintArrayOf( - 0xd76aa478U, 0xe8c7b756U, 0x242070dbU, 0xc1bdceeeU, - 0xf57c0fafU, 0x4787c62aU, 0xa8304613U, 0xfd469501U, - 0x698098d8U, 0x8b44f7afU, 0xffff5bb1U, 0x895cd7beU, - 0x6b901122U, 0xfd987193U, 0xa679438eU, 0x49b40821U, - 0xf61e2562U, 0xc040b340U, 0x265e5a51U, 0xe9b6c7aaU, - 0xd62f105dU, 0x02441453U, 0xd8a1e681U, 0xe7d3fbc8U, - 0x21e1cde6U, 0xc33707d6U, 0xf4d50d87U, 0x455a14edU, - 0xa9e3e905U, 0xfcefa3f8U, 0x676f02d9U, 0x8d2a4c8aU, - 0xfffa3942U, 0x8771f681U, 0x6d9d6122U, 0xfde5380cU, - 0xa4beea44U, 0x4bdecfa9U, 0xf6bb4b60U, 0xbebfbc70U, - 0x289b7ec6U, 0xeaa127faU, 0xd4ef3085U, 0x04881d05U, - 0xd9d4d039U, 0xe6db99e5U, 0x1fa27cf8U, 0xc4ac5665U, - 0xf4292244U, 0x432aff97U, 0xab9423a7U, 0xfc93a039U, - 0x655b59c3U, 0x8f0ccc92U, 0xffeff47dU, 0x85845dd1U, - 0x6fa87e4fU, 0xfe2ce6e0U, 0xa3014314U, 0x4e0811a1U, - 0xf7537e82U, 0xbd3af235U, 0x2ad7d2bbU, 0xeb86d391U, - ).asIntArray() + private val c = intArrayOf( + -0x28955b88, -0x173848aa, +0x242070db, -0x3e423112, + -0x0a83f051, +0x4787c62a, -0x57cfb9ed, -0x02b96aff, + +0x698098d8, -0x74bb0851, -0x0000a44f, -0x76a32842, + +0x6b901122, -0x02678e6d, -0x5986bc72, +0x49b40821, + -0x09e1da9e, -0x3fbf4cc0, +0x265e5a51, -0x16493856, + -0x29d0efa3, +0x02441453, -0x275e197f, -0x182c0438, + +0x21e1cde6, -0x3cc8f82a, -0x0b2af279, +0x455a14ed, + -0x561c16fb, -0x03105c08, +0x676f02d9, -0x72d5b376, + -0x0005c6be, -0x788e097f, +0x6d9d6122, -0x021ac7f4, + -0x5b4115bc, +0x4bdecfa9, -0x0944b4a0, -0x41404390, + +0x289b7ec6, -0x155ed806, -0x2b10cf7b, +0x04881d05, + -0x262b2fc7, -0x1924661b, +0x1fa27cf8, -0x3b53a99b, + -0x0bd6ddbc, +0x432aff97, -0x546bdc59, -0x036c5fc7, + +0x655b59c3, -0x70f3336e, -0x00100b83, -0x7a7ba22f, + +0x6fa87e4f, -0x01d31920, -0x5cfebcec, +0x4e0811a1, + -0x08ac817e, -0x42c50dcb, +0x2ad7d2bb, -0x14792c6f, + ) private val shifts = intArrayOf( 7, 12, 17, 22, 7, 12, 17, 22, @@ -52,11 +52,10 @@ object MD5 : HashFunction { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) { val input = pad(value) val h = initial.copyOf() - val w = IntArray(16) - val v = IntArray(4) 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, order = LITTLE_ENDIAN) } @@ -72,9 +71,9 @@ object MD5 : HashFunction { } } - private fun process(h: IntArray, value: ByteArray, offset: Int, w: IntArray, v: IntArray) { - value.copyInto(w, startIndex = offset, endIndex = offset + block, order = LITTLE_ENDIAN) - h.copyInto(v) + private fun process(h: IntArray, block: ByteArray) { + val w = block.toIntArray(LITTLE_ENDIAN) + val v = h.copyOf() repeat(64) { i -> var f = when (i) { diff --git a/src/commonMain/kotlin/com/infendro/hash/sha1/SHA1.kt b/src/commonMain/kotlin/com/infendro/hash/sha1/SHA1.kt index 912cd4d..fdcca7f 100644 --- a/src/commonMain/kotlin/com/infendro/hash/sha1/SHA1.kt +++ b/src/commonMain/kotlin/com/infendro/hash/sha1/SHA1.kt @@ -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) { diff --git a/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-224.kt b/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-224.kt index 01afd7d..0ba169e 100644 --- a/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-224.kt +++ b/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-224.kt @@ -10,21 +10,20 @@ object `SHA-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 input = `SHA-256`.pad(value) val h = initial.copyOf() - val w = IntArray(64) - val v = IntArray(8) for (i in input.indices step block) { - `SHA-256`.process(h, input, i, w, v) + val block = input.sliceArray(i..<(i + block)) + `SHA-256`.process(h, block) } h.copyInto(destination, destinationOffset, endIndex = 7) } diff --git a/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-256.kt b/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-256.kt index a830dde..5f36bd3 100644 --- a/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-256.kt +++ b/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-256.kt @@ -13,32 +13,31 @@ object `SHA-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( - 0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U, - 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U, - 0xe49b69c1U, 0xefbe4786U, 0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU, - 0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U, 0x06ca6351U, 0x14292967U, - 0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U, 0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U, - 0xa2bfe8a1U, 0xa81a664bU, 0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U, - 0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU, 0x5b9cca4fU, 0x682e6ff3U, - 0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U, - ).asIntArray() + private val c = intArrayOf( + +0x428a2f98, +0x71374491, -0x4a3f0431, -0x164a245b, +0x3956c25b, +0x59f111f1, -0x6dc07d5c, -0x54e3a12b, + -0x27f85568, +0x12835b01, +0x243185be, +0x550c7dc3, +0x72be5d74, -0x7f214e02, -0x6423f959, -0x3e640e8c, + -0x1b64963f, -0x1041b87a, +0x0fc19dc6, +0x240ca1cc, +0x2de92c6f, +0x4a7484aa, +0x5cb0a9dc, +0x76f988da, + -0x67c1aeae, -0x57ce3993, -0x4ffcd838, -0x40a68039, -0x391ff40d, -0x2a586eb9, +0x06ca6351, +0x14292967, + +0x27b70a85, +0x2e1b2138, +0x4d2c6dfc, +0x53380d13, +0x650a7354, +0x766a0abb, -0x7e3d36d2, -0x6d8dd37b, + -0x5d40175f, -0x57e599b5, -0x3db47490, -0x3893ae5d, -0x2e6d17e7, -0x2966f9dc, -0x0bf1ca7b, +0x106aa070, + +0x19a4c116, +0x1e376c08, +0x2748774c, +0x34b0bcb5, +0x391c0cb3, +0x4ed8aa4a, +0x5b9cca4f, +0x682e6ff3, + +0x748f82ee, +0x78a5636f, -0x7b3787ec, -0x7338fdf8, -0x6f410006, -0x5baf9315, -0x41065c09, -0x398e870e, + ) override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) { val input = pad(value) val h = initial.copyOf() - val w = IntArray(64) - val v = IntArray(8) 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) } @@ -54,14 +53,15 @@ object `SHA-256` : HashFunction { } } - internal fun process(h: IntArray, value: ByteArray, offset: Int, w: IntArray, v: IntArray) { - value.copyInto(w, startIndex = offset, endIndex = offset + block) + internal fun process(h: IntArray, block: ByteArray) { + val w = IntArray(64) + block.copyInto(w) for (i in 16..<64) { val s0 = w[i - 15].rotateRight(7) xor w[i - 15].rotateRight(18) xor (w[i - 15] ushr 3) val s1 = w[i - 2].rotateRight(17) xor w[i - 2].rotateRight(19) xor (w[i - 2] ushr 10) w[i] = (w[i - 16] + s0 + w[i - 7] + s1) } - h.copyInto(v) + val v = h.copyOf() repeat(64) { i -> val s0 = v[0].rotateRight(2) xor v[0].rotateRight(13) xor v[0].rotateRight(22) diff --git a/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-384.kt b/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-384.kt index 5f7f5bc..8daa026 100644 --- a/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-384.kt +++ b/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-384.kt @@ -10,21 +10,20 @@ object `SHA-384` : HashFunction { override val block: Int get() = 128 - private val initial = ulongArrayOf( - 0xcbbb9d5dc1059ed8UL, 0x629a292a367cd507UL, - 0x9159015a3070dd17UL, 0x152fecd8f70e5939UL, - 0x67332667ffc00b31UL, 0x8eb44a8768581511UL, - 0xdb0c2e0d64f98fa7UL, 0x47b5481dbefa4fa4UL, - ).asLongArray() + private val initial = longArrayOf( + -0x344462a23efa6128L, +0x629a292a367cd507L, + -0x6ea6fea5cf8f22e9L, +0x152fecd8f70e5939L, + +0x67332667ffc00b31L, -0x714bb57897a7eaefL, + -0x24f3d1f29b067059L, +0x47b5481dbefa4fa4L, + ) override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) { val input = `SHA-512`.pad(value) val h = initial.copyOf() - val w = LongArray(80) - val v = LongArray(8) for (i in input.indices step block) { - `SHA-512`.process(h, input, i, w, v) + val block = input.sliceArray(i..<(i + block)) + `SHA-512`.process(h, block) } h.copyInto(destination, destinationOffset, endIndex = 6) } diff --git a/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-512.kt b/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-512.kt index 2010866..4c4006d 100644 --- a/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-512.kt +++ b/src/commonMain/kotlin/com/infendro/hash/sha2/SHA-512.kt @@ -13,44 +13,43 @@ object `SHA-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( - 0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL, - 0x3956c25bf348b538UL, 0x59f111f1b605d019UL, 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL, - 0xd807aa98a3030242UL, 0x12835b0145706fbeUL, 0x243185be4ee4b28cUL, 0x550c7dc3d5ffb4e2UL, - 0x72be5d74f27b896fUL, 0x80deb1fe3b1696b1UL, 0x9bdc06a725c71235UL, 0xc19bf174cf692694UL, - 0xe49b69c19ef14ad2UL, 0xefbe4786384f25e3UL, 0x0fc19dc68b8cd5b5UL, 0x240ca1cc77ac9c65UL, - 0x2de92c6f592b0275UL, 0x4a7484aa6ea6e483UL, 0x5cb0a9dcbd41fbd4UL, 0x76f988da831153b5UL, - 0x983e5152ee66dfabUL, 0xa831c66d2db43210UL, 0xb00327c898fb213fUL, 0xbf597fc7beef0ee4UL, - 0xc6e00bf33da88fc2UL, 0xd5a79147930aa725UL, 0x06ca6351e003826fUL, 0x142929670a0e6e70UL, - 0x27b70a8546d22ffcUL, 0x2e1b21385c26c926UL, 0x4d2c6dfc5ac42aedUL, 0x53380d139d95b3dfUL, - 0x650a73548baf63deUL, 0x766a0abb3c77b2a8UL, 0x81c2c92e47edaee6UL, 0x92722c851482353bUL, - 0xa2bfe8a14cf10364UL, 0xa81a664bbc423001UL, 0xc24b8b70d0f89791UL, 0xc76c51a30654be30UL, - 0xd192e819d6ef5218UL, 0xd69906245565a910UL, 0xf40e35855771202aUL, 0x106aa07032bbd1b8UL, - 0x19a4c116b8d2d0c8UL, 0x1e376c085141ab53UL, 0x2748774cdf8eeb99UL, 0x34b0bcb5e19b48a8UL, - 0x391c0cb3c5c95a63UL, 0x4ed8aa4ae3418acbUL, 0x5b9cca4f7763e373UL, 0x682e6ff3d6b2b8a3UL, - 0x748f82ee5defb2fcUL, 0x78a5636f43172f60UL, 0x84c87814a1f0ab72UL, 0x8cc702081a6439ecUL, - 0x90befffa23631e28UL, 0xa4506cebde82bde9UL, 0xbef9a3f7b2c67915UL, 0xc67178f2e372532bUL, - 0xca273eceea26619cUL, 0xd186b8c721c0c207UL, 0xeada7dd6cde0eb1eUL, 0xf57d4f7fee6ed178UL, - 0x06f067aa72176fbaUL, 0x0a637dc5a2c898a6UL, 0x113f9804bef90daeUL, 0x1b710b35131c471bUL, - 0x28db77f523047d84UL, 0x32caab7b40c72493UL, 0x3c9ebe0a15c9bebcUL, 0x431d67c49c100d4cUL, - 0x4cc5d4becb3e42b6UL, 0x597f299cfc657e2aUL, 0x5fcb6fab3ad6faecUL, 0x6c44198c4a475817UL, - ).asLongArray() + private val c = longArrayOf( + +0x428a2f98d728ae22L, +0x7137449123ef65cdL, -0x4a3f043013b2c4d1L, -0x164a245a7e762444L, + +0x3956c25bf348b538L, +0x59f111f1b605d019L, -0x6dc07d5b50e6b065L, -0x54e3a12a25927ee8L, + -0x27f855675cfcfdbeL, +0x12835b0145706fbeL, +0x243185be4ee4b28cL, +0x550c7dc3d5ffb4e2L, + +0x72be5d74f27b896fL, -0x7f214e01c4e9694fL, -0x6423f958da38edcbL, -0x3e640e8b3096d96cL, + -0x1b64963e610eb52eL, -0x1041b879c7b0da1dL, +0x0fc19dc68b8cd5b5L, +0x240ca1cc77ac9c65L, + +0x2de92c6f592b0275L, +0x4a7484aa6ea6e483L, +0x5cb0a9dcbd41fbd4L, +0x76f988da831153b5L, + -0x67c1aead11992055L, -0x57ce3992d24bcdf0L, -0x4ffcd8376704dec1L, -0x40a680384110f11cL, + -0x391ff40cc257703eL, -0x2a586eb86cf558dbL, +0x06ca6351e003826fL, +0x142929670a0e6e70L, + +0x27b70a8546d22ffcL, +0x2e1b21385c26c926L, +0x4d2c6dfc5ac42aedL, +0x53380d139d95b3dfL, + +0x650a73548baf63deL, +0x766a0abb3c77b2a8L, -0x7e3d36d1b812511aL, -0x6d8dd37aeb7dcac5L, + -0x5d40175eb30efc9cL, -0x57e599b443bdcfffL, -0x3db4748f2f07686fL, -0x3893ae5cf9ab41d0L, + -0x2e6d17e62910ade8L, -0x2966f9dbaa9a56f0L, -0x0bf1ca7aa88edfd6L, +0x106aa07032bbd1b8L, + +0x19a4c116b8d2d0c8L, +0x1e376c085141ab53L, +0x2748774cdf8eeb99L, +0x34b0bcb5e19b48a8L, + +0x391c0cb3c5c95a63L, +0x4ed8aa4ae3418acbL, +0x5b9cca4f7763e373L, +0x682e6ff3d6b2b8a3L, + +0x748f82ee5defb2fcL, +0x78a5636f43172f60L, -0x7b3787eb5e0f548eL, -0x7338fdf7e59bc614L, + -0x6f410005dc9ce1d8L, -0x5baf9314217d4217L, -0x41065c084d3986ebL, -0x398e870d1c8dacd5L, + -0x35d8c13115d99e64L, -0x2e794738de3f3df9L, -0x15258229321f14e2L, -0x0a82b08011912e88L, + +0x06f067aa72176fbaL, +0x0a637dc5a2c898a6L, +0x113f9804bef90daeL, +0x1b710b35131c471bL, + +0x28db77f523047d84L, +0x32caab7b40c72493L, +0x3c9ebe0a15c9bebcL, +0x431d67c49c100d4cL, + +0x4cc5d4becb3e42b6L, +0x597f299cfc657e2aL, +0x5fcb6fab3ad6faecL, +0x6c44198c4a475817L, + ) override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) { val input = pad(value) val h = initial.copyOf() - val w = LongArray(80) - val v = LongArray(8) 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) } @@ -66,14 +65,15 @@ object `SHA-512` : HashFunction { } } - internal fun process(h: LongArray, value: ByteArray, offset: Int, w: LongArray, v: LongArray) { - value.copyInto(w, startIndex = offset, endIndex = offset + block) + internal fun process(h: LongArray, block: ByteArray) { + val w = LongArray(80) + block.copyInto(w) for (i in 16..<80) { val s0 = w[i - 15].rotateRight(1) xor w[i - 15].rotateRight(8) xor (w[i - 15] ushr 7) val s1 = w[i - 2].rotateRight(19) xor w[i - 2].rotateRight(61) xor (w[i - 2] ushr 6) w[i] = (w[i - 16] + s0 + w[i - 7] + s1) } - h.copyInto(v) + val v = h.copyOf() repeat(80) { i -> val s0 = v[0].rotateRight(28) xor v[0].rotateRight(34) xor v[0].rotateRight(39) diff --git a/src/commonTest/kotlin/com/infendro/hash/blake/Blake-224.kt b/src/commonTest/kotlin/com/infendro/hash/blake/Blake-224.kt index 592bb7c..ea032a8 100644 --- a/src/commonTest/kotlin/com/infendro/hash/blake/Blake-224.kt +++ b/src/commonTest/kotlin/com/infendro/hash/blake/Blake-224.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `Blake-224 Test` { +class `Blake-224_Test` { val function = `Blake-224` @Test @@ -16,52 +16,37 @@ class `Blake-224 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x7dU, 0xc5U, 0x31U, 0x3bU, - 0x1cU, 0x04U, 0x51U, 0x2aU, - 0x17U, 0x4bU, 0xd6U, 0x50U, - 0x3bU, 0x89U, 0x60U, 0x7aU, - 0xecU, 0xbeU, 0xe0U, 0x90U, - 0x3dU, 0x40U, 0xa8U, 0xa5U, - 0x69U, 0xc9U, 0x4eU, 0xedU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x7d, -0x3b, +0x31, +0x3b, +0x1c, +0x04, +0x51, +0x2a, + +0x17, +0x4b, -0x2a, +0x50, +0x3b, -0x77, +0x60, +0x7a, + -0x14, -0x42, -0x20, -0x70, +0x3d, +0x40, -0x58, -0x5b, + +0x69, -0x37, +0x4e, -0x13, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } @Test fun `one block`() { - val expected = ubyteArrayOf( - 0x45U, 0x04U, 0xcbU, 0x03U, - 0x14U, 0xfbU, 0x2aU, 0x4fU, - 0x7aU, 0x69U, 0x2eU, 0x69U, - 0x6eU, 0x48U, 0x79U, 0x12U, - 0xfeU, 0x3fU, 0x24U, 0x68U, - 0xfeU, 0x31U, 0x2cU, 0x73U, - 0xa5U, 0x27U, 0x8eU, 0xc5U, - ).asByteArray() - val actual = function.hash( - ByteArray(1), + val expected = byteArrayOf( + +0x45, +0x04, -0x35, +0x03, +0x14, -0x05, +0x2a, +0x4f, + +0x7a, +0x69, +0x2e, +0x69, +0x6e, +0x48, +0x79, +0x12, + -0x02, +0x3f, +0x24, +0x68, -0x02, +0x31, +0x2c, +0x73, + -0x5b, +0x27, -0x72, -0x3b, ) + val actual = function.hash(ByteArray(1)) assertContentEquals(expected, actual) } @Test fun `two blocks`() { - val expected = ubyteArrayOf( - 0xf5U, 0xaaU, 0x00U, 0xddU, - 0x1cU, 0xb8U, 0x47U, 0xe3U, - 0x14U, 0x03U, 0x72U, 0xafU, - 0x7bU, 0x5cU, 0x46U, 0xb4U, - 0x88U, 0x8dU, 0x82U, 0xc8U, - 0xc0U, 0xa9U, 0x17U, 0x91U, - 0x3cU, 0xfbU, 0x5dU, 0x04U, - ).asByteArray() - val actual = function.hash( - ByteArray(72), + val expected = byteArrayOf( + -0x0b, -0x56, +0x00, -0x23, +0x1c, -0x48, +0x47, -0x1d, + +0x14, +0x03, +0x72, -0x51, +0x7b, +0x5c, +0x46, -0x4c, + -0x78, -0x73, -0x7e, -0x38, -0x40, -0x57, +0x17, -0x6f, + +0x3c, -0x05, +0x5d, +0x04, ) + val actual = function.hash(ByteArray(72)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/blake/Blake-256.kt b/src/commonTest/kotlin/com/infendro/hash/blake/Blake-256.kt index 4f49609..6a54dc1 100644 --- a/src/commonTest/kotlin/com/infendro/hash/blake/Blake-256.kt +++ b/src/commonTest/kotlin/com/infendro/hash/blake/Blake-256.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `Blake-256 Test` { +class `Blake-256_Test` { val function = `Blake-256` @Test @@ -16,55 +16,37 @@ class `Blake-256 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x71U, 0x6fU, 0x6eU, 0x86U, - 0x3fU, 0x74U, 0x4bU, 0x9aU, - 0xc2U, 0x2cU, 0x97U, 0xecU, - 0x7bU, 0x76U, 0xeaU, 0x5fU, - 0x59U, 0x08U, 0xbcU, 0x5bU, - 0x2fU, 0x67U, 0xc6U, 0x15U, - 0x10U, 0xbfU, 0xc4U, 0x75U, - 0x13U, 0x84U, 0xeaU, 0x7aU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x71, +0x6f, +0x6e, -0x7a, +0x3f, +0x74, +0x4b, -0x66, + -0x3e, +0x2c, -0x69, -0x14, +0x7b, +0x76, -0x16, +0x5f, + +0x59, +0x08, -0x44, +0x5b, +0x2f, +0x67, -0x3a, +0x15, + +0x10, -0x41, -0x3c, +0x75, +0x13, -0x7c, -0x16, +0x7a, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } @Test fun `one block`() { - val expected = ubyteArrayOf( - 0x0cU, 0xe8U, 0xd4U, 0xefU, - 0x4dU, 0xd7U, 0xcdU, 0x8dU, - 0x62U, 0xdfU, 0xdeU, 0xd9U, - 0xd4U, 0xedU, 0xb0U, 0xa7U, - 0x74U, 0xaeU, 0x6aU, 0x41U, - 0x92U, 0x9aU, 0x74U, 0xdaU, - 0x23U, 0x10U, 0x9eU, 0x8fU, - 0x11U, 0x13U, 0x9cU, 0x87U, - ).asByteArray() - val actual = function.hash( - ByteArray(1), + val expected = byteArrayOf( + +0x0c, -0x18, -0x2c, -0x11, +0x4d, -0x29, -0x33, -0x73, + +0x62, -0x21, -0x22, -0x27, -0x2c, -0x13, -0x50, -0x59, + +0x74, -0x52, +0x6a, +0x41, -0x6e, -0x66, +0x74, -0x26, + +0x23, +0x10, -0x62, -0x71, +0x11, +0x13, -0x64, -0x79, ) + val actual = function.hash(ByteArray(1)) assertContentEquals(expected, actual) } @Test fun `two blocks`() { - val expected = ubyteArrayOf( - 0xd4U, 0x19U, 0xbaU, 0xd3U, - 0x2dU, 0x50U, 0x4fU, 0xb7U, - 0xd4U, 0x4dU, 0x46U, 0x0cU, - 0x42U, 0xc5U, 0x59U, 0x3fU, - 0xe5U, 0x44U, 0xfaU, 0x4cU, - 0x13U, 0x5dU, 0xecU, 0x31U, - 0xe2U, 0x1bU, 0xd9U, 0xabU, - 0xdcU, 0xc2U, 0x2dU, 0x41U, - ).asByteArray() - val actual = function.hash( - ByteArray(72), + val expected = byteArrayOf( + -0x2c, +0x19, -0x46, -0x2d, +0x2d, +0x50, +0x4f, -0x49, + -0x2c, +0x4d, +0x46, +0x0c, +0x42, -0x3b, +0x59, +0x3f, + -0x1b, +0x44, -0x06, +0x4c, +0x13, +0x5d, -0x14, +0x31, + -0x1e, +0x1b, -0x27, -0x55, -0x24, -0x3e, +0x2d, +0x41, ) + val actual = function.hash(ByteArray(72)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/blake/Blake-384.kt b/src/commonTest/kotlin/com/infendro/hash/blake/Blake-384.kt index e853f52..30c837e 100644 --- a/src/commonTest/kotlin/com/infendro/hash/blake/Blake-384.kt +++ b/src/commonTest/kotlin/com/infendro/hash/blake/Blake-384.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `Blake-384 Test` { +class `Blake-384_Test` { val function = `Blake-384` @Test @@ -16,67 +16,43 @@ class `Blake-384 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xc6U, 0xcbU, 0xd8U, 0x9cU, - 0x92U, 0x6aU, 0xb5U, 0x25U, - 0xc2U, 0x42U, 0xe6U, 0x62U, - 0x1fU, 0x2fU, 0x5fU, 0xa7U, - 0x3aU, 0xa4U, 0xafU, 0xe3U, - 0xd9U, 0xe2U, 0x4aU, 0xedU, - 0x72U, 0x7fU, 0xaaU, 0xadU, - 0xd6U, 0xafU, 0x38U, 0xb6U, - 0x20U, 0xbdU, 0xb6U, 0x23U, - 0xddU, 0x2bU, 0x47U, 0x88U, - 0xb1U, 0xc8U, 0x08U, 0x69U, - 0x84U, 0xafU, 0x87U, 0x06U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x3a, -0x35, -0x28, -0x64, -0x6e, +0x6a, -0x4b, +0x25, + -0x3e, +0x42, -0x1a, +0x62, +0x1f, +0x2f, +0x5f, -0x59, + +0x3a, -0x5c, -0x51, -0x1d, -0x27, -0x1e, +0x4a, -0x13, + +0x72, +0x7f, -0x56, -0x53, -0x2a, -0x51, +0x38, -0x4a, + +0x20, -0x43, -0x4a, +0x23, -0x23, +0x2b, +0x47, -0x78, + -0x4f, -0x38, +0x08, +0x69, -0x7c, -0x51, -0x79, +0x06, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } @Test fun `one block`() { - val expected = ubyteArrayOf( - 0x10U, 0x28U, 0x1fU, 0x67U, - 0xe1U, 0x35U, 0xe9U, 0x0aU, - 0xe8U, 0xe8U, 0x82U, 0x25U, - 0x1aU, 0x35U, 0x55U, 0x10U, - 0xa7U, 0x19U, 0x36U, 0x7aU, - 0xd7U, 0x02U, 0x27U, 0xb1U, - 0x37U, 0x34U, 0x3eU, 0x1bU, - 0xc1U, 0x22U, 0x01U, 0x5cU, - 0x29U, 0x39U, 0x1eU, 0x85U, - 0x45U, 0xb5U, 0x27U, 0x2dU, - 0x13U, 0xa7U, 0xc2U, 0x87U, - 0x9dU, 0xa3U, 0xd8U, 0x07U, - ).asByteArray() - val actual = function.hash( - ByteArray(1), + val expected = byteArrayOf( + +0x10, +0x28, +0x1f, +0x67, -0x1f, +0x35, -0x17, +0x0a, + -0x18, -0x18, -0x7e, +0x25, +0x1a, +0x35, +0x55, +0x10, + -0x59, +0x19, +0x36, +0x7a, -0x29, +0x02, +0x27, -0x4f, + +0x37, +0x34, +0x3e, +0x1b, -0x3f, +0x22, +0x01, +0x5c, + +0x29, +0x39, +0x1e, -0x7b, +0x45, -0x4b, +0x27, +0x2d, + +0x13, -0x59, -0x3e, -0x79, -0x63, -0x5d, -0x28, +0x07, ) + val actual = function.hash(ByteArray(1)) assertContentEquals(expected, actual) } @Test fun `two blocks`() { - val expected = ubyteArrayOf( - 0x0bU, 0x98U, 0x45U, 0xddU, - 0x42U, 0x95U, 0x66U, 0xcdU, - 0xabU, 0x77U, 0x2bU, 0xa1U, - 0x95U, 0xd2U, 0x71U, 0xefU, - 0xfeU, 0x2dU, 0x02U, 0x11U, - 0xf1U, 0x69U, 0x91U, 0xd7U, - 0x66U, 0xbaU, 0x74U, 0x94U, - 0x47U, 0xc5U, 0xcdU, 0xe5U, - 0x69U, 0x78U, 0x0bU, 0x2dU, - 0xaaU, 0x66U, 0xc4U, 0xb2U, - 0x24U, 0xa2U, 0xecU, 0x2eU, - 0x5dU, 0x09U, 0x17U, 0x4cU, - ).asByteArray() - val actual = function.hash( - ByteArray(144), + val expected = byteArrayOf( + +0x0b, -0x68, +0x45, -0x23, +0x42, -0x6b, +0x66, -0x33, + -0x55, +0x77, +0x2b, -0x5f, -0x6b, -0x2e, +0x71, -0x11, + -0x02, +0x2d, +0x02, +0x11, -0x0f, +0x69, -0x6f, -0x29, + +0x66, -0x46, +0x74, -0x6c, +0x47, -0x3b, -0x33, -0x1b, + +0x69, +0x78, +0x0b, +0x2d, -0x56, +0x66, -0x3c, -0x4e, + +0x24, -0x5e, -0x14, +0x2e, +0x5d, +0x09, +0x17, +0x4c, ) + val actual = function.hash(ByteArray(144)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/blake/Blake-512.kt b/src/commonTest/kotlin/com/infendro/hash/blake/Blake-512.kt index afa540f..4b4d0b5 100644 --- a/src/commonTest/kotlin/com/infendro/hash/blake/Blake-512.kt +++ b/src/commonTest/kotlin/com/infendro/hash/blake/Blake-512.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `Blake-512 Test` { +class `Blake-512_Test` { val function = `Blake-512` @Test @@ -16,79 +16,49 @@ class `Blake-512 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xa8U, 0xcfU, 0xbbU, 0xd7U, - 0x37U, 0x26U, 0x06U, 0x2dU, - 0xf0U, 0xc6U, 0x86U, 0x4dU, - 0xdaU, 0x65U, 0xdeU, 0xfeU, - 0x58U, 0xefU, 0x0cU, 0xc5U, - 0x2aU, 0x56U, 0x25U, 0x09U, - 0x0fU, 0xa1U, 0x76U, 0x01U, - 0xe1U, 0xeeU, 0xcdU, 0x1bU, - 0x62U, 0x8eU, 0x94U, 0xf3U, - 0x96U, 0xaeU, 0x40U, 0x2aU, - 0x00U, 0xacU, 0xc9U, 0xeaU, - 0xb7U, 0x7bU, 0x4dU, 0x4cU, - 0x2eU, 0x85U, 0x2aU, 0xaaU, - 0xa2U, 0x5aU, 0x63U, 0x6dU, - 0x80U, 0xafU, 0x3fU, 0xc7U, - 0x91U, 0x3eU, 0xf5U, 0xb8U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x58, -0x31, -0x45, -0x29, +0x37, +0x26, +0x06, +0x2d, + -0x10, -0x3a, -0x7a, +0x4d, -0x26, +0x65, -0x22, -0x02, + +0x58, -0x11, +0x0c, -0x3b, +0x2a, +0x56, +0x25, +0x09, + +0x0f, -0x5f, +0x76, +0x01, -0x1f, -0x12, -0x33, +0x1b, + +0x62, -0x72, -0x6c, -0x0d, -0x6a, -0x52, +0x40, +0x2a, + +0x00, -0x54, -0x37, -0x16, -0x49, +0x7b, +0x4d, +0x4c, + +0x2e, -0x7b, +0x2a, -0x56, -0x5e, +0x5a, +0x63, +0x6d, + -0x80, -0x51, +0x3f, -0x39, -0x6f, +0x3e, -0x0b, -0x48, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } @Test fun `one block`() { - val expected = ubyteArrayOf( - 0x97U, 0x96U, 0x15U, 0x87U, - 0xf6U, 0xd9U, 0x70U, 0xfaU, - 0xbaU, 0x6dU, 0x24U, 0x78U, - 0x04U, 0x5dU, 0xe6U, 0xd1U, - 0xfaU, 0xbdU, 0x09U, 0xb6U, - 0x1aU, 0xe5U, 0x09U, 0x32U, - 0x05U, 0x4dU, 0x52U, 0xbcU, - 0x29U, 0xd3U, 0x1bU, 0xe4U, - 0xffU, 0x91U, 0x02U, 0xb9U, - 0xf6U, 0x9eU, 0x2bU, 0xbdU, - 0xb8U, 0x3bU, 0xe1U, 0x3dU, - 0x4bU, 0x9cU, 0x06U, 0x09U, - 0x1eU, 0x5fU, 0xa0U, 0xb4U, - 0x8bU, 0xd0U, 0x81U, 0xb6U, - 0x34U, 0x05U, 0x8bU, 0xe0U, - 0xecU, 0x49U, 0xbeU, 0xb3U, - ).asByteArray() - val actual = function.hash( - ByteArray(1), + val expected = byteArrayOf( + -0x69, -0x6a, +0x15, -0x79, -0x0a, -0x27, +0x70, -0x06, + -0x46, +0x6d, +0x24, +0x78, +0x04, +0x5d, -0x1a, -0x2f, + -0x06, -0x43, +0x09, -0x4a, +0x1a, -0x1b, +0x09, +0x32, + +0x05, +0x4d, +0x52, -0x44, +0x29, -0x2d, +0x1b, -0x1c, + -0x01, -0x6f, +0x02, -0x47, -0x0a, -0x62, +0x2b, -0x43, + -0x48, +0x3b, -0x1f, +0x3d, +0x4b, -0x64, +0x06, +0x09, + +0x1e, +0x5f, -0x60, -0x4c, -0x75, -0x30, -0x7f, -0x4a, + +0x34, +0x05, -0x75, -0x20, -0x14, +0x49, -0x42, -0x4d, ) + val actual = function.hash(ByteArray(1)) assertContentEquals(expected, actual) } @Test fun `two blocks`() { - val expected = ubyteArrayOf( - 0x31U, 0x37U, 0x17U, 0xd6U, - 0x08U, 0xe9U, 0xcfU, 0x75U, - 0x8dU, 0xcbU, 0x1eU, 0xb0U, - 0xf0U, 0xc3U, 0xcfU, 0x9fU, - 0xc1U, 0x50U, 0xb2U, 0xd5U, - 0x00U, 0xfbU, 0x33U, 0xf5U, - 0x1cU, 0x52U, 0xafU, 0xc9U, - 0x9dU, 0x35U, 0x8aU, 0x2fU, - 0x13U, 0x74U, 0xb8U, 0xa3U, - 0x8bU, 0xbaU, 0x79U, 0x74U, - 0xe7U, 0xf6U, 0xefU, 0x79U, - 0xcaU, 0xb1U, 0x6fU, 0x22U, - 0xceU, 0x1eU, 0x64U, 0x9dU, - 0x6eU, 0x01U, 0xadU, 0x95U, - 0x89U, 0xc2U, 0x13U, 0x04U, - 0x5dU, 0x54U, 0x5dU, 0xdeU, - ).asByteArray() - val actual = function.hash( - ByteArray(144), + val expected = byteArrayOf( + +0x31, +0x37, +0x17, -0x2a, +0x08, -0x17, -0x31, +0x75, + -0x73, -0x35, +0x1e, -0x50, -0x10, -0x3d, -0x31, -0x61, + -0x3f, +0x50, -0x4e, -0x2b, +0x00, -0x05, +0x33, -0x0b, + +0x1c, +0x52, -0x51, -0x37, -0x63, +0x35, -0x76, +0x2f, + +0x13, +0x74, -0x48, -0x5d, -0x75, -0x46, +0x79, +0x74, + -0x19, -0x0a, -0x11, +0x79, -0x36, -0x4f, +0x6f, +0x22, + -0x32, +0x1e, +0x64, -0x63, +0x6e, +0x01, -0x53, -0x6b, + -0x77, -0x3e, +0x13, +0x04, +0x5d, +0x54, +0x5d, -0x22, ) + val actual = function.hash(ByteArray(144)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2b-384.kt b/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2b-384.kt index 62defc3..381298e 100644 --- a/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2b-384.kt +++ b/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2b-384.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `Blake2b-384 Test` { +class `Blake2b-384_Test` { val function = Blake2b(48) @Test @@ -16,23 +16,15 @@ class `Blake2b-384 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xb3U, 0x28U, 0x11U, 0x42U, - 0x33U, 0x77U, 0xf5U, 0x2dU, - 0x78U, 0x62U, 0x28U, 0x6eU, - 0xe1U, 0xa7U, 0x2eU, 0xe5U, - 0x40U, 0x52U, 0x43U, 0x80U, - 0xfdU, 0xa1U, 0x72U, 0x4aU, - 0x6fU, 0x25U, 0xd7U, 0x97U, - 0x8cU, 0x6fU, 0xd3U, 0x24U, - 0x4aU, 0x6cU, 0xafU, 0x04U, - 0x98U, 0x81U, 0x26U, 0x73U, - 0xc5U, 0xe0U, 0x5eU, 0xf5U, - 0x83U, 0x82U, 0x51U, 0x00U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x4d, +0x28, +0x11, +0x42, +0x33, +0x77, -0x0b, +0x2d, + +0x78, +0x62, +0x28, +0x6e, -0x1f, -0x59, +0x2e, -0x1b, + +0x40, +0x52, +0x43, -0x80, -0x03, -0x5f, +0x72, +0x4a, + +0x6f, +0x25, -0x29, -0x69, -0x74, +0x6f, -0x2d, +0x24, + +0x4a, +0x6c, -0x51, +0x04, -0x68, -0x7f, +0x26, +0x73, + -0x3b, -0x20, +0x5e, -0x0b, -0x7d, -0x7e, +0x51, +0x00, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2b-512.kt b/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2b-512.kt index de82fc4..1d42a66 100644 --- a/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2b-512.kt +++ b/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2b-512.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `Blake2b-512 Test` { +class `Blake2b-512_Test` { val function = Blake2b(64) @Test @@ -16,27 +16,17 @@ class `Blake2b-512 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x78U, 0x6aU, 0x02U, 0xf7U, - 0x42U, 0x01U, 0x59U, 0x03U, - 0xc6U, 0xc6U, 0xfdU, 0x85U, - 0x25U, 0x52U, 0xd2U, 0x72U, - 0x91U, 0x2fU, 0x47U, 0x40U, - 0xe1U, 0x58U, 0x47U, 0x61U, - 0x8aU, 0x86U, 0xe2U, 0x17U, - 0xf7U, 0x1fU, 0x54U, 0x19U, - 0xd2U, 0x5eU, 0x10U, 0x31U, - 0xafU, 0xeeU, 0x58U, 0x53U, - 0x13U, 0x89U, 0x64U, 0x44U, - 0x93U, 0x4eU, 0xb0U, 0x4bU, - 0x90U, 0x3aU, 0x68U, 0x5bU, - 0x14U, 0x48U, 0xb7U, 0x55U, - 0xd5U, 0x6fU, 0x70U, 0x1aU, - 0xfeU, 0x9bU, 0xe2U, 0xceU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x78, +0x6a, +0x02, -0x09, +0x42, +0x01, +0x59, +0x03, + -0x3a, -0x3a, -0x03, -0x7b, +0x25, +0x52, -0x2e, +0x72, + -0x6f, +0x2f, +0x47, +0x40, -0x1f, +0x58, +0x47, +0x61, + -0x76, -0x7a, -0x1e, +0x17, -0x09, +0x1f, +0x54, +0x19, + -0x2e, +0x5e, +0x10, +0x31, -0x51, -0x12, +0x58, +0x53, + +0x13, -0x77, +0x64, +0x44, -0x6d, +0x4e, -0x50, +0x4b, + -0x70, +0x3a, +0x68, +0x5b, +0x14, +0x48, -0x49, +0x55, + -0x2b, +0x6f, +0x70, +0x1a, -0x02, -0x65, -0x1e, -0x32, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2s-224.kt b/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2s-224.kt index 5138eb1..f583c96 100644 --- a/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2s-224.kt +++ b/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2s-224.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `Blake2s-224 Test` { +class `Blake2s-224_Test` { val function = Blake2s(28) @Test @@ -16,18 +16,13 @@ class `Blake2s-224 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x1fU, 0xa1U, 0x29U, 0x1eU, - 0x65U, 0x24U, 0x8bU, 0x37U, - 0xb3U, 0x43U, 0x34U, 0x75U, - 0xb2U, 0xa0U, 0xddU, 0x63U, - 0xd5U, 0x4aU, 0x11U, 0xecU, - 0xc4U, 0xe3U, 0xe0U, 0x34U, - 0xe7U, 0xbcU, 0x1eU, 0xf4U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x1f, -0x5f, +0x29, +0x1e, +0x65, +0x24, -0x75, +0x37, + -0x4d, +0x43, +0x34, +0x75, -0x4e, -0x60, -0x23, +0x63, + -0x2b, +0x4a, +0x11, -0x14, -0x3c, -0x1d, -0x20, +0x34, + -0x19, -0x44, +0x1e, -0x0c, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2s-256.kt b/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2s-256.kt index 06e48de..9123b4e 100644 --- a/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2s-256.kt +++ b/src/commonTest/kotlin/com/infendro/hash/blake2/Blake2s-256.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `Blake2s-256 Test` { +class `Blake2s-256_Test` { val function = Blake2s(32) @Test @@ -16,19 +16,13 @@ class `Blake2s-256 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x69U, 0x21U, 0x7aU, 0x30U, - 0x79U, 0x90U, 0x80U, 0x94U, - 0xe1U, 0x11U, 0x21U, 0xd0U, - 0x42U, 0x35U, 0x4aU, 0x7cU, - 0x1fU, 0x55U, 0xb6U, 0x48U, - 0x2cU, 0xa1U, 0xa5U, 0x1eU, - 0x1bU, 0x25U, 0x0dU, 0xfdU, - 0x1eU, 0xd0U, 0xeeU, 0xf9U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x69, +0x21, +0x7a, +0x30, +0x79, -0x70, -0x80, -0x6c, + -0x1f, +0x11, +0x21, -0x30, +0x42, +0x35, +0x4a, +0x7c, + +0x1f, +0x55, -0x4a, +0x48, +0x2c, -0x5f, -0x5b, +0x1e, + +0x1b, +0x25, +0x0d, -0x03, +0x1e, -0x30, -0x12, -0x07, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-224.kt b/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-224.kt index aa7845d..10770ae 100644 --- a/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-224.kt +++ b/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-224.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA3-224 Test` { +class `SHA3-224_Test` { val function = `SHA3-224` @Test @@ -16,18 +16,13 @@ class `SHA3-224 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x6bU, 0x4eU, 0x03U, 0x42U, - 0x36U, 0x67U, 0xdbU, 0xb7U, - 0x3bU, 0x6eU, 0x15U, 0x45U, - 0x4fU, 0x0eU, 0xb1U, 0xabU, - 0xd4U, 0x59U, 0x7fU, 0x9aU, - 0x1bU, 0x07U, 0x8eU, 0x3fU, - 0x5bU, 0x5aU, 0x6bU, 0xc7U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x6b, +0x4e, +0x03, +0x42, +0x36, +0x67, -0x25, -0x49, + +0x3b, +0x6e, +0x15, +0x45, +0x4f, +0x0e, -0x4f, -0x55, + -0x2c, +0x59, +0x7f, -0x66, +0x1b, +0x07, -0x72, +0x3f, + +0x5b, +0x5a, +0x6b, -0x39, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-256.kt b/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-256.kt index 3f45c7d..7f0083d 100644 --- a/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-256.kt +++ b/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-256.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA3-256 Test` { +class `SHA3-256_Test` { val function = `SHA3-256` @Test @@ -16,19 +16,13 @@ class `SHA3-256 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xa7U, 0xffU, 0xc6U, 0xf8U, - 0xbfU, 0x1eU, 0xd7U, 0x66U, - 0x51U, 0xc1U, 0x47U, 0x56U, - 0xa0U, 0x61U, 0xd6U, 0x62U, - 0xf5U, 0x80U, 0xffU, 0x4dU, - 0xe4U, 0x3bU, 0x49U, 0xfaU, - 0x82U, 0xd8U, 0x0aU, 0x4bU, - 0x80U, 0xf8U, 0x43U, 0x4aU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x59, -0x01, -0x3a, -0x08, -0x41, +0x1e, -0x29, +0x66, + +0x51, -0x3f, +0x47, +0x56, -0x60, +0x61, -0x2a, +0x62, + -0x0b, -0x80, -0x01, +0x4d, -0x1c, +0x3b, +0x49, -0x06, + -0x7e, -0x28, +0x0a, +0x4b, -0x80, -0x08, +0x43, +0x4a, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-384.kt b/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-384.kt index b300062..88fd9fe 100644 --- a/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-384.kt +++ b/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-384.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA3-384 Test` { +class `SHA3-384_Test` { val function = `SHA3-384` @Test @@ -16,23 +16,15 @@ class `SHA3-384 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x0cU, 0x63U, 0xa7U, 0x5bU, - 0x84U, 0x5eU, 0x4fU, 0x7dU, - 0x01U, 0x10U, 0x7dU, 0x85U, - 0x2eU, 0x4cU, 0x24U, 0x85U, - 0xc5U, 0x1aU, 0x50U, 0xaaU, - 0xaaU, 0x94U, 0xfcU, 0x61U, - 0x99U, 0x5eU, 0x71U, 0xbbU, - 0xeeU, 0x98U, 0x3aU, 0x2aU, - 0xc3U, 0x71U, 0x38U, 0x31U, - 0x26U, 0x4aU, 0xdbU, 0x47U, - 0xfbU, 0x6bU, 0xd1U, 0xe0U, - 0x58U, 0xd5U, 0xf0U, 0x04U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x0c, +0x63, -0x59, +0x5b, -0x7c, +0x5e, +0x4f, +0x7d, + +0x01, +0x10, +0x7d, -0x7b, +0x2e, +0x4c, +0x24, -0x7b, + -0x3b, +0x1a, +0x50, -0x56, -0x56, -0x6c, -0x04, +0x61, + -0x67, +0x5e, +0x71, -0x45, -0x12, -0x68, +0x3a, +0x2a, + -0x3d, +0x71, +0x38, +0x31, +0x26, +0x4a, -0x25, +0x47, + -0x05, +0x6b, -0x2f, -0x20, +0x58, -0x2b, -0x10, +0x04, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-512.kt b/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-512.kt index 3cdacf7..41dd4d6 100644 --- a/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-512.kt +++ b/src/commonTest/kotlin/com/infendro/hash/keccak/sha3/SHA3-512.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA3-512 Test` { +class `SHA3-512_Test` { val function = `SHA3-512` @Test @@ -16,27 +16,17 @@ class `SHA3-512 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xa6U, 0x9fU, 0x73U, 0xccU, - 0xa2U, 0x3aU, 0x9aU, 0xc5U, - 0xc8U, 0xb5U, 0x67U, 0xdcU, - 0x18U, 0x5aU, 0x75U, 0x6eU, - 0x97U, 0xc9U, 0x82U, 0x16U, - 0x4fU, 0xe2U, 0x58U, 0x59U, - 0xe0U, 0xd1U, 0xdcU, 0xc1U, - 0x47U, 0x5cU, 0x80U, 0xa6U, - 0x15U, 0xb2U, 0x12U, 0x3aU, - 0xf1U, 0xf5U, 0xf9U, 0x4cU, - 0x11U, 0xe3U, 0xe9U, 0x40U, - 0x2cU, 0x3aU, 0xc5U, 0x58U, - 0xf5U, 0x00U, 0x19U, 0x9dU, - 0x95U, 0xb6U, 0xd3U, 0xe3U, - 0x01U, 0x75U, 0x85U, 0x86U, - 0x28U, 0x1dU, 0xcdU, 0x26U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x5a, -0x61, +0x73, -0x34, -0x5e, +0x3a, -0x66, -0x3b, + -0x38, -0x4b, +0x67, -0x24, +0x18, +0x5a, +0x75, +0x6e, + -0x69, -0x37, -0x7e, +0x16, +0x4f, -0x1e, +0x58, +0x59, + -0x20, -0x2f, -0x24, -0x3f, +0x47, +0x5c, -0x80, -0x5a, + +0x15, -0x4e, +0x12, +0x3a, -0x0f, -0x0b, -0x07, +0x4c, + +0x11, -0x1d, -0x17, +0x40, +0x2c, +0x3a, -0x3b, +0x58, + -0x0b, +0x00, +0x19, -0x63, -0x6b, -0x4a, -0x2d, -0x1d, + +0x01, +0x75, -0x7b, -0x7a, +0x28, +0x1d, -0x33, +0x26, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt b/src/commonTest/kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt index 9a4cd1e..01845e2 100644 --- a/src/commonTest/kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt +++ b/src/commonTest/kotlin/com/infendro/hash/keccak/shake/SHAKE128.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHAKE128 Test` { +class SHAKE128_Test { val function = SHAKE128(32) @Test @@ -16,19 +16,13 @@ class `SHAKE128 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x7fU, 0x9cU, 0x2bU, 0xa4U, - 0xe8U, 0x8fU, 0x82U, 0x7dU, - 0x61U, 0x60U, 0x45U, 0x50U, - 0x76U, 0x05U, 0x85U, 0x3eU, - 0xd7U, 0x3bU, 0x80U, 0x93U, - 0xf6U, 0xefU, 0xbcU, 0x88U, - 0xebU, 0x1aU, 0x6eU, 0xacU, - 0xfaU, 0x66U, 0xefU, 0x26U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x7f, -0x64, +0x2b, -0x5c, -0x18, -0x71, -0x7e, +0x7d, + +0x61, +0x60, +0x45, +0x50, +0x76, +0x05, -0x7b, +0x3e, + -0x29, +0x3b, -0x80, -0x6d, -0x0a, -0x11, -0x44, -0x78, + -0x15, +0x1a, +0x6e, -0x54, -0x06, +0x66, -0x11, +0x26, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt b/src/commonTest/kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt index 2543878..5b1f4fd 100644 --- a/src/commonTest/kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt +++ b/src/commonTest/kotlin/com/infendro/hash/keccak/shake/SHAKE256.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHAKE256 Test` { +class SHAKE256_Test { val function = SHAKE256(64) @Test @@ -16,27 +16,17 @@ class `SHAKE256 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x46U, 0xb9U, 0xddU, 0x2bU, - 0x0bU, 0xa8U, 0x8dU, 0x13U, - 0x23U, 0x3bU, 0x3fU, 0xebU, - 0x74U, 0x3eU, 0xebU, 0x24U, - 0x3fU, 0xcdU, 0x52U, 0xeaU, - 0x62U, 0xb8U, 0x1bU, 0x82U, - 0xb5U, 0x0cU, 0x27U, 0x64U, - 0x6eU, 0xd5U, 0x76U, 0x2fU, - 0xd7U, 0x5dU, 0xc4U, 0xddU, - 0xd8U, 0xc0U, 0xf2U, 0x00U, - 0xcbU, 0x05U, 0x01U, 0x9dU, - 0x67U, 0xb5U, 0x92U, 0xf6U, - 0xfcU, 0x82U, 0x1cU, 0x49U, - 0x47U, 0x9aU, 0xb4U, 0x86U, - 0x40U, 0x29U, 0x2eU, 0xacU, - 0xb3U, 0xb7U, 0xc4U, 0xbeU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x46, -0x47, -0x23, +0x2b, +0x0b, -0x58, -0x73, +0x13, + +0x23, +0x3b, +0x3f, -0x15, +0x74, +0x3e, -0x15, +0x24, + +0x3f, -0x33, +0x52, -0x16, +0x62, -0x48, +0x1b, -0x7e, + -0x4b, +0x0c, +0x27, +0x64, +0x6e, -0x2b, +0x76, +0x2f, + -0x29, +0x5d, -0x3c, -0x23, -0x28, -0x40, -0x0e, +0x00, + -0x35, +0x05, +0x01, -0x63, +0x67, -0x4b, -0x6e, -0x0a, + -0x04, -0x7e, +0x1c, +0x49, +0x47, -0x66, -0x4c, -0x7a, + +0x40, +0x29, +0x2e, -0x54, -0x4d, -0x49, -0x3c, -0x42, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/md/MD5.kt b/src/commonTest/kotlin/com/infendro/hash/md/MD5.kt index 9b542cd..d03d05e 100644 --- a/src/commonTest/kotlin/com/infendro/hash/md/MD5.kt +++ b/src/commonTest/kotlin/com/infendro/hash/md/MD5.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `MD5 Test` { +class MD5_Test { val function = MD5 @Test @@ -16,15 +16,11 @@ class `MD5 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xd4U, 0x1dU, 0x8cU, 0xd9U, - 0x8fU, 0x00U, 0xb2U, 0x04U, - 0xe9U, 0x80U, 0x09U, 0x98U, - 0xecU, 0xf8U, 0x42U, 0x7eU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x2c, +0x1d, -0x74, -0x27, -0x71, +0x00, -0x4e, +0x04, + -0x17, -0x80, +0x09, -0x68, -0x14, -0x08, +0x42, +0x7e, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/sha1/SHA1.kt b/src/commonTest/kotlin/com/infendro/hash/sha1/SHA1.kt index 32018df..a5d0f5a 100644 --- a/src/commonTest/kotlin/com/infendro/hash/sha1/SHA1.kt +++ b/src/commonTest/kotlin/com/infendro/hash/sha1/SHA1.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA1 Test` { +class SHA1_Test { val function = SHA1 @Test @@ -16,16 +16,12 @@ class `SHA1 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xdaU, 0x39U, 0xa3U, 0xeeU, - 0x5eU, 0x6bU, 0x4bU, 0x0dU, - 0x32U, 0x55U, 0xbfU, 0xefU, - 0x95U, 0x60U, 0x18U, 0x90U, - 0xafU, 0xd8U, 0x07U, 0x09U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x26, +0x39, -0x5d, -0x12, +0x5e, +0x6b, +0x4b, +0x0d, + +0x32, +0x55, -0x41, -0x11, -0x6b, +0x60, +0x18, -0x70, + -0x51, -0x28, +0x07, +0x09, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-224.kt b/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-224.kt index e324370..ff3351a 100644 --- a/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-224.kt +++ b/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-224.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA-224 Test` { +class `SHA-224_Test` { val function = `SHA-224` @Test @@ -16,18 +16,13 @@ class `SHA-224 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xd1U, 0x4aU, 0x02U, 0x8cU, - 0x2aU, 0x3aU, 0x2bU, 0xc9U, - 0x47U, 0x61U, 0x02U, 0xbbU, - 0x28U, 0x82U, 0x34U, 0xc4U, - 0x15U, 0xa2U, 0xb0U, 0x1fU, - 0x82U, 0x8eU, 0xa6U, 0x2aU, - 0xc5U, 0xb3U, 0xe4U, 0x2fU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x2f, +0x4a, +0x02, -0x74, +0x2a, +0x3a, +0x2b, -0x37, + +0x47, +0x61, +0x02, -0x45, +0x28, -0x7e, +0x34, -0x3c, + +0x15, -0x5e, -0x50, +0x1f, -0x7e, -0x72, -0x5a, +0x2a, + -0x3b, -0x4d, -0x1c, +0x2f, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-256.kt b/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-256.kt index 4cba687..83fad5d 100644 --- a/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-256.kt +++ b/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-256.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA-256 Test` { +class `SHA-256_Test` { val function = `SHA-256` @Test @@ -16,19 +16,13 @@ class `SHA-256 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xe3U, 0xb0U, 0xc4U, 0x42U, - 0x98U, 0xfcU, 0x1cU, 0x14U, - 0x9aU, 0xfbU, 0xf4U, 0xc8U, - 0x99U, 0x6fU, 0xb9U, 0x24U, - 0x27U, 0xaeU, 0x41U, 0xe4U, - 0x64U, 0x9bU, 0x93U, 0x4cU, - 0xa4U, 0x95U, 0x99U, 0x1bU, - 0x78U, 0x52U, 0xb8U, 0x55U, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x1d, -0x50, -0x3c, +0x42, -0x68, -0x04, +0x1c, +0x14, + -0x66, -0x05, -0x0c, -0x38, -0x67, +0x6f, -0x47, +0x24, + +0x27, -0x52, +0x41, -0x1c, +0x64, -0x65, -0x6d, +0x4c, + -0x5c, -0x6b, -0x67, +0x1b, +0x78, +0x52, -0x48, +0x55, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-384.kt b/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-384.kt index 68a0704..754a632 100644 --- a/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-384.kt +++ b/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-384.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA-384 Test` { +class `SHA-384_Test` { val function = `SHA-384` @Test @@ -16,23 +16,15 @@ class `SHA-384 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0x38U, 0xb0U, 0x60U, 0xa7U, - 0x51U, 0xacU, 0x96U, 0x38U, - 0x4cU, 0xd9U, 0x32U, 0x7eU, - 0xb1U, 0xb1U, 0xe3U, 0x6aU, - 0x21U, 0xfdU, 0xb7U, 0x11U, - 0x14U, 0xbeU, 0x07U, 0x43U, - 0x4cU, 0x0cU, 0xc7U, 0xbfU, - 0x63U, 0xf6U, 0xe1U, 0xdaU, - 0x27U, 0x4eU, 0xdeU, 0xbfU, - 0xe7U, 0x6fU, 0x65U, 0xfbU, - 0xd5U, 0x1aU, 0xd2U, 0xf1U, - 0x48U, 0x98U, 0xb9U, 0x5bU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + +0x38, -0x50, +0x60, -0x59, +0x51, -0x54, -0x6a, +0x38, + +0x4c, -0x27, +0x32, +0x7e, -0x4f, -0x4f, -0x1d, +0x6a, + +0x21, -0x03, -0x49, +0x11, +0x14, -0x42, +0x07, +0x43, + +0x4c, +0x0c, -0x39, -0x41, +0x63, -0x0a, -0x1f, -0x26, + +0x27, +0x4e, -0x22, -0x41, -0x19, +0x6f, +0x65, -0x05, + -0x2b, +0x1a, -0x2e, -0x0f, +0x48, -0x68, -0x47, +0x5b, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } } diff --git a/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-512.kt b/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-512.kt index 1ac9cc6..f926638 100644 --- a/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-512.kt +++ b/src/commonTest/kotlin/com/infendro/hash/sha2/SHA-512.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -class `SHA-512 Test` { +class `SHA-512_Test` { val function = `SHA-512` @Test @@ -16,27 +16,17 @@ class `SHA-512 Test` { @Test fun `empty bytearray`() { - val expected = ubyteArrayOf( - 0xcfU, 0x83U, 0xe1U, 0x35U, - 0x7eU, 0xefU, 0xb8U, 0xbdU, - 0xf1U, 0x54U, 0x28U, 0x50U, - 0xd6U, 0x6dU, 0x80U, 0x07U, - 0xd6U, 0x20U, 0xe4U, 0x05U, - 0x0bU, 0x57U, 0x15U, 0xdcU, - 0x83U, 0xf4U, 0xa9U, 0x21U, - 0xd3U, 0x6cU, 0xe9U, 0xceU, - 0x47U, 0xd0U, 0xd1U, 0x3cU, - 0x5dU, 0x85U, 0xf2U, 0xb0U, - 0xffU, 0x83U, 0x18U, 0xd2U, - 0x87U, 0x7eU, 0xecU, 0x2fU, - 0x63U, 0xb9U, 0x31U, 0xbdU, - 0x47U, 0x41U, 0x7aU, 0x81U, - 0xa5U, 0x38U, 0x32U, 0x7aU, - 0xf9U, 0x27U, 0xdaU, 0x3eU, - ).asByteArray() - val actual = function.hash( - ByteArray(0), + val expected = byteArrayOf( + -0x31, -0x7d, -0x1f, +0x35, +0x7e, -0x11, -0x48, -0x43, + -0x0f, +0x54, +0x28, +0x50, -0x2a, +0x6d, -0x80, +0x07, + -0x2a, +0x20, -0x1c, +0x05, +0x0b, +0x57, +0x15, -0x24, + -0x7d, -0x0c, -0x57, +0x21, -0x2d, +0x6c, -0x17, -0x32, + +0x47, -0x30, -0x2f, +0x3c, +0x5d, -0x7b, -0x0e, -0x50, + -0x01, -0x7d, +0x18, -0x2e, -0x79, +0x7e, -0x14, +0x2f, + +0x63, -0x47, +0x31, -0x43, +0x47, +0x41, +0x7a, -0x7f, + -0x5b, +0x38, +0x32, +0x7a, -0x07, +0x27, -0x26, +0x3e, ) + val actual = function.hash(ByteArray(0)) assertContentEquals(expected, actual) } }