implement tests
Some checks failed
/ publish (push) Has been cancelled

also fix MD5
This commit is contained in:
2025-11-10 17:42:15 +01:00
parent 9b93fbd093
commit d033d895da
28 changed files with 469 additions and 30 deletions

View File

@@ -0,0 +1,33 @@
package com.infendro.hash.keccak.sha3
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA3-224 Test` {
val function = `SHA3-224`
@Test
fun `bytes and block`() {
assertEquals(28, function.bytes)
assertEquals(224, function.bits)
assertEquals(144, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,34 @@
package com.infendro.hash.keccak.sha3
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA3-256 Test` {
val function = `SHA3-256`
@Test
fun `bytes and block`() {
assertEquals(32, function.bytes)
assertEquals(256, function.bits)
assertEquals(136, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,38 @@
package com.infendro.hash.keccak.sha3
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA3-384 Test` {
val function = `SHA3-384`
@Test
fun `bytes and block`() {
assertEquals(48, function.bytes)
assertEquals(384, function.bits)
assertEquals(104, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,42 @@
package com.infendro.hash.keccak.sha3
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA3-512 Test` {
val function = `SHA3-512`
@Test
fun `bytes and block`() {
assertEquals(64, function.bytes)
assertEquals(512, function.bits)
assertEquals(72, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,34 @@
package com.infendro.hash.keccak.shake
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHAKE128 Test` {
val function = SHAKE128(32)
@Test
fun `bytes and block`() {
assertEquals(32, function.bytes)
assertEquals(256, function.bits)
assertEquals(168, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,42 @@
package com.infendro.hash.keccak.shake
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHAKE256 Test` {
val function = SHAKE256(64)
@Test
fun `bytes and block`() {
assertEquals(64, function.bytes)
assertEquals(512, function.bits)
assertEquals(136, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,30 @@
package com.infendro.hash.md
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `MD5 Test` {
val function = MD5
@Test
fun `bytes and block`() {
assertEquals(16, function.bytes)
assertEquals(128, function.bits)
assertEquals(64, function.block)
}
@Test
fun `empty bytearray`() {
val expected = ubyteArrayOf(
0xd4U, 0x1dU, 0x8cU, 0xd9U,
0x8fU, 0x00U, 0xb2U, 0x04U,
0xe9U, 0x80U, 0x09U, 0x98U,
0xecU, 0xf8U, 0x42U, 0x7eU,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,31 @@
package com.infendro.hash.sha1
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA1 Test` {
val function = SHA1
@Test
fun `bytes and block`() {
assertEquals(20, function.bytes)
assertEquals(160, function.bits)
assertEquals(64, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,33 @@
package com.infendro.hash.sha2
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA-224 Test` {
val function = `SHA-224`
@Test
fun `bytes and block`() {
assertEquals(28, function.bytes)
assertEquals(224, function.bits)
assertEquals(64, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,34 @@
package com.infendro.hash.sha2
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA-256 Test` {
val function = `SHA-256`
@Test
fun `bytes and block`() {
assertEquals(32, function.bytes)
assertEquals(256, function.bits)
assertEquals(64, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,38 @@
package com.infendro.hash.sha2
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA-384 Test` {
val function = `SHA-384`
@Test
fun `bytes and block`() {
assertEquals(48, function.bytes)
assertEquals(384, function.bits)
assertEquals(128, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,42 @@
package com.infendro.hash.sha2
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class `SHA-512 Test` {
val function = `SHA-512`
@Test
fun `bytes and block`() {
assertEquals(64, function.bytes)
assertEquals(512, function.bits)
assertEquals(128, function.block)
}
@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,
)
val actual = function.hash(
ubyteArrayOf()
)
assertContentEquals(expected, actual)
}
}