1.5.1 release #8

Merged
Infendro merged 1 commits from develop into main 2026-01-22 11:20:04 +00:00
16 changed files with 41 additions and 34 deletions

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@ repositories {
} }
dependencies { dependencies {
implementation("com.infendro:hash:1.5.0") implementation("com.infendro:hash:1.5.1")
} }
``` ```
+1 -1
View File
@@ -5,7 +5,7 @@ import com.infendro.plugin.token
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
group = "com.infendro" group = "com.infendro"
version = "1.5.0" version = "1.5.1"
plugins { plugins {
alias(libs.plugins.infendro) alias(libs.plugins.infendro)
@@ -7,15 +7,15 @@ interface HashFunction {
val block: Int val block: Int
fun hashInto(value: ByteArray, destination: ByteArray) fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int = 0)
fun hashInto(value: ByteArray, destination: UByteArray) = fun hashInto(value: ByteArray, destination: UByteArray, destinationOffset: Int = 0) =
hashInto(value, destination.asByteArray()) hashInto(value, destination.asByteArray())
fun hashInto(value: UByteArray, destination: UByteArray) = fun hashInto(value: UByteArray, destination: UByteArray, destinationOffset: Int = 0) =
hashInto(value.asByteArray(), destination.asByteArray()) hashInto(value.asByteArray(), destination.asByteArray())
fun hashInto(value: UByteArray, destination: ByteArray) = fun hashInto(value: UByteArray, destination: ByteArray, destinationOffset: Int = 0) =
hashInto(value.asByteArray(), destination) hashInto(value.asByteArray(), destination)
fun hash(value: ByteArray): ByteArray = fun hash(value: ByteArray): ByteArray =
@@ -19,7 +19,7 @@ object `Blake-224` : HashFunction {
0x64f98fa7U, 0xbefa4fa4U, 0x64f98fa7U, 0xbefa4fa4U,
).asIntArray() ).asIntArray()
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val length = value.size.toULong() * 8UL val length = value.size.toULong() * 8UL
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
@@ -31,7 +31,7 @@ object `Blake-224` : HashFunction {
t += minOf(length - t, 512UL).toUInt() t += minOf(length - t, 512UL).toUInt()
`Blake-256`.compress(h, input, i, m, v, t) `Blake-256`.compress(h, input, i, m, v, t)
} }
h.copyInto(destination, endIndex = 7) h.copyInto(destination, destinationOffset, endIndex = 7)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -44,7 +44,7 @@ object `Blake-256` : HashFunction {
intArrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0), intArrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0),
) )
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val length = value.size.toULong() * 8UL val length = value.size.toULong() * 8UL
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
@@ -56,7 +56,7 @@ object `Blake-256` : HashFunction {
t += minOf(length - t, 512UL).toUInt() t += minOf(length - t, 512UL).toUInt()
compress(h, input, i, m, v, t) compress(h, input, i, m, v, t)
} }
h.copyInto(destination) h.copyInto(destination, destinationOffset)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -19,7 +19,7 @@ object `Blake-384` : HashFunction {
0xdb0c2e0d64f98fa7U, 0x47b5481dbefa4fa4U, 0xdb0c2e0d64f98fa7U, 0x47b5481dbefa4fa4U,
).asLongArray() ).asLongArray()
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val length = value.size.toULong() * 8UL val length = value.size.toULong() * 8UL
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
@@ -31,7 +31,7 @@ object `Blake-384` : HashFunction {
t += minOf(length - t, 1024UL) t += minOf(length - t, 1024UL)
`Blake-512`.compress(h, input, i, m, v, t) `Blake-512`.compress(h, input, i, m, v, t)
} }
h.copyInto(destination, endIndex = 6) h.copyInto(destination, destinationOffset, endIndex = 6)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -44,7 +44,7 @@ object `Blake-512` : HashFunction {
intArrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0), intArrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0),
) )
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val length = value.size.toULong() * 8UL val length = value.size.toULong() * 8UL
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
@@ -56,7 +56,7 @@ object `Blake-512` : HashFunction {
t += minOf(length - t, 1024UL) t += minOf(length - t, 1024UL)
compress(h, input, i, m, v, t) compress(h, input, i, m, v, t)
} }
h.copyInto(destination) h.copyInto(destination, destinationOffset)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -36,7 +36,7 @@ class Blake2b(
intArrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0), intArrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0),
) )
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val length = value.size.toULong() val length = value.size.toULong()
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
@@ -49,7 +49,7 @@ class Blake2b(
t += minOf(length - t, 128UL) t += minOf(length - t, 128UL)
compress(h, input, i, m, v, t, t < 1024UL) compress(h, input, i, m, v, t, t < 1024UL)
} }
h.toByteArray(LITTLE_ENDIAN).copyInto(destination, endIndex = bytes) h.toByteArray(LITTLE_ENDIAN).copyInto(destination, destinationOffset, endIndex = bytes)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -36,7 +36,7 @@ class Blake2s(
intArrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0), intArrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0),
) )
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val length = value.size.toULong() val length = value.size.toULong()
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
@@ -49,7 +49,7 @@ class Blake2s(
t += minOf(length - t, 64UL).toUInt() t += minOf(length - t, 64UL).toUInt()
compress(h, input, i, m, v, t, t < 1024UL) compress(h, input, i, m, v, t, t < 1024UL)
} }
h.toByteArray(LITTLE_ENDIAN).copyInto(destination, endIndex = bytes) h.toByteArray(LITTLE_ENDIAN).copyInto(destination, destinationOffset, endIndex = bytes)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -36,7 +36,7 @@ open class Keccak(
intArrayOf(27, 20, 39, 8, 14), intArrayOf(27, 20, 39, 8, 14),
) )
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = pad(value) val input = pad(value)
val state = LongArray(25) val state = LongArray(25)
val w = LongArray(block / 8) val w = LongArray(block / 8)
@@ -48,7 +48,7 @@ open class Keccak(
absorb(state, input, i, w) absorb(state, input, i, w)
permute(state, b, c, d) permute(state, b, c, d)
} }
squeeze(state, b, c, d, destination) squeeze(state, b, c, d, destination, destinationOffset)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -67,7 +67,14 @@ open class Keccak(
} }
} }
private fun squeeze(state: LongArray, b: LongArray, c: LongArray, d: LongArray, destination: ByteArray) { private fun squeeze(
state: LongArray,
b: LongArray,
c: LongArray,
d: LongArray,
destination: ByteArray,
destinationOffset: Int,
) {
val buffer = ByteArray(8) val buffer = ByteArray(8)
val threshold = rate / 8 val threshold = rate / 8
@@ -81,7 +88,7 @@ open class Keccak(
val length = minOf(bytes - consumed, 8) val length = minOf(bytes - consumed, 8)
state[i].copyInto(buffer, order = LITTLE_ENDIAN) state[i].copyInto(buffer, order = LITTLE_ENDIAN)
buffer.copyInto(destination, consumed, endIndex = length) buffer.copyInto(destination, destinationOffset + consumed, endIndex = length)
consumed += length consumed += length
i++ i++
@@ -49,7 +49,7 @@ object MD5 : HashFunction {
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,
) )
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
val w = IntArray(16) val w = IntArray(16)
@@ -58,7 +58,7 @@ object MD5 : HashFunction {
for (i in input.indices step block) { for (i in input.indices step block) {
process(h, input, i, w, v) process(h, input, i, w, v)
} }
h.copyInto(destination, order = LITTLE_ENDIAN) h.copyInto(destination, destinationOffset, order = LITTLE_ENDIAN)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -24,7 +24,7 @@ object SHA1 : HashFunction {
0x8f1bbcdcU, 0xca62c1d6U, 0x8f1bbcdcU, 0xca62c1d6U,
).asIntArray() ).asIntArray()
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
val w = IntArray(80) val w = IntArray(80)
@@ -33,7 +33,7 @@ object SHA1 : HashFunction {
for (i in input.indices step block) { for (i in input.indices step block) {
process(h, input, i, w, v) process(h, input, i, w, v)
} }
h.copyInto(destination) h.copyInto(destination, destinationOffset)
} }
private fun pad(value: ByteArray): ByteArray { private fun pad(value: ByteArray): ByteArray {
@@ -17,7 +17,7 @@ object `SHA-224` : HashFunction {
0x64f98fa7U, 0xbefa4fa4U, 0x64f98fa7U, 0xbefa4fa4U,
).asIntArray() ).asIntArray()
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = `SHA-256`.pad(value) val input = `SHA-256`.pad(value)
val h = initial.copyOf() val h = initial.copyOf()
val w = IntArray(64) val w = IntArray(64)
@@ -26,6 +26,6 @@ object `SHA-224` : HashFunction {
for (i in input.indices step block) { for (i in input.indices step block) {
`SHA-256`.process(h, input, i, w, v) `SHA-256`.process(h, input, i, w, v)
} }
h.copyInto(destination, endIndex = 7) h.copyInto(destination, destinationOffset, endIndex = 7)
} }
} }
@@ -31,7 +31,7 @@ object `SHA-256` : HashFunction {
0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U, 0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U,
).asIntArray() ).asIntArray()
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
val w = IntArray(64) val w = IntArray(64)
@@ -40,7 +40,7 @@ object `SHA-256` : HashFunction {
for (i in input.indices step block) { for (i in input.indices step block) {
process(h, input, i, w, v) process(h, input, i, w, v)
} }
h.copyInto(destination) h.copyInto(destination, destinationOffset)
} }
internal fun pad(value: ByteArray): ByteArray { internal fun pad(value: ByteArray): ByteArray {
@@ -17,7 +17,7 @@ object `SHA-384` : HashFunction {
0xdb0c2e0d64f98fa7UL, 0x47b5481dbefa4fa4UL, 0xdb0c2e0d64f98fa7UL, 0x47b5481dbefa4fa4UL,
).asLongArray() ).asLongArray()
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = `SHA-512`.pad(value) val input = `SHA-512`.pad(value)
val h = initial.copyOf() val h = initial.copyOf()
val w = LongArray(80) val w = LongArray(80)
@@ -26,6 +26,6 @@ object `SHA-384` : HashFunction {
for (i in input.indices step block) { for (i in input.indices step block) {
`SHA-512`.process(h, input, i, w, v) `SHA-512`.process(h, input, i, w, v)
} }
h.copyInto(destination, endIndex = 6) h.copyInto(destination, destinationOffset, endIndex = 6)
} }
} }
@@ -43,7 +43,7 @@ object `SHA-512` : HashFunction {
0x4cc5d4becb3e42b6UL, 0x597f299cfc657e2aUL, 0x5fcb6fab3ad6faecUL, 0x6c44198c4a475817UL, 0x4cc5d4becb3e42b6UL, 0x597f299cfc657e2aUL, 0x5fcb6fab3ad6faecUL, 0x6c44198c4a475817UL,
).asLongArray() ).asLongArray()
override fun hashInto(value: ByteArray, destination: ByteArray) { override fun hashInto(value: ByteArray, destination: ByteArray, destinationOffset: Int) {
val input = pad(value) val input = pad(value)
val h = initial.copyOf() val h = initial.copyOf()
val w = LongArray(80) val w = LongArray(80)
@@ -52,7 +52,7 @@ object `SHA-512` : HashFunction {
for (i in input.indices step block) { for (i in input.indices step block) {
process(h, input, i, w, v) process(h, input, i, w, v)
} }
h.copyInto(destination) h.copyInto(destination, destinationOffset)
} }
internal fun pad(value: ByteArray): ByteArray { internal fun pad(value: ByteArray): ByteArray {