From 48d9e1f35e4e7e90de6e5b5e636d76b43743ce2d Mon Sep 17 00:00:00 2001 From: Zaiyao Liu Date: Wed, 7 Jan 2015 03:59:06 +0000 Subject: [PATCH] 8048607: Test key generation of DES and DESEDE Reviewed-by: xuelei --- .../provider/Cipher/DES/TestUtility.java | 50 +++++--- .../crypto/KeyGenerator/TestKGParity.java | 121 ++++++++++++++++++ 2 files changed, 153 insertions(+), 18 deletions(-) create mode 100644 jdk/test/javax/crypto/KeyGenerator/TestKGParity.java diff --git a/jdk/test/com/sun/crypto/provider/Cipher/DES/TestUtility.java b/jdk/test/com/sun/crypto/provider/Cipher/DES/TestUtility.java index 61efd621bdb..ffa0a5bfcb3 100644 --- a/jdk/test/com/sun/crypto/provider/Cipher/DES/TestUtility.java +++ b/jdk/test/com/sun/crypto/provider/Cipher/DES/TestUtility.java @@ -27,39 +27,52 @@ public class TestUtility { - private static final String digits = "0123456789abcdef"; + private static final String DIGITS = "0123456789abcdef"; - public TestUtility() { + private TestUtility() { } public static String hexDump(byte[] bytes) { - StringBuffer buf = new StringBuffer (bytes.length * 2); - int i; + StringBuilder buf = new StringBuilder(bytes.length * 2); + int i; - buf.append (" "); // four spaces + buf.append(" "); // four spaces for (i = 0; i < bytes.length; i++) { - buf.append (digits.charAt ((bytes[i] >> 4) & 0x0f)); - buf.append (digits.charAt (bytes[i] & 0x0f)); - if (((i + 1) % 32) == 0) { - if ((i + 1) != bytes.length) - buf.append ("\n "); // line after four words - } else if (((i + 1) % 4) == 0) - buf.append (' '); // space between words + buf.append(DIGITS.charAt(bytes[i] >> 4 & 0x0f)); + buf.append(DIGITS.charAt(bytes[i] & 0x0f)); + if ((i + 1) % 32 == 0) { + if (i + 1 != bytes.length) { + buf.append("\n "); // line after four words + } + } else if ((i + 1) % 4 == 0) { + buf.append(' '); // space between words + } } - return buf.toString (); + return buf.toString(); } + public static String hexDump(byte[] bytes, int index) { + StringBuilder buf = new StringBuilder(bytes.length * 2); + int i; + + buf.append(" "); // four spaces + buf.append(DIGITS.charAt(bytes[index] >> 4 & 0x0f)); + buf.append(DIGITS.charAt(bytes[index] & 0x0f)); + return buf.toString(); + } public static boolean equalsBlock(byte[] b1, byte[] b2) { - if (b1.length != b2.length) + if (b1.length != b2.length) { return false; + } - for (int i=0; i 0) { + even = !even; + } + } + if (keyByte < 0) { + even = !even; + } + + return even; + } +}