Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
[versions]
androidx-test-runner = "1.5.2"
androidx-test-runner = "1.5.2"

bouncy-castle = "1.73"
bouncy-castle = "1.73"

encoding = "2.3.1"
encoding = "2.3.1"

gradle-android = "8.2.2"
gradle-benchmark = "0.4.11"
gradle-binary-compat = "0.16.3"
gradle-kmp-configuration = "0.3.2"
gradle-kotlin = "1.9.24"
gradle-publish-maven = "0.29.0"
gradle-android = "8.2.2"
gradle-benchmark = "0.4.11"
gradle-binary-compat = "0.16.3"
gradle-kmp-configuration = "0.3.2"
gradle-kotlin = "1.9.24"
gradle-publish-maven = "0.29.0"

kotlincrypto-bitops = "0.1.2"
kotlincrypto-core = "0.6.0"
kotlincrypto-sponges = "0.3.4"
kotlincrypto-bitops = "0.1.2"
kotlincrypto-core = "0.6.1-SNAPSHOT"
kotlincrypto-sponges = "0.3.4"

[libraries]
gradle-kmp-configuration = { module = "io.matthewnelson:gradle-kmp-configuration-plugin", version.ref = "gradle-kmp-configuration" }
gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "gradle-kotlin" }
gradle-publish-maven = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradle-publish-maven" }

kotlincrypto-bitops-bits = { module = "org.kotlincrypto.bitops:bits", version.ref = "kotlincrypto-bitops" }
kotlincrypto-bitops-endian = { module = "org.kotlincrypto.bitops:endian", version.ref = "kotlincrypto-bitops" }
kotlincrypto-core-digest = { module = "org.kotlincrypto.core:digest", version.ref = "kotlincrypto-core" }
kotlincrypto-core-xof = { module = "org.kotlincrypto.core:xof", version.ref = "kotlincrypto-core" }
gradle-kmp-configuration = { module = "io.matthewnelson:gradle-kmp-configuration-plugin", version.ref = "gradle-kmp-configuration" }
gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "gradle-kotlin" }
gradle-publish-maven = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradle-publish-maven" }

kotlincrypto-bitops-bits = { module = "org.kotlincrypto.bitops:bits", version.ref = "kotlincrypto-bitops" }
kotlincrypto-bitops-endian = { module = "org.kotlincrypto.bitops:endian", version.ref = "kotlincrypto-bitops" }
kotlincrypto-core-digest = { module = "org.kotlincrypto.core:digest", version.ref = "kotlincrypto-core" }
kotlincrypto-core-xof = { module = "org.kotlincrypto.core:xof", version.ref = "kotlincrypto-core" }
kotlincrypto-sponges-keccak = { module = "org.kotlincrypto.sponges:keccak", version.ref = "kotlincrypto-sponges" }

# tests & tools
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" }
benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "gradle-benchmark" }
bouncy-castle = { module = "org.bouncycastle:bcprov-ext-jdk15to18", version.ref = "bouncy-castle" }
encoding-base16 = { module = "io.matthewnelson.encoding:base16", version.ref = "encoding" }
encoding-base64 = { module = "io.matthewnelson.encoding:base64", version.ref = "encoding" }
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" }
benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "gradle-benchmark" }
bouncy-castle = { module = "org.bouncycastle:bcprov-ext-jdk15to18", version.ref = "bouncy-castle" }
encoding-base16 = { module = "io.matthewnelson.encoding:base16", version.ref = "encoding" }
encoding-base64 = { module = "io.matthewnelson.encoding:base64", version.ref = "encoding" }

