8288050: Add support of SHA-512/224 and SHA-512/256 to the PBKDF2 and PBES2 impls in SunJCE provider

Reviewed-by: weijun
This commit is contained in:
Valerie Peng 2023-01-26 22:07:31 +00:00
parent d6007a356f
commit 7eff578768
26 changed files with 390 additions and 159 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -70,51 +70,49 @@ abstract class PBEKeyFactory extends SecretKeyFactorySpi {
validTypes.add("PBEWithHmacSHA256AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA384AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA512AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA512/224AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA512/256AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA1AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA224AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA256AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA384AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA512AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA512/224AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA512/256AndAES_256".toUpperCase(Locale.ENGLISH));
}
public static final class PBEWithMD5AndDES
extends PBEKeyFactory {
public PBEWithMD5AndDES() {
public static final class PBEWithMD5AndDES extends PBEKeyFactory {
public PBEWithMD5AndDES() {
super("PBEWithMD5AndDES");
}
}
public static final class PBEWithSHA1AndDESede
extends PBEKeyFactory {
public PBEWithSHA1AndDESede() {
public static final class PBEWithSHA1AndDESede extends PBEKeyFactory {
public PBEWithSHA1AndDESede() {
super("PBEWithSHA1AndDESede");
}
}
public static final class PBEWithSHA1AndRC2_40
extends PBEKeyFactory {
public PBEWithSHA1AndRC2_40() {
public static final class PBEWithSHA1AndRC2_40 extends PBEKeyFactory {
public PBEWithSHA1AndRC2_40() {
super("PBEWithSHA1AndRC2_40");
}
}
public static final class PBEWithSHA1AndRC2_128
extends PBEKeyFactory {
public PBEWithSHA1AndRC2_128() {
public static final class PBEWithSHA1AndRC2_128 extends PBEKeyFactory {
public PBEWithSHA1AndRC2_128() {
super("PBEWithSHA1AndRC2_128");
}
}
public static final class PBEWithSHA1AndRC4_40
extends PBEKeyFactory {
public PBEWithSHA1AndRC4_40() {
public static final class PBEWithSHA1AndRC4_40 extends PBEKeyFactory {
public PBEWithSHA1AndRC4_40() {
super("PBEWithSHA1AndRC4_40");
}
}
public static final class PBEWithSHA1AndRC4_128
extends PBEKeyFactory {
public PBEWithSHA1AndRC4_128() {
public static final class PBEWithSHA1AndRC4_128 extends PBEKeyFactory {
public PBEWithSHA1AndRC4_128() {
super("PBEWithSHA1AndRC4_128");
}
}
@ -122,83 +120,108 @@ abstract class PBEKeyFactory extends SecretKeyFactorySpi {
/*
* Private proprietary algorithm for supporting JCEKS.
*/
public static final class PBEWithMD5AndTripleDES
extends PBEKeyFactory {
public PBEWithMD5AndTripleDES() {
public static final class PBEWithMD5AndTripleDES extends PBEKeyFactory {
public PBEWithMD5AndTripleDES() {
super("PBEWithMD5AndTripleDES");
}
}
public static final class PBEWithHmacSHA1AndAES_128
extends PBEKeyFactory {
public PBEWithHmacSHA1AndAES_128() {
public static final class PBEWithHmacSHA1AndAES_128 extends PBEKeyFactory {
public PBEWithHmacSHA1AndAES_128() {
super("PBEWithHmacSHA1AndAES_128");
}
}
public static final class PBEWithHmacSHA224AndAES_128
extends PBEKeyFactory {
public PBEWithHmacSHA224AndAES_128() {
public PBEWithHmacSHA224AndAES_128() {
super("PBEWithHmacSHA224AndAES_128");
}
}
public static final class PBEWithHmacSHA256AndAES_128
extends PBEKeyFactory {
public PBEWithHmacSHA256AndAES_128() {
public PBEWithHmacSHA256AndAES_128() {
super("PBEWithHmacSHA256AndAES_128");
}
}
public static final class PBEWithHmacSHA384AndAES_128
extends PBEKeyFactory {
public PBEWithHmacSHA384AndAES_128() {
public PBEWithHmacSHA384AndAES_128() {
super("PBEWithHmacSHA384AndAES_128");
}
}
public static final class PBEWithHmacSHA512AndAES_128
extends PBEKeyFactory {
public PBEWithHmacSHA512AndAES_128() {
public PBEWithHmacSHA512AndAES_128() {
super("PBEWithHmacSHA512AndAES_128");
}
}
public static final class PBEWithHmacSHA1AndAES_256
public static final class PBEWithHmacSHA512_224AndAES_128
extends PBEKeyFactory {
public PBEWithHmacSHA1AndAES_256() {
public PBEWithHmacSHA512_224AndAES_128() {
super("PBEWithHmacSHA512/224AndAES_128");
}
}
public static final class PBEWithHmacSHA512_256AndAES_128
extends PBEKeyFactory {
public PBEWithHmacSHA512_256AndAES_128() {
super("PBEWithHmacSHA512/256AndAES_128");
}
}
public static final class PBEWithHmacSHA1AndAES_256 extends PBEKeyFactory {
public PBEWithHmacSHA1AndAES_256() {
super("PBEWithHmacSHA1AndAES_256");
}
}
public static final class PBEWithHmacSHA224AndAES_256
extends PBEKeyFactory {
public PBEWithHmacSHA224AndAES_256() {
public PBEWithHmacSHA224AndAES_256() {
super("PBEWithHmacSHA224AndAES_256");
}
}
public static final class PBEWithHmacSHA256AndAES_256
extends PBEKeyFactory {
public PBEWithHmacSHA256AndAES_256() {
public PBEWithHmacSHA256AndAES_256() {
super("PBEWithHmacSHA256AndAES_256");
}
}
public static final class PBEWithHmacSHA384AndAES_256
extends PBEKeyFactory {
public PBEWithHmacSHA384AndAES_256() {
public PBEWithHmacSHA384AndAES_256() {
super("PBEWithHmacSHA384AndAES_256");
}
}
public static final class PBEWithHmacSHA512AndAES_256
extends PBEKeyFactory {
public PBEWithHmacSHA512AndAES_256() {
public PBEWithHmacSHA512AndAES_256() {
super("PBEWithHmacSHA512AndAES_256");
}
}
public static final class PBEWithHmacSHA512_224AndAES_256
extends PBEKeyFactory {
public PBEWithHmacSHA512_224AndAES_256() {
super("PBEWithHmacSHA512/224AndAES_256");
}
}
public static final class PBEWithHmacSHA512_256AndAES_256
extends PBEKeyFactory {
public PBEWithHmacSHA512_256AndAES_256() {
super("PBEWithHmacSHA512/256AndAES_256");
}
}
/**
* Generates a <code>SecretKey</code> object from the provided key
* specification (key material).

View File

@ -89,6 +89,12 @@ abstract class PBES2Core extends CipherSpi {
case "HmacSHA512":
kdf = new PBKDF2Core.HmacSHA512();
break;
case "HmacSHA512/224":
kdf = new PBKDF2Core.HmacSHA512_224();
break;
case "HmacSHA512/256":
kdf = new PBKDF2Core.HmacSHA512_256();
break;
default:
throw new NoSuchAlgorithmException(
"No Cipher implementation for " + kdfAlgo);
@ -370,6 +376,20 @@ abstract class PBES2Core extends CipherSpi {
}
}
public static final class HmacSHA512_224AndAES_128 extends PBES2Core {
public HmacSHA512_224AndAES_128()
throws NoSuchAlgorithmException, NoSuchPaddingException {
super("HmacSHA512/224", "AES", 16);
}
}
public static final class HmacSHA512_256AndAES_128 extends PBES2Core {
public HmacSHA512_256AndAES_128()
throws NoSuchAlgorithmException, NoSuchPaddingException {
super("HmacSHA512/256", "AES", 16);
}
}
public static final class HmacSHA1AndAES_256 extends PBES2Core {
public HmacSHA1AndAES_256()
throws NoSuchAlgorithmException, NoSuchPaddingException {
@ -404,4 +424,17 @@ abstract class PBES2Core extends CipherSpi {
super("HmacSHA512", "AES", 32);
}
}
public static final class HmacSHA512_224AndAES_256 extends PBES2Core {
public HmacSHA512_224AndAES_256()
throws NoSuchAlgorithmException, NoSuchPaddingException {
super("HmacSHA512/224", "AES", 32);
}
}
public static final class HmacSHA512_256AndAES_256 extends PBES2Core {
public HmacSHA512_256AndAES_256()
throws NoSuchAlgorithmException, NoSuchPaddingException {
super("HmacSHA512/256", "AES", 32);
}
}
}

View File

@ -166,6 +166,8 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
case "HmacSHA256":
case "HmacSHA384":
case "HmacSHA512":
case "HmacSHA512/224":
case "HmacSHA512/256":
kdfAlgo_OID = ObjectIdentifier.of(KnownOIDs.findMatch(kdfAlgo));
break;
default:
@ -285,7 +287,9 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
!o.stdName().equals("HmacSHA224") &&
!o.stdName().equals("HmacSHA256") &&
!o.stdName().equals("HmacSHA384") &&
!o.stdName().equals("HmacSHA512"))) {
!o.stdName().equals("HmacSHA512") &&
!o.stdName().equals("HmacSHA512/224") &&
!o.stdName().equals("HmacSHA512/256"))) {
throw new IOException("PBE parameter parsing error: "
+ "expecting the object identifier for a HmacSHA key "
+ "derivation function");
@ -360,7 +364,7 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
}
DerOutputStream prf = new DerOutputStream();
// algorithm is id-hmacWithSHA1/SHA224/SHA256/SHA384/SHA512
// algorithm is id-hmacWith<MD>
prf.putOID(kdfAlgo_OID);
// parameters is 'NULL'
prf.putNull();
@ -397,7 +401,8 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
*
* The algorithn name pattern is: "PBEWith<prf>And<encryption>"
* where <prf> is one of: HmacSHA1, HmacSHA224, HmacSHA256, HmacSHA384,
* or HmacSHA512, and <encryption> is AES with a keysize suffix.
* HmacSHA512, HmacSHA512/224, or HmacSHA512/256 and <encryption> is
* AES with a keysize suffix.
*/
protected String engineToString() {
return pbes2AlgorithmName;
@ -439,6 +444,18 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
}
}
public static final class HmacSHA512_224AndAES_128 extends PBES2Parameters {
public HmacSHA512_224AndAES_128() throws NoSuchAlgorithmException {
super("PBEWithHmacSHA512/224AndAES_128");
}
}
public static final class HmacSHA512_256AndAES_128 extends PBES2Parameters {
public HmacSHA512_256AndAES_128() throws NoSuchAlgorithmException {
super("PBEWithHmacSHA512/256AndAES_128");
}
}
public static final class HmacSHA1AndAES_256 extends PBES2Parameters {
public HmacSHA1AndAES_256() throws NoSuchAlgorithmException {
super("PBEWithHmacSHA1AndAES_256");
@ -468,4 +485,16 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
super("PBEWithHmacSHA512AndAES_256");
}
}
public static final class HmacSHA512_224AndAES_256 extends PBES2Parameters {
public HmacSHA512_224AndAES_256() throws NoSuchAlgorithmException {
super("PBEWithHmacSHA512/224AndAES_256");
}
}
public static final class HmacSHA512_256AndAES_256 extends PBES2Parameters {
public HmacSHA512_256AndAES_256() throws NoSuchAlgorithmException {
super("PBEWithHmacSHA512/256AndAES_256");
}
}
}

View File

@ -35,8 +35,9 @@ import javax.crypto.spec.PBEKeySpec;
/**
* This class implements a key factory for PBE keys derived using
* PBKDF2 with HmacSHA1/HmacSHA224/HmacSHA256/HmacSHA384/HmacSHA512
* pseudo random function (PRF) as defined in PKCS#5 v2.1.
* PBKDF2 with HmacSHA1, HmacSHA224, HmacSHA256, HmacSHA384, HmacSHA512,
* HmacSHA512/224, and HmacSHA512/256 pseudo random function (PRF) as
* defined in PKCS#5 v2.1.
*
* @author Valerie Peng
*
@ -193,4 +194,16 @@ abstract class PBKDF2Core extends SecretKeyFactorySpi {
super("HmacSHA512");
}
}
public static final class HmacSHA512_224 extends PBKDF2Core {
public HmacSHA512_224() {
super("HmacSHA512/224");
}
}
public static final class HmacSHA512_256 extends PBKDF2Core {
public HmacSHA512_256() {
super("HmacSHA512/256");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -76,6 +76,12 @@ abstract class PBMAC1Core extends HmacCore {
case "HmacSHA512":
kdf = new PBKDF2Core.HmacSHA512();
break;
case "HmacSHA512/224":
kdf = new PBKDF2Core.HmacSHA512_224();
break;
case "HmacSHA512/256":
kdf = new PBKDF2Core.HmacSHA512_256();
break;
default:
throw new ProviderException(
"No MAC implementation for " + algo);
@ -221,4 +227,16 @@ abstract class PBMAC1Core extends HmacCore {
super("HmacSHA512", "SHA-512", 128);
}
}
public static final class HmacSHA512_224 extends PBMAC1Core {
public HmacSHA512_224() throws NoSuchAlgorithmException {
super("HmacSHA512/224", "SHA-512/224", 128);
}
}
public static final class HmacSHA512_256 extends PBMAC1Core {
public HmacSHA512_256() throws NoSuchAlgorithmException {
super("HmacSHA512/256", "SHA-512/256", 128);
}
}
}

View File

@ -347,6 +347,13 @@ public final class SunJCE extends Provider {
ps("Cipher", "PBEWithHmacSHA512AndAES_128",
"com.sun.crypto.provider.PBES2Core$HmacSHA512AndAES_128");
ps("Cipher", "PBEWithHmacSHA512/224AndAES_128",
"com.sun.crypto.provider.PBES2Core$HmacSHA512_224AndAES_128");
ps("Cipher", "PBEWithHmacSHA512/256AndAES_128",
"com.sun.crypto.provider.PBES2Core$HmacSHA512_256AndAES_128");
ps("Cipher", "PBEWithHmacSHA1AndAES_256",
"com.sun.crypto.provider.PBES2Core$HmacSHA1AndAES_256");
@ -362,6 +369,12 @@ public final class SunJCE extends Provider {
ps("Cipher", "PBEWithHmacSHA512AndAES_256",
"com.sun.crypto.provider.PBES2Core$HmacSHA512AndAES_256");
ps("Cipher", "PBEWithHmacSHA512/224AndAES_256",
"com.sun.crypto.provider.PBES2Core$HmacSHA512_224AndAES_256");
ps("Cipher", "PBEWithHmacSHA512/256AndAES_256",
"com.sun.crypto.provider.PBES2Core$HmacSHA512_256AndAES_256");
/*
* Key(pair) Generator engines
*/
@ -498,6 +511,12 @@ public final class SunJCE extends Provider {
ps("AlgorithmParameters", "PBEWithHmacSHA512AndAES_128",
"com.sun.crypto.provider.PBES2Parameters$HmacSHA512AndAES_128");
ps("AlgorithmParameters", "PBEWithHmacSHA512/224AndAES_128",
"com.sun.crypto.provider.PBES2Parameters$HmacSHA512_224AndAES_128");
ps("AlgorithmParameters", "PBEWithHmacSHA512/256AndAES_128",
"com.sun.crypto.provider.PBES2Parameters$HmacSHA512_256AndAES_128");
ps("AlgorithmParameters", "PBEWithHmacSHA1AndAES_256",
"com.sun.crypto.provider.PBES2Parameters$HmacSHA1AndAES_256");
@ -513,6 +532,12 @@ public final class SunJCE extends Provider {
ps("AlgorithmParameters", "PBEWithHmacSHA512AndAES_256",
"com.sun.crypto.provider.PBES2Parameters$HmacSHA512AndAES_256");
ps("AlgorithmParameters", "PBEWithHmacSHA512/224AndAES_256",
"com.sun.crypto.provider.PBES2Parameters$HmacSHA512_224AndAES_256");
ps("AlgorithmParameters", "PBEWithHmacSHA512/256AndAES_256",
"com.sun.crypto.provider.PBES2Parameters$HmacSHA512_256AndAES_256");
ps("AlgorithmParameters", "Blowfish",
"com.sun.crypto.provider.BlowfishParameters");
@ -595,6 +620,12 @@ public final class SunJCE extends Provider {
ps("SecretKeyFactory", "PBEWithHmacSHA512AndAES_128",
"com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512AndAES_128");
ps("SecretKeyFactory", "PBEWithHmacSHA512/224AndAES_128",
"com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512_224AndAES_128");
ps("SecretKeyFactory", "PBEWithHmacSHA512/256AndAES_128",
"com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512_256AndAES_128");
ps("SecretKeyFactory", "PBEWithHmacSHA1AndAES_256",
"com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA1AndAES_256");
@ -610,6 +641,12 @@ public final class SunJCE extends Provider {
ps("SecretKeyFactory", "PBEWithHmacSHA512AndAES_256",
"com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512AndAES_256");
ps("SecretKeyFactory", "PBEWithHmacSHA512/224AndAES_256",
"com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512_224AndAES_256");
ps("SecretKeyFactory", "PBEWithHmacSHA512/256AndAES_256",
"com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512_256AndAES_256");
// PBKDF2
psA("SecretKeyFactory", "PBKDF2WithHmacSHA1",
"com.sun.crypto.provider.PBKDF2Core$HmacSHA1",
@ -622,6 +659,10 @@ public final class SunJCE extends Provider {
"com.sun.crypto.provider.PBKDF2Core$HmacSHA384");
ps("SecretKeyFactory", "PBKDF2WithHmacSHA512",
"com.sun.crypto.provider.PBKDF2Core$HmacSHA512");
ps("SecretKeyFactory", "PBKDF2WithHmacSHA512/224",
"com.sun.crypto.provider.PBKDF2Core$HmacSHA512_224");
ps("SecretKeyFactory", "PBKDF2WithHmacSHA512/256",
"com.sun.crypto.provider.PBKDF2Core$HmacSHA512_256");
/*
* MAC
@ -686,6 +727,11 @@ public final class SunJCE extends Provider {
"com.sun.crypto.provider.PBMAC1Core$HmacSHA384", null, attrs);
ps("Mac", "PBEWithHmacSHA512",
"com.sun.crypto.provider.PBMAC1Core$HmacSHA512", null, attrs);
ps("Mac", "PBEWithHmacSHA512/224",
"com.sun.crypto.provider.PBMAC1Core$HmacSHA512_224", null, attrs);
ps("Mac", "PBEWithHmacSHA512/256",
"com.sun.crypto.provider.PBMAC1Core$HmacSHA512_256", null, attrs);
ps("Mac", "SslMacMD5",
"com.sun.crypto.provider.SslMacCore$SslMacMD5", null, attrs);
ps("Mac", "SslMacSHA1",

View File

@ -308,6 +308,8 @@ public class Cipher {
this.lock = new Object();
}
private static final String SHA512TRUNCATED = "SHA512/2";
private static String[] tokenizeTransformation(String transformation)
throws NoSuchAlgorithmException {
if (transformation == null) {
@ -320,27 +322,31 @@ public class Cipher {
* index 1: feedback component (e.g., CFB)
* index 2: padding component (e.g., PKCS5Padding)
*/
String[] parts = new String[3];
int count = 0;
StringTokenizer parser = new StringTokenizer(transformation, "/");
try {
while (parser.hasMoreTokens() && count < 3) {
parts[count++] = parser.nextToken().trim();
}
if (count == 0 || count == 2) {
String[] parts = { "", "", "" };
// check if the transformation contains algorithms with "/" in their
// name which can cause the parsing logic to go wrong
int sha512Idx = transformation.toUpperCase(Locale.ENGLISH)
.indexOf(SHA512TRUNCATED);
int startIdx = (sha512Idx == -1 ? 0 :
sha512Idx + SHA512TRUNCATED.length());
int endIdx = transformation.indexOf('/', startIdx);
if (endIdx == -1) {
// algorithm
parts[0] = transformation.trim();
} else {
// algorithm/mode/padding
parts[0] = transformation.substring(0, endIdx).trim();
startIdx = endIdx+1;
endIdx = transformation.indexOf('/', startIdx);
if (endIdx == -1) {
throw new NoSuchAlgorithmException("Invalid transformation"
+ " format:" +
transformation);
+ " format:" + transformation);
}
// treats all subsequent tokens as part of padding
if (count == 3 && parser.hasMoreTokens()) {
parts[2] = parts[2] + parser.nextToken("\r\n");
}
} catch (NoSuchElementException e) {
throw new NoSuchAlgorithmException("Invalid transformation " +
"format:" + transformation);
parts[1] = transformation.substring(startIdx, endIdx).trim();
parts[2] = transformation.substring(endIdx+1).trim();
}
if ((parts[0] == null) || (parts[0].isEmpty())) {
if (parts[0].isEmpty()) {
throw new NoSuchAlgorithmException("Invalid transformation: " +
"algorithm not specified-"
+ transformation);
@ -444,19 +450,13 @@ public class Cipher {
String alg = parts[0];
String mode = parts[1];
String pad = parts[2];
if ((mode != null) && (mode.isEmpty())) {
mode = null;
}
if ((pad != null) && (pad.isEmpty())) {
pad = null;
}
if ((mode == null) && (pad == null)) {
// AES
if ((mode.length() == 0) && (pad.length() == 0)) {
// Algorithm only
Transform tr = new Transform(alg, "", null, null);
return Collections.singletonList(tr);
} else { // if ((mode != null) && (pad != null)) {
// AES/CBC/PKCS5Padding
} else {
// Algorithm w/ at least mode or padding or both
List<Transform> list = new ArrayList<>(4);
list.add(new Transform(alg, "/" + mode + "/" + pad, null, null));
list.add(new Transform(alg, "/" + mode, null, pad));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -50,16 +50,23 @@ public enum PBEAlgorithm {
HMAC_SHA256_AES_128("PBEWithHmacSHA256AndAES_128", "", "", AbstractPBEWrapper.AES),
HMAC_SHA384_AES_128("PBEWithHmacSHA384AndAES_128", "", "", AbstractPBEWrapper.AES),
HMAC_SHA512_AES_128("PBEWithHmacSHA512AndAES_128", "", "", AbstractPBEWrapper.AES),
HMAC_SHA512_224_AES_128("PBEWithHmacSHA512/224AndAES_128", "", "", AbstractPBEWrapper.AES),
HMAC_SHA512_256_AES_128("PBEWithHmacSHA512/256AndAES_128", "", "", AbstractPBEWrapper.AES),
HMAC_SHA1_AES_256("PBEWithHmacSHA1AndAES_256", "", "", AbstractPBEWrapper.AES),
HMAC_SHA224_AES_256("PBEWithHmacSHA224AndAES_256", "", "", AbstractPBEWrapper.AES),
HMAC_SHA256_AES_256("PBEWithHmacSHA256AndAES_256", "", "", AbstractPBEWrapper.AES),
HMAC_SHA384_AES_256("PBEWithHmacSHA384AndAES_256", "", "", AbstractPBEWrapper.AES),
HMAC_SHA512_AES_256("PBEWithHmacSHA512AndAES_256", "", "", AbstractPBEWrapper.AES),
HMAC_SHA512_224_AES_256("PBEWithHmacSHA512/224AndAES_256", "", "", AbstractPBEWrapper.AES),
HMAC_SHA512_256_AES_256("PBEWithHmacSHA512/256AndAES_256", "", "", AbstractPBEWrapper.AES),
PBKDF_HMAC_SHA1("PBKDF2WithHmacSHA1", "", "", AbstractPBEWrapper.PBKDF2),
PBKDF_HMAC_SHA224("PBKDF2WithHmacSHA224", "", "", AbstractPBEWrapper.PBKDF2),
PBKDF_HMAC_SHA256("PBKDF2WithHmacSHA256", "", "", AbstractPBEWrapper.PBKDF2),
PBKDF_HMAC_SHA384("PBKDF2WithHmacSHA384", "", "", AbstractPBEWrapper.PBKDF2),
PBKDF_HMAC_SHA512("PBKDF2WithHmacSHA512", "", "", AbstractPBEWrapper.PBKDF2);
PBKDF_HMAC_SHA512("PBKDF2WithHmacSHA512", "", "", AbstractPBEWrapper.PBKDF2),
PBKDF_HMAC_SHA512_224("PBKDF2WithHmacSHA512/224", "", "", AbstractPBEWrapper.PBKDF2),
PBKDF_HMAC_SHA512_256("PBKDF2WithHmacSHA512/256", "", "", AbstractPBEWrapper.PBKDF2);
final String baseAlgo;
final String mode;
final String padding;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -53,7 +53,7 @@ import javax.crypto.spec.PBEParameterSpec;
/*
* @test
* @bug 8048599 8248268
* @bug 8048599 8248268 8288050
* @summary Tests for key wrap and unwrap operations
*/
@ -74,9 +74,14 @@ public class TestCipherKeyWrapperTest {
"pbeWithSHA1AndRC4_128/ECB/NoPadding", "PBEWithHmacSHA1AndAES_128",
"PBEWithHmacSHA224AndAES_128", "PBEWithHmacSHA256AndAES_128",
"PBEWithHmacSHA384AndAES_128", "PBEWithHmacSHA512AndAES_128",
"PBEWithHmacSHA512/224AndAES_128",
"PBEWithHmacSHA512/256AndAES_128",
"PBEWithHmacSHA1AndAES_256", "PBEWithHmacSHA224AndAES_256",
"PBEWithHmacSHA256AndAES_256", "PBEWithHmacSHA384AndAES_256",
"PBEWithHmacSHA512AndAES_256" };
"PBEWithHmacSHA512AndAES_256",
"PBEWithHmacSHA512/224AndAES_256",
"PBEWithHmacSHA512/256AndAES_256",
};
private static final String[] MODEL_AR = { "ECb", "pCbC", "cbC", "cFB",
"cFB24", "cFB40", "OfB48", "OFB64" };
private static final String[] PADDING_AR = { NOPADDING, "PKCS5Padding" };
@ -235,18 +240,20 @@ public class TestCipherKeyWrapperTest {
IllegalBlockSizeException, InvalidAlgorithmParameterException,
NoSuchAlgorithmException {
for (String alg : PBE_ALGORITHM_AR) {
String baseAlgo = alg.split("/")[0].toUpperCase();
String keyAlgo = (alg.endsWith("Padding") ?
alg.split("/")[0].toUpperCase() : alg);
// only run the tests on longer key lengths if unlimited version
// of JCE jurisdiction policy files are installed
if (Cipher.getMaxAllowedKeyLength(alg) < Integer.MAX_VALUE
&& (baseAlgo.endsWith("TRIPLEDES") || alg
&& (keyAlgo.endsWith("TRIPLEDES") || alg
.endsWith("AES_256"))) {
out.println("keyStrength > 128 within " + alg
+ " will not run under global policy");
continue;
}
SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
SecretKeyFactory skf = SecretKeyFactory.getInstance(keyAlgo, p);
SecretKey key = skf.generateSecret(new PBEKeySpec("Secret Lover"
.toCharArray()));
wrapTest(alg, alg, key, key, Cipher.SECRET_KEY, true);
@ -280,7 +287,8 @@ public class TestCipherKeyWrapperTest {
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException,
InvalidAlgorithmParameterException {
String algo = transformation.split("/")[0];
String algo = (transformation.endsWith("Padding") ?
transformation.split("/")[0] : transformation);
boolean isAESBlowfish = algo.indexOf("AES") != -1
|| algo.indexOf("Blowfish") != -1;
AlgorithmParameters aps = null;

View File

@ -23,7 +23,7 @@
/**
* @test
* @bug 4953553 8002277
* @bug 4953553 8002277 8288050
* @summary Ensure that InvalidKeyException is thrown when decrypting
* without parameters as javadoc has stated.
* @author Valerie Peng
@ -54,6 +54,8 @@ public class DecryptWithoutParameters {
"PBEWithHmacSHA256AndAES_128",
"PBEWithHmacSHA384AndAES_128",
"PBEWithHmacSHA512AndAES_128",
"PBEWithHmacSHA512/224AndAES_128",
"PBEWithHmacSHA512/256AndAES_128",
};
// return true if Cipher.init() fails with

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/*
* @test
* @bug 6209660 6383200
* @bug 6209660 6383200 8288050
* @summary Ensure that InvalidAlgorithmParameterException is
* thrown as javadoc specified when parameters of the wrong
* type are used.
@ -50,7 +50,9 @@ public class PBEInvalidParamsTest {
"PBEWithHmacSHA224AndAES_128",
"PBEWithHmacSHA256AndAES_128",
"PBEWithHmacSHA384AndAES_128",
"PBEWithHmacSHA512AndAES_128"
"PBEWithHmacSHA512AndAES_128",
"PBEWithHmacSHA512/224AndAES_128",
"PBEWithHmacSHA512/256AndAES_128",
// skip "PBEWithHmacSHAxxxAndAES_256" since they require Unlimited
// version of JCE jurisdiction policy files.
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/*
* @test
* @bug 6341599 6383200
* @bug 6341599 6383200 8288050
* @summary JCE Reference Guide has recommendations, not requirements,
* for algorithm names
* @author Brad R. Wetmore
@ -46,7 +46,9 @@ public class PBEKeysAlgorithmNames {
"PBKDF2WithHmacSHA224",
"PBKDF2WithHmacSHA256",
"PBKDF2WithHmacSHA384",
"PBKDF2WithHmacSHA512"
"PBKDF2WithHmacSHA512",
"PBKDF2WithHmacSHA512/224",
"PBKDF2WithHmacSHA512/256",
};
public static void main(String[] argv) throws Exception {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/*
* @test
* @bug 4944783 6383200
* @bug 4944783 6383200 8288050
* @summary ensure that the AlgorithmParameters object returned by
* PBE ciphers have the matching algorithm name.
* @author Valerie Peng
@ -49,7 +49,9 @@ public class PBEParametersTest {
"PBEWithHmacSHA224AndAES_128",
"PBEWithHmacSHA256AndAES_128",
"PBEWithHmacSHA384AndAES_128",
"PBEWithHmacSHA512AndAES_128"
"PBEWithHmacSHA512AndAES_128",
"PBEWithHmacSHA512/224AndAES_128",
"PBEWithHmacSHA512/256AndAES_128",
// skip "PBEWithHmacSHAxxxAndAES_256" since they require Unlimited
// version of JCE jurisdiction policy files.
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,11 +23,12 @@
/*
* @test
* @bug 6383200
* @bug 6383200 8288050
* @summary PBE: need new algorithm support in password based encryption
*/
import java.security.*;
import java.util.Arrays;
import java.util.Locale;
import javax.crypto.*;
import javax.crypto.spec.*;
@ -38,7 +39,16 @@ public class PBES2Test {
"PBEWithHmacSHA224AndAES_128",
"PBEWithHmacSHA256AndAES_128",
"PBEWithHmacSHA384AndAES_128",
"PBEWithHmacSHA512AndAES_128"
"PBEWithHmacSHA512AndAES_128",
"PBEWithHmacSHA512/224AndAES_128",
"PBEWithHmacSHA512/256AndAES_128",
"PBEWithHmacSha1AndAES_128/CBC/PKCS5PAdding",
"PBEWithHmacSHA224andAES_128/CBC/PkCS5Padding",
"PBEWithHmacSHA256AndAes_128/CBC/PKCS5PaddIng",
"PBEWithHmacSHa384AndAES_128/CbC/PKCS5Padding",
"PBEWithHmacSHA512andAES_128/CBc/PKCS5Padding",
"PBEWithHmacSha512/224andAES_128/cBC/PKCS5Padding",
"PBEWithHmacShA512/256AndAES_128/CBC/pkCS5Padding",
};
private static final byte[] ivBytes = {
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
@ -64,7 +74,9 @@ public class PBES2Test {
// Create PBE key
PBEKeySpec pbeKeySpec = new PBEKeySpec("mypassword".toCharArray());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algo);
int modeIdx = algo.toUpperCase(Locale.ENGLISH).indexOf("/CBC");
String keyAlgo = (modeIdx == -1 ? algo : algo.substring(0, modeIdx));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(keyAlgo);
SecretKey pbeKey = keyFactory.generateSecret(pbeKeySpec);
byte[] pbeKeyBytes = pbeKey.getEncoded();
System.out.println(" key[" + pbeKeyBytes.length + "]: " +

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,7 +39,7 @@ import javax.crypto.spec.PBEParameterSpec;
/**
* @test
* @bug 8041781
* @bug 8041781 8288050
* @summary test if seal/unseal works correctly with PBE algorithms
* @author Yun Ke
* @author Bill Situ
@ -69,11 +69,15 @@ public class PBESealedObject {
"PBEWithHmacSHA256AndAES_128",
"PBEWithHmacSHA384AndAES_128",
"PBEWithHmacSHA512AndAES_128",
"PBEWithHmacSHA512/224AndAES_128",
"PBEWithHmacSHA512/256AndAES_128",
"PBEWithHmacSHA1AndAES_256",
"PBEWithHmacSHA224AndAES_256",
"PBEWithHmacSHA256AndAES_256",
"PBEWithHmacSHA384AndAES_256",
"PBEWithHmacSHA512AndAES_256"
"PBEWithHmacSHA512AndAES_256",
"PBEWithHmacSHA512/224AndAES_256",
"PBEWithHmacSHA512/256AndAES_256",
};
public static void main(String[] args) {
@ -115,9 +119,10 @@ public class PBESealedObject {
int ITERATION_COUNT = 1000;
AlgorithmParameters pbeParams = null;
String baseAlgo
= new StringTokenizer(algo, "/").nextToken().toUpperCase();
boolean isAES = baseAlgo.contains("AES");
String keyAlgo = (algo.endsWith("Padding") ?
new StringTokenizer(algo, "/").nextToken().toUpperCase() :
algo);
boolean isAES = keyAlgo.contains("AES");
try {
// Initialization
@ -125,7 +130,7 @@ public class PBESealedObject {
new Random().nextBytes(salt);
AlgorithmParameterSpec aps = new PBEParameterSpec(salt,
ITERATION_COUNT);
SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
SecretKeyFactory skf = SecretKeyFactory.getInstance(keyAlgo, p);
SecretKey key = skf.generateSecret(
new PBEKeySpec("Secret Lover".toCharArray()));
@ -161,7 +166,7 @@ public class PBESealedObject {
unsealedKey = (SecretKey) so.getObject(key, "SunJCE");
return Arrays.equals(unsealedKey.getEncoded(), key.getEncoded());
} catch (InvalidKeyException ex) {
if (baseAlgo.endsWith("TRIPLEDES") || baseAlgo.endsWith("AES_256")) {
if (keyAlgo.endsWith("TRIPLEDES") || keyAlgo.endsWith("AES_256")) {
out.println(
"Expected exception , keyStrength > 128 within" + algo);
return true;

View File

@ -34,7 +34,7 @@ import javax.crypto.spec.SecretKeySpec;
/**
* @test
* @bug 8041781
* @bug 8041781 7181214 8288050
* @summary Verify if the SecretKeyFactory.translateKey() method works
* @author Alexander Fomin
* @run main PBKDF2Translate
@ -47,7 +47,9 @@ public class PBKDF2Translate {
"PBKDF2WithHmacSHA224",
"PBKDF2WithHmacSHA256",
"PBKDF2WithHmacSHA384",
"PBKDF2WithHmacSHA512"
"PBKDF2WithHmacSHA512",
"PBKDF2WithHmacSHA512/224",
"PBKDF2WithHmacSHA512/256",
};
private static final String PASS_PHRASE = "some hidden string";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,7 +34,7 @@ import javax.crypto.spec.PBEKeySpec;
/**
* @test
* @bug 8041787
* @bug 8041787 8288050
* @summary verify that Mac.update works with different size ByteBuffer
* @author Alexander Fomin
* @run main PBMacBuffer
@ -50,7 +50,9 @@ public class PBMacBuffer {
"PBEWithHmacSHA224",
"PBEWithHmacSHA256",
"PBEWithHmacSHA384",
"PBEWithHmacSHA512"
"PBEWithHmacSHA512",
"PBEWithHmacSHA512/224",
"PBEWithHmacSHA512/256",
};
String[] PBKDF2Algorithms = {
@ -58,7 +60,9 @@ public class PBMacBuffer {
"PBKDF2WithHmacSHA224",
"PBKDF2WithHmacSHA256",
"PBKDF2WithHmacSHA384",
"PBKDF2WithHmacSHA512"
"PBKDF2WithHmacSHA512",
"PBKDF2WithHmacSHA512/224",
"PBKDF2WithHmacSHA512/256",
};
PBMacBuffer testRunner = new PBMacBuffer();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,7 +32,7 @@ import javax.crypto.spec.PBEKeySpec;
/**
* @test
* @bug 8041787
* @bug 8041787 8288050
* @summary Check if doFinal and update operation result in same PBMac
* @author Alexander Fomin
* @run main PBMacDoFinalVsUpdate
@ -46,7 +46,9 @@ public class PBMacDoFinalVsUpdate {
"PBEWithHmacSHA224",
"PBEWithHmacSHA256",
"PBEWithHmacSHA384",
"PBEWithHmacSHA512"
"PBEWithHmacSHA512",
"PBEWithHmacSHA512/224",
"PBEWithHmacSHA512/256",
};
String[] PBKDF2Algorithms = {
@ -54,7 +56,9 @@ public class PBMacDoFinalVsUpdate {
"PBKDF2WithHmacSHA224",
"PBKDF2WithHmacSHA256",
"PBKDF2WithHmacSHA384",
"PBKDF2WithHmacSHA512"
"PBKDF2WithHmacSHA512",
"PBKDF2WithHmacSHA512/224",
"PBKDF2WithHmacSHA512/256",
};
PBMacDoFinalVsUpdate testRunner = new PBMacDoFinalVsUpdate();
@ -176,12 +180,13 @@ public class PBMacDoFinalVsUpdate {
* otherwise.
*/
protected boolean isMacLengthExpected(String MACAlgo, int lengthToCheck) {
java.util.regex.Pattern p = java.util.regex.Pattern.compile("(\\d+)",
java.util.regex.Pattern.CASE_INSENSITIVE);
java.util.regex.Matcher m = p.matcher(MACAlgo);
int val = 0;
if (m.find()) {
while (m.find()) { // use the lastly found number
val = Integer.parseInt(m.group(1));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,7 +39,7 @@ import javax.crypto.spec.PBEParameterSpec;
/**
* @test
* @bug 8041781
* @bug 8041781 8288050
* @summary Test to see if key wrapper works correctly with PBEKey
* @author Yu-Ching (Valerie) PENG
* @author Bill Situ
@ -69,11 +69,15 @@ public class TestCipherKeyWrapperPBEKey {
"PBEWithHmacSHA256AndAES_128",
"PBEWithHmacSHA384AndAES_128",
"PBEWithHmacSHA512AndAES_128",
"PBEWithHmacSHA512/224AndAES_128",
"PBEWithHmacSHA512/256AndAES_128",
"PBEWithHmacSHA1AndAES_256",
"PBEWithHmacSHA224AndAES_256",
"PBEWithHmacSHA256AndAES_256",
"PBEWithHmacSHA384AndAES_256",
"PBEWithHmacSHA512AndAES_256"
"PBEWithHmacSHA512AndAES_256",
"PBEWithHmacSHA512/224AndAES_256",
"PBEWithHmacSHA512/256AndAES_256",
};
public static void main(String[] args) {
@ -116,9 +120,10 @@ public class TestCipherKeyWrapperPBEKey {
int ITERATION_COUNT = 1000;
AlgorithmParameters pbeParams = null;
String baseAlgo
= new StringTokenizer(algo, "/").nextToken().toUpperCase();
boolean isAES = baseAlgo.contains("AES");
String keyAlgo = (algo.endsWith("Padding") ?
new StringTokenizer(algo, "/").nextToken().toUpperCase() :
algo);
boolean isAES = algo.contains("AES");
boolean isUnlimited =
(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE);
@ -128,7 +133,7 @@ public class TestCipherKeyWrapperPBEKey {
new Random().nextBytes(salt);
AlgorithmParameterSpec aps = new PBEParameterSpec(salt,
ITERATION_COUNT);
SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
SecretKeyFactory skf = SecretKeyFactory.getInstance(keyAlgo, p);
SecretKey key = skf.generateSecret(new PBEKeySpec(
"Secret Key".toCharArray()));
Cipher ci = Cipher.getInstance(algo);
@ -148,8 +153,8 @@ public class TestCipherKeyWrapperPBEKey {
Key unwrappedKey = ci.unwrap(keyWrapper, algo, Cipher.SECRET_KEY);
if ((baseAlgo.endsWith("TRIPLEDES")
|| baseAlgo.endsWith("AES_256")) && !isUnlimited) {
if ((keyAlgo.endsWith("TRIPLEDES")
|| keyAlgo.endsWith("AES_256")) && !isUnlimited) {
out.print(
"Expected InvalidKeyException not thrown");
return false;
@ -159,8 +164,8 @@ public class TestCipherKeyWrapperPBEKey {
} catch (InvalidKeyException ex) {
if ((baseAlgo.endsWith("TRIPLEDES")
|| baseAlgo.endsWith("AES_256")) && !isUnlimited) {
if ((keyAlgo.endsWith("TRIPLEDES")
|| keyAlgo.endsWith("AES_256")) && !isUnlimited) {
out.print(
"Expected InvalidKeyException thrown");
return true;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,7 +31,7 @@ import javax.crypto.NoSuchPaddingException;
/*
* @test
* @bug 8048601
* @bug 8048601 8288050
* @summary Performs multiple-part encryption/decryption depending on the
* specified encryption mode and check if the results obtained by
* different ways are the same.
@ -55,11 +55,15 @@ public class TestCipherTextLength {
"PBEWithSHA1AndRC4_128/ECB/NoPadding", "PBEWithHmacSHA1AndAES_128",
"PBEWithHmacSHA224AndAES_128", "PBEWithHmacSHA256AndAES_128",
"PBEWithHmacSHA384AndAES_128", "PBEWithHmacSHA512AndAES_128",
"PBEWithHmacSHA512/224AndAES_128", "PBEWithHmacSHA512/256AndAES_128",
"PBEWithHmacSHA1AndAES_256", "PBEWithHmacSHA224AndAES_256",
"PBEWithHmacSHA256AndAES_256", "PBEWithHmacSHA384AndAES_256",
"PBEWithHmacSHA512AndAES_256", "PBKDF2WithHmacSHA1",
"PBEWithHmacSHA512AndAES_256", "PBEWithHmacSHA512/224AndAES_256",
"PBEWithHmacSHA512/256AndAES_256", "PBKDF2WithHmacSHA1",
"PBKDF2WithHmacSHA224", "PBKDF2WithHmacSHA256",
"PBKDF2WithHmacSHA384", "PBKDF2WithHmacSHA512"};
"PBKDF2WithHmacSHA384", "PBKDF2WithHmacSHA512",
"PBKDF2WithHmacSHA512/224", "PBKDF2WithHmacSHA512/256",
};
private static final String PBE_PASSWORD = "Hush, it's a secret!!";
// Algorithm tested by PBKDF2Wrappter

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 4628062 4963723 8267319
* @bug 4628062 4963723 8267319 8288050
* @summary Verify that AES KeyGenerator supports default initialization
* when init is not called
* @author Valerie Peng
@ -40,6 +40,8 @@ public class Test4628062 {
private static final int[] HMACSHA256_SIZES = { 32 };
private static final int[] HMACSHA384_SIZES = { 48 };
private static final int[] HMACSHA512_SIZES = { 64 };
private static final int[] HMACSHA512_224_SIZES = { 28 };
private static final int[] HMACSHA512_256_SIZES = { 32 };
public boolean execute(String algo, int[] keySizes) throws Exception {
KeyGenerator kg = KeyGenerator.getInstance(algo, "SunJCE");
@ -74,27 +76,20 @@ public class Test4628062 {
throw new Exception("wrong exception is thrown for invalid key size!");
}
}
System.out.println(algo + " Passed!");
// passed all tests...hooray!
return true;
}
public static void main (String[] args) throws Exception {
Test4628062 test = new Test4628062();
String testName = test.getClass().getName();
if (test.execute("AES", AES_SIZES)) {
System.out.println(testName + ": AES Passed!");
}
if (test.execute("HmacSHA224", HMACSHA224_SIZES)) {
System.out.println(testName + ": HmacSHA224 Passed!");
}
if (test.execute("HmacSHA256", HMACSHA256_SIZES)) {
System.out.println(testName + ": HmacSHA256 Passed!");
}
if (test.execute("HmacSHA384", HMACSHA384_SIZES)) {
System.out.println(testName + ": HmacSHA384 Passed!");
}
if (test.execute("HmacSHA512", HMACSHA512_SIZES)) {
System.out.println(testName + ": HmacSHA512 Passed!");
}
test.execute("AES", AES_SIZES);
test.execute("HmacSHA224", HMACSHA224_SIZES);
test.execute("HmacSHA256", HMACSHA256_SIZES);
test.execute("HmacSHA384", HMACSHA384_SIZES);
test.execute("HmacSHA512", HMACSHA512_SIZES);
test.execute("HmacSHA512/224", HMACSHA512_224_SIZES);
test.execute("HmacSHA512/256", HMACSHA512_256_SIZES);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/**
* @test
* @bug 4893959 8013069
* @bug 4893959 8013069 8288050
* @summary basic test for PBE MAC algorithms.
* @author Valerie Peng
*/
@ -36,15 +36,18 @@ import javax.crypto.*;
import javax.crypto.spec.*;
public class HmacPBESHA1 {
private static final String[] MAC_ALGOS = {
"HmacPBESHA1",
"PBEWithHmacSHA1",
"PBEWithHmacSHA224",
"PBEWithHmacSHA256",
"PBEWithHmacSHA384",
"PBEWithHmacSHA512"
"PBEWithHmacSHA512",
"PBEWithHmacSHA512/224",
"PBEWithHmacSHA512/256",
};
private static final int[] MAC_LENGTHS = { 20, 20, 28, 32, 48, 64 };
private static final int[] MAC_LENGTHS = { 20, 20, 28, 32, 48, 64, 28, 32 };
private static final String KEY_ALGO = "PBE";
private static final String PROVIDER = "SunJCE";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/**
* @test
* @bug 4925866
* @bug 4925866 8288050
* @summary ensures various salt lengths can be used for
* HmacPBESHA1.
* @author Valerie Peng
@ -45,7 +45,9 @@ public class HmacSaltLengths {
"PBEWithHmacSHA224",
"PBEWithHmacSHA256",
"PBEWithHmacSHA384",
"PBEWithHmacSHA512"
"PBEWithHmacSHA512",
"PBEWithHmacSHA512/224",
"PBEWithHmacSHA512/256",
};
private static void runTest(String alg, byte[] plaintext,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/*
* @test
* @bug 7087021 8013069
* @bug 7087021 8013069 8288050
* @summary Clone tests for all MAC algorithms.
* @author Jan Luehe
*/
@ -36,7 +36,9 @@ public class MacClone {
public static void main(String[] args) throws Exception {
String[] algos = { "HmacMD5", "HmacSHA1", "HmacSHA224", "HmacSHA256",
"HmacSHA384", "HmacSHA512" };
"HmacSHA384", "HmacSHA512", "HmacSHA512/224",
"HmacSHA512/256",
};
KeyGenerator kgen = KeyGenerator.getInstance("DES");
SecretKey skey = kgen.generateKey();
for (String algo : algos) {
@ -45,7 +47,9 @@ public class MacClone {
String[] algos2 = { "HmacPBESHA1", "PBEWithHmacSHA1",
"PBEWithHmacSHA224", "PBEWithHmacSHA256",
"PBEWithHmacSHA384", "PBEWithHmacSHA512" };
"PBEWithHmacSHA384", "PBEWithHmacSHA512",
"PBEWithHmacSHA512/224", "PBEWithHmacSHA512/256",
};
skey = new SecretKeySpec("whatever".getBytes(), "PBE");
PBEParameterSpec params =
new PBEParameterSpec("1234567890".getBytes(), 500);

View File

@ -31,8 +31,10 @@ class Utils {
static final int KEY_SIZE = 70;
static final String[] MAC_ALGOS = {"HmacMD5", "HmacSHA1", "HmacSHA224",
"HmacSHA256", "HmacSHA384", "HmacSHA512"};
static final String[] MAC_ALGOS = {
"HmacMD5", "HmacSHA1", "HmacSHA224", "HmacSHA256", "HmacSHA384",
"HmacSHA512", "HmacSHA512/224", "HmacSHA512/256",
};
/**
* Get SecretKeySpec.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,7 @@ import javax.crypto.SecretKey;
/*
* @test
* @bug 8075286
* @bug 8075286 8288050
* @summary Test the HmacSHA algorithm OIDs in JDK.
* OID and Algorithm transformation string should match.
* Both could be able to be used to generate the algorithm instance.
@ -49,7 +49,10 @@ public class TestHmacSHAOids {
new DataTuple("1.2.840.113549.2.8", "HmacSHA224"),
new DataTuple("1.2.840.113549.2.9", "HmacSHA256"),
new DataTuple("1.2.840.113549.2.10", "HmacSHA384"),
new DataTuple("1.2.840.113549.2.11", "HmacSHA512"));
new DataTuple("1.2.840.113549.2.11", "HmacSHA512"),
new DataTuple("1.2.840.113549.2.12", "HmacSHA512/224"),
new DataTuple("1.2.840.113549.2.13", "HmacSHA512/256")
);
public static void main(String[] args) throws Exception {
for (DataTuple dataTuple : DATA) {