From cae73f7be4cc526910c7dafe26c9abfebf6e81a0 Mon Sep 17 00:00:00 2001 From: Matthew Nelson Date: Sun, 12 Jan 2025 13:08:10 -0500 Subject: [PATCH] Update `kotlincrypto.core` and `kotlincrypto.hash` dependencies (#57) --- README.md | 5 +- benchmarks/build.gradle.kts | 3 +- .../macs/benchmarks/BenchmarkBase.kt | 2 + .../macs/benchmarks/HmacSHA2Opts.kt | 2 +- .../macs/benchmarks/HmacSHA3Opts.kt | 2 +- .../kotlincrypto/macs/benchmarks/KmacOpts.kt | 2 +- gradle.properties | 4 +- gradle/libs.versions.toml | 9 +- library/hmac/hmac-md/api/hmac-md.api | 3 + library/hmac/hmac-md/api/hmac-md.klib.api | 2 + .../org/kotlincrypto/macs/hmac/md/HmacMD5.kt | 19 ++- .../macs/hmac/md/HmacMD5UnitTest.kt | 5 + library/hmac/hmac-sha1/api/hmac-sha1.api | 3 + library/hmac/hmac-sha1/api/hmac-sha1.klib.api | 2 + .../kotlincrypto/macs/hmac/sha1/HmacSHA1.kt | 19 ++- .../macs/hmac/sha1/HmacSHA1UnitTest.kt | 5 + library/hmac/hmac-sha2/api/hmac-sha2.api | 15 ++ library/hmac/hmac-sha2/api/hmac-sha2.klib.api | 10 ++ .../kotlincrypto/macs/hmac/sha2/HmacSHA224.kt | 19 ++- .../kotlincrypto/macs/hmac/sha2/HmacSHA256.kt | 19 ++- .../kotlincrypto/macs/hmac/sha2/HmacSHA384.kt | 19 ++- .../kotlincrypto/macs/hmac/sha2/HmacSHA512.kt | 19 ++- .../macs/hmac/sha2/HmacSHA512t.kt | 37 ++--- .../macs/hmac/sha2/HmacSHA512tDeprecated.kt | 30 ++++ .../macs/hmac/sha2/HmacSHA224UnitTest.kt | 5 + .../macs/hmac/sha2/HmacSHA256UnitTest.kt | 5 + .../macs/hmac/sha2/HmacSHA384UnitTest.kt | 5 + .../macs/hmac/sha2/HmacSHA512UnitTest.kt | 5 + .../macs/hmac/sha2/HmacSHA512_224UnitTest.kt | 7 +- .../macs/hmac/sha2/HmacSHA512_256UnitTest.kt | 7 +- library/hmac/hmac-sha3/api/hmac-sha3.api | 24 ++++ library/hmac/hmac-sha3/api/hmac-sha3.klib.api | 16 +++ .../macs/hmac/sha3/HmacKeccak224.kt | 19 ++- .../macs/hmac/sha3/HmacKeccak256.kt | 19 ++- .../macs/hmac/sha3/HmacKeccak384.kt | 19 ++- .../macs/hmac/sha3/HmacKeccak512.kt | 19 ++- .../macs/hmac/sha3/HmacSHA3_224.kt | 19 ++- .../macs/hmac/sha3/HmacSHA3_256.kt | 19 ++- .../macs/hmac/sha3/HmacSHA3_384.kt | 19 ++- .../macs/hmac/sha3/HmacSHA3_512.kt | 19 ++- .../macs/hmac/sha3/HmacKeccak224UnitTest.kt | 5 + .../macs/hmac/sha3/HmacKeccak256UnitTest.kt | 5 + .../macs/hmac/sha3/HmacKeccak384UnitTest.kt | 5 + .../macs/hmac/sha3/HmacKeccak512UnitTest.kt | 5 + .../macs/hmac/sha3/HmacSHA3_224UnitTest.kt | 5 + .../macs/hmac/sha3/HmacSHA3_256UnitTest.kt | 5 + .../macs/hmac/sha3/HmacSHA3_384UnitTest.kt | 5 + .../macs/hmac/sha3/HmacSHA3_512UnitTest.kt | 5 + library/hmac/hmac/api/hmac.api | 3 + library/hmac/hmac/api/hmac.klib.api | 7 +- .../kotlin/org/kotlincrypto/macs/hmac/Hmac.kt | 108 +++++++++------ library/kmac/api/kmac.api | 12 +- library/kmac/api/kmac.klib.api | 10 +- .../org/kotlincrypto/macs/kmac/KMAC128.kt | 18 ++- .../org/kotlincrypto/macs/kmac/KMAC256.kt | 15 +- .../kotlin/org/kotlincrypto/macs/kmac/Kmac.kt | 131 +++++++++++------- .../kotlincrypto/macs/kmac/KMAC128UnitTest.kt | 5 + .../kotlincrypto/macs/kmac/KMAC256UnitTest.kt | 5 + settings.gradle.kts | 1 - .../org/kotlincrypto/macs/MacUnitTest.kt | 59 +++++++- .../org/kotlincrypto/macs/TestJvmMac.kt | 15 +- 61 files changed, 604 insertions(+), 306 deletions(-) create mode 100644 library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512tDeprecated.kt diff --git a/README.md b/README.md index 1f2b1c1..104ae55 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,8 @@ fun main() { HmacSha384(key) HmacSHA512(key) - HmacSHA512_224(key) - HmacSHA512_256(key) - HmacSHA512t(key, 504) + HmacSHA512t(key, 224) // HmacSHA512/224 + HmacSHA512t(key, 256) // HmacSHA512/256 key.fill(0) } diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 6d0bad2..3702060 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -54,11 +54,12 @@ kmpConfiguration { sourceSetMain { dependencies { implementation(libs.benchmark.runtime) + implementation(libs.kotlincrypto.bitops.bits) + implementation(libs.kotlincrypto.bitops.endian) implementation(libs.kotlincrypto.hash.md) implementation(libs.kotlincrypto.hash.sha1) implementation(libs.kotlincrypto.hash.sha2) implementation(libs.kotlincrypto.hash.sha3) - implementation(libs.kotlincrypto.endians.endians) implementation(libs.kotlincrypto.sponges.keccak) implementation(project(":library:hmac:hmac-md")) implementation(project(":library:hmac:hmac-sha1")) diff --git a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/BenchmarkBase.kt b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/BenchmarkBase.kt index fa01dcf..265b488 100644 --- a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/BenchmarkBase.kt +++ b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/BenchmarkBase.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("unused") + package org.kotlincrypto.macs.benchmarks import kotlinx.benchmark.Benchmark diff --git a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/HmacSHA2Opts.kt b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/HmacSHA2Opts.kt index 41c46f6..54bdd74 100644 --- a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/HmacSHA2Opts.kt +++ b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/HmacSHA2Opts.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("SpellCheckingInspection") +@file:Suppress("SpellCheckingInspection", "unused") package org.kotlincrypto.macs.benchmarks diff --git a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/HmacSHA3Opts.kt b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/HmacSHA3Opts.kt index c50f4f1..30da141 100644 --- a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/HmacSHA3Opts.kt +++ b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/HmacSHA3Opts.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "SpellCheckingInspection") +@file:Suppress("ClassName", "SpellCheckingInspection", "unused") package org.kotlincrypto.macs.benchmarks diff --git a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/KmacOpts.kt b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/KmacOpts.kt index 0346cbc..ac6daec 100644 --- a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/KmacOpts.kt +++ b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/macs/benchmarks/KmacOpts.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("SpellCheckingInspection") +@file:Suppress("SpellCheckingInspection", "unused") package org.kotlincrypto.macs.benchmarks diff --git a/gradle.properties b/gradle.properties index 2928be9..ec2eb5f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,10 +30,10 @@ POM_DEVELOPER_ID=KotlinCrypto POM_DEVELOPER_NAME=Kotlin Crypto POM_DEVELOPER_URL=https://github.com/KotlinCrypto/ -VERSION_NAME=0.5.7-SNAPSHOT +VERSION_NAME=0.6.0-SNAPSHOT # 0.1.0-alpha01 = 00 01 00 11 # 0.1.0-beta01 = 00 01 00 21 # 0.1.0-rc01 = 00 01 00 31 # 0.1.0 = 00 01 00 99 # 1.1.0 = 01 01 00 99 -VERSION_CODE=00050799 +VERSION_CODE=00060099 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c0a3e12..6c349e1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,9 +12,9 @@ gradle-kmp-configuration = "0.3.2" gradle-kotlin = "1.9.24" gradle-publish-maven = "0.29.0" -kotlincrypto-core = "0.5.5" -kotlincrypto-hash = "0.5.6" -kotlincrypto-endians = "0.3.1" +kotlincrypto-bitops = "0.1.0-SNAPSHOT" +kotlincrypto-core = "0.6.0-SNAPSHOT" +kotlincrypto-hash = "0.6.0-SNAPSHOT" kotlincrypto-sponges = "0.3.4" [libraries] @@ -36,7 +36,8 @@ benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime" 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" } -kotlincrypto-endians-endians = { module = "org.kotlincrypto.endians:endians", version.ref = "kotlincrypto-endians"} +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-sponges-keccak = { module = "org.kotlincrypto.sponges:keccak", version.ref = "kotlincrypto-sponges" } [plugins] diff --git a/library/hmac/hmac-md/api/hmac-md.api b/library/hmac/hmac-md/api/hmac-md.api index 8cb6a2e..f8941cb 100644 --- a/library/hmac/hmac-md/api/hmac-md.api +++ b/library/hmac/hmac-md/api/hmac-md.api @@ -1,4 +1,7 @@ public final class org/kotlincrypto/macs/hmac/md/HmacMD5 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/md/HmacMD5; } diff --git a/library/hmac/hmac-md/api/hmac-md.klib.api b/library/hmac/hmac-md/api/hmac-md.klib.api index ca85891..2081db1 100644 --- a/library/hmac/hmac-md/api/hmac-md.klib.api +++ b/library/hmac/hmac-md/api/hmac-md.klib.api @@ -8,4 +8,6 @@ // Library unique name: final class org.kotlincrypto.macs.hmac.md/HmacMD5 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.md/HmacMD5|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.md/HmacMD5.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.md/HmacMD5 // org.kotlincrypto.macs.hmac.md/HmacMD5.copy|copy(){}[0] } diff --git a/library/hmac/hmac-md/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/md/HmacMD5.kt b/library/hmac/hmac-md/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/md/HmacMD5.kt index 22c6b23..ba45f46 100644 --- a/library/hmac/hmac-md/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/md/HmacMD5.kt +++ b/library/hmac/hmac-md/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/md/HmacMD5.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.md -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.md.MD5 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacMD5: Hmac { /** - * Instantiates a new instance of [HmacMD5]. + * Creates a new instance of [HmacMD5]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacMD5", MD5()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacMD5", + digest = MD5(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacMD5): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacMD5(engineCopy) + public override fun copy(): HmacMD5 = HmacMD5(this) } diff --git a/library/hmac/hmac-md/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/md/HmacMD5UnitTest.kt b/library/hmac/hmac-md/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/md/HmacMD5UnitTest.kt index d753957..4b4e945 100644 --- a/library/hmac/hmac-md/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/md/HmacMD5UnitTest.kt +++ b/library/hmac/hmac-md/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/md/HmacMD5UnitTest.kt @@ -62,4 +62,9 @@ open class HmacMD5UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha1/api/hmac-sha1.api b/library/hmac/hmac-sha1/api/hmac-sha1.api index 581c22a..d4bd1fd 100644 --- a/library/hmac/hmac-sha1/api/hmac-sha1.api +++ b/library/hmac/hmac-sha1/api/hmac-sha1.api @@ -1,4 +1,7 @@ public final class org/kotlincrypto/macs/hmac/sha1/HmacSHA1 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha1/HmacSHA1; } diff --git a/library/hmac/hmac-sha1/api/hmac-sha1.klib.api b/library/hmac/hmac-sha1/api/hmac-sha1.klib.api index 54e14aa..9d5cff7 100644 --- a/library/hmac/hmac-sha1/api/hmac-sha1.klib.api +++ b/library/hmac/hmac-sha1/api/hmac-sha1.klib.api @@ -8,4 +8,6 @@ // Library unique name: final class org.kotlincrypto.macs.hmac.sha1/HmacSHA1 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha1/HmacSHA1|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha1/HmacSHA1.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha1/HmacSHA1 // org.kotlincrypto.macs.hmac.sha1/HmacSHA1.copy|copy(){}[0] } diff --git a/library/hmac/hmac-sha1/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha1/HmacSHA1.kt b/library/hmac/hmac-sha1/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha1/HmacSHA1.kt index 1b99865..45ef7e1 100644 --- a/library/hmac/hmac-sha1/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha1/HmacSHA1.kt +++ b/library/hmac/hmac-sha1/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha1/HmacSHA1.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha1 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha1.SHA1 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA1: Hmac { /** - * Instantiates a new instance of [HmacSHA1]. + * Creates a new instance of [HmacSHA1]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA1", SHA1()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA1", + digest = SHA1(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA1): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA1(engineCopy) + public override fun copy(): HmacSHA1 = HmacSHA1(this) } diff --git a/library/hmac/hmac-sha1/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha1/HmacSHA1UnitTest.kt b/library/hmac/hmac-sha1/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha1/HmacSHA1UnitTest.kt index 8eacd81..3cd7230 100644 --- a/library/hmac/hmac-sha1/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha1/HmacSHA1UnitTest.kt +++ b/library/hmac/hmac-sha1/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha1/HmacSHA1UnitTest.kt @@ -62,4 +62,9 @@ open class HmacSHA1UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha2/api/hmac-sha2.api b/library/hmac/hmac-sha2/api/hmac-sha2.api index b071ef4..242dc81 100644 --- a/library/hmac/hmac-sha2/api/hmac-sha2.api +++ b/library/hmac/hmac-sha2/api/hmac-sha2.api @@ -1,21 +1,36 @@ public final class org/kotlincrypto/macs/hmac/sha2/HmacSHA224 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha2/HmacSHA224; } public final class org/kotlincrypto/macs/hmac/sha2/HmacSHA256 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha2/HmacSHA256; } public final class org/kotlincrypto/macs/hmac/sha2/HmacSHA384 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha2/HmacSHA384; } public final class org/kotlincrypto/macs/hmac/sha2/HmacSHA512 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha2/HmacSHA512; } public final class org/kotlincrypto/macs/hmac/sha2/HmacSHA512t : org/kotlincrypto/macs/hmac/Hmac { public fun ([BI)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha2/HmacSHA512t; } public final class org/kotlincrypto/macs/hmac/sha2/HmacSHA512tKt { diff --git a/library/hmac/hmac-sha2/api/hmac-sha2.klib.api b/library/hmac/hmac-sha2/api/hmac-sha2.klib.api index 8db8531..5a6f728 100644 --- a/library/hmac/hmac-sha2/api/hmac-sha2.klib.api +++ b/library/hmac/hmac-sha2/api/hmac-sha2.klib.api @@ -8,22 +8,32 @@ // Library unique name: final class org.kotlincrypto.macs.hmac.sha2/HmacSHA224 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha2/HmacSHA224|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha2/HmacSHA224.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha2/HmacSHA224 // org.kotlincrypto.macs.hmac.sha2/HmacSHA224.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha2/HmacSHA256 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha2/HmacSHA256|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha2/HmacSHA256.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha2/HmacSHA256 // org.kotlincrypto.macs.hmac.sha2/HmacSHA256.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha2/HmacSHA384 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha2/HmacSHA384|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha2/HmacSHA384.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha2/HmacSHA384 // org.kotlincrypto.macs.hmac.sha2/HmacSHA384.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha2/HmacSHA512 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha2/HmacSHA512|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha2/HmacSHA512.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha2/HmacSHA512 // org.kotlincrypto.macs.hmac.sha2/HmacSHA512.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha2/HmacSHA512t : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha2/HmacSHA512t|null[0] constructor (kotlin/ByteArray, kotlin/Int) // org.kotlincrypto.macs.hmac.sha2/HmacSHA512t.|(kotlin.ByteArray;kotlin.Int){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha2/HmacSHA512t // org.kotlincrypto.macs.hmac.sha2/HmacSHA512t.copy|copy(){}[0] } final fun org.kotlincrypto.macs.hmac.sha2/HmacSHA512_224(kotlin/ByteArray): org.kotlincrypto.macs.hmac.sha2/HmacSHA512t // org.kotlincrypto.macs.hmac.sha2/HmacSHA512_224|HmacSHA512_224(kotlin.ByteArray){}[0] diff --git a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA224.kt b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA224.kt index 21de02c..ffc8d98 100644 --- a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA224.kt +++ b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA224.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha2 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha2.SHA224 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA224: Hmac { /** - * Instantiates a new instance of [HmacSHA224]. + * Creates a new instance of [HmacSHA224]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA224", SHA224()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA224", + digest = SHA224(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA224): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA224(engineCopy) + public override fun copy(): HmacSHA224 = HmacSHA224(this) } diff --git a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA256.kt b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA256.kt index a22e563..e1de175 100644 --- a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA256.kt +++ b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA256.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha2 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha2.SHA256 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA256: Hmac { /** - * Instantiates a new instance of [HmacSHA256]. + * Creates a new instance of [HmacSHA256]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA256", SHA256()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA256", + digest = SHA256(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA256): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA256(engineCopy) + public override fun copy(): HmacSHA256 = HmacSHA256(this) } diff --git a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA384.kt b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA384.kt index 3d39d5d..5f0eb14 100644 --- a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA384.kt +++ b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA384.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha2 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha2.SHA384 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA384: Hmac { /** - * Instantiates a new instance of [HmacSHA384]. + * Creates a new instance of [HmacSHA384]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA384", SHA384()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA384", + digest = SHA384(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA384): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA384(engineCopy) + public override fun copy(): HmacSHA384 = HmacSHA384(this) } diff --git a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512.kt b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512.kt index 61ab40d..d5ed984 100644 --- a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512.kt +++ b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha2 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha2.SHA512 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA512: Hmac { /** - * Instantiates a new instance of [HmacSHA512]. + * Creates a new instance of [HmacSHA512]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA512", SHA512()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA512", + digest = SHA512(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA512): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA512(engineCopy) + public override fun copy(): HmacSHA512 = HmacSHA512(this) } diff --git a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512t.kt b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512t.kt index acf0e14..605e52f 100644 --- a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512t.kt +++ b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512t.kt @@ -13,41 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation", "FunctionName") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha2 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha2.SHA512t import org.kotlincrypto.macs.hmac.Hmac -/** - * HmacSHA512/224 - * - * @throws [IllegalArgumentException] if [key] is empty - * */ -@Throws(IllegalArgumentException::class) -public fun HmacSHA512_224(key: ByteArray): HmacSHA512t = HmacSHA512t(key, 224) - -/** - * HmacSHA512/256 - * - * @throws [IllegalArgumentException] if [key] is empty - * */ -@Throws(IllegalArgumentException::class) -public fun HmacSHA512_256(key: ByteArray): HmacSHA512t = HmacSHA512t(key, 256) - /** * HmacSHA512/t implementation * */ public class HmacSHA512t: Hmac { /** - * Instantiates a new instance of [HmacSHA512t]. + * Creates a new instance of [HmacSHA512t]. * - * @see [HmacSHA512_224] - * @see [HmacSHA512_256] * @throws [IllegalArgumentException] when: * - [key] is empty * - [t] is less than 8 @@ -55,12 +35,13 @@ public class HmacSHA512t: Hmac { * - [t] is not a factor of 8 * - [t] is 384 * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray, t: Int): super(key, "HmacSHA512/$t", SHA512t(t)) + public constructor(key: ByteArray, t: Int): super( + key = key, + algorithm = "HmacSHA512/$t", + digest = SHA512t(t), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA512t): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA512t(engineCopy) + public override fun copy(): HmacSHA512t = HmacSHA512t(this) } diff --git a/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512tDeprecated.kt b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512tDeprecated.kt new file mode 100644 index 0000000..9342e44 --- /dev/null +++ b/library/hmac/hmac-sha2/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512tDeprecated.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Matthew Nelson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ +@file:JvmName("HmacSHA512tKt") +@file:Suppress("FunctionName", "SpellCheckingInspection") + +package org.kotlincrypto.macs.hmac.sha2 + +import kotlin.jvm.JvmName + + +/** @suppress */ +@Deprecated("Use HmacSHA512t directly", ReplaceWith("HmacSHA512t(key, 224)", "org.kotlincrypto.macs.hmac.sha2.HmacSHA512t")) +public fun HmacSHA512_224(key: ByteArray): HmacSHA512t = HmacSHA512t(key, 224) + +/** @suppress */ +@Deprecated("Use HmacSHA512t directly", ReplaceWith("HmacSHA512t(key, 256)", "org.kotlincrypto.macs.hmac.sha2.HmacSHA512t")) +public fun HmacSHA512_256(key: ByteArray): HmacSHA512t = HmacSHA512t(key, 256) diff --git a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA224UnitTest.kt b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA224UnitTest.kt index 55d0d93..38991ef 100644 --- a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA224UnitTest.kt +++ b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA224UnitTest.kt @@ -62,4 +62,9 @@ open class HmacSHA224UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA256UnitTest.kt b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA256UnitTest.kt index 589b2c8..2d115f6 100644 --- a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA256UnitTest.kt +++ b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA256UnitTest.kt @@ -62,4 +62,9 @@ open class HmacSHA256UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA384UnitTest.kt b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA384UnitTest.kt index 6a42625..589abb6 100644 --- a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA384UnitTest.kt +++ b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA384UnitTest.kt @@ -62,4 +62,9 @@ open class HmacSHA384UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512UnitTest.kt b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512UnitTest.kt index 40ab1e9..d389d22 100644 --- a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512UnitTest.kt +++ b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512UnitTest.kt @@ -62,4 +62,9 @@ open class HmacSHA512UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512_224UnitTest.kt b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512_224UnitTest.kt index 524f184..e2ab3e1 100644 --- a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512_224UnitTest.kt +++ b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512_224UnitTest.kt @@ -22,7 +22,7 @@ import org.kotlincrypto.macs.MacUnitTest import kotlin.test.Test open class HmacSHA512_224UnitTest: MacUnitTest() { - override fun mac(key: ByteArray): Mac = HmacSHA512_224(key) + override fun mac(key: ByteArray): Mac = HmacSHA512t(key, 224) final override val expectedResetSmallHash: String = "22c57dcc73cdacef1ebb24d9870dce63a8b0948400be51023743cfe0" final override val expectedResetMediumHash: String = "53e7ffd5bb5e3a93d9bac8966ed9728c3311010c6bc62be9793640a5" @@ -64,4 +64,9 @@ open class HmacSHA512_224UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512_256UnitTest.kt b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512_256UnitTest.kt index 6043829..0e56f81 100644 --- a/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512_256UnitTest.kt +++ b/library/hmac/hmac-sha2/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha2/HmacSHA512_256UnitTest.kt @@ -22,7 +22,7 @@ import org.kotlincrypto.macs.MacUnitTest import kotlin.test.Test open class HmacSHA512_256UnitTest: MacUnitTest() { - override fun mac(key: ByteArray): Mac = HmacSHA512_256(key) + override fun mac(key: ByteArray): Mac = HmacSHA512t(key, 256) final override val expectedResetSmallHash: String = "5a9c3f3b04f27901c6f61b4f6e2c594c2e92bc782143d073791994b563b4480e" final override val expectedResetMediumHash: String = "447f9db5826247b823f272922f4eaf6f2651c0a30afacfd294d94d3239d2e4ed" @@ -64,4 +64,9 @@ open class HmacSHA512_256UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha3/api/hmac-sha3.api b/library/hmac/hmac-sha3/api/hmac-sha3.api index 9810036..8d76824 100644 --- a/library/hmac/hmac-sha3/api/hmac-sha3.api +++ b/library/hmac/hmac-sha3/api/hmac-sha3.api @@ -1,32 +1,56 @@ public final class org/kotlincrypto/macs/hmac/sha3/HmacKeccak224 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha3/HmacKeccak224; } public final class org/kotlincrypto/macs/hmac/sha3/HmacKeccak256 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha3/HmacKeccak256; } public final class org/kotlincrypto/macs/hmac/sha3/HmacKeccak384 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha3/HmacKeccak384; } public final class org/kotlincrypto/macs/hmac/sha3/HmacKeccak512 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha3/HmacKeccak512; } public final class org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha3/HmacSHA3_224; } public final class org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha3/HmacSHA3_256; } public final class org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha3/HmacSHA3_384; } public final class org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512 : org/kotlincrypto/macs/hmac/Hmac { public fun ([B)V + public synthetic fun copy ()Ljava/lang/Object; + public synthetic fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; + public fun copy ()Lorg/kotlincrypto/macs/hmac/sha3/HmacSHA3_512; } diff --git a/library/hmac/hmac-sha3/api/hmac-sha3.klib.api b/library/hmac/hmac-sha3/api/hmac-sha3.klib.api index 5ff2195..ea1b922 100644 --- a/library/hmac/hmac-sha3/api/hmac-sha3.klib.api +++ b/library/hmac/hmac-sha3/api/hmac-sha3.klib.api @@ -8,32 +8,48 @@ // Library unique name: final class org.kotlincrypto.macs.hmac.sha3/HmacKeccak224 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha3/HmacKeccak224|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha3/HmacKeccak224.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha3/HmacKeccak224 // org.kotlincrypto.macs.hmac.sha3/HmacKeccak224.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha3/HmacKeccak256 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha3/HmacKeccak256|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha3/HmacKeccak256.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha3/HmacKeccak256 // org.kotlincrypto.macs.hmac.sha3/HmacKeccak256.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha3/HmacKeccak384 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha3/HmacKeccak384|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha3/HmacKeccak384.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha3/HmacKeccak384 // org.kotlincrypto.macs.hmac.sha3/HmacKeccak384.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha3/HmacKeccak512 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha3/HmacKeccak512|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha3/HmacKeccak512.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha3/HmacKeccak512 // org.kotlincrypto.macs.hmac.sha3/HmacKeccak512.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha3/HmacSHA3_224 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_224|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_224.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha3/HmacSHA3_224 // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_224.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha3/HmacSHA3_256 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_256|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_256.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha3/HmacSHA3_256 // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_256.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha3/HmacSHA3_384 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_384|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_384.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha3/HmacSHA3_384 // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_384.copy|copy(){}[0] } final class org.kotlincrypto.macs.hmac.sha3/HmacSHA3_512 : org.kotlincrypto.macs.hmac/Hmac { // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_512|null[0] constructor (kotlin/ByteArray) // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_512.|(kotlin.ByteArray){}[0] + + final fun copy(): org.kotlincrypto.macs.hmac.sha3/HmacSHA3_512 // org.kotlincrypto.macs.hmac.sha3/HmacSHA3_512.copy|copy(){}[0] } diff --git a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak224.kt b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak224.kt index 6b41b6b..0cb2c79 100644 --- a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak224.kt +++ b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak224.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha3 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha3.Keccak224 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacKeccak224: Hmac { /** - * Instantiates a new instance of [HmacKeccak224]. + * Creates a new instance of [HmacKeccak224]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacKeccak224", Keccak224()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacKeccak224", + digest = Keccak224(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacKeccak224): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacKeccak224(engineCopy) + public override fun copy(): HmacKeccak224 = HmacKeccak224(this) } diff --git a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak256.kt b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak256.kt index e372e27..5e925a8 100644 --- a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak256.kt +++ b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak256.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha3 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha3.Keccak256 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacKeccak256: Hmac { /** - * Instantiates a new instance of [HmacKeccak256]. + * Creates a new instance of [HmacKeccak256]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacKeccak256", Keccak256()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacKeccak256", + digest = Keccak256(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacKeccak256): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacKeccak256(engineCopy) + public override fun copy(): HmacKeccak256 = HmacKeccak256(this) } diff --git a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak384.kt b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak384.kt index 6e78045..30138dd 100644 --- a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak384.kt +++ b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak384.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha3 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha3.Keccak384 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacKeccak384: Hmac { /** - * Instantiates a new instance of [HmacKeccak384]. + * Creates a new instance of [HmacKeccak384]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacKeccak384", Keccak384()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacKeccak384", + digest = Keccak384(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacKeccak384): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacKeccak384(engineCopy) + public override fun copy(): HmacKeccak384 = HmacKeccak384(this) } diff --git a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak512.kt b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak512.kt index ce314a5..5860c9a 100644 --- a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak512.kt +++ b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak512.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "UnnecessaryOptInAnnotation") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha3 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha3.Keccak512 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacKeccak512: Hmac { /** - * Instantiates a new instance of [HmacKeccak512]. + * Creates a new instance of [HmacKeccak512]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacKeccak512", Keccak512()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacKeccak512", + digest = Keccak512(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacKeccak512): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacKeccak512(engineCopy) + public override fun copy(): HmacKeccak512 = HmacKeccak512(this) } diff --git a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224.kt b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224.kt index 0a18755..b95423a 100644 --- a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224.kt +++ b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "UnnecessaryOptInAnnotation") +@file:Suppress("ClassName", "SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha3 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha3.SHA3_224 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA3_224: Hmac { /** - * Instantiates a new instance of [HmacSHA3_224]. + * Creates a new instance of [HmacSHA3_224]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA3-224", SHA3_224()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA3-224", + digest = SHA3_224(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA3_224): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA3_224(engineCopy) + public override fun copy(): HmacSHA3_224 = HmacSHA3_224(this) } diff --git a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256.kt b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256.kt index 091cb48..7f011f9 100644 --- a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256.kt +++ b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "UnnecessaryOptInAnnotation") +@file:Suppress("ClassName", "SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha3 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha3.SHA3_256 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA3_256: Hmac { /** - * Instantiates a new instance of [HmacSHA3_256]. + * Creates a new instance of [HmacSHA3_256]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA3-256", SHA3_256()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA3-256", + digest = SHA3_256(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA3_256): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA3_256(engineCopy) + public override fun copy(): HmacSHA3_256 = HmacSHA3_256(this) } diff --git a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384.kt b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384.kt index 9e13209..d350cc1 100644 --- a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384.kt +++ b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "UnnecessaryOptInAnnotation") +@file:Suppress("ClassName", "SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha3 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha3.SHA3_384 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA3_384: Hmac { /** - * Instantiates a new instance of [HmacSHA3_384]. + * Creates a new instance of [HmacSHA3_384]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA3-384", SHA3_384()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA3-384", + digest = SHA3_384(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA3_384): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA3_384(engineCopy) + public override fun copy(): HmacSHA3_384 = HmacSHA3_384(this) } diff --git a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512.kt b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512.kt index 9c26b41..61ff9f7 100644 --- a/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512.kt +++ b/library/hmac/hmac-sha3/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512.kt @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("ClassName", "UnnecessaryOptInAnnotation") +@file:Suppress("ClassName", "SpellCheckingInspection") package org.kotlincrypto.macs.hmac.sha3 -import org.kotlincrypto.core.InternalKotlinCryptoApi -import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.hash.sha3.SHA3_512 import org.kotlincrypto.macs.hmac.Hmac @@ -28,16 +26,17 @@ import org.kotlincrypto.macs.hmac.Hmac public class HmacSHA3_512: Hmac { /** - * Instantiates a new instance of [HmacSHA3_512]. + * Creates a new instance of [HmacSHA3_512]. * * @throws [IllegalArgumentException] if [key] is empty. * */ - @OptIn(InternalKotlinCryptoApi::class) - @Throws(IllegalArgumentException::class) - public constructor(key: ByteArray): super(key, "HmacSHA3-512", SHA3_512()) + public constructor(key: ByteArray): super( + key = key, + algorithm = "HmacSHA3-512", + digest = SHA3_512(), + ) - @OptIn(InternalKotlinCryptoApi::class) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: HmacSHA3_512): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = HmacSHA3_512(engineCopy) + public override fun copy(): HmacSHA3_512 = HmacSHA3_512(this) } diff --git a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak224UnitTest.kt b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak224UnitTest.kt index 1ba1096..a849dee 100644 --- a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak224UnitTest.kt +++ b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak224UnitTest.kt @@ -62,4 +62,9 @@ open class HmacKeccak224UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak256UnitTest.kt b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak256UnitTest.kt index 227a767..97f0c9b 100644 --- a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak256UnitTest.kt +++ b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak256UnitTest.kt @@ -62,4 +62,9 @@ open class HmacKeccak256UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak384UnitTest.kt b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak384UnitTest.kt index 479ba9b..d61c451 100644 --- a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak384UnitTest.kt +++ b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak384UnitTest.kt @@ -62,4 +62,9 @@ open class HmacKeccak384UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak512UnitTest.kt b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak512UnitTest.kt index ba2fb20..6b44603 100644 --- a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak512UnitTest.kt +++ b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacKeccak512UnitTest.kt @@ -62,4 +62,9 @@ open class HmacKeccak512UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224UnitTest.kt b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224UnitTest.kt index 0b416c4..750ff35 100644 --- a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224UnitTest.kt +++ b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_224UnitTest.kt @@ -63,4 +63,9 @@ open class HmacSHA3_224UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256UnitTest.kt b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256UnitTest.kt index f2bda87..f636f1c 100644 --- a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256UnitTest.kt +++ b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_256UnitTest.kt @@ -63,4 +63,9 @@ open class HmacSHA3_256UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384UnitTest.kt b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384UnitTest.kt index 4054060..b96f18b 100644 --- a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384UnitTest.kt +++ b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_384UnitTest.kt @@ -63,4 +63,9 @@ open class HmacSHA3_384UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512UnitTest.kt b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512UnitTest.kt index 0a5dcec..d85df80 100644 --- a/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512UnitTest.kt +++ b/library/hmac/hmac-sha3/src/commonTest/kotlin/org/kotlincrypto/macs/hmac/sha3/HmacSHA3_512UnitTest.kt @@ -63,4 +63,9 @@ open class HmacSHA3_512UnitTest: MacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/hmac/hmac/api/hmac.api b/library/hmac/hmac/api/hmac.api index 04295cb..cc9e7a6 100644 --- a/library/hmac/hmac/api/hmac.api +++ b/library/hmac/hmac/api/hmac.api @@ -1,3 +1,6 @@ public abstract class org/kotlincrypto/macs/hmac/Hmac : org/kotlincrypto/core/mac/Mac { + protected fun (Lorg/kotlincrypto/macs/hmac/Hmac;)V + protected fun ([BLjava/lang/String;Lorg/kotlincrypto/core/digest/Digest;)V + public abstract fun copy ()Lorg/kotlincrypto/macs/hmac/Hmac; } diff --git a/library/hmac/hmac/api/hmac.klib.api b/library/hmac/hmac/api/hmac.klib.api index f7215ad..1f5c2c1 100644 --- a/library/hmac/hmac/api/hmac.klib.api +++ b/library/hmac/hmac/api/hmac.klib.api @@ -6,4 +6,9 @@ // - Show declarations: true // Library unique name: -abstract class org.kotlincrypto.macs.hmac/Hmac : org.kotlincrypto.core.mac/Mac // org.kotlincrypto.macs.hmac/Hmac|null[0] +abstract class org.kotlincrypto.macs.hmac/Hmac : org.kotlincrypto.core.mac/Mac { // org.kotlincrypto.macs.hmac/Hmac|null[0] + constructor (kotlin/ByteArray, kotlin/String, org.kotlincrypto.core.digest/Digest) // org.kotlincrypto.macs.hmac/Hmac.|(kotlin.ByteArray;kotlin.String;org.kotlincrypto.core.digest.Digest){}[0] + constructor (org.kotlincrypto.macs.hmac/Hmac) // org.kotlincrypto.macs.hmac/Hmac.|(org.kotlincrypto.macs.hmac.Hmac){}[0] + + abstract fun copy(): org.kotlincrypto.macs.hmac/Hmac // org.kotlincrypto.macs.hmac/Hmac.copy|copy(){}[0] +} diff --git a/library/hmac/hmac/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/Hmac.kt b/library/hmac/hmac/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/Hmac.kt index 0e64d41..abd48c9 100644 --- a/library/hmac/hmac/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/Hmac.kt +++ b/library/hmac/hmac/src/commonMain/kotlin/org/kotlincrypto/macs/hmac/Hmac.kt @@ -13,21 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation", "RemoveRedundantQualifierName") +@file:Suppress("SpellCheckingInspection") package org.kotlincrypto.macs.hmac -import org.kotlincrypto.core.InternalKotlinCryptoApi import org.kotlincrypto.core.digest.Digest import org.kotlincrypto.core.mac.Mac import kotlin.experimental.xor /** - * Core abstraction for Hash-based Message Authentication - * Code implementations. - * - * @see [Mac] - * @see [Digest] + * Core abstraction for Hash-based Message Authentication Code implementations. * */ public abstract class Hmac: Mac { @@ -36,13 +31,12 @@ public abstract class Hmac: Mac { * * @throws [IllegalArgumentException] if [key] is empty or [algorithm] is blank. * */ - @InternalKotlinCryptoApi @Throws(IllegalArgumentException::class) protected constructor( key: ByteArray, algorithm: String, digest: Digest, - ): this(Engine(key, algorithm, digest)) + ): super(algorithm, Engine(key, digest)) /** * Secondary constructor for implementing [copy]. @@ -50,53 +44,48 @@ public abstract class Hmac: Mac { * Implementors of [Hmac] should have a private secondary constructor * that is utilized by its [copy] implementation. * - * @throws [ClassCastException] if [engine] is not [Hmac.Engine] + * e.g. + * + * public class HmacSHA256: Hmac { + * + * // ... + * + * private constructor(other: HmacSHA256): super(other) { + * // Copy implementation details... + * } + * + * // Notice the updated return type + * public override fun copy(): HmacSHA256 = HmacSHA256(this) + * + * // ... + * } * */ - @InternalKotlinCryptoApi - @Throws(ClassCastException::class) - protected constructor(engine: Mac.Engine): super((engine as Engine).algorithm, engine) + protected constructor(other: Hmac): super(other) + + public abstract override fun copy(): Hmac private class Engine: Mac.Engine { - val algorithm: String private val iKey: ByteArray private val oKey: ByteArray private val digest: Digest - @OptIn(InternalKotlinCryptoApi::class) - constructor(key: ByteArray, algorithm: String, digest: Digest): super(key) { - this.algorithm = algorithm - - val sizedKey = if (key.size > digest.blockSize()) { - val keyHash = digest.digest(key) - keyHash.copyOf(digest.blockSize()).also { keyHash.fill(0) } - } else { - // Even if provided key is the correct size, still - // create a copy so sizedKey can always be blanked - // after deriving iKey and oKey. - // - // If the provided key is undersized, it will be - // padded with 0's. - key.copyOf(digest.blockSize()) - } - - this.iKey = ByteArray(digest.blockSize()) { i -> sizedKey[i] xor I_PAD } - this.oKey = ByteArray(digest.blockSize()) { i -> sizedKey[i] xor O_PAD } - - sizedKey.fill(0) - - digest.update(iKey) - this.digest = digest + constructor(key: ByteArray, digest: Digest): super(key) { + // Do not know where Digest is coming from. Always create a new instance. + this.digest = digest.copy() + this.iKey = ByteArray(digest.blockSize()) + this.oKey = ByteArray(digest.blockSize()) + this.digest.resetAndInitialize(key = key, iKey = iKey, oKey = oKey) } - @OptIn(InternalKotlinCryptoApi::class) - private constructor(state: State, engine: Engine): super(state) { - this.algorithm = engine.algorithm - this.iKey = engine.iKey - this.oKey = engine.oKey - this.digest = engine.digest.copy() + private constructor(other: Engine): super(other) { + this.iKey = other.iKey.copyOf() + this.oKey = other.oKey.copyOf() + this.digest = other.digest.copy() } + override fun copy(): Engine = Engine(this) + override fun update(input: Byte) { digest.update(input) } override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } @@ -111,9 +100,38 @@ public abstract class Hmac: Mac { digest.update(iKey) } + override fun reset(newKey: ByteArray) { + digest.resetAndInitialize(key = newKey, iKey = iKey, oKey = oKey) + } + override fun macLength(): Int = digest.digestLength() - override fun copy(): Engine = Engine(object : State() {}, this) + @Suppress("NOTHING_TO_INLINE", "KotlinRedundantDiagnosticSuppress") + private inline fun Digest.resetAndInitialize(key: ByteArray, iKey: ByteArray, oKey: ByteArray) { + val blockSize = blockSize() + reset() + + val sizedKey = if (key.size > blockSize) { + val keyHash = digest(key) + keyHash.copyOf(blockSize).also { keyHash.fill(0) } + } else { + // Even if provided key is the correct size, still + // create a copy so sizedKey can always be blanked + // after deriving iKey and oKey. + // + // If the provided key is undersized, it will be + // padded with 0's. + key.copyOf(blockSize) + } + + for (i in 0.. ([B[B)V public fun ([B[BI)V public synthetic fun ([B[BIZLkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun copy ()Ljava/lang/Object; + public fun copy ()Lorg/kotlincrypto/macs/kmac/KMAC128; + public synthetic fun copy ()Lorg/kotlincrypto/macs/kmac/Kmac; public static final fun xOf ([B)Lorg/kotlincrypto/core/xof/Xof; public static final fun xOf ([B[B)Lorg/kotlincrypto/core/xof/Xof; } @@ -22,6 +25,9 @@ public final class org/kotlincrypto/macs/kmac/KMAC256 : org/kotlincrypto/macs/km public fun ([B[B)V public fun ([B[BI)V public synthetic fun ([B[BIZLkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun copy ()Ljava/lang/Object; + public fun copy ()Lorg/kotlincrypto/macs/kmac/KMAC256; + public synthetic fun copy ()Lorg/kotlincrypto/macs/kmac/Kmac; public static final fun xOf ([B)Lorg/kotlincrypto/core/xof/Xof; public static final fun xOf ([B[B)Lorg/kotlincrypto/core/xof/Xof; } @@ -32,10 +38,12 @@ public final class org/kotlincrypto/macs/kmac/KMAC256$Companion : org/kotlincryp public static synthetic fun xOf$default (Lorg/kotlincrypto/macs/kmac/KMAC256$Companion;[B[BILjava/lang/Object;)Lorg/kotlincrypto/core/xof/Xof; } -public abstract class org/kotlincrypto/macs/kmac/Kmac : org/kotlincrypto/core/mac/Mac, org/kotlincrypto/core/xof/XofAlgorithm { +public abstract class org/kotlincrypto/macs/kmac/Kmac : org/kotlincrypto/core/mac/Mac, org/kotlincrypto/core/xof/ReKeyableXofAlgorithm { protected static final field Companion Lorg/kotlincrypto/macs/kmac/Kmac$Companion; - public synthetic fun (Lorg/kotlincrypto/core/mac/Mac$Engine;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Lorg/kotlincrypto/macs/kmac/Kmac$Engine;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Lorg/kotlincrypto/macs/kmac/Kmac;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun ([B[BIIZLkotlin/jvm/internal/DefaultConstructorMarker;)V + public abstract fun copy ()Lorg/kotlincrypto/macs/kmac/Kmac; } protected final class org/kotlincrypto/macs/kmac/Kmac$Companion { diff --git a/library/kmac/api/kmac.klib.api b/library/kmac/api/kmac.klib.api index 6ce74b6..34f913c 100644 --- a/library/kmac/api/kmac.klib.api +++ b/library/kmac/api/kmac.klib.api @@ -11,6 +11,8 @@ final class org.kotlincrypto.macs.kmac/KMAC128 : org.kotlincrypto.macs.kmac/Kmac constructor (kotlin/ByteArray, kotlin/ByteArray?) // org.kotlincrypto.macs.kmac/KMAC128.|(kotlin.ByteArray;kotlin.ByteArray?){}[0] constructor (kotlin/ByteArray, kotlin/ByteArray?, kotlin/Int) // org.kotlincrypto.macs.kmac/KMAC128.|(kotlin.ByteArray;kotlin.ByteArray?;kotlin.Int){}[0] + final fun copy(): org.kotlincrypto.macs.kmac/KMAC128 // org.kotlincrypto.macs.kmac/KMAC128.copy|copy(){}[0] + final object Companion : org.kotlincrypto.macs.kmac/Kmac.KMACXofFactory { // org.kotlincrypto.macs.kmac/KMAC128.Companion|null[0] final const val MAC_LENGTH // org.kotlincrypto.macs.kmac/KMAC128.Companion.MAC_LENGTH|(){}[0] final fun (): kotlin/Int // org.kotlincrypto.macs.kmac/KMAC128.Companion.MAC_LENGTH.|(){}[0] @@ -24,6 +26,8 @@ final class org.kotlincrypto.macs.kmac/KMAC256 : org.kotlincrypto.macs.kmac/Kmac constructor (kotlin/ByteArray, kotlin/ByteArray?) // org.kotlincrypto.macs.kmac/KMAC256.|(kotlin.ByteArray;kotlin.ByteArray?){}[0] constructor (kotlin/ByteArray, kotlin/ByteArray?, kotlin/Int) // org.kotlincrypto.macs.kmac/KMAC256.|(kotlin.ByteArray;kotlin.ByteArray?;kotlin.Int){}[0] + final fun copy(): org.kotlincrypto.macs.kmac/KMAC256 // org.kotlincrypto.macs.kmac/KMAC256.copy|copy(){}[0] + final object Companion : org.kotlincrypto.macs.kmac/Kmac.KMACXofFactory { // org.kotlincrypto.macs.kmac/KMAC256.Companion|null[0] final const val MAC_LENGTH // org.kotlincrypto.macs.kmac/KMAC256.Companion.MAC_LENGTH|(){}[0] final fun (): kotlin/Int // org.kotlincrypto.macs.kmac/KMAC256.Companion.MAC_LENGTH.|(){}[0] @@ -32,9 +36,11 @@ final class org.kotlincrypto.macs.kmac/KMAC256 : org.kotlincrypto.macs.kmac/Kmac } } -sealed class org.kotlincrypto.macs.kmac/Kmac : org.kotlincrypto.core.mac/Mac, org.kotlincrypto.core.xof/XofAlgorithm { // org.kotlincrypto.macs.kmac/Kmac|null[0] +sealed class org.kotlincrypto.macs.kmac/Kmac : org.kotlincrypto.core.mac/Mac, org.kotlincrypto.core.xof/ReKeyableXofAlgorithm { // org.kotlincrypto.macs.kmac/Kmac|null[0] constructor (kotlin/ByteArray, kotlin/ByteArray?, kotlin/Int, kotlin/Int, kotlin/Boolean) // org.kotlincrypto.macs.kmac/Kmac.|(kotlin.ByteArray;kotlin.ByteArray?;kotlin.Int;kotlin.Int;kotlin.Boolean){}[0] - constructor (org.kotlincrypto.core.mac/Mac.Engine) // org.kotlincrypto.macs.kmac/Kmac.|(org.kotlincrypto.core.mac.Mac.Engine){}[0] + constructor (org.kotlincrypto.macs.kmac/Kmac) // org.kotlincrypto.macs.kmac/Kmac.|(org.kotlincrypto.macs.kmac.Kmac){}[0] + + abstract fun copy(): org.kotlincrypto.macs.kmac/Kmac // org.kotlincrypto.macs.kmac/Kmac.copy|copy(){}[0] sealed class <#A1: org.kotlincrypto.macs.kmac/Kmac> KMACXofFactory : org.kotlincrypto.core.xof/XofFactory<#A1> { // org.kotlincrypto.macs.kmac/Kmac.KMACXofFactory|null[0] constructor () // org.kotlincrypto.macs.kmac/Kmac.KMACXofFactory.|(){}[0] diff --git a/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/KMAC128.kt b/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/KMAC128.kt index b998fae..09741ab 100644 --- a/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/KMAC128.kt +++ b/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/KMAC128.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("SpellCheckingInspection", "LocalVariableName") + package org.kotlincrypto.macs.kmac import org.kotlincrypto.core.mac.Mac @@ -34,7 +36,6 @@ public class KMAC128: Kmac { * * @throws [IllegalArgumentException] if [key] is empty. * */ - @Throws(IllegalArgumentException::class) public constructor( key: ByteArray, ): this(key, null) @@ -48,7 +49,6 @@ public class KMAC128: Kmac { * empty or null value. (e.g. "My Customization".encodeToByteArray()). * @throws [IllegalArgumentException] if [key] is empty. * */ - @Throws(IllegalArgumentException::class) public constructor( key: ByteArray, S: ByteArray?, @@ -64,7 +64,6 @@ public class KMAC128: Kmac { * @throws [IllegalArgumentException] if [key] is empty, or [outputLength] * is negative. * */ - @Throws(IllegalArgumentException::class) public constructor( key: ByteArray, S: ByteArray?, @@ -76,11 +75,17 @@ public class KMAC128: Kmac { S: ByteArray?, outputLength: Int, xofMode: Boolean, - ): super(key, S, BIT_STRENGTH_128, outputLength, xofMode) + ): super( + key = key, + S = S, + bitStrength = BIT_STRENGTH_128, + outputLength = outputLength, + xofMode = xofMode, + ) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: KMAC128): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = KMAC128(engineCopy) + public override fun copy(): KMAC128 = KMAC128(this) public companion object: KMACXofFactory() { @@ -92,6 +97,7 @@ public class KMAC128: Kmac { /** * Produces a new [Xof] (Extendable-Output Function) for [KMAC128] * + * @see [Xof.Companion.reset] * @param [S] A user selected customization bit string to define a variant * of the function. When no customization is desired, [S] is set to an * empty or null value. (e.g. "My Customization".encodeToByteArray()). diff --git a/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/KMAC256.kt b/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/KMAC256.kt index 2df9157..008825a 100644 --- a/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/KMAC256.kt +++ b/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/KMAC256.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("SpellCheckingInspection", "LocalVariableName") + package org.kotlincrypto.macs.kmac import org.kotlincrypto.core.mac.Mac @@ -76,11 +78,17 @@ public class KMAC256: Kmac { S: ByteArray?, outputLength: Int, xofMode: Boolean, - ): super(key, S, BIT_STRENGTH_256, outputLength, xofMode) + ): super( + key = key, + S = S, + bitStrength = BIT_STRENGTH_256, + outputLength = outputLength, + xofMode = xofMode, + ) - private constructor(engine: Mac.Engine): super(engine) + private constructor(other: KMAC256): super(other) - protected override fun copy(engineCopy: Mac.Engine): Mac = KMAC256(engineCopy) + public override fun copy(): KMAC256 = KMAC256(this) public companion object: KMACXofFactory() { @@ -92,6 +100,7 @@ public class KMAC256: Kmac { /** * Produces a new [Xof] (Extendable-Output Function) for [KMAC256] * + * @see [Xof.Companion.reset] * @param [S] A user selected customization bit string to define a variant * of the function. When no customization is desired, [S] is set to an * empty or null value. (e.g. "My Customization".encodeToByteArray()). diff --git a/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/Kmac.kt b/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/Kmac.kt index 2ee2aae..3479b20 100644 --- a/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/Kmac.kt +++ b/library/kmac/src/commonMain/kotlin/org/kotlincrypto/macs/kmac/Kmac.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation", "RemoveRedundantQualifierName") +@file:Suppress("RemoveRedundantQualifierName", "SpellCheckingInspection", "LocalVariableName") package org.kotlincrypto.macs.kmac @@ -27,16 +27,13 @@ import org.kotlincrypto.hash.sha3.CSHAKE256 /** * Core abstraction for Keccak-based Message Authentication * Code implementations: - * - KMAC128 - * - KMAC256 - * - * @see [Mac] + * - [KMAC128] + * - [KMAC256] * */ -public sealed class Kmac: Mac, XofAlgorithm { +public sealed class Kmac: Mac, ReKeyableXofAlgorithm { private val engine: Engine - @OptIn(InternalKotlinCryptoApi::class) protected constructor( key: ByteArray, S: ByteArray?, @@ -44,18 +41,27 @@ public sealed class Kmac: Mac, XofAlgorithm { outputLength: Int, xofMode: Boolean, ): this(if (xofMode) { - XofEngine(key, S, bitStrength) + XofEngine(key, S, bitStrength, outputLength) } else { DigestEngine(key, S, bitStrength, outputLength) }) - @OptIn(InternalKotlinCryptoApi::class) - protected constructor(engine: Mac.Engine): super((engine as Engine).algorithm(), engine) { + protected constructor(other: Kmac): this(other.engine.copy()) + + private constructor(engine: Kmac.Engine): super(engine.algorithm(), engine) { this.engine = engine } - @OptIn(InternalKotlinCryptoApi::class) + public abstract override fun copy(): Kmac + + /** + * Provides [Xof] functionality for [KMAC128] & [KMAC256] + * + * @see [KMAC128.Companion] + * @see [KMAC256.Companion] + * */ public sealed class KMACXofFactory: XofFactory() { + protected inner class KMACXof(delegate: A): XofDelegate(delegate) { init { @@ -66,8 +72,8 @@ public sealed class Kmac: Mac, XofAlgorithm { val reader = (delegateCopy.engine as XofEngine).reader() return object : Xof.Reader() { - override fun readProtected(out: ByteArray, offset: Int, len: Int, bytesRead: Long) { - reader.read(out, offset, len) + override fun readProtected(out: ByteArray, offset: Int, len: Int): Int { + return reader.read(out, offset, len) } override fun closeProtected() { @@ -83,7 +89,7 @@ public sealed class Kmac: Mac, XofAlgorithm { private class DigestEngine: Engine { - protected override val source: Digest + override val source: Digest constructor( key: ByteArray, @@ -102,11 +108,11 @@ public sealed class Kmac: Mac, XofAlgorithm { bytepad() } - private constructor(state: State, engine: DigestEngine): super(state, engine) { - this.source = engine.source.copy() + private constructor(other: DigestEngine): super(other) { + this.source = other.source.copy() } - override fun copy(): Mac.Engine = DigestEngine(object : State() {}, this) + override fun copy(): DigestEngine = DigestEngine(this) override fun doFinal(): ByteArray { padFinal() @@ -116,13 +122,14 @@ public sealed class Kmac: Mac, XofAlgorithm { private class XofEngine: Engine { - protected override val source: Xof<*> + override val source: Xof<*> constructor( key: ByteArray, S: ByteArray?, bitStrength: Int, - ): super(key, bitStrength, outputLength = 0) { + outputLength: Int, + ): super(key, bitStrength, outputLength) { val N = KMAC.encodeToByteArray() this.source = if (bitStrength == BIT_STRENGTH_128) { @@ -134,33 +141,39 @@ public sealed class Kmac: Mac, XofAlgorithm { bytepad() } - private constructor(state: State, engine: XofEngine): super(state, engine) { - this.source = engine.source.copy() + private constructor(other: XofEngine): super(other) { + this.source = other.source.copy() } - override fun copy(): Mac.Engine = XofEngine(object: State() {}, this) + override fun copy(): XofEngine = XofEngine(this) - // Only ever called from a copy of the XofEngine. Calling source.reader - // will also create a copy of the underlying CSHAKE XOF, so we want to reset - // the underlying copy before it is black holed. + // Only ever called from a copy of the XofEngine. fun reader(): Xof<*>.Reader { padFinal() + + // Ensure key material gets wiped for this new copy. Will not + // be reset or updated again (in reader mode). + zeroOutInitBlock() + + // Calling source.reader + // will also create a copy of the underlying CSHAKE XOF, so we want to reset + // the underlying copy before it is black holed. return source.reader(resetXof = true) } // Never called - override fun doFinal(): ByteArray = ByteArray(0) + override fun doFinal(): ByteArray = error("Xof Mode") } + @OptIn(InternalKotlinCryptoApi::class) private sealed class Engine: Mac.Engine, Algorithm { protected abstract val source: Updatable private val bitStrength: Int private val blockSize: Int - private val initBlock: ByteArray + private var initBlock: ByteArray private val outputLength: Int - @OptIn(InternalKotlinCryptoApi::class) constructor(key: ByteArray, bitStrength: Int, outputLength: Int): super(key) { this.bitStrength = bitStrength this.outputLength = outputLength @@ -171,30 +184,18 @@ public sealed class Kmac: Mac, XofAlgorithm { else -> throw IllegalArgumentException("bitStrength must be $BIT_STRENGTH_128 or $BIT_STRENGTH_256") } - // This combines inputs for bytepad(encode_string(K), w Int) - // into a single ByteArray, the initBlock. - val encW = Xof.Utils.leftEncode(blockSize.toLong()) - - // encode_string(K) = (encoded key bit size) + (key) - // this is the encoded key size needed for correctly sizing b - val encKS = Xof.Utils.leftEncode(key.size * 8L) - - val b = ByteArray(encW.size + encKS.size + key.size) - encW.copyInto(b) - encKS.copyInto(b, encW.size) - key.copyInto(b, encW.size + encKS.size) - - this.initBlock = b + this.initBlock = newInitBlock(key, this.blockSize) } - @OptIn(InternalKotlinCryptoApi::class) - constructor(state: State, engine: Engine): super(state) { - this.bitStrength = engine.bitStrength - this.blockSize = engine.blockSize - this.outputLength = engine.outputLength - this.initBlock = engine.initBlock + constructor(other: Engine): super(other) { + this.bitStrength = other.bitStrength + this.blockSize = other.blockSize + this.outputLength = other.outputLength + this.initBlock = other.initBlock.copyOf() } + abstract override fun copy(): Kmac.Engine + protected fun bytepad() { source.update(initBlock) @@ -203,24 +204,50 @@ public sealed class Kmac: Mac, XofAlgorithm { // No padding is needed if (remainder == 0) return - repeat(blockSize - remainder) { - source.update(0) - } + val pad = blockSize - remainder + source.update(ByteArray(pad), 0, pad) } protected fun padFinal() { - @OptIn(InternalKotlinCryptoApi::class) + // TODO: Use hi/lo bits val encL = Xof.Utils.rightEncode(outputLength * 8L) source.update(encL) } + protected fun zeroOutInitBlock() { initBlock.fill(0) } + final override fun update(input: Byte) { source.update(input) } final override fun update(input: ByteArray, offset: Int, len: Int) { source.update(input, offset, len) } final override fun reset() { (source as Resettable).reset(); bytepad() } + final override fun reset(newKey: ByteArray) { + val oldInitBlock = this.initBlock + initBlock = newInitBlock(newKey, blockSize) + reset() + oldInitBlock.fill(0) + } final override fun algorithm(): String = KMAC + bitStrength final override fun macLength(): Int = outputLength + // This combines inputs for bytepad(encode_string(K), w Int) + // into a single ByteArray, the initBlock. + @Suppress("NOTHING_TO_INLINE", "KotlinRedundantDiagnosticSuppress") + private inline fun newInitBlock(key: ByteArray, blockSize: Int): ByteArray { + // TODO: Use hi/lo bits + // encode_string(K) = (encoded key bit size) + (key) + // this is the encoded key size needed for correctly sizing b + val encKS = Xof.Utils.leftEncode(key.size * 8L) + + val encW = Xof.Utils.leftEncode(blockSize) + + val initBlock = ByteArray(encW.size + encKS.size + key.size) + encW.copyInto(initBlock) + encKS.copyInto(initBlock, encW.size) + key.copyInto(initBlock, encW.size + encKS.size) + + return initBlock + } + protected companion object { internal const val KMAC = "KMAC" } diff --git a/library/kmac/src/commonTest/kotlin/org/kotlincrypto/macs/kmac/KMAC128UnitTest.kt b/library/kmac/src/commonTest/kotlin/org/kotlincrypto/macs/kmac/KMAC128UnitTest.kt index ebe339a..61cf150 100644 --- a/library/kmac/src/commonTest/kotlin/org/kotlincrypto/macs/kmac/KMAC128UnitTest.kt +++ b/library/kmac/src/commonTest/kotlin/org/kotlincrypto/macs/kmac/KMAC128UnitTest.kt @@ -110,4 +110,9 @@ open class KMAC128UnitTest: KmacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/library/kmac/src/commonTest/kotlin/org/kotlincrypto/macs/kmac/KMAC256UnitTest.kt b/library/kmac/src/commonTest/kotlin/org/kotlincrypto/macs/kmac/KMAC256UnitTest.kt index 56fbfbd..2482f8b 100644 --- a/library/kmac/src/commonTest/kotlin/org/kotlincrypto/macs/kmac/KMAC256UnitTest.kt +++ b/library/kmac/src/commonTest/kotlin/org/kotlincrypto/macs/kmac/KMAC256UnitTest.kt @@ -110,4 +110,9 @@ open class KMAC256UnitTest: KmacUnitTest() { final override fun givenMac_whenDoFinal_thenLengthMatchesOutput() { super.givenMac_whenDoFinal_thenLengthMatchesOutput() } + + @Test + final override fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + super.givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() + } } diff --git a/settings.gradle.kts b/settings.gradle.kts index a625baf..5f8d015 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,7 +23,6 @@ if (CHECK_PUBLICATION != null) { "hmac:hmac-sha1", "hmac:hmac-sha2", "hmac:hmac-sha3", - "kmac", ).forEach { name -> include(":library:$name") diff --git a/tools/testing/src/commonMain/kotlin/org/kotlincrypto/macs/MacUnitTest.kt b/tools/testing/src/commonMain/kotlin/org/kotlincrypto/macs/MacUnitTest.kt index 43c3f73..9fa9879 100644 --- a/tools/testing/src/commonMain/kotlin/org/kotlincrypto/macs/MacUnitTest.kt +++ b/tools/testing/src/commonMain/kotlin/org/kotlincrypto/macs/MacUnitTest.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("FunctionName") + package org.kotlincrypto.macs import io.matthewnelson.encoding.base64.Base64 @@ -21,7 +23,25 @@ import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString import org.kotlincrypto.core.mac.Mac import org.kotlincrypto.core.Updatable import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +/** + * Test abstraction to verify that the Mac implementation is in proper working order. + * All input utilized is deterministic in order to ensure expected hash values never + * change. + * + * Expected hash values are obtained by an already working implementation of the + * algorithm under test (e.g. Bouncy Castle provider). Those values must then match + * when the KotlinCrypto implementation is put under test. + * + * To implement this abstraction for a new algorithm: + * + * See [org.kotlincrypto.macs.hmac.md.HmacMD5UnitTest] located in `commonTest`. Note that + * the test class is `open`. This allows it to be inherited from in the `jvmTest` source + * set, for example the [org.kotlincrypto.macs.hmac.md.HmacMD5JvmUnitTest] test. This + * ensures that both implementations run under the same test parameters output the same + * values. + * */ abstract class MacUnitTest { abstract fun mac(key: ByteArray): Mac @@ -32,7 +52,18 @@ abstract class MacUnitTest { abstract val expectedUpdateSmallHash: String abstract val expectedUpdateMediumHash: String + private val assertExpectedHashes by lazy { + setOf( + expectedResetSmallHash, + expectedResetMediumHash, + expectedResetLargeHash, + expectedUpdateSmallHash, + expectedUpdateMediumHash, + ).let { assertEquals(5, it.size, "Expected hash values must all be different") } + } + open fun givenMac_whenResetSmallKey_thenDoFinalReturnsExpected() { + assertExpectedHashes val mac = mac(KEY_SMALL) val empty = mac.doFinal().encodeToString(TestData.base16) updateSmall(mac) @@ -43,6 +74,7 @@ abstract class MacUnitTest { } open fun givenMac_whenResetMediumKey_thenDoFinalReturnsExpected() { + assertExpectedHashes val mac = mac(KEY_MEDIUM) val empty = mac.doFinal().encodeToString(TestData.base16) updateSmall(mac) @@ -51,7 +83,9 @@ abstract class MacUnitTest { assertEquals(empty, actual) assertEquals(expectedResetMediumHash, actual) } + open fun givenMac_whenResetLargeKey_thenDoFinalReturnsExpected() { + assertExpectedHashes val mac = mac(KEY_LARGE) val empty = mac.doFinal().encodeToString(TestData.base16) updateSmall(mac) @@ -62,6 +96,7 @@ abstract class MacUnitTest { } open fun givenMac_whenUpdatedSmall_thenDoFinalReturnsExpected() { + assertExpectedHashes val mac = mac(KEY_SMALL) mac.doFinal() updateSmall(mac) @@ -70,6 +105,7 @@ abstract class MacUnitTest { } open fun givenMac_whenUpdatedMedium_thenDoFinalReturnsExpected() { + assertExpectedHashes val mac = mac(KEY_MEDIUM) mac.doFinal() updateMedium(mac) @@ -79,19 +115,38 @@ abstract class MacUnitTest { } open fun givenMac_whenCopied_thenIsDifferentInstance() { + assertExpectedHashes val mac = mac(KEY_SMALL) updateSmall(mac) - val copy = mac.copy() - copy.reset() + val copy = mac.copy() + assertNotEquals(copy, mac) + assertEquals(expectedUpdateSmallHash, copy.doFinal().encodeToString(TestData.base16)) assertEquals(expectedResetSmallHash, copy.doFinal().encodeToString(TestData.base16)) + + updateSmall(copy) + assertEquals(expectedUpdateSmallHash, copy.doFinal().encodeToString(TestData.base16)) assertEquals(expectedUpdateSmallHash, mac.doFinal().encodeToString(TestData.base16)) } open fun givenMac_whenDoFinal_thenLengthMatchesOutput() { + assertExpectedHashes assertEquals(mac(KEY_SMALL).doFinal().encodeToString(TestData.base16).length, expectedResetSmallHash.length) } + open fun givenMac_whenInstanceResetWithNewKey_thenDoFinalReturnsExpected() { + assertExpectedHashes + val mac = mac(KEY_SMALL) + updateSmall(mac) + assertEquals(mac.doFinal().encodeToString(TestData.base16), expectedUpdateSmallHash) + assertEquals(mac.doFinal().encodeToString(TestData.base16), expectedResetSmallHash) + + mac.reset(KEY_MEDIUM) + updateMedium(mac) + assertEquals(mac.doFinal().encodeToString(TestData.base16), expectedUpdateMediumHash) + assertEquals(mac.doFinal().encodeToString(TestData.base16), expectedResetMediumHash) + } + protected companion object { fun updateSmall(mac: Updatable) { diff --git a/tools/testing/src/jvmMain/kotlin/org/kotlincrypto/macs/TestJvmMac.kt b/tools/testing/src/jvmMain/kotlin/org/kotlincrypto/macs/TestJvmMac.kt index 8437032..2776349 100644 --- a/tools/testing/src/jvmMain/kotlin/org/kotlincrypto/macs/TestJvmMac.kt +++ b/tools/testing/src/jvmMain/kotlin/org/kotlincrypto/macs/TestJvmMac.kt @@ -13,12 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("UnnecessaryOptInAnnotation") - package org.kotlincrypto.macs import org.bouncycastle.jce.provider.BouncyCastleProvider -import org.kotlincrypto.core.InternalKotlinCryptoApi import org.kotlincrypto.core.mac.Mac import java.security.NoSuchAlgorithmException import java.security.Security @@ -28,13 +25,12 @@ import javax.crypto.spec.SecretKeySpec * Simple test class that wraps a [javax.crypto.Mac] * with [org.kotlincrypto.core.mac.Mac] * */ -@OptIn(InternalKotlinCryptoApi::class) class TestJvmMac: Mac { constructor(algorithm: String, key: ByteArray): super(algorithm, Engine(algorithm, key)) - private constructor(algorithm: String, engine: Engine): super(algorithm, engine) - override fun copy(engineCopy: Mac.Engine): Mac = TestJvmMac(algorithm, engineCopy as Engine) + private constructor(other: TestJvmMac): super(other) + override fun copy(): TestJvmMac = TestJvmMac(this) private class Engine: Mac.Engine { @@ -46,11 +42,11 @@ class TestJvmMac: Mac { } } - private constructor(state: State, engine: Engine): super(state) { - delegate = engine.delegate.clone() as javax.crypto.Mac + private constructor(other: Engine): super(other) { + delegate = other.delegate.clone() as javax.crypto.Mac } - override fun copy(): Mac.Engine = Engine(object : State() {}, this) + override fun copy(): Engine = Engine(this) override fun macLength(): Int = delegate.macLength @@ -61,6 +57,7 @@ class TestJvmMac: Mac { override fun doFinal(): ByteArray = delegate.doFinal() override fun reset() { delegate.reset() } + override fun reset(newKey: ByteArray) { delegate.init(SecretKeySpec(newKey, delegate.algorithm)) } } private companion object {