[plugins]
android-library = { id = "com.android.library", version.ref = "gradle-android" }
benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "gradle-benchmark" }
binary-compat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "gradle-binary-compat" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "gradle-kotlin" }
android-library = { id = "com.android.library", version.ref = "gradle-android" }
benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "gradle-benchmark" }
binary-compat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "gradle-binary-compat" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "gradle-kotlin" }
14 changes: 8 additions & 6 deletions library/blake2/api/blake2.api
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ public abstract class org/kotlincrypto/hash/blake2/BLAKE2Digest : org/kotlincryp
public abstract class org/kotlincrypto/hash/blake2/BLAKE2Digest$Bit32 : org/kotlincrypto/hash/blake2/BLAKE2Digest {
public synthetic fun <init> (Ljava/lang/String;IZIIIIJII[B[BLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lorg/kotlincrypto/hash/blake2/BLAKE2Digest$Bit32;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
protected fun compressProtected ([BI)V
protected final fun compressProtected ([BI)V
public abstract fun copy ()Lorg/kotlincrypto/hash/blake2/BLAKE2Digest$Bit32;
protected fun digestProtected ([BI)[B
protected fun resetProtected ()V
protected final fun digestIntoProtected ([BI[BI)V
protected final fun digestProtected ([BI)[B
protected final fun resetProtected ()V
}

public abstract class org/kotlincrypto/hash/blake2/BLAKE2Digest$Bit64 : org/kotlincrypto/hash/blake2/BLAKE2Digest {
public synthetic fun <init> (Ljava/lang/String;IZIIIIJII[B[BLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lorg/kotlincrypto/hash/blake2/BLAKE2Digest$Bit64;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
protected fun compressProtected ([BI)V
protected final fun compressProtected ([BI)V
public abstract fun copy ()Lorg/kotlincrypto/hash/blake2/BLAKE2Digest$Bit64;
protected fun digestProtected ([BI)[B
protected fun resetProtected ()V
protected final fun digestIntoProtected ([BI[BI)V
protected final fun digestProtected ([BI)[B
protected final fun resetProtected ()V
}

public final class org/kotlincrypto/hash/blake2/BLAKE2b : org/kotlincrypto/hash/blake2/BLAKE2Digest$Bit64 {
Expand Down
14 changes: 8 additions & 6 deletions library/blake2/api/blake2.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ sealed class org.kotlincrypto.hash.blake2/BLAKE2Digest : org.kotlincrypto.core.d
constructor <init>(org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.<init>|<init>(org.kotlincrypto.hash.blake2.BLAKE2Digest.Bit32){}[0]

abstract fun copy(): org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32 // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.copy|copy(){}[0]
open fun compressProtected(kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.compressProtected|compressProtected(kotlin.ByteArray;kotlin.Int){}[0]
open fun digestProtected(kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.digestProtected|digestProtected(kotlin.ByteArray;kotlin.Int){}[0]
open fun resetProtected() // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.resetProtected|resetProtected(){}[0]
final fun compressProtected(kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.compressProtected|compressProtected(kotlin.ByteArray;kotlin.Int){}[0]
final fun digestIntoProtected(kotlin/ByteArray, kotlin/Int, kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.digestIntoProtected|digestIntoProtected(kotlin.ByteArray;kotlin.Int;kotlin.ByteArray;kotlin.Int){}[0]
final fun digestProtected(kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.digestProtected|digestProtected(kotlin.ByteArray;kotlin.Int){}[0]
final fun resetProtected() // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit32.resetProtected|resetProtected(){}[0]
}

sealed class Bit64 : org.kotlincrypto.hash.blake2/BLAKE2Digest { // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64|null[0]
constructor <init>(kotlin/String, kotlin/Int, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Long, kotlin/Int, kotlin/Int, kotlin/ByteArray?, kotlin/ByteArray?) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.<init>|<init>(kotlin.String;kotlin.Int;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Int;kotlin.Int;kotlin.ByteArray?;kotlin.ByteArray?){}[0]
constructor <init>(org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.<init>|<init>(org.kotlincrypto.hash.blake2.BLAKE2Digest.Bit64){}[0]

abstract fun copy(): org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64 // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.copy|copy(){}[0]
open fun compressProtected(kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.compressProtected|compressProtected(kotlin.ByteArray;kotlin.Int){}[0]
open fun digestProtected(kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.digestProtected|digestProtected(kotlin.ByteArray;kotlin.Int){}[0]
open fun resetProtected() // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.resetProtected|resetProtected(){}[0]
final fun compressProtected(kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.compressProtected|compressProtected(kotlin.ByteArray;kotlin.Int){}[0]
final fun digestIntoProtected(kotlin/ByteArray, kotlin/Int, kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.digestIntoProtected|digestIntoProtected(kotlin.ByteArray;kotlin.Int;kotlin.ByteArray;kotlin.Int){}[0]
final fun digestProtected(kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.digestProtected|digestProtected(kotlin.ByteArray;kotlin.Int){}[0]
final fun resetProtected() // org.kotlincrypto.hash.blake2/BLAKE2Digest.Bit64.resetProtected|resetProtected(){}[0]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public sealed class BLAKE2Digest: Digest {

public abstract override fun copy(): Bit32

protected override fun compressProtected(input: ByteArray, offset: Int) {
protected final override fun compressProtected(input: ByteArray, offset: Int) {
val m = m

if (m == null) {
Expand All @@ -144,7 +144,13 @@ public sealed class BLAKE2Digest: Digest {
m.populate(input, offset)
}

protected override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray {
protected final override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray {
val digest = ByteArray(digestLength())
digestIntoProtected(digest, 0, buf, bufPos)
return digest
}

protected final override fun digestIntoProtected(dest: ByteArray, destOffset: Int, buf: ByteArray, bufPos: Int) {
var m = m

if (m != null) {
Expand Down Expand Up @@ -176,23 +182,20 @@ public sealed class BLAKE2Digest: Digest {
val rem = len % Int.SIZE_BYTES
val iHEnd = len / Int.SIZE_BYTES

val out = h.lePackIntoUnsafe(
dest = ByteArray(len),
destOffset = 0,
h.lePackIntoUnsafe(
dest = dest,
destOffset = destOffset,
sourceIndexStart = 0,
sourceIndexEnd = iHEnd,
)

if (rem > 0) {
h[iHEnd].lePackIntoUnsafe(
dest = out,
destOffset = len - rem,
sourceIndexStart = 0,
sourceIndexEnd = rem,
)
}

return out
if (rem == 0) return
h[iHEnd].lePackIntoUnsafe(
dest = dest,
destOffset = destOffset + len - rem,
sourceIndexStart = 0,
sourceIndexEnd = rem,
)
}

private inline fun F(h: IntArray, m: Bit32Message, tLo: Int, tHi: Int, f0: Int, f1: Int) {
Expand Down Expand Up @@ -292,7 +295,7 @@ public sealed class BLAKE2Digest: Digest {
return this
}

protected override fun resetProtected() {
protected final override fun resetProtected() {
v.fill(0)
h.initialize()
m?.fill()
Expand Down Expand Up @@ -376,7 +379,7 @@ public sealed class BLAKE2Digest: Digest {

public abstract override fun copy(): Bit64

protected override fun compressProtected(input: ByteArray, offset: Int) {
protected final override fun compressProtected(input: ByteArray, offset: Int) {
val m = m

if (m == null) {
Expand All @@ -402,7 +405,13 @@ public sealed class BLAKE2Digest: Digest {
m.populate(input, offset)
}

protected override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray {
protected final override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray {
val digest = ByteArray(digestLength())
digestIntoProtected(digest, 0, buf, bufPos)
return digest
}

protected final override fun digestIntoProtected(dest: ByteArray, destOffset: Int, buf: ByteArray, bufPos: Int) {
var m = m

if (m != null) {
Expand Down Expand Up @@ -434,23 +443,20 @@ public sealed class BLAKE2Digest: Digest {
val rem = len % Long.SIZE_BYTES
val iHEnd = len / Long.SIZE_BYTES

val out = h.lePackIntoUnsafe(
dest = ByteArray(len),
destOffset = 0,
h.lePackIntoUnsafe(
dest = dest,
destOffset = destOffset,
sourceIndexStart = 0,
sourceIndexEnd = iHEnd,
)

if (rem > 0) {
h[iHEnd].lePackIntoUnsafe(
dest = out,
destOffset = len - rem,
sourceIndexStart = 0,
sourceIndexEnd = rem,
)
}

return out
if (rem == 0) return
h[iHEnd].lePackIntoUnsafe(
dest = dest,
destOffset = destOffset + len - rem,
sourceIndexStart = 0,
sourceIndexEnd = rem,
)
}

private inline fun F(h: LongArray, m: Bit64Message, tLo: Long, tHi: Long, f0: Long, f1: Long) {
Expand Down Expand Up @@ -551,7 +557,7 @@ public sealed class BLAKE2Digest: Digest {
return this
}

protected override fun resetProtected() {
protected final override fun resetProtected() {
v.fill(0)
h.initialize()
m?.fill()
Expand Down
11 changes: 7 additions & 4 deletions library/md/src/commonMain/kotlin/org/kotlincrypto/hash/md/MD5.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public class MD5: Digest {
}

protected override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray {
val digest = ByteArray(digestLength())
digestIntoProtected(digest, 0, buf, bufPos)
return digest
}

protected override fun digestIntoProtected(dest: ByteArray, destOffset: Int, buf: ByteArray, bufPos: Int) {
val (bitsLo, bitsHi) = count.final(additional = bufPos).asBits()
buf[bufPos] = 0x80.toByte()

Expand All @@ -118,10 +124,7 @@ public class MD5: Digest {
bitsHi.lePackIntoUnsafe(buf, destOffset = 60)
compressProtected(buf, 0)

return state.lePackIntoUnsafe(
dest = ByteArray(digestLength()),
destOffset = 0,
)
state.lePackIntoUnsafe(dest = dest, destOffset = destOffset)
}

protected override fun resetProtected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ public class SHA1: Digest {
}

protected override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray {
val digest = ByteArray(digestLength())
digestIntoProtected(digest, 0, buf, bufPos)
return digest
}

protected override fun digestIntoProtected(dest: ByteArray, destOffset: Int, buf: ByteArray, bufPos: Int) {
val (bitsLo, bitsHi) = count.final(additional = bufPos).asBits()
buf[bufPos] = 0x80.toByte()

Expand All @@ -128,10 +134,7 @@ public class SHA1: Digest {
bitsLo.bePackIntoUnsafe(buf, destOffset = 60)
compressProtected(buf, 0)

return state.bePackIntoUnsafe(
dest = ByteArray(digestLength()),
destOffset = 0,
)
state.bePackIntoUnsafe(dest = dest, destOffset = destOffset)
}

protected override fun resetProtected() {
Expand Down
2 changes: 2 additions & 0 deletions library/sha2/api/sha2.api
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ public abstract class org/kotlincrypto/hash/sha2/Bit32Digest : org/kotlincrypto/
public synthetic fun <init> (Lorg/kotlincrypto/hash/sha2/Bit32Digest;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
protected final fun compressProtected ([BI)V
public abstract fun copy ()Lorg/kotlincrypto/hash/sha2/Bit32Digest;
protected final fun digestIntoProtected ([BI[BI)V
protected final fun digestProtected ([BI)[B
protected final fun resetProtected ()V
}
Expand All @@ -12,6 +13,7 @@ public abstract class org/kotlincrypto/hash/sha2/Bit64Digest : org/kotlincrypto/
public synthetic fun <init> (Lorg/kotlincrypto/hash/sha2/Bit64Digest;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
protected final fun compressProtected ([BI)V
public abstract fun copy ()Lorg/kotlincrypto/hash/sha2/Bit64Digest;
protected final fun digestIntoProtected ([BI[BI)V
protected final fun digestProtected ([BI)[B
protected final fun resetProtected ()V
}
Expand Down
2 changes: 2 additions & 0 deletions library/sha2/api/sha2.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sealed class org.kotlincrypto.hash.sha2/Bit32Digest : org.kotlincrypto.core.dige

abstract fun copy(): org.kotlincrypto.hash.sha2/Bit32Digest // org.kotlincrypto.hash.sha2/Bit32Digest.copy|copy(){}[0]
final fun compressProtected(kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.sha2/Bit32Digest.compressProtected|compressProtected(kotlin.ByteArray;kotlin.Int){}[0]
final fun digestIntoProtected(kotlin/ByteArray, kotlin/Int, kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.sha2/Bit32Digest.digestIntoProtected|digestIntoProtected(kotlin.ByteArray;kotlin.Int;kotlin.ByteArray;kotlin.Int){}[0]
final fun digestProtected(kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.hash.sha2/Bit32Digest.digestProtected|digestProtected(kotlin.ByteArray;kotlin.Int){}[0]
final fun resetProtected() // org.kotlincrypto.hash.sha2/Bit32Digest.resetProtected|resetProtected(){}[0]
}
Expand All @@ -52,6 +53,7 @@ sealed class org.kotlincrypto.hash.sha2/Bit64Digest : org.kotlincrypto.core.dige

abstract fun copy(): org.kotlincrypto.hash.sha2/Bit64Digest // org.kotlincrypto.hash.sha2/Bit64Digest.copy|copy(){}[0]
final fun compressProtected(kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.sha2/Bit64Digest.compressProtected|compressProtected(kotlin.ByteArray;kotlin.Int){}[0]
final fun digestIntoProtected(kotlin/ByteArray, kotlin/Int, kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.hash.sha2/Bit64Digest.digestIntoProtected|digestIntoProtected(kotlin.ByteArray;kotlin.Int;kotlin.ByteArray;kotlin.Int){}[0]
final fun digestProtected(kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.hash.sha2/Bit64Digest.digestProtected|digestProtected(kotlin.ByteArray;kotlin.Int){}[0]
final fun resetProtected() // org.kotlincrypto.hash.sha2/Bit64Digest.resetProtected|resetProtected(){}[0]
}
Expand Down
Loading
Loading