Skip to content

Commit 2652ee1

Browse files
committed
WIP
1 parent 2521521 commit 2652ee1

File tree

6 files changed

+119
-2
lines changed

6 files changed

+119
-2
lines changed

build-logic/src/main/kotlin/ckbuild/Projects.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ object Projects {
2525
"cryptography-provider-base" to setOf(Tag.PUBLISHED),
2626
"cryptography-provider-jdk" to setOf(Tag.PUBLISHED),
2727
"cryptography-provider-jdk-bc" to setOf(Tag.PUBLISHED),
28+
"cryptography-provider-bouncycastle" to setOf(Tag.PUBLISHED),
2829
"cryptography-provider-apple" to setOf(Tag.PUBLISHED),
29-
"cryptography-provider-cryptokit" to setOf(Tag.PUBLISHED),
30+
// "cryptography-provider-cryptokit" to setOf(Tag.PUBLISHED),
3031
"cryptography-provider-webcrypto" to setOf(Tag.PUBLISHED),
3132
"cryptography-provider-openssl3-api" to setOf(Tag.PUBLISHED),
3233
"cryptography-provider-openssl3-shared" to setOf(Tag.PUBLISHED),
3334
"cryptography-provider-openssl3-prebuilt" to setOf(Tag.PUBLISHED),
34-
"cryptography-provider-optimal" to setOf(Tag.PUBLISHED),
35+
// "cryptography-provider-optimal" to setOf(Tag.PUBLISHED),
3536

3637
"cryptography-provider-jdk-android-tests" to setOf(),
3738
"cryptography-provider-openssl3-test" to setOf(),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2023-2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import ckbuild.*
6+
import org.jetbrains.kotlin.gradle.*
7+
8+
plugins {
9+
id("ckbuild.multiplatform-library")
10+
id("ckbuild.multiplatform-provider-tests")
11+
}
12+
13+
description = "cryptography-kotlin BouncyCastle provider"
14+
15+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
16+
kotlin {
17+
jvmTarget()
18+
19+
compilerOptions {
20+
optIn.addAll(
21+
OptIns.DelicateCryptographyApi,
22+
OptIns.CryptographyProviderApi,
23+
)
24+
}
25+
26+
sourceSets {
27+
jvmMain.dependencies {
28+
api(projects.cryptographyCore)
29+
implementation(libs.bouncycastle)
30+
// implementation(projects.cryptographyProviderBase)
31+
}
32+
}
33+
}
34+
35+
providerTests {
36+
packageName.set("dev.whyoleg.cryptography.providers.bouncycastle")
37+
providerInitializers.put("BouncyCastle", "CryptographyProvider.BouncyCastle")
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2023-2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.whyoleg.cryptography.providers.bouncycastle
6+
7+
import dev.whyoleg.cryptography.*
8+
import dev.whyoleg.cryptography.algorithms.*
9+
import dev.whyoleg.cryptography.providers.jdk.algorithms.*
10+
import dev.whyoleg.cryptography.random.*
11+
import java.security.*
12+
import java.util.*
13+
import java.util.concurrent.*
14+
15+
private val defaultProvider = lazy { BouncyCastleCryptographyProvider }
16+
17+
internal object BouncyCastleCryptographyProvider : CryptographyProvider() {
18+
override val name: String get() = "BouncyCastle"
19+
20+
@Suppress("UNCHECKED_CAST")
21+
override fun <A : CryptographyAlgorithm> getOrNull(identifier: CryptographyAlgorithmId<A>): A? = when (identifier) {
22+
HKDF -> JdkHkdf(state, this)
23+
else -> null
24+
} as A?
25+
}
26+
27+
internal class BouncyCastleCryptographyProviderContainer : CryptographyProviderContainer {
28+
override val priority: Int get() = 100
29+
override val provider: Lazy<CryptographyProvider> get() = defaultProvider
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.whyoleg.cryptography.providers.bouncycastle.algorithms
6+
7+
import dev.whyoleg.cryptography.*
8+
import dev.whyoleg.cryptography.algorithms.*
9+
import dev.whyoleg.cryptography.operations.*
10+
import org.bouncycastle.crypto.generators.*
11+
import org.bouncycastle.crypto.params.*
12+
13+
internal object BcHkdf : HKDF {
14+
override fun secretDerivation(
15+
digest: CryptographyAlgorithmId<Digest>,
16+
outputSize: BinarySize,
17+
salt: ByteArray?,
18+
info: ByteArray?,
19+
): SecretDerivation {
20+
21+
TODO("Not yet implemented")
22+
}
23+
24+
}
25+
26+
private class BcHkdfSecretDerivation(
27+
private val generator: HKDFBytesGenerator,
28+
private val outputSizeBytes: Int,
29+
private val salt: ByteArray?,
30+
private val info: ByteArray?,
31+
) : SecretDerivation {
32+
override fun deriveSecretToByteArrayBlocking(input: ByteArray): ByteArray {
33+
generator.init(
34+
HKDFParameters(
35+
/* ikm = */ input,
36+
/* salt = */ salt,
37+
/* info = */ info
38+
)
39+
)
40+
TODO("Not yet implemented")
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Copyright (c) 2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
3+
#
4+
5+
dev.whyoleg.cryptography.providers.bouncycastle.BouncyCastleCryptographyProviderContainer

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ projects("cryptography-kotlin") {
5555
module("android-tests")
5656
module("bc") // preconfigured JDK with BC provider
5757
}
58+
module("bouncycastle")
5859
module("apple")
5960
module("webcrypto")
6061
folder("openssl3") {

0 commit comments

Comments
 (0)