Skip to content

Commit fb96b8f

Browse files
committed
Merge branch 'mt-johan-feature/pbmac1-prf'
2 parents 990a094 + cdf083e commit fb96b8f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pkix/src/main/java/org/bouncycastle/pkcs/jcajce/JcePBMac1CalculatorBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public MacCalculator build(final char[] password)
187187
salt = pbeParams.getSalt();
188188
iterationCount = BigIntegers.intValueExact(pbeParams.getIterationCount());
189189
keySize = BigIntegers.intValueExact(pbeParams.getKeyLength()) * 8;
190+
prf = pbeParams.getPrf();
190191
}
191192

192193
SecretKeyFactory secFact = helper.createSecretKeyFactory("PBKDF2");

pkix/src/test/java/org/bouncycastle/pkcs/test/PBETest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
import java.security.Security;
44

55
import junit.framework.TestCase;
6+
7+
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
8+
import org.bouncycastle.asn1.pkcs.PBKDF2Params;
9+
import org.bouncycastle.asn1.pkcs.PBMAC1Params;
10+
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
11+
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
612
import org.bouncycastle.jce.provider.BouncyCastleProvider;
713
import org.bouncycastle.operator.MacCalculator;
14+
import org.bouncycastle.operator.OperatorCreationException;
815
import org.bouncycastle.pkcs.jcajce.JcePBMac1CalculatorBuilder;
16+
import org.bouncycastle.pkcs.jcajce.JcePBMac1CalculatorProviderBuilder;
917
import org.bouncycastle.util.Strings;
1018
import org.bouncycastle.util.encoders.Hex;
1119

@@ -29,4 +37,21 @@ public void testPBESHA256()
2937
assertEquals("55ac046e56e3089fec1691c22544b605f94185216dde0465e68b9d57c20dacbc", Hex.toHexString((byte[])pbCalculator.getKey().getRepresentation()));
3038

3139
}
40+
41+
void testPbmac1PrfPropagation() throws OperatorCreationException {
42+
AlgorithmIdentifier prf = new AlgorithmIdentifier(NISTObjectIdentifiers.id_hmacWithSHA3_512, null);;
43+
AlgorithmIdentifier protectionAlgorithm = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_PBMAC1,
44+
new PBMAC1Params(
45+
new AlgorithmIdentifier(PKCSObjectIdentifiers.id_PBKDF2, new PBKDF2Params("salt".getBytes(), 1234, 64, prf)),
46+
new AlgorithmIdentifier(NISTObjectIdentifiers.id_hmacWithSHA3_512, null)
47+
)
48+
);
49+
MacCalculator calculator = new JcePBMac1CalculatorProviderBuilder()
50+
.setProvider(new BouncyCastleProvider()).build().get(protectionAlgorithm, "foobar123".toCharArray());
51+
AlgorithmIdentifier actualPrf = PBKDF2Params.getInstance(
52+
PBMAC1Params.getInstance(calculator.getKey().getAlgorithmIdentifier().getParameters()).getKeyDerivationFunc().getParameters()
53+
).getPrf();
54+
System.out.println("Should be true: " + prf.equals(actualPrf));
55+
}
56+
3257
}

0 commit comments

Comments
 (0)