Compare commits
2 Commits
e5bbd9730c
...
9b93fbd093
| Author | SHA1 | Date | |
|---|---|---|---|
|
9b93fbd093
|
|||
|
2051c3fcbd
|
@@ -1,5 +1,5 @@
|
||||
group = "com.infendro"
|
||||
version = "1.3.0"
|
||||
version = "1.3.1"
|
||||
|
||||
repositories {
|
||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||
|
||||
@@ -7,6 +7,8 @@ abstract class HashFunction {
|
||||
val bits: Int
|
||||
get() = bytes * 8
|
||||
|
||||
abstract val block: Int
|
||||
|
||||
abstract fun hash(
|
||||
value: UByteArray,
|
||||
): UByteArray
|
||||
|
||||
@@ -9,7 +9,7 @@ import kotlin.math.min
|
||||
@Suppress("UNUSED")
|
||||
open class Keccak internal constructor(
|
||||
override val bytes: Int,
|
||||
private val rate: Int,
|
||||
override val block: Int,
|
||||
private val domain: UByte,
|
||||
) : HashFunction() {
|
||||
private val rc = ulongArrayOf(
|
||||
@@ -35,7 +35,7 @@ open class Keccak internal constructor(
|
||||
val paddedValue = buildList {
|
||||
addAll(value)
|
||||
add(domain)
|
||||
while ((size % rate) != (rate - 1)) {
|
||||
while ((size % block) != (block - 1)) {
|
||||
add(0x00U)
|
||||
}
|
||||
add(0x80U)
|
||||
@@ -45,7 +45,7 @@ open class Keccak internal constructor(
|
||||
|
||||
// absorb
|
||||
val chunks = paddedValue
|
||||
.chunked(rate) { it.toUByteArray() }
|
||||
.chunked(block) { it.toUByteArray() }
|
||||
for (chunk in chunks) {
|
||||
val numbers = chunk.toULongArray(LITTLE_ENDIAN)
|
||||
for ((i, number) in numbers.withIndex()) {
|
||||
@@ -58,7 +58,7 @@ open class Keccak internal constructor(
|
||||
return buildList {
|
||||
var i = 0
|
||||
while (size < bytes) {
|
||||
if (i == rate / 8) {
|
||||
if (i == block / 8) {
|
||||
permute(state)
|
||||
i = 0
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ object MD5 : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 16
|
||||
|
||||
override val block: Int
|
||||
get() = 64
|
||||
|
||||
private val s = intArrayOf(
|
||||
7, 12, 17, 22,
|
||||
7, 12, 17, 22,
|
||||
|
||||
@@ -9,6 +9,9 @@ object SHA1 : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 20
|
||||
|
||||
override val block: Int
|
||||
get() = 64
|
||||
|
||||
override fun hash(
|
||||
value: UByteArray,
|
||||
): UByteArray {
|
||||
|
||||
@@ -9,6 +9,9 @@ object `SHA-224` : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 28
|
||||
|
||||
override val block: Int
|
||||
get() = 64
|
||||
|
||||
private val k = uintArrayOf(
|
||||
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U,
|
||||
0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U,
|
||||
|
||||
@@ -9,6 +9,9 @@ object `SHA-256` : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 32
|
||||
|
||||
override val block: Int
|
||||
get() = 64
|
||||
|
||||
private val k = uintArrayOf(
|
||||
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U,
|
||||
0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U,
|
||||
|
||||
@@ -9,6 +9,9 @@ object `SHA-384` : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 48
|
||||
|
||||
override val block: Int
|
||||
get() = 128
|
||||
|
||||
private val k = ulongArrayOf(
|
||||
0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL, 0x3956c25bf348b538UL,
|
||||
0x59f111f1b605d019UL, 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL, 0xd807aa98a3030242UL, 0x12835b0145706fbeUL,
|
||||
|
||||
@@ -9,6 +9,9 @@ object `SHA-512` : HashFunction() {
|
||||
override val bytes: Int
|
||||
get() = 64
|
||||
|
||||
override val block: Int
|
||||
get() = 128
|
||||
|
||||
private val k = ulongArrayOf(
|
||||
0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL, 0x3956c25bf348b538UL,
|
||||
0x59f111f1b605d019UL, 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL, 0xd807aa98a3030242UL, 0x12835b0145706fbeUL,
|
||||
|
||||
Reference in New Issue
Block a user