From 64089cc9f030d8ef7972adb5d117e0b23f47d62b Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 18 May 2006 17:29:21 +0000 Subject: Imported GNU Classpath 0.90 * scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113887 138bc75d-0d04-0410-961f-82ee72b054a4 --- .../classpath/gnu/javax/crypto/prng/CSPRNG.java | 2 +- .../classpath/gnu/javax/crypto/prng/Fortuna.java | 9 ++++++ .../gnu/javax/crypto/prng/ICMGenerator.java | 4 +-- libjava/classpath/gnu/javax/crypto/prng/IPBE.java | 34 +++++++++++++++------- .../classpath/gnu/javax/crypto/prng/PBKDF2.java | 27 +++++++++++------ 5 files changed, 52 insertions(+), 24 deletions(-) (limited to 'libjava/classpath/gnu/javax/crypto/prng') diff --git a/libjava/classpath/gnu/javax/crypto/prng/CSPRNG.java b/libjava/classpath/gnu/javax/crypto/prng/CSPRNG.java index 197009232bc..6585dcb907a 100644 --- a/libjava/classpath/gnu/javax/crypto/prng/CSPRNG.java +++ b/libjava/classpath/gnu/javax/crypto/prng/CSPRNG.java @@ -364,7 +364,7 @@ public class CSPRNG extends BasePRNG { CSPRNG instance = new CSPRNG(); HashMap attrib = new HashMap(); - attrib.put(BLOCKING, new Boolean(getProperty(BLOCK))); + attrib.put(BLOCKING, Boolean.valueOf(getProperty(BLOCK))); String s = null; // Get each file source "gnu.crypto.csprng.file.N". diff --git a/libjava/classpath/gnu/javax/crypto/prng/Fortuna.java b/libjava/classpath/gnu/javax/crypto/prng/Fortuna.java index 6453a9d02d0..69ce860f451 100644 --- a/libjava/classpath/gnu/javax/crypto/prng/Fortuna.java +++ b/libjava/classpath/gnu/javax/crypto/prng/Fortuna.java @@ -142,6 +142,14 @@ public class Fortuna extends BasePRNG implements Serializable, pool = 0; pool0Count = 0; generator.init(attributes); + try + { + fillBlock (); + } + catch (LimitReachedException shouldNotHappen) + { + throw new RuntimeException (shouldNotHappen); + } } public void fillBlock() throws LimitReachedException @@ -324,6 +332,7 @@ public class Fortuna extends BasePRNG implements Serializable, byte[] seed = (byte[]) attributes.get(SEED); if (seed != null) addRandomBytes(seed); + fillBlock (); } /** diff --git a/libjava/classpath/gnu/javax/crypto/prng/ICMGenerator.java b/libjava/classpath/gnu/javax/crypto/prng/ICMGenerator.java index 0de38e256ea..7d4f4c9a32c 100644 --- a/libjava/classpath/gnu/javax/crypto/prng/ICMGenerator.java +++ b/libjava/classpath/gnu/javax/crypto/prng/ICMGenerator.java @@ -98,8 +98,6 @@ import java.util.Map; *
  • * Integer Counter Mode, David A. McGrew.
  • * - * - * @version $Revision: 1.1 $ */ public class ICMGenerator extends BasePRNG implements Cloneable { @@ -376,4 +374,4 @@ public class ICMGenerator extends BasePRNG implements Cloneable cipher.encryptBlock(buffer, 0, buffer, 0); blockNdx = blockNdx.add(BigInteger.ONE); // increment blockNdx } -} \ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/prng/IPBE.java b/libjava/classpath/gnu/javax/crypto/prng/IPBE.java index 531e7ead88a..66921d635d5 100644 --- a/libjava/classpath/gnu/javax/crypto/prng/IPBE.java +++ b/libjava/classpath/gnu/javax/crypto/prng/IPBE.java @@ -39,31 +39,43 @@ exception statement from your version. */ package gnu.javax.crypto.prng; /** - *

    Trivial interface to group Password-based encryption property names.

    - * - * @version $Revision: 1.1 $ + * Trivial interface to group Password-based encryption property names and + * constants. */ public interface IPBE { - - // Constants - // ------------------------------------------------------------------------- - /** * Property name for the iteration count in a PBE algorithm. The property * associated with this is expected to be an {@link Integer}. */ - public static final String ITERATION_COUNT = "gnu.crypto.pbe.iteration.count"; + String ITERATION_COUNT = "gnu.crypto.pbe.iteration.count"; /** * Property name for the password in a PBE algorithm. The property associated * with this is expected to be a char array. */ - public static final String PASSWORD = "gnu.crypto.pbe.password"; + String PASSWORD = "gnu.crypto.pbe.password"; + + /** + * Property name for the password character encoding in a PBE algorithm. The + * property associated with this is expected to be a String denoting a valid + * character-encoding name. If this property is not set, and a password is + * used, then {@link #DEFAULT_PASSWORD_ENCODING} will be used when converting + * the password character(s) to bytes. + */ + String PASSWORD_ENCODING = "gnu.crypto.pbe.password.encoding"; /** * Property name for the salt in a PBE algorithm. The property associated * with this is expected to be a byte array. */ - public static final String SALT = "gnu.crypto.pbe.salt"; -} \ No newline at end of file + String SALT = "gnu.crypto.pbe.salt"; + + /** + * The default character set encoding name to be used if (a) a password is + * to be used as the source for a PBE-based Key Derivation Function (KDF) and + * (b) no character set encoding name was specified among the attributes used + * to initialize the instance. + */ + String DEFAULT_PASSWORD_ENCODING = "UTF-8"; +} diff --git a/libjava/classpath/gnu/javax/crypto/prng/PBKDF2.java b/libjava/classpath/gnu/javax/crypto/prng/PBKDF2.java index 5146bd4b9ab..d39cd0a6597 100644 --- a/libjava/classpath/gnu/javax/crypto/prng/PBKDF2.java +++ b/libjava/classpath/gnu/javax/crypto/prng/PBKDF2.java @@ -62,8 +62,6 @@ import java.util.Map; *
  • B. Kaliski, RFC 2898: * Password-Based Cryptography Specification, Version 2.0
  • * - * - * @version $Revision: 1.1 $ */ public class PBKDF2 extends BasePRNG implements Cloneable { @@ -129,23 +127,34 @@ public class PBKDF2 extends BasePRNG implements Cloneable salt = s; } + byte[] macKeyMaterial; char[] password = (char[]) attributes.get(IPBE.PASSWORD); if (password != null) { + String encoding = (String) attributes.get(IPBE.PASSWORD_ENCODING); + if (encoding == null || encoding.trim().length() == 0) + encoding = IPBE.DEFAULT_PASSWORD_ENCODING; + else + encoding = encoding.trim(); + try { - macAttrib.put(IMac.MAC_KEY_MATERIAL, - new String(password).getBytes("UTF-8")); + macKeyMaterial = new String(password).getBytes(encoding); } catch (UnsupportedEncodingException uee) { - throw new Error(uee.getMessage()); + throw new IllegalArgumentException("Unknown or unsupported encoding: " + + encoding, uee); } } + else + macKeyMaterial = (byte[]) attributes.get(IMac.MAC_KEY_MATERIAL); + + if (macKeyMaterial != null) + macAttrib.put(IMac.MAC_KEY_MATERIAL, macKeyMaterial); else if (!initialised) - { - throw new IllegalArgumentException("no password specified"); - } // otherwise re-use previous password. + throw new IllegalArgumentException("Neither password nor key-material were specified"); + // otherwise re-use previous password/key-material try { @@ -213,4 +222,4 @@ public class PBKDF2 extends BasePRNG implements Cloneable } } } -} \ No newline at end of file +} -- cgit v1.2.3