33import java .security .Security ;
44
55import 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 ;
612import org .bouncycastle .jce .provider .BouncyCastleProvider ;
713import org .bouncycastle .operator .MacCalculator ;
14+ import org .bouncycastle .operator .OperatorCreationException ;
815import org .bouncycastle .pkcs .jcajce .JcePBMac1CalculatorBuilder ;
16+ import org .bouncycastle .pkcs .jcajce .JcePBMac1CalculatorProviderBuilder ;
917import org .bouncycastle .util .Strings ;
1018import 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