Files
hash.kt/src/commonTest/kotlin/com/infendro/hash/blake/Blake-512.kt
Infendro 902cb060a1
All checks were successful
/ test (pull_request) Successful in 1m45s
remove unsigned support
2026-02-08 14:04:41 +01:00

65 lines
2.5 KiB
Kotlin

package com.infendro.hash.blake
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `Blake-512_Test` {
val function = `Blake-512`
@Test
fun `bytes and block`() {
assertEquals(64, function.bytes)
assertEquals(512, function.bits)
assertEquals(128, function.block)
}
@Test
fun `empty bytearray`() {
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 = 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 = 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)
}
}