diff options
Diffstat (limited to 'libjava/classpath/gnu/javax/crypto/prng')
5 files changed, 52 insertions, 24 deletions
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; * <li><a href="http://www.ietf.org/internet-drafts/draft-mcgrew-saag-icm-00.txt"> * Integer Counter Mode</a>, David A. McGrew.</li> * </ol> - * - * @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; /** - * <p>Trivial interface to group Password-based encryption property names.</p> - * - * @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; * <li>B. Kaliski, <a href="http://www.ietf.org/rfc/rfc2898.txt">RFC 2898: * Password-Based Cryptography Specification, Version 2.0</a></li> * </ol> - * - * @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 +} |