From 8aa540d2f783474d1d2e06f16744bf67b9c1facc Mon Sep 17 00:00:00 2001
From: Mark Wielaard
Date: Fri, 10 Mar 2006 21:46:48 +0000
Subject: Imported GNU Classpath 0.90
Imported GNU Classpath 0.90
* scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
* gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
* java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
* java/lang/Math.java: New override file.
* java/lang/Character.java: Merged from Classpath.
(start, end): Now 'int's.
(canonicalName): New field.
(CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
(UnicodeBlock): Added argument.
(of): New overload.
(forName): New method.
Updated unicode blocks.
(sets): Updated.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r111942
---
.../gnu/java/awt/peer/GLightweightPeer.java | 6 +-
.../gnu/java/awt/peer/gtk/GtkButtonPeer.java | 7 +-
.../java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java | 9 +-
.../gnu/java/awt/peer/gtk/GtkCheckboxPeer.java | 57 +-
.../gnu/java/awt/peer/gtk/GtkComponentPeer.java | 157 +-
.../gnu/java/awt/peer/gtk/GtkContainerPeer.java | 25 +-
.../gnu/java/awt/peer/gtk/GtkFileDialogPeer.java | 31 +-
.../gnu/java/awt/peer/gtk/GtkFramePeer.java | 13 +-
.../gnu/java/awt/peer/gtk/GtkGenericPeer.java | 39 +-
.../classpath/gnu/java/awt/peer/gtk/GtkImage.java | 20 +-
.../gnu/java/awt/peer/gtk/GtkLabelPeer.java | 9 +-
.../gnu/java/awt/peer/gtk/GtkListPeer.java | 9 +-
.../gnu/java/awt/peer/gtk/GtkMenuBarPeer.java | 79 +-
.../java/awt/peer/gtk/GtkMenuComponentPeer.java | 59 +-
.../gnu/java/awt/peer/gtk/GtkMenuItemPeer.java | 99 +-
.../gnu/java/awt/peer/gtk/GtkMenuPeer.java | 32 +-
.../gnu/java/awt/peer/gtk/GtkPanelPeer.java | 33 +-
.../gnu/java/awt/peer/gtk/GtkPopupMenuPeer.java | 7 +-
.../gnu/java/awt/peer/gtk/GtkScrollbarPeer.java | 22 +-
.../gnu/java/awt/peer/gtk/GtkTextAreaPeer.java | 6 +-
.../gnu/java/awt/peer/gtk/GtkTextFieldPeer.java | 2 -
.../gnu/java/awt/peer/gtk/GtkToolkit.java | 170 +-
.../gnu/java/awt/peer/gtk/GtkWindowPeer.java | 54 +-
.../gnu/java/awt/peer/swing/SwingButtonPeer.java | 224 ++
.../gnu/java/awt/peer/swing/SwingCanvasPeer.java | 64 +
.../gnu/java/awt/peer/swing/SwingComponent.java | 89 +
.../java/awt/peer/swing/SwingComponentPeer.java | 994 +++++++++
.../java/awt/peer/swing/SwingContainerPeer.java | 241 +++
.../gnu/java/awt/peer/swing/SwingFramePeer.java | 196 ++
.../gnu/java/awt/peer/swing/SwingLabelPeer.java | 196 ++
.../gnu/java/awt/peer/swing/SwingMenuBarPeer.java | 295 +++
.../gnu/java/awt/peer/swing/SwingMenuItemPeer.java | 157 ++
.../gnu/java/awt/peer/swing/SwingMenuPeer.java | 284 +++
.../gnu/java/awt/peer/swing/SwingPanelPeer.java | 67 +
.../java/awt/peer/swing/SwingTextFieldPeer.java | 367 ++++
.../gnu/java/awt/peer/swing/SwingToolkit.java | 165 ++
.../gnu/java/awt/peer/swing/SwingWindowPeer.java | 72 +
.../classpath/gnu/java/awt/peer/swing/package.html | 71 +
.../gnu/java/beans/DefaultExceptionListener.java | 66 +
.../beans/decoder/DefaultExceptionListener.java | 57 -
libjava/classpath/gnu/java/lang/CharData.java | 2228 +++++++++++++-------
.../classpath/gnu/java/net/CRLFInputStream.java | 19 +-
.../classpath/gnu/java/net/LineInputStream.java | 31 +-
.../gnu/java/net/protocol/file/Connection.java | 18 +-
.../gnu/java/net/protocol/ftp/ActiveModeDTP.java | 1 +
.../java/net/protocol/ftp/FTPURLConnection.java | 45 +-
.../java/net/protocol/http/ChunkedInputStream.java | 102 +-
.../gnu/java/net/protocol/http/HTTPConnection.java | 274 ++-
.../java/net/protocol/http/HTTPURLConnection.java | 186 +-
.../gnu/java/net/protocol/http/Headers.java | 283 +--
.../gnu/java/net/protocol/http/Request.java | 58 +-
.../gnu/java/net/protocol/http/Response.java | 24 +-
.../net/protocol/http/ResponseHeaderHandler.java | 2 +-
.../gnu/java/net/protocol/jar/Connection.java | 8 +-
.../gnu/java/nio/channels/FileChannelImpl.java | 2 +-
.../classpath/gnu/java/nio/charset/Provider.java | 3 +-
.../gnu/java/nio/charset/iconv/IconvDecoder.java | 1 -
.../gnu/java/nio/charset/iconv/IconvEncoder.java | 1 -
.../gnu/java/nio/charset/iconv/IconvProvider.java | 2 -
libjava/classpath/gnu/java/rmi/dgc/DGCImpl.java | 178 +-
.../gnu/java/rmi/registry/RegistryImpl.java | 2 +-
.../gnu/java/rmi/server/CombinedClassLoader.java | 149 ++
.../gnu/java/rmi/server/RMIObjectInputStream.java | 64 +-
.../gnu/java/rmi/server/UnicastServerRef.java | 650 +++---
.../classpath/gnu/java/security/Properties.java | 374 ++++
libjava/classpath/gnu/java/security/Registry.java | 455 ++++
.../classpath/gnu/java/security/der/DERValue.java | 29 +-
.../classpath/gnu/java/security/der/DERWriter.java | 10 +-
.../classpath/gnu/java/security/hash/BaseHash.java | 206 ++
.../gnu/java/security/hash/HashFactory.java | 178 ++
.../classpath/gnu/java/security/hash/Haval.java | 759 +++++++
.../gnu/java/security/hash/IMessageDigest.java | 135 ++
libjava/classpath/gnu/java/security/hash/MD2.java | 301 +++
libjava/classpath/gnu/java/security/hash/MD4.java | 328 +++
libjava/classpath/gnu/java/security/hash/MD5.java | 365 ++++
.../gnu/java/security/hash/RipeMD128.java | 291 +++
.../gnu/java/security/hash/RipeMD160.java | 328 +++
.../classpath/gnu/java/security/hash/Sha160.java | 308 +++
.../classpath/gnu/java/security/hash/Sha256.java | 278 +++
.../classpath/gnu/java/security/hash/Sha384.java | 322 +++
.../classpath/gnu/java/security/hash/Sha512.java | 322 +++
.../classpath/gnu/java/security/hash/Tiger.java | 943 +++++++++
.../gnu/java/security/hash/Whirlpool.java | 626 ++++++
.../gnu/java/security/jce/hash/HavalSpi.java | 68 +
.../gnu/java/security/jce/hash/MD2Spi.java | 69 +
.../gnu/java/security/jce/hash/MD4Spi.java | 69 +
.../gnu/java/security/jce/hash/MD5Spi.java | 68 +
.../security/jce/hash/MessageDigestAdapter.java | 147 ++
.../gnu/java/security/jce/hash/RipeMD128Spi.java | 68 +
.../gnu/java/security/jce/hash/RipeMD160Spi.java | 68 +
.../gnu/java/security/jce/hash/Sha160Spi.java | 68 +
.../gnu/java/security/jce/hash/Sha256Spi.java | 68 +
.../gnu/java/security/jce/hash/Sha384Spi.java | 68 +
.../gnu/java/security/jce/hash/Sha512Spi.java | 68 +
.../gnu/java/security/jce/hash/TigerSpi.java | 69 +
.../gnu/java/security/jce/hash/WhirlpoolSpi.java | 68 +
.../gnu/java/security/jce/prng/HavalRandomSpi.java | 66 +
.../gnu/java/security/jce/prng/MD2RandomSpi.java | 66 +
.../gnu/java/security/jce/prng/MD4RandomSpi.java | 66 +
.../gnu/java/security/jce/prng/MD5RandomSpi.java | 66 +
.../java/security/jce/prng/RipeMD128RandomSpi.java | 66 +
.../java/security/jce/prng/RipeMD160RandomSpi.java | 66 +
.../security/jce/prng/SecureRandomAdapter.java | 126 ++
.../java/security/jce/prng/Sha160RandomSpi.java | 66 +
.../java/security/jce/prng/Sha256RandomSpi.java | 66 +
.../java/security/jce/prng/Sha384RandomSpi.java | 66 +
.../java/security/jce/prng/Sha512RandomSpi.java | 66 +
.../gnu/java/security/jce/prng/TigerRandomSpi.java | 66 +
.../java/security/jce/prng/WhirlpoolRandomSpi.java | 66 +
.../gnu/java/security/jce/sig/DSSKeyFactory.java | 238 +++
.../security/jce/sig/DSSKeyPairGeneratorSpi.java | 169 ++
.../gnu/java/security/jce/sig/DSSParameters.java | 220 ++
.../security/jce/sig/DSSParametersGenerator.java | 125 ++
.../java/security/jce/sig/DSSRawSignatureSpi.java | 70 +
.../java/security/jce/sig/EncodedKeyFactory.java | 453 ++++
.../security/jce/sig/KeyPairGeneratorAdapter.java | 109 +
.../gnu/java/security/jce/sig/MD2withRSA.java | 56 +
.../gnu/java/security/jce/sig/MD5withRSA.java | 56 +
.../gnu/java/security/jce/sig/RSAKeyFactory.java | 265 +++
.../security/jce/sig/RSAKeyPairGeneratorSpi.java | 115 +
.../security/jce/sig/RSAPSSRawSignatureSpi.java | 69 +
.../gnu/java/security/jce/sig/SHA160withDSS.java | 54 +
.../gnu/java/security/jce/sig/SHA160withRSA.java | 56 +
.../gnu/java/security/jce/sig/SHA256withRSA.java | 56 +
.../gnu/java/security/jce/sig/SHA384withRSA.java | 56 +
.../gnu/java/security/jce/sig/SHA512withRSA.java | 56 +
.../java/security/jce/sig/SignatureAdapter.java | 263 +++
.../gnu/java/security/key/IKeyPairCodec.java | 132 ++
.../gnu/java/security/key/IKeyPairGenerator.java | 82 +
.../gnu/java/security/key/KeyPairCodecFactory.java | 362 ++++
.../java/security/key/KeyPairGeneratorFactory.java | 148 ++
.../gnu/java/security/key/dss/DSSKey.java | 182 ++
.../java/security/key/dss/DSSKeyPairGenerator.java | 445 ++++
.../security/key/dss/DSSKeyPairPKCS8Codec.java | 235 +++
.../java/security/key/dss/DSSKeyPairRawCodec.java | 383 ++++
.../java/security/key/dss/DSSKeyPairX509Codec.java | 248 +++
.../gnu/java/security/key/dss/DSSPrivateKey.java | 201 ++
.../gnu/java/security/key/dss/DSSPublicKey.java | 201 ++
.../gnu/java/security/key/dss/FIPS186.java | 296 +++
.../gnu/java/security/key/rsa/GnuRSAKey.java | 181 ++
.../java/security/key/rsa/GnuRSAPrivateKey.java | 299 +++
.../gnu/java/security/key/rsa/GnuRSAPublicKey.java | 185 ++
.../java/security/key/rsa/RSAKeyPairGenerator.java | 264 +++
.../security/key/rsa/RSAKeyPairPKCS8Codec.java | 284 +++
.../java/security/key/rsa/RSAKeyPairRawCodec.java | 332 +++
.../java/security/key/rsa/RSAKeyPairX509Codec.java | 248 +++
.../classpath/gnu/java/security/prng/BasePRNG.java | 199 ++
.../gnu/java/security/prng/EntropySource.java | 62 +
.../classpath/gnu/java/security/prng/IRandom.java | 180 ++
.../java/security/prng/LimitReachedException.java | 69 +
.../gnu/java/security/prng/MDGenerator.java | 135 ++
.../gnu/java/security/prng/PRNGFactory.java | 109 +
.../gnu/java/security/prng/RandomEvent.java | 82 +
.../java/security/prng/RandomEventListener.java | 50 +
.../gnu/java/security/provider/DSAKeyFactory.java | 134 --
.../security/provider/DSAKeyPairGenerator.java | 194 --
.../gnu/java/security/provider/DSAParameters.java | 150 --
.../gnu/java/security/provider/DSASignature.java | 251 ---
.../provider/DiffieHellmanKeyFactoryImpl.java | 123 --
.../DiffieHellmanKeyPairGeneratorImpl.java | 86 -
.../java/security/provider/EncodedKeyFactory.java | 303 ---
.../classpath/gnu/java/security/provider/Gnu.java | 248 ++-
.../gnu/java/security/provider/GnuDHPublicKey.java | 115 -
.../java/security/provider/GnuDSAPrivateKey.java | 147 --
.../java/security/provider/GnuDSAPublicKey.java | 137 --
.../java/security/provider/GnuRSAPrivateKey.java | 164 --
.../java/security/provider/GnuRSAPublicKey.java | 109 -
.../gnu/java/security/provider/MD2withRSA.java | 54 -
.../gnu/java/security/provider/MD4withRSA.java | 54 -
.../classpath/gnu/java/security/provider/MD5.java | 338 ---
.../gnu/java/security/provider/MD5withRSA.java | 54 -
.../provider/PKIXCertPathValidatorImpl.java | 9 +-
.../classpath/gnu/java/security/provider/RSA.java | 311 ---
.../gnu/java/security/provider/RSAKeyFactory.java | 181 --
.../classpath/gnu/java/security/provider/SHA.java | 242 ---
.../gnu/java/security/provider/SHA1PRNG.java | 137 --
.../gnu/java/security/provider/SHA1withRSA.java | 61 -
.../gnu/java/security/sig/BaseSignature.java | 261 +++
.../gnu/java/security/sig/ISignature.java | 169 ++
.../gnu/java/security/sig/ISignatureCodec.java | 68 +
.../java/security/sig/SignatureCodecFactory.java | 226 ++
.../gnu/java/security/sig/SignatureFactory.java | 113 +
.../gnu/java/security/sig/dss/DSSSignature.java | 347 +++
.../security/sig/dss/DSSSignatureRawCodec.java | 191 ++
.../security/sig/dss/DSSSignatureX509Codec.java | 193 ++
.../gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java | 306 +++
.../gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java | 299 +++
.../gnu/java/security/sig/rsa/EMSA_PSS.java | 432 ++++
.../classpath/gnu/java/security/sig/rsa/RSA.java | 356 ++++
.../security/sig/rsa/RSAPKCS1V1_5Signature.java | 247 +++
.../sig/rsa/RSAPKCS1V1_5SignatureRawCodec.java | 153 ++
.../sig/rsa/RSAPKCS1V1_5SignatureX509Codec.java | 128 ++
.../gnu/java/security/sig/rsa/RSAPSSSignature.java | 348 +++
.../security/sig/rsa/RSAPSSSignatureRawCodec.java | 159 ++
.../java/security/sig/rsa/RSASignatureFactory.java | 176 ++
.../classpath/gnu/java/security/util/Base64.java | 396 ++++
.../classpath/gnu/java/security/util/DerUtil.java | 64 +
.../gnu/java/security/util/ExpirableObject.java | 172 ++
.../gnu/java/security/util/FormatUtil.java | 140 ++
libjava/classpath/gnu/java/security/util/PRNG.java | 156 ++
.../classpath/gnu/java/security/util/Prime2.java | 417 ++++
.../classpath/gnu/java/security/util/Sequence.java | 149 ++
.../gnu/java/security/util/SimpleList.java | 171 ++
libjava/classpath/gnu/java/security/util/Util.java | 692 ++++++
.../gnu/java/security/x509/X509Certificate.java | 8 +-
.../gnu/java/security/x509/ext/GeneralNames.java | 21 +-
.../gnu/java/util/prefs/EventDispatcher.java | 112 +
.../gnu/java/util/prefs/FileBasedFactory.java | 12 +-
.../gnu/java/util/prefs/FileBasedPreferences.java | 273 +++
.../gnu/java/util/prefs/MemoryBasedFactory.java | 2 +-
.../java/util/prefs/MemoryBasedPreferences.java | 4 +-
.../classpath/gnu/java/util/prefs/NodeWriter.java | 33 +-
212 files changed, 30604 insertions(+), 5395 deletions(-)
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingCanvasPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingMenuItemPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingMenuPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java
create mode 100644 libjava/classpath/gnu/java/awt/peer/swing/package.html
create mode 100644 libjava/classpath/gnu/java/beans/DefaultExceptionListener.java
delete mode 100644 libjava/classpath/gnu/java/beans/decoder/DefaultExceptionListener.java
create mode 100644 libjava/classpath/gnu/java/rmi/server/CombinedClassLoader.java
create mode 100644 libjava/classpath/gnu/java/security/Properties.java
create mode 100644 libjava/classpath/gnu/java/security/Registry.java
create mode 100644 libjava/classpath/gnu/java/security/hash/BaseHash.java
create mode 100644 libjava/classpath/gnu/java/security/hash/HashFactory.java
create mode 100644 libjava/classpath/gnu/java/security/hash/Haval.java
create mode 100644 libjava/classpath/gnu/java/security/hash/IMessageDigest.java
create mode 100644 libjava/classpath/gnu/java/security/hash/MD2.java
create mode 100644 libjava/classpath/gnu/java/security/hash/MD4.java
create mode 100644 libjava/classpath/gnu/java/security/hash/MD5.java
create mode 100644 libjava/classpath/gnu/java/security/hash/RipeMD128.java
create mode 100644 libjava/classpath/gnu/java/security/hash/RipeMD160.java
create mode 100644 libjava/classpath/gnu/java/security/hash/Sha160.java
create mode 100644 libjava/classpath/gnu/java/security/hash/Sha256.java
create mode 100644 libjava/classpath/gnu/java/security/hash/Sha384.java
create mode 100644 libjava/classpath/gnu/java/security/hash/Sha512.java
create mode 100644 libjava/classpath/gnu/java/security/hash/Tiger.java
create mode 100644 libjava/classpath/gnu/java/security/hash/Whirlpool.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/HavalSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/MD2Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/MD4Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/MD5Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/MessageDigestAdapter.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/RipeMD128Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/RipeMD160Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/Sha160Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/Sha256Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/Sha384Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/Sha512Spi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/TigerSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/hash/WhirlpoolSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/HavalRandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/MD2RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/MD4RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/MD5RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/RipeMD128RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/RipeMD160RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/SecureRandomAdapter.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/Sha160RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/Sha256RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/Sha384RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/Sha512RandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/TigerRandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/DSSKeyFactory.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/DSSParameters.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/DSSParametersGenerator.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/DSSRawSignatureSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/EncodedKeyFactory.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/MD2withRSA.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/MD5withRSA.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/RSAKeyFactory.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/SHA160withDSS.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/SHA160withRSA.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/SHA256withRSA.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/SHA384withRSA.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/SHA512withRSA.java
create mode 100644 libjava/classpath/gnu/java/security/jce/sig/SignatureAdapter.java
create mode 100644 libjava/classpath/gnu/java/security/key/IKeyPairCodec.java
create mode 100644 libjava/classpath/gnu/java/security/key/IKeyPairGenerator.java
create mode 100644 libjava/classpath/gnu/java/security/key/KeyPairCodecFactory.java
create mode 100644 libjava/classpath/gnu/java/security/key/KeyPairGeneratorFactory.java
create mode 100644 libjava/classpath/gnu/java/security/key/dss/DSSKey.java
create mode 100644 libjava/classpath/gnu/java/security/key/dss/DSSKeyPairGenerator.java
create mode 100644 libjava/classpath/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
create mode 100644 libjava/classpath/gnu/java/security/key/dss/DSSKeyPairRawCodec.java
create mode 100644 libjava/classpath/gnu/java/security/key/dss/DSSKeyPairX509Codec.java
create mode 100644 libjava/classpath/gnu/java/security/key/dss/DSSPrivateKey.java
create mode 100644 libjava/classpath/gnu/java/security/key/dss/DSSPublicKey.java
create mode 100644 libjava/classpath/gnu/java/security/key/dss/FIPS186.java
create mode 100644 libjava/classpath/gnu/java/security/key/rsa/GnuRSAKey.java
create mode 100644 libjava/classpath/gnu/java/security/key/rsa/GnuRSAPrivateKey.java
create mode 100644 libjava/classpath/gnu/java/security/key/rsa/GnuRSAPublicKey.java
create mode 100644 libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairGenerator.java
create mode 100644 libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
create mode 100644 libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java
create mode 100644 libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
create mode 100644 libjava/classpath/gnu/java/security/prng/BasePRNG.java
create mode 100644 libjava/classpath/gnu/java/security/prng/EntropySource.java
create mode 100644 libjava/classpath/gnu/java/security/prng/IRandom.java
create mode 100644 libjava/classpath/gnu/java/security/prng/LimitReachedException.java
create mode 100644 libjava/classpath/gnu/java/security/prng/MDGenerator.java
create mode 100644 libjava/classpath/gnu/java/security/prng/PRNGFactory.java
create mode 100644 libjava/classpath/gnu/java/security/prng/RandomEvent.java
create mode 100644 libjava/classpath/gnu/java/security/prng/RandomEventListener.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/DSAKeyFactory.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/DSAKeyPairGenerator.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/DSAParameters.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/DSASignature.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyFactoryImpl.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyPairGeneratorImpl.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/EncodedKeyFactory.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/GnuDHPublicKey.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/GnuDSAPrivateKey.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/GnuDSAPublicKey.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/GnuRSAPrivateKey.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/GnuRSAPublicKey.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/MD2withRSA.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/MD4withRSA.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/MD5.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/MD5withRSA.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/RSA.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/RSAKeyFactory.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/SHA.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/SHA1PRNG.java
delete mode 100644 libjava/classpath/gnu/java/security/provider/SHA1withRSA.java
create mode 100644 libjava/classpath/gnu/java/security/sig/BaseSignature.java
create mode 100644 libjava/classpath/gnu/java/security/sig/ISignature.java
create mode 100644 libjava/classpath/gnu/java/security/sig/ISignatureCodec.java
create mode 100644 libjava/classpath/gnu/java/security/sig/SignatureCodecFactory.java
create mode 100644 libjava/classpath/gnu/java/security/sig/SignatureFactory.java
create mode 100644 libjava/classpath/gnu/java/security/sig/dss/DSSSignature.java
create mode 100644 libjava/classpath/gnu/java/security/sig/dss/DSSSignatureRawCodec.java
create mode 100644 libjava/classpath/gnu/java/security/sig/dss/DSSSignatureX509Codec.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/EMSA_PSS.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/RSA.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureRawCodec.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureX509Codec.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/RSAPSSSignature.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java
create mode 100644 libjava/classpath/gnu/java/security/sig/rsa/RSASignatureFactory.java
create mode 100644 libjava/classpath/gnu/java/security/util/Base64.java
create mode 100644 libjava/classpath/gnu/java/security/util/DerUtil.java
create mode 100644 libjava/classpath/gnu/java/security/util/ExpirableObject.java
create mode 100644 libjava/classpath/gnu/java/security/util/FormatUtil.java
create mode 100644 libjava/classpath/gnu/java/security/util/PRNG.java
create mode 100644 libjava/classpath/gnu/java/security/util/Prime2.java
create mode 100644 libjava/classpath/gnu/java/security/util/Sequence.java
create mode 100644 libjava/classpath/gnu/java/security/util/SimpleList.java
create mode 100644 libjava/classpath/gnu/java/security/util/Util.java
create mode 100644 libjava/classpath/gnu/java/util/prefs/EventDispatcher.java
create mode 100644 libjava/classpath/gnu/java/util/prefs/FileBasedPreferences.java
(limited to 'libjava/classpath/gnu/java')
diff --git a/libjava/classpath/gnu/java/awt/peer/GLightweightPeer.java b/libjava/classpath/gnu/java/awt/peer/GLightweightPeer.java
index 25735bb..daaa143d 100644
--- a/libjava/classpath/gnu/java/awt/peer/GLightweightPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/GLightweightPeer.java
@@ -229,9 +229,9 @@ public class GLightweightPeer
public void repaint(long tm, int x, int y, int width, int height)
{
- Component p = comp.getParent ();
- if(p != null)
- p.repaint(tm,x+comp.getX(),y+comp.getY(),width,height);
+ Component p = comp.getParent();
+ if (p != null)
+ p.repaint(tm, x + comp.getX(), y + comp.getY(), width, height);
}
public void requestFocus() {}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkButtonPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkButtonPeer.java
index 054ead6..63d9cd4 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkButtonPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkButtonPeer.java
@@ -1,5 +1,5 @@
/* GtkButtonPeer.java -- Implements ButtonPeer with GTK
- Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -57,7 +57,10 @@ public class GtkButtonPeer extends GtkComponentPeer
public native void connectSignals ();
- native void gtkWidgetModifyFont (String name, int style, int size);
+ /**
+ * Overridden to set Font of Label inside Button inside EventBox.
+ */
+ protected native void gtkWidgetModifyFont(String name, int style, int size);
native void gtkSetLabel (String label);
native void gtkWidgetSetForeground (int red, int green, int blue);
native void gtkWidgetSetBackground (int red, int green, int blue);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java
index 01a6e31..be9247e 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java
@@ -1,5 +1,5 @@
/* GtkCheckboxMenuItemPeer.java -- Implements CheckboxMenuItemPeer with GTK+
- Copyright (C) 1999, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -46,7 +46,7 @@ import java.awt.peer.CheckboxMenuItemPeer;
public class GtkCheckboxMenuItemPeer extends GtkMenuItemPeer
implements CheckboxMenuItemPeer
{
- native void create (String label);
+ protected native void create (String label);
public GtkCheckboxMenuItemPeer (CheckboxMenuItem menu)
{
@@ -56,6 +56,11 @@ public class GtkCheckboxMenuItemPeer extends GtkMenuItemPeer
public native void setState(boolean t);
+ /**
+ * Called from the signal handler of the gtk widget. Posts a
+ * ItemEvent to indicate a state changed, then calls super to post
+ * an ActionEvent.
+ */
protected void postMenuActionEvent ()
{
CheckboxMenuItem item = (CheckboxMenuItem)awtWidget;
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
index 3e05cf8..094aa3c 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
@@ -1,5 +1,5 @@
/* GtkCheckboxPeer.java -- Implements CheckboxPeer with GTK
- Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2002, 2003, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,6 +42,8 @@ import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.peer.CheckboxPeer;
+import java.awt.event.ItemEvent;
+
public class GtkCheckboxPeer extends GtkComponentPeer
implements CheckboxPeer
{
@@ -49,12 +51,15 @@ public class GtkCheckboxPeer extends GtkComponentPeer
public GtkCheckboxGroupPeer old_group;
// The current state of the GTK checkbox.
private boolean currentState;
- private boolean changing = false;
public native void create (GtkCheckboxGroupPeer group);
public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group);
public native void connectSignals ();
- native void gtkWidgetModifyFont (String name, int style, int size);
+
+ /**
+ * Overridden to set Font of label inside button.
+ */
+ protected native void gtkWidgetModifyFont(String name, int style, int size);
native void gtkButtonSetLabel (String label);
native void gtkToggleButtonSetActive (boolean is_active);
@@ -71,23 +76,24 @@ public class GtkCheckboxPeer extends GtkComponentPeer
CheckboxGroup g = checkbox.getCheckboxGroup ();
old_group = GtkCheckboxGroupPeer.getCheckboxGroupPeer (g);
create (old_group);
- gtkToggleButtonSetActive (checkbox.getState ());
+ currentState = checkbox.getState();
+ gtkToggleButtonSetActive(currentState);
gtkButtonSetLabel (checkbox.getLabel ());
}
- public void setState (boolean state)
+ /**
+ * Sets native GtkCheckButton is state is different from current
+ * state. Will set currentState to state to prevent posting an
+ * event since events should only be posted for user initiated
+ * clicks on the GtkCheckButton.
+ */
+ synchronized public void setState (boolean state)
{
- // prevent item_toggled_cb -> postItemEvent ->
- // awtComponent.setState -> this.setState ->
- // gtkToggleButtonSetActive self-deadlock on the GDK lock.
- if (changing && Thread.currentThread() == GtkToolkit.mainThread)
+ if (currentState != state)
{
- changing = false;
- return;
+ currentState = state;
+ gtkToggleButtonSetActive(state);
}
-
- if (currentState != state)
- gtkToggleButtonSetActive (state);
}
public void setLabel (String label)
@@ -111,22 +117,15 @@ public class GtkCheckboxPeer extends GtkComponentPeer
// Override the superclass postItemEvent so that the peer doesn't
// need information that we have.
// called back by native side: item_toggled_cb
- public void postItemEvent (Object item, int stateChange)
+ synchronized public void postItemEvent(Object item, boolean state)
{
- Checkbox currentCheckBox = ((Checkbox)awtComponent);
- // A firing of the event is only desired if the state has changed due to a
- // button press. The currentCheckBox's state must be different from the
- // one that the stateChange is changing to.
- // stateChange = 1 if it goes from false -> true
- // stateChange = 2 if it goes from true -> false
- if (( !currentCheckBox.getState() && stateChange == 1)
- || (currentCheckBox.getState() && stateChange == 2))
- {
- super.postItemEvent (awtComponent, stateChange);
- currentState = !currentCheckBox.getState();
- changing = true;
- currentCheckBox.setState(currentState);
- }
+ // Only fire event is state actually changed.
+ if (currentState != state)
+ {
+ currentState = state;
+ super.postItemEvent(awtComponent,
+ state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
+ }
}
public void dispose ()
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
index fe0dae7..8211839 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
@@ -1,5 +1,6 @@
/* GtkComponentPeer.java -- Implements ComponentPeer with GTK
- Copyright (C) 1998, 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -46,10 +47,10 @@ import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
+import java.awt.EventQueue;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
-import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Insets;
@@ -87,8 +88,6 @@ public class GtkComponentPeer extends GtkGenericPeer
boolean isInRepaint;
- static final Timer repaintTimer = new Timer (true);
-
/* this isEnabled differs from Component.isEnabled, in that it
knows if a parent is disabled. In that case Component.isEnabled
may return true, but our isEnabled will always return false */
@@ -146,12 +145,7 @@ public class GtkComponentPeer extends GtkGenericPeer
Component parent = awtComponent.getParent ();
- // Only set our parent on the GTK side if our parent on the AWT
- // side is not showing. Otherwise the gtk peer will be shown
- // before we've had a chance to position and size it properly.
- if (awtComponent instanceof Window
- || (parent != null && ! parent.isShowing ()))
- setParentAndBounds ();
+ setParentAndBounds ();
setNativeEventMask ();
@@ -202,11 +196,6 @@ public class GtkComponentPeer extends GtkGenericPeer
void setComponentBounds ()
{
Rectangle bounds = awtComponent.getBounds ();
-
- if (bounds.x == 0 && bounds.y == 0
- && bounds.width == 0 && bounds.height == 0)
- return;
-
setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
}
@@ -303,29 +292,29 @@ public class GtkComponentPeer extends GtkGenericPeer
{
case PaintEvent.PAINT:
case PaintEvent.UPDATE:
- {
- try
- {
- Graphics g = getGraphics ();
-
- // Some peers like GtkFileDialogPeer are repainted by Gtk itself
- if (g == null)
- break;
-
- g.setClip (((PaintEvent) event).getUpdateRect());
-
- if (id == PaintEvent.PAINT)
- awtComponent.paint (g);
- else
- awtComponent.update (g);
-
- g.dispose ();
- }
- catch (InternalError e)
- {
- System.err.println (e);
- }
- }
+ {
+ try
+ {
+ Graphics g = getGraphics();
+
+ if (!awtComponent.isShowing() || awtComponent.getWidth() < 1
+ || awtComponent.getHeight() < 1 || g == null)
+ break;
+
+ g.setClip(((PaintEvent) event).getUpdateRect());
+
+ if (id == PaintEvent.PAINT)
+ awtComponent.paint(g);
+ else
+ awtComponent.update(g);
+
+ g.dispose();
+ }
+ catch (InternalError e)
+ {
+ System.err.println(e);
+ }
+ }
break;
case KeyEvent.KEY_PRESSED:
ke = (KeyEvent) event;
@@ -383,19 +372,30 @@ public class GtkComponentPeer extends GtkGenericPeer
if (x == 0 && y == 0 && width == 0 && height == 0)
return;
- repaintTimer.schedule(new RepaintTimerTask(x, y, width, height), tm);
+ if (tm <= 0)
+ q().postEvent(new PaintEvent(awtComponent, PaintEvent.UPDATE,
+ new Rectangle(x, y, width, height)));
+ else
+ RepaintTimerTask.schedule(tm, x, y, width, height, awtComponent);
}
- private class RepaintTimerTask extends TimerTask
+ /**
+ * Used for scheduling delayed paint updates on the event queue.
+ */
+ private static class RepaintTimerTask extends TimerTask
{
+ private static final Timer repaintTimer = new Timer(true);
+
private int x, y, width, height;
+ private Component awtComponent;
- RepaintTimerTask(int x, int y, int width, int height)
+ RepaintTimerTask(Component c, int x, int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
+ this.awtComponent = c;
}
public void run()
@@ -403,6 +403,12 @@ public class GtkComponentPeer extends GtkGenericPeer
q().postEvent (new PaintEvent (awtComponent, PaintEvent.UPDATE,
new Rectangle (x, y, width, height)));
}
+
+ static void schedule(long tm, int x, int y, int width, int height,
+ Component c)
+ {
+ repaintTimer.schedule(new RepaintTimerTask(c, x, y, width, height), tm);
+ }
}
public void requestFocus ()
@@ -429,8 +435,7 @@ public class GtkComponentPeer extends GtkGenericPeer
int new_y = y;
Component parent = awtComponent.getParent ();
- Component next_parent;
-
+
// Heavyweight components that are children of one or more
// lightweight containers have to be handled specially. Because
// calls to GLightweightPeer.setBounds do nothing, GTK has no
@@ -441,33 +446,19 @@ public class GtkComponentPeer extends GtkGenericPeer
// so we need to continue adding offsets until we reach a
// container whose position GTK knows -- that is, the first
// non-lightweight.
- boolean lightweightChild = false;
- Insets i;
- while (parent.isLightweight ())
+ Insets i;
+ while (parent.isLightweight())
{
- lightweightChild = true;
-
- next_parent = parent.getParent ();
-
- i = ((Container) parent).getInsets ();
-
- if (next_parent instanceof Window)
- {
- new_x += i.left;
- new_y += i.top;
- }
- else
- {
- new_x += parent.getX () + i.left;
- new_y += parent.getY () + i.top;
- }
-
- parent = next_parent;
+ i = ((Container) parent).getInsets();
+
+ new_x += parent.getX() + i.left;
+ new_y += parent.getY() + i.top;
+
+ parent = parent.getParent();
}
-
// We only need to convert from Java to GTK coordinates if we're
// placing a heavyweight component in a Window.
- if (parent instanceof Window && !lightweightChild)
+ if (parent instanceof Window)
{
GtkWindowPeer peer = (GtkWindowPeer) parent.getPeer ();
// important: we want the window peer's insets here, not the
@@ -479,12 +470,17 @@ public class GtkComponentPeer extends GtkGenericPeer
int menuBarHeight = 0;
if (peer instanceof GtkFramePeer)
menuBarHeight = ((GtkFramePeer) peer).getMenuBarHeight ();
-
- new_x = x - insets.left;
- new_y = y - insets.top + menuBarHeight;
+
+ new_x -= insets.left;
+ new_y -= insets.top;
+ new_y += menuBarHeight;
}
setNativeBounds (new_x, new_y, width, height);
+
+ // If the height or width were (or are now) smaller than zero
+ // then we want to adjust the visibility.
+ setVisible(awtComponent.isVisible());
}
void setCursor ()
@@ -535,6 +531,13 @@ public class GtkComponentPeer extends GtkGenericPeer
public void setVisible (boolean b)
{
+ // Only really set visible when component is bigger than zero pixels.
+ if (b)
+ {
+ Rectangle bounds = awtComponent.getBounds();
+ b = (bounds.width > 0) && (bounds.height > 0);
+ }
+
if (Thread.currentThread() == GtkToolkit.mainThread)
setVisibleNativeUnlocked (b);
else
@@ -571,6 +574,8 @@ public class GtkComponentPeer extends GtkGenericPeer
KeyEvent keyEvent = new KeyEvent (awtComponent, id, when, mods,
keyCode, keyChar, keyLocation);
+ EventQueue q = q();
+
// Also post a KEY_TYPED event if keyEvent is a key press that
// doesn't represent an action or modifier key.
if (keyEvent.getID () == KeyEvent.KEY_PRESSED
@@ -579,15 +584,17 @@ public class GtkComponentPeer extends GtkGenericPeer
&& keyCode != KeyEvent.VK_CONTROL
&& keyCode != KeyEvent.VK_ALT))
{
- synchronized (q)
- {
- q().postEvent (keyEvent);
- q().postEvent (new KeyEvent (awtComponent, KeyEvent.KEY_TYPED, when, mods,
- KeyEvent.VK_UNDEFINED, keyChar, keyLocation));
+ synchronized(q)
+ {
+ q.postEvent(keyEvent);
+ keyEvent = new KeyEvent(awtComponent, KeyEvent.KEY_TYPED, when,
+ mods, KeyEvent.VK_UNDEFINED, keyChar,
+ keyLocation);
+ q.postEvent(keyEvent);
}
}
else
- q().postEvent (keyEvent);
+ q.postEvent(keyEvent);
}
protected void postFocusEvent (int id, boolean temporary)
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkContainerPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkContainerPeer.java
index b035a98..23737b0 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkContainerPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkContainerPeer.java
@@ -1,5 +1,5 @@
/* GtkContainerPeer.java -- Implements ContainerPeer with GTK
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -65,29 +65,6 @@ public class GtkContainerPeer extends GtkComponentPeer
public void endValidate ()
{
- Component parent = awtComponent.getParent ();
-
- // Only set our parent on the GTK side if our parent on the AWT
- // side is not showing. Otherwise the gtk peer will be shown
- // before we've had a chance to position and size it properly.
- if (parent != null && parent.isShowing ())
- {
- Component[] components = ((Container) awtComponent).getComponents ();
- int ncomponents = components.length;
-
- for (int i = 0; i < ncomponents; i++)
- {
- ComponentPeer peer = components[i].getPeer ();
-
- // Skip lightweight peers.
- if (peer instanceof GtkComponentPeer)
- ((GtkComponentPeer) peer).setParentAndBounds ();
- }
-
- // GTK windows don't have parents.
- if (!(awtComponent instanceof Window))
- setParentAndBounds ();
- }
}
public Insets getInsets()
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java
index 333407b..a0ae9e9 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java
@@ -41,8 +41,6 @@ package gnu.java.awt.peer.gtk;
import java.awt.Dialog;
import java.awt.FileDialog;
import java.awt.Graphics;
-import java.awt.Window;
-import java.awt.event.ComponentEvent;
import java.awt.peer.FileDialogPeer;
import java.io.File;
import java.io.FilenameFilter;
@@ -68,7 +66,8 @@ public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
((FileDialog) awtComponent).getMode());
FileDialog fd = (FileDialog) awtComponent;
-
+
+ nativeSetDirectory(System.getProperty("user.dir"));
setDirectory(fd.getDirectory());
setFile(fd.getFile());
@@ -117,13 +116,9 @@ public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
// is not absolute, let's construct it based on current directory.
currentFile = fileName;
if (fileName.indexOf(FS) == 0)
- {
- nativeSetFile (fileName);
- }
+ nativeSetFile(fileName);
else
- {
- nativeSetFile (nativeGetDirectory() + FS + fileName);
- }
+ nativeSetFile(nativeGetDirectory() + FS + fileName);
}
public void setDirectory (String directory)
@@ -132,18 +127,24 @@ public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
the only way we have to set the directory in FileDialog is by
calling its setDirectory which will call us back. */
if ((directory == null && currentDirectory == null)
- || (directory != null && directory.equals (currentDirectory)))
+ || (directory != null && directory.equals(currentDirectory)))
return;
- if (directory == null || directory.equals (""))
+ if (directory == null || directory.equals(""))
{
currentDirectory = FS;
- nativeSetFile (FS);
- return;
+ nativeSetDirectory(FS);
+ return;
}
-
+
+ // GtkFileChooser requires absolute directory names. If the given directory
+ // name is not absolute, construct it based on current directory if it is not
+ // null. Otherwise, use FS.
currentDirectory = directory;
- nativeSetDirectory (directory);
+ if (directory.indexOf(FS) == 0)
+ nativeSetDirectory(directory);
+ else
+ nativeSetDirectory(nativeGetDirectory() + FS + directory);
}
public void setFilenameFilter (FilenameFilter filter)
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java
index 99cca0c..f59e781 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java
@@ -43,10 +43,7 @@ import java.awt.Graphics;
import java.awt.Image;
import java.awt.MenuBar;
import java.awt.Rectangle;
-import java.awt.Window;
-import java.awt.event.ComponentEvent;
import java.awt.event.PaintEvent;
-import java.awt.image.ColorModel;
import java.awt.peer.FramePeer;
import java.awt.peer.MenuBarPeer;
@@ -77,7 +74,10 @@ public class GtkFramePeer extends GtkWindowPeer
removeMenuBarPeer ();
insets.top -= menuBarHeight;
menuBarHeight = 0;
- awtComponent.validate ();
+ // if component has already been validated, we need to revalidate.
+ // otherwise, it will be validated when it is shown.
+ if (awtComponent.isValid())
+ awtComponent.validate ();
gtkFixedSetVisible (true);
}
else if (bar != null && menuBar == null)
@@ -92,7 +92,10 @@ public class GtkFramePeer extends GtkWindowPeer
setMenuBarWidth (menuBar, menuBarWidth);
menuBarHeight = getMenuBarHeight ();
insets.top += menuBarHeight;
- awtComponent.validate ();
+ // if component has already been validated, we need to revalidate.
+ // otherwise, it will be validated when it is shown.
+ if (awtComponent.isValid())
+ awtComponent.validate ();
gtkFixedSetVisible (true);
}
else if (bar != null && menuBar != null)
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkGenericPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkGenericPeer.java
index 705eed2..468c46d 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkGenericPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkGenericPeer.java
@@ -1,5 +1,5 @@
/* GtkGenericPeer.java - Has a hashcode. Yuck.
- Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2002, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,23 +39,28 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
import java.awt.EventQueue;
+import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
public class GtkGenericPeer
{
+ // Used by Native State Association (NSA) functions to map
+ // gtk_widget to peer object.
final int native_state = getUniqueInteger ();
// Next native state value we will assign.
private static int next_native_state = 0;
// The widget or other java-side object we wrap.
- protected Object awtWidget;
-
- // Global event queue.
- protected static EventQueue q = null;
-
- // Dispose of our native state.
+ protected final Object awtWidget;
+
+ /**
+ * Dispose of our native state. Calls gtk_widget_destroy on the
+ * native widget and removes the awtWidget from the native state
+ * tables. Should be overridden by subclasses if this is not (all)
+ * that needs to be done.
+ */
public native void dispose ();
static EventQueue q ()
@@ -68,12 +73,6 @@ public class GtkGenericPeer
this.awtWidget = awtWidget;
}
- public static void enableQueue (EventQueue sq)
- {
- if (q == null)
- q = sq;
- }
-
protected void postActionEvent (String command, int mods)
{
q().postEvent (new ActionEvent (awtWidget, ActionEvent.ACTION_PERFORMED,
@@ -88,8 +87,20 @@ public class GtkGenericPeer
// Let's assume this will never wrap.
return next_native_state++;
}
+
+ /**
+ * Helper method to set Font for Gtk Widget.
+ */
+ protected void gtkWidgetModifyFont(Font f)
+ {
+ gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize());
+ }
- native void gtkWidgetModifyFont (String name, int style, int size);
+ /**
+ * Sets font for this Gtk Widget. Should be overridden by peers which
+ * are composed of different widgets or are contained in bins.
+ */
+ protected native void gtkWidgetModifyFont(String name, int style, int size);
static void printCurrentThread ()
{
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java
index 82a3463..b48a204 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkImage.java
@@ -1,5 +1,5 @@
/* GtkImage.java
- Copyright (C) 2005 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -329,6 +329,24 @@ public class GtkImage extends Image
props = new Hashtable();
}
+ // The singleton GtkImage that is returned on errors by GtkToolkit.
+ private static GtkImage errorImage;
+
+ /**
+ * Returns an empty GtkImage with the errorLoading flag set.
+ * Called from GtkToolKit when some error occured, but an image needs
+ * to be returned anyway.
+ */
+ static synchronized GtkImage getErrorImage()
+ {
+ if (errorImage == null)
+ {
+ errorImage = new GtkImage();
+ errorImage.errorLoading = true;
+ }
+ return errorImage;
+ }
+
/**
* Native helper function for constructor that takes a pixbuf Pointer.
*/
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java
index 3d099e9..bbf4230 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkLabelPeer.java
@@ -1,5 +1,5 @@
/* GtkLabelPeer.java -- Implements LabelPeer with GTK
- Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -48,7 +48,12 @@ public class GtkLabelPeer extends GtkComponentPeer
implements LabelPeer
{
native void create (String text, float alignment);
- native void gtkWidgetModifyFont (String name, int style, int size);
+
+ /**
+ * Overridden to set the Font of the label inside the gtk_event_box.
+ */
+ protected native void gtkWidgetModifyFont(String name, int style, int size);
+
native void nativeSetAlignment (float alignment);
public native void setText(String text);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java
index ff12fe3..285f794 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkListPeer.java
@@ -1,5 +1,5 @@
/* GtkListPeer.java -- Implements ListPeer with GTK
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -59,7 +59,12 @@ public class GtkListPeer extends GtkComponentPeer
native void create (int rows);
native void connectSignals ();
- native void gtkWidgetModifyFont (String name, int style, int size);
+
+ /**
+ * Overridden to set the Font of the text insode the gtk_scrolled_window.
+ */
+ protected native void gtkWidgetModifyFont (String name, int style, int size);
+
native void gtkWidgetRequestFocus ();
native void getSize (int rows, int visibleRows, int dims[]);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java
index a1a1cbd..d203b43 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java
@@ -1,5 +1,5 @@
/* GtkMenuBarPeer.java -- Implements MenuBarPeer with GTK+
- Copyright (C) 1999, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -48,38 +48,69 @@ import java.awt.peer.MenuPeer;
public class GtkMenuBarPeer extends GtkMenuComponentPeer
implements MenuBarPeer
{
-
- native void create ();
- native void addMenu (MenuPeer menu);
-
- public GtkMenuBarPeer (MenuBar target)
+ /** Whether we already have an help menu set on this peer. */
+ private boolean hasHelpMenu;
+
+ /**
+ * Creates the gtk+ widget for this peer and puts it in the nsa
+ * table. Called from the (super class) constructor.
+ */
+ protected native void create();
+
+ /**
+ * Adds a new GtkMenuPeer to the end of the GtkMenuBarPeer.
+ */
+ private native void addMenu(GtkMenuPeer menu);
+
+ /**
+ * Creates a new GtkMenuBarPeer associated with the given MenuBar.
+ */
+ public GtkMenuBarPeer(MenuBar menubar)
{
- super (target);
+ super(menubar);
}
- void setFont ()
- {
- MenuComponent mc = (MenuComponent) awtWidget;
- Font f = mc.getFont ();
-
- if (f == null)
- mc.setFont (new Font ("Dialog", Font.PLAIN, 12));
- }
-
- // FIXME: remove this method or replace it with one that does
- // something useful.
- /* In Gnome, help menus are no longer right flushed. */
- native void nativeSetHelpMenu(MenuPeer menuPeer);
-
+ /**
+ * Adds a help menu to this MenuBar. Gnome styleguides say the help
+ * menu is just the last item in the menubar (they are NOT right
+ * justified).
+ */
public void addHelpMenu (Menu menu)
{
- // nativeSetHelpMenu((MenuPeer) menu.getPeer());
+ if (hasHelpMenu)
+ {
+ // Remove the (help) menu, which is after all the other items.
+ delMenu(((MenuBar) awtWidget).getMenuCount());
+ hasHelpMenu = false;
+ }
+
+ if (menu != null)
+ {
+ addMenu(menu);
+ hasHelpMenu = true;
+ }
}
+ /**
+ * Deletes the menu at (zero-based) index from this GtkMenuBar.
+ */
public native void delMenu(int index);
- public void addMenu (Menu m)
+ /**
+ * Adds the GtkMenuPeer associated with the Menu to this
+ * GtkMenuBarPeer. Makes sure that any help menus keep the last menu
+ * on the bar.
+ */
+ public void addMenu(Menu m)
{
- // FIXME: implement
+ // Make sure the help menu is the last one.
+ if (hasHelpMenu)
+ {
+ addHelpMenu(null);
+ addMenu((GtkMenuPeer) m.getPeer());
+ addHelpMenu(((MenuBar) awtWidget).getHelpMenu());
+ }
+ else
+ addMenu((GtkMenuPeer) m.getPeer());
}
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
index 4c63359..55b95a1 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
@@ -1,5 +1,5 @@
/* GtkMenuComponentPeer.java -- Implements MenuComponentPeer with GTK+
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,31 +39,66 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
import java.awt.Font;
+import java.awt.MenuComponent;
+import java.awt.MenuContainer;
import java.awt.peer.MenuComponentPeer;
-public class GtkMenuComponentPeer extends GtkGenericPeer
+public abstract class GtkMenuComponentPeer extends GtkGenericPeer
implements MenuComponentPeer
{
- void create ()
- {
- throw new RuntimeException ();
- }
+ /**
+ * Creates the associated gtk+ widget and stores it in the nsa table
+ * for this peer. Called by the constructor.
+ */
+ protected abstract void create ();
- void setFont ()
+ /**
+ * Sets font based on MenuComponent font, or containing menu(bar)
+ * parent font.
+ */
+ private void setFont()
{
+ MenuComponent mc = ((MenuComponent) awtWidget);
+ Font f = mc.getFont();
+
+ if (f == null)
+ {
+ MenuContainer parent = mc.getParent ();
+ // Submenus inherit the font of their containing Menu(Bar).
+ if (parent instanceof MenuComponent)
+ f = parent.getFont ();
+ }
+
+ setFont(f);
}
- public GtkMenuComponentPeer (Object awtWidget)
+ /**
+ * Will call the abstract This package defines an abstract set of AWT peers that is based on Swing
+ widgets. This can be used as an implementation base for peer implementors
+ who don't have access to native widgets or who want to build a quick
+ prototype of a peer set without implementing all of the AWT widgets.
+ An actual implementation would have to provide the following:
+ create()
that needs to be
+ * overridden by subclasses, to create the MenuComponent. It will
+ * then correctly setup the font for the component based on the
+ * component and/or its containing parent component.
+ */
+ public GtkMenuComponentPeer(MenuComponent component)
{
- super (awtWidget);
- create ();
- setFont ();
+ super(component);
+ create();
+ setFont();
}
+ /**
+ * Removes the awtWidget components from the native state tables.
+ * Subclasses should call super.dispose()
if they don't
+ * remove these themselves.
+ */
public native void dispose();
+ /**
+ * Sets the font for this particular MenuComponent only (not any
+ * containing items, if any).
+ */
public void setFont(Font font)
{
- // FIXME: implement
+ if (font != null)
+ gtkWidgetModifyFont(font);
}
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuItemPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuItemPeer.java
index 5728f26..251bab2 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuItemPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuItemPeer.java
@@ -1,5 +1,5 @@
/* GtkMenuItemPeer.java -- Implements MenuItemPeer with GTK+
- Copyright (C) 1999, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,70 +49,71 @@ import java.awt.peer.MenuPeer;
public class GtkMenuItemPeer extends GtkMenuComponentPeer
implements MenuItemPeer
{
- native void create (String label);
- native void connectSignals ();
- native void gtkWidgetModifyFont (String name, int style, int size);
-
- void create ()
+ /**
+ * Creates the associated gtk+ widget and stores it in the nsa table
+ * for this peer. Called by the create() method with the label name
+ * of the associated MenuItem. Needs to be overridden my subclasses
+ * that want to create a different gtk+ widget.
+ */
+ protected native void create (String label);
+
+ /**
+ * Called from constructor to enable signals from an item. If a
+ * subclass needs different (or no) signals connected this method
+ * should be overridden.
+ */
+ protected native void connectSignals ();
+
+ /**
+ * Overridden to set font on menu item label.
+ */
+ protected native void gtkWidgetModifyFont(String name, int style, int size);
+
+ /**
+ * Creates the associated gtk+ widget and stores it in the nsa table
+ * for this peer. Called by the (super class) constructor.
+ * Overridden to get the label if the assiociated MenuItem and to
+ * call create(String).
+ */
+ protected void create()
{
create (((MenuItem) awtWidget).getLabel());
}
- public GtkMenuItemPeer (MenuItem item)
- {
- super (item);
- setEnabled (item.isEnabled ());
- setParent (item);
-
- if (item.getParent() instanceof Menu && ! (item instanceof Menu))
- connectSignals();
- }
-
- void setFont ()
+ /**
+ * Creates a new GtkMenuItemPeer associated with the given MenuItem.
+ * It will call create(), setFont(), setEnabled() and
+ * connectSignals() in that order.
+ */
+ public GtkMenuItemPeer(MenuItem item)
{
- MenuComponent mc = ((MenuComponent) awtWidget);
- Font f = mc.getFont ();
-
- if (f == null)
- {
- MenuComponent parent = (MenuComponent) mc.getParent ();
- Font pf = parent.getFont ();
- gtkWidgetModifyFont (pf.getName (), pf.getStyle (), pf.getSize ());
- }
- else
- gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize());
+ super(item);
+ setEnabled (item.isEnabled());
+ connectSignals();
}
- void setParent (MenuItem item)
+ /**
+ * Calls setEnabled(false).
+ */
+ public void disable()
{
- // add ourself differently, based on what type of parent we have
- // yes, the typecasting here is nasty.
- Object parent = item.getParent ();
- if (parent instanceof MenuBar)
- {
- ((GtkMenuBarPeer)((MenuBar)parent).getPeer ()).addMenu ((MenuPeer) this);
- }
- else // parent instanceof Menu
- {
- ((GtkMenuPeer)((Menu)parent).getPeer ()).addItem (this,
- item.getShortcut ());
- }
+ setEnabled(false);
}
- public void disable ()
+ /**
+ * Calls setEnabled(true).
+ */
+ public void enable()
{
- setEnabled (false);
- }
-
- public void enable ()
- {
- setEnabled (true);
+ setEnabled(true);
}
public native void setEnabled(boolean b);
-
public native void setLabel(String label);
+ /**
+ * Callback setup through connectSignals().
+ */
protected void postMenuActionEvent ()
{
postActionEvent (((MenuItem)awtWidget).getActionCommand (), 0);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java
index fabcf1f..1d581c1 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkMenuPeer.java
@@ -1,5 +1,5 @@
/* GtkMenuPeer.java -- Implements MenuPeer with GTK+
- Copyright (C) 1999, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,28 @@ import java.awt.peer.MenuPeer;
public class GtkMenuPeer extends GtkMenuItemPeer
implements MenuPeer
{
- native void create (String label);
- native void addItem (MenuItemPeer item, int key, boolean shiftModifier);
+ /**
+ * Creates the associated gtk+ widget and stores it in the nsa table
+ * for this peer. Called by the create() method with the label name
+ * of the associated MenuItem. Overridden to greate a Menu widget.
+ */
+ protected native void create (String label);
+
+ private native void addItem(MenuItemPeer item, int key,
+ boolean shiftModifier);
+
+ /** XXX - Document this and the override in GtkPopupMenuPeer. */
native void setupAccelGroup (GtkGenericPeer container);
- native void addTearOff ();
+
+ private native void addTearOff ();
+
+ /**
+ * Overridden to not connect any signals.
+ */
+ protected void connectSignals()
+ {
+ // No signals to connect.
+ }
public GtkMenuPeer (Menu menu)
{
@@ -63,11 +81,11 @@ public class GtkMenuPeer extends GtkMenuItemPeer
MenuContainer parent = menu.getParent ();
if (parent instanceof Menu)
- setupAccelGroup ((GtkGenericPeer)((Menu)parent).getPeer ());
+ setupAccelGroup ((GtkMenuPeer)((Menu)parent).getPeer ());
else if (parent instanceof Component)
- setupAccelGroup ((GtkGenericPeer)((Component)parent).getPeer ());
+ setupAccelGroup ((GtkComponentPeer)((Component)parent).getPeer ());
else
- setupAccelGroup (null);
+ setupAccelGroup (null); // XXX, should we warn about unknown parent?
}
public void addItem (MenuItem item)
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkPanelPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkPanelPeer.java
index fb5adde..88bb715 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkPanelPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkPanelPeer.java
@@ -39,8 +39,11 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
import java.awt.AWTEvent;
+import java.awt.Graphics;
import java.awt.Panel;
+import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
+import java.awt.event.PaintEvent;
import java.awt.peer.PanelPeer;
public class GtkPanelPeer extends GtkContainerPeer
@@ -53,17 +56,39 @@ public class GtkPanelPeer extends GtkContainerPeer
super (p);
}
- public void handleEvent (AWTEvent event)
+ public void handleEvent(AWTEvent event)
{
int id = event.getID();
-
switch (id)
{
case MouseEvent.MOUSE_PRESSED:
- awtComponent.requestFocusInWindow ();
+ awtComponent.requestFocusInWindow();
break;
+ case PaintEvent.UPDATE:
+ case PaintEvent.PAINT:
+ {
+ try
+ {
+ Graphics g = getGraphics();
+ if (! awtComponent.isShowing() || awtComponent.getWidth() < 1
+ || awtComponent.getHeight() < 1 || g == null)
+ return;
+
+ g.setClip(((PaintEvent) event).getUpdateRect());
+
+ // Do not want to clear anything before painting.);
+ awtComponent.paint(g);
+
+ g.dispose();
+ return;
+ }
+ catch (InternalError e)
+ {
+ System.err.println(e);
+ }
+ }
}
- super.handleEvent (event);
+ super.handleEvent(event);
}
native void connectSignals ();
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkPopupMenuPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkPopupMenuPeer.java
index d14c16d..525a910 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkPopupMenuPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkPopupMenuPeer.java
@@ -1,5 +1,5 @@
/* GtkPopupMenuPeer.java -- Implements PopupMenuPeer with GTK+
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -55,11 +55,6 @@ public class GtkPopupMenuPeer extends GtkMenuPeer
native void setupAccelGroup (GtkGenericPeer container);
- void setParent (MenuItem item)
- {
- // we don't need to "add" ourselves to our parent
- }
-
native void show (int x, int y, long time);
public void show (Component origin, int x, int y)
{
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java
index aa3a26e..9b31a73 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java
@@ -1,5 +1,5 @@
/* GtkScrollbarPeer.java -- Implements ScrollbarPeer with GTK+
- Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,6 +39,7 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
import java.awt.Adjustable;
+import java.awt.EventQueue;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.peer.ScrollbarPeer;
@@ -69,12 +70,25 @@ public class GtkScrollbarPeer extends GtkComponentPeer
public native void setLineIncrement(int amount);
public native void setPageIncrement(int amount);
- public native void setValues(int value, int visible, int min, int max);
+ public void setValues(int value, int visible, int min, int max)
+ {
+ Scrollbar sb = (Scrollbar) awtComponent;
+ if (!sb.getValueIsAdjusting())
+ setBarValues(value, visible, min, max);
+ }
+
+ private native void setBarValues(int value, int visible, int min, int max);
+
+ /**
+ * Called from the native site when the scrollbar changed.
+ * Posts a "user generated" AdjustmentEvent to the queue.
+ */
protected void postAdjustmentEvent (int type, int value)
{
- q().postEvent (new AdjustmentEvent ((Adjustable)awtComponent,
+ Scrollbar bar = (Scrollbar) awtComponent;
+ q().postEvent(new AdjustmentEvent(bar,
AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
- type, value));
+ type, value, true));
}
}
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
index e6896c9..5d9be1a 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
@@ -55,7 +55,11 @@ public class GtkTextAreaPeer extends GtkComponentPeer
native void create (int width, int height, int scrollbarVisibility);
- native void gtkWidgetModifyFont (String name, int style, int size);
+ /**
+ * Overridden to set Font for text widget inside scrolled window.
+ */
+ protected native void gtkWidgetModifyFont(String name, int style, int size);
+
native void gtkWidgetRequestFocus ();
public native void connectSignals ();
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java
index 4afdae8..7633048 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java
@@ -112,8 +112,6 @@ public class GtkTextFieldPeer extends GtkComponentPeer
native int gtkEntryGetBorderWidth ();
- native void gtkWidgetModifyFont (String name, int style, int size);
-
public GtkTextFieldPeer (TextField tf)
{
super (tf);
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java
index 0889d85..70e25a3 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java
@@ -1,5 +1,6 @@
/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers
- Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -159,137 +160,93 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
}
/**
- * A helper class to return to clients in cases where a BufferedImage is
- * desired but its construction fails.
+ * Helper to return either a Image -- the argument -- or a
+ * GtkImage with the errorLoading flag set if the argument is null.
*/
- private class GtkErrorImage extends Image
- {
- public GtkErrorImage()
- {
- }
-
- public int getWidth(ImageObserver observer)
- {
- return -1;
- }
-
- public int getHeight(ImageObserver observer)
- {
- return -1;
- }
-
- public ImageProducer getSource()
- {
-
- return new ImageProducer()
- {
- HashSet consumers = new HashSet();
- public void addConsumer(ImageConsumer ic)
- {
- consumers.add(ic);
- }
-
- public boolean isConsumer(ImageConsumer ic)
- {
- return consumers.contains(ic);
- }
-
- public void removeConsumer(ImageConsumer ic)
- {
- consumers.remove(ic);
- }
-
- public void startProduction(ImageConsumer ic)
- {
- consumers.add(ic);
- Iterator i = consumers.iterator();
- while(i.hasNext())
- {
- ImageConsumer c = (ImageConsumer) i.next();
- c.imageComplete(ImageConsumer.IMAGEERROR);
- }
- }
- public void requestTopDownLeftRightResend(ImageConsumer ic)
- {
- startProduction(ic);
- }
- };
- }
-
- public Graphics getGraphics()
- {
- return null;
- }
-
- public Object getProperty(String name, ImageObserver observer)
- {
- return null;
- }
- public Image getScaledInstance(int width, int height, int flags)
- {
- return new GtkErrorImage();
- }
-
- public void flush()
- {
- }
- }
-
-
- /**
- * Helper to return either a BufferedImage -- the argument -- or a
- * GtkErrorImage if the argument is null.
- */
-
- private Image bufferedImageOrError(BufferedImage b)
+ private Image imageOrError(Image b)
{
if (b == null)
- return new GtkErrorImage();
+ return GtkImage.getErrorImage();
else
return b;
}
-
public Image createImage (String filename)
{
if (filename.length() == 0)
return new GtkImage ();
-
- if (useGraphics2D())
- return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (filename));
- else
- return new GtkImage (filename);
+
+ Image image;
+ try
+ {
+ if (useGraphics2D())
+ image = GdkPixbufDecoder.createBufferedImage(filename);
+ else
+ image = new GtkImage(filename);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ image = null;
+ }
+ return imageOrError(image);
}
public Image createImage (URL url)
{
- if (useGraphics2D())
- return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (url));
- else
- return new GtkImage (url);
+ Image image;
+ try
+ {
+ if (useGraphics2D())
+ image = GdkPixbufDecoder.createBufferedImage(url);
+ else
+ image = new GtkImage(url);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ image = null;
+ }
+ return imageOrError(image);
}
public Image createImage (ImageProducer producer)
{
- if (useGraphics2D())
- return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (producer));
- else
- return new GtkImage (producer);
+ Image image;
+ try
+ {
+ if (useGraphics2D())
+ image = GdkPixbufDecoder.createBufferedImage(producer);
+ else
+ image = new GtkImage(producer);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ image = null;
+ }
+ return imageOrError(image);
}
public Image createImage (byte[] imagedata, int imageoffset,
int imagelength)
{
- if (useGraphics2D())
- return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (imagedata,
- imageoffset,
- imagelength));
- else
+ Image image;
+ try
+ {
+ if (useGraphics2D())
+ image = GdkPixbufDecoder.createBufferedImage(imagedata,
+ imageoffset,
+ imagelength);
+ else
+ {
+ byte[] datacopy = new byte[imagelength];
+ System.arraycopy(imagedata, imageoffset, datacopy, 0, imagelength);
+ return new GtkImage(datacopy);
+ }
+ }
+ catch (IllegalArgumentException iae)
{
- byte[] datacopy = new byte[imagelength];
- System.arraycopy (imagedata, imageoffset, datacopy, 0, imagelength);
- return new GtkImage (datacopy);
+ image = null;
}
+ return imageOrError(image);
}
/**
@@ -608,7 +565,6 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
if (q == null)
{
q = new EventQueue();
- GtkGenericPeer.enableQueue (q);
}
}
return q;
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java
index 57fb87f..6cc1390 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java
@@ -38,9 +38,12 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
+import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Frame;
+import java.awt.Graphics;
import java.awt.Window;
+import java.awt.event.PaintEvent;
import java.awt.event.WindowEvent;
import java.awt.peer.WindowPeer;
@@ -123,7 +126,23 @@ public class GtkWindowPeer extends GtkContainerPeer
native void nativeSetBounds (int x, int y, int width, int height);
native void nativeSetBoundsUnlocked (int x, int y, int width, int height);
+ native void nativeSetLocation (int x, int y);
+ native void nativeSetLocationUnlocked (int x, int y);
+ public void setLocation (int x, int y)
+ {
+ // prevent window_configure_cb -> awtComponent.setSize ->
+ // peer.setBounds -> nativeSetBounds self-deadlock on GDK lock.
+ if (Thread.currentThread() == GtkToolkit.mainThread)
+ return;
+ nativeSetLocation (x, y);
+ }
+
+ public void setLocationUnlocked (int x, int y)
+ {
+ nativeSetLocationUnlocked (x, y);
+ }
+
public void setBounds (int x, int y, int width, int height)
{
// prevent window_configure_cb -> awtComponent.setSize ->
@@ -192,12 +211,7 @@ public class GtkWindowPeer extends GtkContainerPeer
public void show ()
{
- // Prevent the window manager from automatically placing this
- // window when it is shown.
- setBounds (awtComponent.getX(),
- awtComponent.getY(),
- awtComponent.getWidth(),
- awtComponent.getHeight());
+ setLocation(awtComponent.getX(), awtComponent.getY());
setVisible (true);
}
@@ -235,4 +249,32 @@ public class GtkWindowPeer extends GtkContainerPeer
// TODO Auto-generated method stub
return false;
}
+
+ public void handleEvent(AWTEvent event)
+ {
+ int id = event.getID();
+ if (id == PaintEvent.UPDATE || id == PaintEvent.PAINT)
+ {
+ try
+ {
+ Graphics g = getGraphics();
+ if (! awtComponent.isShowing() || awtComponent.getWidth() < 1
+ || awtComponent.getHeight() < 1 || g == null)
+ return;
+
+ g.setClip(((PaintEvent) event).getUpdateRect());
+
+ // Do not want to clear anything before painting.
+ awtComponent.paint(g);
+
+ g.dispose();
+ return;
+ }
+ catch (InternalError e)
+ {
+ System.err.println(e);
+ }
+ }
+ super.handleEvent(event);
+ }
}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java
new file mode 100644
index 0000000..2357fcb
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingButtonPeer.java
@@ -0,0 +1,224 @@
+/* SwingButtonPeer.java -- A Swing based peer for AWT buttons
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Button;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.peer.ButtonPeer;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+
+/**
+ * A Swing based peer for the AWT button.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingButtonPeer
+ extends SwingComponentPeer
+ implements ButtonPeer
+{
+
+ /**
+ * A specialized Swing button to be used as AWT button.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ class SwingButton
+ extends JButton
+ implements SwingComponent
+ {
+ /**
+ * Overridden so that this method returns the correct value even without a
+ * peer.
+ *
+ * @return the screen location of the button
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingButtonPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value for the
+ * swing button, even if it has no peer on its own.
+ *
+ * @return true
if the button is currently showing,
+ * false
otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (SwingButtonPeer.this.awtComponent != null)
+ retVal = SwingButtonPeer.this.awtComponent.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingButtonPeer.this.createImage(w, h);
+ }
+
+ /**
+ * Overridden, so that the Swing button can create a Graphics without its
+ * own peer.
+ *
+ * @return a graphics instance for the button
+ */
+ public Graphics getGraphics()
+ {
+ return SwingButtonPeer.this.getGraphics();
+ }
+
+ /**
+ * Returns this button.
+ *
+ * @return this button
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * processMouseEvent()
after having retargetted it to this
+ * button.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to
+ * processMouseMotionEvent()
after having retargetted it to
+ * this button.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to
+ * processKeyEvent()
after having retargetted it to this
+ * button.
+ *
+ * @param ev the mouse event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ ev.setSource(this);
+ processKeyEvent(ev);
+ }
+ }
+
+ /**
+ * Listens for ActionEvents on the Swing button and triggers corresponding
+ * ActionEvents on the AWT button.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ class SwingButtonListener implements ActionListener
+ {
+
+ /**
+ * Receives notification when an action was performend on the button.
+ *
+ * @param event the action event
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ Button b = (Button) SwingButtonPeer.this.awtComponent;
+ ActionListener[] l = b.getActionListeners();
+ if (l.length == 0)
+ return;
+ ActionEvent ev = new ActionEvent(b, ActionEvent.ACTION_PERFORMED,
+ b.getActionCommand());
+ for (int i = 0; i < l.length; ++i)
+ l[i].actionPerformed(ev);
+ }
+
+ }
+
+ /**
+ * Constructs a new SwingButtonPeer.
+ *
+ * @param theButton the AWT button for this peer
+ */
+ public SwingButtonPeer(Button theButton)
+ {
+ SwingButton button = new SwingButton();
+ button.setText(theButton.getLabel());
+ button.addActionListener(new SwingButtonListener());
+ init(theButton, button);
+ }
+
+ /**
+ * Sets the label of the button. This call is forwarded to the setText method
+ * of the managed Swing button.
+ *
+ * @param label the label to set
+ */
+ public void setLabel(String label)
+ {
+ ((SwingButton) swingComponent).setText(label);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingCanvasPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingCanvasPeer.java
new file mode 100644
index 0000000..abef9ef
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingCanvasPeer.java
@@ -0,0 +1,64 @@
+/* SwingCanvasPeer.java -- A canvas peer based on Swing
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Canvas;
+import java.awt.peer.CanvasPeer;
+import java.awt.peer.LightweightPeer;
+
+/**
+ * A CanvasPeer to be used together with the Swing peers.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingCanvasPeer
+ extends SwingComponentPeer
+ implements LightweightPeer, CanvasPeer
+{
+
+ /**
+ * Creates a new SwingCanvasPeer
for the specified Canvas.
+ *
+ * @param canvas the canvas.
+ */
+ public SwingCanvasPeer(Canvas canvas)
+ {
+ init(canvas, null);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java
new file mode 100644
index 0000000..04ca729
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponent.java
@@ -0,0 +1,89 @@
+/* SwingComponent.java -- An interface that defines a Swing component for peers
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JComponent;
+
+/**
+ * Defines some additional methods that the Swing components must implement
+ * in order to work with the Swing peers. This is usually achieved by
+ * subclassing a Swing component and forwarding the method calls to some
+ * protected JComponent method.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public interface SwingComponent
+{
+
+ /**
+ * Returns the actual swing compenent.
+ *
+ * @return the actual swing compenent
+ */
+ JComponent getJComponent();
+
+ /**
+ * Handles a mouse event. This is usually forwarded to
+ * {@link Component#processMouseMotionEvent(MouseEvent)} of the swing
+ * component.
+ *
+ * @param ev the mouse event
+ */
+ void handleMouseEvent(MouseEvent ev);
+
+ /**
+ * Handles a mouse motion event. This is usually forwarded to
+ * {@link Component#processMouseEvent(MouseEvent)} of the swing
+ * component.
+ *
+ * @param ev the mouse motion event
+ */
+ void handleMouseMotionEvent(MouseEvent ev);
+
+ /**
+ * Handles a key event. This is usually forwarded to
+ * {@link Component#processKeyEvent(KeyEvent)} of the swing
+ * component.
+ *
+ * @param ev the key event
+ */
+ void handleKeyEvent(KeyEvent ev);
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java
new file mode 100644
index 0000000..5e34bc9
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java
@@ -0,0 +1,994 @@
+/* SwingComponentPeer.java -- An abstract base class for Swing based peers
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.AWTEvent;
+import java.awt.AWTException;
+import java.awt.BufferCapabilities;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.BufferCapabilities.FlipContents;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.PaintEvent;
+import java.awt.image.ColorModel;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.awt.image.VolatileImage;
+import java.awt.peer.ComponentPeer;
+import java.awt.peer.ContainerPeer;
+
+/**
+ * The base class for Swing based component peers. This provides the basic
+ * functionality needed for Swing based component peers. Many methods are
+ * implemented to forward to the Swing component. Others however forward
+ * to the component's parent and expect the toplevel component peer to provide
+ * a real implementation of it. These are for example the key methods
+ * {@link #getGraphics()} and {@link #createImage(int, int)}, as well as
+ * {@link #getLocationOnScreen()}.
+ *
+ * This class also provides the necesary hooks into the Swing painting and
+ * event handling system. In order to achieve this, it traps paint, mouse and
+ * key events in {@link #handleEvent(AWTEvent)} and calls some special methods
+ * ({@link #peerPaint(Graphics)}, {@link #handleKeyEvent(KeyEvent)},
+ * {@link #handleMouseEvent(MouseEvent)} and
+ * {@link #handleMouseMotionEvent(MouseEvent)}) that call the corresponding
+ * Swing methods.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingComponentPeer
+ implements ComponentPeer
+{
+
+ /**
+ * The AWT component for this peer.
+ */
+ protected Component awtComponent;
+
+ /**
+ * The Swing component for this peer.
+ */
+ protected SwingComponent swingComponent;
+
+ /**
+ * Creates a SwingComponentPeer instance. Subclasses are expected to call
+ * this constructor and thereafter call {@link #init(Component, JComponent)}
+ * in order to setup the AWT and Swing components properly.
+ */
+ protected SwingComponentPeer()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Initializes the AWT and Swing component for this peer. It is expected that
+ * subclasses call this from within their constructor.
+ *
+ * @param awtComp the AWT component for this peer
+ * @param swingComp the Swing component for this peer
+ */
+ protected void init(Component awtComp, SwingComponent swingComp)
+ {
+ awtComponent = awtComp;
+ swingComponent = swingComp;
+ }
+
+ /**
+ * Returns the construction status of the specified image. This is called
+ * by {@link Component#checkImage(Image, int, int, ImageObserver)}.
+ *
+ * @param img the image
+ * @param width the width of the image
+ * @param height the height of the image
+ * @param ob the image observer to be notified of updates of the status
+ *
+ * @return a bitwise ORed set of ImageObserver flags
+ */
+ public int checkImage(Image img, int width, int height, ImageObserver ob)
+ {
+ return Toolkit.getDefaultToolkit().checkImage(img, width, height, ob);
+ }
+
+ /**
+ * Creates an image by starting the specified image producer. This is called
+ * by {@link Component#createImage(ImageProducer)}.
+ *
+ * @param prod the image producer to be used to create the image
+ *
+ * @return the created image
+ */
+ public Image createImage(ImageProducer prod)
+ {
+ Image image = Toolkit.getDefaultToolkit().createImage(prod);
+ return image;
+ }
+
+ /**
+ * Creates an empty image with the specified width
and
+ * height
.
+ *
+ * This is implemented to let the parent component create the image. This
+ * eventually goes up to the top-level component peer, which is then expected
+ * to deliver the image.
+ *
+ * @param width the width of the image to be created
+ * @param height the height of the image to be created
+ *
+ * @return the created image
+ */
+ public Image createImage(int width, int height)
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.createImage(width, height);
+ }
+
+ /**
+ * Disables the component. This is called by {@link Component#disable()}.
+ */
+ public void disable()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setEnabled(false);
+ }
+
+ /**
+ * Disposes the component peer. This should release all resources held by the
+ * peer. This is called when the component is no longer in use.
+ */
+ public void dispose()
+ {
+ awtComponent = null;
+ swingComponent = null;
+ }
+
+ /**
+ * Enables the component. This is called by {@link Component#enable()}.
+ */
+ public void enable()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setEnabled(true);
+ }
+
+ /**
+ * Returns the color model of the component. This is currently not used.
+ *
+ * @return the color model of the component
+ */
+ public ColorModel getColorModel()
+ {
+ // FIXME: When this peer method will be used, we need to provide an
+ // implementation of this, probably forwarding to the toplevel peer, like
+ // in the other methods.
+ return null;
+ }
+
+ /**
+ * Returns the font metrics for the specified font. This is called by
+ * {@link Component#getFontMetrics(Font)}.
+ *
+ * This is implemented to query the font metrics from the parent component.
+ * This will eventually call the top-level component peer, which is then
+ * expected to deliver a font metrics object.
+ *
+ * @param f the font for which to query the font metrics
+ *
+ * @return the font metrics for the specified font
+ */
+ public FontMetrics getFontMetrics(Font f)
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.getFontMetrics(f);
+ }
+
+ /**
+ * Returns a {@link Graphics} object suitable for drawing on this component.
+ * This is called by {@link Component#getGraphics()}.
+ *
+ * This is implemented to query the graphics from the parent component and
+ * adjust the clip and translation to match this component.
+ * This will eventually call the top-level component peer, which is then
+ * expected to deliver a graphics object.
+ *
+ * @return a graphics object suitable for drawing on this component
+ */
+ public Graphics getGraphics()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ Graphics g = parentPeer.getGraphics();
+ g.translate(awtComponent.getX(), awtComponent.getY());
+ g.setClip(0, 0, awtComponent.getWidth(), awtComponent.getHeight());
+ return g;
+ }
+
+ /**
+ * Returns the location of this component in screen coordinates. This is
+ * called by {@link Component#getLocationOnScreen()}.
+ *
+ * This is implemented to query the parent component peer for its screen
+ * location and adds the offset of this component to it. This will eventually
+ * call the top-level component's peer, which is then expected to provide
+ * it's screen location.
+ *
+ * @return the location of this component in screen coordinates
+ */
+ public Point getLocationOnScreen()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ Point location = parentPeer.getLocationOnScreen();
+ location.x += awtComponent.getX();
+ location.y += awtComponent.getY();
+ return location;
+ }
+
+ /**
+ * Returns the minimum size for the component. This is called by
+ * {@link Component#getMinimumSize()}.
+ *
+ * This is implemented to return the Swing component's minimum size.
+ *
+ * @return the minimum size for the component
+ */
+ public Dimension getMinimumSize()
+ {
+ Dimension retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getMinimumSize();
+ else
+ retVal = new Dimension(0, 0);
+ return retVal;
+ }
+
+ /**
+ * Returns the preferred size for the component. This is called by
+ * {@link Component#getPreferredSize()}.
+ *
+ * This is implemented to return the Swing component's preferred size.
+ *
+ * @return the preferred size for the component
+ */
+ public Dimension getPreferredSize()
+ {
+ Dimension retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getPreferredSize();
+ else
+ retVal = new Dimension(0, 0);
+ return retVal;
+ }
+
+ /**
+ * Returns the toolkit that created this peer.
+ *
+ * @return the toolkit that created this peer
+ */
+ public Toolkit getToolkit()
+ {
+ return Toolkit.getDefaultToolkit();
+ }
+
+ /**
+ * Handles the given event. This is called from
+ * {@link Component#dispatchEvent(AWTEvent)} to give the peer a chance to
+ * react to events for the component.
+ *
+ * @param e the event
+ */
+ public void handleEvent(AWTEvent e)
+ {
+ switch (e.getID())
+ {
+ case PaintEvent.UPDATE:
+ case PaintEvent.PAINT:
+ Graphics g = getGraphics();
+ Rectangle clip = ((PaintEvent)e).getUpdateRect();
+ g.clipRect(clip.x, clip.y, clip.width, clip.height);
+ //if (this instanceof LightweightPeer)
+ // {
+ if (e.getID() == PaintEvent.UPDATE)
+ awtComponent.update(g);
+ else
+ awtComponent.paint(g);
+ // }
+ // We paint the 'heavyweights' at last, so that they appear on top of
+ // everything else.
+ peerPaint(g);
+
+ g.dispose();
+ break;
+ case MouseEvent.MOUSE_PRESSED:
+ case MouseEvent.MOUSE_RELEASED:
+ case MouseEvent.MOUSE_CLICKED:
+ case MouseEvent.MOUSE_ENTERED:
+ case MouseEvent.MOUSE_EXITED:
+ handleMouseEvent((MouseEvent) e);
+ break;
+ case MouseEvent.MOUSE_MOVED:
+ case MouseEvent.MOUSE_DRAGGED:
+ handleMouseMotionEvent((MouseEvent) e);
+ break;
+ case KeyEvent.KEY_PRESSED:
+ case KeyEvent.KEY_RELEASED:
+ case KeyEvent.KEY_TYPED:
+ handleKeyEvent((KeyEvent) e);
+ break;
+ default:
+ // Other event types are not handled here.
+ break;
+ }
+ }
+
+ /**
+ * Makes the component invisible. This is called from
+ * {@link Component#hide()}.
+ *
+ * This is implemented to call setVisible(false) on the Swing component.
+ */
+ public void hide()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setVisible(false);
+ }
+
+ /**
+ * Returns true
if the component can receive keyboard input
+ * focus. This is called from {@link Component#isFocusTraversable()}.
+ *
+ * This is implemented to return isFocusable() from the Swing component.
+ *
+ * @specnote Part of the earlier 1.1 API, replaced by isFocusable().
+ */
+ public boolean isFocusTraversable()
+ {
+ return swingComponent != null ?
+ swingComponent.getJComponent().isFocusable() : false;
+ }
+
+ /**
+ * Returns true
if the component can receive keyboard input
+ * focus. This is called from {@link Component#isFocusable()}.
+ *
+ * This is implemented to return isFocusable() from the Swing component.
+ */
+ public boolean isFocusable()
+ {
+ return swingComponent != null ?
+ swingComponent.getJComponent().isFocusable() : false;
+ }
+
+ /**
+ * Returns the minimum size for the component. This is called by
+ * {@link Component#minimumSize()}.
+ *
+ * This is implemented to return the Swing component's minimum size.
+ *
+ * @return the minimum size for the component
+ */
+ public Dimension minimumSize()
+ {
+ Dimension retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getMinimumSize();
+ else
+ retVal = new Dimension(0, 0);
+ return retVal;
+ }
+
+ /**
+ * Returns the preferred size for the component. This is called by
+ * {@link Component#getPreferredSize()}.
+ *
+ * This is implemented to return the Swing component's preferred size.
+ *
+ * @return the preferred size for the component
+ */
+ public Dimension preferredSize()
+ {
+ Dimension retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getPreferredSize();
+ else
+ retVal = new Dimension(0, 0);
+ return retVal;
+ }
+
+ /**
+ * Prepares an image for rendering on this component. This is called by
+ * {@link Component#prepareImage(Image, int, int, ImageObserver)}.
+ *
+ * @param img the image to prepare
+ * @param width the desired width of the rendered image
+ * @param height the desired height of the rendered image
+ * @param ob the image observer to be notified of updates in the preparation
+ * process
+ *
+ * @return true
if the image has been fully prepared,
+ * false
otherwise (in which case the image observer
+ * receives updates)
+ */
+ public void paint(Graphics graphics)
+ {
+ // FIXME: I don't know what this method is supposed to do.
+ }
+
+ /**
+ * Prepares an image for rendering on this component. This is called by
+ * {@link Component#prepareImage(Image, int, int, ImageObserver)}.
+ *
+ * @param img the image to prepare
+ * @param width the desired width of the rendered image
+ * @param height the desired height of the rendered image
+ * @param ob the image observer to be notified of updates in the preparation
+ * process
+ *
+ * @return true
if the image has been fully prepared,
+ * false
otherwise (in which case the image observer
+ * receives updates)
+ */
+ public boolean prepareImage(Image img, int width, int height, ImageObserver ob)
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.prepareImage(img, width, height, ob);
+ }
+
+ public void print(Graphics graphics)
+ {
+ // FIXME: I don't know what this method is supposed to do.
+ }
+
+ /**
+ * Repaints the specified rectangle of this component. This is called from
+ * {@link Component#repaint(long, int, int, int, int)}.
+ *
+ * This is implemented to call repaint() on the Swing component.
+ *
+ * @param tm number of milliseconds to wait with repainting
+ * @param x the X coordinate of the upper left corner of the damaged rectangle
+ * @param y the Y coordinate of the upper left corner of the damaged rectangle
+ * @param width the width of the damaged rectangle
+ * @param height the height of the damaged rectangle
+ */
+ public void repaint(long tm, int x, int y, int width, int height)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().repaint(tm, x, y, width, height);
+ else
+ {
+ PaintEvent ev = new PaintEvent(awtComponent, PaintEvent.UPDATE,
+ new Rectangle(x, y, width, height));
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ev);
+ }
+ }
+
+ /**
+ * Requests that this component receives the focus. This is called from
+ * {@link Component#requestFocus()}.
+ *
+ * This calls requestFocus() on the Swing component.
+ *
+ * @specnote Part of the earlier 1.1 API, apparently replaced by argument
+ * form of the same method.
+ */
+ public void requestFocus()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().requestFocus();
+ }
+
+ /**
+ * Requests that this component receives the focus. This is called from
+ * {@link Component#requestFocus()}.
+ *
+ * This calls requestFocus() on the Swing component.
+ *
+ * @param source TODO
+ * @param bool1 TODO
+ * @param bool2 TODO
+ * @param x TODO
+ *
+ * @return TODO
+ */
+ public boolean requestFocus(Component source, boolean bool1, boolean bool2, long x)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().requestFocus();
+ return swingComponent != null;
+ }
+
+ /**
+ * Notifies the peer that the bounds of this component have changed. This
+ * is called by {@link Component#reshape(int, int, int, int)}.
+ *
+ * This is implemented to call setBounds() on the Swing component.
+ *
+ * @param x the X coordinate of the upper left corner of the component
+ * @param y the Y coordinate of the upper left corner of the component
+ * @param width the width of the component
+ * @param height the height of the component
+ */
+ public void reshape(int x, int y, int width, int height)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setBounds(x, y, width, height);
+ }
+
+ /**
+ * Sets the background color of the component. This is called by
+ * {@link Component#setBackground(Color)}.
+ *
+ * This is implemented to call setBackground() on the Swing component.
+ *
+ * @param color the background color to set
+ */
+ public void setBackground(Color color)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setBackground(color);
+ }
+
+ /**
+ * Notifies the peer that the bounds of this component have changed. This
+ * is called by {@link Component#setBounds(int, int, int, int)}.
+ *
+ * This is implemented to call setBounds() on the Swing component.
+ *
+ * @param x the X coordinate of the upper left corner of the component
+ * @param y the Y coordinate of the upper left corner of the component
+ * @param width the width of the component
+ * @param height the height of the component
+ */
+ public void setBounds(int x, int y, int width, int height)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setBounds(x, y, width, height);
+ }
+
+ /**
+ * Sets the cursor of the component. This is called by
+ * {@link Component#setCursor(Cursor)}.
+ *
+ * This is implemented to call setCursor() on the Swing component.
+ *
+ * @specnote Part of the earlier 1.1 API, apparently no longer needed.
+ */
+ public void setCursor(Cursor cursor)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setCursor(cursor);
+ }
+
+ /**
+ * Sets the enabled/disabled state of this component. This is called by
+ * {@link Component#setEnabled(boolean)}.
+ *
+ * This is implemented to call setEnabled() on the Swing component.
+ *
+ * @param enabled true
to enable the component,
+ * false
to disable it
+ */
+ public void setEnabled(boolean enabled)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setEnabled(enabled);
+ }
+
+ /**
+ * Sets the font of the component. This is called by
+ * {@link Component#setFont(Font)}.
+ *
+ * This is implemented to call setFont() on the Swing component.
+ *
+ * @param font the font to set
+ */
+ public void setFont(Font font)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setFont(font);
+ }
+
+ /**
+ * Sets the foreground color of the component. This is called by
+ * {@link Component#setForeground(Color)}.
+ *
+ * This is implemented to call setForeground() on the Swing component.
+ *
+ * @param color the foreground color to set
+ */
+ public void setForeground(Color color)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setForeground(color);
+ }
+
+ /**
+ * Sets the visibility state of the component. This is called by
+ * {@link Component#setVisible(boolean)}.
+ *
+ * This is implemented to call setVisible() on the Swing component.
+ *
+ * @param visible true
to make the component visible,
+ * false
to make it invisible
+ */
+ public void setVisible(boolean visible)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setVisible(visible);
+ }
+
+ /**
+ * Makes the component visible. This is called by {@link Component#show()}.
+ *
+ * This is implemented to call setVisible(true) on the Swing component.
+ */
+ public void show()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setVisible(true);
+ }
+
+ /**
+ * Get the graphics configuration of the component. The color model
+ * of the component can be derived from the configuration.
+ *
+ * This is implemented to return the GraphicsConfiguration of the parent
+ * component. This will eventually call the toplevel component peer, which
+ * is expected to provide a real implementation.
+ *
+ * @return the graphics configuration of the component
+ */
+ public GraphicsConfiguration getGraphicsConfiguration()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.getGraphicsConfiguration();
+ }
+
+ /**
+ * Part of an older API, no longer needed.
+ */
+ public void setEventMask(long mask)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns true
if this component has been obscured,
+ * false
otherwise. This will only work if
+ * {@link #canDetermineObscurity()} also returns true
.
+ *
+ * This is not yet implemented.
+ *
+ * @return true
if this component has been obscured,
+ * false
otherwise.
+ */
+ public boolean isObscured()
+ {
+ return false;
+ }
+
+ /**
+ * Returns true
if this component peer can determine if the
+ * component has been obscured, false
otherwise.
+ *
+ * This is not yet implemented.
+ *
+ * @return true
if this component peer can determine if the
+ * component has been obscured, false
otherwise
+ */
+ public boolean canDetermineObscurity()
+ {
+ return false;
+ }
+
+ /**
+ * Coalesces the specified paint event.
+ *
+ * @param e the paint event
+ */
+ public void coalescePaintEvent(PaintEvent e)
+ {
+ // Nothing to do here yet.
+ }
+
+ /**
+ * Updates the cursor. This is not yet implemented.
+ */
+ public void updateCursorImmediately()
+ {
+ // Nothing to do here yet.
+ }
+
+ /**
+ * Returns true, if this component can handle wheel scrolling,
+ * false
otherwise.
+ *
+ * This is not yet implemented and returns false
.
+ *
+ * @return true, if this component can handle wheel scrolling,
+ * false
otherwise
+ */
+ public boolean handlesWheelScrolling()
+ {
+ return false;
+ }
+
+ /**
+ * A convenience method that creates a volatile image. The volatile
+ * image is created on the screen device on which this component is
+ * displayed, in the device's current graphics configuration.
+ *
+ * This is implemented to let the parent component peer create an image.
+ * This eventually ends up in the toplevel component peer, which is then
+ * responsible for creating the real image.
+ *
+ * @param width width of the image
+ * @param height height of the image
+ *
+ * @see VolatileImage
+ *
+ * @since 1.2
+ */
+ public VolatileImage createVolatileImage(int width, int height)
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.createVolatileImage(width, height);
+ }
+
+ /**
+ * Create a number of image buffers that implement a buffering
+ * strategy according to the given capabilities.
+ *
+ * This is implemented to forward to the parent component peer. Eventually
+ * this ends up in the top level component peer, which is then responsible
+ * for doing the real work.
+ *
+ * @param numBuffers the number of buffers
+ * @param caps the buffering capabilities
+ *
+ * @throws AWTException if the specified buffering strategy is not
+ * implemented
+ *
+ * @since 1.2
+ */
+ public void createBuffers(int numBuffers, BufferCapabilities caps) throws AWTException
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ parentPeer.createBuffers(numBuffers, caps);
+ }
+
+ /**
+ * Return the back buffer of this component.
+ *
+ * This is implemented to forward to the parent. Eventually this ends
+ * up in the toplevel component, which is then responsible for providing
+ * a back buffer.
+ *
+ * @return the back buffer of this component.
+ *
+ * @since 1.2
+ */
+ public Image getBackBuffer()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.getBackBuffer();
+ }
+
+ /**
+ * Perform a page flip, leaving the contents of the back buffer in
+ * the specified state.
+ *
+ * This is implemented to forward to the parent. Eventually this ends
+ * up in the toplevel component, which is then responsible for doing the real
+ * work.
+ *
+ * @param contents the state in which to leave the back buffer
+ *
+ * @since 1.2
+ */
+ public void flip(FlipContents contents)
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ parentPeer.flip(contents);
+ }
+
+ /**
+ * Destroy the resources created by createBuffers.
+ *
+ * This is implemented to forward to the parent component peer. Eventually
+ * this ends up in the top level component peer, which is then responsible
+ * for doing the real work.
+ *
+ * @since 1.2
+ */
+ public void destroyBuffers()
+ {
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ parentPeer.destroyBuffers();
+ }
+
+ /**
+ * Get the bounds of this component peer.
+ *
+ * This is implemented to forward to the Swing component.
+ *
+ * @return component peer bounds
+ * @since 1.5
+ */
+ public Rectangle getBounds()
+ {
+ Rectangle retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getBounds();
+ else
+ retVal = new Rectangle();
+ return retVal;
+ }
+
+ /**
+ * Reparent this component under another container.
+ *
+ * @param parent
+ * @since 1.5
+ */
+ public void reparent(ContainerPeer parent)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Set the bounds of this component peer.
+ *
+ * This is implemented to forward to the swing component.
+ *
+ * @param x the new x co-ordinate
+ * @param y the new y co-ordinate
+ * @param width the new width
+ * @param height the new height
+ * @param z the new stacking level
+ * @since 1.5
+ */
+ public void setBounds(int x, int y, int width, int height, int z)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().setBounds(x, y, width, height);
+ // FIXME: Somehow handle the Z order.
+ }
+
+ /**
+ * Check if this component supports being reparented.
+ *
+ * @return true if this component can be reparented,
+ * false otherwise.
+ * @since 1.5
+ */
+ public boolean isReparentSupported()
+ {
+ return true;
+ }
+
+
+ /**
+ * Layout this component peer.
+ *
+ * @since 1.5
+ */
+ public void layout()
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().doLayout();
+ }
+
+ /**
+ * Triggers 'heavyweight' painting of the components. This usually calls
+ * paint() on the Swing component.
+ *
+ * @param g the graphics context to use for painting
+ */
+ protected void peerPaint(Graphics g)
+ {
+ if (swingComponent != null)
+ swingComponent.getJComponent().paint(g);
+ }
+
+ /**
+ * Handles mouse events on the component. This is usually forwarded to the
+ * SwingComponent's processMouseEvent() method.
+ *
+ * @param e the mouse event
+ */
+ protected void handleMouseEvent(MouseEvent e)
+ {
+ if (swingComponent != null)
+ swingComponent.handleMouseEvent(e);
+ }
+
+ /**
+ * Handles mouse motion events on the component. This is usually forwarded
+ * to the SwingComponent's processMouseMotionEvent() method.
+ *
+ * @param e the mouse motion event
+ */
+ protected void handleMouseMotionEvent(MouseEvent e)
+ {
+ if (swingComponent != null)
+ swingComponent.handleMouseMotionEvent(e);
+ }
+
+ /**
+ * Handles key events on the component. This is usually forwarded to the
+ * SwingComponent's processKeyEvent() method.
+ *
+ * @param e the key event
+ */
+ protected void handleKeyEvent(KeyEvent e)
+ {
+ if (swingComponent != null)
+ swingComponent.handleKeyEvent(e);
+ }
+
+ /**
+ * Returns the AWT component for this peer.
+ *
+ * @return the AWT component for this peer
+ */
+ public Component getComponent()
+ {
+ return awtComponent;
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java
new file mode 100644
index 0000000..37bea75
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java
@@ -0,0 +1,241 @@
+/* SwingContainerPeer.java -- A Swing based peer for AWT containers
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Shape;
+import java.awt.event.MouseEvent;
+import java.awt.peer.ComponentPeer;
+import java.awt.peer.ContainerPeer;
+
+/**
+ * A peer for Container to be used with the Swing based AWT peers.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingContainerPeer
+ extends SwingComponentPeer
+ implements ContainerPeer
+{
+
+ /**
+ * Creates a new SwingContainerPeer.
+ *
+ * @param awtCont
+ */
+ public SwingContainerPeer(Container awtCont)
+ {
+ init(awtCont, null);
+ }
+
+ /**
+ * Returns the insets of the container.
+ *
+ * This is implemented to return the insets of the Swing container.
+ *
+ * @return the insets of the container
+ */
+ public Insets insets()
+ {
+ Insets retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getInsets();
+ else
+ retVal = new Insets(0, 0, 0, 0);
+ return retVal;
+ }
+
+ /**
+ * Returns the insets of the container.
+ *
+ * This is implemented to return the insets of the Swing container.
+ *
+ * @return the insets of the container
+ */
+ public Insets getInsets()
+ {
+ Insets retVal;
+ if (swingComponent != null)
+ retVal = swingComponent.getJComponent().getInsets();
+ else
+ retVal = new Insets(0, 0, 0, 0);
+ return retVal;
+ }
+
+ /**
+ * Called before the validation of this containers begins.
+ */
+ public void beginValidate()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Called after the validation of this containers ended.
+ */
+ public void endValidate()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Called before the layout of this containers begins.
+ */
+ public void beginLayout()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Called after the layout of this containers ended.
+ */
+ public void endLayout()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns false
unconditionally. This method is not used at
+ * the moment.
+ *
+ * @return false
+ */
+ public boolean isPaintPending()
+ {
+ return false;
+ }
+
+ /**
+ * Returns false
unconditionally. This method is not used at
+ * the moment.
+ *
+ * @return false
+ */
+ public boolean isRestackSupported()
+ {
+ return false;
+ }
+
+ /**
+ * This method is not used at the moment.
+ */
+ public void cancelPendingPaint(int x, int y, int width, int height)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method is not used at the moment.
+ */
+ public void restack()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Triggers painting of a component. This calls peerPaint on all the child
+ * components of this container.
+ *
+ * @param g the graphics context to paint to
+ */
+ protected void peerPaint(Graphics g)
+ {
+ Container c = (Container) awtComponent;
+ Component[] children = c.getComponents();
+ for (int i = children.length - 1; i >= 0; --i)
+ {
+ Component child = children[i];
+ ComponentPeer peer = child.getPeer();
+ boolean translated = false;
+ boolean clipped = false;
+ Shape oldClip = g.getClip();
+ try
+ {
+ g.translate(child.getX(), child.getY());
+ translated = true;
+ g.setClip(0, 0, child.getWidth(), child.getHeight());
+ clipped = true;
+ if (peer instanceof SwingComponentPeer)
+ ((SwingComponentPeer) peer).peerPaint(g);
+ }
+ finally
+ {
+ if (translated)
+ g.translate(- child.getX(), - child.getY());
+ if (clipped)
+ g.setClip(oldClip);
+ }
+ }
+ }
+
+ /**
+ * Handles mouse events by dispatching it to the correct component.
+ *
+ * @param ev the mouse event
+ */
+ protected void handleMouseEvent(MouseEvent ev)
+ {
+ Component comp = awtComponent.getComponentAt(ev.getPoint());
+ ComponentPeer peer = comp.getPeer();
+ if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
+ {
+ ev.translatePoint(comp.getX(), comp.getY());
+ ev.setSource(comp);
+ ((SwingComponentPeer) peer).handleMouseEvent(ev);
+ }
+ }
+
+ /**
+ * Handles mouse events by dispatching it to the correct component.
+ *
+ * @param ev the mouse event
+ */
+ protected void handleMouseMotionEvent(MouseEvent ev)
+ {
+ Component comp = awtComponent.getComponentAt(ev.getPoint());
+ ComponentPeer peer = comp.getPeer();
+ if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
+ {
+ ev.translatePoint(comp.getX(), comp.getY());
+ ((SwingComponentPeer) peer).handleMouseMotionEvent(ev);
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java
new file mode 100644
index 0000000..fea1b50
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingFramePeer.java
@@ -0,0 +1,196 @@
+/* SwingFramePeer.java -- An abstract Swing based peer for AWT frames
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.MenuBar;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.peer.FramePeer;
+
+/**
+ * An abstract base class for FramePeer implementations based on Swing.
+ * This class provides the ability to display and handle AWT MenuBars that
+ * are based on Swing.
+ *
+ * As a minimum, a subclass must implement all the remaining abstract methods
+ * as well as the following methods:
+ *
+ *
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public abstract class SwingFramePeer
+ extends SwingWindowPeer
+ implements FramePeer
+{
+ /**
+ * The menu bar to display.
+ */
+ SwingMenuBarPeer menuBar = null;
+
+ /**
+ * Creates a new SwingFramePeer.
+ *
+ * @param frame the frame
+ */
+ public SwingFramePeer(Frame frame)
+ {
+ super(frame);
+ }
+
+ /**
+ * Sets the menu bar to display in this frame.
+ *
+ * @param mb the menu bar to set
+ */
+ public void setMenuBar(MenuBar mb)
+ {
+ menuBar = (SwingMenuBarPeer) mb.getPeer();
+ menuBar.setFramePeer(this);
+ menuBar.setWidth(awtComponent.getWidth());
+ }
+
+ /**
+ * Triggers 'heavyweight' painting of the frame. This will paint a menu bar
+ * if present as well as the child components of this frame.
+ *
+ * @param g the graphics context to use for painting
+ */
+ protected void peerPaint(Graphics g)
+ {
+ super.peerPaint(g);
+ if (menuBar != null)
+ menuBar.peerPaint(g);
+ }
+
+ /**
+ * Sets the size and location of this frame. This resizes the menubar to fit
+ * within the frame.
+ *
+ * @param x the X coordinate of the screen location
+ * @param y the Y coordinate of the screen location
+ * @param w the width of the frame
+ * @param h the height of the frame
+ */
+ public void setBounds(int x, int y, int w, int h)
+ {
+ super.setBounds(x, y, w, h);
+ if (menuBar != null)
+ menuBar.setWidth(w);
+ }
+
+ /**
+ * Calculates the insets of this frame peer. This fetches the insets
+ * from the superclass and adds the insets of the menubar if one is present.
+ *
+ * @return the insets of the frame
+ */
+ public Insets getInsets()
+ {
+ Insets insets = super.getInsets();
+ if (menuBar != null)
+ insets.top += menuBar.getHeight();
+ return insets;
+ }
+
+ /**
+ * Returns the location of the menu on the screen. This is needed internally
+ * by the {@link SwingMenuBarPeer} in order to determine its screen location.
+ *
+ * @return the location of the menu on the screen
+ */
+ public Point getMenuLocationOnScreen()
+ {
+ Insets i = super.getInsets();
+ return new Point(i.top, i.left);
+ }
+
+ /**
+ * Overridden to provide the ability to handle menus.
+ *
+ * @param ev the mouse event
+ */
+ protected void handleMouseEvent(MouseEvent ev)
+ {
+ Point p = ev.getPoint();
+ Insets i = super.getInsets();
+ if (menuBar != null)
+ {
+ int menuHeight = menuBar.getHeight();
+ if (p.y >= i.top && p.y <= i.top + menuHeight)
+ menuBar.handleMouseEvent(ev);
+ else
+ {
+ ev.translatePoint(0, -menuHeight);
+ super.handleMouseMotionEvent(ev);
+ }
+ }
+
+ super.handleMouseEvent(ev);
+ }
+
+ /**
+ * Overridden to provide the ability to handle menus.
+ *
+ * @param ev the mouse event
+ */
+ protected void handleMouseMotionEvent(MouseEvent ev)
+ {
+ Point p = ev.getPoint();
+ Insets i = super.getInsets();
+ if (menuBar != null)
+ {
+ int menuHeight = menuBar.getHeight();
+ if (p.y >= i.top && p.y <= i.top + menuHeight)
+ menuBar.handleMouseMotionEvent(ev);
+ else
+ {
+ ev.translatePoint(0, -menuHeight);
+ super.handleMouseMotionEvent(ev);
+ }
+ }
+
+ super.handleMouseMotionEvent(ev);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java
new file mode 100644
index 0000000..dd86fff
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingLabelPeer.java
@@ -0,0 +1,196 @@
+/* SwingLabelPeer.java -- A Swing based peer for AWT labels
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Image;
+import java.awt.Label;
+import java.awt.Point;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.peer.LabelPeer;
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+
+
+/**
+ * A Label peer based on {@link JLabel}.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingLabelPeer
+ extends SwingComponentPeer
+ implements LabelPeer
+{
+
+ /**
+ * A spezialized Swing label used to paint the label for the AWT Label.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingLabel
+ extends JLabel
+ implements SwingComponent
+ {
+
+ /**
+ * Returns this label.
+ *
+ * @return this
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * processMouseEvent()
.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to
+ * processMouseMotionEvent()
.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to processKeyEvent()
.
+ *
+ * @param ev the mouse event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ processKeyEvent(ev);
+ }
+
+ /**
+ * Overridden so that this method returns the correct value even without a
+ * peer.
+ *
+ * @return the screen location of the button
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingLabelPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value for the
+ * swing button, even if it has no peer on its own.
+ *
+ * @return true
if the button is currently showing,
+ * false
otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (SwingLabelPeer.this.awtComponent != null)
+ retVal = SwingLabelPeer.this.awtComponent.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingLabelPeer.this.createImage(w, h);
+ }
+
+ }
+
+ /**
+ * Creates a new SwingLabelPeer
for the specified AWT label.
+ *
+ * @param label the AWT label
+ */
+ public SwingLabelPeer(Label label)
+ {
+ super();
+ SwingLabel swingLabel = new SwingLabel();
+ swingLabel.setText(label.getText());
+ swingLabel.setHorizontalAlignment(label.getAlignment());
+ swingLabel.setOpaque(true);
+ init(label, swingLabel);
+ }
+
+ /**
+ * Sets the text of the label. This is implemented to set the text on the
+ * Swing label.
+ *
+ * @param text the text to be set
+ */
+ public void setText(String text)
+ {
+ ((JLabel) swingComponent.getJComponent()).setText(text);
+ }
+
+ /**
+ * Sets the horizontal alignment of the label. This is implemented to
+ * set the alignment on the Swing label.
+ *
+ * @param alignment the horizontal alignment
+ *
+ * @see Label#LEFT
+ * @see Label#RIGHT
+ * @see Label#CENTER
+ */
+ public void setAlignment(int alignment)
+ {
+ ((JLabel) swingComponent.getJComponent()).setHorizontalAlignment(alignment);
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java
new file mode 100644
index 0000000..bd9dcd7
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java
@@ -0,0 +1,295 @@
+/* SwingMenuBarPeer.java -- A Swing based peer for AWT menu bars
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Container;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.peer.MenuBarPeer;
+
+import javax.swing.JMenuBar;
+
+/**
+ * A Swing based peer for the AWT menu bar. This is a little bit different from
+ * the other peers, since the AWT MenuBar is not derived from the AWT
+ * component.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingMenuBarPeer
+ implements MenuBarPeer
+{
+
+ /**
+ * The AWT menu bar.
+ */
+ MenuBar awtMenuBar;
+
+ /**
+ * The Swing menu bar.
+ */
+ SwingMenuBar menuBar;
+
+ /**
+ * The peer of the frame that contains this menu bar.
+ */
+ SwingFramePeer framePeer;
+
+ /**
+ * A specialized JMenuBar that can be used as 'backend' for AWT MenuBars.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingMenuBar
+ extends JMenuBar
+ {
+ /**
+ * Overridden in order to provide a parent frame for this menu bar. The
+ * menu bar still is not inside the component hierarchy, we are faking
+ * here.
+ */
+ public Container getParent()
+ {
+ Container result = null;
+ if (framePeer != null)
+ result = (Container) framePeer.awtComponent;
+ return result;
+ }
+
+ /**
+ * Unconditionally returns true
, since we assume that when the
+ * menubar has a peer, it must be showing.
+ *
+ * @return true
+ */
+ public boolean isShowing()
+ {
+ // FIXME: This might be wrong. Maybe find a better way to do that.
+ return true;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to
+ * processMouseEvent()
.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Determines the menubar's screen location by asking the SwingFramePeer
+ * for it.
+ *
+ * @return the screen location of the menu bar
+ */
+ public Point getLocationOnScreen()
+ {
+ return framePeer.getMenuLocationOnScreen();
+ }
+ }
+
+ /**
+ * Creates a new SwingMenuBarPeer
instance.
+ *
+ * @param awtMenuBar the AWT menu bar
+ */
+ public SwingMenuBarPeer(MenuBar awtMenuBar)
+ {
+ this.awtMenuBar = awtMenuBar;
+ menuBar = new SwingMenuBar();
+ menuBar.setDoubleBuffered(false);
+ // Add all the menus that are already in the MenuBar.
+ for (int i = 0; i < awtMenuBar.getMenuCount(); i++)
+ {
+ Menu menu = awtMenuBar.getMenu(i);
+ menu.addNotify();
+ addMenu(awtMenuBar.getMenu(i));
+ }
+ }
+
+ /**
+ * Sets the SwingFramePeer
of the frame that holds this menu.
+ *
+ * @param peer the SwingFramePeer
to set
+ */
+ public void setFramePeer(SwingFramePeer peer)
+ {
+ framePeer = peer;
+ }
+
+ /**
+ * Adds a menu to the menu bar.
+ *
+ * @param m the menu to add
+ */
+ public void addMenu(Menu m)
+ {
+ SwingMenuPeer menuPeer = (SwingMenuPeer) m.getPeer();
+ menuBar.add(menuPeer.menu);
+ }
+
+ /**
+ * Adds a help menu to the menu bar.
+ *
+ * @param m the menu to add
+ */
+ public void addHelpMenu(Menu menu)
+ {
+ // FIXME: We should manage the help menu differently, so that it always
+ // appears at the rightmost position.
+ SwingMenuPeer menuPeer = (SwingMenuPeer) menu.getPeer();
+ menuBar.add(menuPeer.menu);
+ }
+
+ /**
+ * Removes the menu with the specified index.
+ *
+ * @param index the index of the menu to remove
+ */
+ public void delMenu(int index)
+ {
+ menuBar.remove(index);
+ }
+
+ /**
+ * Disposes this peer. This releases any reference to the AWT and Swing
+ * components.
+ */
+ public void dispose()
+ {
+ menuBar = null;
+ awtMenuBar = null;
+ }
+
+ /**
+ * Sets a font for the menu bar.
+ *
+ * @param font the font to set
+ */
+ public void setFont(Font font)
+ {
+ menuBar.setFont(font);
+ }
+
+ /**
+ * Sets the width of the menu bar. This is called from the top level
+ * component peers to adjust the width of the menubar when their sizes
+ * change.
+ *
+ * @param w the width to set
+ */
+ public void setWidth(int w)
+ {
+ menuBar.setSize(w, menuBar.getPreferredSize().height);
+ menuBar.doLayout();
+ }
+
+ /**
+ * Paints the menu bar.
+ *
+ * @param g the graphics context to use for painting
+ */
+ public void peerPaint(Graphics g)
+ {
+ menuBar.paint(g);
+ }
+
+ /**
+ * Determines the height of the menubar.
+ *
+ * @return the height of the menu bar
+ */
+ public int getHeight()
+ {
+ return menuBar.getPreferredSize().height;
+ }
+
+ /**
+ * Handles mouse events.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ Point point = ev.getPoint();
+ for (int i = 0; i < awtMenuBar.getMenuCount(); i++)
+ {
+ Menu menu = awtMenuBar.getMenu(i);
+ SwingMenuPeer peer = (SwingMenuPeer) menu.getPeer();
+ int x1 = peer.getX();
+ int x2 = x1 + peer.getWidth();
+ if (point.x >= x1 && point.x <= x2)
+ {
+ ev.translatePoint(peer.getX(), peer.getY());
+ peer.handleMouseEvent(ev);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Handles mouse motion events.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ Point point = ev.getPoint();
+ for (int i = 0; i < awtMenuBar.getMenuCount(); i++)
+ {
+ Menu menu = awtMenuBar.getMenu(i);
+ SwingMenuPeer peer = (SwingMenuPeer) menu.getPeer();
+ int x1 = peer.getX();
+ int x2 = x1 + peer.getWidth();
+ if (point.x >= x1 && point.x <= x2)
+ {
+ ev.translatePoint(peer.getX(), peer.getY());
+ peer.handleMouseMotionEvent(ev);
+ break;
+ }
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuItemPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuItemPeer.java
new file mode 100644
index 0000000..8b9d47e
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuItemPeer.java
@@ -0,0 +1,157 @@
+/* SwingMenuItemPeer.java -- A Swing based peer for AWT menu items
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Font;
+import java.awt.MenuItem;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.peer.MenuItemPeer;
+
+import javax.swing.JMenuItem;
+
+/**
+ * A Swing based peer for the AWT MenuItem.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingMenuItemPeer
+ implements MenuItemPeer
+{
+ /**
+ * The AWT menu item.
+ */
+ MenuItem awtMenuItem;
+
+ /**
+ * The Swing menu item.
+ */
+ JMenuItem menuItem;
+
+ /**
+ * Receives ActionEvents from the Swing menu item and forwards them
+ * to the ActionListeners of the AWT MenuItem.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingMenuItemListener implements ActionListener
+ {
+
+ /**
+ * Receives notification when the action has been performed.
+ *
+ * @param event the action event
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ event.setSource(awtMenuItem);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
+ }
+
+ }
+
+ /**
+ * Creates a new instance of SwingMenuItemPeer
.
+ *
+ * @param awtMenuItem the AWT menu item
+ */
+ public SwingMenuItemPeer(MenuItem awtMenuItem)
+ {
+ this.awtMenuItem = awtMenuItem;
+ menuItem = new JMenuItem(awtMenuItem.getLabel());
+ menuItem.addActionListener(new SwingMenuItemListener());
+ }
+
+ /**
+ * Disables the menu item.
+ */
+ public void disable()
+ {
+ menuItem.setEnabled(false);
+ }
+
+ /**
+ * Enables the menu item.
+ */
+ public void enable()
+ {
+ menuItem.setEnabled(true);
+ }
+
+ /**
+ * Sets the enabled state to enabled
.
+ *
+ * @param enabled if the menu item should be enabled or not
+ */
+ public void setEnabled(boolean enabled)
+ {
+ menuItem.setEnabled(enabled);
+ }
+
+ /**
+ * Sets the label for the menu item.
+ *
+ * @param text the label to set
+ */
+ public void setLabel(String text)
+ {
+ menuItem.setText(text);
+ }
+
+ /**
+ * Disposes the menu item. This releases any reference to the Swing and AWT
+ * menu item.
+ */
+ public void dispose()
+ {
+ menuItem = null;
+ awtMenuItem = null;
+ }
+
+ /**
+ * Sets the font for this menu item.
+ *
+ * @param font the font to set
+ */
+ public void setFont(Font font)
+ {
+ menuItem.setFont(font);
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuPeer.java
new file mode 100644
index 0000000..ecb54a5
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingMenuPeer.java
@@ -0,0 +1,284 @@
+/* SwingMenuPeer.java -- A Swing based peer for AWT menus
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Font;
+import java.awt.Menu;
+import java.awt.MenuItem;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.peer.MenuPeer;
+
+import javax.swing.JMenu;
+
+/**
+ * A Swing based peer for the AWT menu.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingMenuPeer
+ implements MenuPeer
+{
+
+ /**
+ * The AWT menu.
+ */
+ Menu awtMenu;
+
+ /**
+ * The Swing menu.
+ */
+ SwingMenu menu;
+
+ /**
+ * A specialized JMenu that can be used as 'backend' for an AWT menu.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingMenu
+ extends JMenu
+ {
+
+ /**
+ * Unconditionally returns true
, since we assume that when the
+ * menu has a peer, it must be showing.
+ *
+ * @return true
+ */
+ public boolean isShowing()
+ {
+ // FIXME: This might be wrong. Maybe find a better way to do that.
+ return true;
+ }
+
+ /**
+ * Overridden so that we can provide a location even without a real peer
+ * attached.
+ *
+ * @return the screen location of this menu
+ */
+ public Point getLocationOnScreen()
+ {
+ Point parentLoc = getParent().getLocationOnScreen();
+ parentLoc.x += getX();
+ parentLoc.y += getY();
+ return parentLoc;
+ }
+
+ /**
+ * Handles mouse events by forwarding them to
+ * processMouseEvent()
.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse events by forwarding them to
+ * processMouseMotionEvent()
.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseMotionEvent(ev);
+ }
+ }
+
+ /**
+ * Creates a new SwingMenuPeer
instance.
+ *
+ * @param awtMenu the AWT menu
+ */
+ public SwingMenuPeer(Menu awtMenu)
+ {
+ this.awtMenu = awtMenu;
+ menu = new SwingMenu();
+ menu.setDoubleBuffered(false);
+ menu.setText(awtMenu.getLabel());
+ for (int i = 0; i < awtMenu.getItemCount(); i++)
+ {
+ MenuItem item = awtMenu.getItem(i);
+ item.addNotify();
+ SwingMenuItemPeer peer = (SwingMenuItemPeer) item.getPeer();
+ menu.add(peer.menuItem);
+ }
+ }
+
+ /**
+ * Adds a menu item to this menu.
+ *
+ * @param item the menu item to add
+ */
+ public void addItem(MenuItem item)
+ {
+ SwingMenuItemPeer menuItemPeer = (SwingMenuItemPeer) item.getPeer();
+ menu.add(menuItemPeer.menuItem);
+ }
+
+ /**
+ * Adds a separator to the menu.
+ */
+ public void addSeparator()
+ {
+ menu.addSeparator();
+ }
+
+ /**
+ * Removes a menu item from the menu.
+ *
+ * @param index the index of the menu item to remove
+ */
+ public void delItem(int index)
+ {
+ menu.remove(index);
+ }
+
+ /**
+ * Disables the menu.
+ */
+ public void disable()
+ {
+ menu.setEnabled(false);
+ }
+
+ /**
+ * Enables the menu.
+ */
+ public void enable()
+ {
+ menu.setEnabled(true);
+ }
+
+ /**
+ * Sets the enabled state of the menu to enabled
.
+ *
+ * @param enabled if the menu should be enabled or not
+ */
+ public void setEnabled(boolean enabled)
+ {
+ menu.setEnabled(enabled);
+ }
+
+ /**
+ * Sets the label of the menu.
+ *
+ * @param text the label to set
+ */
+ public void setLabel(String text)
+ {
+ menu.setText(text);
+ }
+
+ /**
+ * Releases any reference to the AWT and Swing menu instances.
+ */
+ public void dispose()
+ {
+ menu = null;
+ awtMenu = null;
+ }
+
+ /**
+ * Sets the font for the menu.
+ *
+ * @param font the font to set
+ */
+ public void setFont(Font font)
+ {
+ menu.setFont(font);
+ }
+
+ /**
+ * Handles mouse events by forwarding them to the Swing menu.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ menu.handleMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding them to the Swing menu.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ menu.handleMouseMotionEvent(ev);
+ }
+
+ /**
+ * Returns the X coordinate of the upper left corner of the menu. This is
+ * used internally by the SwingMenuBarPeer.
+ *
+ * @return the X coordinate of the upper left corner of the menu
+ */
+ int getX()
+ {
+ return menu.getX();
+ }
+
+ /**
+ * Returns the width of the menu. This is used internally by the
+ * SwingMenuBarPeer.
+ *
+ * @return the X coordinate of the upper left corner of the menu
+ */
+ int getWidth()
+ {
+ return menu.getWidth();
+ }
+
+ /**
+ * Returns the Y coordinate of the upper left corner of the menu. This is
+ * used internally by the SwingMenuBarPeer.
+ *
+ * @return the X coordinate of the upper left corner of the menu
+ */
+ public int getY()
+ {
+ return menu.getY();
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java
new file mode 100644
index 0000000..0a0f20f
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingPanelPeer.java
@@ -0,0 +1,67 @@
+/* SwingPanelPeer.java -- A PanelPeer based on Swing
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Panel;
+import java.awt.peer.LightweightPeer;
+import java.awt.peer.PanelPeer;
+
+/**
+ * A panel peer based on Swing.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+// TODO: Maybe base implementation on JPanel. However, this doesn't seem
+// necessary, but might be good for more consistend Look.
+public class SwingPanelPeer
+ extends SwingContainerPeer
+ implements PanelPeer, LightweightPeer
+{
+
+ /**
+ * Creates a new instance of SwingPanelPeer
for the specified
+ * AWT panel.
+ *
+ * @param panel the AWT panel
+ */
+ public SwingPanelPeer(Panel panel)
+ {
+ super(panel);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java
new file mode 100644
index 0000000..a4c6d82
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java
@@ -0,0 +1,367 @@
+/* SwingTextFieldPeer.java -- A Swing based peer for AWT textfields
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+package gnu.java.awt.peer.swing;
+
+import java.awt.Dimension;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.TextField;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.im.InputMethodRequests;
+import java.awt.peer.TextFieldPeer;
+
+import javax.swing.JComponent;
+import javax.swing.JTextField;
+
+/**
+ * A TextFieldPeer based on Swing JTextField.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class SwingTextFieldPeer
+ extends SwingComponentPeer
+ implements TextFieldPeer
+{
+
+ /**
+ * A specialized Swing textfield for use in the peer.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private class SwingTextField
+ extends JTextField
+ implements SwingComponent
+ {
+
+ /**
+ * Overridden to provide normal behaviour even without a real peer
+ * attached.
+ *
+ * @return the location of the textfield on screen
+ */
+ public Point getLocationOnScreen()
+ {
+ return SwingTextFieldPeer.this.getLocationOnScreen();
+ }
+
+ /**
+ * Overridden so that the isShowing method returns the correct value for the
+ * swing button, even if it has no peer on its own.
+ *
+ * @return true
if the button is currently showing,
+ * false
otherwise
+ */
+ public boolean isShowing()
+ {
+ boolean retVal = false;
+ if (SwingTextFieldPeer.this.awtComponent != null)
+ retVal = SwingTextFieldPeer.this.awtComponent.isShowing();
+ return retVal;
+ }
+
+ /**
+ * Overridden, so that the Swing button can create an Image without its
+ * own peer.
+ *
+ * @param w the width of the image
+ * @param h the height of the image
+ *
+ * @return an image
+ */
+ public Image createImage(int w, int h)
+ {
+ return SwingTextFieldPeer.this.createImage(w, h);
+ }
+
+ /**
+ * Returns this textfield.
+ *
+ * @return this
+ */
+ public JComponent getJComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Handles mouse events by forwarding it to the swing textfield.
+ *
+ * @param ev the mouse event
+ */
+ public void handleMouseEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseEvent(ev);
+ }
+
+ /**
+ * Handles mouse motion events by forwarding it to the swing textfield.
+ *
+ * @param ev the mouse motion event
+ */
+ public void handleMouseMotionEvent(MouseEvent ev)
+ {
+ ev.setSource(this);
+ processMouseMotionEvent(ev);
+ }
+
+ /**
+ * Handles key events by forwarding it to the swing textfield.
+ *
+ * @param ev the key event
+ */
+ public void handleKeyEvent(KeyEvent ev)
+ {
+ ev.setSource(this);
+ processKeyEvent(ev);
+ }
+
+ }
+
+ /**
+ * Creates a new SwingTextFieldPeer
instance for the specified
+ * AWT textfield.
+ *
+ * @param textField the AWT textfield
+ */
+ public SwingTextFieldPeer(TextField textField)
+ {
+ SwingTextField swingTextField = new SwingTextField();
+ swingTextField.setText(textField.getText());
+ init(textField, swingTextField);
+ }
+
+ /**
+ * Returns the minimum size of the textfield.
+ *
+ * @param len not used here
+ *
+ * @return the minimum size of the textfield
+ */
+ public Dimension minimumSize(int len)
+ {
+ return swingComponent.getJComponent().getMinimumSize();
+ }
+
+ /**
+ * Returns the preferred size of the textfield.
+ *
+ * @param len not used here
+ *
+ * @return the preferred size of the textfield
+ */
+ public Dimension preferredSize(int len)
+ {
+ return swingComponent.getJComponent().getPreferredSize();
+ }
+
+ /**
+ * Returns the minimum size of the textfield.
+ *
+ * @param len not used here
+ *
+ * @return the minimum size of the textfield
+ */
+ public Dimension getMinimumSize(int len)
+ {
+ return swingComponent.getJComponent().getMinimumSize();
+ }
+
+ /**
+ * Returns the preferred size of the textfield.
+ *
+ * @param len not used here
+ *
+ * @return the preferred size of the textfield
+ */
+ public Dimension getPreferredSize(int len)
+ {
+ return swingComponent.getJComponent().getPreferredSize();
+ }
+
+ /**
+ * Sets the echo character.
+ *
+ * @param echoChar the echo character to be set
+ */
+ public void setEchoChar(char echoChar)
+ {
+ // TODO: Must be implemented.
+ }
+
+ /**
+ * Sets the echo character.
+ *
+ * @param echoChar the echo character to be set
+ */
+ public void setEchoCharacter(char echoChar)
+ {
+ // TODO: Must be implemented.
+ }
+
+ /**
+ * Returns the end index of the current selection.
+ *
+ * @return the end index of the current selection
+ */
+ public int getSelectionEnd()
+ {
+ // TODO: Must be implemented.
+ return 0;
+ }
+
+ /**
+ * Returns the start index of the current selection.
+ *
+ * @return the start index of the current selection
+ */
+ public int getSelectionStart()
+ {
+ // TODO: Must be implemented.
+ return 0;
+ }
+
+ /**
+ * Returns the current content of the textfield.
+ *
+ * @return the current content of the textfield
+ */
+ public String getText()
+ {
+ return ((JTextField) swingComponent.getJComponent()).getText();
+ }
+
+ /**
+ * Sets the content of the textfield.
+ *
+ * @param text the text to set
+ */
+ public void setText(String text)
+ {
+ ((JTextField) swingComponent.getJComponent()).setText(text);
+ }
+
+ /**
+ * Sets the current selection.
+ *
+ * @param startPos the start index of the selection
+ * @param endPos the start index of the selection
+ */
+ public void select(int start_pos, int endPos)
+ {
+ // TODO: Must be implemented.
+ }
+
+ /**
+ * Sets the editable flag of the text field.
+ *
+ * @param editable true
to make the textfield editable,
+ * false
to make it uneditable
+ */
+ public void setEditable(boolean editable)
+ {
+ ((JTextField) swingComponent.getJComponent()).setEditable(editable);
+ }
+
+ /**
+ * Returns the current caret position.
+ *
+ * @return the current caret position
+ */
+ public int getCaretPosition()
+ {
+ return ((JTextField) swingComponent.getJComponent()).getCaret().getDot();
+ }
+
+ /**
+ * Sets the current caret position.
+ *
+ * @param pos the caret position to set
+ */
+ public void setCaretPosition(int pos)
+ {
+ ((JTextField) swingComponent.getJComponent()).getCaret().setDot(pos);
+ }
+
+ /**
+ * Returns the index of the character at the specified location.
+ *
+ * @param x the X coordinate of the point to query
+ * @param y the Y coordinate of the point to query
+ *
+ * @return the index of the character at the specified location
+ */
+ public int getIndexAtPoint(int x, int y)
+ {
+ // TODO: Must be implemented.
+ return 0;
+ }
+
+ /**
+ * Returns the bounds of the character at the specified index.
+ *
+ * @param pos the index of the character
+ *
+ * @return the bounds of the character at the specified index
+ */
+ public Rectangle getCharacterBounds(int pos)
+ {
+ // TODO: Must be implemented.
+ return null;
+ }
+
+ /**
+ * Not used.
+ */
+ public long filterEvents(long filter)
+ {
+ // TODO: Must be implemented.
+ return 0;
+ }
+
+ /**
+ * Not used.
+ */
+ public InputMethodRequests getInputMethodRequests()
+ {
+ // TODO: Must be implemented.
+ return null;
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java
new file mode 100644
index 0000000..166e1f4
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingToolkit.java
@@ -0,0 +1,165 @@
+/* SwingToolkit.java -- A base toolkit for Swing peers
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Button;
+import java.awt.Canvas;
+import java.awt.Label;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.Panel;
+import java.awt.TextField;
+import java.awt.peer.ButtonPeer;
+import java.awt.peer.CanvasPeer;
+import java.awt.peer.LabelPeer;
+import java.awt.peer.MenuBarPeer;
+import java.awt.peer.MenuItemPeer;
+import java.awt.peer.MenuPeer;
+import java.awt.peer.PanelPeer;
+import java.awt.peer.TextFieldPeer;
+
+import gnu.java.awt.ClasspathToolkit;
+
+/**
+ * A base implementation for {@link java.awt.Toolkit} that provides the
+ * Swing based widgets. Concrete implementations still must provide the
+ * remaining abstract methods.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public abstract class SwingToolkit extends ClasspathToolkit
+{
+
+ /**
+ * Creates a SwingButtonPeer.
+ *
+ * @param button the AWT button
+ *
+ * @return the Swing button peer
+ */
+ protected ButtonPeer createButton(Button button)
+ {
+ return new SwingButtonPeer(button);
+ }
+
+ /**
+ * Creates a SwingCanvasPeer.
+ *
+ * @param canvas the AWT canvas
+ *
+ * @return the Swing canvas peer
+ */
+ protected CanvasPeer createCanvas(Canvas canvas)
+ {
+ return new SwingCanvasPeer(canvas);
+ }
+
+ /**
+ * Creates a SwingLabelPeer.
+ *
+ * @param label the AWT label
+ *
+ * @return the Swing label peer
+ */
+ protected LabelPeer createLabel(Label label)
+ {
+ return new SwingLabelPeer(label);
+ }
+
+ /**
+ * Creates a SwingMenuPeer.
+ *
+ * @param menu the AWT menu
+ *
+ * @return the Swing menu peer
+ */
+ protected MenuPeer createMenu(Menu menu)
+ {
+ return new SwingMenuPeer(menu);
+ }
+
+ /**
+ * Creates a SwingMenuBarPeer.
+ *
+ * @param menuBar the AWT menubar
+ *
+ * @return the Swing menu bar peer
+ */
+ protected MenuBarPeer createMenuBar(MenuBar menuBar)
+ {
+ return new SwingMenuBarPeer(menuBar);
+ }
+
+ /**
+ * Creates a SwingMenuItemPeer.
+ *
+ * @param menuItem the AWT menu item
+ *
+ * @return the Swing menu item peer
+ */
+ protected MenuItemPeer createMenuItem(MenuItem menuItem)
+ {
+ return new SwingMenuItemPeer(menuItem);
+ }
+
+ /**
+ * Creates a SwingPanelPeer.
+ *
+ * @param panel the AWT panel
+ *
+ * @return the Swing panel peer
+ */
+ protected PanelPeer createPanel(Panel panel)
+ {
+ return new SwingPanelPeer(panel);
+ }
+
+ /**
+ * Creates a SwingTextFieldPeer.
+ *
+ * @param textField the AWT text field
+ *
+ * @return the Swing text field peer
+ */
+ protected TextFieldPeer createTextField(TextField textField)
+ {
+ return new SwingTextFieldPeer(textField);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java b/libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java
new file mode 100644
index 0000000..2f89795
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java
@@ -0,0 +1,72 @@
+/* SwingWindowPeer.java -- An abstract base for Swing based window peers
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.peer.swing;
+
+import java.awt.Window;
+import java.awt.peer.WindowPeer;
+
+/**
+ * An abstract base class for Swing based WindowPeer implementation. Concrete
+ * implementations of WindowPeers should subclass this class in order to get
+ * the correct behaviour.
+ *
+ * As a minimum, a subclass must implement all the remaining abstract methods
+ * as well as the following methods:
+ *
+ *
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public abstract class SwingWindowPeer
+ extends SwingContainerPeer
+ implements WindowPeer
+{
+
+ /**
+ * Creates a new instance of WindowPeer.
+ *
+ * @param window the AWT window
+ */
+ public SwingWindowPeer(Window window)
+ {
+ super(window);
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/peer/swing/package.html b/libjava/classpath/gnu/java/awt/peer/swing/package.html
new file mode 100644
index 0000000..506eda8
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/peer/swing/package.html
@@ -0,0 +1,71 @@
+
+
+
+
+
+ Swing based AWT peers.
+
+
+ SwingToolkit
.SwingXXXPeer
counterparts.
+ Some methods must be specially
+ overridden in those peers to provide useful functionality, like
+ getLocationOnScreen()
. See the API documentation for more
+ details
ExceptionListener
instance on its own.
+ *
+ * The implementation just writes the exception's message
+ * to System.err
and is used by the {@link java.beans.Encoder}
+ * and the {@link java.beans.XMLDecoder}.
+ *
The implementation just writes the exception's message to System.err
.
doc/unicode/UnicodeData-3.0.0.txt
and
- * doc/unicode/SpecialCasing-2.txt
, by some
- * perl scripts. These Unicode definition file can be found on the
+ * ../doc/unicode/UnicodeData-4.0.0.txt
and
+ * ../doc/unicode/SpecialCasing-4.0.0.txt
, by some
+ * perl scripts. These Unicode definition files can be found on the
* http://www.unicode.org website.
- * JDK 1.4 uses Unicode version 3.0.0.
+ * JDK 1.5 uses Unicode version 4.0.0.
*
* The data is stored as string constants, but Character will convert these
- * Strings to their respective char[]
components. The field
+ * Strings to their respective char[]
components. The fields
+ * are stored in arrays of 17 elements each, one element per Unicode plane.
* BLOCKS
stores the offset of a block of 2SHIFT
* characters within DATA
. The DATA field, in turn, stores
* information about each character in the low order bits, and an offset
* into the attribute tables UPPER
, LOWER
,
* NUM_VALUE
, and DIRECTION
. Notice that the
* attribute tables are much smaller than 0xffff entries; as many characters
- * in Unicode share common attributes. The DIRECTION table also contains
- * a field for detecting characters with multi-character uppercase expansions.
+ * in Unicode share common attributes. Numbers that are too large to fit
+ * into NUM_VALUE as 16 bit chars are stored in LARGENUMS and a number N is
+ * stored in NUM_VALUE such that (-N - 3) is the offset into LARGENUMS for
+ * the particular character. The DIRECTION table also contains a field for
+ * detecting characters with multi-character uppercase expansions.
* Next, there is a listing for TITLE
exceptions (most characters
* just have the same title case as upper case). Finally, there are two
* tables for multi-character capitalization, UPPER_SPECIAL
@@ -73,208 +77,622 @@ public interface CharData
/**
* The Unicode definition file that was parsed to build this database.
*/
- String SOURCE = "doc/unicode/UnicodeData-3.0.0.txt";
+ String SOURCE = "../doc/unicode/UnicodeData-4.0.0.txt";
/**
* The character shift amount to look up the block offset. In other words,
- * (char) (BLOCKS.value[ch >> SHIFT] + ch)
is the index where
- * ch
is described in DATA
.
+ * (char) (BLOCKS.value[ch >> SHIFT[p]] + ch)
is the index
+ * where ch
is described in DATA
if ch
+ * is in Unicode plane p
. Note that p
is simply
+ * the integer division of ch and 0x10000.
*/
- int SHIFT = 5;
+ int[] SHIFT
+ = new int[] {4, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8};
/**
* The mapping of character blocks to their location in DATA
.
* Each entry has been adjusted so that the 16-bit sum with the desired
* character gives the actual index into DATA
.
*/
- String BLOCKS
- = "\u01c2\u01c2\u01c1\u012c\u012b\u01a0\u01f8\u02dc\u025f\u02ee\u0215"
- + "\u0346\u02dc\u0326\u02bc\u0216\u015f\u02d4\u0376\u0376\u0376\u0369"
- + "\ufe8f\u0344\uff85\uff65\ufdb5\ufda1\033\u02c4\034G\ufea8"
- + "\uff8c\u0235\ufeff\032\ufebf&\ufb20\ufe28\u0113\u0104\ufb61"
- + "\ufb5a\u010b\u0109\u00fe\uff08\u0229\u025e\u01c7\u01fc\u01dc\ufc46"
- + "\u0229\ufe27\ufb55\u0169\ufbc8\u00fc\u0103\ufb68\ufb48\ufb28\ufb08"
- + "\ufae8\ufac8\ufaa8\ufa88\ufa68\ufa48eP\u00ab\u0139\ufe0e"
- + "c\u0155\u01a8\uf669\u0129\u0128\uf91f\ufe56\u0108\u0107\ufac0"
- + "\ufc8e\ufead\u00c6\ufca7\ufb95\uf47d\u009f\ufb17\ufe20\ufd28\ufb2f"
- + ";\uf3b9\ufe57\ufcce\uffbb\uf339\ufa98\uff8b\uff3b\ufa54\uf7e3"
- + "\uff2b\ufad7\ufb69\ufc3a\ufee5\uf4c8\ufcb0\ufa88\ufdbf\uf448\ufe45"
- + "\ufcc7\ufe4f\uf7f1\uf715\uf2e8\ufd9f\uf348\uf96a\ufc02\ufd97\uf2c8"
- + "\uf2a8\uf4b9\uf4b3\uef6b\uf86a\uf84a\ufc58\uf80a\uf7ea\ufc0f\uf7aa"
- + "\uee9c\ufb90\uf74a\uf7fa\uf70a\uf7ca\uf792\uf471\uf4d2\uf732\uf64a"
- + "\uf401\uf64d\uefa8\uf5ca\uf5aa\ueca1\uf569\uf54a\uf52a\uf50a\uf4ea"
- + "\uf4ca\uf4aa\uf48a\uf46a\uf44a\uf42a\uf40a\uf3ea\uf3ca\uf3aa\uf38a"
- + "\uf36a\uf34a\uf32a\uf289\uf777\uf2ca\uf2aa\uf737\uec28\uec08\uebe8"
- + "\uebc8\uf1ea\uf4a2\uf545\uedc6\uf2d7\uf14a\ue8ed\ue81e\uf0ea\uf597"
- + "\uea68\uea48\uea28\uea08\ue9e8\ue9c8\ue9a8\ue988\ue968\ue948\ue928"
- + "\ue908\ue8e8\ue8c8\ue8a8\ue888\ue868\ue848\ue828\ue808\ue7e8\ue7c8"
- + "\ue7a8\ue788\ue768\ue748\ue728\ue708\ue6e8\ue6c8\ue6a8\ue688\ue668"
- + "\ue648\ue628\ue608\ue5e8\ue5c8\ue5a8\ue588\ue568\ue548\ue55f\ue53f"
- + "\ue51f\ue4ff\uefd7\ue4bf\ue49f\ue485\uef87\uef57\uef57\uef57\uef57"
- + "\uef47\ue1ad\uef46\uef46\uef46\ue1e0\ue3dd\uef06\ue9d9\uebeb\ue244"
- + "\ueed4\uef65\ue1f5\uef45\ueee9\uef7c\uee74\uef70\uef7d\uef78\uee91"
- + "\uefd3\uee7d\uee25\uee27\uef65\uefdd\uee96\uefd3\uefe1\uef69\udf88"
- + "\udf68\udf48\ued2b\ued3d\ued19\uef1c\uef08\ued47\ued3d\ued33\uec2b"
- + "\uec0b\uebeb\uebcb\uebce\uea7c\ueb69\ueb6c\ue9b6\ueb0b\ueaeb\ue9e9"
- + "\udca8\udc88\udc68\udc48\ue910\uea23\ueb58\ueb4f\ueb45\ueae5\udb68"
- + "\udb48\ue92b\ue90b\ue8eb\ue8cb\ue8ab\ue88b\ue86b\ue84b\uda28\uda08"
- + "\ud9e8\ud9c8\ud9a8\ud988\ud968\ud948\ud928\ud908\ud8e8\ud8c8\ud8a8"
- + "\ud888\ud868\ud848\ud828\ud808\ud7e8\ud7c8\ud7a8\ud788\ud768\ud748"
- + "\ud728\ud708\ud6e8\ud6c8\ud6a8\ud688\ud668\ud648\ud628\ud608\ud5e8"
- + "\ud5c8\ud5a8\ud588\ud568\ud548\ud528\ud508\ud4e8\ud4c8\ue2b1\ue28b"
- + "\ue26b\ue270\ue22b\ue20b\ue1eb\ue1cb\ue1ab\ue18b\ue18e\udd8f\ue3a8"
- + "\udfd3\ud929\ud90a\ue348\ud8c9\ud8aa\udcd7\udcb2\ud681\ud82a\ud80a"
- + "\ue268\ucede\ud168\ud148\ue116\ue0e9\ue1cb\ue0b7\ue0b7\ue15e\udf17"
- + "\ue034\ue013\udff3\udfd3\ude6c\udf93\udf73\udf55\udf34\ud56a\ud54a"
- + "\ud52a\ud50a\ud4ea\ud4ca\ud4aa\ud48a\ud46a\ud44a\ud42a\ud40a\ud3ea"
- + "\ud3ca\ud3aa\ud38a\ud36a\ud34a\ud32a\ud30a\ud2ea\ud2ca\ud2aa\ud28a"
- + "\ud26a\ud24a\ud22a\ud20a\ud1ea\ud1ca\ud1aa\ud18a\ud16a\ud14a\ud12a"
- + "\ud10a\ud0ea\ud0ca\ud0aa\ud08a\ud06a\ud04a\ud02a\ud00a\ucfea\ucfca"
- + "\ucfaa\ucf8a\ucf6a\ucf4a\ucf2a\ucf0a\uceea\uceca\uceaa\uce8a\uce6a"
- + "\uce4a\uce2a\uce0a\ucdea\ucdca\ucdaa\ucd8a\ucd6a\ucd4a\ucd2a\ucd0a"
- + "\uccea\uccca\uccaa\ucc8a\ucc6a\ucc4a\ucc2a\ucc0a\ucbea\ucbca\ucbaa"
- + "\ucb8a\ucb6a\ucb4a\ucb2a\ucb0a\ucaea\ucaca\ucaaa\uca8a\uca6a\uca4a"
- + "\uca2a\uca0a\uc9ea\uc9ca\uc9aa\uc98a\uc96a\uc94a\uc92a\uc90a\uc8ea"
- + "\uc8ca\uc8aa\uc88a\uc86a\uc84a\uc82a\uc80a\uc7ea\uc7ca\uc7aa\uc78a"
- + "\uc76a\uc74a\uc72a\uc70a\uc6ea\uc6ca\uc6aa\uc68a\uc66a\uc64a\uc62a"
- + "\uc60a\uc5ea\uc5ca\uc5aa\uc58a\uc56a\uc54a\uc52a\uc50a\uc4ea\uc4ca"
- + "\uc4aa\uc48a\uc46a\uc44a\uc42a\uc40a\uc3ea\uc3ca\uc3aa\uc38a\uc36a"
- + "\uc34a\uc32a\uc30a\uc2ea\uc2ca\uc2aa\uc28a\uc26a\uc24a\uc22a\uc20a"
- + "\uc1ea\uc1ca\uc1aa\uc18a\uc16a\uc14a\uc12a\uc10a\uc0ea\uc0ca\uc0aa"
- + "\uc08a\uc06a\uc04a\uc02a\uc00a\ubfea\ubfca\ubfaa\ubf8a\ubf6a\ubf4a"
- + "\ubf2a\ubf0a\ubeea\ubeca\ubeaa\ube8a\ube6a\ube4a\ube2a\ube0a\ubdea"
- + "\ubdca\ubdaa\ubd8a\ubd6a\ubd4a\ubd2a\ubd0a\ubcea\ubcca\ubcaa\ubc8a"
- + "\ubc6a\ubc4a\ubc2a\ubc0a\ubbea\ub2e0\ub568\ub548\ubb6a\ubb4a\ubb2a"
- + "\ubb0a\ubaea\ubaca\ubaaa\uba8a\uba6a\uba4a\uba2a\uba0a\ub9ea\ub9ca"
- + "\ub9aa\ub98a\ub96a\ub94a\ub92a\ub90a\ub8ea\ub8ca\ub8aa\ub88a\ub86a"
- + "\ub84a\ub82a\ub80a\ub7ea\ub7ca\ub7aa\ub78a\ub76a\ub74a\ub72a\ub70a"
- + "\ub6ea\ub6ca\ub6aa\ub68a\ub66a\ub64a\ub62a\ub60a\ub5ea\ub5ca\ub5aa"
- + "\ub58a\ub56a\ub54a\ub52a\ub50a\ub4ea\ub4ca\ub4aa\ub48a\ub46a\ub44a"
- + "\ub42a\ub40a\ub3ea\ub3ca\ub3aa\ub38a\ub36a\ub34a\ub32a\ub30a\ub2ea"
- + "\ub2ca\ub2aa\ub28a\ub26a\ub24a\ub22a\ub20a\ub1ea\ub1ca\ub1aa\ub18a"
- + "\ub16a\ub14a\ub12a\ub10a\ub0ea\ub0ca\ub0aa\ub08a\ub06a\ub04a\ub02a"
- + "\ub00a\uafea\uafca\uafaa\uaf8a\uaf6a\uaf4a\uaf2a\uaf0a\uaeea\uaeca"
- + "\uaeaa\uae8a\uae6a\uae4a\uae2a\uae0a\uadea\uadca\uadaa\uad8a\uad6a"
- + "\uad4a\uad2a\uad0a\uacea\uacca\uacaa\uac8a\uac6a\uac4a\uac2a\uac0a"
- + "\uabea\uabca\uabaa\uab8a\uab6a\uab4a\uab2a\uab0a\uaaea\uaaca\uaaaa"
- + "\uaa8a\uaa6a\uaa4a\uaa2a\uaa0a\ua9ea\ua9ca\ua9aa\ua98a\ua96a\ua94a"
- + "\ua92a\ua90a\ua8ea\ua8ca\ua8aa\ua88a\ua86a\ua84a\ua82a\ua80a\ua7ea"
- + "\ua7ca\ua7aa\ua78a\ua76a\ua74a\ua72a\ua70a\ua6ea\ua6ca\ua6aa\ua68a"
- + "\ua66a\ua64a\ua62a\ua60a\ua5ea\ua5ca\ua5aa\ua58a\ua56a\ua54a\ua52a"
- + "\ua50a\ua4ea\ua4ca\ua4aa\ua48a\ua46a\ua44a\ua42a\ua40a\ua3ea\ua3ca"
- + "\ua3aa\ua38a\ua36a\ua34a\ua32a\ua30a\ua2ea\ua2ca\ua2aa\ua28a\ua26a"
- + "\ua24a\ua22a\ua20a\ua1ea\ua1ca\ua1aa\ua18a\ua16a\ua14a\ua12a\ua10a"
- + "\ua0ea\ua0ca\ua0aa\ua08a\ua06a\ua04a\ua02a\ua00a\u9fea\u9fca\u9faa"
- + "\u9f8a\u9f6a\u9f4a\u9f2a\u9f0a\u9eea\u9eca\u9eaa\u9e8a\u9e6a\u9e4a"
- + "\u9e2a\u9e0a\u9dea\u9dca\u9daa\u9d8a\u9d6a\u9d4a\u9d2a\u9d0a\u9cea"
- + "\u9cca\u9caa\u9c8a\u9c6a\u9c4a\u9c2a\u9c0a\u9bea\u9bca\u9baa\u9b8a"
- + "\u9b6a\u9b4a\u9b2a\u9b0a\u9aea\u9aca\u9aaa\u9a8a\u9a6a\u9a4a\u9a2a"
- + "\u9a0a\u99ea\u99ca\u99aa\u998a\u996a\u994a\u992a\u990a\u98ea\u98ca"
- + "\u98aa\u988a\u986a\u984a\u982a\u980a\u97ea\u97ca\u97aa\u978a\u976a"
- + "\u974a\u972a\u970a\u96ea\u96ca\u96aa\u968a\u966a\u964a\u962a\u960a"
- + "\u95ea\u95ca\u95aa\u958a\u956a\u954a\u952a\u950a\u94ea\u94ca\u94aa"
- + "\u948a\u946a\u944a\u942a\u940a\u93ea\u93ca\u93aa\u938a\u936a\u934a"
- + "\u932a\u930a\u92ea\u92ca\u92aa\u928a\u926a\u924a\u922a\u920a\u91ea"
- + "\u91ca\u91aa\u918a\u916a\u914a\u912a\u910a\u90ea\u90ca\u90aa\u908a"
- + "\u906a\u904a\u902a\u900a\u8fea\u8fca\u8faa\u8f8a\u8f6a\u8f4a\u8f2a"
- + "\u8f0a\u8eea\u8eca\u8eaa\u8e8a\u8e6a\u8e4a\u8e2a\u8e0a\u8dea\u8dca"
- + "\u8daa\u8d8a\u8d6a\u8d4a\u8d2a\u8d0a\u8cea\u8cca\u8caa\u8c8a\u8c6a"
- + "\u8c4a\u8c2a\u8c0a\u8bea\u8bca\u8baa\u8b8a\u8b6a\u8b4a\u8b2a\u8b0a"
- + "\u8aea\u8aca\u8aaa\u8a8a\u8a6a\u8a4a\u8a2a\u8a0a\u89ea\u89ca\u89aa"
- + "\u898a\u896a\u894a\u892a\u890a\u88ea\u88ca\u88aa\u888a\u886a\u884a"
- + "\u882a\u880a\u87ea\u87ca\u87aa\u878a\u876a\u874a\u872a\u870a\u86ea"
- + "\u86ca\u86aa\u868a\u866a\u864a\u862a\u860a\u85ea\u85ca\u85aa\u858a"
- + "\u856a\u854a\u852a\u850a\u84ea\u84ca\u84aa\u848a\u846a\u844a\u842a"
- + "\u840a\u83ea\u83ca\u83aa\u838a\u836a\u834a\u832a\u830a\u82ea\u82ca"
- + "\u82aa\u828a\u826a\u824a\u822a\u820a\u81ea\u81ca\u81aa\u818a\u816a"
- + "\u814a\u812a\u810a\u80ea\u80ca\u80aa\u808a\u806a\u804a\u802a\u800a"
- + "\u7fea\u7fca\u7faa\u7f8a\u7f6a\u7f4a\u7f2a\u7f0a\u7eea\u7eca\u7eaa"
- + "\u7e8a\u7e6a\u7e4a\u7e2a\u7e0a\u7dea\u7dca\u7daa\u7d8a\u7d6a\u7d4a"
- + "\u7d2a\u7d0a\u7cea\u7cca\u7caa\u7c8a\u7c6a\u7c4a\u7c2a\u7c0a\u7bea"
- + "\u7bca\u7baa\u7b8a\u7b6a\u7b4a\u7b2a\u7b0a\u7aea\u7aca\u7aaa\u7a8a"
- + "\u7a6a\u7a4a\u7a2a\u7a0a\u79ea\u79ca\u79aa\u798a\u796a\u794a\u792a"
- + "\u790a\u78ea\u78ca\u78aa\u788a\u786a\u784a\u782a\u780a\u77ea\u77ca"
- + "\u77aa\u778a\u776a\u774a\u772a\u770a\u76ea\u76ca\u76aa\u768a\u766a"
- + "\u764a\u762a\u760a\u75ea\u75ca\u75aa\u758a\u756a\u754a\u752a\u750a"
- + "\u74ea\u74ca\u74aa\u748a\u746a\u744a\u742a\u740a\u73ea\u73ca\u73aa"
- + "\u738a\u736a\u734a\u732a\u730a\u72ea\u72ca\u72aa\u728a\u726a\u724a"
- + "\u722a\u720a\u71ea\u71ca\u71aa\u718a\u716a\u714a\u712a\u710a\u70ea"
- + "\u70ca\u70aa\u708a\u706a\u704a\u702a\u700a\u6fea\u6fca\u6faa\u6f8a"
- + "\u6f6a\u6f4a\u6f2a\u6f0a\u6eea\u6eca\u6eaa\u6e8a\u6e6a\u6e4a\u6e2a"
- + "\u6e0a\u6dea\u6dca\u6daa\u6d8a\u6d6a\u6d4a\u6d2a\u6d0a\u6cea\u6cca"
- + "\u6caa\u6c8a\u6c6a\u6c4a\u6c2a\u6c0a\u6bea\u6bca\u6baa\u6b8a\u6b6a"
- + "\u6b4a\u6b2a\u6b0a\u6aea\u6aca\u6aaa\u6a8a\u6a6a\u6a4a\u6a2a\u6a0a"
- + "\u69ea\u60f0\u6368\u6348\u696a\u694a\u692a\u690a\u68ea\u68ca\u68aa"
- + "\u688a\u686a\u684a\u682a\u680a\u67ea\u67ca\u67aa\u678a\u676a\u674a"
- + "\u672a\u670a\u66ea\u66ca\u66aa\u668a\u666a\u664a\u662a\u660a\u65ea"
- + "\u65ca\u65aa\u658a\u656a\u654a\u652a\u650a\u6b26\u6de1\u6e9c\u5e48"
- + "\u5e28\u5e08\u5de8\u5dc8\u5da8\u5d88\u5d68\u5d48\u5d28\u5d08\u5ce8"
- + "\u5cc8\u5ca8\u5c88\u5c68\u5c48\u5c28\u5c08\u5be8\u5bc8\u5ba8\u5b88"
- + "\u5b68\u5b48\u5b28\u5b08\u5ae8\u5ac8\u5aa8\u5a88\u5a68\u5a48\u5a28"
- + "\u5a08\u59e8\u59c8\u59a8\u5988\u5968\u5948\u5928\u5908\u58e8\u58c8"
- + "\u58a8\u5888\u5868\u5848\u5828\u5808\u57e8\u57c8\u57a8\u5788\u5768"
- + "\u5748\u5d6a\u5d4a\u5d2a\u5d0a\u5cea\u5cca\u5caa\u5c8a\u5c6a\u5c4a"
- + "\u5c2a\u5c0a\u5bea\u5bca\u5baa\u5b8a\u5b6a\u5b4a\u5b2a\u5b0a\u5aea"
- + "\u5aca\u5aaa\u5a8a\u5a6a\u5a4a\u5a2a\u5a0a\u59ea\u59ca\u59aa\u598a"
- + "\u596a\u594a\u592a\u590a\u58ea\u58ca\u58aa\u588a\u586a\u584a\u582a"
- + "\u580a\u57ea\u57ca\u57aa\u578a\u576a\u574a\u572a\u570a\u56ea\u56ca"
- + "\u56aa\u568a\u566a\u564a\u562a\u560a\u55ea\u55ca\u55aa\u558a\u556a"
- + "\u554a\u552a\u550a\u54ea\u54ca\u54aa\u548a\u546a\u544a\u542a\u540a"
- + "\u53ea\u53ca\u53aa\u538a\u536a\u534a\u532a\u530a\u52ea\u52ca\u52aa"
- + "\u528a\u526a\u524a\u522a\u520a\u51ea\u51ca\u51aa\u518a\u516a\u514a"
- + "\u512a\u510a\u50ea\u50ca\u50aa\u508a\u506a\u504a\u502a\u500a\u4fea"
- + "\u4fca\u4faa\u4f8a\u4f6a\u4f4a\u4f2a\u4f0a\u4eea\u4eca\u4eaa\u4e8a"
- + "\u4e6a\u4e4a\u4e2a\u4e0a\u4dea\u4dca\u4daa\u4d8a\u4d6a\u4d4a\u4d2a"
- + "\u4d0a\u4cea\u4cca\u4caa\u4c8a\u4c6a\u4c4a\u4c2a\u4c0a\u4bea\u4bca"
- + "\u4baa\u4b8a\u4b6a\u4b4a\u4b2a\u4b0a\u4aea\u4aca\u4aaa\u4a8a\u4a6a"
- + "\u4a4a\u4a2a\u4a0a\u49ea\u49ca\u49aa\u498a\u496a\u494a\u492a\u490a"
- + "\u48ea\u48ca\u48aa\u488a\u486a\u484a\u482a\u480a\u47ea\u47ca\u47aa"
- + "\u478a\u476a\u474a\u472a\u470a\u46ea\u46ca\u46aa\u468a\u466a\u464a"
- + "\u462a\u460a\u45ea\u45ca\u45aa\u458a\u456a\u454a\u452a\u450a\u44ea"
- + "\u44ca\u44aa\u448a\u446a\u444a\u442a\u440a\u43ea\u43ca\u43aa\u438a"
- + "\u436a\u434a\u432a\u430a\u42ea\u42ca\u42aa\u428a\u426a\u424a\u422a"
- + "\u420a\u41ea\u41ca\u41aa\u418a\u416a\u414a\u412a\u410a\u40ea\u40ca"
- + "\u40aa\u408a\u406a\u404a\u402a\u400a\u3fea\u3fca\u3faa\u3f8a\u3f6a"
- + "\u3f4a\u3f2a\u3f0a\u3eea\u3eca\u3eaa\u3e8a\u3e6a\u3e4a\u3e2a\u3e0a"
- + "\u3dea\u3dca\u3daa\u3d8a\u3d6a\u3d4a\u3d2a\u3d0a\u3cea\u3cca\u3caa"
- + "\u3c8a\u3c6a\u3c4a\u3c2a\u3c0a\u3bea\u3bca\u3baa\u3b8a\u3b6a\u3b4a"
- + "\u3b2a\u3b0a\u3aea\u3aca\u3aaa\u3a8a\u3a6a\u3a4a\u3a2a\u3a0a\u39ea"
- + "\u39ca\u39aa\u398a\u396a\u394a\u392a\u390a\u38ea\u38ca\u38aa\u388a"
- + "\u386a\u384a\u382a\u380a\u37ea\u37ca\u37aa\u378a\u376a\u374a\u372a"
- + "\u370a\u36ea\u36ca\u36aa\u368a\u366a\u364a\u362a\u360a\u35ea\u35ca"
- + "\u35aa\u358a\u356a\u354a\u352a\u350a\u34ea\u34ca\u34aa\u348a\u346a"
- + "\u344a\u342a\u340a\u33ea\u33ca\u33aa\u338a\u336a\u334a\u332a\u330a"
- + "\u32ea\u32ca\u32aa\u328a\u326a\u324a\u322a\u320a\u31ea\u28f2\u2b68"
- + "\u2b48\u3c2b\u3c0b\u3beb\u3bcb\u3bab\u3b8b\u3b6b\u3b4b\u3b2b\u3b0b"
- + "\u3aeb\u3acb\u3aab\u3a8b\u3a6b\u3a4b\u3a2b\u3a0b\u39eb\u39cb\u39ab"
- + "\u398b\u396b\u394b\u392b\u390b\u38eb\u38cb\u38ab\u388b\u386b\u384b"
- + "\u382b\u380b\u37eb\u37cb\u37ab\u378b\u376b\u374b\u372b\u370b\u36eb"
- + "\u36cb\u36ab\u368b\u366b\u364b\u362b\u360b\u35eb\u35cb\u35ab\u358b"
- + "\u356b\u354b\u352b\u350b\u34eb\u34cb\u34ab\u348b\u346b\u344b\u344b"
- + "\u342b\u340b\u33eb\u33cb\u33ab\u338b\u336b\u334b\u332b\u330b\u32eb"
- + "\u32cb\u32ab\u328b\u326b\u324b\u322b\u320b\u31eb\u31cb\u31ab\u318b"
- + "\u316b\u314b\u312b\u310b\u30eb\u30cb\u30ab\u308b\u306b\u304b\u302b"
- + "\u300b\u2feb\u2fcb\u2fab\u2f8b\u2f6b\u2f4b\u2f2b\u2f0b\u2eeb\u2ecb"
- + "\u2eab\u2e8b\u2e6b\u2e4b\u2e2b\u2e0b\u2deb\u2dcb\u2dab\u2d8b\u2d6b"
- + "\u2d4b\u2d2b\u2d0b\u2ceb\u2ccb\u2cab\u2c8b\u2c6b\u2c4b\u2c2b\u2c0b"
- + "\u2beb\u2bcb\u2bab\u2b8b\u2b6b\u2b4b\u2b2b\u2b0b\u2aeb\u2acb\u2aab"
- + "\u2a8b\u2a6b\u2a4b\u2a2b\u2a0b\u29eb\u29cb\u29ab\u298b\u296b\u294b"
- + "\u292b\u290b\u28eb\u28cb\u28ab\u288b\u286b\u284b\u282b\u280b\u27eb"
- + "\u27cb\u27ab\u278b\u276b\u274b\u272b\u270b\u26eb\u26cb\u26ab\u268b"
- + "\u266b\u264b\u262b\u260b\u25eb\u25cb\u25ab\u258b\u256b\u254b\u252b"
- + "\u250b\u24eb\u24cb\u24ab\u248b\u246b\u244b\u242b\u240b\u23eb\u23cb"
- + "\u23ab\u238b\u236b\u234b\u232b\u230b\u22eb\u22cb\u22ab\u228b\u226b"
- + "\u224b\u222b\u220b\u21eb\u21cb\u21ab\u218b\u216b\u214b\u212b\u210b"
- + "\u20eb\u20cb\u20ab\u208b\u206b\u204b\u202b\u200b\u1feb\u1fcb\u1fab"
- + "\u1f8b\u1f6b\u1f4b\u1f2b\u1f0b\u1eeb\u1ecb\u1eab\u1e8b\u1e6b\u1e4b"
- + "\u1e2b\u1e0b\u1deb\u1dcb\u1dab\u1d8b\u1d6b\u1d4b\u1d2b\u1d0b\u1ceb"
- + "\u1ccb\u1cab\u1c8b\u1c6b\u1c4b\u1c2b\u1c0b\u1beb\u1bcb\u1bab\u1b8b"
- + "\u1b6b\u106a\u104a\u102a\u100a\u0fea\u0fca\u0faa\u0f8a\u0f6a\u0668"
- + "\u08e8\u08c8\u08a8\u0888\u0868\u0848\u07d7\u194b\u07b6\u0d1c\u0cfc"
- + "\u0cb2\u0ca9\u0c9c\u0c7c\u0c5c\u0c3c\u0c1c\u0bfc\u0bdc\u0bbc\u0b9c"
- + "\u0b7c\u0b5e\u0b2c\u0b1c\u0ab8\u0adc\u0a9c\u02c2\u0528\u166b\u1667"
- + "\u03ff\u09fc\u09dc\u09bc\u0659\u0bb8\u15a7\u0fc6\u01c0\u01b1\u09cb"
- + "\u082c\u1285";
+ String[] BLOCKS = new String[]{
+ "\017\0275\00744Z\uff90\uff9d\uff93\013"
+ + "\uffb5\013\004\034\025\027\007\ufff7\u00ad\u010d\uffc7"
+ + "\uffb7\uff7b\u0111\u0111\u00b7\u0101\uffdc\uff4a\uff37\ufef3\uff17"
+ + "\uff07\ufef5\uff79\u00dc2\u0141\005\uffe7\u013d\u0130\u0137"
+ + "\u0163\u0163\u0112\u0145\u0166\u0156\u0146\u0136\uff81\u0191\u0106"
+ + "\ufe84\u01ca\ufd3a\u01ba\ufd4b\u01aa\ufe74\ufd37\u014e\u01b3\ufcbb"
+ + "\ufcab\ufccc\ufcbc\u0173\ufcb7\ufca7\ufca8\ufc87\ufc77\ufc67\u0113"
+ + "\ufc47\ufc37\ufc42\ufc17\ufe0c\ufdfc\ufcd3\ufcc4\ufcbd\ufe0a\ufdfb"
+ + "\ufdf4\ufed5\ufec3\ufd17\ufd15\u008a\u007f\u00b5\ufdb1\u00dc\ufd6e"
+ + "\u00f9\u00cb\uffe3k\u00f9\ufd0f\ufcff\ufcef\ufcdf\ufccf\011"
+ + "\u00abi\ufffbX\ufc6f\ufd36\uffd6\ufbcc\ufbbc\ufbac\ufc0f"
+ + "\ufbff\uff70\ufff9\ufb5c\ufb4c\ufb3c\ufb2c\ufb1c\ufb0c\ufafc\ufaec"
+ + "\ufadc\ufacc\ufabc\ufaac\ufa9c\ufa8c\ufa7c\ufa6c\ufa5c\ufa4c\ufa3c"
+ + "\ufa2c\ufee1\ufb03\ufaf3\ufef3\ufcd4\uff0b\uff13\uf9ab\ufb8a\uf7fa"
+ + "\ufa69\ufbe5\ufb6e\uf90e\ufea9\ufeaf\ufb79\uf77a\uf9e9\uf8c7\ufdfc"
+ + "\uf760\ufb82\ufe3f\uf6e4\uf980\uf969\uf70e\ufbc6\uf764\ufda9\ufddd"
+ + "\ufa0a\uf67a\uf8e9\ufb48\uf68d\uf5ec\ufd91\uf6c3\uf7c4\uf75b\uf7af"
+ + "\uf75b\uf93b\ufade\ufb5b\ufd17\uf704\uf801\uf7e9\ufba4\ufcd7\uf72f"
+ + "\ufc91\uf6ac\ufb4b\uf781\uf769\ufc77\ufb71\uf99a\ufc11\uf62c\ufacb"
+ + "\uf701\uf6e9\ufa8f\ufbf7\uf95e\ufb91\uf5ac\ufbd4\uf3eb\uf673\uf7da"
+ + "\ufb87\uf832\uf53c\uf527\uf612\uf603\uf5f3\ufa8f\ufa9d\ufa29\uf4bc"
+ + "\uf4ac\uf2c7\uf6f4\uf678\ufab9\ufab9\uf9bf\uf43c\uf42c\ufa89\uf30a"
+ + "\uf6c8\uf6c4\uf4ca\uf4c3\uf89b\uf57d\uf967\uf4cd\uf4c6\uf4b9\uf264"
+ + "\uf34c\uf33c\uf32c\uf413\uf403\uf502\uf969\uf8b7\uf959\uf2bc\uf2ac"
+ + "\uf29c\uf28c\uf927\uf917\uf911\uf343\uf333\uf773\uf313\uf303\uf2f3"
+ + "\uf2e3\uf2d3\uf6ac\uf2b3\uf2a3\uf293\uf283\uf663\uf263\uf253\uf243"
+ + "\uf233\uf7f1\uf20b\uf203\uf1f3\uf1e3\uef2b\uef1b\uf1b3\uf1a3\ueeeb"
+ + "\uf183\uf163\ueec3\ueeb3\uf13b\uf123\uf123\uf103\uee63\uf0f3\uf0e3"
+ + "\uf0cb\uf4ab\uf2c3\uf3d9\uef9c\uef8c\uf073\uf063\uf053\uf043\uf033"
+ + "\uf5f6\uf012\uf003\ueff3\uefe3\uefd3\uefc3\uefb3\uefa3\uef93\uef83"
+ + "\uef73\uef63\uef53\uef43\uef33\uef23\uef13\uef03\ueef3\ueee3\ueed3"
+ + "\ueec3\ueeb3\ueea3\uee93\uee83\uee73\uee63\uee53\uee43\uee33\uee23"
+ + "\uee13\uee03\uedf3\uede3\uedd3\uedc3\ueb2d\uf374\uf176\uf156\ued73"
+ + "\ued63\ued53\ued43\uf279\uf307\ued05\uf2f7\uecf3\uf2e7\uecd3\uf2d7"
+ + "\ueca5\uf2c7\uec93\uec83\uec73\uf297\uee4c\uf292\ueb56\uf291\uf291"
+ + "\ueb26\uebf3\uebe3\uefda\uebc3\uebb3\uf173\ueb93\ueb83\uf201\uea6c"
+ + "\uea5c\uea4c\uea3c\uea2c\ueb13\ueee9\uf132\uec73\ue9f0\ueac3\uee98"
+ + "\uf076\ue99c\ue98c\ue97c\ue96c\ue95c\ue94c\uf0e4\uf0d4\ue91c\ue90c"
+ + "\ue8fc\ue8ec\ue8dc\ue8cc\ue8bc\ue8ac\ue89c\ue88c\ue87c\ue86c\ue85c"
+ + "\ue84c\ue83c\ue82c\ue81c\ue80c\ue7fc\ue7ec\ue7dc\ue7cc\ue7bc\ue7ac"
+ + "\ue79c\ue78c\ue77c\ue76c\ue75c\ue74c\ue73c\ue72c\ue71c\ue70c\ue6fc"
+ + "\ue6ec\ue6dc\ue6cc\ue6bc\ue6ac\ue69c\ue68c\ue67c\ue66c\ue65c\ue64c"
+ + "\ue63c\ue62c\ue6d0\ue6c0\ue6b4\ue6b0\ue6a0\ue690\uee5e\ue5ac\ue59c"
+ + "\ue58c\ue57c\ue56c\ue55c\ue54c\ue53c\ue52c\ue317\ue307\ue2f7\ue2e7"
+ + "\ue2d7\ue2c7\ue2b7\ue2a7\ue297\ue358\ue277\ue267\ue257\ue247\ue237"
+ + "\ue6e8\uecce\uecce\uecae\uec9e\uec9e\uec9e\uec6e\uec8e\uec8e\uec7e"
+ + "\uec6e\uec6e\ue483\uec5e\uec5e\ue165\uec4e\uec4e\ue07b\uec4d\ue053"
+ + "\udff6\ue71b\uec1d\uec1d\ue28c\uec0d\uec0b\ue25c\uebfb\ue607\ue22c"
+ + "\ue2bf\ue9a1\uea8e\ue889\uec17\ue56b\uec07\uec07\uec07\uea12\uebf7"
+ + "\ue914\ue906\ue8ef\ue8e4\ue8e0\ue967\ueb1b\ueb16\ue8d2\ueacf\uea9a"
+ + "\ue8b9\uea9c\ue8d2\ue8f5\uea66\uea63\uea30\ue87c\uea2e\uea1c\ueaa6"
+ + "\ue7b4\uea90\uea8b\uea81\uea71\uea61\ue10d\ue744\ue114\ue734\ue100"
+ + "\ue704\uea29\udf3c\udf2c\ue6c4\ue6b4\ue9d3\udeec\ue9af\udecc\ue9b1"
+ + "\ue99d\ue989\ue989\ue921\ue9aa\ue9a0\ue9a0\ue996\ue582\ue5c4\ue5b4"
+ + "\ue5a4\ue594\ue584\ue574\ue564\ue554\ue544\ue534\ue524\ue7ee\ue502"
+ + "\ue4f4\ue4e4\ue4dc\ue4c4\udea9\ue4a4\ue494\ue484\ue474\ue465\ue77c"
+ + "\ue444\ue768\ue758\udc6c\udc5c\udc4c\udc3c\udc2c\udd98\ue3b4\udd99"
+ + "\ue394\udd4a\ue744\udd61\udd5b\udd51\ue654\ue324\ue63b\udb5c\ue50b"
+ + "\ue6c4\ue2e4\ue2c4\ue2b4\ue2a4\ue294\ue284\ue274\ue264\ue254\ue244"
+ + "\ue234\ue224\ue214\ue204\ue1f4\ue1e4\ue1d4\ue1d4\ue1c4\ue1b4\ue1a4"
+ + "\ue194\ue184\ue174\ue164\ue16e\ue166\ue36c\ue1de\ue1af\ue37b\ue14f"
+ + "\ue0f0\ue0da\ue331\ue13d\ue149\ue094\ue147\ue2bd\ue0d9\ue28c\ue27c"
+ + "\ue081\ue25c\ue24c\ue03d\ue217\ue04c\ue2ec\ud80c\ud7fc\ud7ec\ud7dc"
+ + "\ud7cc\ud7bc\ud7ac\ud79c\ud78c\ud77c\ud76c\ud75c\ud74c\ud73c\ud72c"
+ + "\ud71c\ud70c\ud6fc\ud6ec\ud6dc\ud6cc\ud6bc\ud6ac\ud69c\ud68c\ud67c"
+ + "\ud66c\ud65c\ud64c\ud63c\ud62c\ud61c\ud60c\ud5fc\ud5ec\ud5dc\ud5cc"
+ + "\ud5bc\ud5ac\ud59c\ud58c\ud57c\ud56c\ud55c\ud54c\ud53c\ud52c\ud51c"
+ + "\ud50c\ud4fc\ud4ec\ud4dc\ud4cc\ud4bc\ud4ac\udc44\ud627\udc24\udc14"
+ + "\udc04\udbf4\udbe4\udf06\udbc4\udbb4\udba4\udb94\udb84\udb74\udb64"
+ + "\udb54\udb44\udb34\udb24\udb14\udb04\ude24\ud33c\uddfe\udeb4\udeb2"
+ + "\ud433\ude56\ud3d2\ud3c3\ud3b3\ud3a3\ud393\ud7bc\ud362\ud363\ud353"
+ + "\ud343\ud333\ud71b\ud706\ud303\ud6d9\ud2e2\ud2d3\ud2c3\ud2b3\ud2a3"
+ + "\ud283\ud2e7\ud273\ud833\ud15c\ud14c\ud13c\ud223\udbc1\udbb4\udc30"
+ + "\udb91\udc00\udc82\udb61\udb55\udbd0\udb31\udb21\udb24\udb65\udaf1"
+ + "\udae1\udb45\udac1\udab1\udaa1\uda91\uda81\uda71\uda61\udaba\uda41"
+ + "\uda31\uda21\uda11\uda01\ud9f3\ud9e1\ud9d2\ud013\ud003\ucff3\ucfe3"
+ + "\ucfd3\ucfc3\ucfb3\ucfa3\ucf93\ucf83\ucf73\ucf63\ucf53\ucf43\ucf33"
+ + "\ucf23\ucf13\ucf03\ucef3\ucee3\uced3\ucec3\uceb3\ucea3\uce93\uce83"
+ + "\uce73\uce63\uce53\uce43\uce33\uce23\uce13\uce03\ucdf3\ucde3\ucdd3"
+ + "\ucdc3\ucdb3\ucda3\ucd93\ucd83\ucd73\ucd63\ucd53\ucd43\ucd33\ucd23"
+ + "\ucd13\ucd03\uccf3\ucce3\uccd3\uccc3\uccb3\ucca3\ucc93\ucc83\ucc73"
+ + "\ucc63\ucc53\ucc43\ucc33\ucc23\ucc13\ucc03\ucbf3\ucbe3\ucbd3\ucbc3"
+ + "\ucbb3\ucba3\ucb93\ucb83\ucb73\ucb63\ucb53\ucb43\ucb33\ucb23\ucb13"
+ + "\ucb03\ucaf3\ucae3\ucad3\ucac3\ucab3\ucaa3\uca93\uca83\uca73\uca63"
+ + "\uca53\uca43\uca33\uca23\uca13\uca03\uc9f3\uc9e3\uc9d3\uc9c3\uc9b3"
+ + "\uc9a3\uc993\uc983\uc973\uc963\uc953\uc943\uc933\uc923\uc913\uc903"
+ + "\uc8f3\uc8e3\uc8d3\uc8c3\uc8b3\uc8a3\uc893\uc883\uc873\uc863\uc853"
+ + "\uc843\uc833\uc823\uc813\uc803\uc7f3\uc7e3\uc7d3\uc7c3\uc7b3\uc7a3"
+ + "\uc793\uc783\uc773\uc763\uc753\uc743\uc733\uc723\uc713\uc703\uc6f3"
+ + "\uc6e3\uc6d3\uc6c3\uc6b3\uc6a3\uc693\uc683\uc673\uc663\uc653\uc643"
+ + "\uc633\uc623\uc613\uc603\uc5f3\uc5e3\uc5d3\uc5c3\uc5b3\uc5a3\uc593"
+ + "\uc583\uc573\uc563\uc553\uc543\uc533\uc523\uc513\uc503\uc4f3\uc4e3"
+ + "\uc4d3\uc4c3\uc4b3\uc4a3\uc493\uc483\uc473\uc463\uc453\uc443\uc433"
+ + "\uc423\uc413\uc403\uc3f3\uc3e3\uc3d3\uc3c3\uc3b3\uc3a3\uc393\uc383"
+ + "\uc373\uc363\uc353\uc343\uc333\uc323\uc313\uc303\uc2f3\uc2e3\uc2d3"
+ + "\uc2c3\uc2b3\uc2a3\uc293\uc283\uc273\uc263\uc253\uc243\uc233\uc223"
+ + "\uc213\uc203\uc1f3\uc1e3\uc1d3\uc1c3\uc1b3\uc1a3\uc193\uc183\uc173"
+ + "\uc163\uc153\uc143\uc133\uc123\uc113\uc103\uc0f3\uc0e3\uc0d3\uc0c3"
+ + "\uc0b3\uc0a3\uc093\uc083\uc073\uc063\uc053\uc043\uc033\uc023\uc013"
+ + "\uc003\ubff3\ubfe3\ubfd3\ubfc3\ubfb3\ubfa3\ubf93\ubf83\ubf73\ubf63"
+ + "\ubf53\ubf43\ubf33\ubf23\ubf13\ubf03\ubef3\ubee3\ubed3\ubec3\ubeb3"
+ + "\ubea3\ube93\ube83\ube73\ube63\ube53\ube43\ube33\ube23\ube13\ube03"
+ + "\ubdf3\ubde3\ubdd3\ubdc3\ubdb3\ubda3\ubd93\ubd83\ubd73\ubd63\ubd53"
+ + "\ubd43\ubd33\ubd23\ubd13\ubd03\ubcf3\ubce3\ubcd3\ubcc3\ubcb3\ubca3"
+ + "\ubc93\ubc83\ubc73\ubc63\ubc53\ubc43\ubc33\ubc23\ubc13\ubc03\ubbf3"
+ + "\ubbe3\ubbd3\ubbc3\ubbb3\ubba3\ubb93\ubb83\ubb73\ubb63\ubb53\ubb43"
+ + "\ubb33\ubb23\ubb13\ubb03\ubaf3\ubae3\ubad3\ubac3\ubab3\ubaa3\uba93"
+ + "\uba83\uba73\uba63\uba53\uba43\uba33\uba23\uba13\uba03\ub9f3\ub9e3"
+ + "\ub9d3\ub9c3\ub9b3\ub9a3\ub993\ub983\ub973\ub963\ub953\ub943\ub933"
+ + "\ub923\ub913\ub903\ub8f3\ub8e3\ub8d3\ub8c3\ub8b3\ub8a3\ub893\ub883"
+ + "\ub873\ub863\ub853\ub843\ub833\ub823\ub813\ub803\ub7f3\ub7e3\ub7d3"
+ + "\ub7c3\ub7b3\ub7a3\ub793\ub783\ub773\ub763\ub753\ub743\ub733\ub723"
+ + "\ub713\ub703\ub6f3\ub6e3\ub6d3\ub6c3\ub6b3\ub6a3\ub693\ub683\ub673"
+ + "\ubc35\ubd04\ubcf4\ubce4\ubcd4\ub613\ub603\ub5f3\ub5e3\ub5d3\ub5c3"
+ + "\ub5b3\ub5a3\ub593\ub583\ub573\ub563\ub553\ub543\ub533\ub523\ub513"
+ + "\ub503\ub4f3\ub4e3\ub4d3\ub4c3\ub4b3\ub4a3\ub493\ub483\ub473\ub463"
+ + "\ub453\ub443\ub433\ub423\ub413\ub403\ub3f3\ub3e3\ub3d3\ub3c3\ub3b3"
+ + "\ub3a3\ub393\ub383\ub373\ub363\ub353\ub343\ub333\ub323\ub313\ub303"
+ + "\ub2f3\ub2e3\ub2d3\ub2c3\ub2b3\ub2a3\ub293\ub283\ub273\ub263\ub253"
+ + "\ub243\ub233\ub223\ub213\ub203\ub1f3\ub1e3\ub1d3\ub1c3\ub1b3\ub1a3"
+ + "\ub193\ub183\ub173\ub163\ub153\ub143\ub133\ub123\ub113\ub103\ub0f3"
+ + "\ub0e3\ub0d3\ub0c3\ub0b3\ub0a3\ub093\ub083\ub073\ub063\ub053\ub043"
+ + "\ub033\ub023\ub013\ub003\uaff3\uafe3\uafd3\uafc3\uafb3\uafa3\uaf93"
+ + "\uaf83\uaf73\uaf63\uaf53\uaf43\uaf33\uaf23\uaf13\uaf03\uaef3\uaee3"
+ + "\uaed3\uaec3\uaeb3\uaea3\uae93\uae83\uae73\uae63\uae53\uae43\uae33"
+ + "\uae23\uae13\uae03\uadf3\uade3\uadd3\uadc3\uadb3\uada3\uad93\uad83"
+ + "\uad73\uad63\uad53\uad43\uad33\uad23\uad13\uad03\uacf3\uace3\uacd3"
+ + "\uacc3\uacb3\uaca3\uac93\uac83\uac73\uac63\uac53\uac43\uac33\uac23"
+ + "\uac13\uac03\uabf3\uabe3\uabd3\uabc3\uabb3\uaba3\uab93\uab83\uab73"
+ + "\uab63\uab53\uab43\uab33\uab23\uab13\uab03\uaaf3\uaae3\uaad3\uaac3"
+ + "\uaab3\uaaa3\uaa93\uaa83\uaa73\uaa63\uaa53\uaa43\uaa33\uaa23\uaa13"
+ + "\uaa03\ua9f3\ua9e3\ua9d3\ua9c3\ua9b3\ua9a3\ua993\ua983\ua973\ua963"
+ + "\ua953\ua943\ua933\ua923\ua913\ua903\ua8f3\ua8e3\ua8d3\ua8c3\ua8b3"
+ + "\ua8a3\ua893\ua883\ua873\ua863\ua853\ua843\ua833\ua823\ua813\ua803"
+ + "\ua7f3\ua7e3\ua7d3\ua7c3\ua7b3\ua7a3\ua793\ua783\ua773\ua763\ua753"
+ + "\ua743\ua733\ua723\ua713\ua703\ua6f3\ua6e3\ua6d3\ua6c3\ua6b3\ua6a3"
+ + "\ua693\ua683\ua673\ua663\ua653\ua643\ua633\ua623\ua613\ua603\ua5f3"
+ + "\ua5e3\ua5d3\ua5c3\ua5b3\ua5a3\ua593\ua583\ua573\ua563\ua553\ua543"
+ + "\ua533\ua523\ua513\ua503\ua4f3\ua4e3\ua4d3\ua4c3\ua4b3\ua4a3\ua493"
+ + "\ua483\ua473\ua463\ua453\ua443\ua433\ua423\ua413\ua403\ua3f3\ua3e3"
+ + "\ua3d3\ua3c3\ua3b3\ua3a3\ua393\ua383\ua373\ua363\ua353\ua343\ua333"
+ + "\ua323\ua313\ua303\ua2f3\ua2e3\ua2d3\ua2c3\ua2b3\ua2a3\ua293\ua283"
+ + "\ua273\ua263\ua253\ua243\ua233\ua223\ua213\ua203\ua1f3\ua1e3\ua1d3"
+ + "\ua1c3\ua1b3\ua1a3\ua193\ua183\ua173\ua163\ua153\ua143\ua133\ua123"
+ + "\ua113\ua103\ua0f3\ua0e3\ua0d3\ua0c3\ua0b3\ua0a3\ua093\ua083\ua073"
+ + "\ua063\ua053\ua043\ua033\ua023\ua013\ua003\u9ff3\u9fe3\u9fd3\u9fc3"
+ + "\u9fb3\u9fa3\u9f93\u9f83\u9f73\u9f63\u9f53\u9f43\u9f33\u9f23\u9f13"
+ + "\u9f03\u9ef3\u9ee3\u9ed3\u9ec3\u9eb3\u9ea3\u9e93\u9e83\u9e73\u9e63"
+ + "\u9e53\u9e43\u9e33\u9e23\u9e13\u9e03\u9df3\u9de3\u9dd3\u9dc3\u9db3"
+ + "\u9da3\u9d93\u9d83\u9d73\u9d63\u9d53\u9d43\u9d33\u9d23\u9d13\u9d03"
+ + "\u9cf3\u9ce3\u9cd3\u9cc3\u9cb3\u9ca3\u9c93\u9c83\u9c73\u9c63\u9c53"
+ + "\u9c43\u9c33\u9c23\u9c13\u9c03\u9bf3\u9be3\u9bd3\u9bc3\u9bb3\u9ba3"
+ + "\u9b93\u9b83\u9b73\u9b63\u9b53\u9b43\u9b33\u9b23\u9b13\u9b03\u9af3"
+ + "\u9ae3\u9ad3\u9ac3\u9ab3\u9aa3\u9a93\u9a83\u9a73\u9a63\u9a53\u9a43"
+ + "\u9a33\u9a23\u9a13\u9a03\u99f3\u99e3\u99d3\u99c3\u99b3\u99a3\u9993"
+ + "\u9983\u9973\u9963\u9953\u9943\u9933\u9923\u9913\u9903\u98f3\u98e3"
+ + "\u98d3\u98c3\u98b3\u98a3\u9893\u9883\u9873\u9863\u9853\u9843\u9833"
+ + "\u9823\u9813\u9803\u97f3\u97e3\u97d3\u97c3\u97b3\u97a3\u9793\u9783"
+ + "\u9773\u9763\u9753\u9743\u9733\u9723\u9713\u9703\u96f3\u96e3\u96d3"
+ + "\u96c3\u96b3\u96a3\u9693\u9683\u9673\u9663\u9653\u9643\u9633\u9623"
+ + "\u9613\u9603\u95f3\u95e3\u95d3\u95c3\u95b3\u95a3\u9593\u9583\u9573"
+ + "\u9563\u9553\u9543\u9533\u9523\u9513\u9503\u94f3\u94e3\u94d3\u94c3"
+ + "\u94b3\u94a3\u9493\u9483\u9473\u9463\u9453\u9443\u9433\u9423\u9413"
+ + "\u9403\u93f3\u93e3\u93d3\u93c3\u93b3\u93a3\u9393\u9383\u9373\u9363"
+ + "\u9353\u9343\u9333\u9323\u9313\u9303\u92f3\u92e3\u92d3\u92c3\u92b3"
+ + "\u92a3\u9293\u9283\u9273\u9263\u9253\u9243\u9233\u9223\u9213\u9203"
+ + "\u91f3\u91e3\u91d3\u91c3\u91b3\u91a3\u9193\u9183\u9173\u9163\u9153"
+ + "\u9143\u9133\u9123\u9113\u9103\u90f3\u90e3\u90d3\u90c3\u90b3\u90a3"
+ + "\u9093\u9083\u9073\u9063\u9053\u9043\u9033\u9023\u9013\u9003\u8ff3"
+ + "\u8fe3\u8fd3\u8fc3\u8fb3\u8fa3\u8f93\u8f83\u8f73\u8f63\u8f53\u8f43"
+ + "\u8f33\u8f23\u8f13\u8f03\u8ef3\u8ee3\u8ed3\u8ec3\u8eb3\u8ea3\u8e93"
+ + "\u8e83\u8e73\u8e63\u8e53\u8e43\u8e33\u8e23\u8e13\u8e03\u8df3\u8de3"
+ + "\u8dd3\u8dc3\u8db3\u8da3\u8d93\u8d83\u8d73\u8d63\u8d53\u8d43\u8d33"
+ + "\u8d23\u8d13\u8d03\u8cf3\u8ce3\u8cd3\u8cc3\u8cb3\u8ca3\u8c93\u8c83"
+ + "\u8c73\u8c63\u8c53\u8c43\u8c33\u8c23\u8c13\u8c03\u8bf3\u8be3\u8bd3"
+ + "\u8bc3\u8bb3\u8ba3\u8b93\u8b83\u8b73\u8b63\u8b53\u8b43\u8b33\u8b23"
+ + "\u8b13\u8b03\u8af3\u8ae3\u8ad3\u8ac3\u8ab3\u8aa3\u8a93\u8a83\u8a73"
+ + "\u8a63\u8a53\u8a43\u8a33\u8a23\u8a13\u8a03\u89f3\u89e3\u89d3\u89c3"
+ + "\u89b3\u89a3\u8993\u8983\u8973\u8963\u8953\u8943\u8933\u8923\u8913"
+ + "\u8903\u88f3\u88e3\u88d3\u88c3\u88b3\u88a3\u8893\u8883\u8873\u8863"
+ + "\u8853\u8843\u8833\u8823\u8813\u8803\u87f3\u87e3\u87d3\u87c3\u87b3"
+ + "\u87a3\u8793\u8783\u8773\u8763\u8753\u8743\u8733\u8723\u8713\u8703"
+ + "\u86f3\u86e3\u86d3\u86c3\u86b3\u86a3\u8693\u8683\u8673\u8663\u8653"
+ + "\u8643\u8633\u8623\u8613\u8603\u85f3\u85e3\u85d3\u85c3\u85b3\u85a3"
+ + "\u8593\u8583\u8573\u8563\u8553\u8543\u8533\u8523\u8513\u8503\u84f3"
+ + "\u84e3\u84d3\u84c3\u84b3\u84a3\u8493\u8483\u8473\u8463\u8453\u8443"
+ + "\u8433\u8423\u8413\u8403\u83f3\u83e3\u83d3\u83c3\u83b3\u83a3\u8393"
+ + "\u8383\u8373\u8363\u8353\u8343\u8333\u8323\u8313\u8303\u82f3\u82e3"
+ + "\u82d3\u82c3\u82b3\u82a3\u8293\u8283\u8273\u8263\u8253\u8243\u8233"
+ + "\u8223\u8213\u8203\u81f3\u81e3\u81d3\u81c3\u81b3\u81a3\u8193\u8183"
+ + "\u8173\u8163\u8153\u8143\u8133\u8123\u8113\u8103\u80f3\u80e3\u80d3"
+ + "\u80c3\u80b3\u80a3\u8093\u8083\u8073\u8063\u8053\u8043\u8033\u8023"
+ + "\u8013\u8003\u7ff3\u7fe3\u7fd3\u7fc3\u7fb3\u7fa3\u7f93\u7f83\u7f73"
+ + "\u7f63\u7f53\u7f43\u7f33\u7f23\u7f13\u7f03\u7ef3\u7ee3\u7ed3\u7ec3"
+ + "\u7eb3\u7ea3\u7e93\u7e83\u7e73\u7e63\u7e53\u7e43\u7e33\u7e23\u7e13"
+ + "\u7e03\u7df3\u7de3\u7dd3\u7dc3\u7db3\u7da3\u7d93\u7d83\u7d73\u7d63"
+ + "\u7d53\u7d43\u7d33\u7d23\u7d13\u7d03\u7cf3\u7ce3\u7cd3\u7cc3\u7cb3"
+ + "\u7ca3\u7c93\u7c83\u7c73\u7c63\u7c53\u7c43\u7c33\u7c23\u7c13\u7c03"
+ + "\u7bf3\u7be3\u7bd3\u7bc3\u7bb3\u7ba3\u7b93\u7b83\u7b73\u7b63\u7b53"
+ + "\u7b43\u7b33\u7b23\u7b13\u7b03\u7af3\u7ae3\u7ad3\u7ac3\u7ab3\u7aa3"
+ + "\u7a93\u7a83\u7a73\u7a63\u7a53\u7a43\u7a33\u7a23\u7a13\u7a03\u79f3"
+ + "\u79e3\u79d3\u79c3\u79b3\u79a3\u7993\u7983\u7973\u7963\u7953\u7943"
+ + "\u7933\u7923\u7913\u7903\u78f3\u78e3\u78d3\u78c3\u78b3\u78a3\u7893"
+ + "\u7883\u7873\u7863\u7853\u7843\u7833\u7823\u7813\u7803\u77f3\u77e3"
+ + "\u77d3\u77c3\u77b3\u77a3\u7793\u7783\u7773\u7763\u7753\u7743\u7733"
+ + "\u7723\u7713\u7703\u76f3\u76e3\u76d3\u76c3\u76b3\u76a3\u7693\u7683"
+ + "\u7673\u7663\u7653\u7643\u7633\u7623\u7613\u7603\u75f3\u75e3\u75d3"
+ + "\u75c3\u75b3\u75a3\u7593\u7583\u7573\u7563\u7553\u7543\u7533\u7523"
+ + "\u7513\u7503\u74f3\u74e3\u74d3\u74c3\u74b3\u74a3\u7493\u7483\u7473"
+ + "\u7463\u7453\u7443\u7433\u7423\u7413\u7403\u73f3\u73e3\u73d3\u73c3"
+ + "\u73b3\u73a3\u7393\u7383\u7373\u7363\u7353\u7343\u7333\u7323\u7313"
+ + "\u7303\u72f3\u72e3\u72d3\u72c3\u72b3\u72a3\u7293\u7283\u7273\u7263"
+ + "\u7253\u7243\u7233\u7223\u7213\u7203\u71f3\u71e3\u71d3\u71c3\u71b3"
+ + "\u71a3\u7193\u7183\u7173\u7163\u7153\u7143\u7133\u7123\u7113\u7103"
+ + "\u70f3\u70e3\u70d3\u70c3\u70b3\u70a3\u7093\u7083\u7073\u7063\u7053"
+ + "\u7043\u7033\u7023\u7013\u7003\u6ff3\u6fe3\u6fd3\u6fc3\u6fb3\u6fa3"
+ + "\u6f93\u6f83\u6f73\u6f63\u6f53\u6f43\u6f33\u6f23\u6f13\u6f03\u6ef3"
+ + "\u6ee3\u6ed3\u6ec3\u6eb3\u6ea3\u6e93\u6e83\u6e73\u6e63\u6e53\u6e43"
+ + "\u6e33\u6e23\u6e13\u6e03\u6df3\u6de3\u6dd3\u6dc3\u6db3\u6da3\u6d93"
+ + "\u6d83\u6d73\u6d63\u6d53\u6d43\u6d33\u6d23\u6d13\u6d03\u6cf3\u6ce3"
+ + "\u6cd3\u6cc3\u6cb3\u6ca3\u6c93\u6c83\u6c73\u6c63\u6c53\u6c43\u6c33"
+ + "\u6c23\u6c13\u6c03\u6bf3\u6be3\u6bd3\u6bc3\u6bb3\u6ba3\u6b93\u6b83"
+ + "\u6b73\u6b63\u6b53\u6b43\u6b33\u6b23\u6b13\u6b03\u6af3\u6ae3\u6ad3"
+ + "\u6ac3\u6ab3\u6aa3\u6a93\u6a83\u6a73\u6a63\u6a53\u6a43\u6a33\u6a23"
+ + "\u6a13\u6a03\u69f3\u69e3\u69d3\u69c3\u69b3\u69a3\u6993\u6983\u6973"
+ + "\u6963\u6953\u6943\u6933\u6923\u6913\u6903\u68f3\u68e3\u68d3\u68c3"
+ + "\u68b3\u68a3\u6893\u6883\u6873\u6863\u6853\u6843\u6833\u6823\u6813"
+ + "\u6803\u67f3\u67e3\u67d3\u67c3\u67b3\u67a3\u6793\u6783\u6773\u6763"
+ + "\u6753\u6743\u6733\u6723\u6713\u6703\u66f3\u66e3\u66d3\u66c3\u66b3"
+ + "\u66a3\u6693\u6683\u6673\u6663\u6653\u6643\u6633\u6623\u6613\u6603"
+ + "\u65f3\u65e3\u65d3\u65c3\u65b3\u65a3\u6593\u6583\u6573\u6563\u6553"
+ + "\u6543\u6533\u6523\u6513\u6503\u64f3\u64e3\u64d3\u64c3\u64b3\u64a3"
+ + "\u6493\u6483\u6a45\u636c\u635c\u634c\u633c\u632c\u6413\u6403\u63f3"
+ + "\u63e3\u63d3\u63c3\u63b3\u63a3\u6393\u6383\u6373\u6363\u6353\u6343"
+ + "\u6333\u6323\u6313\u6303\u62f3\u62e3\u62d3\u62c3\u62b3\u62a3\u6293"
+ + "\u6283\u6273\u6263\u6253\u6243\u6233\u6223\u6213\u6203\u61f3\u61e3"
+ + "\u61d3\u61c3\u61b3\u61a3\u6193\u6183\u6173\u6163\u6153\u6143\u6133"
+ + "\u6123\u6113\u6103\u60f3\u60e3\u60d3\u60c3\u60b3\u60a3\u6093\u6083"
+ + "\u6073\u6063\u6053\u6043\u6033\u6023\u6013\u6003\u5ff3\u5fe3\u5fd3"
+ + "\u5fc3\u5fb3\u5fa3\u6379\u6634\u6624\u6614\u6933\u5e4c\u5e3c\u5e2c"
+ + "\u5e1c\u5e0c\u5dfc\u5dec\u5ddc\u5dcc\u5dbc\u5dac\u5d9c\u5d8c\u5d7c"
+ + "\u5d6c\u5d5c\u5d4c\u5d3c\u5d2c\u5d1c\u5d0c\u5cfc\u5cec\u5cdc\u5ccc"
+ + "\u5cbc\u5cac\u5c9c\u5c8c\u5c7c\u5c6c\u5c5c\u5c4c\u5c3c\u5c2c\u5c1c"
+ + "\u5c0c\u5bfc\u5bec\u5bdc\u5bcc\u5bbc\u5bac\u5b9c\u5b8c\u5b7c\u5b6c"
+ + "\u5b5c\u5b4c\u5b3c\u5b2c\u5b1c\u5b0c\u5afc\u5aec\u5adc\u5acc\u5abc"
+ + "\u5aac\u5a9c\u5a8c\u5a7c\u5a6c\u5a5c\u5a4c\u5a3c\u5a2c\u5a1c\u5a0c"
+ + "\u59fc\u59ec\u59dc\u59cc\u59bc\u59ac\u599c\u598c\u597c\u596c\u595c"
+ + "\u594c\u593c\u592c\u591c\u590c\u58fc\u58ec\u58dc\u58cc\u58bc\u58ac"
+ + "\u589c\u588c\u587c\u586c\u585c\u584c\u583c\u582c\u581c\u580c\u57fc"
+ + "\u57ec\u57dc\u57cc\u57bc\u57ac\u579c\u578c\u577c\u576c\u575c\u574c"
+ + "\u573c\u572c\u5813\u5803\u57f3\u57e3\u57d3\u57c3\u57b3\u57a3\u5793"
+ + "\u5783\u5773\u5763\u5753\u5743\u5733\u5723\u5713\u5703\u56f3\u56e3"
+ + "\u56d3\u56c3\u56b3\u56a3\u5693\u5683\u5673\u5663\u5653\u5643\u5633"
+ + "\u5623\u5613\u5603\u55f3\u55e3\u55d3\u55c3\u55b3\u55a3\u5593\u5583"
+ + "\u5573\u5563\u5553\u5543\u5533\u5523\u5513\u5503\u54f3\u54e3\u54d3"
+ + "\u54c3\u54b3\u54a3\u5493\u5483\u5473\u5463\u5453\u5443\u5433\u5423"
+ + "\u5413\u5403\u53f3\u53e3\u53d3\u53c3\u53b3\u53a3\u5393\u5383\u5373"
+ + "\u5363\u5353\u5343\u5333\u5323\u5313\u5303\u52f3\u52e3\u52d3\u52c3"
+ + "\u52b3\u52a3\u5293\u5283\u5273\u5263\u5253\u5243\u5233\u5223\u5213"
+ + "\u5203\u51f3\u51e3\u51d3\u51c3\u51b3\u51a3\u5193\u5183\u5173\u5163"
+ + "\u5153\u5143\u5133\u5123\u5113\u5103\u50f3\u50e3\u50d3\u50c3\u50b3"
+ + "\u50a3\u5093\u5083\u5073\u5063\u5053\u5043\u5033\u5023\u5013\u5003"
+ + "\u4ff3\u4fe3\u4fd3\u4fc3\u4fb3\u4fa3\u4f93\u4f83\u4f73\u4f63\u4f53"
+ + "\u4f43\u4f33\u4f23\u4f13\u4f03\u4ef3\u4ee3\u4ed3\u4ec3\u4eb3\u4ea3"
+ + "\u4e93\u4e83\u4e73\u4e63\u4e53\u4e43\u4e33\u4e23\u4e13\u4e03\u4df3"
+ + "\u4de3\u4dd3\u4dc3\u4db3\u4da3\u4d93\u4d83\u4d73\u4d63\u4d53\u4d43"
+ + "\u4d33\u4d23\u4d13\u4d03\u4cf3\u4ce3\u4cd3\u4cc3\u4cb3\u4ca3\u4c93"
+ + "\u4c83\u4c73\u4c63\u4c53\u4c43\u4c33\u4c23\u4c13\u4c03\u4bf3\u4be3"
+ + "\u4bd3\u4bc3\u4bb3\u4ba3\u4b93\u4b83\u4b73\u4b63\u4b53\u4b43\u4b33"
+ + "\u4b23\u4b13\u4b03\u4af3\u4ae3\u4ad3\u4ac3\u4ab3\u4aa3\u4a93\u4a83"
+ + "\u4a73\u4a63\u4a53\u4a43\u4a33\u4a23\u4a13\u4a03\u49f3\u49e3\u49d3"
+ + "\u49c3\u49b3\u49a3\u4993\u4983\u4973\u4963\u4953\u4943\u4933\u4923"
+ + "\u4913\u4903\u48f3\u48e3\u48d3\u48c3\u48b3\u48a3\u4893\u4883\u4873"
+ + "\u4863\u4853\u4843\u4833\u4823\u4813\u4803\u47f3\u47e3\u47d3\u47c3"
+ + "\u47b3\u47a3\u4793\u4783\u4773\u4763\u4753\u4743\u4733\u4723\u4713"
+ + "\u4703\u46f3\u46e3\u46d3\u46c3\u46b3\u46a3\u4693\u4683\u4673\u4663"
+ + "\u4653\u4643\u4633\u4623\u4613\u4603\u45f3\u45e3\u45d3\u45c3\u45b3"
+ + "\u45a3\u4593\u4583\u4573\u4563\u4553\u4543\u4533\u4523\u4513\u4503"
+ + "\u44f3\u44e3\u44d3\u44c3\u44b3\u44a3\u4493\u4483\u4473\u4463\u4453"
+ + "\u4443\u4433\u4423\u4413\u4403\u43f3\u43e3\u43d3\u43c3\u43b3\u43a3"
+ + "\u4393\u4383\u4373\u4363\u4353\u4343\u4333\u4323\u4313\u4303\u42f3"
+ + "\u42e3\u42d3\u42c3\u42b3\u42a3\u4293\u4283\u4273\u4263\u4253\u4243"
+ + "\u4233\u4223\u4213\u4203\u41f3\u41e3\u41d3\u41c3\u41b3\u41a3\u4193"
+ + "\u4183\u4173\u4163\u4153\u4143\u4133\u4123\u4113\u4103\u40f3\u40e3"
+ + "\u40d3\u40c3\u40b3\u40a3\u4093\u4083\u4073\u4063\u4053\u4043\u4033"
+ + "\u4023\u4013\u4003\u3ff3\u3fe3\u3fd3\u3fc3\u3fb3\u3fa3\u3f93\u3f83"
+ + "\u3f73\u3f63\u3f53\u3f43\u3f33\u3f23\u3f13\u3f03\u3ef3\u3ee3\u3ed3"
+ + "\u3ec3\u3eb3\u3ea3\u3e93\u3e83\u3e73\u3e63\u3e53\u3e43\u3e33\u3e23"
+ + "\u3e13\u3e03\u3df3\u3de3\u3dd3\u3dc3\u3db3\u3da3\u3d93\u3d83\u3d73"
+ + "\u3d63\u3d53\u3d43\u3d33\u3d23\u3d13\u3d03\u3cf3\u3ce3\u3cd3\u3cc3"
+ + "\u3cb3\u3ca3\u3c93\u3c83\u3c73\u3c63\u3c53\u3c43\u3c33\u3c23\u3c13"
+ + "\u3c03\u3bf3\u3be3\u3bd3\u3bc3\u3bb3\u3ba3\u3b93\u3b83\u3b73\u3b63"
+ + "\u3b53\u3b43\u3b33\u3b23\u3b13\u3b03\u3af3\u3ae3\u3ad3\u3ac3\u3ab3"
+ + "\u3aa3\u3a93\u3a83\u3a73\u3a63\u3a53\u3a43\u3a33\u3a23\u3a13\u3a03"
+ + "\u39f3\u39e3\u39d3\u39c3\u39b3\u39a3\u3993\u3983\u3973\u3963\u3953"
+ + "\u3943\u3933\u3923\u3913\u3903\u38f3\u38e3\u38d3\u38c3\u38b3\u38a3"
+ + "\u3893\u3883\u3873\u3863\u3853\u3843\u3833\u3823\u3813\u3803\u37f3"
+ + "\u37e3\u37d3\u37c3\u37b3\u37a3\u3793\u3783\u3773\u3763\u3753\u3743"
+ + "\u3733\u3723\u3713\u3703\u36f3\u36e3\u36d3\u36c3\u36b3\u36a3\u3693"
+ + "\u3683\u3673\u3663\u3653\u3643\u3633\u3623\u3613\u3603\u35f3\u35e3"
+ + "\u35d3\u35c3\u35b3\u35a3\u3593\u3583\u3573\u3563\u3553\u3543\u3533"
+ + "\u3523\u3513\u3503\u34f3\u34e3\u34d3\u34c3\u34b3\u34a3\u3493\u3483"
+ + "\u3473\u3463\u3453\u3443\u3433\u3423\u3413\u3403\u33f3\u33e3\u33d3"
+ + "\u33c3\u33b3\u33a3\u3393\u3383\u3373\u3363\u3353\u3343\u3333\u3323"
+ + "\u3313\u3303\u32f3\u32e3\u32d3\u32c3\u32b3\u32a3\u3293\u3283\u3273"
+ + "\u3263\u3253\u3243\u3233\u3223\u3213\u3203\u31f3\u31e3\u31d3\u31c3"
+ + "\u31b3\u31a3\u3193\u3183\u3173\u3163\u3153\u3143\u3133\u3123\u3113"
+ + "\u3103\u30f3\u30e3\u30d3\u30c3\u30b3\u30a3\u3093\u3083\u3073\u3063"
+ + "\u3053\u3043\u3033\u3023\u3013\u3003\u2ff3\u2fe3\u2fd3\u2fc3\u2fb3"
+ + "\u2fa3\u2f93\u2f83\u2f73\u2f63\u2f53\u2f43\u2f33\u2f23\u2f13\u2f03"
+ + "\u2ef3\u2ee3\u2ed3\u2ec3\u2eb3\u2ea3\u2e93\u2e83\u2e73\u2e63\u2e53"
+ + "\u2e43\u2e33\u2e23\u2e13\u2e03\u2df3\u2de3\u2dd3\u2dc3\u2db3\u2da3"
+ + "\u2d93\u2d83\u2d73\u2d63\u2d53\u2d43\u2d33\u2d23\u2d13\u2d03\u2cf3"
+ + "\u2ce3\u2cd3\u2cc3\u2cb3\u2ca3\u2c93\u2c83\u3247\u2b6c\u2b5c\u2b4c"
+ + "\u2b3c\u2b2c\u36e2\u36d2\u36c2\u36b2\u36a2\u3692\u3682\u3672\u3662"
+ + "\u3652\u3642\u3632\u3622\u3612\u3602\u35f2\u35e2\u35d2\u35c2\u35b2"
+ + "\u35a2\u3592\u3582\u3572\u3562\u3552\u3542\u3532\u3522\u3512\u3502"
+ + "\u34f2\u34e2\u34d2\u34c2\u34b2\u34a2\u3492\u3482\u3472\u3462\u3452"
+ + "\u3442\u3432\u3422\u3412\u3402\u33f2\u33e2\u33d2\u33c2\u33b2\u33a2"
+ + "\u3392\u3382\u3372\u3362\u3352\u3342\u3332\u3322\u3312\u3302\u32f2"
+ + "\u32e2\u32d2\u32c2\u32b2\u32a2\u3292\u3282\u3272\u3262\u3252\u3242"
+ + "\u3232\u3222\u3212\u3202\u31f2\u31e2\u31d2\u31c2\u31b2\u31a2\u3192"
+ + "\u3182\u3172\u3162\u3152\u3142\u3132\u3122\u3112\u3102\u30f2\u30e2"
+ + "\u30d2\u30c2\u30b2\u30a2\u3092\u3082\u3072\u3062\u3052\u3042\u3032"
+ + "\u3022\u3012\u3002\u2ff2\u2fe2\u2fd2\u2fc2\u2fb2\u2fa2\u2f92\u2f82"
+ + "\u2f72\u2f62\u2f52\u2f42\u2f32\u2f22\u2f12\u2f02\u2ef2\u2ef2\u2ee2"
+ + "\u2ed2\u2ec2\u2eb2\u2ea2\u2e92\u2e82\u2e72\u2e62\u2e52\u2e42\u2e32"
+ + "\u2e22\u2e12\u2e02\u2df2\u2de2\u2dd2\u2dc2\u2db2\u2da2\u2d92\u2d82"
+ + "\u2d72\u2d62\u2d52\u2d42\u2d32\u2d22\u2d12\u2d02\u2cf2\u2ce2\u2cd2"
+ + "\u2cc2\u2cb2\u2ca2\u2c92\u2c82\u2c72\u2c62\u2c52\u2c42\u2c32\u2c22"
+ + "\u2c12\u2c02\u2bf2\u2be2\u2bd2\u2bc2\u2bb2\u2ba2\u2b92\u2b82\u2b72"
+ + "\u2b62\u2b52\u2b42\u2b32\u2b22\u2b12\u2b02\u2af2\u2ae2\u2ad2\u2ac2"
+ + "\u2ab2\u2aa2\u2a92\u2a82\u2a72\u2a62\u2a52\u2a42\u2a32\u2a22\u2a12"
+ + "\u2a02\u29f2\u29e2\u29d2\u29c2\u29b2\u29a2\u2992\u2982\u2972\u2962"
+ + "\u2952\u2942\u2932\u2922\u2912\u2902\u28f2\u28e2\u28d2\u28c2\u28b2"
+ + "\u28a2\u2892\u2882\u2872\u2862\u2852\u2842\u2832\u2822\u2812\u2802"
+ + "\u27f2\u27e2\u27d2\u27c2\u27b2\u27a2\u2792\u2782\u2772\u2762\u2752"
+ + "\u2742\u2732\u2722\u2712\u2702\u26f2\u26e2\u26d2\u26c2\u26b2\u26a2"
+ + "\u2692\u2682\u2672\u2662\u2652\u2642\u2632\u2622\u2612\u2602\u25f2"
+ + "\u25e2\u25d2\u25c2\u25b2\u25a2\u2592\u2582\u2572\u2562\u2552\u2542"
+ + "\u2532\u2522\u2512\u2502\u24f2\u24e2\u24d2\u24c2\u24b2\u24a2\u2492"
+ + "\u2482\u2472\u2462\u2452\u2442\u2432\u2422\u2412\u2402\u23f2\u23e2"
+ + "\u23d2\u23c2\u23b2\u23a2\u2392\u2382\u2372\u2362\u2352\u2342\u2332"
+ + "\u2322\u2312\u2302\u22f2\u22e2\u22d2\u22c2\u22b2\u22a2\u2292\u2282"
+ + "\u2272\u2262\u2252\u2242\u2232\u2222\u2212\u2202\u21f2\u21e2\u21d2"
+ + "\u21c2\u21b2\u21a2\u2192\u2182\u2172\u2162\u2152\u2142\u2132\u2122"
+ + "\u2112\u2102\u20f2\u20e2\u20d2\u20c2\u20b2\u20a2\u2092\u2082\u2072"
+ + "\u2062\u2052\u2042\u2032\u2022\u2012\u2002\u1ff2\u1fe2\u1fd2\u1fc2"
+ + "\u1fb2\u1fa2\u1f92\u1f82\u1f72\u1f62\u1f52\u1f42\u1f32\u1f22\u1f12"
+ + "\u1f02\u1ef2\u1ee2\u1ed2\u1ec2\u1eb2\u1ea2\u1e92\u1e82\u1e72\u1e62"
+ + "\u1e52\u1e42\u1e32\u1e22\u1e12\u1e02\u1df2\u1de2\u1dd2\u1dc2\u1db2"
+ + "\u1da2\u1d92\u1d82\u1d72\u1d62\u1d52\u1d42\u1d32\u1d22\u1d12\u1d02"
+ + "\u1cf2\u1ce2\u1cd2\u1cc2\u1cb2\u1ca2\u1c92\u1c82\u1c72\u1c62\u1c52"
+ + "\u1c42\u1c32\u1c22\u1c12\u1c02\u1bf2\u1be2\u1bd2\u1bc2\u1bb2\u1ba2"
+ + "\u1b92\u1b82\u1b72\u1b62\u1b52\u1b42\u1b32\u1b22\u1b12\u1b02\u1af2"
+ + "\u1ae2\u1ad2\u1ac2\u1ab2\u1aa2\u1a92\u1a82\u1a72\u1a62\u1a52\u1a42"
+ + "\u1a32\u1a22\u1a12\u1a02\u19f2\u19e2\u19d2\u19c2\u19b2\u19a2\u1992"
+ + "\u1982\u1972\u1962\u1952\u1942\u1932\u1922\u1912\u1902\u18f2\u18e2"
+ + "\u18d2\u18c2\u18b2\u18a2\u1892\u1882\u1872\u1862\u1852\u1842\u1832"
+ + "\u1822\u1812\u1802\u17f2\u17e2\u17d2\u17c2\u17b2\u17a2\u1792\u1782"
+ + "\u1772\u1762\u1752\u1742\u1732\u1722\u1712\u1702\u16f2\u16e2\u16d2"
+ + "\u16c2\u16b2\u16a2\u1692\u1682\u1672\u1662\u1652\u1642\u1632\u1622"
+ + "\u1612\u1602\u0b13\u0b03\u0af3\u0ae3\u0ad3\u0ac3\u0ab3\u0aa3\u0a93"
+ + "\u0a83\u0a73\u0a63\u0a53\u0a43\u0a33\u0a23\u0a13\u0a03\u0dd8\u09e3"
+ + "\u09d3\u09c3\u0d9b\u08ac\u089c\u088c\u087c\u086c\u085c\u084c\u083c"
+ + "\u082c\u1402\u0b35\u13f2\u13ec\u0b14\u083f\u082f\u081f\u080f\u07ff"
+ + "\u07ef\u0b82\u075c\u07bc\u07af\u079f\u078f\u077f\u076f\u075f\u074f"
+ + "\u073f\u072f\u071f\u070f\u06ff\u06ef\u06df\u06cf\u06bf\u06af\u069f"
+ + "\u068f\u067f\u066f\u0661\u05dc\u063f\u062f\u061f\u060f\u05fd\u05ef"
+ + "\u05df\u096c\u054c\u053c\u09a9\u0666\u050c\u0818\u10fc\u10f8\u0e1e"
+ + "\u10e8\u08b3\u050f\u04ff\u04ef\u04df\u04cf\u04bf\u04af\u087c\u0795"
+ + "\u0127\u0154\u0154\u017a\u1008\u0859\u08ad\u0493\u0485\u0473\u0453"
+ + "\u01c3\u038b\u0f88\u0333",
+
+ "\000\uffff?\004\004\u00fd\u00bd}=\ufffd\uffbd"
+ + "\uff7d\uff7d\ufef2\uff2d\ufe7d\ufc7f\ufc6f\ufe6d\ufd7d\ufd3d\ufcfd"
+ + "\ufcbd\ufc7d\ufc3d\ufbfd\ufbbd\ufb7d\ufb3d\ufafd\ufabd\ufa7d\ufb2d"
+ + "\uf9fd\uf9bd\uf97d\uf93d\uf8fd\uf8bd\uf87d\uf83d\uf7fd\uf7bd\uf77d"
+ + "\uf73d\uf6fd\uf6bd\uf67d\uf63d\uf5fd\uf5bd\uf57d\uf53d\uf4fd\uf4bd"
+ + "\uf47d\uf43d\uf3fd\uf3bd\uf37d\uf33d\uf2fd\uf2bd\uf27d\uf23d\uf1fd"
+ + "\uf1bd\uf17d\uf13d\uf0fd\uf0bd\uf07d\uf03d\ueffd\uefbd\uef7d\uef3d"
+ + "\ueefd\ueebd\uee7d\uee3d\uedfd\uedbd\ued7d\ued3d\uecfd\uecbd\uec7d"
+ + "\uec3d\uebfd\uebbd\ueb7d\ueb3d\ueafd\ueabd\uea7d\uea3d\ue9fd\ue9bd"
+ + "\ue97d\ue93d\ue8fd\ue8bd\ue87d\ue83d\ue7fd\ue7bd\ue77d\ue73d\ue6fd"
+ + "\ue6bd\ue67d\ue63d\ue5fd\ue5bd\ue57d\ue53d\ue4fd\ue4bd\ue47d\ue43d"
+ + "\ue3fd\ue3bd\ue37d\ue33d\ue2fd\ue2bd\ue27d\ue23d\ue1fd\ue1bd\ue17d"
+ + "\ue13d\ue0fd\ue0bd\ue07d\ue03d\udffd\udfbd\udf7d\udf3d\udefd\udebd"
+ + "\ude7d\ude3d\uddfd\uddbd\udd7d\udd3d\udcfd\udcbd\udc7d\udc3d\udbfd"
+ + "\udbbd\udb7d\udb3d\udafd\udabd\uda7d\uda3d\ud9fd\ud9bd\ud97d\ud93d"
+ + "\ud8fd\ud8bd\ud87d\ud83d\ud7fd\ud7bd\ud77d\ud73d\ud6fd\ud6bd\ud67d"
+ + "\ud63d\ud5fd\ud5bd\ud57d\ud53d\ud4fd\ud4bd\ud47d\ud43d\ud3fd\ud3bd"
+ + "\ud37d\ud33d\ud2fd\ud2bd\ud27d\ud23d\ud1fd\ud1bd\ud17d\ud13d\ud0fd"
+ + "\ud0bd\ud07d\ud03d\ucffd\ucfbd\ucf7d\ucf3d\ucefd\ucebd\uce7d\uce3d"
+ + "\ucdfd\ucdbd\ucd7d\ucd3d\uccfd\uccbd\ucc7d\ucc3d\ucbfd\ucbbd\ucb7d"
+ + "\ucb3d\ucafd\ucabd\uca7d\uca3d\uc9fd\uc9bd\uc97d\uc93d\uc8fd\uc8bd"
+ + "\uc87d\uc83d\uc7fd\uc7bd\uc77d\uc73d\uc6fd\uc6bd\uc67d\uc63d\uc5fd"
+ + "\uc5bd\uc57d\uc53d\uc4fd\uc4bd\uc47d\uc43d\uc3fd\uc3bd\uc37d\uc33d"
+ + "\uc2fd\uc2bd\uc27d\uc23d\uc1fd\uc1bd\uc17d\uc13d\uc0fd\uc0bd\uc07d"
+ + "\uc03d\ubffd\ubfbd\ubf7d\ubf3d\ubefd\ubebd\ube7d\ube3d\ubdfd\ubdbd"
+ + "\ubd7d\ubd3d\ubcfd\ubcbd\ubc7d\ubc3d\ubbfd\ubbbd\ubb7d\ubb3d\ubafd"
+ + "\ubabd\uba7d\uba3d\ub9fd\ub9bd\ub97d\ub93d\ub8fd\ub8bd\ub87d\ub83d"
+ + "\ub7fd\ub7bd\ub77d\ub73d\ub6fd\ub6bd\ub67d\ub63d\ub5fd\ub5bd\ub57d"
+ + "\ub53d\ub4fd\ub4bd\ub47d\ub43d\ub3fd\ub3bd\ub37d\ub33d\ub2fd\ub2bd"
+ + "\ub27d\ub23d\ub1fd\ub1bd\ub17d\ub13d\ub0fd\ub0bd\ub07d\ub03d\uaffd"
+ + "\uafbd\uaf7d\uaf3d\uaefd\uaebd\uae7d\uae3d\uadfd\uadbd\uad7d\uad3d"
+ + "\uacfd\uacbd\uac7d\uac3d\uabfd\uabbd\uab7d\uab3d\uaafd\uaabd\uaa7d"
+ + "\uaa3d\ua9fd\ua9bd\ua97d\ua93d\ua8fd\ua8bd\ua87d\ua83d\ua7fd\ua7bd"
+ + "\ua77d\ua73d\ua6fd\ua6bd\ua67d\ua63d\ua5fd\ua5bd\ua57d\ua53d\ua4fd"
+ + "\ua4bd\ua47d\ua43d\ua3fd\ua3bd\ua37d\ua33d\ua2fd\ua2bd\ua27d\ua23d"
+ + "\ua1fd\ua1bd\ua17d\ua13d\ua0fd\ua0bd\ua07d\ua03d\u9ffd\u9fbd\u9f7d"
+ + "\u9f3d\u9efd\u9ebd\u9e7d\u9e3d\u9dfd\u9dbd\u9d7d\u9d3d\u9cfd\u9cbd"
+ + "\u9c7d\u9c3d\u9bfd\u9bbd\u9b7d\u9b3d\u9afd\u9abd\u9a7d\u9a3d\u99fd"
+ + "\u99bd\u997d\u993d\u98fd\u98bd\u987d\u983d\u97fd\u97bd\u977d\u973d"
+ + "\u96fd\u96bd\u967d\u963d\u95fd\u95bd\u957d\u953d\u94fd\u94bd\u947d"
+ + "\u943d\u93fd\u93bd\u937d\u933d\u92fd\u92bd\u927d\u923d\u91fd\u91bd"
+ + "\u917d\u913d\u90fd\u90bd\u907d\u903d\u8ffd\u8fbd\u8f7d\u8f3d\u8efd"
+ + "\u8ebd\u8e7d\u8e3d\u8dfd\u8dbd\u8d7d\u8d3d\u8cfd\u8cbd\u8c7d\u8c3d"
+ + "\u8bfd\u8bbd\u8b7d\u8b3d\u8afd\u8abd\u8a7d\u8a3d\u89fd\u89bd\u897d"
+ + "\u893d\u88fd\u88bd\u887d\u883d\u87fd\u87bd\u877d\u873d\u86fd\u86bd"
+ + "\u867d\u863d\u85fd\u85bd\u857d\u853d\u84fd\u84bd\u847d\u843d\u83fd"
+ + "\u83bd\u837d\u833d\u82fd\u82bd\u827d\u823d\u81fd\u81bd\u817d\u813d"
+ + "\u80fd\u80bd\u807d\u803d\u7ffd\u7fbd\u7f7d\u7f3d\u7efd\u7ebd\u7e7d"
+ + "\u7e3d\u7dfd\u7dbd\u7d7d\u7d3d\u7cfd\u7cbd\u7c7d\u7c3d\u7bfd\u7bbd"
+ + "\u7b7d\u7b3d\u7afd\u7abd\u7a7d\u7a3d\u79fd\u79bd\u797d\u793d\u78fd"
+ + "\u78bd\u787d\u783d\u77fd\u77bd\u777d\u773d\u76fd\u76bd\u767d\u763d"
+ + "\u75fd\u75bd\u757d\u753d\u74fd\u74bd\u747d\u743d\u73fd\u73bd\u737d"
+ + "\u733d\u72fd\u72bd\u727d\u723d\u71fd\u71bd\u717d\u713d\u70fd\u70bd"
+ + "\u707d\u703d\u6ffd\u6fbd\u6f7d\u6f3d\u6efd\u6ebd\u6e7d\u6e3d\u6dfd"
+ + "\u6dbd\u6d7d\u6d3d\u6cfd\u6cbd\u6c7d\u6c3d\u6bfd\u6bbd\u6b7d\u6b3d"
+ + "\u6afd\u6abd\u6a7d\u6a3d\u69fd\u69bd\u697d\u693d\u68fd\u68bd\u687d"
+ + "\u683d\u67fd\u67bd\u677d\u673d\u66fd\u66bd\u667d\u663d\u65fd\u65bd"
+ + "\u657d\u653d\u64fd\u64bd\u647d\u643d\u63fd\u63bd\u637d\u633d\u62fd"
+ + "\u62bd\u627d\u623d\u61fd\u61bd\u617d\u613d\u60fd\u60bd\u607d\u603d"
+ + "\u5ffd\u5fbd\u5f7d\u5f3d\u5efd\u5ebd\u5e7d\u5e3d\u5dfd\u5dbd\u5d7d"
+ + "\u5d3d\u5cfd\u5cbd\u5c7d\u5c3d\u5bfd\u5bbd\u5b7d\u5b3d\u5afd\u5abd"
+ + "\u5a7d\u5a3d\u59fd\u59bd\u597d\u593d\u58fd\u58bd\u587d\u583d\u57fd"
+ + "\u57bd\u577d\u573d\u56fd\u56bd\u567d\u563d\u55fd\u55bd\u557d\u553d"
+ + "\u54fd\u54bd\u547d\u543d\u53fd\u53bd\u537d\u533d\u52fd\u52bd\u527d"
+ + "\u523d\u51fd\u51bd\u517d\u513d\u50fd\u50bd\u507d\u503d\u4ffd\u4fbd"
+ + "\u4f7d\u4f3d\u4efd\u4ebd\u4e7d\u4e3d\u4dfd\u4dbd\u4d7d\u4d3d\u4cfd"
+ + "\u4cbd\u4c7d\u4c3d\u4bfd\u4bbd\u4b7d\u4b3d\u4afd\u4abd\u4a7d\u4a3d"
+ + "\u49fd\u49bd\u497d\u493d\u48fd\u48bd\u487d\u483d\u47fd\u47bd\u477d"
+ + "\u473d\u46fd\u46bd\u467d\u463d\u45fd\u45bd\u457d\u453d\u44fd\u44bd"
+ + "\u447d\u443d\u43fd\u43bd\u437d\u433d\u42fd\u42bd\u427d\u423d\u41fd"
+ + "\u41bd\u417d\u413d\u40fd\u40bd\u407d\u403d\u3ffd\u3fbd\u3f7d\u3f3d"
+ + "\u3efd\u3ebd\u3e7d\u3e3d\u3dfd\u3dbd\u3d7d\u3d3d\u3cfd\u3cbd\u3c7d"
+ + "\u3c3d\u3bfd\u3bbd\u3b7d\u3b3d\u3afd\u3abd\u3a7d\u3a3d\u39fd\u39bd"
+ + "\u397d\u393d\u38fd\u38bd\u387d\u383d\u37fd\u37bd\u377d\u373d\u36fd"
+ + "\u36bd\u367d\u363d\u35fd\u35bd\u357d\u353d\u34fd\u34bd\u347d\u343d"
+ + "\u33fd\u33bd\u337d\u333d\u32fd\u32bd\u327d\u31d0\u3190\u3150\u311a"
+ + "\u30a6\u2ffb\u2ff8\u3032\u303d\u2ffd\u2fbd\u2f7d\u306d\u3056\u2ebd"
+ + "\u2e7d\u3034\u306a\u30a3\u2f64\u3060\u2fa5\u2ec8\u2e94\u2e2c\u2df8"
+ + "\u2df8\u2d16\u2cdc\u2ca2\u2c68\u2de0\u2a3d\u29fd\u29bd\u297d\u293d"
+ + "\u28fd\u28bd\u287d\u283d\u27fd\u27bd\u277d\u273d\u26fd\u26bd\u267d"
+ + "\u263d\u25fd\u25bd\u257d\u253d\u24fd\u24bd\u247d\u243d\u23fd\u23bd"
+ + "\u237d\u233d\u22fd\u22bd\u227d\u223d\u21fd\u21bd\u217d\u213d\u20fd"
+ + "\u20bd\u207d\u203d\u1ffd\u1fbd\u1f7d\u1f3d\u1efd\u1ebd\u1e7d\u1e3d"
+ + "\u1dfd\u1dbd\u1d7d\u1d3d\u1cfd\u1cbd\u1c7d\u1c3d\u1bfd\u1bbd\u1b7d"
+ + "\u1b3d\u1afd\u1abd\u1a7d\u1a3d\u19fd\u19bd\u197d\u193d\u18fd\u18bd"
+ + "\u187d\u183d\u17fd\u17bd\u177d\u173d\u16fd\u16bd\u167d\u163d\u15fd"
+ + "\u15bd\u157d\u153d\u14fd\u14bd\u147d\u143d\u13fd\u13bd\u137d\u133d"
+ + "\u12fd\u12bd\u127d\u123d\u11fd\u11bd\u117d\u113d\u10fd\u10bd\u107d"
+ + "\u103d\u0ffd\u0fbd\u0f7d\u0f3d\u0efd\u0ebd\u0e7d\u0e3d\u0dfd\u0dbd"
+ + "\u0d7d\u0d3d\u0cfd\u0cbd\u0c7d\u0c3d\u0bfd\u0bbd\u0b7d\u0b3d\u0afd"
+ + "\u0abd\u0a7d\u0a3d\u09fd\u09bd\u097d\u093d\u08fd\u08bd\u087d\u083d"
+ + "\u07fd\u07bd\u077d\u073d\u06fd\u06bd\u067d\u063d\u05fd\u05bd\u057d"
+ + "\u053d\u04fd\u04bd\u047d\u043d\u03fd\u03bd\u037d\u033d\u02fd\u02bd"
+ + "\u027d",
+
+ "\000\uff80\uff00\ufe80\ufe00\ufd80\ufd00\ufc80\ufc00\ufb80\ufb00"
+ + "\ufa80\ufa00\uf980\uf900\uf880\uf800\uf780\uf700\uf680\uf600\uf580"
+ + "\uf500\uf480\uf400\uf380\uf300\uf280\uf200\uf180\uf100\uf080\uf000"
+ + "\uef80\uef00\uee80\uee00\ued80\ued00\uec80\uec00\ueb80\ueb00\uea80"
+ + "\uea00\ue980\ue900\ue880\ue800\ue780\ue700\ue680\ue600\ue580\ue500"
+ + "\ue480\ue400\ue380\ue300\ue280\ue200\ue180\ue100\ue080\ue000\udf80"
+ + "\udf00\ude80\ude00\udd80\udd00\udc80\udc00\udb80\udb00\uda80\uda00"
+ + "\ud980\ud900\ud880\ud800\ud780\ud700\ud680\ud600\ud580\ud500\ud480"
+ + "\ud400\ud380\ud300\ud280\ud200\ud180\ud100\ud080\ud000\ucf80\ucf00"
+ + "\uce80\uce00\ucd80\ucd00\ucc80\ucc00\ucb80\ucb00\uca80\uca00\uc980"
+ + "\uc900\uc880\uc800\uc780\uc700\uc680\uc600\uc580\uc500\uc480\uc400"
+ + "\uc380\uc300\uc280\uc200\uc180\uc100\uc080\uc000\ubf80\ubf00\ube80"
+ + "\ube00\ubd80\ubd00\ubc80\ubc00\ubb80\ubb00\uba80\uba00\ub980\ub900"
+ + "\ub880\ub800\ub780\ub700\ub680\ub600\ub580\ub500\ub480\ub400\ub380"
+ + "\ub300\ub280\ub200\ub180\ub100\ub080\ub000\uaf80\uaf00\uae80\uae00"
+ + "\uad80\uad00\uac80\uac00\uab80\uab00\uaa80\uaa00\ua980\ua900\ua880"
+ + "\ua800\ua780\ua700\ua680\ua600\ua580\ua500\ua480\ua400\ua380\ua300"
+ + "\ua280\ua200\ua180\ua100\ua080\ua000\u9f80\u9f00\u9e80\u9e00\u9d80"
+ + "\u9d00\u9c80\u9c00\u9b80\u9b00\u9a80\u9a00\u9980\u9900\u9880\u9800"
+ + "\u9780\u9700\u9680\u9600\u9580\u9500\u9480\u9400\u9380\u9300\u9280"
+ + "\u9200\u9180\u9100\u9080\u9000\u8f80\u8f00\u8e80\u8e00\u8d80\u8d00"
+ + "\u8c80\u8c00\u8b80\u8b00\u8a80\u8a00\u8980\u8900\u8880\u8800\u8780"
+ + "\u8700\u8680\u8600\u8580\u8500\u8480\u8400\u8380\u8300\u8280\u8200"
+ + "\u8180\u8100\u8080\u8000\u7f80\u7f00\u7e80\u7e00\u7d80\u7d00\u7c80"
+ + "\u7c00\u7b80\u7b00\u7a80\u7a00\u7980\u7900\u7880\u7800\u7780\u7700"
+ + "\u7680\u7600\u7580\u7500\u7480\u7400\u7380\u7300\u7280\u7200\u7180"
+ + "\u7100\u7080\u7000\u6f80\u6f00\u6e80\u6e00\u6d80\u6d00\u6c80\u6c00"
+ + "\u6b80\u6b00\u6a80\u6a00\u6980\u6900\u6880\u6800\u6780\u6700\u6680"
+ + "\u6600\u6580\u6500\u6480\u6400\u6380\u6300\u6280\u6200\u6180\u6100"
+ + "\u6080\u6000\u5f80\u5f00\u5e80\u5e00\u5d80\u5d00\u5c80\u5c00\u5b80"
+ + "\u5b00\u5a80\u5a00\u59a9\u5980\u5900\u5880\u5800\u5780\u5700\u5680"
+ + "\u5600\u5580\u5500\u5480\u5400\u5380\u5300\u5280\u5200\u5180\u5100"
+ + "\u5080\u5000\u4f80\u4f00\u4e80\u4e00\u4d80\u4d00\u4c80\u4c00\u4b80"
+ + "\u4b00\u4a80\u4a00\u4980\u4900\u4880\u4800\u4780\u4700\u4680\u4600"
+ + "\u4580\u4500\u4480\u4400\u4380\u4300\u4280\u4200\u4180\u4100\u4080"
+ + "\u4000\u3f80\u3f00\u3e80\u3e00\u3d80\u3d00\u3c80\u3c00\u3b80\u3b00"
+ + "\u3a80\u3a00\u3980\u3900\u3880\u3800\u3780\u3700\u3680\u3600\u3580"
+ + "\u3500\u3480\u3400\u3380\u3300\u3280\u3200\u3180\u3100\u3080\u3000"
+ + "\u2f80\u2f00\u2e80\u2e00\u2d80\u2d00\u2c80\u2c00\u2b80\u2b00\u2a80"
+ + "\u2a00\u2980\u2900\u2880\u2800\u2780\u2700\u2680\u2600\u2580\u2500"
+ + "\u2480\u2400\u2380\u2300\u2280\u2200\u2180\u2100\u2080\u2000\u1f80"
+ + "\u1f00\u1e80\u1e00\u1d80\u1d00\u1c80\u1c00\u1b80\u1b00\u1a80\u1a00"
+ + "\u1980\u1900\u1880\u1800\u1780\u1700\u1680\u1600\u1580\u1500\u1480"
+ + "\u1400\u1380\u1300\u1280\u1200\u1180\u1100\u1080\u1000\u0f80\u0f00"
+ + "\u0e80\u0e00\u0d80\u0d00\u0c80\u0c00\u0b80\u0b00\u0a80\u0a00\u0980"
+ + "\u0900\u0800\u0780\u0700\u0680\u0662\u0600\u0580\u0500\u0480\u0400"
+ + "\u0380\u0300\u0280\u0200\u0180\u0100",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "\u00ff\000\uff00\ufe90\ufe80\ufe00\ufd80\ufd00\ufc80\ufc00\ufb80"
+ + "\ufb00\ufa80\ufa00\uf980\uf900\uf880\uf800\uf780\uf700\uf680\uf600"
+ + "\uf580\uf500\uf480\uf400\uf380\uf300\uf280\uf200\uf180\uf100\uf080"
+ + "\uf000\uef80\uef00\uee80\uee00\ued80\ued00\uec80\uec00\ueb80\ueb00"
+ + "\uea80\uea00\ue980\ue900\ue880\ue800\ue780\ue700\ue680\ue600\ue580"
+ + "\ue500\ue480\ue400\ue380\ue300\ue280\ue200\ue180\ue100\ue080\ue000"
+ + "\udf80\udf00\ude80\ude00\udd80\udd00\udc80\udc00\udb80\udb00\uda80"
+ + "\uda00\ud980\ud900\ud880\ud800\ud780\ud700\ud680\ud600\ud580\ud500"
+ + "\ud480\ud400\ud380\ud300\ud280\ud200\ud180\ud100\ud080\ud000\ucf80"
+ + "\ucf00\uce80\uce00\ucd80\ucd00\ucc80\ucc00\ucb80\ucb00\uca80\uca00"
+ + "\uc980\uc900\uc880\uc800\uc780\uc700\uc680\uc600\uc580\uc500\uc480"
+ + "\uc400\uc380\uc300\uc280\uc200\uc180\uc100\uc080\uc000\ubf80\ubf00"
+ + "\ube80\ube00\ubd80\ubd00\ubc80\ubc00\ubb80\ubb00\uba80\uba00\ub980"
+ + "\ub900\ub880\ub800\ub780\ub700\ub680\ub600\ub580\ub500\ub480\ub400"
+ + "\ub380\ub300\ub280\ub200\ub180\ub100\ub080\ub000\uaf80\uaf00\uae80"
+ + "\uae00\uad80\uad00\uac80\uac00\uab80\uab00\uaa80\uaa00\ua980\ua900"
+ + "\ua880\ua800\ua780\ua700\ua680\ua600\ua580\ua500\ua480\ua400\ua380"
+ + "\ua300\ua280\ua200\ua180\ua100\ua080\ua000\u9f80\u9f00\u9e80\u9e00"
+ + "\u9d80\u9d00\u9c80\u9c00\u9b80\u9b00\u9a80\u9a00\u9980\u9900\u9880"
+ + "\u9800\u9780\u9700\u9680\u9600\u9580\u9500\u9480\u9400\u9380\u9300"
+ + "\u9280\u9200\u9180\u9100\u9080\u9000\u8f80\u8f00\u8e80\u8e00\u8d80"
+ + "\u8d00\u8c80\u8c00\u8b80\u8b00\u8a80\u8a00\u8980\u8900\u8880\u8800"
+ + "\u8780\u8700\u8680\u8600\u8580\u8500\u8480\u8400\u8380\u8300\u8280"
+ + "\u8200\u8180\u8100\u8080\u8000\u7f80\u7f00\u7e80\u7e00\u7d80\u7d00"
+ + "\u7c80\u7c00\u7b80\u7b00\u7a80\u7a00\u7980\u7900\u7880\u7800\u7780"
+ + "\u7700\u7680\u7600\u7580\u7500\u7480\u7400\u7380\u7300\u7280\u7200"
+ + "\u7180\u7100\u7080\u7000\u6f80\u6f00\u6e80\u6e00\u6d80\u6d00\u6c80"
+ + "\u6c00\u6b80\u6b00\u6a80\u6a00\u6980\u6900\u6880\u6800\u6780\u6700"
+ + "\u6680\u6600\u6580\u6500\u6480\u6400\u6380\u6300\u6280\u6200\u6180"
+ + "\u6100\u6080\u6000\u5f80\u5f00\u5e80\u5e00\u5d80\u5d00\u5c80\u5c00"
+ + "\u5b80\u5b00\u5a80\u5a00\u5980\u5900\u5880\u5800\u5780\u5700\u5680"
+ + "\u5600\u5580\u5500\u5480\u5400\u5380\u5300\u5280\u5200\u5180\u5100"
+ + "\u5080\u5000\u4f80\u4f00\u4e80\u4e00\u4d80\u4d00\u4c80\u4c00\u4b80"
+ + "\u4b00\u4a80\u4a00\u4980\u4900\u4880\u4800\u4780\u4700\u4680\u4600"
+ + "\u4580\u4500\u4480\u4400\u4380\u4300\u4280\u4200\u4180\u4100\u4080"
+ + "\u4000\u3f80\u3f00\u3e80\u3e00\u3d80\u3d00\u3c80\u3c00\u3b80\u3b00"
+ + "\u3a80\u3a00\u3980\u3900\u3880\u3800\u3780\u3700\u3680\u3600\u3580"
+ + "\u3500\u3480\u3400\u3380\u3300\u3280\u3200\u3180\u3100\u3080\u3000"
+ + "\u2f80\u2f00\u2e80\u2e00\u2d80\u2d00\u2c80\u2c00\u2b80\u2b00\u2a80"
+ + "\u2a00\u2980\u2900\u2880\u2800\u2780\u2700\u2680\u2600\u2580\u2500"
+ + "\u2480\u2400\u2380\u2300\u2280\u2200\u2180\u2100\u2080\u2000\u1f80"
+ + "\u1f00\u1e80\u1e00\u1d80\u1d00\u1c80\u1c00\u1b80\u1b00\u1a80\u1a00"
+ + "\u1980\u1900\u1880\u1800\u1780\u1700\u1680\u1600\u1580\u1500\u1480"
+ + "\u1400\u1380\u1300\u1280\u1200\u1180\u1100\u1080\u1000\u0f80\u0f00"
+ + "\u0e80\u0e00\u0d80\u0d00\u0c80\u0c00\u0b80\u0b00\u0a80\u0a00\u0980"
+ + "\u0900\u0880\u0800\u0780\u0700\u0680\u0600\u0580\u0500\u0480\u0400"
+ + "\u0380\u0300\u0280\u0200\u0180\u0100",
+
+ "",
+
+ ""};
+
+ /**
+ * The array containing the numeric values that are too large to be stored as
+ * chars in NUM_VALUE. NUM_VALUE in this case will contain a negative integer
+ * N such that LARGENUMS[-N - 3] contains the correct numeric value.
+ */
+ int[] LARGENUMS
+ = new int[] {40000, 50000, 60000, 70000, 80000, 90000};
/**
* Information about each character. The low order 5 bits form the
@@ -282,496 +700,594 @@ public interface CharData
* next bit is a flag for mirrored directionality. The high order 9 bits
* form the offset into the attribute tables. Note that this limits the
* number of unique character attributes to 512, which is not a problem
- * as of Unicode version 3.2.0, but may soon become one.
+ * as of Unicode version 4.0.0, but may soon become one.
*/
- String DATA
- = "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
- + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082"
- + "\u3e80\u3e80\u3001\u3082\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85"
- + "\u3a85\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85"
- + "\u3e80\u3e80\u3e80\u3e80\u5b88\u5b88\u3e80\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80"
- + "\u3e80\u3e80\u3e80\u5198\u3e80\u3e80\u3e80\u3e80\u4606\u3e80\u3e80"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u3a85"
- + "\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u3e80\u3e80\u3e80\u3e80\u5202\u5202\u5202\u5202"
- + "\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202"
- + "\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202"
- + "\u5202\u5202\u5202\u5202\u5202\u2e82\u3e80\u5198\u2a14\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4686\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u1a1b\u1a1b\u3e80\u3e80\u3e80\u3e80\u4584\u3e80\u3e80"
- + "\u3e80\u0298\u3e80\u0298\u6615\u6696\u0298\u1a97\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u4584\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u4584\u4584\u1a1b\u1a1b\u1a1b\u1a1b"
- + "\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u4584"
- + "\u4584\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b"
- + "\u1a1b\u1a1b\u1a1b\u1a1b\u2e82\u7282\u2e82\u3e80\u2e82\u4902\u7481"
- + "\u7481\u7481\u7481\u7383\u1a1b\u1a1b\u1a1b\u6d82\u6d82\u4902\u4902"
- + "\u3e80\u3e80\u2e82\u4902\u6e01\u6e01\u7501\u7501\u3e80\u1a1b\u1a1b"
- + "\u1a1b\u1b02\u1b82\u1c02\u1c82\u1d02\u1d82\u1e02\u1e82\u1f02\u1f82"
- + "\u2002\u2082\u2102\u2182\u2202\u2282\u2302\u2382\u2402\u2482\u2502"
- + "\u2582\u2602\u2682\u2702\u2782\u0455\u0c99\u04d6\u0c99\017\017"
- + "\017\017\017\u010f\017\017\017\017\017\017\017"
- + "\017\017\017\017\017\017\017\017\017\017\017"
- + "\017\017\017\017\017\017\017\017\u008f\u010f\u008f"
- + "\u018f\u010f\017\017\017\017\017\017\017\017\017"
- + "\017\017\017\017\017\u010f\u010f\u010f\u008f\u020c\u0298"
- + "\u0298\u0318\u039a\u0318\u0298\u0298\u0455\u04d6\u0298\u0519\u0598"
- + "\u0614\u0598\u0698\u0709\u0789\u0809\u0889\u0909\u0989\u0a09\u0a89"
- + "\u0b09\u0b89\u0598\u0298\u0c59\u0c99\u0c59\u0298\u0d01\u0d81\u0e01"
- + "\u0e81\u0f01\u0f81\u1001\u1081\u1101\u1181\u1201\u1281\u1301\u1381"
- + "\u1401\u1481\u1501\u1581\u1601\u1681\u1701\u1781\u1801\u1881\u1901"
- + "\u1981\u0455\u0298\u04d6\u1a1b\u1a97\u0298\u0298\u0298\u0c99\u0455"
- + "\u04d6\u3e80\u0298\u0298\u0298\u0298\u0298\u0298\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u282c\u0298\u039a\u039a\u039a\u039a\u289c"
- + "\u289c\u1a1b\u289c\u2902\u29dd\u0c99\u2a14\u289c\u1a1b\u2a9c\u0519"
- + "\u2b0b\u2b8b\u1a1b\u2c02\u289c\u0298\u1a1b\u2c8b\u2902\u2d5e\u2d8b"
- + "\u2d8b\u2d8b\u0298\u0298\u0519\u0614\u0c99\u0c99\u0c99\u3e80\u0298"
- + "\u039a\u0318\u0298\u3e80\u3e80\u3e80\u3e80\u5405\u5405\u5405\u3e80"
- + "\u5405\u3e80\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u3e80\u501c\u501c\u4f81\u4f81"
- + "\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81"
- + "\u4f81\u4f81\u4f81\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01"
- + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01"
- + "\u2e01\u2e01\u2e01\u2e01\u0c99\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01"
- + "\u2e01\u2e82\u2e82\u2e82\u4902\u4902\u2e82\u2e82\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u2e82\u2e82"
- + "\u2e82\u2e82\u2e82\u3e80\u3e80\u3e80\u3e80\u3e80\u5305\u4606\u5305"
- + "\u5305\u3e80\u5305\u5305\u3e80\u5305\u5305\u5305\u5305\u5305\u5305"
- + "\u5305\u5305\u5305\u5305\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5398\u5405\u4606\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u5087\u5087\u4606\u5087\u5087\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b"
- + "\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u840b\u3082\u3001\u3082\u3001\u3082"
- + "\u3001\u3082\u3001\u3082\u2e82\u3001\u3082\u3001\u3082\u3001\u3082"
- + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
- + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082"
- + "\u3001\u3082\u3001\u3082\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5c09"
- + "\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u4606\u4606"
- + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u1a1b\u1a1b\u4701\u0298\u4781\u4781\u4781\u3e80"
- + "\u4801\u3e80\u4881\u4881\u4902\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01"
- + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2f02"
- + "\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02"
+ String[] DATA = new String[]{
+ "\u2282\u2302\u2382\u2402\u2482\u2502\u2582\u2602\u2682\u2702\u2782"
+ + "\u0455\u0c99\u04d6\u0c99\017\017\017\017\017\017\017"
+ + "\017\017\u008f\u010f\u008f\u018f\u010f\017\017\017\017"
+ + "\017\u010f\017\017\017\017\017\017\017\017\017"
+ + "\017\017\017\017\017\017\017\u010f\u010f\u010f\u008f"
+ + "\u0709\u0789\u0809\u0889\u0909\u0989\u0a09\u0a89\u0b09\u0b89\u0598"
+ + "\u0298\u0c59\u0c99\u0c59\u0298\u0298\u0c99\u0298\u1a97\u3f80\u3f80"
+ + "\u0298\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u020c\u0298\u0298"
+ + "\u0318\u039a\u0318\u0298\u0298\u0455\u04d6\u0298\u0519\u0598\u0614"
+ + "\u0598\u0698\u2a9c\u0519\u2b0b\u2b8b\u1a1b\u2c02\u289c\u0298\u1a1b"
+ + "\u2c8b\u2902\u2d5e\u2d8b\u2d8b\u2d8b\u0298\u0d01\u0d81\u0e01\u0e81"
+ + "\u0f01\u0f81\u1001\u1081\u1101\u1181\u1201\u1281\u1301\u1381\u1401"
+ + "\u1481\u1501\u1581\u1601\u1681\u1701\u1781\u1801\u1881\u1901\u1981"
+ + "\u0455\u0298\u04d6\u1a1b\u1a97\u0298\u0298\u0298\u0c99\u0455\u04d6"
+ + "\u0298\u0298\u0298\u0298\u0298\u0298\u0298\u0298\u0298\u858d\u860e"
+ + "\u8690\u8710\u8790\u8810\u8890\u82ac\u282c\u0298\u039a\u039a\u039a"
+ + "\u039a\u289c\u289c\u1a1b\u289c\u2902\u29dd\u0c99\u2a10\u289c\u1a1b"
+ + "\u1b02\u1b82\u1c02\u1c82\u1d02\u1d82\u1e02\u1e82\u1f02\u1f82\u2002"
+ + "\u2082\u2102\u2182\u2202\u4a82\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01"
+ + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u0c99"
+ + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e82\u3c01\u3c83\u3d02"
+ + "\u3001\u3082\u3e01\u3e81\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
+ + "\u3082\u3201\u3001\u3082\u3001\u3082\u3001\u3082\u3282\u4a82\u2f02"
+ "\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02"
- + "\u0c99\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f82\u2f02\u2f02"
- + "\u4a82\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u4b02"
- + "\u4b82\u4b82\u3e80\u4c02\u4c82\u4d01\u4d01\u4d01\u4d82\u4e02\u2902"
- + "\u3e80\u3e80\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
- + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u2e82\u3b81\u3c03\u3c82"
- + "\u3001\u3082\u3d81\u3e01\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
- + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3101\u3182"
- + "\u3001\u3082\u3001\u3082\u3001\u3082\u2902\u3001\u3082\u3001\u3082"
- + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
- + "\u3082\u4e82\u4f02\u3d02\u2902\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5b10\u5b10\u5b10\u5b10\u5b10"
- + "\u5b10\u7f0b\u3e80\u3e80\u3e80\u7f8b\u800b\u808b\u810b\u818b\u820b"
- + "\u0519\u0519\u0c99\u0455\u04d6\u2902\u3301\u3001\u3082\u3001\u3082"
- + "\u3381\u3001\u3082\u3401\u3401\u3001\u3082\u2902\u3481\u3501\u3581"
- + "\u3001\u3082\u3401\u3601\u3682\u3701\u3781\u3001\u3082\u2902\u2902"
- + "\u3701\u3801\u2902\u3881\u3a85\u3a85\u3a85\u3a85\u3b81\u3c03\u3c82"
- + "\u3b81\u3c03\u3c82\u3b81\u3c03\u3c82\u3001\u3082\u3001\u3082\u3001"
- + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082"
- + "\u3d02\u3001\u3082\u501c\u4606\u4606\u4606\u4606\u3e80\u5087\u5087"
- + "\u3e80\u3e80\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
- + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082"
- + "\u3001\u3082\u3001\u3082\u3201\u3001\u3082\u3001\u3082\u3001\u3082"
- + "\u3282\u3001\u3082\u3001\u3082\u3001\u3082\u3901\u3001\u3082\u3901"
- + "\u2902\u2902\u3001\u3082\u3901\u3001\u3082\u3981\u3981\u3001\u3082"
- + "\u3001\u3082\u3a01\u3001\u3082\u2902\u3a85\u3001\u3082\u2902\u3b02"
- + "\u4d01\u3001\u3082\u3001\u3082\u3e80\u3e80\u3001\u3082\u3e80\u3e80"
- + "\u3001\u3082\u3e80\u3e80\u3e80\u3001\u3082\u3001\u3082\u3001\u3082"
- + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
- + "\u3082\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u0598\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5398\u3e80\u3e80\u3e80\u5398"
- + "\u5398\u5398\u5398\u5398\u5398\u5398\u5398\u5398\u5398\u5398\u5398"
- + "\u5398\u5398\u3e80\u5b10\u5405\u4606\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u3e80\u3e80\u5b10\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01"
- + "\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01"
- + "\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01"
- + "\u4d01\u4d01\u4d01\u4d01\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89"
- + "\u5f09\u5f89\u6009\u6089\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u2902\u2902\u2902\u3f02\u3f82\u2902\u4002"
- + "\u4002\u2902\u4082\u2902\u4102\u2902\u2902\u2902\u2902\u4002\u2902"
- + "\u2902\u4182\u2902\u2902\u2902\u2902\u4202\u4282\u2902\u2902\u2902"
- + "\u2902\u2902\u4282\u2902\u2902\u4302\u2902\u2902\u4382\u2902\u2902"
- + "\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u4402\u2902\u2902"
- + "\u4402\u2902\u2902\u2902\u2902\u4402\u2902\u4482\u4482\u2902\u2902"
- + "\u2902\u2902\u2902\u2902\u4502\u2902\u2902\u2902\u2902\u2902\u2902"
- + "\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u3e80\u3e80\u4584"
- + "\u4584\u4584\u4584\u4584\u4584\u4584\u4584\u4584\u1a1b\u1a1b\u4584"
- + "\u4584\u4584\u4584\u4584\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b"
- + "\u1a1b\u1a1b\u4584\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5101\u5101"
- + "\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101"
- + "\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u3e80"
- + "\u3e80\u4584\u5198\u5198\u5198\u5198\u5198\u5198\u2e01\u2e01\u3e80"
- + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u4982\u4a02"
- + "\u4a02\u4a02\u4902\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02"
- + "\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u4f02\u4f02\u4f02"
- + "\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02"
- + "\u4f02\u4f02\u4606\u4606\u4606\u4606\u4606\u5198\u4606\u4606\u3a85"
- + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u3e80\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u3e80\u4606\u4606\u4606\u5298"
- + "\u4606\u4606\u5298\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u5305\u5305\u5305\u5305\u5305\u5305\u5305"
- + "\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u5305\u5305\u5305\u5298\u5298\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5c89\u5d09\u5d89"
- + "\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u640b\u648b\u650b\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u4606\u5b88\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80"
- + "\u3e80\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80"
- + "\u3e80\u3a85\u3a85\u3e80\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u5b88\u5b88\u5b88\u5b88\u3e80\u4606\u4606\u4606\u3e80\u4606"
- + "\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606"
- + "\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606"
- + "\u5b88\u5b88\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3e80\u3e80\u3a85\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3e80\u3e80\u3e80\u3e80\u5b88\u5b88\u3e80\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85"
- + "\u3e80\u3e80\u3e80\u3e80\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09"
- + "\u5f89\u6009\u6089\u501c\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5509\u5589\u5609"
- + "\u5689\u5709\u5789\u5809\u5889\u5909\u5989\u0318\u5a18\u5a18\u5398"
- + "\u3e80\u3e80\u4606\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u3e80\u3e80\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u6615\u6696\u5484\u5405\u5405\u5405\u5405"
- + "\u5405\u5405\u5405\u5405\u5405\u5405\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u5b88\u5b88\u5198\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u5b88"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3e80"
- + "\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u5198\u5198\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606\u4606\u5484\u5484\u4606"
- + "\u4606\u289c\u4606\u4606\u4606\u4606\u3e80\u3e80\u0709\u0789\u0809"
- + "\u0889\u0909\u0989\u0a09\u0a89\u0b09\u0b89\u5405\u5405\u5405\u5a9c"
- + "\u5a9c\u3e80\u3a85\u3a85\u3a85\u3e80\u3a85\u3e80\u3a85\u3e80\u3e80"
- + "\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u4606\u3a85\u3a85\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u3e80\u4606\u4606\u3a85\u3e80\u3e80"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u5b88"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3e80\u3e80\u4606\u3a85\u5b88\u5b88\u5b88\u5b88\u5b88\u3e80\u4606"
- + "\u5b88\u5b88\u3e80\u5b88\u5b88\u4606\u4606\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u5b88\u5b88\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3a85\u3e80\u5198\u5198\u5198\u5198\u5198\u5198\u5198\u5198"
- + "\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u640b\u670b"
- + "\u678b\u680b\u688b\u690b\u698b\u6a0b\u6a8b\u648b\u6b0b\u3e80\u3e80"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3e80"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u4606\u3a85\u5b88\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u5b88\u5b88\u5b88\u5b88"
- + "\u4606\u3e80\u3e80\u3a85\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3e80\u3e80\u3e80"
- + "\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u4606\u3e80\u5b88\u5b88\u5b88"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85"
- + "\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3e80\u3a85"
- + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3e80\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u4606\u3a85\u3a85\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u039a\u039a\u039a"
- + "\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a"
- + "\u039a\u039a\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u4606\u4606"
- + "\u5198\u5198\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009"
- + "\u6089\u5198\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u0298\u0298\u0318\u039a\u0318"
- + "\u0298\u0298\u6615\u6696\u0298\u0519\u0598\u0614\u0598\u0698\u0709"
- + "\u0789\u0809\u0889\u0909\u0989\u0a09\u0a89\u0b09\u0b89\u0598\u0298"
- + "\u0c99\u0c99\u0c99\u0298\u0298\u0298\u0298\u0298\u0298\u2a14\u0298"
- + "\u0298\u0298\u0298\u5b10\u5b10\u5b10\u5b10\u3e80\u5c09\u5c89\u5d09"
- + "\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u5b88"
- + "\u4606\u4606\u4606\u4606\u3e80\u3e80\u5b88\u5b88\u3e80\u3e80\u5b88"
- + "\u5b88\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u5b88\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3e80\u3a85\u3e80\u3e80"
- + "\u3a85\u3a85\u3e80\u3a85\u3e80\u3e80\u3a85\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3e80\u3a85\u3a85\u3e80\u3a85\u3a85\u3e80\u3a85\u3a85"
- + "\u3e80\u3e80\u4606\u3e80\u5b88\u5b88\u4606\u4606\u3e80\u3e80\u3e80"
- + "\u3e80\u4606\u4606\u3e80\u3e80\u4606\u4606\u4606\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85"
- + "\u3a85\u3e80\u3a85\u3e80\u3a85\u3a85\u4606\u4606\u3e80\u3e80\u5c09"
- + "\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u3a85\u3a85"
- + "\u039a\u039a\u610b\u618b\u620b\u628b\u630b\u638b\u501c\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85"
- + "\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u4606\u3a85"
- + "\u5b88\u5b88\u4606\u4606\u4606\u4606\u4606\u3e80\u4606\u4606\u5b88"
- + "\u3e80\u5b88\u5b88\u4606\u3e80\u3e80\u3a85\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u630b"
- + "\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u501c\u4606"
- + "\u501c\u4606\u501c\u4606\u6615\u6696\u6615\u6696\u5b88\u5b88\u4606"
- + "\u4606\u4606\u3e80\u3e80\u3e80\u5b88\u5b88\u3e80\u3e80\u5b88\u5b88"
- + "\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606\u5b88"
- + "\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3e80\u3a85\u3a85\u3e80\u5b88\u4606\u4606\u4606\u4606\u5b88"
- + "\u4606\u3e80\u3e80\u3e80\u4606\u4606\u5b88\u4606\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u5b88\u5b88\u5b88\u4606\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u5b88\u5b88\u3e80\u3e80\u3e80\u5b88\u5b88\u5b88\u3e80\u5b88\u5b88"
- + "\u5b88\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u5b88\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3e80\u4584\u3e80\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u3e80\u3e80\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89"
- + "\u6009\u6089\u3e80\u3e80\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u5c09"
- + "\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u5087\u5087\u5087\u5b88\u4606\u4606"
- + "\u4606\u3e80\u3e80\u5b88\u5b88\u5b88\u3e80\u5b88\u5b88\u5b88\u4606"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5b88\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u4606\u3e80\u3e80\u3e80\u3e80"
- + "\u5b88\u5b88\u5b88\u4606\u4606\u4606\u3e80\u4606\u3e80\u5b88\u5b88"
- + "\u5b88\u5b88\u5b88\u5b88\u5b88\u5b88\u4606\u5b88\u5b88\u4606\u4606"
- + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u5198\u5198"
- + "\u5198\u5198\u5198\u5198\u5198\u039a\u5198\u3e80\u3e80\u3e80\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u4584\u4606\u4606\u4606\u4606\u4606"
- + "\u4606\u4606\u4606\u5198\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09"
- + "\u5f89\u6009\u6089\u5198\u5198\u3e80\u3e80\u3e80\u3e80\u3a85\u501c"
- + "\u501c\u501c\u5198\u5198\u5198\u5198\u5198\u5198\u5198\u5198\u65b8"
- + "\u5198\u5198\u5198\u5198\u5198\u5198\u501c\u501c\u501c\u501c\u501c"
- + "\u4606\u4606\u501c\u501c\u501c\u501c\u501c\u501c\u4606\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u3e80\u3e80\u501c\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u1a97\u4584\u4584\u4584"
- + "\u3e80\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089"
- + "\u5198\u5198\u5198\u5198\u5198\u5198\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u5b88\u5b88\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u020c\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u6615\u6696\u3e80\u3e80\u3e80\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u5198"
- + "\u5198\u5198\u6b8b\u6c0b\u6c8b\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u4606\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3001\u3082\u3001"
- + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082"
- + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u2e82\u2e82\u2e82"
- + "\u2e82\u2e82\u6d02\u3e80\u3e80\u3e80\u3e80\u6d82\u6d82\u6d82\u6d82"
- + "\u6d82\u6d82\u6d82\u6d82\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01"
- + "\u6e01\u6d82\u6d82\u6d82\u6d82\u6d82\u6d82\u6d82\u6d82\u6e01\u6e01"
- + "\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6d82\u6d82\u6d82\u6d82\u6d82"
- + "\u6d82\u3e80\u3e80\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u3e80\u3e80"
- + "\u2e82\u6d82\u4902\u6d82\u4902\u6d82\u4902\u6d82\u3e80\u6e01\u3e80"
- + "\u6e01\u3e80\u6e01\u3e80\u6e01\u6d82\u6d82\u6d82\u6d82\u6d82\u6d82"
- + "\u6d82\u6d82\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6e82"
- + "\u6e82\u6f02\u6f02\u6f02\u6f02\u6f82\u6f82\u7002\u7002\u7082\u7082"
- + "\u7102\u7102\u3e80\u3e80\u7182\u7182\u7182\u7182\u7182\u7182\u7182"
- + "\u7182\u7203\u7203\u7203\u7203\u7203\u7203\u7203\u7203\u7182\u7182"
- + "\u7182\u7182\u7182\u7182\u7182\u7182\u7203\u7203\u7203\u7203\u7203"
- + "\u7203\u7203\u7203\u6d82\u6d82\u2e82\u7282\u2e82\u3e80\u2e82\u4902"
- + "\u6e01\u6e01\u7301\u7301\u7383\u1a1b\u7402\u1a1b\u1b02\u1b82\u1c02"
- + "\u1c82\u1d02\u1d82\u1e02\u1e82\u1f02\u1f82\u2002\u2082\u2102\u2182"
- + "\u2202\u2282\u2302\u2382\u2402\u2482\u2502\u2582\u2602\u2682\u2702"
- + "\u2782\u6615\u0c99\u6696\u0c99\u3e80\u6d82\u6d82\u4902\u4902\u2e82"
- + "\u7582\u2e82\u4902\u6e01\u6e01\u7601\u7601\u7681\u1a1b\u1a1b\u1a1b"
- + "\u3e80\u3e80\u2e82\u7282\u2e82\u3e80\u2e82\u4902\u7701\u7701\u7781"
- + "\u7781\u7383\u1a1b\u1a1b\u3e80\u020c\u020c\u020c\u020c\u020c\u020c"
- + "\u020c\u782c\u020c\u020c\u020c\u788c\u5b10\u5b10\u7910\u7990\u2a14"
- + "\u7a34\u2a14\u2a14\u2a14\u2a14\u0298\u0298\u7a9d\u7b1e\u6615\u7a9d"
- + "\u7a9d\u7b1e\u6615\u7a9d\u0298\u0298\u0298\u0298\u0298\u0298\u0298"
- + "\u0298\u7b8d\u7c0e\u7c90\u7d10\u7d90\u7e10\u7e90\u782c\u0318\u0318"
- + "\u0318\u0318\u0318\u0298\u0298\u0298\u0298\u29dd\u2d5e\u0298\u0298"
- + "\u0298\u0298\u1a97\u7f0b\u2c8b\u2b0b\u2b8b\u7f8b\u800b\u808b\u810b"
- + "\u818b\u820b\u0519\u0519\u0c99\u0455\u04d6\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3e80\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u4d01\u289c\u289c\u289c\u289c"
- + "\u4d01\u289c\u289c\u2902\u4d01\u4d01\u4d01\u2902\u2902\u4d01\u4d01"
- + "\u4d01\u2902\u289c\u4d01\u289c\u289c\u289c\u4d01\u4d01\u4d01\u4d01"
- + "\u4d01\u289c\u289c\ua20a\ua28a\ua30a\ua38a\ua40a\ua48a\ua50a\ua58a"
- + "\ua60a\u4606\u4606\u4606\u4606\u4606\u4606\u2a14\u4584\u4584\u4584"
- + "\u4584\u4584\u289c\u289c\ua68a\ua70a\ua78a\u3e80\u3e80\u3e80\u289c"
- + "\u289c\u289c\u289c\u3e80\u289c\u289c\u289c\u289c\u3e80\u3e80\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u0c99\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u0c99\u0c99\u289c\u289c\u0c99\u289c\u0c99"
+ + "\u2f02\u2f02\u2f02\u2f02\u0c99\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02"
+ + "\u2f02\u2f82\u3f01\u2902\u3001\u3082\u3001\u3082\u3001\u3082\u3001"
+ + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3d82\u3001"
+ + "\u3082\u539c\u4786\u4786\u4786\u4786\u3f80\u5407\u5407\u3001\u3082"
+ + "\u3001\u3082\u3001\u3082\u3f80\u3f80\u3001\u3082\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u4786\u6008\u3f80\u3f80\u3f80\u3f80\u3b05\u3b05"
+ + "\u3f80\u3b05\u3f80\u3f80\u3b05\u3b05\u3f80\u3b05\u3f80\u3f80\u3b05"
+ + "\u3f80\u3f80\u2e82\u7e02\u2e82\u3f80\u2e82\u4a82\u8181\u8181\u8201"
+ + "\u8201\u7f03\u1a1b\u1a1b\u3f80\u4786\u4786\u6008\u3f80\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3b05\u3f80\u3b05"
+ + "\u3b05\u3b05\u3b05\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3f80\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80"
+ + "\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u5518\u5518\u3b05\u3b05\u3b05\u3b05\u3c01\u3c83"
+ + "\u3d02\u3c01\u3c83\u3d02\u3c01\u3c83\u3d02\u3001\u3082\u3001\u3082"
+ + "\u2902\u2902\u2902\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3b05\u3b05\u3b05\u3b05\u3f80\u3b05\u3f80\u3b05\u3b05\u3f80"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80\u4786\u3b05\u6008\u6008"
+ + "\u4786\u4786\u4786\u3f80\u3f80\u3f80\u6008\u6008\u3f80\u3f80\u6008"
+ + "\u6008\u4786\u3f80\u3f80\u3101\u3182\u3001\u3082\u3001\u3082\u3001"
+ + "\u3082\u2902\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u2e82"
+ + "\u2e82\u2e82\u2e82\u2e82\u7882\u3f80\u3f80\u3f80\u3f80\u1a1b\u1a1b"
+ + "\u3f80\u3f80\u3f80\u3f80\u4684\u3f80\u3f80\u3f80\u0298\u3f80\u5481"
+ + "\u5481\u5481\u5481\u5481\u5481\u5481\u5481\u5481\u5481\u5481\u5481"
+ + "\u5481\u5481\u5481\u5481\u3f80\u3f80\u4684\u5518\u5518\u5518\u5518"
+ + "\u5518\u5518\u539c\u539c\u539c\u539c\u539c\u4786\u4786\u539c\u539c"
+ + "\u539c\u539c\u539c\u539c\u4786\u539c\u539c\u539c\u539c\u539c\u539c"
+ + "\u3f80\u3f80\u539c\u3b05\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u4d82\u4e02\u4e81"
+ + "\u4e81\u4e81\u4f02\u4f82\u2902\u3001\u3082\u3001\u3082\u3001\u3082"
+ + "\u3001\u3082\u3001\u3082\u2e82\u3001\u3082\u3001\u3082\u3001\u3082"
+ + "\u3981\u3001\u3082\u3981\u2902\u2902\u3001\u3082\u3981\u3001\u4502"
+ + "\u2902\u2902\u4502\u2902\u2902\u2902\u2902\u4502\u2902\u4582\u4582"
+ + "\u2902\u2902\u2902\u2902\u4402\u2902\u2902\u4482\u2902\u2902\u2902"
+ + "\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u4002\u4082\u2902\u4102"
+ + "\u4102\u2902\u4182\u2902\u4202\u2902\u2902\u2902\u2902\u3301\u3001"
+ + "\u3082\u3001\u3082\u3381\u3001\u3082\u3401\u3401\u3001\u3082\u2902"
+ + "\u3481\u3501\u3581\u3001\u3082\u3401\u3601\u3682\u3701\u3781\u3001"
+ + "\u3082\u2902\u2902\u3701\u3801\u3882\u3901\u3082\u3a01\u3a01\u3001"
+ + "\u3082\u3001\u3082\u3a81\u3001\u3082\u2902\u3b05\u3001\u3082\u2902"
+ + "\u3b82\u4786\u4786\u4786\u4786\u4786\u4806\u4786\u4786\u4786\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u4786\u3f80\u4786\u4786\u4786\u5698"
+ + "\u4786\u4786\u5698\u4786\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u6008\u3f80\u3f80\u3f80\u3f80\u3b05\u3b05"
+ + "\u3f80\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80\u3f80\u3b05\u3b05\u3f80"
+ + "\u3b05\u3f80\u3b05\u3b05\u3f80\u3b05\u3b05\u3f80\u3b05\u3b05\u3f80"
+ + "\u3f80\u4786\u3f80\u6008\u6008\u6008\u3f80\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3f80\u3b05\u3b05\u3b05\u3f80\u3f80\u3f80"
+ + "\u3f80\u6008\u6008\u5518\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u5f90\u5f90"
+ + "\u5f90\u289c\u289c\u3f80\u3f80\u3f80\u0298\u0298\u6089\u6109\u6189"
+ + "\u6209\u6289\u6309\u6389\u6409\u6489\u6509\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u4786\u3b05\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3f80\u3f80\u3f80\u3b05\u3b05\u3f80\u3f80\u3f80\u3b05\u3b05\u3b05"
+ + "\u3f80\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80"
+ + "\u3b05\u3b05\u3b05\u3f80\u3f80\u3f80\u5582\u5582\u5582\u5582\u5582"
+ + "\u5582\u5582\u5582\u5582\u5582\u5582\u5582\u5582\u5582\u5582\u5582"
+ + "\u2e82\u3f80\u5518\u5614\u3f80\u3f80\u3f80\u3f80\u3f80\u4786\u4786"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u5885\u5885"
+ + "\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885"
+ + "\u5885\u5885\u5885\u6b95\u6c16\u4102\u2902\u2902\u4282\u2902\u2902"
+ + "\u2902\u2902\u4302\u4382\u2902\u2902\u2902\u2902\u2902\u4382\u5790"
+ + "\u5790\u5790\u5790\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u0598\u5818\u289c\u289c\u4e81\u289c\u289c\u289c\u289c\u4e81\u289c"
+ + "\u289c\u2902\u4e81\u4e81\u4e81\u2902\u2902\u4602\u2902\u2902\u2902"
+ + "\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u2902"
+ + "\u2902\u2902\u4684\u4684\u4684\u4684\u4684\u4684\u4684\u4684\u4684"
+ + "\u4684\u4684\u4684\u4684\u4684\u4684\u4684\u4704\u4704\u4684\u4684"
+ + "\u4684\u4684\u4684\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b"
+ + "\u1a1b\u4684\u1a1b\u5614\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u4684\u4684\u1a1b\u1a1b\u1a1b\u1a1b\u4704\u4704"
+ + "\u4704\u4704\u4704\u4704\u4704\u4704\u4704\u4704\u4684\u4684\u1a1b"
+ + "\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b"
+ + "\u1a1b\u1a1b\u1a1b\u1a1b\u2e82\u7e02\u2e82\u3f80\u2e82\u4a82\u8001"
+ + "\u8001\u8001\u8001\u7f03\u1a1b\u1a1b\u1a1b\u289c\uac8a\uad0a\uad8a"
+ + "\uae0a\uae8a\uaf0a\uaf8a\ub00a\ub08a\u4786\u4786\u4786\u4786\u4786"
+ + "\u4786\u4786\u4786\u3f80\u4786\u4786\u4786\u4786\u4786\u4786\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u3f80\u539c"
+ + "\u539c\u658b\u660b\u668b\u670b\u539c\u539c\u539c\u539c\u539c\u539c"
+ + "\u539c\u539c\u539c\u539c\u539c\u289c\u0c99\u289c\u289c\u289c\u289c"
+ + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u3f80\u289c\u3f80"
+ + "\u289c\u289c\u289c\u289c\u3f80\u289c\u289c\u289c\u289c\u3f80\u3f80"
+ + "\u289c\u289c\u289c\u289c\u289c\u539c\u289c\u289c\u289c\u289c\u289c"
+ + "\u0c99\u0c99\u0c99\u0c99\u0c99\u6b95\u6c16\u0298\u289c\u289c\u289c"
+ + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u3f80\u289c\u289c\u289c"
+ + "\u289c\u289c\u289c\u289c\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455"
+ + "\u04d6\u738b\u740b\u748b\u750b\u758b\u760b\u768b\u770b\u778b\uab8b"
+ + "\u738b\u740b\u748b\u750b\u758b\u760b\u4786\u4786\u4786\u4786\u4786"
+ + "\u4786\u4786\u4786\u3f80\u3f80\u3f80\u3f80\u3f80\u4786\u4786\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786"
+ + "\u6008\u6008\u3f80\u3f80\u3f80\u6008\u6008\u6008\u3f80\u6008\u6008"
+ + "\u6008\u4786\u3f80\u3f80\u4786\u6008\u6008\u3f80\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80\u3b05\u3b05\u3b05\u3f80"
+ + "\u3b05\u3f80\u3b05\u3f80\u3f80\u3b05\u3b05\u3f80\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3f80\u3b05\u3b05\u3f80\u6008\u4786\u4786\u4786\u4786"
+ + "\u3f80\u3f80\u6008\u6008\u3f80\u3f80\u6008\u6008\u4786\u3f80\u3f80"
+ + "\u5002\u5082\u5102\u2902\u5181\u5202\u0c99\u3001\u3082\u5281\u3001"
+ + "\u3082\u3f80\u3f80\u3f80\u3f80\u1a1b\u1a1b\u4881\u0298\u4901\u4901"
+ + "\u4901\u3f80\u4981\u3f80\u4a01\u4a01\u2e01\u2e01\u3f80\u2e01\u2e01"
+ + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u4b02\u4b82\u4b82\u4b82"
+ + "\u2f02\u2f02\u4c02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02"
+ + "\u2f02\u4c82\u4d02\u4d02\u3f80\u4786\u4786\u6008\u3f80\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80\u3f80\u3f80\u3b05\u3b05\u3b05"
+ + "\u3b05\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3f80\u3b05\u3f80\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80"
+ + "\u4786\u3b05\u6008\u6008\u4786\u6008\u6008\u6008\u6008\u6008\u6008"
+ + "\u4786\u4786\u4786\u3f80\u3f80\u3f80\u3f80\u5301\u5301\u5301\u5301"
+ + "\u5301\u5301\u5301\u5301\u5301\u5301\u5301\u5301\u5301\u5301\u5301"
+ + "\u5301\u5082\u5082\u5082\u5082\u5082\u5082\u5082\u5082\u5082\u5082"
+ + "\u5082\u5082\u5082\u5082\u5082\u5082\u4e81\u3001\u3082\u3001\u3082"
+ + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u6089\u6109\u6189\u6209\u6289\u6309"
+ + "\u6389\u6409\u6489\u6509\u6b0b\u6b0b\u6b0b\u6b0b\u6b0b\u6b0b\u539c"
+ + "\u4786\u539c\u4786\u539c\u4786\u6b95\u6c16\u6b95\u6c16\u6008\u6008"
+ + "\u4786\u4786\u4786\u3f80\u4786\u3f80\u6008\u6008\u6008\u6008\u6008"
+ + "\u6008\u6008\u6008\u4786\u6008\u6008\u4786\u4786\u4786\u4786\u4786"
+ + "\u4786\u4786\u4786\u6008\u6008\u6008\u6008\u4786\u3f80\u3f80\u5518"
+ + "\u5518\u5518\u5518\u5518\u5518\u5518\u5518\u6109\u6189\u6209\u6289"
+ + "\u6309\u6389\u6409\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786"
+ + "\u4786\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u2e82\u2e82\u2e82\u2e82\u2e82\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u5705\u4786\u5705\u5705\u3f80\u5705\u5705\u3f80\u5705\u5705"
+ + "\u5705\u5705\u5705\u5705\u5705\u5705\u5705\u5705\u5705\u5705\u5705"
+ + "\u5705\u5705\u5705\u3f80\u3f80\u3f80\u3f80\u3f80\u6008\u6008\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3b05\u3f80\u3b05\u3b05\u3f80"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80\u4786\u3b05\u6008\u4786"
+ + "\u4786\u4786\u4786\u4786\u3f80\u4786\u4786\u6008\u3f80\u6008\u6008"
+ + "\u4786\u3f80\u3f80\u0298\u0298\u0318\u039a\u0318\u0298\u0298\u0455"
+ + "\u04d6\u0298\u0519\u0598\u0614\u0598\u0698\u5705\u5705\u5705\u5698"
+ + "\u5698\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u6008\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u2d8b"
+ + "\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b"
+ + "\u738b\u5989\u5a09\u5a89\u5b09\u5b89\u5c09\u5c89\u5d09\u5d89\u5e09"
+ + "\u0318\u5e98\u5e98\u5818\u5885\u5885\u5885\u5885\u5818\u5885\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u4786\u5790\u5407\u4786\u5407\u5407"
+ + "\u5407\u4786\u4786\u4786\u4786\u4786\u4786\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u5818\u3f80\u3f80\u3f80\u5818\u5818\u5818\u5818\u5818\u5818"
+ + "\u5818\u5818\u5818\u5818\u5818\u5818\u5818\u5818\u3f80\u5f90\u5904"
+ + "\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u3f80"
+ + "\u3f80\u5885\u5885\u5885\u5885\u5885\u3f80\u5885\u5885\u5885\u5885"
+ + "\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u6109"
+ + "\u6189\u6209\u6289\u6309\u6389\u6409\u6489\u6509\u688b\u6c8b\u6d0b"
+ + "\u6d8b\u6e0b\u6e8b\u6f0b\u6f8b\u700b\u690b\u708b\u3f80\u3f80\u3f80"
+ + "\u0709\u0789\u0809\u0889\u0909\u0989\u0a09\u0a89\u0b09\u0b89\u5885"
+ + "\u5885\u5885\u5f1c\u5f1c\u5885\u4786\u5885\u5885\u5885\u5885\u5885"
+ + "\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u3f80"
+ + "\u3f80\u5f90\u5f90\u5f90\u5f90\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u5f90\u5f90\u5f90\u5f90\u5f90\u5f90\u4786\u4786\u4786\u4786\u4786"
+ + "\u5904\u5904\u4786\u4786\u289c\u4786\u4786\u4786\u4786\u5885\u5885"
+ + "\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\u5885\uc51a"
+ + "\u289c\u3f80\u3f80\u4786\u5885\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u04d6\u0298\u0455"
+ + "\u04d6\u0298\u1a97\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3f80\u3f80\u3f80\u3f80\u6008\u6008\u3f80\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3f80\u3f80\u3f80\u3f80\u4786\u4786\u6008\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u6b95\u6c16"
+ + "\u3f80\u3f80\u3f80\u020c\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u1a97\u4684\u4684\u4684\u3b05\u3b05\u3b05\u4684\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3f80\u3f80\u4786\u3b05\u6008\u6008\u6008\u6008"
+ + "\u6008\u3f80\u6a06\u6008\u6008\u3f80\u6008\u6008\u4786\u4786\u3f80"
+ + "\u3f80\u3f80\u3f80\u4786\u4786\u3f80\u3f80\u4786\u4786\u4786\u3f80"
+ + "\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80\u4786"
+ + "\u4786\u1a1b\u1a1b\u4684\u4684\u3b05\u4786\u4786\u4786\u4786\u3f80"
+ + "\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3f80\u3f80\u5518\u3f80\u3f80\u3f80\u3f80\u3b05\u3b05\u4786\u4786"
+ + "\u5518\u5518\u6089\u6109\u6189\u6209\u6289\u6309\u6389\u6409\u6489"
+ + "\u6509\u5518\u5518\u3f80\u3f80\u3f80\u3f80\u3b05\u3b05\u4786\u4786"
+ + "\u3f80\u3f80\u6089\u6109\u6189\u6209\u6289\u6309\u6389\u6409\u6489"
+ + "\u6509\u3f80\u3f80\u3b05\u3b05\u3f80\u3f80\u3b05\u3b05\u039a\u039a"
+ + "\u658b\u660b\u668b\u670b\u678b\u680b\u539c\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u4786\u4786\u3b05\u3b05\u3b05\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3b05\u4786\u3b05\u3b05\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u4786\u3f80\u3f80\u3f80\u3f80\u039a"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u4684\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u5518\u4786\u4786\u3b05"
+ + "\u3b05\u3b05\u3b05\u3f80\u3f80\u3f80\u3f80\u6089\u6109\u6189\u6209"
+ + "\u6289\u6309\u6389\u6409\u6489\u6509\u5518\u5518\u5518\u5518\u5518"
+ + "\u5518\u688b\u690b\u698b\u289c\u289c\u289c\u289c\u289c\u289c\u039a"
+ + "\u289c\u3f80\u3f80\u3f80\u3f80\u3f80\u4786\u6008\u6008\u6008\u6008"
+ + "\u3f80\u4786\u4786\u4786\u3f80\u4786\u4786\u4786\u4786\u3f80\u3f80"
+ + "\u3b05\u3b05\u3b05\u3b05\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80"
+ + "\u3f80\u4786\u3b05\u6008\u6a06\u6008\u4786\u4786\u4786\u3f80\u3f80"
+ + "\u6008\u6008\u6008\u3f80\u6008\u6008\u6008\u4786\u3f80\u3f80\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80\u3f80\u4786\u3f80"
+ + "\u3f80\u3f80\u3f80\u6008\u6008\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u5518\u5518\u5518\u710a\u718a"
+ + "\u3b05\u4786\u3b05\u3b05\u4786\u4786\u4786\u4786\u4786\u4786\u3f80"
+ + "\u4786\u4786\u3b05\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80"
+ + "\u4684\u3f80\u4786\u4786\u4786\u4786\u4786\u4786\u3f80\u3f80\u3b05"
+ + "\u539c\u539c\u539c\u5518\u5518\u5518\u5518\u5518\u5518\u5518\u5518"
+ + "\u6ab8\u5518\u5518\u5518\u4786\u6008\u4786\u3f80\u3f80\u3f80\u4786"
+ + "\u4786\u6008\u4786\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3b05\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u6008\u6008\u4786\u4786\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u4e81\u4e81\u289c\u4e81\u2902\u3b05\u3b05\u3b05"
+ + "\u3b05\u2902\u289c\u289c\u3f80\u2902\u4e81\u4e81\u4e81\u4e81\u4e81"
+ + "\u4e81\u4e81\u4e81\u4e81\u4e81\u4e81\u4e81\u4e81\u4e81\u4e81\u4e81"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3b05"
+ + "\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u720a"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3b05\u3b05\u4786\u4786\u4786\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3b05\u3b05"
+ + "\u4786\u4786\u4786\u5518\u5518\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3b05\u3b05\u4786\u4786\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3b05\u3f80\u4786"
+ + "\u4786\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3b05\u3b05\u3b05\u3b05\u7290\u7290\u6008\u4786\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u6008\u6008\u6008\u6008\u4786\u4786"
+ + "\u7808\u7808\u7808\u3f80\u3f80\u3f80\u3f80\u4786\u4786\u4786\u4786"
+ + "\u5518\u5518\u5518\u4684\u5518\u5518\u5518\u039a\u3b05\u4786\u3f80"
+ + "\u3f80\ua90b\ua98b\uaa0b\uaa8b\uab0b\u738b\u740b\u748b\u750b\u758b"
+ + "\u760b\u768b\u770b\u778b\uab8b\u730b\u738b\u740b\u748b\u750b\u758b"
+ + "\u760b\u768b\u770b\u778b\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u0298"
+ + "\u0298\u0298\u0298\u0298\u0298\u5614\u0298\u0298\u0298\u0298\u4786"
+ + "\u4786\u4786\u020c\u3f80\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05\u3b05"
+ + "\u3b05\u3b05\u4786\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u4e81\u4e81"
+ + "\u4e81\u2902\u289c\u4e81\u289c\u289c\u289c\u4e81\u4e81\u4e81\u4e81"
+ + "\u4e81\u289c\u289c\u0c99\u289c\u0c99\u289c\u289c\u289c\u289c\u289c"
+ "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u0c99\u289c\u289c\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u948a"
- + "\u950a\u958a\u960a\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u0c99\u0c99\u0c99\u0c99\u0c99\u289c\u289c"
- + "\u289c\u289c\u289c\u0c99\u0c99\u289c\u289c\u289c\u289c\u4d01\u289c"
- + "\u8281\u289c\u4d01\u289c\u8301\u8381\u4d01\u4d01\u2a9c\u2902\u4d01"
- + "\u4d01\u289c\u4d01\u2902\u3a85\u3a85\u3a85\u3a85\u2902\u289c\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u848a\u850a\u858a\u860a\u868a\u870a\u878a"
- + "\u880a\u888a\u890a\u898a\u8a0a\u8a8a\u8b0a\u8b8a\u8c0a\u8c8a\u8d0a"
- + "\u8d8a\u8e0a\u8e8a\u8f0a\u8f8a\u900a\u908a\u910a\u918a\u920a\u928a"
- + "\u930a\u938a\u940a\u0c99\u0c99\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59"
+ + "\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99"
+ + "\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59"
+ + "\u0c99\u0c99\u0455\u04d6\u0c99\u0c99\u0c99\u0455\u04d6\u0455\u04d6"
+ + "\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0c99"
+ + "\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99"
+ + "\u0c59\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99"
+ + "\u0c99\u0c99\u0c99\u0c59\u0c99\u0c59\u0c99\u0c59\u0c59\u0c59\u0c59"
+ + "\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59"
+ + "\u0c59\u0c59\u0c59\u0c99\u0c59\u0c99\u0c59\u0c59\u0c59\u0c99\u0c99"
+ + "\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c99\u0c99"
+ + "\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c59\u0c99\u0c99\u0c59"
+ + "\u0c59\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59"
+ + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c99"
+ + "\u0c59\u0c99\u0c99\u0c59\u0c99\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99"
+ + "\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c59"
+ + "\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99"
+ + "\u0c99\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c99"
+ + "\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c99\u0c99\u0c99"
+ + "\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99"
+ + "\u0c99\u0c99\u289c\u289c\u289c\u289c\u289c\u0c99\u0c99\u289c\u289c"
+ + "\u289c\u289c\u4e81\u289c\u8c81\u289c\u4e81\u289c\u8d01\u8d81\u4e81"
+ + "\u4e81\u2a9c\u2902\u4684\u4684\u2902\u2902\u2902\u2902\u2902\u2902"
+ + "\u2902\u2902\u2902\u2902\u3f80\u3f80\u3f80\u3f80\u7902\u7902\u7902"
+ + "\u7902\u7902\u7902\u7902\u7902\u7981\u7981\u7981\u7981\u7981\u7981"
+ + "\u7981\u7981\u7902\u7902\u7902\u7902\u7902\u7902\u3f80\u3f80\u7981"
+ + "\u7981\u7981\u7981\u7981\u7981\u3f80\u3f80\u2e82\u7902\u4a82\u7902"
+ + "\u4a82\u7902\u4a82\u7902\u3f80\u7981\u3f80\u7981\u3f80\u7981\u3f80"
+ + "\u7981\u7a02\u7a02\u7a82\u7a82\u7a82\u7a82\u7b02\u7b02\u7b82\u7b82"
+ + "\u7c02\u7c02\u7c82\u7c82\u3f80\u3f80\u7d02\u7d02\u7d02\u7d02\u7d02"
+ + "\u7d02\u7d02\u7d02\u7d83\u7d83\u7d83\u7d83\u7d83\u7d83\u7d83\u7d83"
+ + "\u7902\u7902\u2e82\u7e02\u2e82\u3f80\u2e82\u4a82\u7981\u7981\u7e81"
+ + "\u7e81\u7f03\u1a1b\u7f82\u1a1b\u7902\u7902\u4a82\u4a82\u3f80\u3f80"
+ + "\u2e82\u4a82\u7981\u7981\u8081\u8081\u3f80\u1a1b\u1a1b\u1a1b\u7902"
+ + "\u7902\u4a82\u4a82\u2e82\u5102\u2e82\u4a82\u7981\u7981\u8101\u8101"
+ + "\u5281\u1a1b\u1a1b\u1a1b\u020c\u020c\u020c\u020c\u020c\u020c\u020c"
+ + "\u82ac\u020c\u020c\u020c\u830c\u5f90\u5f90\u7290\u8390\u5614\u8434"
+ + "\u5614\u5614\u5614\u5614\u0298\u0298\u849d\u851e\u6b95\u849d\u849d"
+ + "\u851e\u6b95\u849d\u0598\u0298\u0598\u3f80\u0298\u0598\u0298\u0298"
+ + "\u5614\u6b95\u6c16\u6b95\u6c16\u6b95\u6c16\u0318\u0318\u0318\u0318"
+ + "\u0318\u0298\u0298\u0298\u0298\u29dd\u2d5e\u0298\u0298\u0298\u0298"
+ + "\u1a97\u890b\u2902\u3f80\u3f80\u898b\u8a0b\u8a8b\u8b0b\u8b8b\u8c0b"
+ + "\u0519\u0519\u0c99\u0455\u04d6\u2902\u890b\u2c8b\u2b0b\u2b8b\u898b"
+ + "\u8a0b\u8a8b\u8b0b\u8b8b\u8c0b\u0519\u0519\u0c99\u0455\u04d6\u3f80"
+ + "\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a"
+ + "\u039a\u039a\u039a\u039a\u039a\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u4786\u4786\u4786"
+ + "\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u4786\u5407"
+ + "\u5407\u5407\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99"
+ + "\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59\u0c59"
+ + "\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59"
+ + "\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59"
+ + "\u0c59\u0c99\u0c99\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59"
+ "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59"
- + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99"
- + "\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99"
- + "\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59"
- + "\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59"
- + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59\u0c59"
- + "\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c99\u0c99\u0c99\u0c99"
- + "\u0c99\u0c99\u0c99\u289c\u289c\u0c99\u289c\u289c\u0c99\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u0c99\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u3e80\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u0c99\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59"
- + "\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c59\u0519\u0519\u0c99\u0c59"
+ + "\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c99\u0c99\u0c99"
+ + "\u0c99\u0c59\u0c59\u0c59\u0c59\u0c99\u0c59\u0519\u0519\u0c99\u0c59"
+ "\u0c59\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c99\u0c59\u0c99"
+ "\u0c59\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59"
- + "\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c99\u0c59"
- + "\u0c59\u0c59\u0c59\u0c59\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u0455\u04d6\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u3e80\u3e80\u3e80\u3e80\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u9c1c\u9c1c\u9c1c\u9c1c"
- + "\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c"
- + "\u9c1c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c"
- + "\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u7f0b\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u0c59\u0c99\u0c59\u0c99\u0c59"
- + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59"
- + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59"
- + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u039a\u039a\u0c99\u1a1b\u289c\u039a\u039a\u3e80\u289c\u0c99"
- + "\u0c99\u0c99\u0c99\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u5b10\u5b10\u5b10\u289c\u289c\u3e80\u3e80"
+ + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c59\u0c59\u0c99"
+ + "\u0c99\u0455\u04d6\u0455\u04d6\u0c59\u0c99\u0c99\u0c99\u0c99\u4e81"
+ + "\u2902\u2902\u2902\u2902\u289c\u0c99\u3f80\u3f80\u3f80\u3f80\u8e0a"
+ + "\u8e8a\u8f0a\u8f8a\u900a\u908a\u910a\u918a\u920a\u928a\u930a\u938a"
+ + "\u940a\u948a\u950a\u958a\u960a\u968a\u970a\u978a\u980a\u988a\u990a"
+ + "\u998a\u9a0a\u9a8a\u9b0a\u9b8a\u9c0a\u9c8a\u9d0a\u9d8a\u9e0a\u9e8a"
+ + "\u9f0a\u9f8a\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u0c99\u289c\u289c\u0c99\u289c\u289c\u0c99\u289c"
+ + "\u289c\u289c\u289c\u289c\u289c\u289c\u0c99\u289c\u289c\u289c\u289c"
+ + "\u289c\u289c\u289c\u289c\u0c59\u0c59\u0c59\u0c59\u289c\u289c\u289c"
+ + "\u289c\u289c\u289c\u289c\u0455\u04d6\u289c\u289c\u289c\u289c\u289c"
+ + "\u289c\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c"
+ + "\u539c\u539c\u539c\u539c\u539c\u539c\u289c\u289c\u3f80\u539c\ubc8b"
+ + "\ubd0b\ubd8b\ube0b\ube8b\ubf0b\ubf8b\uc00b\uc08b\uc10b\uc18b\uc20b"
+ + "\uc28b\uc30b\uc38b\u768b\u770b\u778b\uab8b\u289c\u3f80\u3f80\u3f80"
+ "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u3e80\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u3e80\u289c"
- + "\u3e80\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80\u289c\u3e80\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u840b\u9d0b"
- + "\u9d8b\u9e0b\u9e8b\u9f0b\u9f8b\ua00b\ua08b\ua10b\u840b\u9d0b\u9d8b"
- + "\u9e0b\u9e8b\u9f0b\u9f8b\ua00b\ua08b\ua10b\u289c\u3e80\u3e80\u3e80"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u0c59\u0c59\u0c59"
- + "\u0c59\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c"
- + "\u501c\u289c\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u3e80\u3e80"
- + "\u3e80\u501c\u610b\u618b\u620b\u628b\ua80b\ua88b\ua90b\ua98b\uaa0b"
- + "\u640b\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u289c\u3e80\u289c\u289c\u289c"
- + "\u3e80\u289c\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u2c8b\u2b0b\u2b8b\u7f8b\u800b\u808b"
- + "\u810b\u818b\u820b\u968b\u970b\u978b\u980b\u988b\u990b\u998b\u9a0b"
- + "\u9a8b\u9b0b\u9b8b\u2c8b\u2b0b\u2b8b\u7f8b\u800b\u808b\u810b\u818b"
- + "\u820b\u968b\u970b\u978b\u980b\u988b\u990b\u998b\u9a0b\u9a8b\u9b0b"
- + "\u9b8b\u501c\u501c\u501c\u501c\u020c\u0298\u0298\u0298\u289c\u4584"
- + "\u3a85\ua18a\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455"
- + "\u04d6\u289c\u289c\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455\u04d6"
- + "\u2a14\u6615\u6696\u6696\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u1a1b\u1a1b"
- + "\u4584\u4584\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85"
- + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u501c\u501c\u630b"
- + "\u630b\u630b\u630b\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c"
- + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93"
- + "\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93"
- + "\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93"
- + "\uaa93\uaa93\uaa93\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12"
- + "\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12"
- + "\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12"
- + "\uab12\uab12\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305"
- + "\u0519\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305"
- + "\u5305\u5305\u5305\u3e80\u5305\u5305\u5305\u5305\u5305\u3e80\u5305"
- + "\u3e80\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80"
- + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u0298\u2a14\u2a14\u1a97\u1a97"
- + "\u6615\u6696\u6615\u6696\u6615\u6696\u6615\u6696\u6615\u6696\u6615"
- + "\u6696\u3e80\u3e80\u3e80\u3e80\u0298\u0298\u0298\u0298\u1a97\u1a97"
- + "\u1a97\u0598\u0298\u0598\u3e80\u0298\u0598\u0298\u0298\u2a14\u6615"
- + "\u6696\u6615\u6696\u6615\u6696\u0318\u0298\u0d01\u0d81\u0e01\u0e81"
- + "\u0f01\u0f81\u1001\u1081\u1101\u1181\u1201\u1281\u1301\u1381\u1401"
- + "\u1481\u1501\u1581\u1601\u1681\u1701\u1781\u1801\u1881\u1901\u1981"
- + "\u6615\u0298\u6696\u1a1b\u1a97";
+ + "\u289c\u289c\u289c\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\ua18b\ua20b\ua28b\ua30b"
+ + "\ua38b\ua40b\ua48b\ua50b\u2c8b\u2b0b\u2b8b\u898b\u8a0b\u8a8b\u8b0b"
+ + "\u8b8b\u8c0b\ua00b\ua08b\ua10b\ua18b\ua20b\ua28b\ua30b\ua38b\ua40b"
+ + "\ua48b\ua50b\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c"
+ + "\u539c\u539c\u539c\u289c\u289c\u289c\u289c\u539c\u539c\u539c\u539c"
+ + "\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c\u539c"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80"
+ + "\u3f80\u658b\u660b\u668b\u670b\ub28b\ub30b\ub38b\ub40b\ub48b\u688b"
+ + "\u539c\u539c\u539c\u539c\u539c\u539c\ua59c\ua59c\ua59c\ua59c\ua59c"
+ + "\ua59c\ua59c\ua59c\ua59c\ua59c\ua59c\ua59c\ua59c\ua59c\ua59c\ua59c"
+ + "\ua61c\ua61c\ua61c\ua61c\ua61c\ua61c\ua61c\ua61c\ua61c\ua61c\ua61c"
+ + "\ua61c\ua61c\ua61c\ua61c\ua61c\u890b\ua68b\ua70b\ua78b\ua80b\ua88b"
+ + "\u5614\u4684\u4684\u4684\u4684\u4684\u289c\u289c\ub10a\ub18a\ub20a"
+ + "\u4684\u3b05\u0298\u289c\u289c\u289c\u3f80\u3f80\u3f80\u289c\u3f80"
+ + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u3f80\u0c99\u0c99\u0c59"
+ + "\u0c59\u0c59\u0c59\u0455\u04d6\u0455\u04d6\u0455\u04d6\u3f80\u3f80"
+ + "\u3f80\u3f80\u020c\u0298\u0298\u0298\u289c\u4684\u3b05\uac0a\u0455"
+ + "\u04d6\u0455\u04d6\u0455\u04d6\u0455\u04d6\u289c\u289c\u0455\u04d6"
+ + "\u0455\u04d6\u0455\u04d6\u0455\u04d6\u5614\u6b95\u6c16\u6c16\u289c"
+ + "\ub50b\ub58b\ub60b\ub68b\ub70b\ub78b\ub80b\ub88b\ub90b\ub98b\uba0b"
+ + "\uba8b\ubb0b\ubb8b\ubc0b\uc413\uc413\uc413\uc413\uc413\uc413\uc413"
+ + "\uc413\uc413\uc413\uc413\uc413\uc413\uc413\uc413\uc413\uc492\uc492"
+ + "\uc492\uc492\uc492\uc492\uc492\uc492\uc492\uc492\uc492\uc492\uc492"
+ + "\uc492\uc492\uc492\u2e82\u2e82\u2e82\u4a82\u4a82\u2e82\u2e82\u3f80"
+ + "\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u3f80\u5705\u5705\u5705"
+ + "\u5705\u5705\u5705\u5705\u5705\u5705\u0519\u5705\u5705\u5705\u5705"
+ + "\u5705\u5705\u5705\u3f80\u5705\u5705\u5705\u5705\u5705\u3f80\u5705"
+ + "\u3f80\u0298\u5614\u5614\u1a97\u1a97\u6b95\u6c16\u6b95\u6c16\u6b95"
+ + "\u6c16\u6b95\u6c16\u6b95\u6c16\u6b95\u6c16\u0298\u0298\u6b95\u6c16"
+ + "\u0298\u0298\u0298\u0298\u1a97\u1a97\u1a97\u0298\u0298\u0519\u0614"
+ + "\u0c99\u0c99\u0c99\u3f80\u0298\u039a\u0318\u0298\u3f80\u3f80\u3f80"
+ + "\u3f80\u2282\u2302\u2382\u2402\u2482\u2502\u2582\u2602\u2682\u2702"
+ + "\u2782\u0455\u0c99\u04d6\u0c99\u0455\u039a\u039a\u0c99\u1a1b\u289c"
+ + "\u039a\u039a\u3f80\u289c\u0c99\u0c99\u0c99\u0c99\u289c\u289c\u3f80",
+
+ "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\u0080\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\u0080\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\u0080\005\005\u0080\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\u0080\u0080\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u1981\u1981\u1981\u1981\u1981"
+ + "\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981"
+ + "\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981"
+ + "\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981\u1981"
+ + "\u1981\u1981\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02"
+ + "\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02\u1a02"
+ + "\u1a02\u1a02\u1a02\u1a02\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\u0080\u0080\u0080\u0080\u0080\u0118\u0198\u021c\u0080"
+ + "\u0080\u0080\u0080\u028b\u030b\u038b\u040b\u048b\u050b\u058b\u060b"
+ + "\u068b\u070b\u078b\u080b\u088b\u090b\u098b\u0a0b\u0a8b\u0b0b\u0b8b"
+ + "\u0c0b\u0c8b\u0d0b\u0d8b\u0e0b\u0e8b\u0f0b\u0f8b\u100b\u108b\u110b"
+ + "\u118b\u120b\u128b\u130b\u138b\u140b\u148b\u150b\u158b\u160b\u168b"
+ + "\u170b\u178b\u180b\u188b\u0080\u0080\u0080\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u2008\u2008\u2086\u2086\u2086\u021c\u021c\u021c\u2008\u2008\u2008"
+ + "\u2008\u2008\u2008\u2110\u2110\u2110\u2110\u2110\u2110\u2110\u2110"
+ + "\u2086\u2086\u2086\u2086\u2086\u021c\u021c\u2086\u2086\u2086\u2086"
+ + "\u2086\u2086\u2086\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u2086\u2086\u2086\u2086\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u0080"
+ + "\u0080\u0080\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c\u021c"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\005\005\005\005\005\005\005\005\005\005"
+ + "\u190a\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\u0080\u028b\u048b"
+ + "\u070b\u090b\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\u0080\u0118\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\u0080\u0080"
+ + "\u1a89\u1b09\u1b89\u1c09\u1c89\u1d09\u1d89\u1e09\u1e89\u1f09\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u1f85"
+ + "\u1f85\u1f85\u1f85\u1f85\u1f85\u0080\u0080\u1f85\u0080\u1f85\u1f85"
+ + "\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85"
+ + "\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85"
+ + "\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85"
+ + "\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u1f85\u0080\u1f85"
+ + "\u1f85\u0080\u0080\u0080\u1f85\u0080\u0080\u1f85\u219c\u219c\u219c"
+ + "\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c"
+ + "\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c"
+ + "\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c"
+ + "\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c"
+ + "\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c\u219c"
+ + "\u219c\u219c\u219c\u219c\u219c\u219c\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u2201\u2319\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2319\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2319\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u0080\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u0080\u0080\u0080\u0080\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u0080\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u0080\u2201\u0080\u0080\u0080\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u0080\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2201\u0080\u2201\u2201\u0080\u0080\u2201\u0080\u0080\u2201"
+ + "\u2201\u0080\u0080\u2201\u2201\u2201\u2201\u0080\u2201\u2201\u2201"
+ + "\u2201\u2201\u2201\u2201\u2201\u2282\u2282\u2282\u2282\u0080\u2282"
+ + "\u0080\u2282\u2282\u2282\u2282\u2201\u2201\u0080\u2201\u2201\u2201"
+ + "\u2201\u0080\u0080\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u2201"
+ + "\u0080\u2201\u2201\u2201\u2201\u2201\u2201\u2201\u0080\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282\u2282"
+ + "\u2282\u2282\u2201\u2201\u0080\u2201\u2201\u2201\u2201\u0080\u2282"
+ + "\u2282\u2282\u2319\u2282\u2282\u2282\u2282\u2282\u2282\u0080\u0080"
+ + "\u0080\u0080\u2389\u2409\u2489\u2509\u2589\u2609\u2689\u2709\u2789"
+ + "\u2809\u2389\u2409\u2489\u2509\u2589\u2609\u2689\u2709\u2789\u2809"
+ + "\u2389\u2409\u2489\u2509\u2589\u2609\u2689\u2709\u2789\u2809\u2389"
+ + "\u2409\u2489\u2509\u2589\u2609\u2689\u2709\u2789\u2809\u2389\u2409"
+ + "\u2489\u2509\u2589\u2609\u2689\u2709\u2789\u2809",
+
+ "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\005\005\005\005"
+ + "\005\005\005\005\005\005\005\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080\u0080"
+ + "\u0080\u0080\u0080",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "",
+
+ "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106\u0106"
+ + "\u0106\u0106\u0106\u0106\u0106\u0106\u0106\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\u0090\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\000\000\000\000\000\000\000\000\000\000"
+ + "\000\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090"
+ + "\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090"
+ + "\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090"
+ + "\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090"
+ + "\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090"
+ + "\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090"
+ + "\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090"
+ + "\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090"
+ + "\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090\u0090",
+
+ "",
+
+ ""};
/**
* This is the attribute table for computing the numeric value of a
@@ -780,8 +1296,8 @@ public interface CharData
* Note that this is a signed value, but stored as an unsigned char
* since this is a String literal.
*/
- String NUM_VALUE
- = "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff"
+ String[] NUM_VALUE = new String[]{
+ "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff"
+ "\uffff\uffff\uffff\000\001\002\003\004\005\006\007"
+ "\010\011\uffff\uffff\012\013\014\015\016\017\020"
+ "\021\022\023\024\025\026\027\030\031\032\033"
@@ -796,23 +1312,66 @@ public interface CharData
+ "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff"
+ "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff"
+ "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff"
- + "\uffff\uffff\uffff\uffff\uffff\000\001\002\003\004\005"
- + "\006\007\010\011\uffff\uffff\uffff\uffff\000\001\002"
- + "\003\004\005\006\007\010\011\001\002\003\004"
- + "\uffff\020\012d\u03e8\uffff\uffff\uffff\024\036("
- + "2
+ *
+ * The returned map is modifiable. Changing it will not effect this
+ * collection of Headers in any way.
+ *
+ * @return a Map containing all the headers.
+ */
+ public Map getAsMap()
{
- Header key = new Header(name);
- String old = (String) super.get(key);
- if (old == null)
+ LinkedHashMap m = new LinkedHashMap();
+ for (Iterator it = headers.iterator(); it.hasNext(); )
{
- super.put(key, value);
+ HeaderElement e = (HeaderElement)it.next();
+ ArrayList l = (ArrayList)m.get(e.name);
+ if (l == null)
+ {
+ l = new ArrayList(1);
+ l.add(e.value);
+ m.put(e.name, l);
+ }
+ else
+ l.add(0, e.value);
}
- else
+ for (Iterator it = m.entrySet().iterator(); it.hasNext(); )
{
- super.put(key, old + ", " + value);
+ Map.Entry me = (Map.Entry)it.next();
+ ArrayList l = (ArrayList)me.getValue();
+ me.setValue(Collections.unmodifiableList(l));
}
+ return m;
+ }
+
+ /**
+ * Get the name of the Nth header.
+ *
+ * @param i the header index.
+ *
+ * @return the header name.
+ *
+ * @see #getHeaderValue
+ */
+ public String getHeaderName(int i)
+ {
+ if (i >= headers.size() || i < 0)
+ return null;
+
+ return ((HeaderElement)headers.get(i)).name;
+ }
+
+ /**
+ * Get the value of the Nth header.
+ *
+ * @param i the header index.
+ *
+ * @return the header value.
+ *
+ * @see #getHeaderName
+ */
+ public String getHeaderValue(int i)
+ {
+ if (i >= headers.size() || i < 0)
+ return null;
+
+ return ((HeaderElement)headers.get(i)).value;
}
}
diff --git a/libjava/classpath/gnu/java/net/protocol/http/Request.java b/libjava/classpath/gnu/java/net/protocol/http/Request.java
index b9441b3..e15ec41 100644
--- a/libjava/classpath/gnu/java/net/protocol/http/Request.java
+++ b/libjava/classpath/gnu/java/net/protocol/http/Request.java
@@ -1,5 +1,5 @@
/* Request.java --
- Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -94,11 +94,6 @@ public class Request
protected RequestBodyWriter requestBodyWriter;
/**
- * Request body negotiation threshold for 100-continue expectations.
- */
- protected int requestBodyNegotiationThreshold;
-
- /**
* Map of response header handlers.
*/
protected Map responseHeaderHandlers;
@@ -127,7 +122,6 @@ public class Request
this.path = path;
requestHeaders = new Headers();
responseHeaderHandlers = new HashMap();
- requestBodyNegotiationThreshold = 4096;
}
/**
@@ -251,21 +245,6 @@ public class Request
}
/**
- * Sets the request body negotiation threshold.
- * If this is set, it determines the maximum size that the request body
- * may be before body negotiation occurs(via the
- * 100-continue
expectation). This ensures that a large
- * request body is not sent when the server wouldn't have accepted it
- * anyway.
- * @param threshold the body negotiation threshold, or <=0 to disable
- * request body negotation entirely
- */
- public void setRequestBodyNegotiationThreshold(int threshold)
- {
- requestBodyNegotiationThreshold = threshold;
- }
-
- /**
* Dispatches this request.
* A request can only be dispatched once; calling this method a second
* time results in a protocol exception.
@@ -291,10 +270,10 @@ public class Request
if (requestBodyWriter != null)
{
contentLength = requestBodyWriter.getContentLength();
- if (contentLength > requestBodyNegotiationThreshold)
+ String expect = getHeader("Expect");
+ if (expect != null && expect.equals("100-continue"))
{
expectingContinue = true;
- setHeader("Expect", "100-continue");
}
else
{
@@ -323,12 +302,10 @@ public class Request
String line = method + ' ' + requestUri + ' ' + version + CRLF;
out.write(line.getBytes(US_ASCII));
// Request headers
- for (Iterator i = requestHeaders.keySet().iterator();
- i.hasNext(); )
+ for (Iterator i = requestHeaders.iterator(); i.hasNext(); )
{
- String name =(String) i.next();
- String value =(String) requestHeaders.get(name);
- line = name + HEADER_SEP + value + CRLF;
+ Headers.HeaderElement elt = (Headers.HeaderElement)i.next();
+ line = elt.name + HEADER_SEP + elt.value + CRLF;
out.write(line.getBytes(US_ASCII));
}
out.write(CRLF.getBytes(US_ASCII));
@@ -459,23 +436,17 @@ public class Request
void notifyHeaderHandlers(Headers headers)
{
- for (Iterator i = headers.entrySet().iterator(); i.hasNext(); )
+ for (Iterator i = headers.iterator(); i.hasNext(); )
{
- Map.Entry entry = (Map.Entry) i.next();
- String name =(String) entry.getKey();
+ Headers.HeaderElement entry = (Headers.HeaderElement) i.next();
// Handle Set-Cookie
- if ("Set-Cookie".equalsIgnoreCase(name))
- {
- String value = (String) entry.getValue();
- handleSetCookie(value);
- }
+ if ("Set-Cookie".equalsIgnoreCase(entry.name))
+ handleSetCookie(entry.value);
+
ResponseHeaderHandler handler =
- (ResponseHeaderHandler) responseHeaderHandlers.get(name);
+ (ResponseHeaderHandler) responseHeaderHandlers.get(entry.name);
if (handler != null)
- {
- String value = (String) entry.getValue();
- handler.setValue(value);
- }
+ handler.setValue(entry.value);
}
}
@@ -528,6 +499,9 @@ public class Request
throw new ProtocolException("Unsupported Content-Encoding: " +
contentCoding);
}
+ // Remove the Content-Encoding header because the content is
+ // no longer compressed.
+ responseHeaders.remove("Content-Encoding");
}
return in;
}
diff --git a/libjava/classpath/gnu/java/net/protocol/http/Response.java b/libjava/classpath/gnu/java/net/protocol/http/Response.java
index 58d7454..76fac93 100644
--- a/libjava/classpath/gnu/java/net/protocol/http/Response.java
+++ b/libjava/classpath/gnu/java/net/protocol/http/Response.java
@@ -1,5 +1,5 @@
/* Response.java --
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -188,6 +188,28 @@ public class Response
{
return headers.getDateValue(name);
}
+
+ /**
+ * Tests whether this response indicates a redirection.
+ *
+ * @return true
if, false
otherwise.
+ */
+ public boolean isRedirect()
+ {
+ return (code != 304 && getCodeClass() == 3);
+ }
+
+ /**
+ * Tests whether this response indicates an error.
+ * Errors are the response codes 4xx
- Client error and
+ * 5xx
- Server error.
+ *
+ * @return true
if, false
otherwise.
+ */
+ public boolean isError()
+ {
+ return (getCodeClass() == 4 || getCodeClass() == 5);
+ }
/**
* Returns an InputStream that returns the body of the response.
diff --git a/libjava/classpath/gnu/java/net/protocol/http/ResponseHeaderHandler.java b/libjava/classpath/gnu/java/net/protocol/http/ResponseHeaderHandler.java
index 8e4e649..4c5261d 100644
--- a/libjava/classpath/gnu/java/net/protocol/http/ResponseHeaderHandler.java
+++ b/libjava/classpath/gnu/java/net/protocol/http/ResponseHeaderHandler.java
@@ -41,7 +41,7 @@ package gnu.java.net.protocol.http;
/**
* Callback interface for objects that wish to be notified of response
* header values.
- * @see Request#setHeaderHandler(String)
+ * @see Request#setResponseHeaderHandler(String, ResponseHeaderHandler)
*
* @author Chris Burdess (dog@gnu.org)
*/
diff --git a/libjava/classpath/gnu/java/net/protocol/jar/Connection.java b/libjava/classpath/gnu/java/net/protocol/jar/Connection.java
index e2a052e..41c5d6d 100644
--- a/libjava/classpath/gnu/java/net/protocol/jar/Connection.java
+++ b/libjava/classpath/gnu/java/net/protocol/jar/Connection.java
@@ -1,5 +1,5 @@
/* Connection - jar url connection for java.net
- Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,6 +39,7 @@ exception statement from your version. */
package gnu.java.net.protocol.jar;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -145,7 +146,7 @@ public final class Connection extends JarURLConnection
jar_entry = (JarEntry) jar_file.getEntry (entry_name);
if(jar_entry == null)
- throw new IOException ("No entry for " + entry_name + " exists.");
+ throw new FileNotFoundException("No entry for " + entry_name + " exists.");
}
connected = true;
@@ -159,9 +160,6 @@ public final class Connection extends JarURLConnection
if (! doInput)
throw new ProtocolException("Can't open InputStream if doInput is false");
- if (jar_entry == null)
- throw new IOException (jar_url + " couldn't be found.");
-
return jar_file.getInputStream (jar_entry);
}
diff --git a/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java b/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java
index a557c7d..671ae5b 100644
--- a/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java
+++ b/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java
@@ -527,7 +527,7 @@ public final class FileChannelImpl extends FileChannel
throws IOException
{
if (newPosition < 0)
- throw new IllegalArgumentException ("newPostition: " + newPosition);
+ throw new IllegalArgumentException ("newPosition: " + newPosition);
if (!isOpen ())
throw new ClosedChannelException ();
diff --git a/libjava/classpath/gnu/java/nio/charset/Provider.java b/libjava/classpath/gnu/java/nio/charset/Provider.java
index 01c2650..ad3b1da 100644
--- a/libjava/classpath/gnu/java/nio/charset/Provider.java
+++ b/libjava/classpath/gnu/java/nio/charset/Provider.java
@@ -81,7 +81,8 @@ public final class Provider extends CharsetProvider
*/
private boolean extendedLoaded;
- private Provider ()
+ // Package private to avoid an accessor method in PrivilegedAction below.
+ Provider ()
{
extendedLoaded = false;
canonicalNames = new HashMap ();
diff --git a/libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java b/libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java
index fa6f497..f76d3fd 100644
--- a/libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java
+++ b/libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java
@@ -44,7 +44,6 @@ import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
final class IconvDecoder extends CharsetDecoder
diff --git a/libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java b/libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java
index d5cc887..47446f9 100644
--- a/libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java
+++ b/libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java
@@ -43,7 +43,6 @@ import gnu.classpath.Pointer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
diff --git a/libjava/classpath/gnu/java/nio/charset/iconv/IconvProvider.java b/libjava/classpath/gnu/java/nio/charset/iconv/IconvProvider.java
index 6fd8b74..cf9fc56 100644
--- a/libjava/classpath/gnu/java/nio/charset/iconv/IconvProvider.java
+++ b/libjava/classpath/gnu/java/nio/charset/iconv/IconvProvider.java
@@ -40,8 +40,6 @@ package gnu.java.nio.charset.iconv;
import java.nio.charset.Charset;
import java.nio.charset.spi.CharsetProvider;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
diff --git a/libjava/classpath/gnu/java/rmi/dgc/DGCImpl.java b/libjava/classpath/gnu/java/rmi/dgc/DGCImpl.java
index a32445c..a7bc094 100644
--- a/libjava/classpath/gnu/java/rmi/dgc/DGCImpl.java
+++ b/libjava/classpath/gnu/java/rmi/dgc/DGCImpl.java
@@ -8,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@@ -49,70 +49,146 @@ import java.rmi.server.RMISocketFactory;
import java.util.Hashtable;
/**
- * I let DGCImpl to extend UnicastServerRef, but not
- * UnicastRemoteObject, because UnicastRemoteObject must
- * exportObject automatically.
- */
+ * The DGC implementation is used for the server side during the distributed
+ * garbage collection. This interface contains the two methods: dirty and clean.
+ * A dirty call is made when a remote reference is unmarshaled in a client. A
+ * corresponding clean call is made by client it no longer uses that remote
+ * reference. A reference to a remote object is also automatically released
+ * after so called lease period that starts after the dirty call is received. It
+ * is the client's responsibility to renew the leases, by making additional
+ * dirty calls before such leases expire.
+ */
public class DGCImpl
- extends UnicastServerRef implements DGC {
-
- private static final long LEASE_VALUE = 600000L;
- // leaseCache caches a LeaseRecord associated with a vmid
- private Hashtable leaseCache = new Hashtable();
-
-public DGCImpl() throws RemoteException {
- super(new ObjID(ObjID.DGC_ID), 0, RMISocketFactory.getSocketFactory());
-}
-
-public Lease dirty(ObjID[] ids, long sequenceNum, Lease lease) throws RemoteException {
- VMID vmid = lease.getVMID();
- if (vmid == null)
- vmid = new VMID();
- long leaseValue = LEASE_VALUE;
- //long leaseValue = lease.getValue();
+ extends UnicastServerRef
+ implements DGC
+{
+ /*
+ * The DGCImpl extends UnicastServerRef and not UnicastRemoteObject, because
+ * UnicastRemoteObject must exportObject automatically.
+ */
+
+ /**
+ * This defauld lease value is used if the lease value, passed to the
+ * {@link #dirty} is equal to zero.
+ */
+ static final long LEASE_VALUE = 600000L;
+
+ // leaseCache caches a LeaseRecord associated with a vmid
+ Hashtable leaseCache = new Hashtable();
+
+ public DGCImpl() throws RemoteException
+ {
+ super(new ObjID(ObjID.DGC_ID), 0, RMISocketFactory.getSocketFactory());
+ }
+
+ /**
+ * Mark the given objects referecnes as used on the client side.
+ *
+ * @param ids the ids of the used objects.
+ * @param sequenceNum the number of the call (used to detect and discard late
+ * calls).
+ * @param lease the requested lease
+ * @return the granted lease
+ */
+ public Lease dirty(ObjID[] ids, long sequenceNum, Lease lease)
+ throws RemoteException
+ {
+ VMID vmid = lease.getVMID();
+ if (vmid == null)
+ vmid = new VMID();
+
+ long leaseValue = lease.getValue();
+ if (leaseValue <= 0)
+ leaseValue = LEASE_VALUE;
+
lease = new Lease(vmid, leaseValue);
- synchronized(leaseCache){
- LeaseRecord lr = (LeaseRecord)leaseCache.get(vmid);
- if (lr != null)
- lr.reset(leaseValue);
- else{
- lr = new LeaseRecord(vmid, leaseValue);
- leaseCache.put(vmid, lr);
- }
- }
-
- return (lease);
-}
-
-public void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong) throws RemoteException {
- // Not implemented
-}
+ LeaseRecord lr = (LeaseRecord) leaseCache.get(vmid);
+ if (lr != null)
+ lr.reset(leaseValue);
+ else
+ {
+ lr = new LeaseRecord(vmid, leaseValue, ids);
+ leaseCache.put(vmid, lr);
+ }
+ return (lease);
+ }
+
+ /**
+ * Mark the given objects as no longer used on the client side.
+ *
+ * @param ids the ids of the objects that are no longer used.
+ * @param sequenceNum the number of the call (used to detect and discard late
+ * calls)
+ * @param vmid the VMID of the client.
+ * @param strong make the "strong" clean call.
+ */
+ public void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong)
+ throws RemoteException
+ {
+ // Not implemented
+ // TODO implement
+ }
+
/**
* LeaseRecord associates a vmid to expireTime.
*/
- private static class LeaseRecord{
- private VMID vmid;
- private long expireTime;
+ static class LeaseRecord
+ {
+ /**
+ * The lease id.
+ */
+ final VMID vmid;
+
+ /**
+ * The lease expiration time.
+ */
+ long expireTime;
- LeaseRecord(VMID vmid, long leaseValue){
+ /**
+ * The array of ObjeID's that must be protected from being garbage
+ * collected.
+ */
+ final ObjID [] objects;
+
+ /**
+ * Create the new lease record.
+ *
+ * @param vmid lease id.
+ * @param leaseValue lease value
+ */
+ LeaseRecord(VMID vmid, long leaseValue, ObjID [] an_objects)
+ {
this.vmid = vmid;
reset(leaseValue);
+ objects = an_objects;
}
-
- // reset expireTime
- void reset(long leaseValue){
+
+ /**
+ * Prolong the expiration time till current time + passed value
+ *
+ * @param leaseValue the value after that (since the current moment)
+ * the lease should expire in the future.
+ */
+ void reset(long leaseValue)
+ {
long l = System.currentTimeMillis();
expireTime = l + leaseValue;
}
-
- boolean isExpired(){
+
+ /**
+ * Check if the lease has been expired.
+ *
+ * @return true if the lease has been expired, false if it is still valid.
+ */
+ boolean isExpired()
+ {
long l = System.currentTimeMillis();
- if ( l > expireTime)
- return true;
+ if (l > expireTime)
+ return true;
return false;
}
-
- } //End of LeaseRecord
-} //End of DGCImpl
+ } // End of LeaseRecord
+
+} // End of DGCImpl
diff --git a/libjava/classpath/gnu/java/rmi/registry/RegistryImpl.java b/libjava/classpath/gnu/java/rmi/registry/RegistryImpl.java
index 0c94434..7dcca61 100644
--- a/libjava/classpath/gnu/java/rmi/registry/RegistryImpl.java
+++ b/libjava/classpath/gnu/java/rmi/registry/RegistryImpl.java
@@ -111,7 +111,7 @@ public static void version() {
+ System.getProperty("java.vm.name")
+ ") "
+ System.getProperty("java.vm.version"));
- System.out.println("Copyright 2005 Free Software Foundation, Inc.");
+ System.out.println("Copyright 2006 Free Software Foundation, Inc.");
System.out.println("This is free software; see the source for copying conditions. There is NO");
System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
System.exit(0);
diff --git a/libjava/classpath/gnu/java/rmi/server/CombinedClassLoader.java b/libjava/classpath/gnu/java/rmi/server/CombinedClassLoader.java
new file mode 100644
index 0000000..3d2e37d
--- /dev/null
+++ b/libjava/classpath/gnu/java/rmi/server/CombinedClassLoader.java
@@ -0,0 +1,149 @@
+/* CombinedClassLoader.java -- Multiple class loader support for proxy.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.rmi.server;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+/**
+ * This class supports the multiple class loaders to load the resources. It is
+ * used for constructing proxy classes that implement interfaces, loaded by
+ * the several different class loaders.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class CombinedClassLoader extends ClassLoader
+{
+ /**
+ * The class loader array.
+ */
+ ClassLoader[] loaders;
+
+ /**
+ * Create a new combined class loader that uses the given collection of
+ * loaders to load the classes and resources. The loader order is equal to
+ * the order, returned by the collection interator. The duplicate loaders
+ * are discarded and the system class loader is added as the last loader.
+ *
+ * @param a_loaders the loadery collection (may contain duplicate instances
+ * that will be discarded.
+ */
+ public CombinedClassLoader(Collection a_loaders)
+ {
+ ArrayList sLoaders = new ArrayList(a_loaders.size());
+
+ Iterator iter = a_loaders.iterator();
+ Object cl;
+ while (iter.hasNext())
+ {
+ cl = iter.next();
+ if (!sLoaders.contains(cl))
+ sLoaders.add(iter.next());
+ }
+
+ loaders = new ClassLoader[sLoaders.size()];
+
+ for (int i = 0; i < loaders.length; i++)
+ loaders[i] = (ClassLoader) sLoaders.get(i);
+ }
+
+ /**
+ * Find the class with the given name.
+ */
+ protected Class findClass(String name) throws ClassNotFoundException
+ {
+ for (int i = 0; i < loaders.length; i++)
+ {
+ try
+ {
+ return findClass(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ // try another.
+ }
+ }
+ return super.findClass(name);
+ }
+
+ /**
+ * Find the library with the given name
+ */
+ protected String findLibrary(String name)
+ {
+ for (int i = 0; i < loaders.length; i++)
+ {
+ String lib = findLibrary(name);
+ if (lib != null)
+ return lib;
+ }
+ return super.findLibrary(name);
+ }
+
+ /**
+ * Find resource with the given name.
+ */
+ protected URL findResource(String name)
+ {
+ for (int i = 0; i < loaders.length; i++)
+ {
+ URL resource = findResource(name);
+ if (resource != null)
+ return resource;
+ }
+ return super.findResource(name);
+ }
+
+ /**
+ * Find resources with the given name.
+ */
+ protected Enumeration findResources(String name) throws IOException
+ {
+ for (int i = 0; i < loaders.length; i++)
+ {
+ Enumeration resource = findResources(name);
+ if (resource != null)
+ return resource;
+ }
+ return super.findResources(name); }
+}
diff --git a/libjava/classpath/gnu/java/rmi/server/RMIObjectInputStream.java b/libjava/classpath/gnu/java/rmi/server/RMIObjectInputStream.java
index 587d57f..e765354 100644
--- a/libjava/classpath/gnu/java/rmi/server/RMIObjectInputStream.java
+++ b/libjava/classpath/gnu/java/rmi/server/RMIObjectInputStream.java
@@ -46,6 +46,7 @@ import java.io.ObjectStreamClass;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.rmi.server.RMIClassLoader;
+import java.util.ArrayList;
public class RMIObjectInputStream
extends ObjectInputStream {
@@ -76,28 +77,51 @@ protected Object getAnnotation()
return readObject();
}
-protected Class resolveProxyClass(String intfs[])
- throws IOException, ClassNotFoundException
-{
- String annotation = (String)getAnnotation();
-
+
+ protected Class resolveProxyClass(String intfs[]) throws IOException,
+ ClassNotFoundException
+ {
+ String annotation = (String) getAnnotation();
+
Class clss[] = new Class[intfs.length];
- if(annotation == null)
- clss[0] = RMIClassLoader.loadClass(intfs[0]);
- else
- clss[0] = RMIClassLoader.loadClass(annotation, intfs[0]);
-
- //assume all interfaces can be loaded by the same classloader
- ClassLoader loader = clss[0].getClassLoader();
+
for (int i = 0; i < intfs.length; i++)
- clss[i] = Class.forName(intfs[i], false, loader);
-
- try {
- return Proxy.getProxyClass(loader, clss);
- } catch (IllegalArgumentException e) {
- throw new ClassNotFoundException(null, e);
- }
-}
+ {
+ if (annotation == null)
+ clss[i] = RMIClassLoader.loadClass(intfs[i]);
+ else
+ clss[i] = RMIClassLoader.loadClass(annotation, intfs[i]);
+ }
+
+ ClassLoader loader;
+
+ if (clss.length > 0)
+ {
+ // Chain all class loaders (they may differ).
+ ArrayList loaders = new ArrayList(intfs.length);
+ ClassLoader cx;
+ for (int i = 0; i < clss.length; i++)
+ {
+ cx = clss[i].getClassLoader();
+ if (!loaders.contains(cx))
+ {
+ loaders.add(0, cx);
+ }
+ }
+ loader = new CombinedClassLoader(loaders);
+ }
+ else
+ loader = ClassLoader.getSystemClassLoader();
+
+ try
+ {
+ return Proxy.getProxyClass(loader, clss);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ClassNotFoundException(null, e);
+ }
+ }
protected Object readValue(Class valueClass) throws IOException, ClassNotFoundException {
if(valueClass.isPrimitive()){
diff --git a/libjava/classpath/gnu/java/rmi/server/UnicastServerRef.java b/libjava/classpath/gnu/java/rmi/server/UnicastServerRef.java
index 1f6eede..dcb12a5 100644
--- a/libjava/classpath/gnu/java/rmi/server/UnicastServerRef.java
+++ b/libjava/classpath/gnu/java/rmi/server/UnicastServerRef.java
@@ -1,5 +1,5 @@
/* UnicastServerRef.java --
- Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003, 2004
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003, 2004, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -43,263 +43,433 @@ import java.io.ObjectInputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.ObjID;
import java.rmi.server.RMIServerSocketFactory;
+import java.rmi.server.RemoteObjectInvocationHandler;
import java.rmi.server.RemoteRef;
import java.rmi.server.RemoteServer;
import java.rmi.server.RemoteStub;
import java.rmi.server.ServerNotActiveException;
-import java.rmi.server.ServerRef;
import java.rmi.server.Skeleton;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Iterator;
public class UnicastServerRef
- extends UnicastRef
- implements ServerRef{ //SHOULD implement ServerRef
+ extends UnicastRef
+{
+
+ /**
+ * Use GNU Classpath v 0.20 SVUID for interoperability
+ */
+ private static final long serialVersionUID = - 5585608108300801246L;
+
+ /**
+ * The class array, defining parameters of the jdk 1.2 RMI stub constructor.
+ */
+ private static final Class[] stubprototype = new Class[] { RemoteRef.class };
+
+ /**
+ * The exported remote object itself.
+ */
+ Remote myself; // save the remote object itself
+
+ /**
+ * The skeleton (if any), associated with the exported remote object.
+ */
+ private Skeleton skel;
+
+ /**
+ * The stub, associated with the exported remote object (may be proxy class).
+ */
+ private Remote stub;
+
+ /**
+ * The method table (RMI hash code to method) of the methods of the
+ * exported object.
+ */
+ private Hashtable methods = new Hashtable();
+
+ /**
+ * Used by serialization.
+ */
+ UnicastServerRef()
+ {
+ }
+
+ public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory ssf)
+ throws RemoteException
+ {
+ super(id);
+ manager = UnicastConnectionManager.getInstance(port, ssf);
+ }
+
+ /**
+ * Export the object and return its remote stub. The method tries to locate
+ * existing stubs and skeletons. If this fails, the method instantiates the
+ * proxy stub class.
+ *
+ * Stubs and skeletons are always ignored (even if present) if the
+ * java.rmi.server.ignoreStubClasses property is set to true.
+ *
+ * @param obj the object being exported.
+ * @return the stub (existing class or proxy) of the exported object.
+ * @throws RemoteException if the export failed due any reason
+ */
+ public Remote exportObject(Remote obj) throws RemoteException
+ {
+ if (myself == null)
+ {
+ myself = obj;
+ // Save it to server manager, to let client calls in the same VM to
+ // issue
+ // local call
+ manager.serverobj = obj;
+
+ String ignoreStubs;
+
+ ClassLoader loader =obj.getClass().getClassLoader();
+
+ // Stubs are always searched for the bootstrap classes that may have
+ // obsolete pattern and may still need also skeletons.
+ if (loader==null)
+ ignoreStubs = "false";
+ else
+ ignoreStubs = System.getProperty("java.rmi.server.ignoreStubClasses",
+ "false");
+
+ if (! ignoreStubs.equals("true"))
+ {
+ // Find and install the stub
+ Class cls = obj.getClass();
+
+ // where ist the _Stub? (check superclasses also)
+ Class expCls = expCls = findStubSkelClass(cls);
+
+ if (expCls != null)
+ {
+ stub = (RemoteStub) getHelperClass(expCls, "_Stub");
+ // Find and install the skeleton (if there is one)
+ skel = (Skeleton) getHelperClass(expCls, "_Skel");
+ }
+ }
+
+ if (stub == null)
+ stub = createProxyStub(obj.getClass(), this);
+
+ // Build hash of methods which may be called.
+ buildMethodHash(obj.getClass(), true);
+
+ // Export it.
+ UnicastServer.exportObject(this);
+ }
-final static private Class[] stubprototype = new Class[] { RemoteRef.class };
-
-Remote myself; //save the remote object itself
-private Skeleton skel;
-private RemoteStub stub;
-private Hashtable methods = new Hashtable();
-
-/**
- * Used by serialization.
- */
-UnicastServerRef()
-{
-}
-
-public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory ssf) throws RemoteException {
- super(id);
- manager = UnicastConnectionManager.getInstance(port, ssf);
-}
-
-public RemoteStub exportObject(Remote obj) throws RemoteException {
- if (myself == null) {
- myself = obj;
- // Save it to server manager, to let client calls in the same VM to issue
- // local call
- manager.serverobj = obj;
-
- // Find and install the stub
- Class cls = obj.getClass();
- Class expCls;
- try {
- // where ist the _Stub? (check superclasses also)
- expCls = findStubSkelClass(cls);
- } catch (Exception ex) {
- throw new RemoteException("can not find stubs for class: " + cls, ex);
- }
-
- stub = (RemoteStub)getHelperClass(expCls, "_Stub");
- if (stub == null) {
- throw new RemoteException("failed to export: " + cls);
- }
-
- // Find and install the skeleton (if there is one)
- skel = (Skeleton)getHelperClass(expCls, "_Skel");
-
- // Build hash of methods which may be called.
- buildMethodHash(obj.getClass(), true);
-
- // Export it.
- UnicastServer.exportObject(this);
- }
-
- return (stub);
-}
-
-public RemoteStub exportObject(Remote remote, Object obj)
- throws RemoteException
-{
- //FIX ME
- return exportObject(remote);
-}
-
-public RemoteStub getStub(){
return stub;
-}
-
-
-public boolean unexportObject(Remote obj, boolean force) {
+ }
+
+ /**
+ * Get the stub (actual class or proxy) of the exported remote object.
+ *
+ * @return the remote stub (null if exportObject has not been called).
+ */
+ public Remote getStub()
+ {
+ return stub;
+ }
+
+ /**
+ * Unexport the object (remove methods from the method hashcode table
+ * and call UnicastServer.unexportObject.
+ *
+ * @param obj the object being unexported
+ * @param force passed to the UnicastServer.unexportObject.
+ * @return value, returned by the UnicastServer.unexportObject.
+ */
+ public boolean unexportObject(Remote obj, boolean force)
+ {
// Remove all hashes of methods which may be called.
buildMethodHash(obj.getClass(), false);
return UnicastServer.unexportObject(this, force);
-}
-
-/**
-*
-* The Subs/Skels might not there for the actual class, but maybe
-* for one of the superclasses.
-*
-*/
-private Class findStubSkelClass(Class startCls) throws Exception {
- Class cls = startCls;
-
- while (true) {
- try {
- String stubClassname = cls.getName() + "_Stub";
- ClassLoader cl = cls.getClassLoader();
- Class scls = cl == null ? Class.forName(stubClassname)
- : cl.loadClass(stubClassname);
- return cls; // found it
- } catch (ClassNotFoundException e) {
- Class superCls = cls.getSuperclass();
- if (superCls == null
- || superCls == java.rmi.server.UnicastRemoteObject.class)
- {
- throw new Exception("Neither " + startCls
- + " nor one of their superclasses (like" + cls + ")"
- + " has a _Stub");
- }
- cls = superCls;
- }
- }
-}
-
-
-
-private Object getHelperClass(Class cls, String type) {
- try {
- String classname = cls.getName();
- ClassLoader cl = cls.getClassLoader();
- Class scls = cl == null ? Class.forName(classname + type)
- : cl.loadClass(classname + type);
- if (type.equals("_Stub")) {
- try {
- // JDK 1.2 stubs
- Constructor con = scls.getConstructor(stubprototype);
- return (con.newInstance(new Object[]{this}));
- }
- catch (NoSuchMethodException e) {
- }
- catch (InstantiationException e) {
- }
- catch (IllegalAccessException e) {
- }
- catch (IllegalArgumentException e) {
- }
- catch (InvocationTargetException e) {
- }
- // JDK 1.1 stubs
- RemoteStub stub = (RemoteStub)scls.newInstance();
- UnicastRemoteStub.setStubRef(stub, this);
- return (stub);
- }
- else {
- // JDK 1.1 skel
- return (scls.newInstance());
- }
- }
- catch (ClassNotFoundException e) {
- }
- catch (InstantiationException e) {
- }
- catch (IllegalAccessException e) {
- }
- return (null);
-}
-
-
-
-public String getClientHost() throws ServerNotActiveException {
- return RemoteServer.getClientHost();
-}
-
-private void buildMethodHash(Class cls, boolean build) {
- Method[] meths = cls.getMethods();
- for (int i = 0; i < meths.length; i++) {
- /* Don't need to include any java.xxx related stuff */
- if (meths[i].getDeclaringClass().getName().startsWith("java.")) {
- continue;
- }
- long hash = RMIHashes.getMethodHash(meths[i]);
- if(build)
- methods.put(new Long (hash), meths[i]);
- else
- methods.remove(new Long (hash));
-//System.out.println("meth = " + meths[i] + ", hash = " + hash);
- }
-}
-
-Class getMethodReturnType(int method, long hash) throws Exception
-{
- if (method == -1) {
- Method meth = (Method)methods.get(new Long (hash));
+ }
+
+ /**
+ * Return the class in the hierarchy for that the stub class is defined.
+ * The Subs/Skels might not there for the actual class, but maybe for one of
+ * the superclasses.
+ *
+ * @return the class having stub defined, null if none.
+ */
+ private Class findStubSkelClass(Class startCls)
+ {
+ Class cls = startCls;
+
+ while (true)
+ {
+ try
+ {
+ String stubClassname = cls.getName() + "_Stub";
+ ClassLoader cl = cls.getClassLoader();
+ Class scls = cl == null ? Class.forName(stubClassname)
+ : cl.loadClass(stubClassname);
+ return cls; // found it
+ }
+ catch (ClassNotFoundException e)
+ {
+ Class superCls = cls.getSuperclass();
+ if (superCls == null
+ || superCls == java.rmi.server.UnicastRemoteObject.class)
+ {
+ return null;
+ }
+ cls = superCls;
+ }
+ }
+ }
+
+ /**
+ * Get the helper (assisting) class with the given type.
+ *
+ * @param cls the class, for that the helper class is requested. This class
+ * and the requested helper class must share the same class loader.
+ *
+ * @param type the type of the assisting helper. The only currently supported
+ * non deprecated value is "_Stub" (load jdk 1.1 or 1.2 RMI stub). Another
+ * (deprecated) value is "_Skel" (load skeleton).
+ *
+ * @return the instantiated instance of the helper class or null if the
+ * helper class cannot be found or instantiated.
+ */
+ private Object getHelperClass(Class cls, String type)
+ {
+ try
+ {
+ String classname = cls.getName();
+ ClassLoader cl = cls.getClassLoader();
+ Class scls = cl == null ? Class.forName(classname + type)
+ : cl.loadClass(classname + type);
+ if (type.equals("_Stub"))
+ {
+ try
+ {
+ // JDK 1.2 stubs
+ Constructor con = scls.getConstructor(stubprototype);
+ return (con.newInstance(new Object[] { this }));
+ }
+ catch (NoSuchMethodException e)
+ {
+ }
+ catch (InstantiationException e)
+ {
+ }
+ catch (IllegalAccessException e)
+ {
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ catch (InvocationTargetException e)
+ {
+ }
+ // JDK 1.1 stubs
+ RemoteStub stub = (RemoteStub) scls.newInstance();
+ UnicastRemoteStub.setStubRef(stub, this);
+ return (stub);
+ }
+ else
+ {
+ // JDK 1.1 skel
+ return (scls.newInstance());
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ }
+ catch (InstantiationException e)
+ {
+ }
+ catch (IllegalAccessException e)
+ {
+ }
+ return (null);
+ }
+
+ public String getClientHost() throws ServerNotActiveException
+ {
+ return RemoteServer.getClientHost();
+ }
+
+ /**
+ * Build the method has code table and put it into {@link #methods}
+ * (mapping RMI hashcode tos method). The same method is used to remove
+ * the table.
+ *
+ * @param cls the class for that the method table is built.
+ * @param build if true, the class methods are added to the table. If
+ * false, they are removed from the table.
+ */
+ private void buildMethodHash(Class cls, boolean build)
+ {
+ Method[] meths = cls.getMethods();
+ for (int i = 0; i < meths.length; i++)
+ {
+ /* Don't need to include any java.xxx related stuff */
+ if (meths[i].getDeclaringClass().getName().startsWith("java."))
+ {
+ continue;
+ }
+ long hash = RMIHashes.getMethodHash(meths[i]);
+ if (build)
+ methods.put(new Long(hash), meths[i]);
+ else
+ methods.remove(new Long(hash));
+ // System.out.println("meth = " + meths[i] + ", hash = " + hash);
+ }
+ }
+
+ Class getMethodReturnType(int method, long hash) throws Exception
+ {
+ if (method == - 1)
+ {
+ Method meth = (Method) methods.get(new Long(hash));
return meth.getReturnType();
- }else
- return null;
-}
-
-public Object incomingMessageCall(UnicastConnection conn, int method, long hash) throws Exception {
-//System.out.println("method = " + method + ", hash = " + hash);
- // If method is -1 then this is JDK 1.2 RMI - so use the hash
- // to locate the method
- if (method == -1) {
- Method meth = (Method)methods.get(new Long (hash));
-//System.out.println("class = " + myself.getClass() + ", meth = " + meth);
- if (meth == null) {
- throw new NoSuchMethodException();
- }
-
- ObjectInputStream in = conn.getObjectInputStream();
- int nrargs = meth.getParameterTypes().length;
- Object[] args = new Object[nrargs];
- for (int i = 0; i < nrargs; i++) {
- /**
- * For debugging purposes - we don't handle CodeBases
- * quite right so we don't always find the stubs. This
- * lets us know that.
- */
- try {
- // need to handle primitive types
- args[i] = ((RMIObjectInputStream)in).readValue(meth.getParameterTypes()[i]);
-
- }
- catch (Exception t) {
- t.printStackTrace();
- throw t;
- }
- }
- //We must reinterpret the exception thrown by meth.invoke()
- //return (meth.invoke(myself, args));
- Object ret = null;
- try{
- ret = meth.invoke(myself, args);
- }catch(InvocationTargetException e){
- Throwable cause = e.getTargetException();
- if (cause instanceof Exception) {
- throw (Exception)cause;
- }
- else if (cause instanceof Error) {
- throw (Error)cause;
- }
- else {
- throw new Error("The remote method threw a java.lang.Throwable that is neither java.lang.Exception nor java.lang.Error.", e);
- }
- }
- return ret;
- }
- // Otherwise this is JDK 1.1 style RMI - we find the skeleton
- // and invoke it using the method number. We wrap up our
- // connection system in a UnicastRemoteCall so it appears in a
- // way the Skeleton can handle.
- else {
- if (skel == null) {
- throw new NoSuchMethodException();
- }
- UnicastRemoteCall call = new UnicastRemoteCall(conn);
- skel.dispatch(myself, call, method, hash);
- if (!call.isReturnValue())
- return RMIVoidValue.INSTANCE;
- else
- return (call.returnValue());
- }
-}
+ }
+ else
+ return null;
+ }
+
+ public Object incomingMessageCall(UnicastConnection conn, int method,
+ long hash) throws Exception
+ {
+ // System.out.println("method = " + method + ", hash = " + hash);
+ // If method is -1 then this is JDK 1.2 RMI - so use the hash
+ // to locate the method
+ if (method == - 1)
+ {
+ Method meth = (Method) methods.get(new Long(hash));
+ // System.out.println("class = " + myself.getClass() + ", meth = " +
+ // meth);
+ if (meth == null)
+ {
+ throw new NoSuchMethodException();
+ }
+
+ ObjectInputStream in = conn.getObjectInputStream();
+ int nrargs = meth.getParameterTypes().length;
+ Object[] args = new Object[nrargs];
+ for (int i = 0; i < nrargs; i++)
+ {
+ /**
+ * For debugging purposes - we don't handle CodeBases quite right so
+ * we don't always find the stubs. This lets us know that.
+ */
+ try
+ {
+ // need to handle primitive types
+ args[i] = ((RMIObjectInputStream) in)
+ .readValue(meth.getParameterTypes()[i]);
+
+ }
+ catch (Exception t)
+ {
+ t.printStackTrace();
+ throw t;
+ }
+ }
+ //We must reinterpret the exception thrown by meth.invoke()
+ //return (meth.invoke(myself, args));
+ Object ret = null;
+ try
+ {
+ ret = meth.invoke(myself, args);
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable cause = e.getTargetException();
+ if (cause instanceof Exception)
+ {
+ throw (Exception) cause;
+ }
+ else if (cause instanceof Error)
+ {
+ throw (Error) cause;
+ }
+ else
+ {
+ throw new Error(
+ "The remote method threw a java.lang.Throwable that"+
+ " is neither java.lang.Exception nor java.lang.Error.",
+ e);
+ }
+ }
+ return ret;
+ }
+ // Otherwise this is JDK 1.1 style RMI - we find the skeleton
+ // and invoke it using the method number. We wrap up our
+ // connection system in a UnicastRemoteCall so it appears in a
+ // way the Skeleton can handle.
+ else
+ {
+ if (skel == null)
+ {
+ throw new NoSuchMethodException();
+ }
+ UnicastRemoteCall call = new UnicastRemoteCall(conn);
+ skel.dispatch(myself, call, method, hash);
+ if (! call.isReturnValue())
+ return RMIVoidValue.INSTANCE;
+ else
+ return (call.returnValue());
+ }
+ }
+
+ /**
+ * Create the 1.2 proxy stub in the case when the pre-generated stub is not
+ * available of the system is explicitly instructed to use proxy stubs.
+ *
+ * @param stubFor the class for that the proxy class must be constructed.
+ * @param reference the remote reference, used to find the given object
+ *
+ * @return the applicable proxy stub.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+ Remote createProxyStub(Class stubFor, RemoteRef reference)
+ {
+ // Collect all interfaces, implemented by stubFor and derived from
+ // Remote (also Remote itself):
+ HashSet interfaces = new HashSet();
+ Class c = stubFor;
+ Class[] intfs;
+
+ while (c != null)
+ {
+ intfs = c.getInterfaces();
+ for (int i = 0; i < intfs.length; i++)
+ {
+ if (Remote.class.isAssignableFrom(intfs[i]))
+ interfaces.add(intfs[i]);
+ }
+ c = c.getSuperclass();
+ }
+
+ intfs = new Class[interfaces.size()];
+ Iterator it = interfaces.iterator();
+
+ for (int i = 0; i < intfs.length; i++)
+ intfs[i] = (Class) it.next();
+
+ RemoteObjectInvocationHandler handler =
+ new RemoteObjectInvocationHandler(reference);
+
+ Object proxy =
+ Proxy.newProxyInstance(stubFor.getClassLoader(), intfs, handler);
+
+ return (Remote) proxy;
+ }
+
}
diff --git a/libjava/classpath/gnu/java/security/Properties.java b/libjava/classpath/gnu/java/security/Properties.java
new file mode 100644
index 0000000..813888c
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/Properties.java
@@ -0,0 +1,374 @@
+/* Properties.java -- run-time configuration properties.
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.PropertyPermission;
+
+/**
+ *
A global object containing build-specific properties that affect the + * behaviour of the generated binaries from this library.
+ */ +public final class Properties +{ + + // Debugging methods and variables + // ------------------------------------------------------------------------- + + private static final String NAME = "Properties"; + + private static final boolean DEBUG = false; + + // private static final int debuglevel = 9; + private static final PrintWriter err = new PrintWriter(System.out, true); + + private static void debug(final String s) + { + err.println(">>> " + NAME + ": " + s); + } + + // Constants and variables + // ------------------------------------------------------------------------- + + public static final String VERSION = "gnu.crypto.version"; + + public static final String PROPERTIES_FILE = "gnu.crypto.properties.file"; + + public static final String REPRODUCIBLE_PRNG = "gnu.crypto.with.reproducible.prng"; + + public static final String CHECK_WEAK_KEYS = "gnu.crypto.with.check.for.weak.keys"; + + public static final String DO_RSA_BLINDING = "gnu.crypto.with.rsa.blinding"; + + private static final String TRUE = Boolean.TRUE.toString(); + + private static final String FALSE = Boolean.FALSE.toString(); + + private static final HashMap props = new HashMap(); + + private static Properties singleton = null; + + private boolean reproducible = false; + + private boolean checkForWeakKeys = true; + + private boolean doRSABlinding = true; + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** Trivial constructor to enforce Singleton pattern. */ + private Properties() + { + super(); + init(); + } + + // Class methods + // ------------------------------------------------------------------------- + + /** + *Returns the string representation of the library global configuration
+ * property with the designated key
.
null
if such property is not yet set, or key
is
+ * empty.
+ */
+ public static final synchronized String getProperty(String key)
+ {
+ if (key == null)
+ return null;
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(key, "read"));
+ key = key.trim().toLowerCase();
+ if ("".equals(key))
+ return null;
+ return (String) props.get(key);
+ }
+
+ /**
+ * Sets the value of a designated library global configuration property, + * to a string representation of what should be a legal value.
+ * + * @param key the case-insensitive, non-null and non-empty name of a + * configuration property. + * @param value the non-null, non-empty string representation of a legal + * value of the configuration property named bykey
.
+ */
+ public static final synchronized void setProperty(String key, String value)
+ {
+ if (key == null || value == null)
+ return;
+ key = key.trim().toLowerCase();
+ if ("".equals(key))
+ return;
+ if (key.equals(VERSION))
+ return;
+ value = value.trim();
+ if ("".equals(value))
+ return;
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(key, "write"));
+ if (key.equals(REPRODUCIBLE_PRNG)
+ && (value.equalsIgnoreCase(TRUE) || value.equalsIgnoreCase(FALSE)))
+ setReproducible(Boolean.valueOf(value).booleanValue());
+ else if (key.equals(CHECK_WEAK_KEYS)
+ && (value.equalsIgnoreCase(TRUE) || value.equalsIgnoreCase(FALSE)))
+ setCheckForWeakKeys(Boolean.valueOf(value).booleanValue());
+ else if (key.equals(DO_RSA_BLINDING)
+ && (value.equalsIgnoreCase(TRUE) || value.equalsIgnoreCase(FALSE)))
+ setDoRSABlinding(Boolean.valueOf(value).booleanValue());
+ else
+ props.put(key, value);
+ }
+
+ /**
+ * A convenience method that returns, as a boolean, the library global + * configuration property indicating if the default Pseudo Random Number + * Generator produces, or not, the same bit stream when instantiated.
+ * + * @returntrue
if the default PRNG produces the same bit stream
+ * with every VM instance. Returns false
if the default PRNG is
+ * seeded with the time of day of its first invocation.
+ */
+ public static final synchronized boolean isReproducible()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(REPRODUCIBLE_PRNG, "read"));
+ return instance().reproducible;
+ }
+
+ /**
+ * A convenience method that returns, as a boolean, the library global + * configuration property indicating if the implementations of symmetric + * key block ciphers check, or not, for possible/potential weak and semi-weak + * keys that may be produced in the course of generating round encryption + * and/or decryption keys.
+ * + * @returntrue
if the cipher implementations check for weak and
+ * semi-weak keys. Returns false
if the cipher implementations
+ * do not check for weak or semi-weak keys.
+ */
+ public static final synchronized boolean checkForWeakKeys()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(CHECK_WEAK_KEYS, "read"));
+ return instance().checkForWeakKeys;
+ }
+
+ /**
+ * A convenience method that returns, as a boolean, the library global + * configuration property indicating if RSA decryption (RSADP primitive), + * does, or not, blinding against timing attacks.
+ * + * @returntrue
if the RSA decryption primitive includes a
+ * blinding operation. Returns false
if the RSA decryption
+ * primitive does not include the additional blinding operation.
+ */
+ public static final synchronized boolean doRSABlinding()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(DO_RSA_BLINDING, "read"));
+ return instance().doRSABlinding;
+ }
+
+ /**
+ * A convenience method to set the global property for reproducibility of + * the default PRNG bit stream output.
+ * + * @param value iftrue
then the default PRNG bit stream output
+ * is the same with every invocation of the VM.
+ */
+ public static final synchronized void setReproducible(final boolean value)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(REPRODUCIBLE_PRNG, "write"));
+ instance().reproducible = value;
+ props.put(REPRODUCIBLE_PRNG, String.valueOf(value));
+ }
+
+ /**
+ * A convenience method to set the global property for checking for weak + * and semi-weak cipher keys.
+ * + * @param value iftrue
then the cipher implementations will
+ * invoke additional checks for weak and semi-weak key values that may get
+ * generated.
+ */
+ public static final synchronized void setCheckForWeakKeys(final boolean value)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(CHECK_WEAK_KEYS, "write"));
+ instance().checkForWeakKeys = value;
+ props.put(CHECK_WEAK_KEYS, String.valueOf(value));
+ }
+
+ /**
+ * A convenience method to set the global property fo adding a blinding + * operation when executing the RSA decryption primitive.
+ * + * @param value iftrue
then the code for performing the RSA
+ * decryption primitive will include a blinding operation.
+ */
+ public static final synchronized void setDoRSABlinding(final boolean value)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(DO_RSA_BLINDING, "write"));
+ instance().doRSABlinding = value;
+ props.put(DO_RSA_BLINDING, String.valueOf(value));
+ }
+
+ private static final synchronized Properties instance()
+ {
+ if (singleton == null)
+ singleton = new Properties();
+ return singleton;
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+ private void init()
+ {
+ // default values
+ props.put(REPRODUCIBLE_PRNG, (reproducible ? "true" : "false"));
+ props.put(CHECK_WEAK_KEYS, (checkForWeakKeys ? "true" : "false"));
+ props.put(DO_RSA_BLINDING, (doRSABlinding ? "true" : "false"));
+
+ // 1. allow site-wide override by reading a properties file
+ String propFile = null;
+ try
+ {
+ propFile = (String) AccessController.doPrivileged(new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return System.getProperty(PROPERTIES_FILE);
+ }
+ });
+ }
+ catch (SecurityException se)
+ {
+ if (DEBUG)
+ debug("Reading property " + PROPERTIES_FILE
+ + " not allowed. Ignored.");
+ }
+ if (propFile != null)
+ {
+ try
+ {
+ final java.util.Properties temp = new java.util.Properties();
+ final FileInputStream fin = new FileInputStream(propFile);
+ temp.load(fin);
+ temp.list(System.out);
+ props.putAll(temp);
+ }
+ catch (IOException ioe)
+ {
+ if (DEBUG)
+ debug("IO error reading " + propFile + ": " + ioe.getMessage());
+ }
+ catch (SecurityException se)
+ {
+ if (DEBUG)
+ debug("Security error reading " + propFile + ": "
+ + se.getMessage());
+ }
+ }
+
+ // 2. allow vm-specific override by allowing -D options in launcher
+ handleBooleanProperty(REPRODUCIBLE_PRNG);
+ handleBooleanProperty(CHECK_WEAK_KEYS);
+ handleBooleanProperty(DO_RSA_BLINDING);
+
+ // re-sync the 'known' properties
+ reproducible = new Boolean((String) props.get(REPRODUCIBLE_PRNG)).booleanValue();
+ checkForWeakKeys = new Boolean((String) props.get(CHECK_WEAK_KEYS)).booleanValue();
+ doRSABlinding = new Boolean((String) props.get(DO_RSA_BLINDING)).booleanValue();
+
+ // This does not change.
+ props.put(VERSION, Registry.VERSION_STRING);
+ }
+
+ private void handleBooleanProperty(final String name)
+ {
+ String s = null;
+ try
+ {
+ s = System.getProperty(name);
+ }
+ catch (SecurityException x)
+ {
+ if (DEBUG)
+ debug("SecurityManager forbids reading system properties. Ignored");
+ }
+ if (s != null)
+ {
+ s = s.trim().toLowerCase();
+ // we have to test for explicit "true" or "false". anything else may
+ // hide valid value set previously
+ if (s.equals(TRUE) || s.equals(FALSE))
+ {
+ if (DEBUG)
+ debug("Setting " + name + " to '" + s + "'");
+ props.put(name, s);
+ }
+ else
+ {
+ if (DEBUG)
+ debug("Invalid value for -D" + name + ": " + s + ". Ignored");
+ }
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/Registry.java b/libjava/classpath/gnu/java/security/Registry.java
new file mode 100644
index 0000000..efb54e7
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/Registry.java
@@ -0,0 +1,455 @@
+/* Registry.java --
+ Copyright (C) 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security;
+
+/**
+ * A placeholder for names and literals used throughout this
+ * library.
+ */
+public interface Registry
+{
+
+ // Constants
+ // -------------------------------------------------------------------------
+
+ /** The name of our Providers. */
+ String GNU_SECURITY = "GNU";
+ String GNU_CRYPTO = "GNU-CRYPTO";
+ String GNU_SASL = "GNU-SASL";
+
+ /** Our version number. */
+ String VERSION_STRING = "2.1.0";
+
+ // Names of properties to use in Maps when initialising primitives .........
+
+ // Symmetric block cipher algorithms and synonyms...........................
+
+ String ANUBIS_CIPHER = "anubis";
+
+ String BLOWFISH_CIPHER = "blowfish";
+
+ String DES_CIPHER = "des";
+
+ String KHAZAD_CIPHER = "khazad";
+
+ String RIJNDAEL_CIPHER = "rijndael";
+
+ String SERPENT_CIPHER = "serpent";
+
+ String SQUARE_CIPHER = "square";
+
+ String TRIPLEDES_CIPHER = "tripledes";
+
+ String TWOFISH_CIPHER = "twofish";
+
+ String CAST5_CIPHER = "cast5";
+
+ String NULL_CIPHER = "null";
+
+ /** AES is synonymous to Rijndael for 128-bit block size only. */
+ String AES_CIPHER = "aes";
+
+ /** TripleDES is also known as DESede. */
+ String DESEDE_CIPHER = "desede";
+
+ /** CAST5 is also known as CAST-128. */
+ String CAST128_CIPHER = "cast128";
+
+ String CAST_128_CIPHER = "cast-128";
+
+ // Message digest algorithms and synonyms...................................
+
+ String WHIRLPOOL_HASH = "whirlpool";
+
+ String RIPEMD128_HASH = "ripemd128";
+
+ String RIPEMD160_HASH = "ripemd160";
+
+ String SHA160_HASH = "sha-160";
+
+ String SHA256_HASH = "sha-256";
+
+ String SHA384_HASH = "sha-384";
+
+ String SHA512_HASH = "sha-512";
+
+ String TIGER_HASH = "tiger";
+
+ String HAVAL_HASH = "haval";
+
+ String MD5_HASH = "md5";
+
+ String MD4_HASH = "md4";
+
+ String MD2_HASH = "md2";
+
+ /** RIPEMD-128 is synonymous to RIPEMD128. */
+ String RIPEMD_128_HASH = "ripemd-128";
+
+ /** RIPEMD-160 is synonymous to RIPEMD160. */
+ String RIPEMD_160_HASH = "ripemd-160";
+
+ /** SHA-1 is synonymous to SHA-160. */
+ String SHA_1_HASH = "sha-1";
+
+ /** SHA1 is synonymous to SHA-160. */
+ String SHA1_HASH = "sha1";
+
+ /** SHA is synonymous to SHA-160. */
+ String SHA_HASH = "sha";
+
+ // Symmetric block cipher modes of operations...............................
+
+ /** Electronic CodeBook mode. */
+ String ECB_MODE = "ecb";
+
+ /** Counter (NIST) mode. */
+ String CTR_MODE = "ctr";
+
+ /** Integer Counter Mode (David McGrew). */
+ String ICM_MODE = "icm";
+
+ /** Output Feedback Mode (NIST). */
+ String OFB_MODE = "ofb";
+
+ /** Cipher block chaining mode (NIST). */
+ String CBC_MODE = "cbc";
+
+ /** Cipher feedback mode (NIST). */
+ String CFB_MODE = "cfb";
+
+ /** Authenticated-Encrypted mode. */
+ String EAX_MODE = "eax";
+
+ // Padding scheme names and synonyms........................................
+
+ /** PKCS#7 padding scheme. */
+ String PKCS7_PAD = "pkcs7";
+
+ /** Trailing Bit Complement padding scheme. */
+ String TBC_PAD = "tbc";
+
+ /** EME-PKCS1-v1_5 padding as described in section 7.2 in RFC-3447. */
+ String EME_PKCS1_V1_5_PAD = "eme-pkcs1-v1.5";
+
+ /** SSLv3 padding scheme. */
+ String SSL3_PAD = "ssl3";
+
+ /** TLSv1 padding scheme. */
+ String TLS1_PAD = "tls1";
+
+ // Pseudo-random number generators..........................................
+
+ /** (Apparently) RC4 keystream PRNG. */
+ String ARCFOUR_PRNG = "arcfour";
+
+ /** We use "rc4" as an alias for "arcfour". */
+ String RC4_PRNG = "rc4";
+
+ /** PRNG based on David McGrew's Integer Counter Mode. */
+ String ICM_PRNG = "icm";
+
+ /** PRNG based on a designated hash function. */
+ String MD_PRNG = "md";
+
+ /** PRNG based on UMAC's Key Derivation Function. */
+ String UMAC_PRNG = "umac-kdf";
+
+ /**
+ * PRNG based on PBKDF2 from PKCS #5 v.2. This is suffixed with the name
+ * of a MAC to be used as a PRF.
+ */
+ String PBKDF2_PRNG_PREFIX = "pbkdf2-";
+
+ /** The continuously-seeded pseudo-random number generator. */
+ String CSPRNG_PRNG = "csprng";
+
+ /** The Fortuna PRNG. */
+ String FORTUNA_PRNG = "fortuna";
+
+ /** The Fortuna generator PRNG. */
+ String FORTUNA_GENERATOR_PRNG = "fortuna-generator";
+
+ // Asymmetric keypair generators............................................
+
+ String DSS_KPG = "dss";
+
+ String RSA_KPG = "rsa";
+
+ String DH_KPG = "dh";
+
+ String SRP_KPG = "srp";
+
+ /** DSA is synonymous to DSS. */
+ String DSA_KPG = "dsa";
+
+ // Signature-with-appendix schemes..........................................
+
+ String DSS_SIG = "dss";
+
+ String RSA_SIG_PREFIX = "rsa-";
+
+ String RSA_PSS_ENCODING = "pss";
+
+ String RSA_PSS_SIG = RSA_SIG_PREFIX + RSA_PSS_ENCODING;
+
+ String RSA_PKCS1_V1_5_ENCODING = "pkcs1-v1.5";
+
+ String RSA_PKCS1_V1_5_SIG = RSA_SIG_PREFIX + RSA_PKCS1_V1_5_ENCODING;
+
+ /** DSA is synonymous to DSS. */
+ String DSA_SIG = "dsa";
+
+ // Key agreement protocols .................................................
+
+ String DH_KA = "dh";
+
+ String ELGAMAL_KA = "elgamal";
+
+ String SRP6_KA = "srp6";
+
+ String SRP_SASL_KA = "srp-sasl";
+
+ String SRP_TLS_KA = "srp-tls";
+
+ // Keyed-Hash Message Authentication Code ..................................
+
+ /** Name prefix of every HMAC implementation. */
+ String HMAC_NAME_PREFIX = "hmac-";
+
+ // Other MAC algorithms ....................................................
+
+ /** The One-key CBC MAC. */
+ String OMAC_PREFIX = "omac-";
+
+ /** Message Authentication Code using Universal Hashing (Ted Krovetz). */
+ String UHASH32 = "uhash32";
+
+ String UMAC32 = "umac32";
+
+ /** The Truncated Multi-Modular Hash Function -v1 (David McGrew). */
+ String TMMH16 = "tmmh16";
+
+ // String TMMH32 = "tmmh32";
+
+ // Format IDs used to identify how we externalise asymmetric keys ..........
+ // fully-qualified names of the supported codecs
+ String RAW_ENCODING = "gnu.crypto.raw.format";
+ String X509_ENCODING = "gnu.crypto.x509.format";
+ String PKCS8_ENCODING = "gnu.crypto.pkcs8.format";
+ String ASN1_ENCODING = "gnu.crypto.asn1.format";
+
+ // short names of the same. used by JCE adapters
+ String RAW_ENCODING_SHORT_NAME = "RAW";
+ String X509_ENCODING_SORT_NAME = "X.509";
+ String PKCS8_ENCODING_SHORT_NAME = "PKCS#8";
+ String ASN1_ENCODING_SHORT_NAME = "ASN.1";
+
+ // unique identifiers of the same
+ int RAW_ENCODING_ID = 1;
+ int X509_ENCODING_ID = 2;
+ int PKCS8_ENCODING_ID = 3;
+ int ASN1_ENCODING_ID = 4;
+
+ // OID strings used in encoding/decoding keys
+ String DSA_OID_STRING = "1.2.840.10040.4.1";
+ String RSA_OID_STRING = "1.2.840.113549.1.1.1";
+ String DH_OID_STRING = "1.2.840.10046.2.1";
+
+ // Magic bytes we generate/expect in externalised asymmetric keys ..........
+ // the four bytes represent G (0x47) for GNU, 1 (0x01) for Raw format,
+ // D (0x44) for DSS, R (0x52) for RSA, H (0x48) for Diffie-Hellman, or S
+ // (0x53) for SRP-6, and finally P (0x50) for Public, p (0x70) for private,
+ // or S (0x53) for signature.
+ byte[] MAGIC_RAW_DSS_PUBLIC_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x44,
+ 0x50 };
+
+ byte[] MAGIC_RAW_DSS_PRIVATE_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x44,
+ 0x70 };
+
+ byte[] MAGIC_RAW_DSS_SIGNATURE = new byte[] { 0x47, RAW_ENCODING_ID, 0x44,
+ 0x53 };
+
+ byte[] MAGIC_RAW_RSA_PUBLIC_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x52,
+ 0x50 };
+
+ byte[] MAGIC_RAW_RSA_PRIVATE_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x52,
+ 0x70 };
+
+ byte[] MAGIC_RAW_RSA_PSS_SIGNATURE = new byte[] { 0x47, RAW_ENCODING_ID,
+ 0x52, 0x53 };
+
+ byte[] MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE = new byte[] { 0x47, RAW_ENCODING_ID,
+ 0x52, 0x54 };
+
+ byte[] MAGIC_RAW_DH_PUBLIC_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x48,
+ 0x50 };
+
+ byte[] MAGIC_RAW_DH_PRIVATE_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x48,
+ 0x70 };
+
+ byte[] MAGIC_RAW_SRP_PUBLIC_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x53,
+ 0x50 };
+
+ byte[] MAGIC_RAW_SRP_PRIVATE_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x53,
+ 0x70 };
+
+ // SASL Property names .....................................................
+
+ String SASL_PREFIX = "gnu.crypto.sasl";
+
+ /** Name of username property. */
+ String SASL_USERNAME = SASL_PREFIX + ".username";
+
+ /** Name of password property. */
+ String SASL_PASSWORD = SASL_PREFIX + ".password";
+
+ /** Name of authentication information provider packages. */
+ String SASL_AUTH_INFO_PROVIDER_PKGS = SASL_PREFIX
+ + ".auth.info.provider.pkgs";
+
+ /** SASL authorization ID. */
+ String SASL_AUTHORISATION_ID = SASL_PREFIX + ".authorisation.ID";
+
+ /** SASL protocol. */
+ String SASL_PROTOCOL = SASL_PREFIX + ".protocol";
+
+ /** SASL Server name. */
+ String SASL_SERVER_NAME = SASL_PREFIX + ".server.name";
+
+ /** SASL Callback handler. */
+ String SASL_CALLBACK_HANDLER = SASL_PREFIX + ".callback.handler";
+
+ /** SASL channel binding. */
+ String SASL_CHANNEL_BINDING = SASL_PREFIX + ".channel.binding";
+
+ // SASL data element size limits ...........................................
+
+ /** The size limit, in bytes, of a SASL OS (Octet Sequence) element. */
+ int SASL_ONE_BYTE_MAX_LIMIT = 255;
+
+ /**
+ * The size limit, in bytes, of both a SASL MPI (Multi-Precision Integer)
+ * element and a SASL Text element.
+ */
+ int SASL_TWO_BYTE_MAX_LIMIT = 65535;
+
+ /** The size limit, in bytes, of a SASL EOS (Extended Octet Sequence) element. */
+ int SASL_FOUR_BYTE_MAX_LIMIT = 2147483383;
+
+ /** The size limit, in bytes, of a SASL Buffer. */
+ int SASL_BUFFER_MAX_LIMIT = 2147483643;
+
+ // Canonical names of SASL mechanisms ......................................
+
+ String SASL_ANONYMOUS_MECHANISM = "ANONYMOUS";
+
+ String SASL_CRAM_MD5_MECHANISM = "CRAM-MD5";
+
+ String SASL_PLAIN_MECHANISM = "PLAIN";
+
+ String SASL_SRP_MECHANISM = "SRP";
+
+ // Canonical names of Integrity Protection algorithms ......................
+
+ String SASL_HMAC_MD5_IALG = "HMACwithMD5";
+
+ String SASL_HMAC_SHA_IALG = "HMACwithSHA";
+
+ // Quality Of Protection string representations ............................
+
+ /** authentication only. */
+ String QOP_AUTH = "auth";
+
+ /** authentication plus integrity protection. */
+ String QOP_AUTH_INT = "auth-int";
+
+ /** authentication plus integrity and confidentiality protection. */
+ String QOP_AUTH_CONF = "auth-conf";
+
+ // SASL mechanism strength string representation ...........................
+
+ String STRENGTH_HIGH = "high";
+
+ String STRENGTH_MEDIUM = "medium";
+
+ String STRENGTH_LOW = "low";
+
+ // SASL Server Authentication requirement ..................................
+
+ /** Server must authenticate to the client. */
+ String SERVER_AUTH_TRUE = "true";
+
+ /** Server does not need to, or cannot, authenticate to the client. */
+ String SERVER_AUTH_FALSE = "false";
+
+ // SASL mechanism reuse capability .........................................
+
+ String REUSE_TRUE = "true";
+
+ String REUSE_FALSE = "false";
+
+ // Keyrings ...............................................................
+
+ byte[] GKR_MAGIC = new byte[] { 0x47, 0x4b, 0x52, 0x01 };
+
+ // Ring usage fields.
+ int GKR_PRIVATE_KEYS = 1 << 0;
+
+ int GKR_PUBLIC_CREDENTIALS = 1 << 1;
+
+ int GKR_CERTIFICATES = 1 << 2;
+
+ // HMac types.
+ int GKR_HMAC_MD5_128 = 0;
+
+ int GKR_HMAC_SHA_160 = 1;
+
+ int GKR_HMAC_MD5_96 = 2;
+
+ int GKR_HMAC_SHA_96 = 3;
+
+ // Cipher types.
+ int GKR_CIPHER_AES_128_OFB = 0;
+
+ int GKR_CIPHER_AES_128_CBC = 1;
+
+ // Methods
+ // -------------------------------------------------------------------------
+}
diff --git a/libjava/classpath/gnu/java/security/der/DERValue.java b/libjava/classpath/gnu/java/security/der/DERValue.java
index 9a597d7..d98ce78 100644
--- a/libjava/classpath/gnu/java/security/der/DERValue.java
+++ b/libjava/classpath/gnu/java/security/der/DERValue.java
@@ -38,6 +38,8 @@ exception statement from your version. */
package gnu.java.security.der;
+import gnu.java.security.x509.Util;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -108,7 +110,9 @@ public class DERValue implements DER
}
catch (IOException ioe)
{
- encoded = new byte[0];
+ IllegalArgumentException iae = new IllegalArgumentException ();
+ iae.initCause (ioe);
+ throw iae;
}
}
return length;
@@ -138,7 +142,9 @@ public class DERValue implements DER
}
catch (IOException ioe)
{
- encoded = new byte[0];
+ IllegalArgumentException iae = new IllegalArgumentException ();
+ iae.initCause (ioe);
+ throw iae;
}
}
return (byte[]) encoded.clone();
@@ -156,7 +162,9 @@ public class DERValue implements DER
}
catch (IOException ioe)
{
- encoded = new byte[0];
+ IllegalArgumentException iae = new IllegalArgumentException ();
+ iae.initCause (ioe);
+ throw iae;
}
}
return encoded.length;
@@ -164,7 +172,18 @@ public class DERValue implements DER
public String toString()
{
- return "DERValue [ tag=" + tag + ", class=" + tagClass + ", constructed="
- + constructed + ", value=" + value + " ]";
+ String start = "DERValue ( [";
+ if (tagClass == DER.UNIVERSAL)
+ start = start + "UNIVERSAL ";
+ else if (tagClass == DER.PRIVATE)
+ start = start + "PRIVATE ";
+ else if (tagClass == DER.APPLICATION)
+ start = start + "APPLICATION ";
+ start = start + tag + "] constructed=" + constructed + ", value=";
+ if (constructed)
+ start = start + "\n" + Util.hexDump(getEncoded(), "\t");
+ else
+ start = start + value;
+ return start + " )";
}
}
diff --git a/libjava/classpath/gnu/java/security/der/DERWriter.java b/libjava/classpath/gnu/java/security/der/DERWriter.java
index 78524fc..0c26336 100644
--- a/libjava/classpath/gnu/java/security/der/DERWriter.java
+++ b/libjava/classpath/gnu/java/security/der/DERWriter.java
@@ -84,6 +84,12 @@ public class DERWriter implements DER
public static int write(OutputStream out, DERValue object)
throws IOException
{
+ if (DER.CONSTRUCTED_VALUE.equals (object.getValue ()))
+ {
+ out.write (object.getEncoded ());
+ return object.getLength ();
+ }
+
out.write(object.getExternalTag());
Object value = object.getValue();
if (value == null)
@@ -216,10 +222,10 @@ public class DERWriter implements DER
throws IOException
{
byte[] buf = bs.getShiftedByteArray();
- out.write(buf.length + 1);
+ writeLength(out, buf.length + 1);
out.write(bs.getIgnoredBits());
out.write(buf);
- return buf.length;
+ return buf.length + 1;
}
private static int writeString(OutputStream out, int tag, String str)
diff --git a/libjava/classpath/gnu/java/security/hash/BaseHash.java b/libjava/classpath/gnu/java/security/hash/BaseHash.java
new file mode 100644
index 0000000..720b835
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/hash/BaseHash.java
@@ -0,0 +1,206 @@
+/* BaseHash.java --
+ Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.hash;
+
+/**
+ * A base abstract class to facilitate hash implementations.
+ */ +public abstract class BaseHash implements IMessageDigest +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + /** The canonical name prefix of the hash. */ + protected String name; + + /** The hash (output) size in bytes. */ + protected int hashSize; + + /** The hash (inner) block size in bytes. */ + protected int blockSize; + + /** Number of bytes processed so far. */ + protected long count; + + /** Temporary input buffer. */ + protected byte[] buffer; + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** + *Trivial constructor for use by concrete subclasses.
+ * + * @param name the canonical name prefix of this instance. + * @param hashSize the block size of the output in bytes. + * @param blockSize the block size of the internal transform. + */ + protected BaseHash(String name, int hashSize, int blockSize) + { + super(); + + this.name = name; + this.hashSize = hashSize; + this.blockSize = blockSize; + this.buffer = new byte[blockSize]; + + resetContext(); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // IMessageDigest interface implementation --------------------------------- + + public String name() + { + return name; + } + + public int hashSize() + { + return hashSize; + } + + public int blockSize() + { + return blockSize; + } + + public void update(byte b) + { + // compute number of bytes still unhashed; ie. present in buffer + int i = (int) (count % blockSize); + count++; + buffer[i] = b; + if (i == (blockSize - 1)) + { + transform(buffer, 0); + } + } + + public void update(byte[] b) + { + update(b, 0, b.length); + } + + public void update(byte[] b, int offset, int len) + { + int n = (int) (count % blockSize); + count += len; + int partLen = blockSize - n; + int i = 0; + + if (len >= partLen) + { + System.arraycopy(b, offset, buffer, n, partLen); + transform(buffer, 0); + for (i = partLen; i + blockSize - 1 < len; i += blockSize) + { + transform(b, offset + i); + } + n = 0; + } + + if (i < len) + { + System.arraycopy(b, offset + i, buffer, n, len - i); + } + } + + public byte[] digest() + { + byte[] tail = padBuffer(); // pad remaining bytes in buffer + update(tail, 0, tail.length); // last transform of a message + byte[] result = getResult(); // make a result out of context + + reset(); // reset this instance for future re-use + + return result; + } + + public void reset() + { // reset this instance for future re-use + count = 0L; + for (int i = 0; i < blockSize;) + { + buffer[i++] = 0; + } + + resetContext(); + } + + // methods to be implemented by concrete subclasses ------------------------ + + public abstract Object clone(); + + public abstract boolean selfTest(); + + /** + *Returns the byte array to use as padding before completing a hash + * operation.
+ * + * @return the bytes to pad the remaining bytes in the buffer before + * completing a hash operation. + */ + protected abstract byte[] padBuffer(); + + /** + *Constructs the result from the contents of the current context.
+ * + * @return the output of the completed hash operation. + */ + protected abstract byte[] getResult(); + + /** Resets the instance for future re-use. */ + protected abstract void resetContext(); + + /** + *The block digest transformation per se.
+ * + * @param in the blockSize long block, as an array of bytes to digest. + * @param offset the index where the data to digest is located within the + * input buffer. + */ + protected abstract void transform(byte[] in, int offset); +} diff --git a/libjava/classpath/gnu/java/security/hash/HashFactory.java b/libjava/classpath/gnu/java/security/hash/HashFactory.java new file mode 100644 index 0000000..e520921 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/HashFactory.java @@ -0,0 +1,178 @@ +/* HashFactory.java -- + Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + *A Factory to instantiate message digest algorithm instances.
+ */ +public class HashFactory +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** Trivial constructor to enforce Singleton pattern. */ + private HashFactory() + { + super(); + } + + // Class methods + // ------------------------------------------------------------------------- + + /** + *Return an instance of a hash algorithm given its name.
+ * + * @param name the name of the hash algorithm. + * @return an instance of the hash algorithm, or null if none found. + * @exception InternalError if the implementation does not pass its self- + * test. + */ + public static IMessageDigest getInstance(String name) + { + if (name == null) + { + return null; + } + + name = name.trim(); + IMessageDigest result = null; + if (name.equalsIgnoreCase(Registry.WHIRLPOOL_HASH)) + { + result = new Whirlpool(); + } + else if (name.equalsIgnoreCase(Registry.RIPEMD128_HASH) + || name.equalsIgnoreCase(Registry.RIPEMD_128_HASH)) + { + result = new RipeMD128(); + } + else if (name.equalsIgnoreCase(Registry.RIPEMD160_HASH) + || name.equalsIgnoreCase(Registry.RIPEMD_160_HASH)) + { + result = new RipeMD160(); + } + else if (name.equalsIgnoreCase(Registry.SHA160_HASH) + || name.equalsIgnoreCase(Registry.SHA_1_HASH) + || name.equalsIgnoreCase(Registry.SHA1_HASH) + || name.equalsIgnoreCase(Registry.SHA_HASH)) + { + result = new Sha160(); + } + else if (name.equalsIgnoreCase(Registry.SHA256_HASH)) + { + result = new Sha256(); + } + else if (name.equalsIgnoreCase(Registry.SHA384_HASH)) + { + result = new Sha384(); + } + else if (name.equalsIgnoreCase(Registry.SHA512_HASH)) + { + result = new Sha512(); + } + else if (name.equalsIgnoreCase(Registry.TIGER_HASH)) + { + result = new Tiger(); + } + else if (name.equalsIgnoreCase(Registry.HAVAL_HASH)) + { + result = new Haval(); + } + else if (name.equalsIgnoreCase(Registry.MD5_HASH)) + { + result = new MD5(); + } + else if (name.equalsIgnoreCase(Registry.MD4_HASH)) + { + result = new MD4(); + } + else if (name.equalsIgnoreCase(Registry.MD2_HASH)) + { + result = new MD2(); + } + else if (name.equalsIgnoreCase(Registry.HAVAL_HASH)) + { + result = new Haval(); + } + + if (result != null && !result.selfTest()) + { + throw new InternalError(result.name()); + } + + return result; + } + + /** + *Returns a {@link Set} of names of hash algorithms supported by this + * Factory.
+ * + * @return a {@link Set} of hash names (Strings). + */ + public static final Set getNames() + { + HashSet hs = new HashSet(); + hs.add(Registry.WHIRLPOOL_HASH); + hs.add(Registry.RIPEMD128_HASH); + hs.add(Registry.RIPEMD160_HASH); + hs.add(Registry.SHA160_HASH); + hs.add(Registry.SHA256_HASH); + hs.add(Registry.SHA384_HASH); + hs.add(Registry.SHA512_HASH); + hs.add(Registry.TIGER_HASH); + hs.add(Registry.HAVAL_HASH); + hs.add(Registry.MD5_HASH); + hs.add(Registry.MD4_HASH); + hs.add(Registry.MD2_HASH); + + return Collections.unmodifiableSet(hs); + } + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/hash/Haval.java b/libjava/classpath/gnu/java/security/hash/Haval.java new file mode 100644 index 0000000..f9f3282 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/Haval.java @@ -0,0 +1,759 @@ +/* Haval.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *The HAVAL message-digest algorithm is a variable output length, + * with variable number of rounds. By default, this implementation allows + * HAVAL to be used as a drop-in replacement for MD5.
+ * + *References:
+ * + *3
+ * .. 5
. The default is 3
.
+ */
+ private int rounds = HAVAL_3_ROUND;
+
+ /** 128-bit interim result. */
+ private int h0, h1, h2, h3, h4, h5, h6, h7;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Calls the constructor with two argument using {@link #HAVAL_128_BIT} as
+ * the value for the output size (i.e. 128
bits, and
+ * {@link #HAVAL_3_ROUND} for the value of number of rounds.
Calls the constructor with two arguments using the designated output + * size, and {@link #HAVAL_3_ROUND} for the value of number of rounds.
+ * + * @param size the output size in bytes of this instance. + * @throws IllegalArgumentException if the designated output size is invalid. + * @see #HAVAL_128_BIT + * @see #HAVAL_160_BIT + * @see #HAVAL_192_BIT + * @see #HAVAL_224_BIT + * @see #HAVAL_256_BIT + */ + public Haval(int size) + { + this(size, HAVAL_3_ROUND); + } + + /** + *Constructs a Haval
instance with the designated output
+ * size (in bytes). Valid output size
values are 16
,
+ * 20
, 24
, 28
and 32
.
+ * Valid values for rounds
are in the range 3..5
+ * inclusive.
Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private Haval(Haval md) + { + this(md.hashSize, md.rounds); + + this.h0 = md.h0; + this.h1 = md.h1; + this.h2 = md.h2; + this.h3 = md.h3; + this.h4 = md.h4; + this.h5 = md.h5; + this.h6 = md.h6; + this.h7 = md.h7; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Constructor(s) + // ------------------------------------------------------------------------- + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new Haval(this); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected synchronized void transform(byte[] in, int i) + { + int X0 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X1 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X2 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X3 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X4 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X5 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X6 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X7 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X8 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X9 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X10 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X11 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X12 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X13 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X14 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X15 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X16 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X17 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X18 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X19 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X20 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X21 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X22 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X23 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X24 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X25 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X26 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X27 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X28 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X29 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X30 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + int X31 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | (in[i++] & 0xFF) << 24; + + int t0 = h0, t1 = h1, t2 = h2, t3 = h3, t4 = h4, t5 = h5, t6 = h6, t7 = h7; + + // Pass 1 + t7 = FF1(t7, t6, t5, t4, t3, t2, t1, t0, X0); + t6 = FF1(t6, t5, t4, t3, t2, t1, t0, t7, X1); + t5 = FF1(t5, t4, t3, t2, t1, t0, t7, t6, X2); + t4 = FF1(t4, t3, t2, t1, t0, t7, t6, t5, X3); + t3 = FF1(t3, t2, t1, t0, t7, t6, t5, t4, X4); + t2 = FF1(t2, t1, t0, t7, t6, t5, t4, t3, X5); + t1 = FF1(t1, t0, t7, t6, t5, t4, t3, t2, X6); + t0 = FF1(t0, t7, t6, t5, t4, t3, t2, t1, X7); + + t7 = FF1(t7, t6, t5, t4, t3, t2, t1, t0, X8); + t6 = FF1(t6, t5, t4, t3, t2, t1, t0, t7, X9); + t5 = FF1(t5, t4, t3, t2, t1, t0, t7, t6, X10); + t4 = FF1(t4, t3, t2, t1, t0, t7, t6, t5, X11); + t3 = FF1(t3, t2, t1, t0, t7, t6, t5, t4, X12); + t2 = FF1(t2, t1, t0, t7, t6, t5, t4, t3, X13); + t1 = FF1(t1, t0, t7, t6, t5, t4, t3, t2, X14); + t0 = FF1(t0, t7, t6, t5, t4, t3, t2, t1, X15); + + t7 = FF1(t7, t6, t5, t4, t3, t2, t1, t0, X16); + t6 = FF1(t6, t5, t4, t3, t2, t1, t0, t7, X17); + t5 = FF1(t5, t4, t3, t2, t1, t0, t7, t6, X18); + t4 = FF1(t4, t3, t2, t1, t0, t7, t6, t5, X19); + t3 = FF1(t3, t2, t1, t0, t7, t6, t5, t4, X20); + t2 = FF1(t2, t1, t0, t7, t6, t5, t4, t3, X21); + t1 = FF1(t1, t0, t7, t6, t5, t4, t3, t2, X22); + t0 = FF1(t0, t7, t6, t5, t4, t3, t2, t1, X23); + + t7 = FF1(t7, t6, t5, t4, t3, t2, t1, t0, X24); + t6 = FF1(t6, t5, t4, t3, t2, t1, t0, t7, X25); + t5 = FF1(t5, t4, t3, t2, t1, t0, t7, t6, X26); + t4 = FF1(t4, t3, t2, t1, t0, t7, t6, t5, X27); + t3 = FF1(t3, t2, t1, t0, t7, t6, t5, t4, X28); + t2 = FF1(t2, t1, t0, t7, t6, t5, t4, t3, X29); + t1 = FF1(t1, t0, t7, t6, t5, t4, t3, t2, X30); + t0 = FF1(t0, t7, t6, t5, t4, t3, t2, t1, X31); + + // Pass 2 + t7 = FF2(t7, t6, t5, t4, t3, t2, t1, t0, X5, 0x452821E6); + t6 = FF2(t6, t5, t4, t3, t2, t1, t0, t7, X14, 0x38D01377); + t5 = FF2(t5, t4, t3, t2, t1, t0, t7, t6, X26, 0xBE5466CF); + t4 = FF2(t4, t3, t2, t1, t0, t7, t6, t5, X18, 0x34E90C6C); + t3 = FF2(t3, t2, t1, t0, t7, t6, t5, t4, X11, 0xC0AC29B7); + t2 = FF2(t2, t1, t0, t7, t6, t5, t4, t3, X28, 0xC97C50DD); + t1 = FF2(t1, t0, t7, t6, t5, t4, t3, t2, X7, 0x3F84D5B5); + t0 = FF2(t0, t7, t6, t5, t4, t3, t2, t1, X16, 0xB5470917); + + t7 = FF2(t7, t6, t5, t4, t3, t2, t1, t0, X0, 0x9216D5D9); + t6 = FF2(t6, t5, t4, t3, t2, t1, t0, t7, X23, 0x8979FB1B); + t5 = FF2(t5, t4, t3, t2, t1, t0, t7, t6, X20, 0xD1310BA6); + t4 = FF2(t4, t3, t2, t1, t0, t7, t6, t5, X22, 0x98DFB5AC); + t3 = FF2(t3, t2, t1, t0, t7, t6, t5, t4, X1, 0x2FFD72DB); + t2 = FF2(t2, t1, t0, t7, t6, t5, t4, t3, X10, 0xD01ADFB7); + t1 = FF2(t1, t0, t7, t6, t5, t4, t3, t2, X4, 0xB8E1AFED); + t0 = FF2(t0, t7, t6, t5, t4, t3, t2, t1, X8, 0x6A267E96); + + t7 = FF2(t7, t6, t5, t4, t3, t2, t1, t0, X30, 0xBA7C9045); + t6 = FF2(t6, t5, t4, t3, t2, t1, t0, t7, X3, 0xF12C7F99); + t5 = FF2(t5, t4, t3, t2, t1, t0, t7, t6, X21, 0x24A19947); + t4 = FF2(t4, t3, t2, t1, t0, t7, t6, t5, X9, 0xB3916CF7); + t3 = FF2(t3, t2, t1, t0, t7, t6, t5, t4, X17, 0x0801F2E2); + t2 = FF2(t2, t1, t0, t7, t6, t5, t4, t3, X24, 0x858EFC16); + t1 = FF2(t1, t0, t7, t6, t5, t4, t3, t2, X29, 0x636920D8); + t0 = FF2(t0, t7, t6, t5, t4, t3, t2, t1, X6, 0x71574E69); + + t7 = FF2(t7, t6, t5, t4, t3, t2, t1, t0, X19, 0xA458FEA3); + t6 = FF2(t6, t5, t4, t3, t2, t1, t0, t7, X12, 0xF4933D7E); + t5 = FF2(t5, t4, t3, t2, t1, t0, t7, t6, X15, 0x0D95748F); + t4 = FF2(t4, t3, t2, t1, t0, t7, t6, t5, X13, 0x728EB658); + t3 = FF2(t3, t2, t1, t0, t7, t6, t5, t4, X2, 0x718BCD58); + t2 = FF2(t2, t1, t0, t7, t6, t5, t4, t3, X25, 0x82154AEE); + t1 = FF2(t1, t0, t7, t6, t5, t4, t3, t2, X31, 0x7B54A41D); + t0 = FF2(t0, t7, t6, t5, t4, t3, t2, t1, X27, 0xC25A59B5); + + // Pass 3 + t7 = FF3(t7, t6, t5, t4, t3, t2, t1, t0, X19, 0x9C30D539); + t6 = FF3(t6, t5, t4, t3, t2, t1, t0, t7, X9, 0x2AF26013); + t5 = FF3(t5, t4, t3, t2, t1, t0, t7, t6, X4, 0xC5D1B023); + t4 = FF3(t4, t3, t2, t1, t0, t7, t6, t5, X20, 0x286085F0); + t3 = FF3(t3, t2, t1, t0, t7, t6, t5, t4, X28, 0xCA417918); + t2 = FF3(t2, t1, t0, t7, t6, t5, t4, t3, X17, 0xB8DB38EF); + t1 = FF3(t1, t0, t7, t6, t5, t4, t3, t2, X8, 0x8E79DCB0); + t0 = FF3(t0, t7, t6, t5, t4, t3, t2, t1, X22, 0x603A180E); + + t7 = FF3(t7, t6, t5, t4, t3, t2, t1, t0, X29, 0x6C9E0E8B); + t6 = FF3(t6, t5, t4, t3, t2, t1, t0, t7, X14, 0xB01E8A3E); + t5 = FF3(t5, t4, t3, t2, t1, t0, t7, t6, X25, 0xD71577C1); + t4 = FF3(t4, t3, t2, t1, t0, t7, t6, t5, X12, 0xBD314B27); + t3 = FF3(t3, t2, t1, t0, t7, t6, t5, t4, X24, 0x78AF2FDA); + t2 = FF3(t2, t1, t0, t7, t6, t5, t4, t3, X30, 0x55605C60); + t1 = FF3(t1, t0, t7, t6, t5, t4, t3, t2, X16, 0xE65525F3); + t0 = FF3(t0, t7, t6, t5, t4, t3, t2, t1, X26, 0xAA55AB94); + + t7 = FF3(t7, t6, t5, t4, t3, t2, t1, t0, X31, 0x57489862); + t6 = FF3(t6, t5, t4, t3, t2, t1, t0, t7, X15, 0x63E81440); + t5 = FF3(t5, t4, t3, t2, t1, t0, t7, t6, X7, 0x55CA396A); + t4 = FF3(t4, t3, t2, t1, t0, t7, t6, t5, X3, 0x2AAB10B6); + t3 = FF3(t3, t2, t1, t0, t7, t6, t5, t4, X1, 0xB4CC5C34); + t2 = FF3(t2, t1, t0, t7, t6, t5, t4, t3, X0, 0x1141E8CE); + t1 = FF3(t1, t0, t7, t6, t5, t4, t3, t2, X18, 0xA15486AF); + t0 = FF3(t0, t7, t6, t5, t4, t3, t2, t1, X27, 0x7C72E993); + + t7 = FF3(t7, t6, t5, t4, t3, t2, t1, t0, X13, 0xB3EE1411); + t6 = FF3(t6, t5, t4, t3, t2, t1, t0, t7, X6, 0x636FBC2A); + t5 = FF3(t5, t4, t3, t2, t1, t0, t7, t6, X21, 0x2BA9C55D); + t4 = FF3(t4, t3, t2, t1, t0, t7, t6, t5, X10, 0x741831F6); + t3 = FF3(t3, t2, t1, t0, t7, t6, t5, t4, X23, 0xCE5C3E16); + t2 = FF3(t2, t1, t0, t7, t6, t5, t4, t3, X11, 0x9B87931E); + t1 = FF3(t1, t0, t7, t6, t5, t4, t3, t2, X5, 0xAFD6BA33); + t0 = FF3(t0, t7, t6, t5, t4, t3, t2, t1, X2, 0x6C24CF5C); + + if (rounds >= 4) + { + t7 = FF4(t7, t6, t5, t4, t3, t2, t1, t0, X24, 0x7A325381); + t6 = FF4(t6, t5, t4, t3, t2, t1, t0, t7, X4, 0x28958677); + t5 = FF4(t5, t4, t3, t2, t1, t0, t7, t6, X0, 0x3B8F4898); + t4 = FF4(t4, t3, t2, t1, t0, t7, t6, t5, X14, 0x6B4BB9AF); + t3 = FF4(t3, t2, t1, t0, t7, t6, t5, t4, X2, 0xC4BFE81B); + t2 = FF4(t2, t1, t0, t7, t6, t5, t4, t3, X7, 0x66282193); + t1 = FF4(t1, t0, t7, t6, t5, t4, t3, t2, X28, 0x61D809CC); + t0 = FF4(t0, t7, t6, t5, t4, t3, t2, t1, X23, 0xFB21A991); + t7 = FF4(t7, t6, t5, t4, t3, t2, t1, t0, X26, 0x487CAC60); + t6 = FF4(t6, t5, t4, t3, t2, t1, t0, t7, X6, 0x5DEC8032); + t5 = FF4(t5, t4, t3, t2, t1, t0, t7, t6, X30, 0xEF845D5D); + t4 = FF4(t4, t3, t2, t1, t0, t7, t6, t5, X20, 0xE98575B1); + t3 = FF4(t3, t2, t1, t0, t7, t6, t5, t4, X18, 0xDC262302); + t2 = FF4(t2, t1, t0, t7, t6, t5, t4, t3, X25, 0xEB651B88); + t1 = FF4(t1, t0, t7, t6, t5, t4, t3, t2, X19, 0x23893E81); + t0 = FF4(t0, t7, t6, t5, t4, t3, t2, t1, X3, 0xD396ACC5); + + t7 = FF4(t7, t6, t5, t4, t3, t2, t1, t0, X22, 0x0F6D6FF3); + t6 = FF4(t6, t5, t4, t3, t2, t1, t0, t7, X11, 0x83F44239); + t5 = FF4(t5, t4, t3, t2, t1, t0, t7, t6, X31, 0x2E0B4482); + t4 = FF4(t4, t3, t2, t1, t0, t7, t6, t5, X21, 0xA4842004); + t3 = FF4(t3, t2, t1, t0, t7, t6, t5, t4, X8, 0x69C8F04A); + t2 = FF4(t2, t1, t0, t7, t6, t5, t4, t3, X27, 0x9E1F9B5E); + t1 = FF4(t1, t0, t7, t6, t5, t4, t3, t2, X12, 0x21C66842); + t0 = FF4(t0, t7, t6, t5, t4, t3, t2, t1, X9, 0xF6E96C9A); + t7 = FF4(t7, t6, t5, t4, t3, t2, t1, t0, X1, 0x670C9C61); + t6 = FF4(t6, t5, t4, t3, t2, t1, t0, t7, X29, 0xABD388F0); + t5 = FF4(t5, t4, t3, t2, t1, t0, t7, t6, X5, 0x6A51A0D2); + t4 = FF4(t4, t3, t2, t1, t0, t7, t6, t5, X15, 0xD8542F68); + t3 = FF4(t3, t2, t1, t0, t7, t6, t5, t4, X17, 0x960FA728); + t2 = FF4(t2, t1, t0, t7, t6, t5, t4, t3, X10, 0xAB5133A3); + t1 = FF4(t1, t0, t7, t6, t5, t4, t3, t2, X16, 0x6EEF0B6C); + t0 = FF4(t0, t7, t6, t5, t4, t3, t2, t1, X13, 0x137A3BE4); + + if (rounds == 5) + { + t7 = FF5(t7, t6, t5, t4, t3, t2, t1, t0, X27, 0xBA3BF050); + t6 = FF5(t6, t5, t4, t3, t2, t1, t0, t7, X3, 0x7EFB2A98); + t5 = FF5(t5, t4, t3, t2, t1, t0, t7, t6, X21, 0xA1F1651D); + t4 = FF5(t4, t3, t2, t1, t0, t7, t6, t5, X26, 0x39AF0176); + t3 = FF5(t3, t2, t1, t0, t7, t6, t5, t4, X17, 0x66CA593E); + t2 = FF5(t2, t1, t0, t7, t6, t5, t4, t3, X11, 0x82430E88); + t1 = FF5(t1, t0, t7, t6, t5, t4, t3, t2, X20, 0x8CEE8619); + t0 = FF5(t0, t7, t6, t5, t4, t3, t2, t1, X29, 0x456F9FB4); + + t7 = FF5(t7, t6, t5, t4, t3, t2, t1, t0, X19, 0x7D84A5C3); + t6 = FF5(t6, t5, t4, t3, t2, t1, t0, t7, X0, 0x3B8B5EBE); + t5 = FF5(t5, t4, t3, t2, t1, t0, t7, t6, X12, 0xE06F75D8); + t4 = FF5(t4, t3, t2, t1, t0, t7, t6, t5, X7, 0x85C12073); + t3 = FF5(t3, t2, t1, t0, t7, t6, t5, t4, X13, 0x401A449F); + t2 = FF5(t2, t1, t0, t7, t6, t5, t4, t3, X8, 0x56C16AA6); + t1 = FF5(t1, t0, t7, t6, t5, t4, t3, t2, X31, 0x4ED3AA62); + t0 = FF5(t0, t7, t6, t5, t4, t3, t2, t1, X10, 0x363F7706); + + t7 = FF5(t7, t6, t5, t4, t3, t2, t1, t0, X5, 0x1BFEDF72); + t6 = FF5(t6, t5, t4, t3, t2, t1, t0, t7, X9, 0x429B023D); + t5 = FF5(t5, t4, t3, t2, t1, t0, t7, t6, X14, 0x37D0D724); + t4 = FF5(t4, t3, t2, t1, t0, t7, t6, t5, X30, 0xD00A1248); + t3 = FF5(t3, t2, t1, t0, t7, t6, t5, t4, X18, 0xDB0FEAD3); + t2 = FF5(t2, t1, t0, t7, t6, t5, t4, t3, X6, 0x49F1C09B); + t1 = FF5(t1, t0, t7, t6, t5, t4, t3, t2, X28, 0x075372C9); + t0 = FF5(t0, t7, t6, t5, t4, t3, t2, t1, X24, 0x80991B7B); + + t7 = FF5(t7, t6, t5, t4, t3, t2, t1, t0, X2, 0x25D479D8); + t6 = FF5(t6, t5, t4, t3, t2, t1, t0, t7, X23, 0xF6E8DEF7); + t5 = FF5(t5, t4, t3, t2, t1, t0, t7, t6, X16, 0xE3FE501A); + t4 = FF5(t4, t3, t2, t1, t0, t7, t6, t5, X22, 0xB6794C3B); + t3 = FF5(t3, t2, t1, t0, t7, t6, t5, t4, X4, 0x976CE0BD); + t2 = FF5(t2, t1, t0, t7, t6, t5, t4, t3, X1, 0x04C006BA); + t1 = FF5(t1, t0, t7, t6, t5, t4, t3, t2, X25, 0xC1A94FB6); + t0 = FF5(t0, t7, t6, t5, t4, t3, t2, t1, X15, 0x409F60C4); + } + } + + h7 += t7; + h6 += t6; + h5 += t5; + h4 += t4; + h3 += t3; + h2 += t2; + h1 += t1; + h0 += t0; + } + + protected byte[] padBuffer() + { + // pad out to 118 mod 128. other 10 bytes have special use. + int n = (int) (count % BLOCK_SIZE); + int padding = (n < 118) ? (118 - n) : (246 - n); + byte[] result = new byte[padding + 10]; + result[0] = (byte) 0x01; + + // save the version number (LSB 3), the number of rounds (3 bits in the + // middle), the fingerprint length (MSB 2 bits and next byte) and the + // number of bits in the unpadded message. + int bl = hashSize * 8; + result[padding++] = (byte) (((bl & 0x03) << 6) | ((rounds & 0x07) << 3) | (HAVAL_VERSION & 0x07)); + result[padding++] = (byte) (bl >>> 2); + + // save number of bits, casting the long to an array of 8 bytes + long bits = count << 3; + result[padding++] = (byte) bits; + result[padding++] = (byte) (bits >>> 8); + result[padding++] = (byte) (bits >>> 16); + result[padding++] = (byte) (bits >>> 24); + result[padding++] = (byte) (bits >>> 32); + result[padding++] = (byte) (bits >>> 40); + result[padding++] = (byte) (bits >>> 48); + result[padding] = (byte) (bits >>> 56); + + return result; + } + + protected byte[] getResult() + { + tailorDigestBits(); // tailor context for the designated output size + // cast enough top context values into an array of hashSize bytes + byte[] result = new byte[hashSize]; + if (hashSize >= HAVAL_256_BIT) + { + result[31] = (byte) (h7 >>> 24); + result[30] = (byte) (h7 >>> 16); + result[29] = (byte) (h7 >>> 8); + result[28] = (byte) h7; + } + if (hashSize >= HAVAL_224_BIT) + { + result[27] = (byte) (h6 >>> 24); + result[26] = (byte) (h6 >>> 16); + result[25] = (byte) (h6 >>> 8); + result[24] = (byte) h6; + } + if (hashSize >= HAVAL_192_BIT) + { + result[23] = (byte) (h5 >>> 24); + result[22] = (byte) (h5 >>> 16); + result[21] = (byte) (h5 >>> 8); + result[20] = (byte) h5; + } + if (hashSize >= HAVAL_160_BIT) + { + result[19] = (byte) (h4 >>> 24); + result[18] = (byte) (h4 >>> 16); + result[17] = (byte) (h4 >>> 8); + result[16] = (byte) h4; + } + result[15] = (byte) (h3 >>> 24); + result[14] = (byte) (h3 >>> 16); + result[13] = (byte) (h3 >>> 8); + result[12] = (byte) h3; + result[11] = (byte) (h2 >>> 24); + result[10] = (byte) (h2 >>> 16); + result[9] = (byte) (h2 >>> 8); + result[8] = (byte) h2; + result[7] = (byte) (h1 >>> 24); + result[6] = (byte) (h1 >>> 16); + result[5] = (byte) (h1 >>> 8); + result[4] = (byte) h1; + result[3] = (byte) (h0 >>> 24); + result[2] = (byte) (h0 >>> 16); + result[1] = (byte) (h0 >>> 8); + result[0] = (byte) h0; + + return result; + } + + protected void resetContext() + { + h0 = 0x243F6A88; + h1 = 0x85A308D3; + h2 = 0x13198A2E; + h3 = 0x03707344; + h4 = 0xA4093822; + h5 = 0x299F31D0; + h6 = 0x082EFA98; + h7 = 0xEC4E6C89; + } + + public boolean selfTest() + { + if (valid == null) + { + valid = new Boolean(DIGEST0.equals(Util.toString(new Haval().digest()))); + } + return valid.booleanValue(); + } + + // helper methods ---------------------------------------------------------- + + /** Tailors the last output. */ + private void tailorDigestBits() + { + int t; + switch (hashSize) + { + case HAVAL_128_BIT: + t = (h7 & 0x000000FF) | (h6 & 0xFF000000) | (h5 & 0x00FF0000) + | (h4 & 0x0000FF00); + h0 += t >>> 8 | t << 24; + t = (h7 & 0x0000FF00) | (h6 & 0x000000FF) | (h5 & 0xFF000000) + | (h4 & 0x00FF0000); + h1 += t >>> 16 | t << 16; + t = (h7 & 0x00FF0000) | (h6 & 0x0000FF00) | (h5 & 0x000000FF) + | (h4 & 0xFF000000); + h2 += t >>> 24 | t << 8; + t = (h7 & 0xFF000000) | (h6 & 0x00FF0000) | (h5 & 0x0000FF00) + | (h4 & 0x000000FF); + h3 += t; + break; + case HAVAL_160_BIT: + t = (h7 & 0x3F) | (h6 & (0x7F << 25)) | (h5 & (0x3F << 19)); + h0 += t >>> 19 | t << 13; + t = (h7 & (0x3F << 6)) | (h6 & 0x3F) | (h5 & (0x7F << 25)); + h1 += t >>> 25 | t << 7; + t = (h7 & (0x7F << 12)) | (h6 & (0x3F << 6)) | (h5 & 0x3F); + h2 += t; + t = (h7 & (0x3F << 19)) | (h6 & (0x7F << 12)) | (h5 & (0x3F << 6)); + h3 += (t >>> 6); + t = (h7 & (0x7F << 25)) | (h6 & (0x3F << 19)) | (h5 & (0x7F << 12)); + h4 += (t >>> 12); + break; + case HAVAL_192_BIT: + t = (h7 & 0x1F) | (h6 & (0x3F << 26)); + h0 += t >>> 26 | t << 6; + t = (h7 & (0x1F << 5)) | (h6 & 0x1F); + h1 += t; + t = (h7 & (0x3F << 10)) | (h6 & (0x1F << 5)); + h2 += (t >>> 5); + t = (h7 & (0x1F << 16)) | (h6 & (0x3F << 10)); + h3 += (t >>> 10); + t = (h7 & (0x1F << 21)) | (h6 & (0x1F << 16)); + h4 += (t >>> 16); + t = (h7 & (0x3F << 26)) | (h6 & (0x1F << 21)); + h5 += (t >>> 21); + break; + case HAVAL_224_BIT: + h0 += ((h7 >>> 27) & 0x1F); + h1 += ((h7 >>> 22) & 0x1F); + h2 += ((h7 >>> 18) & 0x0F); + h3 += ((h7 >>> 13) & 0x1F); + h4 += ((h7 >>> 9) & 0x0F); + h5 += ((h7 >>> 4) & 0x1F); + h6 += (h7 & 0x0F); + } + } + + /** + * Permutations phi_{i,j}, i=3,4,5, j=1,...,i. + * + * rounds = 3: 6 5 4 3 2 1 0 + * | | | | | | | (replaced by) + * phi_{3,1}: 1 0 3 5 6 2 4 + * phi_{3,2}: 4 2 1 0 5 3 6 + * phi_{3,3}: 6 1 2 3 4 5 0 + * + * rounds = 4: 6 5 4 3 2 1 0 + * | | | | | | | (replaced by) + * phi_{4,1}: 2 6 1 4 5 3 0 + * phi_{4,2}: 3 5 2 0 1 6 4 + * phi_{4,3}: 1 4 3 6 0 2 5 + * phi_{4,4}: 6 4 0 5 2 1 3 + * + * rounds = 5: 6 5 4 3 2 1 0 + * | | | | | | | (replaced by) + * phi_{5,1}: 3 4 1 0 5 2 6 + * phi_{5,2}: 6 2 1 0 3 4 5 + * phi_{5,3}: 2 6 0 4 3 1 5 + * phi_{5,4}: 1 5 3 2 0 4 6 + * phi_{5,5}: 2 5 0 6 4 3 1 + */ + private int FF1(int x7, int x6, int x5, int x4, int x3, int x2, int x1, + int x0, int w) + { + int t; + switch (rounds) + { + case 3: + t = f1(x1, x0, x3, x5, x6, x2, x4); + break; + case 4: + t = f1(x2, x6, x1, x4, x5, x3, x0); + break; + default: + t = f1(x3, x4, x1, x0, x5, x2, x6); + } + return (t >>> 7 | t << 25) + (x7 >>> 11 | x7 << 21) + w; + } + + private int FF2(int x7, int x6, int x5, int x4, int x3, int x2, int x1, + int x0, int w, int c) + { + int t; + switch (rounds) + { + case 3: + t = f2(x4, x2, x1, x0, x5, x3, x6); + break; + case 4: + t = f2(x3, x5, x2, x0, x1, x6, x4); + break; + default: + t = f2(x6, x2, x1, x0, x3, x4, x5); + } + return (t >>> 7 | t << 25) + (x7 >>> 11 | x7 << 21) + w + c; + } + + private int FF3(int x7, int x6, int x5, int x4, int x3, int x2, int x1, + int x0, int w, int c) + { + int t; + switch (rounds) + { + case 3: + t = f3(x6, x1, x2, x3, x4, x5, x0); + break; + case 4: + t = f3(x1, x4, x3, x6, x0, x2, x5); + break; + default: + t = f3(x2, x6, x0, x4, x3, x1, x5); + } + return (t >>> 7 | t << 25) + (x7 >>> 11 | x7 << 21) + w + c; + } + + private int FF4(int x7, int x6, int x5, int x4, int x3, int x2, int x1, + int x0, int w, int c) + { + int t; + switch (rounds) + { + case 4: + t = f4(x6, x4, x0, x5, x2, x1, x3); + break; + default: + t = f4(x1, x5, x3, x2, x0, x4, x6); + } + return (t >>> 7 | t << 25) + (x7 >>> 11 | x7 << 21) + w + c; + } + + private int FF5(int x7, int x6, int x5, int x4, int x3, int x2, int x1, + int x0, int w, int c) + { + int t = f5(x2, x5, x0, x6, x4, x3, x1); + return (t >>> 7 | t << 25) + (x7 >>> 11 | x7 << 21) + w + c; + } + + private int f1(int x6, int x5, int x4, int x3, int x2, int x1, int x0) + { + return x1 & (x0 ^ x4) ^ x2 & x5 ^ x3 & x6 ^ x0; + } + + private int f2(int x6, int x5, int x4, int x3, int x2, int x1, int x0) + { + return x2 & (x1 & ~x3 ^ x4 & x5 ^ x6 ^ x0) ^ x4 & (x1 ^ x5) ^ x3 & x5 ^ x0; + } + + private int f3(int x6, int x5, int x4, int x3, int x2, int x1, int x0) + { + return x3 & (x1 & x2 ^ x6 ^ x0) ^ x1 & x4 ^ x2 & x5 ^ x0; + } + + private int f4(int x6, int x5, int x4, int x3, int x2, int x1, int x0) + { + return x4 & (x5 & ~x2 ^ x3 & ~x6 ^ x1 ^ x6 ^ x0) ^ x3 & (x1 & x2 ^ x5 ^ x6) + ^ x2 & x6 ^ x0; + } + + private int f5(int x6, int x5, int x4, int x3, int x2, int x1, int x0) + { + return x0 & (x1 & x2 & x3 ^ ~x5) ^ x1 & x4 ^ x2 & x5 ^ x3 & x6; + } +} diff --git a/libjava/classpath/gnu/java/security/hash/IMessageDigest.java b/libjava/classpath/gnu/java/security/hash/IMessageDigest.java new file mode 100644 index 0000000..b3d7f69 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/IMessageDigest.java @@ -0,0 +1,135 @@ +/* IMessageDigest.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +/** + *The basic visible methods of any hash algorithm.
+ * + *A hash (or message digest) algorithm produces its output by iterating a + * basic compression function on blocks of data.
+ */ +public interface IMessageDigest extends Cloneable +{ + + // Constants + // ------------------------------------------------------------------------- + + // Methods + // ------------------------------------------------------------------------- + + /** + *Returns the canonical name of this algorithm.
+ * + * @return the canonical name of this instance. + */ + String name(); + + /** + *Returns the output length in bytes of this message digest algorithm.
+ * + * @return the output length in bytes of this message digest algorithm. + */ + int hashSize(); + + /** + *Returns the algorithm's (inner) block size in bytes.
+ * + * @return the algorithm's inner block size in bytes. + */ + int blockSize(); + + /** + *Continues a message digest operation using the input byte.
+ * + * @param b the input byte to digest. + */ + void update(byte b); + + /** + *Continues a message digest operation, by filling the buffer, processing + * data in the algorithm's HASH_SIZE-bit block(s), updating the context and + * count, and buffering the remaining bytes in buffer for the next + * operation.
+ * + * @param in the input block. + */ + void update(byte[] in); + + /** + *Continues a message digest operation, by filling the buffer, processing + * data in the algorithm's HASH_SIZE-bit block(s), updating the context and + * count, and buffering the remaining bytes in buffer for the next + * operation.
+ * + * @param in the input block. + * @param offset start of meaningful bytes in input block. + * @param length number of bytes, in input block, to consider. + */ + void update(byte[] in, int offset, int length); + + /** + *Completes the message digest by performing final operations such as + * padding and resetting the instance.
+ * + * @return the array of bytes representing the hash value. + */ + byte[] digest(); + + /** + *Resets the current context of this instance clearing any eventually cached + * intermediary values.
+ */ + void reset(); + + /** + *A basic test. Ensures that the digest of a pre-determined message is equal + * to a known pre-computed value.
+ * + * @return true if the implementation passes a basic self-test. + * Returns false otherwise. + */ + boolean selfTest(); + + /** + *Returns a clone copy of this instance.
+ * + * @return a clone copy of this instance. + */ + Object clone(); +} diff --git a/libjava/classpath/gnu/java/security/hash/MD2.java b/libjava/classpath/gnu/java/security/hash/MD2.java new file mode 100644 index 0000000..41e8769 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/MD2.java @@ -0,0 +1,301 @@ +/* MD2.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *An implementation of the MD2 message digest algorithm.
+ * + *MD2 is not widely used. Unless it is needed for compatibility with + * existing systems, it is not recommended for use in new applications.
+ * + *References:
+ * + *BLOCK_LENGTH
bytes
+ * are also used to store the running digest.
+ */
+ private byte[] work;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Creates a new MD2 digest ready for use. */
+ public MD2()
+ {
+ super(Registry.MD2_HASH, DIGEST_LENGTH, BLOCK_LENGTH);
+ }
+
+ /**
+ * Private constructor used for cloning.
+ * + * @param md2 the instance to clone. + */ + private MD2(MD2 md2) + { + this(); + + // superclass field + this.count = md2.count; + this.buffer = (byte[]) md2.buffer.clone(); + + // private field + this.checksum = (byte[]) md2.checksum.clone(); + this.work = (byte[]) md2.work.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new MD2(this); + } + + // Implementation of abstract methods in BaseHash -------------------------- + + protected byte[] getResult() + { + byte[] result = new byte[DIGEST_LENGTH]; + + // Encrypt checksum as last block. + encryptBlock(checksum, 0); + + for (int i = 0; i < BLOCK_LENGTH; i++) + { + result[i] = work[i]; + } + + return result; + } + + protected void resetContext() + { + checksum = new byte[BLOCK_LENGTH]; + work = new byte[BLOCK_LENGTH * 3]; + } + + public boolean selfTest() + { + if (valid == null) + { + valid = new Boolean(DIGEST0.equals(Util.toString(new MD2().digest()))); + } + return valid.booleanValue(); + } + + /** + *Generates an array of padding bytes. The padding is defined as
+ * i
bytes of value i
, where i
is the
+ * number of bytes to fill the last block of the message to
+ * BLOCK_LENGTH
bytes (or BLOCK_LENGTH
bytes when
+ * the last block was completely full).
Adds BLOCK_LENGTH
bytes to the running digest.
BLOCK_LENGTH
bytes from.
+ * @param off the offset to start from in the given byte array.
+ */
+ protected void transform(byte[] in, int off)
+ {
+ // encryptBlock(in, off);
+ // updateCheckSum(in, off);
+ updateCheckSumAndEncryptBlock(in, off);
+ }
+
+ // Private instance methods ------------------------------------------------
+
+ /**
+ * Updates the checksum with the BLOCK_LENGTH
bytes from the
+ * given array starting at off
.
+ */
+ /*
+ private void updateCheckSum(byte[] in, int off) {
+ byte l = checksum[BLOCK_LENGTH-1];
+ for (int i = 0; i < BLOCK_LENGTH; i++) {
+ byte b = in[off+i];
+ // l = (byte)((checksum[i] & 0xFF) ^ (PI[((b & 0xFF) ^ (l & 0xFF))] & 0xFF));
+ l = (byte)(checksum[i] ^ PI[(b ^ l) & 0xFF]);
+ checksum[i] = l;
+ }
+ }
+ */
+ /**
+ * Adds a new block (BLOCK_LENGTH
bytes) to the running digest
+ * from the given byte array starting from the given offset.
+ */
+ private void encryptBlock(byte[] in, int off)
+ {
+ for (int i = 0; i < BLOCK_LENGTH; i++)
+ {
+ byte b = in[off + i];
+ work[BLOCK_LENGTH + i] = b;
+ work[BLOCK_LENGTH * 2 + i] = (byte) (work[i] ^ b);
+ }
+
+ byte t = 0;
+ for (int i = 0; i < 18; i++)
+ {
+ for (int j = 0; j < 3 * BLOCK_LENGTH; j++)
+ {
+ // t = (byte)((work[j] & 0xFF) ^ (PI[t & 0xFF] & 0xFF));
+ t = (byte) (work[j] ^ PI[t & 0xFF]);
+ work[j] = t;
+ }
+ // t = (byte)((t + i) & 0xFF);
+ t = (byte) (t + i);
+ }
+ }
+
+ /**
+ * Optimized method that combines a checksum update and encrypt of a block.
+ */
+ private void updateCheckSumAndEncryptBlock(byte[] in, int off)
+ {
+ byte l = checksum[BLOCK_LENGTH - 1];
+ for (int i = 0; i < BLOCK_LENGTH; i++)
+ {
+ byte b = in[off + i];
+ work[BLOCK_LENGTH + i] = b;
+ // work[BLOCK_LENGTH*2+i] = (byte)((work[i] & 0xFF) ^ (b & 0xFF));
+ work[BLOCK_LENGTH * 2 + i] = (byte) (work[i] ^ b);
+ // l = (byte)((checksum[i] & 0xFF) ^ (PI[((b & 0xFF) ^ (l & 0xFF))] & 0xFF));
+ l = (byte) (checksum[i] ^ PI[(b ^ l) & 0xFF]);
+ checksum[i] = l;
+ }
+
+ byte t = 0;
+ for (int i = 0; i < 18; i++)
+ {
+ for (int j = 0; j < 3 * BLOCK_LENGTH; j++)
+ {
+ // t = (byte)((work[j] & 0xFF) ^ (PI[t & 0xFF] & 0xFF));
+ t = (byte) (work[j] ^ PI[t & 0xFF]);
+ work[j] = t;
+ }
+ // t = (byte)((t + i) & 0xFF);
+ t = (byte) (t + i);
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/hash/MD4.java b/libjava/classpath/gnu/java/security/hash/MD4.java
new file mode 100644
index 0000000..54dda35
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/hash/MD4.java
@@ -0,0 +1,328 @@
+/* MD4.java --
+ Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.hash;
+
+import gnu.java.security.Registry;
+import gnu.java.security.util.Util;
+
+/**
+ * An implementation of Ron Rivest's MD4 message digest algorithm.
+ * + *MD4 was the precursor to the stronger {@link gnu.crypto.hash.MD5} + * algorithm, and while not considered cryptograpically secure itself, MD4 is + * in use in various applications. It is slightly faster than MD5.
+ * + *References:
+ * + *Public constructor. Initializes the chaining variables, sets the byte
+ * count to 0
, and creates a new block of 512
bits.
+ *
Trivial private constructor for cloning purposes.
+ * + * @param that the instance to clone. + */ + private MD4(MD4 that) + { + this(); + + this.a = that.a; + this.b = that.b; + this.c = that.c; + this.d = that.d; + this.count = that.count; + this.buffer = (byte[]) that.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new MD4(this); + } + + // Implementation of abstract methods in BashHash -------------------------- + + protected byte[] getResult() + { + byte[] digest = { (byte) a, (byte) (a >>> 8), (byte) (a >>> 16), + (byte) (a >>> 24), (byte) b, (byte) (b >>> 8), + (byte) (b >>> 16), (byte) (b >>> 24), (byte) c, + (byte) (c >>> 8), (byte) (c >>> 16), (byte) (c >>> 24), + (byte) d, (byte) (d >>> 8), (byte) (d >>> 16), + (byte) (d >>> 24) }; + return digest; + } + + protected void resetContext() + { + a = A; + b = B; + c = C; + d = D; + } + + public boolean selfTest() + { + if (valid == null) + { + valid = new Boolean(DIGEST0.equals(Util.toString(new MD4().digest()))); + } + return valid.booleanValue(); + } + + protected byte[] padBuffer() + { + int n = (int) (count % BLOCK_LENGTH); + int padding = (n < 56) ? (56 - n) : (120 - n); + byte[] pad = new byte[padding + 8]; + + pad[0] = (byte) 0x80; + long bits = count << 3; + pad[padding++] = (byte) bits; + pad[padding++] = (byte) (bits >>> 8); + pad[padding++] = (byte) (bits >>> 16); + pad[padding++] = (byte) (bits >>> 24); + pad[padding++] = (byte) (bits >>> 32); + pad[padding++] = (byte) (bits >>> 40); + pad[padding++] = (byte) (bits >>> 48); + pad[padding] = (byte) (bits >>> 56); + + return pad; + } + + protected void transform(byte[] in, int i) + { + int X0 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X1 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X2 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X3 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X4 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X5 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X6 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X7 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X8 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X9 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X10 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X11 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X12 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X13 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X14 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X15 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i] << 24; + + int aa, bb, cc, dd; + + aa = a; + bb = b; + cc = c; + dd = d; + + aa += ((bb & cc) | ((~bb) & dd)) + X0; + aa = aa << 3 | aa >>> -3; + dd += ((aa & bb) | ((~aa) & cc)) + X1; + dd = dd << 7 | dd >>> -7; + cc += ((dd & aa) | ((~dd) & bb)) + X2; + cc = cc << 11 | cc >>> -11; + bb += ((cc & dd) | ((~cc) & aa)) + X3; + bb = bb << 19 | bb >>> -19; + aa += ((bb & cc) | ((~bb) & dd)) + X4; + aa = aa << 3 | aa >>> -3; + dd += ((aa & bb) | ((~aa) & cc)) + X5; + dd = dd << 7 | dd >>> -7; + cc += ((dd & aa) | ((~dd) & bb)) + X6; + cc = cc << 11 | cc >>> -11; + bb += ((cc & dd) | ((~cc) & aa)) + X7; + bb = bb << 19 | bb >>> -19; + aa += ((bb & cc) | ((~bb) & dd)) + X8; + aa = aa << 3 | aa >>> -3; + dd += ((aa & bb) | ((~aa) & cc)) + X9; + dd = dd << 7 | dd >>> -7; + cc += ((dd & aa) | ((~dd) & bb)) + X10; + cc = cc << 11 | cc >>> -11; + bb += ((cc & dd) | ((~cc) & aa)) + X11; + bb = bb << 19 | bb >>> -19; + aa += ((bb & cc) | ((~bb) & dd)) + X12; + aa = aa << 3 | aa >>> -3; + dd += ((aa & bb) | ((~aa) & cc)) + X13; + dd = dd << 7 | dd >>> -7; + cc += ((dd & aa) | ((~dd) & bb)) + X14; + cc = cc << 11 | cc >>> -11; + bb += ((cc & dd) | ((~cc) & aa)) + X15; + bb = bb << 19 | bb >>> -19; + + aa += ((bb & (cc | dd)) | (cc & dd)) + X0 + 0x5a827999; + aa = aa << 3 | aa >>> -3; + dd += ((aa & (bb | cc)) | (bb & cc)) + X4 + 0x5a827999; + dd = dd << 5 | dd >>> -5; + cc += ((dd & (aa | bb)) | (aa & bb)) + X8 + 0x5a827999; + cc = cc << 9 | cc >>> -9; + bb += ((cc & (dd | aa)) | (dd & aa)) + X12 + 0x5a827999; + bb = bb << 13 | bb >>> -13; + aa += ((bb & (cc | dd)) | (cc & dd)) + X1 + 0x5a827999; + aa = aa << 3 | aa >>> -3; + dd += ((aa & (bb | cc)) | (bb & cc)) + X5 + 0x5a827999; + dd = dd << 5 | dd >>> -5; + cc += ((dd & (aa | bb)) | (aa & bb)) + X9 + 0x5a827999; + cc = cc << 9 | cc >>> -9; + bb += ((cc & (dd | aa)) | (dd & aa)) + X13 + 0x5a827999; + bb = bb << 13 | bb >>> -13; + aa += ((bb & (cc | dd)) | (cc & dd)) + X2 + 0x5a827999; + aa = aa << 3 | aa >>> -3; + dd += ((aa & (bb | cc)) | (bb & cc)) + X6 + 0x5a827999; + dd = dd << 5 | dd >>> -5; + cc += ((dd & (aa | bb)) | (aa & bb)) + X10 + 0x5a827999; + cc = cc << 9 | cc >>> -9; + bb += ((cc & (dd | aa)) | (dd & aa)) + X14 + 0x5a827999; + bb = bb << 13 | bb >>> -13; + aa += ((bb & (cc | dd)) | (cc & dd)) + X3 + 0x5a827999; + aa = aa << 3 | aa >>> -3; + dd += ((aa & (bb | cc)) | (bb & cc)) + X7 + 0x5a827999; + dd = dd << 5 | dd >>> -5; + cc += ((dd & (aa | bb)) | (aa & bb)) + X11 + 0x5a827999; + cc = cc << 9 | cc >>> -9; + bb += ((cc & (dd | aa)) | (dd & aa)) + X15 + 0x5a827999; + bb = bb << 13 | bb >>> -13; + + aa += (bb ^ cc ^ dd) + X0 + 0x6ed9eba1; + aa = aa << 3 | aa >>> -3; + dd += (aa ^ bb ^ cc) + X8 + 0x6ed9eba1; + dd = dd << 9 | dd >>> -9; + cc += (dd ^ aa ^ bb) + X4 + 0x6ed9eba1; + cc = cc << 11 | cc >>> -11; + bb += (cc ^ dd ^ aa) + X12 + 0x6ed9eba1; + bb = bb << 15 | bb >>> -15; + aa += (bb ^ cc ^ dd) + X2 + 0x6ed9eba1; + aa = aa << 3 | aa >>> -3; + dd += (aa ^ bb ^ cc) + X10 + 0x6ed9eba1; + dd = dd << 9 | dd >>> -9; + cc += (dd ^ aa ^ bb) + X6 + 0x6ed9eba1; + cc = cc << 11 | cc >>> -11; + bb += (cc ^ dd ^ aa) + X14 + 0x6ed9eba1; + bb = bb << 15 | bb >>> -15; + aa += (bb ^ cc ^ dd) + X1 + 0x6ed9eba1; + aa = aa << 3 | aa >>> -3; + dd += (aa ^ bb ^ cc) + X9 + 0x6ed9eba1; + dd = dd << 9 | dd >>> -9; + cc += (dd ^ aa ^ bb) + X5 + 0x6ed9eba1; + cc = cc << 11 | cc >>> -11; + bb += (cc ^ dd ^ aa) + X13 + 0x6ed9eba1; + bb = bb << 15 | bb >>> -15; + aa += (bb ^ cc ^ dd) + X3 + 0x6ed9eba1; + aa = aa << 3 | aa >>> -3; + dd += (aa ^ bb ^ cc) + X11 + 0x6ed9eba1; + dd = dd << 9 | dd >>> -9; + cc += (dd ^ aa ^ bb) + X7 + 0x6ed9eba1; + cc = cc << 11 | cc >>> -11; + bb += (cc ^ dd ^ aa) + X15 + 0x6ed9eba1; + bb = bb << 15 | bb >>> -15; + + a += aa; + b += bb; + c += cc; + d += dd; + } +} diff --git a/libjava/classpath/gnu/java/security/hash/MD5.java b/libjava/classpath/gnu/java/security/hash/MD5.java new file mode 100644 index 0000000..4632929 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/MD5.java @@ -0,0 +1,365 @@ +/* MD5.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *The MD5 message-digest algorithm takes as input a message of arbitrary + * length and produces as output a 128-bit "fingerprint" or "message digest" of + * the input. It is conjectured that it is computationally infeasible to + * produce two messages having the same message digest, or to produce any + * message having a given prespecified target message digest.
+ * + *References:
+ * + *Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private MD5(MD5 md) + { + this(); + + this.h0 = md.h0; + this.h1 = md.h1; + this.h2 = md.h2; + this.h3 = md.h3; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new MD5(this); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected synchronized void transform(byte[] in, int i) + { + int X0 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X1 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X2 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X3 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X4 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X5 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X6 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X7 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X8 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X9 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X10 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X11 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X12 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X13 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X14 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i++] << 24; + int X15 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 + | in[i] << 24; + + int A = h0; + int B = h1; + int C = h2; + int D = h3; + + // hex constants are from md5.c in FSF Gnu Privacy Guard 0.9.2 + // round 1 + A += ((B & C) | (~B & D)) + X0 + 0xD76AA478; + A = B + (A << 7 | A >>> -7); + D += ((A & B) | (~A & C)) + X1 + 0xE8C7B756; + D = A + (D << 12 | D >>> -12); + C += ((D & A) | (~D & B)) + X2 + 0x242070DB; + C = D + (C << 17 | C >>> -17); + B += ((C & D) | (~C & A)) + X3 + 0xC1BDCEEE; + B = C + (B << 22 | B >>> -22); + + A += ((B & C) | (~B & D)) + X4 + 0xF57C0FAF; + A = B + (A << 7 | A >>> -7); + D += ((A & B) | (~A & C)) + X5 + 0x4787C62A; + D = A + (D << 12 | D >>> -12); + C += ((D & A) | (~D & B)) + X6 + 0xA8304613; + C = D + (C << 17 | C >>> -17); + B += ((C & D) | (~C & A)) + X7 + 0xFD469501; + B = C + (B << 22 | B >>> -22); + + A += ((B & C) | (~B & D)) + X8 + 0x698098D8; + A = B + (A << 7 | A >>> -7); + D += ((A & B) | (~A & C)) + X9 + 0x8B44F7AF; + D = A + (D << 12 | D >>> -12); + C += ((D & A) | (~D & B)) + X10 + 0xFFFF5BB1; + C = D + (C << 17 | C >>> -17); + B += ((C & D) | (~C & A)) + X11 + 0x895CD7BE; + B = C + (B << 22 | B >>> -22); + + A += ((B & C) | (~B & D)) + X12 + 0x6B901122; + A = B + (A << 7 | A >>> -7); + D += ((A & B) | (~A & C)) + X13 + 0xFD987193; + D = A + (D << 12 | D >>> -12); + C += ((D & A) | (~D & B)) + X14 + 0xA679438E; + C = D + (C << 17 | C >>> -17); + B += ((C & D) | (~C & A)) + X15 + 0x49B40821; + B = C + (B << 22 | B >>> -22); + + // round 2 + A += ((B & D) | (C & ~D)) + X1 + 0xF61E2562; + A = B + (A << 5 | A >>> -5); + D += ((A & C) | (B & ~C)) + X6 + 0xC040B340; + D = A + (D << 9 | D >>> -9); + C += ((D & B) | (A & ~B)) + X11 + 0x265E5A51; + C = D + (C << 14 | C >>> -14); + B += ((C & A) | (D & ~A)) + X0 + 0xE9B6C7AA; + B = C + (B << 20 | B >>> -20); + + A += ((B & D) | (C & ~D)) + X5 + 0xD62F105D; + A = B + (A << 5 | A >>> -5); + D += ((A & C) | (B & ~C)) + X10 + 0x02441453; + D = A + (D << 9 | D >>> -9); + C += ((D & B) | (A & ~B)) + X15 + 0xD8A1E681; + C = D + (C << 14 | C >>> -14); + B += ((C & A) | (D & ~A)) + X4 + 0xE7D3FBC8; + B = C + (B << 20 | B >>> -20); + + A += ((B & D) | (C & ~D)) + X9 + 0x21E1CDE6; + A = B + (A << 5 | A >>> -5); + D += ((A & C) | (B & ~C)) + X14 + 0xC33707D6; + D = A + (D << 9 | D >>> -9); + C += ((D & B) | (A & ~B)) + X3 + 0xF4D50D87; + C = D + (C << 14 | C >>> -14); + B += ((C & A) | (D & ~A)) + X8 + 0x455A14ED; + B = C + (B << 20 | B >>> -20); + + A += ((B & D) | (C & ~D)) + X13 + 0xA9E3E905; + A = B + (A << 5 | A >>> -5); + D += ((A & C) | (B & ~C)) + X2 + 0xFCEFA3F8; + D = A + (D << 9 | D >>> -9); + C += ((D & B) | (A & ~B)) + X7 + 0x676F02D9; + C = D + (C << 14 | C >>> -14); + B += ((C & A) | (D & ~A)) + X12 + 0x8D2A4C8A; + B = C + (B << 20 | B >>> -20); + + // round 3 + A += (B ^ C ^ D) + X5 + 0xFFFA3942; + A = B + (A << 4 | A >>> -4); + D += (A ^ B ^ C) + X8 + 0x8771F681; + D = A + (D << 11 | D >>> -11); + C += (D ^ A ^ B) + X11 + 0x6D9D6122; + C = D + (C << 16 | C >>> -16); + B += (C ^ D ^ A) + X14 + 0xFDE5380C; + B = C + (B << 23 | B >>> -23); + + A += (B ^ C ^ D) + X1 + 0xA4BEEA44; + A = B + (A << 4 | A >>> -4); + D += (A ^ B ^ C) + X4 + 0x4BDECFA9; + D = A + (D << 11 | D >>> -11); + C += (D ^ A ^ B) + X7 + 0xF6BB4B60; + C = D + (C << 16 | C >>> -16); + B += (C ^ D ^ A) + X10 + 0xBEBFBC70; + B = C + (B << 23 | B >>> -23); + + A += (B ^ C ^ D) + X13 + 0x289B7EC6; + A = B + (A << 4 | A >>> -4); + D += (A ^ B ^ C) + X0 + 0xEAA127FA; + D = A + (D << 11 | D >>> -11); + C += (D ^ A ^ B) + X3 + 0xD4EF3085; + C = D + (C << 16 | C >>> -16); + B += (C ^ D ^ A) + X6 + 0x04881D05; + B = C + (B << 23 | B >>> -23); + + A += (B ^ C ^ D) + X9 + 0xD9D4D039; + A = B + (A << 4 | A >>> -4); + D += (A ^ B ^ C) + X12 + 0xE6DB99E5; + D = A + (D << 11 | D >>> -11); + C += (D ^ A ^ B) + X15 + 0x1FA27CF8; + C = D + (C << 16 | C >>> -16); + B += (C ^ D ^ A) + X2 + 0xC4AC5665; + B = C + (B << 23 | B >>> -23); + + // round 4 + A += (C ^ (B | ~D)) + X0 + 0xF4292244; + A = B + (A << 6 | A >>> -6); + D += (B ^ (A | ~C)) + X7 + 0x432AFF97; + D = A + (D << 10 | D >>> -10); + C += (A ^ (D | ~B)) + X14 + 0xAB9423A7; + C = D + (C << 15 | C >>> -15); + B += (D ^ (C | ~A)) + X5 + 0xFC93A039; + B = C + (B << 21 | B >>> -21); + + A += (C ^ (B | ~D)) + X12 + 0x655B59C3; + A = B + (A << 6 | A >>> -6); + D += (B ^ (A | ~C)) + X3 + 0x8F0CCC92; + D = A + (D << 10 | D >>> -10); + C += (A ^ (D | ~B)) + X10 + 0xFFEFF47D; + C = D + (C << 15 | C >>> -15); + B += (D ^ (C | ~A)) + X1 + 0x85845dd1; + B = C + (B << 21 | B >>> -21); + + A += (C ^ (B | ~D)) + X8 + 0x6FA87E4F; + A = B + (A << 6 | A >>> -6); + D += (B ^ (A | ~C)) + X15 + 0xFE2CE6E0; + D = A + (D << 10 | D >>> -10); + C += (A ^ (D | ~B)) + X6 + 0xA3014314; + C = D + (C << 15 | C >>> -15); + B += (D ^ (C | ~A)) + X13 + 0x4E0811A1; + B = C + (B << 21 | B >>> -21); + + A += (C ^ (B | ~D)) + X4 + 0xF7537E82; + A = B + (A << 6 | A >>> -6); + D += (B ^ (A | ~C)) + X11 + 0xBD3AF235; + D = A + (D << 10 | D >>> -10); + C += (A ^ (D | ~B)) + X2 + 0x2AD7D2BB; + C = D + (C << 15 | C >>> -15); + B += (D ^ (C | ~A)) + X9 + 0xEB86D391; + B = C + (B << 21 | B >>> -21); + + h0 += A; + h1 += B; + h2 += C; + h3 += D; + } + + protected byte[] padBuffer() + { + int n = (int) (count % BLOCK_SIZE); + int padding = (n < 56) ? (56 - n) : (120 - n); + byte[] result = new byte[padding + 8]; + + // padding is always binary 1 followed by binary 0s + result[0] = (byte) 0x80; + + // save number of bits, casting the long to an array of 8 bytes + long bits = count << 3; + result[padding++] = (byte) bits; + result[padding++] = (byte) (bits >>> 8); + result[padding++] = (byte) (bits >>> 16); + result[padding++] = (byte) (bits >>> 24); + result[padding++] = (byte) (bits >>> 32); + result[padding++] = (byte) (bits >>> 40); + result[padding++] = (byte) (bits >>> 48); + result[padding] = (byte) (bits >>> 56); + + return result; + } + + protected byte[] getResult() + { + byte[] result = new byte[] { (byte) h0, (byte) (h0 >>> 8), + (byte) (h0 >>> 16), (byte) (h0 >>> 24), + (byte) h1, (byte) (h1 >>> 8), + (byte) (h1 >>> 16), (byte) (h1 >>> 24), + (byte) h2, (byte) (h2 >>> 8), + (byte) (h2 >>> 16), (byte) (h2 >>> 24), + (byte) h3, (byte) (h3 >>> 8), + (byte) (h3 >>> 16), (byte) (h3 >>> 24) }; + + return result; + } + + protected void resetContext() + { + // magic MD5/RIPEMD128 initialisation constants + h0 = 0x67452301; + h1 = 0xEFCDAB89; + h2 = 0x98BADCFE; + h3 = 0x10325476; + } + + public boolean selfTest() + { + if (valid == null) + { + valid = new Boolean(DIGEST0.equals(Util.toString(new MD5().digest()))); + } + return valid.booleanValue(); + } +} diff --git a/libjava/classpath/gnu/java/security/hash/RipeMD128.java b/libjava/classpath/gnu/java/security/hash/RipeMD128.java new file mode 100644 index 0000000..83e8f25 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/RipeMD128.java @@ -0,0 +1,291 @@ +/* RipeMD128.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *RIPEMD-128 is a 128-bit message digest.
+ * + *References:
+ * + *Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private RipeMD128(RipeMD128 md) + { + this(); + + this.h0 = md.h0; + this.h1 = md.h1; + this.h2 = md.h2; + this.h3 = md.h3; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new RipeMD128(this); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected void transform(byte[] in, int offset) + { + int A, B, C, D, Ap, Bp, Cp, Dp, T, s, i; + + // encode 64 bytes from input block into an array of 16 unsigned + // integers. + for (i = 0; i < 16; i++) + { + X[i] = (in[offset++] & 0xFF) | (in[offset++] & 0xFF) << 8 + | (in[offset++] & 0xFF) << 16 | in[offset++] << 24; + } + + A = Ap = h0; + B = Bp = h1; + C = Cp = h2; + D = Dp = h3; + + for (i = 0; i < 16; i++) + { // rounds 0...15 + s = S[i]; + T = A + (B ^ C ^ D) + X[i]; + A = D; + D = C; + C = B; + B = T << s | T >>> (32 - s); + + s = Sp[i]; + T = Ap + ((Bp & Dp) | (Cp & ~Dp)) + X[Rp[i]] + 0x50A28BE6; + Ap = Dp; + Dp = Cp; + Cp = Bp; + Bp = T << s | T >>> (32 - s); + } + + for (; i < 32; i++) + { // rounds 16...31 + s = S[i]; + T = A + ((B & C) | (~B & D)) + X[R[i]] + 0x5A827999; + A = D; + D = C; + C = B; + B = T << s | T >>> (32 - s); + + s = Sp[i]; + T = Ap + ((Bp | ~Cp) ^ Dp) + X[Rp[i]] + 0x5C4DD124; + Ap = Dp; + Dp = Cp; + Cp = Bp; + Bp = T << s | T >>> (32 - s); + } + + for (; i < 48; i++) + { // rounds 32...47 + s = S[i]; + T = A + ((B | ~C) ^ D) + X[R[i]] + 0x6ED9EBA1; + A = D; + D = C; + C = B; + B = T << s | T >>> (32 - s); + + s = Sp[i]; + T = Ap + ((Bp & Cp) | (~Bp & Dp)) + X[Rp[i]] + 0x6D703EF3; + Ap = Dp; + Dp = Cp; + Cp = Bp; + Bp = T << s | T >>> (32 - s); + } + + for (; i < 64; i++) + { // rounds 48...63 + s = S[i]; + T = A + ((B & D) | (C & ~D)) + X[R[i]] + 0x8F1BBCDC; + A = D; + D = C; + C = B; + B = T << s | T >>> (32 - s); + + s = Sp[i]; + T = Ap + (Bp ^ Cp ^ Dp) + X[Rp[i]]; + Ap = Dp; + Dp = Cp; + Cp = Bp; + Bp = T << s | T >>> (32 - s); + } + + T = h1 + C + Dp; + h1 = h2 + D + Ap; + h2 = h3 + A + Bp; + h3 = h0 + B + Cp; + h0 = T; + } + + protected byte[] padBuffer() + { + int n = (int) (count % BLOCK_SIZE); + int padding = (n < 56) ? (56 - n) : (120 - n); + byte[] result = new byte[padding + 8]; + + // padding is always binary 1 followed by binary 0s + result[0] = (byte) 0x80; + + // save number of bits, casting the long to an array of 8 bytes + long bits = count << 3; + result[padding++] = (byte) bits; + result[padding++] = (byte) (bits >>> 8); + result[padding++] = (byte) (bits >>> 16); + result[padding++] = (byte) (bits >>> 24); + result[padding++] = (byte) (bits >>> 32); + result[padding++] = (byte) (bits >>> 40); + result[padding++] = (byte) (bits >>> 48); + result[padding] = (byte) (bits >>> 56); + + return result; + } + + protected byte[] getResult() + { + byte[] result = new byte[] { (byte) h0, (byte) (h0 >>> 8), + (byte) (h0 >>> 16), (byte) (h0 >>> 24), + (byte) h1, (byte) (h1 >>> 8), + (byte) (h1 >>> 16), (byte) (h1 >>> 24), + (byte) h2, (byte) (h2 >>> 8), + (byte) (h2 >>> 16), (byte) (h2 >>> 24), + (byte) h3, (byte) (h3 >>> 8), + (byte) (h3 >>> 16), (byte) (h3 >>> 24) }; + + return result; + } + + protected void resetContext() + { + // magic RIPEMD128 initialisation constants + h0 = 0x67452301; + h1 = 0xEFCDAB89; + h2 = 0x98BADCFE; + h3 = 0x10325476; + } + + public boolean selfTest() + { + if (valid == null) + { + valid = new Boolean + (DIGEST0.equals(Util.toString(new RipeMD128().digest()))); + } + return valid.booleanValue(); + } +} diff --git a/libjava/classpath/gnu/java/security/hash/RipeMD160.java b/libjava/classpath/gnu/java/security/hash/RipeMD160.java new file mode 100644 index 0000000..73ecc516 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/RipeMD160.java @@ -0,0 +1,328 @@ +/* RipeMD160.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *RIPEMD-160 is a 160-bit message digest.
+ * + *References:
+ * + *Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private RipeMD160(RipeMD160 md) + { + this(); + + this.h0 = md.h0; + this.h1 = md.h1; + this.h2 = md.h2; + this.h3 = md.h3; + this.h4 = md.h4; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return (new RipeMD160(this)); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected void transform(byte[] in, int offset) + { + int A, B, C, D, E, Ap, Bp, Cp, Dp, Ep, T, s, i; + + // encode 64 bytes from input block into an array of 16 unsigned integers + for (i = 0; i < 16; i++) + { + X[i] = (in[offset++] & 0xFF) | (in[offset++] & 0xFF) << 8 + | (in[offset++] & 0xFF) << 16 | in[offset++] << 24; + } + + A = Ap = h0; + B = Bp = h1; + C = Cp = h2; + D = Dp = h3; + E = Ep = h4; + + for (i = 0; i < 16; i++) + { // rounds 0...15 + s = S[i]; + T = A + (B ^ C ^ D) + X[i]; + A = E; + E = D; + D = C << 10 | C >>> 22; + C = B; + B = (T << s | T >>> (32 - s)) + A; + + s = Sp[i]; + T = Ap + (Bp ^ (Cp | ~Dp)) + X[Rp[i]] + 0x50A28BE6; + Ap = Ep; + Ep = Dp; + Dp = Cp << 10 | Cp >>> 22; + Cp = Bp; + Bp = (T << s | T >>> (32 - s)) + Ap; + } + + for (; i < 32; i++) + { // rounds 16...31 + s = S[i]; + T = A + ((B & C) | (~B & D)) + X[R[i]] + 0x5A827999; + A = E; + E = D; + D = C << 10 | C >>> 22; + C = B; + B = (T << s | T >>> (32 - s)) + A; + + s = Sp[i]; + T = Ap + ((Bp & Dp) | (Cp & ~Dp)) + X[Rp[i]] + 0x5C4DD124; + Ap = Ep; + Ep = Dp; + Dp = Cp << 10 | Cp >>> 22; + Cp = Bp; + Bp = (T << s | T >>> (32 - s)) + Ap; + } + + for (; i < 48; i++) + { // rounds 32...47 + s = S[i]; + T = A + ((B | ~C) ^ D) + X[R[i]] + 0x6ED9EBA1; + A = E; + E = D; + D = C << 10 | C >>> 22; + C = B; + B = (T << s | T >>> (32 - s)) + A; + + s = Sp[i]; + T = Ap + ((Bp | ~Cp) ^ Dp) + X[Rp[i]] + 0x6D703EF3; + Ap = Ep; + Ep = Dp; + Dp = Cp << 10 | Cp >>> 22; + Cp = Bp; + Bp = (T << s | T >>> (32 - s)) + Ap; + } + + for (; i < 64; i++) + { // rounds 48...63 + s = S[i]; + T = A + ((B & D) | (C & ~D)) + X[R[i]] + 0x8F1BBCDC; + A = E; + E = D; + D = C << 10 | C >>> 22; + C = B; + B = (T << s | T >>> (32 - s)) + A; + + s = Sp[i]; + T = Ap + ((Bp & Cp) | (~Bp & Dp)) + X[Rp[i]] + 0x7A6D76E9; + Ap = Ep; + Ep = Dp; + Dp = Cp << 10 | Cp >>> 22; + Cp = Bp; + Bp = (T << s | T >>> (32 - s)) + Ap; + } + + for (; i < 80; i++) + { // rounds 64...79 + s = S[i]; + T = A + (B ^ (C | ~D)) + X[R[i]] + 0xA953FD4E; + A = E; + E = D; + D = C << 10 | C >>> 22; + C = B; + B = (T << s | T >>> (32 - s)) + A; + + s = Sp[i]; + T = Ap + (Bp ^ Cp ^ Dp) + X[Rp[i]]; + Ap = Ep; + Ep = Dp; + Dp = Cp << 10 | Cp >>> 22; + Cp = Bp; + Bp = (T << s | T >>> (32 - s)) + Ap; + } + + T = h1 + C + Dp; + h1 = h2 + D + Ep; + h2 = h3 + E + Ap; + h3 = h4 + A + Bp; + h4 = h0 + B + Cp; + h0 = T; + } + + protected byte[] padBuffer() + { + int n = (int) (count % BLOCK_SIZE); + int padding = (n < 56) ? (56 - n) : (120 - n); + byte[] result = new byte[padding + 8]; + + // padding is always binary 1 followed by binary 0s + result[0] = (byte) 0x80; + + // save number of bits, casting the long to an array of 8 bytes + long bits = count << 3; + result[padding++] = (byte) bits; + result[padding++] = (byte) (bits >>> 8); + result[padding++] = (byte) (bits >>> 16); + result[padding++] = (byte) (bits >>> 24); + result[padding++] = (byte) (bits >>> 32); + result[padding++] = (byte) (bits >>> 40); + result[padding++] = (byte) (bits >>> 48); + result[padding] = (byte) (bits >>> 56); + + return result; + } + + protected byte[] getResult() + { + byte[] result = new byte[] { (byte) h0, (byte) (h0 >>> 8), + (byte) (h0 >>> 16), (byte) (h0 >>> 24), + (byte) h1, (byte) (h1 >>> 8), + (byte) (h1 >>> 16), (byte) (h1 >>> 24), + (byte) h2, (byte) (h2 >>> 8), + (byte) (h2 >>> 16), (byte) (h2 >>> 24), + (byte) h3, (byte) (h3 >>> 8), + (byte) (h3 >>> 16), (byte) (h3 >>> 24), + (byte) h4, (byte) (h4 >>> 8), + (byte) (h4 >>> 16), (byte) (h4 >>> 24) }; + + return result; + } + + protected void resetContext() + { + // magic RIPEMD160 initialisation constants + h0 = 0x67452301; + h1 = 0xEFCDAB89; + h2 = 0x98BADCFE; + h3 = 0x10325476; + h4 = 0xC3D2E1F0; + } + + public boolean selfTest() + { + if (valid == null) + { + valid = new Boolean + (DIGEST0.equals(Util.toString(new RipeMD160().digest()))); + } + return valid.booleanValue(); + } +} diff --git a/libjava/classpath/gnu/java/security/hash/Sha160.java b/libjava/classpath/gnu/java/security/hash/Sha160.java new file mode 100644 index 0000000..bf5f456 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/Sha160.java @@ -0,0 +1,308 @@ +/* Sha160.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *The Secure Hash Algorithm (SHA-1) is required for use with the Digital + * Signature Algorithm (DSA) as specified in the Digital Signature Standard + * (DSS) and whenever a secure hash algorithm is required for federal + * applications. For a message of length less than 2^64 bits, the SHA-1 + * produces a 160-bit condensed representation of the message called a message + * digest. The message digest is used during generation of a signature for the + * message. The SHA-1 is also used to compute a message digest for the received + * version of the message during the process of verifying the signature. Any + * change to the message in transit will, with very high probability, result in + * a different message digest, and the signature will fail to verify.
+ * + *The SHA-1 is designed to have the following properties: it is + * computationally infeasible to find a message which corresponds to a given + * message digest, or to find two different messages which produce the same + * message digest.
+ * + *References:
+ * + *Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private Sha160(Sha160 md) + { + this(); + + this.h0 = md.h0; + this.h1 = md.h1; + this.h2 = md.h2; + this.h3 = md.h3; + this.h4 = md.h4; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + public static final int[] G(int hh0, int hh1, int hh2, int hh3, int hh4, + byte[] in, int offset) + { + // int[] w = new int[80]; + // int i, T; + // for (i = 0; i < 16; i++) { + // w[i] = in[offset++] << 24 | + // (in[offset++] & 0xFF) << 16 | + // (in[offset++] & 0xFF) << 8 | + // (in[offset++] & 0xFF); + // } + // for (i = 16; i < 80; i++) { + // T = w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]; + // w[i] = T << 1 | T >>> 31; + // } + + // return sha(hh0, hh1, hh2, hh3, hh4, in, offset, w); + return sha(hh0, hh1, hh2, hh3, hh4, in, offset); + } + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new Sha160(this); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected void transform(byte[] in, int offset) + { + // int i, T; + // for (i = 0; i < 16; i++) { + // W[i] = in[offset++] << 24 | + // (in[offset++] & 0xFF) << 16 | + // (in[offset++] & 0xFF) << 8 | + // (in[offset++] & 0xFF); + // } + // for (i = 16; i < 80; i++) { + // T = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16]; + // W[i] = T << 1 | T >>> 31; + // } + + // int[] result = sha(h0, h1, h2, h3, h4, in, offset, W); + int[] result = sha(h0, h1, h2, h3, h4, in, offset); + + h0 = result[0]; + h1 = result[1]; + h2 = result[2]; + h3 = result[3]; + h4 = result[4]; + } + + protected byte[] padBuffer() + { + int n = (int) (count % BLOCK_SIZE); + int padding = (n < 56) ? (56 - n) : (120 - n); + byte[] result = new byte[padding + 8]; + + // padding is always binary 1 followed by binary 0s + result[0] = (byte) 0x80; + + // save number of bits, casting the long to an array of 8 bytes + long bits = count << 3; + result[padding++] = (byte) (bits >>> 56); + result[padding++] = (byte) (bits >>> 48); + result[padding++] = (byte) (bits >>> 40); + result[padding++] = (byte) (bits >>> 32); + result[padding++] = (byte) (bits >>> 24); + result[padding++] = (byte) (bits >>> 16); + result[padding++] = (byte) (bits >>> 8); + result[padding] = (byte) bits; + + return result; + } + + protected byte[] getResult() + { + byte[] result = new byte[] { (byte) (h0 >>> 24), (byte) (h0 >>> 16), + (byte) (h0 >>> 8), (byte) h0, + (byte) (h1 >>> 24), (byte) (h1 >>> 16), + (byte) (h1 >>> 8), (byte) h1, + (byte) (h2 >>> 24), (byte) (h2 >>> 16), + (byte) (h2 >>> 8), (byte) h2, + (byte) (h3 >>> 24), (byte) (h3 >>> 16), + (byte) (h3 >>> 8), (byte) h3, + (byte) (h4 >>> 24), (byte) (h4 >>> 16), + (byte) (h4 >>> 8), (byte) h4 }; + + return result; + } + + protected void resetContext() + { + // magic SHA-1/RIPEMD160 initialisation constants + h0 = 0x67452301; + h1 = 0xEFCDAB89; + h2 = 0x98BADCFE; + h3 = 0x10325476; + h4 = 0xC3D2E1F0; + } + + public boolean selfTest() + { + if (valid == null) + { + Sha160 md = new Sha160(); + md.update((byte) 0x61); // a + md.update((byte) 0x62); // b + md.update((byte) 0x63); // c + String result = Util.toString(md.digest()); + valid = new Boolean(DIGEST0.equals(result)); + } + return valid.booleanValue(); + } + + // SHA specific methods ---------------------------------------------------- + + private static final synchronized int[] + // sha(int hh0, int hh1, int hh2, int hh3, int hh4, byte[] in, int offset, int[] w) { + sha(int hh0, int hh1, int hh2, int hh3, int hh4, byte[] in, int offset) + { + int A = hh0; + int B = hh1; + int C = hh2; + int D = hh3; + int E = hh4; + int r, T; + + for (r = 0; r < 16; r++) + { + w[r] = in[offset++] << 24 | (in[offset++] & 0xFF) << 16 + | (in[offset++] & 0xFF) << 8 | (in[offset++] & 0xFF); + } + for (r = 16; r < 80; r++) + { + T = w[r - 3] ^ w[r - 8] ^ w[r - 14] ^ w[r - 16]; + w[r] = T << 1 | T >>> 31; + } + + // rounds 0-19 + for (r = 0; r < 20; r++) + { + T = (A << 5 | A >>> 27) + ((B & C) | (~B & D)) + E + w[r] + 0x5A827999; + E = D; + D = C; + C = B << 30 | B >>> 2; + B = A; + A = T; + } + + // rounds 20-39 + for (r = 20; r < 40; r++) + { + T = (A << 5 | A >>> 27) + (B ^ C ^ D) + E + w[r] + 0x6ED9EBA1; + E = D; + D = C; + C = B << 30 | B >>> 2; + B = A; + A = T; + } + + // rounds 40-59 + for (r = 40; r < 60; r++) + { + T = (A << 5 | A >>> 27) + (B & C | B & D | C & D) + E + w[r] + + 0x8F1BBCDC; + E = D; + D = C; + C = B << 30 | B >>> 2; + B = A; + A = T; + } + + // rounds 60-79 + for (r = 60; r < 80; r++) + { + T = (A << 5 | A >>> 27) + (B ^ C ^ D) + E + w[r] + 0xCA62C1D6; + E = D; + D = C; + C = B << 30 | B >>> 2; + B = A; + A = T; + } + + return new int[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E }; + } +} diff --git a/libjava/classpath/gnu/java/security/hash/Sha256.java b/libjava/classpath/gnu/java/security/hash/Sha256.java new file mode 100644 index 0000000..9ef70a1 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/Sha256.java @@ -0,0 +1,278 @@ +/* Sha256.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *Implementation of SHA2-1 [SHA-256] per the IETF Draft Specification.
+ * + *References:
+ *Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private Sha256(Sha256 md) + { + this(); + + this.h0 = md.h0; + this.h1 = md.h1; + this.h2 = md.h2; + this.h3 = md.h3; + this.h4 = md.h4; + this.h5 = md.h5; + this.h6 = md.h6; + this.h7 = md.h7; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + public static final int[] G(int hh0, int hh1, int hh2, int hh3, int hh4, + int hh5, int hh6, int hh7, byte[] in, int offset) + { + return sha(hh0, hh1, hh2, hh3, hh4, hh5, hh6, hh7, in, offset); + } + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new Sha256(this); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected void transform(byte[] in, int offset) + { + int[] result = sha(h0, h1, h2, h3, h4, h5, h6, h7, in, offset); + + h0 = result[0]; + h1 = result[1]; + h2 = result[2]; + h3 = result[3]; + h4 = result[4]; + h5 = result[5]; + h6 = result[6]; + h7 = result[7]; + } + + protected byte[] padBuffer() + { + int n = (int) (count % BLOCK_SIZE); + int padding = (n < 56) ? (56 - n) : (120 - n); + byte[] result = new byte[padding + 8]; + + // padding is always binary 1 followed by binary 0s + result[0] = (byte) 0x80; + + // save number of bits, casting the long to an array of 8 bytes + long bits = count << 3; + result[padding++] = (byte) (bits >>> 56); + result[padding++] = (byte) (bits >>> 48); + result[padding++] = (byte) (bits >>> 40); + result[padding++] = (byte) (bits >>> 32); + result[padding++] = (byte) (bits >>> 24); + result[padding++] = (byte) (bits >>> 16); + result[padding++] = (byte) (bits >>> 8); + result[padding] = (byte) bits; + + return result; + } + + protected byte[] getResult() + { + return new byte[] { (byte) (h0 >>> 24), (byte) (h0 >>> 16), + (byte) (h0 >>> 8), (byte) h0, (byte) (h1 >>> 24), + (byte) (h1 >>> 16), (byte) (h1 >>> 8), (byte) h1, + (byte) (h2 >>> 24), (byte) (h2 >>> 16), + (byte) (h2 >>> 8), (byte) h2, (byte) (h3 >>> 24), + (byte) (h3 >>> 16), (byte) (h3 >>> 8), (byte) h3, + (byte) (h4 >>> 24), (byte) (h4 >>> 16), + (byte) (h4 >>> 8), (byte) h4, (byte) (h5 >>> 24), + (byte) (h5 >>> 16), (byte) (h5 >>> 8), (byte) h5, + (byte) (h6 >>> 24), (byte) (h6 >>> 16), + (byte) (h6 >>> 8), (byte) h6, (byte) (h7 >>> 24), + (byte) (h7 >>> 16), (byte) (h7 >>> 8), (byte) h7 }; + } + + protected void resetContext() + { + // magic SHA-256 initialisation constants + h0 = 0x6a09e667; + h1 = 0xbb67ae85; + h2 = 0x3c6ef372; + h3 = 0xa54ff53a; + h4 = 0x510e527f; + h5 = 0x9b05688c; + h6 = 0x1f83d9ab; + h7 = 0x5be0cd19; + } + + public boolean selfTest() + { + if (valid == null) + { + Sha256 md = new Sha256(); + md.update((byte) 0x61); // a + md.update((byte) 0x62); // b + md.update((byte) 0x63); // c + String result = Util.toString(md.digest()); + valid = new Boolean(DIGEST0.equals(result)); + } + + return valid.booleanValue(); + } + + // SHA specific methods ---------------------------------------------------- + + private static final synchronized int[] sha(int hh0, int hh1, int hh2, + int hh3, int hh4, int hh5, + int hh6, int hh7, byte[] in, + int offset) + { + int A = hh0; + int B = hh1; + int C = hh2; + int D = hh3; + int E = hh4; + int F = hh5; + int G = hh6; + int H = hh7; + int r, T, T2; + + for (r = 0; r < 16; r++) + { + w[r] = (in[offset++] << 24 | (in[offset++] & 0xFF) << 16 + | (in[offset++] & 0xFF) << 8 | (in[offset++] & 0xFF)); + } + for (r = 16; r < 64; r++) + { + T = w[r - 2]; + T2 = w[r - 15]; + w[r] = ((((T >>> 17) | (T << 15)) ^ ((T >>> 19) | (T << 13)) ^ (T >>> 10)) + + w[r - 7] + + (((T2 >>> 7) | (T2 << 25)) ^ ((T2 >>> 18) | (T2 << 14)) ^ (T2 >>> 3)) + + w[r - 16]); + } + + for (r = 0; r < 64; r++) + { + T = (H + + (((E >>> 6) | (E << 26)) ^ ((E >>> 11) | (E << 21)) ^ ((E >>> 25) | (E << 7))) + + ((E & F) ^ (~E & G)) + k[r] + w[r]); + T2 = ((((A >>> 2) | (A << 30)) ^ ((A >>> 13) | (A << 19)) ^ ((A >>> 22) | (A << 10))) + + ((A & B) ^ (A & C) ^ (B & C))); + H = G; + G = F; + F = E; + E = D + T; + D = C; + C = B; + B = A; + A = T + T2; + } + + return new int[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, hh5 + F, + hh6 + G, hh7 + H }; + } +} diff --git a/libjava/classpath/gnu/java/security/hash/Sha384.java b/libjava/classpath/gnu/java/security/hash/Sha384.java new file mode 100644 index 0000000..2f619dc --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/Sha384.java @@ -0,0 +1,322 @@ +/* Sha384.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *Implementation of SHA2-2 [SHA-384] per the IETF Draft Specification.
+ * + *References:
+ *Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private Sha384(Sha384 md) + { + this(); + + this.h0 = md.h0; + this.h1 = md.h1; + this.h2 = md.h2; + this.h3 = md.h3; + this.h4 = md.h4; + this.h5 = md.h5; + this.h6 = md.h6; + this.h7 = md.h7; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + public static final long[] G(long hh0, long hh1, long hh2, long hh3, + long hh4, long hh5, long hh6, long hh7, + byte[] in, int offset) + { + return sha(hh0, hh1, hh2, hh3, hh4, hh5, hh6, hh7, in, offset); + } + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new Sha384(this); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected void transform(byte[] in, int offset) + { + long[] result = sha(h0, h1, h2, h3, h4, h5, h6, h7, in, offset); + + h0 = result[0]; + h1 = result[1]; + h2 = result[2]; + h3 = result[3]; + h4 = result[4]; + h5 = result[5]; + h6 = result[6]; + h7 = result[7]; + } + + protected byte[] padBuffer() + { + int n = (int) (count % BLOCK_SIZE); + int padding = (n < 112) ? (112 - n) : (240 - n); + byte[] result = new byte[padding + 16]; + + // padding is always binary 1 followed by binary 0s + result[0] = (byte) 0x80; + + // save number of bits, casting the long to an array of 8 bytes + // TODO: FIX Only ~35 bits of 128 bit counter usable this way + long bits = count << 3; + padding += 8; + result[padding++] = (byte) (bits >>> 56); + result[padding++] = (byte) (bits >>> 48); + result[padding++] = (byte) (bits >>> 40); + result[padding++] = (byte) (bits >>> 32); + result[padding++] = (byte) (bits >>> 24); + result[padding++] = (byte) (bits >>> 16); + result[padding++] = (byte) (bits >>> 8); + result[padding] = (byte) bits; + + return result; + } + + protected byte[] getResult() + { + return new byte[] { (byte) (h0 >>> 56), (byte) (h0 >>> 48), + (byte) (h0 >>> 40), (byte) (h0 >>> 32), + (byte) (h0 >>> 24), (byte) (h0 >>> 16), + (byte) (h0 >>> 8), (byte) h0, (byte) (h1 >>> 56), + (byte) (h1 >>> 48), (byte) (h1 >>> 40), + (byte) (h1 >>> 32), (byte) (h1 >>> 24), + (byte) (h1 >>> 16), (byte) (h1 >>> 8), (byte) h1, + (byte) (h2 >>> 56), (byte) (h2 >>> 48), + (byte) (h2 >>> 40), (byte) (h2 >>> 32), + (byte) (h2 >>> 24), (byte) (h2 >>> 16), + (byte) (h2 >>> 8), (byte) h2, (byte) (h3 >>> 56), + (byte) (h3 >>> 48), (byte) (h3 >>> 40), + (byte) (h3 >>> 32), (byte) (h3 >>> 24), + (byte) (h3 >>> 16), (byte) (h3 >>> 8), (byte) h3, + (byte) (h4 >>> 56), (byte) (h4 >>> 48), + (byte) (h4 >>> 40), (byte) (h4 >>> 32), + (byte) (h4 >>> 24), (byte) (h4 >>> 16), + (byte) (h4 >>> 8), (byte) h4, (byte) (h5 >>> 56), + (byte) (h5 >>> 48), (byte) (h5 >>> 40), + (byte) (h5 >>> 32), (byte) (h5 >>> 24), + (byte) (h5 >>> 16), (byte) (h5 >>> 8), (byte) h5 + // (byte)(h6 >>> 56), (byte)(h6 >>> 48), (byte)(h6 >>> 40), (byte)(h6 >>> 32), + // (byte)(h6 >>> 24), (byte)(h6 >>> 16), (byte)(h6 >>> 8), (byte) h6, + // (byte)(h7 >>> 56), (byte)(h7 >>> 48), (byte)(h7 >>> 40), (byte)(h7 >>> 32), + // (byte)(h7 >>> 24), (byte)(h7 >>> 16), (byte)(h7 >>> 8), (byte) h7 + }; + } + + protected void resetContext() + { + // magic SHA-384 initialisation constants + h0 = 0xcbbb9d5dc1059ed8L; + h1 = 0x629a292a367cd507L; + h2 = 0x9159015a3070dd17L; + h3 = 0x152fecd8f70e5939L; + h4 = 0x67332667ffc00b31L; + h5 = 0x8eb44a8768581511L; + h6 = 0xdb0c2e0d64f98fa7L; + h7 = 0x47b5481dbefa4fa4L; + } + + public boolean selfTest() + { + if (valid == null) + { + Sha384 md = new Sha384(); + md.update((byte) 0x61); // a + md.update((byte) 0x62); // b + md.update((byte) 0x63); // c + String result = Util.toString(md.digest()); + valid = new Boolean(DIGEST0.equals(result)); + } + return valid.booleanValue(); + } + + // SHA specific methods ---------------------------------------------------- + + private static final synchronized long[] sha(long hh0, long hh1, long hh2, + long hh3, long hh4, long hh5, + long hh6, long hh7, byte[] in, + int offset) + { + long A = hh0; + long B = hh1; + long C = hh2; + long D = hh3; + long E = hh4; + long F = hh5; + long G = hh6; + long H = hh7; + long T, T2; + int r; + + for (r = 0; r < 16; r++) + { + w[r] = (long) in[offset++] << 56 | ((long) in[offset++] & 0xFF) << 48 + | ((long) in[offset++] & 0xFF) << 40 + | ((long) in[offset++] & 0xFF) << 32 + | ((long) in[offset++] & 0xFF) << 24 + | ((long) in[offset++] & 0xFF) << 16 + | ((long) in[offset++] & 0xFF) << 8 + | ((long) in[offset++] & 0xFF); + } + for (r = 16; r < 80; r++) + { + T = w[r - 2]; + T2 = w[r - 15]; + w[r] = (((T >>> 19) | (T << 45)) ^ ((T >>> 61) | (T << 3)) ^ (T >>> 6)) + + w[r - 7] + + (((T2 >>> 1) | (T2 << 63)) ^ ((T2 >>> 8) | (T2 << 56)) ^ (T2 >>> 7)) + + w[r - 16]; + } + + for (r = 0; r < 80; r++) + { + + T = H + + (((E >>> 14) | (E << 50)) ^ ((E >>> 18) | (E << 46)) ^ ((E >>> 41) | (E << 23))) + + ((E & F) ^ ((~E) & G)) + k[r] + w[r]; + // T IS INCORRECT SOMEHOW + T2 = (((A >>> 28) | (A << 36)) ^ ((A >>> 34) | (A << 30)) ^ ((A >>> 39) | (A << 25))) + + ((A & B) ^ (A & C) ^ (B & C)); + H = G; + G = F; + F = E; + E = D + T; + D = C; + C = B; + B = A; + A = T + T2; + } + + return new long[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, hh5 + F, + hh6 + G, hh7 + H }; + } +} diff --git a/libjava/classpath/gnu/java/security/hash/Sha512.java b/libjava/classpath/gnu/java/security/hash/Sha512.java new file mode 100644 index 0000000..798b34d --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/Sha512.java @@ -0,0 +1,322 @@ +/* Sha512.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + *Implementation of SHA2-3 [SHA-512] per the IETF Draft Specification.
+ * + *References:
+ *Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private Sha512(Sha512 md) + { + this(); + + this.h0 = md.h0; + this.h1 = md.h1; + this.h2 = md.h2; + this.h3 = md.h3; + this.h4 = md.h4; + this.h5 = md.h5; + this.h6 = md.h6; + this.h7 = md.h7; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + public static final long[] G(long hh0, long hh1, long hh2, long hh3, + long hh4, long hh5, long hh6, long hh7, + byte[] in, int offset) + { + return sha(hh0, hh1, hh2, hh3, hh4, hh5, hh6, hh7, in, offset); + } + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return new Sha512(this); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected void transform(byte[] in, int offset) + { + long[] result = sha(h0, h1, h2, h3, h4, h5, h6, h7, in, offset); + + h0 = result[0]; + h1 = result[1]; + h2 = result[2]; + h3 = result[3]; + h4 = result[4]; + h5 = result[5]; + h6 = result[6]; + h7 = result[7]; + } + + protected byte[] padBuffer() + { + int n = (int) (count % BLOCK_SIZE); + int padding = (n < 112) ? (112 - n) : (240 - n); + byte[] result = new byte[padding + 16]; + + // padding is always binary 1 followed by binary 0s + result[0] = (byte) 0x80; + + // save number of bits, casting the long to an array of 8 bytes + // TODO: FIX Only ~35 bits of 128 bit counter usable this way + long bits = count << 3; + padding += 8; + result[padding++] = (byte) (bits >>> 56); + result[padding++] = (byte) (bits >>> 48); + result[padding++] = (byte) (bits >>> 40); + result[padding++] = (byte) (bits >>> 32); + result[padding++] = (byte) (bits >>> 24); + result[padding++] = (byte) (bits >>> 16); + result[padding++] = (byte) (bits >>> 8); + result[padding] = (byte) bits; + + return result; + } + + protected byte[] getResult() + { + return new byte[] { (byte) (h0 >>> 56), (byte) (h0 >>> 48), + (byte) (h0 >>> 40), (byte) (h0 >>> 32), + (byte) (h0 >>> 24), (byte) (h0 >>> 16), + (byte) (h0 >>> 8), (byte) h0, (byte) (h1 >>> 56), + (byte) (h1 >>> 48), (byte) (h1 >>> 40), + (byte) (h1 >>> 32), (byte) (h1 >>> 24), + (byte) (h1 >>> 16), (byte) (h1 >>> 8), (byte) h1, + (byte) (h2 >>> 56), (byte) (h2 >>> 48), + (byte) (h2 >>> 40), (byte) (h2 >>> 32), + (byte) (h2 >>> 24), (byte) (h2 >>> 16), + (byte) (h2 >>> 8), (byte) h2, (byte) (h3 >>> 56), + (byte) (h3 >>> 48), (byte) (h3 >>> 40), + (byte) (h3 >>> 32), (byte) (h3 >>> 24), + (byte) (h3 >>> 16), (byte) (h3 >>> 8), (byte) h3, + (byte) (h4 >>> 56), (byte) (h4 >>> 48), + (byte) (h4 >>> 40), (byte) (h4 >>> 32), + (byte) (h4 >>> 24), (byte) (h4 >>> 16), + (byte) (h4 >>> 8), (byte) h4, (byte) (h5 >>> 56), + (byte) (h5 >>> 48), (byte) (h5 >>> 40), + (byte) (h5 >>> 32), (byte) (h5 >>> 24), + (byte) (h5 >>> 16), (byte) (h5 >>> 8), (byte) h5, + (byte) (h6 >>> 56), (byte) (h6 >>> 48), + (byte) (h6 >>> 40), (byte) (h6 >>> 32), + (byte) (h6 >>> 24), (byte) (h6 >>> 16), + (byte) (h6 >>> 8), (byte) h6, (byte) (h7 >>> 56), + (byte) (h7 >>> 48), (byte) (h7 >>> 40), + (byte) (h7 >>> 32), (byte) (h7 >>> 24), + (byte) (h7 >>> 16), (byte) (h7 >>> 8), (byte) h7 }; + } + + protected void resetContext() + { + // magic SHA-512 initialisation constants + h0 = 0x6a09e667f3bcc908L; + h1 = 0xbb67ae8584caa73bL; + h2 = 0x3c6ef372fe94f82bL; + h3 = 0xa54ff53a5f1d36f1L; + h4 = 0x510e527fade682d1L; + h5 = 0x9b05688c2b3e6c1fL; + h6 = 0x1f83d9abfb41bd6bL; + h7 = 0x5be0cd19137e2179L; + } + + public boolean selfTest() + { + if (valid == null) + { + Sha512 md = new Sha512(); + md.update((byte) 0x61); // a + md.update((byte) 0x62); // b + md.update((byte) 0x63); // c + String result = Util.toString(md.digest()); + valid = new Boolean(DIGEST0.equals(result)); + } + return valid.booleanValue(); + } + + // SHA specific methods ---------------------------------------------------- + + private static final synchronized long[] sha(long hh0, long hh1, long hh2, + long hh3, long hh4, long hh5, + long hh6, long hh7, byte[] in, + int offset) + { + long A = hh0; + long B = hh1; + long C = hh2; + long D = hh3; + long E = hh4; + long F = hh5; + long G = hh6; + long H = hh7; + long T, T2; + int r; + + for (r = 0; r < 16; r++) + { + w[r] = (long) in[offset++] << 56 | ((long) in[offset++] & 0xFF) << 48 + | ((long) in[offset++] & 0xFF) << 40 + | ((long) in[offset++] & 0xFF) << 32 + | ((long) in[offset++] & 0xFF) << 24 + | ((long) in[offset++] & 0xFF) << 16 + | ((long) in[offset++] & 0xFF) << 8 + | ((long) in[offset++] & 0xFF); + } + for (r = 16; r < 80; r++) + { + T = w[r - 2]; + T2 = w[r - 15]; + w[r] = (((T >>> 19) | (T << 45)) ^ ((T >>> 61) | (T << 3)) ^ (T >>> 6)) + + w[r - 7] + + (((T2 >>> 1) | (T2 << 63)) ^ ((T2 >>> 8) | (T2 << 56)) ^ (T2 >>> 7)) + + w[r - 16]; + } + + for (r = 0; r < 80; r++) + { + T = H + + (((E >>> 14) | (E << 50)) ^ ((E >>> 18) | (E << 46)) ^ ((E >>> 41) | (E << 23))) + + ((E & F) ^ ((~E) & G)) + k[r] + w[r]; + T2 = (((A >>> 28) | (A << 36)) ^ ((A >>> 34) | (A << 30)) ^ ((A >>> 39) | (A << 25))) + + ((A & B) ^ (A & C) ^ (B & C)); + H = G; + G = F; + F = E; + E = D + T; + D = C; + C = B; + B = A; + A = T + T2; + } + + return new long[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, hh5 + F, + hh6 + G, hh7 + H }; + } +} diff --git a/libjava/classpath/gnu/java/security/hash/Tiger.java b/libjava/classpath/gnu/java/security/hash/Tiger.java new file mode 100644 index 0000000..f39fed30 --- /dev/null +++ b/libjava/classpath/gnu/java/security/hash/Tiger.java @@ -0,0 +1,943 @@ +/* Tiger.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.hash; + +import gnu.java.security.Registry; +import gnu.java.security.util.Util; + +/** + * The Tiger message digest. Tiger was designed by Ross Anderson and Eli + * Biham, with the goal of producing a secure, fast hash function that + * performs especially well on next-generation 64-bit architectures, but + * is still efficient on 32- and 16-bit architectures. + * + *Tiger processes data in 512-bit blocks and produces a 192-bit + * digest.
+ * + *References:
+ *Whirlpool, a new 512-bit hashing function operating on messages less than + * 2 ** 256 bits in length. The function structure is designed according to the + * Wide Trail strategy and permits a wide variety of implementation trade-offs. + *
+ * + *IMPORTANT: This implementation is not thread-safe.
+ * + *References:
+ * + *Private constructor for cloning purposes.
+ * + * @param md the instance to clone. + */ + private Whirlpool(Whirlpool md) + { + this(); + + this.H0 = md.H0; + this.H1 = md.H1; + this.H2 = md.H2; + this.H3 = md.H3; + this.H4 = md.H4; + this.H5 = md.H5; + this.H6 = md.H6; + this.H7 = md.H7; + this.count = md.count; + this.buffer = (byte[]) md.buffer.clone(); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // java.lang.Cloneable interface implementation ---------------------------- + + public Object clone() + { + return (new Whirlpool(this)); + } + + // Implementation of concrete methods in BaseHash -------------------------- + + protected void transform(byte[] in, int offset) + { + // apply mu to the input + n0 = (in[offset++] & 0xFFL) << 56 | (in[offset++] & 0xFFL) << 48 + | (in[offset++] & 0xFFL) << 40 | (in[offset++] & 0xFFL) << 32 + | (in[offset++] & 0xFFL) << 24 | (in[offset++] & 0xFFL) << 16 + | (in[offset++] & 0xFFL) << 8 | (in[offset++] & 0xFFL); + n1 = (in[offset++] & 0xFFL) << 56 | (in[offset++] & 0xFFL) << 48 + | (in[offset++] & 0xFFL) << 40 | (in[offset++] & 0xFFL) << 32 + | (in[offset++] & 0xFFL) << 24 | (in[offset++] & 0xFFL) << 16 + | (in[offset++] & 0xFFL) << 8 | (in[offset++] & 0xFFL); + n2 = (in[offset++] & 0xFFL) << 56 | (in[offset++] & 0xFFL) << 48 + | (in[offset++] & 0xFFL) << 40 | (in[offset++] & 0xFFL) << 32 + | (in[offset++] & 0xFFL) << 24 | (in[offset++] & 0xFFL) << 16 + | (in[offset++] & 0xFFL) << 8 | (in[offset++] & 0xFFL); + n3 = (in[offset++] & 0xFFL) << 56 | (in[offset++] & 0xFFL) << 48 + | (in[offset++] & 0xFFL) << 40 | (in[offset++] & 0xFFL) << 32 + | (in[offset++] & 0xFFL) << 24 | (in[offset++] & 0xFFL) << 16 + | (in[offset++] & 0xFFL) << 8 | (in[offset++] & 0xFFL); + n4 = (in[offset++] & 0xFFL) << 56 | (in[offset++] & 0xFFL) << 48 + | (in[offset++] & 0xFFL) << 40 | (in[offset++] & 0xFFL) << 32 + | (in[offset++] & 0xFFL) << 24 | (in[offset++] & 0xFFL) << 16 + | (in[offset++] & 0xFFL) << 8 | (in[offset++] & 0xFFL); + n5 = (in[offset++] & 0xFFL) << 56 | (in[offset++] & 0xFFL) << 48 + | (in[offset++] & 0xFFL) << 40 | (in[offset++] & 0xFFL) << 32 + | (in[offset++] & 0xFFL) << 24 | (in[offset++] & 0xFFL) << 16 + | (in[offset++] & 0xFFL) << 8 | (in[offset++] & 0xFFL); + n6 = (in[offset++] & 0xFFL) << 56 | (in[offset++] & 0xFFL) << 48 + | (in[offset++] & 0xFFL) << 40 | (in[offset++] & 0xFFL) << 32 + | (in[offset++] & 0xFFL) << 24 | (in[offset++] & 0xFFL) << 16 + | (in[offset++] & 0xFFL) << 8 | (in[offset++] & 0xFFL); + n7 = (in[offset++] & 0xFFL) << 56 | (in[offset++] & 0xFFL) << 48 + | (in[offset++] & 0xFFL) << 40 | (in[offset++] & 0xFFL) << 32 + | (in[offset++] & 0xFFL) << 24 | (in[offset++] & 0xFFL) << 16 + | (in[offset++] & 0xFFL) << 8 | (in[offset++] & 0xFFL); + + // transform K into the key schedule Kr; 0 <= r <= R + k00 = H0; + k01 = H1; + k02 = H2; + k03 = H3; + k04 = H4; + k05 = H5; + k06 = H6; + k07 = H7; + + nn0 = n0 ^ k00; + nn1 = n1 ^ k01; + nn2 = n2 ^ k02; + nn3 = n3 ^ k03; + nn4 = n4 ^ k04; + nn5 = n5 ^ k05; + nn6 = n6 ^ k06; + nn7 = n7 ^ k07; + + // intermediate cipher output + w0 = w1 = w2 = w3 = w4 = w5 = w6 = w7 = 0L; + + for (int r = 0; r < R; r++) + { + // 1. compute intermediate round key schedule by applying ro[rc] + // to the previous round key schedule --rc being the round constant + Kr0 = T0[(int) ((k00 >> 56) & 0xFFL)] ^ T1[(int) ((k07 >> 48) & 0xFFL)] + ^ T2[(int) ((k06 >> 40) & 0xFFL)] + ^ T3[(int) ((k05 >> 32) & 0xFFL)] + ^ T4[(int) ((k04 >> 24) & 0xFFL)] + ^ T5[(int) ((k03 >> 16) & 0xFFL)] + ^ T6[(int) ((k02 >> 8) & 0xFFL)] ^ T7[(int) (k01 & 0xFFL)] + ^ rc[r]; + + Kr1 = T0[(int) ((k01 >> 56) & 0xFFL)] ^ T1[(int) ((k00 >> 48) & 0xFFL)] + ^ T2[(int) ((k07 >> 40) & 0xFFL)] + ^ T3[(int) ((k06 >> 32) & 0xFFL)] + ^ T4[(int) ((k05 >> 24) & 0xFFL)] + ^ T5[(int) ((k04 >> 16) & 0xFFL)] + ^ T6[(int) ((k03 >> 8) & 0xFFL)] ^ T7[(int) (k02 & 0xFFL)]; + + Kr2 = T0[(int) ((k02 >> 56) & 0xFFL)] ^ T1[(int) ((k01 >> 48) & 0xFFL)] + ^ T2[(int) ((k00 >> 40) & 0xFFL)] + ^ T3[(int) ((k07 >> 32) & 0xFFL)] + ^ T4[(int) ((k06 >> 24) & 0xFFL)] + ^ T5[(int) ((k05 >> 16) & 0xFFL)] + ^ T6[(int) ((k04 >> 8) & 0xFFL)] ^ T7[(int) (k03 & 0xFFL)]; + + Kr3 = T0[(int) ((k03 >> 56) & 0xFFL)] ^ T1[(int) ((k02 >> 48) & 0xFFL)] + ^ T2[(int) ((k01 >> 40) & 0xFFL)] + ^ T3[(int) ((k00 >> 32) & 0xFFL)] + ^ T4[(int) ((k07 >> 24) & 0xFFL)] + ^ T5[(int) ((k06 >> 16) & 0xFFL)] + ^ T6[(int) ((k05 >> 8) & 0xFFL)] ^ T7[(int) (k04 & 0xFFL)]; + + Kr4 = T0[(int) ((k04 >> 56) & 0xFFL)] ^ T1[(int) ((k03 >> 48) & 0xFFL)] + ^ T2[(int) ((k02 >> 40) & 0xFFL)] + ^ T3[(int) ((k01 >> 32) & 0xFFL)] + ^ T4[(int) ((k00 >> 24) & 0xFFL)] + ^ T5[(int) ((k07 >> 16) & 0xFFL)] + ^ T6[(int) ((k06 >> 8) & 0xFFL)] ^ T7[(int) (k05 & 0xFFL)]; + + Kr5 = T0[(int) ((k05 >> 56) & 0xFFL)] ^ T1[(int) ((k04 >> 48) & 0xFFL)] + ^ T2[(int) ((k03 >> 40) & 0xFFL)] + ^ T3[(int) ((k02 >> 32) & 0xFFL)] + ^ T4[(int) ((k01 >> 24) & 0xFFL)] + ^ T5[(int) ((k00 >> 16) & 0xFFL)] + ^ T6[(int) ((k07 >> 8) & 0xFFL)] ^ T7[(int) (k06 & 0xFFL)]; + + Kr6 = T0[(int) ((k06 >> 56) & 0xFFL)] ^ T1[(int) ((k05 >> 48) & 0xFFL)] + ^ T2[(int) ((k04 >> 40) & 0xFFL)] + ^ T3[(int) ((k03 >> 32) & 0xFFL)] + ^ T4[(int) ((k02 >> 24) & 0xFFL)] + ^ T5[(int) ((k01 >> 16) & 0xFFL)] + ^ T6[(int) ((k00 >> 8) & 0xFFL)] ^ T7[(int) (k07 & 0xFFL)]; + + Kr7 = T0[(int) ((k07 >> 56) & 0xFFL)] ^ T1[(int) ((k06 >> 48) & 0xFFL)] + ^ T2[(int) ((k05 >> 40) & 0xFFL)] + ^ T3[(int) ((k04 >> 32) & 0xFFL)] + ^ T4[(int) ((k03 >> 24) & 0xFFL)] + ^ T5[(int) ((k02 >> 16) & 0xFFL)] + ^ T6[(int) ((k01 >> 8) & 0xFFL)] ^ T7[(int) (k00 & 0xFFL)]; + + k00 = Kr0; + k01 = Kr1; + k02 = Kr2; + k03 = Kr3; + k04 = Kr4; + k05 = Kr5; + k06 = Kr6; + k07 = Kr7; + + // 2. incrementally compute the cipher output + w0 = T0[(int) ((nn0 >> 56) & 0xFFL)] ^ T1[(int) ((nn7 >> 48) & 0xFFL)] + ^ T2[(int) ((nn6 >> 40) & 0xFFL)] + ^ T3[(int) ((nn5 >> 32) & 0xFFL)] + ^ T4[(int) ((nn4 >> 24) & 0xFFL)] + ^ T5[(int) ((nn3 >> 16) & 0xFFL)] ^ T6[(int) ((nn2 >> 8) & 0xFFL)] + ^ T7[(int) (nn1 & 0xFFL)] ^ Kr0; + w1 = T0[(int) ((nn1 >> 56) & 0xFFL)] ^ T1[(int) ((nn0 >> 48) & 0xFFL)] + ^ T2[(int) ((nn7 >> 40) & 0xFFL)] + ^ T3[(int) ((nn6 >> 32) & 0xFFL)] + ^ T4[(int) ((nn5 >> 24) & 0xFFL)] + ^ T5[(int) ((nn4 >> 16) & 0xFFL)] ^ T6[(int) ((nn3 >> 8) & 0xFFL)] + ^ T7[(int) (nn2 & 0xFFL)] ^ Kr1; + w2 = T0[(int) ((nn2 >> 56) & 0xFFL)] ^ T1[(int) ((nn1 >> 48) & 0xFFL)] + ^ T2[(int) ((nn0 >> 40) & 0xFFL)] + ^ T3[(int) ((nn7 >> 32) & 0xFFL)] + ^ T4[(int) ((nn6 >> 24) & 0xFFL)] + ^ T5[(int) ((nn5 >> 16) & 0xFFL)] ^ T6[(int) ((nn4 >> 8) & 0xFFL)] + ^ T7[(int) (nn3 & 0xFFL)] ^ Kr2; + w3 = T0[(int) ((nn3 >> 56) & 0xFFL)] ^ T1[(int) ((nn2 >> 48) & 0xFFL)] + ^ T2[(int) ((nn1 >> 40) & 0xFFL)] + ^ T3[(int) ((nn0 >> 32) & 0xFFL)] + ^ T4[(int) ((nn7 >> 24) & 0xFFL)] + ^ T5[(int) ((nn6 >> 16) & 0xFFL)] ^ T6[(int) ((nn5 >> 8) & 0xFFL)] + ^ T7[(int) (nn4 & 0xFFL)] ^ Kr3; + w4 = T0[(int) ((nn4 >> 56) & 0xFFL)] ^ T1[(int) ((nn3 >> 48) & 0xFFL)] + ^ T2[(int) ((nn2 >> 40) & 0xFFL)] + ^ T3[(int) ((nn1 >> 32) & 0xFFL)] + ^ T4[(int) ((nn0 >> 24) & 0xFFL)] + ^ T5[(int) ((nn7 >> 16) & 0xFFL)] ^ T6[(int) ((nn6 >> 8) & 0xFFL)] + ^ T7[(int) (nn5 & 0xFFL)] ^ Kr4; + w5 = T0[(int) ((nn5 >> 56) & 0xFFL)] ^ T1[(int) ((nn4 >> 48) & 0xFFL)] + ^ T2[(int) ((nn3 >> 40) & 0xFFL)] + ^ T3[(int) ((nn2 >> 32) & 0xFFL)] + ^ T4[(int) ((nn1 >> 24) & 0xFFL)] + ^ T5[(int) ((nn0 >> 16) & 0xFFL)] ^ T6[(int) ((nn7 >> 8) & 0xFFL)] + ^ T7[(int) (nn6 & 0xFFL)] ^ Kr5; + w6 = T0[(int) ((nn6 >> 56) & 0xFFL)] ^ T1[(int) ((nn5 >> 48) & 0xFFL)] + ^ T2[(int) ((nn4 >> 40) & 0xFFL)] + ^ T3[(int) ((nn3 >> 32) & 0xFFL)] + ^ T4[(int) ((nn2 >> 24) & 0xFFL)] + ^ T5[(int) ((nn1 >> 16) & 0xFFL)] ^ T6[(int) ((nn0 >> 8) & 0xFFL)] + ^ T7[(int) (nn7 & 0xFFL)] ^ Kr6; + w7 = T0[(int) ((nn7 >> 56) & 0xFFL)] ^ T1[(int) ((nn6 >> 48) & 0xFFL)] + ^ T2[(int) ((nn5 >> 40) & 0xFFL)] + ^ T3[(int) ((nn4 >> 32) & 0xFFL)] + ^ T4[(int) ((nn3 >> 24) & 0xFFL)] + ^ T5[(int) ((nn2 >> 16) & 0xFFL)] ^ T6[(int) ((nn1 >> 8) & 0xFFL)] + ^ T7[(int) (nn0 & 0xFFL)] ^ Kr7; + + nn0 = w0; + nn1 = w1; + nn2 = w2; + nn3 = w3; + nn4 = w4; + nn5 = w5; + nn6 = w6; + nn7 = w7; + } + + // apply the Miyaguchi-Preneel hash scheme + H0 ^= w0 ^ n0; + H1 ^= w1 ^ n1; + H2 ^= w2 ^ n2; + H3 ^= w3 ^ n3; + H4 ^= w4 ^ n4; + H5 ^= w5 ^ n5; + H6 ^= w6 ^ n6; + H7 ^= w7 ^ n7; + } + + protected byte[] padBuffer() + { + // [WHIRLPOOL] p. 6: + // "...padded with a 1-bit, then with as few 0-bits as necessary to + // obtain a bit string whose length is an odd multiple of 256, and + // finally with the 256-bit right-justified binary representation of L." + // in this implementation we use 'count' as the number of bytes hashed + // so far. hence the minimal number of bytes added to the message proper + // are 33 (1 for the 1-bit followed by the 0-bits and the encoding of + // the count framed in a 256-bit block). our formula is then: + // count + 33 + padding = 0 (mod BLOCK_SIZE) + int n = (int) ((count + 33) % BLOCK_SIZE); + int padding = n == 0 ? 33 : BLOCK_SIZE - n + 33; + + byte[] result = new byte[padding]; + + // padding is always binary 1 followed by binary 0s + result[0] = (byte) 0x80; + + // save (right justified) the number of bits hashed + long bits = count * 8; + int i = padding - 8; + result[i++] = (byte) (bits >>> 56); + result[i++] = (byte) (bits >>> 48); + result[i++] = (byte) (bits >>> 40); + result[i++] = (byte) (bits >>> 32); + result[i++] = (byte) (bits >>> 24); + result[i++] = (byte) (bits >>> 16); + result[i++] = (byte) (bits >>> 8); + result[i] = (byte) bits; + + return result; + } + + protected byte[] getResult() + { + // apply inverse mu to the context + byte[] result = new byte[] { (byte) (H0 >>> 56), (byte) (H0 >>> 48), + (byte) (H0 >>> 40), (byte) (H0 >>> 32), + (byte) (H0 >>> 24), (byte) (H0 >>> 16), + (byte) (H0 >>> 8), (byte) H0, + (byte) (H1 >>> 56), (byte) (H1 >>> 48), + (byte) (H1 >>> 40), (byte) (H1 >>> 32), + (byte) (H1 >>> 24), (byte) (H1 >>> 16), + (byte) (H1 >>> 8), (byte) H1, + (byte) (H2 >>> 56), (byte) (H2 >>> 48), + (byte) (H2 >>> 40), (byte) (H2 >>> 32), + (byte) (H2 >>> 24), (byte) (H2 >>> 16), + (byte) (H2 >>> 8), (byte) H2, + (byte) (H3 >>> 56), (byte) (H3 >>> 48), + (byte) (H3 >>> 40), (byte) (H3 >>> 32), + (byte) (H3 >>> 24), (byte) (H3 >>> 16), + (byte) (H3 >>> 8), (byte) H3, + (byte) (H4 >>> 56), (byte) (H4 >>> 48), + (byte) (H4 >>> 40), (byte) (H4 >>> 32), + (byte) (H4 >>> 24), (byte) (H4 >>> 16), + (byte) (H4 >>> 8), (byte) H4, + (byte) (H5 >>> 56), (byte) (H5 >>> 48), + (byte) (H5 >>> 40), (byte) (H5 >>> 32), + (byte) (H5 >>> 24), (byte) (H5 >>> 16), + (byte) (H5 >>> 8), (byte) H5, + (byte) (H6 >>> 56), (byte) (H6 >>> 48), + (byte) (H6 >>> 40), (byte) (H6 >>> 32), + (byte) (H6 >>> 24), (byte) (H6 >>> 16), + (byte) (H6 >>> 8), (byte) H6, + (byte) (H7 >>> 56), (byte) (H7 >>> 48), + (byte) (H7 >>> 40), (byte) (H7 >>> 32), + (byte) (H7 >>> 24), (byte) (H7 >>> 16), + (byte) (H7 >>> 8), (byte) H7 }; + + return result; + } + + protected void resetContext() + { + H0 = H1 = H2 = H3 = H4 = H5 = H6 = H7 = 0L; + } + + public boolean selfTest() + { + if (valid == null) + { + valid = new Boolean( + DIGEST0.equals(Util.toString(new Whirlpool().digest()))); + } + return valid.booleanValue(); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/HavalSpi.java b/libjava/classpath/gnu/java/security/jce/hash/HavalSpi.java new file mode 100644 index 0000000..e127779 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/HavalSpi.java @@ -0,0 +1,68 @@ +/* HavalSpi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + * The implementation of theHAVAL
Service Provider Interface
+ * (SPI) Adapter.+ * + * @version Revision: $ + */ +public class HavalSpi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public HavalSpi() + { + super(Registry.HAVAL_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/MD2Spi.java b/libjava/classpath/gnu/java/security/jce/hash/MD2Spi.java new file mode 100644 index 0000000..5b6b0e1 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/MD2Spi.java @@ -0,0 +1,69 @@ +/* MD2Spi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + *
The implementation of the MD2 Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class MD2Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** Trivial 0-arguments constructor. */ + public MD2Spi() + { + super(Registry.MD2_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/MD4Spi.java b/libjava/classpath/gnu/java/security/jce/hash/MD4Spi.java new file mode 100644 index 0000000..8be4499 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/MD4Spi.java @@ -0,0 +1,69 @@ +/* MD4Spi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + *The implementation of the MD4 Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class MD4Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** Trivial 0-arguments constructor. */ + public MD4Spi() + { + super(Registry.MD4_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/MD5Spi.java b/libjava/classpath/gnu/java/security/jce/hash/MD5Spi.java new file mode 100644 index 0000000..92fb6ab --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/MD5Spi.java @@ -0,0 +1,68 @@ +/* MD5Spi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + * The implementation of the MD5 Service Provider Interface (SPI) + * adapter.+ * + * @version $Revision: 1.1 $ + */ +public class MD5Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public MD5Spi() + { + super(Registry.MD5_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/MessageDigestAdapter.java b/libjava/classpath/gnu/java/security/jce/hash/MessageDigestAdapter.java new file mode 100644 index 0000000..9b8a73d --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/MessageDigestAdapter.java @@ -0,0 +1,147 @@ +/* MessageDigestAdapter.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.hash.IMessageDigest; +import gnu.java.security.hash.HashFactory; + +import java.security.DigestException; +import java.security.MessageDigestSpi; + +/** + * The implementation of a generic {@link java.security.MessageDigest} adapter + * class to wrap gnu.crypto hash instances.
+ * + * This class defines the Service Provider Interface (SPI) for the + * {@link java.security.MessageDigest} class, which provides the functionality + * of a message digest algorithm, such as MD5 or SHA. Message digests are secure + * one-way hash functions that take arbitrary-sized data and output a fixed- + * length hash value.
+ * + * All the abstract methods in the {@link java.security.MessageDigestSpi} class + * are implemented by this class and all its sub-classes.
+ * + * All the implementations which subclass this object, and which are serviced by + * the GNU Crypto provider implement the {@link java.lang.Cloneable} interface.
+ * + * @version $Revision: 1.1 $ + */ +class MessageDigestAdapter extends MessageDigestSpi implements Cloneable +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + /** Our underlying hash instance. */ + private IMessageDigest adaptee; + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** + * Trivial protected constructor. + * + * @param mdName the canonical name of the hash algorithm. + */ + protected MessageDigestAdapter(String mdName) + { + this(HashFactory.getInstance(mdName)); + } + + /** + * Private constructor for cloning purposes. + * + * @param adaptee a clone of the underlying hash algorithm instance. + */ + private MessageDigestAdapter(IMessageDigest adaptee) + { + super(); + + this.adaptee = adaptee; + } + + // Class methods + // ------------------------------------------------------------------------- + + // java.security.MessageDigestSpi interface implementation + // ------------------------------------------------------------------------- + + public Object clone() + { + return new MessageDigestAdapter((IMessageDigest) adaptee.clone()); + } + + public int engineGetDigestLength() + { + return adaptee.hashSize(); + } + + public void engineUpdate(byte input) + { + adaptee.update(input); + } + + public void engineUpdate(byte[] input, int offset, int len) + { + adaptee.update(input, offset, len); + } + + public byte[] engineDigest() + { + return adaptee.digest(); + } + + public int engineDigest(byte[] buf, int offset, int len) + throws DigestException + { + int result = adaptee.hashSize(); + if (len < result) + { + throw new DigestException(); + } + byte[] md = adaptee.digest(); + System.arraycopy(md, 0, buf, offset, result); + return result; + } + + public void engineReset() + { + adaptee.reset(); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/RipeMD128Spi.java b/libjava/classpath/gnu/java/security/jce/hash/RipeMD128Spi.java new file mode 100644 index 0000000..b8e90d4 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/RipeMD128Spi.java @@ -0,0 +1,68 @@ +/* RipeMD128Spi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + * The implementation of the RIPEMD-128 Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class RipeMD128Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public RipeMD128Spi() + { + super(Registry.RIPEMD128_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/RipeMD160Spi.java b/libjava/classpath/gnu/java/security/jce/hash/RipeMD160Spi.java new file mode 100644 index 0000000..49615e2 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/RipeMD160Spi.java @@ -0,0 +1,68 @@ +/* RipeMD160Spi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + * The implementation of the RIPEMD-160 Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class RipeMD160Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public RipeMD160Spi() + { + super(Registry.RIPEMD160_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/Sha160Spi.java b/libjava/classpath/gnu/java/security/jce/hash/Sha160Spi.java new file mode 100644 index 0000000..a9b7263 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/Sha160Spi.java @@ -0,0 +1,68 @@ +/* Sha160Spi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + * The implementation of the SHA-1 (160-bit) Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class Sha160Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public Sha160Spi() + { + super(Registry.SHA160_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/Sha256Spi.java b/libjava/classpath/gnu/java/security/jce/hash/Sha256Spi.java new file mode 100644 index 0000000..9eeaebd --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/Sha256Spi.java @@ -0,0 +1,68 @@ +/* Sha256Spi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + *
The implementation of the SHA-2-1 (256-bit) Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class Sha256Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public Sha256Spi() + { + super(Registry.SHA256_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/Sha384Spi.java b/libjava/classpath/gnu/java/security/jce/hash/Sha384Spi.java new file mode 100644 index 0000000..96e1e6e --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/Sha384Spi.java @@ -0,0 +1,68 @@ +/* Sha384Spi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + *The implementation of the SHA-2-2 (384-bit) Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class Sha384Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public Sha384Spi() + { + super(Registry.SHA384_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/Sha512Spi.java b/libjava/classpath/gnu/java/security/jce/hash/Sha512Spi.java new file mode 100644 index 0000000..75c6170 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/Sha512Spi.java @@ -0,0 +1,68 @@ +/* Sha512Spi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + *The implementation of the SHA-2-3 (512-bit) Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class Sha512Spi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public Sha512Spi() + { + super(Registry.SHA512_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/TigerSpi.java b/libjava/classpath/gnu/java/security/jce/hash/TigerSpi.java new file mode 100644 index 0000000..b355d78 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/TigerSpi.java @@ -0,0 +1,69 @@ +/* TigerSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + *The implementation of the Tiger Service Provider Interface + * (SPI) adapter.
+ * + * @version $Revision: 1.1 $ + */ +public class TigerSpi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** Trivial 0-arguments constructor. */ + public TigerSpi() + { + super(Registry.TIGER_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/hash/WhirlpoolSpi.java b/libjava/classpath/gnu/java/security/jce/hash/WhirlpoolSpi.java new file mode 100644 index 0000000..e42e74d --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/hash/WhirlpoolSpi.java @@ -0,0 +1,68 @@ +/* WhirlpoolSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.hash; + +import gnu.java.security.Registry; + +/** + * The implementation of the Whirlpool Service Provider Interface + * (SPI) adapter.+ * + * @version $Revision: 1.1 $ + */ +public class WhirlpoolSpi extends MessageDigestAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public WhirlpoolSpi() + { + super(Registry.WHIRLPOOL_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/HavalRandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/HavalRandomSpi.java new file mode 100644 index 0000000..0c39a37 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/HavalRandomSpi.java @@ -0,0 +1,66 @@ +/* HavalRandomSpi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + * The implementation of the HAVAL-based SecureRandom Service Provider + * Interface (SPI) Adapter.
+ */ +public class HavalRandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public HavalRandomSpi() + { + super(Registry.HAVAL_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/MD2RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/MD2RandomSpi.java new file mode 100644 index 0000000..72a7f48 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/MD2RandomSpi.java @@ -0,0 +1,66 @@ +/* MD2RandomSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + * The implementation of the MD2-based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class MD2RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public MD2RandomSpi() + { + super(Registry.MD2_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/MD4RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/MD4RandomSpi.java new file mode 100644 index 0000000..f5f98f8 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/MD4RandomSpi.java @@ -0,0 +1,66 @@ +/* MD4RandomSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + * The implementation of the MD4-based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class MD4RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public MD4RandomSpi() + { + super(Registry.MD4_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/MD5RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/MD5RandomSpi.java new file mode 100644 index 0000000..0181247 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/MD5RandomSpi.java @@ -0,0 +1,66 @@ +/* MD5RandomSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + * The implementation of the MD5-based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class MD5RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public MD5RandomSpi() + { + super(Registry.MD5_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/RipeMD128RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/RipeMD128RandomSpi.java new file mode 100644 index 0000000..5580716 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/RipeMD128RandomSpi.java @@ -0,0 +1,66 @@ +/* RipeMD128RandomSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + *
The implementation of the RIPEMD128-based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class RipeMD128RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public RipeMD128RandomSpi() + { + super(Registry.RIPEMD128_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/RipeMD160RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/RipeMD160RandomSpi.java new file mode 100644 index 0000000..734fe82 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/RipeMD160RandomSpi.java @@ -0,0 +1,66 @@ +/* RipeMD160RandomSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + * The implementation of the RIPEMD160-based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class RipeMD160RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public RipeMD160RandomSpi() + { + super(Registry.RIPEMD160_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/SecureRandomAdapter.java b/libjava/classpath/gnu/java/security/jce/prng/SecureRandomAdapter.java new file mode 100644 index 0000000..e7cb720 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/SecureRandomAdapter.java @@ -0,0 +1,126 @@ +/* SecureRandomAdapter.java -- + Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.prng.LimitReachedException; +import gnu.java.security.prng.MDGenerator; + +import java.security.SecureRandomSpi; +import java.util.HashMap; + +/** + *
The implementation of a generic {@link java.security.SecureRandom} adapter + * class to wrap gnu.crypto prng instances based on Message Digest algorithms.
+ * + *This class defines the Service Provider Interface (SPI) for + * the {@link java.security.SecureRandom} class, which provides the + * functionality of a cryptographically strong pseudo-random number generator.
+ * + *All the abstract methods in the {@link SecureRandomSpi} class are + * implemented by this class and all its sub-classes.
+ */ +abstract class SecureRandomAdapter extends SecureRandomSpi +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + /** Our underlying prng instance. */ + private MDGenerator adaptee = new MDGenerator(); + + /** The name of the message digest algorithm used by the adaptee. */ + private String mdName; + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** + *Trivial protected constructor.
+ * + * @param mdName the canonical name of the underlying hash algorithm. + */ + protected SecureRandomAdapter(String mdName) + { + super(); + + this.mdName = mdName; + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // java.security.SecureRandomSpi interface implementation ------------------ + + public byte[] engineGenerateSeed(int numBytes) + { + if (numBytes < 1) + { + return new byte[0]; + } + byte[] result = new byte[numBytes]; + this.engineNextBytes(result); + return result; + } + + public void engineNextBytes(byte[] bytes) + { + if (!adaptee.isInitialised()) + { + this.engineSetSeed(new byte[0]); + } + try + { + adaptee.nextBytes(bytes, 0, bytes.length); + } + catch (LimitReachedException ignored) + { + } + } + + public void engineSetSeed(byte[] seed) + { + HashMap attributes = new HashMap(); + attributes.put(MDGenerator.MD_NAME, mdName); + attributes.put(MDGenerator.SEEED, seed); + adaptee.init(attributes); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/Sha160RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/Sha160RandomSpi.java new file mode 100644 index 0000000..c93b02d --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/Sha160RandomSpi.java @@ -0,0 +1,66 @@ +/* Sha160RandomSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + * The implementation of the SHA1-based SecureRandom Service Provider + * Interface (SPI) adapter.+ */ +public class Sha160RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public Sha160RandomSpi() + { + super(Registry.SHA160_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/Sha256RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/Sha256RandomSpi.java new file mode 100644 index 0000000..7369964 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/Sha256RandomSpi.java @@ -0,0 +1,66 @@ +/* Sha256RandomSpi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + *
The implementation of the SHA-256 based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class Sha256RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public Sha256RandomSpi() + { + super(Registry.SHA256_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/Sha384RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/Sha384RandomSpi.java new file mode 100644 index 0000000..afbf193 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/Sha384RandomSpi.java @@ -0,0 +1,66 @@ +/* Sha384RandomSpi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + *The implementation of the SHA-384 based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class Sha384RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public Sha384RandomSpi() + { + super(Registry.SHA384_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/Sha512RandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/Sha512RandomSpi.java new file mode 100644 index 0000000..b2b3377 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/Sha512RandomSpi.java @@ -0,0 +1,66 @@ +/* Sha512RandomSpi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + *The implementation of the SHA-512 based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class Sha512RandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public Sha512RandomSpi() + { + super(Registry.SHA512_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/TigerRandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/TigerRandomSpi.java new file mode 100644 index 0000000..b4795b9 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/TigerRandomSpi.java @@ -0,0 +1,66 @@ +/* TigerRandomSpi.java -- + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + * The implementation of the Tiger based SecureRandom Service Provider + * Interface (SPI) adapter.+ */ +public class TigerRandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public TigerRandomSpi() + { + super(Registry.TIGER_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java b/libjava/classpath/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java new file mode 100644 index 0000000..f327f9d --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java @@ -0,0 +1,66 @@ +/* WhirlpoolRandomSpi.java -- + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.prng; + +import gnu.java.security.Registry; + +/** + * The implementation of the Whirlpool-based SecureRandom Service Provider + * Interface (SPI) adapter.
+ */ +public class WhirlpoolRandomSpi extends SecureRandomAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public WhirlpoolRandomSpi() + { + super(Registry.WHIRLPOOL_HASH); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/DSSKeyFactory.java b/libjava/classpath/gnu/java/security/jce/sig/DSSKeyFactory.java new file mode 100644 index 0000000..bb4d85c --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/DSSKeyFactory.java @@ -0,0 +1,238 @@ +/* DSSKeyFactory.java -- JCE DSA key factory Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.key.dss.DSSKeyPairPKCS8Codec; +import gnu.java.security.key.dss.DSSKeyPairX509Codec; +import gnu.java.security.key.dss.DSSPrivateKey; +import gnu.java.security.key.dss.DSSPublicKey; + +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.KeyFactorySpi; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.interfaces.DSAPrivateKey; +import java.security.interfaces.DSAPublicKey; +import java.security.spec.DSAPrivateKeySpec; +import java.security.spec.DSAPublicKeySpec; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +/** + * DSA key factory. + * + * @author Casey Marshall (rsdio@metastatic.org) + */ +public class DSSKeyFactory extends KeyFactorySpi +{ + // implicit 0-arguments constructor + + protected PublicKey engineGeneratePublic(KeySpec keySpec) + throws InvalidKeySpecException + { + if (keySpec instanceof DSAPublicKeySpec) + { + DSAPublicKeySpec spec = (DSAPublicKeySpec) keySpec; + BigInteger p = spec.getP(); + BigInteger q = spec.getQ(); + BigInteger g = spec.getG(); + BigInteger y = spec.getY(); + return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y); + } + + if (keySpec instanceof X509EncodedKeySpec) + { + X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec; + byte[] encoded = spec.getEncoded(); + PublicKey result; + try + { + result = new DSSKeyPairX509Codec().decodePublicKey(encoded); + return result; + } + catch (RuntimeException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + throw new InvalidKeySpecException("Unsupported (public) key specification"); + } + + protected PrivateKey engineGeneratePrivate(KeySpec keySpec) + throws InvalidKeySpecException + { + if (keySpec instanceof DSAPrivateKeySpec) + { + DSAPrivateKeySpec spec = (DSAPrivateKeySpec) keySpec; + BigInteger p = spec.getP(); + BigInteger q = spec.getQ(); + BigInteger g = spec.getG(); + BigInteger x = spec.getX(); + return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x); + } + + if (keySpec instanceof PKCS8EncodedKeySpec) + { + PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec; + byte[] encoded = spec.getEncoded(); + PrivateKey result; + try + { + result = new DSSKeyPairPKCS8Codec().decodePrivateKey(encoded); + return result; + } + catch (RuntimeException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + throw new InvalidKeySpecException("Unsupported (private) key specification"); + } + + protected KeySpec engineGetKeySpec(Key key, Class keySpec) + throws InvalidKeySpecException + { + if (key instanceof DSAPublicKey) + { + if (keySpec.isAssignableFrom(DSAPublicKeySpec.class)) + { + DSAPublicKey dsaKey = (DSAPublicKey) key; + BigInteger p = dsaKey.getParams().getP(); + BigInteger q = dsaKey.getParams().getQ(); + BigInteger g = dsaKey.getParams().getG(); + BigInteger y = dsaKey.getY(); + return new DSAPublicKeySpec(y, p, q, g); + } + + if (keySpec.isAssignableFrom(X509EncodedKeySpec.class)) + { + if (key instanceof DSSPublicKey) + { + DSSPublicKey dssKey = (DSSPublicKey) key; + byte[] encoded = dssKey.getEncoded(Registry.X509_ENCODING_ID); + return new X509EncodedKeySpec(encoded); + } + + if (Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat())) + { + byte[] encoded = key.getEncoded(); + return new X509EncodedKeySpec(encoded); + } + + throw new InvalidKeySpecException("Wrong key type or unsupported (public) key specification"); + } + + throw new InvalidKeySpecException("Unsupported (public) key specification"); + } + + if (key instanceof DSAPrivateKey) + { + if (keySpec.isAssignableFrom(DSAPrivateKeySpec.class)) + { + DSAPrivateKey dsaKey = (DSAPrivateKey) key; + BigInteger p = dsaKey.getParams().getP(); + BigInteger q = dsaKey.getParams().getQ(); + BigInteger g = dsaKey.getParams().getG(); + BigInteger x = dsaKey.getX(); + return new DSAPrivateKeySpec(x, p, q, g); + } + + if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class)) + { + if (key instanceof DSSPrivateKey) + { + DSSPrivateKey dssKey = (DSSPrivateKey) key; + byte[] encoded = dssKey.getEncoded(Registry.PKCS8_ENCODING_ID); + return new PKCS8EncodedKeySpec(encoded); + } + + if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat())) + { + byte[] encoded = key.getEncoded(); + return new PKCS8EncodedKeySpec(encoded); + } + + throw new InvalidKeySpecException("Wrong key type or unsupported (private) key specification"); + } + + throw new InvalidKeySpecException("Unsupported (private) key specification"); + } + + throw new InvalidKeySpecException("Wrong key type or unsupported key specification"); + } + + protected Key engineTranslateKey(Key key) throws InvalidKeyException + { + if ((key instanceof DSSPublicKey) || (key instanceof DSSPrivateKey)) + return key; + + if (key instanceof DSAPublicKey) + { + DSAPublicKey dsaKey = (DSAPublicKey) key; + BigInteger p = dsaKey.getParams().getP(); + BigInteger q = dsaKey.getParams().getQ(); + BigInteger g = dsaKey.getParams().getG(); + BigInteger y = dsaKey.getY(); + return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y); + } + + if (key instanceof DSAPrivateKey) + { + DSAPrivateKey dsaKey = (DSAPrivateKey) key; + BigInteger p = dsaKey.getParams().getP(); + BigInteger q = dsaKey.getParams().getQ(); + BigInteger g = dsaKey.getParams().getG(); + BigInteger x = dsaKey.getX(); + return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x); + } + + throw new InvalidKeyException("Wrong key type"); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java b/libjava/classpath/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java new file mode 100644 index 0000000..97e9594 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java @@ -0,0 +1,169 @@ +/* DSSKeyPairGeneratorSpi.java -- + Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.key.dss.DSSKeyPairGenerator; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidParameterException; +import java.security.SecureRandom; +import java.security.interfaces.DSAKeyPairGenerator; +import java.security.interfaces.DSAParams; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.DSAParameterSpec; +import java.util.HashMap; + +/** + * The implementation of a {@link java.security.KeyPairGenerator} adapter class + * to wrap gnu.crypto DSS keypair generator instances.
+ *
+ * In case the client does not explicitly initialize the KeyPairGenerator (via
+ * a call to an initialize()
method), the GNU Crypto provider
+ * uses a default modulus size (keysize) of 1024 bits.
+ *
+ * @version $Revision: 1.3 $
+ */
+public class DSSKeyPairGeneratorSpi extends KeyPairGeneratorAdapter implements
+ DSAKeyPairGenerator
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ public DSSKeyPairGeneratorSpi()
+ {
+ super(Registry.DSS_KPG);
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ public void initialize(int keysize, SecureRandom random)
+ {
+ this.initialize(keysize, false, random);
+ }
+
+ public void initialize(AlgorithmParameterSpec params, SecureRandom random)
+ throws InvalidAlgorithmParameterException
+ {
+ HashMap attributes = new HashMap();
+ if (params != null)
+ {
+ if (!(params instanceof DSAParameterSpec))
+ throw new InvalidAlgorithmParameterException(
+ "Parameters argument is not a non-null instance, or " +
+ "sub-instance, of java.security.spec.DSAParameterSpec");
+
+ attributes.put(DSSKeyPairGenerator.DSS_PARAMETERS, params);
+ }
+
+ if (random != null)
+ {
+ attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
+ }
+
+ attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
+ new Integer(Registry.ASN1_ENCODING_ID));
+ try
+ {
+ adaptee.setup(attributes);
+ }
+ catch (IllegalArgumentException x)
+ {
+ InvalidAlgorithmParameterException y =
+ new InvalidAlgorithmParameterException();
+ y.initCause(x);
+ throw y;
+ }
+ }
+
+ // java.security.interfaces.DSAKeyPairGenerator interface implementation -----
+
+ public void initialize(DSAParams params, SecureRandom random)
+ throws InvalidParameterException
+ {
+ if (params == null || !(params instanceof DSAParameterSpec))
+ throw new InvalidParameterException(
+ "Parameters argument is either null or is not an instance, or " +
+ "sub-instance, of java.security.spec.DSAParameterSpec");
+ DSAParameterSpec spec = (DSAParameterSpec) params;
+ try
+ {
+ this.initialize((AlgorithmParameterSpec) spec, random);
+ }
+ catch (InvalidAlgorithmParameterException x)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(x);
+ throw y;
+ }
+ }
+
+ public void initialize(int modlen, boolean genParams, SecureRandom random)
+ throws InvalidParameterException
+ {
+ HashMap attributes = new HashMap();
+ attributes.put(DSSKeyPairGenerator.MODULUS_LENGTH, new Integer(modlen));
+ if (random != null)
+ attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
+
+ attributes.put(DSSKeyPairGenerator.USE_DEFAULTS,
+ Boolean.valueOf(!genParams));
+ attributes.put(DSSKeyPairGenerator.STRICT_DEFAULTS, Boolean.TRUE);
+ attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
+ new Integer(Registry.ASN1_ENCODING_ID));
+ try
+ {
+ adaptee.setup(attributes);
+ }
+ catch (IllegalArgumentException x)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(x);
+ throw y;
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/jce/sig/DSSParameters.java b/libjava/classpath/gnu/java/security/jce/sig/DSSParameters.java
new file mode 100644
index 0000000..ba1f414
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/jce/sig/DSSParameters.java
@@ -0,0 +1,220 @@
+/* DSSParameters.java -- DSS parameters DAO
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.jce.sig;
+
+import gnu.java.security.Registry;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+import gnu.java.security.der.DERWriter;
+import gnu.java.security.util.DerUtil;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.AlgorithmParametersSpi;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.DSAParameterSpec;
+import java.security.spec.InvalidParameterSpecException;
+import java.util.ArrayList;
+
+/**
+ * A JCE-specific Data Access Object (DAO) for DSS parameters.
+ */
+public class DSSParameters
+ extends AlgorithmParametersSpi
+{
+ /**
+ * A prime modulus, where 2L-1 < p < 2L
+ * for 512 <= L <= 1024
and L
a multiple of
+ * 64
.
+ */
+ private BigInteger p;
+
+ /**
+ * A prime divisor of p - 1
, where 2159 < q
+ * < 2160
.
+ */
+ private BigInteger q;
+
+ /**
+ * g = h(p-1)/q mod p
, where h
is any
+ * integer with 1 < h < p - 1
such that h
+ * (p-1)/q mod p > 1
(g
has order q mod p
+ *
).
+ */
+ private BigInteger g;
+
+ // default 0-arguments constructor
+
+ protected void engineInit(AlgorithmParameterSpec spec)
+ throws InvalidParameterSpecException
+ {
+ if (! (spec instanceof DSAParameterSpec))
+ throw new InvalidParameterSpecException("Wrong AlgorithmParameterSpec type: "
+ + spec.getClass().getName());
+ DSAParameterSpec dsaSpec = (DSAParameterSpec) spec;
+ p = dsaSpec.getP();
+ q = dsaSpec.getQ();
+ g = dsaSpec.getG();
+ }
+
+ /**
+ * Decodes the set of DSS parameters as per RFC-2459; i.e. the DER-encoded
+ * form of the following ASN.1 construct:
+ *
+ *
+ * DssParams ::= SEQUENCE { + * p INTEGER, + * q INTEGER, + * g INTEGER + * } + *+ */ + protected void engineInit(byte[] params) throws IOException + { + DERReader der = new DERReader(params); + + DERValue derParams = der.read(); + DerUtil.checkIsConstructed(derParams, "Wrong DSS Parameters field"); + + DERValue val = der.read(); + DerUtil.checkIsBigInteger(val, "Wrong P field"); + p = (BigInteger) val.getValue(); + val = der.read(); + DerUtil.checkIsBigInteger(val, "Wrong Q field"); + q = (BigInteger) val.getValue(); + val = der.read(); + DerUtil.checkIsBigInteger(val, "Wrong G field"); + g = (BigInteger) val.getValue(); + } + + protected void engineInit(byte[] params, String format) throws IOException + { + if (format != null) + { + format = format.trim(); + if (format.length() == 0) + throw new IOException("Format MUST NOT be an empty string"); + + if (! format.equalsIgnoreCase(Registry.ASN1_ENCODING_SHORT_NAME)) + throw new IOException("Unknown or unsupported format: " + format); + } + + engineInit(params); + } + + protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) + throws InvalidParameterSpecException + { + if (! paramSpec.isAssignableFrom(DSAParameterSpec.class)) + throw new InvalidParameterSpecException("Wrong AlgorithmParameterSpec type: " + + paramSpec.getName()); + return new DSAParameterSpec(p, q, g); + } + + /** + * Encodes the set of DSS parameters as per RFC-2459; i.e. as the DER-encoded + * form of the following ASN.1 construct: + * + *
+ * DssParams ::= SEQUENCE { + * p INTEGER, + * q INTEGER, + * g INTEGER + * } + *+ */ + protected byte[] engineGetEncoded() throws IOException + { + DERValue derP = new DERValue(DER.INTEGER, p); + DERValue derQ = new DERValue(DER.INTEGER, q); + DERValue derG = new DERValue(DER.INTEGER, g); + + ArrayList params = new ArrayList(3); + params.add(derP); + params.add(derQ); + params.add(derG); + DERValue derParams = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, params); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DERWriter.write(baos, derParams); + byte[] result = baos.toByteArray(); + + return result; + } + + protected byte[] engineGetEncoded(String format) throws IOException + { + if (format != null) + { + format = format.trim(); + if (format.length() == 0) + throw new IOException("Format MUST NOT be an empty string"); + + if (! format.equalsIgnoreCase(Registry.ASN1_ENCODING_SHORT_NAME)) + throw new IOException("Unknown or unsupported format: " + format); + } + + return engineGetEncoded(); + } + + protected String engineToString() + { + StringBuffer sb = new StringBuffer("p="); + if (p == null) + sb.append("???"); + else + sb.append("0x").append(p.toString(16)); + + sb.append(", q="); + if (q == null) + sb.append("???"); + else + sb.append("0x").append(q.toString(16)); + + sb.append(", g="); + if (g == null) + sb.append("???"); + else + sb.append("0x").append(g.toString(16)); + + return sb.toString(); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/DSSParametersGenerator.java b/libjava/classpath/gnu/java/security/jce/sig/DSSParametersGenerator.java new file mode 100644 index 0000000..09c1386 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/DSSParametersGenerator.java @@ -0,0 +1,125 @@ +/* DSSParametersGenerator.java -- JCE Adapter for a generator of DSS parameters + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.key.dss.DSSKeyPairGenerator; +import gnu.java.security.key.dss.FIPS186; +import gnu.java.security.provider.Gnu; + +import java.math.BigInteger; +import java.security.AlgorithmParameterGeneratorSpi; +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.Provider; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.DSAParameterSpec; +import java.security.spec.InvalidParameterSpecException; + +/** + * A JCE Adapter for a generator of DSS parameters. + */ +public class DSSParametersGenerator + extends AlgorithmParameterGeneratorSpi +{ + private static final Provider GNU = new Gnu(); + + /** Size of the public modulus in bits. */ + private int modulusLength = -1; + + /** User specified source of randomness. */ + private SecureRandom rnd; + + /** Our concrete DSS parameters generator. */ + private FIPS186 fips; + + // default 0-arguments constructor + + protected void engineInit(int size, SecureRandom random) + { + if ((size % 64) != 0 || size < 512 || size > 1024) + throw new InvalidParameterException("Modulus size/length (in bits) MUST " + + "be a multiple of 64, greater than " + + "or equal to 512, and less than or " + + "equal to 1024"); + this.modulusLength = size; + this.rnd = random; + } + + protected void engineInit(AlgorithmParameterSpec spec, SecureRandom random) + throws InvalidAlgorithmParameterException + { + if (! (spec instanceof DSAParameterSpec)) + throw new InvalidAlgorithmParameterException("Wrong AlgorithmParameterSpec type: " + + spec.getClass().getName()); + DSAParameterSpec dsaSpec = (DSAParameterSpec) spec; + BigInteger p = dsaSpec.getP(); + int size = p.bitLength(); + this.engineInit(size, random); + } + + protected AlgorithmParameters engineGenerateParameters() + { + if (modulusLength < 1) + modulusLength = DSSKeyPairGenerator.DEFAULT_MODULUS_LENGTH; + + fips = new FIPS186(modulusLength, rnd); + BigInteger[] params = fips.generateParameters(); + BigInteger p = params[3]; + BigInteger q = params[2]; + BigInteger g = params[5]; + DSAParameterSpec spec = new DSAParameterSpec(p, q, g); + AlgorithmParameters result = null; + try + { + result = AlgorithmParameters.getInstance(Registry.DSS_KPG, GNU); + result.init(spec); + } + catch (NoSuchAlgorithmException ignore) + { + } + catch (InvalidParameterSpecException ignore) + { + } + return result; + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/DSSRawSignatureSpi.java b/libjava/classpath/gnu/java/security/jce/sig/DSSRawSignatureSpi.java new file mode 100644 index 0000000..16e4ddd --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/DSSRawSignatureSpi.java @@ -0,0 +1,70 @@ +/* DSSRawSignatureSpi.java -- + Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.dss.DSSSignatureRawCodec; + +/** + * The implementation of Service Provider Interface (SPI) adapter + * for the DSS (Digital Signature Standard) signature scheme, encoded and/or + * decoded in RAW format.
+ * + * @version $Revision: 1.1 $ + */ +public class DSSRawSignatureSpi extends SignatureAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public DSSRawSignatureSpi() + { + super(Registry.DSS_SIG, new DSSSignatureRawCodec()); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/EncodedKeyFactory.java b/libjava/classpath/gnu/java/security/jce/sig/EncodedKeyFactory.java new file mode 100644 index 0000000..60152c2 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/EncodedKeyFactory.java @@ -0,0 +1,453 @@ +/* EncodedKeyFactory.java -- JCE Encoded key factory Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.key.dss.DSSPrivateKey; +import gnu.java.security.key.dss.DSSPublicKey; +import gnu.java.security.key.rsa.GnuRSAPrivateKey; +import gnu.java.security.key.rsa.GnuRSAPublicKey; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.InvalidParameterException; +import java.security.Key; +import java.security.KeyFactorySpi; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.DSAPrivateKeySpec; +import java.security.spec.DSAPublicKeySpec; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.RSAPrivateCrtKeySpec; +import java.security.spec.RSAPublicKeySpec; +import java.security.spec.X509EncodedKeySpec; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.crypto.interfaces.DHPrivateKey; +import javax.crypto.interfaces.DHPublicKey; +import javax.crypto.spec.DHPrivateKeySpec; +import javax.crypto.spec.DHPublicKeySpec; + +/** + * A factory for keys encoded in either the X.509 format (for public keys) or + * the PKCS#8 format (for private keys). + */ +public class EncodedKeyFactory + extends KeyFactorySpi +{ + private static final Logger log = Logger.getLogger(EncodedKeyFactory.class.getName()); + + // implicit 0-arguments constructor + + // Class methods + // -------------------------------------------------------------------------- + + private static Object invokeConstructor(String className, Object[] params) + throws InvalidKeySpecException + { + Class clazz = getConcreteClass(className); + try + { + Constructor ctor = getConcreteCtor(clazz); + Object result = ctor.newInstance(params); + return result; + } + catch (InstantiationException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + catch (IllegalAccessException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(y); + throw y; + } + catch (InvocationTargetException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + private static Class getConcreteClass(String className) + throws InvalidKeySpecException + { + try + { + Class result = Class.forName(className); + return result; + } + catch (ClassNotFoundException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + private static Constructor getConcreteCtor(Class clazz) + throws InvalidKeySpecException + { + try + { + Constructor result = clazz.getConstructor(new Class[] {int.class, + BigInteger.class, + BigInteger.class, + BigInteger.class, + BigInteger.class}); + return result; + } + catch (NoSuchMethodException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + private static Object invokeValueOf(String className, byte[] encoded) + throws InvalidKeySpecException + { + Class clazz = getConcreteClass(className); + try + { + Method valueOf = getValueOfMethod(clazz); + Object result = valueOf.invoke(null, new Object[] { encoded }); + return result; + } + catch (IllegalAccessException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + catch (InvocationTargetException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + private static Method getValueOfMethod(Class clazz) + throws InvalidKeySpecException + { + try + { + Method result = clazz.getMethod("valueOf", new Class[] {byte[].class}); + return result; + } + catch (NoSuchMethodException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + // Instance methods + // -------------------------------------------------------------------------- + + protected PublicKey engineGeneratePublic(KeySpec keySpec) + throws InvalidKeySpecException + { + log.entering(this.getClass().getName(), "engineGeneratePublic()", keySpec); + + PublicKey result = null; + if (keySpec instanceof DSAPublicKeySpec) + result = decodeDSSPublicKey((DSAPublicKeySpec) keySpec); + else if (keySpec instanceof RSAPublicKeySpec) + result = decodeRSAPublicKey((RSAPublicKeySpec) keySpec); + else if (keySpec instanceof DHPublicKeySpec) + result = decodeDHPublicKey((DHPublicKeySpec) keySpec); + else + { + if (! (keySpec instanceof X509EncodedKeySpec)) + throw new InvalidKeySpecException("Unsupported key specification"); + + byte[] input = ((X509EncodedKeySpec) keySpec).getEncoded(); + boolean ok = false; + // try DSS + try + { + result = DSSPublicKey.valueOf(input); + ok = true; + } + catch (InvalidParameterException ignored) + { + log.log(Level.FINE, "Exception in DSSPublicKey.valueOf(). Ignore", + ignored); + } + + if (! ok) // try RSA + try + { + result = GnuRSAPublicKey.valueOf(input); + ok = true; + } + catch (InvalidParameterException ignored) + { + log.log(Level.FINE, + "Exception in GnuRSAPublicKey.valueOf(). Ignore", + ignored); + } + + if (! ok) // try DH + result = decodeDHPublicKey(input); + } + + log.exiting(this.getClass().getName(), "engineGeneratePublic()", result); + return result; + } + + protected PrivateKey engineGeneratePrivate(KeySpec keySpec) + throws InvalidKeySpecException + { + log.entering(this.getClass().getName(), "engineGeneratePrivate()", keySpec); + + PrivateKey result = null; + if (keySpec instanceof DSAPrivateKeySpec) + result = decodeDSSPrivateKey((DSAPrivateKeySpec) keySpec); + else if (keySpec instanceof RSAPrivateCrtKeySpec) + result = decodeRSAPrivateKey((RSAPrivateCrtKeySpec) keySpec); + else if (keySpec instanceof DHPrivateKeySpec) + result = decodeDHPrivateKey((DHPrivateKeySpec) keySpec); + else + { + if (! (keySpec instanceof PKCS8EncodedKeySpec)) + throw new InvalidKeySpecException("Unsupported key specification"); + + byte[] input = ((PKCS8EncodedKeySpec) keySpec).getEncoded(); + boolean ok = false; + // try DSS + try + { + result = DSSPrivateKey.valueOf(input); + ok = true; + } + catch (InvalidParameterException ignored) + { + log.log(Level.FINE, "Exception in DSSPrivateKey.valueOf(). Ignore", + ignored); + } + + if (! ok) // try RSA + try + { + result = GnuRSAPrivateKey.valueOf(input); + ok = true; + } + catch (InvalidParameterException ignored) + { + log.log(Level.FINE, + "Exception in GnuRSAPrivateKey.valueOf(). Ignore", + ignored); + } + + if (! ok) // try DH + result = decodeDHPrivateKey(input); + } + + log.exiting(this.getClass().getName(), "engineGeneratePrivate()", result); + return result; + } + + protected KeySpec engineGetKeySpec(Key key, Class keySpec) + throws InvalidKeySpecException + { + if (key instanceof PublicKey + && Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat()) + && keySpec.isAssignableFrom(X509EncodedKeySpec.class)) + return new X509EncodedKeySpec(key.getEncoded()); + + if (key instanceof PrivateKey + && Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat()) + && keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class)) + return new PKCS8EncodedKeySpec(key.getEncoded()); + + throw new InvalidKeySpecException("Unsupported format or invalid key spec class"); + } + + protected Key engineTranslateKey(Key key) throws InvalidKeyException + { + throw new InvalidKeyException("Key translation not supported"); + } + + /** + * @param spec an instance of {@link DSAPublicKeySpec} to decode. + * @return an instance of {@link DSSPublicKey} constructed from the + * information in the designated key-specification. + */ + private DSSPublicKey decodeDSSPublicKey(DSAPublicKeySpec spec) + { + BigInteger p = spec.getP(); + BigInteger q = spec.getQ(); + BigInteger g = spec.getG(); + BigInteger y = spec.getY(); + return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y); + } + + /** + * @param spec an instance of {@link RSAPublicKeySpec} to decode. + * @return an instance of {@link GnuRSAPublicKey} constructed from the + * information in the designated key-specification. + */ + private GnuRSAPublicKey decodeRSAPublicKey(RSAPublicKeySpec spec) + { + BigInteger n = spec.getModulus(); + BigInteger e = spec.getPublicExponent(); + return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e); + } + + /** + * @param spec an instance of {@link DHPublicKeySpec} to decode. + * @return an instance of a {@link DHPublicKey} constructed from the + * information in the designated key-specification. + * @throws InvalidKeySpecException if no concrete implementation of the + * {@link DHPublicKey} interface exists at run-time, or if an + * exception occurs during its instantiation. + */ + private DHPublicKey decodeDHPublicKey(DHPublicKeySpec spec) + throws InvalidKeySpecException + { + BigInteger p = spec.getP(); + BigInteger g = spec.getG(); + BigInteger y = spec.getY(); + Object[] params = new Object[] {new Integer(Registry.X509_ENCODING_ID), + null, p, g, y}; + Object obj = invokeConstructor("gnu.javax.crypto.key.dh.GnuDHPublicKey", + params); + return (DHPublicKey) obj; + } + + /** + * @param encoded the bytes to decode. + * @return an instance of a {@link DHPublicKey} constructed from the + * information in the designated key-specification. + * @throws InvalidKeySpecException if no concrete implementation of the + * {@link DHPublicKey} interface exists at run-time, or if an + * exception occurs during its instantiation. + */ + private DHPublicKey decodeDHPublicKey(byte[] encoded) + throws InvalidKeySpecException + { + Object obj = invokeValueOf("gnu.javax.crypto.key.dh.GnuDHPublicKey", + encoded); + return (DHPublicKey) obj; + } + + /** + * @param spec an instance of {@link DSAPrivateKeySpec} to decode. + * @return an instance of {@link DSSPrivateKey} constructed from the + * information in the designated key-specification. + */ + private PrivateKey decodeDSSPrivateKey(DSAPrivateKeySpec spec) + { + BigInteger p = spec.getP(); + BigInteger q = spec.getQ(); + BigInteger g = spec.getG(); + BigInteger x = spec.getX(); + return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x); + } + + /** + * @param spec an instance of {@link RSAPrivateCrtKeySpec} to decode. + * @return an instance of {@link GnuRSAPrivateKey} constructed from the + * information in the designated key-specification. + */ + private PrivateKey decodeRSAPrivateKey(RSAPrivateCrtKeySpec spec) + { + BigInteger n = spec.getModulus(); + BigInteger e = spec.getPublicExponent(); + BigInteger d = spec.getPrivateExponent(); + BigInteger p = spec.getPrimeP(); + BigInteger q = spec.getPrimeQ(); + BigInteger dP = spec.getPrimeExponentP(); + BigInteger dQ = spec.getPrimeExponentQ(); + BigInteger qInv = spec.getCrtCoefficient(); + return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID, + n, e, d, p, q, dP, dQ, qInv); + } + + /** + * @param spec an instance of {@link DHPrivateKeySpec} to decode. + * @return an instance of a {@link DHPrivateKey} constructed from the + * information in the designated key-specification. + * @throws InvalidKeySpecException if no concrete implementation of the + * {@link DHPrivateKey} interface exists at run-time, or if an + * exception occurs during its instantiation. + */ + private DHPrivateKey decodeDHPrivateKey(DHPrivateKeySpec spec) + throws InvalidKeySpecException + { + BigInteger p = spec.getP(); + BigInteger g = spec.getG(); + BigInteger x = spec.getX(); + Object[] params = new Object[] {new Integer(Registry.PKCS8_ENCODING_ID), + null, p, g, x}; + Object obj = invokeConstructor("gnu.javax.crypto.key.dh.GnuDHPrivateKey", + params); + return (DHPrivateKey) obj; + } + + /** + * @param encoded the bytes to decode. + * @return an instance of a {@link DHPrivateKey} constructed from the + * information in the designated key-specification. + * @throws InvalidKeySpecException if no concrete implementation of the + * {@link DHPrivateKey} interface exists at run-time, or if an + * exception occurs during its instantiation. + */ + private DHPrivateKey decodeDHPrivateKey(byte[] encoded) + throws InvalidKeySpecException + { + Object obj = invokeValueOf("gnu.javax.crypto.key.dh.GnuDHPrivateKey", + encoded); + return (DHPrivateKey) obj; + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java b/libjava/classpath/gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java new file mode 100644 index 0000000..6026829 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java @@ -0,0 +1,109 @@ +/* KeyPairGeneratorAdapter.java -- + Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.key.IKeyPairGenerator; +import gnu.java.security.key.KeyPairGeneratorFactory; + +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +/** + * The implementation of a generic {@link java.security.KeyPairGenerator} + * adapter class to wrap gnu.crypto keypair generator instances.
+ * + * This class defines the Service Provider Interface (SPI) for the + * {@link java.security.KeyPairGenerator} class, which is used to generate pairs + * of public and private keys.
+ * + * All the abstract methods in the {@link java.security.KeyPairGeneratorSpi} + * class are implemented by this class and all its sub-classes.
+ *
+ * In case the client does not explicitly initialize the KeyPairGenerator (via
+ * a call to an initialize()
method), the GNU Crypto provider
+ * supplies (and document) default values to be used. For example, the GNU
+ * Crypto provider uses a default modulus size (keysize) of 1024 bits for
+ * the DSS (Digital Signature Standard) a.k.a DSA.
+ * + * @version $Revision: 1.3 $ + */ +public abstract class KeyPairGeneratorAdapter extends KeyPairGenerator +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + /** Our underlying keypair instance. */ + protected IKeyPairGenerator adaptee; + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** + * Trivial protected constructor. + * + * @param kpgName the canonical name of the keypair generator algorithm. + */ + protected KeyPairGeneratorAdapter(String kpgName) + { + super(kpgName); + + this.adaptee = KeyPairGeneratorFactory.getInstance(kpgName); + } + + // Class methods + // ------------------------------------------------------------------------- + + // java.security.KeyPairGeneratorSpi interface implementation + // ------------------------------------------------------------------------- + + public abstract void initialize(int keysize, SecureRandom random); + + public abstract void initialize(AlgorithmParameterSpec params, + SecureRandom random) + throws InvalidAlgorithmParameterException; + + public KeyPair generateKeyPair() + { + return adaptee.generate(); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/MD2withRSA.java b/libjava/classpath/gnu/java/security/jce/sig/MD2withRSA.java new file mode 100644 index 0000000..353be21 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/MD2withRSA.java @@ -0,0 +1,56 @@ +/* MD2WithRSA.java -- RSA PKCS1 with MD2 JCE signature Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.rsa.RSAPKCS1V1_5SignatureX509Codec; + +/** + * A JCE Adapter for the RSA PKCS1 (v1.5) signature with MD2 hash and X.509 + * encoding format. + */ +public class MD2withRSA + extends SignatureAdapter +{ + public MD2withRSA() + { + super(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.MD2_HASH, + new RSAPKCS1V1_5SignatureX509Codec()); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/MD5withRSA.java b/libjava/classpath/gnu/java/security/jce/sig/MD5withRSA.java new file mode 100644 index 0000000..42c481b --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/MD5withRSA.java @@ -0,0 +1,56 @@ +/* MD5withRSA.java -- RSA PKCS1 with MD5 JCE signature Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.rsa.RSAPKCS1V1_5SignatureX509Codec; + +/** + * A JCE Adapter for the RSA PKCS1 (v1.5) signature with MD5 hash and X.509 + * encoding format. + */ +public class MD5withRSA + extends SignatureAdapter +{ + public MD5withRSA() + { + super(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.MD5_HASH, + new RSAPKCS1V1_5SignatureX509Codec()); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/RSAKeyFactory.java b/libjava/classpath/gnu/java/security/jce/sig/RSAKeyFactory.java new file mode 100644 index 0000000..fecf54c --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/RSAKeyFactory.java @@ -0,0 +1,265 @@ +/* RSAKeyFactory.java -- RSA key-factory JCE Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.key.rsa.GnuRSAPrivateKey; +import gnu.java.security.key.rsa.GnuRSAPublicKey; +import gnu.java.security.key.rsa.RSAKeyPairPKCS8Codec; +import gnu.java.security.key.rsa.RSAKeyPairX509Codec; + +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.KeyFactorySpi; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.interfaces.RSAPrivateCrtKey; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.RSAPrivateCrtKeySpec; +import java.security.spec.RSAPrivateKeySpec; +import java.security.spec.RSAPublicKeySpec; +import java.security.spec.X509EncodedKeySpec; + +public class RSAKeyFactory + extends KeyFactorySpi +{ + // implicit 0-arguments constructor + + protected PublicKey engineGeneratePublic(KeySpec keySpec) + throws InvalidKeySpecException + { + if (keySpec instanceof RSAPublicKeySpec) + { + RSAPublicKeySpec spec = (RSAPublicKeySpec) keySpec; + BigInteger n = spec.getModulus(); + BigInteger e = spec.getPublicExponent(); + return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e); + } + + if (keySpec instanceof X509EncodedKeySpec) + { + X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec; + byte[] encoded = spec.getEncoded(); + PublicKey result; + try + { + result = new RSAKeyPairX509Codec().decodePublicKey(encoded); + } + catch (RuntimeException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + throw new InvalidKeySpecException("Unsupported (public) key specification"); + } + + protected PrivateKey engineGeneratePrivate(KeySpec keySpec) + throws InvalidKeySpecException + { + if (keySpec instanceof RSAPrivateCrtKeySpec) + { + RSAPrivateCrtKeySpec spec = (RSAPrivateCrtKeySpec) keySpec; + BigInteger n = spec.getModulus(); + BigInteger e = spec.getPublicExponent(); + BigInteger d = spec.getPrivateExponent(); + BigInteger p = spec.getPrimeP(); + BigInteger q = spec.getPrimeQ(); + BigInteger dP = spec.getPrimeExponentP(); + BigInteger dQ = spec.getPrimeExponentQ(); + BigInteger qInv = spec.getCrtCoefficient(); + return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID, + n, e, d, p, q, dP, dQ, qInv); + } + +// if (keySpec instanceof RSAPrivateKeySpec) +// { +// RSAPrivateKeySpec spec = (RSAPrivateKeySpec) keySpec; +// BigInteger n = spec.getModulus(); +// BigInteger d = spec.getPrivateExponent(); +// return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID, +// n, null, d, null, null, null, null, null); +// } + + if (keySpec instanceof PKCS8EncodedKeySpec) + { + PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec; + byte[] encoded = spec.getEncoded(); + PrivateKey result; + try + { + result = new RSAKeyPairPKCS8Codec().decodePrivateKey(encoded); + } + catch (RuntimeException x) + { + InvalidKeySpecException y = new InvalidKeySpecException(); + y.initCause(x); + throw y; + } + } + + throw new InvalidKeySpecException("Unsupported (private) key specification"); + } + + protected KeySpec engineGetKeySpec(Key key, Class keySpec) + throws InvalidKeySpecException + { + if (key instanceof RSAPublicKey) + { + if (keySpec.isAssignableFrom(RSAPublicKeySpec.class)) + { + RSAPublicKey rsaKey = (RSAPublicKey) key; + BigInteger n = rsaKey.getModulus(); + BigInteger e = rsaKey.getPublicExponent(); + return new RSAPublicKeySpec(n, e); + } + + if (keySpec.isAssignableFrom(X509EncodedKeySpec.class)) + { + if (key instanceof GnuRSAPublicKey) + { + GnuRSAPublicKey rsaKey = (GnuRSAPublicKey) key; + byte[] encoded = rsaKey.getEncoded(Registry.X509_ENCODING_ID); + return new X509EncodedKeySpec(encoded); + } + + if (Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat())) + { + byte[] encoded = key.getEncoded(); + return new X509EncodedKeySpec(encoded); + } + + throw new InvalidKeySpecException("Wrong key type or unsupported (public) key specification"); + } + + throw new InvalidKeySpecException("Unsupported (public) key specification"); + } + + if ((key instanceof RSAPrivateCrtKey) + && keySpec.isAssignableFrom(RSAPrivateCrtKeySpec.class)) + { + RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) key; + BigInteger n = rsaKey.getModulus(); + BigInteger e = rsaKey.getPublicExponent(); + BigInteger d = rsaKey.getPrivateExponent(); + BigInteger p = rsaKey.getPrimeP(); + BigInteger q = rsaKey.getPrimeQ(); + BigInteger dP = rsaKey.getPrimeExponentP(); + BigInteger dQ = rsaKey.getPrimeExponentQ(); + BigInteger qInv = rsaKey.getCrtCoefficient(); + return new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv); + } + + if ((key instanceof RSAPrivateKey) + && keySpec.isAssignableFrom(RSAPrivateKeySpec.class)) + { + RSAPrivateKey rsaKey = (RSAPrivateKey) key; + BigInteger n = rsaKey.getModulus(); + BigInteger d = rsaKey.getPrivateExponent(); + return new RSAPrivateKeySpec(n, d); + } + + if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class)) + { + if (key instanceof GnuRSAPrivateKey) + { + GnuRSAPrivateKey rsaKey = (GnuRSAPrivateKey) key; + byte[] encoded = rsaKey.getEncoded(Registry.PKCS8_ENCODING_ID); + return new PKCS8EncodedKeySpec(encoded); + } + + if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat())) + { + byte[] encoded = key.getEncoded(); + return new PKCS8EncodedKeySpec(encoded); + } + + throw new InvalidKeySpecException("Wrong key type or unsupported (private) key specification"); + } + + throw new InvalidKeySpecException("Wrong key type or unsupported key specification"); + } + + protected Key engineTranslateKey(Key key) throws InvalidKeyException + { + if ((key instanceof GnuRSAPublicKey) || (key instanceof GnuRSAPrivateKey)) + return key; + + if (key instanceof RSAPublicKey) + { + RSAPublicKey rsaKey = (RSAPublicKey) key; + BigInteger n = rsaKey.getModulus(); + BigInteger e = rsaKey.getPublicExponent(); + return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e); + } + + if (key instanceof RSAPrivateCrtKey) + { + RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) key; + BigInteger n = rsaKey.getModulus(); + BigInteger e = rsaKey.getPublicExponent(); + BigInteger d = rsaKey.getPrivateExponent(); + BigInteger p = rsaKey.getPrimeP(); + BigInteger q = rsaKey.getPrimeQ(); + BigInteger dP = rsaKey.getPrimeExponentP(); + BigInteger dQ = rsaKey.getPrimeExponentQ(); + BigInteger qInv = rsaKey.getCrtCoefficient(); + return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID, + n, e, d, p, q, dP, dQ, qInv); + } + +// if (key instanceof RSAPrivateKey) +// { +// RSAPrivateKey rsaKey = (RSAPrivateKey) key; +// BigInteger n = rsaKey.getModulus(); +// BigInteger d = rsaKey.getPrivateExponent(); +// return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID, +// n, null, d, null, null, null, null, null); +// } + + throw new InvalidKeyException("Unsupported key type"); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java b/libjava/classpath/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java new file mode 100644 index 0000000..24dc7c5 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java @@ -0,0 +1,115 @@ +/* RSAKeyPairGeneratorSpi.java -- JCE RSA KeyPairGenerator Adapter + Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.key.rsa.RSAKeyPairGenerator; + +import java.security.InvalidAlgorithmParameterException; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.RSAKeyGenParameterSpec; +import java.util.HashMap; + +/** + * The implementation of a {@link java.security.KeyPairGenerator} adapter class + * to wrap gnu.crypto RSA keypair generator instances.
+ *
+ * In case the client does not explicitly initialize the KeyPairGenerator (via
+ * a call to an initialize()
method), the GNU Crypto provider
+ * uses a default modulus size (keysize) of 1024 bits.
+ */ +public class RSAKeyPairGeneratorSpi extends KeyPairGeneratorAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public RSAKeyPairGeneratorSpi() + { + super(Registry.RSA_KPG); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + public void initialize(int keysize, SecureRandom random) + { + HashMap attributes = new HashMap(); + attributes.put(RSAKeyPairGenerator.MODULUS_LENGTH, new Integer(keysize)); + if (random != null) + { + attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random); + } + + attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT, + new Integer(Registry.ASN1_ENCODING_ID)); + adaptee.setup(attributes); + } + + public void initialize(AlgorithmParameterSpec params, SecureRandom random) + throws InvalidAlgorithmParameterException + { + HashMap attributes = new HashMap(); + if (params != null) + { + if (!(params instanceof RSAKeyGenParameterSpec)) + { + throw new InvalidAlgorithmParameterException("params"); + } + + attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params); + } + + if (random != null) + { + attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random); + } + + attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT, + new Integer(Registry.ASN1_ENCODING_ID)); + adaptee.setup(attributes); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java b/libjava/classpath/gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java new file mode 100644 index 0000000..e44b8ad --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java @@ -0,0 +1,69 @@ +/* RSAPSSRawSignatureSpi.java -- + Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.rsa.RSAPSSSignatureRawCodec; + +/** + * The implementation of Service Provider Interface (SPI) adapter + * for the RSA-PSS signature scheme, encoded and/or decoded in RAW format.
+ * + * @version $Revision: 1.1 $ + */ +public class RSAPSSRawSignatureSpi extends SignatureAdapter +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + public RSAPSSRawSignatureSpi() + { + super(Registry.RSA_PSS_SIG, new RSAPSSSignatureRawCodec()); + } + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/SHA160withDSS.java b/libjava/classpath/gnu/java/security/jce/sig/SHA160withDSS.java new file mode 100644 index 0000000..c55139f --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/SHA160withDSS.java @@ -0,0 +1,54 @@ +/* SHA160withDSS.java -- JCE Adapter for DSS with SHA1 signatures + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.dss.DSSSignatureX509Codec; + +/** + * A JCE Adapter for providing X.509 formatted DSS with SHA1 signatures. + */ +public class SHA160withDSS + extends SignatureAdapter +{ + public SHA160withDSS() + { + super(Registry.DSS_SIG, new DSSSignatureX509Codec()); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/SHA160withRSA.java b/libjava/classpath/gnu/java/security/jce/sig/SHA160withRSA.java new file mode 100644 index 0000000..d3b2054 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/SHA160withRSA.java @@ -0,0 +1,56 @@ +/* SHA160withRSA.java -- RSA PKCS1 with SHA160 JCE signature Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.rsa.RSAPKCS1V1_5SignatureX509Codec; + +/** + * A JCE Adapter for the RSA PKCS1 (v1.5) signature with SHA160 hash and X.509 + * encoding format. + */ +public class SHA160withRSA + extends SignatureAdapter +{ + public SHA160withRSA() + { + super(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.SHA160_HASH, + new RSAPKCS1V1_5SignatureX509Codec()); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/SHA256withRSA.java b/libjava/classpath/gnu/java/security/jce/sig/SHA256withRSA.java new file mode 100644 index 0000000..d21888b --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/SHA256withRSA.java @@ -0,0 +1,56 @@ +/* SHA256withRSA.java -- RSA PKCS1 with SHA256 JCE signature Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.rsa.RSAPKCS1V1_5SignatureX509Codec; + +/** + * A JCE Adapter for the RSA PKCS1 (v1.5) signature with SHA256 hash and X.509 + * encoding format. + */ +public class SHA256withRSA + extends SignatureAdapter +{ + public SHA256withRSA() + { + super(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.SHA256_HASH, + new RSAPKCS1V1_5SignatureX509Codec()); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/SHA384withRSA.java b/libjava/classpath/gnu/java/security/jce/sig/SHA384withRSA.java new file mode 100644 index 0000000..5495ec1 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/SHA384withRSA.java @@ -0,0 +1,56 @@ +/* SHA384withRSA.java -- RSA PKCS1 with SHA384 JCE signature Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.rsa.RSAPKCS1V1_5SignatureX509Codec; + +/** + * A JCE Adapter for the RSA PKCS1 (v1.5) signature with SHA384 hash and X.509 + * encoding format. + */ +public class SHA384withRSA + extends SignatureAdapter +{ + public SHA384withRSA() + { + super(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.SHA384_HASH, + new RSAPKCS1V1_5SignatureX509Codec()); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/SHA512withRSA.java b/libjava/classpath/gnu/java/security/jce/sig/SHA512withRSA.java new file mode 100644 index 0000000..f763229 --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/SHA512withRSA.java @@ -0,0 +1,56 @@ +/* SHA512withRSA.java -- RSA PKCS1 with SHA512 JCE signature Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.Registry; +import gnu.java.security.sig.rsa.RSAPKCS1V1_5SignatureX509Codec; + +/** + * A JCE Adapter for the RSA PKCS1 (v1.5) signature with SHA512 hash and X.509 + * encoding format. + */ +public class SHA512withRSA + extends SignatureAdapter +{ + public SHA512withRSA() + { + super(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.SHA512_HASH, + new RSAPKCS1V1_5SignatureX509Codec()); + } +} diff --git a/libjava/classpath/gnu/java/security/jce/sig/SignatureAdapter.java b/libjava/classpath/gnu/java/security/jce/sig/SignatureAdapter.java new file mode 100644 index 0000000..6cb7c7c --- /dev/null +++ b/libjava/classpath/gnu/java/security/jce/sig/SignatureAdapter.java @@ -0,0 +1,263 @@ +/* SignatureAdapter.java -- + Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.jce.sig; + +import gnu.java.security.sig.BaseSignature; +import gnu.java.security.sig.ISignature; +import gnu.java.security.sig.ISignatureCodec; +import gnu.java.security.sig.SignatureFactory; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.InvalidParameterException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.SignatureException; +import java.security.SignatureSpi; +import java.security.spec.AlgorithmParameterSpec; +import java.util.HashMap; +import java.util.logging.Logger; + +/** + * The implementation of a generic {@link java.security.Signature} adapter class + * to wrap gnu.crypto signature instances.
+ * + * This class defines the Service Provider Interface (SPI) for the + * {@link java.security.Signature} class, which provides the functionality of a + * digital signature algorithm. Digital signatures are used for authentication + * and integrity assurance of digital data.
+ * + * All the abstract methods in the {@link java.security.SignatureSpi} class are + * implemented by this class and all its sub-classes.
+ * + * All the implementations which subclass this object, and which are serviced by + * the GNU Crypto provider implement the {@link java.lang.Cloneable} interface.
+ * + * @version $Revision: 1.2 $ + */ +class SignatureAdapter extends SignatureSpi implements Cloneable +{ + private static final Logger log = Logger.getLogger(SignatureAdapter.class.getName()); + + // Constants and variables + // ------------------------------------------------------------------------- + + /** Our underlying signature instance. */ + private ISignature adaptee; + + /** Our underlying signature encoder/decoder engine. */ + private ISignatureCodec codec; + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** + * Trivial protected constructor.
+ * + * @param sigName the canonical name of the signature scheme. + * @param codec the signature codec engine to use with this scheme. + */ + protected SignatureAdapter(String sigName, ISignatureCodec codec) + { + this(SignatureFactory.getInstance(sigName), codec); + } + + /** + * Private constructor for cloning purposes.
+ * + * @param adaptee a clone of the underlying signature scheme instance. + * @param codec the signature codec engine to use with this scheme. + */ + private SignatureAdapter(ISignature adaptee, ISignatureCodec codec) + { + super(); + + this.adaptee = adaptee; + this.codec = codec; + } + + // Class methods + // ------------------------------------------------------------------------- + + // java.security.SignatureSpi interface implementation + // ------------------------------------------------------------------------- + + public Object clone() + { + return new SignatureAdapter((ISignature) adaptee.clone(), codec); + } + + public void engineInitVerify(PublicKey publicKey) throws InvalidKeyException + { + HashMap attributes = new HashMap(); + attributes.put(BaseSignature.VERIFIER_KEY, publicKey); + try + { + adaptee.setupVerify(attributes); + } + catch (IllegalArgumentException x) + { + throw new InvalidKeyException(String.valueOf(x)); + } + } + + public void engineInitSign(PrivateKey privateKey) throws InvalidKeyException + { + HashMap attributes = new HashMap(); + attributes.put(BaseSignature.SIGNER_KEY, privateKey); + try + { + adaptee.setupSign(attributes); + } + catch (IllegalArgumentException x) + { + throw new InvalidKeyException(String.valueOf(x)); + } + } + + public void engineInitSign(PrivateKey privateKey, SecureRandom random) + throws InvalidKeyException + { + HashMap attributes = new HashMap(); + attributes.put(BaseSignature.SIGNER_KEY, privateKey); + attributes.put(BaseSignature.SOURCE_OF_RANDOMNESS, random); + try + { + adaptee.setupSign(attributes); + } + catch (IllegalArgumentException x) + { + throw new InvalidKeyException(String.valueOf(x)); + } + } + + public void engineUpdate(byte b) throws SignatureException + { + try + { + adaptee.update(b); + } + catch (IllegalStateException x) + { + throw new SignatureException(String.valueOf(x)); + } + } + + public void engineUpdate(byte[] b, int off, int len) + throws SignatureException + { + try + { + adaptee.update(b, off, len); + } + catch (IllegalStateException x) + { + throw new SignatureException(String.valueOf(x)); + } + } + + public byte[] engineSign() throws SignatureException + { + Object signature = null; + try + { + signature = adaptee.sign(); + } + catch (IllegalStateException x) + { + throw new SignatureException(String.valueOf(x)); + } + + byte[] result = codec.encodeSignature(signature); + return result; + } + + public int engineSign(byte[] outbuf, int offset, int len) + throws SignatureException + { + byte[] signature = this.engineSign(); + int result = signature.length; + if (result > len) + { + throw new SignatureException("len"); + } + + System.arraycopy(signature, 0, outbuf, offset, result); + return result; + } + + public boolean engineVerify(byte[] sigBytes) throws SignatureException + { + log.entering("SignatureAdapter", "engineVerify"); + + Object signature = codec.decodeSignature(sigBytes); + boolean result = false; + try + { + result = adaptee.verify(signature); + } + catch (IllegalStateException x) + { + throw new SignatureException(String.valueOf(x)); + } + + log.exiting("SignatureAdapter", "engineVerify", new Boolean(result)); + return result; + } + + // Deprecated. Replaced by engineSetParameter. + public void engineSetParameter(String param, Object value) + throws InvalidParameterException + { + throw new InvalidParameterException("deprecated"); + } + + public void engineSetParameter(AlgorithmParameterSpec params) + throws InvalidAlgorithmParameterException + { + } + + // Deprecated + public Object engineGetParameter(String param) + throws InvalidParameterException + { + throw new InvalidParameterException("deprecated"); + } +} diff --git a/libjava/classpath/gnu/java/security/key/IKeyPairCodec.java b/libjava/classpath/gnu/java/security/key/IKeyPairCodec.java new file mode 100644 index 0000000..c64f928 --- /dev/null +++ b/libjava/classpath/gnu/java/security/key/IKeyPairCodec.java @@ -0,0 +1,132 @@ +/* IKeyPairCodec.java -- + Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.key; + +import gnu.java.security.Registry; + +import java.security.PrivateKey; +import java.security.PublicKey; + +/** + *
The visible methods of an object that knows how to encode and decode + * cryptographic asymmetric keypairs. Codecs are useful for (a) externalising + * public and private keys for storage and on-the-wire transmission, as well as + * (b) re-creating their internal Java representation from external sources.
+ * + * @version $Revision: 1.2 $ + */ +public interface IKeyPairCodec +{ + // Constants + // ------------------------------------------------------------------------- + + /** Constant identifying the Raw encoding format. */ + int RAW_FORMAT = Registry.RAW_ENCODING_ID; + + /** Constant identifying the X.509 encoding format. */ + int X509_FORMAT = Registry.X509_ENCODING_ID; + + /** Constant identifying the PKCS#8 encoding format. */ + int PKCS8_FORMAT = Registry.PKCS8_ENCODING_ID; + + /** + * Constant identifying the ASN.1 encoding format: a combined encoding + * of X.509 for public keys, and PKCS#8 for private ones. + */ + int ASN1_FORMAT = Registry.ASN1_ENCODING_ID; + + // Method(s) + // ------------------------------------------------------------------------- + + /** + *Returns the unique identifier (within this library) of the format used + * to externalise public and private keys.
+ * + * @return the identifier of the format, the object supports. + */ + int getFormatID(); + + /** + *Encodes an instance of a public key for storage or transmission purposes.
+ * + * @param key the non-null key to encode. + * @return a byte sequence representing the encoding of the designated key + * according to the format supported by this codec. + * @exception IllegalArgumentException if the designated key is not supported + * by this codec. + */ + byte[] encodePublicKey(PublicKey key); + + /** + *Encodes an instance of a private key for storage or transmission purposes.
+ * + * @param key the non-null key to encode. + * @return a byte sequence representing the encoding of the designated key + * according to the format supported by this codec. + * @exception IllegalArgumentException if the designated key is not supported + * by this codec. + */ + byte[] encodePrivateKey(PrivateKey key); + + /** + *Decodes an instance of an external public key into its native Java + * representation.
+ * + * @param input the source of the externalised key to decode. + * @return a concrete instance of a public key, reconstructed from the + * designated input. + * @exception IllegalArgumentException if the designated input does not + * contain a known representation of a public key for the format supported by + * the concrete codec. + */ + PublicKey decodePublicKey(byte[] input); + + /** + *Decodes an instance of an external private key into its native Java + * representation.
+ * + * @param input the source of the externalised key to decode. + * @return a concrete instance of a private key, reconstructed from the + * designated input. + * @exception IllegalArgumentException if the designated input does not + * contain a known representation of a private key for the format supported + * by the concrete codec. + */ + PrivateKey decodePrivateKey(byte[] input); +} diff --git a/libjava/classpath/gnu/java/security/key/IKeyPairGenerator.java b/libjava/classpath/gnu/java/security/key/IKeyPairGenerator.java new file mode 100644 index 0000000..219863d --- /dev/null +++ b/libjava/classpath/gnu/java/security/key/IKeyPairGenerator.java @@ -0,0 +1,82 @@ +/* IKeyPairGenerator.java -- + Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.key; + +import java.security.KeyPair; +import java.util.Map; + +/** + * The visible methods of every asymmetric keypair generator.+ * + * @version $Revision: 1.1 $ + */ +public interface IKeyPairGenerator +{ + + // Constants + // ------------------------------------------------------------------------- + + // Methods + // ------------------------------------------------------------------------- + + /** + * Returns the canonical name of this keypair generator.
+ * + * @return the canonical name of this instance. + */ + String name(); + + /** + * [Re]-initialises this instance for use with a given set of attributes.
+ *
+ * @param attributes a map of name/value pairs to use for setting up the
+ * instance.
+ * @exception IllegalArgumentException if at least one of the mandatory
+ * attributes is missing or an invalid value was specified.
+ */
+ void setup(Map attributes);
+
+ /**
+ * Generates a new keypair based on the attributes used to configure the
+ * instance.
+ *
+ * @return a new keypair.
+ */
+ KeyPair generate();
+}
diff --git a/libjava/classpath/gnu/java/security/key/KeyPairCodecFactory.java b/libjava/classpath/gnu/java/security/key/KeyPairCodecFactory.java
new file mode 100644
index 0000000..1a8b8aa
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/KeyPairCodecFactory.java
@@ -0,0 +1,362 @@
+/* KeyPairCodecFactory.java --
+ Copyright 2001, 2002, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.dss.DSSKeyPairPKCS8Codec;
+import gnu.java.security.key.dss.DSSKeyPairRawCodec;
+import gnu.java.security.key.dss.DSSKeyPairX509Codec;
+import gnu.java.security.key.dss.DSSPrivateKey;
+import gnu.java.security.key.dss.DSSPublicKey;
+import gnu.java.security.key.rsa.GnuRSAPrivateKey;
+import gnu.java.security.key.rsa.GnuRSAPublicKey;
+import gnu.java.security.key.rsa.RSAKeyPairPKCS8Codec;
+import gnu.java.security.key.rsa.RSAKeyPairRawCodec;
+import gnu.java.security.key.rsa.RSAKeyPairX509Codec;
+import gnu.java.security.util.FormatUtil;
+
+import java.lang.reflect.Constructor;
+import java.security.Key;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A Factory class to instantiate key encoder/decoder instances.
+ */
+public class KeyPairCodecFactory
+{
+ private static Set names;
+
+ /** Trivial constructor to enforce Singleton pattern. */
+ private KeyPairCodecFactory()
+ {
+ super();
+ }
+
+ /**
+ * Returns the appropriate codec given a composed key-pair generator algorithm
+ * and an encoding format. A composed name is formed by the concatenation of
+ * the canonical key-pair algorithm name, the forward slash character
+ * /
and the canonical name of the encoding format.
+ *
+ * IMPORTANT: For backward compatibility, when the encoding format
+ * name is missing, the Raw encoding format is assumed. When this is the case
+ * the trailing forward slash is discarded from the name.
+ *
+ * @param name the case-insensitive key codec name.
+ * @return an instance of the keypair codec, or null
if none
+ * found.
+ */
+ public static IKeyPairCodec getInstance(String name)
+ {
+ if (name == null)
+ return null;
+
+ name = name.trim();
+ if (name.length() == 0)
+ return null;
+
+ if (name.startsWith("/"))
+ return null;
+
+ if (name.endsWith("/"))
+ return getInstance(name.substring(0, name.length() - 1),
+ Registry.RAW_ENCODING_ID);
+
+ int i = name.indexOf("/");
+ if (i == -1)
+ return getInstance(name, Registry.RAW_ENCODING_ID);
+
+ String kpgName = name.substring(0, i);
+ String formatName = name.substring(i + 1);
+ return getInstance(kpgName, formatName);
+ }
+
+ /**
+ * Returns an instance of a keypair codec given the canonical name of the
+ * key-pair algorithm, and the name of the encoding format to use when
+ * externalizing the keys.
+ *
+ * @param name the case-insensitive key-pair algorithm name.
+ * @param format the name of the encoding format to use when externalizing the
+ * keys generated by the key-pair algorithm.
+ * @return an instance of the key-pair codec, or null
if none
+ * found.
+ */
+ public static IKeyPairCodec getInstance(String name, String format)
+ {
+ int formatID = FormatUtil.getFormatID(format);
+ if (formatID == 0)
+ return null;
+
+ return getInstance(name, formatID);
+ }
+
+ /**
+ * Returns an instance of a keypair codec given the canonical name of the
+ * key-pair algorithm, and the identifier of the format to use when
+ * externalizing the keys.
+ *
+ * @param name the case-insensitive key-pair algorithm name.
+ * @param formatID the identifier of the format to use when externalizing the
+ * keys generated by the key-pair algorithm.
+ * @return an instance of the key-pair codec, or null
if none
+ * found.
+ */
+ public static IKeyPairCodec getInstance(String name, int formatID)
+ {
+ if (name == null)
+ return null;
+
+ name = name.trim();
+ switch (formatID)
+ {
+ case Registry.RAW_ENCODING_ID:
+ return getRawCodec(name);
+ case Registry.X509_ENCODING_ID:
+ return getX509Codec(name);
+ case Registry.PKCS8_ENCODING_ID:
+ return getPKCS8Codec(name);
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns an instance of a keypair codec given a key.
+ *
+ * @param key the key to encode.
+ * @return an instance of the keypair codec, or null
if none
+ * found.
+ */
+ public static IKeyPairCodec getInstance(Key key)
+ {
+ if (key == null)
+ return null;
+
+ String format = key.getFormat();
+ int formatID = FormatUtil.getFormatID(format);
+ if (formatID == 0)
+ return null;
+
+ switch (formatID)
+ {
+ case Registry.RAW_ENCODING_ID:
+ return getRawCodec(key);
+ case Registry.X509_ENCODING_ID:
+ return getX509Codec(key);
+ case Registry.PKCS8_ENCODING_ID:
+ return getPKCS8Codec(key);
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns a {@link Set} of supported key-pair codec names.
+ *
+ * @return a {@link Set} of the names of supported key-pair codec (Strings).
+ */
+ public static synchronized final Set getNames()
+ {
+ if (names == null)
+ {
+ HashSet hs = new HashSet();
+ hs.add(Registry.DSS_KPG + "/" + Registry.RAW_ENCODING_SHORT_NAME);
+ hs.add(Registry.DSS_KPG + "/" + Registry.X509_ENCODING_SORT_NAME);
+ hs.add(Registry.DSS_KPG + "/" + Registry.PKCS8_ENCODING_SHORT_NAME);
+ hs.add(Registry.RSA_KPG + "/" + Registry.RAW_ENCODING_SHORT_NAME);
+ hs.add(Registry.RSA_KPG + "/" + Registry.X509_ENCODING_SORT_NAME);
+ hs.add(Registry.RSA_KPG + "/" + Registry.PKCS8_ENCODING_SHORT_NAME);
+ hs.add(Registry.DH_KPG + "/" + Registry.RAW_ENCODING_SHORT_NAME);
+ hs.add(Registry.SRP_KPG + "/" + Registry.RAW_ENCODING_SHORT_NAME);
+
+ names = Collections.unmodifiableSet(hs);
+ }
+
+ return names;
+ }
+
+ private static IKeyPairCodec makeInstance (String clazz)
+ {
+ try
+ {
+ Class c = Class.forName (clazz);
+ Constructor ctor = c.getConstructor (new Class[0]);
+ return (IKeyPairCodec) ctor.newInstance (new Object[0]);
+ }
+ catch (Exception x)
+ {
+ IllegalArgumentException iae =
+ new IllegalArgumentException ("strong crypto key codec not available: "
+ + clazz);
+ iae.initCause (x);
+ throw iae;
+ }
+ }
+
+ private static boolean matches (Object o, String clazz)
+ {
+ try
+ {
+ Class c = Class.forName (clazz);
+ return c.isAssignableFrom (o.getClass ());
+ }
+ catch (Exception x)
+ {
+ // Can't match.
+ return false;
+ }
+ }
+
+ /**
+ * @param name the trimmed name of a key-pair algorithm.
+ * @return a Raw format codec for the designated key-pair algorithm, or
+ * null
if none exists.
+ */
+ private static IKeyPairCodec getRawCodec(String name)
+ {
+ IKeyPairCodec result = null;
+ if (name.equalsIgnoreCase(Registry.DSA_KPG)
+ || name.equals(Registry.DSS_KPG))
+ result = new DSSKeyPairRawCodec();
+ else if (name.equalsIgnoreCase(Registry.RSA_KPG))
+ result = new RSAKeyPairRawCodec();
+ else if (name.equalsIgnoreCase(Registry.DH_KPG))
+ result = makeInstance("gnu.javax.crypto.key.dh.DHKeyPairRawCodec");
+ else if (name.equalsIgnoreCase(Registry.SRP_KPG))
+ result = makeInstance("gnu.javax.crypto.key.srp6.SRPKeyPairRawCodec");
+
+ return result;
+ }
+
+ /**
+ * @param name the trimmed name of a key-pair algorithm.
+ * @return a X.509 format codec for the designated key-pair algorithm, or
+ * null
if none exists.
+ */
+ private static IKeyPairCodec getX509Codec(String name)
+ {
+ IKeyPairCodec result = null;
+ if (name.equalsIgnoreCase(Registry.DSA_KPG)
+ || name.equals(Registry.DSS_KPG))
+ result = new DSSKeyPairX509Codec();
+ else if (name.equalsIgnoreCase(Registry.RSA_KPG))
+ result = new RSAKeyPairX509Codec();
+ else if (name.equalsIgnoreCase(Registry.DH_KPG))
+ result = makeInstance("gnu.javax.crypto.key.dh.DHKeyPairX509Codec");
+
+ return result;
+ }
+
+ /**
+ * @param name the trimmed name of a key-pair algorithm.
+ * @return a PKCS#8 format codec for the designated key-pair algorithm, or
+ * null
if none exists.
+ */
+ private static IKeyPairCodec getPKCS8Codec(String name)
+ {
+ IKeyPairCodec result = null;
+ if (name.equalsIgnoreCase(Registry.DSA_KPG)
+ || name.equals(Registry.DSS_KPG))
+ result = new DSSKeyPairPKCS8Codec();
+ else if (name.equalsIgnoreCase(Registry.RSA_KPG))
+ result = new RSAKeyPairPKCS8Codec();
+ else if (name.equalsIgnoreCase(Registry.DH_KPG))
+ result = makeInstance("gnu.javax.crypto.key.dh.DHKeyPairPKCS8Codec");
+
+ return result;
+ }
+
+ /**
+ * @param key a {@link Key} for which we want to return a Raw codec.
+ * @return the Raw codec corresponding to the key, or null
if
+ * none exists for this key.
+ */
+ private static IKeyPairCodec getRawCodec(Key key)
+ {
+ IKeyPairCodec result = null;
+ if ((key instanceof DSSPublicKey) || (key instanceof DSSPrivateKey))
+ result = new DSSKeyPairRawCodec();
+ else if ((key instanceof GnuRSAPublicKey)
+ || (key instanceof GnuRSAPrivateKey))
+ result = new RSAKeyPairRawCodec();
+ else if (matches(key, "gnu.javax.crypto.key.dh.GnuDHPublicKey")
+ || matches(key, "gnu.javax.crypto.key.dh.GnuDHPrivateKey"))
+ result = makeInstance("gnu.javax.crypto.key.dh.DHKeyPairRawCodec");
+ else if (matches(key, "gnu.javax.crypto.key.srp6.SRPPublicKey")
+ || matches(key, "gnu.javax.crypto.key.srp6.SRPPrivateKey"))
+ result = makeInstance("gnu.javax.crypto.key.srp6.SRPKeyPairRawCodec");
+
+ return result;
+ }
+
+ /**
+ * @param key a {@link Key} for which we want to return an X.509 codec.
+ * @return the X.509 codec corresponding to the key, or null
if
+ * none exists for this key.
+ */
+ private static IKeyPairCodec getX509Codec(Key key)
+ {
+ IKeyPairCodec result = null;
+ if (key instanceof DSSPublicKey)
+ result = new DSSKeyPairX509Codec();
+ else if (key instanceof GnuRSAPublicKey)
+ result = new RSAKeyPairX509Codec();
+
+ return result;
+ }
+
+ /**
+ * @param key a {@link Key} for which we want to return a PKCS#8 codec.
+ * @return the PKCS#8 codec corresponding to the key, or null
if
+ * none exists for this key.
+ */
+ private static IKeyPairCodec getPKCS8Codec(Key key)
+ {
+ IKeyPairCodec result = null;
+ if (key instanceof DSSPrivateKey)
+ result = new DSSKeyPairPKCS8Codec();
+ else if (key instanceof GnuRSAPrivateKey)
+ result = new RSAKeyPairPKCS8Codec();
+
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/KeyPairGeneratorFactory.java b/libjava/classpath/gnu/java/security/key/KeyPairGeneratorFactory.java
new file mode 100644
index 0000000..edcc186
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/KeyPairGeneratorFactory.java
@@ -0,0 +1,148 @@
+/* KeyPairGeneratorFactory.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.dss.DSSKeyPairGenerator;
+import gnu.java.security.key.rsa.RSAKeyPairGenerator;
+
+import java.lang.reflect.Constructor;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
A Factory to instantiate asymmetric keypair generators.
+ * + * @version $Revision: 1.1 $ + */ +public class KeyPairGeneratorFactory +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + /** Trivial constructor to enforce Singleton pattern. */ + private KeyPairGeneratorFactory() + { + super(); + } + + // Class methods + // ------------------------------------------------------------------------- + + /** + *Returns an instance of a keypair generator given its name.
+ * + * @param name the case-insensitive key generator name. + * @return an instance of the keypair generator, ornull
if none
+ * found.
+ */
+ public static IKeyPairGenerator getInstance(String name)
+ {
+ if (name == null)
+ {
+ return null;
+ }
+
+ name = name.trim();
+ IKeyPairGenerator result = null;
+ if (name.equalsIgnoreCase(Registry.DSA_KPG)
+ || name.equals(Registry.DSS_KPG))
+ {
+ result = new DSSKeyPairGenerator();
+ }
+ else if (name.equalsIgnoreCase(Registry.RSA_KPG))
+ {
+ result = new RSAKeyPairGenerator();
+ }
+ else if (name.equalsIgnoreCase(Registry.DH_KPG))
+ {
+ result = makeInstance ("gnu.javax.crypto.key.dh.GnuDHKeyPairGenerator");
+ }
+ else if (name.equalsIgnoreCase(Registry.SRP_KPG))
+ {
+ result = makeInstance ("gnu.javax.crypto.key.srp6.SRPKeyPairGenerator");
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns a {@link Set} of keypair generator names supported by this + * Factory. Those keypair generators may be used in conjunction with + * the digital signature schemes with appendix supported by this library.
+ * + * @return a {@link Set} of keypair generator names (Strings). + */ + public static final Set getNames() + { + HashSet hs = new HashSet(); + hs.add(Registry.DSS_KPG); + hs.add(Registry.RSA_KPG); + hs.add(Registry.DH_KPG); + hs.add(Registry.SRP_KPG); + + return Collections.unmodifiableSet(hs); + } + + private static IKeyPairGenerator makeInstance (String clazz) + { + try + { + Class c = Class.forName (clazz); + Constructor ctor = c.getConstructor (new Class[0]); + return (IKeyPairGenerator) ctor.newInstance (new Object[0]); + } + catch (Exception x) + { + IllegalArgumentException iae = + new IllegalArgumentException ("strong crypto key pair generator not available: " + + clazz); + iae.initCause (x); + throw iae; + } + } + + // Instance methods + // ------------------------------------------------------------------------- +} diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSKey.java b/libjava/classpath/gnu/java/security/key/dss/DSSKey.java new file mode 100644 index 0000000..428cab1 --- /dev/null +++ b/libjava/classpath/gnu/java/security/key/dss/DSSKey.java @@ -0,0 +1,182 @@ +/* DSSKey.java -- + Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.key.dss; + +import gnu.java.security.Registry; +import gnu.java.security.util.FormatUtil; + +import java.math.BigInteger; +import java.security.Key; +import java.security.interfaces.DSAKey; +import java.security.interfaces.DSAParams; +import java.security.spec.DSAParameterSpec; + +/** + *A base asbtract class for both public and private DSS (Digital Signature
+ * Standard) keys. It encapsulates the three DSS numbers: p
,
+ * q
and g
.
According to the JDK, cryptographic Keys all have a format.
+ * The format used in this implementation is called Raw, and basically
+ * consists of the raw byte sequences of algorithm parameters. The exact order
+ * of the byte sequences and the implementation details are given in each of
+ * the relevant getEncoded()
methods of each of the private and
+ * public keys.
2L-1 < p < 2L
+ * for 512 <= L <= 1024
and L
a multiple of
+ * 64
.
+ */
+ protected final BigInteger p;
+
+ /**
+ * A prime divisor of p - 1
, where 2159 < q
+ * < 2160
.
+ */
+ protected final BigInteger q;
+
+ /**
+ * g = h(p-1)/q mod p
, where h
is any
+ * integer with 1 < h < p - 1
such that h
+ * (p-1)/q mod p > 1
(g
has order q mod p
+ *
).
+ */
+ protected final BigInteger g;
+
+ /**
+ * Identifier of the default encoding format to use when externalizing the
+ * key material.
+ */
+ protected final int defaultFormat;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Trivial protected constructor.
+ *
+ * @param defaultFormat the identifier of the encoding format to use by
+ * default when externalizing the key.
+ * @param p the DSS parameter p
.
+ * @param q the DSS parameter q
.
+ * @param g the DSS parameter g
.
+ */
+ protected DSSKey(int defaultFormat, BigInteger p, BigInteger q, BigInteger g)
+ {
+ super();
+
+ this.defaultFormat = defaultFormat <= 0 ? Registry.RAW_ENCODING_ID
+ : defaultFormat;
+ this.p = p;
+ this.q = q;
+ this.g = g;
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // java.security.interfaces.DSAKey interface implementation ----------------
+
+ public DSAParams getParams()
+ {
+ return new DSAParameterSpec(p, q, g);
+ }
+
+ // java.security.Key interface implementation ------------------------------
+
+ public String getAlgorithm()
+ {
+ return Registry.DSS_KPG;
+ }
+
+ /** @deprecated see getEncoded(int). */
+ public byte[] getEncoded()
+ {
+ return getEncoded(defaultFormat);
+ }
+
+ public String getFormat()
+ {
+ return FormatUtil.getEncodingShortName(defaultFormat);
+ }
+
+ // Other instance methods --------------------------------------------------
+
+ /**
+ * Returns true
if the designated object is an instance of
+ * {@link DSAKey} and has the same DSS (Digital Signature Standard) parameter
+ * values as this one.
true
if the designated object is of the same type and
+ * value as this one.
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof DSAKey))
+ {
+ return false;
+ }
+ DSAKey that = (DSAKey) obj;
+ return p.equals(that.getParams().getP())
+ && q.equals(that.getParams().getQ())
+ && g.equals(that.getParams().getG());
+ }
+
+ // abstract methods to be implemented by subclasses ------------------------
+
+ public abstract byte[] getEncoded(int format);
+}
diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairGenerator.java b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairGenerator.java
new file mode 100644
index 0000000..5aa7461
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairGenerator.java
@@ -0,0 +1,445 @@
+/* DSSKeyPairGenerator.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.dss;
+
+import gnu.java.security.Registry;
+import gnu.java.security.hash.Sha160;
+import gnu.java.security.key.IKeyPairGenerator;
+import gnu.java.security.util.PRNG;
+
+import java.io.PrintWriter;
+import java.math.BigInteger;
+import java.security.KeyPair;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.spec.DSAParameterSpec;
+import java.util.Map;
+
+/**
+ * A key-pair generator for asymetric keys to use in conjunction with the DSS + * (Digital Signature Standard).
+ * + * References:p
, q
and g
for
+ * a given modulus length. The ultimate behaviour of this generator with
+ * regard to using pre-computed parameter sets will depend on the value of
+ * this property and of the following one {@link #STRICT_DEFAULTS}:
+ *
+ * 512
and
+ * 1024
, and is of the form 512 + 64 * n
. In
+ * addition, a new paramter set will always be generated; i.e. no pre-
+ * computed values are used.512
, 768
and 1024
. Any
+ * other value, of the modulus length, even if between 512
and
+ * 1024
, and of the form 512 + 64 * n
, will cause
+ * an {@link IllegalArgumentException} to be thrown. When those modulus
+ * length (512
, 768
, and 1024
) are
+ * specified, the paramter set is always the same.512
,
+ * 768
, or 1024
.p
, q
, and g
values.
+ * The default is to generate these values or use pre-computed ones,
+ * depending on the value of the USE_DEFAULTS
attribute.
+ */
+ public static final String DSS_PARAMETERS = "gnu.crypto.dss.params";
+
+ /**
+ * Property name of the preferred encoding format to use when externalizing
+ * generated instance of key-pairs from this generator. The property is taken
+ * to be an {@link Integer} that encapsulates an encoding format identifier.
+ */
+ public static final String PREFERRED_ENCODING_FORMAT = "gnu.crypto.dss.encoding";
+
+ /** Default value for the modulus length. */
+ public static final int DEFAULT_MODULUS_LENGTH = 1024;
+
+ /** Default encoding format to use when none was specified. */
+ private static final int DEFAULT_ENCODING_FORMAT = Registry.RAW_ENCODING_ID;
+
+ /** Initial SHS context. */
+ private static final int[] T_SHS = new int[] { 0x67452301, 0xEFCDAB89,
+ 0x98BADCFE, 0x10325476,
+ 0xC3D2E1F0 };
+
+ // from jdk1.3.1/docs/guide/security/CryptoSpec.html#AppB
+ public static final DSAParameterSpec KEY_PARAMS_512 = new DSAParameterSpec(
+ new BigInteger(
+ "fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae"
+ + "01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17",
+ 16),
+ new BigInteger(
+ "962eddcc369cba8ebb260ee6b6a126d9346e38c5",
+ 16),
+ new BigInteger(
+ "678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e"
+ + "35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4",
+ 16));
+
+ public static final DSAParameterSpec KEY_PARAMS_768 = new DSAParameterSpec(
+ new BigInteger(
+ "e9e642599d355f37c97ffd3567120b8e25c9cd43e927b3a9670fbec5d8901419"
+ + "22d2c3b3ad2480093799869d1e846aab49fab0ad26d2ce6a22219d470bce7d77"
+ + "7d4a21fbe9c270b57f607002f3cef8393694cf45ee3688c11a8c56ab127a3daf",
+ 16),
+ new BigInteger(
+ "9cdbd84c9f1ac2f38d0f80f42ab952e7338bf511",
+ 16),
+ new BigInteger(
+ "30470ad5a005fb14ce2d9dcd87e38bc7d1b1c5facbaecbe95f190aa7a31d23c4"
+ + "dbbcbe06174544401a5b2c020965d8c2bd2171d3668445771f74ba084d2029d8"
+ + "3c1c158547f3a9f1a2715be23d51ae4d3e5a1f6a7064f316933a346d3f529252",
+ 16));
+
+ public static final DSAParameterSpec KEY_PARAMS_1024 = new DSAParameterSpec(
+ new BigInteger(
+ "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669"
+ + "455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b7"
+ + "6b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb"
+ + "83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7",
+ 16),
+ new BigInteger(
+ "9760508f15230bccb292b982a2eb840bf0581cf5",
+ 16),
+ new BigInteger(
+ "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d078267"
+ + "5159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e1"
+ + "3c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243b"
+ + "cca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a",
+ 16));
+
+ private static final BigInteger TWO_POW_160 = TWO.pow(160);
+
+ /** The length of the modulus of DSS keys generated by this instance. */
+ private int L;
+
+ /** The optional {@link SecureRandom} instance to use. */
+ private SecureRandom rnd = null;
+
+ private BigInteger seed;
+
+ private BigInteger counter;
+
+ private BigInteger p;
+
+ private BigInteger q;
+
+ private BigInteger e;
+
+ private BigInteger g;
+
+ private BigInteger XKEY;
+
+ /** Our default source of randomness. */
+ private PRNG prng = null;
+
+ /** Preferred encoding format of generated keys. */
+ private int preferredFormat;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ // implicit 0-arguments constructor
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // gnu.crypto.key.IKeyPairGenerator interface implementation ---------------
+
+ public String name()
+ {
+ return Registry.DSS_KPG;
+ }
+
+ /**
+ * Configures this instance.
+ * + * @param attributes the map of name/value pairs to use. + * @exception IllegalArgumentException if the designated MODULUS_LENGTH + * value is not greater than 512, less than 1024 and not of the form + *512 + 64j
.
+ */
+ public void setup(Map attributes)
+ {
+ // find out the modulus length
+ Integer l = (Integer) attributes.get(MODULUS_LENGTH);
+ L = (l == null ? DEFAULT_MODULUS_LENGTH : l.intValue());
+ if ((L % 64) != 0 || L < 512 || L > 1024)
+ throw new IllegalArgumentException(MODULUS_LENGTH);
+
+ // should we use the default pre-computed params?
+ Boolean useDefaults = (Boolean) attributes.get(USE_DEFAULTS);
+ if (useDefaults == null)
+ {
+ useDefaults = Boolean.TRUE;
+ }
+
+ Boolean strictDefaults = (Boolean) attributes.get(STRICT_DEFAULTS);
+ if (strictDefaults == null)
+ strictDefaults = Boolean.FALSE;
+
+ // are we given a set of DSA params or we shall use/generate our own?
+ DSAParameterSpec params = (DSAParameterSpec) attributes.get(DSS_PARAMETERS);
+ if (params != null)
+ {
+ p = params.getP();
+ q = params.getQ();
+ g = params.getG();
+ }
+ else if (useDefaults.equals(Boolean.TRUE))
+ {
+ switch (L)
+ {
+ case 512:
+ p = KEY_PARAMS_512.getP();
+ q = KEY_PARAMS_512.getQ();
+ g = KEY_PARAMS_512.getG();
+ break;
+ case 768:
+ p = KEY_PARAMS_768.getP();
+ q = KEY_PARAMS_768.getQ();
+ g = KEY_PARAMS_768.getG();
+ break;
+ case 1024:
+ p = KEY_PARAMS_1024.getP();
+ q = KEY_PARAMS_1024.getQ();
+ g = KEY_PARAMS_1024.getG();
+ break;
+ default:
+ if (strictDefaults.equals(Boolean.TRUE))
+ throw new IllegalArgumentException(
+ "Does not provide default parameters for " + L
+ + "-bit modulus length");
+ else
+ {
+ p = null;
+ q = null;
+ g = null;
+ }
+ }
+ }
+ else
+ {
+ p = null;
+ q = null;
+ g = null;
+ }
+
+ // do we have a SecureRandom, or should we use our own?
+ rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
+
+ // what is the preferred encoding format
+ Integer formatID = (Integer) attributes.get(PREFERRED_ENCODING_FORMAT);
+ preferredFormat = formatID == null
+ ? DEFAULT_ENCODING_FORMAT
+ : formatID.intValue();
+
+ // set the seed-key
+ byte[] kb = new byte[20]; // we need 160 bits of randomness
+ nextRandomBytes(kb);
+ XKEY = new BigInteger(1, kb).setBit(159).setBit(0);
+ }
+
+ public KeyPair generate()
+ {
+ if (p == null)
+ {
+ BigInteger[] params = new FIPS186(L, rnd).generateParameters();
+ seed = params[FIPS186.DSA_PARAMS_SEED];
+ counter = params[FIPS186.DSA_PARAMS_COUNTER];
+ q = params[FIPS186.DSA_PARAMS_Q];
+ p = params[FIPS186.DSA_PARAMS_P];
+ e = params[FIPS186.DSA_PARAMS_E];
+ g = params[FIPS186.DSA_PARAMS_G];
+ if (DEBUG && debuglevel > 0)
+ {
+ debug("seed: " + seed.toString(16));
+ debug("counter: " + counter.intValue());
+ debug("q: " + q.toString(16));
+ debug("p: " + p.toString(16));
+ debug("e: " + e.toString(16));
+ debug("g: " + g.toString(16));
+ }
+ }
+
+ BigInteger x = nextX();
+ BigInteger y = g.modPow(x, p);
+
+ PublicKey pubK = new DSSPublicKey(preferredFormat, p, q, g, y);
+ PrivateKey secK = new DSSPrivateKey(preferredFormat, p, q, g, x);
+
+ return new KeyPair(pubK, secK);
+ }
+
+ // Other instance methods --------------------------------------------------
+
+ /**
+ * This method applies the following algorithm described in 3.1 of + * FIPS-186:
+ * + *Where b
is the length of a secret b-bit seed-key (XKEY).
Note that in this implementation, XSEED, the optional user input, is + * always zero.
+ */ + private synchronized BigInteger nextX() + { + byte[] xk = XKEY.toByteArray(); + byte[] in = new byte[64]; // 512-bit block for SHS + System.arraycopy(xk, 0, in, 0, xk.length); + + int[] H = Sha160.G(T_SHS[0], T_SHS[1], T_SHS[2], T_SHS[3], T_SHS[4], in, 0); + byte[] h = new byte[20]; + for (int i = 0, j = 0; i < 5; i++) + { + h[j++] = (byte) (H[i] >>> 24); + h[j++] = (byte) (H[i] >>> 16); + h[j++] = (byte) (H[i] >>> 8); + h[j++] = (byte) H[i]; + } + BigInteger result = new BigInteger(1, h).mod(q); + XKEY = XKEY.add(result).add(BigInteger.ONE).mod(TWO_POW_160); + + return result; + } + + /** + *Fills the designated byte array with random data.
+ * + * @param buffer the byte array to fill with random data. + */ + private void nextRandomBytes(byte[] buffer) + { + if (rnd != null) + { + rnd.nextBytes(buffer); + } + else + getDefaultPRNG().nextBytes(buffer); + } + + private PRNG getDefaultPRNG() + { + if (prng == null) + prng = PRNG.getInstance(); + + return prng; + } +} diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java new file mode 100644 index 0000000..30e30bd --- /dev/null +++ b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java @@ -0,0 +1,235 @@ +/* DSSKeyPairPKCS8Codec.java -- PKCS#8 Encoding/Decoding handler + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.key.dss; + +import gnu.java.security.OID; +import gnu.java.security.Registry; +import gnu.java.security.der.DER; +import gnu.java.security.der.DERReader; +import gnu.java.security.der.DERValue; +import gnu.java.security.der.DERWriter; +import gnu.java.security.key.IKeyPairCodec; +import gnu.java.security.util.DerUtil; +import gnu.java.security.util.Util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.security.InvalidParameterException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.ArrayList; + +/** + * An implementation of an {@link IKeyPairCodec} that knows how to encode / + * decode PKCS#8 ASN.1 external representation of DSS private keys. + * + * @author Casey Marshall (rsdio@metastatic.org) + */ +public class DSSKeyPairPKCS8Codec + implements IKeyPairCodec +{ + private static final OID DSA_ALG_OID = new OID(Registry.DSA_OID_STRING); + + // implicit 0-arguments constructor + + public int getFormatID() + { + return PKCS8_FORMAT; + } + + /** + * @throws InvalidParameterException ALWAYS. + */ + public byte[] encodePublicKey(PublicKey key) + { + throw new InvalidParameterException("Wrong format for public keys"); + } + + /** + * Returns the PKCS#8 ASN.1 PrivateKeyInfo representation of a DSA + * private key. The ASN.1 specification is as follows: + * + *+ * PrivateKeyInfo ::= SEQUENCE { + * version INTEGER, -- MUST be 0 + * privateKeyAlgorithm AlgorithmIdentifier, + * privateKey OCTET STRING + * } + * + * AlgorithmIdentifier ::= SEQUENCE { + * algorithm OBJECT IDENTIFIER, + * parameters ANY DEFINED BY algorithm OPTIONAL + * } + * + * DssParams ::= SEQUENCE { + * p INTEGER, + * q INTEGER, + * g INTEGER + * } + *+ * + * @return the DER encoded form of the ASN.1 representation of the + * PrivateKeyInfo field in an X.509 certificate. + * @throw InvalidParameterException if an error occurs during the marshalling + * process. + */ + public byte[] encodePrivateKey(PrivateKey key) + { + if (! (key instanceof DSSPrivateKey)) + throw new InvalidParameterException("Wrong key type"); + + DERValue derVersion = new DERValue(DER.INTEGER, BigInteger.ZERO); + + DERValue derOID = new DERValue(DER.OBJECT_IDENTIFIER, DSA_ALG_OID); + + DSSPrivateKey pk = (DSSPrivateKey) key; + BigInteger p = pk.getParams().getP(); + BigInteger q = pk.getParams().getQ(); + BigInteger g = pk.getParams().getG(); + BigInteger x = pk.getX(); + + ArrayList params = new ArrayList(3); + params.add(new DERValue(DER.INTEGER, p)); + params.add(new DERValue(DER.INTEGER, q)); + params.add(new DERValue(DER.INTEGER, g)); + DERValue derParams = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, params); + + ArrayList algorithmID = new ArrayList(2); + algorithmID.add(derOID); + algorithmID.add(derParams); + DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, + algorithmID); + + DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, Util.trim(x)); + + ArrayList pki = new ArrayList(3); + pki.add(derVersion); + pki.add(derAlgorithmID); + pki.add(derPrivateKey); + DERValue derPKI = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, pki); + + byte[] result; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try + { + DERWriter.write(baos, derPKI); + result = baos.toByteArray(); + } + catch (IOException e) + { + InvalidParameterException y = new InvalidParameterException(); + y.initCause(e); + throw y; + } + + return result; + } + + /** + * @throws InvalidParameterException ALWAYS. + */ + public PublicKey decodePublicKey(byte[] input) + { + throw new InvalidParameterException("Wrong format for public keys"); + } + + /** + * @param input the byte array to unmarshall into a valid DSS + * {@link PrivateKey} instance. MUST NOT be null. + * @return a new instance of a {@link DSSPrivateKey} decoded from the + * PrivateKeyInfo material fed as
input
.
+ * @throw InvalidParameterException if an exception occurs during the
+ * unmarshalling process.
+ */
+ public PrivateKey decodePrivateKey(byte[] input)
+ {
+ if (input == null)
+ throw new InvalidParameterException("Input bytes MUST NOT be null");
+
+ BigInteger version, p, q, g, x;
+ DERReader der = new DERReader(input);
+ try
+ {
+ DERValue derPKI = der.read();
+ DerUtil.checkIsConstructed(derPKI, "Wrong PrivateKeyInfo field");
+
+ DERValue derVersion = der.read();
+ if (! (derVersion.getValue() instanceof BigInteger))
+ throw new InvalidParameterException("Wrong Version field");
+
+ version = (BigInteger) derVersion.getValue();
+ if (version.compareTo(BigInteger.ZERO) != 0)
+ throw new InvalidParameterException("Unexpected Version: " + version);
+
+ DERValue derAlgoritmID = der.read();
+ DerUtil.checkIsConstructed(derAlgoritmID, "Wrong AlgorithmIdentifier field");
+
+ DERValue derOID = der.read();
+ OID algOID = (OID) derOID.getValue();
+ if (! algOID.equals(DSA_ALG_OID))
+ throw new InvalidParameterException("Unexpected OID: " + algOID);
+
+ DERValue derParams = der.read();
+ DerUtil.checkIsConstructed(derParams, "Wrong DSS Parameters field");
+
+ DERValue val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong P field");
+ p = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong Q field");
+ q = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong G field");
+ g = (BigInteger) val.getValue();
+
+ val = der.read();
+ byte[] xBytes = (byte[]) val.getValue();
+ x = new BigInteger(1, xBytes);
+ }
+ catch (IOException e)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(e);
+ throw y;
+ }
+
+ return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x);
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairRawCodec.java b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairRawCodec.java
new file mode 100644
index 0000000..86e5b0b
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairRawCodec.java
@@ -0,0 +1,383 @@
+/* DSSKeyPairRawCodec.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.dss;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.IKeyPairCodec;
+
+import java.io.ByteArrayOutputStream;
+import java.math.BigInteger;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+
+/**
+ * An object that implements the {@link IKeyPairCodec} operations for the + * Raw format to use with DSS keypairs.
+ * + * @version $Revision: 1.1 $ + */ +public class DSSKeyPairRawCodec implements IKeyPairCodec +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + // Constructor(s) + // ------------------------------------------------------------------------- + + // implicit 0-arguments constructor + + // Class methods + // ------------------------------------------------------------------------- + + // Instance methods + // ------------------------------------------------------------------------- + + // gnu.crypto.keys.IKeyPairCodec interface implementation ------------------ + + public int getFormatID() + { + return RAW_FORMAT; + } + + /** + *Returns the encoded form of the designated DSS (Digital Signature + * Standard) public key according to the Raw format supported by + * this library.
+ * + *The Raw format for a DSA public key, in this implementation, is + * a byte sequence consisting of the following:
+ *p
in internet order,toByteArray()
method on the DSA parameter
+ * p
,q
,toByteArray()
method on the DSA parameter
+ * q
,g
,toByteArray()
method on the DSA parameter
+ * g
,y
,toByteArray()
method on the DSA parameter
+ * y
,Returns the encoded form of the designated DSS (Digital Signature + * Standard) private key according to the Raw format supported by + * this library.
+ * + *The Raw format for a DSA private key, in this implementation, is + * a byte sequence consisting of the following:
+ *p
in internet order,toByteArray()
method on the DSA parameter
+ * p
,q
,toByteArray()
method on the DSA parameter
+ * q
,g
,toByteArray()
method on the DSA parameter
+ * g
,x
,toByteArray()
method on the DSA parameter
+ * x
,+ * SubjectPublicKeyInfo ::= SEQUENCE { + * algorithm AlgorithmIdentifier, + * subjectPublicKey BIT STRING + * } + * + * AlgorithmIdentifier ::= SEQUENCE { + * algorithm OBJECT IDENTIFIER, + * parameters ANY DEFINED BY algorithm OPTIONAL + * } + * + * DssParams ::= SEQUENCE { + * p INTEGER, + * q INTEGER, + * g INTEGER + * } + *+ * + *
The subjectPublicKey field, which is a BIT STRING, contains the + * DER-encoded form of the DSA public key as an INTEGER.
+ * + *+ * DSAPublicKey ::= INTEGER -- public key, Y + *+ * + * @param key the {@link PublicKey} instance to encode. MUST be an instance of + * {@link DSSPublicKey}. + * @return the ASN.1 representation of the SubjectPublicKeyInfo in an + * X.509 certificate. + * @throw InvalidParameterException if
key
is not an instance
+ * of {@link DSSPublicKey} or if an exception occurs during the
+ * marshalling process.
+ */
+ public byte[] encodePublicKey(PublicKey key)
+ {
+ if (! (key instanceof DSSPublicKey))
+ throw new InvalidParameterException("key");
+
+ DERValue derOID = new DERValue(DER.OBJECT_IDENTIFIER, DSA_ALG_OID);
+
+ DSSPublicKey dssKey = (DSSPublicKey) key;
+ BigInteger p = dssKey.getParams().getP();
+ BigInteger q = dssKey.getParams().getQ();
+ BigInteger g = dssKey.getParams().getG();
+ BigInteger y = dssKey.getY();
+
+ DERValue derP = new DERValue(DER.INTEGER, p);
+ DERValue derQ = new DERValue(DER.INTEGER, q);
+ DERValue derG = new DERValue(DER.INTEGER, g);
+
+ ArrayList params = new ArrayList(3);
+ params.add(derP);
+ params.add(derQ);
+ params.add(derG);
+ DERValue derParams = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, params);
+
+ ArrayList algorithmID = new ArrayList(2);
+ algorithmID.add(derOID);
+ algorithmID.add(derParams);
+ DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,
+ algorithmID);
+
+ DERValue derDSAPublicKey = new DERValue(DER.INTEGER, y);
+ byte[] yBytes = derDSAPublicKey.getEncoded();
+ DERValue derSPK = new DERValue(DER.BIT_STRING, new BitString(yBytes));
+
+ ArrayList spki = new ArrayList(2);
+ spki.add(derAlgorithmID);
+ spki.add(derSPK);
+ DERValue derSPKI = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, spki);
+
+ byte[] result;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try
+ {
+ DERWriter.write(baos, derSPKI);
+ result = baos.toByteArray();
+ }
+ catch (IOException x)
+ {
+ InvalidParameterException e = new InvalidParameterException();
+ e.initCause(x);
+ throw e;
+ }
+
+ return result;
+ }
+
+ /**
+ * @throws InvalidParameterException ALWAYS.
+ */
+ public byte[] encodePrivateKey(PrivateKey key)
+ {
+ throw new InvalidParameterException("Wrong format for private keys");
+ }
+
+ /**
+ * @param input the byte array to unmarshall into a valid DSS
+ * {@link PublicKey} instance. MUST NOT be null.
+ * @return a new instance of a {@link DSSPublicKey} decoded from the
+ * SubjectPublicKeyInfo material in an X.509 certificate.
+ * @throw InvalidParameterException if an exception occurs during the
+ * unmarshalling process.
+ */
+ public PublicKey decodePublicKey(byte[] input)
+ {
+ if (input == null)
+ throw new InvalidParameterException("Input bytes MUST NOT be null");
+
+ BigInteger p, g, q, y;
+ DERReader der = new DERReader(input);
+ try
+ {
+ DERValue derSPKI = der.read();
+ DerUtil.checkIsConstructed(derSPKI, "Wrong SubjectPublicKeyInfo field");
+
+ DERValue derAlgorithmID = der.read();
+ DerUtil.checkIsConstructed(derAlgorithmID, "Wrong AlgorithmIdentifier field");
+
+ DERValue derOID = der.read();
+ if (! (derOID.getValue() instanceof OID))
+ throw new InvalidParameterException("Wrong Algorithm field");
+
+ OID algOID = (OID) derOID.getValue();
+ if (! algOID.equals(DSA_ALG_OID))
+ throw new InvalidParameterException("Unexpected OID: " + algOID);
+
+ DERValue derParams = der.read();
+ DerUtil.checkIsConstructed(derParams, "Wrong DSS Parameters field");
+
+ DERValue val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong P field");
+ p = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong Q field");
+ q = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong G field");
+ g = (BigInteger) val.getValue();
+
+ val = der.read();
+ if (! (val.getValue() instanceof BitString))
+ throw new InvalidParameterException("Wrong SubjectPublicKey field");
+
+ byte[] yBytes = ((BitString) val.getValue()).toByteArray();
+
+ DERReader dsaPub = new DERReader(yBytes);
+ val = dsaPub.read();
+ DerUtil.checkIsBigInteger(val, "Wrong Y field");
+ y = (BigInteger) val.getValue();
+ }
+ catch (IOException x)
+ {
+ InvalidParameterException e = new InvalidParameterException();
+ e.initCause(x);
+ throw e;
+ }
+
+ return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y);
+ }
+
+ /**
+ * @throws InvalidParameterException ALWAYS.
+ */
+ public PrivateKey decodePrivateKey(byte[] input)
+ {
+ throw new InvalidParameterException("Wrong format for private keys");
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSPrivateKey.java b/libjava/classpath/gnu/java/security/key/dss/DSSPrivateKey.java
new file mode 100644
index 0000000..c81eb93
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/dss/DSSPrivateKey.java
@@ -0,0 +1,201 @@
+/* DSSPrivateKey.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.dss;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.IKeyPairCodec;
+
+import java.math.BigInteger;
+import java.security.PrivateKey;
+import java.security.interfaces.DSAPrivateKey;
+
+/**
+ * An object that embodies a DSS (Digital Signature Standard) private key.
+ * + * @version $Revision: 1.2 $ + * @see #getEncoded + */ +public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + /** + *A randomly or pseudorandomly generated integer with 0 < x <
+ * q
.
p-1
.
+ * @param g a generator of the unique cyclic group Z*
+ * p
.
+ * @param x the private key part.
+ */
+ public DSSPrivateKey(BigInteger p, BigInteger q, BigInteger g, BigInteger x)
+ {
+ this(Registry.RAW_ENCODING_ID, p, q, g, x);
+ }
+
+ /**
+ * Constructs a new instance of a DSSPrivateKey
given the
+ * designated arguments.
+ *
+ * @param preferredFormat the indetifier of the preferred encoding format to
+ * use when externalizing this key.
+ * @param p the public modulus.
+ * @param q the public prime divisor of p-1
.
+ * @param g a generator of the unique cyclic group Z*
+ * p
.
+ * @param x the private key part.
+ */
+ public DSSPrivateKey(int preferredFormat, BigInteger p, BigInteger q,
+ BigInteger g, BigInteger x)
+ {
+ super(preferredFormat == Registry.ASN1_ENCODING_ID ? Registry.PKCS8_ENCODING_ID
+ : preferredFormat,
+ p, q, g);
+
+ this.x = x;
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * A class method that takes the output of the encodePrivateKey()
+ * method of a DSS keypair codec object (an instance implementing
+ * {@link gnu.java.security.key.IKeyPairCodec} for DSS keys, and re-constructs
+ * an instance of this object.
+ *
+ * @param k the contents of a previously encoded instance of this object.
+ * @exception ArrayIndexOutOfBoundsException if there is not enough bytes, in
+ * k
, to represent a valid encoding of an
+ * instance of this object.
+ * @exception IllegalArgumentException if the byte sequence does not represent
+ * a valid encoding of an instance of this object.
+ */
+ public static DSSPrivateKey valueOf(byte[] k)
+ {
+ // try RAW codec
+ if (k[0] == Registry.MAGIC_RAW_DSS_PRIVATE_KEY[0])
+ try
+ {
+ return (DSSPrivateKey) new DSSKeyPairRawCodec().decodePrivateKey(k);
+ }
+ catch (IllegalArgumentException ignored)
+ {
+ }
+
+ // try PKCS#8 codec
+ return (DSSPrivateKey) new DSSKeyPairPKCS8Codec().decodePrivateKey(k);
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // java.security.interfaces.DSAPrivateKey interface implementation ---------
+
+ public BigInteger getX()
+ {
+ return x;
+ }
+
+ // Other instance methods --------------------------------------------------
+
+ /**
+ * Returns the encoded form of this private key according to the + * designated format.
+ * + * @param format the desired format identifier of the resulting encoding. + * @return the byte sequence encoding this key according to the designated + * format. + * @exception IllegalArgumentException if the format is not supported. + * @see DSSKeyPairRawCodec + */ + public byte[] getEncoded(int format) + { + byte[] result; + switch (format) + { + case IKeyPairCodec.RAW_FORMAT: + result = new DSSKeyPairRawCodec().encodePrivateKey(this); + break; + case IKeyPairCodec.PKCS8_FORMAT: + result = new DSSKeyPairPKCS8Codec().encodePrivateKey(this); + break; + default: + throw new IllegalArgumentException("Unsupported encoding format: " + + format); + } + return result; + } + + /** + *Returns true
if the designated object is an instance of
+ * {@link DSAPrivateKey} and has the same DSS (Digital Signature Standard)
+ * parameter values as this one.
true
if the designated object is of the same type and
+ * value as this one.
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof DSAPrivateKey))
+ {
+ return false;
+ }
+ DSAPrivateKey that = (DSAPrivateKey) obj;
+ return super.equals(that) && x.equals(that.getX());
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSPublicKey.java b/libjava/classpath/gnu/java/security/key/dss/DSSPublicKey.java
new file mode 100644
index 0000000..93bb640
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/dss/DSSPublicKey.java
@@ -0,0 +1,201 @@
+/* DSSPublicKey.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.dss;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.IKeyPairCodec;
+
+import java.math.BigInteger;
+import java.security.PublicKey;
+import java.security.interfaces.DSAPublicKey;
+
+/**
+ * An object that embodies a DSS (Digital Signature Standard) public key.
+ * + * @version $Revision: 1.2 $ + * @see #getEncoded + */ +public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey +{ + + // Constants and variables + // ------------------------------------------------------------------------- + + /** + *y = gx mod p
where x
is the private
+ * part of the DSA key.
+ */
+ private final BigInteger y;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Conveience constructor. Calls the constructor with 5 arguments passing
+ * {@link Registry#RAW_ENCODING_ID} as the identifier of the preferred
+ * encoding format.
+ *
+ * @param p the public modulus.
+ * @param q the public prime divisor of p-1
.
+ * @param g a generator of the unique cyclic group Z*
+ * p
.
+ * @param y the public key part.
+ */
+ public DSSPublicKey(BigInteger p, BigInteger q, BigInteger g, BigInteger y)
+ {
+ this(Registry.RAW_ENCODING_ID, p, q, g, y);
+ }
+
+ /**
+ * Constructs a new instance of DSSPublicKey
given the designated
+ * arguments.
+ *
+ * @param preferredFormat the identifier of the preferred encoding format to
+ * use when externalizing this key.
+ * @param p the public modulus.
+ * @param q the public prime divisor of p-1
.
+ * @param g a generator of the unique cyclic group Z*
+ * p
.
+ * @param y the public key part.
+ */
+ public DSSPublicKey(int preferredFormat, BigInteger p, BigInteger q,
+ BigInteger g, BigInteger y)
+ {
+ super(preferredFormat == Registry.ASN1_ENCODING_ID ? Registry.X509_ENCODING_ID
+ : preferredFormat,
+ p, q, g);
+
+ this.y = y;
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * A class method that takes the output of the encodePublicKey()
+ * method of a DSS keypair codec object (an instance implementing
+ * {@link gnu.java.security.key.IKeyPairCodec} for DSS keys, and re-constructs
+ * an instance of this object.
+ *
+ * @param k the contents of a previously encoded instance of this object.
+ * @exception ArrayIndexOutOfBoundsException if there is not enough bytes, in
+ * k
, to represent a valid encoding of an
+ * instance of this object.
+ * @exception IllegalArgumentException if the byte sequence does not represent
+ * a valid encoding of an instance of this object.
+ */
+ public static DSSPublicKey valueOf(byte[] k)
+ {
+ // try RAW codec
+ if (k[0] == Registry.MAGIC_RAW_DSS_PUBLIC_KEY[0])
+ try
+ {
+ return (DSSPublicKey) new DSSKeyPairRawCodec().decodePublicKey(k);
+ }
+ catch (IllegalArgumentException ignored)
+ {
+ }
+
+ // try X.509 codec
+ return (DSSPublicKey) new DSSKeyPairX509Codec().decodePublicKey(k);
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // java.security.interfaces.DSAPublicKey interface implementation ----------
+
+ public BigInteger getY()
+ {
+ return y;
+ }
+
+ // Other instance methods --------------------------------------------------
+
+ /**
+ * Returns the encoded form of this public key according to the designated + * format.
+ * + * @param format the desired format identifier of the resulting encoding. + * @return the byte sequence encoding this key according to the designated + * format. + * @exception IllegalArgumentException if the format is not supported. + * @see DSSKeyPairRawCodec + */ + public byte[] getEncoded(int format) + { + byte[] result; + switch (format) + { + case IKeyPairCodec.RAW_FORMAT: + result = new DSSKeyPairRawCodec().encodePublicKey(this); + break; + case IKeyPairCodec.X509_FORMAT: + result = new DSSKeyPairX509Codec().encodePublicKey(this); + break; + default: + throw new IllegalArgumentException("Unsupported encoding format: " + + format); + } + return result; + } + + /** + *Returns true
if the designated object is an instance of
+ * {@link DSAPublicKey} and has the same DSS (Digital Signature Standard)
+ * parameter values as this one.
true
if the designated object is of the same type and
+ * value as this one.
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof DSAPublicKey))
+ {
+ return false;
+ }
+ DSAPublicKey that = (DSAPublicKey) obj;
+ return super.equals(that) && y.equals(that.getY());
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/dss/FIPS186.java b/libjava/classpath/gnu/java/security/key/dss/FIPS186.java
new file mode 100644
index 0000000..74be626
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/dss/FIPS186.java
@@ -0,0 +1,296 @@
+/* FIPS186.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.dss;
+
+import gnu.java.security.hash.Sha160;
+import gnu.java.security.util.PRNG;
+import gnu.java.security.util.Prime2;
+
+import java.math.BigInteger;
+import java.security.SecureRandom;
+
+/**
+ * An implementation of the DSA parameters generation as described in + * FIPS-186.
+ * + * References:p
, q
, and
+ * g
parameters only when L
(the modulus length)
+ * is not one of the following: 512
, 768
and
+ * 1024
. For those values of L
, this implementation
+ * uses pre-computed values of p
, q
, and
+ * g
given in the document CryptoSpec included in the
+ * security guide documentation of the standard JDK distribution.
+ *
+ * The DSS requires two primes , p
and q
,
+ * satisfying the following three conditions:
+ *
+ *
2159 < q < 2160
2L-1 < p < 2L
for a
+ * specified L
, where L = 512 + 64j
for some
+ * 0 <= j <= 8
q
, in the range 2159 < q
+ * < 2160. Once this is accomplished, the same SEED
+ * value is used to construct an X
in the range 2L-1
+ * < X < 2L. The prime, p
, is then
+ * formed by rounding X
to a number congruent to 1 mod
+ * 2q
. In this implementation we use the same SEED value given
+ * in FIPS-186, Appendix 5.
+ */
+ public BigInteger[] generateParameters()
+ {
+ int counter, offset;
+ BigInteger SEED, alpha, U, q, OFFSET, SEED_PLUS_OFFSET, W, X, p, c, g;
+ byte[] a, u;
+ byte[] kb = new byte[20]; // to hold 160 bits of randomness
+
+ // Let L-1 = n*160 + b, where b and n are integers and 0 <= b < 160.
+ int b = (L - 1) % 160;
+ int n = (L - 1 - b) / 160;
+ BigInteger[] V = new BigInteger[n + 1];
+ algorithm: while (true)
+ {
+ step1: while (true)
+ {
+ // 1. Choose an arbitrary sequence of at least 160 bits and
+ // call it SEED.
+ nextRandomBytes(kb);
+ SEED = new BigInteger(1, kb).setBit(159).setBit(0);
+ // Let g be the length of SEED in bits. here always 160
+ // 2. Compute: U = SHA[SEED] XOR SHA[(SEED+1) mod 2**g]
+ alpha = SEED.add(BigInteger.ONE).mod(TWO_POW_160);
+ synchronized (sha)
+ {
+ a = SEED.toByteArray();
+ sha.update(a, 0, a.length);
+ a = sha.digest();
+ u = alpha.toByteArray();
+ sha.update(u, 0, u.length);
+ u = sha.digest();
+ }
+ for (int i = 0; i < a.length; i++)
+ {
+ a[i] ^= u[i];
+ }
+ U = new BigInteger(1, a);
+ // 3. Form q from U by setting the most significant bit (the
+ // 2**159 bit) and the least significant bit to 1. In terms of
+ // boolean operations, q = U OR 2**159 OR 1. Note that
+ // 2**159 < q < 2**160.
+ q = U.setBit(159).setBit(0);
+ // 4. Use a robust primality testing algorithm to test whether
+ // q is prime(1). A robust primality test is one where the
+ // probability of a non-prime number passing the test is at
+ // most 1/2**80.
+ // 5. If q is not prime, go to step 1.
+ if (Prime2.isProbablePrime(q))
+ {
+ break step1;
+ }
+ } // step1
+
+ // 6. Let counter = 0 and offset = 2.
+ counter = 0;
+ offset = 2;
+ step7: while (true)
+ {
+ OFFSET = BigInteger.valueOf(offset & 0xFFFFFFFFL);
+ SEED_PLUS_OFFSET = SEED.add(OFFSET);
+ // 7. For k = 0,...,n let V[k] = SHA[(SEED + offset + k) mod 2**g].
+ synchronized (sha)
+ {
+ for (int k = 0; k <= n; k++)
+ {
+ a = SEED_PLUS_OFFSET.add(
+ BigInteger.valueOf(k & 0xFFFFFFFFL)).mod(
+ TWO_POW_160).toByteArray();
+ sha.update(a, 0, a.length);
+ V[k] = new BigInteger(1, sha.digest());
+ }
+ }
+ // 8. Let W be the integer:
+ // V[0]+V[1]*2**160+...+V[n-1]*2**((n-1)*160)+(V[n]mod2**b)*2**(n*160)
+ // and let : X = W + 2**(L-1).
+ // Note that 0 <= W < 2**(L-1) and hence 2**(L-1) <= X < 2**L.
+ W = V[0];
+ for (int k = 1; k < n; k++)
+ {
+ W = W.add(V[k].multiply(TWO.pow(k * 160)));
+ }
+ W = W.add(V[n].mod(TWO.pow(b)).multiply(TWO.pow(n * 160)));
+ X = W.add(TWO.pow(L - 1));
+ // 9. Let c = X mod 2q and set p = X - (c - 1).
+ // Note that p is congruent to 1 mod 2q.
+ c = X.mod(TWO.multiply(q));
+ p = X.subtract(c.subtract(BigInteger.ONE));
+ // 10. If p < 2**(L-1), then go to step 13.
+ if (p.compareTo(TWO.pow(L - 1)) >= 0)
+ {
+ // 11. Perform a robust primality test on p.
+ // 12. If p passes the test performed in step 11, go to step 15.
+ if (Prime2.isProbablePrime(p))
+ {
+ break algorithm;
+ }
+ }
+ // 13. Let counter = counter + 1 and offset = offset + n + 1.
+ counter++;
+ offset += n + 1;
+ // 14. If counter >= 4096 go to step 1, otherwise go to step 7.
+ if (counter >= 4096)
+ {
+ continue algorithm;
+ }
+ } // step7
+ } // algorithm
+
+ // compute g. from FIPS-186, Appendix 4:
+ // 1. Generate p and q as specified in Appendix 2.
+ // 2. Let e = (p - 1) / q
+ BigInteger e = p.subtract(BigInteger.ONE).divide(q);
+ BigInteger h = TWO;
+ BigInteger p_minus_1 = p.subtract(BigInteger.ONE);
+ g = TWO;
+ // 3. Set h = any integer, where 1 < h < p - 1 and
+ // h differs from any value previously tried
+ for (; h.compareTo(p_minus_1) < 0; h = h.add(BigInteger.ONE))
+ {
+ // 4. Set g = h**e mod p
+ g = h.modPow(e, p);
+ // 5. If g = 1, go to step 3
+ if (!g.equals(BigInteger.ONE))
+ {
+ break;
+ }
+ }
+
+ return new BigInteger[] { SEED, BigInteger.valueOf(counter), q, p, e, g };
+ }
+
+ // helper methods ----------------------------------------------------------
+
+ /**
+ * Fills the designated byte array with random data.
+ *
+ * @param buffer the byte array to fill with random data.
+ */
+ private void nextRandomBytes(byte[] buffer)
+ {
+ if (rnd != null)
+ {
+ rnd.nextBytes(buffer);
+ }
+ else
+ getDefaultPRNG().nextBytes(buffer);
+ }
+
+ private PRNG getDefaultPRNG()
+ {
+ if (prng == null)
+ prng = PRNG.getInstance();
+
+ return prng;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/rsa/GnuRSAKey.java b/libjava/classpath/gnu/java/security/key/rsa/GnuRSAKey.java
new file mode 100644
index 0000000..72cd808
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/rsa/GnuRSAKey.java
@@ -0,0 +1,181 @@
+/* GnuRSAKey.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.IKeyPairCodec;
+import gnu.java.security.util.FormatUtil;
+
+import java.math.BigInteger;
+import java.security.Key;
+import java.security.interfaces.RSAKey;
+
+/**
+ * A base asbtract class for both public and private RSA keys.
+ *
+ * @version $Revision: 1.3 $
+ */
+public abstract class GnuRSAKey implements Key, RSAKey
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** The public modulus of an RSA key pair. */
+ private final BigInteger n;
+
+ /** The public exponent of an RSA key pair. */
+ private final BigInteger e;
+
+ /**
+ * Identifier of the default encoding format to use when externalizing the
+ * key material.
+ */
+ protected final int defaultFormat;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Trivial protected constructor.
+ *
+ * @param defaultFormat the identifier of the encoding format to use by
+ * default when externalizing the key.
+ * @param n the public modulus n
.
+ * @param e the public exponent e
.
+ */
+ protected GnuRSAKey(int defaultFormat, BigInteger n, BigInteger e)
+ {
+ super();
+
+ this.defaultFormat = defaultFormat <= 0 ? Registry.RAW_ENCODING_ID
+ : defaultFormat;
+ this.n = n;
+ this.e = e;
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // java.security.interfaces.RSAKey interface implementation ----------------
+
+ public BigInteger getModulus()
+ {
+ return getN();
+ }
+
+ // java.security.Key interface implementation ------------------------------
+
+ public String getAlgorithm()
+ {
+ return Registry.RSA_KPG;
+ }
+
+ /** @deprecated see getEncoded(int). */
+ public byte[] getEncoded()
+ {
+ return getEncoded(IKeyPairCodec.RAW_FORMAT);
+ }
+
+ public String getFormat()
+ {
+ return FormatUtil.getEncodingShortName(defaultFormat);
+ }
+
+ // Other instance methods --------------------------------------------------
+
+ /**
+ * Returns the modulus n
.
+ *
+ * @return the modulus n
.
+ */
+ public BigInteger getN()
+ {
+ return n;
+ }
+
+ /**
+ * Returns the public exponent e
.
+ *
+ * @return the public exponent e
.
+ */
+ public BigInteger getPublicExponent()
+ {
+ return getE();
+ }
+
+ /**
+ * Same as {@link #getPublicExponent()}.
+ *
+ * @return the public exponent e
.
+ */
+ public BigInteger getE()
+ {
+ return e;
+ }
+
+ /**
+ * Returns true
if the designated object is an instance of
+ * {@link RSAKey} and has the same RSA parameter values as this one.
+ *
+ * @param obj the other non-null RSA key to compare to.
+ * @return true
if the designated object is of the same type and
+ * value as this one.
+ */
+ public boolean equals(final Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof RSAKey))
+ {
+ return false;
+ }
+ final RSAKey that = (RSAKey) obj;
+ return n.equals(that.getModulus());
+ }
+
+ // abstract methods to be implemented by subclasses ------------------------
+
+ public abstract byte[] getEncoded(int format);
+}
diff --git a/libjava/classpath/gnu/java/security/key/rsa/GnuRSAPrivateKey.java b/libjava/classpath/gnu/java/security/key/rsa/GnuRSAPrivateKey.java
new file mode 100644
index 0000000..f8acaa5
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/rsa/GnuRSAPrivateKey.java
@@ -0,0 +1,299 @@
+/* GnuRSAPrivateKey.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.IKeyPairCodec;
+
+import java.math.BigInteger;
+import java.security.PrivateKey;
+import java.security.interfaces.RSAPrivateCrtKey;
+import java.security.interfaces.RSAPrivateKey;
+
+/**
+ * An object that embodies an RSA private key.
+ *
+ * References:
+ *
+ * -
+ * RSA-PSS Signature Scheme with Appendix, part B.
+ * Primitive specification and supporting documentation.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ *
+ * @version $Revision: 1.3 $
+ */
+public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
+ RSAPrivateCrtKey
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** The first prime divisor of the modulus. */
+ private final BigInteger p;
+
+ /** The second prime divisor of the modulus. */
+ private final BigInteger q;
+
+ /** The public exponent of an RSA key. */
+ // private final BigInteger e;
+ /** The private exponent of an RSA private key. */
+ private final BigInteger d;
+
+ /** The first factor's exponent. */
+ private final BigInteger dP;
+
+ /** The second factor's exponent. */
+ private final BigInteger dQ;
+
+ /** The CRT (Chinese Remainder Theorem) coefficient. */
+ private final BigInteger qInv;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Convenience constructor. Calls the constructor with 5 arguments passing
+ * {@link Registry#RAW_ENCODING_ID} as the identifier of the preferred
+ * encoding format.
+ *
+ * @param p the modulus first prime divisor.
+ * @param q the modulus second prime divisor.
+ * @param e the public exponent.
+ * @param d the private exponent.
+ */
+ public GnuRSAPrivateKey(BigInteger p, BigInteger q, BigInteger e,
+ BigInteger d)
+ {
+ this(Registry.RAW_ENCODING_ID, p, q, e, d);
+ }
+
+ /**
+ * Constructs a new instance of a GnuRSAPrivateKey
given the
+ * designated arguments.
+ *
+ * @param preferredFormat the indetifier of the preferred encoding format to
+ * use when externalizing this key.
+ * @param p the modulus first prime divisor.
+ * @param q the modulus second prime divisor.
+ * @param e the public exponent.
+ * @param d the private exponent.
+ */
+ public GnuRSAPrivateKey(int preferredFormat, BigInteger p, BigInteger q,
+ BigInteger e, BigInteger d)
+ {
+ this(preferredFormat, p.multiply(q), e, d, p, q,
+ e.modInverse(p.subtract(BigInteger.ONE)),
+ e.modInverse(q.subtract(BigInteger.ONE)),
+ q.modInverse(p));
+ }
+
+ /**
+ * Constructs a new instance of a GnuRSAPrivateKey
given the
+ * designated arguments.
+ *
+ * @param preferredFormat the indetifier of the preferred encoding format to
+ * use when externalizing this key.
+ * @param n the public modulus, which is also the product of p
+ * and q
.
+ * @param e the public exponent.
+ * @param d the private exponent.
+ * @param p the modulus first prime divisor.
+ * @param q the modulus second prime divisor.
+ * @param dP the first prime's exponen. A positive integer less than
+ * p
and q
, satisfying e * dP = 1 (mod p-1)
+ *
.
+ * @param dQ the second prime's exponent. A positive integer less than
+ * p
and q
, satisfying e * dQ = 1 (mod p-1)
+ *
.
+ * @param qInv the Chinese Remainder Theorem coefiicient. A positive integer
+ * less than p
, satisfying q * qInv = 1 (mod p)
.
+ */
+ public GnuRSAPrivateKey(int preferredFormat, BigInteger n, BigInteger e,
+ BigInteger d, BigInteger p, BigInteger q,
+ BigInteger dP, BigInteger dQ, BigInteger qInv)
+ {
+ super(preferredFormat == Registry.ASN1_ENCODING_ID ? Registry.PKCS8_ENCODING_ID
+ : preferredFormat,
+ n, e);
+
+ this.d = d;
+ this.p = p;
+ this.q = q;
+ // the exponents dP and dQ are positive integers less than p and q
+ // respectively satisfying
+ // e * dP = 1 (mod p-1);
+ // e * dQ = 1 (mod q-1),
+ this.dP = dP;
+ this.dQ = dQ;
+ // the CRT coefficient qInv is a positive integer less than p satisfying
+ // q * qInv = 1 (mod p).
+ this.qInv = qInv;
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * A class method that takes the output of the encodePrivateKey()
+ * method of an RSA keypair codec object (an instance implementing
+ * {@link IKeyPairCodec} for RSA keys, and re-constructs an instance of this
+ * object.
+ *
+ * @param k the contents of a previously encoded instance of this object.
+ * @throws ArrayIndexOutOfBoundsException if there is not enough bytes, in
+ * k
, to represent a valid encoding of an instance
+ * of this object.
+ * @throws IllegalArgumentException if the byte sequence does not represent a
+ * valid encoding of an instance of this object.
+ */
+ public static GnuRSAPrivateKey valueOf(final byte[] k)
+ {
+ // try RAW codec
+ if (k[0] == Registry.MAGIC_RAW_RSA_PRIVATE_KEY[0])
+ try
+ {
+ return (GnuRSAPrivateKey) new RSAKeyPairRawCodec().decodePrivateKey(k);
+ }
+ catch (IllegalArgumentException ignored)
+ {
+ }
+
+ // try PKCS#8 codec
+ return (GnuRSAPrivateKey) new RSAKeyPairPKCS8Codec().decodePrivateKey(k);
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ public BigInteger getPrimeP()
+ {
+ return p;
+ }
+
+ public BigInteger getPrimeQ()
+ {
+ return q;
+ }
+
+ public BigInteger getPrimeExponentP()
+ {
+ return dP;
+ }
+
+ public BigInteger getPrimeExponentQ()
+ {
+ return dQ;
+ }
+
+ public BigInteger getCrtCoefficient()
+ {
+ return qInv;
+ }
+
+ // java.security.interfaces.RSAPrivateKey interface implementation ---------
+
+ public BigInteger getPrivateExponent()
+ {
+ return d;
+ }
+
+ // Other instance methods --------------------------------------------------
+
+ /**
+ * Returns the encoded form of this private key according to the
+ * designated format.
+ *
+ * @param format the desired format identifier of the resulting encoding.
+ * @return the byte sequence encoding this key according to the designated
+ * format.
+ * @throws IllegalArgumentException if the format is not supported.
+ * @see RSAKeyPairRawCodec
+ * @see RSAKeyPairPKCS8Codec
+ */
+ public byte[] getEncoded(int format)
+ {
+ final byte[] result;
+ switch (format)
+ {
+ case IKeyPairCodec.RAW_FORMAT:
+ result = new RSAKeyPairRawCodec().encodePrivateKey(this);
+ break;
+ case IKeyPairCodec.PKCS8_FORMAT:
+ result = new RSAKeyPairPKCS8Codec().encodePrivateKey(this);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported encoding format: "
+ + format);
+ }
+ return result;
+ }
+
+ /**
+ * Returns true
if the designated object is an instance of
+ * this class and has the same RSA parameter values as this one.
+ *
+ * @param obj the other non-null RSA key to compare to.
+ * @return true
if the designated object is of the same type
+ * and value as this one.
+ */
+ public boolean equals(final Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj instanceof RSAPrivateKey)
+ {
+ final RSAPrivateKey that = (RSAPrivateKey) obj;
+ return super.equals(that) && d.equals(that.getPrivateExponent());
+ }
+ if (obj instanceof RSAPrivateCrtKey)
+ {
+ final RSAPrivateCrtKey that = (RSAPrivateCrtKey) obj;
+ return super.equals(that) && p.equals(that.getPrimeP())
+ && q.equals(that.getPrimeQ())
+ && dP.equals(that.getPrimeExponentP())
+ && dQ.equals(that.getPrimeExponentQ())
+ && qInv.equals(that.getCrtCoefficient());
+ }
+ return false;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/rsa/GnuRSAPublicKey.java b/libjava/classpath/gnu/java/security/key/rsa/GnuRSAPublicKey.java
new file mode 100644
index 0000000..f49027c
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/rsa/GnuRSAPublicKey.java
@@ -0,0 +1,185 @@
+/* GnuRSAPublicKey.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.IKeyPairCodec;
+
+import java.math.BigInteger;
+import java.security.PublicKey;
+import java.security.interfaces.RSAPublicKey;
+
+/**
+ * An object that encapsulates an RSA public key.
+ *
+ * References:
+ *
+ * -
+ * RSA-PSS Signature Scheme with Appendix, part B.
+ * Primitive specification and supporting documentation.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ *
+ * @version $Revision: 1.2 $
+ */
+public class GnuRSAPublicKey extends GnuRSAKey implements PublicKey,
+ RSAPublicKey
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Conveience constructor. Calls the constructor with 3 arguments passing
+ * {@link Registry#RAW_ENCODING_ID} as the identifier of the preferred
+ * encoding format.
+ *
+ * @param n the modulus.
+ * @param e the public exponent.
+ */
+ public GnuRSAPublicKey(final BigInteger n, final BigInteger e)
+ {
+ this(Registry.RAW_ENCODING_ID, n, e);
+ }
+
+ /**
+ * Constructs a new instance of GnuRSAPublicKey
given the
+ * designated arguments.
+ *
+ * @param preferredFormat the identifier of the preferred encoding format to
+ * use when externalizing this key.
+ * @param n the modulus.
+ * @param e the public exponent.
+ */
+ public GnuRSAPublicKey(int preferredFormat, BigInteger n, BigInteger e)
+ {
+ super(preferredFormat == Registry.ASN1_ENCODING_ID ? Registry.X509_ENCODING_ID
+ : preferredFormat,
+ n, e);
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * A class method that takes the output of the encodePublicKey()
+ * method of an RSA keypair codec object (an instance implementing
+ * {@link IKeyPairCodec} for RSA keys, and re-constructs an instance of this
+ * object.
+ *
+ * @param k the contents of a previously encoded instance of this object.
+ * @throws ArrayIndexOutOfBoundsException if there is not enough bytes, in
+ * k
, to represent a valid encoding of an instance
+ * of this object.
+ * @throws IllegalArgumentException if the byte sequence does not represent a
+ * valid encoding of an instance of this object.
+ */
+ public static GnuRSAPublicKey valueOf(final byte[] k)
+ {
+ // try RAW codec
+ if (k[0] == Registry.MAGIC_RAW_RSA_PUBLIC_KEY[0])
+ try
+ {
+ return (GnuRSAPublicKey) new RSAKeyPairRawCodec().decodePublicKey(k);
+ }
+ catch (IllegalArgumentException ignored)
+ {
+ }
+
+ // try X.509 codec
+ return (GnuRSAPublicKey) new RSAKeyPairX509Codec().decodePublicKey(k);
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the encoded form of this public key according to the designated
+ * format.
+ *
+ * @param format the desired format identifier of the resulting encoding.
+ * @return the byte sequence encoding this key according to the designated
+ * format.
+ * @throws IllegalArgumentException if the format is not supported.
+ * @see RSAKeyPairRawCodec
+ */
+ public byte[] getEncoded(final int format)
+ {
+ final byte[] result;
+ switch (format)
+ {
+ case IKeyPairCodec.RAW_FORMAT:
+ result = new RSAKeyPairRawCodec().encodePublicKey(this);
+ break;
+ case IKeyPairCodec.X509_FORMAT:
+ result = new RSAKeyPairX509Codec().encodePublicKey(this);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported encoding format: "
+ + format);
+ }
+ return result;
+ }
+
+ /**
+ * Returns true
if the designated object is an instance of
+ * this class and has the same RSA parameter values as this one.
+ *
+ * @param obj the other non-null RSA key to compare to.
+ * @return true
if the designated object is of the same type and
+ * value as this one.
+ */
+ public boolean equals(final Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof RSAPublicKey))
+ {
+ return false;
+ }
+ final RSAPublicKey that = (RSAPublicKey) obj;
+ return super.equals(that)
+ && getPublicExponent().equals(that.getPublicExponent());
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairGenerator.java b/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairGenerator.java
new file mode 100644
index 0000000..9c7338f
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairGenerator.java
@@ -0,0 +1,264 @@
+/* RSAKeyPairGenerator.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.IKeyPairGenerator;
+import gnu.java.security.util.PRNG;
+import gnu.java.security.util.Prime2;
+
+import java.math.BigInteger;
+import java.security.KeyPair;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.spec.RSAKeyGenParameterSpec;
+import java.util.Map;
+
+/**
+ * A key-pair generator for asymetric keys to use in conjunction with the RSA
+ * scheme.
+ *
+ * Reference:
+ *
+ * -
+ * RSA-PSS Signature Scheme with Appendix, part B. Primitive
+ * specification and supporting documentation. Jakob Jonsson and Burt Kaliski.
+ *
+ * - Handbook of Applied
+ * Cryptography, Alfred J. Menezes, Paul C. van Oorschot and Scott A.
+ * Vanstone. Section 11.3 RSA and related signature schemes.
+ *
+ */
+public class RSAKeyPairGenerator implements IKeyPairGenerator
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** The BigInteger constant 1. */
+ private static final BigInteger ONE = BigInteger.ONE;
+
+ /** The BigInteger constant 2. */
+ private static final BigInteger TWO = BigInteger.valueOf(2L);
+
+ /** Property name of the length (Integer) of the modulus of an RSA key. */
+ public static final String MODULUS_LENGTH = "gnu.crypto.rsa.L";
+
+ /**
+ * Property name of an optional {@link SecureRandom} instance to use. The
+ * default is to use a classloader singleton from {@link PRNG}.
+ */
+ public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.rsa.prng";
+
+ /**
+ * Property name of an optional {@link RSAKeyGenParameterSpec} instance to
+ * use for this generator's n
, and e
values. The
+ * default is to generate n
and use a fixed value for
+ * e (Fermat's F4 number).
+ */
+ public static final String RSA_PARAMETERS = "gnu.crypto.rsa.params";
+
+ /**
+ * Property name of the preferred encoding format to use when externalizing
+ * generated instance of key-pairs from this generator. The property is taken
+ * to be an {@link Integer} that encapsulates an encoding format identifier.
+ */
+ public static final String PREFERRED_ENCODING_FORMAT = "gnu.crypto.rsa.encoding";
+
+ /** Default value for the modulus length. */
+ private static final int DEFAULT_MODULUS_LENGTH = 1024;
+
+ /** Default encoding format to use when none was specified. */
+ private static final int DEFAULT_ENCODING_FORMAT = Registry.RAW_ENCODING_ID;
+
+ /** The desired bit length of the modulus. */
+ private int L;
+
+ /**
+ * This implementation uses, by default, Fermat's F4 number as the public
+ * exponent.
+ */
+ private BigInteger e = BigInteger.valueOf(65537L);
+
+ /** The optional {@link SecureRandom} instance to use. */
+ private SecureRandom rnd = null;
+
+ /** Our default source of randomness. */
+ private PRNG prng = null;
+
+ /** Preferred encoding format of generated keys. */
+ private int preferredFormat;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ // implicit 0-arguments constructor
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // gnu.crypto.key.IKeyPairGenerator interface implementation ---------------
+
+ public String name()
+ {
+ return Registry.RSA_KPG;
+ }
+
+ /**
+ * Configures this instance.
+ *
+ * @param attributes the map of name/value pairs to use.
+ * @exception IllegalArgumentException if the designated MODULUS_LENGTH
+ * value is less than 1024.
+ */
+ public void setup(Map attributes)
+ {
+ // do we have a SecureRandom, or should we use our own?
+ rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
+
+ // are we given a set of RSA params or we shall use our own?
+ RSAKeyGenParameterSpec params = (RSAKeyGenParameterSpec) attributes.get(RSA_PARAMETERS);
+
+ // find out the modulus length
+ if (params != null)
+ {
+ L = params.getKeysize();
+ e = params.getPublicExponent();
+ }
+ else
+ {
+ Integer l = (Integer) attributes.get(MODULUS_LENGTH);
+ L = (l == null ? DEFAULT_MODULUS_LENGTH : l.intValue());
+ }
+
+ if (L < 1024)
+ {
+ throw new IllegalArgumentException(MODULUS_LENGTH);
+ }
+
+ // what is the preferred encoding format
+ Integer formatID = (Integer) attributes.get(PREFERRED_ENCODING_FORMAT);
+ preferredFormat = formatID == null ? DEFAULT_ENCODING_FORMAT
+ : formatID.intValue();
+ }
+
+ /**
+ * The algorithm used here is described in nessie-pss-B.pdf
+ * document which is part of the RSA-PSS submission to NESSIE.
+ *
+ * @return an RSA keypair.
+ */
+ public KeyPair generate()
+ {
+ BigInteger p, q, n, d;
+
+ // 1. Generate a prime p in the interval [2**(M-1), 2**M - 1], where
+ // M = CEILING(L/2), and such that GCD(p, e) = 1
+ int M = (L + 1) / 2;
+ BigInteger lower = TWO.pow(M - 1);
+ BigInteger upper = TWO.pow(M).subtract(ONE);
+ byte[] kb = new byte[(M + 7) / 8]; // enough bytes to frame M bits
+ step1: while (true)
+ {
+ nextRandomBytes(kb);
+ p = new BigInteger(1, kb).setBit(0);
+ if (p.compareTo(lower) >= 0 && p.compareTo(upper) <= 0
+ && Prime2.isProbablePrime(p) && p.gcd(e).equals(ONE))
+ {
+ break step1;
+ }
+ }
+
+ // 2. Generate a prime q such that the product of p and q is an L-bit
+ // number, and such that GCD(q, e) = 1
+ step2: while (true)
+ {
+ nextRandomBytes(kb);
+ q = new BigInteger(1, kb).setBit(0);
+ n = p.multiply(q);
+ if (n.bitLength() == L && Prime2.isProbablePrime(q)
+ && q.gcd(e).equals(ONE))
+ {
+ break step2;
+ }
+
+ // TODO: test for p != q
+ }
+
+ // TODO: ensure p < q
+
+ // 3. Put n = pq. The public key is (n, e).
+ // 4. Compute the parameters necessary for the private key K (see
+ // Section 2.2).
+ BigInteger phi = p.subtract(ONE).multiply(q.subtract(ONE));
+ d = e.modInverse(phi);
+
+ // 5. Output the public key and the private key.
+ PublicKey pubK = new GnuRSAPublicKey(preferredFormat, n, e);
+ PrivateKey secK = new GnuRSAPrivateKey(preferredFormat, p, q, e, d);
+
+ return new KeyPair(pubK, secK);
+ }
+
+ // helper methods ----------------------------------------------------------
+
+ /**
+ * Fills the designated byte array with random data.
+ *
+ * @param buffer the byte array to fill with random data.
+ */
+ private void nextRandomBytes(byte[] buffer)
+ {
+ if (rnd != null)
+ {
+ rnd.nextBytes(buffer);
+ }
+ else
+ getDefaultPRNG().nextBytes(buffer);
+ }
+
+ private PRNG getDefaultPRNG()
+ {
+ if (prng == null)
+ prng = PRNG.getInstance();
+
+ return prng;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java b/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
new file mode 100644
index 0000000..a7f65b6
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
@@ -0,0 +1,284 @@
+/* RSAKeyPairPKCS8Codec.java -- PKCS#8 Encoding/Decoding handler
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.rsa;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.InvalidParameterException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.util.ArrayList;
+
+import gnu.java.security.OID;
+import gnu.java.security.Registry;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+import gnu.java.security.der.DERWriter;
+import gnu.java.security.key.IKeyPairCodec;
+import gnu.java.security.util.DerUtil;
+
+/**
+ * An implementation of an {@link IKeyPairCodec} that knows how to encode /
+ * decode PKCS#8 ASN.1 external representation of RSA private keys.
+ */
+public class RSAKeyPairPKCS8Codec
+ implements IKeyPairCodec
+{
+ private static final OID RSA_ALG_OID = new OID(Registry.RSA_OID_STRING);
+
+ // implicit 0-arguments constructor
+
+ public int getFormatID()
+ {
+ return PKCS8_FORMAT;
+ }
+
+ /**
+ * @throws InvalidParameterException ALWAYS.
+ */
+ public byte[] encodePublicKey(PublicKey key)
+ {
+ throw new InvalidParameterException("Wrong format for public keys");
+ }
+
+ /**
+ * Returns the PKCS#8 ASN.1 PrivateKeyInfo representation of an RSA
+ * private key. The ASN.1 specification is as follows:
+ *
+ *
+ * PrivateKeyInfo ::= SEQUENCE {
+ * version INTEGER, -- MUST be 0
+ * privateKeyAlgorithm AlgorithmIdentifier,
+ * privateKey OCTET STRING
+ * }
+ *
+ * AlgorithmIdentifier ::= SEQUENCE {
+ * algorithm OBJECT IDENTIFIER,
+ * parameters ANY DEFINED BY algorithm OPTIONAL
+ * }
+ *
+ *
+ * The privateKey field, which is an OCTET STRING, contains the
+ * DER-encoded form of the RSA private key defined as:
+ *
+ *
+ * RSAPrivateKey ::= SEQUENCE {
+ * version INTEGER, -- MUST be 0
+ * modulus INTEGER, -- n
+ * publicExponent INTEGER, -- e
+ * privateExponent INTEGER, -- d
+ * prime1 INTEGER, -- p
+ * prime2 INTEGER, -- q
+ * exponent1 INTEGER, -- d mod (p-1)
+ * exponent2 INTEGER, -- d mod (q-1)
+ * coefficient INTEGER, -- (inverse of q) mod p
+ * }
+ *
+ *
+ * @return the DER encoded form of the ASN.1 representation of the
+ * PrivateKeyInfo field for an RSA {@link PrivateKey}..
+ * @throw InvalidParameterException if an error occurs during the marshalling
+ * process.
+ */
+ public byte[] encodePrivateKey(PrivateKey key)
+ {
+ if (! (key instanceof GnuRSAPrivateKey))
+ throw new InvalidParameterException("Wrong key type");
+
+ GnuRSAPrivateKey pk = (GnuRSAPrivateKey) key;
+ BigInteger n = pk.getN();
+ BigInteger e = pk.getE();
+ BigInteger d = pk.getPrivateExponent();
+ BigInteger p = pk.getPrimeP();
+ BigInteger q = pk.getPrimeQ();
+ BigInteger dP = pk.getPrimeExponentP();
+ BigInteger dQ = pk.getPrimeExponentQ();
+ BigInteger qInv = pk.getCrtCoefficient();
+
+ DERValue derVersion = new DERValue(DER.INTEGER, BigInteger.ZERO);
+
+ DERValue derOID = new DERValue(DER.OBJECT_IDENTIFIER, RSA_ALG_OID);
+
+ ArrayList algorithmID = new ArrayList(1);
+ algorithmID.add(derOID);
+ DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,
+ algorithmID);
+
+ DERValue derRSAVersion = new DERValue(DER.INTEGER, BigInteger.ZERO);
+ DERValue derN = new DERValue(DER.INTEGER, n);
+ DERValue derE = new DERValue(DER.INTEGER, e);
+ DERValue derD = new DERValue(DER.INTEGER, d);
+ DERValue derP = new DERValue(DER.INTEGER, p);
+ DERValue derQ = new DERValue(DER.INTEGER, q);
+ DERValue derDP = new DERValue(DER.INTEGER, dP);
+ DERValue derDQ = new DERValue(DER.INTEGER, dQ);
+ DERValue derQInv = new DERValue(DER.INTEGER, qInv);
+
+ ArrayList rsaPrivateKey = new ArrayList();
+ rsaPrivateKey.add(derRSAVersion);
+ rsaPrivateKey.add(derN);
+ rsaPrivateKey.add(derE);
+ rsaPrivateKey.add(derD);
+ rsaPrivateKey.add(derP);
+ rsaPrivateKey.add(derQ);
+ rsaPrivateKey.add(derDP);
+ rsaPrivateKey.add(derDQ);
+ rsaPrivateKey.add(derQInv);
+ DERValue derRSAPrivateKey = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,
+ rsaPrivateKey);
+ byte[] pkBytes = derRSAPrivateKey.getEncoded();
+ DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, pkBytes);
+
+ ArrayList pki = new ArrayList(3);
+ pki.add(derVersion);
+ pki.add(derAlgorithmID);
+ pki.add(derPrivateKey);
+ DERValue derPKI = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, pki);
+
+ byte[] result;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try
+ {
+ DERWriter.write(baos, derPKI);
+ result = baos.toByteArray();
+ }
+ catch (IOException x)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(x);
+ throw y;
+ }
+
+ return result;
+ }
+
+ /**
+ * @throws InvalidParameterException ALWAYS.
+ */
+ public PublicKey decodePublicKey(byte[] input)
+ {
+ throw new InvalidParameterException("Wrong format for public keys");
+ }
+
+ /**
+ * @param input the byte array to unmarshall into a valid RSA
+ * {@link PrivateKey} instance. MUST NOT be null.
+ * @return a new instance of a {@link GnuRSAPrivateKey} decoded from the
+ * PrivateKeyInfo material fed as input
.
+ * @throw InvalidParameterException if an exception occurs during the
+ * unmarshalling process.
+ */
+ public PrivateKey decodePrivateKey(byte[] input)
+ {
+ if (input == null)
+ throw new InvalidParameterException("Input bytes MUST NOT be null");
+
+ BigInteger version, n, e, d, p, q, dP, dQ, qInv;
+ DERReader der = new DERReader(input);
+ try
+ {
+ DERValue derPKI = der.read();
+ DerUtil.checkIsConstructed(derPKI, "Wrong PrivateKeyInfo field");
+
+ DERValue derVersion = der.read();
+ DerUtil.checkIsBigInteger(derVersion, "Wrong Version field");
+ version = (BigInteger) derVersion.getValue();
+ if (version.compareTo(BigInteger.ZERO) != 0)
+ throw new InvalidParameterException("Unexpected Version: " + version);
+
+ DERValue derAlgoritmID = der.read();
+ DerUtil.checkIsConstructed(derAlgoritmID, "Wrong AlgorithmIdentifier field");
+
+ DERValue derOID = der.read();
+ OID algOID = (OID) derOID.getValue();
+ if (! algOID.equals(RSA_ALG_OID))
+ throw new InvalidParameterException("Unexpected OID: " + algOID);
+
+ DERValue val = der.read();
+ byte[] pkBytes = (byte[]) val.getValue();
+
+ der = new DERReader(pkBytes);
+ DERValue derRSAPrivateKey = der.read();
+ DerUtil.checkIsConstructed(derRSAPrivateKey, "Wrong RSAPrivateKey field");
+
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong RSAPrivateKey Version field");
+ version = (BigInteger) val.getValue();
+ if (version.compareTo(BigInteger.ZERO) != 0)
+ throw new InvalidParameterException("Unexpected RSAPrivateKey Version: "
+ + version);
+
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong modulus field");
+ n = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong publicExponent field");
+ e = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong privateExponent field");
+ d = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong prime1 field");
+ p = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong prime2 field");
+ q = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong exponent1 field");
+ dP = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong exponent2 field");
+ dQ = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong coefficient field");
+ qInv = (BigInteger) val.getValue();
+ }
+ catch (IOException x)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(x);
+ throw y;
+ }
+
+ return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID, n, e, d, p, q,
+ dP, dQ, qInv);
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java b/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java
new file mode 100644
index 0000000..fb7cea9
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java
@@ -0,0 +1,332 @@
+/* RSAKeyPairRawCodec.java --
+ Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.key.IKeyPairCodec;
+
+import java.io.ByteArrayOutputStream;
+import java.math.BigInteger;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+
+/**
+ * An object that implements the {@link IKeyPairCodec} interface for the
+ * Raw format to use with RSA keypairs.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class RSAKeyPairRawCodec implements IKeyPairCodec
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ // implicit 0-arguments constructor
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // gnu.crypto.key.IKeyPairCodec interface implementation -------------------
+
+ public int getFormatID()
+ {
+ return RAW_FORMAT;
+ }
+
+ /**
+ * Returns the encoded form of the designated RSA public key according to
+ * the Raw format supported by this library.
+ *
+ * The Raw format for an RSA public key, in this implementation, is
+ * a byte sequence consisting of the following:
+ *
+ *
+ * - 4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_RSA_PUBLIC_KEY},
-
+ *
- 1-byte version consisting of the constant: 0x01,
+ * - 4-byte count of following bytes representing the RSA parameter
+ *
n
(the modulus) in internet order,
+ * - n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the
toByteArray()
method on the RSA parameter n
,
+ * - 4-byte count of following bytes representing the RSA parameter
+ *
e
(the public exponent) in internet order,
+ * - n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the
toByteArray()
method on the RSA parameter e
.
+ *
+ *
+ * @param key the key to encode.
+ * @return the Raw format encoding of the designated key.
+ * @exception IllegalArgumentException if the designated key is not an RSA
+ * one.
+ */
+ public byte[] encodePublicKey(PublicKey key)
+ {
+ if (!(key instanceof GnuRSAPublicKey))
+ {
+ throw new IllegalArgumentException("key");
+ }
+
+ GnuRSAPublicKey rsaKey = (GnuRSAPublicKey) key;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ // magic
+ baos.write(Registry.MAGIC_RAW_RSA_PUBLIC_KEY[0]);
+ baos.write(Registry.MAGIC_RAW_RSA_PUBLIC_KEY[1]);
+ baos.write(Registry.MAGIC_RAW_RSA_PUBLIC_KEY[2]);
+ baos.write(Registry.MAGIC_RAW_RSA_PUBLIC_KEY[3]);
+
+ // version
+ baos.write(0x01);
+
+ // n
+ byte[] buffer = rsaKey.getModulus().toByteArray();
+ int length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ // e
+ buffer = rsaKey.getPublicExponent().toByteArray();
+ length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ return baos.toByteArray();
+ }
+
+ public PublicKey decodePublicKey(byte[] k)
+ {
+ // magic
+ if (k[0] != Registry.MAGIC_RAW_RSA_PUBLIC_KEY[0]
+ || k[1] != Registry.MAGIC_RAW_RSA_PUBLIC_KEY[1]
+ || k[2] != Registry.MAGIC_RAW_RSA_PUBLIC_KEY[2]
+ || k[3] != Registry.MAGIC_RAW_RSA_PUBLIC_KEY[3])
+ {
+ throw new IllegalArgumentException("magic");
+ }
+
+ // version
+ if (k[4] != 0x01)
+ {
+ throw new IllegalArgumentException("version");
+ }
+ int i = 5;
+
+ int l;
+ byte[] buffer;
+
+ // n
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ buffer = new byte[l];
+ System.arraycopy(k, i, buffer, 0, l);
+ i += l;
+ BigInteger n = new BigInteger(1, buffer);
+
+ // e
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ buffer = new byte[l];
+ System.arraycopy(k, i, buffer, 0, l);
+ i += l;
+ BigInteger e = new BigInteger(1, buffer);
+
+ return new GnuRSAPublicKey(n, e);
+ }
+
+ /**
+ * Returns the encoded form of the designated RSA private key according to
+ * the Raw format supported by this library.
+ *
+ * The Raw format for an RSA private key, in this implementation,
+ * is a byte sequence consisting of the following:
+ *
+ *
+ * - 4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_RSA_PRIVATE_KEY},
-
+ *
- 1-byte version consisting of the constant: 0x01,
+ * - 4-byte count of following bytes representing the RSA parameter
+ *
p
(the first prime factor of the modulus) in internet
+ * order,
+ * - n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the
toByteArray()
method on the RSA parameter p
,
+ * - 4-byte count of following bytes representing the RSA parameter
+ *
q
(the second prime factor of the modulus) in internet
+ * order,
+ * - n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the
toByteArray()
method on the RSA parameter q
,
+ * - 4-byte count of following bytes representing the RSA parameter
+ *
e
(the public exponent) in internet order,
+ * - n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the
toByteArray()
method on the RSA parameter e
,
+ * - 4-byte count of following bytes representing the RSA parameter
+ *
d
(the private exponent) in internet order,
+ * - n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the
toByteArray()
method on the RSA parameter d
,
+ *
+ *
+ * @param key the key to encode.
+ * @return the Raw format encoding of the designated key.
+ */
+ public byte[] encodePrivateKey(PrivateKey key)
+ {
+ if (!(key instanceof GnuRSAPrivateKey))
+ {
+ throw new IllegalArgumentException("key");
+ }
+
+ GnuRSAPrivateKey rsaKey = (GnuRSAPrivateKey) key;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ // magic
+ baos.write(Registry.MAGIC_RAW_RSA_PRIVATE_KEY[0]);
+ baos.write(Registry.MAGIC_RAW_RSA_PRIVATE_KEY[1]);
+ baos.write(Registry.MAGIC_RAW_RSA_PRIVATE_KEY[2]);
+ baos.write(Registry.MAGIC_RAW_RSA_PRIVATE_KEY[3]);
+
+ // version
+ baos.write(0x01);
+
+ // p
+ byte[] buffer = rsaKey.getPrimeP().toByteArray();
+ int length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ // q
+ buffer = rsaKey.getPrimeQ().toByteArray();
+ length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ // e
+ buffer = rsaKey.getPublicExponent().toByteArray();
+ length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ // d
+ buffer = rsaKey.getPrivateExponent().toByteArray();
+ length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ return baos.toByteArray();
+ }
+
+ public PrivateKey decodePrivateKey(byte[] k)
+ {
+ // magic
+ if (k[0] != Registry.MAGIC_RAW_RSA_PRIVATE_KEY[0]
+ || k[1] != Registry.MAGIC_RAW_RSA_PRIVATE_KEY[1]
+ || k[2] != Registry.MAGIC_RAW_RSA_PRIVATE_KEY[2]
+ || k[3] != Registry.MAGIC_RAW_RSA_PRIVATE_KEY[3])
+ {
+ throw new IllegalArgumentException("magic");
+ }
+
+ // version
+ if (k[4] != 0x01)
+ {
+ throw new IllegalArgumentException("version");
+ }
+ int i = 5;
+
+ int l;
+ byte[] buffer;
+
+ // p
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ buffer = new byte[l];
+ System.arraycopy(k, i, buffer, 0, l);
+ i += l;
+ BigInteger p = new BigInteger(1, buffer);
+
+ // q
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ buffer = new byte[l];
+ System.arraycopy(k, i, buffer, 0, l);
+ i += l;
+ BigInteger q = new BigInteger(1, buffer);
+
+ // e
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ buffer = new byte[l];
+ System.arraycopy(k, i, buffer, 0, l);
+ i += l;
+ BigInteger e = new BigInteger(1, buffer);
+
+ // d
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ buffer = new byte[l];
+ System.arraycopy(k, i, buffer, 0, l);
+ i += l;
+ BigInteger d = new BigInteger(1, buffer);
+
+ return new GnuRSAPrivateKey(p, q, e, d);
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java b/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
new file mode 100644
index 0000000..1c36278
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
@@ -0,0 +1,248 @@
+/* RSAKeyPairX509Codec.java -- X.509 Encoding/Decoding handler
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.key.rsa;
+
+import gnu.java.security.OID;
+import gnu.java.security.Registry;
+import gnu.java.security.der.BitString;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+import gnu.java.security.der.DERWriter;
+import gnu.java.security.key.IKeyPairCodec;
+import gnu.java.security.util.DerUtil;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.InvalidParameterException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.util.ArrayList;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of an {@link IKeyPairCodec} that knows how to encode /
+ * decode X.509 ASN.1 external representation of RSA public keys.
+ */
+public class RSAKeyPairX509Codec
+ implements IKeyPairCodec
+{
+ private static final Logger log = Logger.getLogger(RSAKeyPairX509Codec.class.getName());
+ private static final OID RSA_ALG_OID = new OID(Registry.RSA_OID_STRING);
+
+ // implicit 0-arguments constructor
+
+ public int getFormatID()
+ {
+ return X509_FORMAT;
+ }
+
+ /**
+ * Returns the X.509 ASN.1 SubjectPublicKeyInfo representation of an
+ * RSA public key. The ASN.1 specification, as defined in RFC-3280, and
+ * RFC-2459, is as follows:
+ *
+ *
+ * SubjectPublicKeyInfo ::= SEQUENCE {
+ * algorithm AlgorithmIdentifier,
+ * subjectPublicKey BIT STRING
+ * }
+ *
+ * AlgorithmIdentifier ::= SEQUENCE {
+ * algorithm OBJECT IDENTIFIER,
+ * parameters ANY DEFINED BY algorithm OPTIONAL
+ * }
+ *
+ *
+ * As indicated in RFC-2459: "The parameters field shall have ASN.1 type NULL
+ * for this algorithm identifier.".
+ *
+ * The subjectPublicKey field, which is a BIT STRING, contains the
+ * DER-encoded form of the RSA public key defined as:
+ *
+ *
+ * RSAPublicKey ::= SEQUENCE {
+ * modulus INTEGER, -- n
+ * publicExponent INTEGER -- e
+ * }
+ *
+ *
+ * @param key the {@link PublicKey} instance to encode. MUST be an instance of
+ * {@link GnuRSAPublicKey}.
+ * @return the ASN.1 representation of the SubjectPublicKeyInfo in an
+ * X.509 certificate.
+ * @throw InvalidParameterException if key
is not an instance
+ * of {@link GnuRSAPublicKey} or if an exception occurs during the
+ * marshalling process.
+ */
+ public byte[] encodePublicKey(PublicKey key)
+ {
+ log.entering(this.getClass().getName(), "encodePublicKey()", key);
+
+ if (! (key instanceof GnuRSAPublicKey))
+ throw new InvalidParameterException("key");
+
+ DERValue derOID = new DERValue(DER.OBJECT_IDENTIFIER, RSA_ALG_OID);
+
+ GnuRSAPublicKey rsaKey = (GnuRSAPublicKey) key;
+ BigInteger n = rsaKey.getN();
+ BigInteger e = rsaKey.getE();
+
+ DERValue derN = new DERValue(DER.INTEGER, n);
+ DERValue derE = new DERValue(DER.INTEGER, e);
+
+ ArrayList algorithmID = new ArrayList(1);
+ algorithmID.add(derOID);
+ DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,
+ algorithmID);
+
+ ArrayList publicKey = new ArrayList(2);
+ publicKey.add(derN);
+ publicKey.add(derE);
+ DERValue derPublicKey = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,
+ publicKey);
+ byte[] spkBytes = derPublicKey.getEncoded();
+ DERValue derSPK = new DERValue(DER.BIT_STRING, new BitString(spkBytes));
+
+ ArrayList spki = new ArrayList(2);
+ spki.add(derAlgorithmID);
+ spki.add(derSPK);
+ DERValue derSPKI = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, spki);
+
+ byte[] result;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try
+ {
+ DERWriter.write(baos, derSPKI);
+ result = baos.toByteArray();
+ }
+ catch (IOException x)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(x);
+ throw y;
+ }
+
+ log.exiting(this.getClass().getName(), "encodePublicKey()", result);
+ return result;
+ }
+
+ /**
+ * @throws InvalidParameterException ALWAYS.
+ */
+ public byte[] encodePrivateKey(PrivateKey key)
+ {
+ throw new InvalidParameterException("Wrong format for private keys");
+ }
+
+ /**
+ * @param input the byte array to unmarshall into a valid RSA
+ * {@link PublicKey} instance. MUST NOT be null.
+ * @return a new instance of a {@link GnuRSAPublicKey} decoded from the
+ * SubjectPublicKeyInfo material in an X.509 certificate.
+ * @throw InvalidParameterException if an exception occurs during the
+ * unmarshalling process.
+ */
+ public PublicKey decodePublicKey(byte[] input)
+ {
+ log.entering(this.getClass().getName(), "decodePublicKey()", input);
+
+ if (input == null)
+ throw new InvalidParameterException("Input bytes MUST NOT be null");
+
+ BigInteger n, e;
+ DERReader der = new DERReader(input);
+ try
+ {
+ DERValue derSPKI = der.read();
+ DerUtil.checkIsConstructed(derSPKI, "Wrong SubjectPublicKeyInfo field");
+
+ DERValue derAlgorithmID = der.read();
+ DerUtil.checkIsConstructed(derAlgorithmID, "Wrong AlgorithmIdentifier field");
+
+ DERValue derOID = der.read();
+ if (! (derOID.getValue() instanceof OID))
+ throw new InvalidParameterException("Wrong Algorithm field");
+
+ OID algOID = (OID) derOID.getValue();
+ if (! algOID.equals(RSA_ALG_OID))
+ throw new InvalidParameterException("Unexpected OID: " + algOID);
+
+ // rfc-2459 states that this field is OPTIONAL but NULL if/when present
+ DERValue val = der.read();
+ if (val.getTag() == DER.NULL)
+ val = der.read();
+
+ if (! (val.getValue() instanceof BitString))
+ throw new InvalidParameterException("Wrong SubjectPublicKey field");
+
+ byte[] spkBytes = ((BitString) val.getValue()).toByteArray();
+
+ der = new DERReader(spkBytes);
+ val = der.read();
+ DerUtil.checkIsConstructed(derAlgorithmID, "Wrong subjectPublicKey field");
+
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong modulus field");
+ n = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong publicExponent field");
+ e = (BigInteger) val.getValue();
+ }
+ catch (IOException x)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(x);
+ throw y;
+ }
+
+ PublicKey result = new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e);
+ log.exiting(this.getClass().getName(), "decodePublicKey()", result);
+ return result;
+ }
+
+ /**
+ * @throws InvalidParameterException ALWAYS.
+ */
+ public PrivateKey decodePrivateKey(byte[] input)
+ {
+ throw new InvalidParameterException("Wrong format for private keys");
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/prng/BasePRNG.java b/libjava/classpath/gnu/java/security/prng/BasePRNG.java
new file mode 100644
index 0000000..fe815d7
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/prng/BasePRNG.java
@@ -0,0 +1,199 @@
+/* BasePRNG.java --
+ Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.prng;
+
+import java.util.Map;
+
+/**
+ * An abstract class to facilitate implementing PRNG algorithms.
+ */
+public abstract class BasePRNG implements IRandom
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** The canonical name prefix of the PRNG algorithm. */
+ protected String name;
+
+ /** Indicate if this instance has already been initialised or not. */
+ protected boolean initialised;
+
+ /** A temporary buffer to serve random bytes. */
+ protected byte[] buffer;
+
+ /** The index into buffer of where the next byte will come from. */
+ protected int ndx;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Trivial constructor for use by concrete subclasses.
+ *
+ * @param name the canonical name of this instance.
+ */
+ protected BasePRNG(String name)
+ {
+ super();
+
+ this.name = name;
+ initialised = false;
+ buffer = new byte[0];
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // IRandom interface implementation ----------------------------------------
+
+ public String name()
+ {
+ return name;
+ }
+
+ public void init(Map attributes)
+ {
+ this.setup(attributes);
+
+ ndx = 0;
+ initialised = true;
+ }
+
+ public byte nextByte() throws IllegalStateException, LimitReachedException
+ {
+ if (!initialised)
+ {
+ throw new IllegalStateException();
+ }
+ return nextByteInternal();
+ }
+
+ public void nextBytes(byte[] out) throws IllegalStateException,
+ LimitReachedException
+ {
+ nextBytes(out, 0, out.length);
+ }
+
+ public void nextBytes(byte[] out, int offset, int length)
+ throws IllegalStateException, LimitReachedException
+ {
+ if (!initialised)
+ throw new IllegalStateException("not initialized");
+
+ if (length == 0)
+ return;
+
+ if (offset < 0 || length < 0 || offset + length > out.length)
+ throw new ArrayIndexOutOfBoundsException("offset=" + offset + " length="
+ + length + " limit="
+ + out.length);
+
+ if (ndx >= buffer.length)
+ {
+ fillBlock();
+ ndx = 0;
+ }
+ int count = 0;
+ while (count < length)
+ {
+ int amount = Math.min(buffer.length - ndx, length - count);
+ System.arraycopy(buffer, ndx, out, offset + count, amount);
+ count += amount;
+ ndx += amount;
+ if (ndx >= buffer.length)
+ {
+ fillBlock();
+ ndx = 0;
+ }
+ }
+ }
+
+ public void addRandomByte(byte b)
+ {
+ throw new UnsupportedOperationException("random state is non-modifiable");
+ }
+
+ public void addRandomBytes(byte[] buffer)
+ {
+ addRandomBytes(buffer, 0, buffer.length);
+ }
+
+ public void addRandomBytes(byte[] buffer, int offset, int length)
+ {
+ throw new UnsupportedOperationException("random state is non-modifiable");
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ public boolean isInitialised()
+ {
+ return initialised;
+ }
+
+ private byte nextByteInternal() throws LimitReachedException
+ {
+ if (ndx >= buffer.length)
+ {
+ this.fillBlock();
+ ndx = 0;
+ }
+
+ return buffer[ndx++];
+ }
+
+ // abstract methods to implement by subclasses -----------------------------
+
+ public Object clone() throws CloneNotSupportedException
+ {
+ BasePRNG result = (BasePRNG) super.clone();
+ if (this.buffer != null)
+ result.buffer = (byte[]) this.buffer.clone();
+
+ return result;
+ }
+
+ public abstract void setup(Map attributes);
+
+ public abstract void fillBlock() throws LimitReachedException;
+}
diff --git a/libjava/classpath/gnu/java/security/prng/EntropySource.java b/libjava/classpath/gnu/java/security/prng/EntropySource.java
new file mode 100644
index 0000000..260c668
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/prng/EntropySource.java
@@ -0,0 +1,62 @@
+/* EntropySource.java --
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.prng;
+
+/**
+ * A generic interface for adding random bytes to an entropy pool.
+ */
+public interface EntropySource
+{
+
+ /**
+ * Returns the estimated quality of this source. This value should be
+ * between 0 and 100 (the running quality is computed as a percentage,
+ * 100 percent being perfect-quality).
+ *
+ * @return The quality.
+ */
+ double quality();
+
+ /**
+ * Returns a new buffer with the next random bytes to add.
+ *
+ * @return The next random bytes.
+ */
+ byte[] nextBytes();
+}
\ No newline at end of file
diff --git a/libjava/classpath/gnu/java/security/prng/IRandom.java b/libjava/classpath/gnu/java/security/prng/IRandom.java
new file mode 100644
index 0000000..2c89e7a
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/prng/IRandom.java
@@ -0,0 +1,180 @@
+/* IRandom.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.prng;
+
+import java.util.Map;
+
+/**
+ * The basic visible methods of any pseudo-random number generator.
+ *
+ * The [HAC] defines a PRNG (as implemented in this library) as follows:
+ *
+ *
+ * - "5.6 Definition: A pseudorandom bit generator (PRBG) is said to pass
+ * the next-bit test if there is no polynomial-time algorithm which,
+ * on input of the first
L
bits of an output sequence S
,
+ * can predict the (L+1)
st bit of S
with a
+ * probability significantly grater than 1/2
."
+ *
+ * - "5.8 Definition: A PRBG that passes the next-bit test
+ * (possibly under some plausible but unproved mathematical assumption such
+ * as the intractability of factoring integers) is called a
+ * cryptographically secure pseudorandom bit generator (CSPRBG)."
+ *
+ *
+ * IMPLEMENTATION NOTE: Although all the concrete classes in this
+ * package implement the {@link Cloneable} interface, it is important to note
+ * here that such an operation, for those algorithms that use an underlting
+ * symmetric key block cipher, DOES NOT clone any session key material
+ * that may have been used in initialising the source PRNG (the instance to be
+ * cloned). Instead a clone of an already initialised PRNG, that uses and
+ * underlying symmetric key block cipher, is another instance with a clone of
+ * the same cipher that operates with the same block size but without any
+ * knowledge of neither key material nor key size.
+ *
+ * References:
+ *
+ *
+ * - [HAC]: Handbook of
+ * Applied Cryptography.
+ * CRC Press, Inc. ISBN 0-8493-8523-7, 1997
+ * Menezes, A., van Oorschot, P. and S. Vanstone.
+ *
+ */
+public interface IRandom extends Cloneable
+{
+
+ // Constants
+ // -------------------------------------------------------------------------
+
+ // Methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the canonical name of this instance.
+ *
+ * @return the canonical name of this instance. */
+ String name();
+
+ /**
+ * Initialises the pseudo-random number generator scheme with the
+ * appropriate attributes.
+ *
+ * @param attributes a set of name-value pairs that describe the desired
+ * future instance behaviour.
+ * @exception IllegalArgumentException if at least one of the defined name/
+ * value pairs contains invalid data.
+ */
+ void init(Map attributes);
+
+ /**
+ * Returns the next 8 bits of random data generated from this instance.
+ *
+ * @return the next 8 bits of random data generated from this instance.
+ * @exception IllegalStateException if the instance is not yet initialised.
+ * @exception LimitReachedException if this instance has reached its
+ * theoretical limit for generating non-repetitive pseudo-random data.
+ */
+ byte nextByte() throws IllegalStateException, LimitReachedException;
+
+ /**
+ * Fills the designated byte array, starting from byte at index
+ * offset
, for a maximum of length
bytes with the
+ * output of this generator instance.
+ *
+ * @param out the placeholder to contain the generated random bytes.
+ * @param offset the starting index in out to consider. This method
+ * does nothing if this parameter is not within 0
and
+ * out.length
.
+ * @param length the maximum number of required random bytes. This method
+ * does nothing if this parameter is less than 1
.
+ * @exception IllegalStateException if the instance is not yet initialised.
+ * @exception LimitReachedException if this instance has reached its
+ * theoretical limit for generating non-repetitive pseudo-random data.
+ */
+ void nextBytes(byte[] out, int offset, int length)
+ throws IllegalStateException, LimitReachedException;
+
+ /**
+ *
Supplement, or possibly replace, the random state of this PRNG with
+ * a random byte.
+ *
+ * Implementations are not required to implement this method in any
+ * meaningful way; this may be a no-operation, and implementations may
+ * throw an {@link UnsupportedOperationException}.
+ *
+ * @param b The byte to add.
+ */
+ void addRandomByte(byte b);
+
+ /**
+ * Supplement, or possibly replace, the random state of this PRNG with
+ * a sequence of new random bytes.
+ *
+ * Implementations are not required to implement this method in any
+ * meaningful way; this may be a no-operation, and implementations may
+ * throw an {@link UnsupportedOperationException}.
+ *
+ * @param in The buffer of new random bytes to add.
+ */
+ void addRandomBytes(byte[] in);
+
+ /**
+ * Supplement, or possibly replace, the random state of this PRNG with
+ * a sequence of new random bytes.
+ *
+ * Implementations are not required to implement this method in any
+ * meaningful way; this may be a no-operation, and implementations may
+ * throw an {@link UnsupportedOperationException}.
+ *
+ * @param in The buffer of new random bytes to add.
+ * @param offset The offset from whence to begin reading random bytes.
+ * @param length The number of random bytes to add.
+ * @exception IndexOutOfBoundsException If offset, length,
+ * or offset+length is out of bounds.
+ */
+ void addRandomBytes(byte[] in, int offset, int length);
+
+ /**
+ * Returns a clone copy of this instance.
+ *
+ * @return a clone copy of this instance.
+ */
+ Object clone() throws CloneNotSupportedException;
+}
\ No newline at end of file
diff --git a/libjava/classpath/gnu/java/security/prng/LimitReachedException.java b/libjava/classpath/gnu/java/security/prng/LimitReachedException.java
new file mode 100644
index 0000000..2fd8bfa
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/prng/LimitReachedException.java
@@ -0,0 +1,69 @@
+/* LimitReachedException.java --
+ Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.prng;
+
+/**
+ * A checked exception that indicates that a pseudo random number generated has
+ * reached its theoretical limit in generating random bytes.
+ */
+public class LimitReachedException extends Exception
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ public LimitReachedException()
+ {
+ super();
+ }
+
+ public LimitReachedException(String msg)
+ {
+ super(msg);
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instant methods
+ // -------------------------------------------------------------------------
+}
\ No newline at end of file
diff --git a/libjava/classpath/gnu/java/security/prng/MDGenerator.java b/libjava/classpath/gnu/java/security/prng/MDGenerator.java
new file mode 100644
index 0000000..255647d
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/prng/MDGenerator.java
@@ -0,0 +1,135 @@
+/* MDGenerator.java --
+ Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.prng;
+
+import gnu.java.security.Registry;
+import gnu.java.security.hash.HashFactory;
+import gnu.java.security.hash.IMessageDigest;
+
+import java.util.Map;
+
+/**
+ * A simple pseudo-random number generator that relies on a hash algorithm,
+ * that (a) starts its operation by hashing a seed
, and then (b)
+ * continuously re-hashing its output. If no hash algorithm name is specified
+ * in the {@link Map} of attributes used to initialise the instance then the
+ * SHA-160 algorithm is used as the underlying hash function. Also, if no
+ * seed
is given, an empty octet sequence is used.
+ */
+public class MDGenerator extends BasePRNG implements Cloneable
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** Property name of underlying hash algorithm for this generator. */
+ public static final String MD_NAME = "gnu.crypto.prng.md.hash.name";
+
+ /** Property name of seed material. */
+ public static final String SEEED = "gnu.crypto.prng.md.seed";
+
+ /** The underlying hash instance. */
+ private IMessageDigest md;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Trivial 0-arguments constructor. */
+ public MDGenerator()
+ {
+ super(Registry.MD_PRNG);
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // Implementation of abstract methods in BaseRandom ------------------------
+
+ public void setup(Map attributes)
+ {
+ // find out which hash to use
+ String underlyingMD = (String) attributes.get(MD_NAME);
+ if (underlyingMD == null)
+ {
+ if (md == null)
+ { // happy birthday
+ // ensure we have a reliable implementation of this hash
+ md = HashFactory.getInstance(Registry.SHA160_HASH);
+ }
+ else
+ { // a clone. reset it for reuse
+ md.reset();
+ }
+ }
+ else
+ { // ensure we have a reliable implementation of this hash
+ md = HashFactory.getInstance(underlyingMD);
+ }
+
+ // get the seeed
+ byte[] seed = (byte[]) attributes.get(SEEED);
+ if (seed == null)
+ {
+ seed = new byte[0];
+ }
+
+ md.update(seed, 0, seed.length);
+ }
+
+ public void fillBlock() throws LimitReachedException
+ {
+ IMessageDigest mdc = (IMessageDigest) md.clone();
+ buffer = mdc.digest();
+ md.update(buffer, 0, buffer.length);
+ }
+
+ // Cloneable interface implementation ---------------------------------------
+
+ public Object clone() throws CloneNotSupportedException
+ {
+ MDGenerator result = (MDGenerator) super.clone();
+ if (this.md != null)
+ result.md = (IMessageDigest) this.md.clone();
+
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/prng/PRNGFactory.java b/libjava/classpath/gnu/java/security/prng/PRNGFactory.java
new file mode 100644
index 0000000..8b51414
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/prng/PRNGFactory.java
@@ -0,0 +1,109 @@
+/* PRNGFactory.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.prng;
+
+import gnu.java.security.Registry;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A Factory to instantiate pseudo random number generators.
+ */
+public class PRNGFactory implements Registry
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Trivial constructor to enforce Singleton pattern. */
+ protected PRNGFactory()
+ {
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns an instance of a padding algorithm given its name.
+ *
+ * @param prng the case-insensitive name of the PRNG.
+ * @return an instance of the pseudo-random number generator.
+ * @exception InternalError if the implementation does not pass its self-
+ * test.
+ */
+ public static final IRandom getInstance(String prng)
+ {
+ if (prng == null)
+ {
+ return null;
+ }
+
+ prng = prng.trim();
+ IRandom result = null;
+ if (prng.equalsIgnoreCase(MD_PRNG))
+ {
+ result = new MDGenerator();
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns a {@link Set} of names of padding algorithms supported by this
+ * Factory.
+ *
+ * @return a {@link Set} of pseudo-random number generator algorithm names
+ * (Strings).
+ */
+ public static final Set getNames()
+ {
+ HashSet hs = new HashSet();
+ hs.add(MD_PRNG);
+ return Collections.unmodifiableSet(hs);
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+}
diff --git a/libjava/classpath/gnu/java/security/prng/RandomEvent.java b/libjava/classpath/gnu/java/security/prng/RandomEvent.java
new file mode 100644
index 0000000..c070621
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/prng/RandomEvent.java
@@ -0,0 +1,82 @@
+/* RandomEvent.java -- an event with random data.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.prng;
+
+import java.util.EventObject;
+
+/**
+ * An interface for entropy accumulators that will be notified of random
+ * events.
+ */
+public class RandomEvent extends EventObject
+{
+
+ private final byte sourceNumber;
+
+ private final byte poolNumber;
+
+ private final byte[] data;
+
+ public RandomEvent(Object source, byte sourceNumber, byte poolNumber,
+ byte[] data)
+ {
+ super(source);
+ this.sourceNumber = sourceNumber;
+ this.poolNumber = poolNumber;
+ if (data.length == 0 || data.length > 32)
+ throw new IllegalArgumentException(
+ "random events take between 1 and 32 bytes of data");
+ this.data = (byte[]) data.clone();
+ }
+
+ public byte getSourceNumber()
+ {
+ return sourceNumber;
+ }
+
+ public byte getPoolNumber()
+ {
+ return poolNumber;
+ }
+
+ public byte[] getData()
+ {
+ return data;
+ }
+}
\ No newline at end of file
diff --git a/libjava/classpath/gnu/java/security/prng/RandomEventListener.java b/libjava/classpath/gnu/java/security/prng/RandomEventListener.java
new file mode 100644
index 0000000..1dc1461
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/prng/RandomEventListener.java
@@ -0,0 +1,50 @@
+/* RandomEventListener.java --
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.prng;
+
+import java.util.EventListener;
+
+/**
+ * An interface for entropy accumulators that will be notified of random
+ * events.
+ */
+public interface RandomEventListener extends EventListener
+{
+ void addRandomEvent(RandomEvent event);
+}
\ No newline at end of file
diff --git a/libjava/classpath/gnu/java/security/provider/DSAKeyFactory.java b/libjava/classpath/gnu/java/security/provider/DSAKeyFactory.java
deleted file mode 100644
index 7e154e2..0000000
--- a/libjava/classpath/gnu/java/security/provider/DSAKeyFactory.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/* DSAKeyFactory.java -- DSA key factory.
- Copyright (C) 2003 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.KeyFactorySpi;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.interfaces.DSAPrivateKey;
-import java.security.interfaces.DSAPublicKey;
-import java.security.spec.DSAPrivateKeySpec;
-import java.security.spec.DSAPublicKeySpec;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-
-/**
- * DSA key factory.
- *
- * @author Casey Marshall (rsdio@metastatic.org)
- */
-public class DSAKeyFactory extends KeyFactorySpi
-{
-
- // Constructor.
- // ------------------------------------------------------------------------
-
- public DSAKeyFactory()
- {
- super();
- }
-
- // Instance methods.
- // ------------------------------------------------------------------------
-
- protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
- throws InvalidKeySpecException
- {
- if (!(keySpec instanceof DSAPrivateKeySpec))
- throw new InvalidKeySpecException();
- return new GnuDSAPrivateKey(
- ((DSAPrivateKeySpec) keySpec).getX(),
- ((DSAPrivateKeySpec) keySpec).getP(),
- ((DSAPrivateKeySpec) keySpec).getQ(),
- ((DSAPrivateKeySpec) keySpec).getG());
- }
-
- protected PublicKey engineGeneratePublic(KeySpec keySpec)
- throws InvalidKeySpecException
- {
- if (!(keySpec instanceof DSAPublicKeySpec))
- throw new InvalidKeySpecException();
- return new GnuDSAPublicKey(
- ((DSAPublicKeySpec) keySpec).getY(),
- ((DSAPublicKeySpec) keySpec).getP(),
- ((DSAPublicKeySpec) keySpec).getQ(),
- ((DSAPublicKeySpec) keySpec).getG());
- }
-
- protected KeySpec engineGetKeySpec(Key key, Class keySpec)
- throws InvalidKeySpecException
- {
- if ((key instanceof DSAPublicKey) &&
- keySpec.isAssignableFrom(DSAPublicKeySpec.class))
- {
- return new DSAPublicKeySpec(((DSAPublicKey) key).getY(),
- ((DSAPublicKey) key).getParams().getP(),
- ((DSAPublicKey) key).getParams().getQ(),
- ((DSAPublicKey) key).getParams().getG());
- }
- if ((key instanceof DSAPrivateKey) &&
- keySpec.isAssignableFrom(DSAPrivateKeySpec.class))
- {
- return new DSAPrivateKeySpec(((DSAPrivateKey) key).getX(),
- ((DSAPrivateKey) key).getParams().getP(),
- ((DSAPrivateKey) key).getParams().getQ(),
- ((DSAPrivateKey) key).getParams().getG());
- }
- throw new InvalidKeySpecException();
- }
-
- protected Key engineTranslateKey(Key key) throws InvalidKeyException
- {
- if ((key instanceof GnuDSAPublicKey) || (key instanceof GnuDSAPrivateKey))
- return key;
- if (key instanceof DSAPublicKey)
- return new GnuDSAPublicKey(((DSAPublicKey) key).getY(),
- ((DSAPublicKey) key).getParams().getP(),
- ((DSAPublicKey) key).getParams().getQ(),
- ((DSAPublicKey) key).getParams().getG());
- if (key instanceof DSAPrivateKey)
- return new GnuDSAPrivateKey(((DSAPrivateKey) key).getX(),
- ((DSAPrivateKey) key).getParams().getP(),
- ((DSAPrivateKey) key).getParams().getQ(),
- ((DSAPrivateKey) key).getParams().getG());
- throw new InvalidKeyException();
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/DSAKeyPairGenerator.java b/libjava/classpath/gnu/java/security/provider/DSAKeyPairGenerator.java
deleted file mode 100644
index ddd1800..0000000
--- a/libjava/classpath/gnu/java/security/provider/DSAKeyPairGenerator.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/* GnuDSAKeyPairGenerator.java --- Gnu DSA Key Pair Generator
- Copyright (C) 1999, 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import java.math.BigInteger;
-import java.security.AlgorithmParameterGenerator;
-import java.security.AlgorithmParameters;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidParameterException;
-import java.security.KeyPair;
-import java.security.KeyPairGeneratorSpi;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.security.interfaces.DSAParams;
-import java.security.spec.AlgorithmParameterSpec;
-import java.security.spec.DSAParameterSpec;
-import java.security.spec.InvalidParameterSpecException;
-import java.util.Random;
-
-public class DSAKeyPairGenerator extends KeyPairGeneratorSpi
- implements java.security.interfaces.DSAKeyPairGenerator
-{
-int keysize;
-SecureRandom random;
-private BigInteger q = null; // the small prime
-private BigInteger p = null; // the big prime
-private BigInteger g = null;
-
-public DSAKeyPairGenerator()
-{
- keysize = 1024;
- getDefaults ();
-}
-
-public void initialize(int keysize, SecureRandom random)
-{
- initialize (keysize, false, random);
-}
-
-public void initialize(AlgorithmParameterSpec params,
- SecureRandom random)
- throws InvalidAlgorithmParameterException
-{
- if( !( params instanceof DSAParameterSpec ) )
- throw new InvalidAlgorithmParameterException("Must be DSAParameterSpec");
-
- try
- {
- initialize ((DSAParams) params, random);
- }
- catch (InvalidParameterException ipe)
- {
- InvalidAlgorithmParameterException iape =
- new InvalidAlgorithmParameterException();
- iape.initCause (ipe);
- throw iape;
- }
-}
-
-public void initialize (DSAParams params, SecureRandom random)
-{
- DSAParameterSpec dsaparameterspec = (DSAParameterSpec)params;
- if (dsaparameterspec.getP() == null
- || dsaparameterspec.getQ() == null
- || dsaparameterspec.getG() == null)
- {
- throw new InvalidParameterException ("none of p, q, or g may be null");
- }
- p = dsaparameterspec.getP();
- q = dsaparameterspec.getQ();
- g = dsaparameterspec.getG();
- this.random = random;
-}
-
-public void initialize(int modlen, boolean genParams, SecureRandom random)
- throws InvalidParameterException
-{
- if( ((modlen % 64) != 0) || (modlen < 512) || (modlen > 1024) )
- throw new InvalidParameterException();
-
- this.keysize = modlen;
- this.random = random;
- if (this.random == null)
- {
- this.random = new SecureRandom ();
- }
- if (genParams)
- {
- try
- {
- AlgorithmParameterGenerator apgDSA = AlgorithmParameterGenerator.getInstance("DSA");
- apgDSA.init (modlen, random);
- AlgorithmParameters apDSA = apgDSA.generateParameters();
- DSAParameterSpec dsaparameterspec = (DSAParameterSpec)apDSA.getParameterSpec( DSAParameterSpec.class );
- p = dsaparameterspec.getP();
- q = dsaparameterspec.getQ();
- g = dsaparameterspec.getG();
- }
- catch (NoSuchAlgorithmException nsae)
- {
- InvalidParameterException ipe =
- new InvalidParameterException ("can't generate DSA parameters");
- ipe.initCause (nsae);
- throw ipe;
- }
- catch (InvalidParameterSpecException ipse)
- {
- InvalidParameterException ipe =
- new InvalidParameterException ("can't generate DSA parameters");
- ipe.initCause (ipse);
- throw ipe;
- }
- }
- else if (!getDefaults ())
- {
- throw new InvalidParameterException ("unsupported key size: " + modlen);
- }
-}
-
-public KeyPair generateKeyPair()
-{
- if (random == null)
- {
- random = new SecureRandom ();
- }
-
- BigInteger x = new BigInteger( 159, random );
-
- BigInteger y = g.modPow( x, p );
-
- return new KeyPair( new GnuDSAPublicKey(y,p,q,g), new GnuDSAPrivateKey(x,p,q,g));
- //return new KeyPair( public, private );
-}
-
-//These constants are Sun's Constants copied from the
-//Cryptography Specification
-private boolean getDefaults()
-{
- if( keysize == 512) {
- p = new BigInteger("fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17", 16);
- q = new BigInteger("962eddcc369cba8ebb260ee6b6a126d9346e38c5", 16);
- g = new BigInteger("678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4", 16);
- return true;
- } else if( keysize == 768) {
- p = new BigInteger("e9e642599d355f37c97ffd3567120b8e25c9cd43e927b3a9670fbec5d890141922d2c3b3ad2480093799869d1e846aab49fab0ad26d2ce6a22219d470bce7d777d4a21fbe9c270b57f607002f3cef8393694cf45ee3688c11a8c56ab127a3daf", 16);
- q = new BigInteger("9cdbd84c9f1ac2f38d0f80f42ab952e7338bf511", 16);
- g = new BigInteger("30470ad5a005fb14ce2d9dcd87e38bc7d1b1c5facbaecbe95f190aa7a31d23c4dbbcbe06174544401a5b2c020965d8c2bd2171d3668445771f74ba084d2029d83c1c158547f3a9f1a2715be23d51ae4d3e5a1f6a7064f316933a346d3f529252", 16);
- return true;
- } else if( keysize == 1024) {
- p = new BigInteger("fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7", 16);
- q = new BigInteger("9760508f15230bccb292b982a2eb840bf0581cf5", 16);
- g = new BigInteger("f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a", 16);
- return true;
- }
- return false;
-}
-
-}
diff --git a/libjava/classpath/gnu/java/security/provider/DSAParameters.java b/libjava/classpath/gnu/java/security/provider/DSAParameters.java
deleted file mode 100644
index 77d6489..0000000
--- a/libjava/classpath/gnu/java/security/provider/DSAParameters.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/* DSAParameters.java --- DSA Parameters Implementation
- Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.io.ASN1ParsingException;
-import gnu.java.security.der.DER;
-import gnu.java.security.der.DERReader;
-import gnu.java.security.der.DERValue;
-import gnu.java.security.der.DERWriter;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.security.AlgorithmParametersSpi;
-import java.security.spec.AlgorithmParameterSpec;
-import java.security.spec.DSAParameterSpec;
-import java.security.spec.InvalidParameterSpecException;
-import java.util.ArrayList;
-
-/*
- ASN.1 Encoding for DSA from rfc2459
-
- id-dsa ID ::= { iso(1) member-body(2) us(840) x9-57(10040)
- x9cm(4) 1 }
-
- Dss-Parms ::= SEQUENCE {
- p INTEGER,
- q INTEGER,
- g INTEGER }
-
-*/
-public class DSAParameters extends AlgorithmParametersSpi
-{
-private BigInteger q; // the small prime
-private BigInteger p; // the big prime
-private BigInteger g;
-
-
-public void engineInit(AlgorithmParameterSpec paramSpec)
- throws InvalidParameterSpecException
-{
- if( paramSpec instanceof DSAParameterSpec ) {
- DSAParameterSpec dsaParamSpec = (DSAParameterSpec)paramSpec;
- p = dsaParamSpec.getP();
- q = dsaParamSpec.getQ();
- g = dsaParamSpec.getG();
- }
- else
- throw new InvalidParameterSpecException("Only accepts DSAParameterSpec");
-}
-
-public void engineInit(byte[] params)
- throws IOException
-{
- DERReader in = new DERReader(params);
- DERValue val = in.read();
- if (val.getValue() != DER.CONSTRUCTED_VALUE)
- throw new ASN1ParsingException("badly formed parameters");
- try
- {
- p = (BigInteger) in.read().getValue();
- q = (BigInteger) in.read().getValue();
- g = (BigInteger) in.read().getValue();
- }
- catch (Exception x)
- {
- throw new ASN1ParsingException("badly formed parameters");
- }
-}
-
-public void engineInit(byte[] params, String format)
- throws IOException
-{
- if( !format.equals("ASN.1") )
- throw new IOException("Invalid Format: Only accepts ASN.1");
- engineInit( params );
-}
-
-public AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
- throws InvalidParameterSpecException
-{
- if( paramSpec.isAssignableFrom(DSAParameterSpec.class) )
- return new DSAParameterSpec(p, q, g);
- else
- throw new InvalidParameterSpecException("Only accepts DSAParameterSpec");
-}
-
-public byte[] engineGetEncoded()
- throws IOException
-{
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- ArrayList seq = new ArrayList(3);
- seq.add(new DERValue(DER.INTEGER, p));
- seq.add(new DERValue(DER.INTEGER, q));
- seq.add(new DERValue(DER.INTEGER, g));
- DERWriter.write(bout, new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, seq));
- return bout.toByteArray();
-}
-
-
-public byte[] engineGetEncoded(String format)
- throws IOException
-{
- if( !format.equals("ASN.1") )
- throw new IOException("Invalid Format: Only accepts ASN.1");
- return engineGetEncoded();
-}
-
-public String engineToString()
-{
- return ("q: " + q + " p: " + p + " g: " + g);
-}
-
-}
diff --git a/libjava/classpath/gnu/java/security/provider/DSASignature.java b/libjava/classpath/gnu/java/security/provider/DSASignature.java
deleted file mode 100644
index 1d3875d..0000000
--- a/libjava/classpath/gnu/java/security/provider/DSASignature.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/* DSASignature.java --
- Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.der.DER;
-import gnu.java.security.der.DERReader;
-import gnu.java.security.der.DERValue;
-import gnu.java.security.der.DERWriter;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.InvalidParameterException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.SecureRandom;
-import java.security.SignatureException;
-import java.security.SignatureSpi;
-import java.security.interfaces.DSAPrivateKey;
-import java.security.interfaces.DSAPublicKey;
-import java.security.spec.AlgorithmParameterSpec;
-import java.util.ArrayList;
-import java.util.Random;
-
-public class DSASignature extends SignatureSpi
-{
- private DSAPublicKey publicKey;
- private DSAPrivateKey privateKey;
- private final MessageDigest digest;
- private final SecureRandom random;
-
- public DSASignature() throws NoSuchAlgorithmException
- {
- random = new SecureRandom();
- digest = MessageDigest.getInstance ("SHA1");
- }
-
- private void init()
- {
- digest.reset();
- }
-
- public void engineInitVerify (PublicKey publicKey)
- throws InvalidKeyException
- {
- if (publicKey instanceof DSAPublicKey)
- this.publicKey = (DSAPublicKey) publicKey;
- else
- throw new InvalidKeyException();
- init();
- }
-
- public void engineInitSign (PrivateKey privateKey)
- throws InvalidKeyException
- {
- if (privateKey instanceof DSAPrivateKey)
- this.privateKey = (DSAPrivateKey) privateKey;
- else
- throw new InvalidKeyException ("not a DSA private key");
-
- init();
- }
-
- public void engineInitSign (PrivateKey privateKey,
- SecureRandom random)
- throws InvalidKeyException
- {
- if (privateKey instanceof DSAPrivateKey)
- this.privateKey = (DSAPrivateKey) privateKey;
- else
- throw new InvalidKeyException ("not a DSA private key");
-
- appRandom = random;
- init();
- }
-
- public void engineUpdate(byte b)
- throws SignatureException
- {
- digest.update (b);
- }
-
- public void engineUpdate (byte[] b, int off, int len)
- throws SignatureException
- {
- digest.update (b, off, len);
- }
-
- public byte[] engineSign() throws SignatureException
- {
- if (privateKey == null)
- throw new SignatureException ("not initialized for signing");
-
- try
- {
- BigInteger g = privateKey.getParams().getG();
- BigInteger p = privateKey.getParams().getP();
- BigInteger q = privateKey.getParams().getQ();
-
- BigInteger x = privateKey.getX();
-
- BigInteger k = new BigInteger (159, appRandom != null ? appRandom : random);
-
- BigInteger r = g.modPow(k, p);
- r = r.mod(q);
-
- byte bytes[] = digest.digest();
- BigInteger sha = new BigInteger (1, bytes);
-
- BigInteger s = sha.add (x.multiply (r));
- s = s.multiply (k.modInverse(q)).mod (q);
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- ArrayList seq = new ArrayList (2);
- seq.add(0, new DERValue (DER.INTEGER, r));
- seq.add(1, new DERValue (DER.INTEGER, s));
- DERWriter.write (bout, new DERValue (DER.CONSTRUCTED | DER.SEQUENCE, seq));
- return bout.toByteArray();
- }
- catch (IOException ioe)
- {
- SignatureException se = new SignatureException();
- se.initCause (ioe);
- throw se;
- }
- catch (ArithmeticException ae)
- {
- SignatureException se = new SignatureException();
- se.initCause (ae);
- throw se;
- }
- }
-
- public int engineSign (byte[] outbuf, int offset, int len)
- throws SignatureException
- {
- byte tmp[] = engineSign();
- if (tmp.length > len)
- throw new SignatureException ("output buffer too short");
- System.arraycopy (tmp, 0, outbuf, offset, tmp.length);
- return tmp.length;
- }
-
- public boolean engineVerify (byte[] sigBytes)
- throws SignatureException
- {
- // Decode sigBytes from ASN.1 DER encoding
- try
- {
- DERReader in = new DERReader (sigBytes);
- DERValue val = in.read();
- if (!val.isConstructed())
- throw new SignatureException ("badly formed signature");
- BigInteger r = (BigInteger) in.read().getValue();
- BigInteger s = (BigInteger) in.read().getValue();
-
- BigInteger g = publicKey.getParams().getG();
- BigInteger p = publicKey.getParams().getP();
- BigInteger q = publicKey.getParams().getQ();
-
- BigInteger y = publicKey.getY();
-
- BigInteger w = s.modInverse (q);
-
- byte bytes[] = digest.digest();
- BigInteger sha = new BigInteger (1, bytes);
-
- BigInteger u1 = w.multiply (sha).mod ( q );
-
- BigInteger u2 = r.multiply (w).mod(q);
-
- BigInteger v = g.modPow (u1, p).multiply (y.modPow (u2, p)).mod (p).mod (q);
-
- if (v.equals (r))
- return true;
- else
- return false;
- }
- catch (IOException ioe)
- {
- SignatureException se = new SignatureException ("badly formed signature");
- se.initCause (ioe);
- throw se;
- }
- }
-
- public void engineSetParameter (String param,
- Object value)
- throws InvalidParameterException
- {
- throw new InvalidParameterException();
- }
-
- public void engineSetParameter (AlgorithmParameterSpec params)
- throws InvalidAlgorithmParameterException
- {
- throw new InvalidParameterException();
-
- }
-
- public Object engineGetParameter (String param)
- throws InvalidParameterException
- {
- throw new InvalidParameterException();
- }
-
- public Object clone() throws CloneNotSupportedException
- {
- return super.clone();
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyFactoryImpl.java b/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyFactoryImpl.java
deleted file mode 100644
index 591fc68..0000000
--- a/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyFactoryImpl.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/* DiffieHellmanKeyFactoryImpl.java --
- Copyright (C) 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.javax.crypto.GnuDHPrivateKey;
-
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.KeyFactorySpi;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-
-import javax.crypto.spec.DHParameterSpec;
-import javax.crypto.spec.DHPrivateKeySpec;
-import javax.crypto.spec.DHPublicKeySpec;
-
-import javax.crypto.interfaces.DHPrivateKey;
-import javax.crypto.interfaces.DHPublicKey;
-
-public class DiffieHellmanKeyFactoryImpl extends KeyFactorySpi
-{
- protected PrivateKey engineGeneratePrivate (final KeySpec spec)
- throws InvalidKeySpecException
- {
- if (spec instanceof DHPrivateKeySpec)
- {
- DHPrivateKeySpec dh = (DHPrivateKeySpec) spec;
- return new GnuDHPrivateKey (dh.getX (),
- new DHParameterSpec (dh.getP (), dh.getG ()));
- }
- throw new InvalidKeySpecException ();
- }
-
- protected PublicKey engineGeneratePublic (final KeySpec spec)
- throws InvalidKeySpecException
- {
- if (spec instanceof DHPublicKeySpec)
- {
- DHPublicKeySpec dh = (DHPublicKeySpec) spec;
- return new GnuDHPublicKey (new DHParameterSpec (dh.getP (), dh.getG ()),
- dh.getY(), null);
- }
- throw new InvalidKeySpecException ();
- }
-
- protected KeySpec engineGetKeySpec (final Key key, final Class specClass)
- throws InvalidKeySpecException
- {
- if (key instanceof DHPrivateKey)
- {
- if (DHPrivateKeySpec.class.isAssignableFrom (specClass))
- {
- DHParameterSpec params = ((DHPrivateKey) key).getParams ();
- return new DHPrivateKeySpec (((DHPrivateKey) key).getX (),
- params.getP (), params.getG ());
- }
- }
- if (key instanceof DHPublicKey)
- {
- if (DHPublicKeySpec.class.isAssignableFrom (specClass))
- {
- DHParameterSpec params = ((DHPublicKey) key).getParams ();
- return new DHPublicKeySpec (((DHPublicKey) key).getY (),
- params.getP (), params.getG ());
- }
- }
- throw new InvalidKeySpecException ();
- }
-
- protected Key engineTranslateKey (final Key key)
- throws InvalidKeyException
- {
- if (key instanceof DHPrivateKey)
- {
- return new GnuDHPrivateKey (((DHPrivateKey) key).getX (),
- ((DHPrivateKey) key).getParams ());
- }
- if (key instanceof DHPublicKey)
- {
- return new GnuDHPublicKey (((DHPublicKey) key).getParams (),
- ((DHPublicKey) key).getY (), null);
- }
- throw new InvalidKeyException ();
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyPairGeneratorImpl.java b/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyPairGeneratorImpl.java
deleted file mode 100644
index 1b68d27..0000000
--- a/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyPairGeneratorImpl.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/* DiffieHellmanKeyPairGeneratorImpl.java --
- Copyright (C) 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.javax.crypto.GnuDHPrivateKey;
-
-import java.math.BigInteger;
-
-import java.security.KeyPair;
-import java.security.KeyPairGeneratorSpi;
-import java.security.SecureRandom;
-import java.security.spec.AlgorithmParameterSpec;
-
-import javax.crypto.spec.DHParameterSpec;
-
-public class DiffieHellmanKeyPairGeneratorImpl extends KeyPairGeneratorSpi
-{
- private SecureRandom random;
- private DHParameterSpec params;
-
- public KeyPair generateKeyPair ()
- {
- if (params == null || random == null)
- throw new IllegalStateException ("not initialized");
- byte[] buf = new byte[(params.getP ().bitLength() >>> 3)];
- random.nextBytes (buf);
- BigInteger x = new BigInteger (1, buf);
- BigInteger y = params.getG ().modPow (x, params.getP ());
- GnuDHPublicKey pub = new GnuDHPublicKey (params, y, null);
- GnuDHPrivateKey priv = new GnuDHPrivateKey (x, params);
-
- return new KeyPair (pub, priv);
- }
-
- public void initialize (final int keysize, final SecureRandom random)
- {
- throw new UnsupportedOperationException ("key generation without parameters not supported");
- }
-
- public void initialize (final AlgorithmParameterSpec params,
- final SecureRandom random)
- {
- if (!(params instanceof DHParameterSpec))
- throw new IllegalArgumentException ("expecting Diffie-Hellman parameters");
- this.params = (DHParameterSpec) params;
- this.random = random;
- if (this.random == null)
- this.random = new SecureRandom ();
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/EncodedKeyFactory.java b/libjava/classpath/gnu/java/security/provider/EncodedKeyFactory.java
deleted file mode 100644
index 2bf0fff..0000000
--- a/libjava/classpath/gnu/java/security/provider/EncodedKeyFactory.java
+++ /dev/null
@@ -1,303 +0,0 @@
-/* EncodedKeyFactory.java -- encoded key factory.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.OID;
-import gnu.java.security.der.BitString;
-import gnu.java.security.der.DERReader;
-import gnu.java.security.der.DERValue;
-
-import java.io.IOException;
-import java.math.BigInteger;
-import java.security.AlgorithmParameters;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.KeyFactorySpi;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.spec.DSAParameterSpec;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.InvalidParameterSpecException;
-import java.security.spec.KeySpec;
-import java.security.spec.PKCS8EncodedKeySpec;
-import java.security.spec.RSAPrivateCrtKeySpec;
-import java.security.spec.RSAPublicKeySpec;
-import java.security.spec.X509EncodedKeySpec;
-
-import javax.crypto.spec.DHParameterSpec;
-
-/**
- * A factory for keys encoded in either the X.509 format (for public
- * keys) or the PKCS#8 format (for private keys).
- *
- * @author Casey Marshall (rsdio@metastatic.org)
- */
-public class EncodedKeyFactory extends KeyFactorySpi
-{
-
- // Constants.
- // ------------------------------------------------------------------------
-
- private static final OID ID_DSA = new OID("1.2.840.10040.4.1");
- private static final OID ID_RSA = new OID("1.2.840.113549.1.1.1");
- private static final OID ID_DH = new OID("1.2.840.10046.2.1");
-
- // Instance methods.
- // ------------------------------------------------------------------------
-
- public PublicKey engineGeneratePublic(KeySpec spec)
- throws InvalidKeySpecException
- {
- if (!(spec instanceof X509EncodedKeySpec))
- throw new InvalidKeySpecException("only supports X.509 key specs");
- DERReader der = new DERReader(((X509EncodedKeySpec) spec).getEncoded());
- try
- {
- DERValue spki = der.read();
- if (!spki.isConstructed())
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- DERValue alg = der.read();
- if (!alg.isConstructed())
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- DERValue val = der.read();
- if (!(val.getValue() instanceof OID))
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- OID algId = (OID) val.getValue();
- byte[] algParams = null;
- if (alg.getLength() > val.getEncodedLength())
- {
- val = der.read();
- algParams = val.getEncoded();
- if (val.isConstructed())
- der.skip(val.getLength());
- }
- val = der.read();
- if (!(val.getValue() instanceof BitString))
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- byte[] publicKey = ((BitString) val.getValue()).toByteArray();
- if (algId.equals(ID_DSA))
- {
- BigInteger p = null, g = null, q = null, Y;
- if (algParams != null)
- {
- DERReader dsaParams = new DERReader(algParams);
- val = dsaParams.read();
- if (!val.isConstructed())
- throw new InvalidKeySpecException("malformed DSA parameters");
- val = dsaParams.read();
- if (!(val.getValue() instanceof BigInteger))
- throw new InvalidKeySpecException("malformed DSA parameters");
- p = (BigInteger) val.getValue();
- val = dsaParams.read();
- if (!(val.getValue() instanceof BigInteger))
- throw new InvalidKeySpecException("malformed DSA parameters");
- q = (BigInteger) val.getValue();
- val = dsaParams.read();
- if (!(val.getValue() instanceof BigInteger))
- throw new InvalidKeySpecException("malformed DSA parameters");
- g = (BigInteger) val.getValue();
- }
- DERReader dsaPub = new DERReader(publicKey);
- val = dsaPub.read();
- if (!(val.getValue() instanceof BigInteger))
- throw new InvalidKeySpecException("malformed DSA parameters");
- Y = (BigInteger) val.getValue();
- return new GnuDSAPublicKey(Y, p, q, g);
- }
- else if (algId.equals(ID_RSA))
- {
- DERReader rsaParams = new DERReader(publicKey);
- if (!rsaParams.read().isConstructed())
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- return new GnuRSAPublicKey(new RSAPublicKeySpec(
- (BigInteger) rsaParams.read().getValue(),
- (BigInteger) rsaParams.read().getValue()));
- }
- else if (algId.equals(ID_DH))
- {
- if (algParams == null)
- throw new InvalidKeySpecException("missing DH parameters");
- DERReader dhParams = new DERReader(algParams);
- val = dhParams.read();
- BigInteger p, g, q, Y;
- if (!val.isConstructed())
- throw new InvalidKeySpecException("malformed DH parameters");
- val = dhParams.read();
- if (!(val.getValue() instanceof BigInteger))
- throw new InvalidKeySpecException("malformed DH parameters");
- p = (BigInteger) val.getValue();
- val = dhParams.read();
- if (!(val.getValue() instanceof BigInteger))
- throw new InvalidKeySpecException("malformed DH parameters");
- g = (BigInteger) val.getValue();
- val = dhParams.read();
- if (!(val.getValue() instanceof BigInteger))
- throw new InvalidKeySpecException("malformed DH parameters");
- q = (BigInteger) val.getValue();
- DERReader dhPub = new DERReader(publicKey);
- val = dhPub.read();
- if (!(val.getValue() instanceof BigInteger))
- throw new InvalidKeySpecException("malformed DH parameters");
- Y = (BigInteger) val.getValue();
- return (PublicKey) new GnuDHPublicKey(new DHParameterSpec(p, g), Y, q);
- }
- else
- throw new InvalidKeySpecException("unknown algorithm: " + algId);
- }
- catch (IOException ioe)
- {
- throw new InvalidKeySpecException(ioe.getMessage());
- }
- }
-
- public PrivateKey engineGeneratePrivate(KeySpec spec)
- throws InvalidKeySpecException
- {
- if (!(spec instanceof PKCS8EncodedKeySpec))
- {
- throw new InvalidKeySpecException("only supports PKCS8 key specs");
- }
- DERReader der = new DERReader(((PKCS8EncodedKeySpec) spec).getEncoded());
- try
- {
- DERValue pki = der.read();
- if (!pki.isConstructed())
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- DERValue val = der.read();
- if (!(val.getValue() instanceof BigInteger))
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- DERValue alg = der.read();
- if (!alg.isConstructed())
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- val = der.read();
- if (!(val.getValue() instanceof OID))
- {
- throw new InvalidKeySpecException("malformed encoded key");
- }
- OID algId = (OID) val.getValue();
- byte[] algParams = null;
- if (alg.getLength() > val.getEncodedLength())
- {
- val = der.read();
- algParams = val.getEncoded();
- if (val.isConstructed())
- der.skip(val.getLength());
- }
- byte[] privateKey = (byte[]) der.read().getValue();
- if (algId.equals(ID_DSA))
- {
- if (algParams == null)
- {
- throw new InvalidKeySpecException("missing DSA parameters");
- }
- AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
- params.init(algParams);
- DSAParameterSpec dsaSpec = (DSAParameterSpec)
- params.getParameterSpec(DSAParameterSpec.class);
- DERReader dsaPriv = new DERReader(privateKey);
- return new GnuDSAPrivateKey((BigInteger) dsaPriv.read().getValue(),
- dsaSpec.getP(), dsaSpec.getQ(), dsaSpec.getG());
- }
- else if (algId.equals(ID_RSA))
- {
- DERReader rsaParams = new DERReader(privateKey);
- if (!rsaParams.read().isConstructed())
- throw new InvalidKeySpecException("malformed encoded key");
- return new GnuRSAPrivateKey(new RSAPrivateCrtKeySpec(
- (BigInteger) rsaParams.read().getValue(), // n
- (BigInteger) rsaParams.read().getValue(), // e
- (BigInteger) rsaParams.read().getValue(), // d
- (BigInteger) rsaParams.read().getValue(), // p
- (BigInteger) rsaParams.read().getValue(), // q
- (BigInteger) rsaParams.read().getValue(), // d mod (p - 1)
- (BigInteger) rsaParams.read().getValue(), // d mod (q - 1)
- (BigInteger) rsaParams.read().getValue())); // (inv q) mod p
- }
- else
- throw new InvalidKeySpecException("unknown algorithm: " + algId);
- }
- catch (InvalidParameterSpecException iapse)
- {
- throw new InvalidKeySpecException(iapse.getMessage());
- }
- catch (NoSuchAlgorithmException nsae)
- {
- throw new InvalidKeySpecException(nsae.getMessage());
- }
- catch (IOException ioe)
- {
- throw new InvalidKeySpecException(ioe.getMessage());
- }
- }
-
- public KeySpec engineGetKeySpec(Key key, Class speClass)
- throws InvalidKeySpecException
- {
- if ((key instanceof PrivateKey) && key.getFormat().equals("PKCS#8")
- && speClass.isAssignableFrom(PKCS8EncodedKeySpec.class))
- return new PKCS8EncodedKeySpec(key.getEncoded());
- else if ((key instanceof PublicKey) && key.getFormat().equals("X.509")
- && speClass.isAssignableFrom(X509EncodedKeySpec.class))
- return new X509EncodedKeySpec(key.getEncoded());
- else
- throw new InvalidKeySpecException();
- }
-
- public Key engineTranslateKey(Key key) throws InvalidKeyException
- {
- throw new InvalidKeyException("translating keys not supported");
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/Gnu.java b/libjava/classpath/gnu/java/security/provider/Gnu.java
index e553bbc..0613566 100644
--- a/libjava/classpath/gnu/java/security/provider/Gnu.java
+++ b/libjava/classpath/gnu/java/security/provider/Gnu.java
@@ -57,105 +57,209 @@ public final class Gnu extends Provider
// we automatically get all the implementation classes.
// Signature
- put("Signature.SHA1withDSA",
- gnu.java.security.provider.DSASignature.class.getName());
-
- put("Alg.Alias.Signature.DSS", "SHA1withDSA");
- put("Alg.Alias.Signature.DSA", "SHA1withDSA");
- put("Alg.Alias.Signature.SHAwithDSA", "SHA1withDSA");
- put("Alg.Alias.Signature.DSAwithSHA", "SHA1withDSA");
- put("Alg.Alias.Signature.DSAwithSHA1", "SHA1withDSA");
- put("Alg.Alias.Signature.SHA/DSA", "SHA1withDSA");
- put("Alg.Alias.Signature.SHA-1/DSA", "SHA1withDSA");
- put("Alg.Alias.Signature.SHA1/DSA", "SHA1withDSA");
- put("Alg.Alias.Signature.OID.1.2.840.10040.4.3", "SHA1withDSA");
- put("Alg.Alias.Signature.1.2.840.10040.4.3", "SHA1withDSA");
- put("Alg.Alias.Signature.1.3.14.3.2.13", "SHA1withDSA");
- put("Alg.Alias.Signature.1.3.14.3.2.27", "SHA1withDSA");
-
- put("Signature.MD2withRSA", MD2withRSA.class.getName());
+ put("Signature.SHA160withDSS",
+ gnu.java.security.jce.sig.SHA160withDSS.class.getName());
+ put("Alg.Alias.Signature.SHA1withDSA", "SHA160withDSS");
+ put("Alg.Alias.Signature.DSS", "SHA160withDSS");
+ put("Alg.Alias.Signature.DSA", "SHA160withDSS");
+ put("Alg.Alias.Signature.SHAwithDSA", "SHA160withDSS");
+ put("Alg.Alias.Signature.DSAwithSHA", "SHA160withDSS");
+ put("Alg.Alias.Signature.DSAwithSHA1", "SHA160withDSS");
+ put("Alg.Alias.Signature.SHA/DSA", "SHA160withDSS");
+ put("Alg.Alias.Signature.SHA-1/DSA", "SHA160withDSS");
+ put("Alg.Alias.Signature.SHA1/DSA", "SHA160withDSS");
+ put("Alg.Alias.Signature.OID.1.2.840.10040.4.3", "SHA160withDSS");
+ put("Alg.Alias.Signature.1.2.840.10040.4.3", "SHA160withDSS");
+ put("Alg.Alias.Signature.1.3.14.3.2.13", "SHA160withDSS");
+ put("Alg.Alias.Signature.1.3.14.3.2.27", "SHA160withDSS");
+
+ put("Signature.MD2withRSA",
+ gnu.java.security.jce.sig.MD2withRSA.class.getName());
put("Signature.MD2withRSA ImplementedIn", "Software");
put("Alg.Alias.Signature.md2WithRSAEncryption", "MD2withRSA");
put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.2", "MD2withRSA");
put("Alg.Alias.Signature.1.2.840.113549.1.1.2", "MD2withRSA");
- put("Signature.MD4withRSA", MD4withRSA.class.getName());
- put("Signature.MD4withRSA ImplementedIn", "Software");
- put("Alg.Alias.Signature.md4WithRSAEncryption", "MD4withRSA");
- put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.3", "MD4withRSA");
- put("Alg.Alias.Signature.1.2.840.113549.1.1.3", "MD4withRSA");
-
- put("Signature.MD5withRSA", MD5withRSA.class.getName());
+ put("Signature.MD5withRSA",
+ gnu.java.security.jce.sig.MD5withRSA.class.getName());
put("Signature.MD5withRSA ImplementedIn", "Software");
put("Alg.Alias.Signature.md5WithRSAEncryption", "MD5withRSA");
put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.4", "MD5withRSA");
put("Alg.Alias.Signature.1.2.840.113549.1.1.4", "MD5withRSA");
- put("Signature.SHA1withRSA", SHA1withRSA.class.getName());
- put("Signature.SHA1withRSA ImplementedIn", "Software");
- put("Alg.Alias.Signature.sha-1WithRSAEncryption", "SHA1withRSA");
- put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.5", "SHA1withRSA");
- put("Alg.Alias.Signature.1.2.840.113549.1.1.5", "SHA1withRSA");
+ put("Signature.SHA160withRSA",
+ gnu.java.security.jce.sig.SHA160withRSA.class.getName());
+ put("Signature.SHA160withRSA ImplementedIn", "Software");
+ put("Alg.Alias.Signature.sha-1WithRSAEncryption", "SHA160withRSA");
+ put("Alg.Alias.Signature.sha-160WithRSAEncryption", "SHA160withRSA");
+ put("Alg.Alias.Signature.sha1WithRSAEncryption", "SHA160withRSA");
+ put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.5", "SHA160withRSA");
+ put("Alg.Alias.Signature.1.2.840.113549.1.1.5", "SHA160withRSA");
+ put("Alg.Alias.Signature.SHA1withRSA", "SHA160withRSA");
+
+ put("Signature.SHA256withRSA",
+ gnu.java.security.jce.sig.SHA256withRSA.class.getName());
+ put("Signature.SHA160withRSA ImplementedIn", "Software");
+ put("Alg.Alias.Signature.sha256WithRSAEncryption", "SHA256withRSA");
+ put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.11", "SHA256withRSA");
+ put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA256withRSA");
+
+ put("Signature.SHA384withRSA",
+ gnu.java.security.jce.sig.SHA384withRSA.class.getName());
+ put("Signature.SHA160withRSA ImplementedIn", "Software");
+ put("Alg.Alias.Signature.sha384WithRSAEncryption", "SHA384withRSA");
+ put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.12", "SHA384withRSA");
+ put("Alg.Alias.Signature.1.2.840.113549.1.1.12", "SHA384withRSA");
+
+ put("Signature.SHA512withRSA",
+ gnu.java.security.jce.sig.SHA512withRSA.class.getName());
+ put("Signature.SHA160withRSA ImplementedIn", "Software");
+ put("Alg.Alias.Signature.sha512WithRSAEncryption", "SHA512withRSA");
+ put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.13", "SHA512withRSA");
+ put("Alg.Alias.Signature.1.2.840.113549.1.1.13", "SHA512withRSA");
+
+ put("Signature.DSS/RAW",
+ gnu.java.security.jce.sig.DSSRawSignatureSpi.class.getName());
+ put("Signature.DSS/RAW KeySize", "1024");
+ put("Signature.DSS/RAW ImplementedIn", "Software");
+
+ put("Signature.RSA-PSS/RAW",
+ gnu.java.security.jce.sig.RSAPSSRawSignatureSpi.class.getName());
+ put("Signature.RSA-PSS/RAW KeySize", "1024");
+ put("Signature.RSA-PSS/RAW ImplementedIn", "Software");
// Key Pair Generator
- put("KeyPairGenerator.DSA",
- gnu.java.security.provider.DSAKeyPairGenerator.class.getName());
- put("KeyPairGenerator.DiffieHellman", DiffieHellmanKeyPairGeneratorImpl.class.getName ());
-
- put("Alg.Alias.KeyPairGenerator.OID.1.2.840.10040.4.1", "DSA");
- put("Alg.Alias.KeyPairGenerator.1.2.840.10040.4.1", "DSA");
- put("Alg.Alias.KeyPairGenerator.1.3.14.3.2.12", "DSA");
- put("Alg.Alias.KeyPairGenerator.DH", "DiffieHellman");
+ put("KeyPairGenerator.DSS",
+ gnu.java.security.jce.sig.DSSKeyPairGeneratorSpi.class.getName());
+ put("KeyPairGenerator.DSS KeySize", "1024");
+ put("KeyPairGenerator.DSS ImplementedIn", "Software");
+ put("Alg.Alias.KeyPairGenerator.DSA", "DSS");
+ put("Alg.Alias.KeyPairGenerator.OID.1.2.840.10040.4.1", "DSS");
+ put("Alg.Alias.KeyPairGenerator.1.2.840.10040.4.1", "DSS");
+ put("Alg.Alias.KeyPairGenerator.1.3.14.3.2.12", "DSS");
+
+ put("KeyPairGenerator.RSA",
+ gnu.java.security.jce.sig.RSAKeyPairGeneratorSpi.class.getName());
+ put("KeyPairGenerator.RSA KeySize", "1024");
+ put("KeyPairGenerator.RSA ImplementedIn", "Software");
// Key Factory
- put("KeyFactory.DSA",
- gnu.java.security.provider.DSAKeyFactory.class.getName());
-
- put("KeyFactory.Encoded", EncodedKeyFactory.class.getName());
+ put("KeyFactory.DSS",
+ gnu.java.security.jce.sig.DSSKeyFactory.class.getName());
+ put("Alg.Alias.KeyFactory.DSA", "DSS");
+ put("Alg.Alias.KeyFactory.OID.1.2.840.10040.4.1", "DSS");
+ put("Alg.Alias.KeyFactory.1.2.840.10040.4.1", "DSS");
+ put("Alg.Alias.KeyFactory.1.3.14.3.2.12", "DSS");
+
+ put("KeyFactory.RSA",
+ gnu.java.security.jce.sig.RSAKeyFactory.class.getName());
+
+ put("KeyFactory.Encoded",
+ gnu.java.security.jce.sig.EncodedKeyFactory.class.getName());
put("KeyFactory.Encoded ImplementedIn", "Software");
put("Alg.Alias.KeyFactory.X.509", "Encoded");
put("Alg.Alias.KeyFactory.X509", "Encoded");
put("Alg.Alias.KeyFactory.PKCS#8", "Encoded");
put("Alg.Alias.KeyFactory.PKCS8", "Encoded");
- put("KeyFactory.RSA", RSAKeyFactory.class.getName());
-
- put("Alg.Alias.KeyFactory.OID.1.2.840.10040.4.1", "DSA");
- put("Alg.Alias.KeyFactory.1.2.840.10040.4.1", "DSA");
- put("Alg.Alias.KeyFactory.1.3.14.3.2.12", "DSA");
-
- put("KeyFactory.DiffieHellman", DiffieHellmanKeyFactoryImpl.class.getName());
- put("Alg.Alias.KeyFactory.DH", "DiffieHellman");
-
- // Message Digests
- put("MessageDigest.SHA", gnu.java.security.provider.SHA.class.getName());
- put("MessageDigest.MD5", gnu.java.security.provider.MD5.class.getName());
-
- // Format "Alias", "Actual Name"
- put("Alg.Alias.MessageDigest.SHA1", "SHA");
- put("Alg.Alias.MessageDigest.SHA-1", "SHA");
- put("Alg.Alias.MessageDigest.SHA-160", "SHA");
+ put("MessageDigest.HAVAL", gnu.java.security.jce.hash.HavalSpi.class.getName());
+ put("MessageDigest.HAVAL ImplementedIn", "Software");
+ put("MessageDigest.MD2", gnu.java.security.jce.hash.MD2Spi.class.getName());
+ put("MessageDigest.MD2 ImplementedIn", "Software");
+ put("MessageDigest.MD4", gnu.java.security.jce.hash.MD4Spi.class.getName());
+ put("MessageDigest.MD4 ImplementedIn", "Software");
+ put("MessageDigest.MD5", gnu.java.security.jce.hash.MD5Spi.class.getName());
+ put("MessageDigest.MD5 ImplementedIn", "Software");
+ put("MessageDigest.RIPEMD128", gnu.java.security.jce.hash.RipeMD128Spi.class.getName());
+ put("MessageDigest.RIPEMD128 ImplementedIn", "Software");
+ put("MessageDigest.RIPEMD160", gnu.java.security.jce.hash.RipeMD160Spi.class.getName());
+ put("MessageDigest.RIPEMD160 ImplementedIn", "Software");
+ put("MessageDigest.SHA-160", gnu.java.security.jce.hash.Sha160Spi.class.getName());
+ put("MessageDigest.SHA-160 ImplementedIn", "Software");
+ put("MessageDigest.SHA-256", gnu.java.security.jce.hash.Sha256Spi.class.getName());
+ put("MessageDigest.SHA-256 ImplementedIn", "Software");
+ put("MessageDigest.SHA-384", gnu.java.security.jce.hash.Sha384Spi.class.getName());
+ put("MessageDigest.SHA-384 ImplementedIn", "Software");
+ put("MessageDigest.SHA-512", gnu.java.security.jce.hash.Sha512Spi.class.getName());
+ put("MessageDigest.SHA-512 ImplementedIn", "Software");
+ put("MessageDigest.TIGER", gnu.java.security.jce.hash.TigerSpi.class.getName());
+ put("MessageDigest.TIGER ImplementedIn", "Software");
+ put("MessageDigest.WHIRLPOOL", gnu.java.security.jce.hash.WhirlpoolSpi.class.getName());
+ put("MessageDigest.WHIRLPOOL ImplementedIn", "Software");
+
+ put("Alg.Alias.MessageDigest.SHS", "SHA-160");
+ put("Alg.Alias.MessageDigest.SHA", "SHA-160");
+ put("Alg.Alias.MessageDigest.SHA1", "SHA-160");
+ put("Alg.Alias.MessageDigest.SHA-1", "SHA-160");
+ put("Alg.Alias.MessageDigest.SHA2-256", "SHA-256");
+ put("Alg.Alias.MessageDigest.SHA2-384", "SHA-384");
+ put("Alg.Alias.MessageDigest.SHA2-512", "SHA-512");
+ put("Alg.Alias.MessageDigest.SHA256", "SHA-256");
+ put("Alg.Alias.MessageDigest.SHA384", "SHA-384");
+ put("Alg.Alias.MessageDigest.SHA512", "SHA-512");
+ put("Alg.Alias.MessageDigest.RIPEMD-160", "RIPEMD160");
+ put("Alg.Alias.MessageDigest.RIPEMD-128", "RIPEMD128");
+ put("Alg.Alias.MessageDigest.OID.1.2.840.11359.2.2", "MD2");
+ put("Alg.Alias.MessageDigest.1.2.840.11359.2.2", "MD2");
+ put("Alg.Alias.MessageDigest.OID.1.2.840.11359.2.5", "MD5");
+ put("Alg.Alias.MessageDigest.1.2.840.11359.2.5", "MD5");
+ put("Alg.Alias.MessageDigest.OID.1.3.14.3.2.26", "SHA1");
+ put("Alg.Alias.MessageDigest.1.3.14.3.2.26", "SHA1");
// Algorithm Parameters
- put("AlgorithmParameters.DSA",
- gnu.java.security.provider.DSAParameters.class.getName());
-
- put("Alg.Alias.AlgorithmParameters.DSS", "DSA");
- put("Alg.Alias.AlgorithmParameters.SHAwithDSA", "DSA");
- put("Alg.Alias.AlgorithmParameters.OID.1.2.840.10040.4.3", "DSA");
- put("Alg.Alias.AlgorithmParameters.1.2.840.10040.4.3", "DSA");
+ put("AlgorithmParameters.DSS",
+ gnu.java.security.jce.sig.DSSParameters.class.getName());
+ put("Alg.Alias.AlgorithmParameters.DSA", "DSS");
+ put("Alg.Alias.AlgorithmParameters.SHAwithDSA", "DSS");
+ put("Alg.Alias.AlgorithmParameters.OID.1.2.840.10040.4.3", "DSS");
+ put("Alg.Alias.AlgorithmParameters.1.2.840.10040.4.3", "DSS");
// Algorithm Parameter Generator
put("AlgorithmParameterGenerator.DSA",
- gnu.java.security.provider.DSAParameterGenerator.class.getName());
+ gnu.java.security.jce.sig.DSSParametersGenerator.class.getName());
+ put("Alg.Alias.AlgorithmParameterGenerator.DSA", "DSS");
// SecureRandom
put("SecureRandom.SHA1PRNG",
- gnu.java.security.provider.SHA1PRNG.class.getName());
+ gnu.java.security.jce.prng.Sha160RandomSpi.class.getName());
+
+ put("SecureRandom.MD2PRNG", gnu.java.security.jce.prng.MD2RandomSpi.class.getName());
+ put("SecureRandom.MD2PRNG ImplementedIn", "Software");
+ put("SecureRandom.MD4PRNG", gnu.java.security.jce.prng.MD4RandomSpi.class.getName());
+ put("SecureRandom.MD4PRNG ImplementedIn", "Software");
+ put("SecureRandom.MD5PRNG", gnu.java.security.jce.prng.MD5RandomSpi.class.getName());
+ put("SecureRandom.MD5PRNG ImplementedIn", "Software");
+ put("SecureRandom.RIPEMD128PRNG", gnu.java.security.jce.prng.RipeMD128RandomSpi.class.getName());
+ put("SecureRandom.RIPEMD128PRNG ImplementedIn", "Software");
+ put("SecureRandom.RIPEMD160PRNG", gnu.java.security.jce.prng.RipeMD160RandomSpi.class.getName());
+ put("SecureRandom.RIPEMD160PRNG ImplementedIn", "Software");
+ put("SecureRandom.SHA-160PRNG", gnu.java.security.jce.prng.Sha160RandomSpi.class.getName());
+ put("SecureRandom.SHA-160PRNG ImplementedIn", "Software");
+ put("SecureRandom.SHA-256PRNG", gnu.java.security.jce.prng.Sha256RandomSpi.class.getName());
+ put("SecureRandom.SHA-256PRNG ImplementedIn", "Software");
+ put("SecureRandom.SHA-384PRNG", gnu.java.security.jce.prng.Sha384RandomSpi.class.getName());
+ put("SecureRandom.SHA-384PRNG ImplementedIn", "Software");
+ put("SecureRandom.SHA-512PRNG", gnu.java.security.jce.prng.Sha512RandomSpi.class.getName());
+ put("SecureRandom.SHA-512PRNG ImplementedIn", "Software");
+ put("SecureRandom.TIGERPRNG", gnu.java.security.jce.prng.TigerRandomSpi.class.getName());
+ put("SecureRandom.TIGERPRNG ImplementedIn", "Software");
+ put("SecureRandom.HAVALPRNG", gnu.java.security.jce.prng.HavalRandomSpi.class.getName());
+ put("SecureRandom.HAVALPRNG ImplementedIn", "Software");
+ put("SecureRandom.WHIRLPOOLPRNG", gnu.java.security.jce.prng.WhirlpoolRandomSpi.class.getName());
+ put("SecureRandom.WHIRLPOOLPRNG ImplementedIn", "Software");
+
+ put("Alg.Alias.SecureRandom.SHA-1PRNG", "SHA-160PRNG");
+ put("Alg.Alias.SecureRandom.SHA1PRNG", "SHA-160PRNG");
+ put("Alg.Alias.SecureRandom.SHAPRNG", "SHA-160PRNG");
+ put("Alg.Alias.SecureRandom.SHA-256PRNG", "SHA-256PRNG");
+ put("Alg.Alias.SecureRandom.SHA-2-1PRNG", "SHA-256PRNG");
+ put("Alg.Alias.SecureRandom.SHA-384PRNG", "SHA-384PRNG");
+ put("Alg.Alias.SecureRandom.SHA-2-2PRNG", "SHA-384PRNG");
+ put("Alg.Alias.SecureRandom.SHA-512PRNG", "SHA-512PRNG");
+ put("Alg.Alias.SecureRandom.SHA-2-3PRNG", "SHA-512PRNG");
// CertificateFactory
put("CertificateFactory.X509", X509CertificateFactory.class.getName());
-
put("CertificateFactory.X509 ImplementedIn", "Software");
put("Alg.Alias.CertificateFactory.X.509", "X509");
@@ -166,14 +270,6 @@ public final class Gnu extends Provider
// CertStore
put("CertStore.Collection", CollectionCertStoreImpl.class.getName());
- // KeyAgreement
- put("KeyAgreement.DiffieHellman", gnu.javax.crypto.DiffieHellmanImpl.class.getName());
- put("Alg.Alias.KeyAgreement.DH", "DiffieHellman");
-
- // Cipher
- put("Cipher.RSAES-PKCS1-v1_5", gnu.javax.crypto.RSACipherImpl.class.getName());
- put("Alg.Alias.Cipher.RSA", "RSAES-PKCS1-v1_5");
-
return null;
}
});
diff --git a/libjava/classpath/gnu/java/security/provider/GnuDHPublicKey.java b/libjava/classpath/gnu/java/security/provider/GnuDHPublicKey.java
deleted file mode 100644
index 6e13f6b..0000000
--- a/libjava/classpath/gnu/java/security/provider/GnuDHPublicKey.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/* GnuDHPublicKey.java -- A Diffie-Hellman public key.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.OID;
-import gnu.java.security.der.BitString;
-import gnu.java.security.der.DER;
-import gnu.java.security.der.DERValue;
-
-import java.math.BigInteger;
-import java.util.ArrayList;
-
-import javax.crypto.interfaces.DHPublicKey;
-import javax.crypto.spec.DHParameterSpec;
-
-public class GnuDHPublicKey implements DHPublicKey
-{
-
- // Fields.
- // -------------------------------------------------------------------------
-
- private byte[] encoded;
- private final DHParameterSpec params;
- private final BigInteger Y;
- private final BigInteger q;
-
- // Constructor.
- // -------------------------------------------------------------------------
-
- public GnuDHPublicKey(DHParameterSpec params, BigInteger Y, BigInteger q)
- {
- this.params = params;
- this.Y = Y;
- this.q = q;
- }
-
- // Instance methods.
- // -------------------------------------------------------------------------
-
- public BigInteger getY()
- {
- return Y;
- }
-
- public DHParameterSpec getParams()
- {
- return params;
- }
-
- public String getAlgorithm()
- {
- return "DH";
- }
-
- public String getFormat()
- {
- return "X.509";
- }
-
- public byte[] getEncoded()
- {
- if (encoded != null)
- return (byte[]) encoded.clone();
- ArrayList spki = new ArrayList(2);
- ArrayList alg = new ArrayList(2);
- alg.add(new DERValue(DER.OBJECT_IDENTIFIER, new OID("1.2.840.10046.2.1")));
- ArrayList param = new ArrayList(3);
- param.add(new DERValue(DER.INTEGER, params.getP()));
- param.add(new DERValue(DER.INTEGER, params.getG()));
- param.add(new DERValue(DER.INTEGER, q));
- alg.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, param));
- spki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, alg));
- spki.add(new DERValue(DER.BIT_STRING, new BitString(Y.toByteArray())));
- encoded = new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, spki).getEncoded();
- if (encoded != null)
- return (byte[]) encoded.clone();
- return null;
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/GnuDSAPrivateKey.java b/libjava/classpath/gnu/java/security/provider/GnuDSAPrivateKey.java
deleted file mode 100644
index aac2faa..0000000
--- a/libjava/classpath/gnu/java/security/provider/GnuDSAPrivateKey.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/* GnuDSAPrivateKey.java --- Gnu DSA Private Key
- Copyright (C) 1999,2003,2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.OID;
-import gnu.java.security.der.DER;
-import gnu.java.security.der.DERValue;
-import gnu.java.security.der.DERWriter;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.security.interfaces.DSAParams;
-import java.security.interfaces.DSAPrivateKey;
-import java.security.spec.DSAParameterSpec;
-import java.util.ArrayList;
-
-public class GnuDSAPrivateKey implements DSAPrivateKey
-{
- private byte[] encodedKey;
- BigInteger x;
- BigInteger p;
- BigInteger q;
- BigInteger g;
-
- public GnuDSAPrivateKey(BigInteger x, BigInteger p, BigInteger q, BigInteger g )
- {
- this.x = x;
- this.p = p;
- this.q = q;
- this.g = g;
- }
-
- public String getAlgorithm()
- {
- return "DSA";
- }
-
- public String getFormat()
- {
- return "PKCS#8";
- }
-
- /**
- * Encodes this key as a PrivateKeyInfo
, as described in
- * PKCS #8. The ASN.1 specification for this structure is:
- *
- *
- * PrivateKeyInfo ::= SEQUENCE {
- * version Version,
- * privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
- * privateKey PrivateKey,
- * attributes [0] IMPLICIT Attributes OPTIONAL }
- *
- * Version ::= INTEGER
- *
- * PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
- *
- * PrivateKey ::= OCTET STRING
- *
- * Attributes ::= SET OF Attribute
- *
- *
- * DSA private keys (in Classpath at least) have no attributes.
- */
- public byte[] getEncoded()
- {
- if (encodedKey != null)
- return (byte[]) encodedKey.clone();
- try
- {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ArrayList pki = new ArrayList(3);
- pki.add(new DERValue(DER.INTEGER, BigInteger.ZERO));
- ArrayList algId = new ArrayList(2);
- algId.add(new DERValue(DER.OBJECT_IDENTIFIER,
- new OID("1.2.840.10040.4.1")));
- ArrayList algParams = new ArrayList(3);
- algParams.add(new DERValue(DER.INTEGER, p));
- algParams.add(new DERValue(DER.INTEGER, q));
- algParams.add(new DERValue(DER.INTEGER, g));
- algId.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, algParams));
- pki.add(new DERValue(DER.OCTET_STRING, x.toByteArray()));
- DERWriter.write(out, new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, pki));
- return (byte[]) (encodedKey = out.toByteArray()).clone();
- }
- catch (IOException ioe)
- {
- return null;
- }
- }
-
- public DSAParams getParams()
- {
- return (DSAParams)(new DSAParameterSpec(p,q,g));
- }
-
- public BigInteger getX()
- {
- return x;
- }
-
- public String toString()
- {
- return "GnuDSAPrivateKey: x="
- + (x != null ? x.toString(16) : "null") + " p="
- + (p != null ? p.toString(16) : "null") + " q="
- + (q != null ? q.toString(16) : "null") + " g="
- + (g != null ? g.toString(16) : "null");
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/GnuDSAPublicKey.java b/libjava/classpath/gnu/java/security/provider/GnuDSAPublicKey.java
deleted file mode 100644
index 41195fa..0000000
--- a/libjava/classpath/gnu/java/security/provider/GnuDSAPublicKey.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/* GnuDSAPublicKey.java --- Gnu DSA Public Key
- Copyright (C) 1999,2003,2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.OID;
-import gnu.java.security.der.BitString;
-import gnu.java.security.der.DER;
-import gnu.java.security.der.DERValue;
-import gnu.java.security.der.DERWriter;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.security.interfaces.DSAParams;
-import java.security.interfaces.DSAPublicKey;
-import java.security.spec.DSAParameterSpec;
-import java.util.ArrayList;
-
-public class GnuDSAPublicKey implements DSAPublicKey
-{
- private byte[] encodedKey;
- BigInteger y;
- BigInteger p;
- BigInteger q;
- BigInteger g;
-
- public GnuDSAPublicKey(BigInteger y, BigInteger p, BigInteger q, BigInteger g )
- {
- this.y = y;
- this.p = p;
- this.q = q;
- this.g = g;
- }
-
- public String getAlgorithm()
- {
- return "DSA";
- }
-
- public String getFormat()
- {
- return "X.509";
- }
-
- /**
- * The encoded form of DSA public keys is:
- *
- *
- * SubjectPublicKeyInfo ::= SEQUENCE {
- * algorithm AlgorithmIdentifier,
- * subjectPublicKey BIT STRING }
- *
- */
- public byte[] getEncoded()
- {
- if (encodedKey != null)
- return (byte[]) encodedKey.clone();
- try
- {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ArrayList spki = new ArrayList(2);
- ArrayList alg = new ArrayList(2);
- alg.add(new DERValue(DER.OBJECT_IDENTIFIER,
- new OID("1.2.840.113549.1.1.1")));
- ArrayList params = new ArrayList(3);
- params.add(new DERValue(DER.INTEGER, p));
- params.add(new DERValue(DER.INTEGER, q));
- params.add(new DERValue(DER.INTEGER, g));
- alg.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, params));
- spki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, alg));
- spki.add(new DERValue(DER.BIT_STRING, new BitString(y.toByteArray())));
- DERWriter.write(out, new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, spki));
- return (byte[]) (encodedKey = out.toByteArray()).clone();
- }
- catch (IOException ioe)
- {
- return null;
- }
- }
-
- public DSAParams getParams()
- {
- if (p == null || q == null || g == null)
- return null;
- return (DSAParams)(new DSAParameterSpec(p,q,g));
- }
-
- public BigInteger getY()
- {
- return y;
- }
-
- public String toString()
- {
- return
- "GnuDSAPublicKey: y=" + (y != null ? y.toString(16) : "(null)") +
- " p=" + (p != null ? p.toString(16) : "(null)") +
- " q=" + (q != null ? q.toString(16) : "(null)") +
- " g=" + (g != null ? g.toString(16) : "(null)");
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/GnuRSAPrivateKey.java b/libjava/classpath/gnu/java/security/provider/GnuRSAPrivateKey.java
deleted file mode 100644
index b09fc88..0000000
--- a/libjava/classpath/gnu/java/security/provider/GnuRSAPrivateKey.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/* GnuRSAPrivateKey.java -- GNU RSA private key.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.OID;
-import gnu.java.security.der.DER;
-import gnu.java.security.der.DERValue;
-
-import java.math.BigInteger;
-import java.security.interfaces.RSAPrivateCrtKey;
-import java.security.spec.RSAPrivateCrtKeySpec;
-import java.util.ArrayList;
-
-class GnuRSAPrivateKey implements RSAPrivateCrtKey
-{
-
- // Fields.
- // -------------------------------------------------------------------------
-
- private final RSAPrivateCrtKeySpec spec;
- private byte[] encodedKey;
-
- // Constructor.
- // -------------------------------------------------------------------------
-
- public GnuRSAPrivateKey(RSAPrivateCrtKeySpec spec)
- {
- this.spec = spec;
- }
-
- // Instance methods.
- // -------------------------------------------------------------------------
-
- public BigInteger getModulus()
- {
- return spec.getModulus();
- }
-
- public BigInteger getPrivateExponent()
- {
- return spec.getPrivateExponent();
- }
-
- public BigInteger getCrtCoefficient()
- {
- return spec.getCrtCoefficient();
- }
-
- public BigInteger getPrimeExponentP()
- {
- return spec.getPrimeExponentP();
- }
-
- public BigInteger getPrimeExponentQ()
- {
- return spec.getPrimeExponentQ();
- }
-
- public BigInteger getPrimeP()
- {
- return spec.getPrimeP();
- }
-
- public BigInteger getPrimeQ()
- {
- return spec.getPrimeQ();
- }
-
- public BigInteger getPublicExponent()
- {
- return spec.getPublicExponent();
- }
-
- public String getAlgorithm()
- {
- return "RSA";
- }
-
- public String getFormat()
- {
- return "PKCS#8";
- }
-
- /**
- * The encoded form is:
- *
- *
- * RSAPrivateKey ::= SEQUENCE {
- * version Version,
- * modulus INTEGER, -- n
- * publicExponent INTEGER, -- e
- * privateExponent INTEGER, -- d
- * prime1 INTEGER, -- p
- * prime2 INTEGER, -- q
- * exponent1 INTEGER, -- d mod (p-1)
- * exponent2 INTEGER, -- d mod (q-1)
- * coefficient INTEGER -- (inverse of q) mod p }
- *
- *
- * Which is in turn encoded in a PrivateKeyInfo structure from PKCS#8.
- */
- public byte[] getEncoded()
- {
- if (encodedKey != null)
- return (byte[]) encodedKey.clone();
- ArrayList key = new ArrayList(9);
- key.add(new DERValue(DER.INTEGER, BigInteger.ZERO));
- key.add(new DERValue(DER.INTEGER, getModulus()));
- key.add(new DERValue(DER.INTEGER, getPublicExponent()));
- key.add(new DERValue(DER.INTEGER, getPrivateExponent()));
- key.add(new DERValue(DER.INTEGER, getPrimeP()));
- key.add(new DERValue(DER.INTEGER, getPrimeQ()));
- key.add(new DERValue(DER.INTEGER, getPrimeExponentP()));
- key.add(new DERValue(DER.INTEGER, getPrimeExponentQ()));
- key.add(new DERValue(DER.INTEGER, getCrtCoefficient()));
- DERValue pk = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, key);
- ArrayList pki = new ArrayList(3);
- pki.add(new DERValue(DER.INTEGER, BigInteger.ZERO));
- ArrayList alg = new ArrayList(2);
- alg.add(new DERValue(DER.OBJECT_IDENTIFIER,
- new OID("1.2.840.113549.1.1.1")));
- alg.add(new DERValue(DER.NULL, null));
- pki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, alg));
- pki.add(new DERValue(DER.OCTET_STRING, pk.getEncoded()));
- encodedKey = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, pki).getEncoded();
- return (byte[]) encodedKey.clone();
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/GnuRSAPublicKey.java b/libjava/classpath/gnu/java/security/provider/GnuRSAPublicKey.java
deleted file mode 100644
index a35e761..0000000
--- a/libjava/classpath/gnu/java/security/provider/GnuRSAPublicKey.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/* GnuRSAPublicKey.java -- GNU RSA public key.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.OID;
-import gnu.java.security.der.BitString;
-import gnu.java.security.der.DER;
-import gnu.java.security.der.DERValue;
-
-import java.math.BigInteger;
-import java.security.interfaces.RSAPublicKey;
-import java.security.spec.RSAPublicKeySpec;
-import java.util.ArrayList;
-
-class GnuRSAPublicKey implements RSAPublicKey
-{
-
- // Fields.
- // -------------------------------------------------------------------------
-
- private final RSAPublicKeySpec spec;
- private byte[] encodedKey;
-
- // Constructor.
- // -------------------------------------------------------------------------
-
- public GnuRSAPublicKey(RSAPublicKeySpec spec)
- {
- this.spec = spec;
- }
-
- // Instance methods.
- // -------------------------------------------------------------------------
-
- public BigInteger getModulus()
- {
- return spec.getModulus();
- }
-
- public BigInteger getPublicExponent()
- {
- return spec.getPublicExponent();
- }
-
- public String getAlgorithm()
- {
- return "RSA";
- }
-
- public String getFormat()
- {
- return "X.509";
- }
-
- public byte[] getEncoded()
- {
- if (encodedKey != null)
- return (byte[]) encodedKey.clone();
- ArrayList key = new ArrayList(2);
- key.add(new DERValue(DER.INTEGER, getModulus()));
- key.add(new DERValue(DER.INTEGER, getPublicExponent()));
- DERValue rsapk = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, key);
- ArrayList alg = new ArrayList(2);
- alg.add(new DERValue(DER.OBJECT_IDENTIFIER,
- new OID("1.2.840.113549.1.1.1")));
- alg.add(new DERValue(DER.NULL, null));
- ArrayList spki = new ArrayList(2);
- spki.add(new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, alg));
- spki.add(new DERValue(DER.BIT_STRING, new BitString(rsapk.getEncoded())));
- encodedKey = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, spki).getEncoded();
- return (byte[]) encodedKey.clone();
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/MD2withRSA.java b/libjava/classpath/gnu/java/security/provider/MD2withRSA.java
deleted file mode 100644
index a72ae55..0000000
--- a/libjava/classpath/gnu/java/security/provider/MD2withRSA.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/* MD2withRSA.java -- MD2 with RSA encryption signatures.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-public class MD2withRSA extends RSA
-{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
- public MD2withRSA() throws NoSuchAlgorithmException
- {
- super(MessageDigest.getInstance("MD2"), DIGEST_ALGORITHM.getChild(2));
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/MD4withRSA.java b/libjava/classpath/gnu/java/security/provider/MD4withRSA.java
deleted file mode 100644
index 76a6a1a..0000000
--- a/libjava/classpath/gnu/java/security/provider/MD4withRSA.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/* MD4withRSA.java -- MD4 with RSA encryption signatures.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-public class MD4withRSA extends RSA
-{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
- public MD4withRSA() throws NoSuchAlgorithmException
- {
- super(MessageDigest.getInstance("MD4"), DIGEST_ALGORITHM.getChild(4));
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/MD5.java b/libjava/classpath/gnu/java/security/provider/MD5.java
deleted file mode 100644
index 1534eb9..0000000
--- a/libjava/classpath/gnu/java/security/provider/MD5.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/* MD5.java -- Class implementing the MD5 algorithm as specified in RFC1321.
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-import java.security.MessageDigest;
-
-/**
- This class implements the MD5 algorithm as described in RFC1321.
-
- @see java.security.MessageDigest
-*/
-public class MD5 extends MessageDigest implements Cloneable
-{
- private final int W[] = new int[16];
- private long bytecount;
- private int A;
- private int B;
- private int C;
- private int D;
-
- public MD5()
- {
- super("MD5");
- engineReset ();
- }
-
- public Object clone()
- {
- return new MD5 (this);
- }
-
- private MD5 (MD5 copy)
- {
- this ();
- bytecount = copy.bytecount;
- A = copy.A;
- B = copy.B;
- C = copy.C;
- D = copy.D;
- System.arraycopy (copy.W, 0, W, 0, 16);
- }
-
- public int engineGetDigestLength()
- {
- return 16;
- }
-
- // Intialize the A,B,C,D needed for the hash
- public void engineReset()
- {
- bytecount = 0;
- A = 0x67452301;
- B = 0xefcdab89;
- C = 0x98badcfe;
- D = 0x10325476;
- for(int i = 0; i < 16; i++)
- W[i] = 0;
- }
-
- public void engineUpdate (byte b)
- {
- int i = (int)bytecount % 64;
- int shift = (3 - i % 4) * 8;
- int idx = i / 4;
-
- // if you could index ints, this would be: W[idx][shift/8] = b
- W[idx] = (W[idx] & ~(0xff << shift)) | ((b & 0xff) << shift);
-
- // if we've filled up a block, then process it
- if ((++ bytecount) % 64 == 0)
- munch ();
- }
-
- public void engineUpdate (byte bytes[], int off, int len)
- {
- if (len < 0)
- throw new ArrayIndexOutOfBoundsException ();
-
- int end = off + len;
- while (off < end)
- engineUpdate (bytes[off++]);
- }
-
- public byte[] engineDigest()
- {
- long bitcount = bytecount * 8;
- engineUpdate ((byte)0x80); // 10000000 in binary; the start of the padding
-
- // add the rest of the padding to fill this block out, but leave 8
- // bytes to put in the original bytecount
- while ((int)bytecount % 64 != 56)
- engineUpdate ((byte)0);
-
- // add the length of the original, unpadded block to the end of
- // the padding
- W[14] = SWAP((int)(0xffffffff & bitcount));
- W[15] = SWAP((int)(0xffffffff & (bitcount >>> 32)));
- bytecount += 8;
-
- // digest the fully padded block
- munch ();
-
- A = SWAP(A);
- B = SWAP(B);
- C = SWAP(C);
- D = SWAP(D);
- byte[] result = new byte[] {(byte)(A >>> 24), (byte)(A >>> 16),
- (byte)(A >>> 8), (byte)A,
- (byte)(B >>> 24), (byte)(B >>> 16),
- (byte)(B >>> 8), (byte)B,
- (byte)(C >>> 24), (byte)(C >>> 16),
- (byte)(C >>> 8), (byte)C,
- (byte)(D >>> 24), (byte)(D >>> 16),
- (byte)(D >>> 8), (byte)D};
-
- engineReset ();
- return result;
- }
-
- private int F( int X, int Y, int Z)
- {
- return ((X & Y) | (~X & Z));
- }
-
- private int G( int X, int Y, int Z)
- {
- return ((X & Z) | (Y & ~Z));
- }
-
- private int H( int X, int Y, int Z)
- {
- return (X ^ Y ^ Z);
- }
-
- private int I( int X, int Y, int Z)
- {
- return (Y ^ (X | ~Z));
- }
-
- private int rotateLeft( int i, int count)
- {
- //Taken from FIPS 180-1
- return ( (i << count) | (i >>> (32 - count)) ) ;
- }
-
- /* Round 1. */
- private int FF( int a, int b, int c, int d, int k, int s, int i)
- {
- /* Let [abcd k s i] denote the operation */
- a += F(b,c,d) + k + i;
- return b + rotateLeft(a, s);
- }
- /* Round 2. */
- private int GG( int a, int b, int c, int d, int k, int s, int i)
- {
- /* Let [abcd k s i] denote the operation */
- a += G(b,c,d) + k + i;
- return b + rotateLeft(a, s);
- }
- /* Round 3. */
- private int HH( int a, int b, int c, int d, int k, int s, int i)
- {
- /* Let [abcd k s t] denote the operation */
- a += H(b,c,d) + k + i;
- return b + rotateLeft(a, s);
- }
-
- /* Round 4. */
- private int II( int a, int b, int c, int d, int k, int s, int i)
- {
- /* Let [abcd k s t] denote the operation */
- a += I(b,c,d) + k + i;
- return b + rotateLeft(a, s);
- }
-
- private int SWAP(int n)
- {
- //Copied from md5.c in FSF Gnu Privacy Guard 0.9.2
- return (( (0xff & n) << 24) | ((n & 0xff00) << 8) | ((n >>> 8) & 0xff00) | (n >>> 24));
- }
-
- private void munch()
- {
- int AA,BB,CC,DD, j;
- int X[] = new int[16];
-
- /* Copy block i into X. */
- for(j = 0; j < 16; j++)
- X[j] = SWAP(W[j]);
-
- /* Save A as AA, B as BB, C as CC, and D as DD. */
- AA = A;
- BB = B;
- CC = C;
- DD = D;
-
- /* The hex constants are from md5.c
- in FSF Gnu Privacy Guard 0.9.2 */
- /* Round 1. */
- /* Let [abcd k s i] denote the operation
- a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
- /* Do the following 16 operations. */
- A = FF(A,B,C,D, X[0], 7, 0xd76aa478);
- D = FF(D,A,B,C, X[1], 12, 0xe8c7b756);
- C = FF(C,D,A,B, X[2], 17, 0x242070db);
- B = FF(B,C,D,A, X[3], 22, 0xc1bdceee);
-
- A = FF(A,B,C,D, X[4], 7, 0xf57c0faf);
- D = FF(D,A,B,C, X[5], 12, 0x4787c62a);
- C = FF(C,D,A,B, X[6], 17, 0xa8304613);
- B = FF(B,C,D,A, X[7], 22, 0xfd469501);
-
- A = FF(A,B,C,D, X[8], 7, 0x698098d8);
- D = FF(D,A,B,C, X[9], 12, 0x8b44f7af);
- C = FF(C,D,A,B, X[10], 17, 0xffff5bb1);
- B = FF(B,C,D,A, X[11], 22, 0x895cd7be);
-
- A = FF(A,B,C,D, X[12], 7, 0x6b901122);
- D = FF(D,A,B,C, X[13], 12, 0xfd987193);
- C = FF(C,D,A,B, X[14], 17, 0xa679438e);
- B = FF(B,C,D,A, X[15], 22, 0x49b40821);
-
- /* Round 2. */
- /* Let [abcd k s i] denote the operation
- a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
- /* Do the following 16 operations. */
- A = GG(A,B,C,D, X[1], 5, 0xf61e2562);
- D = GG(D,A,B,C, X[6], 9, 0xc040b340);
- C = GG(C,D,A,B, X[11], 14, 0x265e5a51);
- B = GG(B,C,D,A, X[0], 20, 0xe9b6c7aa);
-
- A = GG(A,B,C,D, X[5], 5, 0xd62f105d);
- D = GG(D,A,B,C, X[10], 9, 0x02441453);
- C = GG(C,D,A,B, X[15], 14, 0xd8a1e681);
- B = GG(B,C,D,A, X[4], 20, 0xe7d3fbc8);
-
- A = GG(A,B,C,D, X[9], 5, 0x21e1cde6);
- D = GG(D,A,B,C, X[14], 9, 0xc33707d6);
- C = GG(C,D,A,B, X[3], 14, 0xf4d50d87);
- B = GG(B,C,D,A, X[8], 20, 0x455a14ed);
-
- A = GG(A,B,C,D, X[13], 5, 0xa9e3e905);
- D = GG(D,A,B,C, X[2], 9, 0xfcefa3f8);
- C = GG(C,D,A,B, X[7], 14, 0x676f02d9);
- B = GG(B,C,D,A, X[12], 20, 0x8d2a4c8a);
-
- /* Round 3. */
- /* Let [abcd k s t] denote the operation
- a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
- /* Do the following 16 operations. */
- A = HH(A,B,C,D, X[5], 4, 0xfffa3942);
- D = HH(D,A,B,C, X[8], 11, 0x8771f681);
- C = HH(C,D,A,B, X[11], 16, 0x6d9d6122);
- B = HH(B,C,D,A, X[14], 23, 0xfde5380c);
-
- A = HH(A,B,C,D, X[1], 4, 0xa4beea44);
- D = HH(D,A,B,C, X[4], 11, 0x4bdecfa9);
- C = HH(C,D,A,B, X[7], 16, 0xf6bb4b60);
- B = HH(B,C,D,A, X[10], 23, 0xbebfbc70);
-
- A = HH(A,B,C,D, X[13], 4, 0x289b7ec6);
- D = HH(D,A,B,C, X[0], 11, 0xeaa127fa);
- C = HH(C,D,A,B, X[3], 16, 0xd4ef3085);
- B = HH(B,C,D,A, X[6], 23, 0x04881d05);
-
- A = HH(A,B,C,D, X[9], 4, 0xd9d4d039);
- D = HH(D,A,B,C, X[12], 11, 0xe6db99e5);
- C = HH(C,D,A,B, X[15], 16, 0x1fa27cf8);
- B = HH(B,C,D,A, X[2], 23, 0xc4ac5665);
-
- /* Round 4. */
- /* Let [abcd k s t] denote the operation
- a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
- /* Do the following 16 operations. */
- A = II(A,B,C,D, X[0], 6, 0xf4292244);
- D = II(D,A,B,C, X[7], 10, 0x432aff97);
- C = II(C,D,A,B, X[14], 15, 0xab9423a7);
- B = II(B,C,D,A, X[5], 21, 0xfc93a039);
-
- A = II(A,B,C,D, X[12], 6, 0x655b59c3);
- D = II(D,A,B,C, X[3], 10, 0x8f0ccc92);
- C = II(C,D,A,B, X[10], 15, 0xffeff47d);
- B = II(B,C,D,A, X[1], 21, 0x85845dd1);
-
- A = II(A,B,C,D, X[8], 6, 0x6fa87e4f);
- D = II(D,A,B,C, X[15], 10, 0xfe2ce6e0);
- C = II(C,D,A,B, X[6], 15, 0xa3014314);
- B = II(B,C,D,A, X[13], 21, 0x4e0811a1);
-
- A = II(A,B,C,D, X[4], 6, 0xf7537e82);
- D = II(D,A,B,C, X[11], 10, 0xbd3af235);
- C = II(C,D,A,B, X[2], 15, 0x2ad7d2bb);
- B = II(B,C,D,A, X[9], 21, 0xeb86d391);
-
- /* Then perform the following additions. (That is increment each
- of the four registers by the value it had before this block
- was started.) */
- A = A + AA;
- B = B + BB;
- C = C + CC;
- D = D + DD;
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/MD5withRSA.java b/libjava/classpath/gnu/java/security/provider/MD5withRSA.java
deleted file mode 100644
index 721d897..0000000
--- a/libjava/classpath/gnu/java/security/provider/MD5withRSA.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/* MD5withRSA.java -- MD5 with RSA encryption signatures.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-public class MD5withRSA extends RSA
-{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
- public MD5withRSA() throws NoSuchAlgorithmException
- {
- super(MessageDigest.getInstance("MD5"), DIGEST_ALGORITHM.getChild(5));
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/PKIXCertPathValidatorImpl.java b/libjava/classpath/gnu/java/security/provider/PKIXCertPathValidatorImpl.java
index ab89434..8801637 100644
--- a/libjava/classpath/gnu/java/security/provider/PKIXCertPathValidatorImpl.java
+++ b/libjava/classpath/gnu/java/security/provider/PKIXCertPathValidatorImpl.java
@@ -39,6 +39,8 @@ exception statement from your version. */
package gnu.java.security.provider;
import gnu.java.security.OID;
+import gnu.java.security.Registry;
+import gnu.java.security.key.dss.DSSPublicKey;
import gnu.java.security.x509.GnuPKIExtension;
import gnu.java.security.x509.PolicyNodeImpl;
import gnu.java.security.x509.X509CRLSelectorImpl;
@@ -241,8 +243,11 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
if (!(prevKey instanceof DSAPublicKey))
throw new InvalidKeyException("DSA keys not chainable");
dsa = ((DSAPublicKey) prevKey).getParams();
- pubKey = new GnuDSAPublicKey(((DSAPublicKey) pubKey).getY(),
- dsa.getP(), dsa.getQ(), dsa.getG());
+ pubKey = new DSSPublicKey(Registry.X509_ENCODING_ID,
+ dsa.getP(),
+ dsa.getQ(),
+ dsa.getG(),
+ ((DSAPublicKey) pubKey).getY());
}
}
if (sigProvider == null)
diff --git a/libjava/classpath/gnu/java/security/provider/RSA.java b/libjava/classpath/gnu/java/security/provider/RSA.java
deleted file mode 100644
index c3cfbbf..0000000
--- a/libjava/classpath/gnu/java/security/provider/RSA.java
+++ /dev/null
@@ -1,311 +0,0 @@
-/* RSA.java -- RSA PKCS#1 signatures.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.OID;
-import gnu.java.security.der.DER;
-import gnu.java.security.der.DERReader;
-import gnu.java.security.der.DERValue;
-import gnu.java.security.der.DERWriter;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.security.InvalidKeyException;
-import java.security.MessageDigest;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.SecureRandom;
-import java.security.SignatureException;
-import java.security.SignatureSpi;
-import java.security.interfaces.RSAPrivateKey;
-import java.security.interfaces.RSAPublicKey;
-import java.util.ArrayList;
-
-public abstract class RSA extends SignatureSpi implements Cloneable
-{
-
- // Constants and fields.
- // -------------------------------------------------------------------------
-
- /**
- * digestAlgorithm OBJECT IDENTIFIER ::=
- * { iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) }
- */
- protected static final OID DIGEST_ALGORITHM = new OID("1.2.840.113549.2");
-
- protected final OID digestAlgorithm;
- protected final MessageDigest md;
- protected RSAPrivateKey signerKey;
- protected RSAPublicKey verifierKey;
-
- // Constructor.
- // -------------------------------------------------------------------------
-
- protected RSA(MessageDigest md, OID digestAlgorithm)
- {
- super();
- this.md = md;
- this.digestAlgorithm = digestAlgorithm;
- }
-
- // Instance methods.
- // -------------------------------------------------------------------------
-
- public Object clone() throws CloneNotSupportedException
- {
- return super.clone();
- }
-
- protected Object engineGetParameter(String param)
- {
- throw new UnsupportedOperationException("deprecated");
- }
-
- protected void engineSetParameter(String param, Object value)
- {
- throw new UnsupportedOperationException("deprecated");
- }
-
- protected void engineInitSign(PrivateKey privateKey)
- throws InvalidKeyException
- {
- if (!(privateKey instanceof RSAPrivateKey))
- throw new InvalidKeyException();
- verifierKey = null;
- signerKey = (RSAPrivateKey) privateKey;
- }
-
- protected void engineInitSign(PrivateKey privateKey, SecureRandom random)
- throws InvalidKeyException
- {
- // This class does not need random bytes.
- engineInitSign(privateKey);
- }
-
- protected void engineInitVerify(PublicKey publicKey)
- throws InvalidKeyException
- {
- if (!(publicKey instanceof RSAPublicKey))
- throw new InvalidKeyException();
- signerKey = null;
- verifierKey = (RSAPublicKey) publicKey;
- }
-
- protected void engineUpdate(byte b) throws SignatureException
- {
- if (signerKey == null && verifierKey == null)
- throw new SignatureException("not initialized");
- md.update(b);
- }
-
- protected void engineUpdate(byte[] buf, int off, int len)
- throws SignatureException
- {
- if (signerKey == null && verifierKey == null)
- throw new SignatureException("not initialized");
- md.update(buf, off, len);
- }
-
- protected byte[] engineSign() throws SignatureException
- {
- if (signerKey == null)
- throw new SignatureException("not initialized for signing");
- //
- // The signature will be the RSA encrypted BER representation of
- // the following:
- //
- // DigestInfo ::= SEQUENCE {
- // digestAlgorithm DigestAlgorithmIdentifier,
- // digest Digest }
- //
- // DigestAlgorithmIdentifier ::= AlgorithmIdentifier
- //
- // Digest ::= OCTET STRING
- //
- ArrayList digestAlg = new ArrayList(2);
- digestAlg.add(new DERValue(DER.OBJECT_IDENTIFIER, digestAlgorithm));
- digestAlg.add(new DERValue(DER.NULL, null));
- ArrayList digestInfo = new ArrayList(2);
- digestInfo.add(new DERValue(DER.SEQUENCE, digestAlg));
- digestInfo.add(new DERValue(DER.OCTET_STRING, md.digest()));
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try
- {
- DERWriter.write(out, new DERValue(DER.SEQUENCE, digestInfo));
- }
- catch (IOException ioe)
- {
- throw new SignatureException(ioe.toString());
- }
- byte[] buf = out.toByteArray();
- md.reset();
-
- // k = octect length of the modulus.
- int k = signerKey.getModulus().bitLength();
- k = (k >>> 3) + ((k & 7) == 0 ? 0 : 1);
- if (buf.length < k - 3)
- {
- throw new SignatureException("RSA modulus too small");
- }
- byte[] d = new byte[k];
-
- // Padding type 1:
- // 00 | 01 | FF | ... | FF | 00 | D
- d[1] = 0x01;
- for (int i = 2; i < k - buf.length - 1; i++)
- d[i] = (byte) 0xFF;
- System.arraycopy(buf, 0, d, k - buf.length, buf.length);
-
- BigInteger eb = new BigInteger(d);
-
- byte[] ed = eb.modPow(signerKey.getPrivateExponent(),
- signerKey.getModulus()).toByteArray();
-
- // Ensure output is k octets long.
- if (ed.length < k)
- {
- byte[] b = new byte[k];
- System.arraycopy(eb, 0, b, k - ed.length, ed.length);
- ed = b;
- }
- else if (ed.length > k)
- {
- if (ed.length != k + 1)
- {
- throw new SignatureException("modPow result is larger than the modulus");
- }
- // Maybe an extra 00 octect.
- byte[] b = new byte[k];
- System.arraycopy(ed, 1, b, 0, k);
- ed = b;
- }
-
- return ed;
- }
-
- protected int engineSign(byte[] out, int off, int len)
- throws SignatureException
- {
- if (out == null || off < 0 || len < 0 || off+len > out.length)
- throw new SignatureException("illegal output argument");
- byte[] result = engineSign();
- if (result.length > len)
- throw new SignatureException("not enough space for signature");
- System.arraycopy(result, 0, out, off, result.length);
- return result.length;
- }
-
- protected boolean engineVerify(byte[] sig) throws SignatureException
- {
- if (verifierKey == null)
- throw new SignatureException("not initialized for verifying");
- if (sig == null)
- throw new SignatureException("no signature specified");
- int k = verifierKey.getModulus().bitLength();
- k = (k >>> 3) + ((k & 7) == 0 ? 0 : 1);
- if (sig.length != k)
- throw new SignatureException("signature is the wrong size (expecting "
- + k + " bytes, got " + sig.length + ")");
- BigInteger ed = new BigInteger(1, sig);
- byte[] eb = ed.modPow(verifierKey.getPublicExponent(),
- verifierKey.getModulus()).toByteArray();
-
- int i = 0;
- if (eb[0] == 0x00)
- {
- for (i = 1; i < eb.length && eb[i] == 0x00; i++);
- if (i == 1)
- throw new SignatureException("wrong RSA padding");
- i--;
- }
- else if (eb[0] == 0x01)
- {
- for (i = 1; i < eb.length && eb[i] != 0x00; i++)
- if (eb[i] != (byte) 0xFF)
- throw new IllegalArgumentException("wrong RSA padding");
- }
- else
- throw new SignatureException("wrong RSA padding type");
-
- byte[] d = new byte[eb.length-i-1];
- System.arraycopy(eb, i+1, d, 0, eb.length-i-1);
-
- DERReader der = new DERReader(d);
- try
- {
- DERValue val = der.read();
- if (val.getTag() != DER.SEQUENCE)
- throw new SignatureException("failed to parse DigestInfo");
- val = der.read();
- if (val.getTag() != DER.SEQUENCE)
- throw new SignatureException("failed to parse DigestAlgorithmIdentifier");
- boolean sequenceIsBer = val.getLength() == 0;
- val = der.read();
- if (val.getTag() != DER.OBJECT_IDENTIFIER)
- throw new SignatureException("failed to parse object identifier");
- if (!val.getValue().equals(digestAlgorithm))
- throw new SignatureException("digest algorithms do not match");
- val = der.read();
- // We should never see parameters here, since they are never used.
- if (val.getTag() != DER.NULL)
- throw new SignatureException("cannot handle digest parameters");
- if (sequenceIsBer)
- der.skip(1); // end-of-sequence byte.
- val = der.read();
- if (val.getTag() != DER.OCTET_STRING)
- throw new SignatureException("failed to parse Digest");
- return MessageDigest.isEqual(md.digest(), (byte[]) val.getValue());
- }
- catch (IOException ioe)
- {
- throw new SignatureException(ioe.toString());
- }
- }
-
- protected boolean engineVerify(byte[] sig, int off, int len)
- throws SignatureException
- {
- if (sig == null || off < 0 || len < 0 || off+len > sig.length)
- throw new SignatureException("illegal parameter");
- byte[] buf = new byte[len];
- System.arraycopy(sig, off, buf, 0, len);
- return engineVerify(buf);
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/RSAKeyFactory.java b/libjava/classpath/gnu/java/security/provider/RSAKeyFactory.java
deleted file mode 100644
index d13cbe5..0000000
--- a/libjava/classpath/gnu/java/security/provider/RSAKeyFactory.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/* RSAKeyFactory.java -- RSA key factory.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.KeyFactorySpi;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-
-import java.security.interfaces.RSAPrivateCrtKey;
-import java.security.interfaces.RSAPrivateKey;
-import java.security.interfaces.RSAPublicKey;
-
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-import java.security.spec.PKCS8EncodedKeySpec;
-import java.security.spec.RSAPrivateCrtKeySpec;
-import java.security.spec.RSAPrivateKeySpec;
-import java.security.spec.RSAPublicKeySpec;
-import java.security.spec.X509EncodedKeySpec;
-
-public class RSAKeyFactory extends KeyFactorySpi
-{
-
- // Default constructor.
- // -------------------------------------------------------------------------
-
- // Instance methods.
- // -------------------------------------------------------------------------
-
- protected PrivateKey engineGeneratePrivate(KeySpec spec)
- throws InvalidKeySpecException
- {
- if (spec instanceof RSAPrivateCrtKeySpec)
- {
- return new GnuRSAPrivateKey((RSAPrivateCrtKeySpec) spec);
- }
- if (spec instanceof RSAPrivateKeySpec)
- {
- return new GnuRSAPrivateKey(new RSAPrivateCrtKeySpec(
- ((RSAPrivateKeySpec) spec).getModulus(), null,
- ((RSAPrivateKeySpec) spec).getPrivateExponent(), null,
- null, null, null, null));
- }
- if (spec instanceof PKCS8EncodedKeySpec)
- {
- EncodedKeyFactory ekf = new EncodedKeyFactory();
- PrivateKey pk = ekf.engineGeneratePrivate(spec);
- if (pk instanceof RSAPrivateKey)
- return pk;
- }
- throw new InvalidKeySpecException();
- }
-
- protected PublicKey engineGeneratePublic(KeySpec spec)
- throws InvalidKeySpecException
- {
- if (spec instanceof RSAPublicKeySpec)
- {
- return new GnuRSAPublicKey((RSAPublicKeySpec) spec);
- }
- if (spec instanceof X509EncodedKeySpec)
- {
- EncodedKeyFactory ekf = new EncodedKeyFactory();
- PublicKey pk = ekf.engineGeneratePublic(spec);
- if (pk instanceof RSAPublicKey)
- return pk;
- }
- throw new InvalidKeySpecException();
- }
-
- protected KeySpec engineGetKeySpec(Key key, Class keySpec)
- throws InvalidKeySpecException
- {
- if (keySpec.isAssignableFrom(RSAPrivateCrtKeySpec.class)
- && (key instanceof RSAPrivateCrtKey))
- {
- return new RSAPrivateCrtKeySpec(
- ((RSAPrivateCrtKey) key).getModulus(),
- ((RSAPrivateCrtKey) key).getPublicExponent(),
- ((RSAPrivateCrtKey) key).getPrivateExponent(),
- ((RSAPrivateCrtKey) key).getPrimeP(),
- ((RSAPrivateCrtKey) key).getPrimeQ(),
- ((RSAPrivateCrtKey) key).getPrimeExponentP(),
- ((RSAPrivateCrtKey) key).getPrimeExponentQ(),
- ((RSAPrivateCrtKey) key).getCrtCoefficient());
- }
- if (keySpec.isAssignableFrom(RSAPrivateKeySpec.class)
- && (key instanceof RSAPrivateKey))
- {
- return new RSAPrivateKeySpec(
- ((RSAPrivateCrtKey) key).getModulus(),
- ((RSAPrivateCrtKey) key).getPrivateExponent());
- }
- if (keySpec.isAssignableFrom(RSAPublicKeySpec.class)
- && (key instanceof RSAPublicKey))
- {
- return new RSAPublicKeySpec(
- ((RSAPrivateCrtKey) key).getModulus(),
- ((RSAPrivateCrtKey) key).getPublicExponent());
- }
- if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class)
- && key.getFormat().equalsIgnoreCase("PKCS#8"))
- {
- return new PKCS8EncodedKeySpec(key.getEncoded());
- }
- if (keySpec.isAssignableFrom(X509EncodedKeySpec.class)
- && key.getFormat().equalsIgnoreCase("X.509"))
- {
- return new X509EncodedKeySpec(key.getEncoded());
- }
- throw new InvalidKeySpecException();
- }
-
- protected Key engineTranslateKey(Key key) throws InvalidKeyException
- {
- if (key instanceof RSAPrivateCrtKey)
- {
- return new GnuRSAPrivateKey(new RSAPrivateCrtKeySpec(
- ((RSAPrivateCrtKey) key).getModulus(),
- ((RSAPrivateCrtKey) key).getPublicExponent(),
- ((RSAPrivateCrtKey) key).getPrivateExponent(),
- ((RSAPrivateCrtKey) key).getPrimeP(),
- ((RSAPrivateCrtKey) key).getPrimeQ(),
- ((RSAPrivateCrtKey) key).getPrimeExponentP(),
- ((RSAPrivateCrtKey) key).getPrimeExponentQ(),
- ((RSAPrivateCrtKey) key).getCrtCoefficient()));
- }
- if (key instanceof RSAPrivateKey)
- {
- return new GnuRSAPrivateKey(new RSAPrivateCrtKeySpec(
- ((RSAPrivateKey) key).getModulus(), null,
- ((RSAPrivateKey) key).getPrivateExponent(), null,
- null, null, null, null));
- }
- if (key instanceof RSAPublicKey)
- {
- return new GnuRSAPublicKey(new RSAPublicKeySpec(
- ((RSAPrivateCrtKey) key).getModulus(),
- ((RSAPrivateCrtKey) key).getPublicExponent()));
- }
- throw new InvalidKeyException();
- }
-}
diff --git a/libjava/classpath/gnu/java/security/provider/SHA.java b/libjava/classpath/gnu/java/security/provider/SHA.java
deleted file mode 100644
index e3b09bc..0000000
--- a/libjava/classpath/gnu/java/security/provider/SHA.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/* SHA.java -- Class implementing the SHA-1 algorithm as specified in [1].
- Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import java.security.MessageDigest;
-
-/**
- This class implements the SHA-1 algorithm as described in [1].
-
- [1] Federal Information Processing Standards Publication 180-1.
- Specifications for the Secure Hash Standard. April 17, 1995.
-
- @see java.security.MessageDigest
-*/
-public class SHA extends MessageDigest implements Cloneable
-{
- public SHA ()
- {
- super("SHA");
- engineReset ();
- }
-
- public int engineGetDigestLength()
- {
- return 20;
- }
-
- public void engineUpdate (byte b)
- {
- int i = ((int)bytecount) & 0x3f; //wgs
- int shift = (3 - i % 4) << 3;
- int idx = i / 4;
-
- i = (int)b;
- W[idx] = (W[idx] & ~(0xff << shift)) | ((i & 0xff) << shift);
-
- // if we've filled up a block, then process it
- if (((++bytecount) & 0x3f) == 0)
- munch ();
- }
-
- // This could be optimized.
- public void engineUpdate (byte bytes[], int off, int len)
- {
- if (len < 0)
- throw new ArrayIndexOutOfBoundsException ();
-
- int end = off + len;
- while (off < end)
- engineUpdate (bytes[off++]);
- }
-
- public void engineReset ()
- {
- bytecount = 0;
- // magic numbers from [1] p. 10.
- H0 = 0x67452301;
- H1 = 0xefcdab89;
- H2 = 0x98badcfe;
- H3 = 0x10325476;
- H4 = 0xc3d2e1f0;
- }
-
- public byte[] engineDigest ()
- {
- long bitcount = bytecount << 3;
- engineUpdate ((byte)0x80); // 10000000 in binary; the start of the padding
-
- // add the rest of the padding to fill this block out, but leave 8
- // bytes to put in the original bytecount
- while ((bytecount & 0x3f) != 56)
- engineUpdate ((byte)0);
-
- // add the length of the original, unpadded block to the end of
- // the padding
- W[14] = (int)(bitcount >>> 32);
- W[15] = (int)bitcount;
- bytecount += 8;
-
- // digest the fully padded block
- munch ();
-
- byte[] result
- = new byte[] {(byte)(H0 >>> 24), (byte)(H0 >>> 16),
- (byte)(H0 >>> 8), (byte)H0,
- (byte)(H1 >>> 24), (byte)(H1 >>> 16),
- (byte)(H1 >>> 8), (byte)H1,
- (byte)(H2 >>> 24), (byte)(H2 >>> 16),
- (byte)(H2 >>> 8), (byte)H2,
- (byte)(H3 >>> 24), (byte)(H3 >>> 16),
- (byte)(H3 >>> 8), (byte)H3,
- (byte)(H4 >>> 24), (byte)(H4 >>> 16),
- (byte)(H4 >>> 8), (byte)H4};
-
- engineReset ();
- return result;
- }
-
- // Process a single block. This is pretty much copied verbatim from
- // [1] pp. 9, 10.
- private void munch ()
- {
- for (int t = 16; t < 80; ++ t)
- {
- int Wt = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16];
- W[t] = Wt << 1 | Wt >>> 31;
- }
-
- int A = H0;
- int B = H1;
- int C = H2;
- int D = H3;
- int E = H4;
-
- for (int t = 0; t < 20; ++ t)
- {
- int TEMP = (A << 5 | A >>> 27) // S^5(A)
- + ((B & C) | (~B & D)) // f_t(B,C,D)
- + E + W[t]
- + 0x5a827999; // K_t
-
- E = D;
- D = C;
- C = B << 30 | B >>> 2; // S^30(B)
- B = A;
- A = TEMP;
- }
-
- for (int t = 20; t < 40; ++ t)
- {
- int TEMP = (A << 5 | A >>> 27) // S^5(A)
- + (B ^ C ^ D) // f_t(B,C,D)
- + E + W[t]
- + 0x6ed9eba1; // K_t
-
- E = D;
- D = C;
- C = B << 30 | B >>> 2; // S^30(B)
- B = A;
- A = TEMP;
- }
-
- for (int t = 40; t < 60; ++ t)
- {
- int TEMP = (A << 5 | A >>> 27) // S^5(A)
- + (B & C | B & D | C & D) // f_t(B,C,D)
- + E + W[t]
- + 0x8f1bbcdc; // K_t
-
- E = D;
- D = C;
- C = B << 30 | B >>> 2; // S^30(B)
- B = A;
- A = TEMP;
- }
-
- for (int t = 60; t < 80; ++ t)
- {
- int TEMP = (A << 5 | A >>> 27) // S^5(A)
- + (B ^ C ^ D) // f_t(B,C,D)
- + E + W[t]
- + 0xca62c1d6; // K_t
-
- E = D;
- D = C;
- C = B << 30 | B >>> 2; // S^30(B)
- B = A;
- A = TEMP;
- }
-
- H0 += A;
- H1 += B;
- H2 += C;
- H3 += D;
- H4 += E;
-
- // Reset W by clearing it.
- for (int t = 0; t < 80; ++ t)
- W[t] = 0;
- }
-
- public Object clone ()
- {
- return new SHA (this);
- }
-
- private SHA (SHA copy)
- {
- this ();
- bytecount = copy.bytecount;
- H0 = copy.H0;
- H1 = copy.H1;
- H2 = copy.H2;
- H3 = copy.H3;
- H4 = copy.H4;
- System.arraycopy (copy.W, 0, W, 0, 80);
- }
-
- private final int W[] = new int[80];
- private long bytecount;
- private int H0;
- private int H1;
- private int H2;
- private int H3;
- private int H4;
-}
diff --git a/libjava/classpath/gnu/java/security/provider/SHA1PRNG.java b/libjava/classpath/gnu/java/security/provider/SHA1PRNG.java
deleted file mode 100644
index e4058e3..0000000
--- a/libjava/classpath/gnu/java/security/provider/SHA1PRNG.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/* SHA1PRNG.java --- Secure Random SPI SHA1PRNG
- Copyright (C) 1999, 2001, 2003, 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import java.io.Serializable;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandomSpi;
-import java.util.Random;
-
-public class SHA1PRNG extends SecureRandomSpi implements Serializable
-{
- MessageDigest digest;
- byte seed[];
- byte data[];
- int seedpos;
- int datapos;
- private boolean seeded = false; // set to true when we seed this
- /**
- * The size of seed.
- */
- private static final int SEED_SIZE = 20;
- /**
- * The size of data.
- */
- private static final int DATA_SIZE = 40;
-
- /**
- * Create a new SHA-1 pseudo-random number generator.
- */
- public SHA1PRNG()
- {
- try {
- digest = MessageDigest.getInstance("SHA");
- } catch ( NoSuchAlgorithmException nsae) {
-// System.out.println("Failed to find SHA Message Digest: " + nsae);
-// nsae.printStackTrace();
- throw new InternalError ("no SHA implementation found");
- }
-
- seed = new byte[SEED_SIZE];
- seedpos = 0;
- data = new byte[DATA_SIZE];
- datapos = SEED_SIZE; // try to force hashing a first block
- }
-
- public void engineSetSeed(byte[] seed)
- {
- for(int i = 0; i < seed.length; i++)
- this.seed[seedpos++ % SEED_SIZE] ^= seed[i];
- seedpos %= SEED_SIZE;
-
- }
-
- public void engineNextBytes(byte[] bytes)
- {
- ensureIsSeeded ();
- int loc = 0;
- while (loc < bytes.length)
- {
- int copy = Math.min (bytes.length - loc, SEED_SIZE - datapos);
-
- if (copy > 0)
- {
- System.arraycopy (data, datapos, bytes, loc, copy);
- datapos += copy;
- loc += copy;
- }
- else
- {
- // No data ready for copying, so refill our buffer.
- System.arraycopy( seed, 0, data, SEED_SIZE, SEED_SIZE);
- byte[] digestdata = digest.digest( data );
- System.arraycopy( digestdata, 0, data, 0, SEED_SIZE);
- datapos = 0;
- }
- }
- }
-
- public byte[] engineGenerateSeed(int numBytes)
- {
- byte tmp[] = new byte[numBytes];
-
- engineNextBytes( tmp );
- return tmp;
- }
-
- private void ensureIsSeeded()
- {
- if (!seeded)
- {
- new Random(0L).nextBytes(seed);
-
- byte[] digestdata = digest.digest(data);
- System.arraycopy(digestdata, 0, data, 0, SEED_SIZE);
-
- seeded = true;
- }
- }
-
-}
diff --git a/libjava/classpath/gnu/java/security/provider/SHA1withRSA.java b/libjava/classpath/gnu/java/security/provider/SHA1withRSA.java
deleted file mode 100644
index 0e63fde..0000000
--- a/libjava/classpath/gnu/java/security/provider/SHA1withRSA.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/* SHA1withRSA.java -- SHA-1 with RSA encryption signatures.
- Copyright (C) 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.security.provider;
-
-import gnu.java.security.OID;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-public class SHA1withRSA extends RSA
-{
-
- // Constant.
- // -------------------------------------------------------------------------
-
- private static final OID SHA1 = new OID("1.3.14.3.2.26");
-
- // Constructor.
- // -------------------------------------------------------------------------
-
- public SHA1withRSA() throws NoSuchAlgorithmException
- {
- super(MessageDigest.getInstance("SHA-160"), SHA1);
- }
-}
diff --git a/libjava/classpath/gnu/java/security/sig/BaseSignature.java b/libjava/classpath/gnu/java/security/sig/BaseSignature.java
new file mode 100644
index 0000000..dd964d4
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/BaseSignature.java
@@ -0,0 +1,261 @@
+/* BaseSignature.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig;
+
+import gnu.java.security.hash.IMessageDigest;
+import gnu.java.security.prng.IRandom;
+import gnu.java.security.prng.LimitReachedException;
+import gnu.java.security.util.PRNG;
+
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ *
A base abstract class to facilitate implementations of concrete
+ * Signatures.
+ */
+public abstract class BaseSignature implements ISignature
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** The canonical name of this signature scheme. */
+ protected String schemeName;
+
+ /** The underlying message digest instance for this signature scheme. */
+ protected IMessageDigest md;
+
+ /** The public key to use when verifying signatures. */
+ protected PublicKey publicKey;
+
+ /** The private key to use when generating signatures (signing). */
+ protected PrivateKey privateKey;
+
+ /** The optional {@link Random} instance to use. */
+ private Random rnd;
+
+ /** The optional {@link IRandom} instance to use. */
+ private IRandom irnd;
+
+ /** Our default source of randomness. */
+ private PRNG prng = null;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Trivial constructor.
+ *
+ * @param schemeName the name of this signature scheme.
+ * @param md the underlying instance of the message digest algorithm.
+ * @throws IllegalArgumentException if the designated hash instance is
+ * null
.
+ */
+ protected BaseSignature(String schemeName, IMessageDigest md)
+ {
+ super();
+
+ this.schemeName = schemeName;
+ if (md == null)
+ throw new IllegalArgumentException("Message digest MUST NOT be null");
+
+ this.md = md;
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // gnu.crypto.sig.ISignature interface implementation ----------------------
+
+ public String name()
+ {
+ return schemeName + "-" + md.name();
+ }
+
+ public void setupVerify(Map attributes) throws IllegalArgumentException
+ {
+ setup(attributes);
+
+ // do we have a public key?
+ PublicKey key = (PublicKey) attributes.get(VERIFIER_KEY);
+ if (key != null)
+ {
+ setupForVerification(key);
+ }
+ }
+
+ public void setupSign(Map attributes) throws IllegalArgumentException
+ {
+ setup(attributes);
+
+ // do we have a private key?
+ PrivateKey key = (PrivateKey) attributes.get(SIGNER_KEY);
+ if (key != null)
+ {
+ setupForSigning(key);
+ }
+ }
+
+ public void update(byte b)
+ {
+ if (md == null)
+ {
+ throw new IllegalStateException();
+ }
+ md.update(b);
+ }
+
+ public void update(byte[] b, int off, int len)
+ {
+ if (md == null)
+ {
+ throw new IllegalStateException();
+ }
+ md.update(b, off, len);
+ }
+
+ public Object sign()
+ {
+ if (md == null || privateKey == null)
+ {
+ throw new IllegalStateException();
+ }
+
+ return generateSignature();
+ }
+
+ public boolean verify(Object sig)
+ {
+ if (md == null || publicKey == null)
+ {
+ throw new IllegalStateException();
+ }
+
+ return verifySignature(sig);
+ }
+
+ // abstract methods to be implemented by concrete subclasses ---------------
+
+ public abstract Object clone();
+
+ protected abstract void setupForVerification(PublicKey key)
+ throws IllegalArgumentException;
+
+ protected abstract void setupForSigning(PrivateKey key)
+ throws IllegalArgumentException;
+
+ protected abstract Object generateSignature() throws IllegalStateException;
+
+ protected abstract boolean verifySignature(Object signature)
+ throws IllegalStateException;
+
+ // Other instance methods --------------------------------------------------
+
+ /** Initialises the internal fields of this instance. */
+ protected void init()
+ {
+ md.reset();
+ rnd = null;
+ irnd = null;
+ publicKey = null;
+ privateKey = null;
+ }
+
+ /**
+ * Fills the designated byte array with random data.
+ *
+ * @param buffer the byte array to fill with random data.
+ */
+ protected void nextRandomBytes(byte[] buffer)
+ {
+ if (rnd != null)
+ {
+ rnd.nextBytes(buffer);
+ }
+ else if (irnd != null)
+ {
+ try
+ {
+ irnd.nextBytes(buffer, 0, buffer.length);
+ }
+ catch (IllegalStateException x)
+ {
+ throw new RuntimeException("nextRandomBytes(): "
+ + String.valueOf(x));
+ }
+ catch (LimitReachedException x)
+ {
+ throw new RuntimeException("nextRandomBytes(): "
+ + String.valueOf(x));
+ }
+ }
+ else
+ getDefaultPRNG().nextBytes(buffer);
+ }
+
+ private void setup(Map attributes)
+ {
+ init();
+
+ // do we have a Random or SecureRandom, or should we use our own?
+ Object obj = attributes.get(SOURCE_OF_RANDOMNESS);
+ if (obj instanceof Random)
+ {
+ rnd = (Random) obj;
+ }
+ else if (obj instanceof IRandom)
+ {
+ irnd = (IRandom) obj;
+ }
+ }
+
+ private PRNG getDefaultPRNG()
+ {
+ if (prng == null)
+ prng = PRNG.getInstance();
+
+ return prng;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/ISignature.java b/libjava/classpath/gnu/java/security/sig/ISignature.java
new file mode 100644
index 0000000..77653ee
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/ISignature.java
@@ -0,0 +1,169 @@
+/* ISignature.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig;
+
+import java.util.Map;
+
+/**
+ * The visible methods of every signature-with-appendix scheme.
+ *
+ * The Handbook of Applied Cryptography (HAC), by A. Menezes & al. states:
+ * "Digital signature schemes which require the message as input to the
+ * verification algorithm are called digital signature schemes with
+ * appendix. ... They rely on cryptographic hash functions rather than
+ * customised redundancy functions, and are less prone to existential forgery
+ * attacks."
+ *
+ * References:
+ *
+ * - Handbook of Applied
+ * Cryptography, Alfred J. Menezes, Paul C. van Oorschot and Scott A.
+ * Vanstone. Section 11.2.2 Digital signature schemes with appendix.
+ *
+ *
+ * @version $Revision: 1.1 $
+ */
+public interface ISignature extends Cloneable
+{
+
+ // Constants
+ // -------------------------------------------------------------------------
+
+ /** Property name of the verifier's public key. */
+ public static final String VERIFIER_KEY = "gnu.crypto.sig.public.key";
+
+ /** Property name of the signer's private key. */
+ public static final String SIGNER_KEY = "gnu.crypto.sig.private.key";
+
+ /**
+ * Property name of an optional {@link java.security.SecureRandom},
+ * {@link java.util.Random}, or {@link gnu.crypto.prng.IRandom} instance to
+ * use. The default is to use a classloader singleton from
+ * {@link gnu.crypto.util.PRNG}.
+ */
+ public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.sig.prng";
+
+ // Methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the canonical name of this signature scheme.
+ *
+ * @return the canonical name of this instance.
+ */
+ String name();
+
+ /**
+ * Initialises this instance for signature verification.
+ *
+ * @param attributes the attributes to use for setting up this instance.
+ * @throws IllegalArgumentException if the designated public key is not
+ * appropriate for this signature scheme.
+ * @see #SOURCE_OF_RANDOMNESS
+ * @see #VERIFIER_KEY
+ */
+ void setupVerify(Map attributes) throws IllegalArgumentException;
+
+ /**
+ * Initialises this instance for signature generation.
+ *
+ * @param attributes the attributes to use for setting up this instance.
+ * @throws IllegalArgumentException if the designated private key is not
+ * appropriate for this signature scheme.
+ * @see #SOURCE_OF_RANDOMNESS
+ * @see #SIGNER_KEY
+ */
+ void setupSign(Map attributes) throws IllegalArgumentException;
+
+ /**
+ * Digests one byte of a message for signing or verification purposes.
+ *
+ * @param b the message byte to digest.
+ * @throws IllegalStateException if this instance was not setup for
+ * signature generation/verification.
+ */
+ void update(byte b) throws IllegalStateException;
+
+ /**
+ * Digests a sequence of bytes from a message for signing or verification
+ * purposes.
+ *
+ * @param buffer the byte sequence to consider.
+ * @param offset the byte poisition in buffer
of the first byte
+ * to consider.
+ * @param length the number of bytes in buffer
starting from the
+ * byte at index offset
to digest.
+ * @throws IllegalStateException if this instance was not setup for
+ * signature generation/verification.
+ */
+ void update(byte[] buffer, int offset, int length)
+ throws IllegalStateException;
+
+ /**
+ * Terminates a signature generation phase by digesting and processing the
+ * context of the underlying message digest algorithm instance.
+ *
+ * @return a {@link Object} representing the native output of the signature
+ * scheme implementation.
+ * @throws IllegalStateException if this instance was not setup for
+ * signature generation.
+ */
+ Object sign() throws IllegalStateException;
+
+ /**
+ * Terminates a signature verification phase by digesting and processing
+ * the context of the underlying message digest algorithm instance.
+ *
+ * @param signature a native signature object previously generated by an
+ * invocation of the sign()
method.
+ * @return true
iff the outpout of the verification phase
+ * confirms that the designated signature object has been generated using the
+ * corresponding public key of the recepient.
+ * @throws IllegalStateException if this instance was not setup for
+ * signature verification.
+ */
+ boolean verify(Object signature) throws IllegalStateException;
+
+ /**
+ * Returns a clone copy of this instance.
+ *
+ * @return a clone copy of this instance.
+ */
+ Object clone();
+}
diff --git a/libjava/classpath/gnu/java/security/sig/ISignatureCodec.java b/libjava/classpath/gnu/java/security/sig/ISignatureCodec.java
new file mode 100644
index 0000000..119eca5
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/ISignatureCodec.java
@@ -0,0 +1,68 @@
+/* ISignatureCodec.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig;
+
+import gnu.java.security.Registry;
+
+/**
+ * The visible methods of an object that knows how to encode and decode
+ * cryptographic signatures. Codecs are useful for (a) externalising signature
+ * output data for storage and on-the-wire transmission, as well as (b) re-
+ * creating their internal Java representation from external sources.
+ *
+ * @version $Revision: 1.1 $
+ */
+public interface ISignatureCodec
+{
+
+ // Constants
+ // -------------------------------------------------------------------------
+
+ /** Constant identifying the Raw encoding format. */
+ int RAW_FORMAT = Registry.RAW_ENCODING_ID;
+
+ // Method(s)
+ // -------------------------------------------------------------------------
+
+ int getFormatID();
+
+ byte[] encodeSignature(Object signature);
+
+ Object decodeSignature(byte[] input);
+}
diff --git a/libjava/classpath/gnu/java/security/sig/SignatureCodecFactory.java b/libjava/classpath/gnu/java/security/sig/SignatureCodecFactory.java
new file mode 100644
index 0000000..c5b2ccd
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/SignatureCodecFactory.java
@@ -0,0 +1,226 @@
+/* SignatureCodecFactory.java -- Factory to instantiate Signature codecs
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig;
+
+import gnu.java.security.Registry;
+import gnu.java.security.hash.HashFactory;
+import gnu.java.security.sig.dss.DSSSignatureRawCodec;
+import gnu.java.security.sig.dss.DSSSignatureX509Codec;
+import gnu.java.security.sig.rsa.RSAPKCS1V1_5SignatureRawCodec;
+import gnu.java.security.sig.rsa.RSAPKCS1V1_5SignatureX509Codec;
+import gnu.java.security.sig.rsa.RSAPSSSignatureRawCodec;
+import gnu.java.security.util.FormatUtil;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A Factory class to instantiate Signature codecs.
+ */
+public class SignatureCodecFactory
+{
+ private static Set names;
+
+ /** Trivial constructor to enforce Singleton pattern. */
+ private SignatureCodecFactory()
+ {
+ super();
+ }
+
+ /**
+ * Returns the appropriate codec given a composed signature algorithm and an
+ * encoding format. A composed name is formed by the concatenation of the
+ * canonical signature algorithm name, the forward slash character
+ * /
and the canonical name of the encoding format.
+ *
+ * When the encoding format name is missing, the Raw encoding format is
+ * assumed. When this is the case the trailing forward slash is discarded from
+ * the name.
+ *
+ * @param name the case-insensitive, possibly composed, signature codec name.
+ * @return an instance of the signaturecodec, or null
if none
+ * found.
+ */
+ public static ISignatureCodec getInstance(String name)
+ {
+ if (name == null)
+ return null;
+
+ name = name.trim();
+ if (name.length() == 0)
+ return null;
+
+ if (name.startsWith("/"))
+ return null;
+
+ if (name.endsWith("/"))
+ return getInstance(name.substring(0, name.length() - 1),
+ Registry.RAW_ENCODING_ID);
+
+ int i = name.indexOf("/");
+ if (i == - 1)
+ return getInstance(name, Registry.RAW_ENCODING_ID);
+
+ String sigName = name.substring(0, i);
+ String formatName = name.substring(i + 1);
+ return getInstance(sigName, formatName);
+ }
+
+ /**
+ * Returns an instance of a signature codec given the canonical name of the
+ * signature algorithm, and that of the encoding format.
+ *
+ * @param name the case-insensitive signature algorithm name.
+ * @param format the name of the format to use when encodigng/decoding
+ * signatures generated by the named algorithm.
+ * @return an instance of the signature codec, or null
if none
+ * found.
+ */
+ public static ISignatureCodec getInstance(String name, String format)
+ {
+ int formatID = FormatUtil.getFormatID(format);
+ if (formatID == 0)
+ return null;
+
+ return getInstance(name, formatID);
+ }
+
+ /**
+ * Returns an instance of a signature codec given the canonical name of the
+ * signature algorithm, and the identifier of the format to use when
+ * encoding/decoding signatures generated by that algorithm.
+ *
+ * @param name the case-insensitive signature algorithm name.
+ * @param formatID the identifier of the format to use when encoding /
+ * decoding signatures generated by the designated algorithm.
+ * @return an instance of the signature codec, or null
if none
+ * found.
+ */
+ public static ISignatureCodec getInstance(String name, int formatID)
+ {
+ if (name == null)
+ return null;
+
+ name = name.trim();
+ switch (formatID)
+ {
+ case Registry.RAW_ENCODING_ID:
+ return getRawCodec(name);
+ case Registry.X509_ENCODING_ID:
+ return getX509Codec(name);
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns a {@link Set} of supported signature codec names.
+ *
+ * @return a {@link Set} of the names of supported signature codec (Strings).
+ */
+ public static synchronized final Set getNames()
+ {
+ if (names == null)
+ {
+ HashSet hs = new HashSet();
+ hs.add(Registry.DSS_SIG + "/" + Registry.RAW_ENCODING_SHORT_NAME);
+ hs.add(Registry.DSS_SIG + "/" + Registry.X509_ENCODING_SORT_NAME);
+ Set hashNames = HashFactory.getNames();
+ for (Iterator it = hashNames.iterator(); it.hasNext();)
+ {
+ String mdName = (String) it.next();
+ String name = Registry.RSA_PKCS1_V1_5_SIG + "-" + mdName;
+ hs.add(name + "/" + Registry.RAW_ENCODING_SHORT_NAME);
+ hs.add(name + "/" + Registry.X509_ENCODING_SORT_NAME);
+ name = Registry.RSA_PSS_SIG + "-" + mdName;
+ hs.add(name + "/" + Registry.RAW_ENCODING_SHORT_NAME);
+ }
+
+ names = Collections.unmodifiableSet(hs);
+ }
+
+ return names;
+ }
+
+ /**
+ * @param name the trimmed name of a signature algorithm.
+ * @return a Raw format codec for the designated signature algorithm, or
+ * null
if none exists.
+ */
+ private static ISignatureCodec getRawCodec(String name)
+ {
+ ISignatureCodec result = null;
+ if (name.equalsIgnoreCase(Registry.DSA_SIG)
+ || name.equalsIgnoreCase(Registry.DSS_SIG))
+ result = new DSSSignatureRawCodec();
+ else
+ {
+ name = name.toLowerCase();
+ if (name.startsWith(Registry.RSA_PKCS1_V1_5_SIG))
+ result = new RSAPKCS1V1_5SignatureRawCodec();
+ else if (name.startsWith(Registry.RSA_PSS_SIG))
+ result = new RSAPSSSignatureRawCodec();
+ }
+
+ return result;
+ }
+
+ /**
+ * @param name the trimmed name of a signature algorithm.
+ * @return a X.509 format codec for the designated signature algorithm, or
+ * null
if none exists.
+ */
+ private static ISignatureCodec getX509Codec(String name)
+ {
+ ISignatureCodec result = null;
+ if (name.equalsIgnoreCase(Registry.DSA_SIG)
+ || name.equalsIgnoreCase(Registry.DSS_SIG))
+ result = new DSSSignatureX509Codec();
+ else
+ {
+ name = name.toLowerCase();
+ if (name.startsWith(Registry.RSA_PKCS1_V1_5_SIG))
+ result = new RSAPKCS1V1_5SignatureX509Codec();
+ }
+
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/SignatureFactory.java b/libjava/classpath/gnu/java/security/sig/SignatureFactory.java
new file mode 100644
index 0000000..d5bd728
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/SignatureFactory.java
@@ -0,0 +1,113 @@
+/* SignatureFactory.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig;
+
+import gnu.java.security.Registry;
+import gnu.java.security.sig.dss.DSSSignature;
+import gnu.java.security.sig.rsa.RSASignatureFactory;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A Factory to instantiate signature-with-appendix handlers.
+ */
+public class SignatureFactory
+{
+ private static Set names;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Trivial constructor to enforce Singleton pattern. */
+ private SignatureFactory()
+ {
+ super();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns an instance of a signature-with-appendix scheme given its name.
+ *
+ * @param ssa the case-insensitive signature-with-appendix scheme name.
+ * @return an instance of the scheme, or null
if none found.
+ */
+ public static final ISignature getInstance(String ssa)
+ {
+ if (ssa == null)
+ {
+ return null;
+ }
+
+ ssa = ssa.trim();
+ ssa = ssa.toLowerCase();
+ ISignature result = null;
+ if (ssa.equalsIgnoreCase(Registry.DSA_SIG) || ssa.equals(Registry.DSS_SIG))
+ {
+ result = new DSSSignature();
+ }
+ else if (ssa.startsWith(Registry.RSA_SIG_PREFIX))
+ result = RSASignatureFactory.getInstance(ssa);
+
+ return result;
+ }
+
+ /**
+ * Returns a {@link Set} of signature-with-appendix scheme names supported
+ * by this Factory.
+ *
+ * @return a {@link Set} of signature-with-appendix scheme names (Strings).
+ */
+ public static synchronized final Set getNames()
+ {
+ if (names == null)
+ {
+ HashSet hs = new HashSet();
+ hs.add(Registry.DSS_SIG);
+ hs.addAll(RSASignatureFactory.getNames());
+
+ names = Collections.unmodifiableSet(hs);
+ }
+
+ return names;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/dss/DSSSignature.java b/libjava/classpath/gnu/java/security/sig/dss/DSSSignature.java
new file mode 100644
index 0000000..6bedfae
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/dss/DSSSignature.java
@@ -0,0 +1,347 @@
+/* DSSSignature.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.dss;
+
+import gnu.java.security.Registry;
+import gnu.java.security.hash.IMessageDigest;
+import gnu.java.security.hash.Sha160;
+import gnu.java.security.prng.IRandom;
+import gnu.java.security.sig.BaseSignature;
+import gnu.java.security.sig.ISignature;
+
+import java.math.BigInteger;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.interfaces.DSAPrivateKey;
+import java.security.interfaces.DSAPublicKey;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ *
The DSS (Digital Signature Standard) algorithm makes use of the following
+ * parameters:
+ *
+ *
+ * - p: A prime modulus, where
2L-1 < p < 2L
+ *
for 512 <= L <= 1024
and L
a
+ * multiple of 64
.
+ * - q: A prime divisor of
p - 1
, where 2159
+ * < q < 2160
.
+ * - g: Where
g = h(p-1)/q mod p
, where
+ * h
is any integer with 1 < h < p - 1
such
+ * that h (p-1)/q mod p > 1
(g
has order
+ * q mod p
).
+ * - x: A randomly or pseudorandomly generated integer with
0 < x
+ * < q
.
+ * - y:
y = gx mod p
.
+ * - k: A randomly or pseudorandomly generated integer with
0 < k
+ * < q
.
+ *
+ *
+ * The integers p
, q
, and g
can be
+ * public and can be common to a group of users. A user's private and public
+ * keys are x
and y
, respectively. They are normally
+ * fixed for a period of time. Parameters x
and k
are
+ * used for signature generation only, and must be kept secret. Parameter
+ * k
must be regenerated for each signature.
+ *
+ * The signature of a message M
is the pair of numbers r
+ * and s
computed according to the equations below:
+ *
+ *
+ * r = (gk mod p) mod q
and
+ * s = (k-1(SHA(M) + xr)) mod q
.
+ *
+ *
+ * In the above, k-1
is the multiplicative inverse of
+ * k
, mod q
; i.e., (k-1 k) mod q = 1
+ *
and 0 < k-1 < q
. The value of SHA(M)
+ * is a 160-bit string output by the Secure Hash Algorithm specified in FIPS 180.
+ * For use in computing s
, this string must be converted to an
+ * integer.
+ *
+ * As an option, one may wish to check if r == 0
or s == 0
+ *
. If either r == 0
or s == 0
, a new value
+ * of k
should be generated and the signature should be
+ * recalculated (it is extremely unlikely that r == 0
or s ==
+ * 0
if signatures are generated properly).
+ *
+ * The signature is transmitted along with the message to the verifier.
+ *
+ * References:
+ *
+ * - Digital
+ * Signature Standard (DSS), Federal Information Processing Standards
+ * Publication 186. National Institute of Standards and Technology.
+ *
+ *
+ * @version $Revision: 1.1 $
+ */
+public class DSSSignature extends BaseSignature
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Trivial 0-arguments constructor. */
+ public DSSSignature()
+ {
+ super(Registry.DSS_SIG, new Sha160());
+ }
+
+ /** Private constructor for cloning purposes. */
+ private DSSSignature(DSSSignature that)
+ {
+ this();
+
+ this.publicKey = that.publicKey;
+ this.privateKey = that.privateKey;
+ this.md = (IMessageDigest) that.md.clone();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ public static final BigInteger[] sign(final DSAPrivateKey k, final byte[] h)
+ {
+ final DSSSignature sig = new DSSSignature();
+ final Map attributes = new HashMap();
+ attributes.put(ISignature.SIGNER_KEY, k);
+ sig.setupSign(attributes);
+
+ return sig.computeRS(h);
+ }
+
+ public static final BigInteger[] sign(final DSAPrivateKey k, final byte[] h,
+ Random rnd)
+ {
+ final DSSSignature sig = new DSSSignature();
+ final Map attributes = new HashMap();
+ attributes.put(ISignature.SIGNER_KEY, k);
+ if (rnd != null)
+ {
+ attributes.put(ISignature.SOURCE_OF_RANDOMNESS, rnd);
+ }
+ sig.setupSign(attributes);
+
+ return sig.computeRS(h);
+ }
+
+ public static final BigInteger[] sign(final DSAPrivateKey k, final byte[] h,
+ IRandom irnd)
+ {
+ final DSSSignature sig = new DSSSignature();
+ final Map attributes = new HashMap();
+ attributes.put(ISignature.SIGNER_KEY, k);
+ if (irnd != null)
+ {
+ attributes.put(ISignature.SOURCE_OF_RANDOMNESS, irnd);
+ }
+ sig.setupSign(attributes);
+
+ return sig.computeRS(h);
+ }
+
+ public static final boolean verify(final DSAPublicKey k, final byte[] h,
+ final BigInteger[] rs)
+ {
+ final DSSSignature sig = new DSSSignature();
+ final Map attributes = new HashMap();
+ attributes.put(ISignature.VERIFIER_KEY, k);
+ sig.setupVerify(attributes);
+
+ return sig.checkRS(rs, h);
+ }
+
+ // Implementation of abstract methods in superclass
+ // -------------------------------------------------------------------------
+
+ public Object clone()
+ {
+ return new DSSSignature(this);
+ }
+
+ protected void setupForVerification(PublicKey k)
+ throws IllegalArgumentException
+ {
+ if (!(k instanceof DSAPublicKey))
+ {
+ throw new IllegalArgumentException();
+ }
+ this.publicKey = k;
+ }
+
+ protected void setupForSigning(PrivateKey k) throws IllegalArgumentException
+ {
+ if (!(k instanceof DSAPrivateKey))
+ {
+ throw new IllegalArgumentException();
+ }
+ this.privateKey = k;
+ }
+
+ protected Object generateSignature() throws IllegalStateException
+ {
+ // BigInteger p = ((DSAPrivateKey) privateKey).getParams().getP();
+ // BigInteger q = ((DSAPrivateKey) privateKey).getParams().getQ();
+ // BigInteger g = ((DSAPrivateKey) privateKey).getParams().getG();
+ // BigInteger x = ((DSAPrivateKey) privateKey).getX();
+ // BigInteger m = new BigInteger(1, md.digest());
+ // BigInteger k, r, s;
+ //
+ // byte[] kb = new byte[20]; // we'll use 159 bits only
+ // while (true) {
+ // this.nextRandomBytes(kb);
+ // k = new BigInteger(1, kb);
+ // k.clearBit(159);
+ // r = g.modPow(k, p).mod(q);
+ // if (r.equals(BigInteger.ZERO)) {
+ // continue;
+ // }
+ // s = m.add(x.multiply(r)).multiply(k.modInverse(q)).mod(q);
+ // if (s.equals(BigInteger.ZERO)) {
+ // continue;
+ // }
+ // break;
+ // }
+ final BigInteger[] rs = computeRS(md.digest());
+
+ // return encodeSignature(r, s);
+ return encodeSignature(rs[0], rs[1]);
+ }
+
+ protected boolean verifySignature(Object sig) throws IllegalStateException
+ {
+ final BigInteger[] rs = decodeSignature(sig);
+ // BigInteger r = rs[0];
+ // BigInteger s = rs[1];
+ //
+ // BigInteger g = ((DSAPublicKey) publicKey).getParams().getG();
+ // BigInteger p = ((DSAPublicKey) publicKey).getParams().getP();
+ // BigInteger q = ((DSAPublicKey) publicKey).getParams().getQ();
+ // BigInteger y = ((DSAPublicKey) publicKey).getY();
+ // BigInteger w = s.modInverse(q);
+ //
+ // byte bytes[] = md.digest();
+ // BigInteger u1 = w.multiply(new BigInteger(1, bytes)).mod(q);
+ // BigInteger u2 = r.multiply(w).mod(q);
+ //
+ // BigInteger v = g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q);
+ // return v.equals(r);
+ return checkRS(rs, md.digest());
+ }
+
+ // Other instance methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the output of a signature generation phase.
+ *
+ * @return an object encapsulating the DSS signature pair r
and
+ * s
.
+ */
+ private Object encodeSignature(BigInteger r, BigInteger s)
+ {
+ return new BigInteger[] { r, s };
+ }
+
+ /**
+ * Returns the output of a previously generated signature object as a pair
+ * of {@link java.math.BigInteger}.
+ *
+ * @return the DSS signature pair r
and s
.
+ */
+ private BigInteger[] decodeSignature(Object signature)
+ {
+ return (BigInteger[]) signature;
+ }
+
+ private BigInteger[] computeRS(final byte[] digestBytes)
+ {
+ final BigInteger p = ((DSAPrivateKey) privateKey).getParams().getP();
+ final BigInteger q = ((DSAPrivateKey) privateKey).getParams().getQ();
+ final BigInteger g = ((DSAPrivateKey) privateKey).getParams().getG();
+ final BigInteger x = ((DSAPrivateKey) privateKey).getX();
+ final BigInteger m = new BigInteger(1, digestBytes);
+ BigInteger k, r, s;
+
+ final byte[] kb = new byte[20]; // we'll use 159 bits only
+ while (true)
+ {
+ this.nextRandomBytes(kb);
+ k = new BigInteger(1, kb);
+ k.clearBit(159);
+ r = g.modPow(k, p).mod(q);
+ if (r.equals(BigInteger.ZERO))
+ {
+ continue;
+ }
+ s = m.add(x.multiply(r)).multiply(k.modInverse(q)).mod(q);
+ if (s.equals(BigInteger.ZERO))
+ {
+ continue;
+ }
+ break;
+ }
+
+ return new BigInteger[] { r, s };
+ }
+
+ private boolean checkRS(final BigInteger[] rs, final byte[] digestBytes)
+ {
+ final BigInteger r = rs[0];
+ final BigInteger s = rs[1];
+
+ final BigInteger g = ((DSAPublicKey) publicKey).getParams().getG();
+ final BigInteger p = ((DSAPublicKey) publicKey).getParams().getP();
+ final BigInteger q = ((DSAPublicKey) publicKey).getParams().getQ();
+ final BigInteger y = ((DSAPublicKey) publicKey).getY();
+ final BigInteger w = s.modInverse(q);
+
+ final BigInteger u1 = w.multiply(new BigInteger(1, digestBytes)).mod(q);
+ final BigInteger u2 = r.multiply(w).mod(q);
+
+ final BigInteger v = g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q);
+ return v.equals(r);
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/dss/DSSSignatureRawCodec.java b/libjava/classpath/gnu/java/security/sig/dss/DSSSignatureRawCodec.java
new file mode 100644
index 0000000..02f6b1d
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/dss/DSSSignatureRawCodec.java
@@ -0,0 +1,191 @@
+/* DSSSignatureRawCodec.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.dss;
+
+import gnu.java.security.Registry;
+import gnu.java.security.sig.ISignatureCodec;
+
+import java.io.ByteArrayOutputStream;
+import java.math.BigInteger;
+
+/**
+ *
An object that implements the {@link ISignatureCodec} operations for the
+ * Raw format to use with DSS signatures.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class DSSSignatureRawCodec implements ISignatureCodec
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ // implicit 0-arguments constructor
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // gnu.crypto.sig.ISignatureCodec interface implementation -----------------
+
+ public int getFormatID()
+ {
+ return RAW_FORMAT;
+ }
+
+ /**
+ * Returns the encoded form of the designated DSS (Digital Signature
+ * Standard) signature object according to the Raw format supported by
+ * this library.
+ *
+ * The Raw format for a DSA signature, in this implementation, is a
+ * byte sequence consisting of the following:
+ *
+ *
+ * - 4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_DSS_SIGNATURE},
+ * - 1-byte version consisting of the constant: 0x01,
+ * - 4-byte count of following bytes representing the DSS parameter
+ *
r
in internet order,
+ * - n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the
toByteArray()
method on the DSS parameter r
,
+ * - 4-byte count of following bytes representing the DSS parameter
+ *
s
,
+ * - n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the
toByteArray()
method on the DSS parameter s
.
+ *
+ *
+ * @param signature the signature to encode, consisting of the two DSS
+ * parameters r
and s
as a {@link java.math.BigInteger}
+ * array.
+ * @return the Raw format encoding of the designated signature.
+ * @exception IllegalArgumentException if the designated signature is not a
+ * DSS (Digital Signature Standard) one.
+ */
+ public byte[] encodeSignature(Object signature)
+ {
+ BigInteger r, s;
+ try
+ {
+ BigInteger[] sig = (BigInteger[]) signature;
+ r = sig[0];
+ s = sig[1];
+ }
+ catch (Exception x)
+ {
+ throw new IllegalArgumentException("key");
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ // magic
+ baos.write(Registry.MAGIC_RAW_DSS_SIGNATURE[0]);
+ baos.write(Registry.MAGIC_RAW_DSS_SIGNATURE[1]);
+ baos.write(Registry.MAGIC_RAW_DSS_SIGNATURE[2]);
+ baos.write(Registry.MAGIC_RAW_DSS_SIGNATURE[3]);
+
+ // version
+ baos.write(0x01);
+
+ // r
+ byte[] buffer = r.toByteArray();
+ int length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ // s
+ buffer = s.toByteArray();
+ length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ return baos.toByteArray();
+ }
+
+ public Object decodeSignature(byte[] k)
+ {
+ // magic
+ if (k[0] != Registry.MAGIC_RAW_DSS_SIGNATURE[0]
+ || k[1] != Registry.MAGIC_RAW_DSS_SIGNATURE[1]
+ || k[2] != Registry.MAGIC_RAW_DSS_SIGNATURE[2]
+ || k[3] != Registry.MAGIC_RAW_DSS_SIGNATURE[3])
+ {
+ throw new IllegalArgumentException("magic");
+ }
+
+ // version
+ if (k[4] != 0x01)
+ {
+ throw new IllegalArgumentException("version");
+ }
+
+ int i = 5;
+ int l;
+ byte[] buffer;
+
+ // r
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ buffer = new byte[l];
+ System.arraycopy(k, i, buffer, 0, l);
+ i += l;
+ BigInteger r = new BigInteger(1, buffer);
+
+ // s
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ buffer = new byte[l];
+ System.arraycopy(k, i, buffer, 0, l);
+ i += l;
+ BigInteger s = new BigInteger(1, buffer);
+
+ return new BigInteger[] { r, s };
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/dss/DSSSignatureX509Codec.java b/libjava/classpath/gnu/java/security/sig/dss/DSSSignatureX509Codec.java
new file mode 100644
index 0000000..0fdb754
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/dss/DSSSignatureX509Codec.java
@@ -0,0 +1,193 @@
+/* DSSSignatureX509Codec.java -- X.509 encoder/decoder for DSS signatures
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.dss;
+
+import gnu.java.security.Registry;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+import gnu.java.security.der.DERWriter;
+import gnu.java.security.sig.ISignatureCodec;
+import gnu.java.security.util.DerUtil;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.InvalidParameterException;
+import java.util.ArrayList;
+
+/**
+ * An implementation of an {@link ISignatureCodec} that knows to encode and
+ * decode DSS signatures into the raw bytes which would constitute a DER-encoded
+ * form of the ASN.1 structure defined in RFC-2459, and RFC-2313 as described in
+ * the next paragraphs.
+ *
+ * Digital signatures when transmitted in an X.509 certificates are encoded
+ * in DER (Distinguished Encoding Rules) as a BIT STRING; i.e.
+ *
+ *
+ * Certificate ::= SEQUENCE {
+ * tbsCertificate TBSCertificate,
+ * signatureAlgorithm AlgorithmIdentifier,
+ * signature BIT STRING
+ * }
+ *
+ *
+ * The output of the encoder, and the input of the decoder, of this codec are
+ * then the raw bytes of such a BIT STRING; i.e. not the DER-encoded
+ * form itself.
+ *
+ * RFC-2459 states that, for the Digital Signature Standard (DSS), which
+ * generates two MPIs, commonly called r
and s
, as the
+ * result of digitally signing a message, these two numbers will be transferred
+ * as the following ASN.1 structure:
+ *
+ *
+ * Dss-Sig-Value ::= SEQUENCE {
+ * r INTEGER,
+ * s INTEGER
+ * }
+ *
+ *
+ * Client code that needs to build a DER BIT STRING MUST construct such
+ * an ASN.1 value. The following is an example of how to do this:
+ *
+ *
+ * ...
+ * import gnu.java.security.der.BitString;
+ * import gnu.java.security.der.DER;
+ * import gnu.java.security.der.DERValue;
+ * ...
+ * DERValue bitString = new DERValue(DER.BIT_STRING, new BitString(sigBytes));
+ * ...
+ *
+ */
+public class DSSSignatureX509Codec
+ implements ISignatureCodec
+{
+ // implicit 0-arguments constructor
+
+ public int getFormatID()
+ {
+ return Registry.X509_ENCODING_ID;
+ }
+
+ /**
+ * Encodes a DSS Signature output as the signature raw bytes which can
+ * be used to construct an ASN.1 DER-encoded BIT STRING as defined in the
+ * documentation of this class.
+ *
+ * @param signature the output of the DSS signature algorithm; i.e. the value
+ * returned by the invocation of
+ * {@link gnu.java.security.sig.ISignature#sign()} method. In the
+ * case of a DSS signature this is an array of two MPIs called
+ * r
and s
.
+ * @return the raw bytes of a DSS signature which could be then used as the
+ * contents of a BIT STRING as per rfc-2459.
+ * @throws InvalidParameterException if an exception occurs during the
+ * marshalling process.
+ */
+ public byte[] encodeSignature(Object signature)
+ {
+ BigInteger[] rs = (BigInteger[]) signature;
+
+ DERValue derR = new DERValue(DER.INTEGER, rs[0]);
+ DERValue derS = new DERValue(DER.INTEGER, rs[1]);
+
+ ArrayList dssSigValue = new ArrayList(2);
+ dssSigValue.add(derR);
+ dssSigValue.add(derS);
+ DERValue derDssSigValue = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,
+ dssSigValue);
+ byte[] result;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try
+ {
+ DERWriter.write(baos, derDssSigValue);
+ result = baos.toByteArray();
+ }
+ catch (IOException x)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(x);
+ throw y;
+ }
+
+ return result;
+ }
+
+ /**
+ * Decodes a signature as defined in the documentation of this class.
+ *
+ * @param input the byte array to unmarshall into a valid DSS signature
+ * instance; i.e. an array of two MPIs. MUST NOT be null.
+ * @return an array of two MPIs, r
and s
in this
+ * order, decoded from the designated input
.
+ * @throw InvalidParameterException if an exception occurs during the
+ * unmarshalling process.
+ */
+ public Object decodeSignature(byte[] input)
+ {
+ if (input == null)
+ throw new InvalidParameterException("Input bytes MUST NOT be null");
+
+ BigInteger r, s;
+ DERReader der = new DERReader(input);
+ try
+ {
+ DERValue derDssSigValue = der.read();
+ DerUtil.checkIsConstructed(derDssSigValue, "Wrong Dss-Sig-Value field");
+
+ DERValue val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong R field");
+ r = (BigInteger) val.getValue();
+ val = der.read();
+ DerUtil.checkIsBigInteger(val, "Wrong S field");
+ s = (BigInteger) val.getValue();
+ }
+ catch (IOException x)
+ {
+ InvalidParameterException y = new InvalidParameterException();
+ y.initCause(x);
+ throw y;
+ }
+
+ return new BigInteger[] { r, s };
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java b/libjava/classpath/gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java
new file mode 100644
index 0000000..efe580d
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java
@@ -0,0 +1,306 @@
+/* EME_PKCS1_V1_5.java --
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import gnu.java.security.prng.IRandom;
+import gnu.java.security.prng.LimitReachedException;
+import gnu.java.security.util.PRNG;
+
+import java.io.ByteArrayOutputStream;
+import java.security.interfaces.RSAKey;
+import java.util.Random;
+
+/**
+ * An implementation of the EME-PKCS1-V1.5 encoding and decoding methods.
+ *
+ * EME-PKCS1-V1.5 is parameterised by the entity k
which is the
+ * byte count of an RSA public shared modulus.
+ *
+ * References:
+ *
+ * - Public-Key Cryptography
+ * Standards (PKCS) #1:
+ * RSA Cryptography Specifications Version 2.1.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ */
+public class EME_PKCS1_V1_5
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ private int k;
+
+ private ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ /** Our default source of randomness. */
+ private PRNG prng = PRNG.getInstance();
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ private EME_PKCS1_V1_5(final int k)
+ {
+ super();
+
+ this.k = k;
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ public static final EME_PKCS1_V1_5 getInstance(final int k)
+ {
+ if (k < 0)
+ {
+ throw new IllegalArgumentException("k must be a positive integer");
+ }
+ return new EME_PKCS1_V1_5(k);
+ }
+
+ public static final EME_PKCS1_V1_5 getInstance(final RSAKey key)
+ {
+ final int modBits = key.getModulus().bitLength();
+ final int k = (modBits + 7) / 8;
+ return EME_PKCS1_V1_5.getInstance(k);
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Generates an octet string PS
of length k - mLen -
+ * 3
consisting of pseudo-randomly generated nonzero octets. The
+ * length of PS
will be at least eight octets.
+ *
+ * The method then concatenates PS
, the message M
,
+ * and other padding to form an encoded message EM
of length
+ * k
octets as:
+ *
+ *
+ * EM = 0x00 || 0x02 || PS || 0x00 || M.
+ *
+ *
+ * This method uses a default PRNG to obtain the padding bytes.
+ *
+ * @param M the message to encode.
+ * @return the encoded message EM
.
+ */
+ public byte[] encode(final byte[] M)
+ {
+ // a. Generate an octet string PS of length k - mLen - 3 consisting
+ // of pseudo-randomly generated nonzero octets. The length of PS
+ // will be at least eight octets.
+ final byte[] PS = new byte[k - M.length - 3];
+
+ // FIXME. This should be configurable, somehow.
+ prng.nextBytes(PS);
+ int i = 0;
+ for (; i < PS.length; i++)
+ {
+ if (PS[i] == 0)
+ PS[i] = 1;
+ }
+ // b. Concatenate PS, the message M, and other padding to form an
+ // encoded message EM of length k octets as
+ //
+ // EM = 0x00 || 0x02 || PS || 0x00 || M.
+ return assembleEM(PS, M);
+ }
+
+ /**
+ * Similar to {@link #encode(byte[])} method, except that the source of
+ * randomness to use for obtaining the padding bytes (an instance of
+ * {@link IRandom}) is given as a parameter.
+ *
+ * @param M the message to encode.
+ * @param irnd the {@link IRandom} instance to use as a source of randomness.
+ * @return the encoded message EM
.
+ */
+ public byte[] encode(final byte[] M, final IRandom irnd)
+ {
+ final byte[] PS = new byte[k - M.length - 3];
+ try
+ {
+ irnd.nextBytes(PS, 0, PS.length);
+ int i = 0;
+ outer: while (true)
+ {
+ for (; i < PS.length; i++)
+ {
+ if (PS[i] == 0x00)
+ {
+ System.arraycopy(PS, i + 1, PS, i, PS.length - i - 1);
+ irnd.nextBytes(PS, PS.length - 1, 1);
+ continue outer;
+ }
+ }
+ break;
+ }
+ }
+ catch (IllegalStateException x)
+ {
+ throw new RuntimeException("encode(): " + String.valueOf(x));
+ }
+ catch (LimitReachedException x)
+ {
+ throw new RuntimeException("encode(): " + String.valueOf(x));
+ }
+
+ return assembleEM(PS, M);
+ }
+
+ /**
+ * Similar to the {@link #encode(byte[], IRandom)} method, except that
+ * the source of randmoness is an instance of {@link Random}.
+ *
+ * @param M the message to encode.
+ * @param rnd the {@link Random} instance to use as a source of randomness.
+ * @return the encoded message EM
.
+ */
+ public byte[] encode(final byte[] M, final Random rnd)
+ {
+ final byte[] PS = new byte[k - M.length - 3];
+ rnd.nextBytes(PS);
+ int i = 0;
+ outer: while (true)
+ {
+ for (; i < PS.length; i++)
+ {
+ if (PS[i] == 0x00)
+ {
+ System.arraycopy(PS, i + 1, PS, i, PS.length - i - 1);
+ PS[PS.length - 1] = (byte) rnd.nextInt();
+ continue outer;
+ }
+ }
+ break;
+ }
+
+ return assembleEM(PS, M);
+ }
+
+ /**
+ *
Separate the encoded message EM
into an octet string
+ * PS
consisting of nonzero octets and a message M
+ * as:
+ *
+ *
+ * EM = 0x00 || 0x02 || PS || 0x00 || M.
+ *
+ *
+ * If the first octet of EM
does not have hexadecimal value
+ * 0x00
, if the second octet of EM
does not have
+ * hexadecimal value 0x02
, if there is no octet with hexadecimal
+ * value 0x00
to separate PS
from M
,
+ * or if the length of PS
is less than 8
octets,
+ * output "decryption error" and stop.
+
+ * @param EM the designated encoded message.
+ * @return the decoded message M
framed in the designated
+ * EM
value.
+ * @throws IllegalArgumentException if the length of the designated entity
+ * EM
is different than k
(the length in bytes of
+ * the public shared modulus), or if any of the conditions described above
+ * is detected.
+ */
+ public byte[] decode(final byte[] EM)
+ {
+ // Separate the encoded message EM into an
+ // octet string PS consisting of nonzero octets and a message M as
+ //
+ // EM = 0x00 || 0x02 || PS || 0x00 || M.
+ //
+ // If the first octet of EM does not have hexadecimal value 0x00, if
+ // the second octet of EM does not have hexadecimal value 0x02, if
+ // there is no octet with hexadecimal value 0x00 to separate PS from
+ // M, or if the length of PS is less than 8 octets, output
+ // "decryption error" and stop. (See the note below.)
+ final int emLen = EM.length;
+ if (emLen != k)
+ {
+ throw new IllegalArgumentException("decryption error");
+ }
+ if (EM[0] != 0x00)
+ {
+ throw new IllegalArgumentException("decryption error");
+ }
+ if (EM[1] != 0x02)
+ {
+ throw new IllegalArgumentException("decryption error");
+ }
+ int i = 2;
+ for (; i < emLen; i++)
+ {
+ if (EM[i] == 0x00)
+ {
+ break;
+ }
+ }
+ if (i >= emLen || i < 11)
+ {
+ throw new IllegalArgumentException("decryption error");
+ }
+ i++;
+ final byte[] result = new byte[emLen - i];
+ System.arraycopy(EM, i, result, 0, result.length);
+ return result;
+ }
+
+ // helper methods ----------------------------------------------------------
+
+ private byte[] assembleEM(final byte[] PS, final byte[] M)
+ {
+ // b. Concatenate PS, the message M, and other padding to form an
+ // encoded message EM of length k octets as
+ //
+ // EM = 0x00 || 0x02 || PS || 0x00 || M.
+ baos.reset();
+ baos.write(0x00);
+ baos.write(0x02);
+ baos.write(PS, 0, PS.length);
+ baos.write(0x00);
+ baos.write(M, 0, M.length);
+ final byte[] result = baos.toByteArray();
+ baos.reset();
+
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java b/libjava/classpath/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java
new file mode 100644
index 0000000..2ea8a30
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java
@@ -0,0 +1,299 @@
+/* EMSA_PKCS1_V1_5.java --
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.hash.HashFactory;
+import gnu.java.security.hash.IMessageDigest;
+
+import java.io.ByteArrayOutputStream;
+
+/**
+ * An implementation of the EMSA-PKCS1-V1.5 encoding scheme.
+ *
+ * EMSA-PKCS1-V1.5 is parameterised by the choice of hash function Hash and
+ * hLen which denotes the length in octets of the hash function output.
+ *
+ * References:
+ *
+ * - Public-Key Cryptography
+ * Standards (PKCS) #1:
+ * RSA Cryptography Specifications Version 2.1.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ *
+ * @version $Revision: 1.2 $
+ */
+public class EMSA_PKCS1_V1_5 implements Cloneable
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /* Notes.
+ 1. For the six hash functions mentioned in Appendix B.1, the DER encoding
+ T of the DigestInfo value is equal to the following:
+
+ MD2: (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 02 05 00 04 10 || H
+ MD5: (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 05 05 00 04 10 || H
+ SHA-1: (0x)30 21 30 09 06 05 2b 0e 03 02 1a 05 00 04 14 || H
+ SHA-256: (0x)30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00 04 20 || H
+ SHA-384: (0x)30 41 30 0d 06 09 60 86 48 01 65 03 04 02 02 05 00 04 30 || H
+ SHA-512: (0x)30 51 30 0d 06 09 60 86 48 01 65 03 04 02 03 05 00 04 40 || H
+ */
+ private static final byte[] MD2_PREFIX = { (byte) 0x30, (byte) 0x20,
+ (byte) 0x30, (byte) 0x0c,
+ (byte) 0x06, (byte) 0x08,
+ (byte) 0x2a, (byte) 0x86,
+ (byte) 0x48, (byte) 0x86,
+ (byte) 0xf7, (byte) 0x0d,
+ (byte) 0x02, (byte) 0x02,
+ (byte) 0x05, (byte) 0x00,
+ (byte) 0x04, (byte) 0x10 };
+
+ private static final byte[] MD5_PREFIX = { (byte) 0x30, (byte) 0x20,
+ (byte) 0x30, (byte) 0x0c,
+ (byte) 0x06, (byte) 0x08,
+ (byte) 0x2a, (byte) 0x86,
+ (byte) 0x48, (byte) 0x86,
+ (byte) 0xf7, (byte) 0x0d,
+ (byte) 0x02, (byte) 0x05,
+ (byte) 0x05, (byte) 0x00,
+ (byte) 0x04, (byte) 0x10 };
+
+ private static final byte[] SHA160_PREFIX = { (byte) 0x30, (byte) 0x21,
+ (byte) 0x30, (byte) 0x09,
+ (byte) 0x06, (byte) 0x05,
+ (byte) 0x2b, (byte) 0x0e,
+ (byte) 0x03, (byte) 0x02,
+ (byte) 0x1a, (byte) 0x05,
+ (byte) 0x00, (byte) 0x04,
+ (byte) 0x14 };
+
+ private static final byte[] SHA256_PREFIX = { (byte) 0x30, (byte) 0x31,
+ (byte) 0x30, (byte) 0x0d,
+ (byte) 0x06, (byte) 0x09,
+ (byte) 0x60, (byte) 0x86,
+ (byte) 0x48, (byte) 0x01,
+ (byte) 0x65, (byte) 0x03,
+ (byte) 0x04, (byte) 0x02,
+ (byte) 0x01, (byte) 0x05,
+ (byte) 0x00, (byte) 0x04,
+ (byte) 0x20 };
+
+ private static final byte[] SHA384_PREFIX = { (byte) 0x30, (byte) 0x41,
+ (byte) 0x30, (byte) 0x0d,
+ (byte) 0x06, (byte) 0x09,
+ (byte) 0x60, (byte) 0x86,
+ (byte) 0x48, (byte) 0x01,
+ (byte) 0x65, (byte) 0x03,
+ (byte) 0x04, (byte) 0x02,
+ (byte) 0x02, (byte) 0x05,
+ (byte) 0x00, (byte) 0x04,
+ (byte) 0x30 };
+
+ private static final byte[] SHA512_PREFIX = { (byte) 0x30, (byte) 0x51,
+ (byte) 0x30, (byte) 0x0d,
+ (byte) 0x06, (byte) 0x09,
+ (byte) 0x60, (byte) 0x86,
+ (byte) 0x48, (byte) 0x01,
+ (byte) 0x65, (byte) 0x03,
+ (byte) 0x04, (byte) 0x02,
+ (byte) 0x03, (byte) 0x05,
+ (byte) 0x00, (byte) 0x04,
+ (byte) 0x40 };
+
+ /** The underlying hash function to use with this instance. */
+ private IMessageDigest hash;
+
+ /** The output size of the hash function in octets. */
+ private int hLen; // TODO: field not used!!! investigate
+
+ /** The DER part of DigestInfo not containing the hash value itself. */
+ private byte[] prefix;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Trivial private constructor to enforce use through Factory method.
+ *
+ * @param hash the message digest instance to use with this scheme instance.
+ */
+ private EMSA_PKCS1_V1_5(final IMessageDigest hash)
+ {
+ super();
+
+ this.hash = hash;
+ hLen = hash.hashSize();
+ final String name = hash.name();
+ if (name.equals(Registry.MD2_HASH))
+ {
+ prefix = MD2_PREFIX;
+ }
+ else if (name.equals(Registry.MD5_HASH))
+ {
+ prefix = MD5_PREFIX;
+ }
+ else if (name.equals(Registry.SHA160_HASH))
+ {
+ prefix = SHA160_PREFIX;
+ }
+ else if (name.equals(Registry.SHA256_HASH))
+ {
+ prefix = SHA256_PREFIX;
+ }
+ else if (name.equals(Registry.SHA384_HASH))
+ {
+ prefix = SHA384_PREFIX;
+ }
+ else if (name.equals(Registry.SHA512_HASH))
+ {
+ prefix = SHA512_PREFIX;
+ }
+ else
+ {
+ throw new UnsupportedOperationException(); // should not happen
+ }
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns an instance of this object given a designated name of a hash
+ * function.
+ *
+ * @param mdName the canonical name of a hash function.
+ * @return an instance of this object configured for use with the designated
+ * options.
+ * @throws UnsupportedOperationException if the hash function is not
+ * implemented or does not have an ID listed in RFC-3447.
+ */
+ public static final EMSA_PKCS1_V1_5 getInstance(final String mdName)
+ {
+ final IMessageDigest hash = HashFactory.getInstance(mdName);
+ final String name = hash.name();
+ if (!(name.equals(Registry.MD2_HASH) || name.equals(Registry.MD5_HASH)
+ || name.equals(Registry.SHA160_HASH)
+ || name.equals(Registry.SHA256_HASH)
+ || name.equals(Registry.SHA384_HASH) || name.equals(Registry.SHA512_HASH)))
+ {
+ throw new UnsupportedOperationException("hash with no OID: " + name);
+ }
+ return new EMSA_PKCS1_V1_5(hash);
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // Cloneable interface implementation --------------------------------------
+
+ public Object clone()
+ {
+ return getInstance(hash.name());
+ }
+
+ // own methods -------------------------------------------------------------
+
+ /**
+ * Frames the hash of a message, along with an ID of the hash function in
+ * a DER sequence according to the specifications of EMSA-PKCS1-V1.5 as
+ * described in RFC-3447 (see class documentation).
+ *
+ * @param mHash the byte sequence resulting from applying the message digest
+ * algorithm Hash to the message M.
+ * @param emLen intended length in octets of the encoded message, at least
+ * tLen + 11
, where tLen
is the octet length of the
+ * DER encoding T
of a certain value computed during the
+ * encoding operation.
+ * @return encoded message, an octet string of length emLen
.
+ * @throws IllegalArgumentException if the message is too long, or if the
+ * intended encoded message length is too short.
+ */
+ public byte[] encode(final byte[] mHash, final int emLen)
+ {
+ // 1. Apply the hash function to the message M to produce a hash value
+ // H: H = Hash(M).
+ // If the hash function outputs "message too long," output "message
+ // too long" and stop.
+ // 2. Encode the algorithm ID for the hash function and the hash value
+ // into an ASN.1 value of type DigestInfo (see Appendix A.2.4) with
+ // the Distinguished Encoding Rules (DER), where the type DigestInfo
+ // has the syntax
+ // DigestInfo ::= SEQUENCE {
+ // digestAlgorithm AlgorithmIdentifier,
+ // digest OCTET STRING
+ // }
+ // The first field identifies the hash function and the second contains
+ // the hash value. Let T be the DER encoding of the DigestInfo value
+ // (see the notes below) and let tLen be the length in octets of T.
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ baos.write(prefix, 0, prefix.length);
+ baos.write(mHash, 0, mHash.length);
+ final byte[] T = baos.toByteArray();
+ final int tLen = T.length;
+ // 3. If emLen < tLen + 11, output "intended encoded message length too
+ // short" and stop.
+ if (emLen < tLen + 11)
+ {
+ throw new IllegalArgumentException("emLen too short");
+ }
+ // 4. Generate an octet string PS consisting of emLen - tLen - 3 octets
+ // with hexadecimal value 0xff. The length of PS will be at least 8
+ // octets.
+ final byte[] PS = new byte[emLen - tLen - 3];
+ for (int i = 0; i < PS.length; i++)
+ {
+ PS[i] = (byte) 0xFF;
+ }
+ // 5. Concatenate PS, the DER encoding T, and other padding to form the
+ // encoded message EM as: EM = 0x00 || 0x01 || PS || 0x00 || T.
+ baos.reset();
+ baos.write(0x00);
+ baos.write(0x01);
+ baos.write(PS, 0, PS.length);
+ baos.write(0x00);
+ baos.write(T, 0, tLen);
+ final byte[] result = baos.toByteArray();
+ baos.reset();
+ // 6. Output EM.
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/EMSA_PSS.java b/libjava/classpath/gnu/java/security/sig/rsa/EMSA_PSS.java
new file mode 100644
index 0000000..d11a861
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/EMSA_PSS.java
@@ -0,0 +1,432 @@
+/* EMSA_PSS.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import gnu.java.security.hash.HashFactory;
+import gnu.java.security.hash.IMessageDigest;
+import gnu.java.security.util.Util;
+
+import java.io.PrintWriter;
+import java.util.Arrays;
+
+/**
+ * An implementation of the EMSA-PSS encoding/decoding scheme.
+ *
+ * EMSA-PSS coincides with EMSA4 in IEEE P1363a D5 except that EMSA-PSS acts
+ * on octet strings and not on bit strings. In particular, the bit lengths of
+ * the hash and the salt must be multiples of 8 in EMSA-PSS. Moreover, EMSA4
+ * outputs an integer of a desired bit length rather than an octet string.
+ *
+ * EMSA-PSS is parameterized by the choice of hash function Hash and mask
+ * generation function MGF. In this submission, MGF is based on a Hash
+ * definition that coincides with the corresponding definitions in IEEE Std
+ * 1363-2000, PKCS #1 v2.0, and the draft ANSI X9.44. In PKCS #1 v2.0 and the
+ * draft ANSI X9.44, the recommended hash function is SHA-1, while IEEE Std
+ * 1363-2000 recommends SHA-1 and RIPEMD-160.
+ *
+ * References:
+ *
+ * -
+ * RSA-PSS Signature Scheme with Appendix, part B.
+ * Primitive specification and supporting documentation.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ *
+ * @version $Revision: 1.1 $
+ */
+public class EMSA_PSS implements Cloneable
+{
+
+ // Debugging methods and variables
+ // -------------------------------------------------------------------------
+
+ private static final String NAME = "emsa-pss";
+
+ private static final boolean DEBUG = false;
+
+ private static final int debuglevel = 5;
+
+ private static final PrintWriter err = new PrintWriter(System.out, true);
+
+ private static void debug(String s)
+ {
+ err.println(">>> " + NAME + ": " + s);
+ }
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** The underlying hash function to use with this instance. */
+ private IMessageDigest hash;
+
+ /** The output size of the hash function in octets. */
+ private int hLen;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Trivial private constructor to enforce use through Factory method.
+ *
+ * @param hash the message digest instance to use with this scheme instance.
+ */
+ private EMSA_PSS(IMessageDigest hash)
+ {
+ super();
+
+ this.hash = hash;
+ hLen = hash.hashSize();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns an instance of this object given a designated name of a hash
+ * function.
+ *
+ * @param mdName the canonical name of a hash function.
+ * @return an instance of this object configured for use with the designated
+ * options.
+ */
+ public static EMSA_PSS getInstance(String mdName)
+ {
+ IMessageDigest hash = HashFactory.getInstance(mdName);
+ return new EMSA_PSS(hash);
+ }
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // Cloneable interface implementation --------------------------------------
+
+ public Object clone()
+ {
+ return getInstance(hash.name());
+ }
+
+ // own methods -------------------------------------------------------------
+
+ /**
+ * The encoding operation EMSA-PSS-Encode computes the hash of a message
+ * M
using a hash function and maps the result to an encoded
+ * message EM
of a specified length using a mask generation
+ * function.
+ *
+ * @param mHash the byte sequence resulting from applying the message digest
+ * algorithm Hash to the message M.
+ * @param emBits the maximal bit length of the integer OS2IP(EM), at least
+ * 8.hLen + 8.sLen + 9
.
+ * @param salt the salt to use when encoding the output.
+ * @return the encoded message EM
, an octet string of length
+ * emLen = CEILING(emBits / 8)
.
+ * @exception IllegalArgumentException if an exception occurs.
+ *
+ */
+ public byte[] encode(byte[] mHash, int emBits, byte[] salt)
+ {
+ int sLen = salt.length;
+
+ // 1. If the length of M is greater than the input limitation for the hash
+ // function (2**61 - 1 octets for SHA-1) then output "message too long"
+ // and stop.
+ // 2. Let mHash = Hash(M), an octet string of length hLen.
+ if (hLen != mHash.length)
+ {
+ throw new IllegalArgumentException("wrong hash");
+ }
+ // 3. If emBits < 8.hLen + 8.sLen + 9, output 'encoding error' and stop.
+ if (emBits < (8 * hLen + 8 * sLen + 9))
+ {
+ throw new IllegalArgumentException("encoding error");
+ }
+ int emLen = (emBits + 7) / 8;
+ // 4. Generate a random octet string salt of length sLen; if sLen = 0,
+ // then salt is the empty string.
+ // ...passed as argument to accomodate JCE
+ // 5. Let M0 = 00 00 00 00 00 00 00 00 || mHash || salt;
+ // M0 is an octet string of length 8 + hLen + sLen with eight initial zero
+ // octets.
+ // 6. Let H = Hash(M0), an octet string of length hLen.
+ byte[] H;
+ int i;
+ synchronized (hash)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ hash.update((byte) 0x00);
+ }
+ hash.update(mHash, 0, hLen);
+ hash.update(salt, 0, sLen);
+ H = hash.digest();
+ }
+ // 7. Generate an octet string PS consisting of emLen - sLen - hLen - 2
+ // zero octets. The length of PS may be 0.
+ // 8. Let DB = PS || 01 || salt.
+ byte[] DB = new byte[emLen - sLen - hLen - 2 + 1 + sLen];
+ DB[emLen - sLen - hLen - 2] = 0x01;
+ System.arraycopy(salt, 0, DB, emLen - sLen - hLen - 1, sLen);
+ // 9. Let dbMask = MGF(H, emLen - hLen - 1).
+ byte[] dbMask = MGF(H, emLen - hLen - 1);
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("dbMask (encode): " + Util.toString(dbMask));
+ debug("DB (encode): " + Util.toString(DB));
+ }
+ // 10. Let maskedDB = DB XOR dbMask.
+ for (i = 0; i < DB.length; i++)
+ {
+ DB[i] = (byte) (DB[i] ^ dbMask[i]);
+ }
+ // 11. Set the leftmost 8emLen - emBits bits of the leftmost octet in
+ // maskedDB to zero.
+ DB[0] &= (0xFF >>> (8 * emLen - emBits));
+ // 12. Let EM = maskedDB || H || bc, where bc is the single octet with
+ // hexadecimal value 0xBC.
+ byte[] result = new byte[emLen];
+ System.arraycopy(DB, 0, result, 0, emLen - hLen - 1);
+ System.arraycopy(H, 0, result, emLen - hLen - 1, hLen);
+ result[emLen - 1] = (byte) 0xBC;
+ // 13. Output EM.
+ return result;
+ }
+
+ /**
+ * The decoding operation EMSA-PSS-Decode recovers the message hash from
+ * an encoded message EM
and compares it to the hash of
+ * M
.
+ *
+ * @param mHash the byte sequence resulting from applying the message digest
+ * algorithm Hash to the message M.
+ * @param EM the encoded message, an octet string of length
+ * emLen = CEILING(emBits/8).
+ * @param emBits the maximal bit length of the integer OS2IP(EM), at least
+ * 8.hLen + 8.sLen + 9
.
+ * @param sLen the length, in octets, of the expected salt.
+ * @return true
if the result of the verification was
+ * consistent with the expected reseult; and false
if the
+ * result was inconsistent.
+ * @exception IllegalArgumentException if an exception occurs.
+ */
+ public boolean decode(byte[] mHash, byte[] EM, int emBits, int sLen)
+ {
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("mHash: " + Util.toString(mHash));
+ debug("EM: " + Util.toString(EM));
+ debug("emBits: " + String.valueOf(emBits));
+ debug("sLen: " + String.valueOf(sLen));
+ }
+ if (sLen < 0)
+ {
+ throw new IllegalArgumentException("sLen");
+ }
+
+ // 1. If the length of M is greater than the input limitation for the hash
+ // function (2**61 ? 1 octets for SHA-1) then output 'inconsistent' and
+ // stop.
+ // 2. Let mHash = Hash(M), an octet string of length hLen.
+ if (hLen != mHash.length)
+ {
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("hLen != mHash.length; hLen: " + String.valueOf(hLen));
+ }
+ throw new IllegalArgumentException("wrong hash");
+ }
+ // 3. If emBits < 8.hLen + 8.sLen + 9, output 'decoding error' and stop.
+ if (emBits < (8 * hLen + 8 * sLen + 9))
+ {
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("emBits < (8hLen + 8sLen + 9); sLen: " + String.valueOf(sLen));
+ }
+ throw new IllegalArgumentException("decoding error");
+ }
+ int emLen = (emBits + 7) / 8;
+ // 4. If the rightmost octet of EM does not have hexadecimal value bc,
+ // output 'inconsistent' and stop.
+ if ((EM[EM.length - 1] & 0xFF) != 0xBC)
+ {
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("EM does not end with 0xBC");
+ }
+ return false;
+ }
+ // 5. Let maskedDB be the leftmost emLen ? hLen ? 1 octets of EM, and let
+ // H be the next hLen octets.
+ // 6. If the leftmost 8.emLen ? emBits bits of the leftmost octet in
+ // maskedDB are not all equal to zero, output 'inconsistent' and stop.
+ if ((EM[0] & (0xFF << (8 - (8 * emLen - emBits)))) != 0)
+ {
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("Leftmost 8emLen - emBits bits of EM are not 0s");
+ }
+ return false;
+ }
+ byte[] DB = new byte[emLen - hLen - 1];
+ byte[] H = new byte[hLen];
+ System.arraycopy(EM, 0, DB, 0, emLen - hLen - 1);
+ System.arraycopy(EM, emLen - hLen - 1, H, 0, hLen);
+ // 7. Let dbMask = MGF(H, emLen ? hLen ? 1).
+ byte[] dbMask = MGF(H, emLen - hLen - 1);
+ // 8. Let DB = maskedDB XOR dbMask.
+ int i;
+ for (i = 0; i < DB.length; i++)
+ {
+ DB[i] = (byte) (DB[i] ^ dbMask[i]);
+ }
+ // 9. Set the leftmost 8.emLen ? emBits bits of DB to zero.
+ DB[0] &= (0xFF >>> (8 * emLen - emBits));
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("dbMask (decode): " + Util.toString(dbMask));
+ debug("DB (decode): " + Util.toString(DB));
+ }
+ // 10. If the emLen -hLen -sLen -2 leftmost octets of DB are not zero or
+ // if the octet at position emLen -hLen -sLen -1 is not equal to 0x01,
+ // output 'inconsistent' and stop.
+ // IMPORTANT (rsn): this is an error in the specs, the index of the 0x01
+ // byte should be emLen -hLen -sLen -2 and not -1! authors have been
+ // advised
+ for (i = 0; i < (emLen - hLen - sLen - 2); i++)
+ {
+ if (DB[i] != 0)
+ {
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("DB[" + String.valueOf(i) + "] != 0x00");
+ }
+ return false;
+ }
+ }
+ if (DB[i] != 0x01)
+ { // i == emLen -hLen -sLen -2
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("DB's byte at position (emLen -hLen -sLen -2); i.e. "
+ + String.valueOf(i) + " is not 0x01");
+ }
+ return false;
+ }
+ // 11. Let salt be the last sLen octets of DB.
+ byte[] salt = new byte[sLen];
+ System.arraycopy(DB, DB.length - sLen, salt, 0, sLen);
+ // 12. Let M0 = 00 00 00 00 00 00 00 00 || mHash || salt;
+ // M0 is an octet string of length 8 + hLen + sLen with eight initial
+ // zero octets.
+ // 13. Let H0 = Hash(M0), an octet string of length hLen.
+ byte[] H0;
+ synchronized (hash)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ hash.update((byte) 0x00);
+ }
+ hash.update(mHash, 0, hLen);
+ hash.update(salt, 0, sLen);
+ H0 = hash.digest();
+ }
+ // 14. If H = H0, output 'consistent.' Otherwise, output 'inconsistent.'
+ return Arrays.equals(H, H0);
+ }
+
+ // helper methods ----------------------------------------------------------
+
+ /**
+ * A mask generation function takes an octet string of variable length
+ * and a desired output length as input, and outputs an octet string of the
+ * desired length. There may be restrictions on the length of the input and
+ * output octet strings, but such bounds are generally very large. Mask
+ * generation functions are deterministic; the octet string output is
+ * completely determined by the input octet string. The output of a mask
+ * generation function should be pseudorandom, that is, it should be
+ * infeasible to predict, given one part of the output but not the input,
+ * another part of the output. The provable security of RSA-PSS relies on
+ * the random nature of the output of the mask generation function, which in
+ * turn relies on the random nature of the underlying hash function.
+ *
+ * @param Z a seed.
+ * @param l the desired output length in octets.
+ * @return the mask.
+ * @exception IllegalArgumentException if the desired output length is too
+ * long.
+ */
+ private byte[] MGF(byte[] Z, int l)
+ {
+ // 1. If l > (2**32).hLen, output 'mask too long' and stop.
+ if (l < 1 || (l & 0xFFFFFFFFL) > ((hLen & 0xFFFFFFFFL) << 32L))
+ {
+ throw new IllegalArgumentException("mask too long");
+ }
+ // 2. Let T be the empty octet string.
+ byte[] result = new byte[l];
+ // 3. For i = 0 to CEILING(l/hLen) ? 1, do
+ int limit = ((l + hLen - 1) / hLen) - 1;
+ IMessageDigest hashZ = null;
+ hashZ = (IMessageDigest) hash.clone();
+ hashZ.digest();
+ hashZ.update(Z, 0, Z.length);
+ IMessageDigest hashZC = null;
+ byte[] t;
+ int sofar = 0;
+ int length;
+ for (int i = 0; i < limit; i++)
+ {
+ // 3.1 Convert i to an octet string C of length 4 with the primitive
+ // I2OSP: C = I2OSP(i, 4).
+ // 3.2 Concatenate the hash of the seed Z and C to the octet string T:
+ // T = T || Hash(Z || C)
+ hashZC = (IMessageDigest) hashZ.clone();
+ hashZC.update((byte) (i >>> 24));
+ hashZC.update((byte) (i >>> 16));
+ hashZC.update((byte) (i >>> 8));
+ hashZC.update((byte) i);
+ t = hashZC.digest();
+ length = l - sofar;
+ length = (length > hLen ? hLen : length);
+ System.arraycopy(t, 0, result, sofar, length);
+ sofar += length;
+ }
+ // 4. Output the leading l octets of T as the octet string mask.
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/RSA.java b/libjava/classpath/gnu/java/security/sig/rsa/RSA.java
new file mode 100644
index 0000000..7d1707e
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/RSA.java
@@ -0,0 +1,356 @@
+/* RSA.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import gnu.java.security.Properties;
+import gnu.java.security.util.PRNG;
+
+import java.math.BigInteger;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.interfaces.RSAPrivateCrtKey;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.interfaces.RSAPublicKey;
+
+/**
+ * Utility methods related to the RSA algorithm.
+ *
+ * References:
+ *
+ * -
+ * RSA-PSS Signature Scheme with Appendix, part B.
+ * Primitive specification and supporting documentation.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ * - Public-Key Cryptography
+ * Standards (PKCS) #1:
+ * RSA Cryptography Specifications Version 2.1.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ * -
+ * Remote timing attacks are practical
+ * D. Boneh and D. Brumley.
+ *
+ */
+public class RSA
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ private static final BigInteger ZERO = BigInteger.ZERO;
+
+ private static final BigInteger ONE = BigInteger.ONE;
+
+ /** Our default source of randomness. */
+ private static final PRNG prng = PRNG.getInstance();
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Trivial private constructor to enforce Singleton pattern. */
+ private RSA()
+ {
+ super();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Signature and verification methods --------------------------------------
+
+ /**
+ * An implementation of the RSASP method: Assuming that the
+ * designated RSA private key is a valid one, this method computes a
+ * signature representative for a designated message
+ * representative signed by the holder of the designated RSA private
+ * key.
+ *
+ * @param K the RSA private key.
+ * @param m the message representative: an integer between
+ * 0
and n - 1
, where n
is the RSA
+ * modulus.
+ * @return the signature representative, an integer between
+ * 0
and n - 1
, where n
is the RSA
+ * modulus.
+ * @throws ClassCastException if K
is not an RSA one.
+ * @throws IllegalArgumentException if m
(the message
+ * representative) is out of range.
+ */
+ public static final BigInteger sign(final PrivateKey K, final BigInteger m)
+ {
+ try
+ {
+ return RSADP((RSAPrivateKey) K, m);
+ }
+ catch (IllegalArgumentException x)
+ {
+ throw new IllegalArgumentException(
+ "message representative out of range");
+ }
+ }
+
+ /**
+ *
An implementation of the RSAVP method: Assuming that the
+ * designated RSA public key is a valid one, this method computes a
+ * message representative for the designated signature
+ * representative generated by an RSA private key, for a message
+ * intended for the holder of the designated RSA public key.
+ *
+ * @param K the RSA public key.
+ * @param s the signature representative, an integer between
+ * 0
and n - 1
, where n
is the RSA
+ * modulus.
+ * @return a message representative: an integer between 0
+ * and n - 1
, where n
is the RSA modulus.
+ * @throws ClassCastException if K
is not an RSA one.
+ * @throws IllegalArgumentException if s
(the signature
+ * representative) is out of range.
+ */
+ public static final BigInteger verify(final PublicKey K, final BigInteger s)
+ {
+ try
+ {
+ return RSAEP((RSAPublicKey) K, s);
+ }
+ catch (IllegalArgumentException x)
+ {
+ throw new IllegalArgumentException(
+ "signature representative out of range");
+ }
+ }
+
+ // Encryption and decryption methods ---------------------------------------
+
+ /**
+ * An implementation of the RSAEP
algorithm.
+ *
+ * @param K the recipient's RSA public key.
+ * @param m the message representative as an MPI.
+ * @return the resulting MPI --an MPI between 0
and
+ * n - 1
(n
being the public shared modulus)-- that
+ * will eventually be padded with an appropriate framing/padding scheme.
+ * @throws ClassCastException if K
is not an RSA one.
+ * @throws IllegalArgumentException if m
, the message
+ * representative is not between 0
and n - 1
+ * (n
being the public shared modulus).
+ */
+ public static final BigInteger encrypt(final PublicKey K, final BigInteger m)
+ {
+ try
+ {
+ return RSAEP((RSAPublicKey) K, m);
+ }
+ catch (IllegalArgumentException x)
+ {
+ throw new IllegalArgumentException(
+ "message representative out of range");
+ }
+ }
+
+ /**
+ * An implementation of the RSADP
algorithm.
+ *
+ * @param K the recipient's RSA private key.
+ * @param c the ciphertext representative as an MPI.
+ * @return the message representative, an MPI between 0
and
+ * n - 1
(n
being the shared public modulus).
+ * @throws ClassCastException if K
is not an RSA one.
+ * @throws IllegalArgumentException if c
, the ciphertext
+ * representative is not between 0
and n - 1
+ * (n
being the shared public modulus).
+ */
+ public static final BigInteger decrypt(final PrivateKey K, final BigInteger c)
+ {
+ try
+ {
+ return RSADP((RSAPrivateKey) K, c);
+ }
+ catch (IllegalArgumentException x)
+ {
+ throw new IllegalArgumentException(
+ "ciphertext representative out of range");
+ }
+ }
+
+ // Conversion methods ------------------------------------------------------
+
+ /**
+ * Converts a multi-precision integer (MPI) s
into an
+ * octet sequence of length k
.
+ *
+ * @param s the multi-precision integer to convert.
+ * @param k the length of the output.
+ * @return the result of the transform.
+ * @exception IllegalArgumentException if the length in octets of meaningful
+ * bytes of s
is greater than k
.
+ */
+ public static final byte[] I2OSP(final BigInteger s, final int k)
+ {
+ byte[] result = s.toByteArray();
+ if (result.length < k)
+ {
+ final byte[] newResult = new byte[k];
+ System.arraycopy(result, 0, newResult, k - result.length, result.length);
+ result = newResult;
+ }
+ else if (result.length > k)
+ { // leftmost extra bytes should all be 0
+ final int limit = result.length - k;
+ for (int i = 0; i < limit; i++)
+ {
+ if (result[i] != 0x00)
+ {
+ throw new IllegalArgumentException("integer too large");
+ }
+ }
+ final byte[] newResult = new byte[k];
+ System.arraycopy(result, limit, newResult, 0, k);
+ result = newResult;
+ }
+ return result;
+ }
+
+ // helper methods ----------------------------------------------------------
+
+ private static final BigInteger RSAEP(final RSAPublicKey K, final BigInteger m)
+ {
+ // 1. If the representative m is not between 0 and n - 1, output
+ // "representative out of range" and stop.
+ final BigInteger n = K.getModulus();
+ if (m.compareTo(ZERO) < 0 || m.compareTo(n.subtract(ONE)) > 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ // 2. Let c = m^e mod n.
+ final BigInteger e = K.getPublicExponent();
+ final BigInteger result = m.modPow(e, n);
+ // 3. Output c.
+ return result;
+ }
+
+ private static final BigInteger RSADP(final RSAPrivateKey K, BigInteger c)
+ {
+ // 1. If the representative c is not between 0 and n - 1, output
+ // "representative out of range" and stop.
+ final BigInteger n = K.getModulus();
+ if (c.compareTo(ZERO) < 0 || c.compareTo(n.subtract(ONE)) > 0)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ // 2. The representative m is computed as follows.
+ BigInteger result;
+ if (!(K instanceof RSAPrivateCrtKey))
+ {
+ // a. If the first form (n, d) of K is used, let m = c^d mod n.
+ final BigInteger d = K.getPrivateExponent();
+ result = c.modPow(d, n);
+ }
+ else
+ {
+ // from [3] p.13 --see class docs:
+ // The RSA blinding operation calculates x = (r^e) * g mod n before
+ // decryption, where r is random, e is the RSA encryption exponent, and
+ // g is the ciphertext to be decrypted. x is then decrypted as normal,
+ // followed by division by r, i.e. (x^e) / r mod n. Since r is random,
+ // x is random and timing the decryption should not reveal information
+ // about the key. Note that r should be a new random number for every
+ // decryption.
+ final boolean rsaBlinding = Properties.doRSABlinding();
+ BigInteger r = null;
+ BigInteger e = null;
+ if (rsaBlinding)
+ { // pre-decryption
+ r = newR(n);
+ e = ((RSAPrivateCrtKey) K).getPublicExponent();
+ final BigInteger x = r.modPow(e, n).multiply(c).mod(n);
+ c = x;
+ }
+
+ // b. If the second form (p, q, dP, dQ, qInv) and (r_i, d_i, t_i)
+ // of K is used, proceed as follows:
+ final BigInteger p = ((RSAPrivateCrtKey) K).getPrimeP();
+ final BigInteger q = ((RSAPrivateCrtKey) K).getPrimeQ();
+ final BigInteger dP = ((RSAPrivateCrtKey) K).getPrimeExponentP();
+ final BigInteger dQ = ((RSAPrivateCrtKey) K).getPrimeExponentQ();
+ final BigInteger qInv = ((RSAPrivateCrtKey) K).getCrtCoefficient();
+
+ // i. Let m_1 = c^dP mod p and m_2 = c^dQ mod q.
+ final BigInteger m_1 = c.modPow(dP, p);
+ final BigInteger m_2 = c.modPow(dQ, q);
+ // ii. If u > 2, let m_i = c^(d_i) mod r_i, i = 3, ..., u.
+ // iii. Let h = (m_1 - m_2) * qInv mod p.
+ final BigInteger h = m_1.subtract(m_2).multiply(qInv).mod(p);
+ // iv. Let m = m_2 + q * h.
+ result = m_2.add(q.multiply(h));
+
+ if (rsaBlinding)
+ { // post-decryption
+ result = result.multiply(r.modInverse(n)).mod(n);
+ }
+ }
+
+ // 3. Output m
+ return result;
+ }
+
+ /**
+ * Returns a random MPI with a random bit-length of the form 8b
,
+ * where b
is in the range [32..64]
.
+ *
+ * @return a random MPI whose length in bytes is between 32 and 64 inclusive.
+ */
+ private static final BigInteger newR(final BigInteger N)
+ {
+ final int upper = (N.bitLength() + 7) / 8;
+ final int lower = upper / 2;
+ final byte[] bl = new byte[1];
+ int b;
+ do
+ {
+ prng.nextBytes(bl);
+ b = bl[0] & 0xFF;
+ }
+ while (b < lower || b > upper);
+ final byte[] buffer = new byte[b]; // 256-bit MPI
+ prng.nextBytes(buffer);
+ return new BigInteger(1, buffer);
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java b/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java
new file mode 100644
index 0000000..d4b69a7
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java
@@ -0,0 +1,247 @@
+/* RSAPKCS1V1_5Signature.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.hash.HashFactory;
+import gnu.java.security.hash.IMessageDigest;
+import gnu.java.security.sig.BaseSignature;
+
+import java.math.BigInteger;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.interfaces.RSAPublicKey;
+import java.util.Arrays;
+
+/**
+ * The RSA-PKCS1-V1.5 signature scheme is a digital signature scheme with
+ * appendix (SSA) combining the RSA algorithm with the EMSA-PKCS1-v1_5 encoding
+ * method.
+ *
+ * References:
+ *
+ * -
+ * RSA-PSS Signature Scheme with Appendix, part B.
+ * Primitive specification and supporting documentation.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ * - Public-Key Cryptography
+ * Standards (PKCS) #1:
+ * RSA Cryptography Specifications Version 2.1.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ *
+ * @version $Revision: 1.2 $
+ */
+public class RSAPKCS1V1_5Signature extends BaseSignature
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** The underlying EMSA-PKCS1-v1.5 instance for this object. */
+ private EMSA_PKCS1_V1_5 pkcs1;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Default 0-arguments constructor. Uses SHA-1 as the default hash.
+ */
+ public RSAPKCS1V1_5Signature()
+ {
+ this(Registry.SHA160_HASH);
+ }
+
+ /**
+ * Constructs an instance of this object using the designated message
+ * digest algorithm as its underlying hash function.
+ *
+ * @param mdName the canonical name of the underlying hash function.
+ */
+ public RSAPKCS1V1_5Signature(final String mdName)
+ {
+ this(HashFactory.getInstance(mdName));
+ }
+
+ public RSAPKCS1V1_5Signature(IMessageDigest md)
+ {
+ super(Registry.RSA_PKCS1_V1_5_SIG, md);
+
+ pkcs1 = EMSA_PKCS1_V1_5.getInstance(md.name());
+ }
+
+ /** Private constructor for cloning purposes. */
+ private RSAPKCS1V1_5Signature(final RSAPKCS1V1_5Signature that)
+ {
+ this(that.md.name());
+
+ this.publicKey = that.publicKey;
+ this.privateKey = that.privateKey;
+ this.md = (IMessageDigest) that.md.clone();
+ this.pkcs1 = (EMSA_PKCS1_V1_5) that.pkcs1.clone();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // Implementation of abstract methods in superclass ------------------------
+
+ public Object clone()
+ {
+ return new RSAPKCS1V1_5Signature(this);
+ }
+
+ protected void setupForVerification(final PublicKey k)
+ throws IllegalArgumentException
+ {
+ if (!(k instanceof RSAPublicKey))
+ {
+ throw new IllegalArgumentException();
+ }
+ publicKey = k;
+ }
+
+ protected void setupForSigning(final PrivateKey k)
+ throws IllegalArgumentException
+ {
+ if (!(k instanceof RSAPrivateKey))
+ {
+ throw new IllegalArgumentException();
+ }
+ privateKey = k;
+ }
+
+ protected Object generateSignature() throws IllegalStateException
+ {
+ // 1. EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding
+ // operation (Section 9.2) to the message M to produce an encoded
+ // message EM of length k octets:
+ //
+ // EM = EMSA-PKCS1-V1_5-ENCODE (M, k).
+ //
+ // If the encoding operation outputs "message too long," output
+ // "message too long" and stop. If the encoding operation outputs
+ // "intended encoded message length too short," output "RSA modulus
+ // too short" and stop.
+ final int modBits = ((RSAPrivateKey) privateKey).getModulus().bitLength();
+ final int k = (modBits + 7) / 8;
+ final byte[] EM = pkcs1.encode(md.digest(), k);
+
+ // 2. RSA signature:
+ // a. Convert the encoded message EM to an integer message epresentative
+ // m (see Section 4.2): m = OS2IP (EM).
+ final BigInteger m = new BigInteger(1, EM);
+ // b. Apply the RSASP1 signature primitive (Section 5.2.1) to the RSA
+ // private key K and the message representative m to produce an
+ // integer signature representative s: s = RSASP1 (K, m).
+ final BigInteger s = RSA.sign(privateKey, m);
+ // c. Convert the signature representative s to a signature S of length
+ // k octets (see Section 4.1): S = I2OSP (s, k).
+ // 3. Output the signature S.
+ return RSA.I2OSP(s, k);
+ }
+
+ protected boolean verifySignature(final Object sig)
+ throws IllegalStateException
+ {
+ if (publicKey == null)
+ {
+ throw new IllegalStateException();
+ }
+ final byte[] S = (byte[]) sig;
+ // 1. Length checking: If the length of the signature S is not k octets,
+ // output "invalid signature" and stop.
+ final int modBits = ((RSAPublicKey) publicKey).getModulus().bitLength();
+ final int k = (modBits + 7) / 8;
+ if (S.length != k)
+ {
+ return false;
+ }
+ // 2. RSA verification:
+ // a. Convert the signature S to an integer signature representative
+ // s (see Section 4.2): s = OS2IP (S).
+ final BigInteger s = new BigInteger(1, S);
+ // b. Apply the RSAVP1 verification primitive (Section 5.2.2) to the
+ // RSA public key (n, e) and the signature representative s to
+ // produce an integer message representative m:
+ // m = RSAVP1 ((n, e), s).
+ // If RSAVP1 outputs "signature representative out of range,"
+ // output "invalid signature" and stop.
+ final BigInteger m;
+ try
+ {
+ m = RSA.verify(publicKey, s);
+ }
+ catch (IllegalArgumentException x)
+ {
+ return false;
+ }
+ // c. Convert the message representative m to an encoded message EM
+ // of length k octets (see Section 4.1): EM = I2OSP (m, k).
+ // If I2OSP outputs "integer too large," output "invalid signature"
+ // and stop.
+ final byte[] EM;
+ try
+ {
+ EM = RSA.I2OSP(m, k);
+ }
+ catch (IllegalArgumentException x)
+ {
+ return false;
+ }
+ // 3. EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding
+ // operation (Section 9.2) to the message M to produce a second
+ // encoded message EM' of length k octets:
+ // EM' = EMSA-PKCS1-V1_5-ENCODE (M, k).
+ // If the encoding operation outputs "message too long," output
+ // "message too long" and stop. If the encoding operation outputs
+ // "intended encoded message length too short," output "RSA modulus
+ // too short" and stop.
+ final byte[] EMp = pkcs1.encode(md.digest(), k);
+ // 4. Compare the encoded message EM and the second encoded message EM'.
+ // If they are the same, output "valid signature"; otherwise, output
+ // "invalid signature."
+ return Arrays.equals(EM, EMp);
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureRawCodec.java b/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureRawCodec.java
new file mode 100644
index 0000000..68c1eda
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureRawCodec.java
@@ -0,0 +1,153 @@
+/* RSAPKCS1V1_5SignatureRawCodec.java -- Raw RSA PKCS1 v1.5 signature codeec
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import java.io.ByteArrayOutputStream;
+
+import gnu.java.security.Registry;
+import gnu.java.security.sig.ISignatureCodec;
+
+/**
+ * An object that implements the {@link ISignatureCodec} operations for the
+ * Raw format to use with RSA-PKCS#1 v1.5 signatures.
+ */
+public class RSAPKCS1V1_5SignatureRawCodec
+ implements ISignatureCodec
+{
+ public int getFormatID()
+ {
+ return RAW_FORMAT;
+ }
+
+ /**
+ * Returns the encoded form of the designated RSA-PKCS#1 (v1.5) signature
+ * object according to the Raw format supported by this library.
+ *
+ * The Raw format for such a signature, in this implementation, is a
+ * byte sequence consisting of the following:
+ *
+ *
+ * - 4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE},
+ *
-
+ *
- 1-byte version consisting of the constant: 0x01,
+ * - 4-byte count of following bytes representing the RSA-PKCS#1 (v1.5)
+ * signature bytes in internet order,
+ * - the RSA-PKCS#1 (v1.5) signature bytes in internet order.
+ *
+ *
+ * @param signature the signature to encode, consisting of the output of the
+ * sign()
method of a {@link RSAPKCS1V1_5Signature}
+ * instance --a byte array.
+ * @return the Raw format encoding of the designated signature.
+ * @exception IllegalArgumentException if the designated signature is not an
+ * RSA-PKCS#1 (v1.5) one.
+ */
+ public byte[] encodeSignature(Object signature)
+ {
+ byte[] buffer;
+ try
+ {
+ buffer = (byte[]) signature;
+ }
+ catch (Exception x)
+ {
+ throw new IllegalArgumentException("Signature/codec mismatch");
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ // magic
+ baos.write(Registry.MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE[0]);
+ baos.write(Registry.MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE[1]);
+ baos.write(Registry.MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE[2]);
+ baos.write(Registry.MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE[3]);
+
+ // version
+ baos.write(0x01);
+
+ // signature bytes
+ int length = buffer.length;
+ baos.write( length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ return baos.toByteArray();
+ }
+
+ /**
+ * Returns the decoded object from a designated input assumed to have been
+ * generated by the {@link #encodeSignature(Object)} method.
+ *
+ * @param input the input bytes of a previously Raw-encoded RSA PKCS1 (v1.5)
+ * signature.
+ * @return the signature object.
+ * @throws IllegalArgumentException if the designated input does not start
+ * with the right magic characters, or if the version
+ * is not supported.
+ */
+ public Object decodeSignature(byte[] input)
+ {
+ // magic
+ if (input[0] != Registry.MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE[0]
+ || input[1] != Registry.MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE[1]
+ || input[2] != Registry.MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE[2]
+ || input[3] != Registry.MAGIC_RAW_RSA_PKCS1V1_5_SIGNATURE[3])
+ throw new IllegalArgumentException("Signature/codec mismatch");
+
+ // version
+ if (input[4] != 0x01)
+ throw new IllegalArgumentException("Wrong or unsupported format version");
+
+ int i = 5;
+ int l;
+
+ // signature bytes
+ l = input[i++] << 24
+ | (input[i++] & 0xFF) << 16
+ | (input[i++] & 0xFF) << 8
+ | (input[i++] & 0xFF);
+ byte[] result = new byte[l];
+ System.arraycopy(input, i, result, 0, l);
+
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureX509Codec.java b/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureX509Codec.java
new file mode 100644
index 0000000..3cb3756
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureX509Codec.java
@@ -0,0 +1,128 @@
+/* RSAPSSSignatureX509Codec.java -- X.509 encoder/decoder for RSA signatures
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.sig.ISignatureCodec;
+
+import java.security.InvalidParameterException;
+
+/**
+ * An implementation of an {@link ISignatureCodec} that knows to encode and
+ * decode RSA PKCS1 (v1.5) signatures into the raw bytes which would constitute
+ * a DER-encoded form of the ASN.1 structure defined in RFC-2459, and RFC-2313
+ * as described in the next paragraphs.
+ *
+ * Digital signatures when transmitted in an X.509 certificates are encoded
+ * in DER (Distinguished Encoding Rules) as a BIT STRING; i.e.
+ *
+ *
+ * Certificate ::= SEQUENCE {
+ * tbsCertificate TBSCertificate,
+ * signatureAlgorithm AlgorithmIdentifier,
+ * signature BIT STRING
+ * }
+ *
+ *
+ * The output of the encoder, and the input of the decoder, of this codec are
+ * then the raw bytes of such a BIT STRING; i.e. not the DER-encoded
+ * form itself.
+ *
+ * Our implementation of the RSA PKCS1 signature algorithm outputs a byte array
+ * as the result of generating a digital signature, in accordance with RFC-2313.
+ * As a consequence, the encoder and decoder of this codec, simply pass through
+ * such a byte array.
+ *
+ * Client code that needs to build a DER BIT STRING MUST construct such
+ * an ASN.1 value. The following is an example of how to do this:
+ *
+ *
+ * ...
+ * import gnu.java.security.der.BitString;
+ * import gnu.java.security.der.DER;
+ * import gnu.java.security.der.DERValue;
+ * ...
+ * DERValue bitString = new DERValue(DER.BIT_STRING, new BitString(sigBytes));
+ * ...
+ *
+ */
+public class RSAPKCS1V1_5SignatureX509Codec
+ implements ISignatureCodec
+{
+ // default 0-arguments constructor
+
+ public int getFormatID()
+ {
+ return Registry.X509_ENCODING_ID;
+ }
+
+ /**
+ * Encodes an RSA Signature output as a signature BIT STRING as
+ * defined in the documentation of this class.
+ *
+ * @param signature the output of the RSA PKCS1 (v1.5) signature algorithm;
+ * i.e. the value returned by the invocation of
+ * {@link gnu.java.security.sig.ISignature#sign()} method. In the
+ * case of the RSA PKCS1 (v1.5) signature this is an array of bytes.
+ * @return the raw bytes of an RSA signature which could be then used as the
+ * contents of a BIT STRING as per rfc-2459.
+ */
+ public byte[] encodeSignature(Object signature)
+ {
+ byte[] result = (byte[]) signature;
+ return result;
+ }
+
+ /**
+ * Decodes a signature as defined in the documentation of this class.
+ *
+ * @param input the byte array to unmarshall into a valid RSA PKCS1 (v1.5)
+ * signature instance; i.e. a byte array. MUST NOT be null.
+ * @return an array of raw bytes decoded from the designated input. In the
+ * case of RSA PKCS1 (v1.5) this is the same as the input.
+ * @throw InvalidParameterException if the input
array is null.
+ */
+ public Object decodeSignature(byte[] input)
+ {
+ if (input == null)
+ throw new InvalidParameterException("Input bytes MUST NOT be null");
+
+ return input;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/RSAPSSSignature.java b/libjava/classpath/gnu/java/security/sig/rsa/RSAPSSSignature.java
new file mode 100644
index 0000000..95a6653f
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/RSAPSSSignature.java
@@ -0,0 +1,348 @@
+/* RSAPSSSignature.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.hash.HashFactory;
+import gnu.java.security.hash.IMessageDigest;
+import gnu.java.security.sig.BaseSignature;
+import gnu.java.security.util.Util;
+
+import java.io.PrintWriter;
+import java.math.BigInteger;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.interfaces.RSAPublicKey;
+
+/**
+ * The RSA-PSS signature scheme is a public-key encryption scheme combining
+ * the RSA algorithm with the Probabilistic Signature Scheme (PSS) encoding
+ * method.
+ *
+ * The inventors of RSA are Ronald L. Rivest, Adi Shamir, and Leonard Adleman,
+ * while the inventors of the PSS encoding method are Mihir Bellare and Phillip
+ * Rogaway. During efforts to adopt RSA-PSS into the P1363a standards effort,
+ * certain adaptations to the original version of RSA-PSS were made by Mihir
+ * Bellare and Phillip Rogaway and also by Burt Kaliski (the editor of IEEE
+ * P1363a) to facilitate implementation and integration into existing protocols.
+ *
+ * References:
+ *
+ * -
+ * RSA-PSS Signature Scheme with Appendix, part B.
+ * Primitive specification and supporting documentation.
+ * Jakob Jonsson and Burt Kaliski.
+ *
+ *
+ * @version $Revision: 1.2 $
+ */
+public class RSAPSSSignature extends BaseSignature
+{
+
+ // Debugging methods and variables
+ // -------------------------------------------------------------------------
+
+ private static final String NAME = "rsa-pss";
+
+ private static final boolean DEBUG = false;
+
+ private static final int debuglevel = 1;
+
+ private static final PrintWriter err = new PrintWriter(System.out, true);
+
+ private static void debug(String s)
+ {
+ err.println(">>> " + NAME + ": " + s);
+ }
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** The underlying EMSA-PSS instance for this object. */
+ private EMSA_PSS pss;
+
+ /** The desired length in octets of the EMSA-PSS salt. */
+ private int sLen;
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Default 0-arguments constructor. Uses SHA-1 as the default hash and a
+ * 0-octet salt.
+ */
+ public RSAPSSSignature()
+ {
+ this(Registry.SHA160_HASH, 0);
+ }
+
+ /**
+ * Constructs an instance of this object using the designated message
+ * digest algorithm as its underlying hash function, and having 0-octet
+ * salt.
+ *
+ * @param mdName the canonical name of the underlying hash function.
+ */
+ public RSAPSSSignature(String mdName)
+ {
+ this(mdName, 0);
+ }
+
+ /**
+ * Constructs an instance of this object using the designated message
+ * digest algorithm as its underlying hash function.
+ *
+ * @param mdName the canonical name of the underlying hash function.
+ * @param sLen the desired length in octets of the salt to use for encoding /
+ * decoding signatures.
+ */
+ public RSAPSSSignature(String mdName, int sLen)
+ {
+ this(HashFactory.getInstance(mdName), sLen);
+ }
+
+ public RSAPSSSignature(IMessageDigest md, int sLen)
+ {
+ super(Registry.RSA_PSS_SIG, md);
+
+ pss = EMSA_PSS.getInstance(md.name());
+ this.sLen = sLen;
+ }
+
+ /** Private constructor for cloning purposes. */
+ private RSAPSSSignature(RSAPSSSignature that)
+ {
+ this(that.md.name(), that.sLen);
+
+ this.publicKey = that.publicKey;
+ this.privateKey = that.privateKey;
+ this.md = (IMessageDigest) that.md.clone();
+ this.pss = (EMSA_PSS) that.pss.clone();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // Instance methods
+ // -------------------------------------------------------------------------
+
+ // Implementation of abstract methods in superclass ------------------------
+
+ public Object clone()
+ {
+ return new RSAPSSSignature(this);
+ }
+
+ protected void setupForVerification(PublicKey k)
+ throws IllegalArgumentException
+ {
+ if (!(k instanceof RSAPublicKey))
+ {
+ throw new IllegalArgumentException();
+ }
+ publicKey = (RSAPublicKey) k;
+ }
+
+ protected void setupForSigning(PrivateKey k) throws IllegalArgumentException
+ {
+ if (!(k instanceof RSAPrivateKey))
+ {
+ throw new IllegalArgumentException();
+ }
+ privateKey = (RSAPrivateKey) k;
+ }
+
+ protected Object generateSignature() throws IllegalStateException
+ {
+ // 1. Apply the EMSA-PSS encoding operation to the message M to produce an
+ // encoded message EM of length CEILING((modBits ? 1)/8) octets such
+ // that the bit length of the integer OS2IP(EM) is at most modBits ? 1:
+ // EM = EMSA-PSS-Encode(M,modBits ? 1).
+ // Note that the octet length of EM will be one less than k if
+ // modBits ? 1 is divisible by 8. If the encoding operation outputs
+ // 'message too long' or 'encoding error,' then output 'message too
+ // long' or 'encoding error' and stop.
+ int modBits = ((RSAPrivateKey) privateKey).getModulus().bitLength();
+ byte[] salt = new byte[sLen];
+ this.nextRandomBytes(salt);
+ byte[] EM = pss.encode(md.digest(), modBits - 1, salt);
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("EM (sign): " + Util.toString(EM));
+ }
+ // 2. Convert the encoded message EM to an integer message representative
+ // m (see Section 1.2.2): m = OS2IP(EM).
+ BigInteger m = new BigInteger(1, EM);
+ // 3. Apply the RSASP signature primitive to the public key K and the
+ // message representative m to produce an integer signature
+ // representative s: s = RSASP(K,m).
+ BigInteger s = RSA.sign(privateKey, m);
+ // 4. Convert the signature representative s to a signature S of length k
+ // octets (see Section 1.2.1): S = I2OSP(s, k).
+ // 5. Output the signature S.
+ int k = (modBits + 7) / 8;
+ // return encodeSignature(s, k);
+ return RSA.I2OSP(s, k);
+ }
+
+ protected boolean verifySignature(Object sig) throws IllegalStateException
+ {
+ if (publicKey == null)
+ {
+ throw new IllegalStateException();
+ }
+ // byte[] S = decodeSignature(sig);
+ byte[] S = (byte[]) sig;
+ // 1. If the length of the signature S is not k octets, output 'signature
+ // invalid' and stop.
+ int modBits = ((RSAPublicKey) publicKey).getModulus().bitLength();
+ int k = (modBits + 7) / 8;
+ if (S.length != k)
+ {
+ return false;
+ }
+ // 2. Convert the signature S to an integer signature representative s:
+ // s = OS2IP(S).
+ BigInteger s = new BigInteger(1, S);
+ // 3. Apply the RSAVP verification primitive to the public key (n, e) and
+ // the signature representative s to produce an integer message
+ // representative m: m = RSAVP((n, e), s).
+ // If RSAVP outputs 'signature representative out of range,' then
+ // output 'signature invalid' and stop.
+ BigInteger m = null;
+ try
+ {
+ m = RSA.verify(publicKey, s);
+ }
+ catch (IllegalArgumentException x)
+ {
+ return false;
+ }
+ // 4. Convert the message representative m to an encoded message EM of
+ // length emLen = CEILING((modBits - 1)/8) octets, where modBits is
+ // equal to the bit length of the modulus: EM = I2OSP(m, emLen).
+ // Note that emLen will be one less than k if modBits - 1 is divisible
+ // by 8. If I2OSP outputs 'integer too large,' then output 'signature
+ // invalid' and stop.
+ int emBits = modBits - 1;
+ int emLen = (emBits + 7) / 8;
+ byte[] EM = m.toByteArray();
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("EM (verify): " + Util.toString(EM));
+ }
+ if (EM.length > emLen)
+ {
+ return false;
+ }
+ else if (EM.length < emLen)
+ {
+ byte[] newEM = new byte[emLen];
+ System.arraycopy(EM, 0, newEM, emLen - EM.length, EM.length);
+ EM = newEM;
+ }
+ // 5. Apply the EMSA-PSS decoding operation to the message M and the
+ // encoded message EM: Result = EMSA-PSS-Decode(M, EM, emBits). If
+ // Result = 'consistent,' output 'signature verified.' Otherwise,
+ // output 'signature invalid.'
+ byte[] mHash = md.digest();
+ boolean result = false;
+ try
+ {
+ result = pss.decode(mHash, EM, emBits, sLen);
+ }
+ catch (IllegalArgumentException x)
+ {
+ result = false;
+ }
+ return result;
+ }
+
+ // Other instance methods --------------------------------------------------
+
+ /**
+ * Converts the signature representative s
to a signature
+ * S
of length k
octets; i.e.
+ * S = I2OSP(s, k)
, where k = CEILING(modBits/8)
.
+ *
+ * @param s the signature representative.
+ * @param k the length of the output.
+ * @return the signature as an octet sequence.
+ * @exception IllegalArgumentException if the length in octets of meaningful
+ * bytes of s
is greater than k
, implying that
+ * s
is not less than the RSA modulus.
+ */
+ // private Object encodeSignature(BigInteger s, int k) {
+ // if (DEBUG && debuglevel > 8) {
+ // debug("s.bitLength(): "+String.valueOf(s.bitLength()));
+ // debug("k: "+String.valueOf(k));
+ // }
+ // byte[] result = s.toByteArray();
+ // if (DEBUG && debuglevel > 8) {
+ // debug("s: "+Util.toString(result));
+ // debug("s (bytes): "+String.valueOf(result.length));
+ // }
+ // if (result.length < k) {
+ // byte[] newResult = new byte[k];
+ // System.arraycopy(result, 0, newResult, k-result.length, result.length);
+ // result = newResult;
+ // } else if (result.length > k) { // leftmost extra bytes should all be 0
+ // int limit = result.length - k;
+ // for (int i = 0; i < limit; i++) {
+ // if (result[i] != 0x00) {
+ // throw new IllegalArgumentException("integer too large");
+ // }
+ // }
+ // byte[] newResult = new byte[k];
+ // System.arraycopy(result, limit, newResult, 0, k);
+ // result = newResult;
+ // }
+ // return result;
+ // }
+ /**
+ * Returns the output of a previously generated signature object as an octet
+ * sequence.
+ *
+ * @return the octet sequence S
.
+ */
+ // private byte[] decodeSignature(Object signature) {
+ // return (byte[]) signature;
+ // }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java b/libjava/classpath/gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java
new file mode 100644
index 0000000..64a972c
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java
@@ -0,0 +1,159 @@
+/* RSAPSSSignatureRawCodec.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import gnu.java.security.Registry;
+import gnu.java.security.sig.ISignatureCodec;
+
+import java.io.ByteArrayOutputStream;
+
+/**
+ *
An object that implements the {@link gnu.crypto.sig.ISignatureCodec}
+ * operations for the Raw format to use with RSA-PSS signatures.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class RSAPSSSignatureRawCodec implements ISignatureCodec
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ // implicit 0-arguments constructor
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ // gnu.crypto.keys.IKeyPairCodec interface implementation
+ // -------------------------------------------------------------------------
+
+ public int getFormatID()
+ {
+ return RAW_FORMAT;
+ }
+
+ /**
+ * Returns the encoded form of the designated RSA-PSS signature object
+ * according to the Raw format supported by this library.
+ *
+ * The Raw format for an RSA-PSS signature, in this implementation,
+ * is a byte sequence consisting of the following:
+ *
+ *
+ * - 4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_RSA_PSS_SIGNATURE},
-
+ *
- 1-byte version consisting of the constant: 0x01,
+ * - 4-byte count of following bytes representing the RSA-PSS signature
+ * bytes in internet order,
+ * - the RSA-PSS signature bytes in internet order.
+ *
+ *
+ * @param signature the signature to encode, consisting of the output of the
+ * sign()
method of a {@link RSAPSSSignature} instance --a byte
+ * array.
+ * @return the Raw format encoding of the designated signature.
+ * @exception IllegalArgumentException if the designated signature is not an
+ * RSA-PSS one.
+ */
+ public byte[] encodeSignature(Object signature)
+ {
+ byte[] buffer;
+ try
+ {
+ buffer = (byte[]) signature;
+ }
+ catch (Exception x)
+ {
+ throw new IllegalArgumentException("key");
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ // magic
+ baos.write(Registry.MAGIC_RAW_RSA_PSS_SIGNATURE[0]);
+ baos.write(Registry.MAGIC_RAW_RSA_PSS_SIGNATURE[1]);
+ baos.write(Registry.MAGIC_RAW_RSA_PSS_SIGNATURE[2]);
+ baos.write(Registry.MAGIC_RAW_RSA_PSS_SIGNATURE[3]);
+
+ // version
+ baos.write(0x01);
+
+ // signature bytes
+ int length = buffer.length;
+ baos.write(length >>> 24);
+ baos.write((length >>> 16) & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write(length & 0xFF);
+ baos.write(buffer, 0, length);
+
+ return baos.toByteArray();
+ }
+
+ public Object decodeSignature(byte[] k)
+ {
+ // magic
+ if (k[0] != Registry.MAGIC_RAW_RSA_PSS_SIGNATURE[0]
+ || k[1] != Registry.MAGIC_RAW_RSA_PSS_SIGNATURE[1]
+ || k[2] != Registry.MAGIC_RAW_RSA_PSS_SIGNATURE[2]
+ || k[3] != Registry.MAGIC_RAW_RSA_PSS_SIGNATURE[3])
+ {
+ throw new IllegalArgumentException("magic");
+ }
+
+ // version
+ if (k[4] != 0x01)
+ {
+ throw new IllegalArgumentException("version");
+ }
+
+ int i = 5;
+ int l;
+
+ // signature bytes
+ l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
+ byte[] result = new byte[l];
+ System.arraycopy(k, i, result, 0, l);
+
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/sig/rsa/RSASignatureFactory.java b/libjava/classpath/gnu/java/security/sig/rsa/RSASignatureFactory.java
new file mode 100644
index 0000000..b8e12ca
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/sig/rsa/RSASignatureFactory.java
@@ -0,0 +1,176 @@
+/* RSASignatureFactory.java -- A Factory class to instantiate RSA Signatures
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.sig.rsa;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import gnu.java.security.Registry;
+import gnu.java.security.hash.HashFactory;
+import gnu.java.security.hash.IMessageDigest;
+import gnu.java.security.sig.ISignature;
+
+/**
+ * A Factory class to instantiate RSA Signature classes.
+ */
+public class RSASignatureFactory
+{
+ private static Set names;
+
+ /**
+ * Private constructor to enforce usage through Factory (class) methods.
+ */
+ private RSASignatureFactory()
+ {
+ super();
+ }
+
+ /**
+ * Returns a new instance of an RSA Signature given its name. The name of an
+ * RSA Signature always starts with rsa-
, followed by either
+ * pss
or pkcs1_v1.5
. An optional message digest
+ * name, to be used with the RSA signature may be specified by appending the
+ * hyphen chanaracter -
followed by the canonical message digest
+ * algorithm name. When no message digest algorithm name is given, SHA-160 is
+ * used.
+ *
+ * @param name the composite RSA signature name.
+ * @return a new instance of an RSA Signature algorithm implementation.
+ * Returns null
if the given name does not correspond to any
+ * supported RSA Signature encoding and message digest combination.
+ */
+ public static final ISignature getInstance(String name)
+ {
+ if (name == null)
+ return null;
+
+ name = name.trim();
+ if (name.length() == 0)
+ return null;
+
+ name = name.toLowerCase();
+ if (! name.startsWith(Registry.RSA_SIG_PREFIX))
+ return null;
+
+ name = name.substring(Registry.RSA_SIG_PREFIX.length()).trim();
+ if (name.startsWith(Registry.RSA_PSS_ENCODING))
+ return getPSSSignature(name);
+ else if (name.startsWith(Registry.RSA_PKCS1_V1_5_ENCODING))
+ return getPKCS1Signature(name);
+ else
+ return null;
+ }
+
+ /**
+ * Returns a {@link Set} of names of RSA signatures supported by this
+ * Factory.
+ *
+ * @return a {@link Set} of RSA Signature algorithm names (Strings).
+ */
+ public static synchronized final Set getNames()
+ {
+ if (names == null)
+ {
+ Set hashNames = HashFactory.getNames();
+ HashSet hs = new HashSet();
+ for (Iterator it = hashNames.iterator(); it.hasNext();)
+ {
+ String mdName = (String) it.next();
+ hs.add(Registry.RSA_PSS_SIG + "-" + mdName);
+ }
+
+ hs.add(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.MD2_HASH);
+ hs.add(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.MD5_HASH);
+ hs.add(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.SHA160_HASH);
+ hs.add(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.SHA256_HASH);
+ hs.add(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.SHA384_HASH);
+ hs.add(Registry.RSA_PKCS1_V1_5_SIG + "-" + Registry.SHA512_HASH);
+
+ names = Collections.unmodifiableSet(hs);
+ }
+
+ return names;
+ }
+
+ private static final ISignature getPSSSignature(String name)
+ {
+ name = name.substring(Registry.RSA_PSS_ENCODING.length()).trim();
+ // remove the hyphen if found at the beginning
+ if (name.startsWith("-"))
+ name = name.substring(1).trim();
+
+ IMessageDigest md;
+ if (name.length() == 0)
+ md = HashFactory.getInstance(Registry.SHA160_HASH);
+ else
+ {
+ // check if there is such a hash
+ md = HashFactory.getInstance(name);
+ if (md == null)
+ return null;
+ }
+
+ ISignature result = new RSAPSSSignature(md, 0);
+ return result;
+ }
+
+ private static final ISignature getPKCS1Signature(String name)
+ {
+ name = name.substring(Registry.RSA_PKCS1_V1_5_ENCODING.length()).trim();
+ // remove the hyphen if found at the beginning
+ if (name.startsWith("-"))
+ name = name.substring(1).trim();
+
+ IMessageDigest md;
+ if (name.length() == 0)
+ md = HashFactory.getInstance(Registry.SHA160_HASH);
+ else
+ {
+ // check if there is such a hash
+ md = HashFactory.getInstance(name);
+ if (md == null)
+ return null;
+ }
+
+ ISignature result = new RSAPKCS1V1_5Signature(md);
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/Base64.java b/libjava/classpath/gnu/java/security/util/Base64.java
new file mode 100644
index 0000000..f9998c3
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/Base64.java
@@ -0,0 +1,396 @@
+/* Base64.java --
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Most of this implementation is from Robert Harder's public domain Base64
+ * code (version 1.4.1 available from <http://iharder.net/xmlizable>).
+ */
+public class Base64
+{
+
+ // Debugging methods and variables
+ // -------------------------------------------------------------------------
+
+ private static final String NAME = "Base64";
+
+ private static final boolean DEBUG = true;
+
+ private static final int debuglevel = 9;
+
+ private static final PrintWriter err = new PrintWriter(System.out, true);
+
+ private static void debug(String s)
+ {
+ err.println(">>> " + NAME + ": " + s);
+ }
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ /** Maximum line length (76) of Base64 output. */
+ private static final int MAX_LINE_LENGTH = 76;
+
+ /** The new line character (\n) as one byte. */
+ private static final byte NEW_LINE = (byte) '\n';
+
+ /** The equals sign (=) as a byte. */
+ private static final byte EQUALS_SIGN = (byte) '=';
+
+ private static final byte WHITE_SPACE_ENC = -5; // white space in encoding
+
+ private static final byte EQUALS_SIGN_ENC = -1; // equals sign in encoding
+
+ /** The 64 valid Base64 values. */
+ private static final byte[] ALPHABET = { (byte) 'A', (byte) 'B', (byte) 'C',
+ (byte) 'D', (byte) 'E', (byte) 'F',
+ (byte) 'G', (byte) 'H', (byte) 'I',
+ (byte) 'J', (byte) 'K', (byte) 'L',
+ (byte) 'M', (byte) 'N', (byte) 'O',
+ (byte) 'P', (byte) 'Q', (byte) 'R',
+ (byte) 'S', (byte) 'T', (byte) 'U',
+ (byte) 'V', (byte) 'W', (byte) 'X',
+ (byte) 'Y', (byte) 'Z', (byte) 'a',
+ (byte) 'b', (byte) 'c', (byte) 'd',
+ (byte) 'e', (byte) 'f', (byte) 'g',
+ (byte) 'h', (byte) 'i', (byte) 'j',
+ (byte) 'k', (byte) 'l', (byte) 'm',
+ (byte) 'n', (byte) 'o', (byte) 'p',
+ (byte) 'q', (byte) 'r', (byte) 's',
+ (byte) 't', (byte) 'u', (byte) 'v',
+ (byte) 'w', (byte) 'x', (byte) 'y',
+ (byte) 'z', (byte) '0', (byte) '1',
+ (byte) '2', (byte) '3', (byte) '4',
+ (byte) '5', (byte) '6', (byte) '7',
+ (byte) '8', (byte) '9', (byte) '+',
+ (byte) '/' };
+
+ /**
+ * Translates a Base64 value to either its 6-bit reconstruction value or a
+ * negative number indicating some other meaning.
+ */
+ private static final byte[] DECODABET = { -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
+ -5, -5, // Whitespace: Tab and Linefeed
+ -9, -9, // Decimal 11 - 12
+ -5, // Whitespace: Carriage Return
+ -9, -9, -9, -9, -9, -9, -9, -9, -9,
+ -9, -9, -9, -9, // Decimal 14 - 26
+ -9, -9, -9, -9, -9, // Decimal 27 - 31
+ -5, // Whitespace: Space
+ -9, -9, -9, -9, -9, -9, -9, -9, -9,
+ -9, // Decimal 33 - 42
+ 62, // Plus sign at decimal 43
+ -9, -9, -9, // Decimal 44 - 46
+ 63, // Slash at decimal 47
+ 52, 53, 54, 55, 56, 57, 58, 59, 60,
+ 61, // Numbers zero through nine
+ -9, -9, -9, // Decimal 58 - 60
+ -1, // Equals sign at decimal 61
+ -9, -9, -9, // Decimal 62 - 64
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, // Letters 'A' through 'N'
+ 14, 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, // Letters 'O' through 'Z'
+ -9, -9, -9, -9, -9, -9, // Decimal 91 - 96
+ 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, // Letters 'a' through 'm'
+ 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, // Letters 'n' through 'z'
+ -9, -9, -9, -9 // Decimal 123 - 126
+ };
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Trivial private ctor to enfore Singleton pattern. */
+ private Base64()
+ {
+ super();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Encodes a byte array into Base64 notation. Equivalent to calling
+ * encode(source, 0, source.length)
.
+ *
+ * @param src the data to convert.
+ */
+ public static final String encode(final byte[] src)
+ {
+ return encode(src, 0, src.length, true);
+ }
+
+ /**
+ * Encodes a byte array into Base64 notation.
+ *
+ * @param src the data to convert.
+ * @param off offset in array where conversion should begin.
+ * @param len length of data to convert.
+ * @param breakLines break lines at 80 characters or less.
+ */
+ public static final String encode(final byte[] src, final int off,
+ final int len, final boolean breakLines)
+ {
+ final int len43 = len * 4 / 3;
+ final byte[] outBuff = new byte[len43 // Main 4:3
+ + ((len % 3) > 0 ? 4 : 0) // Account for padding
+ + (breakLines ? (len43 / MAX_LINE_LENGTH)
+ : 0)]; // New lines
+ int d = 0;
+ int e = 0;
+ final int len2 = len - 2;
+ int lineLength = 0;
+ for (; d < len2; d += 3, e += 4)
+ {
+ encode3to4(src, d + off, 3, outBuff, e);
+ lineLength += 4;
+ if (breakLines && lineLength == MAX_LINE_LENGTH)
+ {
+ outBuff[e + 4] = NEW_LINE;
+ e++;
+ lineLength = 0;
+ }
+ }
+
+ if (d < len)
+ { // padding needed
+ encode3to4(src, d + off, len - d, outBuff, e);
+ e += 4;
+ }
+
+ return new String(outBuff, 0, e);
+ }
+
+ /**
+ * Decodes data from Base64 notation.
+ *
+ * @param s the string to decode.
+ * @return the decoded data.
+ */
+ public static final byte[] decode(final String s)
+ throws UnsupportedEncodingException
+ {
+ final byte[] bytes;
+ bytes = s.getBytes("US-ASCII");
+ return decode(bytes, 0, bytes.length);
+ }
+
+ /**
+ * Decodes Base64 content in byte array format and returns the decoded byte
+ * array.
+ *
+ * @param src the Base64 encoded data.
+ * @param off the offset of where to begin decoding.
+ * @param len the length of characters to decode.
+ * @return the decoded data.
+ * @throws IllegalArgumentException if src
contains an illegal
+ * Base-64 character.
+ */
+ public static byte[] decode(final byte[] src, final int off, final int len)
+ {
+ final int len34 = len * 3 / 4;
+ final byte[] outBuff = new byte[len34]; // Upper limit on size of output
+ int outBuffPosn = 0;
+ final byte[] b4 = new byte[4];
+ int b4Posn = 0;
+ int i;
+ byte sbiCrop, sbiDecode;
+ for (i = off; i < off + len; i++)
+ {
+ sbiCrop = (byte) (src[i] & 0x7F); // Only the low seven bits
+ sbiDecode = DECODABET[sbiCrop];
+ if (sbiDecode >= WHITE_SPACE_ENC)
+ { // White space, Equals sign or better
+ if (sbiDecode >= EQUALS_SIGN_ENC)
+ {
+ b4[b4Posn++] = sbiCrop;
+ if (b4Posn > 3)
+ {
+ outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn);
+ b4Posn = 0;
+ // If that was the equals sign, break out of 'for' loop
+ if (sbiCrop == EQUALS_SIGN)
+ break;
+ } // end if: quartet built
+ } // end if: equals sign or better
+ }
+ else
+ {
+ throw new IllegalArgumentException("Illegal BASE-64 character at #"
+ + i + ": " + src[i]
+ + "(decimal)");
+ }
+ }
+
+ final byte[] result = new byte[outBuffPosn];
+ System.arraycopy(outBuff, 0, result, 0, outBuffPosn);
+ return result;
+ }
+
+ /**
+ * Encodes up to three bytes of the array src
and writes
+ * the resulting four Base64 bytes to dest
. The source and
+ * destination arrays can be manipulated anywhere along their length by
+ * specifying sOffset
and dOffset
.
+ *
+ * This method does not check to make sure the arrays are large enough to
+ * accomodate sOffset + 3
for the src
array or
+ * dOffset + 4
for the dest
array. The actual
+ * number of significant bytes in the input array is given by
+ * numBytes
.
+ *
+ * @param src the array to convert.
+ * @param sOffset the index where conversion begins.
+ * @param numBytes the number of significant bytes in your array.
+ * @param dest the array to hold the conversion.
+ * @param dOffset the index where output will be put.
+ * @return the destination
array.
+ */
+ private static final byte[] encode3to4(final byte[] src, final int sOffset,
+ final int numBytes, final byte[] dest,
+ final int dOffset)
+ {
+ // 1 2 3
+ // 01234567890123456789012345678901 Bit position
+ // --------000000001111111122222222 Array position from threeBytes
+ // --------| || || || | Six bit groups to index ALPHABET
+ // >>18 >>12 >> 6 >> 0 Right shift necessary
+ // 0x3F 0x3F 0x3F Additional AND
+
+ // Create buffer with zero-padding if there are only one or two
+ // significant bytes passed in the array.
+ // We have to shift left 24 in order to flush out the 1's that appear
+ // when Java treats a value as negative that is cast from a byte to an int.
+ final int inBuff = (numBytes > 0 ? ((src[sOffset] << 24) >>> 8) : 0)
+ | (numBytes > 1 ? ((src[sOffset + 1] << 24) >>> 16) : 0)
+ | (numBytes > 2 ? ((src[sOffset + 2] << 24) >>> 24) : 0);
+ switch (numBytes)
+ {
+ case 3:
+ dest[dOffset] = ALPHABET[(inBuff >>> 18)];
+ dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
+ dest[dOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3F];
+ dest[dOffset + 3] = ALPHABET[(inBuff) & 0x3F];
+ break;
+ case 2:
+ dest[dOffset] = ALPHABET[(inBuff >>> 18)];
+ dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
+ dest[dOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3F];
+ dest[dOffset + 3] = EQUALS_SIGN;
+ break;
+ case 1:
+ dest[dOffset] = ALPHABET[(inBuff >>> 18)];
+ dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
+ dest[dOffset + 2] = EQUALS_SIGN;
+ dest[dOffset + 3] = EQUALS_SIGN;
+ break;
+ }
+ return dest;
+ }
+
+ /**
+ * Decodes four bytes from array src
and writes the
+ * resulting bytes (up to three of them) to dest
.
+ *
+ * The source and destination arrays can be manipulated anywhere along
+ * their length by specifying sOffset
and dOffset
.
+ *
+ *
+ * This method does not check to make sure your arrays are large enough
+ * to accomodate sOffset + 4
for the src
array or
+ * dOffset + 3
for the dest
array. This method
+ * returns the actual number of bytes that were converted from the Base64
+ * encoding.
+ *
+ * @param src the array to convert.
+ * @param sOffset the index where conversion begins.
+ * @param dest the array to hold the conversion.
+ * @param dOffset the index where output will be put.
+ * @return the number of decoded bytes converted.
+ */
+ private static final int decode4to3(final byte[] src, final int sOffset,
+ final byte[] dest, final int dOffset)
+ {
+ if (src[sOffset + 2] == EQUALS_SIGN)
+ { // Example: Dk==
+ final int outBuff = ((DECODABET[src[sOffset]] & 0xFF) << 18)
+ | ((DECODABET[src[sOffset + 1]] & 0xFF) << 12);
+ dest[dOffset] = (byte) (outBuff >>> 16);
+ return 1;
+ }
+
+ if (src[sOffset + 3] == EQUALS_SIGN)
+ { // Example: DkL=
+ final int outBuff = ((DECODABET[src[sOffset]] & 0xFF) << 18)
+ | ((DECODABET[src[sOffset + 1]] & 0xFF) << 12)
+ | ((DECODABET[src[sOffset + 2]] & 0xFF) << 6);
+ dest[dOffset] = (byte) (outBuff >>> 16);
+ dest[dOffset + 1] = (byte) (outBuff >>> 8);
+ return 2;
+ }
+
+ try
+ { // Example: DkLE
+ final int outBuff = ((DECODABET[src[sOffset]] & 0xFF) << 18)
+ | ((DECODABET[src[sOffset + 1]] & 0xFF) << 12)
+ | ((DECODABET[src[sOffset + 2]] & 0xFF) << 6)
+ | ((DECODABET[src[sOffset + 3]] & 0xFF));
+ dest[dOffset] = (byte) (outBuff >> 16);
+ dest[dOffset + 1] = (byte) (outBuff >> 8);
+ dest[dOffset + 2] = (byte) outBuff;
+ return 3;
+ }
+ catch (Exception x)
+ {
+ if (DEBUG && debuglevel > 8)
+ {
+ debug("" + src[sOffset] + ": " + (DECODABET[src[sOffset]]));
+ debug("" + src[sOffset + 1] + ": " + (DECODABET[src[sOffset + 1]]));
+ debug("" + src[sOffset + 2] + ": " + (DECODABET[src[sOffset + 2]]));
+ debug("" + src[sOffset + 3] + ": " + (DECODABET[src[sOffset + 3]]));
+ }
+ return -1;
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/DerUtil.java b/libjava/classpath/gnu/java/security/util/DerUtil.java
new file mode 100644
index 0000000..26232ba
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/DerUtil.java
@@ -0,0 +1,64 @@
+/* DerUtil.java -- Utility methods for DER read/write operations
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import gnu.java.security.der.DEREncodingException;
+import gnu.java.security.der.DERValue;
+
+import java.math.BigInteger;
+
+/**
+ * Utility methods for DER encoding handling.
+ */
+public abstract class DerUtil
+{
+ public static final void checkIsConstructed(DERValue v, String msg)
+ throws DEREncodingException
+ {
+ if (! v.isConstructed())
+ throw new DEREncodingException(msg);
+ }
+
+ public static final void checkIsBigInteger(DERValue v, String msg)
+ throws DEREncodingException
+ {
+ if (! (v.getValue() instanceof BigInteger))
+ throw new DEREncodingException(msg);
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/ExpirableObject.java b/libjava/classpath/gnu/java/security/util/ExpirableObject.java
new file mode 100644
index 0000000..2d44520
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/ExpirableObject.java
@@ -0,0 +1,172 @@
+/* ExpirableObject.java -- an object that is automatically destroyed.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.security.auth.DestroyFailedException;
+import javax.security.auth.Destroyable;
+
+/**
+ * The base class for objects with sensitive data that are automatically
+ * destroyed after a timeout elapses. On creation, an object that extends
+ * this class will automatically be added to a {@link Timer} object that,
+ * once a timeout elapses, will automatically call the {@link
+ * Destroyable#destroy()} method.
+ *
+ * Concrete subclasses must implement the {@link doDestroy()} method
+ * instead of {@link Destroyable#destroy()}; the behavior of that method
+ * should match exactly the behavior desired of destroy()
.
+ *
+ *
Note that if a {@link DestroyFailedException} occurs when the timeout
+ * expires, it will not be reported.
+ *
+ * @see Destroyable
+ */
+public abstract class ExpirableObject implements Destroyable
+{
+
+ // Constants and fields.
+ // -------------------------------------------------------------------------
+
+ /**
+ * The default timeout, used in the default constructor.
+ */
+ public static final long DEFAULT_TIMEOUT = 3600000L;
+
+ /**
+ * The timer that expires instances.
+ */
+ private static final Timer EXPIRER = new Timer(true);
+
+ /**
+ * A reference to the task that will destroy this object when the timeout
+ * expires.
+ */
+ private final Destroyer destroyer;
+
+ // Constructors.
+ // -------------------------------------------------------------------------
+
+ /**
+ * Create a new expirable object that will expire after one hour.
+ */
+ protected ExpirableObject()
+ {
+ this(DEFAULT_TIMEOUT);
+ }
+
+ /**
+ * Create a new expirable object that will expire after the specified
+ * timeout.
+ *
+ * @param delay The delay before expiration.
+ * @throws IllegalArgumentException If delay is negative, or if
+ * delay + System.currentTimeMillis()
is negative.
+ */
+ protected ExpirableObject(final long delay)
+ {
+ destroyer = new Destroyer(this);
+ EXPIRER.schedule(destroyer, delay);
+ }
+
+ // Instance methods.
+ // -------------------------------------------------------------------------
+
+ /**
+ * Destroys this object. This method calls {@link doDestroy}, then, if
+ * no exception is thrown, cancels the task that would destroy this object
+ * when the timeout is reached.
+ *
+ * @throws DestroyFailedException If this operation fails.
+ */
+ public final void destroy() throws DestroyFailedException
+ {
+ doDestroy();
+ destroyer.cancel();
+ }
+
+ /**
+ * Subclasses must implement this method instead of the {@link
+ * Destroyable#destroy()} method.
+ *
+ * @throws DestroyFailedException If this operation fails.
+ */
+ protected abstract void doDestroy() throws DestroyFailedException;
+
+ // Inner classes.
+ // -------------------------------------------------------------------------
+
+ /**
+ * The task that destroys the target when the timeout elapses.
+ */
+ private final class Destroyer extends TimerTask
+ {
+
+ // Fields.
+ // -----------------------------------------------------------------------
+
+ private final ExpirableObject target;
+
+ // Constructor.
+ // -----------------------------------------------------------------------
+
+ Destroyer(final ExpirableObject target)
+ {
+ super();
+ this.target = target;
+ }
+
+ // Instance methods.
+ // -----------------------------------------------------------------------
+
+ public void run()
+ {
+ try
+ {
+ if (!target.isDestroyed())
+ target.doDestroy();
+ }
+ catch (DestroyFailedException dfe)
+ {
+ }
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/FormatUtil.java b/libjava/classpath/gnu/java/security/util/FormatUtil.java
new file mode 100644
index 0000000..eed669c
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/FormatUtil.java
@@ -0,0 +1,140 @@
+/* FormatUtil.java -- Encoding and decoding format utility methods
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import gnu.java.security.Registry;
+
+/**
+ * Encoding and decoding format utility methods.
+ */
+public class FormatUtil
+{
+ /** Trivial constructor to enforce Singleton pattern. */
+ private FormatUtil()
+ {
+ super();
+ }
+
+ /**
+ * Returns the fully qualified name of the designated encoding ID.
+ *
+ * @param formatID the unique identifier of the encoding format.
+ * @return the fully qualified name of the designated format. Returns
+ * null
if no such encoding format is known.
+ */
+ public static final String getEncodingName(int formatID)
+ {
+ String result = null;
+ switch (formatID)
+ {
+ case Registry.RAW_ENCODING_ID:
+ result = Registry.RAW_ENCODING;
+ break;
+ case Registry.X509_ENCODING_ID:
+ result = Registry.X509_ENCODING;
+ break;
+ case Registry.PKCS8_ENCODING_ID:
+ result = Registry.PKCS8_ENCODING;
+ break;
+ case Registry.ASN1_ENCODING_ID:
+ result = Registry.ASN1_ENCODING;
+ break;
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns the short name of the designated encoding ID. This is used by the
+ * JCE Adapters.
+ *
+ * @param formatID the unique identifier of the encoding format.
+ * @return the short name of the designated format. Returns null
+ * if no such encoding format is known.
+ */
+ public static final String getEncodingShortName(int formatID)
+ {
+ String result = null;
+ switch (formatID)
+ {
+ case Registry.RAW_ENCODING_ID:
+ result = Registry.RAW_ENCODING_SHORT_NAME;
+ break;
+ case Registry.X509_ENCODING_ID:
+ result = Registry.X509_ENCODING_SORT_NAME;
+ break;
+ case Registry.PKCS8_ENCODING_ID:
+ result = Registry.PKCS8_ENCODING_SHORT_NAME;
+ break;
+ case Registry.ASN1_ENCODING_ID:
+ result = Registry.ASN1_ENCODING_SHORT_NAME;
+ break;
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns the identifier of the encoding format given its short name.
+ *
+ * @param name the case-insensitive canonical short name of an encoding
+ * format.
+ * @return the identifier of the designated encoding format, or 0
+ * if the name does not correspond to any known format.
+ */
+ public static final int getFormatID(String name)
+ {
+ if (name == null)
+ return 0;
+
+ name = name.trim();
+ if (name.length() == 0)
+ return 0;
+
+ int result = 0;
+ if (name.equalsIgnoreCase(Registry.RAW_ENCODING_SHORT_NAME))
+ result = Registry.RAW_ENCODING_ID;
+ else if (name.equalsIgnoreCase(Registry.X509_ENCODING_SORT_NAME))
+ result = Registry.X509_ENCODING_ID;
+ else if (name.equalsIgnoreCase(Registry.PKCS8_ENCODING_SHORT_NAME))
+ result = Registry.PKCS8_ENCODING_ID;
+
+ return result;
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/PRNG.java b/libjava/classpath/gnu/java/security/util/PRNG.java
new file mode 100644
index 0000000..138cc6b
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/PRNG.java
@@ -0,0 +1,156 @@
+/* PRNG.java -- A Utility methods for default source of randomness
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import java.util.HashMap;
+
+import gnu.java.security.prng.IRandom;
+import gnu.java.security.prng.LimitReachedException;
+import gnu.java.security.prng.MDGenerator;
+
+/**
+ * A useful hash-based (SHA) pseudo-random number generator used
+ * throughout this library.
+ *
+ * @see MDGenerator
+ */
+public class PRNG
+{
+ // Constans and fields
+ // --------------------------------------------------------------------------
+
+ /** The underlying {@link IRandom}. */
+ private IRandom delegate;
+
+ // Constructor(s)
+ // --------------------------------------------------------------------------
+
+ /**
+ * Private constructor to enforce using the Factory method.
+ *
+ * @param delegate
+ * the undelying {@link IRandom} object used.
+ */
+ private PRNG(IRandom delegate)
+ {
+ super();
+
+ this.delegate = delegate;
+ }
+
+ // Class methods
+ // --------------------------------------------------------------------------
+
+ public static final PRNG getInstance()
+ {
+ IRandom delegate = new MDGenerator();
+ try
+ {
+ HashMap map = new HashMap();
+ // initialise it with a seed
+ long t = System.currentTimeMillis();
+ byte[] seed = new byte[] {
+ (byte) (t >>> 56), (byte) (t >>> 48),
+ (byte) (t >>> 40), (byte) (t >>> 32),
+ (byte) (t >>> 24), (byte) (t >>> 16),
+ (byte) (t >>> 8), (byte) t};
+ map.put(MDGenerator.SEEED, seed);
+ delegate.init(map); // default is to use SHA-1 hash
+ }
+ catch (Exception x)
+ {
+ throw new ExceptionInInitializerError(x);
+ }
+
+ return new PRNG(delegate);
+ }
+
+ // Instance methods
+ // --------------------------------------------------------------------------
+
+ /**
+ * Completely fills the designated buffer
with random data
+ * generated by the underlying delegate.
+ *
+ * @param buffer
+ * the place holder of random bytes generated by the underlying
+ * delegate. On output, the contents of buffer
are
+ * replaced with pseudo-random data, iff the buffer
+ * size is not zero.
+ */
+ public void nextBytes(byte[] buffer)
+ {
+ nextBytes(buffer, 0, buffer.length);
+ }
+
+ /**
+ * Fills the designated buffer
, starting from byte at position
+ * offset
with, at most, length
bytes of random
+ * data generated by the underlying delegate.
+ *
+ * @see IRandom#nextBytes
+ */
+ public void nextBytes(byte[] buffer, int offset, int length)
+ {
+ try
+ {
+ delegate.nextBytes(buffer, offset, length);
+ }
+ catch (LimitReachedException x) // re-initialise with a seed
+ {
+ try
+ {
+ HashMap map = new HashMap();
+ long t = System.currentTimeMillis();
+ byte[] seed = new byte[] {
+ (byte)(t >>> 56), (byte)(t >>> 48),
+ (byte)(t >>> 40), (byte)(t >>> 32),
+ (byte)(t >>> 24), (byte)(t >>> 16),
+ (byte)(t >>> 8), (byte) t };
+ map.put(MDGenerator.SEEED, seed);
+ delegate.init(map); // default is to use SHA-1 hash
+ delegate.nextBytes(buffer, offset, length);
+ }
+ catch (Exception y)
+ {
+ throw new ExceptionInInitializerError(y);
+ }
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/Prime2.java b/libjava/classpath/gnu/java/security/util/Prime2.java
new file mode 100644
index 0000000..6e46f5f
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/Prime2.java
@@ -0,0 +1,417 @@
+/* Prime2.java --
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import java.io.PrintWriter;
+import java.lang.ref.WeakReference;
+import java.math.BigInteger;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ *
A collection of prime number related utilities used in this library.
+ */
+public class Prime2
+{
+
+ // Debugging methods and variables
+ // -------------------------------------------------------------------------
+
+ private static final String NAME = "prime";
+
+ private static final boolean DEBUG = false;
+
+ private static final int debuglevel = 5;
+
+ private static final PrintWriter err = new PrintWriter(System.out, true);
+
+ private static void debug(String s)
+ {
+ err.println(">>> " + NAME + ": " + s);
+ }
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ private static final int DEFAULT_CERTAINTY = 20; // XXX is this a good value?
+
+ private static final BigInteger ZERO = BigInteger.ZERO;
+
+ private static final BigInteger ONE = BigInteger.ONE;
+
+ private static final BigInteger TWO = BigInteger.valueOf(2L);
+
+ /**
+ * The first SMALL_PRIME primes: Algorithm P, section 1.3.2, The Art of
+ * Computer Programming, Donald E. Knuth.
+ */
+ private static final int SMALL_PRIME_COUNT = 1000;
+
+ private static final BigInteger[] SMALL_PRIME = new BigInteger[SMALL_PRIME_COUNT];
+ static
+ {
+ long time = -System.currentTimeMillis();
+ SMALL_PRIME[0] = TWO;
+ int N = 3;
+ int J = 0;
+ int prime;
+ P2: while (true)
+ {
+ SMALL_PRIME[++J] = BigInteger.valueOf(N);
+ if (J >= 999)
+ {
+ break P2;
+ }
+ P4: while (true)
+ {
+ N += 2;
+ P6: for (int K = 1; true; K++)
+ {
+ prime = SMALL_PRIME[K].intValue();
+ if ((N % prime) == 0)
+ {
+ continue P4;
+ }
+ else if ((N / prime) <= prime)
+ {
+ continue P2;
+ }
+ }
+ }
+ }
+ time += System.currentTimeMillis();
+ if (DEBUG && debuglevel > 8)
+ {
+ StringBuffer sb;
+ for (int i = 0; i < (SMALL_PRIME_COUNT / 10); i++)
+ {
+ sb = new StringBuffer();
+ for (int j = 0; j < 10; j++)
+ {
+ sb.append(String.valueOf(SMALL_PRIME[i * 10 + j])).append(" ");
+ }
+ debug(sb.toString());
+ }
+ }
+ if (DEBUG && debuglevel > 4)
+ {
+ debug("Generating first " + String.valueOf(SMALL_PRIME_COUNT)
+ + " primes took: " + String.valueOf(time) + " ms.");
+ }
+ }
+
+ private static final Map knownPrimes = new WeakHashMap();
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Trivial constructor to enforce Singleton pattern. */
+ private Prime2()
+ {
+ super();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Trial division for the first 1000 small primes.
+ *
+ * Returns true
if at least one small prime, among the first
+ * 1000 ones, was found to divide the designated number. Retuens false
+ * otherwise.
+ *
+ * @param w the number to test.
+ * @return true
if at least one small prime was found to divide
+ * the designated number.
+ */
+ public static boolean hasSmallPrimeDivisor(BigInteger w)
+ {
+ BigInteger prime;
+ for (int i = 0; i < SMALL_PRIME_COUNT; i++)
+ {
+ prime = SMALL_PRIME[i];
+ if (w.mod(prime).equals(ZERO))
+ {
+ if (DEBUG && debuglevel > 4)
+ {
+ debug(prime.toString(16) + " | " + w.toString(16) + "...");
+ }
+ return true;
+ }
+ }
+ if (DEBUG && debuglevel > 4)
+ {
+ debug(w.toString(16) + " has no small prime divisors...");
+ }
+ return false;
+ }
+
+ /**
+ * Java port of Colin Plumb primality test (Euler Criterion)
+ * implementation for a base of 2 --from bnlib-1.1 release, function
+ * primeTest() in prime.c. this is his comments.
+ *
+ * "Now, check that bn is prime. If it passes to the base 2, it's prime
+ * beyond all reasonable doubt, and everything else is just gravy, but it
+ * gives people warm fuzzies to do it.
+ *
+ * This starts with verifying Euler's criterion for a base of 2. This is
+ * the fastest pseudoprimality test that I know of, saving a modular squaring
+ * over a Fermat test, as well as being stronger. 7/8 of the time, it's as
+ * strong as a strong pseudoprimality test, too. (The exception being when
+ * bn == 1 mod 8
and 2
is a quartic residue, i.e.
+ * bn
is of the form a^2 + (8*b)^2
.) The precise
+ * series of tricks used here is not documented anywhere, so here's an
+ * explanation. Euler's criterion states that if p
is prime
+ * then a^((p-1)/2)
is congruent to Jacobi(a,p)
,
+ * modulo p
. Jacobi(a, p)
is a function which is
+ * +1
if a is a square modulo p
, and -1
+ * if it is not. For a = 2
, this is particularly simple. It's
+ * +1
if p == +/-1 (mod 8)
, and -1
if
+ * m == +/-3 (mod 8)
. If p == 3 (mod 4)
, then all
+ * a strong test does is compute 2^((p-1)/2)
. and see if it's
+ * +1
or -1
. (Euler's criterion says which
+ * it should be.) If p == 5 (mod 8)
, then 2^((p-1)/2)
+ * is -1
, so the initial step in a strong test, looking at
+ * 2^((p-1)/4)
, is wasted --you're not going to find a
+ * +/-1
before then if it is prime, and it shouldn't
+ * have either of those values if it isn't. So don't bother.
+ *
+ * The remaining case is p == 1 (mod 8)
. In this case, we
+ * expect 2^((p-1)/2) == 1 (mod p)
, so we expect that the
+ * square root of this, 2^((p-1)/4)
, will be +/-1 (mod p)
+ *
. Evaluating this saves us a modular squaring 1/4 of the time. If
+ * it's -1
, a strong pseudoprimality test would call p
+ * prime as well. Only if the result is +1
, indicating that
+ * 2
is not only a quadratic residue, but a quartic one as well,
+ * does a strong pseudoprimality test verify more things than this test does.
+ * Good enough.
+ *
+ * We could back that down another step, looking at 2^((p-1)/8)
+ * if there was a cheap way to determine if 2
were expected to
+ * be a quartic residue or not. Dirichlet proved that 2
is a
+ * quadratic residue iff p
is of the form a^2 + (8*b^2)
.
+ * All primes == 1 (mod 4)
can be expressed as a^2 +
+ * (2*b)^2
, but I see no cheap way to evaluate this condition."
+ *
+ * @param bn the number to test.
+ * @return true
iff the designated number passes Euler criterion
+ * as implemented by Colin Plumb in his bnlib version 1.1.
+ */
+ public static boolean passEulerCriterion(final BigInteger bn)
+ {
+ BigInteger bn_minus_one = bn.subtract(ONE);
+ BigInteger e = bn_minus_one;
+ // l is the 3 least-significant bits of e
+ int l = e.and(BigInteger.valueOf(7L)).intValue();
+ int j = 1; // Where to start in prime array for strong prime tests
+ BigInteger a;
+ int k;
+
+ if (l != 0)
+ {
+ e = e.shiftRight(1);
+ a = TWO.modPow(e, bn);
+ if (l == 6) // bn == 7 mod 8, expect +1
+ {
+ if (a.bitLength() != 1)
+ {
+ debugBI("Fails Euler criterion #1", bn);
+ return false; // Not prime
+ }
+ k = 1;
+ }
+ else // bn == 3 or 5 mod 8, expect -1 == bn-1
+ {
+ a = a.add(ONE);
+ if (a.compareTo(bn) != 0)
+ {
+ debugBI("Fails Euler criterion #2", bn);
+ return false; // Not prime
+ }
+ k = 1;
+ if ((l & 4) != 0) // bn == 5 mod 8, make odd for strong tests
+ {
+ e = e.shiftRight(1);
+ k = 2;
+ }
+ }
+ }
+ else // bn == 1 mod 8, expect 2^((bn-1)/4) == +/-1 mod bn
+ {
+ e = e.shiftRight(2);
+ a = TWO.modPow(e, bn);
+ if (a.bitLength() == 1)
+ j = 0; // Re-do strong prime test to base 2
+ else
+ {
+ a = a.add(ONE);
+ if (a.compareTo(bn) != 0)
+ {
+ debugBI("Fails Euler criterion #3", bn);
+ return false; // Not prime
+ }
+ }
+ // bnMakeOdd(n) = d * 2^s. Replaces n with d and returns s.
+ k = e.getLowestSetBit();
+ e = e.shiftRight(k);
+ k += 2;
+ }
+ // It's prime! Now go on to confirmation tests
+
+ // Now, e = (bn-1)/2^k is odd. k >= 1, and has a given value with
+ // probability 2^-k, so its expected value is 2. j = 1 in the usual case
+ // when the previous test was as good as a strong prime test, but 1/8 of
+ // the time, j = 0 because the strong prime test to the base 2 needs to
+ // be re-done.
+ for (int i = j; i < 7; i++) // try only the first 7 primes
+ {
+ a = SMALL_PRIME[i];
+ a = a.modPow(e, bn);
+ if (a.bitLength() == 1)
+ continue; // Passed this test
+
+ l = k;
+ while (true)
+ {
+// a = a.add(ONE);
+// if (a.compareTo(w) == 0) { // Was result bn-1?
+ if (a.compareTo(bn_minus_one) == 0) // Was result bn-1?
+ break; // Prime
+
+ if (--l == 0) // Reached end, not -1? luck?
+ {
+ debugBI("Fails Euler criterion #4", bn);
+ return false; // Failed, not prime
+ }
+ // This portion is executed, on average, once
+// a = a.subtract(ONE); // Put a back where it was
+ a = a.modPow(TWO, bn);
+ if (a.bitLength() == 1)
+ {
+ debugBI("Fails Euler criterion #5", bn);
+ return false; // Failed, not prime
+ }
+ }
+ // It worked (to the base primes[i])
+ }
+ debugBI("Passes Euler criterion", bn);
+ return true;
+ }
+
+ public static boolean isProbablePrime(BigInteger w)
+ {
+ return isProbablePrime(w, DEFAULT_CERTAINTY);
+ }
+
+ /**
+ * Wrapper around {@link BigInteger#isProbablePrime(int)} with few pre-checks.
+ *
+ * @param w the integer to test.
+ * @param certainty the certainty with which to compute the test.
+ */
+ public static boolean isProbablePrime(BigInteger w, int certainty)
+ {
+ // Nonnumbers are not prime.
+ if (w == null)
+ return false;
+
+ // eliminate trivial cases when w == 0 or 1
+ if (w.equals(ZERO) || w.equals(ONE))
+ return false;
+
+ // Test if w is a known small prime.
+ for (int i = 0; i < SMALL_PRIME_COUNT; i++)
+ if (w.equals(SMALL_PRIME[i]))
+ {
+ if (DEBUG && debuglevel > 4)
+ debug(w.toString(16) + " is a small prime");
+ return true;
+ }
+
+ // Check if it's already a known prime
+ WeakReference obj = (WeakReference) knownPrimes.get(w);
+ if (obj != null && w.equals(obj.get()))
+ {
+ if (DEBUG && debuglevel > 4)
+ debug("found in known primes");
+ return true;
+ }
+
+ // trial division with first 1000 primes
+ if (hasSmallPrimeDivisor(w))
+ {
+ if (DEBUG && debuglevel > 4)
+ debug(w.toString(16) + " has a small prime divisor. Rejected...");
+ return false;
+ }
+
+// Euler's criterion.
+// if (passEulerCriterion(w)) {
+// if (DEBUG && debuglevel > 4) {
+// debug(w.toString(16)+" passes Euler's criterion...");
+// }
+// } else {
+// if (DEBUG && debuglevel > 4) {
+// debug(w.toString(16)+" fails Euler's criterion. Rejected...");
+// }
+// return false;
+// }
+//
+// if (DEBUG && debuglevel > 4)
+// {
+// debug(w.toString(16) + " is probable prime. Accepted...");
+// }
+
+ boolean result = w.isProbablePrime(certainty);
+ if (result && certainty > 0) // store it in the known primes weak hash-map
+ knownPrimes.put(w, new WeakReference(w));
+
+ return result;
+ }
+
+ // helper methods -----------------------------------------------------------
+
+ private static final void debugBI(String msg, BigInteger bn)
+ {
+ if (DEBUG && debuglevel > 4)
+ debug("*** " + msg + ": 0x" + bn.toString(16));
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/Sequence.java b/libjava/classpath/gnu/java/security/util/Sequence.java
new file mode 100644
index 0000000..5edc794
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/Sequence.java
@@ -0,0 +1,149 @@
+/* Sequence.java -- a sequence of integers.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import java.util.AbstractList;
+import java.util.LinkedList;
+
+/**
+ * A monotonic sequence of integers in the finite field 232.
+ */
+public final class Sequence extends AbstractList
+{
+
+ // Field.
+ // ------------------------------------------------------------------------
+
+ private final Integer[] sequence;
+
+ // Constructor.
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create a sequence of integers from 0 to end, with an increment
+ * of 1. If end is less than 0, then the sequence will wrap around
+ * through all positive integers then negative integers until the end
+ * value is reached. Naturally, this will result in an enormous object,
+ * so don't do this.
+ *
+ * @param end The ending value.
+ */
+ public Sequence(int end)
+ {
+ this(0, end, 1);
+ }
+
+ /**
+ * Create a sequence of integers from start to end, with an
+ * increment of 1. If end is less than start, then the sequence
+ * will wrap around until the end value is reached. Naturally, this will
+ * result in an enormous object, so don't do this.
+ *
+ * @param start The starting value.
+ * @param end The ending value.
+ */
+ public Sequence(int start, int end)
+ {
+ this(start, end, 1);
+ }
+
+ /**
+ * Create a sequence of integers from start to end, with an
+ * increment of span. If end is less than start, then
+ * the sequence will wrap around until the end value is reached. Naturally,
+ * this will result in an enormous object, so don't do this.
+ *
+ * span can be negative, resulting in a decresing sequence.
+ *
+ *
If span is 0, then the sequence will contain {start,
+ * end} if start != end, or just the singleton
+ * start if start == end.
+ *
+ * @param start The starting value.
+ * @param end The ending value.
+ * @param span The increment value.
+ */
+ public Sequence(int start, int end, int span)
+ {
+ if (span == 0)
+ {
+ if (start != end)
+ {
+ sequence = new Integer[] { new Integer(start), new Integer(end) };
+ }
+ else
+ {
+ sequence = new Integer[] { new Integer(start) };
+ }
+ }
+ else
+ {
+ LinkedList l = new LinkedList();
+ for (int i = start; i != end; i += span)
+ {
+ l.add(new Integer(i));
+ }
+ l.add(new Integer(end));
+ sequence = (Integer[]) l.toArray(new Integer[l.size()]);
+ }
+ }
+
+ // Instance methods.
+ // ------------------------------------------------------------------------
+
+ public Object get(int index)
+ {
+ if (index < 0 || index >= size())
+ {
+ throw new IndexOutOfBoundsException("index=" + index + ", size="
+ + size());
+ }
+ return sequence[index];
+ }
+
+ public int size()
+ {
+ return sequence.length;
+ }
+
+ public Object[] toArray()
+ {
+ return (Object[]) sequence.clone();
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/SimpleList.java b/libjava/classpath/gnu/java/security/util/SimpleList.java
new file mode 100644
index 0000000..b2525c4
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/SimpleList.java
@@ -0,0 +1,171 @@
+/* SimpleList.java -- simple way to make tuples.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import java.util.AbstractList;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * A simple way to create immutable n-tuples. This class can be created with
+ * up to four elements specified via one of the constructors, or with a
+ * collection of arbitrary size.
+ */
+public final class SimpleList extends AbstractList
+{
+
+ // Fields.
+ // ------------------------------------------------------------------------
+
+ private final Object[] elements;
+
+ // Constructors.
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create a singleton list.
+ *
+ * @param e1 The first element.
+ */
+ public SimpleList(final Object element)
+ {
+ elements = new Object[1];
+ elements[0] = element;
+ }
+
+ /**
+ * Create an ordered pair (2-tuple).
+ *
+ * @param e1 The first element.
+ * @param e2 The second element.
+ */
+ public SimpleList(final Object e1, final Object e2)
+ {
+ elements = new Object[2];
+ elements[0] = e1;
+ elements[1] = e2;
+ }
+
+ /**
+ * Create a 3-tuple.
+ *
+ * @param e1 The first element.
+ * @param e2 The second element.
+ * @param e3 The third element.
+ */
+ public SimpleList(final Object e1, final Object e2, final Object e3)
+ {
+ elements = new Object[3];
+ elements[0] = e1;
+ elements[1] = e2;
+ elements[2] = e3;
+ }
+
+ /**
+ * Create a 4-tuple.
+ *
+ * @param e1 The first element.
+ * @param e2 The second element.
+ * @param e3 The third element.
+ * @param e4 The fourth element.
+ */
+ public SimpleList(final Object e1, final Object e2, final Object e3,
+ final Object e4)
+ {
+ elements = new Object[4];
+ elements[0] = e1;
+ elements[1] = e2;
+ elements[2] = e3;
+ elements[3] = e4;
+ }
+
+ /**
+ * Create the empty list.
+ */
+ public SimpleList()
+ {
+ elements = null;
+ }
+
+ /**
+ * Create an n-tuple of arbitrary size. Even if the supplied collection has
+ * no natural order, the created n-tuple will have the order that the
+ * elements are returned by the collection's iterator.
+ *
+ * @param c The collection.
+ */
+ public SimpleList(Collection c)
+ {
+ elements = new Object[c.size()];
+ int i = 0;
+ for (Iterator it = c.iterator(); it.hasNext() && i < elements.length;)
+ {
+ elements[i++] = it.next();
+ }
+ }
+
+ // Instance methods.
+ // ------------------------------------------------------------------------
+
+ public int size()
+ {
+ if (elements == null)
+ return 0;
+ return elements.length;
+ }
+
+ public Object get(int index)
+ {
+ if (elements == null)
+ {
+ throw new IndexOutOfBoundsException("list is empty");
+ }
+ if (index < 0 || index >= elements.length)
+ {
+ throw new IndexOutOfBoundsException("index=" + index + ", size="
+ + size());
+ }
+ return elements[index];
+ }
+
+ public String toString()
+ {
+ return SimpleList.class.getName() + "(" + size() + ") " + super.toString();
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/util/Util.java b/libjava/classpath/gnu/java/security/util/Util.java
new file mode 100644
index 0000000..53f8e3c
--- /dev/null
+++ b/libjava/classpath/gnu/java/security/util/Util.java
@@ -0,0 +1,692 @@
+/* Util.java -- various utility routines.
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.util;
+
+import java.math.BigInteger;
+
+/**
+ *
A collection of utility methods used throughout this project.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class Util
+{
+
+ // Constants and variables
+ // -------------------------------------------------------------------------
+
+ // Hex charset
+ private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();
+
+ // Base-64 charset
+ private static final String BASE64_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
+
+ private static final char[] BASE64_CHARSET = BASE64_CHARS.toCharArray();
+
+ // Constructor(s)
+ // -------------------------------------------------------------------------
+
+ /** Trivial constructor to enforce Singleton pattern. */
+ private Util()
+ {
+ super();
+ }
+
+ // Class methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns a string of hexadecimal digits from a byte array. Each byte is
+ * converted to 2 hex symbols; zero(es) included.
+ *
+ * This method calls the method with same name and three arguments as:
+ *
+ *
+ * toString(ba, 0, ba.length);
+ *
+ *
+ * @param ba the byte array to convert.
+ * @return a string of hexadecimal characters (two for each byte)
+ * representing the designated input byte array.
+ */
+ public static String toString(byte[] ba)
+ {
+ return toString(ba, 0, ba.length);
+ }
+
+ /**
+ * Returns a string of hexadecimal digits from a byte array, starting at
+ * offset
and consisting of length
bytes. Each byte
+ * is converted to 2 hex symbols; zero(es) included.
+ *
+ * @param ba the byte array to convert.
+ * @param offset the index from which to start considering the bytes to
+ * convert.
+ * @param length the count of bytes, starting from the designated offset to
+ * convert.
+ * @return a string of hexadecimal characters (two for each byte)
+ * representing the designated input byte sub-array.
+ */
+ public static final String toString(byte[] ba, int offset, int length)
+ {
+ char[] buf = new char[length * 2];
+ for (int i = 0, j = 0, k; i < length;)
+ {
+ k = ba[offset + i++];
+ buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
+ buf[j++] = HEX_DIGITS[k & 0x0F];
+ }
+ return new String(buf);
+ }
+
+ /**
+ * Returns a string of hexadecimal digits from a byte array. Each byte is
+ * converted to 2 hex symbols; zero(es) included. The argument is
+ * treated as a large little-endian integer and is returned as a
+ * large big-endian integer.
+ *
+ * This method calls the method with same name and three arguments as:
+ *
+ *
+ * toReversedString(ba, 0, ba.length);
+ *
+ *
+ * @param ba the byte array to convert.
+ * @return a string of hexadecimal characters (two for each byte)
+ * representing the designated input byte array.
+ */
+ public static String toReversedString(byte[] ba)
+ {
+ return toReversedString(ba, 0, ba.length);
+ }
+
+ /**
+ * Returns a string of hexadecimal digits from a byte array, starting at
+ * offset
and consisting of length
bytes. Each byte
+ * is converted to 2 hex symbols; zero(es) included.
+ *
+ * The byte array is treated as a large little-endian integer, and
+ * is returned as a large big-endian integer.
+ *
+ * @param ba the byte array to convert.
+ * @param offset the index from which to start considering the bytes to
+ * convert.
+ * @param length the count of bytes, starting from the designated offset to
+ * convert.
+ * @return a string of hexadecimal characters (two for each byte)
+ * representing the designated input byte sub-array.
+ */
+ public static final String toReversedString(byte[] ba, int offset, int length)
+ {
+ char[] buf = new char[length * 2];
+ for (int i = offset + length - 1, j = 0, k; i >= offset;)
+ {
+ k = ba[offset + i--];
+ buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
+ buf[j++] = HEX_DIGITS[k & 0x0F];
+ }
+ return new String(buf);
+ }
+
+ /**
+ * Returns a byte array from a string of hexadecimal digits.
+ *
+ * @param s a string of hexadecimal ASCII characters
+ * @return the decoded byte array from the input hexadecimal string.
+ */
+ public static byte[] toBytesFromString(String s)
+ {
+ int limit = s.length();
+ byte[] result = new byte[((limit + 1) / 2)];
+ int i = 0, j = 0;
+ if ((limit % 2) == 1)
+ {
+ result[j++] = (byte) fromDigit(s.charAt(i++));
+ }
+ while (i < limit)
+ {
+ result[j] = (byte) (fromDigit(s.charAt(i++)) << 4);
+ result[j++] |= (byte) fromDigit(s.charAt(i++));
+ }
+ return result;
+ }
+
+ /**
+ * Returns a byte array from a string of hexadecimal digits, interpreting
+ * them as a large big-endian integer and returning it as a large
+ * little-endian integer.
+ *
+ * @param s a string of hexadecimal ASCII characters
+ * @return the decoded byte array from the input hexadecimal string.
+ */
+ public static byte[] toReversedBytesFromString(String s)
+ {
+ int limit = s.length();
+ byte[] result = new byte[((limit + 1) / 2)];
+ int i = 0;
+ if ((limit % 2) == 1)
+ {
+ result[i++] = (byte) fromDigit(s.charAt(--limit));
+ }
+ while (limit > 0)
+ {
+ result[i] = (byte) fromDigit(s.charAt(--limit));
+ result[i++] |= (byte) (fromDigit(s.charAt(--limit)) << 4);
+ }
+ return result;
+ }
+
+ /**
+ * Returns a number from 0
to 15
corresponding
+ * to the designated hexadecimal digit.
+ *
+ * @param c a hexadecimal ASCII symbol.
+ */
+ public static int fromDigit(char c)
+ {
+ if (c >= '0' && c <= '9')
+ {
+ return c - '0';
+ }
+ else if (c >= 'A' && c <= 'F')
+ {
+ return c - 'A' + 10;
+ }
+ else if (c >= 'a' && c <= 'f')
+ {
+ return c - 'a' + 10;
+ }
+ else
+ throw new IllegalArgumentException("Invalid hexadecimal digit: " + c);
+ }
+
+ /**
+ * Returns a string of 8 hexadecimal digits (most significant digit first)
+ * corresponding to the unsigned integer n
.
+ *
+ * @param n the unsigned integer to convert.
+ * @return a hexadecimal string 8-character long.
+ */
+ public static String toString(int n)
+ {
+ char[] buf = new char[8];
+ for (int i = 7; i >= 0; i--)
+ {
+ buf[i] = HEX_DIGITS[n & 0x0F];
+ n >>>= 4;
+ }
+ return new String(buf);
+ }
+
+ /**
+ * Returns a string of hexadecimal digits from an integer array. Each int
+ * is converted to 4 hex symbols.
+ */
+ public static String toString(int[] ia)
+ {
+ int length = ia.length;
+ char[] buf = new char[length * 8];
+ for (int i = 0, j = 0, k; i < length; i++)
+ {
+ k = ia[i];
+ buf[j++] = HEX_DIGITS[(k >>> 28) & 0x0F];
+ buf[j++] = HEX_DIGITS[(k >>> 24) & 0x0F];
+ buf[j++] = HEX_DIGITS[(k >>> 20) & 0x0F];
+ buf[j++] = HEX_DIGITS[(k >>> 16) & 0x0F];
+ buf[j++] = HEX_DIGITS[(k >>> 12) & 0x0F];
+ buf[j++] = HEX_DIGITS[(k >>> 8) & 0x0F];
+ buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
+ buf[j++] = HEX_DIGITS[k & 0x0F];
+ }
+ return new String(buf);
+ }
+
+ /**
+ * Returns a string of 16 hexadecimal digits (most significant digit first)
+ * corresponding to the unsigned long n
.
+ *
+ * @param n the unsigned long to convert.
+ * @return a hexadecimal string 16-character long.
+ */
+ public static String toString(long n)
+ {
+ char[] b = new char[16];
+ for (int i = 15; i >= 0; i--)
+ {
+ b[i] = HEX_DIGITS[(int) (n & 0x0FL)];
+ n >>>= 4;
+ }
+ return new String(b);
+ }
+
+ /**
+ * Similar to the toString()
method except that the Unicode
+ * escape character is inserted before every pair of bytes. Useful to
+ * externalise byte arrays that will be constructed later from such strings;
+ * eg. s-box values.
+ *
+ * @throws ArrayIndexOutOfBoundsException if the length is odd.
+ */
+ public static String toUnicodeString(byte[] ba)
+ {
+ return toUnicodeString(ba, 0, ba.length);
+ }
+
+ /**
+ * Similar to the toString()
method except that the Unicode
+ * escape character is inserted before every pair of bytes. Useful to
+ * externalise byte arrays that will be constructed later from such strings;
+ * eg. s-box values.
+ *
+ * @throws ArrayIndexOutOfBoundsException if the length is odd.
+ */
+ public static final String toUnicodeString(byte[] ba, int offset, int length)
+ {
+ StringBuffer sb = new StringBuffer();
+ int i = 0;
+ int j = 0;
+ int k;
+ sb.append('\n').append("\"");
+ while (i < length)
+ {
+ sb.append("\\u");
+
+ k = ba[offset + i++];
+ sb.append(HEX_DIGITS[(k >>> 4) & 0x0F]);
+ sb.append(HEX_DIGITS[k & 0x0F]);
+
+ k = ba[offset + i++];
+ sb.append(HEX_DIGITS[(k >>> 4) & 0x0F]);
+ sb.append(HEX_DIGITS[k & 0x0F]);
+
+ if ((++j % 8) == 0)
+ {
+ sb.append("\"+").append('\n').append("\"");
+ }
+ }
+ sb.append("\"").append('\n');
+ return sb.toString();
+ }
+
+ /**
+ * Similar to the toString()
method except that the Unicode
+ * escape character is inserted before every pair of bytes. Useful to
+ * externalise integer arrays that will be constructed later from such
+ * strings; eg. s-box values.
+ *
+ * @throws ArrayIndexOutOfBoundsException if the length is not a multiple of 4.
+ */
+ public static String toUnicodeString(int[] ia)
+ {
+ StringBuffer sb = new StringBuffer();
+ int i = 0;
+ int j = 0;
+ int k;
+ sb.append('\n').append("\"");
+ while (i < ia.length)
+ {
+ k = ia[i++];
+ sb.append("\\u");
+ sb.append(HEX_DIGITS[(k >>> 28) & 0x0F]);
+ sb.append(HEX_DIGITS[(k >>> 24) & 0x0F]);
+ sb.append(HEX_DIGITS[(k >>> 20) & 0x0F]);
+ sb.append(HEX_DIGITS[(k >>> 16) & 0x0F]);
+ sb.append("\\u");
+ sb.append(HEX_DIGITS[(k >>> 12) & 0x0F]);
+ sb.append(HEX_DIGITS[(k >>> 8) & 0x0F]);
+ sb.append(HEX_DIGITS[(k >>> 4) & 0x0F]);
+ sb.append(HEX_DIGITS[k & 0x0F]);
+
+ if ((++j % 4) == 0)
+ {
+ sb.append("\"+").append('\n').append("\"");
+ }
+ }
+ sb.append("\"").append('\n');
+ return sb.toString();
+ }
+
+ public static byte[] toBytesFromUnicode(String s)
+ {
+ int limit = s.length() * 2;
+ byte[] result = new byte[limit];
+ char c;
+ for (int i = 0; i < limit; i++)
+ {
+ c = s.charAt(i >>> 1);
+ result[i] = (byte) (((i & 1) == 0) ? c >>> 8 : c);
+ }
+ return result;
+ }
+
+ /**
+ * Dumps a byte array as a string, in a format that is easy to read for
+ * debugging. The string m
is prepended to the start of each
+ * line.
+ *
+ * If offset
and length
are omitted, the whole
+ * array is used. If m
is omitted, nothing is prepended to each
+ * line.
+ *
+ * @param data the byte array to be dumped.
+ * @param offset the offset within data to start from.
+ * @param length the number of bytes to dump.
+ * @param m a string to be prepended to each line.
+ * @return a string containing the result.
+ */
+ public static String dumpString(byte[] data, int offset, int length, String m)
+ {
+ if (data == null)
+ {
+ return m + "null\n";
+ }
+ StringBuffer sb = new StringBuffer(length * 3);
+ if (length > 32)
+ {
+ sb.append(m).append("Hexadecimal dump of ").append(length).append(
+ " bytes...\n");
+ }
+ // each line will list 32 bytes in 4 groups of 8 each
+ int end = offset + length;
+ String s;
+ int l = Integer.toString(length).length();
+ if (l < 4)
+ {
+ l = 4;
+ }
+ for (; offset < end; offset += 32)
+ {
+ if (length > 32)
+ {
+ s = " " + offset;
+ sb.append(m).append(s.substring(s.length() - l)).append(": ");
+ }
+ int i = 0;
+ for (; i < 32 && offset + i + 7 < end; i += 8)
+ {
+ sb.append(toString(data, offset + i, 8)).append(' ');
+ }
+ if (i < 32)
+ {
+ for (; i < 32 && offset + i < end; i++)
+ {
+ sb.append(byteToString(data[offset + i]));
+ }
+ }
+ sb.append('\n');
+ }
+ return sb.toString();
+ }
+
+ public static String dumpString(byte[] data)
+ {
+ return (data == null) ? "null\n" : dumpString(data, 0, data.length, "");
+ }
+
+ public static String dumpString(byte[] data, String m)
+ {
+ return (data == null) ? "null\n" : dumpString(data, 0, data.length, m);
+ }
+
+ public static String dumpString(byte[] data, int offset, int length)
+ {
+ return dumpString(data, offset, length, "");
+ }
+
+ /**
+ * Returns a string of 2 hexadecimal digits (most significant digit first)
+ * corresponding to the lowest 8 bits of n
.
+ *
+ * @param n the byte value to convert.
+ * @return a string of 2 hex characters representing the input.
+ */
+ public static String byteToString(int n)
+ {
+ char[] buf = { HEX_DIGITS[(n >>> 4) & 0x0F], HEX_DIGITS[n & 0x0F] };
+ return new String(buf);
+ }
+
+ /**
+ * Converts a designated byte array to a Base-64 representation, with the
+ * exceptions that (a) leading 0-byte(s) are ignored, and (b) the character
+ * '.' (dot) shall be used instead of "+' (plus).
+ *
+ * Used by SASL password file manipulation primitives.
+ *
+ * @param buffer an arbitrary sequence of bytes to represent in Base-64.
+ * @return unpadded (without the '=' character(s)) Base-64 representation of
+ * the input.
+ */
+ public static final String toBase64(byte[] buffer)
+ {
+ int len = buffer.length, pos = len % 3;
+ byte b0 = 0, b1 = 0, b2 = 0;
+ switch (pos)
+ {
+ case 1:
+ b2 = buffer[0];
+ break;
+ case 2:
+ b1 = buffer[0];
+ b2 = buffer[1];
+ break;
+ }
+ StringBuffer sb = new StringBuffer();
+ int c;
+ boolean notleading = false;
+ do
+ {
+ c = (b0 & 0xFC) >>> 2;
+ if (notleading || c != 0)
+ {
+ sb.append(BASE64_CHARSET[c]);
+ notleading = true;
+ }
+ c = ((b0 & 0x03) << 4) | ((b1 & 0xF0) >>> 4);
+ if (notleading || c != 0)
+ {
+ sb.append(BASE64_CHARSET[c]);
+ notleading = true;
+ }
+ c = ((b1 & 0x0F) << 2) | ((b2 & 0xC0) >>> 6);
+ if (notleading || c != 0)
+ {
+ sb.append(BASE64_CHARSET[c]);
+ notleading = true;
+ }
+ c = b2 & 0x3F;
+ if (notleading || c != 0)
+ {
+ sb.append(BASE64_CHARSET[c]);
+ notleading = true;
+ }
+ if (pos >= len)
+ {
+ break;
+ }
+ else
+ {
+ try
+ {
+ b0 = buffer[pos++];
+ b1 = buffer[pos++];
+ b2 = buffer[pos++];
+ }
+ catch (ArrayIndexOutOfBoundsException x)
+ {
+ break;
+ }
+ }
+ }
+ while (true);
+
+ if (notleading)
+ {
+ return sb.toString();
+ }
+ return "0";
+ }
+
+ /**
+ * The inverse function of the above.
+ *
+ * Converts a string representing the encoding of some bytes in Base-64
+ * to their original form.
+ *
+ * @param str the Base-64 encoded representation of some byte(s).
+ * @return the bytes represented by the str
.
+ * @throws NumberFormatException if str
is null
, or
+ * str
contains an illegal Base-64 character.
+ * @see #toBase64(byte[])
+ */
+ public static final byte[] fromBase64(String str)
+ {
+ int len = str.length();
+ if (len == 0)
+ {
+ throw new NumberFormatException("Empty string");
+ }
+ byte[] a = new byte[len + 1];
+ int i, j;
+ for (i = 0; i < len; i++)
+ {
+ try
+ {
+ a[i] = (byte) BASE64_CHARS.indexOf(str.charAt(i));
+ }
+ catch (ArrayIndexOutOfBoundsException x)
+ {
+ throw new NumberFormatException("Illegal character at #" + i);
+ }
+ }
+ i = len - 1;
+ j = len;
+ try
+ {
+ while (true)
+ {
+ a[j] = a[i];
+ if (--i < 0)
+ {
+ break;
+ }
+ a[j] |= (a[i] & 0x03) << 6;
+ j--;
+ a[j] = (byte) ((a[i] & 0x3C) >>> 2);
+ if (--i < 0)
+ {
+ break;
+ }
+ a[j] |= (a[i] & 0x0F) << 4;
+ j--;
+ a[j] = (byte) ((a[i] & 0x30) >>> 4);
+ if (--i < 0)
+ {
+ break;
+ }
+ a[j] |= (a[i] << 2);
+ j--;
+ a[j] = 0;
+ if (--i < 0)
+ {
+ break;
+ }
+ }
+ }
+ catch (Exception ignored)
+ {
+ }
+
+ try
+ { // ignore leading 0-bytes
+ while (a[j] == 0)
+ {
+ j++;
+ }
+ }
+ catch (Exception x)
+ {
+ return new byte[1]; // one 0-byte
+ }
+ byte[] result = new byte[len - j + 1];
+ System.arraycopy(a, j, result, 0, len - j + 1);
+ return result;
+ }
+
+ // BigInteger utilities ----------------------------------------------------
+
+ /**
+ * Treats the input as the MSB representation of a number, and discards
+ * leading zero elements. For efficiency, the input is simply returned if no
+ * leading zeroes are found.
+ *
+ * @param n the {@link BigInteger} to trim.
+ * @return the byte array representation of the designated {@link BigInteger}
+ * with no leading 0-bytes.
+ */
+ public static final byte[] trim(BigInteger n)
+ {
+ byte[] in = n.toByteArray();
+ if (in.length == 0 || in[0] != 0)
+ {
+ return in;
+ }
+ int len = in.length;
+ int i = 1;
+ while (in[i] == 0 && i < len)
+ {
+ ++i;
+ }
+ byte[] result = new byte[len - i];
+ System.arraycopy(in, i, result, 0, len - i);
+ return result;
+ }
+
+ /**
+ * Returns a hexadecimal dump of the trimmed bytes of a {@link BigInteger}.
+ *
+ *
+ * @param x the {@link BigInteger} to display.
+ * @return the string representation of the designated {@link BigInteger}.
+ */
+ public static final String dump(BigInteger x)
+ {
+ return dumpString(trim(x));
+ }
+}
diff --git a/libjava/classpath/gnu/java/security/x509/X509Certificate.java b/libjava/classpath/gnu/java/security/x509/X509Certificate.java
index 14ac43a..cf01617 100644
--- a/libjava/classpath/gnu/java/security/x509/X509Certificate.java
+++ b/libjava/classpath/gnu/java/security/x509/X509Certificate.java
@@ -40,7 +40,6 @@ package gnu.java.security.x509;
import gnu.classpath.debug.Component;
import gnu.classpath.debug.SystemLogger;
-
import gnu.java.security.OID;
import gnu.java.security.der.BitString;
import gnu.java.security.der.DER;
@@ -88,8 +87,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
-import java.util.logging.Level;
import java.util.logging.Logger;
import javax.security.auth.x500.X500Principal;
@@ -661,10 +658,7 @@ public class X509Certificate extends java.security.cert.X509Certificate
der.skip(spki.getLength());
logger.log (Component.X509, "read subjectPublicKey == {0}", subjectKey);
- if (version > 1)
- {
- val = der.read();
- }
+ val = der.read();
if (version >= 2 && val.getTagClass() != DER.UNIVERSAL && val.getTag() == 1)
{
byte[] b = (byte[]) val.getValue();
diff --git a/libjava/classpath/gnu/java/security/x509/ext/GeneralNames.java b/libjava/classpath/gnu/java/security/x509/ext/GeneralNames.java
index e92aeda..dae94cd 100644
--- a/libjava/classpath/gnu/java/security/x509/ext/GeneralNames.java
+++ b/libjava/classpath/gnu/java/security/x509/ext/GeneralNames.java
@@ -52,6 +52,8 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import javax.security.auth.x500.X500Principal;
+
public class GeneralNames
{
@@ -81,12 +83,14 @@ public class GeneralNames
if (!nameList.isConstructed())
throw new IOException("malformed GeneralNames");
int len = 0;
+ int i = 0;
while (len < nameList.getLength())
{
DERValue name = der.read();
List namePair = new ArrayList(2);
- if (name.getTagClass() != DER.APPLICATION)
- throw new IOException("malformed GeneralName");
+ int tagClass = name.getTagClass();
+ if (tagClass != DER.CONTEXT)
+ throw new IOException("malformed GeneralName: Tag class is " + tagClass);
namePair.add(new Integer(name.getTag()));
DERValue val = null;
switch (name.getTag())
@@ -99,6 +103,15 @@ public class GeneralNames
break;
case OTHER_NAME:
+ // MUST return the encoded bytes of the OID/OctetString sequence
+ byte[] anotherName = name.getEncoded();
+ anotherName[0] = (byte) (DER.CONSTRUCTED|DER.SEQUENCE);
+ namePair.add(anotherName);
+ // DERReader goes back on Constructed things so we need to skip over them
+ DERValue skip = der.read(); // skip OID
+ skip = der.read(); // skip Octet String
+ break;
+
case EDI_PARTY_NAME:
namePair.add(name.getValue());
break;
@@ -106,7 +119,9 @@ public class GeneralNames
case DIRECTORY_NAME:
byte[] b = name.getEncoded();
b[0] = (byte) (DER.CONSTRUCTED|DER.SEQUENCE);
- namePair.add(new X500DistinguishedName(b).toString());
+ DERReader r = new DERReader (b);
+ r.read ();
+ namePair.add(new X500Principal(r.read ().getEncoded ()).toString());
break;
case IP_ADDRESS:
diff --git a/libjava/classpath/gnu/java/util/prefs/EventDispatcher.java b/libjava/classpath/gnu/java/util/prefs/EventDispatcher.java
new file mode 100644
index 0000000..feabe4d
--- /dev/null
+++ b/libjava/classpath/gnu/java/util/prefs/EventDispatcher.java
@@ -0,0 +1,112 @@
+/* EventDispatcher.java -- Dispatch events for prefs
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.util.prefs;
+
+import java.util.ArrayList;
+
+/**
+ * This is a helper class used for dispatching events for
+ * the prefs package.
+ */
+public class EventDispatcher extends Thread
+{
+ // This is a singleton class. We dispatch all events via a
+ // new Thread which is created on demand.
+ private static final Thread dispatchThread = new EventDispatcher();
+
+ // This is a queue of events to dispatch. This thread waits on
+ // the queue and when notified will remove events until the queue
+ // is empty.
+ private static final ArrayList queue = new ArrayList();
+
+ // FIXME: this thread probably ought to go in some classpath-internal
+ // ThreadGroup. But we don't have that yet.
+ private EventDispatcher()
+ {
+ setDaemon(true);
+ start();
+ }
+
+ public void run()
+ {
+ while (true)
+ {
+ Runnable r;
+ synchronized (queue)
+ {
+ while (queue.size() == 0)
+ {
+ try
+ {
+ wait();
+ }
+ catch (InterruptedException _)
+ {
+ // Ignore.
+ }
+ }
+ r = (Runnable) queue.remove(0);
+ }
+ // Invoke outside the synchronization, so that
+ // we aren't blocking other threads from posting events.
+ try
+ {
+ r.run();
+ }
+ catch (Throwable _)
+ {
+ // Ignore.
+ }
+ }
+ }
+
+ /**
+ * Add a new runnable to the event dispatch queue. The
+ * runnable will be invoked in the event dispatch queue
+ * without any locks held.
+ * @param runner the Runnable to dispatch
+ */
+ public static void dispatch(Runnable runner)
+ {
+ synchronized (queue)
+ {
+ queue.add(runner);
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/util/prefs/FileBasedFactory.java b/libjava/classpath/gnu/java/util/prefs/FileBasedFactory.java
index 70f3558..e5f24ef 100644
--- a/libjava/classpath/gnu/java/util/prefs/FileBasedFactory.java
+++ b/libjava/classpath/gnu/java/util/prefs/FileBasedFactory.java
@@ -47,11 +47,19 @@ import java.util.prefs.*;
*/
public class FileBasedFactory implements PreferencesFactory {
+ // We don't save or read any system preferences for the
+ // time being.
+ private static final Preferences systemPreferences
+ = new MemoryBasedPreferences(null, "", false);
+
+ private static final Preferences userPreferences
+ = new FileBasedPreferences();
+
public Preferences systemRoot() {
- return null;
+ return systemPreferences;
}
public Preferences userRoot() {
- return null;
+ return userPreferences;
}
}
diff --git a/libjava/classpath/gnu/java/util/prefs/FileBasedPreferences.java b/libjava/classpath/gnu/java/util/prefs/FileBasedPreferences.java
new file mode 100644
index 0000000..f7566dd
--- /dev/null
+++ b/libjava/classpath/gnu/java/util/prefs/FileBasedPreferences.java
@@ -0,0 +1,273 @@
+/* FileBasedPreferences.java -- File-based preference implementation
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.util.prefs;
+
+import gnu.classpath.SystemProperties;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.util.Properties;
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
+
+/**
+ * This is a simple file-based preference implementation which writes
+ * the preferences as properties files. A node is represented as a directory
+ * beneath the user's home directory. The preferences for the node are
+ * stored in a single properties file in that directory. Sub-nodes are
+ * stored in subdirectories. This implementation uses file locking to
+ * mediate access to the properties files.
+ */
+public class FileBasedPreferences
+ extends AbstractPreferences
+{
+ /**
+ * Name of the property file storing the data in a given directory.
+ */
+ private static final String DATA_FILE = "data.properties";
+
+ /**
+ * The directory corresponding to this preference node.
+ */
+ private File directory;
+
+ /**
+ * The file holding the data for this node.
+ */
+ private File dataFile;
+
+ /**
+ * The data in this node.
+ */
+ private Properties properties;
+
+ /**
+ * Create the root node for the file-based preferences.
+ */
+ FileBasedPreferences()
+ {
+ super(null, "");
+ String home = SystemProperties.getProperty("user.home");
+ this.directory = new File(new File(home, ".classpath"), "userPrefs");
+ this.dataFile = new File(this.directory, DATA_FILE);
+ load();
+ }
+
+ /**
+ * Create a new file-based preference object with the given parent
+ * and the given name.
+ * @param parent the parent
+ * @param name the name of this node
+ */
+ FileBasedPreferences(FileBasedPreferences parent, String name)
+ {
+ super(parent, name);
+ this.directory = new File(parent.directory, name);
+ this.dataFile = new File(this.directory, DATA_FILE);
+ load();
+ }
+
+ private void load()
+ {
+ this.properties = new Properties();
+ FileInputStream fis = null;
+ FileLock lock = null;
+ try
+ {
+ fis = new FileInputStream(this.dataFile);
+ FileChannel channel = fis.getChannel();
+ lock = channel.lock(0, Long.MAX_VALUE, true);
+ this.properties.load(fis);
+ // We release the lock and close the stream in the 'finally'
+ // clause.
+ }
+ catch (IOException _)
+ {
+ // We don't mind; this means we're making a new node.
+ newNode = true;
+ }
+ finally
+ {
+ try
+ {
+ // Release the lock and close the stream.
+ if (lock != null)
+ lock.release();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore.
+ }
+ try
+ {
+ // Close the stream.
+ if (fis != null)
+ fis.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore.
+ }
+ }
+ }
+
+ public boolean isUserNode()
+ {
+ // For now file preferences are always user nodes.
+ return true;
+ }
+
+ protected String[] childrenNamesSpi() throws BackingStoreException
+ {
+ // FIXME: security manager.
+ String[] result = directory.list(new FilenameFilter()
+ {
+ public boolean accept(File dir, String name)
+ {
+ return new File(dir, name).isDirectory();
+ }
+ });
+ if (result == null)
+ result = new String[0];
+ return result;
+ }
+
+ protected AbstractPreferences childSpi(String name)
+ {
+ return new FileBasedPreferences(this, name);
+ }
+
+ protected String[] keysSpi() throws BackingStoreException
+ {
+ return (String[]) properties.keySet().toArray(new String[0]);
+ }
+
+ protected String getSpi(String key)
+ {
+ return properties.getProperty(key);
+ }
+
+ protected void putSpi(String key, String value)
+ {
+ properties.put(key, value);
+ }
+
+ protected void removeSpi(String key)
+ {
+ properties.remove(key);
+ }
+
+ protected void flushSpi() throws BackingStoreException
+ {
+ // FIXME: security manager.
+ try
+ {
+ if (isRemoved())
+ {
+ // Delete the underlying file.
+ // FIXME: ideally we would also delete the directory
+ // if it had no subdirectories. This doesn't matter
+ // much though.
+ // FIXME: there's a strange race here if a different VM is
+ // simultaneously updating this node.
+ dataFile.delete();
+ }
+ else
+ {
+ // Write the underlying file.
+ directory.mkdirs();
+
+ FileOutputStream fos = null;
+ FileLock lock = null;
+ try
+ {
+ // Note that we let IOExceptions from the try clause
+ // propagate to the outer 'try'.
+ fos = new FileOutputStream(dataFile);
+ FileChannel channel = fos.getChannel();
+ lock = channel.lock();
+ properties.store(fos, "created by GNU Classpath FileBasedPreferences");
+ // Lock is released and file closed in the finally clause.
+ }
+ finally
+ {
+ try
+ {
+ if (lock != null)
+ lock.release();
+ }
+ catch (IOException _)
+ {
+ // Ignore.
+ }
+ try
+ {
+ if (fos != null)
+ fos.close();
+ }
+ catch (IOException _)
+ {
+ // Ignore.
+ }
+ }
+ }
+ }
+ catch (IOException ioe)
+ {
+ throw new BackingStoreException(ioe);
+ }
+ }
+
+ protected void syncSpi() throws BackingStoreException
+ {
+ // FIXME: we ought to synchronize but instead we merely flush.
+ flushSpi();
+ }
+
+ protected void removeNodeSpi() throws BackingStoreException
+ {
+ // We can simply delegate.
+ flushSpi();
+ }
+}
diff --git a/libjava/classpath/gnu/java/util/prefs/MemoryBasedFactory.java b/libjava/classpath/gnu/java/util/prefs/MemoryBasedFactory.java
index abaf001..275b879 100644
--- a/libjava/classpath/gnu/java/util/prefs/MemoryBasedFactory.java
+++ b/libjava/classpath/gnu/java/util/prefs/MemoryBasedFactory.java
@@ -40,7 +40,7 @@ package gnu.java.util.prefs;
import java.util.prefs.*;
/**
- * Memory based PreferencesFactory usefull for testing.
+ * Memory based PreferencesFactory useful for testing.
* Returns completely empty Preferences for system and user roots.
* All changes are only backed by the current instances in memory.
*
diff --git a/libjava/classpath/gnu/java/util/prefs/MemoryBasedPreferences.java b/libjava/classpath/gnu/java/util/prefs/MemoryBasedPreferences.java
index b2f321c..cccb9bf 100644
--- a/libjava/classpath/gnu/java/util/prefs/MemoryBasedPreferences.java
+++ b/libjava/classpath/gnu/java/util/prefs/MemoryBasedPreferences.java
@@ -1,5 +1,5 @@
/* MemoryBasedPreferences - A Preference node which holds all entries in memory
- Copyright (C) 2001 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -79,7 +79,7 @@ public class MemoryBasedPreferences extends AbstractPreferences {
/**
* Returns an empty array since all children names are always already
- * chached.
+ * cached.
*/
protected String[] childrenNamesSpi() throws BackingStoreException {
return new String[0];
diff --git a/libjava/classpath/gnu/java/util/prefs/NodeWriter.java b/libjava/classpath/gnu/java/util/prefs/NodeWriter.java
index 1eed9e6..c3cf8e8 100644
--- a/libjava/classpath/gnu/java/util/prefs/NodeWriter.java
+++ b/libjava/classpath/gnu/java/util/prefs/NodeWriter.java
@@ -1,5 +1,5 @@
/* NodeWriter - Writes and exports preferences nodes to files
- Copyright (C) 2001 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,6 +41,7 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.StringTokenizer;
@@ -67,23 +68,24 @@ public class NodeWriter {
private boolean subtree;
/**
- * Creates a new NodeWriter for the given preferences node and writer.
- */
- public NodeWriter(Preferences prefs, Writer w) {
- this.prefs = prefs;
- if (w instanceof BufferedWriter) {
- this.bw = (BufferedWriter) w;
- } else {
- this.bw = new BufferedWriter(w);
- }
- }
-
- /**
* Creates a new NodeWriter for the given preferences node and
* outputstream. Creates a new OutputStreamWriter.
*/
public NodeWriter(Preferences prefs, OutputStream os) {
- this(prefs, new OutputStreamWriter(os));
+ this.prefs = prefs;
+ Writer w;
+ try
+ {
+ w = new OutputStreamWriter(os, "UTF-8");
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ // Shouldn't happen, since we always have UTF-8 available.
+ InternalError ie = new InternalError("UTF-8 encoding missing");
+ ie.initCause(uee);
+ throw ie;
+ }
+ this.bw = new BufferedWriter(w);
}
/**
@@ -112,6 +114,9 @@ public class NodeWriter {
private void writeHeader() throws BackingStoreException, IOException {
bw.write("");
bw.newLine();
+ bw.write("");
+ bw.newLine();
bw.newLine();
bw.write("