diff options
| author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-14 23:12:35 +0000 |
|---|---|---|
| committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-14 23:12:35 +0000 |
| commit | ffde862e033a0825e1e9972a89c0f1f80b261a8e (patch) | |
| tree | 97037d2c09c8384d80531f67ec36a01205df6bdb /libjava/classpath/gnu/javax/crypto/jce/prng | |
| parent | b415ff10527e977c3758234fd930e2c027bfa17d (diff) | |
| download | ppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.tar.gz ppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.zip | |
2006-08-14 Mark Wielaard <mark@klomp.org>
Imported GNU Classpath 0.92
* HACKING: Add more importing hints. Update automake version
requirement.
* configure.ac (gconf-peer): New enable AC argument.
Add --disable-gconf-peer and --enable-default-preferences-peer
to classpath configure when gconf is disabled.
* scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and
gnu/java/awt/dnd/peer/gtk to bc. Classify
gnu/java/security/Configuration.java as generated source file.
* gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java,
gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java,
gnu/java/lang/management/VMClassLoadingMXBeanImpl.java,
gnu/java/lang/management/VMRuntimeMXBeanImpl.java,
gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java,
gnu/java/lang/management/VMThreadMXBeanImpl.java,
gnu/java/lang/management/VMMemoryMXBeanImpl.java,
gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub
classes.
* java/lang/management/VMManagementFactory.java: Likewise.
* java/net/VMURLConnection.java: Likewise.
* gnu/java/nio/VMChannel.java: Likewise.
* java/lang/Thread.java (getState): Add stub implementation.
* java/lang/Class.java (isEnum): Likewise.
* java/lang/Class.h (isEnum): Likewise.
* gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed.
* javax/naming/spi/NamingManager.java: New override for StackWalker
functionality.
* configure, sources.am, Makefile.in, gcj/Makefile.in,
include/Makefile.in, testsuite/Makefile.in: Regenerated.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116139 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/gnu/javax/crypto/jce/prng')
5 files changed, 94 insertions, 211 deletions
diff --git a/libjava/classpath/gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java b/libjava/classpath/gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java index 0c071561b6f..652793b04ff 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java +++ b/libjava/classpath/gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java @@ -48,24 +48,17 @@ import java.security.SecureRandomSpi; import java.util.HashMap; /** - * Implementation of the <i>Service Provider Interface</i> (<b>SPI</b>) - * for the ARCFOUR keystream generator. + * Implementation of the <i>Service Provider Interface</i> (<b>SPI</b>) for + * the ARCFOUR keystream generator. */ -public class ARCFourRandomSpi extends SecureRandomSpi +public class ARCFourRandomSpi + extends SecureRandomSpi { - - // Constants and variables - // ------------------------------------------------------------------------- - /** Our underlying prng instance. */ private IRandom adaptee; - /** Have we been initialized? */ private boolean virgin; - // Constructor(s) - // ------------------------------------------------------------------------- - /** * Default 0-arguments constructor. */ @@ -76,20 +69,10 @@ public class ARCFourRandomSpi extends SecureRandomSpi virgin = true; } - // Class methods - // ------------------------------------------------------------------------- - - // Instance methods - // ------------------------------------------------------------------------- - - // java.security.SecureRandomSpi interface implementation ------------------ - public byte[] engineGenerateSeed(int numBytes) { if (numBytes < 1) - { - return new byte[0]; - } + return new byte[0]; byte[] result = new byte[numBytes]; this.engineNextBytes(result); return result; @@ -98,9 +81,7 @@ public class ARCFourRandomSpi extends SecureRandomSpi public void engineNextBytes(byte[] bytes) { if (virgin) - { - this.engineSetSeed(new byte[0]); - } + this.engineSetSeed(new byte[0]); try { adaptee.nextBytes(bytes, 0, bytes.length); @@ -117,4 +98,4 @@ public class ARCFourRandomSpi extends SecureRandomSpi adaptee.init(attributes); virgin = false; } -}
\ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/prng/CSPRNGSpi.java b/libjava/classpath/gnu/javax/crypto/jce/prng/CSPRNGSpi.java index c0aa015b065..6ded636aaf3 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/prng/CSPRNGSpi.java +++ b/libjava/classpath/gnu/javax/crypto/jce/prng/CSPRNGSpi.java @@ -38,29 +38,22 @@ exception statement from your version. */ package gnu.javax.crypto.jce.prng; -import gnu.java.security.Registry; -import gnu.javax.crypto.prng.CSPRNG; import gnu.java.security.prng.IRandom; import gnu.java.security.prng.LimitReachedException; +import gnu.javax.crypto.prng.CSPRNG; import java.net.MalformedURLException; import java.security.SecureRandomSpi; /** - * The implementation of the continuously-seeded SecureRandom - * <i>Service Provider Interface</i> (<b>SPI</b>) adapter.<p> + * The implementation of the continuously-seeded SecureRandom <i>Service + * Provider Interface</i> (<b>SPI</b>) adapter. */ -public class CSPRNGSpi extends SecureRandomSpi +public class CSPRNGSpi + extends SecureRandomSpi { - - // Constants and variables - // ------------------------------------------------------------------------- - private final IRandom adaptee; - // Constructor(s) - // ------------------------------------------------------------------------- - public CSPRNGSpi() throws ClassNotFoundException, MalformedURLException, NumberFormatException { @@ -69,20 +62,13 @@ public class CSPRNGSpi extends SecureRandomSpi adaptee = CSPRNG.getSystemInstance(); } - // Instance methods - // ------------------------------------------------------------------------- - protected byte[] engineGenerateSeed(final int count) { if (count < 0) - { - throw new IllegalArgumentException("count must be nonnegative"); - } + throw new IllegalArgumentException("count must be nonnegative"); byte[] buf = new byte[count]; if (count == 0) - { - return buf; - } + return buf; engineNextBytes(buf); return buf; } @@ -90,9 +76,7 @@ public class CSPRNGSpi extends SecureRandomSpi protected void engineNextBytes(final byte[] buffer) { if (buffer == null) - { - throw new NullPointerException(); - } + throw new NullPointerException(); try { adaptee.nextBytes(buffer, 0, buffer.length); @@ -106,9 +90,7 @@ public class CSPRNGSpi extends SecureRandomSpi protected void engineSetSeed(final byte[] seed) { if (seed == null) - { - throw new NullPointerException(); - } + throw new NullPointerException(); adaptee.addRandomBytes(seed, 0, seed.length); } -}
\ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/prng/FortunaImpl.java b/libjava/classpath/gnu/javax/crypto/jce/prng/FortunaImpl.java index 7006bbbaddc..8e3782ef055 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/prng/FortunaImpl.java +++ b/libjava/classpath/gnu/javax/crypto/jce/prng/FortunaImpl.java @@ -40,24 +40,26 @@ package gnu.javax.crypto.jce.prng; import gnu.java.security.prng.LimitReachedException; import gnu.javax.crypto.prng.Fortuna; + import java.security.SecureRandomSpi; import java.util.Collections; -public final class FortunaImpl extends SecureRandomSpi +public final class FortunaImpl + extends SecureRandomSpi { private final Fortuna adaptee; - public FortunaImpl () + public FortunaImpl() { - adaptee = new Fortuna (); - adaptee.init (Collections.singletonMap (Fortuna.SEED, new byte[0])); + adaptee = new Fortuna(); + adaptee.init(Collections.singletonMap(Fortuna.SEED, new byte[0])); } - - protected void engineSetSeed (byte[] seed) + + protected void engineSetSeed(byte[] seed) { synchronized (adaptee) { - adaptee.addRandomBytes (seed); + adaptee.addRandomBytes(seed); } } @@ -67,19 +69,19 @@ public final class FortunaImpl extends SecureRandomSpi { try { - adaptee.nextBytes (buffer); + adaptee.nextBytes(buffer); } catch (LimitReachedException shouldNotHappen) { - throw new Error (shouldNotHappen); + throw new Error(shouldNotHappen); } } } - protected byte[] engineGenerateSeed (int numbytes) + protected byte[] engineGenerateSeed(int numbytes) { byte[] seed = new byte[numbytes]; - engineNextBytes (seed); + engineNextBytes(seed); return seed; } -}
\ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/prng/ICMRandomSpi.java b/libjava/classpath/gnu/javax/crypto/jce/prng/ICMRandomSpi.java index d04b782f9f5..9855f95bd98 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/prng/ICMRandomSpi.java +++ b/libjava/classpath/gnu/javax/crypto/jce/prng/ICMRandomSpi.java @@ -38,44 +38,27 @@ exception statement from your version. */ package gnu.javax.crypto.jce.prng; +import gnu.java.security.Configuration; import gnu.java.security.Registry; +import gnu.java.security.prng.LimitReachedException; import gnu.javax.crypto.cipher.IBlockCipher; import gnu.javax.crypto.prng.ICMGenerator; -import gnu.java.security.prng.LimitReachedException; -import java.io.PrintWriter; import java.math.BigInteger; import java.security.SecureRandomSpi; import java.util.HashMap; import java.util.Random; +import java.util.logging.Logger; /** - * <p>An <em>Adapter</em> class around {@link ICMGenerator} to allow using this - * algorithm as a JCE {@link java.security.SecureRandom}.</p> + * An <em>Adapter</em> class around {@link ICMGenerator} to allow using this + * algorithm as a JCE {@link java.security.SecureRandom}. */ -public class ICMRandomSpi extends SecureRandomSpi +public class ICMRandomSpi + extends SecureRandomSpi { - - // Debugging methods and variables - // ------------------------------------------------------------------------- - - private static final String NAME = "ICMRandomSpi"; - - private static final boolean DEBUG = false; - - private static final int debuglevel = 0; - - private static final PrintWriter err = new PrintWriter(System.out, true); - - private static void debug(String s) - { - err.println(">>> " + NAME + ": " + s); - } - - // Constants and variables - // ------------------------------------------------------------------------- - - /** Class-wide prng to generate random material for the underlying prng.*/ + private static final Logger log = Logger.getLogger(ICMRandomSpi.class.getName()); + /** Class-wide prng to generate random material for the underlying prng. */ private static final ICMGenerator prng; // blank final static { @@ -86,28 +69,18 @@ public class ICMRandomSpi extends SecureRandomSpi // error messages private static final String MSG = "Exception while setting up an " + Registry.ICM_PRNG + " SPI: "; - private static final String RETRY = "Retry..."; - private static final String LIMIT_REACHED_MSG = "Limit reached: "; - private static final String RESEED = "Re-seed..."; - /** Our underlying prng instance. */ private ICMGenerator adaptee = new ICMGenerator(); - // Constructor(s) - // ------------------------------------------------------------------------- - // default 0-arguments constructor - // Class methods - // ------------------------------------------------------------------------- - private static void resetLocalPRNG() { - if (DEBUG && debuglevel > 8) - debug(">>> resetLocalPRNG()"); + if (Configuration.DEBUG) + log.entering(ICMRandomSpi.class.getName(), "resetLocalPRNG"); HashMap attributes = new HashMap(); attributes.put(ICMGenerator.CIPHER, Registry.AES_CIPHER); byte[] key = new byte[128 / 8]; // AES default key size @@ -122,50 +95,39 @@ public class ICMRandomSpi extends SecureRandomSpi // choose a random value between 1 and aesBlockSize / 2 int limit = aesBlockSize / 2; while (ndxLen < 1 || ndxLen > limit) - { - ndxLen = rand.nextInt(limit + 1); - } - attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, new Integer(ndxLen)); + ndxLen = rand.nextInt(limit + 1); + attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, Integer.valueOf(ndxLen)); byte[] index = new byte[ndxLen]; rand.nextBytes(index); attributes.put(ICMGenerator.SEGMENT_INDEX, new BigInteger(1, index)); - prng.setup(attributes); - if (DEBUG && debuglevel > 8) - debug("<<< resetLocalPRNG()"); + if (Configuration.DEBUG) + log.exiting(ICMRandomSpi.class.getName(), "resetLocalPRNG"); } - // Instance methods - // ------------------------------------------------------------------------- - - // java.security.SecureRandomSpi interface implementation ------------------ - public byte[] engineGenerateSeed(int numBytes) { - if (DEBUG && debuglevel > 8) - debug(">>> engineGenerateSeed()"); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "engineGenerateSeed"); if (numBytes < 1) { - if (DEBUG && debuglevel > 8) - debug("<<< engineGenerateSeed()"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "engineGenerateSeed"); return new byte[0]; } byte[] result = new byte[numBytes]; this.engineNextBytes(result); - if (DEBUG && debuglevel > 8) - debug("<<< engineGenerateSeed()"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "engineGenerateSeed"); return result; } public void engineNextBytes(byte[] bytes) { - if (DEBUG && debuglevel > 8) - debug(">>> engineNextBytes()"); - if (!adaptee.isInitialised()) - { - this.engineSetSeed(new byte[0]); - } - + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "engineNextBytes"); + if (! adaptee.isInitialised()) + this.engineSetSeed(new byte[0]); while (true) { try @@ -175,30 +137,28 @@ public class ICMRandomSpi extends SecureRandomSpi } catch (LimitReachedException x) { // reseed the generator - if (DEBUG) + if (Configuration.DEBUG) { - debug(LIMIT_REACHED_MSG + String.valueOf(x)); - x.printStackTrace(err); - debug(RESEED); + log.fine(LIMIT_REACHED_MSG + String.valueOf(x)); + log.fine(RESEED); } resetLocalPRNG(); } } - if (DEBUG && debuglevel > 8) - debug("<<< engineNextBytes()"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "engineNextBytes"); } public void engineSetSeed(byte[] seed) { - if (DEBUG && debuglevel > 8) - debug(">>> engineSetSeed()"); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "engineSetSeed"); // compute the total number of random bytes required to setup adaptee int materialLength = 0; materialLength += 16; // key material size materialLength += 16; // offset size materialLength += 8; // index size == half of an AES block byte[] material = new byte[materialLength]; - // use as much as possible bytes from the seed int materialOffset = 0; int materialLeft = material.length; @@ -209,8 +169,8 @@ public class ICMRandomSpi extends SecureRandomSpi materialOffset += lenToCopy; materialLeft -= lenToCopy; } - if (materialOffset > 0) - { // generate the rest + if (materialOffset > 0) // generate the rest + { while (true) { try @@ -224,22 +184,20 @@ public class ICMRandomSpi extends SecureRandomSpi } catch (LimitReachedException x) { - if (DEBUG) + if (Configuration.DEBUG) { - debug(MSG + String.valueOf(x)); - debug(RETRY); + log.fine(MSG + String.valueOf(x)); + log.fine(RETRY); } } } } - // setup the underlying adaptee instance HashMap attributes = new HashMap(); - // use AES cipher with 128-bit block size attributes.put(ICMGenerator.CIPHER, Registry.AES_CIPHER); // use an index the size of quarter of an AES block - attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, new Integer(4)); + attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, Integer.valueOf(4)); // specify the key byte[] key = new byte[16]; System.arraycopy(material, 0, key, 0, 16); @@ -252,9 +210,8 @@ public class ICMRandomSpi extends SecureRandomSpi byte[] index = new byte[8]; System.arraycopy(material, 32, index, 0, 8); attributes.put(ICMGenerator.SEGMENT_INDEX, new BigInteger(1, index)); - adaptee.init(attributes); - if (DEBUG && debuglevel > 8) - debug("<<< engineSetSeed()"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "engineSetSeed"); } -}
\ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/prng/UMacRandomSpi.java b/libjava/classpath/gnu/javax/crypto/jce/prng/UMacRandomSpi.java index 7dad68b2f95..f6949dd8d71 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/prng/UMacRandomSpi.java +++ b/libjava/classpath/gnu/javax/crypto/jce/prng/UMacRandomSpi.java @@ -38,65 +38,41 @@ exception statement from your version. */ package gnu.javax.crypto.jce.prng; +import gnu.java.security.Configuration; import gnu.java.security.Registry; -import gnu.javax.crypto.cipher.IBlockCipher; import gnu.java.security.prng.LimitReachedException; +import gnu.javax.crypto.cipher.IBlockCipher; import gnu.javax.crypto.prng.UMacGenerator; -import java.io.PrintWriter; import java.security.SecureRandomSpi; import java.util.HashMap; import java.util.Random; +import java.util.logging.Logger; /** - * <p>An <em>Adapter</em> class around {@link UMacGenerator} to allow using this - * algorithm as a JCE {@link java.security.SecureRandom}.</p> + * An <em>Adapter</em> class around {@link UMacGenerator} to allow using this + * algorithm as a JCE {@link java.security.SecureRandom}. */ -public class UMacRandomSpi extends SecureRandomSpi +public class UMacRandomSpi + extends SecureRandomSpi { - - // Debugging methods and variables - // ------------------------------------------------------------------------- - - private static final String NAME = "UMacRandomSpi"; - - private static final boolean DEBUG = false; - - private static final PrintWriter err = new PrintWriter(System.out, true); - - private static void debug(String s) - { - err.println(">>> " + NAME + ": " + s); - } - - // Constants and variables - // ------------------------------------------------------------------------- - - /** Class-wide prng to generate random material for the underlying prng.*/ + private static final Logger log = Logger.getLogger(UMacRandomSpi.class.getName()); + /** Class-wide prng to generate random material for the underlying prng. */ private static final UMacGenerator prng; // blank final static { prng = new UMacGenerator(); resetLocalPRNG(); } - // error messages private static final String MSG = "Exception while setting up a " + Registry.UMAC_PRNG + " SPI: "; - private static final String RETRY = "Retry..."; - /** Our underlying prng instance. */ private UMacGenerator adaptee = new UMacGenerator(); - // Constructor(s) - // ------------------------------------------------------------------------- - // default 0-arguments constructor - // Class methods - // ------------------------------------------------------------------------- - private static void resetLocalPRNG() { HashMap attributes = new HashMap(); @@ -106,22 +82,14 @@ public class UMacRandomSpi extends SecureRandomSpi rand.nextBytes(key); attributes.put(IBlockCipher.KEY_MATERIAL, key); int index = rand.nextInt() & 0xFF; - attributes.put(UMacGenerator.INDEX, new Integer(index)); - + attributes.put(UMacGenerator.INDEX, Integer.valueOf(index)); prng.setup(attributes); } - // Instance methods - // ------------------------------------------------------------------------- - - // java.security.SecureRandomSpi interface implementation ------------------ - public byte[] engineGenerateSeed(int numBytes) { if (numBytes < 1) - { - return new byte[0]; - } + return new byte[0]; byte[] result = new byte[numBytes]; this.engineNextBytes(result); return result; @@ -129,11 +97,8 @@ public class UMacRandomSpi extends SecureRandomSpi public void engineNextBytes(byte[] bytes) { - if (!adaptee.isInitialised()) - { - this.engineSetSeed(new byte[0]); - } - + if (! adaptee.isInitialised()) + this.engineSetSeed(new byte[0]); while (true) { try @@ -155,7 +120,6 @@ public class UMacRandomSpi extends SecureRandomSpi materialLength += 16; // key material size materialLength++; // index size byte[] material = new byte[materialLength]; - // use as much as possible bytes from the seed int materialOffset = 0; int materialLeft = material.length; @@ -166,8 +130,8 @@ public class UMacRandomSpi extends SecureRandomSpi materialOffset += lenToCopy; materialLeft -= lenToCopy; } - if (materialOffset > 0) - { // generate the rest + if (materialOffset > 0) // generate the rest + { while (true) { try @@ -175,24 +139,22 @@ public class UMacRandomSpi extends SecureRandomSpi prng.nextBytes(material, materialOffset, materialLeft); break; } - catch (IllegalStateException x) - { // should not happen + catch (IllegalStateException x) // should not happen + { throw new InternalError(MSG + String.valueOf(x)); } catch (LimitReachedException x) { - if (DEBUG) + if (Configuration.DEBUG) { - debug(MSG + String.valueOf(x)); - debug(RETRY); + log.fine(MSG + String.valueOf(x)); + log.fine(RETRY); } } } } - // setup the underlying adaptee instance HashMap attributes = new HashMap(); - // use AES cipher with 128-bit block size attributes.put(UMacGenerator.CIPHER, Registry.AES_CIPHER); // specify the key @@ -200,8 +162,7 @@ public class UMacRandomSpi extends SecureRandomSpi System.arraycopy(material, 0, key, 0, 16); attributes.put(IBlockCipher.KEY_MATERIAL, key); // use a 1-byte index - attributes.put(UMacGenerator.INDEX, new Integer(material[16] & 0xFF)); - + attributes.put(UMacGenerator.INDEX, Integer.valueOf(material[16] & 0xFF)); adaptee.init(attributes); } -}
\ No newline at end of file +} |

