Skip to content

Commit fe1fc6c

Browse files
author
royb
committed
Added HKDF, PBEPBKDF2 and SCRYPT implementations for KDF (JDK25)
1 parent c040eb3 commit fe1fc6c

File tree

18 files changed

+1054
-102
lines changed

18 files changed

+1054
-102
lines changed

build.gradle

Lines changed: 95 additions & 95 deletions
Large diffs are not rendered by default.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

mls/build.gradle

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ checkstyleMain {
7979
compileJava {
8080
options.release = 8
8181

82-
options.errorprone.disableWarningsInGeneratedCode = true
83-
options.errorprone.errorproneArgs = ["-Xep:IgnoredPureGetter:OFF"]
84-
options.errorprone.errorproneArgs.add("-XepExcludedPaths:.*/build/generated/.*")
82+
// options.errorprone.disableWarningsInGeneratedCode = true
83+
// options.errorprone.errorproneArgs = ["-Xep:IgnoredPureGetter:OFF"]
84+
// options.errorprone.errorproneArgs.add("-XepExcludedPaths:.*/build/generated/.*")
8585
}
8686

8787
compileJava9Java {
@@ -133,7 +133,21 @@ def createStartScripts(String mainClassName) {
133133
application {
134134
applicationDistribution.into('bin') {
135135
from(newTask)
136-
fileMode = 0755
136+
filePermissions {
137+
user {
138+
read = true
139+
write = true
140+
execute = true
141+
}
142+
group {
143+
read = true
144+
execute = true
145+
}
146+
other {
147+
read = true
148+
execute = true
149+
}
150+
}
137151
}
138152
}
139153
}

prov/build.gradle

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ plugins {
33
}
44

55
dependencies {
6+
implementation project(':core')
7+
testImplementation project(':core')
68
testImplementation files('../libs/unboundid-ldapsdk-6.0.8.jar')
79
}
810

@@ -17,6 +19,18 @@ sourceSets {
1719
srcDirs "${project(":core").projectDir}/src/main/resources"
1820
}
1921
}
22+
main {
23+
resources {
24+
srcDirs += ["${project(':core').projectDir}/src/main/resources"]
25+
}
26+
27+
java {
28+
srcDirs = ['src/main/java']
29+
}
30+
resources {
31+
srcDirs = ['src/main/resources']
32+
}
33+
}
2034

2135
java9 {
2236
java {
@@ -38,6 +52,11 @@ sourceSets {
3852
srcDirs = ['src/main/jdk21']
3953
}
4054
}
55+
java25 {
56+
java {
57+
srcDirs = ['src/main/jdk25']
58+
}
59+
}
4160

4261
}
4362

@@ -67,6 +86,15 @@ dependencies {
6786
sourceSets.java15.output.classesDirs]) {
6887
builtBy compileJava15Java
6988
}
89+
90+
java25Implementation files([
91+
sourceSets.main.output.classesDirs,
92+
sourceSets.java9.output.classesDirs,
93+
sourceSets.java11.output.classesDirs,
94+
sourceSets.java15.output.classesDirs,
95+
sourceSets.java21.output.classesDirs]) {
96+
builtBy compileJava21Java
97+
}
7098
}
7199

72100

@@ -94,6 +122,11 @@ compileJava21Java {
94122
options.sourcepath = files(['src/main/java', 'src/main/jdk21'])
95123
}
96124

125+
compileJava25Java {
126+
options.release = 25
127+
options.sourcepath = files(['src/main/java', 'src/main/jdk25'])
128+
}
129+
97130

