Skip to content

Commit

Permalink
Add dokka documentation at https://macs.kotlincrypto.org` (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm authored Feb 5, 2025
1 parent 15e36f3 commit bc680c8
Show file tree
Hide file tree
Showing 21 changed files with 339 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ build/
.idea/
local.properties
.kotlin/

gh-pages/*
!gh-pages/publish.sh
101 changes: 11 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,97 +24,19 @@

Message Authentication Code algorithms for Kotlin Multiplatform

### Usage
### Modules

See [HERE][url-core-usage] for basic usage example for `Mac`.
- [hmac](library/hmac/hmac/README.md)
- [hmac-md](library/hmac/hmac-md/README.md)
- [hmac-sha1](library/hmac/hmac-sha1/README.md)
- [hmac-sha2](library/hmac/hmac-sha2/README.md)
- [hmac-sha3](library/hmac/hmac-sha3/README.md)
- [blake2](library/blake2/README.md)
- [kmac](library/kmac/README.md)

```kotlin
// Using SecureRandom from the secure-random repo as an example
import org.kotlincrypto.SecureRandom
// ...

fun main() {
val key = SecureRandom().nextBytesOf(100)

// Hmacs that may be needed for backward compatibility but
// should no longer be utilized because they have been broken.
HmacMD5(key)
HmacSHA1(key)

key.fill(0)
}
```

`SHA2 Hmac`

```kotlin
fun main() {
val key = SecureRandom().nextBytesOf(100)

HmacSHA224(key)
HmacSHA256(key)
HmacSha384(key)
HmacSHA512(key)

HmacSHA512t(key, 224) // HmacSHA512/224
HmacSHA512t(key, 256) // HmacSHA512/256

key.fill(0)
}
```

`SHA3 Hmac`

```kotlin
fun main() {
val key = SecureRandom().nextBytesOf(100)

HmacKeccak224(key)
HmacKeccak256(key)
HmacKeccak384(key)
HmacKeccak512(key)
HmacSHA3_224(key)
HmacSHA3_256(key)
HmacSHA3_384(key)
HmacSHA3_512(key)

key.fill(0)
}
```

`SHA3 KMAC & XOFs` (i.e. [Extendable-Output Functions][url-pub-xof])

See [HERE][url-core-usage] for details on what `XOFs` are, and a basic usage example for `Xof`.
### API Docs

```kotlin
fun main() {
val key = SecureRandom().nextBytesOf(100)

val S = "My Customization".encodeToByteArray()

// Macs
KMAC128(key)
KMAC256(key, S, outputLength = 123) // returns 123 bytes instead of the default when doFinal() is invoked

// Xofs
KMAC128.xOf(key, S)
KMAC256.xOf(key)

key.fill(0)
}
````

`BLAKE2 Macs`

```kotlin
fun main() {
val key64 = SecureRandom().nextBytesOf(64)
val key32 = SecureRandom().nextBytesOf(32)

BLAKE2b(key64, 512)
BLAKE2s(key32, 256)
}
```
- [https://macs.kotlincrypto.org][url-docs]

### Get Started

Expand Down Expand Up @@ -185,7 +107,6 @@ dependencies {
[url-license]: https://www.apache.org/licenses/LICENSE-2.0.txt
[url-kotlin]: https://kotlinlang.org
[url-core]: https://github.com/KotlinCrypto/core
[url-core-usage]: https://github.com/KotlinCrypto/core#usage
[url-hash]: https://github.com/KotlinCrypto/hash
[url-pub-xof]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf
[url-version-catalog]: https://github.com/KotlinCrypto/version-catalog
[url-docs]: https://macs.kotlincrypto.org
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
}

dependencies {
implementation(libs.gradle.dokka)
implementation(libs.gradle.kmp.configuration)
implementation(libs.gradle.kotlin)
implementation(libs.gradle.publish.maven)
Expand Down
9 changes: 4 additions & 5 deletions build-logic/src/main/kotlin/-KmpConfigurationExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ fun KmpConfigurationExtension.configureShared(
publish: Boolean = false,
action: Action<KmpConfigurationContainerDsl>
) {
// TODO: Enable once module :library:hmac:hmac-md5 is removed
// if (publish) {
// require(!java9ModuleName.isNullOrBlank()) { "publications must specify a module-info name" }
// }
if (publish) {
require(!java9ModuleName.isNullOrBlank()) { "publications must specify a module-info name" }
}

configure {
options {
Expand Down Expand Up @@ -76,7 +75,7 @@ fun KmpConfigurationExtension.configureShared(
mingwAll()

common {
if (publish) pluginIds("publication")
if (publish) pluginIds("publication", "dokka")

sourceSetTest {
dependencies {
Expand Down
48 changes: 48 additions & 0 deletions build-logic/src/main/kotlin/dokka.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2025 Matthew Nelson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
import org.jetbrains.dokka.DokkaConfiguration.Visibility
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import java.net.URI

plugins {
id("org.jetbrains.dokka")
}

tasks.withType<DokkaTaskPartial>().configureEach {
suppressInheritedMembers = true

dokkaSourceSets.configureEach {
includes.from("README.md")
noStdlibLink = true

externalDocumentationLink {
url = URI("https://core.kotlincrypto.org/").toURL()
}
externalDocumentationLink {
url = URI("https://hash.kotlincrypto.org/").toURL()
}

sourceLink {
localDirectory = rootDir
remoteUrl = URI("https://github.com/KotlinCrypto/MACs/tree/master").toURL()
remoteLineSuffix = "#L"
}

documentedVisibilities.set(setOf(
Visibility.PUBLIC,
))
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
alias(libs.plugins.android.library) apply(false)
alias(libs.plugins.benchmark) apply(false)
alias(libs.plugins.binary.compat)
alias(libs.plugins.dokka)
alias(libs.plugins.kotlin.multiplatform) apply(false)
}

Expand Down
37 changes: 37 additions & 0 deletions gh-pages/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Copyright (c) 2025 Matthew Nelson
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e

readonly DIR_SCRIPT="$( cd "$( dirname "$0" )" >/dev/null && pwd )"
readonly REPO_NAME="MACs"

trap 'rm -rf "$DIR_SCRIPT/$REPO_NAME"' EXIT

cd "$DIR_SCRIPT"
git clone -b gh-pages --single-branch https://github.com/KotlinCrypto/$REPO_NAME.git
rm -rf "$DIR_SCRIPT/$REPO_NAME/"*
echo "$REPO_NAME.kotlincrypto.org" > "$DIR_SCRIPT/$REPO_NAME/CNAME"

cd ..
./gradlew clean -DKMP_TARGETS_ALL
./gradlew dokkaHtmlMultiModule --no-build-cache -DKMP_TARGETS_ALL
cp -aR build/dokka/htmlMultiModule/* gh-pages/$REPO_NAME

cd "$DIR_SCRIPT/$REPO_NAME"
sed -i "s|module:|module:library/|g" "package-list"

git add --all
git commit -S --message "Update dokka docs"
git push
75 changes: 39 additions & 36 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
[versions]
androidx-test-runner = "1.5.2"
androidx-test-runner = "1.5.2"

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

encoding = "2.3.1"
encoding = "2.3.1"

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

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

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

kotlincrypto-core-digest = { module = "org.kotlincrypto.core:digest", version.ref = "kotlincrypto-core" }
kotlincrypto-core-mac = { module = "org.kotlincrypto.core:mac", version.ref = "kotlincrypto-core" }
kotlincrypto-core-xof = { module = "org.kotlincrypto.core:xof", version.ref = "kotlincrypto-core" }
kotlincrypto-hash-blake2 = { module = "org.kotlincrypto.hash:blake2", version.ref = "kotlincrypto-hash" }
kotlincrypto-hash-md = { module = "org.kotlincrypto.hash:md", version.ref = "kotlincrypto-hash" }
kotlincrypto-hash-sha1 = { module = "org.kotlincrypto.hash:sha1", version.ref = "kotlincrypto-hash" }
kotlincrypto-hash-sha2 = { module = "org.kotlincrypto.hash:sha2", version.ref = "kotlincrypto-hash" }
kotlincrypto-hash-sha3 = { module = "org.kotlincrypto.hash:sha3", version.ref = "kotlincrypto-hash" }
gradle-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "gradle-dokka" }
gradle-kmp-configuration = { module = "io.matthewnelson:gradle-kmp-configuration-plugin", version.ref = "gradle-kmp-configuration" }
gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "gradle-kotlin" }
gradle-publish-maven = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradle-publish-maven" }

kotlincrypto-core-digest = { module = "org.kotlincrypto.core:digest", version.ref = "kotlincrypto-core" }
kotlincrypto-core-mac = { module = "org.kotlincrypto.core:mac", version.ref = "kotlincrypto-core" }
kotlincrypto-core-xof = { module = "org.kotlincrypto.core:xof", version.ref = "kotlincrypto-core" }
kotlincrypto-hash-blake2 = { module = "org.kotlincrypto.hash:blake2", version.ref = "kotlincrypto-hash" }
kotlincrypto-hash-md = { module = "org.kotlincrypto.hash:md", version.ref = "kotlincrypto-hash" }
kotlincrypto-hash-sha1 = { module = "org.kotlincrypto.hash:sha1", version.ref = "kotlincrypto-hash" }
kotlincrypto-hash-sha2 = { module = "org.kotlincrypto.hash:sha2", version.ref = "kotlincrypto-hash" }
kotlincrypto-hash-sha3 = { module = "org.kotlincrypto.hash:sha3", version.ref = "kotlincrypto-hash" }

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

[plugins]
android-library = { id = "com.android.library", version.ref = "gradle-android" }
benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "gradle-benchmark" }
binary-compat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "gradle-binary-compat" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "gradle-kotlin" }
android-library = { id = "com.android.library", version.ref = "gradle-android" }
benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "gradle-benchmark" }
binary-compat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "gradle-binary-compat" }
dokka = { id = "org.jetbrains.dokka", version.ref = "gradle-dokka" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "gradle-kotlin" }
25 changes: 25 additions & 0 deletions library/blake2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Module blake2

`Mac` implementations for BLAKE2 Keyed Hashing

Implementations for:
- BLAKE2b
- BLAKE2s

See [HERE][url-mac-usage] for basic usage example of `Mac`.

```kotlin
// Using SecureRandom from the secure-random repo as an example
import org.kotlincrypto.SecureRandom
// ...

fun main() {
val key64 = SecureRandom().nextBytesOf(64)
val key32 = SecureRandom().nextBytesOf(32)

BLAKE2b(key64, 512)
BLAKE2s(key32, 256)
}
```

[url-mac-usage]: https://core.kotlincrypto.org/library/mac/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import org.kotlincrypto.core.mac.Mac
import org.kotlincrypto.hash.blake2.BLAKE2Digest

/**
* Core abstraction for BLAKE2 Keyed Hashing in the form of Message Authentication
*
* Code implementations:
* Core abstraction for:
* - [BLAKE2b]
* - [BLAKE2s]
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import org.kotlincrypto.core.InternalKotlinCryptoApi
* BLAKE2b Keyed Hashing implementation
*
* https://datatracker.ietf.org/doc/rfc7693/
*
* https://www.blake2.net/blake2.pdf
* */
public class BLAKE2b: BLAKE2Mac {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import org.kotlincrypto.core.InternalKotlinCryptoApi
* BLAKE2s Keyed Hashing implementation
*
* https://datatracker.ietf.org/doc/rfc7693/
*
* https://www.blake2.net/blake2.pdf
* */
public class BLAKE2s: BLAKE2Mac {

Expand Down
Loading

0 comments on commit bc680c8

Please sign in to comment.