├── .github └── workflows │ └── CI.yml ├── .gitignore ├── .kotlin-js-store └── yarn.lock ├── CHANGELOG.md ├── LICENSE ├── README.md ├── RELEASING.md ├── benchmarks ├── .gitignore ├── README.md ├── build.gradle.kts └── src │ ├── commonMain │ └── kotlin │ │ └── org │ │ └── kotlincrypto │ │ └── hash │ │ └── benchmarks │ │ ├── BLAKE2Ops.kt │ │ ├── BenchmarkBase.kt │ │ ├── MDOps.kt │ │ ├── SHA1Ops.kt │ │ ├── SHA2Ops.kt │ │ └── SHA3Ops.kt │ └── jvmMain │ └── kotlin │ └── org │ └── kotlincrypto │ └── hash │ └── benchmarks │ ├── BouncyCastleBenchmarkBase.kt │ └── BouncyCastleOps.kt ├── bom ├── .gitignore ├── build.gradle.kts └── gradle.properties ├── build-logic ├── .gitignore ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── -KmpConfigurationExtension.kt │ ├── bom-include.gradle.kts │ ├── configuration.gradle.kts │ ├── dokka.gradle.kts │ └── publication.gradle.kts ├── build.gradle.kts ├── gh-pages └── publish.sh ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── blake2 │ ├── .gitignore │ ├── README.md │ ├── api │ │ ├── blake2.api │ │ └── blake2.klib.api │ ├── build.gradle.kts │ ├── gradle.properties │ └── src │ │ ├── commonMain │ │ └── kotlin │ │ │ └── org │ │ │ └── kotlincrypto │ │ │ └── hash │ │ │ └── blake2 │ │ │ ├── BLAKE2Digest.kt │ │ │ ├── BLAKE2b.kt │ │ │ ├── BLAKE2s.kt │ │ │ └── internal │ │ │ └── -Message.kt │ │ ├── commonTest │ │ └── kotlin │ │ │ └── org │ │ │ └── kotlincrypto │ │ │ └── hash │ │ │ └── blake2 │ │ │ ├── BLAKE2bUnitTest.kt │ │ │ ├── BLAKE2b_160UnitTest.kt │ │ │ ├── BLAKE2b_184UnitTest.kt │ │ │ ├── BLAKE2b_256UnitTest.kt │ │ │ ├── BLAKE2b_384UnitTest.kt │ │ │ ├── BLAKE2b_512UnitTest.kt │ │ │ ├── BLAKE2b_512_Salt_Personalization_UnitTest.kt │ │ │ ├── BLAKE2sUnitTest.kt │ │ │ ├── BLAKE2s_128UnitTest.kt │ │ │ ├── BLAKE2s_160UnitTest.kt │ │ │ ├── BLAKE2s_184UnitTest.kt │ │ │ ├── BLAKE2s_224UnitTest.kt │ │ │ ├── BLAKE2s_256UnitTest.kt │ │ │ └── BLAKE2s_256_Salt_Personalization_UnitTest.kt │ │ ├── jvmMain │ │ └── java9 │ │ │ └── module-info.java │ │ └── jvmTest │ │ └── kotlin │ │ └── org │ │ └── kotlincrypto │ │ └── hash │ │ └── blake2 │ │ ├── BLAKE2b_160JvmUnitTest.kt │ │ ├── BLAKE2b_184JvmUnitTest.kt │ │ ├── BLAKE2b_256JvmUnitTest.kt │ │ ├── BLAKE2b_384JvmUnitTest.kt │ │ ├── BLAKE2b_512JvmUnitTest.kt │ │ ├── BLAKE2b_512_Salt_Personalization_JvmUnitTest.kt │ │ ├── BLAKE2s_128JvmUnitTest.kt │ │ ├── BLAKE2s_160JvmUnitTest.kt │ │ ├── BLAKE2s_184JvmUnitTest.kt │ │ ├── BLAKE2s_224JvmUnitTest.kt │ │ ├── BLAKE2s_256JvmUnitTest.kt │ │ └── BLAKE2s_256_Salt_Personalization_JvmUnitTest.kt ├── md │ ├── .gitignore │ ├── README.md │ ├── api │ │ ├── md.api │ │ └── md.klib.api │ ├── build.gradle.kts │ ├── gradle.properties │ └── src │ │ ├── commonMain │ │ └── kotlin │ │ │ └── org │ │ │ └── kotlincrypto │ │ │ └── hash │ │ │ └── md │ │ │ └── MD5.kt │ │ ├── commonTest │ │ └── kotlin │ │ │ └── org │ │ │ └── kotlincrypto │ │ │ └── hash │ │ │ └── md │ │ │ └── MD5UnitTest.kt │ │ ├── jvmMain │ │ └── java9 │ │ │ └── module-info.java │ │ └── jvmTest │ │ └── kotlin │ │ └── org │ │ └── kotlincrypto │ │ └── hash │ │ └── md │ │ └── MD5JvmUnitTest.kt ├── sha1 │ ├── .gitignore │ ├── README.md │ ├── api │ │ ├── sha1.api │ │ └── sha1.klib.api │ ├── build.gradle.kts │ ├── gradle.properties │ └── src │ │ ├── commonMain │ │ └── kotlin │ │ │ └── org │ │ │ └── kotlincrypto │ │ │ └── hash │ │ │ └── sha1 │ │ │ └── SHA1.kt │ │ ├── commonTest │ │ └── kotlin │ │ │ └── org │ │ │ └── kotlincrypto │ │ │ └── hash │ │ │ └── sha1 │ │ │ └── SHA1UnitTest.kt │ │ ├── jvmMain │ │ └── java9 │ │ │ └── module-info.java │ │ └── jvmTest │ │ └── kotlin │ │ └── org │ │ └── kotlincrypto │ │ └── hash │ │ └── sha1 │ │ └── SHA1JvmUnitTest.kt ├── sha2 │ ├── .gitignore │ ├── README.md │ ├── api │ │ ├── sha2.api │ │ └── sha2.klib.api │ ├── build.gradle.kts │ ├── gradle.properties │ └── src │ │ ├── commonMain │ │ └── kotlin │ │ │ └── org │ │ │ └── kotlincrypto │ │ │ └── hash │ │ │ └── sha2 │ │ │ ├── Bit32Digest.kt │ │ │ ├── Bit64Digest.kt │ │ │ ├── SHA224.kt │ │ │ ├── SHA256.kt │ │ │ ├── SHA384.kt │ │ │ ├── SHA512.kt │ │ │ ├── SHA512t.kt │ │ │ └── SHA512tDeprecated.kt │ │ ├── commonTest │ │ └── kotlin │ │ │ └── org │ │ │ └── kotlincrypto │ │ │ └── hash │ │ │ └── sha2 │ │ │ ├── SHA224UnitTest.kt │ │ │ ├── SHA256UnitTest.kt │ │ │ ├── SHA384UnitTest.kt │ │ │ ├── SHA512UnitTest.kt │ │ │ ├── SHA512_224UnitTest.kt │ │ │ ├── SHA512_232UnitTest.kt │ │ │ ├── SHA512_256UnitTest.kt │ │ │ └── SHA512tUnitTest.kt │ │ ├── jvmMain │ │ └── java9 │ │ │ └── module-info.java │ │ └── jvmTest │ │ └── kotlin │ │ └── org │ │ └── kotlincrypto │ │ └── hash │ │ └── sha2 │ │ ├── SHA224JvmUnitTest.kt │ │ ├── SHA256JvmUnitTest.kt │ │ ├── SHA384JvmUnitTest.kt │ │ ├── SHA512JvmUnitTest.kt │ │ ├── SHA512_224JvmUnitTest.kt │ │ ├── SHA512_232JvmUnitTest.kt │ │ └── SHA512_256Jvm256UnitTest.kt └── sha3 │ ├── .gitignore │ ├── README.md │ ├── api │ ├── sha3.api │ └── sha3.klib.api │ ├── build.gradle.kts │ ├── gradle.properties │ └── src │ ├── commonMain │ └── kotlin │ │ └── org │ │ └── kotlincrypto │ │ └── hash │ │ └── sha3 │ │ ├── CSHAKE128.kt │ │ ├── CSHAKE256.kt │ │ ├── Keccak224.kt │ │ ├── Keccak256.kt │ │ ├── Keccak384.kt │ │ ├── Keccak512.kt │ │ ├── KeccakDigest.kt │ │ ├── ParallelDigest.kt │ │ ├── ParallelHash128.kt │ │ ├── ParallelHash256.kt │ │ ├── SHA3_224.kt │ │ ├── SHA3_256.kt │ │ ├── SHA3_384.kt │ │ ├── SHA3_512.kt │ │ ├── SHAKE128.kt │ │ ├── SHAKE256.kt │ │ ├── SHAKEDigest.kt │ │ ├── TupleDigest.kt │ │ ├── TupleHash128.kt │ │ └── TupleHash256.kt │ ├── commonTest │ └── kotlin │ │ └── org │ │ └── kotlincrypto │ │ └── hash │ │ └── sha3 │ │ ├── CSHAKE128UnitTest.kt │ │ ├── CSHAKE128XofUnitTest.kt │ │ ├── CSHAKE128_NS_UnitTest.kt │ │ ├── CSHAKE128_N_UnitTest.kt │ │ ├── CSHAKE128_S_UnitTest.kt │ │ ├── CSHAKE256UnitTest.kt │ │ ├── CSHAKE256XofUnitTest.kt │ │ ├── CSHAKE256_NS_UnitTest.kt │ │ ├── CSHAKE256_N_UnitTest.kt │ │ ├── CSHAKE256_S_UnitTest.kt │ │ ├── Keccak224UnitTest.kt │ │ ├── Keccak256UnitTest.kt │ │ ├── Keccak384UnitTest.kt │ │ ├── Keccak512UnitTest.kt │ │ ├── ParallelHash128UnitTest.kt │ │ ├── ParallelHash128XofUnitTest.kt │ │ ├── ParallelHash256UnitTest.kt │ │ ├── ParallelHash256XofUnitTest.kt │ │ ├── SHA3_224UnitTest.kt │ │ ├── SHA3_256UnitTest.kt │ │ ├── SHA3_384UnitTest.kt │ │ ├── SHA3_512UnitTest.kt │ │ ├── SHAKE128UnitTest.kt │ │ ├── SHAKE128XofUnitTest.kt │ │ ├── SHAKE256UnitTest.kt │ │ ├── SHAKE256XofUnitTest.kt │ │ ├── SHAKEDigestUnitTest.kt │ │ ├── TupleHash128UnitTest.kt │ │ ├── TupleHash128XofUnitTest.kt │ │ ├── TupleHash256UnitTest.kt │ │ └── TupleHash256XofUnitTest.kt │ ├── jvmMain │ └── java9 │ │ └── module-info.java │ └── jvmTest │ └── kotlin │ └── org │ └── kotlincrypto │ └── hash │ └── sha3 │ ├── CSHAKE128JvmUnitTest.kt │ ├── CSHAKE128XofJvmUnitTest.kt │ ├── CSHAKE128_NS_JvmUnitTest.kt │ ├── CSHAKE128_N_JvmUnitTest.kt │ ├── CSHAKE128_S_JvmUnitTest.kt │ ├── CSHAKE256JvmUnitTest.kt │ ├── CSHAKE256XofJvmUnitTest.kt │ ├── CSHAKE256_NS_JvmUnitTest.kt │ ├── CSHAKE256_N_JvmUnitTest.kt │ ├── CSHAKE256_S_JvmUnitTest.kt │ ├── Keccak224JvmUnitTest.kt │ ├── Keccak256JvmUnitTest.kt │ ├── Keccak384JvmUnitTest.kt │ ├── Keccak512JvmUnitTest.kt │ ├── ParallelHash128JvmUnitTest.kt │ ├── ParallelHash128XofJvmUnitTest.kt │ ├── ParallelHash256JvmUnitTest.kt │ ├── ParallelHash256XofJvmUnitTest.kt │ ├── SHA3_224JvmUnitTest.kt │ ├── SHA3_256JvmUnitTest.kt │ ├── SHA3_384JvmUnitTest.kt │ ├── SHA3_512JvmUnitTest.kt │ ├── SHAKE128JvmUnitTest.kt │ ├── SHAKE128XofJvmUnitTest.kt │ ├── SHAKE256JvmUnitTest.kt │ ├── SHAKE256XofJvmUnitTest.kt │ ├── TupleHash128JvmUnitTest.kt │ ├── TupleHash128XofJvmUnitTest.kt │ ├── TupleHash256JvmUnitTest.kt │ └── TupleHash256XofJvmUnitTest.kt ├── settings.gradle.kts ├── test-android ├── .gitignore ├── api │ ├── test-android.api │ └── test-android.klib.api ├── build.gradle.kts └── src │ ├── androidInstrumentedTest │ ├── blake2 │ ├── md │ ├── sha1 │ ├── sha2 │ └── sha3 │ └── androidMain │ └── kotlin │ └── org │ └── kotlincrypto │ └── hash │ └── Stub.kt └── tools ├── check-publication ├── .gitignore ├── build.gradle.kts └── src │ └── commonMain │ └── kotlin │ └── tools │ └── check │ └── publication │ └── Stub.kt └── testing ├── .gitignore ├── build.gradle.kts └── src ├── commonMain └── kotlin │ └── org │ └── kotlincrypto │ └── hash │ ├── DigestUnitTest.kt │ ├── HashUnitTest.kt │ ├── TestData.kt │ └── XofUnitTest.kt └── jvmMain └── kotlin └── org └── kotlincrypto └── hash ├── TestBCDigest.kt └── TestJvmDigest.kt /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | /build 3 | .idea/ 4 | *.iml 5 | local.properties 6 | .kotlin/ 7 | 8 | gh-pages/* 9 | !gh-pages/publish.sh 10 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | # Releasing 2 | 3 | The release process is documented [HERE](https://github.com/KotlinCrypto/documentation/blob/master/RELEASING.md) 4 | -------------------------------------------------------------------------------- /benchmarks/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /benchmarks/README.md: -------------------------------------------------------------------------------- 1 | # benchmarks 2 | 3 | Benchmarks for tracking performance of `hash` implementations. 4 | 5 | **NOTE:** Benchmarking is run on every Pull Request. Results can be viewed for each 6 | workflow run on the [GitHub Actions][url-actions] tab of the repository. 7 | 8 | - Run All platforms: 9 | ```shell 10 | ./gradlew benchmark 11 | ``` 12 | 13 | - Run Jvm: 14 | ```shell 15 | ./gradlew jvmBenchmark 16 | ``` 17 | 18 | - Run Js: 19 | ```shell 20 | ./gradlew jsBenchmark 21 | ``` 22 | 23 | - Run WasmJs: 24 | ```shell 25 | ./gradlew wasmJsBenchmark 26 | ``` 27 | 28 | - Run Native: 29 | ```shell 30 | ./gradlew nativeHostBenchmark 31 | ``` 32 | 33 | [url-actions]: https://github.com/KotlinCrypto/hash/actions/ 34 | -------------------------------------------------------------------------------- /benchmarks/src/commonMain/kotlin/org/kotlincrypto/hash/benchmarks/BLAKE2Ops.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName", "unused") 17 | 18 | package org.kotlincrypto.hash.benchmarks 19 | 20 | import kotlinx.benchmark.* 21 | import org.kotlincrypto.hash.blake2.BLAKE2b 22 | import org.kotlincrypto.hash.blake2.BLAKE2s 23 | 24 | @State(Scope.Benchmark) 25 | @BenchmarkMode(Mode.AverageTime) 26 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 27 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 28 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 29 | open class BLAKE2b_512Benchmark: DigestBenchmarkBase(BLAKE2b(512)) 30 | 31 | @State(Scope.Benchmark) 32 | @BenchmarkMode(Mode.AverageTime) 33 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 34 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 35 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 36 | open class BLAKE2s_256Benchmark: DigestBenchmarkBase(BLAKE2s(256)) 37 | -------------------------------------------------------------------------------- /benchmarks/src/commonMain/kotlin/org/kotlincrypto/hash/benchmarks/BenchmarkBase.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.benchmarks 17 | 18 | import kotlinx.benchmark.Benchmark 19 | import kotlinx.benchmark.Setup 20 | import org.kotlincrypto.core.digest.Digest 21 | import kotlin.random.Random 22 | 23 | const val ITERATIONS = 5 24 | const val TIME_WARMUP = 2 25 | const val TIME_MEASURE = 4 26 | 27 | abstract class HashBenchmarkBase(private val blockSize: Int) { 28 | 29 | abstract fun update(input: ByteArray, offset: Int, len: Int) 30 | abstract fun digest(input: ByteArray): ByteArray 31 | 32 | // Number of bytes is based off of the algorithm's block size in 33 | // order to fairly benchmark the Digest implementation such that 2 34 | // full compressions + overflow input are processed. 35 | private val bytes = Random.Default.nextBytes((blockSize * 2) + (blockSize / 4)) 36 | 37 | @Setup 38 | fun setup() { update(bytes, 0, blockSize) } 39 | 40 | @Benchmark 41 | fun digest() { digest(bytes) } 42 | } 43 | 44 | abstract class DigestBenchmarkBase(private val d: Digest): HashBenchmarkBase(d.blockSize()) { 45 | 46 | final override fun digest(input: ByteArray): ByteArray { 47 | return d.digest(input) 48 | } 49 | final override fun update(input: ByteArray, offset: Int, len: Int) { 50 | d.update(input, offset, len) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /benchmarks/src/commonMain/kotlin/org/kotlincrypto/hash/benchmarks/MDOps.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("unused") 17 | 18 | package org.kotlincrypto.hash.benchmarks 19 | 20 | import kotlinx.benchmark.* 21 | import org.kotlincrypto.hash.md.MD5 22 | 23 | @State(Scope.Benchmark) 24 | @BenchmarkMode(Mode.AverageTime) 25 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 26 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 27 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 28 | open class MD5Benchmark: DigestBenchmarkBase(MD5()) 29 | -------------------------------------------------------------------------------- /benchmarks/src/commonMain/kotlin/org/kotlincrypto/hash/benchmarks/SHA1Ops.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("unused") 17 | 18 | package org.kotlincrypto.hash.benchmarks 19 | 20 | import kotlinx.benchmark.* 21 | import org.kotlincrypto.hash.sha1.SHA1 22 | 23 | @State(Scope.Benchmark) 24 | @BenchmarkMode(Mode.AverageTime) 25 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 26 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 27 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 28 | open class SHA1Benchmark: DigestBenchmarkBase(SHA1()) 29 | -------------------------------------------------------------------------------- /benchmarks/src/commonMain/kotlin/org/kotlincrypto/hash/benchmarks/SHA2Ops.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName", "unused") 17 | 18 | package org.kotlincrypto.hash.benchmarks 19 | 20 | import kotlinx.benchmark.* 21 | import org.kotlincrypto.hash.sha2.SHA256 22 | import org.kotlincrypto.hash.sha2.SHA512 23 | 24 | @State(Scope.Benchmark) 25 | @BenchmarkMode(Mode.AverageTime) 26 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 27 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 28 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 29 | open class SHA256Benchmark: DigestBenchmarkBase(SHA256()) 30 | 31 | @State(Scope.Benchmark) 32 | @BenchmarkMode(Mode.AverageTime) 33 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 34 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 35 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 36 | open class SHA512Benchmark: DigestBenchmarkBase(SHA512()) 37 | -------------------------------------------------------------------------------- /benchmarks/src/commonMain/kotlin/org/kotlincrypto/hash/benchmarks/SHA3Ops.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName", "unused") 17 | 18 | package org.kotlincrypto.hash.benchmarks 19 | 20 | import kotlinx.benchmark.* 21 | import org.kotlincrypto.hash.sha3.ParallelHash128 22 | import org.kotlincrypto.hash.sha3.SHA3_256 23 | import org.kotlincrypto.hash.sha3.SHAKE128 24 | import org.kotlincrypto.hash.sha3.TupleHash128 25 | 26 | @State(Scope.Benchmark) 27 | @BenchmarkMode(Mode.AverageTime) 28 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 29 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 30 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 31 | open class SHA3_256Benchmark: DigestBenchmarkBase(SHA3_256()) 32 | 33 | @State(Scope.Benchmark) 34 | @BenchmarkMode(Mode.AverageTime) 35 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 36 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 37 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 38 | open class SHAKE128Benchmark: DigestBenchmarkBase(SHAKE128()) 39 | 40 | @State(Scope.Benchmark) 41 | @BenchmarkMode(Mode.AverageTime) 42 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 43 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 44 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 45 | open class ParallelHash128Benchmark: DigestBenchmarkBase(ParallelHash128(null, 64)) 46 | 47 | @State(Scope.Benchmark) 48 | @BenchmarkMode(Mode.AverageTime) 49 | @OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) 50 | @Warmup(iterations = ITERATIONS, time = TIME_WARMUP) 51 | @Measurement(iterations = ITERATIONS, time = TIME_MEASURE) 52 | open class TupleHash128Benchmark: DigestBenchmarkBase(TupleHash128(null)) 53 | -------------------------------------------------------------------------------- /benchmarks/src/jvmMain/kotlin/org/kotlincrypto/hash/benchmarks/BouncyCastleBenchmarkBase.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.benchmarks 17 | 18 | import org.bouncycastle.jce.provider.BouncyCastleProvider 19 | import org.kotlincrypto.core.digest.Digest 20 | import java.security.MessageDigest 21 | import java.security.NoSuchAlgorithmException 22 | import java.security.Security 23 | 24 | abstract class BouncyCastleBenchmarkBase private constructor( 25 | private val d: MessageDigest, 26 | blockSize: Int, 27 | ): HashBenchmarkBase(blockSize) { 28 | 29 | constructor(kcDigest: Digest): this(kcDigest.toBCDigest(), kcDigest.blockSize()) 30 | 31 | final override fun digest(input: ByteArray): ByteArray { 32 | return d.digest(input) 33 | } 34 | final override fun update(input: ByteArray, offset: Int, len: Int) { 35 | d.update(input, offset, len) 36 | } 37 | 38 | private companion object { 39 | 40 | private val INIT_BC by lazy { 41 | Security.addProvider(BouncyCastleProvider()) 42 | } 43 | 44 | @Throws(NoSuchAlgorithmException::class) 45 | private fun Digest.toBCDigest(): MessageDigest { 46 | INIT_BC 47 | return MessageDigest.getInstance(algorithm(), BouncyCastleProvider.PROVIDER_NAME) 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /bom/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /bom/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("publication") 18 | id("java-platform") 19 | } 20 | 21 | dependencies { 22 | constraints { 23 | rootProject.subprojects.forEach { 24 | if ( 25 | it.path.startsWith(":library:") 26 | && evaluationDependsOn(it.path).plugins.hasPlugin("bom-include") 27 | ) { 28 | api(project(it.path)) 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bom/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 KotlinCrypto 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | POM_ARTIFACT_ID=bom 15 | POM_NAME=KotlinCrypto Hash BOM 16 | POM_DESCRIPTION=Bill of materials for KotlinCrypto hash library 17 | -------------------------------------------------------------------------------- /build-logic/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /build-logic/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | `kotlin-dsl` 18 | } 19 | 20 | dependencies { 21 | implementation(libs.gradle.dokka) 22 | implementation(libs.gradle.kmp.configuration) 23 | implementation(libs.gradle.kotlin) 24 | implementation(libs.gradle.publish.maven) 25 | } 26 | -------------------------------------------------------------------------------- /build-logic/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("UnstableApiUsage") 17 | 18 | rootProject.name = "build-logic" 19 | 20 | dependencyResolutionManagement { 21 | repositories { 22 | mavenCentral() 23 | gradlePluginPortal() 24 | } 25 | 26 | versionCatalogs { 27 | create("libs") { 28 | from(files("../gradle/libs.versions.toml")) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/bom-include.gradle.kts: -------------------------------------------------------------------------------- 1 | // include project in BOM 2 | -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/configuration.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | import org.gradle.api.tasks.testing.logging.TestExceptionFormat 17 | import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED 18 | import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED 19 | import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED 20 | import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR 21 | import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT 22 | import org.gradle.api.tasks.testing.logging.TestLogEvent.STARTED 23 | 24 | plugins { 25 | id("io.matthewnelson.kmp.configuration") 26 | } 27 | 28 | tasks.withType { 29 | testLogging { 30 | exceptionFormat = TestExceptionFormat.FULL 31 | events(STARTED, PASSED, SKIPPED, FAILED, STANDARD_ERROR, STANDARD_OUT) 32 | showStandardStreams = true 33 | showStackTraces = true 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/dokka.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | import org.jetbrains.dokka.gradle.DokkaExtension 17 | import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier 18 | import java.net.URI 19 | import java.time.LocalDate 20 | 21 | plugins { 22 | id("org.jetbrains.dokka") 23 | } 24 | 25 | rootProject.dependencies { dokka(project(project.path)) } 26 | 27 | extensions.configure { 28 | dokkaPublications.configureEach { 29 | suppressObviousFunctions.set(true) 30 | } 31 | 32 | dokkaSourceSets.configureEach { 33 | includes.from("README.md") 34 | enableKotlinStdLibDocumentationLink.set(false) 35 | 36 | externalDocumentationLinks { 37 | register(project.path + ":core") { 38 | url.set(URI("https://core.kotlincrypto.org/")) 39 | } 40 | register(project.path + ":error") { 41 | url.set(URI("https://error.kotlincrypto.org/")) 42 | } 43 | } 44 | 45 | sourceLink { 46 | localDirectory.set(rootDir) 47 | remoteUrl.set(URI("https://github.com/KotlinCrypto/hash/tree/master")) 48 | remoteLineSuffix.set("#L") 49 | } 50 | 51 | documentedVisibilities( 52 | VisibilityModifier.Public, 53 | ) 54 | } 55 | 56 | pluginsConfiguration.html { 57 | footerMessage.set("© 2023-${LocalDate.now().year} Copyright KotlinCrypto") 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/publication.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | import org.gradle.plugins.signing.SigningExtension 17 | 18 | plugins { 19 | id("com.vanniktech.maven.publish") 20 | } 21 | 22 | if (!version.toString().endsWith("-SNAPSHOT")) { 23 | extensions.configure("signing") { 24 | useGpgCmd() 25 | } 26 | } 27 | 28 | tasks.withType().configureEach { 29 | isPreserveFileTimestamps = false 30 | isReproducibleFileOrder = true 31 | } 32 | -------------------------------------------------------------------------------- /gh-pages/publish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) 2025 KotlinCrypto 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | set -e 16 | 17 | readonly DIR_SCRIPT="$( cd "$( dirname "$0" )" >/dev/null && pwd )" 18 | readonly REPO_NAME="hash" 19 | 20 | trap 'rm -rf "$DIR_SCRIPT/$REPO_NAME"' EXIT 21 | 22 | cd "$DIR_SCRIPT" 23 | git clone -b gh-pages --single-branch https://github.com/KotlinCrypto/$REPO_NAME.git 24 | rm -rf "$DIR_SCRIPT/$REPO_NAME/"* 25 | echo "$REPO_NAME.kotlincrypto.org" > "$DIR_SCRIPT/$REPO_NAME/CNAME" 26 | 27 | cd .. 28 | ./gradlew clean -DKMP_TARGETS_ALL 29 | ./gradlew dokkaGenerate --no-build-cache -DKMP_TARGETS_ALL 30 | cp -aR build/dokka/html/* gh-pages/$REPO_NAME 31 | 32 | cd "$DIR_SCRIPT/$REPO_NAME" 33 | sed -i "s|module:|module:library/|g" "package-list" 34 | 35 | git add --all 36 | git commit -S --message "Update dokka docs" 37 | git push 38 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 2 | org.gradle.parallel=true 3 | org.gradle.caching=true 4 | 5 | android.useAndroidX=true 6 | android.enableJetifier=true 7 | 8 | kotlin.code.style=official 9 | kotlin.mpp.applyDefaultHierarchyTemplate=false 10 | kotlin.mpp.stability.nowarn=true 11 | kotlin.native.ignoreDisabledTargets=true 12 | 13 | org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled 14 | org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true 15 | 16 | SONATYPE_HOST=S01 17 | RELEASE_SIGNING_ENABLED=true 18 | 19 | GROUP=org.kotlincrypto.hash 20 | 21 | POM_INCEPTION_YEAR=2023 22 | 23 | POM_URL=https://github.com/KotlinCrypto/hash/ 24 | POM_SCM_URL=https://github.com/KotlinCrypto/hash/ 25 | POM_SCM_CONNECTION=scm:git:git://github.com/KotlinCrypto/hash.git 26 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/KotlinCrypto/hash.git 27 | 28 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 29 | POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt 30 | POM_LICENCE_DIST=repo 31 | 32 | POM_DEVELOPER_ID=KotlinCrypto 33 | POM_DEVELOPER_NAME=Kotlin Crypto 34 | POM_DEVELOPER_URL=https://github.com/KotlinCrypto/ 35 | 36 | VERSION_NAME=0.7.1-SNAPSHOT 37 | # 0.1.0-alpha01 = 00 01 00 11 38 | # 0.1.0-beta01 = 00 01 00 21 39 | # 0.1.0-rc01 = 00 01 00 31 40 | # 0.1.0 = 00 01 00 99 41 | # 1.1.0 = 01 01 00 99 42 | VERSION_CODE=00070111 43 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KotlinCrypto/hash/50bed91ab958249be81c4c60124d7aea4e02d16f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStorePath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | 6 | # https://gradle.org/release-checksums/ 7 | distributionSha256Sum=296742a352f0b20ec14b143fb684965ad66086c7810b7b255dee216670716175 8 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-all.zip 9 | -------------------------------------------------------------------------------- /library/blake2/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /library/blake2/README.md: -------------------------------------------------------------------------------- 1 | # Module blake2 2 | 3 | `Digest` implementations for BLAKE2 Hashing 4 | 5 | Implementations for: 6 | - BLAKE2b 7 | - BLAKE2s 8 | 9 | Implementations also available as `Mac` via [KotlinCrypto/MACs][url-macs] for keyed hashing. 10 | 11 | See [HERE][url-digest-usage] for basic usage example of `Digest`. 12 | 13 | ```kotlin 14 | fun main() { 15 | BLAKE2b(512) 16 | BLAKE2s(256) 17 | } 18 | ``` 19 | 20 | [url-digest-usage]: https://core.kotlincrypto.org/library/digest/index.html 21 | [url-macs]: https://github.com/KotlinCrypto/MACs 22 | -------------------------------------------------------------------------------- /library/blake2/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("configuration") 18 | id("bom-include") 19 | } 20 | 21 | kmpConfiguration { 22 | configureShared(java9ModuleName = "org.kotlincrypto.hash.blake2", publish = true) { 23 | common { 24 | sourceSetMain { 25 | dependencies { 26 | api(libs.kotlincrypto.core.digest) 27 | implementation(libs.kotlincrypto.bitops.bits) 28 | implementation(libs.kotlincrypto.bitops.endian) 29 | } 30 | } 31 | sourceSetTest { 32 | dependencies { 33 | implementation(project(":tools:testing")) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /library/blake2/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2025 KotlinCrypto 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | POM_ARTIFACT_ID=blake2 15 | POM_NAME=KotlinCrypto BLAKE2 Hashing 16 | POM_DESCRIPTION=Digests for BLAKE2b, BLAKE2s 17 | -------------------------------------------------------------------------------- /library/blake2/src/commonMain/kotlin/org/kotlincrypto/hash/blake2/internal/-Message.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("KotlinRedundantDiagnosticSuppress", "NOTHING_TO_INLINE") 17 | 18 | package org.kotlincrypto.hash.blake2.internal 19 | 20 | import org.kotlincrypto.bitops.endian.Endian.Little.lePackIntoUnsafe 21 | import kotlin.jvm.JvmInline 22 | 23 | private const val LEN_MESSAGE = 16 24 | private const val SIZE_MESSAGE_32B = LEN_MESSAGE * Int.SIZE_BYTES 25 | private const val SIZE_MESSAGE_64B = LEN_MESSAGE * Long.SIZE_BYTES 26 | 27 | @JvmInline 28 | internal value class Bit32Message internal constructor(internal val m: IntArray) { 29 | internal constructor(b: ByteArray, offset: Int): this(IntArray(LEN_MESSAGE)) { populate(b, offset) } 30 | } 31 | 32 | @JvmInline 33 | internal value class Bit64Message internal constructor(internal val m: LongArray) { 34 | internal constructor(b: ByteArray, offset: Int): this(LongArray(LEN_MESSAGE)) { populate(b, offset) } 35 | } 36 | 37 | internal inline operator fun Bit32Message.get(sigmaByte: Byte): Int = m[sigmaByte.toInt()] 38 | internal inline operator fun Bit64Message.get(sigmaByte: Byte): Long = m[sigmaByte.toInt()] 39 | 40 | internal inline fun Bit32Message.copy(): Bit32Message = Bit32Message(m.copyOf()) 41 | internal inline fun Bit64Message.copy(): Bit64Message = Bit64Message(m.copyOf()) 42 | 43 | internal inline fun Bit32Message.fill() { m.fill(0) } 44 | internal inline fun Bit64Message.fill() { m.fill(0) } 45 | 46 | internal inline fun Bit32Message.populate(b: ByteArray, offset: Int) { 47 | b.lePackIntoUnsafe(m, destOffset = 0, sourceIndexStart = offset, sourceIndexEnd = offset + SIZE_MESSAGE_32B) 48 | } 49 | 50 | internal inline fun Bit64Message.populate(b: ByteArray, offset: Int) { 51 | b.lePackIntoUnsafe(m, destOffset = 0, sourceIndexStart = offset, sourceIndexEnd = offset + SIZE_MESSAGE_64B) 52 | } 53 | -------------------------------------------------------------------------------- /library/blake2/src/commonTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2bUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.InternalKotlinCryptoApi 19 | import org.kotlincrypto.error.InvalidKeyException 20 | import org.kotlincrypto.error.InvalidParameterException 21 | import kotlin.test.Test 22 | import kotlin.test.assertFailsWith 23 | 24 | @OptIn(InternalKotlinCryptoApi::class) 25 | class BLAKE2bUnitTest { 26 | 27 | @Test 28 | fun givenBLAKE2bDigest_whenInvalidBitStrength_thenThrowsException() { 29 | assertFailsWith { BLAKE2b(8 - 8) } 30 | assertFailsWith { BLAKE2b(8 - 1) } 31 | assertFailsWith { BLAKE2b(512 + 8) } 32 | assertFailsWith { BLAKE2b(512 + 1) } 33 | } 34 | 35 | @Test 36 | fun givenBLAKE2bDigest_whenInvalidPersonalization_thenThrowsException() { 37 | // Checks assertion parameters used for non-personalization arguments are valid 38 | BLAKE2b(512, ByteArray(16)) 39 | assertFailsWith { BLAKE2b(512, ByteArray(16 - 1)) } 40 | } 41 | 42 | @Test 43 | fun givenBLAKE2bDigest_whenInvalidSalt_thenThrowsException() { 44 | // Checks assertion parameters used for non-salt arguments are valid 45 | BLAKE2b(512, 0, salt = ByteArray(16), null) 46 | assertFailsWith { BLAKE2b(512, 0, salt = ByteArray(16 -1), null) } 47 | } 48 | 49 | @Test 50 | fun givenBLAKE2bDigest_whenInvalidKeyLength_thenThrowsException() { 51 | // Checks assertion parameters used for non keyLength arguments are valid 52 | BLAKE2b(512, 0, null, null) 53 | assertFailsWith { BLAKE2b(512, 0 - 1, null, null) } 54 | assertFailsWith { BLAKE2b(512, 64 + 1, null, null) } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /library/blake2/src/commonTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2b_160UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | @Suppress("ClassName") 23 | open class BLAKE2b_160UnitTest: DigestUnitTest() { 24 | override val digest: Digest = BLAKE2b(160) 25 | final override val expectedResetHash: String = "3345524abf6bbe1809449224b5972c41790b6cf2" 26 | final override val expectedMultiBlockHash: String = "bc1baca26f10b1bdd02371f9d78210aa16c56cd3" 27 | final override val expectedUpdateSmallHash: String = "16bd8c06eedd341e843a4619a990c4dc3edb21ef" 28 | final override val expectedUpdateMediumHash: String = "0392905eea6fc6984c776fe7db5aff54b1c273a3" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/blake2/src/commonTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2b_256UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | @Suppress("ClassName") 23 | open class BLAKE2b_256UnitTest: DigestUnitTest() { 24 | override val digest: Digest = BLAKE2b(256) 25 | final override val expectedResetHash: String = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8" 26 | final override val expectedMultiBlockHash: String = "26bbc0909fede5fcc5598fabdad3798cb75b7fba7c50487e3ff3a9a20e21d3e8" 27 | final override val expectedUpdateSmallHash: String = "d336561fbbb648ea3c8ac17707b371fbc4b8168cb4ff3842c4905ea2345c2d82" 28 | final override val expectedUpdateMediumHash: String = "77a6faa978acdeba7bb899c87f03cc17a59d77d3c3d1668c863ea70e0b92f260" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/blake2/src/commonTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2sUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.InternalKotlinCryptoApi 19 | import org.kotlincrypto.error.InvalidKeyException 20 | import org.kotlincrypto.error.InvalidParameterException 21 | import kotlin.test.Test 22 | import kotlin.test.assertFailsWith 23 | 24 | @OptIn(InternalKotlinCryptoApi::class) 25 | class BLAKE2sUnitTest { 26 | 27 | @Test 28 | fun givenBLAKE2sDigest_whenInvalidBitStrength_thenThrowsException() { 29 | assertFailsWith { BLAKE2s(8 - 8) } 30 | assertFailsWith { BLAKE2s(8 - 1) } 31 | assertFailsWith { BLAKE2s(256 + 8) } 32 | assertFailsWith { BLAKE2s(256 + 1) } 33 | } 34 | 35 | @Test 36 | fun givenBLAKE2sDigest_whenInvalidPersonalization_thenThrowsException() { 37 | // Checks assertion parameters used for non-personalization arguments are valid 38 | BLAKE2s(256, ByteArray(8)) 39 | assertFailsWith { BLAKE2s(256, ByteArray(8 - 1)) } 40 | } 41 | 42 | @Test 43 | fun givenBLAKE2sDigest_whenInvalidSalt_thenThrowsException() { 44 | // Checks assertion parameters used for non-salt arguments are valid 45 | BLAKE2s(256, 0, salt = ByteArray(8), null) 46 | assertFailsWith { BLAKE2s(256, 0, salt = ByteArray(8 -1), null) } 47 | } 48 | 49 | @Test 50 | fun givenBLAKE2sDigest_whenInvalidKeyLength_thenThrowsException() { 51 | // Checks assertion parameters used for non keyLength arguments are valid 52 | BLAKE2s(256, 0, null, null) 53 | assertFailsWith { BLAKE2s(256, 0 - 1, null, null) } 54 | assertFailsWith { BLAKE2s(256, 32 + 1, null, null) } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /library/blake2/src/commonTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_128UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | @Suppress("ClassName") 23 | open class BLAKE2s_128UnitTest: DigestUnitTest() { 24 | override val digest: Digest = BLAKE2s(128) 25 | final override val expectedResetHash: String = "64550d6ffe2c0a01a14aba1eade0200c" 26 | final override val expectedMultiBlockHash: String = "4cbf8cd6c17a32c0ad94b565c56f6936" 27 | final override val expectedUpdateSmallHash: String = "ab38f13c29c9a4447792dff4001eed60" 28 | final override val expectedUpdateMediumHash: String = "b6a126f99de02e6e09c4403ed1b01b86" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/blake2/src/commonTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_160UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | @Suppress("ClassName") 23 | open class BLAKE2s_160UnitTest: DigestUnitTest() { 24 | override val digest: Digest = BLAKE2s(160) 25 | final override val expectedResetHash: String = "354c9c33f735962418bdacb9479873429c34916f" 26 | final override val expectedMultiBlockHash: String = "6bfbde3b164b7b27aeefcab4e0359d820cbe6250" 27 | final override val expectedUpdateSmallHash: String = "509c284931a449f5f344c90ec1b45b9b6254843f" 28 | final override val expectedUpdateMediumHash: String = "d3bb5a9fd454d510ad0cc8e087ed636009d2b6f0" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/blake2/src/commonTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_224UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | @Suppress("ClassName") 23 | open class BLAKE2s_224UnitTest: DigestUnitTest() { 24 | override val digest: Digest = BLAKE2s(224) 25 | final override val expectedResetHash: String = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4" 26 | final override val expectedMultiBlockHash: String = "5b6de0890945e84fc8499672aa96697e35c25a66c33e539f6ec8bdde" 27 | final override val expectedUpdateSmallHash: String = "94b6a32aeaafeca766f21babb72fc3aae69cc467bf427b1699a2465d" 28 | final override val expectedUpdateMediumHash: String = "6a158630e37aadda75cea26fe687e012e173d01fafed85f109916f77" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/blake2/src/commonTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_256UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | @Suppress("ClassName") 23 | open class BLAKE2s_256UnitTest: DigestUnitTest() { 24 | override val digest: Digest = BLAKE2s(256) 25 | final override val expectedResetHash: String = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9" 26 | final override val expectedMultiBlockHash: String = "34b367319d4591cae7c58f61ba116fa0efc71d84c888c747a8a323e32524bdcf" 27 | final override val expectedUpdateSmallHash: String = "22b549dea81305261255701e6b4e74201c4372ffaa2c8eebe551abbad6b60c91" 28 | final override val expectedUpdateMediumHash: String = "95fa4ca59b1d60ecbbdf28f8e22adafe0613d73b4581b205b966bb2b293371ba" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/blake2/src/jvmMain/java9/module-info.java: -------------------------------------------------------------------------------- 1 | @SuppressWarnings("module") 2 | module org.kotlincrypto.hash.blake2 { 3 | requires kotlin.stdlib; 4 | requires transitive org.kotlincrypto.core.digest; 5 | requires org.kotlincrypto.bitops.bits; 6 | requires org.kotlincrypto.bitops.endian; 7 | 8 | exports org.kotlincrypto.hash.blake2; 9 | } 10 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2b_160JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class BLAKE2b_160JvmUnitTest: BLAKE2b_160UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2b_184JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.bouncycastle.crypto.digests.Blake2bDigest 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | @Suppress("ClassName") 23 | class BLAKE2b_184JvmUnitTest: BLAKE2b_184UnitTest() { 24 | override val digest: Digest = TestBCDigest(Blake2bDigest(160 + 24), copy = { Blake2bDigest(this) }) 25 | } 26 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2b_256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class BLAKE2b_256JvmUnitTest: BLAKE2b_256UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2b_384JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class BLAKE2b_384JvmUnitTest: BLAKE2b_384UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2b_512JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class BLAKE2b_512JvmUnitTest: BLAKE2b_512UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2b_512_Salt_Personalization_JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.bouncycastle.crypto.digests.Blake2bDigest 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | @Suppress("ClassName") 23 | class BLAKE2b_512_Salt_Personalization_JvmUnitTest: BLAKE2b_512_Salt_Personalization_UnitTest() { 24 | override val digest: Digest = TestBCDigest( 25 | digest = Blake2bDigest( 26 | /* key = */ null, 27 | /* digestLength = */ 512 / Byte.SIZE_BITS, 28 | /* salt = */ salt, 29 | /* personalization = */ personalization, 30 | ), 31 | copy = { Blake2bDigest(this) }, 32 | ) 33 | } 34 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_128JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class BLAKE2s_128JvmUnitTest: BLAKE2s_128UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_160JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class BLAKE2s_160JvmUnitTest: BLAKE2s_160UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_184JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.bouncycastle.crypto.digests.Blake2sDigest 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | @Suppress("ClassName") 23 | class BLAKE2s_184JvmUnitTest: BLAKE2s_184UnitTest() { 24 | override val digest: Digest = TestBCDigest(Blake2sDigest(160 + 24), copy = { Blake2sDigest(this) }) 25 | } 26 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_224JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class BLAKE2s_224JvmUnitTest: BLAKE2s_224UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class BLAKE2s_256JvmUnitTest: BLAKE2s_256UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/blake2/src/jvmTest/kotlin/org/kotlincrypto/hash/blake2/BLAKE2s_256_Salt_Personalization_JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.blake2 17 | 18 | import org.bouncycastle.crypto.digests.Blake2sDigest 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | @Suppress("ClassName") 23 | class BLAKE2s_256_Salt_Personalization_JvmUnitTest: BLAKE2s_256_Salt_Personalization_UnitTest() { 24 | override val digest: Digest = TestBCDigest( 25 | digest = Blake2sDigest( 26 | /* key = */ null, 27 | /* digestBytes = */ 256 / Byte.SIZE_BITS, 28 | /* salt = */ salt, 29 | /* personalization = */ personalization, 30 | ), 31 | copy = { Blake2sDigest(this) }, 32 | ) 33 | } 34 | -------------------------------------------------------------------------------- /library/md/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /library/md/README.md: -------------------------------------------------------------------------------- 1 | # Module md 2 | 3 | `Digest` implementations for MD Hashing 4 | 5 | Implementations for: 6 | - MD5 7 | 8 | Implementations also available for `Hmac` via [KotlinCrypto/MACs][url-macs]. 9 | 10 | See [HERE][url-digest-usage] for basic usage example of `Digest`. 11 | 12 | ```kotlin 13 | fun main() { 14 | MD5() 15 | } 16 | ``` 17 | 18 | [url-digest-usage]: https://core.kotlincrypto.org/library/digest/index.html 19 | [url-macs]: https://github.com/KotlinCrypto/MACs 20 | -------------------------------------------------------------------------------- /library/md/api/md.api: -------------------------------------------------------------------------------- 1 | public final class org/kotlincrypto/hash/md/MD5 : org/kotlincrypto/core/digest/Digest { 2 | public fun ()V 3 | public synthetic fun copy ()Ljava/lang/Object; 4 | public fun copy ()Lorg/kotlincrypto/hash/md/MD5; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /library/md/api/md.klib.api: -------------------------------------------------------------------------------- 1 | // Klib ABI Dump 2 | // Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, wasmWasi, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64] 3 | // Rendering settings: 4 | // - Signature version: 2 5 | // - Show manifest properties: true 6 | // - Show declarations: true 7 | 8 | // Library unique name: 9 | final class org.kotlincrypto.hash.md/MD5 : org.kotlincrypto.core.digest/Digest { // org.kotlincrypto.hash.md/MD5|null[0] 10 | constructor () // org.kotlincrypto.hash.md/MD5.|(){}[0] 11 | 12 | final fun copy(): org.kotlincrypto.hash.md/MD5 // org.kotlincrypto.hash.md/MD5.copy|copy(){}[0] 13 | } 14 | -------------------------------------------------------------------------------- /library/md/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("configuration") 18 | id("bom-include") 19 | } 20 | 21 | kmpConfiguration { 22 | configureShared(java9ModuleName = "org.kotlincrypto.hash.md", publish = true) { 23 | common { 24 | sourceSetMain { 25 | dependencies { 26 | api(libs.kotlincrypto.core.digest) 27 | implementation(libs.kotlincrypto.bitops.bits) 28 | implementation(libs.kotlincrypto.bitops.endian) 29 | } 30 | } 31 | sourceSetTest { 32 | dependencies { 33 | implementation(project(":tools:testing")) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /library/md/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 KotlinCrypto 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | POM_ARTIFACT_ID=md 15 | POM_NAME=KotlinCrypto MD Hashing 16 | POM_DESCRIPTION=Digests for MD5 17 | -------------------------------------------------------------------------------- /library/md/src/commonTest/kotlin/org/kotlincrypto/hash/md/MD5UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.md 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | open class MD5UnitTest: DigestUnitTest() { 23 | override val digest: Digest = MD5() 24 | final override val expectedResetHash: String = "d41d8cd98f00b204e9800998ecf8427e" 25 | final override val expectedMultiBlockHash: String = "c88e9b8294852cc9de9c1991e41960cc" 26 | final override val expectedUpdateSmallHash: String = "a0b0f0ae132fe7c79c678fddda4309ba" 27 | final override val expectedUpdateMediumHash: String = "9fcb20905157e9afaa264a1e26762308" 28 | 29 | @Test 30 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 31 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 32 | } 33 | 34 | @Test 35 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 36 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 37 | } 38 | 39 | @Test 40 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 41 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 42 | } 43 | 44 | @Test 45 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 46 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 47 | } 48 | 49 | @Test 50 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 51 | super.givenDigest_whenCopied_thenIsDifferentInstance() 52 | } 53 | 54 | @Test 55 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 56 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/md/src/jvmMain/java9/module-info.java: -------------------------------------------------------------------------------- 1 | module org.kotlincrypto.hash.md { 2 | requires kotlin.stdlib; 3 | requires transitive org.kotlincrypto.core.digest; 4 | requires org.kotlincrypto.bitops.bits; 5 | requires org.kotlincrypto.bitops.endian; 6 | 7 | exports org.kotlincrypto.hash.md; 8 | } 9 | -------------------------------------------------------------------------------- /library/md/src/jvmTest/kotlin/org/kotlincrypto/hash/md/MD5JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.md 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class MD5JvmUnitTest: MD5UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha1/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /library/sha1/README.md: -------------------------------------------------------------------------------- 1 | # Module sha1 2 | 3 | `Digest` implementations for SHA1 Hashing 4 | 5 | Implementations for: 6 | - SHA-1 7 | 8 | Implementations also available for `Hmac` via [KotlinCrypto/MACs][url-macs]. 9 | 10 | See [HERE][url-digest-usage] for basic usage example of `Digest`. 11 | 12 | ```kotlin 13 | fun main() { 14 | SHA1() 15 | } 16 | ``` 17 | 18 | [url-digest-usage]: https://core.kotlincrypto.org/library/digest/index.html 19 | [url-macs]: https://github.com/KotlinCrypto/MACs 20 | -------------------------------------------------------------------------------- /library/sha1/api/sha1.api: -------------------------------------------------------------------------------- 1 | public final class org/kotlincrypto/hash/sha1/SHA1 : org/kotlincrypto/core/digest/Digest { 2 | public fun ()V 3 | public synthetic fun copy ()Ljava/lang/Object; 4 | public fun copy ()Lorg/kotlincrypto/hash/sha1/SHA1; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /library/sha1/api/sha1.klib.api: -------------------------------------------------------------------------------- 1 | // Klib ABI Dump 2 | // Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, wasmWasi, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64] 3 | // Rendering settings: 4 | // - Signature version: 2 5 | // - Show manifest properties: true 6 | // - Show declarations: true 7 | 8 | // Library unique name: 9 | final class org.kotlincrypto.hash.sha1/SHA1 : org.kotlincrypto.core.digest/Digest { // org.kotlincrypto.hash.sha1/SHA1|null[0] 10 | constructor () // org.kotlincrypto.hash.sha1/SHA1.|(){}[0] 11 | 12 | final fun copy(): org.kotlincrypto.hash.sha1/SHA1 // org.kotlincrypto.hash.sha1/SHA1.copy|copy(){}[0] 13 | } 14 | -------------------------------------------------------------------------------- /library/sha1/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("configuration") 18 | id("bom-include") 19 | } 20 | 21 | kmpConfiguration { 22 | configureShared(java9ModuleName = "org.kotlincrypto.hash.sha1", publish = true) { 23 | common { 24 | sourceSetMain { 25 | dependencies { 26 | api(libs.kotlincrypto.core.digest) 27 | implementation(libs.kotlincrypto.bitops.bits) 28 | implementation(libs.kotlincrypto.bitops.endian) 29 | } 30 | } 31 | sourceSetTest { 32 | dependencies { 33 | implementation(project(":tools:testing")) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /library/sha1/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 KotlinCrypto 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | POM_ARTIFACT_ID=sha1 15 | POM_NAME=KotlinCrypto SHA1 Hashing 16 | POM_DESCRIPTION=Digests for SHA-1 17 | -------------------------------------------------------------------------------- /library/sha1/src/commonTest/kotlin/org/kotlincrypto/hash/sha1/SHA1UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha1 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | open class SHA1UnitTest: DigestUnitTest() { 23 | override val digest: Digest = SHA1() 24 | final override val expectedResetHash: String = "da39a3ee5e6b4b0d3255bfef95601890afd80709" 25 | final override val expectedMultiBlockHash: String = "46b459054f55a0e41f8810ae8b265868bf65b45b" 26 | final override val expectedUpdateSmallHash: String = "3e87f2fb5366045ef4fcaf3a845554d16b36f69d" 27 | final override val expectedUpdateMediumHash: String = "c0e5c75fba36a5a24ad475ac2321c581aea8008e" 28 | 29 | @Test 30 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 31 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 32 | } 33 | 34 | @Test 35 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 36 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 37 | } 38 | 39 | @Test 40 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 41 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 42 | } 43 | 44 | @Test 45 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 46 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 47 | } 48 | 49 | @Test 50 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 51 | super.givenDigest_whenCopied_thenIsDifferentInstance() 52 | } 53 | 54 | @Test 55 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 56 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/sha1/src/jvmMain/java9/module-info.java: -------------------------------------------------------------------------------- 1 | @SuppressWarnings("module") 2 | module org.kotlincrypto.hash.sha1 { 3 | requires kotlin.stdlib; 4 | requires transitive org.kotlincrypto.core.digest; 5 | requires org.kotlincrypto.bitops.bits; 6 | requires org.kotlincrypto.bitops.endian; 7 | 8 | exports org.kotlincrypto.hash.sha1; 9 | } 10 | -------------------------------------------------------------------------------- /library/sha1/src/jvmTest/kotlin/org/kotlincrypto/hash/sha1/SHA1JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha1 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class SHA1JvmUnitTest: SHA1UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha2/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /library/sha2/README.md: -------------------------------------------------------------------------------- 1 | # Module sha2 2 | 3 | `Digest` implementations for SHA2 Hashing 4 | 5 | Implementations for: 6 | - SHA-224 7 | - SHA-256 8 | - SHA-384 9 | - SHA-512 10 | - SHA-512/t 11 | 12 | Implementations also available for `Hmac` via [KotlinCrypto/MACs][url-macs]. 13 | 14 | See [HERE][url-digest-usage] for basic usage example of `Digest`. 15 | 16 | ```kotlin 17 | fun main() { 18 | SHA224() 19 | SHA256() 20 | SHA384() 21 | SHA512() 22 | 23 | SHA512t(t = 224) // SHA-512/224 24 | SHA512t(t = 256) // SHA-512/256 25 | } 26 | ``` 27 | 28 | [url-digest-usage]: https://core.kotlincrypto.org/library/digest/index.html 29 | [url-macs]: https://github.com/KotlinCrypto/MACs 30 | -------------------------------------------------------------------------------- /library/sha2/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("configuration") 18 | id("bom-include") 19 | } 20 | 21 | kmpConfiguration { 22 | configureShared(java9ModuleName = "org.kotlincrypto.hash.sha2", publish = true) { 23 | common { 24 | sourceSetMain { 25 | dependencies { 26 | api(libs.kotlincrypto.core.digest) 27 | implementation(libs.kotlincrypto.bitops.bits) 28 | implementation(libs.kotlincrypto.bitops.endian) 29 | } 30 | } 31 | sourceSetTest { 32 | dependencies { 33 | implementation(project(":tools:testing")) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /library/sha2/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 KotlinCrypto 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | POM_ARTIFACT_ID=sha2 15 | POM_NAME=KotlinCrypto SHA2 Hashing 16 | POM_DESCRIPTION=Digests for SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/t 17 | -------------------------------------------------------------------------------- /library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA224.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | /** 19 | * SHA-224 implementation 20 | * */ 21 | public class SHA224: Bit32Digest { 22 | 23 | public constructor(): super(bitStrength = 224, h = H) 24 | 25 | private constructor(other: SHA224): super(other) 26 | 27 | public override fun copy(): SHA224 = SHA224(this) 28 | 29 | private companion object { 30 | private val H = intArrayOf( 31 | -1056596264, 914150663, 812702999, -150054599, 32 | -4191439, 1750603025, 1694076839, -1090891868, 33 | ) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA256.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | /** 19 | * SHA-256 implementation 20 | * */ 21 | public class SHA256: Bit32Digest { 22 | 23 | public constructor(): super(bitStrength = 256, h = H) 24 | 25 | private constructor(other: SHA256): super(other) 26 | 27 | public override fun copy(): SHA256 = SHA256(this) 28 | 29 | private companion object { 30 | private val H = intArrayOf( 31 | 1779033703, -1150833019, 1013904242, -1521486534, 32 | 1359893119, -1694144372, 528734635, 1541459225, 33 | ) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA384.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | /** 19 | * SHA-384 implementation 20 | * */ 21 | public class SHA384: Bit64Digest { 22 | 23 | public constructor(): super(bitStrength = 384, t = null, h = H) 24 | 25 | private constructor(other: SHA384): super(other) 26 | 27 | public override fun copy(): SHA384 = SHA384(this) 28 | 29 | private companion object { 30 | private val H = longArrayOf( 31 | -3766243637369397544L, 7105036623409894663L, -7973340178411365097L, 1526699215303891257L, 32 | 7436329637833083697L, -8163818279084223215L, -2662702644619276377L, 5167115440072839076L, 33 | ) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA512.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | /** 19 | * SHA-512 implementation 20 | * */ 21 | public class SHA512: Bit64Digest { 22 | 23 | public constructor(): super(bitStrength = 512, t = null, h = H) 24 | 25 | private constructor(other: SHA512): super(other) 26 | 27 | public override fun copy(): SHA512 = SHA512(this) 28 | 29 | private companion object { 30 | private val H = longArrayOf( 31 | 7640891576956012808L, -4942790177534073029L, 4354685564936845355L, -6534734903238641935L, 32 | 5840696475078001361L, -7276294671716946913L, 2270897969802886507L, 6620516959819538809L, 33 | ) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA512t.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.error.InvalidParameterException 19 | 20 | /** 21 | * SHA-512/t implementation 22 | * */ 23 | public class SHA512t: Bit64Digest { 24 | 25 | /** 26 | * Primary constructor for creating a new [SHA512t] instance 27 | * 28 | * @throws [InvalidParameterException] when: 29 | * - [t] is less than 0 30 | * - [t] is greater than or equal to 512 31 | * - [t] is not a factor of 8 32 | * - [t] is 384 33 | * */ 34 | public constructor(t: Int): super( 35 | bitStrength = 512, 36 | t = t, 37 | h = longArrayOf( 38 | 7640891576956012808L xor -6510615555426900571L, 39 | -4942790177534073029L xor -6510615555426900571L, 40 | 4354685564936845355L xor -6510615555426900571L, 41 | -6534734903238641935L xor -6510615555426900571L, 42 | 5840696475078001361L xor -6510615555426900571L, 43 | -7276294671716946913L xor -6510615555426900571L, 44 | 2270897969802886507L xor -6510615555426900571L, 45 | 6620516959819538809L xor -6510615555426900571L, 46 | ) 47 | ) 48 | 49 | private constructor(other: SHA512t): super(other) 50 | 51 | public override fun copy(): SHA512t = SHA512t(this) 52 | } 53 | -------------------------------------------------------------------------------- /library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA512tDeprecated.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:JvmName("SHA512tKt") 17 | @file:Suppress("FunctionName") 18 | 19 | package org.kotlincrypto.hash.sha2 20 | 21 | import kotlin.jvm.JvmName 22 | 23 | /** @suppress */ 24 | @Deprecated("Use SHA512t directly", ReplaceWith("SHA512t(224)", "org.kotlincrypto.hash.sha2.SHA512t")) 25 | public fun SHA512_224(): SHA512t = SHA512t(t = 224) 26 | 27 | /** @suppress */ 28 | @Deprecated("Use SHA512t directly", ReplaceWith("SHA512t(256)", "org.kotlincrypto.hash.sha2.SHA512t")) 29 | public fun SHA512_256(): SHA512t = SHA512t(t = 256) 30 | -------------------------------------------------------------------------------- /library/sha2/src/commonTest/kotlin/org/kotlincrypto/hash/sha2/SHA224UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | open class SHA224UnitTest: DigestUnitTest() { 23 | override val digest: Digest = SHA224() 24 | final override val expectedResetHash: String = "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f" 25 | final override val expectedMultiBlockHash: String = "6cb6794e118a4798c51f984650153ebc77f51e06d88ce8eea04b0f00" 26 | final override val expectedUpdateSmallHash: String = "bda63b682436fa6767ad866fb78c48da5da268a80e49fa91b2a1349d" 27 | final override val expectedUpdateMediumHash: String = "190464776331b2a2d618bb82e3567c4de96c7d23bd7ea0376d8cabc8" 28 | 29 | @Test 30 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 31 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 32 | } 33 | 34 | @Test 35 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 36 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 37 | } 38 | 39 | @Test 40 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 41 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 42 | } 43 | 44 | @Test 45 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 46 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 47 | } 48 | 49 | @Test 50 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 51 | super.givenDigest_whenCopied_thenIsDifferentInstance() 52 | } 53 | 54 | @Test 55 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 56 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/sha2/src/commonTest/kotlin/org/kotlincrypto/hash/sha2/SHA256UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | open class SHA256UnitTest: DigestUnitTest() { 23 | override val digest: Digest = SHA256() 24 | final override val expectedResetHash: String = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" 25 | final override val expectedMultiBlockHash: String = "eb87d5109755faf32c76f0808352aae70373bef3215c34feaab18c75f8c8a825" 26 | final override val expectedUpdateSmallHash: String = "9e5271a0c245b7e73d5f7936a1c6897cc9f7e844a62a2e0dcc97fdd933295853" 27 | final override val expectedUpdateMediumHash: String = "b04e2d0ca3c0bd2027bbb58e9267ffb0f526953dd319545a89faf9f3e3b6d2fa" 28 | 29 | @Test 30 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 31 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 32 | } 33 | 34 | @Test 35 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 36 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 37 | } 38 | 39 | @Test 40 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 41 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 42 | } 43 | 44 | @Test 45 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 46 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 47 | } 48 | 49 | @Test 50 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 51 | super.givenDigest_whenCopied_thenIsDifferentInstance() 52 | } 53 | 54 | @Test 55 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 56 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/sha2/src/commonTest/kotlin/org/kotlincrypto/hash/sha2/SHA512_224UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | @Suppress("ClassName") 23 | open class SHA512_224UnitTest: DigestUnitTest() { 24 | override val digest: Digest = SHA512t(224) 25 | final override val expectedResetHash: String = "6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4" 26 | final override val expectedMultiBlockHash: String = "def504f69a18c54a156bdd73afdf3797f55259f0ed7510af5c0a9a32" 27 | final override val expectedUpdateSmallHash: String = "d45c8e42b7a6a28123e5026f8d55acdd9b2e8738e4b65fe65c86f5c4" 28 | final override val expectedUpdateMediumHash: String = "ac0a3c03de7ca29bcb05f1d5f1ad074da0002bcda21b05637c25099f" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /library/sha2/src/commonTest/kotlin/org/kotlincrypto/hash/sha2/SHA512_256UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.DigestUnitTest 20 | import kotlin.test.Test 21 | 22 | @Suppress("ClassName") 23 | open class SHA512_256UnitTest: DigestUnitTest() { 24 | override val digest: Digest = SHA512t(256) 25 | final override val expectedResetHash: String = "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a" 26 | final override val expectedMultiBlockHash: String = "5457acd619882cfb6e8a403dea7c32f1a7de70e1f1d39c390b8cba8a204f3933" 27 | final override val expectedUpdateSmallHash: String = "49a4cf33a539e4819ff6ef478ef24f307379efb33b296e97a19497135314d1e0" 28 | final override val expectedUpdateMediumHash: String = "85fcfb43e87203b9c795e2251e2490d1f3db3a7679cb0f6ebada4104bcc34fa9" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /library/sha2/src/commonTest/kotlin/org/kotlincrypto/hash/sha2/SHA512tUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.error.InvalidParameterException 19 | import kotlin.test.Test 20 | import kotlin.test.assertFailsWith 21 | 22 | class SHA512tUnitTest { 23 | 24 | @Test 25 | fun givenSHA512tDigest_whenInvalidBitStrength_thenThrowsException() { 26 | assertFailsWith { SHA512t(-1) } 27 | assertFailsWith { SHA512t(384) } 28 | assertFailsWith { SHA512t(512) } 29 | assertFailsWith { SHA512t(512 - 8 + 1) } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /library/sha2/src/jvmMain/java9/module-info.java: -------------------------------------------------------------------------------- 1 | @SuppressWarnings("module") 2 | module org.kotlincrypto.hash.sha2 { 3 | requires kotlin.stdlib; 4 | requires transitive org.kotlincrypto.core.digest; 5 | requires org.kotlincrypto.bitops.bits; 6 | requires org.kotlincrypto.bitops.endian; 7 | 8 | exports org.kotlincrypto.hash.sha2; 9 | } 10 | -------------------------------------------------------------------------------- /library/sha2/src/jvmTest/kotlin/org/kotlincrypto/hash/sha2/SHA224JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class SHA224JvmUnitTest: SHA224UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha2/src/jvmTest/kotlin/org/kotlincrypto/hash/sha2/SHA256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class SHA256JvmUnitTest: SHA256UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha2/src/jvmTest/kotlin/org/kotlincrypto/hash/sha2/SHA384JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class SHA384JvmUnitTest: SHA384UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha2/src/jvmTest/kotlin/org/kotlincrypto/hash/sha2/SHA512JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class SHA512JvmUnitTest: SHA512UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha2/src/jvmTest/kotlin/org/kotlincrypto/hash/sha2/SHA512_224JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class SHA512_224JvmUnitTest: SHA512_224UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha2/src/jvmTest/kotlin/org/kotlincrypto/hash/sha2/SHA512_232JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.bouncycastle.crypto.digests.SHA512tDigest 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | @Suppress("ClassName") 23 | class SHA512_232JvmUnitTest: SHA512_232UnitTest() { 24 | override val digest: Digest = TestBCDigest(SHA512tDigest(224 + 8), copy = { SHA512tDigest(this) }) 25 | } 26 | -------------------------------------------------------------------------------- /library/sha2/src/jvmTest/kotlin/org/kotlincrypto/hash/sha2/SHA512_256Jvm256UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha2 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class SHA512_256Jvm256UnitTest: SHA512_256UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /library/sha3/README.md: -------------------------------------------------------------------------------- 1 | # Module sha3 2 | 3 | `Digest` and `Xof` implementations for SHA3 Hashing 4 | 5 | Implementations for: 6 | - Keccak-224 7 | - Keccak-256 8 | - Keccak-384 9 | - Keccak-512 10 | - SHA3-224 11 | - SHA3-256 12 | - SHA3-384 13 | - SHA3-512 14 | - SHAKE128 15 | - SHAKE256 16 | - CSHAKE128 17 | - CSHAKE256 18 | - ParallelHash128 19 | - ParallelHash256 20 | - TupleHash128 21 | - TupleHash256 22 | 23 | Implementations also available for `Hmac` and `KMAC` via [KotlinCrypto/MACs][url-macs]. 24 | 25 | See [HERE][url-digest-usage] for basic usage example of `Digest`. 26 | 27 | ```kotlin 28 | fun main() { 29 | Keccak224() 30 | Keccak256() 31 | Keccak384() 32 | Keccak512() 33 | SHA3_224() 34 | SHA3_256() 35 | SHA3_384() 36 | SHA3_512() 37 | 38 | SHAKE128() 39 | 40 | // Return 640 bytes instead of the default 41 | // whenever digest() is called. 42 | SHAKE256(outputLength = 640) 43 | 44 | // NIST.SP.800-185 derived functions 45 | val S = "My Customization".encodeToByteArray() 46 | CSHAKE128(null, S, outputLength = 128) 47 | CSHAKE256(null, S) 48 | ParallelHash128(null, B = 123) 49 | ParallelHash256(S, B = 456, outputLength = 123) 50 | TupleHash128(S, outputLength = 320) 51 | TupleHash256(null) 52 | } 53 | ``` 54 | 55 | See [HERE][url-xof-usage] for basic usage example of `Xof` (i.e. [Extendable-Output Functions][url-pub-xof]). 56 | 57 | ```kotlin 58 | fun main() { 59 | val xof: Xof = SHAKE128.xOf() 60 | SHAKE256.xOf() 61 | 62 | // NIST.SP.800-185 derived functions 63 | val S = "My Customization".encodeToByteArray() 64 | CSHAKE128.xOf(null, S) 65 | CSHAKE256.xOf(null, S) 66 | ParallelHash128.xOf(S, B = 123) 67 | ParallelHash256.xOf(B = 654) 68 | TupleHash128.xOf(S) 69 | TupleHash256.xOf() 70 | } 71 | ``` 72 | 73 | [url-digest-usage]: https://core.kotlincrypto.org/library/digest/index.html 74 | [url-xof-usage]: https://core.kotlincrypto.org/library/xof/index.html 75 | [url-macs]: https://github.com/KotlinCrypto/MACs 76 | [url-pub-xof]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 77 | -------------------------------------------------------------------------------- /library/sha3/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("configuration") 18 | id("bom-include") 19 | } 20 | 21 | kmpConfiguration { 22 | configureShared(java9ModuleName = "org.kotlincrypto.hash.sha3", publish = true) { 23 | common { 24 | sourceSetMain { 25 | dependencies { 26 | api(libs.kotlincrypto.core.digest) 27 | api(libs.kotlincrypto.core.xof) 28 | implementation(libs.kotlincrypto.bitops.endian) 29 | implementation(libs.kotlincrypto.sponges.keccak) 30 | } 31 | } 32 | sourceSetTest { 33 | dependencies { 34 | implementation(project(":tools:testing")) 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /library/sha3/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 KotlinCrypto 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | POM_ARTIFACT_ID=sha3 15 | POM_NAME=KotlinCrypto SHA3 Hashing 16 | POM_DESCRIPTION=Digests for SHA3-224, SHA3-256, SHA3-384, SHA3-512, Keccak-224, Keccak-256, Keccak-384, Keccak-512, SHAKE128, SHAKE256, CSHAKE128, CSHAKE256, ParallelHash128, ParallelHash256, TupleHash128, TupleHash256 17 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/Keccak224.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | /** 19 | * Keccak-224 implementation 20 | * 21 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 22 | * */ 23 | public class Keccak224: KeccakDigest { 24 | 25 | public constructor(): super( 26 | algorithm = "${KECCAK}-224", 27 | blockSize = 144, 28 | digestLength = 28, 29 | dsByte = PAD_KECCAK, 30 | ) 31 | 32 | private constructor(other: Keccak224): super(other) 33 | 34 | public override fun copy(): Keccak224 = Keccak224(this) 35 | } 36 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/Keccak256.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | /** 19 | * Keccak-256 implementation 20 | * 21 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 22 | * */ 23 | public class Keccak256: KeccakDigest { 24 | 25 | public constructor(): super( 26 | algorithm = "${KECCAK}-256", 27 | blockSize = 136, 28 | digestLength = 32, 29 | dsByte = PAD_KECCAK, 30 | ) 31 | 32 | private constructor(other: Keccak256): super(other) 33 | 34 | public override fun copy(): Keccak256 = Keccak256(this) 35 | } 36 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/Keccak384.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | /** 19 | * Keccak-384 implementation 20 | * 21 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 22 | * */ 23 | public class Keccak384: KeccakDigest { 24 | 25 | public constructor(): super( 26 | algorithm = "${KECCAK}-384", 27 | blockSize = 104, 28 | digestLength = 48, 29 | dsByte = PAD_KECCAK, 30 | ) 31 | 32 | private constructor(other: Keccak384): super(other) 33 | 34 | public override fun copy(): Keccak384 = Keccak384(this) 35 | } 36 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/Keccak512.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | /** 19 | * Keccak-512 implementation 20 | * 21 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 22 | * */ 23 | public class Keccak512: KeccakDigest { 24 | 25 | public constructor(): super( 26 | algorithm = "${KECCAK}-512", 27 | blockSize = 72, 28 | digestLength = 64, 29 | dsByte = PAD_KECCAK, 30 | ) 31 | 32 | private constructor(other: Keccak512): super(other) 33 | 34 | public override fun copy(): Keccak512 = Keccak512(this) 35 | } 36 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/SHA3_224.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | /** 21 | * SHA3-224 implementation 22 | * 23 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 24 | * */ 25 | public class SHA3_224: KeccakDigest { 26 | 27 | public constructor(): super( 28 | algorithm = "${SHA3}-224", 29 | blockSize = 144, 30 | digestLength = 28, 31 | dsByte = PAD_SHA3, 32 | ) 33 | 34 | private constructor(other: SHA3_224): super(other) 35 | 36 | public override fun copy(): SHA3_224 = SHA3_224(this) 37 | } 38 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/SHA3_256.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | /** 21 | * SHA3-256 implementation 22 | * 23 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 24 | * */ 25 | public class SHA3_256: KeccakDigest { 26 | 27 | public constructor(): super( 28 | algorithm = "${SHA3}-256", 29 | blockSize = 136, 30 | digestLength = 32, 31 | dsByte = PAD_SHA3, 32 | ) 33 | 34 | private constructor(other: SHA3_256): super(other) 35 | 36 | public override fun copy(): SHA3_256 = SHA3_256(this) 37 | } 38 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/SHA3_384.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | /** 21 | * SHA3-384 implementation 22 | * 23 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 24 | * */ 25 | public class SHA3_384: KeccakDigest { 26 | 27 | public constructor(): super( 28 | algorithm = "${SHA3}-384", 29 | blockSize = 104, 30 | digestLength = 48, 31 | dsByte = PAD_SHA3, 32 | ) 33 | 34 | private constructor(other: SHA3_384): super(other) 35 | 36 | public override fun copy(): SHA3_384 = SHA3_384(this) 37 | } 38 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/SHA3_512.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | /** 21 | * SHA3-512 implementation 22 | * 23 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 24 | * */ 25 | public class SHA3_512: KeccakDigest { 26 | 27 | public constructor(): super( 28 | algorithm = "${SHA3}-512", 29 | blockSize = 72, 30 | digestLength = 64, 31 | dsByte = PAD_SHA3, 32 | ) 33 | 34 | private constructor(other: SHA3_512): super(other) 35 | 36 | public override fun copy(): SHA3_512 = SHA3_512(this) 37 | } 38 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/SHAKE128.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.core.xof.Xof 20 | import org.kotlincrypto.error.InvalidParameterException 21 | import kotlin.jvm.JvmStatic 22 | 23 | /** 24 | * SHAKE128 implementation 25 | * 26 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 27 | * 28 | * @see [xOf] 29 | * */ 30 | public class SHAKE128: SHAKEDigest { 31 | 32 | /** 33 | * Creates a new [SHAKE128] [Digest] instance with a default output length of 32 bytes. 34 | * */ 35 | public constructor(): this(DIGEST_LENGTH_BIT_128) 36 | 37 | /** 38 | * Creates a new [SHAKE128] [Digest] instance with a non-default output length. 39 | * 40 | * @param [outputLength] The number of bytes returned when [digest] is invoked 41 | * 42 | * @throws [InvalidParameterException] If [outputLength] is negative 43 | * */ 44 | public constructor( 45 | outputLength: Int, 46 | ): this(outputLength, xOfMode = false) 47 | 48 | @Throws(InvalidParameterException::class) 49 | private constructor( 50 | outputLength: Int, 51 | xOfMode: Boolean, 52 | ): super( 53 | N = null, 54 | S = null, 55 | xOfMode = xOfMode, 56 | algorithm = SHAKE + BIT_STRENGTH_128, 57 | blockSize = BLOCK_SIZE_BIT_128, 58 | digestLength = outputLength, 59 | ) 60 | 61 | private constructor(other: SHAKE128): super(other) 62 | 63 | public override fun copy(): SHAKE128 = SHAKE128(this) 64 | 65 | public companion object: SHAKEXofFactory() { 66 | 67 | /** 68 | * Produces a new [Xof] (Extendable-Output Function) for [SHAKE128] 69 | * */ 70 | @JvmStatic 71 | public fun xOf(): Xof { 72 | return SHAKEXof(SHAKE128(outputLength = 0, xOfMode = true)) 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /library/sha3/src/commonMain/kotlin/org/kotlincrypto/hash/sha3/SHAKE256.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.core.xof.Xof 20 | import org.kotlincrypto.error.InvalidParameterException 21 | import kotlin.jvm.JvmStatic 22 | 23 | /** 24 | * SHAKE256 implementation 25 | * 26 | * https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf 27 | * 28 | * @see [xOf] 29 | * */ 30 | public class SHAKE256: SHAKEDigest { 31 | 32 | /** 33 | * Creates a new [SHAKE256] [Digest] instance with a default output length of 64 bytes. 34 | * */ 35 | public constructor(): this(DIGEST_LENGTH_BIT_256) 36 | 37 | /** 38 | * Creates a new [SHAKE256] [Digest] instance with a non-default output length. 39 | * 40 | * @param [outputLength] The number of bytes returned when [digest] is invoked 41 | * 42 | * @throws [InvalidParameterException] If [outputLength] is negative 43 | * */ 44 | public constructor( 45 | outputLength: Int, 46 | ): this(outputLength, xOfMode = false) 47 | 48 | @Throws(InvalidParameterException::class) 49 | private constructor( 50 | outputLength: Int, 51 | xOfMode: Boolean, 52 | ): super( 53 | N = null, 54 | S = null, 55 | xOfMode = xOfMode, 56 | algorithm = SHAKE + BIT_STRENGTH_256, 57 | blockSize = BLOCK_SIZE_BIT_256, 58 | digestLength = outputLength, 59 | ) 60 | 61 | private constructor(other: SHAKE256): super(other) 62 | 63 | public override fun copy(): SHAKE256 = SHAKE256(this) 64 | 65 | public companion object: SHAKEXofFactory() { 66 | 67 | /** 68 | * Produces a new [Xof] (Extendable-Output Function) for [SHAKE256] 69 | * */ 70 | @JvmStatic 71 | public fun xOf(): Xof { 72 | return SHAKEXof(SHAKE256(outputLength = 0, xOfMode = true)) 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE128_NS_UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.kotlincrypto.core.digest.Digest 21 | 22 | open class CSHAKE128_NS_UnitTest: CSHAKE128UnitTest() { 23 | override val digest: Digest = CSHAKE128(N, S) 24 | final override val expectedResetHash: String = "91d6b4ecfd7f295f8e11a2a738a294bb1e4f9fa5aec7834e37ac97c81c41bf8e" 25 | final override val expectedMultiBlockHash: String = "f642e42d66a0192dfa28cfdfd04f96db7f39922b6bca659b10555a571951cd94" 26 | final override val expectedUpdateSmallHash: String = "ba9a9ecb49bac859073f141aa782aa3b0f2006183819b0b2aacf52bbc77b85aa" 27 | final override val expectedUpdateMediumHash: String = "bcc7b6cb50fe65aa14bbc050d973d87c3dad221f402f6114c1c22c643ae966f1" 28 | } 29 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE128_N_UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.kotlincrypto.core.digest.Digest 21 | 22 | open class CSHAKE128_N_UnitTest: CSHAKE128UnitTest() { 23 | override val digest: Digest = CSHAKE128(N, null) 24 | final override val expectedResetHash: String = "63e5b592ba16aef96e22c02f995e04421df9ec14be1b5e82d4da9af10ff2a8c0" 25 | final override val expectedMultiBlockHash: String = "0f73cd62bff065856b8d1d6ecf8bf62c3cab5823b799b102afd887cc087615e1" 26 | final override val expectedUpdateSmallHash: String = "d72243337762656b8d1d48f0ba502468590745e825f6fcfb5c031ff458c2a1e6" 27 | final override val expectedUpdateMediumHash: String = "8110a0f4e6886075dc1d11372a3760868ca6b719cace7a95b75a69583021637f" 28 | } 29 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE128_S_UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.kotlincrypto.core.digest.Digest 21 | 22 | open class CSHAKE128_S_UnitTest: CSHAKE128UnitTest() { 23 | override val digest: Digest = CSHAKE128(null, S) 24 | final override val expectedResetHash: String = "4f3047dee03c3b698f2b6da12bffe7ff89bb5c5bb0bc4e4a8a2ba77c12d70af6" 25 | final override val expectedMultiBlockHash: String = "3f8d7e75e01ead3924941e176e32daac8d6c04bdc345afa921114196fc6d3f74" 26 | final override val expectedUpdateSmallHash: String = "42de220e99553116a60d6316540774d2e9984419cffe5ac2fc62cf0b41227ac3" 27 | final override val expectedUpdateMediumHash: String = "1379ca33af3ec1032c51eed4c3996c18f90e3121d8ce8ef36323fa159045472f" 28 | } 29 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE256_NS_UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | 20 | @Suppress("ClassName") 21 | open class CSHAKE256_NS_UnitTest: CSHAKE256UnitTest() { 22 | override val digest: Digest = CSHAKE256(N, S) 23 | final override val expectedResetHash: String = "2a46f1df815e8cd2f645df371d97989fa31ff99c80731c1f6ec2d3e48b183193524742eb87c5007edd1549feaaddbff2623cd16f3b5f8506e438d6aad8476107" 24 | final override val expectedMultiBlockHash: String = "613b6da6d25c57f9938d1ba08feb10683be68cfdb22f025a6ec907840071de95ae8cd656aab857ca2f69a429b755fb333e4ce4c2e40672773008cc4bdffd7f42" 25 | final override val expectedUpdateSmallHash: String = "69269d2e388a5b116b70ed4d8ce8eb5f964e8236d25e7e29bbf251f990fc99036ab170a1ba47eeca03581741b420167bc806634af4387753eaac0a77e6fa06e4" 26 | final override val expectedUpdateMediumHash: String = "2d555623df2198f3fd36f5f5a79190eb06b6ce38bfe10cc9f1ff86542a2511babe79fd1b0c0d0b6d9d9941a131a69a4ea90483e7dc592848e03a0703f112d717" 27 | } 28 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE256_N_UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | 20 | @Suppress("ClassName") 21 | open class CSHAKE256_N_UnitTest: CSHAKE256UnitTest() { 22 | override val digest: Digest = CSHAKE256(N, null) 23 | final override val expectedResetHash: String = "bee8b14df0e3c77030458609ed34cea99206ced74a5fe6bf9d3e72852ec7ca5647cef12bcb27dd9cd3fcd604fd7f1daff8ab6091d48e9f5c101d3e99dfc57e17" 24 | final override val expectedMultiBlockHash: String = "b6a2c5010e7f1f21983bc8d3a76c73de56be42dad1372fd5d1f38eef05f6c687a400456f2e6090abe08130864fa9f087af6b8d72a3950af748e2426001dfa949" 25 | final override val expectedUpdateSmallHash: String = "44c2e60abb32ba2fe774bc634bf9dc5fafc86382b90f3181d52a412a6d07ec6da9eddf23b27d232cba7832e8b81c6be65590a3b3c332b41c350629815acc2ee9" 26 | final override val expectedUpdateMediumHash: String = "9d1ad68945f0b9808308cb35bb043e231dfda40b0ca8f3214d43c34b007bc1777ee4517f178db034a60743d317c6316880e608f3362d586184f3babef64c0eee" 27 | } 28 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE256_S_UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | 20 | @Suppress("ClassName") 21 | open class CSHAKE256_S_UnitTest: CSHAKE256UnitTest() { 22 | override val digest: Digest = CSHAKE256(null, S) 23 | final override val expectedResetHash: String = "3d79db7f3aaef4585ef784a9765ded61b069986184806de469e73fd3aaa854aaabd507ed16f87c0cb54e4f3cfbd9da9241476220f47a04eb4da29f514df65627" 24 | final override val expectedMultiBlockHash: String = "bc2cc3604eb61a42c4b3e3ce768230fbb7bf47a5b614ac002d7b035278a7482f3a4964465506682b4b71f2af02b13bb04cc9ac249701e8838e58e29fa7dafe4a" 25 | final override val expectedUpdateSmallHash: String = "bf7058871040867ebe9d2de8714273c4068d85704d959160914c24c4061654ff5f39759cc4af9480bf75b4d7e9e68031159aec1b1ebee2ef0ffc83c7970a9b0a" 26 | final override val expectedUpdateMediumHash: String = "2430b7216231190dc13970c1fb1d8b4d64c6f2e02e6b0392d6a491bebba8668b6d0de4500e949c20d6986f069e52a1cd04a694a00021fa11e42e92d493a16f78" 27 | } 28 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/Keccak224UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import kotlin.test.Test 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.DigestUnitTest 21 | 22 | open class Keccak224UnitTest: DigestUnitTest() { 23 | override val digest: Digest = Keccak224() 24 | final override val expectedResetHash: String = "f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd" 25 | final override val expectedMultiBlockHash: String = "8901f481f220903f5c57bffccc83a87d5175eef176bc57ae8009841c" 26 | final override val expectedUpdateSmallHash: String = "20f33d3e558dc42e091d6181a8cd93be377faec004599ae2789d23d0" 27 | final override val expectedUpdateMediumHash: String = "68cba72dfecc8c2c925ea08f2d41a4567fe79d8e98dd2e583a2524ee" 28 | 29 | @Test 30 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 31 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 32 | } 33 | 34 | @Test 35 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 36 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 37 | } 38 | 39 | @Test 40 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 41 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 42 | } 43 | 44 | @Test 45 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 46 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 47 | } 48 | 49 | @Test 50 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 51 | super.givenDigest_whenCopied_thenIsDifferentInstance() 52 | } 53 | 54 | @Test 55 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 56 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/Keccak256UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import kotlin.test.Test 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.DigestUnitTest 21 | 22 | open class Keccak256UnitTest: DigestUnitTest() { 23 | override val digest: Digest = Keccak256() 24 | final override val expectedResetHash: String = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" 25 | final override val expectedMultiBlockHash: String = "326262bcbb724c678f35e66e01395b18cde0d308807379010617018f0b3e4496" 26 | final override val expectedUpdateSmallHash: String = "8da7db9b1b86176084b942444756fd50f17afd89a16f9df1de1d1a0a8903c583" 27 | final override val expectedUpdateMediumHash: String = "06c89b5c8b7f8e6ad6480b29b50180cbfc92c3c2c9b2954833289e695c9eec0b" 28 | 29 | @Test 30 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 31 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 32 | } 33 | 34 | @Test 35 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 36 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 37 | } 38 | 39 | @Test 40 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 41 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 42 | } 43 | 44 | @Test 45 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 46 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 47 | } 48 | 49 | @Test 50 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 51 | super.givenDigest_whenCopied_thenIsDifferentInstance() 52 | } 53 | 54 | @Test 55 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 56 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/ParallelHash128UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import kotlin.test.Test 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.DigestUnitTest 21 | 22 | open class ParallelHash128UnitTest: DigestUnitTest() { 23 | protected val B = 100 24 | override val digest: Digest = ParallelHash128(null, B) 25 | final override val expectedResetHash: String = "4860c15ced13a8e56e95a6c7ea14e55be8ad8db61373f1b2372687dfd3c9c38f" 26 | final override val expectedMultiBlockHash: String = "8608090cc85438b6d29346d608815d87c2bf77073f001eab06bb6f8ecce16983" 27 | final override val expectedUpdateSmallHash: String = "f931e465e69bb9895cf655eb5227a55f8775eb0ca3b04edc7c9edfb577552f56" 28 | final override val expectedUpdateMediumHash: String = "57d11d6d370bd6ca17ad773f590e82d06cb2f4feb36dda629263ce723ac5d97e" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/SHA3_224UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import kotlin.test.Test 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.DigestUnitTest 21 | 22 | @Suppress("ClassName") 23 | open class SHA3_224UnitTest: DigestUnitTest() { 24 | override val digest: Digest = SHA3_224() 25 | final override val expectedResetHash: String = "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7" 26 | final override val expectedMultiBlockHash: String = "c877c6e2817b2602be1ae07f10a045e1030d0078f6c954f69f112e20" 27 | final override val expectedUpdateSmallHash: String = "d167147af05bbf46f5c730dc69fad8ed64e2afa900b8e4ebde4d8e00" 28 | final override val expectedUpdateMediumHash: String = "ac05fe6c9eedb6c000204443aeb3c2c99d38d20b4bd97c315d814202" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/SHA3_256UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import kotlin.test.Test 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.DigestUnitTest 21 | 22 | @Suppress("ClassName") 23 | open class SHA3_256UnitTest: DigestUnitTest() { 24 | override val digest: Digest = SHA3_256() 25 | final override val expectedResetHash: String = "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a" 26 | final override val expectedMultiBlockHash: String = "28b4fcc975d3c40f259b34fe2f362b83358e0b7679e81f31444183b58a561005" 27 | final override val expectedUpdateSmallHash: String = "b41380a98cec55fee0785b76c6dbe5500a6f7b9d4ede7de182acb5d0dc1e7e59" 28 | final override val expectedUpdateMediumHash: String = "aecf3132dd50201f8ea6959ebed69cff09ae5cb2e1fed97bb7cd4ff8ae4e73eb" 29 | 30 | @Test 31 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 32 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 33 | } 34 | 35 | @Test 36 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 37 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 38 | } 39 | 40 | @Test 41 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 42 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 43 | } 44 | 45 | @Test 46 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 47 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 48 | } 49 | 50 | @Test 51 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 52 | super.givenDigest_whenCopied_thenIsDifferentInstance() 53 | } 54 | 55 | @Test 56 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 57 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/SHAKE128UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import kotlin.test.Test 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.DigestUnitTest 21 | 22 | open class SHAKE128UnitTest: DigestUnitTest() { 23 | override val digest: Digest = SHAKE128() 24 | final override val expectedResetHash: String = "7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26" 25 | final override val expectedMultiBlockHash: String = "fb77bf6b8c431a775e3780d3dda611c948c5d3d6306143ca2089c2749de7c2e2" 26 | final override val expectedUpdateSmallHash: String = "0b33a664b281d9a38638832fd314444c2fa5865072e61505d0776c5cdd322ca3" 27 | final override val expectedUpdateMediumHash: String = "9bf64f28a64f294769abd18b8903820453c9f31fe1bf620f95dede8f0b5d9f56" 28 | 29 | @Test 30 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 31 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 32 | } 33 | 34 | @Test 35 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 36 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 37 | } 38 | 39 | @Test 40 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 41 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 42 | } 43 | 44 | @Test 45 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 46 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 47 | } 48 | 49 | @Test 50 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 51 | super.givenDigest_whenCopied_thenIsDifferentInstance() 52 | } 53 | 54 | @Test 55 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 56 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/SHAKEDigestUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import kotlin.test.Test 19 | import kotlin.test.assertEquals 20 | 21 | class SHAKEDigestUnitTest { 22 | 23 | @Test 24 | fun givenSHAKEDigest_whenLengthNonDefault_thenReturnsExpectedByteSize() { 25 | // This exercises ALL inheritors of SHAKEDigest and how they will 26 | // function with a non-default outputLength argument (i.e. digestLength) 27 | SHAKE128(outputLength = 0).let { digest -> 28 | assertEquals(0, digest.digestLength()) 29 | assertEquals(0, digest.digest().size) 30 | } 31 | 32 | SHAKE256(outputLength = 500).let { digest -> 33 | assertEquals(500, digest.digestLength()) 34 | assertEquals(500, digest.digest().size) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /library/sha3/src/commonTest/kotlin/org/kotlincrypto/hash/sha3/TupleHash128UnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import kotlin.test.Test 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.DigestUnitTest 21 | 22 | open class TupleHash128UnitTest: DigestUnitTest() { 23 | override val digest: Digest = TupleHash128(null) 24 | final override val expectedResetHash: String = "786aa3d4fcaadf0aa723a4818a1a72de2330d613e5de7ae4eb6cb4cdd26adba2" 25 | final override val expectedMultiBlockHash: String = "26f53178710b7fdb63c91a22b066669cb0907017461a162c90e18bcad003f632" 26 | final override val expectedUpdateSmallHash: String = "a3e4e5f23ff4cb7587a83fe386f37cf3e9f80b0ba5d74de9e72815079b13d660" 27 | final override val expectedUpdateMediumHash: String = "98be957009fca08674e795afd8660a3d46a1a9899f1539ef0b9d5e1acc73c0bf" 28 | 29 | @Test 30 | final override fun givenDigest_whenReset_thenDigestDigestReturnsExpected() { 31 | super.givenDigest_whenReset_thenDigestDigestReturnsExpected() 32 | } 33 | 34 | @Test 35 | final override fun givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() { 36 | super.givenDigest_whenMultiBlockDigest_thenDigestDigestReturnsExpected() 37 | } 38 | 39 | @Test 40 | final override fun givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() { 41 | super.givenDigest_whenUpdatedSmall_thenDigestDigestReturnsExpected() 42 | } 43 | 44 | @Test 45 | final override fun givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() { 46 | super.givenDigest_whenUpdatedMedium_thenDigestDigestReturnsExpected() 47 | } 48 | 49 | @Test 50 | final override fun givenDigest_whenCopied_thenIsDifferentInstance() { 51 | super.givenDigest_whenCopied_thenIsDifferentInstance() 52 | } 53 | 54 | @Test 55 | final override fun givenDigest_whenDigested_thenLengthMatchesOutput() { 56 | super.givenDigest_whenDigested_thenLengthMatchesOutput() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/sha3/src/jvmMain/java9/module-info.java: -------------------------------------------------------------------------------- 1 | @SuppressWarnings("module") 2 | module org.kotlincrypto.hash.sha3 { 3 | requires kotlin.stdlib; 4 | requires transitive org.kotlincrypto.core.digest; 5 | requires transitive org.kotlincrypto.core.xof; 6 | requires org.kotlincrypto.bitops.endian; 7 | requires org.kotlincrypto.sponges.keccak; 8 | 9 | exports org.kotlincrypto.hash.sha3; 10 | } 11 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE128JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.CSHAKEDigest 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | class CSHAKE128JvmUnitTest: CSHAKE128UnitTest() { 23 | override val digest: Digest = TestBCDigest(CSHAKEDigest(128, null, null), copy = { CSHAKEDigest(this) }) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE128XofJvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.CSHAKEDigest 19 | import org.kotlincrypto.core.Updatable 20 | 21 | class CSHAKE128XofJvmUnitTest: CSHAKE128XofUnitTest() { 22 | private val digest = CSHAKEDigest(128, N, null) 23 | override val xof: Updatable = object : Updatable { 24 | override fun update(input: Byte) { digest.update(input) } 25 | override fun update(input: ByteArray) { digest.update(input, 0, input.size) } 26 | override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } 27 | } 28 | 29 | override fun read(vararg args: ByteArray) { 30 | args.forEach { 31 | digest.doOutput(it, 0, it.size) 32 | } 33 | } 34 | 35 | override fun partialRead(out: ByteArray, offset: Int, len: Int) { 36 | digest.doOutput(out, offset, len) 37 | } 38 | 39 | override fun reset() { 40 | digest.reset() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE128_NS_JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.bouncycastle.crypto.digests.CSHAKEDigest 21 | import org.kotlincrypto.core.digest.Digest 22 | import org.kotlincrypto.hash.TestBCDigest 23 | 24 | class CSHAKE128_NS_JvmUnitTest: CSHAKE128_NS_UnitTest() { 25 | override val digest: Digest = TestBCDigest(CSHAKEDigest(128, N, S), copy = { CSHAKEDigest(this) }) 26 | } 27 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE128_N_JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.bouncycastle.crypto.digests.CSHAKEDigest 21 | import org.kotlincrypto.core.digest.Digest 22 | import org.kotlincrypto.hash.TestBCDigest 23 | 24 | class CSHAKE128_N_JvmUnitTest: CSHAKE128_N_UnitTest() { 25 | override val digest: Digest = TestBCDigest(CSHAKEDigest(128, N, null), copy = { CSHAKEDigest(this) }) 26 | } 27 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE128_S_JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.bouncycastle.crypto.digests.CSHAKEDigest 21 | import org.kotlincrypto.core.digest.Digest 22 | import org.kotlincrypto.hash.TestBCDigest 23 | 24 | class CSHAKE128_S_JvmUnitTest: CSHAKE128_S_UnitTest() { 25 | override val digest: Digest = TestBCDigest(CSHAKEDigest(128, null, S), copy = { CSHAKEDigest(this) }) 26 | } 27 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.CSHAKEDigest 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | class CSHAKE256JvmUnitTest: CSHAKE256UnitTest() { 23 | override val digest: Digest = TestBCDigest(CSHAKEDigest(256, null, null), copy = { CSHAKEDigest(this) }) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE256XofJvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.CSHAKEDigest 19 | import org.kotlincrypto.core.Updatable 20 | 21 | class CSHAKE256XofJvmUnitTest: CSHAKE256XofUnitTest() { 22 | private val digest = CSHAKEDigest(256, N, null) 23 | override val xof: Updatable = object : Updatable { 24 | override fun update(input: Byte) { digest.update(input) } 25 | override fun update(input: ByteArray) { digest.update(input, 0, input.size) } 26 | override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } 27 | } 28 | 29 | override fun read(vararg args: ByteArray) { 30 | args.forEach { 31 | digest.doOutput(it, 0, it.size) 32 | } 33 | } 34 | 35 | override fun partialRead(out: ByteArray, offset: Int, len: Int) { 36 | digest.doOutput(out, offset, len) 37 | } 38 | 39 | override fun reset() { 40 | digest.reset() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE256_NS_JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.bouncycastle.crypto.digests.CSHAKEDigest 21 | import org.kotlincrypto.core.digest.Digest 22 | import org.kotlincrypto.hash.TestBCDigest 23 | 24 | class CSHAKE256_NS_JvmUnitTest: CSHAKE256_NS_UnitTest() { 25 | override val digest: Digest = TestBCDigest(CSHAKEDigest(256, N, S), copy = { CSHAKEDigest(this) }) 26 | } 27 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE256_N_JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.bouncycastle.crypto.digests.CSHAKEDigest 21 | import org.kotlincrypto.core.digest.Digest 22 | import org.kotlincrypto.hash.TestBCDigest 23 | 24 | class CSHAKE256_N_JvmUnitTest: CSHAKE256_N_UnitTest() { 25 | override val digest: Digest = TestBCDigest(CSHAKEDigest(256, N, null), copy = { CSHAKEDigest(this) }) 26 | } 27 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/CSHAKE256_S_JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | @file:Suppress("ClassName") 17 | 18 | package org.kotlincrypto.hash.sha3 19 | 20 | import org.bouncycastle.crypto.digests.CSHAKEDigest 21 | import org.kotlincrypto.core.digest.Digest 22 | import org.kotlincrypto.hash.TestBCDigest 23 | 24 | class CSHAKE256_S_JvmUnitTest: CSHAKE256_S_UnitTest() { 25 | override val digest: Digest = TestBCDigest(CSHAKEDigest(256, null, S), copy = { CSHAKEDigest(this) }) 26 | } 27 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/Keccak224JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class Keccak224JvmUnitTest: Keccak224UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/Keccak256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class Keccak256JvmUnitTest: Keccak256UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/Keccak384JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class Keccak384JvmUnitTest: Keccak384UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/Keccak512JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class Keccak512JvmUnitTest: Keccak512UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/ParallelHash128JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.ParallelHash 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | class ParallelHash128JvmUnitTest: ParallelHash128UnitTest() { 23 | override val digest: Digest = TestBCDigest(ParallelHash(128, null, B), copy = { ParallelHash(this) }) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/ParallelHash128XofJvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.ParallelHash 19 | import org.kotlincrypto.core.Updatable 20 | 21 | class ParallelHash128XofJvmUnitTest: ParallelHash128XofUnitTest() { 22 | private val digest = ParallelHash(128, null, B) 23 | override val xof: Updatable = object : Updatable { 24 | override fun update(input: Byte) { digest.update(input) } 25 | override fun update(input: ByteArray) { digest.update(input, 0, input.size) } 26 | override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } 27 | } 28 | 29 | override fun read(vararg args: ByteArray) { 30 | args.forEach { 31 | digest.doOutput(it, 0, it.size) 32 | } 33 | } 34 | 35 | override fun partialRead(out: ByteArray, offset: Int, len: Int) { 36 | digest.doOutput(out, offset, len) 37 | } 38 | 39 | override fun reset() { 40 | digest.reset() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/ParallelHash256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.ParallelHash 19 | import org.kotlincrypto.core.digest.Digest 20 | import org.kotlincrypto.hash.TestBCDigest 21 | 22 | class ParallelHash256JvmUnitTest: ParallelHash256UnitTest() { 23 | override val digest: Digest = TestBCDigest(ParallelHash(256, null, B), copy = { ParallelHash(this) }) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/ParallelHash256XofJvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.ParallelHash 19 | import org.kotlincrypto.core.Updatable 20 | 21 | class ParallelHash256XofJvmUnitTest: ParallelHash256XofUnitTest() { 22 | private val digest = ParallelHash(256, null, B) 23 | override val xof: Updatable = object : Updatable { 24 | override fun update(input: Byte) { digest.update(input) } 25 | override fun update(input: ByteArray) { digest.update(input, 0, input.size) } 26 | override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } 27 | } 28 | 29 | override fun read(vararg args: ByteArray) { 30 | args.forEach { 31 | digest.doOutput(it, 0, it.size) 32 | } 33 | } 34 | 35 | override fun partialRead(out: ByteArray, offset: Int, len: Int) { 36 | digest.doOutput(out, offset, len) 37 | } 38 | 39 | override fun reset() { 40 | digest.reset() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/SHA3_224JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class SHA3_224JvmUnitTest: SHA3_224UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/SHA3_256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class SHA3_256JvmUnitTest: SHA3_256UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/SHA3_384JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class SHA3_384JvmUnitTest: SHA3_384UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/SHA3_512JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | @Suppress("ClassName") 22 | class SHA3_512JvmUnitTest: SHA3_512UnitTest() { 23 | override val digest: Digest = TestJvmDigest(super.digest) 24 | } 25 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/SHAKE128JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class SHAKE128JvmUnitTest: SHAKE128UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/SHAKE128XofJvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.SHAKEDigest 19 | import org.kotlincrypto.core.Updatable 20 | 21 | class SHAKE128XofJvmUnitTest: SHAKE128XofUnitTest() { 22 | private val digest = SHAKEDigest(128) 23 | override val xof: Updatable = object : Updatable { 24 | override fun update(input: Byte) { digest.update(input) } 25 | override fun update(input: ByteArray) { digest.update(input, 0, input.size) } 26 | override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } 27 | } 28 | 29 | override fun read(vararg args: ByteArray) { 30 | args.forEach { 31 | digest.doOutput(it, 0, it.size) 32 | } 33 | } 34 | 35 | override fun partialRead(out: ByteArray, offset: Int, len: Int) { 36 | digest.doOutput(out, offset, len) 37 | } 38 | 39 | override fun reset() { 40 | digest.reset() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/SHAKE256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class SHAKE256JvmUnitTest: SHAKE256UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/SHAKE256XofJvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.SHAKEDigest 19 | import org.kotlincrypto.core.Updatable 20 | 21 | class SHAKE256XofJvmUnitTest: SHAKE256XofUnitTest() { 22 | private val digest = SHAKEDigest(256) 23 | override val xof: Updatable = object : Updatable { 24 | override fun update(input: Byte) { digest.update(input) } 25 | override fun update(input: ByteArray) { digest.update(input, 0, input.size) } 26 | override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } 27 | } 28 | 29 | override fun read(vararg args: ByteArray) { 30 | args.forEach { 31 | digest.doOutput(it, 0, it.size) 32 | } 33 | } 34 | 35 | override fun partialRead(out: ByteArray, offset: Int, len: Int) { 36 | digest.doOutput(out, offset, len) 37 | } 38 | 39 | override fun reset() { 40 | digest.reset() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/TupleHash128JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class TupleHash128JvmUnitTest: TupleHash128UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/TupleHash128XofJvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.TupleHash 19 | import org.kotlincrypto.core.Updatable 20 | 21 | class TupleHash128XofJvmUnitTest: TupleHash128XofUnitTest() { 22 | private val digest = TupleHash(128, null) 23 | override val xof: Updatable = object : Updatable { 24 | override fun update(input: Byte) { digest.update(input) } 25 | override fun update(input: ByteArray) { digest.update(input, 0, input.size) } 26 | override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } 27 | } 28 | 29 | override fun read(vararg args: ByteArray) { 30 | args.forEach { 31 | digest.doOutput(it, 0, it.size) 32 | } 33 | } 34 | 35 | override fun partialRead(out: ByteArray, offset: Int, len: Int) { 36 | digest.doOutput(out, offset, len) 37 | } 38 | 39 | override fun reset() { 40 | digest.reset() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/TupleHash256JvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import org.kotlincrypto.hash.TestJvmDigest 20 | 21 | class TupleHash256JvmUnitTest: TupleHash256UnitTest() { 22 | override val digest: Digest = TestJvmDigest(super.digest) 23 | } 24 | -------------------------------------------------------------------------------- /library/sha3/src/jvmTest/kotlin/org/kotlincrypto/hash/sha3/TupleHash256XofJvmUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash.sha3 17 | 18 | import org.bouncycastle.crypto.digests.TupleHash 19 | import org.kotlincrypto.core.Updatable 20 | 21 | class TupleHash256XofJvmUnitTest: TupleHash256XofUnitTest() { 22 | private val digest = TupleHash(256, null) 23 | override val xof: Updatable = object : Updatable { 24 | override fun update(input: Byte) { digest.update(input) } 25 | override fun update(input: ByteArray) { digest.update(input, 0, input.size) } 26 | override fun update(input: ByteArray, offset: Int, len: Int) { digest.update(input, offset, len) } 27 | } 28 | 29 | override fun read(vararg args: ByteArray) { 30 | args.forEach { 31 | digest.doOutput(it, 0, it.size) 32 | } 33 | } 34 | 35 | override fun partialRead(out: ByteArray, offset: Int, len: Int) { 36 | digest.doOutput(out, offset, len) 37 | } 38 | 39 | override fun reset() { 40 | digest.reset() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "hash" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenCentral() 6 | gradlePluginPortal() 7 | google() 8 | } 9 | } 10 | 11 | includeBuild("build-logic") 12 | 13 | @Suppress("PrivatePropertyName") 14 | private val CHECK_PUBLICATION: String? by settings 15 | 16 | if (CHECK_PUBLICATION != null) { 17 | include(":tools:check-publication") 18 | } else { 19 | listOf( 20 | "blake2", 21 | "md", 22 | "sha1", 23 | "sha2", 24 | "sha3", 25 | ).forEach { name -> 26 | include(":library:$name") 27 | } 28 | 29 | include(":benchmarks") 30 | include(":bom") 31 | include(":tools:testing") 32 | include(":test-android") 33 | } 34 | -------------------------------------------------------------------------------- /test-android/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /test-android/api/test-android.api: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KotlinCrypto/hash/50bed91ab958249be81c4c60124d7aea4e02d16f/test-android/api/test-android.api -------------------------------------------------------------------------------- /test-android/api/test-android.klib.api: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KotlinCrypto/hash/50bed91ab958249be81c4c60124d7aea4e02d16f/test-android/api/test-android.klib.api -------------------------------------------------------------------------------- /test-android/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("configuration") 18 | } 19 | 20 | repositories { google() } 21 | 22 | kmpConfiguration { 23 | configure { 24 | androidLibrary { 25 | kotlinJvmTarget = JavaVersion.VERSION_11 26 | compileSourceCompatibility = JavaVersion.VERSION_11 27 | compileTargetCompatibility = JavaVersion.VERSION_11 28 | 29 | android { 30 | namespace = "org.kotlincrypto.hash" 31 | compileSdk = 34 32 | 33 | defaultConfig { 34 | minSdk = 14 35 | 36 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 37 | } 38 | } 39 | 40 | sourceSetTestInstrumented { 41 | kotlin.srcDir("src/androidInstrumentedTest/blake2") 42 | kotlin.srcDir("src/androidInstrumentedTest/md") 43 | kotlin.srcDir("src/androidInstrumentedTest/sha1") 44 | kotlin.srcDir("src/androidInstrumentedTest/sha2") 45 | kotlin.srcDir("src/androidInstrumentedTest/sha3") 46 | 47 | dependencies { 48 | implementation(libs.androidx.test.runner) 49 | implementation(kotlin("test")) 50 | 51 | implementation(project(":library:blake2")) 52 | implementation(project(":library:md")) 53 | implementation(project(":library:sha1")) 54 | implementation(project(":library:sha2")) 55 | implementation(project(":library:sha3")) 56 | implementation(project(":tools:testing")) 57 | } 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test-android/src/androidInstrumentedTest/blake2: -------------------------------------------------------------------------------- 1 | ../../../library/blake2/src/commonTest/kotlin -------------------------------------------------------------------------------- /test-android/src/androidInstrumentedTest/md: -------------------------------------------------------------------------------- 1 | ../../../library/md/src/commonTest/kotlin -------------------------------------------------------------------------------- /test-android/src/androidInstrumentedTest/sha1: -------------------------------------------------------------------------------- 1 | ../../../library/sha1/src/commonTest/kotlin -------------------------------------------------------------------------------- /test-android/src/androidInstrumentedTest/sha2: -------------------------------------------------------------------------------- 1 | ../../../library/sha2/src/commonTest/kotlin -------------------------------------------------------------------------------- /test-android/src/androidInstrumentedTest/sha3: -------------------------------------------------------------------------------- 1 | ../../../library/sha3/src/commonTest/kotlin -------------------------------------------------------------------------------- /test-android/src/androidMain/kotlin/org/kotlincrypto/hash/Stub.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash 17 | 18 | internal fun stub() { /* no-op */ } 19 | -------------------------------------------------------------------------------- /tools/check-publication/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /tools/check-publication/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("configuration") 18 | } 19 | 20 | repositories { 21 | val host = "https://s01.oss.sonatype.org" 22 | 23 | if (version.toString().endsWith("-SNAPSHOT")) { 24 | maven("$host/content/repositories/snapshots/") 25 | } else { 26 | maven("$host/content/groups/staging") { 27 | val p = rootProject.properties 28 | 29 | credentials { 30 | username = p["mavenCentralUsername"]?.toString() 31 | password = p["mavenCentralPassword"]?.toString() 32 | } 33 | } 34 | } 35 | } 36 | 37 | kmpConfiguration { 38 | configureShared { 39 | common { 40 | sourceSetMain { 41 | dependencies { 42 | implementation(platform("$group:bom:$version")) 43 | implementation("$group:blake2") 44 | implementation("$group:md") 45 | implementation("$group:sha1") 46 | implementation("$group:sha2") 47 | implementation("$group:sha3") 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tools/check-publication/src/commonMain/kotlin/tools/check/publication/Stub.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package tools.check.publication 17 | 18 | internal fun stub() { /* no-op */ } 19 | -------------------------------------------------------------------------------- /tools/testing/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /tools/testing/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | plugins { 17 | id("configuration") 18 | } 19 | 20 | kmpConfiguration { 21 | configureShared { 22 | jvm { 23 | sourceSetMain { 24 | dependencies { 25 | api(libs.bouncy.castle) 26 | } 27 | } 28 | } 29 | 30 | common { 31 | sourceSetMain { 32 | dependencies { 33 | implementation(kotlin("test")) 34 | implementation(libs.kotlincrypto.core.digest) 35 | implementation(libs.encoding.base16) 36 | implementation(libs.encoding.base64) 37 | } 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tools/testing/src/commonMain/kotlin/org/kotlincrypto/hash/HashUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash 17 | 18 | import org.kotlincrypto.core.Updatable 19 | import kotlin.test.assertEquals 20 | 21 | sealed class HashUnitTest { 22 | abstract val expectedResetHash: String 23 | abstract val expectedUpdateSmallHash: String 24 | abstract val expectedUpdateMediumHash: String 25 | 26 | internal val assertExpectedHashes by lazy { 27 | val expected = 4 28 | val set = mutableSetOf( 29 | expectedResetHash, 30 | expectedUpdateSmallHash, 31 | expectedUpdateMediumHash, 32 | ) 33 | 34 | when (this) { 35 | is DigestUnitTest -> expectedMultiBlockHash 36 | is XofUnitTest -> expectedPartialReadHash 37 | }.let { set.add(it) } 38 | 39 | assertEquals(expected, set.size, "Expected hash values must all be different") 40 | } 41 | 42 | companion object { 43 | fun updateSmall(updatable: Updatable) { 44 | updatable.update(TestData.BYTES_SMALL) 45 | } 46 | 47 | fun updateMedium(updatable: Updatable) { 48 | // Some algorithms don't discard 0 length input, effecting 49 | // the end result (e.g. TupleHash). This ensures that, if 50 | // that's the case, it is exercised in testing. 51 | updatable.update(TestData.BYTES_EMPTY) 52 | updatable.update(TestData.BYTES_EMPTY, 0, TestData.BYTES_EMPTY.size) 53 | 54 | updatable.update(TestData.BYTES_MEDIUM[0]) 55 | updatable.update(TestData.BYTES_MEDIUM) 56 | updatable.update(TestData.BYTES_MEDIUM, 100, 1_000) 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tools/testing/src/jvmMain/kotlin/org/kotlincrypto/hash/TestBCDigest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 KotlinCrypto 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | package org.kotlincrypto.hash 17 | 18 | import org.kotlincrypto.core.digest.Digest 19 | import java.lang.IllegalStateException 20 | 21 | class TestBCDigest: Digest { 22 | 23 | private val delegate: T 24 | private val copy: T.() -> T 25 | 26 | constructor( 27 | digest: T, 28 | copy: T.() -> T 29 | ): super( 30 | digest.algorithmName, 31 | digest.byteLength, 32 | digest.digestSize 33 | ) { 34 | this.delegate = digest 35 | this.copy = copy 36 | } 37 | 38 | @Suppress("UNCHECKED_CAST") 39 | private constructor(other: TestBCDigest<*>): super(other) { 40 | this.copy = other.copy as T.() -> T 41 | this.delegate = other.copy.invoke(other.delegate as T) 42 | } 43 | 44 | override fun copy(): Digest = TestBCDigest(this) 45 | 46 | override fun compressProtected(input: ByteArray, offset: Int) { throw IllegalStateException("update is overridden...") } 47 | 48 | override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray { 49 | val out = ByteArray(digestLength()) 50 | delegate.doFinal(out, 0) 51 | return out 52 | } 53 | 54 | override fun updateProtected(input: Byte) { delegate.update(input) } 55 | override fun updateProtected(input: ByteArray, offset: Int, len: Int) { delegate.update(input, offset, len) } 56 | 57 | override fun resetProtected() { delegate.reset() } 58 | } 59 | --------------------------------------------------------------------------------