98131
task sourcesJar(type: Jar) {
99132
archiveBaseName="bcprov"
@@ -113,6 +146,9 @@ task sourcesJar(type: Jar) {
113146
into('META-INF/versions/21') {
114147
from sourceSets.java21.allSource
115148
}
149+
into('META-INF/versions/25') {
150+
from sourceSets.java25.allSource
151+
}
116152
}
117153

118154
jar {
@@ -132,6 +168,9 @@ jar {
132168
into('META-INF/versions/21') {
133169
from sourceSets.java21.output
134170
}
171+
into('META-INF/versions/25') {
172+
from sourceSets.java25.output
173+
}
135174
String v = "${rootProject.extensions.ext.bundle_version}"
136175
manifest.attributes('Multi-Release': 'true')
137176
manifest.attributes('Bundle-Name': 'bcprov')
@@ -187,18 +226,40 @@ sourceSets {
187226
srcDir(files("src/test/jdk21"))
188227
}
189228
}
229+
230+
test25 {
231+
java {
232+
compileClasspath += main.output + test.output
233+
runtimeClasspath += test.output
234+
srcDir(files("src/test/jdk25"))
235+
}
236+
}
237+
}
238+
239+
dependencies {
240+
java9Implementation project(':core')
241+
java11Implementation project(':core')
242+
java15Implementation project(':core')
243+
java21Implementation project(':core')
244+
java25Implementation project(':core')
190245
}
191246

192247
dependencies {
193248
test11Implementation group: 'junit', name: 'junit', version: '4.13.2'
194249
test15Implementation group: 'junit', name: 'junit', version: '4.13.2'
195250
test21Implementation group: 'junit', name: 'junit', version: '4.13.2'
251+
test25Implementation group: 'junit', name: 'junit', version: '4.13.2'
196252
test11Implementation files('../libs/unboundid-ldapsdk-6.0.8.jar')
197253
test15Implementation files('../libs/unboundid-ldapsdk-6.0.8.jar')
198254
test21Implementation files('../libs/unboundid-ldapsdk-6.0.8.jar')
255+
test25Implementation files('../libs/unboundid-ldapsdk-6.0.8.jar')
199256
test11Implementation(project(":core"))
200257
test15Implementation(project(":core"))
201258
test21Implementation(project(":core"))
259+
test25Implementation(project(":core"))
260+
test25Implementation sourceSets.java25.output
261+
262+
202263
}
203264

204265

@@ -219,6 +280,11 @@ compileTest21Java {
219280
options.sourcepath = files(['src/test/java', 'src/test/jdk21'])
220281
}
221282

283+
compileTest25Java {
284+
options.release = 25
285+
options.sourcepath = files(['src/test/java', 'src/test/jdk25'])
286+
}
287+
222288
publishing {
223289
publications {
224290
maven(MavenPublication) {
@@ -233,6 +299,13 @@ publishing {
233299
}
234300
}
235301

302+
configurations {
303+
test11Implementation.extendsFrom testImplementation
304+
test15Implementation.extendsFrom testImplementation
305+
test21Implementation.extendsFrom testImplementation
306+
test25Implementation.extendsFrom testImplementation
307+
}
308+
236309

237310
test {
238311
jvmArgs = ['-Dtest.java.version.prefix=any']
@@ -367,6 +440,39 @@ task test21(type: Test) {
367440
}
368441
}
369442

443+
task test25(type: Test) {
444+
445+
// This is testing the 25 code base
446+
onlyIf {System.getenv("BC_JDK25") != null}
447+
dependsOn jar
448+
449+
testClassesDirs = sourceSets.test25.output.classesDirs
450+
classpath = sourceSets.test25.runtimeClasspath + files(jar.archiveFile)
451+
452+
forkEvery = 1;
453+
maxParallelForks = 8;
454+
455+
systemProperty 'bc.test.data.home', bcTestDataHome
456+
maxHeapSize = "1536m"
457+
testLogging.showStandardStreams = false
458+
459+
javaLauncher = javaToolchains.launcherFor {
460+
languageVersion = JavaLanguageVersion.of(25)
461+
}
462+
463+
jvmArgs = ['-Dtest.java.version.prefix=25']
464+
465+
466+
finalizedBy jacocoTestReport
467+
468+
filter {
469+
includeTestsMatching "AllTest*"
470+
if (project.hasProperty('excludeTests')) {
471+
excludeTestsMatching "${excludeTests}"
472+
}
473+
}
474+
}
475+
370476
if (System.getenv("BC_JDK8") != null) {
371477
System.out.println("${project.name}: Adding test8 as dependency for test task because BC_JDK8 is defined")
372478
test.dependsOn("test8")
@@ -386,7 +492,10 @@ if (System.getenv("BC_JDK21") != null) {
386492
System.out.println("${project.name}: Adding test21 as dependency for test task because BC_JDK21 is defined")
387493
test.dependsOn("test21")
388494
}
389-
495+
if (System.getenv("BC_JDK25") != null) {
496+
System.out.println("${project.name}: Adding test25 as dependency for test task because BC_JDK25 is defined")
497+
test.dependsOn("test25")
498+
}
390499

391500

392501

prov/src/main/java/org/bouncycastle/jce/provider/BouncyCastleProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public final class BouncyCastleProvider extends Provider
9595

9696
private static final String[] SYMMETRIC_GENERIC =
9797
{
98-
"PBEPBKDF1", "PBEPBKDF2", "PBEPKCS12", "TLSKDF", "SCRYPT"
98+
"PBEPBKDF1", "PBEPBKDF2", "PBEPKCS12", "TLSKDF", "SCRYPT", "HKDF"
9999
};
100100

101101
private static final String[] SYMMETRIC_MACS =
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.bouncycastle.jcajce.provider.symmetric;
2+
3+
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
4+
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
5+
import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
6+
7+
public class HKDF
8+
{
9+
private static final String PREFIX = "org.bouncycastle.jcajce.provider.symmetric" + ".hkdf.";
10+
11+
public static class Mappings
12+
extends AlgorithmProvider
13+
{
14+
public Mappings()
15+
{
16+
}
17+
18+
public void configure(ConfigurableProvider provider)
19+
{
20+
21+
provider.addAlgorithm("KDF.HKDF", PREFIX + "HKDFSpi");
22+
provider.addAlgorithm("KDF.HKDF-SHA256", PREFIX + "HKDFSpi$HKDFwithSHA256");
23+
provider.addAlgorithm("KDF.HKDF-SHA384", PREFIX + "HKDFSpi$HKDFwithSHA384");
24+
provider.addAlgorithm("KDF.HKDF-SHA512", PREFIX + "HKDFSpi$HKDFwithSHA512");
25+
26+
// Use SymmetricAlgorithmProvider?
27+
//TODO: add PKCSObjectIdentifiers?
28+
//PKCSObjectIdentifiers.id_alg_hkdf_with_sha256
29+
//PKCSObjectIdentifiers.id_alg_hkdf_with_sha384
30+
//PKCSObjectIdentifiers.id_alg_hkdf_with_sha512
31+
32+
}
33+
}
34+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.bouncycastle.jcajce.provider.symmetric;
2+
3+
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
4+
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
5+
import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
6+
7+
public class PBEPBKDF2
8+
{
9+
private static final String PREFIX = "org.bouncycastle.jcajce.provider.symmetric" + ".pbepbkdf2.";
10+
11+
public static class Mappings
12+
extends AlgorithmProvider
13+
{
14+
public Mappings()
15+
{
16+
}
17+
18+
public void configure(ConfigurableProvider provider)
19+
{
20+
// provider.addAlgorithm("AlgorithmParameters.PBKDF2", PREFIX + "PBEPBKDF2Spi$AlgParams");
21+
// provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + PKCSObjectIdentifiers.id_PBKDF2, "PBKDF2");
22+
provider.addAlgorithm("KDF.PBEPBKDF2", PREFIX + "PBEPBKDF2Spi$PBKDF2withUTF8");
23+
provider.addAlgorithm("Alg.Alias.KDF.PBKDF2WITHHMACSHA1", "PBKDF2");
24+
provider.addAlgorithm("Alg.Alias.KDF.PBKDF2WITHHMACSHA1ANDUTF8", "PBKDF2");
25+
provider.addAlgorithm("Alg.Alias.KDF." + PKCSObjectIdentifiers.id_PBKDF2, "PBKDF2");
26+
provider.addAlgorithm("KDF.PBKDF2WITHASCII", PREFIX + "PBEPBKDF2Spi$PBKDF2with8BIT");
27+
provider.addAlgorithm("Alg.Alias.KDF.PBKDF2WITH8BIT", "PBKDF2WITHASCII");
28+
provider.addAlgorithm("Alg.Alias.KDF.PBKDF2WITHHMACSHA1AND8BIT", "PBKDF2WITHASCII");
29+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA224", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA224");
30+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA256", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA256");
31+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA384", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA384");
32+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA512", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA512");
33+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA512-224", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA512_224");
34+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA512-256", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA512_256");
35+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA3-224", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA3_224");
36+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA3-256", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA3_256");
37+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA3-384", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA3_384");
38+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSHA3-512", PREFIX + "PBEPBKDF2Spi$PBKDF2withSHA3_512");
39+
provider.addAlgorithm("KDF.PBKDF2WITHHMACGOST3411", PREFIX + "PBEPBKDF2Spi$PBKDF2withGOST3411");
40+
provider.addAlgorithm("KDF.PBKDF2WITHHMACSM3", PREFIX + "PBEPBKDF2Spi$PBKDF2withSM3");
41+
42+
43+
}
44+
}
45+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.bouncycastle.jcajce.provider.symmetric;
2+
3+
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
4+
import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
5+
6+
public class SCRYPT
7+
{
8+
private static final String PREFIX = "org.bouncycastle.jcajce.provider.symmetric" + ".scrypt.";
9+
10+
public static class Mappings
11+
extends AlgorithmProvider
12+
{
13+
public Mappings()
14+
{
15+
}
16+
17+
public void configure(ConfigurableProvider provider)
18+
{
19+
provider.addAlgorithm("KDF.SCRYPT", PREFIX + "SCryptSpi$ScryptWithUTF8");
20+
}
21+
}
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.bouncycastle.jcajce.provider.symmetric.hkdf;
2+
3+
import org.bouncycastle.crypto.params.HKDFParameters;
4+
5+
import java.security.spec.AlgorithmParameterSpec;
6+
7+
public class HKDFParameterSpec
8+
extends HKDFParameters
9+
implements AlgorithmParameterSpec
10+
{
11+
public HKDFParameterSpec(byte[] ikm, byte[] salt, byte[] info)
12+
{
13+
super(ikm, salt, info);
14+
}
15+
}

0 commit comments

Comments
 (0)