diff --git a/library/blake2/api/blake2.api b/library/blake2/api/blake2.api index f1dd422..a667be7 100644 --- a/library/blake2/api/blake2.api +++ b/library/blake2/api/blake2.api @@ -1,10 +1,14 @@ public abstract class org/kotlincrypto/macs/blake2/BLAKE2Mac : org/kotlincrypto/core/mac/Mac { public synthetic fun (Lorg/kotlincrypto/macs/blake2/BLAKE2Mac$Engine;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun (Lorg/kotlincrypto/macs/blake2/BLAKE2Mac;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun ([BI[BLorg/kotlincrypto/hash/blake2/BLAKE2Digest$KeyedHashFactory;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun ([BI[BLorg/kotlincrypto/macs/blake2/BLAKE2Mac$DigestFactory;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public abstract fun copy ()Lorg/kotlincrypto/macs/blake2/BLAKE2Mac; } +protected abstract interface class org/kotlincrypto/macs/blake2/BLAKE2Mac$DigestFactory { + public abstract fun newInstance (II[B[B)Lorg/kotlincrypto/hash/blake2/BLAKE2Digest; +} + public final class org/kotlincrypto/macs/blake2/BLAKE2b : org/kotlincrypto/macs/blake2/BLAKE2Mac { public fun ([BI)V public fun ([BI[B)V diff --git a/library/blake2/api/blake2.klib.api b/library/blake2/api/blake2.klib.api index d519ecf..b9c0a2f 100644 --- a/library/blake2/api/blake2.klib.api +++ b/library/blake2/api/blake2.klib.api @@ -21,8 +21,12 @@ final class org.kotlincrypto.macs.blake2/BLAKE2s : org.kotlincrypto.macs.blake2/ } sealed class org.kotlincrypto.macs.blake2/BLAKE2Mac : org.kotlincrypto.core.mac/Mac { // org.kotlincrypto.macs.blake2/BLAKE2Mac|null[0] - constructor (kotlin/ByteArray, kotlin/Int, kotlin/ByteArray?, org.kotlincrypto.hash.blake2/BLAKE2Digest.KeyedHashFactory<*>) // org.kotlincrypto.macs.blake2/BLAKE2Mac.|(kotlin.ByteArray;kotlin.Int;kotlin.ByteArray?;org.kotlincrypto.hash.blake2.BLAKE2Digest.KeyedHashFactory<*>){}[0] + constructor (kotlin/ByteArray, kotlin/Int, kotlin/ByteArray?, org.kotlincrypto.macs.blake2/BLAKE2Mac.DigestFactory) // org.kotlincrypto.macs.blake2/BLAKE2Mac.|(kotlin.ByteArray;kotlin.Int;kotlin.ByteArray?;org.kotlincrypto.macs.blake2.BLAKE2Mac.DigestFactory){}[0] constructor (org.kotlincrypto.macs.blake2/BLAKE2Mac) // org.kotlincrypto.macs.blake2/BLAKE2Mac.|(org.kotlincrypto.macs.blake2.BLAKE2Mac){}[0] abstract fun copy(): org.kotlincrypto.macs.blake2/BLAKE2Mac // org.kotlincrypto.macs.blake2/BLAKE2Mac.copy|copy(){}[0] + + abstract fun interface DigestFactory { // org.kotlincrypto.macs.blake2/BLAKE2Mac.DigestFactory|null[0] + abstract fun newInstance(kotlin/Int, kotlin/Int, kotlin/ByteArray?, kotlin/ByteArray?): org.kotlincrypto.hash.blake2/BLAKE2Digest // org.kotlincrypto.macs.blake2/BLAKE2Mac.DigestFactory.newInstance|newInstance(kotlin.Int;kotlin.Int;kotlin.ByteArray?;kotlin.ByteArray?){}[0] + } } diff --git a/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2Mac.kt b/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2Mac.kt index 6e9568f..ebb56c0 100644 --- a/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2Mac.kt +++ b/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2Mac.kt @@ -16,7 +16,6 @@ package org.kotlincrypto.macs.blake2 import org.kotlincrypto.core.Algorithm -import org.kotlincrypto.core.InternalKotlinCryptoApi import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.blake2.BLAKE2Digest @@ -34,22 +33,32 @@ public sealed class BLAKE2Mac: Mac { key: ByteArray, bitStrength: Int, personalization: ByteArray?, - factory: BLAKE2Digest.KeyedHashFactory<*>, + factory: DigestFactory, ): this(Engine(key, bitStrength, personalization, factory)) protected constructor(other: BLAKE2Mac): super(other) + protected fun interface DigestFactory { + + @Throws(IllegalArgumentException::class) + public fun newInstance( + bitStrength: Int, + keyLength: Int, + salt: ByteArray?, + personalization: ByteArray?, + ): BLAKE2Digest + } + private constructor(engine: Engine): super(engine.algorithm(), engine) public abstract override fun copy(): BLAKE2Mac - @OptIn(InternalKotlinCryptoApi::class) private class Engine: Mac.Engine, Algorithm { private val bitStrength: Int private val keyBlock: ByteArray private val personalization: ByteArray? - private val factory: BLAKE2Digest.KeyedHashFactory<*> + private val factory: DigestFactory private var digest: BLAKE2Digest @Throws(IllegalArgumentException::class) @@ -57,11 +66,11 @@ public sealed class BLAKE2Mac: Mac { key: ByteArray, bitStrength: Int, personalization: ByteArray?, - factory: BLAKE2Digest.KeyedHashFactory<*>, + factory: DigestFactory, ): super(key) { this.bitStrength = bitStrength this.personalization = personalization?.copyOf() - this.digest = factory.keyedHashInstance( + this.digest = factory.newInstance( bitStrength = bitStrength, keyLength = key.size, salt = null, @@ -95,7 +104,7 @@ public sealed class BLAKE2Mac: Mac { override fun reset(newKey: ByteArray) { val oldDigest = digest - this.digest = factory.keyedHashInstance( + this.digest = factory.newInstance( bitStrength = bitStrength, keyLength = newKey.size, salt = null, diff --git a/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2b.kt b/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2b.kt index 4b0fe43..74424aa 100644 --- a/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2b.kt +++ b/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2b.kt @@ -15,6 +15,8 @@ **/ package org.kotlincrypto.macs.blake2 +import org.kotlincrypto.core.InternalKotlinCryptoApi + /** * BLAKE2b Keyed Hashing implementation * @@ -65,10 +67,26 @@ public class BLAKE2b: BLAKE2Mac { key = key, bitStrength = bitStrength, personalization = personalization, - factory = org.kotlincrypto.hash.blake2.BLAKE2b, + factory = Companion, ) private constructor(other: BLAKE2b): super(other) public override fun copy(): BLAKE2b = BLAKE2b(this) + + private companion object: DigestFactory { + + @OptIn(InternalKotlinCryptoApi::class) + override fun newInstance( + bitStrength: Int, + keyLength: Int, + salt: ByteArray?, + personalization: ByteArray?, + ): org.kotlincrypto.hash.blake2.BLAKE2b = org.kotlincrypto.hash.blake2.BLAKE2b( + bitStrength = bitStrength, + keyLength = keyLength, + salt = salt, + personalization = personalization, + ) + } } diff --git a/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2s.kt b/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2s.kt index f93de19..fe5459d 100644 --- a/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2s.kt +++ b/library/blake2/src/commonMain/kotlin/org/kotlincrypto/macs/blake2/BLAKE2s.kt @@ -15,6 +15,8 @@ **/ package org.kotlincrypto.macs.blake2 +import org.kotlincrypto.core.InternalKotlinCryptoApi + /** * BLAKE2s Keyed Hashing implementation * @@ -65,10 +67,26 @@ public class BLAKE2s: BLAKE2Mac { key = key, bitStrength = bitStrength, personalization = personalization, - factory = org.kotlincrypto.hash.blake2.BLAKE2s, + factory = Companion, ) private constructor(other: BLAKE2s): super(other) public override fun copy(): BLAKE2s = BLAKE2s(this) + + private companion object: DigestFactory { + + @OptIn(InternalKotlinCryptoApi::class) + override fun newInstance( + bitStrength: Int, + keyLength: Int, + salt: ByteArray?, + personalization: ByteArray?, + ): org.kotlincrypto.hash.blake2.BLAKE2s = org.kotlincrypto.hash.blake2.BLAKE2s( + bitStrength = bitStrength, + keyLength = keyLength, + salt = salt, + personalization = personalization, + ) + } }