summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-06-27 20:01:40 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-06-27 20:01:40 +0000
commit3b00aa20227be4b0f2314278dcea3ef3739c44aa (patch)
treef7d11ad3bf3342c619595f748dbb91b184b8324c
parent78c2fbfb5f722402791ad87028a3a5f62ed4c086 (diff)
downloadclasspath-3b00aa20227be4b0f2314278dcea3ef3739c44aa.tar.gz
2006-06-27 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD --> generics-branch for 2006/06/16 to 2006/06/27.
-rw-r--r--ChangeLog1277
-rw-r--r--NEWS16
-rw-r--r--configure.ac28
-rw-r--r--doc/vmintegration.texinfo30
-rw-r--r--examples/gnu/classpath/examples/java2d/J2dBenchmark.java1571
-rw-r--r--examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java891
-rw-r--r--examples/gnu/classpath/examples/java2d/JNIOverhead.java390
-rw-r--r--examples/gnu/classpath/examples/swing/Demo.java10
-rw-r--r--gnu/java/awt/java2d/AbstractGraphics2D.java10
-rw-r--r--gnu/java/awt/peer/gtk/CairoGraphics2D.java29
-rw-r--r--gnu/java/awt/peer/gtk/ComponentGraphics.java76
-rw-r--r--gnu/java/awt/peer/gtk/FreetypeGlyphVector.java44
-rw-r--r--gnu/java/awt/peer/gtk/GtkCheckboxPeer.java5
-rw-r--r--gnu/java/awt/peer/gtk/GtkLabelPeer.java8
-rw-r--r--gnu/java/awt/peer/gtk/GtkToolkit.java5
-rw-r--r--gnu/java/awt/peer/qt/QtGraphics.java13
-rw-r--r--gnu/java/awt/peer/qt/QtToolkit.java5
-rw-r--r--gnu/java/awt/peer/swing/SwingComponentPeer.java76
-rw-r--r--gnu/java/lang/management/ClassLoadingMXBeanImpl.java85
-rw-r--r--gnu/java/lang/management/RuntimeMXBeanImpl.java4
-rw-r--r--gnu/java/security/.cvsignore1
-rw-r--r--gnu/java/security/Configuration.java.in56
-rw-r--r--gnu/java/security/Properties.java113
-rw-r--r--gnu/java/security/Registry.java54
-rw-r--r--gnu/java/security/hash/BaseHash.java61
-rw-r--r--gnu/java/security/hash/HashFactory.java89
-rw-r--r--gnu/java/security/hash/Haval.java410
-rw-r--r--gnu/java/security/hash/IMessageDigest.java72
-rw-r--r--gnu/java/security/hash/MD2.java163
-rw-r--r--gnu/java/security/hash/MD4.java169
-rw-r--r--gnu/java/security/hash/MD5.java166
-rw-r--r--gnu/java/security/hash/RipeMD128.java148
-rw-r--r--gnu/java/security/hash/RipeMD160.java163
-rw-r--r--gnu/java/security/hash/Sha160.java141
-rw-r--r--gnu/java/security/hash/Sha256.java150
-rw-r--r--gnu/java/security/hash/Sha384.java203
-rw-r--r--gnu/java/security/hash/Sha512.java209
-rw-r--r--gnu/java/security/hash/Tiger.java1339
-rw-r--r--gnu/java/security/hash/Whirlpool.java81
-rw-r--r--gnu/java/security/jce/hash/HavalSpi.java20
-rw-r--r--gnu/java/security/jce/hash/MD2Spi.java20
-rw-r--r--gnu/java/security/jce/hash/MD4Spi.java20
-rw-r--r--gnu/java/security/jce/hash/MD5Spi.java18
-rw-r--r--gnu/java/security/jce/hash/MessageDigestAdapter.java50
-rw-r--r--gnu/java/security/jce/hash/RipeMD128Spi.java18
-rw-r--r--gnu/java/security/jce/hash/RipeMD160Spi.java18
-rw-r--r--gnu/java/security/jce/hash/Sha160Spi.java18
-rw-r--r--gnu/java/security/jce/hash/Sha256Spi.java20
-rw-r--r--gnu/java/security/jce/hash/Sha384Spi.java20
-rw-r--r--gnu/java/security/jce/hash/Sha512Spi.java20
-rw-r--r--gnu/java/security/jce/hash/TigerSpi.java20
-rw-r--r--gnu/java/security/jce/hash/WhirlpoolSpi.java18
-rw-r--r--gnu/java/security/jce/prng/HavalRandomSpi.java18
-rw-r--r--gnu/java/security/jce/prng/MD2RandomSpi.java18
-rw-r--r--gnu/java/security/jce/prng/MD4RandomSpi.java18
-rw-r--r--gnu/java/security/jce/prng/MD5RandomSpi.java18
-rw-r--r--gnu/java/security/jce/prng/RipeMD128RandomSpi.java20
-rw-r--r--gnu/java/security/jce/prng/RipeMD160RandomSpi.java18
-rw-r--r--gnu/java/security/jce/prng/SecureRandomAdapter.java53
-rw-r--r--gnu/java/security/jce/prng/Sha160RandomSpi.java18
-rw-r--r--gnu/java/security/jce/prng/Sha256RandomSpi.java20
-rw-r--r--gnu/java/security/jce/prng/Sha384RandomSpi.java20
-rw-r--r--gnu/java/security/jce/prng/Sha512RandomSpi.java20
-rw-r--r--gnu/java/security/jce/prng/TigerRandomSpi.java18
-rw-r--r--gnu/java/security/jce/prng/WhirlpoolRandomSpi.java18
-rw-r--r--gnu/java/security/jce/sig/DSSKeyFactory.java35
-rw-r--r--gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java63
-rw-r--r--gnu/java/security/jce/sig/DSSParameters.java2
-rw-r--r--gnu/java/security/jce/sig/DSSRawSignatureSpi.java22
-rw-r--r--gnu/java/security/jce/sig/EncodedKeyFactory.java60
-rw-r--r--gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java44
-rw-r--r--gnu/java/security/jce/sig/RSAKeyFactory.java50
-rw-r--r--gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java47
-rw-r--r--gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java21
-rw-r--r--gnu/java/security/jce/sig/SignatureAdapter.java71
-rw-r--r--gnu/java/security/key/IKeyPairCodec.java56
-rw-r--r--gnu/java/security/key/IKeyPairGenerator.java23
-rw-r--r--gnu/java/security/key/KeyPairCodecFactory.java2
-rw-r--r--gnu/java/security/key/KeyPairGeneratorFactory.java61
-rw-r--r--gnu/java/security/key/dss/DSSKey.java95
-rw-r--r--gnu/java/security/key/dss/DSSKeyPairGenerator.java225
-rw-r--r--gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java8
-rw-r--r--gnu/java/security/key/dss/DSSKeyPairRawCodec.java250
-rw-r--r--gnu/java/security/key/dss/DSSKeyPairX509Codec.java6
-rw-r--r--gnu/java/security/key/dss/DSSPrivateKey.java69
-rw-r--r--gnu/java/security/key/dss/DSSPublicKey.java66
-rw-r--r--gnu/java/security/key/dss/FIPS186.java108
-rw-r--r--gnu/java/security/key/rsa/GnuRSAKey.java66
-rw-r--r--gnu/java/security/key/rsa/GnuRSAPrivateKey.java91
-rw-r--r--gnu/java/security/key/rsa/GnuRSAPublicKey.java68
-rw-r--r--gnu/java/security/key/rsa/RSAKeyPairGenerator.java97
-rw-r--r--gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java17
-rw-r--r--gnu/java/security/key/rsa/RSAKeyPairRawCodec.java208
-rw-r--r--gnu/java/security/key/rsa/RSAKeyPairX509Codec.java9
-rw-r--r--gnu/java/security/pkcs/PKCS7SignedData.java2
-rw-r--r--gnu/java/security/pkcs/SignerInfo.java2
-rw-r--r--gnu/java/security/prng/BasePRNG.java39
-rw-r--r--gnu/java/security/prng/EntropySource.java1
-rw-r--r--gnu/java/security/prng/IRandom.java156
-rw-r--r--gnu/java/security/prng/LimitReachedException.java18
-rw-r--r--gnu/java/security/prng/MDGenerator.java60
-rw-r--r--gnu/java/security/prng/PRNGFactory.java40
-rw-r--r--gnu/java/security/prng/RandomEvent.java11
-rw-r--r--gnu/java/security/prng/RandomEventListener.java8
-rw-r--r--gnu/java/security/provider/Gnu.java82
-rw-r--r--gnu/java/security/provider/PKIXCertPathValidatorImpl.java208
-rw-r--r--gnu/java/security/provider/X509CertificateFactory.java61
-rw-r--r--gnu/java/security/sig/BaseSignature.java98
-rw-r--r--gnu/java/security/sig/ISignature.java109
-rw-r--r--gnu/java/security/sig/ISignatureCodec.java11
-rw-r--r--gnu/java/security/sig/SignatureFactory.java24
-rw-r--r--gnu/java/security/sig/dss/DSSSignature.java204
-rw-r--r--gnu/java/security/sig/dss/DSSSignatureRawCodec.java105
-rw-r--r--gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java142
-rw-r--r--gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java190
-rw-r--r--gnu/java/security/sig/rsa/EMSA_PSS.java189
-rw-r--r--gnu/java/security/sig/rsa/RSA.java182
-rw-r--r--gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java145
-rw-r--r--gnu/java/security/sig/rsa/RSAPSSSignature.java187
-rw-r--r--gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java79
-rw-r--r--gnu/java/security/util/Base64.java206
-rw-r--r--gnu/java/security/util/ExpirableObject.java70
-rw-r--r--gnu/java/security/util/PRNG.java31
-rw-r--r--gnu/java/security/util/Sequence.java64
-rw-r--r--gnu/java/security/util/SimpleList.java48
-rw-r--r--gnu/java/security/util/Util.java353
-rw-r--r--gnu/java/security/x509/X509CRL.java2
-rw-r--r--gnu/java/security/x509/X509CRLEntry.java2
-rw-r--r--gnu/java/security/x509/X509Certificate.java16
-rw-r--r--gnu/java/security/x509/ext/Extension.java2
-rw-r--r--gnu/java/security/x509/ext/GeneralNames.java2
-rw-r--r--gnu/java/util/prefs/GConfBasedFactory.java78
-rw-r--r--gnu/java/util/prefs/GConfBasedPreferences.java406
-rw-r--r--gnu/java/util/prefs/gconf/GConfNativePeer.java262
-rw-r--r--gnu/javax/crypto/assembly/Assembly.java109
-rw-r--r--gnu/javax/crypto/assembly/Cascade.java203
-rw-r--r--gnu/javax/crypto/assembly/CascadeStage.java22
-rw-r--r--gnu/javax/crypto/assembly/CascadeTransformer.java24
-rw-r--r--gnu/javax/crypto/assembly/DeflateTransformer.java124
-rw-r--r--gnu/javax/crypto/assembly/Direction.java30
-rw-r--r--gnu/javax/crypto/assembly/LoopbackTransformer.java20
-rw-r--r--gnu/javax/crypto/assembly/ModeStage.java33
-rw-r--r--gnu/javax/crypto/assembly/Operation.java32
-rw-r--r--gnu/javax/crypto/assembly/PaddingTransformer.java52
-rw-r--r--gnu/javax/crypto/assembly/Stage.java103
-rw-r--r--gnu/javax/crypto/assembly/Transformer.java192
-rw-r--r--gnu/javax/crypto/assembly/TransformerException.java58
-rw-r--r--gnu/javax/crypto/cipher/Anubis.java390
-rw-r--r--gnu/javax/crypto/cipher/BaseCipher.java114
-rw-r--r--gnu/javax/crypto/cipher/Blowfish.java842
-rw-r--r--gnu/javax/crypto/cipher/Cast5.java1290
-rw-r--r--gnu/javax/crypto/cipher/CipherFactory.java96
-rw-r--r--gnu/javax/crypto/cipher/DES.java756
-rw-r--r--gnu/javax/crypto/cipher/IBlockCipher.java130
-rw-r--r--gnu/javax/crypto/cipher/IBlockCipherSpi.java64
-rw-r--r--gnu/javax/crypto/cipher/Khazad.java314
-rw-r--r--gnu/javax/crypto/cipher/NullCipher.java45
-rw-r--r--gnu/javax/crypto/cipher/Rijndael.java533
-rw-r--r--gnu/javax/crypto/cipher/Serpent.java249
-rw-r--r--gnu/javax/crypto/cipher/Square.java415
-rw-r--r--gnu/javax/crypto/cipher/TripleDES.java87
-rw-r--r--gnu/javax/crypto/cipher/Twofish.java433
-rw-r--r--gnu/javax/crypto/cipher/WeakKeyException.java22
-rw-r--r--gnu/javax/crypto/jce/DiffieHellmanImpl.java5
-rw-r--r--gnu/javax/crypto/jce/GnuCrypto.java159
-rw-r--r--gnu/javax/crypto/jce/GnuSasl.java94
-rw-r--r--gnu/javax/crypto/jce/PBKDF2SecretKeyFactory.java77
-rw-r--r--gnu/javax/crypto/jce/cipher/AESSpi.java24
-rw-r--r--gnu/javax/crypto/jce/cipher/ARCFourSpi.java49
-rw-r--r--gnu/javax/crypto/jce/cipher/AnubisSpi.java7
-rw-r--r--gnu/javax/crypto/jce/cipher/BlowfishSpi.java7
-rw-r--r--gnu/javax/crypto/jce/cipher/Cast5Spi.java20
-rw-r--r--gnu/javax/crypto/jce/cipher/CipherAdapter.java250
-rw-r--r--gnu/javax/crypto/jce/cipher/DESSpi.java11
-rw-r--r--gnu/javax/crypto/jce/cipher/KhazadSpi.java7
-rw-r--r--gnu/javax/crypto/jce/cipher/NullCipherSpi.java7
-rw-r--r--gnu/javax/crypto/jce/cipher/PBES2.java513
-rw-r--r--gnu/javax/crypto/jce/cipher/RijndaelSpi.java7
-rw-r--r--gnu/javax/crypto/jce/cipher/SerpentSpi.java7
-rw-r--r--gnu/javax/crypto/jce/cipher/SquareSpi.java7
-rw-r--r--gnu/javax/crypto/jce/cipher/TripleDESSpi.java7
-rw-r--r--gnu/javax/crypto/jce/cipher/TwofishSpi.java7
-rw-r--r--gnu/javax/crypto/jce/key/AnubisKeyGeneratorImpl.java11
-rw-r--r--gnu/javax/crypto/jce/key/AnubisSecretKeyFactoryImpl.java3
-rw-r--r--gnu/javax/crypto/jce/key/BlowfishKeyGeneratorImpl.java11
-rw-r--r--gnu/javax/crypto/jce/key/BlowfishSecretKeyFactoryImpl.java3
-rw-r--r--gnu/javax/crypto/jce/key/Cast5KeyGeneratorImpl.java11
-rw-r--r--gnu/javax/crypto/jce/key/Cast5SecretKeyFactoryImpl.java3
-rw-r--r--gnu/javax/crypto/jce/key/DESKeyGeneratorImpl.java31
-rw-r--r--gnu/javax/crypto/jce/key/DESSecretKeyFactoryImpl.java28
-rw-r--r--gnu/javax/crypto/jce/key/DESedeSecretKeyFactoryImpl.java28
-rw-r--r--gnu/javax/crypto/jce/key/KhazadKeyGeneratorImpl.java12
-rw-r--r--gnu/javax/crypto/jce/key/KhazadSecretKeyFactoryImpl.java4
-rw-r--r--gnu/javax/crypto/jce/key/RijndaelKeyGeneratorImpl.java12
-rw-r--r--gnu/javax/crypto/jce/key/RijndaelSecretKeyFactoryImpl.java4
-rw-r--r--gnu/javax/crypto/jce/key/SecretKeyFactoryImpl.java34
-rw-r--r--gnu/javax/crypto/jce/key/SecretKeyGeneratorImpl.java58
-rw-r--r--gnu/javax/crypto/jce/key/SerpentKeyGeneratorImpl.java12
-rw-r--r--gnu/javax/crypto/jce/key/SerpentSecretKeyFactoryImpl.java4
-rw-r--r--gnu/javax/crypto/jce/key/SquareKeyGeneratorImpl.java12
-rw-r--r--gnu/javax/crypto/jce/key/SquareSecretKeyFactoryImpl.java4
-rw-r--r--gnu/javax/crypto/jce/key/TripleDESKeyGeneratorImpl.java12
-rw-r--r--gnu/javax/crypto/jce/key/TwofishKeyGeneratorImpl.java12
-rw-r--r--gnu/javax/crypto/jce/key/TwofishSecretKeyFactoryImpl.java4
-rw-r--r--gnu/javax/crypto/jce/keyring/GnuKeyring.java12
-rw-r--r--gnu/javax/crypto/jce/mac/HMacHavalSpi.java21
-rw-r--r--gnu/javax/crypto/jce/mac/HMacMD2Spi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/HMacMD4Spi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/HMacMD5Spi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/HMacRipeMD128Spi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/HMacRipeMD160Spi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/HMacSHA160Spi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/HMacSHA256Spi.java21
-rw-r--r--gnu/javax/crypto/jce/mac/HMacSHA384Spi.java21
-rw-r--r--gnu/javax/crypto/jce/mac/HMacSHA512Spi.java21
-rw-r--r--gnu/javax/crypto/jce/mac/HMacTigerSpi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/HMacWhirlpoolSpi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/MacAdapter.java44
-rw-r--r--gnu/javax/crypto/jce/mac/OMacAnubisImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacBlowfishImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacCast5Impl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacDESImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacImpl.java42
-rw-r--r--gnu/javax/crypto/jce/mac/OMacKhazadImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacRijndaelImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacSerpentImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacSquareImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacTripleDESImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/OMacTwofishImpl.java9
-rw-r--r--gnu/javax/crypto/jce/mac/TMMH16Spi.java16
-rw-r--r--gnu/javax/crypto/jce/mac/UHash32Spi.java7
-rw-r--r--gnu/javax/crypto/jce/mac/UMac32Spi.java22
-rw-r--r--gnu/javax/crypto/jce/params/BlockCipherParameters.java137
-rw-r--r--gnu/javax/crypto/jce/params/DEREncodingException.java5
-rw-r--r--gnu/javax/crypto/jce/params/DERReader.java35
-rw-r--r--gnu/javax/crypto/jce/params/DERWriter.java29
-rw-r--r--gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java33
-rw-r--r--gnu/javax/crypto/jce/prng/CSPRNGSpi.java35
-rw-r--r--gnu/javax/crypto/jce/prng/FortunaImpl.java26
-rw-r--r--gnu/javax/crypto/jce/prng/ICMRandomSpi.java52
-rw-r--r--gnu/javax/crypto/jce/prng/UMacRandomSpi.java55
-rw-r--r--gnu/javax/crypto/jce/sig/DHKeyFactory.java29
-rw-r--r--gnu/javax/crypto/jce/sig/DHKeyPairGeneratorSpi.java6
-rw-r--r--gnu/javax/crypto/jce/spec/BlockCipherParameterSpec.java57
-rw-r--r--gnu/javax/crypto/jce/spec/TMMHParameterSpec.java38
-rw-r--r--gnu/javax/crypto/jce/spec/UMac32ParameterSpec.java25
-rw-r--r--gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java2
-rw-r--r--gnu/javax/crypto/key/dh/RFC2631.java5
-rw-r--r--gnu/javax/crypto/key/srp6/SRPAlgorithm.java5
-rw-r--r--gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java7
-rw-r--r--gnu/javax/crypto/keyring/AuthenticatedEntry.java2
-rw-r--r--gnu/javax/crypto/keyring/EncryptedEntry.java2
-rw-r--r--gnu/javax/crypto/keyring/Entry.java2
-rw-r--r--gnu/javax/crypto/keyring/EnvelopeEntry.java2
-rw-r--r--gnu/javax/crypto/keyring/GnuPrivateKeyring.java2
-rw-r--r--gnu/javax/crypto/keyring/GnuPublicKeyring.java2
-rw-r--r--gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java4
-rw-r--r--gnu/javax/crypto/keyring/PasswordEncryptedEntry.java4
-rw-r--r--gnu/javax/crypto/keyring/PasswordProtectedEntry.java2
-rw-r--r--gnu/javax/crypto/mac/OMAC.java2
-rw-r--r--gnu/javax/crypto/mac/UHash32.java8
-rw-r--r--gnu/javax/crypto/mac/UMac32.java2
-rw-r--r--gnu/javax/crypto/mode/BaseMode.java10
-rw-r--r--gnu/javax/crypto/mode/EAX.java4
-rw-r--r--gnu/javax/crypto/pad/BasePad.java2
-rw-r--r--gnu/javax/crypto/pad/PKCS1_V1_5.java2
-rw-r--r--gnu/javax/crypto/pad/PKCS7.java2
-rw-r--r--gnu/javax/crypto/pad/TBC.java2
-rw-r--r--gnu/javax/crypto/prng/CSPRNG.java2
-rw-r--r--gnu/javax/crypto/prng/ICMGenerator.java2
-rw-r--r--gnu/javax/crypto/prng/UMacGenerator.java2
-rw-r--r--gnu/javax/crypto/sasl/SaslInputStream.java2
-rw-r--r--gnu/javax/crypto/sasl/SaslOutputStream.java2
-rw-r--r--gnu/javax/crypto/sasl/srp/KDF.java4
-rw-r--r--gnu/javax/crypto/sasl/srp/SRPClient.java2
-rw-r--r--gnu/javax/crypto/sasl/srp/SRPServer.java2
-rw-r--r--gnu/javax/imageio/gif/GIFFile.java709
-rw-r--r--gnu/javax/imageio/gif/GIFImageReader.java242
-rw-r--r--gnu/javax/imageio/gif/GIFImageReaderSpi.java122
-rw-r--r--gnu/javax/imageio/gif/GIFStream.java102
-rw-r--r--gnu/javax/net/ssl/provider/KeyPool.java13
-rw-r--r--gnu/javax/security/auth/callback/ConsoleCallbackHandler.java2
-rw-r--r--gnu/javax/security/auth/login/ConfigFileParser.java2
-rw-r--r--gnu/javax/security/auth/login/ConfigFileTokenizer.java2
-rw-r--r--gnu/javax/security/auth/login/GnuConfiguration.java38
-rw-r--r--include/Makefile.am7
-rw-r--r--include/gnu_java_awt_peer_gtk_ComponentGraphics.h2
-rw-r--r--include/gnu_java_awt_peer_gtk_GtkLabelPeer.h2
-rw-r--r--include/gnu_java_util_prefs_gconf_GConfNativePeer.h30
-rw-r--r--java/awt/Component.java142
-rw-r--r--java/awt/Container.java2
-rw-r--r--java/awt/GridBagConstraints.java139
-rw-r--r--java/awt/GridBagLayout.java217
-rw-r--r--java/awt/Insets.java7
-rw-r--r--java/awt/Label.java434
-rw-r--r--java/awt/List.java18
-rw-r--r--java/awt/Point.java13
-rw-r--r--java/awt/TextField.java10
-rw-r--r--java/awt/Toolkit.java8
-rw-r--r--java/awt/datatransfer/Clipboard.java8
-rw-r--r--java/awt/datatransfer/DataFlavor.java114
-rw-r--r--java/awt/event/KeyEvent.java21
-rw-r--r--java/awt/font/FontRenderContext.java10
-rw-r--r--java/awt/font/LineBreakMeasurer.java107
-rw-r--r--java/awt/font/TextLayout.java225
-rw-r--r--java/awt/font/TextMeasurer.java147
-rw-r--r--java/awt/image/BufferedImage.java5
-rw-r--r--java/lang/Thread.java15
-rw-r--r--java/lang/management/ClassLoadingMXBean.java103
-rw-r--r--java/lang/management/ManagementFactory.java35
-rw-r--r--java/lang/management/OperatingSystemMXBean.java2
-rw-r--r--java/lang/management/RuntimeMXBean.java2
-rw-r--r--java/lang/management/ThreadInfo.java405
-rw-r--r--java/lang/management/ThreadMXBean.java497
-rw-r--r--java/net/URL.java12
-rw-r--r--java/rmi/server/UID.java30
-rw-r--r--java/security/cert/X509CertSelector.java4
-rw-r--r--java/text/AttributedString.java11
-rw-r--r--java/util/logging/LogManager.java76
-rw-r--r--java/util/logging/LoggingMXBean.java85
-rw-r--r--javax/imageio/spi/IIORegistry.java7
-rw-r--r--javax/management/DynamicMBean.java2
-rw-r--r--javax/management/MBeanFeatureInfo.java154
-rw-r--r--javax/swing/AbstractButton.java2
-rw-r--r--javax/swing/DefaultListSelectionModel.java117
-rw-r--r--javax/swing/JComponent.java158
-rw-r--r--javax/swing/JInternalFrame.java195
-rw-r--r--javax/swing/JLabel.java350
-rw-r--r--javax/swing/JLayeredPane.java145
-rw-r--r--javax/swing/JList.java124
-rw-r--r--javax/swing/JMenu.java60
-rw-r--r--javax/swing/JSplitPane.java3
-rw-r--r--javax/swing/RepaintManager.java63
-rw-r--r--javax/swing/SizeSequence.java6
-rw-r--r--javax/swing/UIManager.java134
-rw-r--r--javax/swing/plaf/IconUIResource.java9
-rw-r--r--javax/swing/plaf/basic/BasicButtonListener.java20
-rw-r--r--javax/swing/plaf/basic/BasicButtonUI.java8
-rw-r--r--javax/swing/plaf/basic/BasicGraphicsUtils.java174
-rw-r--r--javax/swing/plaf/basic/BasicInternalFrameUI.java33
-rw-r--r--javax/swing/plaf/basic/BasicLabelUI.java72
-rw-r--r--javax/swing/plaf/basic/BasicListUI.java119
-rw-r--r--javax/swing/plaf/basic/BasicMenuItemUI.java25
-rw-r--r--javax/swing/plaf/basic/BasicMenuUI.java7
-rw-r--r--javax/swing/plaf/basic/BasicPopupMenuUI.java5
-rw-r--r--javax/swing/plaf/basic/BasicTextFieldUI.java19
-rw-r--r--javax/swing/plaf/basic/BasicTextUI.java120
-rw-r--r--javax/swing/plaf/basic/SharedUIDefaults.java13
-rw-r--r--javax/swing/plaf/metal/MetalUtils.java88
-rw-r--r--javax/swing/text/AbstractDocument.java127
-rw-r--r--javax/swing/text/DefaultCaret.java31
-rw-r--r--javax/swing/text/GapContent.java359
-rw-r--r--javax/swing/text/JTextComponent.java302
-rw-r--r--javax/swing/text/PlainDocument.java201
-rw-r--r--javax/swing/text/rtf/RTFParser.java14
-rw-r--r--javax/swing/text/rtf/RTFScanner.java28
-rw-r--r--lib/Makefile.am1
-rw-r--r--native/jni/Makefile.am9
-rw-r--r--native/jni/gconf-peer/.cvsignore6
-rw-r--r--native/jni/gconf-peer/GConfNativePeer.c518
-rw-r--r--native/jni/gconf-peer/Makefile.am14
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c10
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c2
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c31
-rw-r--r--native/plugin/Makefile.am2
-rwxr-xr-xscripts/check_jni_methods.sh3
-rw-r--r--tools/.cvsignore3
-rw-r--r--tools/gnu/classpath/tools/getopt/Parser.java8
-rw-r--r--vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java89
-rw-r--r--vm/reference/java/lang/VMThread.java12
-rw-r--r--vm/reference/java/lang/management/VMThreadInfo.java159
371 files changed, 19182 insertions, 13297 deletions
diff --git a/ChangeLog b/ChangeLog
index dc79ef573..66208011d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,1289 @@
+2006-06-27 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * java/lang/management/ThreadMXBean.java:
+ (getThreadInfo(long[])): Corrected return type.
+ (getThreadInfo(long[], int)): Likewise.
+
+2006-06-27 Mark Wielaard <mark@klomp.org>
+
+ * java/awt/datatransfer/Clipboard.java (addFlavorListener): Do
+ nothing when listener is null.
+ (removeFlavorListener): Likewise.
+
+ * java/awt/datatransfer/DataFlavor.java
+ (getRepresentationClassFromMime): Renamed to
+ getRepresentationClassFromMimeThrows.
+ (isRepresentationClassInputStream): Use Class.isAssignableFrom().
+ (isRepresentationClassSerializable): Likewise.
+ (isFlavorJavaFileListType): Likewise and check primary and
+ subtype.
+ (getParameter): Parameters are separated by semi-colons.
+ (DataFlavor(Class,String,String)): Do some sanity checks.
+ (DataFlavor(String,String,ClassLoader)): Call
+ getRepresentationClassFromMimeThrows.
+ (DataFlavor(String)): Likewise.
+ (equals(DataFlavor)): Special case primary type text and charset
+ parameter.
+
+2006-06-27 David Gilbert <david.gilbert@object-refinery.com>
+
+ * java/awt/Component.java
+ (setName): Fire required PropertyChangeEvent,
+ * java/awt/Label.java
+ (getText): Removed redundant brackets,
+ (generateName): New method (override),
+ (nextLabelNumber): New field,
+ (getUniqueLong): New method.
+
+2006-06-27 Roman Kennke <kennke@aicas.com>
+
+ * gnu/java/awt/peer/swing/SwingComponentPeer.java
+ (createImage): Delegate this to the parent.
+ (handleEvent): Only handle PAINT/UPDATE events when the
+ component is actually showing.
+ (hide): Repaint the parent after hiding a component.
+ (prepareImage): Have only one return point.
+ (setVisible): Delegate to show() and hide().
+ (createVolatileImage): Added null check to avoid NPE.
+
+2006-06-27 David Gilbert <david.gilbert@object-refinery.com>
+
+ * java/awt/Label.java: Reformatted source code.
+
+2006-06-27 Roman Kennke <kennke@aicas.com>
+
+ * java/awt/image/BufferedImage.java
+ (getSource): Use a fixed DirectColorModel to deliver the
+ RGB pixels to the ImageConsumer.
+
+2006-06-27 David Gilbert <david.gilbert@object-refinery.com>
+
+ * java/awt/Point.java
+ (setLocation(double, double)): Round to nearest integer coordinates.
+
+2006-06-27 David Gilbert <david.gilbert@object-refinery.com>
+
+ * java/awt/Component.java
+ (minSizeSet): New field,
+ (maxSize): Likewise,
+ (maxSizeSet): Likewise,
+ (isMaximumSizeSet): Implemented,
+ (isMinimumSizeSet): Likewise,
+ (isPreferredSizeSet): Likewise,
+ (setMaximumSize): Likewise,
+ (setMinimumSize): Likewise,
+ (setPreferredSize): Likewise.
+
+2006-06-27 Roman Kennke <kennke@aicas.com>
+
+ * javax/imageio/spi/IIORegistry.java
+ (IIORegistry): Added BMP codec.
+
+2006-06-27 Mark Wielaard <mark@klomp.org>
+
+ * javax/swing/JComponent.java
+ (firePropertyChange(String,char,char)): New override method.
+
+2006-06-26 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * java/lang/Thread.java:
+ (getState()): New method.
+ * java/lang/management/ClassLoadingMXBean.java:
+ Corrected class documentation.
+ * java/lang/management/ManagementFactory.java:
+ Added new temporary marked stub to get thread bean.
+ * java/lang/management/OperatingSystemMXBean.java:
+ Corrected class documentation.
+ * java/lang/management/RuntimeMXBean.java:
+ Corrected class documentation.
+ * java/lang/management/ThreadInfo.java,
+ * java/lang/management/ThreadMXBean.java:
+ New classes.
+ * vm/reference/java/lang/VMThread.java:
+ (getState()): New method.
+ * vm/reference/java/lang/management/VMThreadInfo.java:
+ New VM class.
+
+2006-06-26 Sven de Marothy <sven@physto.se>
+
+ * gnu/javax/imageio/gif/GIFFile.java
+ * gnu/javax/imageio/gif/GIFImageReader.java
+ * gnu/javax/imageio/gif/GIFImageSpi.java
+ * gnu/javax/imageio/gif/GIFStream.java
+ New files.
+ * javax/imageio/spi/IIORegistry.java: Load new GIF decoder plugin.
+
+2006-06-26 Tania Bento <tbento@redhat.com>
+
+ * java/awt/List.java
+ (List): A list should have at least 4 visible rows.
+ (replaceItem): Should throw an ArrayIndexOutOfBoundsException,
+ not an IllegalArgumentException.
+ (makeVisible): Should not throw an IllegalArgumentException if
+ the specified index is out of range.
+
+2006-06-26 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/JList.java
+ (getNextMatch): Reimplemented to perform a circular search for the
+ matching item.
+
+2006-06-26 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/JList.java
+ (init): Set default value for visibleRowCount to 8,
+ (setVisibleRowCount): Fire PropertyChangeEvent when value changes.
+
+2006-06-26 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/JList.java
+ (valueIsAdjusting): Removed,
+ (init): Removed initialization of valueIsAdjusting field,
+ (getValueIsAdjusting): Fetch value from selection model,
+ (setValueIsAdjusting): Store value in selection model.
+
+2006-06-26 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/plaf/basic/BasicListUI.java
+ (installKeyboardActions): Rewritten to fit with the
+ ActionMap/InputMap architecture.
+ (uninstallKeyboardActions): Implemented.
+ (ListAction): Made private. Added TODO for splitting
+ up this bulk Action.
+ (ListAction.ListAction): New constructor. This one
+ takes a cmd parameter to be installed as actionCommand.
+
+2006-06-26 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/java/security/key/rsa/RSAKeyPairRawCodec.java: Remove RCS Revision.
+ * gnu/javax/crypto/assembly/DeflateTransformer.java: Likewise.
+
+2006-06-26 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/javax/crypto/jce/PBKDF2SecretKeyFactory.java: Source formatting.
+ * gnu/javax/crypto/jce/GnuSasl.java: Likewise.
+ * gnu/javax/crypto/jce/GnuCrypto.java: Likewise.
+ * gnu/javax/crypto/jce/DiffieHellmanImpl.java: Likewise.
+ * gnu/javax/crypto/jce/spec/UMac32ParameterSpec.java: Likewise.
+ * gnu/javax/crypto/jce/spec/TMMHParameterSpec.java: Likewise.
+ * gnu/javax/crypto/jce/spec/BlockCipherParameterSpec.java: Likewise.
+ * gnu/javax/crypto/jce/sig/DHKeyFactory.java: Likewise.
+ * gnu/javax/crypto/jce/prng/UMacRandomSpi.java: Likewise.
+ * gnu/javax/crypto/jce/prng/ICMRandomSpi.java: Likewise.
+ * gnu/javax/crypto/jce/prng/FortunaImpl.java: Likewise.
+ * gnu/javax/crypto/jce/prng/CSPRNGSpi.java: Likewise.
+ * gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java: Likewise.
+ * gnu/javax/crypto/jce/params/DERWriter.java: Likewise.
+ * gnu/javax/crypto/jce/params/DERReader.java: Likewise.
+ * gnu/javax/crypto/jce/params/DEREncodingException.java: Likewise.
+ * gnu/javax/crypto/jce/params/BlockCipherParameters.java: Likewise.
+ * gnu/javax/crypto/jce/mac/UMac32Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/UHash32Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/TMMH16Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacTwofishImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacTripleDESImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacSquareImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacSerpentImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacRijndaelImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacKhazadImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacDESImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacCast5Impl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacBlowfishImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/OMacAnubisImpl.java: Likewise.
+ * gnu/javax/crypto/jce/mac/MacAdapter.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacWhirlpoolSpi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacTigerSpi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacSHA512Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacSHA384Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacSHA256Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacSHA160Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacRipeMD160Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacRipeMD128Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacMD5Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacMD4Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacMD2Spi.java: Likewise.
+ * gnu/javax/crypto/jce/mac/HMacHavalSpi.java: Likewise.
+ * gnu/javax/crypto/jce/keyring/GnuKeyring.java: Likewise.
+ * gnu/javax/crypto/jce/key/TwofishSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/TwofishKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/TripleDESKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/SquareSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/SquareKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/SerpentSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/SerpentKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/SecretKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/SecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/RijndaelSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/RijndaelKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/KhazadSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/KhazadKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/DESSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/DESKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/DESedeSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/Cast5SecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/Cast5KeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/BlowfishSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/BlowfishKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/AnubisSecretKeyFactoryImpl.java: Likewise.
+ * gnu/javax/crypto/jce/key/AnubisKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/TwofishSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/TripleDESSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/SquareSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/SerpentSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/RijndaelSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/PBES2.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/NullCipherSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/KhazadSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/DESSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/CipherAdapter.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/Cast5Spi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/BlowfishSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/ARCFourSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/AnubisSpi.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/AESSpi.java: Likewise.
+
+2006-06-26 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/JList.java
+ (setLayoutOrientation): Check for valid argument.
+
+2006-06-26 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/JComponent.java
+ (firePropertyChange(String,int,int)): New method. Overrides
+ Component method and makes it public.
+ (firePropertyChange(String,boolean,boolean)): Likewise.
+
+2006-06-25 Vivek Lakshmanan <vivekl@redhat.com>
+
+ * gnu/java/security/.cvsignore: New File.
+ * gnu/java/security/Configuration.java.in: New File.
+ * gnu/java/security/Properties.java: Change import from
+ gnu.classpath.Configuration to gnu.java.security.Configuration.
+ * gnu/java/security/hash/Whirlpool.java: Likewise.
+ * gnu/java/security/jce/sig/EncodedKeyFactory.java: Likewise.
+ * gnu/java/security/jce/sig/SignatureAdapter.java: Likewise.
+ * gnu/java/security/key/dss/DSSKeyPairGenerator.java: Likewise.
+ * gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java: Likewise.
+ * gnu/java/security/key/dss/DSSPrivateKey.java: Likewise.
+ * gnu/java/security/key/rsa/GnuRSAPrivateKey.java: Likewise.
+ * gnu/java/security/key/rsa/RSAKeyPairGenerator.java: Likewise.
+ * gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java: Likewise.
+ * gnu/java/security/key/rsa/RSAKeyPairX509Codec.java: Likewise.
+ * gnu/java/security/pkcs/PKCS7SignedData.java: Likewise.
+ * gnu/java/security/pkcs/SignerInfo.java: Likewise.
+ * gnu/java/security/provider/PKIXCertPathValidatorImpl.java: Likewise.
+ * gnu/java/security/sig/rsa/EMSA_PSS.java: Likewise.
+ * gnu/java/security/sig/rsa/RSAPSSSignature.java: Likewise.
+ * gnu/java/security/util/Base64.java: Likewise.
+ * gnu/java/security/x509/X509CRL.java: Likewise.
+ * gnu/java/security/x509/X509CRLEntry.java: Likewise.
+ * gnu/java/security/x509/ext/Extension.java: Likewise.
+ * gnu/javax/crypto/cipher/Anubis.java: Likewise.
+ * gnu/javax/crypto/cipher/BaseCipher.java: Likewise.
+ * gnu/javax/crypto/cipher/Khazad.java: Likewise.
+ * gnu/javax/crypto/cipher/Rijndael.java: Likewise.
+ * gnu/javax/crypto/cipher/Twofish.java: Likewise.
+ * gnu/javax/crypto/jce/keyring/GnuKeyring.java: Likewise.
+ * gnu/javax/crypto/jce/prng/ICMRandomSpi.java: Likewise.
+ * gnu/javax/crypto/jce/prng/UMacRandomSpi.java: Likewise.
+ * gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java: Likewise.
+ * gnu/javax/crypto/keyring/Entry.java: Likewise.
+ * gnu/javax/crypto/keyring/EnvelopeEntry.java: Likewise.
+ * gnu/javax/crypto/keyring/GnuPrivateKeyring.java: Likewise.
+ * gnu/javax/crypto/keyring/GnuPublicKeyring.java: Likewise.
+ * gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java: Likewise.
+ * gnu/javax/crypto/keyring/PasswordEncryptedEntry.java: Likewise.
+ * gnu/javax/crypto/mac/OMAC.java: Likewise.
+ * gnu/javax/crypto/pad/BasePad.java: Likewise.
+ * gnu/javax/crypto/pad/PKCS1_V1_5.java: Likewise.
+ * gnu/javax/crypto/pad/PKCS7.java: Likewise.
+ * gnu/javax/crypto/pad/TBC.java: Likewise.
+ * gnu/javax/crypto/prng/CSPRNG.java: Likewise.
+ * gnu/javax/crypto/sasl/SaslInputStream.java: Likewise.
+ * gnu/javax/crypto/sasl/SaslOutputStream.java: Likewise.
+ * gnu/javax/crypto/sasl/srp/SRPClient.java: Likewise.
+ * gnu/javax/crypto/sasl/srp/SRPServer.java: Likewise.
+ * gnu/javax/security/auth/login/ConfigFileParser.java: Likewise.
+ * gnu/javax/security/auth/login/ConfigFileTokenizer.java: Likewise.
+ * gnu/javax/security/auth/login/GnuConfiguration.java
+ (getAppConfigurationEntry): Change reference to
+ gnu.classpath.Configuration.DEBUG to gnu.java.security.Configuration.DEBUG.
+ (getConfigFromUserHome): Likewise.
+ (getInputStreamFromURL): Likewise.
+ (getUserHome): Likewise.
+ (init): Likewise.
+ (processSecurityProperties): Likewise.
+ (processSystemProperty): Likewise.
+ (processUserHome): Likewise.
+ * configure.ac: Add gnu/java/security/Configuration.java to AC_CONFIG_FILES list.
+ * lib/Makefile.am: Remove gnu/java/security/Configuration.java when required.
+
+
+2006-06-25 Carsten Neumann <cn-develop@gmx.net>
+
+ * javax/swing/text/DefaultCaret.java (isActive): New method.
+
+2006-06-26 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * gnu/java/lang/management/ClassLoadingMXBeanImpl.java,
+ * java/lang/management/ClassLoadingMXBean.java:
+ (getTotalLoadedClassCount()): Corrected return type.
+ (getUnloadedClassCount()): Likewise.
+ * vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java:
+ (getUnloadedClassCount()): Likewise.
+
+2006-06-25 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/javax/crypto/cipher/WeakKeyException.java: Source formatting.
+ * gnu/javax/crypto/cipher/Twofish.java: Likewise.
+ * gnu/javax/crypto/cipher/TripleDES.java: Likewise.
+ * gnu/javax/crypto/cipher/Square.java: Likewise.
+ * gnu/javax/crypto/cipher/Serpent.java: Likewise.
+ * gnu/javax/crypto/cipher/Rijndael.java: Likewise.
+ * gnu/javax/crypto/cipher/NullCipher.java: Likewise.
+ * gnu/javax/crypto/cipher/Khazad.java: Likewise.
+ * gnu/javax/crypto/cipher/IBlockCipherSpi.java: Likewise.
+ * gnu/javax/crypto/cipher/IBlockCipher.java: Likewise.
+ * gnu/javax/crypto/cipher/DES.java: Likewise.
+ * gnu/javax/crypto/cipher/CipherFactory.java: Likewise.
+ * gnu/javax/crypto/cipher/Cast5.java: Likewise.
+ * gnu/javax/crypto/cipher/Blowfish.java: Likewise.
+ * gnu/javax/crypto/cipher/BaseCipher.java: Likewise.
+ * gnu/javax/crypto/cipher/Anubis.java: Likewise.
+
+2006-06-25 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/javax/crypto/assembly/TransformerException.java: Source formatting.
+ * gnu/javax/crypto/assembly/Transformer.java: Likewise.
+ * gnu/javax/crypto/assembly/Stage.java: Likewise.
+ * gnu/javax/crypto/assembly/PaddingTransformer.java: Likewise.
+ * gnu/javax/crypto/assembly/Operation.java: Likewise.
+ * gnu/javax/crypto/assembly/ModeStage.java: Likewise.
+ * gnu/javax/crypto/assembly/LoopbackTransformer.java: Likewise.
+ * gnu/javax/crypto/assembly/Direction.java: Likewise.
+ * gnu/javax/crypto/assembly/DeflateTransformer.java: Likewise.
+ * gnu/javax/crypto/assembly/CascadeTransformer.java: Likewise.
+ * gnu/javax/crypto/assembly/CascadeStage.java: Likewise.
+ * gnu/javax/crypto/assembly/Cascade.java: Likewise.
+ * gnu/javax/crypto/assembly/Assembly.java: Likewise.
+
+2006-06-24 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * NEWS,
+ * doc/vmintegration.texinfo:
+ Updated with information on new VM interface.
+ * gnu/java/lang/management/ClassLoadingMXBeanImpl.java,
+ * java/lang/management/ClassLoadingMXBean.java:
+ New files implementing the class loading bean.
+ * java/lang/management/ManagementFactory.java:
+ (getClassLoadingMXBean()): Implemented.
+ * vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java:
+ New VM interface file.
+
+2006-06-24 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * gnu/java/lang/management/RuntimeMXBeanImpl.java:
+ (isBootClassPathSupported()): Use SystemProperties
+ rather than System.getProperty.
+
+2006-06-24 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/java/security/Properties.java: Source formatting.
+ * gnu/java/security/Registry.java: Likewise.
+
+2006-06-24 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/java/security/util/Util.java: Source formatting.
+ * gnu/java/security/util/SimpleList.java: Likewise.
+ * gnu/java/security/util/Sequence.java: Likewise.
+ * gnu/java/security/util/PRNG.java: Likewise.
+ * gnu/java/security/util/ExpirableObject.java: Likewise.
+ * gnu/java/security/util/Base64.java: Likewise.
+ * gnu/java/security/sig/SignatureFactory.java: Likewise.
+ * gnu/java/security/sig/ISignatureCodec.java: Likewise.
+ * gnu/java/security/sig/ISignature.java: Likewise.
+ * gnu/java/security/sig/BaseSignature.java: Likewise.
+ * gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java: Likewise.
+ * gnu/java/security/sig/rsa/RSAPSSSignature.java: Likewise.
+ * gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java: Likewise.
+ * gnu/java/security/sig/rsa/RSA.java: Likewise.
+ * gnu/java/security/sig/rsa/EMSA_PSS.java: Likewise.
+ * gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java: Likewise.
+ * gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java: Likewise.
+ * gnu/java/security/sig/dss/DSSSignatureRawCodec.java: Likewise.
+ * gnu/java/security/sig/dss/DSSSignature.java: Likewise.
+ * gnu/java/security/provider/X509CertificateFactory.java: Likewise.
+ * gnu/java/security/provider/PKIXCertPathValidatorImpl.java: Likewise.
+ * gnu/java/security/provider/Gnu.java: Likewise.
+ * gnu/java/security/prng/RandomEventListener.java: Likewise.
+ * gnu/java/security/prng/RandomEvent.java: Likewise.
+ * gnu/java/security/prng/PRNGFactory.java: Likewise.
+ * gnu/java/security/prng/MDGenerator.java: Likewise.
+ * gnu/java/security/prng/LimitReachedException.java: Likewise.
+ * gnu/java/security/prng/IRandom.java: Likewise.
+ * gnu/java/security/prng/EntropySource.java: Likewise.
+ * gnu/java/security/prng/BasePRNG.java: Likewise.
+
+2006-06-23 Francis Kung <fkung@redhat.com>
+
+ * examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java
+ (Harness.actionPerformed): Process additional options.
+ (J2dBenchmarkWrapper): Defer init call until after options are processed.
+ (J2dBenchmarkWrapper.setAlias): New method.
+ (J2dBenchmarkWrapper.setComposite): New method.
+ (J2dBenchmarkWrapper.setFill): New method.
+ (J2dBenchmarkWrapper.setRotation): New method.
+ (J2dBenchmarkWrapper.setShear): New method.
+ (J2dBenchmarkWrapper.setStroke): New method.
+ (J2dBenchmarkWrapper.setTranslation): New method.
+ (run): Add additional options to GUI.
+ * examples/gnu/classpath/examples/java2d/J2dBenchmark.java:
+ Added protected fields for various options.
+ (GraphicsTest.runSet_noClipping): Reset graphics settings between tests.
+ (GraphicsTest.runSet_withClipping): Reset graphics settings between tests.
+ (GraphicsTest.runSet_zeroClipping): Reset graphics settings between tests.
+ (getNextColor): Renamed to setRandom.
+ (init): Load additional image for texturing if needed.
+ (loadBufferedImage): New method.
+ (main): Accept additional command-line switches.
+ (prepareGraphics): New method.
+ (resetGraphics): New method.
+ (runTestSuite): Accept additional image-processing options.
+ (setRandom): Renamed from getNextColor; generate various random options
+ (test_drawArc): Rename getNextColor to setRandom.
+ (test_drawCubic): Likewise.
+ (test_drawEllipse): Likewise.
+ (test_drawGeneralPath): Likewise.
+ (test_drawImage): Likewise.
+ (test_drawLine): Likewise.
+ (test_drawQuadCurve): Likewise.
+ (test_drawRectangle): Likewise.
+ (test_drawRoundRectangle): Likewise.
+ (test_drawTransparentImage): Likewise.
+ (test_fillArc): Rename getNextColor to setRandom.
+ (test_fillEllipse): Likewise.
+ (test_fillGeneralPath): Likewise.
+ (test_fillRectangle): Likewise.
+ (test_fillRoundRectangle): Likewise.
+ (TestRecorder.getAverage): Round the average time.
+
+2006-06-23 Tom Tromey <tromey@redhat.com>
+
+ * java/util/logging/LoggingMXBean.java: New file.
+ * java/util/logging/LogManager.java (LOGGING_MXBEAN_NAME): New field.
+ (loggingBean): New field.
+ (getLoggingMXBean): New method.
+
+2006-06-23 Tania Bento <tbento@redhat.com>
+
+ * java/awt/TextField.java
+ (TextField): Default number of columns should be 0, not 1.
+ (TextField): Check if number of columns given as argument
+ is valid (>= 0) and set the number of columns accordingly.
+ (TextField): Check if the string passed is null. If it is,
+ set columns to 0, else columns is set to the length of
+ the string.
+
+2006-06-23 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/plaf/basic/BasicInternalFrameUI.java
+ (InternalFramePropertyChangeListener.propertyChange):
+ Don't call getPropertyName() repeatedly. Added null checks
+ to avoid NPEs. Call closeFrame() if the closed property
+ changes.
+
+2006-06-23 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/JInternalFrame.java
+ (maxTransition): Removed.
+ (JInternalFrame): Set maxium=false. Initialize desktopIcon here.
+ Don't initialize storedBounds here.
+ (dipose): Rewritten to correctly dispose the JInternalFrame.
+ (getDesktopIcon): Don't initialize desktopIcon here.
+ (getLayer): Delegate to JLayeredPane.getLayer().
+ (getNormalBounds): Return bounds when storedBounds == null,
+ otherwise storedBounds.
+ (hide): Don't change selection. Also hide the desktopIcon.
+ (moveToBack): Call getParent() only once.
+ (moveToFront): Call getParent() only once.
+ (pack): Call validate() to make sure that the layout is
+ propagated to the children.
+ (setClosed): Fire InternalFrameEvent first, before the
+ PropertyVetoEvent.
+ (setJMenuBar): Fire PropertyChangeEvent for this property.
+ (setLayer): Delegate to JLayeredPane.
+ (setLayeredPane): Check for null and throw IllegalArgumenException.
+ (setMaximum): Remove handling of maxTransition and normalBounds.
+ Should probably be done in the UI.
+ (setNormalBounds): Store Rectangle object directly, not a copy.
+ (setRootPane): Go into rootPaneCheckingEnabled mode so that
+ adding the RootPane doesn't add it to the contentPane.
+ Fire PropertyChangeEvent.
+ (setSelected): Added condition for when this property must not
+ be changed.
+ (show): Don't ask the DesktopPane to select the frame. Moved
+ code around to fire InternalFrameEvent before actually calling
+ super.show(). Also make the desktopIcon visible.
+ (setTitle): Fire PropertyChangeEvent unconditionally.
+
+2006-06-23 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/JLayeredPane.java
+ (getPosition): Moved code around to avoid unnecessary method calls.
+ (setPosition): Delegate to setLayer().
+ (insertIndexForLayer(int,int)): Delegate to new private helper method.
+ (insertIndexForLayer(Component,int,int)): New helper method
+ to support the use of setComponentZOrder() which doesn't remove
+ the component and thus the insertIndexForLayer must ignore
+ the component to be moved to get the index right.
+ (setLayer): Added check to prevent unnecessary execution of
+ method body. Changed to update the component order here.
+ Added repaint() to make sure that the update becomes visible.
+ (addImpl): Call setLayer() only when a constraint has been specified.
+ Validate and repaint the JLayeredPane.
+
+2006-06-23 Roman Kennke <kennke@aicas.com>
+
+ * java/awt/Container.java
+ (getComponentZOrder): Use ncomponents instead of
+ component.length so that we don't consider the empty space
+ after the last component.
+
+2006-06-22 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/JComponent.java
+ (vetoableChangeSupport): New field.
+ (removeVetoableChangeListener): Rewritten to use
+ vetoableChangeSupport.
+ (addVetoableChangeListener): Rewritten to use
+ vetoableChangeSupport.
+ (fireVetoableChange): Rewritten to use
+ vetoableChangeSupport.
+ (addPropertyChangeListener): Removed. This is handled in
+ Component already.
+ (firePropertyChange(String,boolean,boolean)): Likewise.
+ (firePropertyChange(String,char,char)): Likewise.
+ (firePropertyChange(String,int,int)): Likewise.
+ (revalidate): Don't do anything when the commponent has no
+ parent.
+
+2006-06-22 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/JLabel.java: Updated API docs.
+
+2006-06-22 Robert Schuster <robertschuster@fsfe.org>
+
+ * java/awt/Insets.java: Updated copyright year.
+ (toString): Changed string, removed a line from the
+ documentation.
+
+2006-06-22 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/text/AbstractDocument.java
+ (AbstractDocument): Set the i18n document property.
+ (removeImpl): Added checks for correct boundaries.
+
+2006-06-22 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/text/PlainDocument.java
+ (rootElement): Changed type to Element.
+ (tabSize): Removed field. This is stored in the document properties
+ instead.
+ (PlainDocument): Set tabSize property. Init rootElement without
+ cast.
+ (insertUpdate): Rewritten. The previous implementation did not
+ handle some corner cases properly and was a mess.
+ (removeUpdate): Cast rootElement to BranchElement.
+
+2006-06-22 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/plaf/basic/BasicLabelUI.java
+ (installKeyboardActions): Implemented,
+ (uninstallKeyboardActions): Implemented,
+ (propertyChange): Add handling for 'displayedMnemonic' and 'labelFor'
+ properties.
+
+2006-06-22 Robert Schuster <robertschuster@fsfe.org>
+
+ * javax/swing/JMenu.java:
+ (removeAll): Added check for popupMenu not being null.
+
+2006-06-22 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/JLabel.java
+ (getText): Updated API docs,
+ (setText): Corrected the check for an unchanged value, and the update
+ of the displayedMnemonicIndex.
+
+2006-06-22 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/JLabel.java
+ (setDisplayedMnemonic(int)): Fire property change event AFTER updating
+ field,
+ (setDisplayedMnemonicIndex): Modified argument checking to handle case
+ where label text is null.
+
+2006-06-22 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/JLabel.java
+ (setDisplayedMnemonic): Updated API docs,
+ (getDisplayedMnemonic): Removed unnecessary type-cast,
+ (setDisplayedMnemonicIndex): Removed unnecessary validation,
+ (getDisplayedMnemonicIndex): Updated API docs.
+
2006-06-21 Jeroen Frijters <jeroen@frijters.net>
* java/util/Collections (entrySet): Fixed compile error.
+2006-06-21 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/DefaultListSelectionModel.java
+ (getSelectionMode): Updated API docs,
+ (setAnchorSelectionIndex): Added ListSelectionEvent generation,
+ (addSelectionInterval): If mode is SINGLE_SELECTION, just call
+ setSelectionInterval(),
+ (setSelectionInterval): Reimplemented SINGLE_SELECTION and
+ SINGLE_INTERVAL_SELECTION cases.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/text/AbstractDocument.java
+ (BranchElement.numChildren): New field.
+ (BranchElement.BranchElement): Initialize children array with
+ one element (that's the least number of elements that makes sense).
+ Initialize numChildren.
+ (BranchElement.children): Use numChildren as boundary.
+ (BranchElement.getElement): Use numChildren as boundary.
+ (BranchElement.getElementCount): Use numChildren as boundary.
+ (BranchElement.getElementIndex): Use numChildren as boundary.
+ (BranchElement.getEndOffset): Use numChildren as boundary.
+ (BranchElement.getStartOffset): Use numChildren as boundary.
+ (BranchElement.positionToElement): Use numChildren as boundary.
+ (BranchElement.replace): Handle the children array more efficiently
+ by growing in blocks > 1, and reusing space from removed elements.
+ (LeafElement.startDelta): Removed.
+ (LeafElement.endDelta): Removed.
+ (LeafElement.LeafElement): Removed handling of deltas.
+ (LeafElement.getEndOffset): Likewise.
+ (LeafElement.getStartOffset): Likewise.
+ * javax/swing/text/JTextComponent.java
+ (setDocument): Added locking of the old document to avoid dangling
+ notification beeing delivered while the document is beeing
+ disconnected.
+ (getScrollableTracksViewportWidth): Fixed condition.
+ * javax/swing/text/PlainDocument.java
+ (createDefaultRoot): Create elements without AttributeSet.
+ * javax/swing/text/rtf/RTFParser.java
+ (parseFile): Handle slightly incorrect RTF gracefully.
+ * javax/swing/text/rtf/RTFScanner.java
+ (lastToken): New field.
+ (readTokenImpl): New method.
+ (peekToken): New method.
+ (readToken): Changed to call readTokenImpl or return the lastToken
+ if there's one present.
+
+2006-06-21 Tania Bento <tbento@redhat.com>
+
+ * javax/swing/JMenu.java
+ (remove): An IllegalArgumentException should be thrown if
+ either index < 0 or if index > 0 and there are no menu
+ components. Also, a check was added that ensures there are
+ menu components before removing the desired the component.
+
+2006-06-21 Lillian Angel <langel@redhat.com>
+
+ * javax/swing/text/DefaultCaret.java
+ (install): Added check to prevent NPE.
+ (propertyChange): Added checks to prevent NPEs.
+
+2006-06-21 Tania Bento <tbento@redhat.com>
+
+ * javax/swing/JMenu.java
+ Changed instantiation of popupMenu to null.
+ (JMenu): Instantiated popupMenu to new JPopupMenu.
+ (JMenu): Instantiated popupMenu to new JPopupMenu.
+ (add): Changed popupMenu to getPopupMenu().
+ (add): Changed popupMenu to getPopupMenu().
+ (add): Changed popupMenu to getPopupMenu().
+ (add): Changed popupMenu to getPopupMenu().
+ (remove): Changed popupMenu to getPopupMenu().
+ (remove): Changed popupMenu to getPopupMenu().
+ (insert): Changed popupMenu to getPopupMenu().
+ (setSelectedHelper): Changed popupMenu to getPopupMenu().
+ (isPopupMenuVisible): Changed popupMenu to getPopupMenu().
+ (setPopupMenuVisible): Changed popupMenu to getPopupMenu().
+ (getMenuComponentCount): Changed popupMenu to getPopupMenu().
+ (getMenuComponents): Changed popupMenu to getPopupMenu().
+ (getPopupMenu): Check first if popupMenu is null and if so,
+ instantiate it to a new JPopupMenu and set the invoker.
+ * javax/swing/plaf/basic/BasicPopupMenuUI.java
+ (popupMenuWillBecomeVisible): Component Listener should only
+ be added to the root container if the root container is not
+ null. This avoids a null pointer exception.
+
+2006-06-21 Tania Bento <tbento@redhat.com>
+
+ * javax/swing/JMenu.java
+ (JMenu): Delay should be set to 200, not default of 0.
+ (JMenu): Delay should be set to 200, not default of 0.
+ (JMenu): Delay should be set to 200, not default of 0.
+ (JMenu): Delay should be set to 200, not default of 0.
+ (remove): Added check that index >= 0 before removing
+ the component.
+ (getItem): Return null if item count equals 0.
+ (isTearOff): Should throw new error and not return false.
+ (getMenuComponent): Return null if popupMenu is null or
+ if there are no menu components.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * java/awt/font/FontRenderContext.java:
+ (equals): Added special conditions for affineTransform beeing
+ null.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/UIManager.java
+ (MultiplexUIDefaults.clear): Removed method. The fallback UIDefaults
+ must not be cleared.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/plaf/metal/MetalUtils.java
+ (paintHorizontalGradient): Use paintHorizontalGradient2D when
+ Graphics2D is available. Use fillRect instead of drawLine, this
+ is much faster.
+ (paintVerticalGradient): Use paintHorizontalGradient2D when
+ Graphics2D is available. Use fillRect instead of drawLine, this
+ is much faster.
+ (paintHorizontalGradient2D): New method. Paints gradient
+ using Graphics2D functions.
+ (paintVerticalGradient2D): New method. Paints gradient
+ using Graphics2D functions.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/plaf/basic/BasicButtonListener.java
+ (propertyChange): Create a TextLayout and store it in the button
+ when the 'text' property changes.
+ * javax/swing/plaf/basic/BasicButtonUI.java
+ (paintText): Call BasicGraphicsUtils utility method for
+ drawing strings, instead of Graphics.drawString().
+ * javax/swing/plaf/basic/BasicGraphicsUtils.java
+ (CACHE_TEXT_LAYOUT): New constant field. Used as a key for storing
+ cached text layouts as client properties in JComponents.
+ (drawString(JComponent,Graphics,String,int,int)): New helper method.
+ (drawStringUnderlineCharAt): New helper method.
+ * javax/swing/plaf/basic/BasicMenuItemUI.java
+ (PropertyChangeHandler.propertyChange): Update cached text layout
+ when 'text' property changes. Use equals() instead of == for
+ string comparison.
+ (paintText): Use new BasicGraphicsUtils methods for painting
+ the cached text layout.
+ (installListeners): Call super.installListeners() and remove
+ the unneeded listener installs.
+ (uninstallListeners): Call super.uninstallListeners() and remove
+ the unneeded listener uninstalls.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/plaf/basic/BasicTextUI.java
+ (PropertyChangeHandler.propertyChange): Handle document listener
+ update here.
+ (background): Removed unneeded fields.
+ (inactiveBackground): Remove unneeded fields.
+ (installUI): Install the document listener. Slightly changed
+ order of operations. Don't trigger modelChanged().
+ (installDefaults): Only install properties when the
+ current properties are null or instances of UIResource.
+ (installListeners): Removed unnecessary listener installs.
+ (installDocumentListeners): Removed unneeded method.
+ (uninstallListeners): Removed unnecessary listener uninstalls.
+ (modelChanged): Removed call to installDocumentListeners().
+ * javax/swing/plaf/basic/BasicTextFieldUI.java
+ (propertyChange): Update the colors by fetching them from
+ SharedUIDefaults. Fixed conditions.
+ * javax/swing/plaf/basic/SharedUIDefaults.java
+ (getColor): New method.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/SizeSequence.java
+ (SizeSequence): Initialize array with correct number of entries.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/JSplitPane.java
+ (setDividerLocation): Substract divider size when computing
+ the absolute size.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/JComponent.java
+ (paintChildrenWithOverlap): Determine opaque property by
+ calling the corresponding Component method, without requiring
+ a JComponent.
+ (paintChildrenOptimized): Removed old unneeded code.
+ (paintImmediately): Use JComponent's convertRectangleToAncestor()
+ method instead of SwingUtilities.convertRectangle(). This is
+ more efficient.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/AbstractButton.java
+ (init): Call setText() instead of setting the property directly,
+ so that listeners (especially in the UI) get notified.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/UIManager.java
+ (MultiplexUIDefaults): New inner class.
+ (currentUIDefaults): Changed type to be MultiplexUIDefaults.
+ (userUIDefaults): Changed name to be lookAndFeelDefaults.
+ (<cinit>): Call setLookAndFeel(String) instead of trying to load
+ directly. Print stacktrace if something goes wrong.
+ (get): Delegate call to currentUIDefaults.
+ (getDefaults): If currentUIDefaults is null, then lazily instantiate
+ it.
+ (getUI): Delegate call to currentUIDefaults.
+ (put): Delegate call to currentUIDefaults.
+ (setLookAndFeel): Initialize currentUIDefaults with
+ MultiplexUIDefaults. Set lookAndFeelDefaults.
+ (setLookAndFeel): Use current thread's context classloader for
+ loading the L&F.
+
+2006-06-21 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/text/GapContent.java
+ (GapContentPosition.GapContentPosition): Replace
+ Collections.binarySearch with call to local search() to make
+ sure we find the first object that equals the searched object.
+ (setPositionsInRange): Likewise.
+ (adjustPositionsInRange): Likewise.
+ (search): New helper method.
+
+2006-06-21 Gary Benson <gbenson@redhat.com>
+
+ * gnu/java/awt/peer/gtk/CairoGraphics2D.java: Add security check.
+ * gnu/java/awt/peer/qt/QtGraphics.java: Likewise.
+ * gnu/java/awt/java2d/AbstractGraphics2D.java: Likewise.
+
+2006-06-20 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * native/plugin/Makefile.am (libgcjwebplugin_la_CXXFLAGS): Define
+ APPLETVIEWER_EXECUTABLE to gappletviewer.
+
+2006-06-20 Tom Tromey <tromey@redhat.com>
+
+ PR classpath/28095:
+ * java/net/URL.java (URL): Throw MalformedURLException if a
+ RuntimeException is caught. Chain exceptions.
+
+2006-06-20 Lillian Angel <langel@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
+ (create): Added check to prevent Seg Fault. Should not
+ set the label if it is null.
+ * gnu/java/awt/peer/gtk/GtkLabelPeer.java
+ (setText): Changed to be a non-native function. Calls
+ setNativeText if the String parameter is non-null.
+ (setNativeText): Replaces old native setText function.
+ * include/gnu_java_awt_peer_gtk_GtkLabelPeer.h: Regenerated.
+ * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
+ (Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText): Removed.
+ Replaced by Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeText.
+ (Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeText): Replaced
+ Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText.
+
+2006-06-20 Lillian Angel <langel@redhat.com>
+
+ * javax/swing/text/JTextComponent.java
+ (AccessibleJTextComponent): Rewrote all javadocs
+ for this inner class.
+
+2006-06-20 Francis Kung <fkung@redhat.com>
+
+ * examples/gnu/classpath/examples/java2d/J2dBenchmark.java:
+ Changed many members to be protected.
+ (J2dBenchmark): moved to init() instead.
+ (init): New method.
+ (main): Call init() after creating object
+ (testComplete): New method.
+ (test_drawArc): Use maxTests varialbe instead of constant.
+ (test_drawCubicCurve): Likewise.
+ (test_drawEllipse): Likewise.
+ (test_drawGeneralPath): Likewise.
+ (test_drawImage): Likewise.
+ (test_drawLine): Likewise.
+ (test_drawQuadCurve): Likewise.
+ (test_drawRectangle): Likewise.
+ (test_drawRoundRectangle): Likewise.
+ (test_drawTransparentImage): Likewise.
+ (test_fillArc): Likewise.
+ (test_fillEllipse): Likewise.
+ (test_fillGeneralPath): Likewise.
+ (test_fillRectangle): Likewise.
+ (test_fillRoundRectangle): Likewise.
+ (GraphicsTest.runSetNoClipping): Added runCount parameter.
+ (GraphicsTest.runSetWithClipping): Likewise.
+ (GraphicsTest.runSetZeroClipping): Likewise.
+ (GraphicsTest.run): Added checks for more option flags.
+ * examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java:
+ New file.
+
+2006-06-20 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/text/GapContent.java
+ (GapContentPosition.mark): New field.
+ (GapContentPosition.index): Removed.
+ (GapContentPosition.GapContentPosition): Changed to take the
+ real offset as parameter. Added handling of reference counter.
+ Try to cleanup before creating new instances.
+ (getOffset): Delegate to the Mark method with same name.
+ (Mark): New class, encapsulating a mark.
+ (positionMarks): Removed field.
+ (numMarks): Removed field.
+ (marks): New field.
+ (queueOfDeath): New field.
+ (GapContent): Removed init of old fields, added init of new fields.
+ (createPosition): Added check for validity of arguments.
+ Create GapContentPosition directly with offset.
+ (shiftEnd): Pass end of buffer directly to adjustPositionsInRange.
+ (shiftGap): Pass end of buffer directly to adjustPositionsInRange.
+ (shiftGapStartDown): Call resetMarksAtZero().
+ (shiftGapEndUp): Call resetMarksAtZero().
+ (replace): Don't call resetMarksAtZero().
+ (setPositionInRange): Replaced by simpler algorithm, similar to
+ adjustPositionsInRange.
+ (adjustPositionsInRange): Adapted to use of Mark objects.
+ (resetMarksAtZero): Reset all marks that point to zero instead
+ of only the first one.
+ (dumpMarks): Adjusted to dump Mark objects.
+ (insertMark): Removed.
+ (garbageCollect): New method. Cleans up the marks list.
+ (binarySearch): Removed.
+
+2006-06-20 Lillian Angel <langel@redhat.com>
+
+ * gnu/java/awt/peer/gtk/CairoGraphics2D.java
+ (drawImage): Added call to updateColor because
+ Cairo seems to lose the current color.
+
+2006-06-20 Gary Benson <gbenson@redhat.com>
+
+ * java/awt/Toolkit.java: Add security check.
+ * gnu/java/awt/peer/gtk/GtkToolkit.java: Likewise.
+ * gnu/java/awt/peer/qt/QtToolkit.java: Likewise.
+
+2006-06-20 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/java/security/key/dss/DSSKey.java: Source formatting.
+ * gnu/java/security/key/dss/DSSKeyPairGenerator.java: Likewise.
+ * gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java: Likewise.
+ * gnu/java/security/key/dss/DSSKeyPairRawCodec.java: Likewise.
+ * gnu/java/security/key/dss/DSSKeyPairX509Codec.java: Likewise.
+ * gnu/java/security/key/dss/DSSPrivateKey.java: Likewise.
+ * gnu/java/security/key/dss/DSSPublicKey.java: Likewise.
+ * gnu/java/security/key/dss/FIPS186.java: Likewise.
+ * gnu/java/security/key/rsa/GnuRSAKey.java: Likewise.
+ * gnu/java/security/key/rsa/GnuRSAPrivateKey.java: Likewise.
+ * gnu/java/security/key/rsa/GnuRSAPublicKey.java: Likewise.
+ * gnu/java/security/key/rsa/RSAKeyPairGenerator.java: Likewise.
+ * gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java: Likewise.
+ * gnu/java/security/key/rsa/RSAKeyPairRawCodec.java: Likewise.
+ * gnu/java/security/key/rsa/RSAKeyPairX509Codec.java: Likewise.
+ * gnu/java/security/key/IKeyPairCodec.java: Likewise.
+ * gnu/java/security/key/IKeyPairGenerator.java: Likewise.
+ * gnu/java/security/key/KeyPairCodecFactory.java: Likewise.
+ * gnu/java/security/key/KeyPairGeneratorFactory.java: Likewise.
+
+2006-06-19 Lillian Angel <langel@redhat.com>
+
+ * gnu/java/awt/peer/gtk/CairoGraphics2D.java
+ (drawImage): Should always use getRGB to get the pixels.
+ getData returns an incorrect array of pixels.
+
+2006-06-19 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/java/security/jce/hash/HavalSpi.java: Source formatting.
+ * gnu/java/security/jce/hash/MD2Spi.java: Likewise.
+ * gnu/java/security/jce/hash/MD4Spi.java: Likewise.
+ * gnu/java/security/jce/hash/MD5Spi.java: Likewise.
+ * gnu/java/security/jce/hash/MessageDigestAdapter.java: Likewise.
+ * gnu/java/security/jce/hash/RipeMD128Spi.java: Likewise.
+ * gnu/java/security/jce/hash/RipeMD160Spi.java: Likewise.
+ * gnu/java/security/jce/hash/Sha160Spi.java: Likewise.
+ * gnu/java/security/jce/hash/Sha256Spi.java: Likewise.
+ * gnu/java/security/jce/hash/Sha384Spi.java: Likewise.
+ * gnu/java/security/jce/hash/Sha512Spi.java: Likewise.
+ * gnu/java/security/jce/hash/TigerSpi.java: Likewise.
+ * gnu/java/security/jce/hash/WhirlpoolSpi.java: Likewise.
+ * gnu/java/security/jce/prng/HavalRandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/MD2RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/MD4RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/MD5RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/RipeMD128RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/RipeMD160RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/SecureRandomAdapter.java: Likewise.
+ * gnu/java/security/jce/prng/Sha160RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/Sha256RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/Sha384RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/Sha512RandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/TigerRandomSpi.java: Likewise.
+ * gnu/java/security/jce/prng/WhirlpoolRandomSpi.java: Likewise.
+ * gnu/java/security/jce/sig/DSSKeyFactory.java: Likewise.
+ * gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java: Likewise.
+ * gnu/java/security/jce/sig/DSSParameters.java: Likewise.
+ * gnu/java/security/jce/sig/DSSRawSignatureSpi.java: Likewise.
+ * gnu/java/security/jce/sig/EncodedKeyFactory.java: Likewise.
+ * gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java: Likewise.
+ * gnu/java/security/jce/sig/RSAKeyFactory.java: Likewise.
+ * gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java: Likewise.
+ * gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java: Likewise.
+ * gnu/java/security/jce/sig/SignatureAdapter.java: Likewise.
+
+2006-06-19 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * NEWS: Updated (delayed) for security tools and tools.texinfo.
+
+2006-06-19 Roman Kennke <kennke@aicas.com>
+
+ * gnu/java/awt/peer/gtk/ComponentGraphics.java
+ (drawImage): Clip volatile image correctly.
+ (drawVolatileImage): Added arguments for clipping.
+ * native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
+ (drawVolatileImage): Added arguments for clipping. Clip image
+ correctly.
+ * include/gnu_java_awt_peer_gtk_ComponentGraphics.h: Regenerated.
+
+2006-06-19 Audrius Meskauskas <AudriusA@Bioinformatics.org>
+
+ PR 28035
+ * java/rmi/server/UID.java (constructor): Synchronized
+ the whole constructor on the UID class.
+
+2006-06-19 Roman Kennke <kennke@aicas.com>
+
+ * javax/swing/RepaintManager.java
+ (addInvalidComponent): Only add component that are displayable,
+ that have displayable parents and that have a validateRoot.
+ Also, don't validate components that have a CellRendererPane
+ ancestor.
+
+2006-06-19 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/plaf/IconUIResource.java
+ (IconUIResource): Throw IllegalArgumentException for null icon.
+
+2006-06-18 Audrius Meskauskas <AudriusA@Bioinformatics.org>
+
+ PR 28035
+ * java/rmi/server/UID.java (constructor): First increment
+ uidCounter, and then use the value.
+
+2006-06-18 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * java/awt/GridBagLayout.java (AdjustForGravity): Implement.
+ * java/awt/GridBagConstraints.java: Indent.
+
+2006-06-18 Tom Tromey <tromey@redhat.com>
+
+ * native/jni/gconf-peer/.cvsignore: New file.
+
+2006-06-18 Tom Tromey <tromey@redhat.com>
+
+ * tools/gnu/classpath/tools/getopt/Parser.java (handleLongOption):
+ Also handle short options.
+
+2006-06-18 Jim Huang <jserv@kaffe.org>
+
+ PR classpath/28076:
+ * native/jni/gconf-peer/Makefile.am (libgconfpeer_la_LIBADD):
+ Fixed typo.
+
+2006-06-19 Mark Wielaard <mark@klomp.org>
+
+ * include/Makefile.am: gnu_java_util_prefs_gconf_%.h should depend
+ on gnu/java/util/prefs/gconf/%.class.
+ * Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class: Fix
+ chache typo, should be cache.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1keys):
+ Declare tmp early.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1nodes):
+ Likewise.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1remove_1dir):
+ Don't return a value for void function.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1add_1dir)
+ Likewise.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists):
+ Mark clazz as unused. Return JNI_FALSE, not NULL for jboolean
+ function.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class):
+ Mark clazz ad unused.
+
+2006-06-18 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/java/security/hash/Whirlpool.java: Source formatting.
+ * gnu/java/security/hash/Tiger.java: Likewise.
+ * gnu/java/security/hash/Sha512.java: Likewise.
+ * gnu/java/security/hash/Sha384.java: Likewise.
+ * gnu/java/security/hash/Sha256.java: Likewise.
+ * gnu/java/security/hash/Sha160.java: Likewise.
+ * gnu/java/security/hash/RipeMD160.java: Likewise.
+ * gnu/java/security/hash/RipeMD128.java: Likewise.
+ * gnu/java/security/hash/MD5.java: Likewise.
+ * gnu/java/security/hash/MD4.java: Likewise.
+ * gnu/java/security/hash/MD2.java: Likewise.
+ * gnu/java/security/hash/IMessageDigest.java: Likewise.
+ * gnu/java/security/hash/Haval.java: Likewise.
+ * gnu/java/security/hash/HashFactory.java: Likewise.
+ * gnu/java/security/hash/BaseHash.java: Likewise.
+
+2006-06-18 Sven de Marothy <sven@physto.se>
+
+ * java/awt/event/KeyEvent.java:
+ (VK_WINDOWS, VK_CONTEXT_MENU, VK_BEGIN): Add new keysym fields.
+ * natve/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c:
+ Implement WINDOWS, ALT_GR and CONTEXT_MENU keysyms.
+
+2006-06-18 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/java/security/util/Prime2.java: Removed.
+ * gnu/java/security/key/dss/FIPS186.java: Remove unused imports.
+ (generateParameters): Use isProbablePrime() in BigInteger instead of Prime2.
+ * gnu/java/security/key/rsa/RSAKeyPairGenerator.java: Remove unused imports.
+ (generate): Use isProbablePrime() in BigInteger instead of Prime2.
+ * gnu/javax/crypto/key/dh/RFC2631.java: Remove unused imports.
+ (generateParameters): Use isProbablePrime() in BigInteger instead of Prime2.
+ * gnu/javax/crypto/key/srp6/SRPAlgorithm.java: Remove unused imports.
+ (checkParams): Use isProbablePrime() in BigInteger instead of Prime2.
+ * gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java: Remove unused imports.
+ (generateParameters): Use isProbablePrime() in BigInteger instead of Prime2.
+ * gnu/javax/net/ssl/provider/KeyPool.java: Remove unused imports.
+ (generateRSAKeyPair): Use isProbablePrime() in BigInteger instead of Prime2.
+
+2006-06-18 Sven de Marothy <sven@physto.se>
+
+ * java/awt/GridBagLayout.java (AdjustForGravity): Implement.
+ * java/awt/font/TextMeasurer.java: Fix copyright date,
+ remove commented-out code.
+
+2006-06-18 Sven de Marothy <sven@physto.se>
+
+ * gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
+ (FreetypeGlyphVector, clone): Implement cloning.
+ (getGlyphLogicalBounds): Bounds should be offset to the glyph position.
+ * java/awt/font/TextMeasurer.java: Implement.
+ * java/awt/font/LineBreakMeasurer.java:
+ Reimplement to use TextMeasurer.
+ * java/awt/font/TextLayout.java
+ New constructors.
+ (getBlackboxBounds, getLogicalHighlightShape): Reimplement.
+ (getText, getFont): New private static methods.
+ (setCharIndices): New method.
+ * java/text/AttributedString.java
+ (AttributedString): Fix constructor to stop at end point.
+
2006-06-17 Tom Tromey <tromey@redhat.com>
* lib/gen-classlist.sh.in: Search all top-level directories, not
just 'org', in external.
+2006-06-12 Mario torre <neugens at limasoftware.net>
+
+ * gnu/java/util/prefs/GConfBasedPreferences.java: new class.
+ * gnu/java/util/prefs/GConfBasedFactory.java: new class.
+ * gnu/java/util/prefs/gconf/GConfNativePeer.java: new class.
+ * gnu_java_util_prefs_gconf_GConfNativePeer.h: generated
+ header file.
+ * classpath/native/jni/gconf-peer/GConfNativePeer.c: new C file.
+ * configure.ac: update to introduce new files. Added options
+ to build gconf native peer used by the GConf preference backend.
+ * include/Makefile.am: update to introduce new files.
+ * native/jni/Makefile.am update to introduce new files.
+ * scripts/check_jni_methods.sh: added three new ignored file
+ from check.
+ * native/jni/gconf-peer/Makefile.am: new Makefile needed to
+ build gconf-peer shared library.
+
+2006-06-17 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java:
+ Use Integer.valueOf() instead of new Integer().
+ * gnu/java/security/jce/sig/EncodedKeyFactory.java: Likewise.
+ * gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java: Likewise.
+ * gnu/java/security/util/Sequence.java: Likewise.
+ * gnu/java/security/x509/ext/GeneralNames.java: Likewise.
+ * gnu/java/security/x509/X509Certificate.java: Likewise.
+ * gnu/javax/crypto/assembly/ModeStage.java: Likewise.
+ * gnu/javax/crypto/cipher/Anubis.java: Likewise.
+ * gnu/javax/crypto/cipher/Blowfish.java: Likewise.
+ * gnu/javax/crypto/cipher/Cast5.java: Likewise.
+ * gnu/javax/crypto/cipher/DES.java: Likewise.
+ * gnu/javax/crypto/cipher/Khazad.java: Likewise.
+ * gnu/javax/crypto/cipher/NullCipher.java: Likewise.
+ * gnu/javax/crypto/cipher/Rijndael.java: Likewise.
+ * gnu/javax/crypto/cipher/Serpent.java: Likewise.
+ * gnu/javax/crypto/cipher/Square.java: Likewise.
+ * gnu/javax/crypto/cipher/TripleDES.java: Likewise.
+ * gnu/javax/crypto/cipher/Twofish.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/CipherAdapter.java: Likewise.
+ * gnu/javax/crypto/jce/cipher/PBES2.java: Likewise.
+ * gnu/javax/crypto/jce/key/SecretKeyGeneratorImpl.java: Likewise.
+ * gnu/javax/crypto/jce/PBKDF2SecretKeyFactory.java: Likewise.
+ * gnu/javax/crypto/jce/prng/ICMRandomSpi.java: Likewise.
+ * gnu/javax/crypto/jce/prng/UMacRandomSpi.java: Likewise.
+ * gnu/javax/crypto/jce/sig/DHKeyPairGeneratorSpi.java: Likewise.
+ * gnu/javax/crypto/keyring/AuthenticatedEntry.java: Likewise.
+ * gnu/javax/crypto/keyring/EncryptedEntry.java: Likewise.
+ * gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java: Likewise.
+ * gnu/javax/crypto/keyring/PasswordEncryptedEntry.java: Likewise.
+ * gnu/javax/crypto/keyring/PasswordProtectedEntry.java: Likewise.
+ * gnu/javax/crypto/mac/UHash32.java: Likewise.
+ * gnu/javax/crypto/mac/UMac32.java: Likewise.
+ * gnu/javax/crypto/mode/BaseMode.java: Likewise.
+ * gnu/javax/crypto/mode/EAX.java: Likewise.
+ * gnu/javax/crypto/prng/ICMGenerator.java: Likewise.
+ * gnu/javax/crypto/prng/UMacGenerator.java: Likewise.
+ * gnu/javax/crypto/sasl/srp/KDF.java: Likewise.
+ * gnu/javax/security/auth/callback/ConsoleCallbackHandler.java: Likewise.
+ * java/security/cert/X509CertSelector.java: Likewise.
+
+2006-06-17 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * javax/management/DynamicMBean.java:
+ (setAttribute): Fixed to return void.
+ * javax/management/MBeanFeatureInfo.java:
+ New file.
+
+2006-06-17 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ On behalf of Vivek Lakshmanan <vivekl@redhat.com>
+ * gnu/javax/crypto/jce/cipher/CipherAdapter.java
+ (engineInit(int, Key, SecureRandom)): Seperate common initialization logic
+ into engineInitHandler and reuse the code in
+ engineInit(int, Key, AlgorithmSpec, SecureRandom).
+ (engineInitHandler): New method.
+ (engineInit(int, Key, AlgorithmParameterSpec, SecureRandom)): When param is
+ null, use random or default information when possible.
+
+2006-06-16 Francis Kung <fkung@redhat.com>
+
+ * examples/gnu/classpath/examples/swing/Demo.java:
+ (mkButtonBar): Rename FillRect to JNIOverhead.
+ (mkMenuBar): Rename FillRect to JNIOverhead.
+ * examples/gnu/classpath/examples/swing/FillRect.java: Removed.
+ * examples/gnu/classpath/examples/java2d/J2dBenchmark.java: New file.
+ * examples/gnu/classpath/examples/java2d/JNIOverhead.java:
+ Moved from old FillRect.
+
+2006-06-16 Tom Tromey <tromey@redhat.com>
+
+ * tools/.cvsignore: Added new tool names.
+
2006-06-16 Keith Seitz <keiths@redhat.com>
* gnu/classpath/jdwp/event/EventManager.java (getDefault): Redo
diff --git a/NEWS b/NEWS
index 09d8722ba..f6284ed30 100644
--- a/NEWS
+++ b/NEWS
@@ -13,11 +13,19 @@ New in release 0.92 (UNRELEASED)
build the GTK peers.
* A Mozilla plugin, 'gcjwebplugin', is now included. It introduces a
dependency on the Mozilla plugin support headers and libraries.
+* A tools.texinfo document has been created and now includes documentation
+ about:
+ * appletviewer
+ * gcjwebplugin
+ * jarsigner
+ * keytool
* Several new tools are now included:
* appletviewer
* jar
* native2ascii
* serialver
+ * keytool
+ * jarsigner
A new configure option --enable-tool-wrappers causes wrapper
binaries to be built for VMs that support the JNI Invocation API.
* We've imported the JSR 166 (concurrency) reference implementation.
@@ -31,7 +39,7 @@ Runtime interface changes:
* The method gnu.java.io.PlatformHelper.toCanonicalForm() has been
replaced with a JNI implementation of VMFile.toCanonicalForm() for
GNU/Posix systems.
-* An new class, VMRuntimeMXBeanImpl, is used to implement
+* A new class, VMRuntimeMXBeanImpl, is used to implement
the low-level support of the runtime management bean.
VMs should use it to supply the input arguments and start
time of the VM. In addition, one of sun.boot.class.path
@@ -41,6 +49,12 @@ Runtime interface changes:
reference implementation. We've also added a couple other new VM
classes to support the JSR 166 code -- sun.reflect.Reflection and
sun.reflect.misc.ReflectUtil.
+* Another new class, VMClassLoadingMXBeanImpl, is used to implement
+ the low-level support of the class loading management bean.
+ VMs need to supply it with information about how many classes
+ are currently loaded, how many have been unloaded and whether
+ verbose class loading output is on or off. Provision should also
+ be made for the latter to be toggled at runtime.
New in release 0.91 (May 15, 2006)
diff --git a/configure.ac b/configure.ac
index 61385dca3..3e8d48e98 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,25 @@ AC_ARG_ENABLE([core-jni],
[COMPILE_CORE_JNI=yes])
AM_CONDITIONAL(CREATE_CORE_JNI_LIBRARIES, test "x${COMPILE_CORE_JNI}" = xyes)
+dnl -----------------------------------------------------------
+dnl GConf native peer (enabled by default)
+dnl -----------------------------------------------------------
+AC_ARG_ENABLE([gconf-peer],
+ [AS_HELP_STRING(--disable-gconf-peer,compile GConf native peers (disabled by --disable-jni) [default=yes])],
+ [case "${enableval}" in
+ yes) COMPILE_GCONF_PEER=yes ;;
+ no) COMPILE_GCONF_PEER=no ;;
+ *) COMPILE_GCONF_PEER=yes ;;
+ esac],
+ [COMPILE_GCONF_PEER=yes])
+AM_CONDITIONAL(CREATE_GCONF_PEER_LIBRARIES, test "x${COMPILE_GCONF_PEER}" = xyes)
+
+dnl -----------------------------------------------------------
+dnl GTK native peer error checking
+dnl -----------------------------------------------------------
+AC_ARG_ENABLE([gconf-peers],,AC_MSG_ERROR([No --enable-gconf-peers (or --disable-gconf-peers) option; you want --enable-gconf-peer]))
+
+
dnl ------------------------------------------------------------
dnl Whether to compile with -Werror or not (disabled by default)
dnl ------------------------------------------------------------
@@ -432,6 +451,13 @@ if test "x${COMPILE_JNI}" = xyes; then
AC_SUBST(XTEST_LIBS)
fi
+ dnl gconf-peer
+ if test "x${COMPILE_GCONF_PEER}" = xyes; then
+ PKG_CHECK_MODULES(GCONF, gconf-2.0 >= 2.11.2)
+ AC_SUBST(GCONF_CFLAGS)
+ AC_SUBST(GCONF_LIBS)
+ fi
+
dnl Check for AWT related Qt4
if test "x${COMPILE_QT_PEER}" = xyes; then
PKG_CHECK_MODULES(QT, QtCore QtGui >= 4.1.0, HAVE_QT4="yes", HAVE_QT4="no")
@@ -708,6 +734,7 @@ external/w3c_dom/Makefile
external/relaxngDatatype/Makefile
external/jsr166/Makefile
gnu/classpath/Configuration.java
+gnu/java/security/Configuration.java
include/Makefile
native/Makefile
native/fdlibm/Makefile
@@ -720,6 +747,7 @@ native/jni/java-net/Makefile
native/jni/java-nio/Makefile
native/jni/java-util/Makefile
native/jni/gtk-peer/Makefile
+native/jni/gconf-peer/Makefile
native/jni/qt-peer/Makefile
native/jni/xmlj/Makefile
native/jni/midi-alsa/Makefile
diff --git a/doc/vmintegration.texinfo b/doc/vmintegration.texinfo
index d0e628311..7c0c0b521 100644
--- a/doc/vmintegration.texinfo
+++ b/doc/vmintegration.texinfo
@@ -1267,9 +1267,10 @@ implementations of the management beans.
@menu
* gnu.java.lang.management.VMRuntimeMXBeanImpl::
+* gnu.java.lang.management.VMClassLoadingMXBeanImpl::
@end menu
-@node gnu.java.lang.management.VMRuntimeMXBeanImpl,,,gnu.java.lang.management
+@node gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management.VMClassLoadingMXBeanImpl,,gnu.java.lang.management
@subsection @code{gnu.java.lang.management.VMRuntimeMXBeanImpl}
The @code{gnu.java.lang.management.RuntimeMXBeanImpl} provides an
@@ -1311,6 +1312,33 @@ The virtual machine also needs to provide either the
property in order to support the optional boot class path
retrieval functionality.
+@node gnu.java.lang.management.VMClassLoadingMXBeanImpl,,gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management
+@subsection @code{gnu.java.lang.management.VMClassLoadingMXBeanImpl}
+
+The @code{gnu.java.lang.management.ClassLoadingMXBeanImpl} provides an
+implementation of the @code{java.lang.management.ClassLoadingMXBean} interface,
+and is supported by VM functionality in the form of
+@code{gnu.java.lang.management.VMClassLoadingMXBeanImpl}. This provides a
+series of methods, which should be implemented by the virtual machine
+in order to provide the required information for the bean. Implementing
+this bean requires the VM to monitor when classes are loaded and unloaded,
+and provide the option of verbose class loading output.
+
+The methods are as follows:
+
+@itemize @bullet
+@item @code{(getLoadedClassCount())} -- This should return
+the number of classes that are currently loaded by the VM.
+@item @code{(getUnloadedClassCount())} -- This should return
+the number of classes that have been loaded by the VM, but
+have since been unloaded.
+@item @code{(isVerbose())} -- This should return @code{true}
+or @code{false}, depending on whether verbose class loading
+output is turned or not, respectively.
+@item @code{(setVerbose(boolean))} -- This should allow the
+verbose class loading output to be turned on and off.
+@end itemize
+
@node Classpath Callbacks, , gnu.java.lang.management, Classpath Hooks
Some of the classes you implement for the VM will need to call back to
package-private methods in Classpath:
diff --git a/examples/gnu/classpath/examples/java2d/J2dBenchmark.java b/examples/gnu/classpath/examples/java2d/J2dBenchmark.java
new file mode 100644
index 000000000..118ae2463
--- /dev/null
+++ b/examples/gnu/classpath/examples/java2d/J2dBenchmark.java
@@ -0,0 +1,1571 @@
+/* J2dBenchmark.java -- Benchmarking utility for java2d,
+ based on the Aicas AWT benchmarker
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This file is part of GNU Classpath examples.
+
+ 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. */
+
+package gnu.classpath.examples.java2d;
+
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GradientPaint;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.Label;
+import java.awt.MediaTracker;
+import java.awt.Panel;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.TexturePaint;
+import java.awt.Toolkit;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Arc2D;
+import java.awt.geom.CubicCurve2D;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Line2D;
+import java.awt.geom.QuadCurve2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.geom.RoundRectangle2D;
+import java.awt.image.BufferedImage;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class J2dBenchmark
+ extends Panel
+{
+ /**
+ * Default number of test-iterations.
+ */
+ protected static final int DEFAULT_TEST_SIZE = 1000;
+
+ /**
+ * Default screen size.
+ */
+ protected static final int DEFAULT_SCREEN_WIDTH = 320;
+
+ protected static final int DEFAULT_SCREEN_HEIGHT = 240;
+
+ /**
+ * Java2D tests.
+ */
+ protected static final int J2DTEST_ARC = 1 << 0;
+
+ protected static final int J2DTEST_CUBICCURVE = 1 << 1;
+
+ protected static final int J2DTEST_ELLIPSE = 1 << 2;
+
+ protected static final int J2DTEST_GENERALPATH = 1 << 3;
+
+ protected static final int J2DTEST_LINE = 1 << 4;
+
+ protected static final int J2DTEST_QUADCURVE = 1 << 5;
+
+ protected static final int J2DTEST_RECTANGLE = 1 << 6;
+
+ protected static final int J2DTEST_ROUNDRECTANGLE = 1 << 7;
+
+ protected static final int J2DTEST_IMAGE = 1 << 8;
+
+ protected static final int J2DTEST_NONE = 0;
+
+ /*
+ private static final int J2DTEST_ALL = J2DTEST_ARC | J2DTEST_CUBICCURVE
+ | J2DTEST_ELLIPSE
+ | J2DTEST_GENERALPATH | J2DTEST_LINE
+ | J2DTEST_QUADCURVE
+ | J2DTEST_RECTANGLE
+ | J2DTEST_ROUNDRECTANGLE
+ | J2DTEST_IMAGE;
+ */
+ private static final int J2DTEST_ALL = J2DTEST_ARC | J2DTEST_CUBICCURVE
+ | J2DTEST_ELLIPSE
+ | J2DTEST_LINE
+ | J2DTEST_QUADCURVE
+ | J2DTEST_RECTANGLE
+ | J2DTEST_ROUNDRECTANGLE
+ | J2DTEST_IMAGE;
+
+ int iterations = 1;
+
+ protected int screenWidth = DEFAULT_SCREEN_WIDTH;
+
+ protected int screenHeight = DEFAULT_SCREEN_HEIGHT;
+
+ protected boolean noClippingFlag = true;
+
+ protected boolean withClippingFlag = true;
+
+ protected boolean zeroClippingFlag = true;
+
+ protected boolean singleBufferFlag = true;
+
+ protected boolean doubleBufferFlag = true;
+
+ protected boolean gradientFlag = false;
+
+ protected String texture = null;
+
+ protected boolean strokeFlag = false;
+
+ protected float composite = 1;
+
+ protected int xtranslate = 0;
+
+ protected int ytranslate = 0;
+
+ protected double xshear = 0;
+
+ protected double yshear = 0;
+
+ protected double rotate = 0;
+
+ protected boolean antialiasFlag = false;
+
+ protected AffineTransform affineTransform = null;
+
+ protected int awtTests = J2DTEST_ALL;
+
+ protected int testSize = DEFAULT_TEST_SIZE;
+
+ private Label testLabel;
+
+ private String testContext = "";
+
+ Logger logger = Logger.getLogger("J2dGraphicsBenchmark");
+
+ private Image pngTestImage;
+
+ private Image gifTestImage;
+
+ protected BufferedImage textureImage;
+
+ protected TestSet testSetMap = new TestSet();
+
+ public String init()
+ {
+ boolean loadError = false;
+ pngTestImage = loadImage("aicas.png");
+ gifTestImage = loadImage("palme.gif");
+
+ if (texture != null)
+ {
+ textureImage = loadBufferedImage(texture);
+
+ if (textureImage == null)
+ {
+ logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "init",
+ "Unable to load texture - defaulting "
+ + "to solid colours");
+ texture = null;
+ loadError = true;
+ }
+ }
+
+ setLayout(new BorderLayout());
+ testLabel = new Label();
+ add(testLabel, BorderLayout.NORTH);
+ add(new GraphicsTest(), BorderLayout.CENTER);
+
+ if (loadError)
+ return "Unable to load image";
+ else
+ return null;
+ }
+
+ void setTestContext(String testName)
+ {
+ logger.logp(Level.INFO, "J2dGraphicsBenchmark", "recordTest",
+ "--- Starting new test context: " + testName);
+ testContext = testName;
+ testLabel.setText(testName);
+ }
+
+ private void recordTest(String testName, long time)
+ {
+ logger.logp(Level.INFO, "J2dGraphicsBenchmark", "recordTest",
+ testContext + ": " + testName + " duration (ms): " + time);
+ TestRecorder recorder = testSetMap.getTest(testName);
+ if (recorder == null)
+ {
+ recorder = new TestRecorder(testName);
+ testSetMap.putTest(testName, recorder);
+ }
+ recorder.addRun(time);
+ }
+
+ void printReport()
+ {
+ for (Iterator i = testSetMap.testIterator(); i.hasNext();)
+ {
+ TestRecorder recorder = testSetMap.getTest((String) i.next());
+ System.out.println("TEST " + recorder.getTestName() + ": average "
+ + recorder.getAverage() + "ms ["
+ + recorder.getMinTime() + "-"
+ + recorder.getMaxTime() + "]");
+ }
+ }
+
+ void testComplete()
+ {
+ System.exit(0);
+ }
+
+ public static void main(String[] args)
+ {
+ int awtTests;
+ int i;
+ boolean endOfOptionsFlag;
+ J2dBenchmark speed = new J2dBenchmark();
+
+ // Parse arguments.
+ i = 0;
+ endOfOptionsFlag = false;
+ awtTests = J2DTEST_NONE;
+ while (i < args.length)
+ {
+ if (! endOfOptionsFlag)
+ {
+ if (args[i].equals("--help") || args[i].equals("-help")
+ || args[i].equals("-h"))
+ {
+ System.out.println("Usage: J2dBenchmark [<options>] [<test> ...]");
+ System.out.println("");
+ System.out.println("Options: -i|--iterations=<n|-1> - number of iterations (-1 is infinite; default "
+ + speed.iterations + ")");
+ System.out.println(" -w|--width=<n> - screen width; default "
+ + DEFAULT_SCREEN_WIDTH);
+ System.out.println(" -h|--height=<n> - screen height; default "
+ + DEFAULT_SCREEN_HEIGHT);
+ System.out.println(" -d|--noDoubleBuffer - disable double-buffering test");
+ System.out.println(" -s|--testsize=<n> - size of each test; default "
+ + DEFAULT_TEST_SIZE);
+ System.out.println(" -c|--noClipping - disable clipping test");
+ System.out.println(" -z|--noZeroClipping - disable clipping to zero test");
+ System.out.println("");
+ System.out.println("Additional options:");
+ System.out.println(" --with-gradients - enable gradients (not compatible with --texture)");
+ System.out.println(" --with-stroking - enable random stroking");
+ System.out.println(" --texture=<file> - enable texturing with this file (not compatible with --with-gradients)");
+ System.out.println(" --composite=<n|-1> - set alpha composite level; -1 for random; default 1.0 (no transparency)");
+ System.out.println(" --anti-alias=<on|off> - set anti-aliasing hint (not all implementations respect this); default off");
+ System.out.println(" --x-translate=<n> - set x-axis translation; default 0");
+ System.out.println(" --y-translate=<n> - set y-axis translation; default 0");
+ System.out.println(" --x-shear=<n> - set x-axis shear; default 0");
+ System.out.println(" --y-shear=<n> - set y-axis shear; default 0");
+ System.out.println(" --rotate=<n|-1> - set rotation (radians); -1 for random; default: 0 (none)");
+ System.out.println("");
+ System.out.println("Tests: arc");
+ System.out.println(" cubiccurve");
+ System.out.println(" ellipse");
+ // System.out.println(" generalpath");
+ System.out.println(" line");
+ System.out.println(" quadcurve");
+ System.out.println(" rectangle");
+ System.out.println(" roundrectangle");
+ System.out.println(" image");
+ System.exit(1);
+ }
+ else if ((args[i].startsWith("-i=") || args[i].startsWith("--iterations=")))
+ {
+ speed.iterations = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if ((args[i].equals("-i") || args[i].equals("--iterations")))
+ {
+ if ((i + 1) >= args.length)
+ {
+ System.err.println("ERROR: No argument given for option '"
+ + args[i] + "'!");
+ System.exit(2);
+ }
+ speed.iterations = Integer.parseInt(args[i + 1]);
+ i += 2;
+ continue;
+ }
+ else if ((args[i].startsWith("-w=") || args[i].startsWith("--width=")))
+ {
+ speed.screenWidth = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if ((args[i].equals("-w") || args[i].equals("--width")))
+ {
+ if ((i + 1) >= args.length)
+ {
+ System.err.println("ERROR: No argument given for option '"
+ + args[i] + "'!");
+ System.exit(2);
+ }
+ speed.screenWidth = Integer.parseInt(args[i + 1]);
+ i += 2;
+ continue;
+ }
+ else if ((args[i].startsWith("-h=") || args[i].startsWith("--height=")))
+ {
+ speed.screenHeight = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if ((args[i].equals("-h") || args[i].equals("--height")))
+ {
+ if ((i + 1) >= args.length)
+ {
+ System.err.println("ERROR: No argument given for option '"
+ + args[i] + "'!");
+ System.exit(2);
+ }
+ speed.screenHeight = Integer.parseInt(args[i + 1]);
+ i += 2;
+ continue;
+ }
+ else if ((args[i].equals("-d") || args[i].equals("--noDoubleBuffer")))
+ {
+ speed.doubleBufferFlag = false;
+ i += 1;
+ continue;
+ }
+ else if ((args[i].startsWith("-s=") || args[i].startsWith("--testsize=")))
+ {
+ if ((i + 1) >= args.length)
+ {
+ System.err.println("ERROR: No argument given for option '"
+ + args[i] + "'!");
+ System.exit(2);
+ }
+ speed.testSize = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if ((args[i].equals("-s") || args[i].equals("--testsize")))
+ {
+ if ((i + 1) >= args.length)
+ {
+ System.err.println("ERROR: No argument given for option '"
+ + args[i] + "'!");
+ System.exit(2);
+ }
+ speed.testSize = Integer.parseInt(args[i + 1]);
+ i += 2;
+ continue;
+ }
+ else if ((args[i].equals("-c") || args[i].equals("--noClipping")))
+ {
+ speed.noClippingFlag = false;
+ i += 1;
+ continue;
+ }
+ else if ((args[i].equals("-z") || args[i].equals("--noZeroClipping")))
+ {
+ speed.zeroClippingFlag = false;
+ i += 1;
+ continue;
+ }
+ else if (args[i].equals("--with-gradients"))
+ {
+ speed.gradientFlag = true;
+ i += 1;
+ continue;
+ }
+ else if (args[i].equals("--with-stroking"))
+ {
+ speed.strokeFlag = true;
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--texture="))
+ {
+ speed.texture = args[i].substring(args[i].indexOf('=') + 1);
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--composite="))
+ {
+ speed.composite = Float.parseFloat(args[i].substring(args[i].indexOf('=') + 1));
+ if (speed.composite != - 1
+ && (speed.composite < 0 || speed.composite > 1))
+ {
+ System.err.println("ERROR: Invalid value for composite (must be between 0 and 1, or -1 for random)");
+ System.exit(2);
+ }
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--anti-alias="))
+ {
+ speed.antialiasFlag = (args[i].substring(args[i].indexOf('=') + 1).equals("on"));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--x-translate="))
+ {
+ speed.xtranslate = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--y-translate="))
+ {
+ speed.ytranslate = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--x-shear="))
+ {
+ speed.xshear = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--y-shear="))
+ {
+ speed.yshear = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--rotate="))
+ {
+ speed.rotate = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+
+ else if (args[i].equals("--"))
+ {
+ endOfOptionsFlag = true;
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("-"))
+ {
+ System.err.println("ERROR: Unknown option '" + args[i] + "'!");
+ System.exit(2);
+ }
+ }
+ StringTokenizer tokenizer = new StringTokenizer(args[i], " +,");
+ while (tokenizer.hasMoreTokens())
+ {
+ String s = tokenizer.nextToken().toLowerCase();
+ if (s.equals("arc"))
+ awtTests |= J2DTEST_ARC;
+ else if (s.equals("cubiccurve"))
+ awtTests |= J2DTEST_CUBICCURVE;
+ else if (s.equals("ellipse"))
+ awtTests |= J2DTEST_ELLIPSE;
+ else if (s.equals("generalpath"))
+ awtTests |= J2DTEST_GENERALPATH;
+ else if (s.equals("line"))
+ awtTests |= J2DTEST_LINE;
+ else if (s.equals("quadcurve"))
+ awtTests |= J2DTEST_QUADCURVE;
+ else if (s.equals("rectangle"))
+ awtTests |= J2DTEST_RECTANGLE;
+ else if (s.equals("roundrectangle"))
+ awtTests |= J2DTEST_ROUNDRECTANGLE;
+ else if (s.equals("image"))
+ awtTests |= J2DTEST_IMAGE;
+ else
+ {
+ System.err.println("Unknown AWT test '" + s + "'!");
+ System.exit(2);
+ }
+ }
+ i += 1;
+ }
+ if (awtTests != J2DTEST_NONE)
+ speed.awtTests = awtTests;
+
+ // Create graphics.
+ speed.init();
+ final Frame frame = new Frame("J2dGraphicsBenchmark");
+
+ frame.addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ frame.setVisible(false);
+ System.exit(0);
+ }
+ });
+
+ frame.add(speed, BorderLayout.CENTER);
+ frame.setSize(speed.screenWidth, speed.screenHeight);
+ frame.setVisible(true);
+
+ // Insets are correctly set only after the native peer was created.
+ Insets insets = frame.getInsets();
+ // The internal size of the frame should be 320x240.
+ frame.setSize(320 + insets.right + insets.left, 240 + insets.top
+ + insets.bottom);
+ }
+
+ private Image loadImage(String imageName)
+ {
+ Image result = null;
+ logger.logp(Level.INFO, "J2dGraphicsBenchmark", "loadImage",
+ "Loading image: " + imageName);
+ URL url = getClass().getResource(imageName);
+ if (url != null)
+ {
+ result = Toolkit.getDefaultToolkit().getImage(url);
+ prepareImage(result, this);
+ }
+ else
+ {
+ logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "loadImage",
+ "Could not locate image resource in class path: "
+ + imageName);
+ }
+ return result;
+ }
+
+ private BufferedImage loadBufferedImage(String imageName)
+ {
+ BufferedImage result = null;
+ logger.logp(Level.INFO, "J2dGraphicsBenchmark", "loadImage",
+ "Loading image: " + imageName);
+
+ // Try to load image out of classpath before trying an absolute filename
+ URL url = getClass().getResource(imageName);
+ Image img;
+ if (url != null)
+ img = Toolkit.getDefaultToolkit().getImage(url);
+ else
+ img = Toolkit.getDefaultToolkit().getImage(imageName);
+
+ if (img != null)
+ {
+ // Wait for image to load
+ try
+ {
+ MediaTracker tracker = new MediaTracker(this);
+ tracker.addImage(img, 1);
+ tracker.waitForAll();
+
+ prepareImage(img, this);
+ result = new BufferedImage(img.getWidth(this), img.getHeight(this),
+ BufferedImage.TYPE_INT_RGB);
+ result.createGraphics().drawImage(img, 0, 0, this);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ if (result == null)
+ {
+ logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "loadBufferedImage",
+ "Could not locate image resource in class path: "
+ + imageName);
+ }
+ return result;
+ }
+
+ /**
+ * Executes the test methods.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ void runTestSet(Graphics2D g, Dimension size)
+ {
+ // Any user-specified options (ie set transforms, rendering hints)
+ prepareGraphics((Graphics2D) g);
+
+ if ((awtTests & J2DTEST_ARC) != 0)
+ {
+ test_drawArc(g, size);
+ test_fillArc(g, size);
+ }
+
+ if ((awtTests & J2DTEST_CUBICCURVE) != 0)
+ {
+ test_drawCubicCurve(g, size);
+ }
+
+ if ((awtTests & J2DTEST_ELLIPSE) != 0)
+ {
+ test_drawEllipse(g, size);
+ test_fillEllipse(g, size);
+ }
+
+ if ((awtTests & J2DTEST_GENERALPATH) != 0)
+ {
+ // Current implementation doesn't work
+ test_drawGeneralPath(g, size);
+ test_fillGeneralPath(g, size);
+ }
+
+ if ((awtTests & J2DTEST_LINE) != 0)
+ {
+ test_drawLine(g, size);
+ }
+
+ if ((awtTests & J2DTEST_QUADCURVE) != 0)
+ {
+ test_drawQuadCurve(g, size);
+ }
+
+ if ((awtTests & J2DTEST_RECTANGLE) != 0)
+ {
+ test_drawRectangle(g, size);
+ test_fillRectangle(g, size);
+ }
+
+ if ((awtTests & J2DTEST_ROUNDRECTANGLE) != 0)
+ {
+ test_drawRoundRectangle(g, size);
+ test_fillRoundRectangle(g, size);
+ }
+
+ if ((awtTests & J2DTEST_IMAGE) != 0)
+ {
+ test_drawImage(g, size);
+ test_drawTransparentImage(g, size);
+ }
+ }
+
+ /**
+ * Reset all graphics settings to the standard, default values
+ *
+ * @param g the object to apply settings to
+ */
+ private void resetGraphics(Graphics2D g)
+ {
+ g.setTransform(new AffineTransform());
+ g.setStroke(new BasicStroke());
+ g.setComposite(AlphaComposite.SrcOut);
+ }
+
+ /**
+ * Sets initial user graphics options
+ *
+ * @param g the object to apply settings to
+ */
+ private void prepareGraphics(Graphics2D g)
+ {
+ // Transforms
+ if (affineTransform != null)
+ g.setTransform(affineTransform);
+
+ else if (xtranslate != 0 || ytranslate != 0 || xshear != 0 || yshear != 0)
+ {
+ g.translate(xtranslate, ytranslate);
+ g.shear(xshear, yshear);
+ }
+
+ if (rotate > 0)
+ g.rotate(rotate * Math.PI, screenWidth / 2, screenHeight / 2);
+
+ // Composite (transparency)
+ if (composite > 0)
+ {
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
+ composite));
+ }
+
+ // Textures
+ if (texture != null)
+ g.setPaint(new TexturePaint(textureImage,
+ new Rectangle(0, 0, textureImage.getWidth(),
+ textureImage.getHeight())));
+
+ // Anti-alias setting
+ if (antialiasFlag)
+ g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON));
+ else
+ g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_OFF));
+ }
+
+ /**
+ * Gets new random settings
+ *
+ * @param g the object to set parameters for
+ * @param size the screen size
+ */
+ private void setRandom(Graphics2D g, Dimension size)
+ {
+ // Set colour / paint
+ if (gradientFlag)
+ {
+ Color c1 = new Color((int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1);
+
+ Color c2 = new Color((int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1);
+
+ g.setPaint(new GradientPaint(0, 0, c1, screenWidth / 5,
+ screenHeight / 5, c2, true));
+ }
+
+ else if (texture == null)
+ g.setPaint(new Color((int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1));
+
+ // Set stroke width and options
+ if (strokeFlag)
+ {
+ int cap = (int) (Math.random() * 3 + 1);
+ if (cap == 1)
+ cap = BasicStroke.CAP_SQUARE;
+ else if (cap == 2)
+ cap = BasicStroke.CAP_BUTT;
+ else
+ cap = BasicStroke.CAP_ROUND;
+
+ int join = (int) (Math.random() * 3 + 1);
+ if (join == 1)
+ join = BasicStroke.JOIN_MITER;
+ else if (join == 2)
+ join = BasicStroke.JOIN_BEVEL;
+ else
+ join = BasicStroke.JOIN_ROUND;
+
+ float[] dashes = { 10, 10 };
+ g.setStroke(new BasicStroke((int) (Math.random() * 10), cap, join, 10f,
+ dashes, 0));
+ }
+
+ // Composite / transparency
+ if (composite == - 1)
+ {
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
+ (float) Math.random()));
+ }
+
+ // Transformations
+ if (rotate == - 1)
+ g.rotate(Math.random() * Math.PI * 2);
+ }
+
+ /**
+ * Draws random arcs within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawArc(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize;
+ long startTime;
+ long endTime;
+ minSize = 10;
+ startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x = (int) (Math.random() * (size.width - minSize + 1));
+ int y = (int) (Math.random() * (size.height - minSize + 1));
+ int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
+ int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
+ int startAngle = (int) (Math.random() * 360);
+ int arcAngle = (int) (Math.random() * 360 - startAngle);
+
+ Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle,
+ Arc2D.OPEN);
+ g.draw(arc);
+ }
+ endTime = System.currentTimeMillis();
+ recordTest("draw(Arc2D.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random filled arcs within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_fillArc(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize;
+ long startTime;
+ long endTime;
+ minSize = 10;
+ startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x = (int) (Math.random() * (size.width - minSize + 1));
+ int y = (int) (Math.random() * (size.height - minSize + 1));
+ int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
+ int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
+ int startAngle = (int) (Math.random() * 360);
+ int arcAngle = (int) (Math.random() * 360);
+
+ Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle,
+ Arc2D.OPEN);
+ g.fill(arc);
+ }
+ endTime = System.currentTimeMillis();
+ recordTest("fill(Arc2D.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random cubic curves within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawCubicCurve(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize = 10;
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x1 = (int) (Math.random() * (size.width - minSize));
+ int y1 = (int) (Math.random() * (size.height - minSize));
+ int xc1 = (int) (Math.random() * (size.width - minSize));
+ int yc1 = (int) (Math.random() * (size.height - minSize));
+ int xc2 = (int) (Math.random() * (size.width - minSize));
+ int yc2 = (int) (Math.random() * (size.height - minSize));
+ int x2 = (int) (Math.random() * (size.width - minSize));
+ int y2 = (int) (Math.random() * (size.height - minSize));
+
+ CubicCurve2D curve = new CubicCurve2D.Double(x1, y1, xc1, yc1, xc2,
+ yc2, x2, y2);
+ g.draw(curve);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("draw(CubicCurve2D.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random ellipses within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawEllipse(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize = 10;
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x1 = (int) (Math.random() * (size.width - minSize));
+ int y1 = (int) (Math.random() * (size.height - minSize));
+ int x2 = (int) (Math.random() * (size.width - minSize));
+ int y2 = (int) (Math.random() * (size.height - minSize));
+ Ellipse2D ellipse = new Ellipse2D.Double(x1, y1, x2, y2);
+ g.draw(ellipse);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("draw(Ellipse.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random ellipses within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_fillEllipse(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize = 10;
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x1 = (int) (Math.random() * (size.width - minSize));
+ int y1 = (int) (Math.random() * (size.height - minSize));
+ int x2 = (int) (Math.random() * (size.width - minSize));
+ int y2 = (int) (Math.random() * (size.height - minSize));
+ Ellipse2D ellipse = new Ellipse2D.Double(x1, y1, x2, y2);
+ g.fill(ellipse);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("fill(Ellipse.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ // TODO: fix the GeneralPath methods.
+ /**
+ * Draws random polygons within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawGeneralPath(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ long startTime = System.currentTimeMillis();
+
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int points = (int) (Math.random() * 6) + 2;
+ GeneralPath shape = new GeneralPath();
+ shape.moveTo((float) Math.random() * (size.width),
+ (float) Math.random() * (size.height));
+ for (int j = 0; j < points; j += 1)
+ {
+ shape.lineTo((float) (Math.random() * (size.width)),
+ (float) (Math.random() * (size.height)));
+ }
+ g.draw(shape);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("draw(GeneralPath) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random filled polygons within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_fillGeneralPath(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ long startTime = System.currentTimeMillis();
+
+ GeneralPath shape = new GeneralPath();
+ shape.moveTo((float) Math.random() * (size.width), (float) Math.random()
+ * (size.height));
+
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int points = (int) (Math.random() * 6) + 2;
+ for (int j = 0; j < points; j += 1)
+ {
+ shape.lineTo((float) (Math.random() * (size.width)),
+ (float) (Math.random() * (size.height)));
+ }
+ g.fill(shape);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("fill(GeneralPath) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random lines within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawLine(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize = 10;
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x1 = (int) (Math.random() * (size.width - minSize));
+ int y1 = (int) (Math.random() * (size.height - minSize));
+ int x2 = (int) (Math.random() * (size.width - minSize));
+ int y2 = (int) (Math.random() * (size.height - minSize));
+ Line2D line = new Line2D.Double(x1, y1, x2, y2);
+ g.draw(line);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("draw(Line2D.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random quadratic curves within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawQuadCurve(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize = 10;
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x1 = (int) (Math.random() * (size.width - minSize));
+ int y1 = (int) (Math.random() * (size.height - minSize));
+ int xc = (int) (Math.random() * (size.width - minSize));
+ int yc = (int) (Math.random() * (size.height - minSize));
+ int x2 = (int) (Math.random() * (size.width - minSize));
+ int y2 = (int) (Math.random() * (size.height - minSize));
+
+ QuadCurve2D curve = new QuadCurve2D.Double(x1, y1, xc, yc, x2, y2);
+ g.draw(curve);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("draw(QuadCurve2D.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random rectangles within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawRectangle(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize = 10;
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x1 = (int) (Math.random() * (size.width - minSize));
+ int y1 = (int) (Math.random() * (size.height - minSize));
+ int x2 = (int) (Math.random() * (size.width - minSize));
+ int y2 = (int) (Math.random() * (size.height - minSize));
+ Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2, y2);
+ g.draw(rect);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("draw(Rectangle.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random rectangles within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_fillRectangle(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize = 10;
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x1 = (int) (Math.random() * (size.width - minSize));
+ int y1 = (int) (Math.random() * (size.height - minSize));
+ int x2 = (int) (Math.random() * (size.width - minSize));
+ int y2 = (int) (Math.random() * (size.height - minSize));
+ Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2, y2);
+ g.fill(rect);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("fill(Rectangle.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random rounded rectangles within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawRoundRectangle(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize;
+ long startTime;
+ long endTime;
+ minSize = 10;
+ startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x = (int) (Math.random() * (size.width - minSize + 1));
+ int y = (int) (Math.random() * (size.height - minSize + 1));
+ int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
+ int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
+ int arcWidth = (int) (Math.random() * (width - 1) + 1);
+ int arcHeight = (int) (Math.random() * (height - 1) + 5);
+ RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width,
+ height, arcWidth,
+ arcHeight);
+ g.draw(rect);
+ }
+ endTime = System.currentTimeMillis();
+ recordTest("draw(RoundRectangle.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random filled rounded rectangles within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_fillRoundRectangle(Graphics2D g, Dimension size)
+ {
+ int maxTests = testSize;
+ int minSize;
+ long startTime;
+ long endTime;
+ minSize = 10;
+ startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x = (int) (Math.random() * (size.width - minSize + 1));
+ int y = (int) (Math.random() * (size.height - minSize + 1));
+ int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
+ int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
+ int arcWidth = (int) (Math.random() * (width - 1) + 1);
+ int arcHeight = (int) (Math.random() * (height - 1) + 5);
+ RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width,
+ height, arcWidth,
+ arcHeight);
+ g.fill(rect);
+ }
+ endTime = System.currentTimeMillis();
+ recordTest("fill(RoundRectangle.Double) " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ /**
+ * Draws random images within the given dimensions.
+ *
+ * @param g The Graphics2D object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawImage(Graphics2D g, Dimension size)
+ {
+ if (gifTestImage == null)
+ {
+ logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "runTestSet",
+ "Skipping 'test_drawImage' due to missing resource.");
+ return;
+ }
+
+ int maxTests = testSize / 2;
+ if (maxTests == 0)
+ maxTests = 1;
+ int imageWidth = gifTestImage.getWidth(this);
+ int imageHeight = gifTestImage.getHeight(this);
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x = (int) (Math.random() * (size.width - imageWidth + 1));
+ int y = (int) (Math.random() * (size.height - imageHeight + 1));
+ g.drawImage(gifTestImage, x, y, this);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("drawImage " + maxTests + " times", (endTime - startTime));
+ }
+
+ /**
+ * Draws random transparent images within the given dimensions.
+ *
+ * @param g The Graphics object that is used to paint.
+ * @param size The size of the canvas.
+ */
+ private void test_drawTransparentImage(Graphics2D g, Dimension size)
+ {
+ if (pngTestImage == null)
+ {
+ logger.logp(Level.WARNING, "AicasGraphicsBenchmark", "runTestSet",
+ "Skipping 'drawTransparentImage' due to missing resource.");
+ return;
+ }
+
+ int maxTests = testSize / 5;
+ if (maxTests == 0)
+ maxTests = 1;
+ int imageWidth = pngTestImage.getWidth(this);
+ int imageHeight = pngTestImage.getHeight(this);
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < maxTests; i += 1)
+ {
+ setRandom(g, size);
+ int x = (int) (Math.random() * (size.width - imageWidth + 1));
+ int y = (int) (Math.random() * (size.height - imageHeight + 1));
+ g.drawImage(pngTestImage, x, y, this);
+ }
+ long endTime = System.currentTimeMillis();
+ recordTest("draw transparent image " + maxTests + " times",
+ (endTime - startTime));
+ }
+
+ private class GraphicsTest
+ extends Canvas
+ implements Runnable
+ {
+ Thread paintThread;
+
+ boolean done = false;
+
+ boolean doPaint = false;
+
+ boolean withClipping = false;
+
+ public GraphicsTest()
+ {
+ paintThread = new Thread(this);
+ paintThread.start();
+ }
+
+ public void run()
+ {
+ int runCount = 0;
+ while (! done)
+ {
+ runCount++;
+
+ try
+ {
+ synchronized (this)
+ {
+ while (! doPaint)
+ {
+ try
+ {
+ wait(200);
+ }
+ catch (InterruptedException exception)
+ {
+ return;
+ }
+ }
+ }
+
+ // if (iterations != 0)
+ // System.out.println("--- run...("
+ // + runCount
+ // + "/"
+ // + iterations
+ // + ") ------------------------------------------------------");
+
+ Graphics g = getGraphics();
+ Dimension size = getSize();
+
+ if (singleBufferFlag)
+ {
+ logger.logp(Level.INFO, "J2dGraphicsBenchmark.GraphicsTest",
+ "run",
+ "Start testing non-double-buffered drawing");
+
+ if (noClippingFlag)
+ runSet_noClipping((Graphics2D) g, size, runCount);
+
+ if (withClippingFlag)
+ runSet_withClipping((Graphics2D) g, size, runCount);
+
+ if (zeroClippingFlag)
+ runSet_zeroClipping((Graphics2D) g, size, runCount);
+
+ g.dispose();
+ }
+
+ if (doubleBufferFlag)
+ {
+ logger.logp(Level.INFO, "J2dGraphicsBenchmark.GraphicsTest",
+ "run", "Start testing double-buffered drawing");
+ Graphics canvas = getGraphics();
+ Image doublebuffer = createImage(size.width, size.height);
+
+ if (noClippingFlag)
+ {
+ g = doublebuffer.getGraphics();
+ runSet_noClipping((Graphics2D) g, size,
+ "double buffering", runCount);
+ g.dispose();
+ canvas.drawImage(doublebuffer, 0, 0, this);
+ }
+
+ if (withClippingFlag)
+ {
+ g = doublebuffer.getGraphics();
+ runSet_withClipping((Graphics2D) g, size,
+ "double buffering", runCount);
+ g.dispose();
+ canvas.drawImage(doublebuffer, 0, 0, this);
+ }
+
+ if (zeroClippingFlag)
+ {
+ g = doublebuffer.getGraphics();
+ runSet_zeroClipping((Graphics2D) g, size,
+ "double buffering", runCount);
+ g.dispose();
+ canvas.drawImage(doublebuffer, 0, 0, this);
+ canvas.dispose();
+ }
+ }
+
+ printReport();
+
+ if (iterations != 1)
+ {
+ if (iterations != - 1)
+ iterations--;
+ }
+ else
+ {
+ // System.out.println("--- done
+ // --------------------------------------------------------");
+ synchronized (this)
+ {
+ doPaint = false;
+ }
+ done = true;
+ }
+ }
+ catch (Error error)
+ {
+ System.err.println("Error: " + error);
+ System.exit(129);
+ }
+ }
+ testComplete();
+ }
+
+ private void runSet_zeroClipping(Graphics2D g, Dimension size, int runCount)
+ {
+ runSet_zeroClipping(g, size, "", runCount);
+ }
+
+ private void runSet_zeroClipping(Graphics2D g, Dimension size,
+ String context, int runCount)
+ {
+ int clipped_width;
+ int clipped_height;
+ int clipped_x;
+ int clipped_y;
+
+ clipped_width = 0;
+ clipped_height = 0;
+ clipped_x = (size.width) / 2;
+ clipped_y = (size.height) / 2;
+
+ // Reset any transforms from past tests
+ resetGraphics(g);
+
+ Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
+ g.setClip(fullWindow);
+ g.setPaint(Color.BLACK);
+ g.fill(fullWindow);
+
+ Rectangle windowBorder = new Rectangle(0, 0, size.width - 1,
+ size.width - 1);
+ g.setPaint(Color.WHITE);
+ g.draw(windowBorder);
+
+ Rectangle innerBorder = new Rectangle(clipped_x - 1, clipped_y - 1,
+ clipped_width + 2,
+ clipped_height + 2);
+ g.fill(innerBorder);
+
+ Rectangle innerBox = new Rectangle(clipped_x, clipped_y, clipped_width,
+ clipped_height);
+ g.clip(innerBox);
+ g.setPaint(Color.BLACK);
+ g.fill(fullWindow);
+
+ if (context.equals(""))
+ setTestContext("(" + runCount + ") clipping to zero");
+ else
+ setTestContext("(" + runCount + ") clipping to zero (" + context + ")");
+
+ runTestSet(g, size);
+ }
+
+ private void runSet_withClipping(Graphics2D g, Dimension size, int runCount)
+ {
+ runSet_withClipping(g, size, "", runCount);
+ }
+
+ private void runSet_withClipping(Graphics2D g, Dimension size,
+ String context, int runCount)
+ {
+ int clipped_width = 2 * size.width / 3;
+ int clipped_height = 2 * size.height / 3;
+ int clipped_x = (size.width - clipped_width) / 2;
+ int clipped_y = (size.height - clipped_height) / 2;
+
+ // Reset any transforms from past tests
+ resetGraphics(g);
+
+ Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
+ g.setClip(fullWindow);
+
+ g.setPaint(Color.BLACK);
+ g.fill(fullWindow);
+
+ Rectangle windowBorder = new Rectangle(0, 0, size.width - 1,
+ size.height - 1);
+ g.setPaint(Color.GREEN);
+ g.draw(windowBorder);
+
+ Rectangle innerBorder = new Rectangle(clipped_x - 1, clipped_y - 1,
+ clipped_width + 2,
+ clipped_height + 2);
+ g.setPaint(Color.WHITE);
+ g.fill(innerBorder);
+
+ Rectangle innerBox = new Rectangle(clipped_x, clipped_y, clipped_width,
+ clipped_height);
+ g.clip(innerBox);
+
+ g.setPaint(Color.BLACK);
+ g.fill(fullWindow);
+
+ if (context.equals(""))
+ setTestContext("(" + runCount + ") with clipping ");
+ else
+ setTestContext("(" + runCount + ") with clipping (" + context + ")");
+
+ runTestSet(g, size);
+ }
+
+ private void runSet_noClipping(Graphics2D g, Dimension size, int runCount)
+ {
+ runSet_noClipping(g, size, "", runCount);
+ }
+
+ private void runSet_noClipping(Graphics2D g, Dimension size,
+ String context, int runCount)
+ {
+ // Reset any transforms from past tests
+ resetGraphics(g);
+
+ Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
+ g.setPaint(Color.BLACK);
+ g.fill(fullWindow);
+
+ if (context.equals(""))
+ setTestContext("(" + runCount + ") without clipping");
+ else
+ setTestContext("(" + runCount + ") without clipping (" + context + ")");
+
+ runTestSet(g, size);
+ }
+
+ public void paint(Graphics g)
+ {
+ synchronized (this)
+ {
+ doPaint = true;
+ notify();
+ }
+ }
+ }
+}
+
+class TestContext
+{
+}
+
+class TestSet
+{
+ private Map testsMap = new TreeMap();
+
+ public void putTest(String testName, TestRecorder recoder)
+ {
+ testsMap.put(testName, recoder);
+ }
+
+ public TestRecorder getTest(String testName)
+ {
+ return (TestRecorder) testsMap.get(testName);
+ }
+
+ public Iterator testIterator()
+ {
+ return testsMap.keySet().iterator();
+ }
+}
+
+class TestRecorder
+{
+ String test;
+
+ long totalTime = 0;
+
+ long minTime = Long.MAX_VALUE;
+
+ long maxTime = Long.MIN_VALUE;
+
+ int runCount = 0;
+
+ /**
+ * @return Returns the maxTime.
+ */
+ public final long getMaxTime()
+ {
+ return maxTime;
+ }
+
+ /**
+ * @return Returns the minTime.
+ */
+ public final long getMinTime()
+ {
+ return minTime;
+ }
+
+ /**
+ * @return Returns the test name.
+ */
+ public final String getTestName()
+ {
+ return test;
+ }
+
+ public final long getAverage()
+ {
+ return (totalTime / runCount);
+ }
+
+ public TestRecorder(String testName)
+ {
+ test = testName;
+ }
+
+ public void addRun(long time)
+ {
+ totalTime += time;
+ if (minTime > time)
+ minTime = time;
+ if (maxTime < time)
+ maxTime = time;
+ runCount += 1;
+ }
+}
diff --git a/examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java b/examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java
new file mode 100644
index 000000000..bb583cbdc
--- /dev/null
+++ b/examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java
@@ -0,0 +1,891 @@
+/* J2dBenchmarkGUI.java -- GUI for java2d benchmarker
+ 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.classpath.examples.java2d;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
+
+/**
+ * Extends the J2dBenchmark to provide a GUI for selecting options and tests.
+ */
+public class J2dBenchmarkGUI
+ implements ActionListener
+{
+
+ JLabel errorLabel;
+
+ JCheckBox noClipping;
+
+ JCheckBox withClipping;
+
+ JCheckBox zeroClipping;
+
+ JCheckBox singleBuffer;
+
+ JCheckBox doubleBuffer;
+
+ public J2dBenchmarkGUI()
+ {
+ super();
+ }
+
+ public static void main(String[] args)
+ {
+ new J2dBenchmarkGUI().run();
+ }
+
+ /**
+ * Sets up the initial GUI
+ */
+ public void run()
+ {
+ // Store all elements in a hashtable so that they can be passed into the
+ // harness easily.
+ Hashtable elements = new Hashtable();
+
+ // Set up frame
+ final JFrame frame = new JFrame("Java2D benchmark");
+ errorLabel = new JLabel(" ");
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
+ Container content = frame.getContentPane();
+
+ // Display options for dimensions, iterations, test size, etc
+ JPanel options = new JPanel(new GridLayout(0, 2));
+
+ options.add(new JLabel("Height: "));
+ JTextField heightField = new JTextField(Integer.toString(J2dBenchmark.DEFAULT_SCREEN_HEIGHT));
+ heightField.setColumns(5);
+ options.add(heightField);
+ elements.put("height", heightField);
+
+ options.add(new JLabel("Width: "));
+ JTextField widthField = new JTextField(Integer.toString(J2dBenchmark.DEFAULT_SCREEN_WIDTH));
+ widthField.setColumns(5);
+ options.add(widthField);
+ elements.put("width", widthField);
+
+ options.add(new JLabel("Iterations: "));
+ JTextField iterField = new JTextField("1");
+ iterField.setColumns(5);
+ options.add(iterField);
+ elements.put("iterations", iterField);
+
+ options.add(new JLabel("Test size: "));
+ JTextField testSizeField = new JTextField(Integer.toString(J2dBenchmark.DEFAULT_TEST_SIZE));
+ testSizeField.setColumns(5);
+ options.add(testSizeField);
+ elements.put("size", testSizeField);
+
+ options.add(new JLabel("Test without clipping: "));
+ noClipping = new JCheckBox("", true);
+ noClipping.addActionListener(this);
+ options.add(noClipping);
+ elements.put("noclip", noClipping);
+
+ options.add(new JLabel("Test with clipping: "));
+ withClipping = new JCheckBox("", true);
+ withClipping.addActionListener(this);
+ options.add(withClipping);
+ elements.put("withclip", withClipping);
+
+ options.add(new JLabel("Test with clipping to zero: "));
+ zeroClipping = new JCheckBox("", true);
+ zeroClipping.addActionListener(this);
+ options.add(zeroClipping);
+ elements.put("zeroclip", zeroClipping);
+
+ options.add(new JLabel("Run single-buffer test: "));
+ singleBuffer = new JCheckBox("", true);
+ singleBuffer.addActionListener(this);
+ options.add(singleBuffer);
+ elements.put("singlebuffer", singleBuffer);
+
+ options.add(new JLabel("Run double-buffer test: "));
+ doubleBuffer = new JCheckBox("", true);
+ doubleBuffer.addActionListener(this);
+ options.add(doubleBuffer);
+ elements.put("doublebuffer", doubleBuffer);
+
+ // Allow user to select tests to run
+ JPanel tests = new JPanel();
+ tests.setLayout(new BoxLayout(tests, BoxLayout.PAGE_AXIS));
+ tests.setBorder(new BevelBorder(BevelBorder.RAISED));
+ tests.add(new JLabel("Shapes to test:"));
+
+ JCheckBox test_arcDraw = new JCheckBox("Arc", true);
+ tests.add(test_arcDraw);
+ elements.put("test_arcDraw", test_arcDraw);
+
+ JCheckBox test_ccurveDraw = new JCheckBox("Cubic Curve", true);
+ tests.add(test_ccurveDraw);
+ elements.put("test_ccurveDraw", test_ccurveDraw);
+
+ JCheckBox test_ellipseDraw = new JCheckBox("Ellipse", true);
+ tests.add(test_ellipseDraw);
+ elements.put("test_ellipseDraw", test_ellipseDraw);
+
+ /*
+ JCheckBox test_pathDraw = new JCheckBox("General Path", true);
+ tests.add(test_pathDraw);
+ elements.put("test_pathDraw", test_pathDraw);
+ */
+
+ JCheckBox test_lineDraw = new JCheckBox("Line", true);
+ tests.add(test_lineDraw);
+ elements.put("test_lineDraw", test_lineDraw);
+
+ JCheckBox test_qcurveDraw = new JCheckBox("Quadratic Curve", true);
+ tests.add(test_qcurveDraw);
+ elements.put("test_qcurveDraw", test_qcurveDraw);
+
+ JCheckBox test_rectDraw = new JCheckBox("Rectangle", true);
+ tests.add(test_rectDraw);
+ elements.put("test_rectDraw", test_rectDraw);
+
+ JCheckBox test_rrectDraw = new JCheckBox("Round Rectangle", true);
+ tests.add(test_rrectDraw);
+ elements.put("test_rrectDraw", test_rrectDraw);
+
+ JCheckBox test_image = new JCheckBox("Images", true);
+ tests.add(test_image);
+ elements.put("test_image", test_image);
+
+ // Additional image-processing options
+ JPanel extras = new JPanel();
+ extras.setBorder(new BevelBorder(BevelBorder.LOWERED));
+ GridBagLayout layout = new GridBagLayout();
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.anchor = GridBagConstraints.NORTHWEST;
+ gbc.insets = new Insets(5, 2, 15, 15);
+ extras.setLayout(layout);
+
+ // Filling (solid, gradient, or texture)
+ JPanel opt_Fill = new JPanel();
+ opt_Fill.setLayout(new BoxLayout(opt_Fill, BoxLayout.PAGE_AXIS));
+ JLabel opt_FillLabel = new JLabel("Filling:");
+ opt_FillLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ opt_Fill.add(opt_FillLabel);
+
+ ButtonGroup opt_FillGroup = new ButtonGroup();
+ JRadioButton opt_FillSolid = new JRadioButton("Solid colour", true);
+ opt_FillSolid.setActionCommand("solid");
+ opt_Fill.add(opt_FillSolid);
+ opt_FillGroup.add(opt_FillSolid);
+ JRadioButton opt_FillGradient = new JRadioButton("Gradient", false);
+ opt_FillGradient.setActionCommand("gradient");
+ opt_Fill.add(opt_FillGradient);
+ opt_FillGroup.add(opt_FillGradient);
+ JRadioButton opt_FillTexture = new JRadioButton("Texture", false);
+ opt_FillTexture.setActionCommand("texture");
+ opt_Fill.add(opt_FillTexture);
+ opt_FillGroup.add(opt_FillTexture);
+ JTextField opt_FillTextureFile = new JTextField("texture file");
+ opt_FillTextureFile.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ opt_Fill.add(opt_FillTextureFile);
+ elements.put("opt_FillGroup", opt_FillGroup);
+ elements.put("opt_FillTextureFile", opt_FillTextureFile);
+ layout.setConstraints(opt_Fill, gbc);
+ extras.add(opt_Fill);
+
+ // Stroke
+ JPanel opt_Stroke = new JPanel();
+ opt_Stroke.setLayout(new BoxLayout(opt_Stroke, BoxLayout.PAGE_AXIS));
+ JLabel opt_StrokeLabel = new JLabel("Stroke:");
+ opt_StrokeLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ opt_Stroke.add(opt_StrokeLabel);
+ JCheckBox opt_StrokeRandom = new JCheckBox("random", false);
+ elements.put("opt_StrokeRandom", opt_StrokeRandom);
+ opt_Stroke.add(opt_StrokeRandom);
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ layout.setConstraints(opt_Stroke, gbc);
+ extras.add(opt_Stroke);
+
+ // Anti-Alias
+ JPanel opt_Alias = new JPanel();
+ opt_Alias.setLayout(new BoxLayout(opt_Alias, BoxLayout.PAGE_AXIS));
+ JLabel opt_AliasLabel = new JLabel("Anti-Aliasing:");
+ opt_AliasLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ opt_Alias.add(opt_AliasLabel);
+ JCheckBox opt_AliasOn = new JCheckBox("on", false);
+ elements.put("opt_AliasOn", opt_AliasOn);
+ opt_Alias.add(opt_AliasOn);
+ gbc.gridwidth = 1;
+ layout.setConstraints(opt_Alias, gbc);
+ extras.add(opt_Alias);
+
+ // Alpha composite
+ JPanel opt_Composite = new JPanel();
+ opt_Composite.setLayout(new BoxLayout(opt_Composite, BoxLayout.PAGE_AXIS));
+ JLabel opt_CompositeLabel = new JLabel("Alpha Composite:");
+ opt_CompositeLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ opt_Composite.add(opt_CompositeLabel);
+ JTextField opt_CompositeValue = new JTextField("1.0");
+ opt_CompositeValue.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ elements.put("opt_CompositeValue", opt_CompositeValue);
+ opt_Composite.add(opt_CompositeValue);
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ layout.setConstraints(opt_Composite, gbc);
+ extras.add(opt_Composite);
+
+ // Transformations
+ // TODO: allow user-defined matrices for AffineTransform
+ // (backend already has hooks for it, need to create gui)
+ JLabel opt_TransformLabel = new JLabel("Transformations:");
+ opt_TransformLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ gbc.insets = new Insets(5, 2, 0, 15);
+ layout.setConstraints(opt_TransformLabel, gbc);
+ extras.add(opt_TransformLabel);
+
+ JPanel opt_Transform_Translate = new JPanel(new GridLayout(0, 2, 5, 5));
+ opt_Transform_Translate.add(new JLabel("x-axis translation "));
+ JTextField opt_TransformTranslateX = new JTextField("0");
+ opt_TransformTranslateX.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ opt_Transform_Translate.add(opt_TransformTranslateX);
+ elements.put("opt_TransformTranslateX", opt_TransformTranslateX);
+ opt_Transform_Translate.add(new JLabel("y-axis translation "));
+ JTextField opt_TransformTranslateY = new JTextField("0");
+ opt_TransformTranslateY.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ opt_Transform_Translate.add(opt_TransformTranslateY);
+ elements.put("opt_TransformTranslateY", opt_TransformTranslateY);
+ gbc.gridwidth = 1;
+ gbc.insets = new Insets(0, 2, 5, 15);
+ layout.setConstraints(opt_Transform_Translate, gbc);
+ extras.add(opt_Transform_Translate);
+
+ JPanel opt_Transform_Shear = new JPanel(new GridLayout(0, 2, 5, 5));
+ opt_Transform_Shear.add(new JLabel("x-axis shear "));
+ JTextField opt_TransformShearX = new JTextField("0");
+ opt_TransformShearX.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ opt_Transform_Shear.add(opt_TransformShearX);
+ elements.put("opt_TransformShearX", opt_TransformShearX);
+ opt_Transform_Shear.add(new JLabel("y-axis shear "));
+ JTextField opt_TransformShearY = new JTextField("0");
+ opt_Transform_Shear.add(opt_TransformShearY);
+ elements.put("opt_TransformShearY", opt_TransformShearY);
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ layout.setConstraints(opt_Transform_Shear, gbc);
+ extras.add(opt_Transform_Shear);
+
+ JPanel opt_Transform_Rotate = new JPanel(new GridLayout(0, 2, 5, 5));
+ opt_Transform_Rotate.add(new JLabel("rotation (radians) "));
+ JTextField opt_TransformRotate = new JTextField("0");
+ opt_Transform_Rotate.add(opt_TransformRotate);
+ elements.put("opt_TransformRotate", opt_TransformRotate);
+ layout.setConstraints(opt_Transform_Rotate, gbc);
+ extras.add(opt_Transform_Rotate);
+
+ // Final submit button
+ JPanel submit = new JPanel();
+ submit.setLayout(new BoxLayout(submit, BoxLayout.PAGE_AXIS));
+
+ JButton rectButton = new JButton("Run benchmark");
+ rectButton.setAlignmentX(JComponent.CENTER_ALIGNMENT);
+ submit.add(rectButton, BorderLayout.CENTER);
+
+ errorLabel.setAlignmentX(JComponent.CENTER_ALIGNMENT);
+ errorLabel.setForeground(Color.RED);
+ submit.add(errorLabel);
+
+ rectButton.addActionListener(new Harness(elements, errorLabel));
+
+ // Lay it all out
+ JPanel body = new JPanel();
+ body.setLayout(new BoxLayout(body, BoxLayout.LINE_AXIS));
+ options.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ body.add(options);
+ body.add(Box.createHorizontalStrut(50));
+ tests.setAlignmentX(JComponent.RIGHT_ALIGNMENT);
+ body.add(tests);
+
+ body.setAlignmentX(JComponent.CENTER_ALIGNMENT);
+ panel.add(body);
+ extras.setAlignmentX(JComponent.CENTER_ALIGNMENT);
+ panel.add(extras);
+ submit.setAlignmentX(JComponent.CENTER_ALIGNMENT);
+ panel.add(submit);
+
+ content.add(panel, BorderLayout.CENTER);
+
+ // Leave some breathing space in the frame
+ frame.pack();
+
+ frame.addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ frame.setVisible(false);
+ System.exit(0);
+ }
+ });
+
+ frame.show();
+ }
+
+ /**
+ * Handles user events on the options GUI, ensuring that user input is valid
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ if (! noClipping.isSelected() && ! withClipping.isSelected()
+ && ! zeroClipping.isSelected())
+ errorLabel.setText("You must select at least one clipping option");
+
+ else if (! singleBuffer.isSelected() && ! doubleBuffer.isSelected())
+ errorLabel.setText("You must select at least one buffering option");
+
+ else
+ errorLabel.setText(" ");
+ }
+
+ /**
+ * Parses GUI input and sets options in the benchmarker
+ */
+ private class Harness
+ implements ActionListener
+ {
+ Hashtable elements;
+
+ JLabel errorLabel;
+
+ /**
+ * Creates a new Harness object
+ *
+ * @param elements Hashtable containing the swing elements from the GUI
+ * @param errorLabel JLabel on which to display any error messages
+ */
+ public Harness(Hashtable elements, JLabel errorLabel)
+ {
+ super();
+
+ this.elements = elements;
+ this.errorLabel = errorLabel;
+ }
+
+ /**
+ * Handles user button-clicks, parsing the form, setting options, and
+ * starting the J2dBenchmark
+ *
+ * @param ae event that triggered this action
+ */
+ public void actionPerformed(ActionEvent ae)
+ {
+ try
+ {
+ // Create benchmarker object
+ final JFrame frame = new JFrame("Java2D benchmark");
+ J2dBenchmarkWrapper speed = new J2dBenchmarkWrapper(frame);
+
+ // Set options
+ speed.setDimensions(Integer.parseInt(((JTextField) elements.get("width")).getText()),
+ Integer.parseInt(((JTextField) elements.get("height")).getText()));
+
+ speed.setIterations(Integer.parseInt(((JTextField) elements.get("iterations")).getText()));
+ speed.setTestSize(Integer.parseInt(((JTextField) elements.get("size")).getText()));
+
+ speed.setClipping(((JCheckBox) elements.get("noclip")).isSelected(),
+ ((JCheckBox) elements.get("withclip")).isSelected(),
+ ((JCheckBox) elements.get("zeroclip")).isSelected());
+
+ speed.setBuffers(((JCheckBox) elements.get("singlebuffer")).isSelected(),
+ ((JCheckBox) elements.get("doublebuffer")).isSelected());
+
+ // Set additional processing options
+ speed.setFill(((ButtonGroup) elements.get("opt_FillGroup")).getSelection().getActionCommand(),
+ ((JTextField) elements.get("opt_FillTextureFile")).getText());
+
+ speed.setStroke(((JCheckBox) elements.get("opt_StrokeRandom")).isSelected());
+
+ speed.setAlias(((JCheckBox) elements.get("opt_AliasOn")).isSelected());
+
+ speed.setComposite(Float.parseFloat(((JTextField) elements.get("opt_CompositeValue")).getText()));
+
+ speed.setTranslation(Integer.parseInt(((JTextField) elements.get("opt_TransformTranslateX")).getText()),
+ Integer.parseInt(((JTextField) elements.get("opt_TransformTranslateY")).getText()));
+
+ speed.setRotation(Double.parseDouble(((JTextField) elements.get("opt_TransformRotate")).getText()));
+
+ speed.setShear(Double.parseDouble(((JTextField) elements.get("opt_TransformShearX")).getText()),
+ Double.parseDouble(((JTextField) elements.get("opt_TransformShearY")).getText()));
+
+ // Set tests
+ int testSuite = 0;
+ if (((JCheckBox) elements.get("test_arcDraw")).isSelected())
+ testSuite |= J2dBenchmarkWrapper.J2DTEST_ARC;
+ if (((JCheckBox) elements.get("test_ccurveDraw")).isSelected())
+ testSuite |= J2dBenchmarkWrapper.J2DTEST_CUBICCURVE;
+ if (((JCheckBox) elements.get("test_ellipseDraw")).isSelected())
+ testSuite |= J2dBenchmarkWrapper.J2DTEST_ELLIPSE;
+ //if (((JCheckBox)elements.get("test_pathDraw")).isSelected())
+ // testSuite |= J2dBenchmarkWrapper.J2DTEST_GENERALPATH;
+ if (((JCheckBox) elements.get("test_lineDraw")).isSelected())
+ testSuite |= J2dBenchmarkWrapper.J2DTEST_LINE;
+ if (((JCheckBox) elements.get("test_qcurveDraw")).isSelected())
+ testSuite |= J2dBenchmarkWrapper.J2DTEST_QUADCURVE;
+ if (((JCheckBox) elements.get("test_rectDraw")).isSelected())
+ testSuite |= J2dBenchmarkWrapper.J2DTEST_RECTANGLE;
+ if (((JCheckBox) elements.get("test_rrectDraw")).isSelected())
+ testSuite |= J2dBenchmarkWrapper.J2DTEST_ROUNDRECTANGLE;
+ if (((JCheckBox) elements.get("test_image")).isSelected())
+ testSuite |= J2dBenchmarkWrapper.J2DTEST_IMAGE;
+
+ if (testSuite != 0)
+ {
+ speed.setTests(testSuite);
+
+ String initResult = speed.init();
+
+ if (initResult == null)
+ {
+ // Create graphics.
+ frame.add(speed, BorderLayout.CENTER);
+ frame.setSize(
+ Integer.parseInt(((JTextField) elements.get("width")).getText()),
+ Integer.parseInt(((JTextField) elements.get("height")).getText()));
+ frame.setVisible(true);
+
+ // Insets are correctly set only after the native peer was
+ // created.
+ Insets insets = frame.getInsets();
+ frame.setSize(frame.getWidth() + insets.right + insets.left,
+ frame.getHeight() + insets.top + insets.bottom);
+
+ // Clear any old error messages
+ errorLabel.setText(" ");
+ }
+ else
+ errorLabel.setText(initResult);
+ }
+ else
+ errorLabel.setText("Please select at least one test.");
+ }
+ catch (NumberFormatException e)
+ {
+ errorLabel.setText("Please enter valid integers");
+ }
+ }
+ }
+
+ /**
+ * Wrapper for the J2dBenchmark, which outputs the results to a GUI
+ * instead of the command-line
+ */
+ private class J2dBenchmarkWrapper
+ extends J2dBenchmark
+ {
+ JFrame myFrame;
+
+ ResultsDisplay display;
+
+ /**
+ * Create new J2dBenchmarkWrapper object
+ *
+ * @param frame parent frame
+ */
+ public J2dBenchmarkWrapper(JFrame frame)
+ {
+ // Redirect log messages to the custom handler
+ logger.setUseParentHandlers(false);
+ display = new ResultsDisplay();
+ display.setLevel(Level.INFO);
+ logger.addHandler(display);
+
+ myFrame = frame;
+ }
+
+ /**
+ * Set dimensions of benchmarking canvas
+ *
+ * @param width width of canvas
+ * @param height height of canvas
+ */
+ public void setDimensions(int width, int height)
+ {
+ screenHeight = height;
+ screenWidth = width;
+ setSize(width, height);
+ }
+
+ /**
+ * Set number of iterations
+ *
+ * @param it number of iterations
+ */
+ public void setIterations(int it)
+ {
+ iterations = it;
+ }
+
+ /**
+ * Set size of each test
+ *
+ * @param size size of test
+ */
+ public void setTestSize(int size)
+ {
+ testSize = size;
+ }
+
+ /**
+ * Set clipping options
+ *
+ * @param no run test with no clipping
+ * @param with run test with clipping
+ * @param zero run test with clipping to zero
+ */
+ public void setClipping(boolean no, boolean with, boolean zero)
+ {
+ this.noClippingFlag = no;
+ this.withClippingFlag = with;
+ this.zeroClippingFlag = zero;
+ }
+
+ /**
+ * Set buffering options
+ *
+ * @param single run test without double-buffering
+ * @param doubleb run test with double-buffering
+ */
+ public void setBuffers(boolean single, boolean doubleb)
+ {
+ this.singleBufferFlag = single;
+ this.doubleBufferFlag = doubleb;
+ }
+
+ /**
+ * Set fill options
+ *
+ * @param type fill type: "solid", "gradient", or "texture"
+ * @param file filename to use if texturing
+ */
+ public void setFill(String type, String file)
+ {
+ if (type.equals("gradient"))
+ this.gradientFlag = true;
+ else if (type.equals("texture"))
+ {
+ this.texture = file;
+ }
+ }
+
+ /**
+ * Set stroke options
+ *
+ * @param stroke boolean flag to use random stroking or not
+ */
+ public void setStroke(boolean stroke)
+ {
+ this.strokeFlag = stroke;
+ }
+
+ /**
+ * Set anti-aliasing options
+ *
+ * @param alias boolean flag to use anti-aliasing or not
+ */
+ public void setAlias(boolean alias)
+ {
+ this.antialiasFlag = alias;
+ }
+
+ /**
+ * Set alpha composite
+ *
+ * @param alpha alpha composite
+ */
+ public void setComposite(float alpha)
+ {
+ this.composite = alpha;
+ }
+
+ /**
+ * Set translation values
+ *
+ * @param x x-axis translation
+ * @param y y-axis translation
+ */
+ public void setTranslation(int x, int y)
+ {
+ this.xtranslate = x;
+ this.ytranslate = y;
+ }
+
+ /**
+ * Set rotation
+ *
+ * @param theta angle to rotate by (radians)
+ */
+ public void setRotation(double theta)
+ {
+ this.rotate = theta;
+ }
+
+ /**
+ * Set shear values
+ *
+ * @param x x-axis shear value
+ * @param y-axis shear value
+ */
+ public void setShear(double x, double y)
+ {
+ this.xshear = x;
+ this.yshear = y;
+ }
+
+ /**
+ * Set tests to run
+ *
+ * @param tests bit-shifted list of tests (see J2dBenchmark constants)
+ */
+ public void setTests(int tests)
+ {
+ awtTests = tests;
+ }
+
+ /**
+ * Saves test report after each iteration
+ */
+ void printReport()
+ {
+ // Report test results to the GUI display
+ ArrayList results = new ArrayList();
+ for (Iterator i = testSetMap.testIterator(); i.hasNext();)
+ {
+ TestRecorder recorder = testSetMap.getTest((String) i.next());
+
+ results.add("TEST " + recorder.getTestName() + ": average "
+ + recorder.getAverage() + "ms [" + recorder.getMinTime()
+ + "-" + recorder.getMaxTime() + "]");
+ }
+
+ display.report(results);
+ }
+
+ /**
+ * Disables current frame and displays test results
+ */
+ void testComplete()
+ {
+ // Clear benchmarking canvas and display results instead
+ myFrame.setVisible(false);
+
+ display.show();
+ }
+ }
+
+ /**
+ * GUI to display results of benchmarking
+ */
+ private class ResultsDisplay
+ extends Handler
+ implements ActionListener
+ {
+ /**
+ * Allow user to select results from each iteration
+ */
+ JComboBox iterations;
+
+ /**
+ * Area to print results in
+ */
+ JTextArea results;
+
+ /**
+ * Allow user to view summary or full details of test report
+ */
+ JCheckBox details;
+
+ /**
+ * Store all test results
+ */
+ ArrayList testResults;
+
+ /**
+ * Store all test details
+ */
+ ArrayList testDetails;
+
+ /**
+ * Initialize variables
+ */
+ public ResultsDisplay()
+ {
+ testResults = new ArrayList();
+ testDetails = new ArrayList();
+ testDetails.add(new ArrayList());
+ }
+
+ /**
+ * Parse all results and display on a GUI
+ */
+ public void show()
+ {
+ // Set up panel
+ JFrame frame = new JFrame("Java2D benchmark results");
+ Container cp = frame.getContentPane();
+
+ // Non-editable text area for the results
+ results = new JTextArea();
+ results.setEditable(false);
+ results.setRows(15);
+ results.setColumns(60);
+
+ // Checkbox to optionally display details (ie log messages)
+ details = new JCheckBox("Details", false);
+ details.addActionListener(this);
+
+ // Combo box to allow selection of iteration number
+ iterations = new JComboBox();
+ iterations.addActionListener(this);
+ for (int i = 0; i < testResults.size(); i++)
+ iterations.addItem("Iteration #" + (i + 1));
+
+ // Lay it all out
+ JPanel topleft = new JPanel();
+ topleft.add(new JLabel("View results from: "));
+ topleft.add(iterations);
+ topleft.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ details.setAlignmentX(JComponent.RIGHT_ALIGNMENT);
+ JPanel top = new JPanel();
+ top.setLayout(new BoxLayout(top, BoxLayout.LINE_AXIS));
+ top.add(topleft);
+ top.add(details);
+
+ cp.add(top, BorderLayout.NORTH);
+ cp.add(new JScrollPane(results), BorderLayout.SOUTH);
+
+ frame.pack();
+ frame.show();
+ }
+
+ /**
+ * This overrides the logger publish method, which accepts log messages and
+ * saves them for later display
+ *
+ * @param record information about the log event
+ */
+ public void publish(LogRecord record)
+ {
+ ((ArrayList) testDetails.get(testDetails.size() - 1)).add(record.getMessage());
+ }
+
+ /**
+ * Accepts a test summary report, generated after each iteration of a test
+ *
+ * @param results test results
+ */
+ public void report(ArrayList results)
+ {
+ testResults.add(results);
+ testDetails.add(new ArrayList());
+ }
+
+ /**
+ * Provided as part of the Handler interface; not used
+ */
+ public void flush()
+ {
+ }
+
+ /**
+ * Provided as part of the Handler interface; not used
+ */
+ public void close()
+ {
+ }
+
+ /**
+ * Handle user-generated events on the results GUI
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ // Display information about the requested iteration
+ int iteration = iterations.getSelectedIndex();
+ String message = "";
+
+ // Display summary or details, as requested
+ Iterator it;
+ if (details.isSelected())
+ it = ((ArrayList) testDetails.get(iteration)).iterator();
+ else
+ it = ((ArrayList) testResults.get(iteration)).iterator();
+
+ // Parse the ArrayList's
+ while (it.hasNext())
+ {
+ message = message + ((String) it.next() + "\n");
+ }
+
+ // Output to screen
+ results.setText(message);
+ }
+ }
+
+}
diff --git a/examples/gnu/classpath/examples/java2d/JNIOverhead.java b/examples/gnu/classpath/examples/java2d/JNIOverhead.java
new file mode 100644
index 000000000..efa57d2a3
--- /dev/null
+++ b/examples/gnu/classpath/examples/java2d/JNIOverhead.java
@@ -0,0 +1,390 @@
+/* JNIOverhead.java - demonstrator for classpath/gcj fillrect performance issue
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath examples.
+
+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. */
+
+package gnu.classpath.examples.java2d;
+
+import gnu.classpath.examples.swing.DemoFactory;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+/**
+ * @author Norman Hendrich
+ */
+public class JNIOverhead
+ extends JPanel
+ implements ActionListener
+{
+
+ static JNIOverhead fillRectDemo;
+
+ LCDCanvas lcd;
+ Worker worker;
+ JLabel label;
+ JCheckBox translate;
+ JCheckBox lines;
+
+ int nx = 128;
+ int ny = 64;
+ int matrix[][], future[][];
+ int generation = 0;
+
+ // 20 msec, or 50 repaints per sec (theoretically)
+ int sleepMillis = 20;
+ long lastMillis = System.currentTimeMillis();
+
+ boolean enableRepaints = true;
+
+ /**
+ * If true, test translation.
+ */
+ boolean testTranslation = false;
+
+ /**
+ * If true, paint lines rather than rectangles
+ */
+ boolean paintLines;
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getActionCommand().equals("CLOSE"))
+ {
+ System.exit(0);
+ }
+ }
+
+ public JNIOverhead()
+ {
+ setSize(nx, ny);
+ createContent();
+ }
+
+ public void createContent()
+ {
+ setLayout(new BorderLayout());
+
+ JPanel p = new JPanel(new BorderLayout());
+ lcd = new LCDCanvas();
+ label = new JLabel();
+ label.setText("not running");
+
+ translate = new JCheckBox("translate");
+ translate.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ testTranslation = translate.isSelected();
+ }
+ });
+
+ lines = new JCheckBox("lines");
+ lines.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ paintLines = lines.isSelected();
+ }
+ });
+
+ JPanel bottom = new JPanel();
+ bottom.add(lines);
+ bottom.add(translate);
+
+ p.add(lcd, BorderLayout.CENTER);
+ p.add(bottom, BorderLayout.SOUTH);
+ p.add(label, BorderLayout.NORTH);
+ add(p);
+ }
+
+ public void setSize(int _nx,int _ny )
+ {
+ nx = _nx;
+ ny = _ny;
+ matrix = new int[nx][ny];
+ future = new int[nx][ny];
+ }
+
+ public void initFrameContent()
+ {
+ JPanel closePanel = new JPanel();
+ JButton closeButton = new JButton("Close");
+ closeButton.setActionCommand("CLOSE");
+ closeButton.addActionListener(this);
+ closePanel.add(closeButton);
+ add(closePanel, BorderLayout.SOUTH);
+ }
+
+ public void setSleepMillis(int millis)
+ {
+ sleepMillis = millis;
+ }
+
+ public class LCDCanvas extends JPanel
+ {
+ private int sx, sy;
+ private Color activePixel = new Color(30, 30, 40);
+ private Color passivePixel = new Color(200, 180, 240);
+ private Color gridPixel = new Color(255, 240, 240);
+
+ public LCDCanvas()
+ {
+ super();
+ sx = 4 * nx;
+ sy = 4 * ny;
+ }
+
+ public void paintComponent(Graphics g)
+ {
+ // for buffered drawing - not used atm
+ // g.drawImage( buffer, 0, 0, null );
+ long t1 = System.currentTimeMillis();
+
+ g.setColor(gridPixel);
+ g.fillRect(0, 0, sx, sy);
+
+ Color pixelColor = null;
+
+ int dx, dy;
+
+ if (paintLines)
+ {
+ for (int ix = 0; ix < nx; ix++)
+ for (int iy = 0; iy < ny; iy++)
+ {
+ if (matrix[ix][iy] != 0)
+ pixelColor = activePixel;
+ else
+ pixelColor = passivePixel;
+
+ dx = 4 * ix;
+ dy = 4 * iy;
+ g.setColor(pixelColor);
+
+ if (testTranslation)
+ {
+ g.translate(dx, dy);
+ g.drawLine(0, 0, 5, 5);
+ g.translate(- dx, - dy);
+ }
+ else
+ g.drawLine(dx, dy, dx + 5, dy + 5);
+ }
+ }
+ else
+ for (int ix = 0; ix < nx; ix++)
+ {
+ for (int iy = 0; iy < ny; iy++)
+ {
+ if (matrix[ix][iy] != 0)
+ pixelColor = activePixel;
+ else
+ pixelColor = passivePixel;
+
+ dx = 4 * ix;
+ dy = 4 * iy;
+ g.setColor(pixelColor);
+
+ if (testTranslation)
+ {
+ g.translate(dx, dy);
+ g.fillRect(0, 0, 3, 3);
+ g.translate(- dx, - dy);
+ }
+ else
+ g.fillRect(dx, dy, 3, 3);
+ }
+ }
+
+ long t2 = System.currentTimeMillis();
+
+ label.setText("paintComponent took " + (t2 - t1) + " msec. " + "("
+ + (nx * ny + 1) + " "
+ + (paintLines ? "drawLine" : "fillRect") + " calls)");
+
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(sx,sy);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(sx,sy);
+ }
+ }
+
+ public class Worker extends Thread
+ {
+ public void run()
+ {
+ boolean running = true;
+ while(running)
+ {
+ iteration();
+
+ if (enableRepaints)
+ display();
+
+ if (sleepMillis > 0)
+ {
+ try
+ {
+ Thread.sleep( sleepMillis );
+ }
+ catch(InterruptedException ie)
+ {
+ running = false;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * stupid animation algorithm: show binary representation of current
+ * iteration.
+ */
+ public void iteration()
+ {
+ generation++;
+
+ for (int i = 0; i < nx; i++)
+ {
+ long tmp1 = 1L << i;
+ for (int j = 0; j < ny; j++)
+ {
+ // count neighbors
+ long tmp2 = (1L << j);
+
+
+ long tmp3 = generation & tmp1 & tmp2;
+ if (tmp3 != 0)
+ matrix[i][j] = 1;
+ else
+ matrix[i][j] = 0;
+ }
+ }
+
+ if ((generation % 100) == 0)
+ {
+ long t = System.currentTimeMillis();
+ // System.out.println(
+ // " generation= " + generation +
+ // " iterations/sec= " + 100.0*1000/(t-lastMillis) );
+ lastMillis = t;
+ }
+ }
+
+ public void display()
+ {
+ lcd.repaint();
+ }
+
+ public static void usage()
+ {
+ System.out.println(
+ "Usage: <java> FillRect2 [-sleep <millis>] [-size <int>] [-nopaint]\n"
+ + "Example: jamvm FillRect2 -sleep 10 -size 100\n"
+ );
+ System.exit(0);
+ }
+
+ public static void main(String args[])
+ throws Exception
+ {
+ fillRectDemo = new JNIOverhead();
+ for (int i = 0; i < args.length; i++)
+ {
+ if ("-help".equals(args[i]))
+ {
+ usage();
+ }
+ if ("-sleep".equals(args[i]))
+ {
+ fillRectDemo.setSleepMillis( Integer.parseInt(args[i + 1]));
+ i++;
+ }
+ if ("-size".equals(args[i]))
+ {
+ int size = Integer.parseInt(args[i + 1]);
+ fillRectDemo.setSize(size, size);
+ i++;
+ }
+ if ("-nopaint".equals(args[i]))
+ {
+ fillRectDemo.enableRepaints = false;
+ }
+ }
+
+ SwingUtilities.invokeLater (new Runnable()
+ {
+ public void run()
+ {
+
+ fillRectDemo.initFrameContent();
+ JFrame frame = new JFrame("FillRect performance test");
+ frame.getContentPane().add(fillRectDemo);
+ frame.pack();
+ frame.show();
+ fillRectDemo.worker = fillRectDemo.new Worker();
+ fillRectDemo.worker.start();
+ }
+ });
+ }
+
+ /**
+ * Returns a DemoFactory that creates a SliderDemo.
+ *
+ * @return a DemoFactory that creates a SliderDemo
+ */
+ public static DemoFactory createDemoFactory()
+ {
+ return new DemoFactory()
+ {
+ public JComponent createDemo()
+ {
+ fillRectDemo = new JNIOverhead();
+ SwingUtilities.invokeLater
+ (new Runnable()
+ {
+ public void run()
+ {
+ fillRectDemo.worker = fillRectDemo.new Worker();
+ fillRectDemo.worker.start();
+ }
+ });
+ return fillRectDemo;
+ }
+ };
+ }
+}
diff --git a/examples/gnu/classpath/examples/swing/Demo.java b/examples/gnu/classpath/examples/swing/Demo.java
index f1daaac33..ad20fec7e 100644
--- a/examples/gnu/classpath/examples/swing/Demo.java
+++ b/examples/gnu/classpath/examples/swing/Demo.java
@@ -22,6 +22,8 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
package gnu.classpath.examples.swing;
+import gnu.classpath.examples.java2d.JNIOverhead;
+
import java.awt.*;
import java.awt.event.*;
@@ -156,8 +158,8 @@ public class Demo
examples.add(new JMenuItem(new PopupAction("NavigationFilter",
NavigationFilterDemo.createDemoFactory())));
- examples.add(new JMenuItem(new PopupAction("Paint Performance",
- FillRect.createDemoFactory())));
+ examples.add(new JMenuItem(new PopupAction("JNI Overhead",
+ JNIOverhead.createDemoFactory())));
final JMenuItem vmMenu;
@@ -549,8 +551,8 @@ public class Demo
TreeDemo.createDemoFactory())));
panel.add(new JButton(new PopupAction("Theme Editor",
MetalThemeEditor.createDemoFactory())));
- panel.add(new JButton(new PopupAction("Paint Performance",
- FillRect.createDemoFactory())));
+ panel.add(new JButton(new PopupAction("JNI Overhead",
+ JNIOverhead.createDemoFactory())));
JButton exitDisposer = mkDisposerButton(frame);
panel.add(exitDisposer);
diff --git a/gnu/java/awt/java2d/AbstractGraphics2D.java b/gnu/java/awt/java2d/AbstractGraphics2D.java
index dd1865cdf..bfe6ced55 100644
--- a/gnu/java/awt/java2d/AbstractGraphics2D.java
+++ b/gnu/java/awt/java2d/AbstractGraphics2D.java
@@ -39,6 +39,7 @@ package gnu.java.awt.java2d;
import java.awt.AWTError;
import java.awt.AlphaComposite;
+import java.awt.AWTPermission;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
@@ -539,6 +540,15 @@ public abstract class AbstractGraphics2D
*/
public void setComposite(Composite comp)
{
+ if (! (comp instanceof AlphaComposite))
+ {
+ // FIXME: this check is only required "if this Graphics2D
+ // context is drawing to a Component on the display screen".
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new AWTPermission("readDisplayPixels"));
+ }
+
composite = comp;
if (! (comp.equals(AlphaComposite.SrcOver)))
isOptimized = false;
diff --git a/gnu/java/awt/peer/gtk/CairoGraphics2D.java b/gnu/java/awt/peer/gtk/CairoGraphics2D.java
index 3d093bae4..30cf85908 100644
--- a/gnu/java/awt/peer/gtk/CairoGraphics2D.java
+++ b/gnu/java/awt/peer/gtk/CairoGraphics2D.java
@@ -41,6 +41,7 @@ package gnu.java.awt.peer.gtk;
import gnu.java.awt.ClasspathToolkit;
import java.awt.AlphaComposite;
+import java.awt.AWTPermission;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
@@ -886,6 +887,12 @@ public abstract class CairoGraphics2D extends Graphics2D
}
else
{
+ // FIXME: this check is only required "if this Graphics2D
+ // context is drawing to a Component on the display screen".
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new AWTPermission("readDisplayPixels"));
+
// FIXME: implement general Composite support
throw new java.lang.UnsupportedOperationException();
}
@@ -1201,6 +1208,7 @@ public abstract class CairoGraphics2D extends Graphics2D
// Note - this can get us in trouble when the gdk lock is re-acquired.
// for example by VolatileImage. See ComponentGraphics for how we work
// around this.
+
if( !(img instanceof BufferedImage) )
{
ImageProducer source = img.getSource();
@@ -1217,6 +1225,7 @@ public abstract class CairoGraphics2D extends Graphics2D
// If this BufferedImage has a BufferedImageGraphics object,
// use the cached CairoSurface that BIG is drawing onto
+
if( BufferedImageGraphics.bufferedImages.get( b ) != null )
db = (DataBuffer)BufferedImageGraphics.bufferedImages.get( b );
else
@@ -1231,6 +1240,7 @@ public abstract class CairoGraphics2D extends Graphics2D
if(db instanceof CairoSurface)
{
((CairoSurface)db).drawSurface(nativePointer, i2u, alpha);
+ updateColor();
return true;
}
@@ -1247,24 +1257,7 @@ public abstract class CairoGraphics2D extends Graphics2D
setPaint( oldPaint );
}
- int[] pixels;
-
- // Shortcut for easy color models.
- if( b.getColorModel().equals(rgb32) )
- {
- pixels = ((DataBufferInt)db).getData();
- for(int i = 0; i < pixels.length; i++)
- pixels[i] |= 0xFF000000;
- }
- else if( b.getColorModel().equals(argb32) )
- {
- pixels = ((DataBufferInt)db).getData();
- }
- else
- {
- pixels = b.getRGB(0, 0, width, height,
- null, 0, width);
- }
+ int[] pixels = b.getRGB(0, 0, width, height, null, 0, width);
drawPixels(nativePointer, pixels, width, height, width, i2u, alpha);
diff --git a/gnu/java/awt/peer/gtk/ComponentGraphics.java b/gnu/java/awt/peer/gtk/ComponentGraphics.java
index e49c95f01..cb8350265 100644
--- a/gnu/java/awt/peer/gtk/ComponentGraphics.java
+++ b/gnu/java/awt/peer/gtk/ComponentGraphics.java
@@ -39,7 +39,6 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
import java.awt.Color;
-import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
@@ -47,15 +46,12 @@ import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Toolkit;
-import java.awt.Point;
-import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
-import java.awt.image.ImagingOpException;
import java.awt.image.RenderedImage;
/**
@@ -170,7 +166,8 @@ public class ComponentGraphics extends CairoGraphics2D
private native void drawVolatile(GtkComponentPeer component,
long vimg, int x, int y,
- int width, int height);
+ int width, int height, int cx, int cy,
+ int cw, int ch);
/**
* Returns a Graphics2D object for a component, either an instance of this
@@ -285,21 +282,24 @@ public class ComponentGraphics extends CairoGraphics2D
if (img instanceof GtkVolatileImage)
{
GtkVolatileImage vimg = (GtkVolatileImage) img;
- int type = transform.getType();
- if (type == AffineTransform.TYPE_IDENTITY)
- {
- drawVolatile(component, vimg.nativePointer,
- x, y, vimg.width, vimg.height);
- return true;
- }
- else if (type == AffineTransform.TYPE_TRANSLATION)
- {
- x += transform.getTranslateX();
- y += transform.getTranslateY();
- drawVolatile(component, vimg.nativePointer,
- x, y, vimg.width, vimg.height);
- return true;
- }
+ int type = transform.getType();
+ if ((type == AffineTransform.TYPE_IDENTITY
+ || type == AffineTransform.TYPE_TRANSLATION)
+ && (clip == null || clip instanceof Rectangle2D))
+ {
+ Rectangle2D r = (Rectangle2D) clip;
+ if (r == null)
+ r = getRealBounds();
+ x += transform.getTranslateX();
+ y += transform.getTranslateY();
+ drawVolatile(component, vimg.nativePointer,
+ x, y, vimg.width, vimg.height,
+ (int) (r.getX() + transform.getTranslateX()),
+ (int) (r.getY() + transform.getTranslateY()),
+ (int) r.getWidth(),
+ (int) r.getHeight());
+ return true;
+ }
else
return super.drawImage(vimg.getSnapshot(), x, y, observer);
}
@@ -323,24 +323,28 @@ public class ComponentGraphics extends CairoGraphics2D
// If it is a GtkVolatileImage with an "easy" transform then
// draw directly. Always pass a BufferedImage to super to avoid
// deadlock (see Note in CairoGraphics.drawImage()).
- if (img instanceof GtkVolatileImage)
+ if (img instanceof GtkVolatileImage
+ && (clip == null || clip instanceof Rectangle2D))
{
GtkVolatileImage vimg = (GtkVolatileImage) img;
- int type = transform.getType();
- if (type == AffineTransform.TYPE_IDENTITY)
- {
- drawVolatile(component, vimg.nativePointer,
- x, y, width, height);
- return true;
- }
- else if (type == AffineTransform.TYPE_TRANSLATION)
- {
- x += transform.getTranslateX();
- y += transform.getTranslateY();
- drawVolatile(component, vimg.nativePointer,
- x, y, width, height);
- return true;
- }
+ int type = transform.getType();
+ if ((type == AffineTransform.TYPE_IDENTITY
+ || type == AffineTransform.TYPE_TRANSLATION)
+ && (clip == null || clip instanceof Rectangle2D))
+ {
+ Rectangle2D r = (Rectangle2D) clip;
+ if (r == null)
+ r = getRealBounds();
+ x += transform.getTranslateX();
+ y += transform.getTranslateY();
+ drawVolatile(component, vimg.nativePointer,
+ x, y, width, height,
+ (int) (r.getX() + transform.getTranslateX()),
+ (int) (r.getY() + transform.getTranslateY()),
+ (int) r.getWidth(),
+ (int) r.getHeight());
+ return true;
+ }
else
return super.drawImage(vimg.getSnapshot(), x, y,
width, height, observer);
diff --git a/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java b/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
index 4978c6a45..2c9d91793 100644
--- a/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
+++ b/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
@@ -137,6 +137,35 @@ public class FreetypeGlyphVector extends GlyphVector
}
/**
+ * Cloning constructor
+ */
+ private FreetypeGlyphVector( FreetypeGlyphVector gv )
+ {
+ font = gv.font;
+ peer = gv.peer;
+ frc = gv.frc;
+ s = gv.s;
+ nGlyphs = gv.nGlyphs;
+ logicalBounds = gv.logicalBounds.getBounds2D();
+
+ if( gv.metricsCache != null )
+ {
+ metricsCache = new GlyphMetrics[ nGlyphs ];
+ System.arraycopy(gv.metricsCache, 0, metricsCache, 0, nGlyphs);
+ }
+
+ glyphCodes = new int[ nGlyphs ];
+ glyphPositions = new float[ nGlyphs ];
+ glyphTransforms = new AffineTransform[ nGlyphs ];
+ for(int i = 0; i < nGlyphs; i++ )
+ {
+ glyphTransforms[ i ] = new AffineTransform( gv.glyphTransforms[ i ] );
+ glyphCodes[i] = gv.glyphCodes[ i ];
+ glyphPositions[i] = gv.glyphPositions[ i ];
+ }
+ }
+
+ /**
* Create the array of glyph codes.
*/
private void getGlyphs()
@@ -172,6 +201,12 @@ public class FreetypeGlyphVector extends GlyphVector
private native GeneralPath getGlyphOutlineNative(int glyphIndex);
+
+ public Object clone()
+ {
+ return new FreetypeGlyphVector( this );
+ }
+
/**
* Duh, compares two instances.
*/
@@ -260,8 +295,11 @@ public class FreetypeGlyphVector extends GlyphVector
if( gm == null )
return null;
Rectangle2D r = gm.getBounds2D();
- return new Rectangle2D.Double( r.getX() - gm.getLSB(), r.getY(),
- gm.getAdvanceX(), r.getHeight() );
+ Point2D p = getGlyphPosition( glyphIndex );
+ return new Rectangle2D.Double( p.getX() + r.getX() - gm.getLSB(),
+ p.getY() + r.getY(),
+ gm.getAdvanceX(),
+ r.getHeight() );
}
/*
@@ -385,8 +423,6 @@ public class FreetypeGlyphVector extends GlyphVector
for( int i = 1; i < nGlyphs; i++ )
{
Rectangle2D r2 = (Rectangle2D)getGlyphLogicalBounds( i );
- Point2D p = getGlyphPosition( i );
- r2.setRect( p.getX(), p.getY(), r2.getWidth(), r2.getHeight() );
rect = rect.createUnion( r2 );
}
diff --git a/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java b/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
index 094aa3c03..2963c4334 100644
--- a/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
@@ -78,7 +78,10 @@ public class GtkCheckboxPeer extends GtkComponentPeer
create (old_group);
currentState = checkbox.getState();
gtkToggleButtonSetActive(currentState);
- gtkButtonSetLabel (checkbox.getLabel ());
+
+ String label = checkbox.getLabel();
+ if (label != null)
+ gtkButtonSetLabel(label);
}
/**
diff --git a/gnu/java/awt/peer/gtk/GtkLabelPeer.java b/gnu/java/awt/peer/gtk/GtkLabelPeer.java
index bbf4230b3..02db90d72 100644
--- a/gnu/java/awt/peer/gtk/GtkLabelPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkLabelPeer.java
@@ -56,7 +56,7 @@ public class GtkLabelPeer extends GtkComponentPeer
native void nativeSetAlignment (float alignment);
- public native void setText(String text);
+ public native void setNativeText(String text);
native void setNativeBounds (int x, int y, int width, int height);
// Because this is a composite widget, we need to retrieve the
@@ -69,6 +69,12 @@ public class GtkLabelPeer extends GtkComponentPeer
create (label.getText (), getGtkAlignment (label.getAlignment ()));
}
+ public void setText(String text)
+ {
+ if (text != null)
+ setNativeText(text);
+ }
+
public GtkLabelPeer (Label l)
{
super (l);
diff --git a/gnu/java/awt/peer/gtk/GtkToolkit.java b/gnu/java/awt/peer/gtk/GtkToolkit.java
index 163fc52f7..baabeca75 100644
--- a/gnu/java/awt/peer/gtk/GtkToolkit.java
+++ b/gnu/java/awt/peer/gtk/GtkToolkit.java
@@ -310,6 +310,11 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props)
{
+ SecurityManager sm;
+ sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPrintJobAccess();
+
return null;
}
diff --git a/gnu/java/awt/peer/qt/QtGraphics.java b/gnu/java/awt/peer/qt/QtGraphics.java
index 55c2a70cf..d8957404f 100644
--- a/gnu/java/awt/peer/qt/QtGraphics.java
+++ b/gnu/java/awt/peer/qt/QtGraphics.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package gnu.java.awt.peer.qt;
import java.awt.AlphaComposite;
+import java.awt.AWTPermission;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
@@ -605,8 +606,16 @@ public abstract class QtGraphics extends Graphics2D
composite = comp;
}
else
- throw new UnsupportedOperationException("We don't support custom"+
- " composites yet.");
+ {
+ // FIXME: this check is only required "if this Graphics2D
+ // context is drawing to a Component on the display screen".
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new AWTPermission("readDisplayPixels"));
+
+ throw new UnsupportedOperationException("We don't support custom"+
+ " composites yet.");
+ }
}
public Composite getComposite()
diff --git a/gnu/java/awt/peer/qt/QtToolkit.java b/gnu/java/awt/peer/qt/QtToolkit.java
index 73652f8df..c6bc70cfd 100644
--- a/gnu/java/awt/peer/qt/QtToolkit.java
+++ b/gnu/java/awt/peer/qt/QtToolkit.java
@@ -402,6 +402,11 @@ public class QtToolkit extends ClasspathToolkit
String jobtitle,
Properties props)
{
+ SecurityManager sm;
+ sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPrintJobAccess();
+
throw new RuntimeException("Not implemented");
}
diff --git a/gnu/java/awt/peer/swing/SwingComponentPeer.java b/gnu/java/awt/peer/swing/SwingComponentPeer.java
index f60c8e96c..96ccc00b8 100644
--- a/gnu/java/awt/peer/swing/SwingComponentPeer.java
+++ b/gnu/java/awt/peer/swing/SwingComponentPeer.java
@@ -48,8 +48,6 @@ import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
@@ -101,8 +99,8 @@ public class SwingComponentPeer
/**
* Creates a SwingComponentPeer instance. Subclasses are expected to call
* this constructor and thereafter call
- * {@link #init(Component, SwingComponent)} in order to setup the AWT and
- * Swing components properly.
+ * {@link #init(Component,SwingComponent)}
+ * in order to setup the AWT and Swing components properly.
*/
protected SwingComponentPeer()
{
@@ -167,12 +165,9 @@ public class SwingComponentPeer
*/
public Image createImage(int width, int height)
{
- GraphicsEnvironment graphicsEnv =
- GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice dev = graphicsEnv.getDefaultScreenDevice();
- GraphicsConfiguration conf = dev.getDefaultConfiguration();
- Image image = conf.createCompatibleImage(width, height);
- return image;
+ Component parent = awtComponent.getParent();
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.createImage(width, height);
}
/**
@@ -336,21 +331,24 @@ public class SwingComponentPeer
{
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)
- // {
+ // This only will work when the component is showing.
+ if (awtComponent.isShowing())
+ {
+ 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();
+ // }
+ // 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:
@@ -384,6 +382,11 @@ public class SwingComponentPeer
{
if (swingComponent != null)
swingComponent.getJComponent().setVisible(false);
+
+ Component parent = awtComponent.getParent();
+ if (parent != null)
+ parent.repaint(awtComponent.getX(), awtComponent.getY(),
+ awtComponent.getWidth(), awtComponent.getHeight());
}
/**
@@ -470,17 +473,15 @@ public class SwingComponentPeer
public boolean prepareImage(Image img, int width, int height, ImageObserver ob)
{
Component parent = awtComponent.getParent();
- boolean res;
if(parent != null)
- {
- ComponentPeer parentPeer = parent.getPeer();
- res = parentPeer.prepareImage(img, width, height, ob);
- }
+ {
+ ComponentPeer parentPeer = parent.getPeer();
+ return parentPeer.prepareImage(img, width, height, ob);
+ }
else
- {
- res = Toolkit.getDefaultToolkit().prepareImage(img, width, height, ob);
- }
- return res;
+ {
+ return Toolkit.getDefaultToolkit().prepareImage(img, width, height, ob);
+ }
}
public void print(Graphics graphics)
@@ -662,8 +663,10 @@ public class SwingComponentPeer
*/
public void setVisible(boolean visible)
{
- if (swingComponent != null)
- swingComponent.getJComponent().setVisible(visible);
+ if (visible)
+ show();
+ else
+ hide();
}
/**
@@ -782,8 +785,13 @@ public class SwingComponentPeer
public VolatileImage createVolatileImage(int width, int height)
{
Component parent = awtComponent.getParent();
- ComponentPeer parentPeer = parent.getPeer();
- return parentPeer.createVolatileImage(width, height);
+ VolatileImage im = null;
+ if (parent != null)
+ {
+ ComponentPeer parentPeer = parent.getPeer();
+ im = parentPeer.createVolatileImage(width, height);
+ }
+ return im;
}
/**
diff --git a/gnu/java/lang/management/ClassLoadingMXBeanImpl.java b/gnu/java/lang/management/ClassLoadingMXBeanImpl.java
new file mode 100644
index 000000000..88d19fc1a
--- /dev/null
+++ b/gnu/java/lang/management/ClassLoadingMXBeanImpl.java
@@ -0,0 +1,85 @@
+/* ClassLoadingMXBeanImpl.java - Implementation of a class loading bean
+ Copyright (C) 2006 Free Software Foundation
+
+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.lang.management;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.ManagementPermission;
+
+/**
+ * Provides access to information about the class loading
+ * behaviour of the current invocation of the virtual
+ * machine. Instances of this bean are obtained by calling
+ * {@link ManagementFactory#getClassLoadingMXBean()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public final class ClassLoadingMXBeanImpl
+ implements ClassLoadingMXBean
+{
+
+ public int getLoadedClassCount()
+ {
+ return VMClassLoadingMXBeanImpl.getLoadedClassCount();
+ }
+
+ public long getTotalLoadedClassCount()
+ {
+ return getLoadedClassCount() + getUnloadedClassCount();
+ }
+
+ public long getUnloadedClassCount()
+ {
+ return VMClassLoadingMXBeanImpl.getUnloadedClassCount();
+ }
+
+ public boolean isVerbose()
+ {
+ return VMClassLoadingMXBeanImpl.isVerbose();
+ }
+
+ public void setVerbose(boolean verbose)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new ManagementPermission("control"));
+ VMClassLoadingMXBeanImpl.setVerbose(verbose);
+ }
+
+}
+
diff --git a/gnu/java/lang/management/RuntimeMXBeanImpl.java b/gnu/java/lang/management/RuntimeMXBeanImpl.java
index dade39865..6c5210b61 100644
--- a/gnu/java/lang/management/RuntimeMXBeanImpl.java
+++ b/gnu/java/lang/management/RuntimeMXBeanImpl.java
@@ -176,9 +176,9 @@ public final class RuntimeMXBeanImpl
{
if (bootClassPath == null)
{
- bootClassPath = System.getProperty(JAVA_BOOT_CLASS_PATH);
+ bootClassPath = SystemProperties.getProperty(JAVA_BOOT_CLASS_PATH);
if (bootClassPath == null)
- bootClassPath = System.getProperty(SUN_BOOT_CLASS_PATH);
+ bootClassPath = SystemProperties.getProperty(SUN_BOOT_CLASS_PATH);
if (bootClassPath == null)
bootClassPathSupported = false;
}
diff --git a/gnu/java/security/.cvsignore b/gnu/java/security/.cvsignore
new file mode 100644
index 000000000..11f6639eb
--- /dev/null
+++ b/gnu/java/security/.cvsignore
@@ -0,0 +1 @@
+Configuration.java
diff --git a/gnu/java/security/Configuration.java.in b/gnu/java/security/Configuration.java.in
new file mode 100644
index 000000000..1deb543d4
--- /dev/null
+++ b/gnu/java/security/Configuration.java.in
@@ -0,0 +1,56 @@
+/* Configuration.java --
+ 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;
+
+/**
+ * This file defines compile-time constants that can be accessed by
+ * our crypto code. All crypto code should use and define such
+ * constants here instead of using the gnu.classpath.Configuration class.
+ */
+public interface Configuration
+{
+
+ /**
+ * The value of DEBUG is substituted according to whether the
+ * "--enable-debug" argument was passed to configure. Code
+ * which is made conditional based on the value of this flag - typically
+ * code that generates debugging output - will be removed by the optimizer
+ * in a non-debug build.
+ */
+ boolean DEBUG = @LIBDEBUG@;
+}
diff --git a/gnu/java/security/Properties.java b/gnu/java/security/Properties.java
index 4e8bc01ea..a515a5428 100644
--- a/gnu/java/security/Properties.java
+++ b/gnu/java/security/Properties.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import java.io.FileInputStream;
import java.io.IOException;
@@ -49,12 +49,13 @@ import java.util.PropertyPermission;
import java.util.logging.Logger;
/**
- * <p>A global object containing build-specific properties that affect the
- * behaviour of the generated binaries from this library.</p>
+ * A global object containing build-specific properties that affect the
+ * behaviour of the generated binaries from this library.
*/
public final class Properties
{
private static final Logger log = Logger.getLogger(Properties.class.getName());
+
public static final String VERSION = "gnu.crypto.version";
public static final String PROPERTIES_FILE = "gnu.crypto.properties.file";
@@ -79,9 +80,6 @@ public final class Properties
private boolean doRSABlinding = true;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial constructor to enforce Singleton pattern. */
private Properties()
{
@@ -89,18 +87,15 @@ public final class Properties
init();
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the string representation of the library global configuration
- * property with the designated <code>key</code>.</p>
- *
+ * Returns the string representation of the library global configuration
+ * property with the designated <code>key</code>.
+ *
* @param key the case-insensitive, non-null and non-empty name of a
- * configuration property.
+ * configuration property.
* @return the string representation of the designated property, or
- * <code>null</code> if such property is not yet set, or <code>key</code> is
- * empty.
+ * <code>null</code> if such property is not yet set, or
+ * <code>key</code> is empty.
*/
public static final synchronized String getProperty(String key)
{
@@ -116,13 +111,13 @@ public final class Properties
}
/**
- * <p>Sets the value of a designated library global configuration property,
- * to a string representation of what should be a legal value.</p>
- *
+ * 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 by <code>key</code>.
+ * configuration property.
+ * @param value the non-null, non-empty string representation of a legal value
+ * of the configuration property named by <code>key</code>.
*/
public static final synchronized void setProperty(String key, String value)
{
@@ -153,13 +148,14 @@ public final class Properties
}
/**
- * <p>A convenience method that returns, as a boolean, the library global
+ * 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.</p>
- *
- * @return <code>true</code> if the default PRNG produces the same bit stream
- * with every VM instance. Returns <code>false</code> if the default PRNG is
- * seeded with the time of day of its first invocation.
+ * Generator produces, or not, the same bit stream when instantiated.
+ *
+ * @return <code>true</code> if the default PRNG produces the same bit
+ * stream with every VM instance. Returns <code>false</code> if the
+ * default PRNG is seeded with the time of day of its first
+ * invocation.
*/
public static final synchronized boolean isReproducible()
{
@@ -170,15 +166,15 @@ public final class Properties
}
/**
- * <p>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.</p>
- *
- * @return <code>true</code> if the cipher implementations check for weak and
- * semi-weak keys. Returns <code>false</code> if the cipher implementations
- * do not check for weak or semi-weak keys.
+ * 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.
+ *
+ * @return <code>true</code> if the cipher implementations check for weak
+ * and semi-weak keys. Returns <code>false</code> if the cipher
+ * implementations do not check for weak or semi-weak keys.
*/
public static final synchronized boolean checkForWeakKeys()
{
@@ -189,13 +185,14 @@ public final class Properties
}
/**
- * <p>A convenience method that returns, as a boolean, the library global
+ * 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.</p>
- *
+ * does, or not, blinding against timing attacks.
+ *
* @return <code>true</code> if the RSA decryption primitive includes a
- * blinding operation. Returns <code>false</code> if the RSA decryption
- * primitive does not include the additional blinding operation.
+ * blinding operation. Returns <code>false</code> if the RSA
+ * decryption primitive does not include the additional blinding
+ * operation.
*/
public static final synchronized boolean doRSABlinding()
{
@@ -206,11 +203,11 @@ public final class Properties
}
/**
- * <p>A convenience method to set the global property for reproducibility of
- * the default PRNG bit stream output.</p>
- *
+ * A convenience method to set the global property for reproducibility of the
+ * default PRNG bit stream output.
+ *
* @param value if <code>true</code> then the default PRNG bit stream output
- * is the same with every invocation of the VM.
+ * is the same with every invocation of the VM.
*/
public static final synchronized void setReproducible(final boolean value)
{
@@ -222,12 +219,12 @@ public final class Properties
}
/**
- * <p>A convenience method to set the global property for checking for weak
- * and semi-weak cipher keys.</p>
- *
+ * A convenience method to set the global property for checking for weak and
+ * semi-weak cipher keys.
+ *
* @param value if <code>true</code> then the cipher implementations will
- * invoke additional checks for weak and semi-weak key values that may get
- * generated.
+ * invoke additional checks for weak and semi-weak key values that
+ * may get generated.
*/
public static final synchronized void setCheckForWeakKeys(final boolean value)
{
@@ -239,11 +236,11 @@ public final class Properties
}
/**
- * <p>A convenience method to set the global property fo adding a blinding
- * operation when executing the RSA decryption primitive.</p>
- *
+ * A convenience method to set the global property fo adding a blinding
+ * operation when executing the RSA decryption primitive.
+ *
* @param value if <code>true</code> then the code for performing the RSA
- * decryption primitive will include a blinding operation.
+ * decryption primitive will include a blinding operation.
*/
public static final synchronized void setDoRSABlinding(final boolean value)
{
@@ -261,15 +258,12 @@ public final class 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
@@ -309,17 +303,14 @@ public final class Properties
+ 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 = Boolean.valueOf((String) props.get(REPRODUCIBLE_PRNG)).booleanValue();
checkForWeakKeys = Boolean.valueOf((String) props.get(CHECK_WEAK_KEYS)).booleanValue();
doRSABlinding = Boolean.valueOf((String) props.get(DO_RSA_BLINDING)).booleanValue();
-
// This does not change.
props.put(VERSION, Registry.VERSION_STRING);
}
@@ -339,7 +330,7 @@ public final class Properties
if (s != null)
{
s = s.trim().toLowerCase();
- // we have to test for explicit "true" or "false". anything else may
+ // we have to test for explicit "true" or "false". anything else may
// hide valid value set previously
if (s.equals(TRUE) || s.equals(FALSE))
{
diff --git a/gnu/java/security/Registry.java b/gnu/java/security/Registry.java
index 9d8ceac8d..b3df24c9e 100644
--- a/gnu/java/security/Registry.java
+++ b/gnu/java/security/Registry.java
@@ -44,10 +44,6 @@ package gnu.java.security;
*/
public interface Registry
{
-
- // Constants
- // -------------------------------------------------------------------------
-
/** The name of our Providers. */
String GNU_SECURITY = "GNU";
String GNU_CRYPTO = "GNU-CRYPTO";
@@ -303,38 +299,38 @@ public interface Registry
// 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_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_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_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_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_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_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_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_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_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_PUBLIC_KEY = new byte[] {
+ 0x47, RAW_ENCODING_ID, 0x53, 0x50 };
- byte[] MAGIC_RAW_SRP_PRIVATE_KEY = new byte[] { 0x47, RAW_ENCODING_ID, 0x53,
- 0x70 };
+ byte[] MAGIC_RAW_SRP_PRIVATE_KEY = new byte[] {
+ 0x47, RAW_ENCODING_ID, 0x53, 0x70 };
// SASL Property names .....................................................
@@ -347,8 +343,7 @@ public interface Registry
String SASL_PASSWORD = SASL_PREFIX + ".password";
/** Name of authentication information provider packages. */
- String SASL_AUTH_INFO_PROVIDER_PKGS = SASL_PREFIX
- + ".auth.info.provider.pkgs";
+ String SASL_AUTH_INFO_PROVIDER_PKGS = SASL_PREFIX + ".auth.info.provider.pkgs";
/** SASL authorization ID. */
String SASL_AUTHORISATION_ID = SASL_PREFIX + ".authorisation.ID";
@@ -455,7 +450,4 @@ public interface Registry
int GKR_CIPHER_AES_128_OFB = 0;
int GKR_CIPHER_AES_128_CBC = 1;
-
- // Methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/hash/BaseHash.java b/gnu/java/security/hash/BaseHash.java
index 720b83539..ff1750aea 100644
--- a/gnu/java/security/hash/BaseHash.java
+++ b/gnu/java/security/hash/BaseHash.java
@@ -39,14 +39,11 @@ exception statement from your version. */
package gnu.java.security.hash;
/**
- * <p>A base abstract class to facilitate hash implementations.</p>
+ * A base abstract class to facilitate hash implementations.
*/
-public abstract class BaseHash implements IMessageDigest
+public abstract class BaseHash
+ implements IMessageDigest
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The canonical name prefix of the hash. */
protected String name;
@@ -62,12 +59,9 @@ public abstract class BaseHash implements IMessageDigest
/** Temporary input buffer. */
protected byte[] buffer;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Trivial constructor for use by concrete subclasses.</p>
- *
+ * 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.
@@ -84,14 +78,6 @@ public abstract class BaseHash implements IMessageDigest
resetContext();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // IMessageDigest interface implementation ---------------------------------
-
public String name()
{
return name;
@@ -114,9 +100,7 @@ public abstract class BaseHash implements IMessageDigest
count++;
buffer[i] = b;
if (i == (blockSize - 1))
- {
- transform(buffer, 0);
- }
+ transform(buffer, 0);
}
public void update(byte[] b)
@@ -136,16 +120,13 @@ public abstract class BaseHash implements IMessageDigest
System.arraycopy(b, offset, buffer, n, partLen);
transform(buffer, 0);
for (i = partLen; i + blockSize - 1 < len; i += blockSize)
- {
- transform(b, offset + i);
- }
+ transform(b, offset + i);
+
n = 0;
}
if (i < len)
- {
- System.arraycopy(b, offset + i, buffer, n, len - i);
- }
+ System.arraycopy(b, offset + i, buffer, n, len - i);
}
public byte[] digest()
@@ -163,31 +144,27 @@ public abstract class BaseHash implements IMessageDigest
{ // reset this instance for future re-use
count = 0L;
for (int i = 0; i < blockSize;)
- {
- buffer[i++] = 0;
- }
+ buffer[i++] = 0;
resetContext();
}
- // methods to be implemented by concrete subclasses ------------------------
-
public abstract Object clone();
public abstract boolean selfTest();
/**
- * <p>Returns the byte array to use as padding before completing a hash
- * operation.</p>
- *
+ * 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.
+ * completing a hash operation.
*/
protected abstract byte[] padBuffer();
/**
- * <p>Constructs the result from the contents of the current context.</p>
- *
+ * Constructs the result from the contents of the current context.
+ *
* @return the output of the completed hash operation.
*/
protected abstract byte[] getResult();
@@ -196,11 +173,11 @@ public abstract class BaseHash implements IMessageDigest
protected abstract void resetContext();
/**
- * <p>The block digest transformation per se.</p>
- *
+ * The block digest transformation per se.
+ *
* @param in the <i>blockSize</i> long block, as an array of bytes to digest.
* @param offset the index where the data to digest is located within the
- * input buffer.
+ * input buffer.
*/
protected abstract void transform(byte[] in, int offset);
}
diff --git a/gnu/java/security/hash/HashFactory.java b/gnu/java/security/hash/HashFactory.java
index e52092123..2a4e48785 100644
--- a/gnu/java/security/hash/HashFactory.java
+++ b/gnu/java/security/hash/HashFactory.java
@@ -45,113 +45,73 @@ import java.util.HashSet;
import java.util.Set;
/**
- * <p>A <i>Factory</i> to instantiate message digest algorithm instances.</p>
+ * A <i>Factory</i> to instantiate message digest algorithm instances.
*/
public class HashFactory
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial constructor to enforce <i>Singleton</i> pattern. */
private HashFactory()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Return an instance of a hash algorithm given its name.</p>
- *
+ * 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.
+ * test.
*/
public static IMessageDigest getInstance(String name)
{
if (name == null)
- {
- return null;
- }
+ return null;
name = name.trim();
IMessageDigest result = null;
if (name.equalsIgnoreCase(Registry.WHIRLPOOL_HASH))
- {
- result = new Whirlpool();
- }
+ result = new Whirlpool();
else if (name.equalsIgnoreCase(Registry.RIPEMD128_HASH)
|| name.equalsIgnoreCase(Registry.RIPEMD_128_HASH))
- {
- result = new RipeMD128();
- }
+ result = new RipeMD128();
else if (name.equalsIgnoreCase(Registry.RIPEMD160_HASH)
|| name.equalsIgnoreCase(Registry.RIPEMD_160_HASH))
- {
- result = new RipeMD160();
- }
+ 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();
- }
+ result = new Sha160();
else if (name.equalsIgnoreCase(Registry.SHA256_HASH))
- {
- result = new Sha256();
- }
+ result = new Sha256();
else if (name.equalsIgnoreCase(Registry.SHA384_HASH))
- {
- result = new Sha384();
- }
+ result = new Sha384();
else if (name.equalsIgnoreCase(Registry.SHA512_HASH))
- {
- result = new Sha512();
- }
+ result = new Sha512();
else if (name.equalsIgnoreCase(Registry.TIGER_HASH))
- {
- result = new Tiger();
- }
+ result = new Tiger();
else if (name.equalsIgnoreCase(Registry.HAVAL_HASH))
- {
- result = new Haval();
- }
+ result = new Haval();
else if (name.equalsIgnoreCase(Registry.MD5_HASH))
- {
- result = new MD5();
- }
+ result = new MD5();
else if (name.equalsIgnoreCase(Registry.MD4_HASH))
- {
- result = new MD4();
- }
+ result = new MD4();
else if (name.equalsIgnoreCase(Registry.MD2_HASH))
- {
- result = new MD2();
- }
+ result = new MD2();
else if (name.equalsIgnoreCase(Registry.HAVAL_HASH))
- {
- result = new Haval();
- }
+ result = new Haval();
- if (result != null && !result.selfTest())
- {
- throw new InternalError(result.name());
- }
+ if (result != null && ! result.selfTest())
+ throw new InternalError(result.name());
return result;
}
/**
- * <p>Returns a {@link Set} of names of hash algorithms supported by this
- * <i>Factory</i>.</p>
- *
+ * Returns a {@link Set} of names of hash algorithms supported by this
+ * <i>Factory</i>.
+ *
* @return a {@link Set} of hash names (Strings).
*/
public static final Set getNames()
@@ -172,7 +132,4 @@ public class HashFactory
return Collections.unmodifiableSet(hs);
}
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/hash/Haval.java b/gnu/java/security/hash/Haval.java
index 1bf75652d..662934f34 100644
--- a/gnu/java/security/hash/Haval.java
+++ b/gnu/java/security/hash/Haval.java
@@ -42,25 +42,21 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>The <i>HAVAL</i> message-digest algorithm is a variable output length,
- * with variable number of rounds. By default, this implementation allows
- * <i>HAVAL</i> to be used as a drop-in replacement for <i>MD5</i>.</p>
- *
- * <p>References:</p>
- *
+ * The <i>HAVAL</i> message-digest algorithm is a variable output length, with
+ * variable number of rounds. By default, this implementation allows <i>HAVAL</i>
+ * to be used as a drop-in replacement for <i>MD5</i>.
+ * <p>
+ * References:
* <ol>
- * <li>HAVAL - A One-Way Hashing Algorithm with Variable Length of Output<br>
- * Advances in Cryptology - AUSCRYPT'92, Lecture Notes in Computer Science,<br>
- * Springer-Verlag, 1993; <br>
- * Y. Zheng, J. Pieprzyk and J. Seberry.</li>
+ * <li>HAVAL - A One-Way Hashing Algorithm with Variable Length of Output<br>
+ * Advances in Cryptology - AUSCRYPT'92, Lecture Notes in Computer Science,<br>
+ * Springer-Verlag, 1993; <br>
+ * Y. Zheng, J. Pieprzyk and J. Seberry.</li>
* </ol>
*/
-public class Haval extends BaseHash
+public class Haval
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final int HAVAL_VERSION = 1;
public static final int HAVAL_128_BIT = 16;
@@ -88,20 +84,18 @@ public class Haval extends BaseHash
/**
* Number of HAVAL rounds. Allowed values are integers in the range <code>3
- * .. 5</code>. The default is <code>3</code>.
+ * .. 5</code>.
+ * The default is <code>3</code>.
*/
private int rounds = HAVAL_3_ROUND;
/** 128-bit interim result. */
private int h0, h1, h2, h3, h4, h5, h6, h7;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Calls the constructor with two argument using {@link #HAVAL_128_BIT} as
- * the value for the output size (i.e. <code>128</code> bits, and
- * {@link #HAVAL_3_ROUND} for the value of number of rounds.</p>
+ * Calls the constructor with two argument using {@link #HAVAL_128_BIT} as the
+ * value for the output size (i.e. <code>128</code> bits, and
+ * {@link #HAVAL_3_ROUND} for the value of number of rounds.
*/
public Haval()
{
@@ -109,9 +103,9 @@ public class Haval extends BaseHash
}
/**
- * <p>Calls the constructor with two arguments using the designated output
- * size, and {@link #HAVAL_3_ROUND} for the value of number of rounds.</p>
- *
+ * 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
@@ -126,16 +120,16 @@ public class Haval extends BaseHash
}
/**
- * <p>Constructs a <code>Haval</code> instance with the designated output
- * size (in bytes). Valid output <code>size</code> values are <code>16</code>,
- * <code>20</code>, <code>24</code>, <code>28</code> and <code>32</code>.
- * Valid values for <code>rounds</code> are in the range <code>3..5</code>
- * inclusive.</p>
- *
+ * Constructs a <code>Haval</code> instance with the designated output size
+ * (in bytes). Valid output <code>size</code> values are <code>16</code>,
+ * <code>20</code>, <code>24</code>, <code>28</code> and
+ * <code>32</code>. Valid values for <code>rounds</code> are in the range
+ * <code>3..5</code> inclusive.
+ *
* @param size the output size in bytes of this instance.
* @param rounds the number of rounds to apply when transforming data.
* @throws IllegalArgumentException if the designated output size is invalid,
- * or if the number of rounds is invalid.
+ * or if the number of rounds is invalid.
* @see #HAVAL_128_BIT
* @see #HAVAL_160_BIT
* @see #HAVAL_192_BIT
@@ -149,24 +143,24 @@ public class Haval extends BaseHash
{
super(Registry.HAVAL_HASH, size, BLOCK_SIZE);
- if (size != HAVAL_128_BIT && size != HAVAL_160_BIT && size != HAVAL_192_BIT
- && size != HAVAL_224_BIT && size != HAVAL_256_BIT)
- {
- throw new IllegalArgumentException("Invalid HAVAL output size");
- }
+ if (size != HAVAL_128_BIT
+ && size != HAVAL_160_BIT
+ && size != HAVAL_192_BIT
+ && size != HAVAL_224_BIT
+ && size != HAVAL_256_BIT)
+ throw new IllegalArgumentException("Invalid HAVAL output size");
- if (rounds != HAVAL_3_ROUND && rounds != HAVAL_4_ROUND
+ if (rounds != HAVAL_3_ROUND
+ && rounds != HAVAL_4_ROUND
&& rounds != HAVAL_5_ROUND)
- {
- throw new IllegalArgumentException("Invalid HAVAL number of rounds");
- }
+ throw new IllegalArgumentException("Invalid HAVAL number of rounds");
this.rounds = rounds;
}
/**
- * <p>Private constructor for cloning purposes.</p>
- *
+ * Private constructor for cloning purposes.
+ *
* @param md the instance to clone.
*/
private Haval(Haval md)
@@ -185,93 +179,142 @@ public class Haval extends BaseHash
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 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);
@@ -458,7 +501,6 @@ public class Haval extends BaseHash
t0 = FF5(t0, t7, t6, t5, t4, t3, t2, t1, X15, 0x409F60C4);
}
}
-
h7 += t7;
h6 += t6;
h5 += t5;
@@ -471,30 +513,30 @@ public class Haval extends BaseHash
protected byte[] padBuffer()
{
- // pad out to 118 mod 128. other 10 bytes have special use.
- int n = (int) (count % BLOCK_SIZE);
+ // 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);
-
+ int sigByte = (bl & 0x03) << 6;
+ sigByte |= (rounds & 0x07) << 3;
+ sigByte |= HAVAL_VERSION & 0x07;
+ result[padding++] = (byte) sigByte;
+ 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);
-
+ 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;
}
@@ -505,49 +547,48 @@ public class Haval extends BaseHash
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[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[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[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[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[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;
-
+ 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;
}
@@ -567,13 +608,12 @@ public class Haval extends BaseHash
{
if (valid == null)
{
- valid = Boolean.valueOf(DIGEST0.equals(Util.toString(new Haval().digest())));
+ String d = Util.toString(new Haval().digest());
+ valid = Boolean.valueOf(DIGEST0.equals(d));
}
return valid.booleanValue();
}
- // helper methods ----------------------------------------------------------
-
/** Tailors the last output. */
private void tailorDigestBits()
{
@@ -581,17 +621,25 @@ public class Haval extends BaseHash
switch (hashSize)
{
case HAVAL_128_BIT:
- t = (h7 & 0x000000FF) | (h6 & 0xFF000000) | (h5 & 0x00FF0000)
- | (h4 & 0x0000FF00);
+ t = (h7 & 0x000000FF)
+ | (h6 & 0xFF000000)
+ | (h5 & 0x00FF0000)
+ | (h4 & 0x0000FF00);
h0 += t >>> 8 | t << 24;
- t = (h7 & 0x0000FF00) | (h6 & 0x000000FF) | (h5 & 0xFF000000)
- | (h4 & 0x00FF0000);
+ t = (h7 & 0x0000FF00)
+ | (h6 & 0x000000FF)
+ | (h5 & 0xFF000000)
+ | (h4 & 0x00FF0000);
h1 += t >>> 16 | t << 16;
- t = (h7 & 0x00FF0000) | (h6 & 0x0000FF00) | (h5 & 0x000000FF)
- | (h4 & 0xFF000000);
+ t = (h7 & 0x00FF0000)
+ | (h6 & 0x0000FF00)
+ | (h5 & 0x000000FF)
+ | (h4 & 0xFF000000);
h2 += t >>> 24 | t << 8;
- t = (h7 & 0xFF000000) | (h6 & 0x00FF0000) | (h5 & 0x0000FF00)
- | (h4 & 0x000000FF);
+ t = (h7 & 0xFF000000)
+ | (h6 & 0x00FF0000)
+ | (h5 & 0x0000FF00)
+ | (h4 & 0x000000FF);
h3 += t;
break;
case HAVAL_160_BIT:
@@ -625,9 +673,9 @@ public class Haval extends BaseHash
h1 += ((h7 >>> 22) & 0x1F);
h2 += ((h7 >>> 18) & 0x0F);
h3 += ((h7 >>> 13) & 0x1F);
- h4 += ((h7 >>> 9) & 0x0F);
- h5 += ((h7 >>> 4) & 0x1F);
- h6 += (h7 & 0x0F);
+ h4 += ((h7 >>> 9) & 0x0F);
+ h5 += ((h7 >>> 4) & 0x1F);
+ h6 += (h7 & 0x0F);
}
}
@@ -748,8 +796,8 @@ public class Haval extends BaseHash
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;
+ 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)
diff --git a/gnu/java/security/hash/IMessageDigest.java b/gnu/java/security/hash/IMessageDigest.java
index b3d7f69ca..2c5bdd41a 100644
--- a/gnu/java/security/hash/IMessageDigest.java
+++ b/gnu/java/security/hash/IMessageDigest.java
@@ -39,64 +39,56 @@ exception statement from your version. */
package gnu.java.security.hash;
/**
- * <p>The basic visible methods of any hash algorithm.</p>
- *
- * <p>A hash (or message digest) algorithm produces its output by iterating a
- * basic compression function on blocks of data.</p>
+ * The basic visible methods of any hash algorithm.
+ * <p>
+ * A hash (or message digest) algorithm produces its output by iterating a basic
+ * compression function on blocks of data.
*/
-public interface IMessageDigest extends Cloneable
+public interface IMessageDigest
+ extends Cloneable
{
-
- // Constants
- // -------------------------------------------------------------------------
-
- // Methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the canonical name of this algorithm.</p>
- *
+ * Returns the canonical name of this algorithm.
+ *
* @return the canonical name of this instance.
*/
String name();
/**
- * <p>Returns the output length in bytes of this message digest algorithm.</p>
- *
+ * Returns the output length in bytes of this message digest algorithm.
+ *
* @return the output length in bytes of this message digest algorithm.
*/
int hashSize();
/**
- * <p>Returns the algorithm's (inner) block size in bytes.</p>
- *
+ * Returns the algorithm's (inner) block size in bytes.
+ *
* @return the algorithm's inner block size in bytes.
*/
int blockSize();
/**
- * <p>Continues a message digest operation using the input byte.</p>
- *
+ * Continues a message digest operation using the input byte.
+ *
* @param b the input byte to digest.
*/
void update(byte b);
/**
- * <p>Continues a message digest operation, by filling the buffer, processing
+ * 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.</p>
- *
+ * count, and buffering the remaining bytes in buffer for the next operation.
+ *
* @param in the input block.
*/
void update(byte[] in);
/**
- * <p>Continues a message digest operation, by filling the buffer, processing
+ * 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.</p>
- *
+ * 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.
@@ -104,31 +96,31 @@ public interface IMessageDigest extends Cloneable
void update(byte[] in, int offset, int length);
/**
- * <p>Completes the message digest by performing final operations such as
- * padding and resetting the instance.</p>
- *
+ * 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();
/**
- * <p>Resets the current context of this instance clearing any eventually cached
- * intermediary values.</p>
+ * Resets the current context of this instance clearing any eventually cached
+ * intermediary values.
*/
void reset();
/**
- * <p>A basic test. Ensures that the digest of a pre-determined message is equal
- * to a known pre-computed value.</p>
- *
- * @return <tt>true</tt> if the implementation passes a basic self-test.
- * Returns <tt>false</tt> otherwise.
+ * A basic test. Ensures that the digest of a pre-determined message is equal
+ * to a known pre-computed value.
+ *
+ * @return <code>true</code> if the implementation passes a basic self-test.
+ * Returns <code>false</code> otherwise.
*/
boolean selfTest();
/**
- * <p>Returns a clone copy of this instance.</p>
- *
+ * Returns a clone copy of this instance.
+ *
* @return a clone copy of this instance.
*/
Object clone();
diff --git a/gnu/java/security/hash/MD2.java b/gnu/java/security/hash/MD2.java
index 2a93c42c4..8f6b265b0 100644
--- a/gnu/java/security/hash/MD2.java
+++ b/gnu/java/security/hash/MD2.java
@@ -42,13 +42,12 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>An implementation of the MD2 message digest algorithm.</p>
- *
- * <p>MD2 is not widely used. Unless it is needed for compatibility with
- * existing systems, it is not recommended for use in new applications.</p>
- *
- * <p>References:</p>
- *
+ * An implementation of the MD2 message digest algorithm.
+ * <p>
+ * MD2 is not widely used. Unless it is needed for compatibility with
+ * existing systems, it is not recommended for use in new applications.
+ * <p>
+ * References:
* <ol>
* <li>The <a href="http://www.ietf.org/rfc/rfc1319.txt">MD2</a>
* Message-Digest Algorithm.<br>
@@ -57,12 +56,9 @@ import gnu.java.security.util.Util;
* under section RFC 1319.</li>
* </ol>
*/
-public class MD2 extends BaseHash
+public class MD2
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** An MD2 message digest is always 128-bits long, or 16 bytes. */
private static final int DIGEST_LENGTH = 16;
@@ -70,34 +66,39 @@ public class MD2 extends BaseHash
private static final int BLOCK_LENGTH = 16;
/** 256 byte "random" permutation of the digits of pi. */
- private static final byte[] PI = { 41, 46, 67, -55, -94, -40, 124, 1, 61, 54,
- 84, -95, -20, -16, 6, 19, 98, -89, 5, -13,
- -64, -57, 115, -116, -104, -109, 43, -39,
- -68, 76, -126, -54, 30, -101, 87, 60, -3,
- -44, -32, 22, 103, 66, 111, 24, -118, 23,
- -27, 18, -66, 78, -60, -42, -38, -98, -34,
- 73, -96, -5, -11, -114, -69, 47, -18, 122,
- -87, 104, 121, -111, 21, -78, 7, 63, -108,
- -62, 16, -119, 11, 34, 95, 33, -128, 127,
- 93, -102, 90, -112, 50, 39, 53, 62, -52,
- -25, -65, -9, -105, 3, -1, 25, 48, -77, 72,
- -91, -75, -47, -41, 94, -110, 42, -84, 86,
- -86, -58, 79, -72, 56, -46, -106, -92, 125,
- -74, 118, -4, 107, -30, -100, 116, 4, -15,
- 69, -99, 112, 89, 100, 113, -121, 32, -122,
- 91, -49, 101, -26, 45, -88, 2, 27, 96, 37,
- -83, -82, -80, -71, -10, 28, 70, 97, 105,
- 52, 64, 126, 15, 85, 71, -93, 35, -35, 81,
- -81, 58, -61, 92, -7, -50, -70, -59, -22,
- 38, 44, 83, 13, 110, -123, 40, -124, 9,
- -45, -33, -51, -12, 65, -127, 77, 82, 106,
- -36, 55, -56, 108, -63, -85, -6, 36, -31,
- 123, 8, 12, -67, -79, 74, 120, -120, -107,
- -117, -29, 99, -24, 109, -23, -53, -43, -2,
- 59, 0, 29, 57, -14, -17, -73, 14, 102, 88,
- -48, -28, -90, 119, 114, -8, -21, 117, 75,
- 10, 49, 68, 80, -76, -113, -19, 31, 26,
- -37, -103, -115, 51, -97, 17, -125, 20 };
+ private static final byte[] PI = {
+ 41, 46, 67, -55, -94, -40, 124, 1,
+ 61, 54, 84, -95, -20, -16, 6, 19,
+ 98, -89, 5, -13, -64, -57, 115, -116,
+ -104, -109, 43, -39, -68, 76, -126, -54,
+ 30, -101, 87, 60, -3, -44, -32, 22,
+ 103, 66, 111, 24, -118, 23, -27, 18,
+ -66, 78, -60, -42, -38, -98, -34, 73,
+ -96, -5, -11, -114, -69, 47, -18, 122,
+ -87, 104, 121, -111, 21, -78, 7, 63,
+ -108, -62, 16, -119, 11, 34, 95, 33,
+ -128, 127, 93, -102, 90, -112, 50, 39,
+ 53, 62, -52, -25, -65, -9, -105, 3,
+ -1, 25, 48, -77, 72, -91, -75, -47,
+ -41, 94, -110, 42, -84, 86, -86, -58,
+ 79, -72, 56, -46, -106, -92, 125, -74,
+ 118, -4, 107, -30, -100, 116, 4, -15,
+ 69, -99, 112, 89, 100, 113, -121, 32,
+ -122, 91, -49, 101, -26, 45, -88, 2,
+ 27, 96, 37, -83, -82, -80, -71, -10,
+ 28, 70, 97, 105, 52, 64, 126, 15,
+ 85, 71, -93, 35, -35, 81, -81, 58,
+ -61, 92, -7, -50, -70, -59, -22, 38,
+ 44, 83, 13, 110, -123, 40, -124, 9,
+ -45, -33, -51, -12, 65, -127, 77, 82,
+ 106, -36, 55, -56, 108, -63, -85, -6,
+ 36, -31, 123, 8, 12, -67, -79, 74,
+ 120, -120, -107, -117, -29, 99, -24, 109,
+ -23, -53, -43, -2, 59, 0, 29, 57,
+ -14, -17, -73, 14, 102, 88, -48, -28,
+ -90, 119, 114, -8, -21, 117, 75, 10,
+ 49, 68, 80, -76, -113, -19, 31, 26,
+ -37, -103, -115, 51, - 97, 17, -125, 20 };
/** The output of this message digest when no data has been input. */
private static final String DIGEST0 = "8350E5A3E24C153DF2275C9F80692773";
@@ -114,9 +115,6 @@ public class MD2 extends BaseHash
*/
private byte[] work;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Creates a new MD2 digest ready for use. */
public MD2()
{
@@ -124,7 +122,7 @@ public class MD2 extends BaseHash
}
/**
- * <p>Private constructor used for cloning.</p>
+ * Private constructor used for cloning.
*
* @param md2 the instance to clone.
*/
@@ -135,38 +133,23 @@ public class MD2 extends BaseHash
// 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];
- }
+ result[i] = work[i];
return result;
}
@@ -181,17 +164,18 @@ public class MD2 extends BaseHash
{
if (valid == null)
{
- valid = Boolean.valueOf(DIGEST0.equals(Util.toString(new MD2().digest())));
+ String d = Util.toString(new MD2().digest());
+ valid = Boolean.valueOf(DIGEST0.equals(d));
}
return valid.booleanValue();
}
/**
- * <p>Generates an array of padding bytes. The padding is defined as
+ * Generates an array of padding bytes. The padding is defined as
* <code>i</code> bytes of value <code>i</code>, where <code>i</code> is the
* number of bytes to fill the last block of the message to
* <code>BLOCK_LENGTH</code> bytes (or <code>BLOCK_LENGTH</code> bytes when
- * the last block was completely full).</p>
+ * the last block was completely full).
*
* @return the bytes to pad the remaining bytes in the buffer before
* completing a hash operation.
@@ -200,47 +184,26 @@ public class MD2 extends BaseHash
{
int length = BLOCK_LENGTH - (int) (count % BLOCK_LENGTH);
if (length == 0)
- {
- length = BLOCK_LENGTH;
- }
+ length = BLOCK_LENGTH;
+
byte[] pad = new byte[length];
for (int i = 0; i < length; i++)
- {
- pad[i] = (byte) length;
- }
+ pad[i] = (byte) length;
+
return pad;
}
/**
- * <p>Adds <code>BLOCK_LENGTH</code> bytes to the running digest.</p>
+ * Adds <code>BLOCK_LENGTH</code> bytes to the running digest.
*
* @param in the byte array to take the <code>BLOCK_LENGTH</code> 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 <code>BLOCK_LENGTH</code> bytes from the
- * given array starting at <code>off</code>.
- */
- /*
- 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 (<code>BLOCK_LENGTH</code> bytes) to the running digest
* from the given byte array starting from the given offset.
@@ -251,20 +214,17 @@ public class MD2 extends BaseHash
{
byte b = in[off + i];
work[BLOCK_LENGTH + i] = b;
- work[BLOCK_LENGTH * 2 + i] = (byte) (work[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]);
+ t = (byte)(work[j] ^ PI[t & 0xFF]);
work[j] = t;
}
- // t = (byte)((t + i) & 0xFF);
- t = (byte) (t + i);
+ t = (byte)(t + i);
}
}
@@ -278,24 +238,19 @@ public class MD2 extends BaseHash
{
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]);
+ work[BLOCK_LENGTH * 2 + i] = (byte)(work[i] ^ b);
+ 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]);
+ t = (byte)(work[j] ^ PI[t & 0xFF]);
work[j] = t;
}
- // t = (byte)((t + i) & 0xFF);
- t = (byte) (t + i);
+ t = (byte)(t + i);
}
}
}
diff --git a/gnu/java/security/hash/MD4.java b/gnu/java/security/hash/MD4.java
index 215cd9837..dfc1c6bd6 100644
--- a/gnu/java/security/hash/MD4.java
+++ b/gnu/java/security/hash/MD4.java
@@ -42,14 +42,13 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>An implementation of Ron Rivest's MD4 message digest algorithm.</p>
- *
- * <p>MD4 was the precursor to the stronger {@link gnu.java.security.hash.MD5}
+ * An implementation of Ron Rivest's MD4 message digest algorithm.
+ * <p>
+ * MD4 was the precursor to the stronger {@link gnu.java.security.hash.MD5}
* algorithm, and while not considered cryptograpically secure itself, MD4 is
- * in use in various applications. It is slightly faster than MD5.</p>
- *
- * <p>References:</p>
- *
+ * in use in various applications. It is slightly faster than MD5.
+ * <p>
+ * References:
* <ol>
* <li>The <a href="http://www.ietf.org/rfc/rfc1320.txt">MD4</a>
* Message-Digest Algorithm.<br>
@@ -58,12 +57,9 @@ import gnu.java.security.util.Util;
*
* @author Casey Marshall (rsdio@metastatic.org)
*/
-public class MD4 extends BaseHash
+public class MD4
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** An MD4 message digest is always 128-bits long, or 16 bytes. */
private static final int DIGEST_LENGTH = 16;
@@ -86,13 +82,9 @@ public class MD4 extends BaseHash
private int a, b, c, d;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Public constructor. Initializes the chaining variables, sets the byte
+ * Public constructor. Initializes the chaining variables, sets the byte
* count to <code>0</code>, and creates a new block of <code>512</code> bits.
- * </p>
*/
public MD4()
{
@@ -100,7 +92,7 @@ public class MD4 extends BaseHash
}
/**
- * <p>Trivial private constructor for cloning purposes.</p>
+ * Trivial private constructor for cloning purposes.
*
* @param that the instance to clone.
*/
@@ -116,30 +108,18 @@ public class MD4 extends BaseHash
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;
+ return new byte[] {
+ (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) };
}
protected void resetContext()
@@ -154,68 +134,97 @@ public class MD4 extends BaseHash
{
if (valid == null)
{
- valid = Boolean.valueOf(DIGEST0.equals(Util.toString(new MD4().digest())));
+ String d = Util.toString(new MD4().digest());
+ valid = Boolean.valueOf(DIGEST0.equals(d));
}
return valid.booleanValue();
}
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_LENGTH);
+ 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);
-
+ 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 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;
diff --git a/gnu/java/security/hash/MD5.java b/gnu/java/security/hash/MD5.java
index 165392394..653078512 100644
--- a/gnu/java/security/hash/MD5.java
+++ b/gnu/java/security/hash/MD5.java
@@ -42,26 +42,22 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>The MD5 message-digest algorithm takes as input a message of arbitrary
+ * 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.</p>
- *
- * <p>References:</p>
- *
+ * message having a given prespecified target message digest.
+ * <p>
+ * References:
* <ol>
* <li>The <a href="http://www.ietf.org/rfc/rfc1321.txt">MD5</a> Message-
* Digest Algorithm.<br>
* R. Rivest.</li>
* </ol>
*/
-public class MD5 extends BaseHash
+public class MD5
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final int BLOCK_SIZE = 64; // inner block size in bytes
private static final String DIGEST0 = "D41D8CD98F00B204E9800998ECF8427E";
@@ -72,9 +68,6 @@ public class MD5 extends BaseHash
/** 128-bit interim result. */
private int h0, h1, h2, h3;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public MD5()
{
@@ -82,7 +75,7 @@ public class MD5 extends BaseHash
}
/**
- * <p>Private constructor for cloning purposes.</p>
+ * Private constructor for cloning purposes.
*
* @param md the instance to clone.
*/
@@ -98,61 +91,81 @@ public class MD5 extends BaseHash
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 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;
@@ -310,39 +323,31 @@ public class MD5 extends BaseHash
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_SIZE);
+ 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);
-
+ 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;
+ return 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) };
}
protected void resetContext()
@@ -358,7 +363,8 @@ public class MD5 extends BaseHash
{
if (valid == null)
{
- valid = Boolean.valueOf(DIGEST0.equals(Util.toString(new MD5().digest())));
+ String d = Util.toString(new MD5().digest());
+ valid = Boolean.valueOf(DIGEST0.equals(d));
}
return valid.booleanValue();
}
diff --git a/gnu/java/security/hash/RipeMD128.java b/gnu/java/security/hash/RipeMD128.java
index 31874a0c2..62f5a05e5 100644
--- a/gnu/java/security/hash/RipeMD128.java
+++ b/gnu/java/security/hash/RipeMD128.java
@@ -42,54 +42,48 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>RIPEMD-128 is a 128-bit message digest.</p>
- *
- * <p>References:</p>
- *
+ * RIPEMD-128 is a 128-bit message digest.
+ * <p>
+ * References:
* <ol>
* <li><a href="http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html">
* RIPEMD160</a>: A Strengthened Version of RIPEMD.<br>
* Hans Dobbertin, Antoon Bosselaers and Bart Preneel.</li>
* </ol>
*/
-public class RipeMD128 extends BaseHash
+public class RipeMD128
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final int BLOCK_SIZE = 64; // inner block size in bytes
private static final String DIGEST0 = "CDF26213A150DC3ECB610F18F6B38B46";
/** Constants for the transform method. */
// selection of message word
- private static final int[] R = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
- 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0,
- 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8,
- 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10,
- 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2 };
-
- private static final int[] Rp = { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1,
- 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14,
- 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14,
- 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4,
- 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14 };
+ private static final int[] R = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
+ 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
+ 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2 };
+
+ private static final int[] Rp = {
+ 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
+ 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
+ 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
+ 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14 };
// amount for rotate left (rol)
- private static final int[] S = { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15,
- 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12,
- 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9,
- 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12,
- 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5,
- 12 };
-
- private static final int[] Sp = { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11,
- 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11,
- 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8,
- 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15,
- 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5,
- 15, 8 };
+ private static final int[] S = {
+ 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
+ 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
+ 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
+ 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12 };
+
+ private static final int[] Sp = {
+ 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
+ 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
+ 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
+ 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8 };
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
@@ -100,9 +94,6 @@ public class RipeMD128 extends BaseHash
/** 512 bits work buffer = 16 x 32-bit words */
private int[] X = new int[16];
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public RipeMD128()
{
@@ -110,7 +101,7 @@ public class RipeMD128 extends BaseHash
}
/**
- * <p>Private constructor for cloning purposes.</p>
+ * Private constructor for cloning purposes.
*
* @param md the instance to clone.
*/
@@ -126,40 +117,26 @@ public class RipeMD128 extends BaseHash
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.
+ // 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;
- }
-
+ 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
+ for (i = 0; i < 16; i++) // rounds 0...15
+ {
s = S[i];
T = A + (B ^ C ^ D) + X[i];
A = D;
@@ -174,9 +151,8 @@ public class RipeMD128 extends BaseHash
Cp = Bp;
Bp = T << s | T >>> (32 - s);
}
-
- for (; i < 32; i++)
- { // rounds 16...31
+ for (; i < 32; i++) // rounds 16...31
+ {
s = S[i];
T = A + ((B & C) | (~B & D)) + X[R[i]] + 0x5A827999;
A = D;
@@ -191,9 +167,8 @@ public class RipeMD128 extends BaseHash
Cp = Bp;
Bp = T << s | T >>> (32 - s);
}
-
- for (; i < 48; i++)
- { // rounds 32...47
+ for (; i < 48; i++) // rounds 32...47
+ {
s = S[i];
T = A + ((B | ~C) ^ D) + X[R[i]] + 0x6ED9EBA1;
A = D;
@@ -208,9 +183,8 @@ public class RipeMD128 extends BaseHash
Cp = Bp;
Bp = T << s | T >>> (32 - s);
}
-
- for (; i < 64; i++)
- { // rounds 48...63
+ for (; i < 64; i++) // rounds 48...63
+ {
s = S[i];
T = A + ((B & D) | (C & ~D)) + X[R[i]] + 0x8F1BBCDC;
A = D;
@@ -225,7 +199,6 @@ public class RipeMD128 extends BaseHash
Cp = Bp;
Bp = T << s | T >>> (32 - s);
}
-
T = h1 + C + Dp;
h1 = h2 + D + Ap;
h2 = h3 + A + Bp;
@@ -235,39 +208,32 @@ public class RipeMD128 extends BaseHash
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_SIZE);
+ 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);
-
+ 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;
+ return 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)
+ };
}
protected void resetContext()
@@ -283,8 +249,8 @@ public class RipeMD128 extends BaseHash
{
if (valid == null)
{
- valid = Boolean.valueOf
- (DIGEST0.equals(Util.toString(new RipeMD128().digest())));
+ String d = Util.toString(new RipeMD128().digest());
+ valid = Boolean.valueOf(DIGEST0.equals(d));
}
return valid.booleanValue();
}
diff --git a/gnu/java/security/hash/RipeMD160.java b/gnu/java/security/hash/RipeMD160.java
index 642ffb32d..7949bc254 100644
--- a/gnu/java/security/hash/RipeMD160.java
+++ b/gnu/java/security/hash/RipeMD160.java
@@ -42,59 +42,51 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>RIPEMD-160 is a 160-bit message digest.</p>
- *
- * <p>References:</p>
- *
+ * RIPEMD-160 is a 160-bit message digest.
+ * <p>
+ * References:
* <ol>
* <li><a href="http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html">
* RIPEMD160</a>: A Strengthened Version of RIPEMD.<br>
* Hans Dobbertin, Antoon Bosselaers and Bart Preneel.</li>
* </ol>
*/
-public class RipeMD160 extends BaseHash
+public class RipeMD160
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final int BLOCK_SIZE = 64; // inner block size in bytes
private static final String DIGEST0 = "9C1185A5C5E9FC54612808977EE8F548B2258D31";
// selection of message word
- private static final int[] R = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
- 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0,
- 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8,
- 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10,
- 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0,
- 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15,
- 13 };
-
- private static final int[] Rp = { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1,
- 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14,
- 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14,
- 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4,
- 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
- 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0,
- 3, 9, 11 };
+ private static final int[] R = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
+ 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
+ 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
+ 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 };
+
+ private static final int[] Rp = {
+ 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
+ 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
+ 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
+ 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
+ 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 };
// amount for rotate left (rol)
- private static final int[] S = { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15,
- 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12,
- 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9,
- 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12,
- 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5,
- 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13,
- 14, 11, 8, 5, 6 };
-
- private static final int[] Sp = { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11,
- 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11,
- 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8,
- 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15,
- 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5,
- 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6,
- 5, 15, 13, 11, 11 };
+ private static final int[] S = {
+ 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
+ 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
+ 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
+ 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
+ 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 };
+
+ private static final int[] Sp = {
+ 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
+ 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
+ 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
+ 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
+ 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 };
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
@@ -105,9 +97,6 @@ public class RipeMD160 extends BaseHash
/** 512 bits work buffer = 16 x 32-bit words */
private int[] X = new int[16];
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public RipeMD160()
{
@@ -115,7 +104,7 @@ public class RipeMD160 extends BaseHash
}
/**
- * <p>Private constructor for cloning purposes.</p>
+ * Private constructor for cloning purposes.
*
* @param md the instance to clone.
*/
@@ -132,40 +121,27 @@ public class RipeMD160 extends BaseHash
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;
- }
-
+ 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
+ for (i = 0; i < 16; i++) // rounds 0...15
+ {
s = S[i];
T = A + (B ^ C ^ D) + X[i];
A = E;
@@ -182,9 +158,8 @@ public class RipeMD160 extends BaseHash
Cp = Bp;
Bp = (T << s | T >>> (32 - s)) + Ap;
}
-
- for (; i < 32; i++)
- { // rounds 16...31
+ for (; i < 32; i++) // rounds 16...31
+ {
s = S[i];
T = A + ((B & C) | (~B & D)) + X[R[i]] + 0x5A827999;
A = E;
@@ -201,9 +176,8 @@ public class RipeMD160 extends BaseHash
Cp = Bp;
Bp = (T << s | T >>> (32 - s)) + Ap;
}
-
- for (; i < 48; i++)
- { // rounds 32...47
+ for (; i < 48; i++) // rounds 32...47
+ {
s = S[i];
T = A + ((B | ~C) ^ D) + X[R[i]] + 0x6ED9EBA1;
A = E;
@@ -220,9 +194,8 @@ public class RipeMD160 extends BaseHash
Cp = Bp;
Bp = (T << s | T >>> (32 - s)) + Ap;
}
-
- for (; i < 64; i++)
- { // rounds 48...63
+ for (; i < 64; i++) // rounds 48...63
+ {
s = S[i];
T = A + ((B & D) | (C & ~D)) + X[R[i]] + 0x8F1BBCDC;
A = E;
@@ -239,9 +212,8 @@ public class RipeMD160 extends BaseHash
Cp = Bp;
Bp = (T << s | T >>> (32 - s)) + Ap;
}
-
- for (; i < 80; i++)
- { // rounds 64...79
+ for (; i < 80; i++) // rounds 64...79
+ {
s = S[i];
T = A + (B ^ (C | ~D)) + X[R[i]] + 0xA953FD4E;
A = E;
@@ -258,7 +230,6 @@ public class RipeMD160 extends BaseHash
Cp = Bp;
Bp = (T << s | T >>> (32 - s)) + Ap;
}
-
T = h1 + C + Dp;
h1 = h2 + D + Ep;
h2 = h3 + E + Ap;
@@ -269,41 +240,33 @@ public class RipeMD160 extends BaseHash
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_SIZE);
+ 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);
-
+ 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;
+ return 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)
+ };
}
protected void resetContext()
@@ -320,8 +283,8 @@ public class RipeMD160 extends BaseHash
{
if (valid == null)
{
- valid = Boolean.valueOf
- (DIGEST0.equals(Util.toString(new RipeMD160().digest())));
+ String d = Util.toString(new RipeMD160().digest());
+ valid = Boolean.valueOf(DIGEST0.equals(d));
}
return valid.booleanValue();
}
diff --git a/gnu/java/security/hash/Sha160.java b/gnu/java/security/hash/Sha160.java
index 037b118e6..6adeba070 100644
--- a/gnu/java/security/hash/Sha160.java
+++ b/gnu/java/security/hash/Sha160.java
@@ -42,7 +42,7 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>The Secure Hash Algorithm (SHA-1) is required for use with the Digital
+ * 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
@@ -51,15 +51,14 @@ import gnu.java.security.util.Util;
* 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.</p>
- *
- * <p>The SHA-1 is designed to have the following properties: it is
+ * a different message digest, and the signature will fail to verify.
+ * <p>
+ * 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.</p>
- *
- * <p>References:</p>
- *
+ * message digest.
+ * <p>
+ * References:
* <ol>
* <li><a href="http://www.itl.nist.gov/fipspubs/fip180-1.htm">SECURE HASH
* STANDARD</a><br>
@@ -67,12 +66,9 @@ import gnu.java.security.util.Util;
* </li>
* </ol>
*/
-public class Sha160 extends BaseHash
+public class Sha160
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final int BLOCK_SIZE = 64; // inner block size in bytes
private static final String DIGEST0 = "A9993E364706816ABA3E25717850C26C9CD0D89D";
@@ -85,9 +81,6 @@ public class Sha160 extends BaseHash
/** 160-bit interim result. */
private int h0, h1, h2, h3, h4;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Sha160()
{
@@ -95,7 +88,7 @@ public class Sha160 extends BaseHash
}
/**
- * <p>Private constructor for cloning purposes.</p>
+ * Private constructor for cloning purposes.
*
* @param md the instance to clone.
*/
@@ -112,58 +105,20 @@ public class Sha160 extends BaseHash
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];
@@ -173,41 +128,32 @@ public class Sha160 extends BaseHash
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_SIZE);
+ 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;
-
+ 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;
+ 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 };
}
protected void resetContext()
@@ -234,11 +180,9 @@ public class Sha160 extends BaseHash
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)
+ private static synchronized final int[] sha(int hh0, int hh1, int hh2,
+ int hh3, int hh4, byte[] in,
+ int offset)
{
int A = hh0;
int B = hh1;
@@ -246,20 +190,17 @@ public class Sha160 extends BaseHash
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);
- }
+ 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++)
+ for (r = 0; r < 20; r++) // rounds 0-19
{
T = (A << 5 | A >>> 27) + ((B & C) | (~B & D)) + E + w[r] + 0x5A827999;
E = D;
@@ -268,9 +209,7 @@ public class Sha160 extends BaseHash
B = A;
A = T;
}
-
- // rounds 20-39
- for (r = 20; r < 40; r++)
+ for (r = 20; r < 40; r++) // rounds 20-39
{
T = (A << 5 | A >>> 27) + (B ^ C ^ D) + E + w[r] + 0x6ED9EBA1;
E = D;
@@ -279,21 +218,16 @@ public class Sha160 extends BaseHash
B = A;
A = T;
}
-
- // rounds 40-59
- for (r = 40; r < 60; r++)
+ for (r = 40; r < 60; r++) // rounds 40-59
{
- T = (A << 5 | A >>> 27) + (B & C | B & D | C & D) + E + w[r]
- + 0x8F1BBCDC;
+ 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++)
+ for (r = 60; r < 80; r++) // rounds 60-79
{
T = (A << 5 | A >>> 27) + (B ^ C ^ D) + E + w[r] + 0xCA62C1D6;
E = D;
@@ -302,7 +236,6 @@ public class Sha160 extends BaseHash
B = A;
A = T;
}
-
return new int[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E };
}
}
diff --git a/gnu/java/security/hash/Sha256.java b/gnu/java/security/hash/Sha256.java
index 284425ea4..536b1c8ba 100644
--- a/gnu/java/security/hash/Sha256.java
+++ b/gnu/java/security/hash/Sha256.java
@@ -42,46 +42,41 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>Implementation of SHA2-1 [SHA-256] per the IETF Draft Specification.</p>
- *
- * <p>References:</p>
+ * Implementation of SHA2-1 [SHA-256] per the IETF Draft Specification.
+ * <p>
+ * References:
* <ol>
* <li><a href="http://ftp.ipv4.heanet.ie/pub/ietf/internet-drafts/draft-ietf-ipsec-ciph-aes-cbc-03.txt">
* Descriptions of SHA-256, SHA-384, and SHA-512</a>,</li>
* <li>http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf</li>
* </ol>
*/
-public class Sha256 extends BaseHash
+public class Sha256
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
- private static final int[] k = { 0x428a2f98, 0x71374491, 0xb5c0fbcf,
- 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
- 0x923f82a4, 0xab1c5ed5, 0xd807aa98,
- 0x12835b01, 0x243185be, 0x550c7dc3,
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
- 0xc19bf174, 0xe49b69c1, 0xefbe4786,
- 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f,
- 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
- 0x983e5152, 0xa831c66d, 0xb00327c8,
- 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
- 0x06ca6351, 0x14292967, 0x27b70a85,
- 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
- 0x650a7354, 0x766a0abb, 0x81c2c92e,
- 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
- 0xc24b8b70, 0xc76c51a3, 0xd192e819,
- 0xd6990624, 0xf40e3585, 0x106aa070,
- 0x19a4c116, 0x1e376c08, 0x2748774c,
- 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
- 0x5b9cca4f, 0x682e6ff3, 0x748f82ee,
- 0x78a5636f, 0x84c87814, 0x8cc70208,
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7,
- 0xc67178f2 };
+ private static final int[] k = {
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
+ };
private static final int BLOCK_SIZE = 64; // inner block size in bytes
- private static final String DIGEST0 = "BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD";
+ private static final String DIGEST0 =
+ "BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD";
private static final int[] w = new int[64];
@@ -91,9 +86,6 @@ public class Sha256 extends BaseHash
/** 256-bit interim result. */
private int h0, h1, h2, h3, h4, h5, h6, h7;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Sha256()
{
@@ -101,7 +93,7 @@ public class Sha256 extends BaseHash
}
/**
- * <p>Private constructor for cloning purposes.</p>
+ * Private constructor for cloning purposes.
*
* @param md the instance to clone.
*/
@@ -121,31 +113,20 @@ public class Sha256 extends BaseHash
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];
@@ -158,41 +139,35 @@ public class Sha256 extends BaseHash
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_SIZE);
+ 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;
-
+ 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 };
+ 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()
@@ -219,13 +194,10 @@ public class Sha256 extends BaseHash
String result = Util.toString(md.digest());
valid = Boolean.valueOf(DIGEST0.equals(result));
}
-
return valid.booleanValue();
}
- // SHA specific methods ----------------------------------------------------
-
- private static final synchronized int[] sha(int hh0, int hh1, int hh2,
+ private static synchronized final int[] sha(int hh0, int hh1, int hh2,
int hh3, int hh4, int hh5,
int hh6, int hh7, byte[] in,
int offset)
@@ -239,29 +211,31 @@ public class Sha256 extends BaseHash
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));
- }
+ 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];
+ 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]);
+ + (((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 >>> 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)));
+ 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;
@@ -271,8 +245,8 @@ public class Sha256 extends BaseHash
B = A;
A = T + T2;
}
-
- return new int[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, hh5 + F,
- hh6 + G, hh7 + H };
+ return new int[] {
+ hh0 + A, hh1 + B, hh2 + C, hh3 + D,
+ hh4 + E, hh5 + F, hh6 + G, hh7 + H };
}
}
diff --git a/gnu/java/security/hash/Sha384.java b/gnu/java/security/hash/Sha384.java
index 332f048d7..a47eb67db 100644
--- a/gnu/java/security/hash/Sha384.java
+++ b/gnu/java/security/hash/Sha384.java
@@ -42,66 +42,52 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>Implementation of SHA2-2 [SHA-384] per the IETF Draft Specification.</p>
- *
- * <p>References:</p>
+ * Implementation of SHA2-2 [SHA-384] per the IETF Draft Specification.
+ * <p>
+ * References:
* <ol>
* <li><a href="http://ftp.ipv4.heanet.ie/pub/ietf/internet-drafts/draft-ietf-ipsec-ciph-aes-cbc-03.txt">
* Descriptions of SHA-256, SHA-384, and SHA-512</a>,</li>
* <li>http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf</li>
* </ol>
*/
-public class Sha384 extends BaseHash
+public class Sha384
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- private static final long[] k = { 0x428a2f98d728ae22L, 0x7137449123ef65cdL,
- 0xb5c0fbcfec4d3b2fL, 0xe9b5dba58189dbbcL,
- 0x3956c25bf348b538L, 0x59f111f1b605d019L,
- 0x923f82a4af194f9bL, 0xab1c5ed5da6d8118L,
- 0xd807aa98a3030242L, 0x12835b0145706fbeL,
- 0x243185be4ee4b28cL, 0x550c7dc3d5ffb4e2L,
- 0x72be5d74f27b896fL, 0x80deb1fe3b1696b1L,
- 0x9bdc06a725c71235L, 0xc19bf174cf692694L,
- 0xe49b69c19ef14ad2L, 0xefbe4786384f25e3L,
- 0x0fc19dc68b8cd5b5L, 0x240ca1cc77ac9c65L,
- 0x2de92c6f592b0275L, 0x4a7484aa6ea6e483L,
- 0x5cb0a9dcbd41fbd4L, 0x76f988da831153b5L,
- 0x983e5152ee66dfabL, 0xa831c66d2db43210L,
- 0xb00327c898fb213fL, 0xbf597fc7beef0ee4L,
- 0xc6e00bf33da88fc2L, 0xd5a79147930aa725L,
- 0x06ca6351e003826fL, 0x142929670a0e6e70L,
- 0x27b70a8546d22ffcL, 0x2e1b21385c26c926L,
- 0x4d2c6dfc5ac42aedL, 0x53380d139d95b3dfL,
- 0x650a73548baf63deL, 0x766a0abb3c77b2a8L,
- 0x81c2c92e47edaee6L, 0x92722c851482353bL,
- 0xa2bfe8a14cf10364L, 0xa81a664bbc423001L,
- 0xc24b8b70d0f89791L, 0xc76c51a30654be30L,
- 0xd192e819d6ef5218L, 0xd69906245565a910L,
- 0xf40e35855771202aL, 0x106aa07032bbd1b8L,
- 0x19a4c116b8d2d0c8L, 0x1e376c085141ab53L,
- 0x2748774cdf8eeb99L, 0x34b0bcb5e19b48a8L,
- 0x391c0cb3c5c95a63L, 0x4ed8aa4ae3418acbL,
- 0x5b9cca4f7763e373L, 0x682e6ff3d6b2b8a3L,
- 0x748f82ee5defb2fcL, 0x78a5636f43172f60L,
- 0x84c87814a1f0ab72L, 0x8cc702081a6439ecL,
- 0x90befffa23631e28L, 0xa4506cebde82bde9L,
- 0xbef9a3f7b2c67915L, 0xc67178f2e372532bL,
- 0xca273eceea26619cL, 0xd186b8c721c0c207L,
- 0xeada7dd6cde0eb1eL, 0xf57d4f7fee6ed178L,
- 0x06f067aa72176fbaL, 0x0a637dc5a2c898a6L,
- 0x113f9804bef90daeL, 0x1b710b35131c471bL,
- 0x28db77f523047d84L, 0x32caab7b40c72493L,
- 0x3c9ebe0a15c9bebcL, 0x431d67c49c100d4cL,
- 0x4cc5d4becb3e42b6L, 0x597f299cfc657e2aL,
- 0x5fcb6fab3ad6faecL, 0x6c44198c4a475817L };
+ private static final long[] k = {
+ 0x428a2f98d728ae22L, 0x7137449123ef65cdL, 0xb5c0fbcfec4d3b2fL,
+ 0xe9b5dba58189dbbcL, 0x3956c25bf348b538L, 0x59f111f1b605d019L,
+ 0x923f82a4af194f9bL, 0xab1c5ed5da6d8118L, 0xd807aa98a3030242L,
+ 0x12835b0145706fbeL, 0x243185be4ee4b28cL, 0x550c7dc3d5ffb4e2L,
+ 0x72be5d74f27b896fL, 0x80deb1fe3b1696b1L, 0x9bdc06a725c71235L,
+ 0xc19bf174cf692694L, 0xe49b69c19ef14ad2L, 0xefbe4786384f25e3L,
+ 0x0fc19dc68b8cd5b5L, 0x240ca1cc77ac9c65L, 0x2de92c6f592b0275L,
+ 0x4a7484aa6ea6e483L, 0x5cb0a9dcbd41fbd4L, 0x76f988da831153b5L,
+ 0x983e5152ee66dfabL, 0xa831c66d2db43210L, 0xb00327c898fb213fL,
+ 0xbf597fc7beef0ee4L, 0xc6e00bf33da88fc2L, 0xd5a79147930aa725L,
+ 0x06ca6351e003826fL, 0x142929670a0e6e70L, 0x27b70a8546d22ffcL,
+ 0x2e1b21385c26c926L, 0x4d2c6dfc5ac42aedL, 0x53380d139d95b3dfL,
+ 0x650a73548baf63deL, 0x766a0abb3c77b2a8L, 0x81c2c92e47edaee6L,
+ 0x92722c851482353bL, 0xa2bfe8a14cf10364L, 0xa81a664bbc423001L,
+ 0xc24b8b70d0f89791L, 0xc76c51a30654be30L, 0xd192e819d6ef5218L,
+ 0xd69906245565a910L, 0xf40e35855771202aL, 0x106aa07032bbd1b8L,
+ 0x19a4c116b8d2d0c8L, 0x1e376c085141ab53L, 0x2748774cdf8eeb99L,
+ 0x34b0bcb5e19b48a8L, 0x391c0cb3c5c95a63L, 0x4ed8aa4ae3418acbL,
+ 0x5b9cca4f7763e373L, 0x682e6ff3d6b2b8a3L, 0x748f82ee5defb2fcL,
+ 0x78a5636f43172f60L, 0x84c87814a1f0ab72L, 0x8cc702081a6439ecL,
+ 0x90befffa23631e28L, 0xa4506cebde82bde9L, 0xbef9a3f7b2c67915L,
+ 0xc67178f2e372532bL, 0xca273eceea26619cL, 0xd186b8c721c0c207L,
+ 0xeada7dd6cde0eb1eL, 0xf57d4f7fee6ed178L, 0x06f067aa72176fbaL,
+ 0x0a637dc5a2c898a6L, 0x113f9804bef90daeL, 0x1b710b35131c471bL,
+ 0x28db77f523047d84L, 0x32caab7b40c72493L, 0x3c9ebe0a15c9bebcL,
+ 0x431d67c49c100d4cL, 0x4cc5d4becb3e42b6L, 0x597f299cfc657e2aL,
+ 0x5fcb6fab3ad6faecL, 0x6c44198c4a475817L };
private static final int BLOCK_SIZE = 128; // inner block size in bytes
- private static final String DIGEST0 = "CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED"
- + "8086072BA1E7CC2358BAECA134C825A7";
+ private static final String DIGEST0 =
+ "CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED"
+ + "8086072BA1E7CC2358BAECA134C825A7";
private static final long[] w = new long[80];
@@ -111,9 +97,6 @@ public class Sha384 extends BaseHash
/** 512-bit interim result. */
private long h0, h1, h2, h3, h4, h5, h6, h7;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Sha384()
{
@@ -121,7 +104,7 @@ public class Sha384 extends BaseHash
}
/**
- * <p>Private constructor for cloning purposes.</p>
+ * Private constructor for cloning purposes.
*
* @param md the instance to clone.
*/
@@ -141,9 +124,6 @@ public class Sha384 extends BaseHash
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)
@@ -151,22 +131,14 @@ public class Sha384 extends BaseHash
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];
@@ -179,57 +151,41 @@ public class Sha384 extends BaseHash
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_SIZE);
+ 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;
-
+ 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
- };
+ 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 };
}
protected void resetContext()
@@ -259,9 +215,7 @@ public class Sha384 extends BaseHash
return valid.booleanValue();
}
- // SHA specific methods ----------------------------------------------------
-
- private static final synchronized long[] sha(long hh0, long hh1, long hh2,
+ private static synchronized final long[] sha(long hh0, long hh1, long hh2,
long hh3, long hh4, long hh5,
long hh6, long hh7, byte[] in,
int offset)
@@ -276,35 +230,38 @@ public class Sha384 extends BaseHash
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);
- }
+ 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))
+ + (((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 >>> 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)))
+ T2 = (((A >>> 28) | (A << 36))
+ ^ ((A >>> 34) | (A << 30))
+ ^ ((A >>> 39) | (A << 25)))
+ ((A & B) ^ (A & C) ^ (B & C));
H = G;
G = F;
@@ -315,8 +272,8 @@ public class Sha384 extends BaseHash
B = A;
A = T + T2;
}
-
- return new long[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, hh5 + F,
- hh6 + G, hh7 + H };
+ return new long[] {
+ hh0 + A, hh1 + B, hh2 + C, hh3 + D,
+ hh4 + E, hh5 + F, hh6 + G, hh7 + H };
}
}
diff --git a/gnu/java/security/hash/Sha512.java b/gnu/java/security/hash/Sha512.java
index da035dcfc..e6f553ed4 100644
--- a/gnu/java/security/hash/Sha512.java
+++ b/gnu/java/security/hash/Sha512.java
@@ -42,66 +42,52 @@ import gnu.java.security.Registry;
import gnu.java.security.util.Util;
/**
- * <p>Implementation of SHA2-3 [SHA-512] per the IETF Draft Specification.</p>
- *
- * <p>References:</p>
+ * Implementation of SHA2-3 [SHA-512] per the IETF Draft Specification.
+ * <p>
+ * References:
* <ol>
* <li><a href="http://ftp.ipv4.heanet.ie/pub/ietf/internet-drafts/draft-ietf-ipsec-ciph-aes-cbc-03.txt">
* Descriptions of SHA-256, SHA-384, and SHA-512</a>,</li>
* <li>http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf</li>
* </ol>
*/
-public class Sha512 extends BaseHash
+public class Sha512
+ extends BaseHash
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- private static final long[] k = { 0x428a2f98d728ae22L, 0x7137449123ef65cdL,
- 0xb5c0fbcfec4d3b2fL, 0xe9b5dba58189dbbcL,
- 0x3956c25bf348b538L, 0x59f111f1b605d019L,
- 0x923f82a4af194f9bL, 0xab1c5ed5da6d8118L,
- 0xd807aa98a3030242L, 0x12835b0145706fbeL,
- 0x243185be4ee4b28cL, 0x550c7dc3d5ffb4e2L,
- 0x72be5d74f27b896fL, 0x80deb1fe3b1696b1L,
- 0x9bdc06a725c71235L, 0xc19bf174cf692694L,
- 0xe49b69c19ef14ad2L, 0xefbe4786384f25e3L,
- 0x0fc19dc68b8cd5b5L, 0x240ca1cc77ac9c65L,
- 0x2de92c6f592b0275L, 0x4a7484aa6ea6e483L,
- 0x5cb0a9dcbd41fbd4L, 0x76f988da831153b5L,
- 0x983e5152ee66dfabL, 0xa831c66d2db43210L,
- 0xb00327c898fb213fL, 0xbf597fc7beef0ee4L,
- 0xc6e00bf33da88fc2L, 0xd5a79147930aa725L,
- 0x06ca6351e003826fL, 0x142929670a0e6e70L,
- 0x27b70a8546d22ffcL, 0x2e1b21385c26c926L,
- 0x4d2c6dfc5ac42aedL, 0x53380d139d95b3dfL,
- 0x650a73548baf63deL, 0x766a0abb3c77b2a8L,
- 0x81c2c92e47edaee6L, 0x92722c851482353bL,
- 0xa2bfe8a14cf10364L, 0xa81a664bbc423001L,
- 0xc24b8b70d0f89791L, 0xc76c51a30654be30L,
- 0xd192e819d6ef5218L, 0xd69906245565a910L,
- 0xf40e35855771202aL, 0x106aa07032bbd1b8L,
- 0x19a4c116b8d2d0c8L, 0x1e376c085141ab53L,
- 0x2748774cdf8eeb99L, 0x34b0bcb5e19b48a8L,
- 0x391c0cb3c5c95a63L, 0x4ed8aa4ae3418acbL,
- 0x5b9cca4f7763e373L, 0x682e6ff3d6b2b8a3L,
- 0x748f82ee5defb2fcL, 0x78a5636f43172f60L,
- 0x84c87814a1f0ab72L, 0x8cc702081a6439ecL,
- 0x90befffa23631e28L, 0xa4506cebde82bde9L,
- 0xbef9a3f7b2c67915L, 0xc67178f2e372532bL,
- 0xca273eceea26619cL, 0xd186b8c721c0c207L,
- 0xeada7dd6cde0eb1eL, 0xf57d4f7fee6ed178L,
- 0x06f067aa72176fbaL, 0x0a637dc5a2c898a6L,
- 0x113f9804bef90daeL, 0x1b710b35131c471bL,
- 0x28db77f523047d84L, 0x32caab7b40c72493L,
- 0x3c9ebe0a15c9bebcL, 0x431d67c49c100d4cL,
- 0x4cc5d4becb3e42b6L, 0x597f299cfc657e2aL,
- 0x5fcb6fab3ad6faecL, 0x6c44198c4a475817L };
+ private static final long[] k = {
+ 0x428a2f98d728ae22L, 0x7137449123ef65cdL, 0xb5c0fbcfec4d3b2fL,
+ 0xe9b5dba58189dbbcL, 0x3956c25bf348b538L, 0x59f111f1b605d019L,
+ 0x923f82a4af194f9bL, 0xab1c5ed5da6d8118L, 0xd807aa98a3030242L,
+ 0x12835b0145706fbeL, 0x243185be4ee4b28cL, 0x550c7dc3d5ffb4e2L,
+ 0x72be5d74f27b896fL, 0x80deb1fe3b1696b1L, 0x9bdc06a725c71235L,
+ 0xc19bf174cf692694L, 0xe49b69c19ef14ad2L, 0xefbe4786384f25e3L,
+ 0x0fc19dc68b8cd5b5L, 0x240ca1cc77ac9c65L, 0x2de92c6f592b0275L,
+ 0x4a7484aa6ea6e483L, 0x5cb0a9dcbd41fbd4L, 0x76f988da831153b5L,
+ 0x983e5152ee66dfabL, 0xa831c66d2db43210L, 0xb00327c898fb213fL,
+ 0xbf597fc7beef0ee4L, 0xc6e00bf33da88fc2L, 0xd5a79147930aa725L,
+ 0x06ca6351e003826fL, 0x142929670a0e6e70L, 0x27b70a8546d22ffcL,
+ 0x2e1b21385c26c926L, 0x4d2c6dfc5ac42aedL, 0x53380d139d95b3dfL,
+ 0x650a73548baf63deL, 0x766a0abb3c77b2a8L, 0x81c2c92e47edaee6L,
+ 0x92722c851482353bL, 0xa2bfe8a14cf10364L, 0xa81a664bbc423001L,
+ 0xc24b8b70d0f89791L, 0xc76c51a30654be30L, 0xd192e819d6ef5218L,
+ 0xd69906245565a910L, 0xf40e35855771202aL, 0x106aa07032bbd1b8L,
+ 0x19a4c116b8d2d0c8L, 0x1e376c085141ab53L, 0x2748774cdf8eeb99L,
+ 0x34b0bcb5e19b48a8L, 0x391c0cb3c5c95a63L, 0x4ed8aa4ae3418acbL,
+ 0x5b9cca4f7763e373L, 0x682e6ff3d6b2b8a3L, 0x748f82ee5defb2fcL,
+ 0x78a5636f43172f60L, 0x84c87814a1f0ab72L, 0x8cc702081a6439ecL,
+ 0x90befffa23631e28L, 0xa4506cebde82bde9L, 0xbef9a3f7b2c67915L,
+ 0xc67178f2e372532bL, 0xca273eceea26619cL, 0xd186b8c721c0c207L,
+ 0xeada7dd6cde0eb1eL, 0xf57d4f7fee6ed178L, 0x06f067aa72176fbaL,
+ 0x0a637dc5a2c898a6L, 0x113f9804bef90daeL, 0x1b710b35131c471bL,
+ 0x28db77f523047d84L, 0x32caab7b40c72493L, 0x3c9ebe0a15c9bebcL,
+ 0x431d67c49c100d4cL, 0x4cc5d4becb3e42b6L, 0x597f299cfc657e2aL,
+ 0x5fcb6fab3ad6faecL, 0x6c44198c4a475817L };
private static final int BLOCK_SIZE = 128; // inner block size in bytes
- private static final String DIGEST0 = "DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A"
- + "2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F";
+ private static final String DIGEST0 =
+ "DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A"
+ + "2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F";
private static final long[] w = new long[80];
@@ -111,9 +97,6 @@ public class Sha512 extends BaseHash
/** 512-bit interim result. */
private long h0, h1, h2, h3, h4, h5, h6, h7;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Sha512()
{
@@ -121,7 +104,7 @@ public class Sha512 extends BaseHash
}
/**
- * <p>Private constructor for cloning purposes.</p>
+ * Private constructor for cloning purposes.
*
* @param md the instance to clone.
*/
@@ -141,9 +124,6 @@ public class Sha512 extends BaseHash
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)
@@ -151,22 +131,14 @@ public class Sha512 extends BaseHash
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];
@@ -179,59 +151,45 @@ public class Sha512 extends BaseHash
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_SIZE);
+ 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;
-
+ 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 };
+ 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()
@@ -261,9 +219,7 @@ public class Sha512 extends BaseHash
return valid.booleanValue();
}
- // SHA specific methods ----------------------------------------------------
-
- private static final synchronized long[] sha(long hh0, long hh1, long hh2,
+ private static synchronized final long[] sha(long hh0, long hh1, long hh2,
long hh3, long hh4, long hh5,
long hh6, long hh7, byte[] in,
int offset)
@@ -278,33 +234,36 @@ public class Sha512 extends BaseHash
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);
- }
+ 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))
+ + (((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 >>> 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)))
+ T2 = (((A >>> 28) | (A << 36))
+ ^ ((A >>> 34) | (A << 30))
+ ^ ((A >>> 39) | (A << 25)))
+ ((A & B) ^ (A & C) ^ (B & C));
H = G;
G = F;
@@ -315,8 +274,8 @@ public class Sha512 extends BaseHash
B = A;
A = T + T2;
}
-
- return new long[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, hh5 + F,
- hh6 + G, hh7 + H };
+ return new long[] {
+ hh0 + A, hh1 + B, hh2 + C, hh3 + D,
+ hh4 + E, hh5 + F, hh6 + G, hh7 + H };
}
}
diff --git a/gnu/java/security/hash/Tiger.java b/gnu/java/security/hash/Tiger.java
index be0921dce..101df39ef 100644
--- a/gnu/java/security/hash/Tiger.java
+++ b/gnu/java/security/hash/Tiger.java
@@ -46,29 +46,27 @@ import gnu.java.security.util.Util;
* 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.
- *
- * <p>Tiger processes data in 512-bit blocks and produces a 192-bit
- * digest.</p>
- *
- * <p>References:</p>
+ * <p>
+ * Tiger processes data in 512-bit blocks and produces a 192-bit
+ * digest.
+ * <p>
+ * References:
* <ol>
* <li><a
* href="http://www.cs.technion.ac.il/~biham/Reports/Tiger/">Tiger: A
* Fast New Hash Function</a>, Ross Anderson and Eli Biham.</a></li>
* </ol>
*/
-public class Tiger extends BaseHash
+public class Tiger
+ extends BaseHash
{
-
- // Constants and variables.
- // -----------------------------------------------------------------------
-
private static final int HASH_SIZE = 24;
private static final int BLOCK_SIZE = 64;
/** Result when no data has been input. */
- private static final String DIGEST0 = "3293AC630C13F0245F92BBB1766E16167A4E58492DDE73F3";
+ private static final String DIGEST0 =
+ "3293AC630C13F0245F92BBB1766E16167A4E58492DDE73F3";
private static final long A = 0x0123456789ABCDEFL;
@@ -77,524 +75,360 @@ public class Tiger extends BaseHash
private static final long C = 0xF096A5B4C3B2E187L;
/** S-Box T1. */
- private static final long[] T1 = { 0x02AAB17CF7E90C5EL, 0xAC424B03E243A8ECL,
- 0x72CD5BE30DD5FCD3L, 0x6D019B93F6F97F3AL,
- 0xCD9978FFD21F9193L, 0x7573A1C9708029E2L,
- 0xB164326B922A83C3L, 0x46883EEE04915870L,
- 0xEAACE3057103ECE6L, 0xC54169B808A3535CL,
- 0x4CE754918DDEC47CL, 0x0AA2F4DFDC0DF40CL,
- 0x10B76F18A74DBEFAL, 0xC6CCB6235AD1AB6AL,
- 0x13726121572FE2FFL, 0x1A488C6F199D921EL,
- 0x4BC9F9F4DA0007CAL, 0x26F5E6F6E85241C7L,
- 0x859079DBEA5947B6L, 0x4F1885C5C99E8C92L,
- 0xD78E761EA96F864BL, 0x8E36428C52B5C17DL,
- 0x69CF6827373063C1L, 0xB607C93D9BB4C56EL,
- 0x7D820E760E76B5EAL, 0x645C9CC6F07FDC42L,
- 0xBF38A078243342E0L, 0x5F6B343C9D2E7D04L,
- 0xF2C28AEB600B0EC6L, 0x6C0ED85F7254BCACL,
- 0x71592281A4DB4FE5L, 0x1967FA69CE0FED9FL,
- 0xFD5293F8B96545DBL, 0xC879E9D7F2A7600BL,
- 0x860248920193194EL, 0xA4F9533B2D9CC0B3L,
- 0x9053836C15957613L, 0xDB6DCF8AFC357BF1L,
- 0x18BEEA7A7A370F57L, 0x037117CA50B99066L,
- 0x6AB30A9774424A35L, 0xF4E92F02E325249BL,
- 0x7739DB07061CCAE1L, 0xD8F3B49CECA42A05L,
- 0xBD56BE3F51382F73L, 0x45FAED5843B0BB28L,
- 0x1C813D5C11BF1F83L, 0x8AF0E4B6D75FA169L,
- 0x33EE18A487AD9999L, 0x3C26E8EAB1C94410L,
- 0xB510102BC0A822F9L, 0x141EEF310CE6123BL,
- 0xFC65B90059DDB154L, 0xE0158640C5E0E607L,
- 0x884E079826C3A3CFL, 0x930D0D9523C535FDL,
- 0x35638D754E9A2B00L, 0x4085FCCF40469DD5L,
- 0xC4B17AD28BE23A4CL, 0xCAB2F0FC6A3E6A2EL,
- 0x2860971A6B943FCDL, 0x3DDE6EE212E30446L,
- 0x6222F32AE01765AEL, 0x5D550BB5478308FEL,
- 0xA9EFA98DA0EDA22AL, 0xC351A71686C40DA7L,
- 0x1105586D9C867C84L, 0xDCFFEE85FDA22853L,
- 0xCCFBD0262C5EEF76L, 0xBAF294CB8990D201L,
- 0xE69464F52AFAD975L, 0x94B013AFDF133E14L,
- 0x06A7D1A32823C958L, 0x6F95FE5130F61119L,
- 0xD92AB34E462C06C0L, 0xED7BDE33887C71D2L,
- 0x79746D6E6518393EL, 0x5BA419385D713329L,
- 0x7C1BA6B948A97564L, 0x31987C197BFDAC67L,
- 0xDE6C23C44B053D02L, 0x581C49FED002D64DL,
- 0xDD474D6338261571L, 0xAA4546C3E473D062L,
- 0x928FCE349455F860L, 0x48161BBACAAB94D9L,
- 0x63912430770E6F68L, 0x6EC8A5E602C6641CL,
- 0x87282515337DDD2BL, 0x2CDA6B42034B701BL,
- 0xB03D37C181CB096DL, 0xE108438266C71C6FL,
- 0x2B3180C7EB51B255L, 0xDF92B82F96C08BBCL,
- 0x5C68C8C0A632F3BAL, 0x5504CC861C3D0556L,
- 0xABBFA4E55FB26B8FL, 0x41848B0AB3BACEB4L,
- 0xB334A273AA445D32L, 0xBCA696F0A85AD881L,
- 0x24F6EC65B528D56CL, 0x0CE1512E90F4524AL,
- 0x4E9DD79D5506D35AL, 0x258905FAC6CE9779L,
- 0x2019295B3E109B33L, 0xF8A9478B73A054CCL,
- 0x2924F2F934417EB0L, 0x3993357D536D1BC4L,
- 0x38A81AC21DB6FF8BL, 0x47C4FBF17D6016BFL,
- 0x1E0FAADD7667E3F5L, 0x7ABCFF62938BEB96L,
- 0xA78DAD948FC179C9L, 0x8F1F98B72911E50DL,
- 0x61E48EAE27121A91L, 0x4D62F7AD31859808L,
- 0xECEBA345EF5CEAEBL, 0xF5CEB25EBC9684CEL,
- 0xF633E20CB7F76221L, 0xA32CDF06AB8293E4L,
- 0x985A202CA5EE2CA4L, 0xCF0B8447CC8A8FB1L,
- 0x9F765244979859A3L, 0xA8D516B1A1240017L,
- 0x0BD7BA3EBB5DC726L, 0xE54BCA55B86ADB39L,
- 0x1D7A3AFD6C478063L, 0x519EC608E7669EDDL,
- 0x0E5715A2D149AA23L, 0x177D4571848FF194L,
- 0xEEB55F3241014C22L, 0x0F5E5CA13A6E2EC2L,
- 0x8029927B75F5C361L, 0xAD139FABC3D6E436L,
- 0x0D5DF1A94CCF402FL, 0x3E8BD948BEA5DFC8L,
- 0xA5A0D357BD3FF77EL, 0xA2D12E251F74F645L,
- 0x66FD9E525E81A082L, 0x2E0C90CE7F687A49L,
- 0xC2E8BCBEBA973BC5L, 0x000001BCE509745FL,
- 0x423777BBE6DAB3D6L, 0xD1661C7EAEF06EB5L,
- 0xA1781F354DAACFD8L, 0x2D11284A2B16AFFCL,
- 0xF1FC4F67FA891D1FL, 0x73ECC25DCB920ADAL,
- 0xAE610C22C2A12651L, 0x96E0A810D356B78AL,
- 0x5A9A381F2FE7870FL, 0xD5AD62EDE94E5530L,
- 0xD225E5E8368D1427L, 0x65977B70C7AF4631L,
- 0x99F889B2DE39D74FL, 0x233F30BF54E1D143L,
- 0x9A9675D3D9A63C97L, 0x5470554FF334F9A8L,
- 0x166ACB744A4F5688L, 0x70C74CAAB2E4AEADL,
- 0xF0D091646F294D12L, 0x57B82A89684031D1L,
- 0xEFD95A5A61BE0B6BL, 0x2FBD12E969F2F29AL,
- 0x9BD37013FEFF9FE8L, 0x3F9B0404D6085A06L,
- 0x4940C1F3166CFE15L, 0x09542C4DCDF3DEFBL,
- 0xB4C5218385CD5CE3L, 0xC935B7DC4462A641L,
- 0x3417F8A68ED3B63FL, 0xB80959295B215B40L,
- 0xF99CDAEF3B8C8572L, 0x018C0614F8FCB95DL,
- 0x1B14ACCD1A3ACDF3L, 0x84D471F200BB732DL,
- 0xC1A3110E95E8DA16L, 0x430A7220BF1A82B8L,
- 0xB77E090D39DF210EL, 0x5EF4BD9F3CD05E9DL,
- 0x9D4FF6DA7E57A444L, 0xDA1D60E183D4A5F8L,
- 0xB287C38417998E47L, 0xFE3EDC121BB31886L,
- 0xC7FE3CCC980CCBEFL, 0xE46FB590189BFD03L,
- 0x3732FD469A4C57DCL, 0x7EF700A07CF1AD65L,
- 0x59C64468A31D8859L, 0x762FB0B4D45B61F6L,
- 0x155BAED099047718L, 0x68755E4C3D50BAA6L,
- 0xE9214E7F22D8B4DFL, 0x2ADDBF532EAC95F4L,
- 0x32AE3909B4BD0109L, 0x834DF537B08E3450L,
- 0xFA209DA84220728DL, 0x9E691D9B9EFE23F7L,
- 0x0446D288C4AE8D7FL, 0x7B4CC524E169785BL,
- 0x21D87F0135CA1385L, 0xCEBB400F137B8AA5L,
- 0x272E2B66580796BEL, 0x3612264125C2B0DEL,
- 0x057702BDAD1EFBB2L, 0xD4BABB8EACF84BE9L,
- 0x91583139641BC67BL, 0x8BDC2DE08036E024L,
- 0x603C8156F49F68EDL, 0xF7D236F7DBEF5111L,
- 0x9727C4598AD21E80L, 0xA08A0896670A5FD7L,
- 0xCB4A8F4309EBA9CBL, 0x81AF564B0F7036A1L,
- 0xC0B99AA778199ABDL, 0x959F1EC83FC8E952L,
- 0x8C505077794A81B9L, 0x3ACAAF8F056338F0L,
- 0x07B43F50627A6778L, 0x4A44AB49F5ECCC77L,
- 0x3BC3D6E4B679EE98L, 0x9CC0D4D1CF14108CL,
- 0x4406C00B206BC8A0L, 0x82A18854C8D72D89L,
- 0x67E366B35C3C432CL, 0xB923DD61102B37F2L,
- 0x56AB2779D884271DL, 0xBE83E1B0FF1525AFL,
- 0xFB7C65D4217E49A9L, 0x6BDBE0E76D48E7D4L,
- 0x08DF828745D9179EL, 0x22EA6A9ADD53BD34L,
- 0xE36E141C5622200AL, 0x7F805D1B8CB750EEL,
- 0xAFE5C7A59F58E837L, 0xE27F996A4FB1C23CL,
- 0xD3867DFB0775F0D0L, 0xD0E673DE6E88891AL,
- 0x123AEB9EAFB86C25L, 0x30F1D5D5C145B895L,
- 0xBB434A2DEE7269E7L, 0x78CB67ECF931FA38L,
- 0xF33B0372323BBF9CL, 0x52D66336FB279C74L,
- 0x505F33AC0AFB4EAAL, 0xE8A5CD99A2CCE187L,
- 0x534974801E2D30BBL, 0x8D2D5711D5876D90L,
- 0x1F1A412891BC038EL, 0xD6E2E71D82E56648L,
- 0x74036C3A497732B7L, 0x89B67ED96361F5ABL,
- 0xFFED95D8F1EA02A2L, 0xE72B3BD61464D43DL,
- 0xA6300F170BDC4820L, 0xEBC18760ED78A77AL };
+ private static final long[] T1 = {
+ 0x02AAB17CF7E90C5EL, 0xAC424B03E243A8ECL, 0x72CD5BE30DD5FCD3L,
+ 0x6D019B93F6F97F3AL, 0xCD9978FFD21F9193L, 0x7573A1C9708029E2L,
+ 0xB164326B922A83C3L, 0x46883EEE04915870L, 0xEAACE3057103ECE6L,
+ 0xC54169B808A3535CL, 0x4CE754918DDEC47CL, 0x0AA2F4DFDC0DF40CL,
+ 0x10B76F18A74DBEFAL, 0xC6CCB6235AD1AB6AL, 0x13726121572FE2FFL,
+ 0x1A488C6F199D921EL, 0x4BC9F9F4DA0007CAL, 0x26F5E6F6E85241C7L,
+ 0x859079DBEA5947B6L, 0x4F1885C5C99E8C92L, 0xD78E761EA96F864BL,
+ 0x8E36428C52B5C17DL, 0x69CF6827373063C1L, 0xB607C93D9BB4C56EL,
+ 0x7D820E760E76B5EAL, 0x645C9CC6F07FDC42L, 0xBF38A078243342E0L,
+ 0x5F6B343C9D2E7D04L, 0xF2C28AEB600B0EC6L, 0x6C0ED85F7254BCACL,
+ 0x71592281A4DB4FE5L, 0x1967FA69CE0FED9FL, 0xFD5293F8B96545DBL,
+ 0xC879E9D7F2A7600BL, 0x860248920193194EL, 0xA4F9533B2D9CC0B3L,
+ 0x9053836C15957613L, 0xDB6DCF8AFC357BF1L, 0x18BEEA7A7A370F57L,
+ 0x037117CA50B99066L, 0x6AB30A9774424A35L, 0xF4E92F02E325249BL,
+ 0x7739DB07061CCAE1L, 0xD8F3B49CECA42A05L, 0xBD56BE3F51382F73L,
+ 0x45FAED5843B0BB28L, 0x1C813D5C11BF1F83L, 0x8AF0E4B6D75FA169L,
+ 0x33EE18A487AD9999L, 0x3C26E8EAB1C94410L, 0xB510102BC0A822F9L,
+ 0x141EEF310CE6123BL, 0xFC65B90059DDB154L, 0xE0158640C5E0E607L,
+ 0x884E079826C3A3CFL, 0x930D0D9523C535FDL, 0x35638D754E9A2B00L,
+ 0x4085FCCF40469DD5L, 0xC4B17AD28BE23A4CL, 0xCAB2F0FC6A3E6A2EL,
+ 0x2860971A6B943FCDL, 0x3DDE6EE212E30446L, 0x6222F32AE01765AEL,
+ 0x5D550BB5478308FEL, 0xA9EFA98DA0EDA22AL, 0xC351A71686C40DA7L,
+ 0x1105586D9C867C84L, 0xDCFFEE85FDA22853L, 0xCCFBD0262C5EEF76L,
+ 0xBAF294CB8990D201L, 0xE69464F52AFAD975L, 0x94B013AFDF133E14L,
+ 0x06A7D1A32823C958L, 0x6F95FE5130F61119L, 0xD92AB34E462C06C0L,
+ 0xED7BDE33887C71D2L, 0x79746D6E6518393EL, 0x5BA419385D713329L,
+ 0x7C1BA6B948A97564L, 0x31987C197BFDAC67L, 0xDE6C23C44B053D02L,
+ 0x581C49FED002D64DL, 0xDD474D6338261571L, 0xAA4546C3E473D062L,
+ 0x928FCE349455F860L, 0x48161BBACAAB94D9L, 0x63912430770E6F68L,
+ 0x6EC8A5E602C6641CL, 0x87282515337DDD2BL, 0x2CDA6B42034B701BL,
+ 0xB03D37C181CB096DL, 0xE108438266C71C6FL, 0x2B3180C7EB51B255L,
+ 0xDF92B82F96C08BBCL, 0x5C68C8C0A632F3BAL, 0x5504CC861C3D0556L,
+ 0xABBFA4E55FB26B8FL, 0x41848B0AB3BACEB4L, 0xB334A273AA445D32L,
+ 0xBCA696F0A85AD881L, 0x24F6EC65B528D56CL, 0x0CE1512E90F4524AL,
+ 0x4E9DD79D5506D35AL, 0x258905FAC6CE9779L, 0x2019295B3E109B33L,
+ 0xF8A9478B73A054CCL, 0x2924F2F934417EB0L, 0x3993357D536D1BC4L,
+ 0x38A81AC21DB6FF8BL, 0x47C4FBF17D6016BFL, 0x1E0FAADD7667E3F5L,
+ 0x7ABCFF62938BEB96L, 0xA78DAD948FC179C9L, 0x8F1F98B72911E50DL,
+ 0x61E48EAE27121A91L, 0x4D62F7AD31859808L, 0xECEBA345EF5CEAEBL,
+ 0xF5CEB25EBC9684CEL, 0xF633E20CB7F76221L, 0xA32CDF06AB8293E4L,
+ 0x985A202CA5EE2CA4L, 0xCF0B8447CC8A8FB1L, 0x9F765244979859A3L,
+ 0xA8D516B1A1240017L, 0x0BD7BA3EBB5DC726L, 0xE54BCA55B86ADB39L,
+ 0x1D7A3AFD6C478063L, 0x519EC608E7669EDDL, 0x0E5715A2D149AA23L,
+ 0x177D4571848FF194L, 0xEEB55F3241014C22L, 0x0F5E5CA13A6E2EC2L,
+ 0x8029927B75F5C361L, 0xAD139FABC3D6E436L, 0x0D5DF1A94CCF402FL,
+ 0x3E8BD948BEA5DFC8L, 0xA5A0D357BD3FF77EL, 0xA2D12E251F74F645L,
+ 0x66FD9E525E81A082L, 0x2E0C90CE7F687A49L, 0xC2E8BCBEBA973BC5L,
+ 0x000001BCE509745FL, 0x423777BBE6DAB3D6L, 0xD1661C7EAEF06EB5L,
+ 0xA1781F354DAACFD8L, 0x2D11284A2B16AFFCL, 0xF1FC4F67FA891D1FL,
+ 0x73ECC25DCB920ADAL, 0xAE610C22C2A12651L, 0x96E0A810D356B78AL,
+ 0x5A9A381F2FE7870FL, 0xD5AD62EDE94E5530L, 0xD225E5E8368D1427L,
+ 0x65977B70C7AF4631L, 0x99F889B2DE39D74FL, 0x233F30BF54E1D143L,
+ 0x9A9675D3D9A63C97L, 0x5470554FF334F9A8L, 0x166ACB744A4F5688L,
+ 0x70C74CAAB2E4AEADL, 0xF0D091646F294D12L, 0x57B82A89684031D1L,
+ 0xEFD95A5A61BE0B6BL, 0x2FBD12E969F2F29AL, 0x9BD37013FEFF9FE8L,
+ 0x3F9B0404D6085A06L, 0x4940C1F3166CFE15L, 0x09542C4DCDF3DEFBL,
+ 0xB4C5218385CD5CE3L, 0xC935B7DC4462A641L, 0x3417F8A68ED3B63FL,
+ 0xB80959295B215B40L, 0xF99CDAEF3B8C8572L, 0x018C0614F8FCB95DL,
+ 0x1B14ACCD1A3ACDF3L, 0x84D471F200BB732DL, 0xC1A3110E95E8DA16L,
+ 0x430A7220BF1A82B8L, 0xB77E090D39DF210EL, 0x5EF4BD9F3CD05E9DL,
+ 0x9D4FF6DA7E57A444L, 0xDA1D60E183D4A5F8L, 0xB287C38417998E47L,
+ 0xFE3EDC121BB31886L, 0xC7FE3CCC980CCBEFL, 0xE46FB590189BFD03L,
+ 0x3732FD469A4C57DCL, 0x7EF700A07CF1AD65L, 0x59C64468A31D8859L,
+ 0x762FB0B4D45B61F6L, 0x155BAED099047718L, 0x68755E4C3D50BAA6L,
+ 0xE9214E7F22D8B4DFL, 0x2ADDBF532EAC95F4L, 0x32AE3909B4BD0109L,
+ 0x834DF537B08E3450L, 0xFA209DA84220728DL, 0x9E691D9B9EFE23F7L,
+ 0x0446D288C4AE8D7FL, 0x7B4CC524E169785BL, 0x21D87F0135CA1385L,
+ 0xCEBB400F137B8AA5L, 0x272E2B66580796BEL, 0x3612264125C2B0DEL,
+ 0x057702BDAD1EFBB2L, 0xD4BABB8EACF84BE9L, 0x91583139641BC67BL,
+ 0x8BDC2DE08036E024L, 0x603C8156F49F68EDL, 0xF7D236F7DBEF5111L,
+ 0x9727C4598AD21E80L, 0xA08A0896670A5FD7L, 0xCB4A8F4309EBA9CBL,
+ 0x81AF564B0F7036A1L, 0xC0B99AA778199ABDL, 0x959F1EC83FC8E952L,
+ 0x8C505077794A81B9L, 0x3ACAAF8F056338F0L, 0x07B43F50627A6778L,
+ 0x4A44AB49F5ECCC77L, 0x3BC3D6E4B679EE98L, 0x9CC0D4D1CF14108CL,
+ 0x4406C00B206BC8A0L, 0x82A18854C8D72D89L, 0x67E366B35C3C432CL,
+ 0xB923DD61102B37F2L, 0x56AB2779D884271DL, 0xBE83E1B0FF1525AFL,
+ 0xFB7C65D4217E49A9L, 0x6BDBE0E76D48E7D4L, 0x08DF828745D9179EL,
+ 0x22EA6A9ADD53BD34L, 0xE36E141C5622200AL, 0x7F805D1B8CB750EEL,
+ 0xAFE5C7A59F58E837L, 0xE27F996A4FB1C23CL, 0xD3867DFB0775F0D0L,
+ 0xD0E673DE6E88891AL, 0x123AEB9EAFB86C25L, 0x30F1D5D5C145B895L,
+ 0xBB434A2DEE7269E7L, 0x78CB67ECF931FA38L, 0xF33B0372323BBF9CL,
+ 0x52D66336FB279C74L, 0x505F33AC0AFB4EAAL, 0xE8A5CD99A2CCE187L,
+ 0x534974801E2D30BBL, 0x8D2D5711D5876D90L, 0x1F1A412891BC038EL,
+ 0xD6E2E71D82E56648L, 0x74036C3A497732B7L, 0x89B67ED96361F5ABL,
+ 0xFFED95D8F1EA02A2L, 0xE72B3BD61464D43DL, 0xA6300F170BDC4820L,
+ 0xEBC18760ED78A77AL };
/** S-Box T2. */
- private static final long[] T2 = { 0xE6A6BE5A05A12138L, 0xB5A122A5B4F87C98L,
- 0x563C6089140B6990L, 0x4C46CB2E391F5DD5L,
- 0xD932ADDBC9B79434L, 0x08EA70E42015AFF5L,
- 0xD765A6673E478CF1L, 0xC4FB757EAB278D99L,
- 0xDF11C6862D6E0692L, 0xDDEB84F10D7F3B16L,
- 0x6F2EF604A665EA04L, 0x4A8E0F0FF0E0DFB3L,
- 0xA5EDEEF83DBCBA51L, 0xFC4F0A2A0EA4371EL,
- 0xE83E1DA85CB38429L, 0xDC8FF882BA1B1CE2L,
- 0xCD45505E8353E80DL, 0x18D19A00D4DB0717L,
- 0x34A0CFEDA5F38101L, 0x0BE77E518887CAF2L,
- 0x1E341438B3C45136L, 0xE05797F49089CCF9L,
- 0xFFD23F9DF2591D14L, 0x543DDA228595C5CDL,
- 0x661F81FD99052A33L, 0x8736E641DB0F7B76L,
- 0x15227725418E5307L, 0xE25F7F46162EB2FAL,
- 0x48A8B2126C13D9FEL, 0xAFDC541792E76EEAL,
- 0x03D912BFC6D1898FL, 0x31B1AAFA1B83F51BL,
- 0xF1AC2796E42AB7D9L, 0x40A3A7D7FCD2EBACL,
- 0x1056136D0AFBBCC5L, 0x7889E1DD9A6D0C85L,
- 0xD33525782A7974AAL, 0xA7E25D09078AC09BL,
- 0xBD4138B3EAC6EDD0L, 0x920ABFBE71EB9E70L,
- 0xA2A5D0F54FC2625CL, 0xC054E36B0B1290A3L,
- 0xF6DD59FF62FE932BL, 0x3537354511A8AC7DL,
- 0xCA845E9172FADCD4L, 0x84F82B60329D20DCL,
- 0x79C62CE1CD672F18L, 0x8B09A2ADD124642CL,
- 0xD0C1E96A19D9E726L, 0x5A786A9B4BA9500CL,
- 0x0E020336634C43F3L, 0xC17B474AEB66D822L,
- 0x6A731AE3EC9BAAC2L, 0x8226667AE0840258L,
- 0x67D4567691CAECA5L, 0x1D94155C4875ADB5L,
- 0x6D00FD985B813FDFL, 0x51286EFCB774CD06L,
- 0x5E8834471FA744AFL, 0xF72CA0AEE761AE2EL,
- 0xBE40E4CDAEE8E09AL, 0xE9970BBB5118F665L,
- 0x726E4BEB33DF1964L, 0x703B000729199762L,
- 0x4631D816F5EF30A7L, 0xB880B5B51504A6BEL,
- 0x641793C37ED84B6CL, 0x7B21ED77F6E97D96L,
- 0x776306312EF96B73L, 0xAE528948E86FF3F4L,
- 0x53DBD7F286A3F8F8L, 0x16CADCE74CFC1063L,
- 0x005C19BDFA52C6DDL, 0x68868F5D64D46AD3L,
- 0x3A9D512CCF1E186AL, 0x367E62C2385660AEL,
- 0xE359E7EA77DCB1D7L, 0x526C0773749ABE6EL,
- 0x735AE5F9D09F734BL, 0x493FC7CC8A558BA8L,
- 0xB0B9C1533041AB45L, 0x321958BA470A59BDL,
- 0x852DB00B5F46C393L, 0x91209B2BD336B0E5L,
- 0x6E604F7D659EF19FL, 0xB99A8AE2782CCB24L,
- 0xCCF52AB6C814C4C7L, 0x4727D9AFBE11727BL,
- 0x7E950D0C0121B34DL, 0x756F435670AD471FL,
- 0xF5ADD442615A6849L, 0x4E87E09980B9957AL,
- 0x2ACFA1DF50AEE355L, 0xD898263AFD2FD556L,
- 0xC8F4924DD80C8FD6L, 0xCF99CA3D754A173AL,
- 0xFE477BACAF91BF3CL, 0xED5371F6D690C12DL,
- 0x831A5C285E687094L, 0xC5D3C90A3708A0A4L,
- 0x0F7F903717D06580L, 0x19F9BB13B8FDF27FL,
- 0xB1BD6F1B4D502843L, 0x1C761BA38FFF4012L,
- 0x0D1530C4E2E21F3BL, 0x8943CE69A7372C8AL,
- 0xE5184E11FEB5CE66L, 0x618BDB80BD736621L,
- 0x7D29BAD68B574D0BL, 0x81BB613E25E6FE5BL,
- 0x071C9C10BC07913FL, 0xC7BEEB7909AC2D97L,
- 0xC3E58D353BC5D757L, 0xEB017892F38F61E8L,
- 0xD4EFFB9C9B1CC21AL, 0x99727D26F494F7ABL,
- 0xA3E063A2956B3E03L, 0x9D4A8B9A4AA09C30L,
- 0x3F6AB7D500090FB4L, 0x9CC0F2A057268AC0L,
- 0x3DEE9D2DEDBF42D1L, 0x330F49C87960A972L,
- 0xC6B2720287421B41L, 0x0AC59EC07C00369CL,
- 0xEF4EAC49CB353425L, 0xF450244EEF0129D8L,
- 0x8ACC46E5CAF4DEB6L, 0x2FFEAB63989263F7L,
- 0x8F7CB9FE5D7A4578L, 0x5BD8F7644E634635L,
- 0x427A7315BF2DC900L, 0x17D0C4AA2125261CL,
- 0x3992486C93518E50L, 0xB4CBFEE0A2D7D4C3L,
- 0x7C75D6202C5DDD8DL, 0xDBC295D8E35B6C61L,
- 0x60B369D302032B19L, 0xCE42685FDCE44132L,
- 0x06F3DDB9DDF65610L, 0x8EA4D21DB5E148F0L,
- 0x20B0FCE62FCD496FL, 0x2C1B912358B0EE31L,
- 0xB28317B818F5A308L, 0xA89C1E189CA6D2CFL,
- 0x0C6B18576AAADBC8L, 0xB65DEAA91299FAE3L,
- 0xFB2B794B7F1027E7L, 0x04E4317F443B5BEBL,
- 0x4B852D325939D0A6L, 0xD5AE6BEEFB207FFCL,
- 0x309682B281C7D374L, 0xBAE309A194C3B475L,
- 0x8CC3F97B13B49F05L, 0x98A9422FF8293967L,
- 0x244B16B01076FF7CL, 0xF8BF571C663D67EEL,
- 0x1F0D6758EEE30DA1L, 0xC9B611D97ADEB9B7L,
- 0xB7AFD5887B6C57A2L, 0x6290AE846B984FE1L,
- 0x94DF4CDEACC1A5FDL, 0x058A5BD1C5483AFFL,
- 0x63166CC142BA3C37L, 0x8DB8526EB2F76F40L,
- 0xE10880036F0D6D4EL, 0x9E0523C9971D311DL,
- 0x45EC2824CC7CD691L, 0x575B8359E62382C9L,
- 0xFA9E400DC4889995L, 0xD1823ECB45721568L,
- 0xDAFD983B8206082FL, 0xAA7D29082386A8CBL,
- 0x269FCD4403B87588L, 0x1B91F5F728BDD1E0L,
- 0xE4669F39040201F6L, 0x7A1D7C218CF04ADEL,
- 0x65623C29D79CE5CEL, 0x2368449096C00BB1L,
- 0xAB9BF1879DA503BAL, 0xBC23ECB1A458058EL,
- 0x9A58DF01BB401ECCL, 0xA070E868A85F143DL,
- 0x4FF188307DF2239EL, 0x14D565B41A641183L,
- 0xEE13337452701602L, 0x950E3DCF3F285E09L,
- 0x59930254B9C80953L, 0x3BF299408930DA6DL,
- 0xA955943F53691387L, 0xA15EDECAA9CB8784L,
- 0x29142127352BE9A0L, 0x76F0371FFF4E7AFBL,
- 0x0239F450274F2228L, 0xBB073AF01D5E868BL,
- 0xBFC80571C10E96C1L, 0xD267088568222E23L,
- 0x9671A3D48E80B5B0L, 0x55B5D38AE193BB81L,
- 0x693AE2D0A18B04B8L, 0x5C48B4ECADD5335FL,
- 0xFD743B194916A1CAL, 0x2577018134BE98C4L,
- 0xE77987E83C54A4ADL, 0x28E11014DA33E1B9L,
- 0x270CC59E226AA213L, 0x71495F756D1A5F60L,
- 0x9BE853FB60AFEF77L, 0xADC786A7F7443DBFL,
- 0x0904456173B29A82L, 0x58BC7A66C232BD5EL,
- 0xF306558C673AC8B2L, 0x41F639C6B6C9772AL,
- 0x216DEFE99FDA35DAL, 0x11640CC71C7BE615L,
- 0x93C43694565C5527L, 0xEA038E6246777839L,
- 0xF9ABF3CE5A3E2469L, 0x741E768D0FD312D2L,
- 0x0144B883CED652C6L, 0xC20B5A5BA33F8552L,
- 0x1AE69633C3435A9DL, 0x97A28CA4088CFDECL,
- 0x8824A43C1E96F420L, 0x37612FA66EEEA746L,
- 0x6B4CB165F9CF0E5AL, 0x43AA1C06A0ABFB4AL,
- 0x7F4DC26FF162796BL, 0x6CBACC8E54ED9B0FL,
- 0xA6B7FFEFD2BB253EL, 0x2E25BC95B0A29D4FL,
- 0x86D6A58BDEF1388CL, 0xDED74AC576B6F054L,
- 0x8030BDBC2B45805DL, 0x3C81AF70E94D9289L,
- 0x3EFF6DDA9E3100DBL, 0xB38DC39FDFCC8847L,
- 0x123885528D17B87EL, 0xF2DA0ED240B1B642L,
- 0x44CEFADCD54BF9A9L, 0x1312200E433C7EE6L,
- 0x9FFCC84F3A78C748L, 0xF0CD1F72248576BBL,
- 0xEC6974053638CFE4L, 0x2BA7B67C0CEC4E4CL,
- 0xAC2F4DF3E5CE32EDL, 0xCB33D14326EA4C11L,
- 0xA4E9044CC77E58BCL, 0x5F513293D934FCEFL,
- 0x5DC9645506E55444L, 0x50DE418F317DE40AL,
- 0x388CB31A69DDE259L, 0x2DB4A83455820A86L,
- 0x9010A91E84711AE9L, 0x4DF7F0B7B1498371L,
- 0xD62A2EABC0977179L, 0x22FAC097AA8D5C0EL };
+ private static final long[] T2 = {
+ 0xE6A6BE5A05A12138L, 0xB5A122A5B4F87C98L, 0x563C6089140B6990L,
+ 0x4C46CB2E391F5DD5L, 0xD932ADDBC9B79434L, 0x08EA70E42015AFF5L,
+ 0xD765A6673E478CF1L, 0xC4FB757EAB278D99L, 0xDF11C6862D6E0692L,
+ 0xDDEB84F10D7F3B16L, 0x6F2EF604A665EA04L, 0x4A8E0F0FF0E0DFB3L,
+ 0xA5EDEEF83DBCBA51L, 0xFC4F0A2A0EA4371EL, 0xE83E1DA85CB38429L,
+ 0xDC8FF882BA1B1CE2L, 0xCD45505E8353E80DL, 0x18D19A00D4DB0717L,
+ 0x34A0CFEDA5F38101L, 0x0BE77E518887CAF2L, 0x1E341438B3C45136L,
+ 0xE05797F49089CCF9L, 0xFFD23F9DF2591D14L, 0x543DDA228595C5CDL,
+ 0x661F81FD99052A33L, 0x8736E641DB0F7B76L, 0x15227725418E5307L,
+ 0xE25F7F46162EB2FAL, 0x48A8B2126C13D9FEL, 0xAFDC541792E76EEAL,
+ 0x03D912BFC6D1898FL, 0x31B1AAFA1B83F51BL, 0xF1AC2796E42AB7D9L,
+ 0x40A3A7D7FCD2EBACL, 0x1056136D0AFBBCC5L, 0x7889E1DD9A6D0C85L,
+ 0xD33525782A7974AAL, 0xA7E25D09078AC09BL, 0xBD4138B3EAC6EDD0L,
+ 0x920ABFBE71EB9E70L, 0xA2A5D0F54FC2625CL, 0xC054E36B0B1290A3L,
+ 0xF6DD59FF62FE932BL, 0x3537354511A8AC7DL, 0xCA845E9172FADCD4L,
+ 0x84F82B60329D20DCL, 0x79C62CE1CD672F18L, 0x8B09A2ADD124642CL,
+ 0xD0C1E96A19D9E726L, 0x5A786A9B4BA9500CL, 0x0E020336634C43F3L,
+ 0xC17B474AEB66D822L, 0x6A731AE3EC9BAAC2L, 0x8226667AE0840258L,
+ 0x67D4567691CAECA5L, 0x1D94155C4875ADB5L, 0x6D00FD985B813FDFL,
+ 0x51286EFCB774CD06L, 0x5E8834471FA744AFL, 0xF72CA0AEE761AE2EL,
+ 0xBE40E4CDAEE8E09AL, 0xE9970BBB5118F665L, 0x726E4BEB33DF1964L,
+ 0x703B000729199762L, 0x4631D816F5EF30A7L, 0xB880B5B51504A6BEL,
+ 0x641793C37ED84B6CL, 0x7B21ED77F6E97D96L, 0x776306312EF96B73L,
+ 0xAE528948E86FF3F4L, 0x53DBD7F286A3F8F8L, 0x16CADCE74CFC1063L,
+ 0x005C19BDFA52C6DDL, 0x68868F5D64D46AD3L, 0x3A9D512CCF1E186AL,
+ 0x367E62C2385660AEL, 0xE359E7EA77DCB1D7L, 0x526C0773749ABE6EL,
+ 0x735AE5F9D09F734BL, 0x493FC7CC8A558BA8L, 0xB0B9C1533041AB45L,
+ 0x321958BA470A59BDL, 0x852DB00B5F46C393L, 0x91209B2BD336B0E5L,
+ 0x6E604F7D659EF19FL, 0xB99A8AE2782CCB24L, 0xCCF52AB6C814C4C7L,
+ 0x4727D9AFBE11727BL, 0x7E950D0C0121B34DL, 0x756F435670AD471FL,
+ 0xF5ADD442615A6849L, 0x4E87E09980B9957AL, 0x2ACFA1DF50AEE355L,
+ 0xD898263AFD2FD556L, 0xC8F4924DD80C8FD6L, 0xCF99CA3D754A173AL,
+ 0xFE477BACAF91BF3CL, 0xED5371F6D690C12DL, 0x831A5C285E687094L,
+ 0xC5D3C90A3708A0A4L, 0x0F7F903717D06580L, 0x19F9BB13B8FDF27FL,
+ 0xB1BD6F1B4D502843L, 0x1C761BA38FFF4012L, 0x0D1530C4E2E21F3BL,
+ 0x8943CE69A7372C8AL, 0xE5184E11FEB5CE66L, 0x618BDB80BD736621L,
+ 0x7D29BAD68B574D0BL, 0x81BB613E25E6FE5BL, 0x071C9C10BC07913FL,
+ 0xC7BEEB7909AC2D97L, 0xC3E58D353BC5D757L, 0xEB017892F38F61E8L,
+ 0xD4EFFB9C9B1CC21AL, 0x99727D26F494F7ABL, 0xA3E063A2956B3E03L,
+ 0x9D4A8B9A4AA09C30L, 0x3F6AB7D500090FB4L, 0x9CC0F2A057268AC0L,
+ 0x3DEE9D2DEDBF42D1L, 0x330F49C87960A972L, 0xC6B2720287421B41L,
+ 0x0AC59EC07C00369CL, 0xEF4EAC49CB353425L, 0xF450244EEF0129D8L,
+ 0x8ACC46E5CAF4DEB6L, 0x2FFEAB63989263F7L, 0x8F7CB9FE5D7A4578L,
+ 0x5BD8F7644E634635L, 0x427A7315BF2DC900L, 0x17D0C4AA2125261CL,
+ 0x3992486C93518E50L, 0xB4CBFEE0A2D7D4C3L, 0x7C75D6202C5DDD8DL,
+ 0xDBC295D8E35B6C61L, 0x60B369D302032B19L, 0xCE42685FDCE44132L,
+ 0x06F3DDB9DDF65610L, 0x8EA4D21DB5E148F0L, 0x20B0FCE62FCD496FL,
+ 0x2C1B912358B0EE31L, 0xB28317B818F5A308L, 0xA89C1E189CA6D2CFL,
+ 0x0C6B18576AAADBC8L, 0xB65DEAA91299FAE3L, 0xFB2B794B7F1027E7L,
+ 0x04E4317F443B5BEBL, 0x4B852D325939D0A6L, 0xD5AE6BEEFB207FFCL,
+ 0x309682B281C7D374L, 0xBAE309A194C3B475L, 0x8CC3F97B13B49F05L,
+ 0x98A9422FF8293967L, 0x244B16B01076FF7CL, 0xF8BF571C663D67EEL,
+ 0x1F0D6758EEE30DA1L, 0xC9B611D97ADEB9B7L, 0xB7AFD5887B6C57A2L,
+ 0x6290AE846B984FE1L, 0x94DF4CDEACC1A5FDL, 0x058A5BD1C5483AFFL,
+ 0x63166CC142BA3C37L, 0x8DB8526EB2F76F40L, 0xE10880036F0D6D4EL,
+ 0x9E0523C9971D311DL, 0x45EC2824CC7CD691L, 0x575B8359E62382C9L,
+ 0xFA9E400DC4889995L, 0xD1823ECB45721568L, 0xDAFD983B8206082FL,
+ 0xAA7D29082386A8CBL, 0x269FCD4403B87588L, 0x1B91F5F728BDD1E0L,
+ 0xE4669F39040201F6L, 0x7A1D7C218CF04ADEL, 0x65623C29D79CE5CEL,
+ 0x2368449096C00BB1L, 0xAB9BF1879DA503BAL, 0xBC23ECB1A458058EL,
+ 0x9A58DF01BB401ECCL, 0xA070E868A85F143DL, 0x4FF188307DF2239EL,
+ 0x14D565B41A641183L, 0xEE13337452701602L, 0x950E3DCF3F285E09L,
+ 0x59930254B9C80953L, 0x3BF299408930DA6DL, 0xA955943F53691387L,
+ 0xA15EDECAA9CB8784L, 0x29142127352BE9A0L, 0x76F0371FFF4E7AFBL,
+ 0x0239F450274F2228L, 0xBB073AF01D5E868BL, 0xBFC80571C10E96C1L,
+ 0xD267088568222E23L, 0x9671A3D48E80B5B0L, 0x55B5D38AE193BB81L,
+ 0x693AE2D0A18B04B8L, 0x5C48B4ECADD5335FL, 0xFD743B194916A1CAL,
+ 0x2577018134BE98C4L, 0xE77987E83C54A4ADL, 0x28E11014DA33E1B9L,
+ 0x270CC59E226AA213L, 0x71495F756D1A5F60L, 0x9BE853FB60AFEF77L,
+ 0xADC786A7F7443DBFL, 0x0904456173B29A82L, 0x58BC7A66C232BD5EL,
+ 0xF306558C673AC8B2L, 0x41F639C6B6C9772AL, 0x216DEFE99FDA35DAL,
+ 0x11640CC71C7BE615L, 0x93C43694565C5527L, 0xEA038E6246777839L,
+ 0xF9ABF3CE5A3E2469L, 0x741E768D0FD312D2L, 0x0144B883CED652C6L,
+ 0xC20B5A5BA33F8552L, 0x1AE69633C3435A9DL, 0x97A28CA4088CFDECL,
+ 0x8824A43C1E96F420L, 0x37612FA66EEEA746L, 0x6B4CB165F9CF0E5AL,
+ 0x43AA1C06A0ABFB4AL, 0x7F4DC26FF162796BL, 0x6CBACC8E54ED9B0FL,
+ 0xA6B7FFEFD2BB253EL, 0x2E25BC95B0A29D4FL, 0x86D6A58BDEF1388CL,
+ 0xDED74AC576B6F054L, 0x8030BDBC2B45805DL, 0x3C81AF70E94D9289L,
+ 0x3EFF6DDA9E3100DBL, 0xB38DC39FDFCC8847L, 0x123885528D17B87EL,
+ 0xF2DA0ED240B1B642L, 0x44CEFADCD54BF9A9L, 0x1312200E433C7EE6L,
+ 0x9FFCC84F3A78C748L, 0xF0CD1F72248576BBL, 0xEC6974053638CFE4L,
+ 0x2BA7B67C0CEC4E4CL, 0xAC2F4DF3E5CE32EDL, 0xCB33D14326EA4C11L,
+ 0xA4E9044CC77E58BCL, 0x5F513293D934FCEFL, 0x5DC9645506E55444L,
+ 0x50DE418F317DE40AL, 0x388CB31A69DDE259L, 0x2DB4A83455820A86L,
+ 0x9010A91E84711AE9L, 0x4DF7F0B7B1498371L, 0xD62A2EABC0977179L,
+ 0x22FAC097AA8D5C0EL };
/** S-Box T3. */
- private static final long[] T3 = { 0xF49FCC2FF1DAF39BL, 0x487FD5C66FF29281L,
- 0xE8A30667FCDCA83FL, 0x2C9B4BE3D2FCCE63L,
- 0xDA3FF74B93FBBBC2L, 0x2FA165D2FE70BA66L,
- 0xA103E279970E93D4L, 0xBECDEC77B0E45E71L,
- 0xCFB41E723985E497L, 0xB70AAA025EF75017L,
- 0xD42309F03840B8E0L, 0x8EFC1AD035898579L,
- 0x96C6920BE2B2ABC5L, 0x66AF4163375A9172L,
- 0x2174ABDCCA7127FBL, 0xB33CCEA64A72FF41L,
- 0xF04A4933083066A5L, 0x8D970ACDD7289AF5L,
- 0x8F96E8E031C8C25EL, 0xF3FEC02276875D47L,
- 0xEC7BF310056190DDL, 0xF5ADB0AEBB0F1491L,
- 0x9B50F8850FD58892L, 0x4975488358B74DE8L,
- 0xA3354FF691531C61L, 0x0702BBE481D2C6EEL,
- 0x89FB24057DEDED98L, 0xAC3075138596E902L,
- 0x1D2D3580172772EDL, 0xEB738FC28E6BC30DL,
- 0x5854EF8F63044326L, 0x9E5C52325ADD3BBEL,
- 0x90AA53CF325C4623L, 0xC1D24D51349DD067L,
- 0x2051CFEEA69EA624L, 0x13220F0A862E7E4FL,
- 0xCE39399404E04864L, 0xD9C42CA47086FCB7L,
- 0x685AD2238A03E7CCL, 0x066484B2AB2FF1DBL,
- 0xFE9D5D70EFBF79ECL, 0x5B13B9DD9C481854L,
- 0x15F0D475ED1509ADL, 0x0BEBCD060EC79851L,
- 0xD58C6791183AB7F8L, 0xD1187C5052F3EEE4L,
- 0xC95D1192E54E82FFL, 0x86EEA14CB9AC6CA2L,
- 0x3485BEB153677D5DL, 0xDD191D781F8C492AL,
- 0xF60866BAA784EBF9L, 0x518F643BA2D08C74L,
- 0x8852E956E1087C22L, 0xA768CB8DC410AE8DL,
- 0x38047726BFEC8E1AL, 0xA67738B4CD3B45AAL,
- 0xAD16691CEC0DDE19L, 0xC6D4319380462E07L,
- 0xC5A5876D0BA61938L, 0x16B9FA1FA58FD840L,
- 0x188AB1173CA74F18L, 0xABDA2F98C99C021FL,
- 0x3E0580AB134AE816L, 0x5F3B05B773645ABBL,
- 0x2501A2BE5575F2F6L, 0x1B2F74004E7E8BA9L,
- 0x1CD7580371E8D953L, 0x7F6ED89562764E30L,
- 0xB15926FF596F003DL, 0x9F65293DA8C5D6B9L,
- 0x6ECEF04DD690F84CL, 0x4782275FFF33AF88L,
- 0xE41433083F820801L, 0xFD0DFE409A1AF9B5L,
- 0x4325A3342CDB396BL, 0x8AE77E62B301B252L,
- 0xC36F9E9F6655615AL, 0x85455A2D92D32C09L,
- 0xF2C7DEA949477485L, 0x63CFB4C133A39EBAL,
- 0x83B040CC6EBC5462L, 0x3B9454C8FDB326B0L,
- 0x56F56A9E87FFD78CL, 0x2DC2940D99F42BC6L,
- 0x98F7DF096B096E2DL, 0x19A6E01E3AD852BFL,
- 0x42A99CCBDBD4B40BL, 0xA59998AF45E9C559L,
- 0x366295E807D93186L, 0x6B48181BFAA1F773L,
- 0x1FEC57E2157A0A1DL, 0x4667446AF6201AD5L,
- 0xE615EBCACFB0F075L, 0xB8F31F4F68290778L,
- 0x22713ED6CE22D11EL, 0x3057C1A72EC3C93BL,
- 0xCB46ACC37C3F1F2FL, 0xDBB893FD02AAF50EL,
- 0x331FD92E600B9FCFL, 0xA498F96148EA3AD6L,
- 0xA8D8426E8B6A83EAL, 0xA089B274B7735CDCL,
- 0x87F6B3731E524A11L, 0x118808E5CBC96749L,
- 0x9906E4C7B19BD394L, 0xAFED7F7E9B24A20CL,
- 0x6509EADEEB3644A7L, 0x6C1EF1D3E8EF0EDEL,
- 0xB9C97D43E9798FB4L, 0xA2F2D784740C28A3L,
- 0x7B8496476197566FL, 0x7A5BE3E6B65F069DL,
- 0xF96330ED78BE6F10L, 0xEEE60DE77A076A15L,
- 0x2B4BEE4AA08B9BD0L, 0x6A56A63EC7B8894EL,
- 0x02121359BA34FEF4L, 0x4CBF99F8283703FCL,
- 0x398071350CAF30C8L, 0xD0A77A89F017687AL,
- 0xF1C1A9EB9E423569L, 0x8C7976282DEE8199L,
- 0x5D1737A5DD1F7ABDL, 0x4F53433C09A9FA80L,
- 0xFA8B0C53DF7CA1D9L, 0x3FD9DCBC886CCB77L,
- 0xC040917CA91B4720L, 0x7DD00142F9D1DCDFL,
- 0x8476FC1D4F387B58L, 0x23F8E7C5F3316503L,
- 0x032A2244E7E37339L, 0x5C87A5D750F5A74BL,
- 0x082B4CC43698992EL, 0xDF917BECB858F63CL,
- 0x3270B8FC5BF86DDAL, 0x10AE72BB29B5DD76L,
- 0x576AC94E7700362BL, 0x1AD112DAC61EFB8FL,
- 0x691BC30EC5FAA427L, 0xFF246311CC327143L,
- 0x3142368E30E53206L, 0x71380E31E02CA396L,
- 0x958D5C960AAD76F1L, 0xF8D6F430C16DA536L,
- 0xC8FFD13F1BE7E1D2L, 0x7578AE66004DDBE1L,
- 0x05833F01067BE646L, 0xBB34B5AD3BFE586DL,
- 0x095F34C9A12B97F0L, 0x247AB64525D60CA8L,
- 0xDCDBC6F3017477D1L, 0x4A2E14D4DECAD24DL,
- 0xBDB5E6D9BE0A1EEBL, 0x2A7E70F7794301ABL,
- 0xDEF42D8A270540FDL, 0x01078EC0A34C22C1L,
- 0xE5DE511AF4C16387L, 0x7EBB3A52BD9A330AL,
- 0x77697857AA7D6435L, 0x004E831603AE4C32L,
- 0xE7A21020AD78E312L, 0x9D41A70C6AB420F2L,
- 0x28E06C18EA1141E6L, 0xD2B28CBD984F6B28L,
- 0x26B75F6C446E9D83L, 0xBA47568C4D418D7FL,
- 0xD80BADBFE6183D8EL, 0x0E206D7F5F166044L,
- 0xE258A43911CBCA3EL, 0x723A1746B21DC0BCL,
- 0xC7CAA854F5D7CDD3L, 0x7CAC32883D261D9CL,
- 0x7690C26423BA942CL, 0x17E55524478042B8L,
- 0xE0BE477656A2389FL, 0x4D289B5E67AB2DA0L,
- 0x44862B9C8FBBFD31L, 0xB47CC8049D141365L,
- 0x822C1B362B91C793L, 0x4EB14655FB13DFD8L,
- 0x1ECBBA0714E2A97BL, 0x6143459D5CDE5F14L,
- 0x53A8FBF1D5F0AC89L, 0x97EA04D81C5E5B00L,
- 0x622181A8D4FDB3F3L, 0xE9BCD341572A1208L,
- 0x1411258643CCE58AL, 0x9144C5FEA4C6E0A4L,
- 0x0D33D06565CF620FL, 0x54A48D489F219CA1L,
- 0xC43E5EAC6D63C821L, 0xA9728B3A72770DAFL,
- 0xD7934E7B20DF87EFL, 0xE35503B61A3E86E5L,
- 0xCAE321FBC819D504L, 0x129A50B3AC60BFA6L,
- 0xCD5E68EA7E9FB6C3L, 0xB01C90199483B1C7L,
- 0x3DE93CD5C295376CL, 0xAED52EDF2AB9AD13L,
- 0x2E60F512C0A07884L, 0xBC3D86A3E36210C9L,
- 0x35269D9B163951CEL, 0x0C7D6E2AD0CDB5FAL,
- 0x59E86297D87F5733L, 0x298EF221898DB0E7L,
- 0x55000029D1A5AA7EL, 0x8BC08AE1B5061B45L,
- 0xC2C31C2B6C92703AL, 0x94CC596BAF25EF42L,
- 0x0A1D73DB22540456L, 0x04B6A0F9D9C4179AL,
- 0xEFFDAFA2AE3D3C60L, 0xF7C8075BB49496C4L,
- 0x9CC5C7141D1CD4E3L, 0x78BD1638218E5534L,
- 0xB2F11568F850246AL, 0xEDFABCFA9502BC29L,
- 0x796CE5F2DA23051BL, 0xAAE128B0DC93537CL,
- 0x3A493DA0EE4B29AEL, 0xB5DF6B2C416895D7L,
- 0xFCABBD25122D7F37L, 0x70810B58105DC4B1L,
- 0xE10FDD37F7882A90L, 0x524DCAB5518A3F5CL,
- 0x3C9E85878451255BL, 0x4029828119BD34E2L,
- 0x74A05B6F5D3CECCBL, 0xB610021542E13ECAL,
- 0x0FF979D12F59E2ACL, 0x6037DA27E4F9CC50L,
- 0x5E92975A0DF1847DL, 0xD66DE190D3E623FEL,
- 0x5032D6B87B568048L, 0x9A36B7CE8235216EL,
- 0x80272A7A24F64B4AL, 0x93EFED8B8C6916F7L,
- 0x37DDBFF44CCE1555L, 0x4B95DB5D4B99BD25L,
- 0x92D3FDA169812FC0L, 0xFB1A4A9A90660BB6L,
- 0x730C196946A4B9B2L, 0x81E289AA7F49DA68L,
- 0x64669A0F83B1A05FL, 0x27B3FF7D9644F48BL,
- 0xCC6B615C8DB675B3L, 0x674F20B9BCEBBE95L,
- 0x6F31238275655982L, 0x5AE488713E45CF05L,
- 0xBF619F9954C21157L, 0xEABAC46040A8EAE9L,
- 0x454C6FE9F2C0C1CDL, 0x419CF6496412691CL,
- 0xD3DC3BEF265B0F70L, 0x6D0E60F5C3578A9EL };
+ private static final long[] T3 = {
+ 0xF49FCC2FF1DAF39BL, 0x487FD5C66FF29281L, 0xE8A30667FCDCA83FL,
+ 0x2C9B4BE3D2FCCE63L, 0xDA3FF74B93FBBBC2L, 0x2FA165D2FE70BA66L,
+ 0xA103E279970E93D4L, 0xBECDEC77B0E45E71L, 0xCFB41E723985E497L,
+ 0xB70AAA025EF75017L, 0xD42309F03840B8E0L, 0x8EFC1AD035898579L,
+ 0x96C6920BE2B2ABC5L, 0x66AF4163375A9172L, 0x2174ABDCCA7127FBL,
+ 0xB33CCEA64A72FF41L, 0xF04A4933083066A5L, 0x8D970ACDD7289AF5L,
+ 0x8F96E8E031C8C25EL, 0xF3FEC02276875D47L, 0xEC7BF310056190DDL,
+ 0xF5ADB0AEBB0F1491L, 0x9B50F8850FD58892L, 0x4975488358B74DE8L,
+ 0xA3354FF691531C61L, 0x0702BBE481D2C6EEL, 0x89FB24057DEDED98L,
+ 0xAC3075138596E902L, 0x1D2D3580172772EDL, 0xEB738FC28E6BC30DL,
+ 0x5854EF8F63044326L, 0x9E5C52325ADD3BBEL, 0x90AA53CF325C4623L,
+ 0xC1D24D51349DD067L, 0x2051CFEEA69EA624L, 0x13220F0A862E7E4FL,
+ 0xCE39399404E04864L, 0xD9C42CA47086FCB7L, 0x685AD2238A03E7CCL,
+ 0x066484B2AB2FF1DBL, 0xFE9D5D70EFBF79ECL, 0x5B13B9DD9C481854L,
+ 0x15F0D475ED1509ADL, 0x0BEBCD060EC79851L, 0xD58C6791183AB7F8L,
+ 0xD1187C5052F3EEE4L, 0xC95D1192E54E82FFL, 0x86EEA14CB9AC6CA2L,
+ 0x3485BEB153677D5DL, 0xDD191D781F8C492AL, 0xF60866BAA784EBF9L,
+ 0x518F643BA2D08C74L, 0x8852E956E1087C22L, 0xA768CB8DC410AE8DL,
+ 0x38047726BFEC8E1AL, 0xA67738B4CD3B45AAL, 0xAD16691CEC0DDE19L,
+ 0xC6D4319380462E07L, 0xC5A5876D0BA61938L, 0x16B9FA1FA58FD840L,
+ 0x188AB1173CA74F18L, 0xABDA2F98C99C021FL, 0x3E0580AB134AE816L,
+ 0x5F3B05B773645ABBL, 0x2501A2BE5575F2F6L, 0x1B2F74004E7E8BA9L,
+ 0x1CD7580371E8D953L, 0x7F6ED89562764E30L, 0xB15926FF596F003DL,
+ 0x9F65293DA8C5D6B9L, 0x6ECEF04DD690F84CL, 0x4782275FFF33AF88L,
+ 0xE41433083F820801L, 0xFD0DFE409A1AF9B5L, 0x4325A3342CDB396BL,
+ 0x8AE77E62B301B252L, 0xC36F9E9F6655615AL, 0x85455A2D92D32C09L,
+ 0xF2C7DEA949477485L, 0x63CFB4C133A39EBAL, 0x83B040CC6EBC5462L,
+ 0x3B9454C8FDB326B0L, 0x56F56A9E87FFD78CL, 0x2DC2940D99F42BC6L,
+ 0x98F7DF096B096E2DL, 0x19A6E01E3AD852BFL, 0x42A99CCBDBD4B40BL,
+ 0xA59998AF45E9C559L, 0x366295E807D93186L, 0x6B48181BFAA1F773L,
+ 0x1FEC57E2157A0A1DL, 0x4667446AF6201AD5L, 0xE615EBCACFB0F075L,
+ 0xB8F31F4F68290778L, 0x22713ED6CE22D11EL, 0x3057C1A72EC3C93BL,
+ 0xCB46ACC37C3F1F2FL, 0xDBB893FD02AAF50EL, 0x331FD92E600B9FCFL,
+ 0xA498F96148EA3AD6L, 0xA8D8426E8B6A83EAL, 0xA089B274B7735CDCL,
+ 0x87F6B3731E524A11L, 0x118808E5CBC96749L, 0x9906E4C7B19BD394L,
+ 0xAFED7F7E9B24A20CL, 0x6509EADEEB3644A7L, 0x6C1EF1D3E8EF0EDEL,
+ 0xB9C97D43E9798FB4L, 0xA2F2D784740C28A3L, 0x7B8496476197566FL,
+ 0x7A5BE3E6B65F069DL, 0xF96330ED78BE6F10L, 0xEEE60DE77A076A15L,
+ 0x2B4BEE4AA08B9BD0L, 0x6A56A63EC7B8894EL, 0x02121359BA34FEF4L,
+ 0x4CBF99F8283703FCL, 0x398071350CAF30C8L, 0xD0A77A89F017687AL,
+ 0xF1C1A9EB9E423569L, 0x8C7976282DEE8199L, 0x5D1737A5DD1F7ABDL,
+ 0x4F53433C09A9FA80L, 0xFA8B0C53DF7CA1D9L, 0x3FD9DCBC886CCB77L,
+ 0xC040917CA91B4720L, 0x7DD00142F9D1DCDFL, 0x8476FC1D4F387B58L,
+ 0x23F8E7C5F3316503L, 0x032A2244E7E37339L, 0x5C87A5D750F5A74BL,
+ 0x082B4CC43698992EL, 0xDF917BECB858F63CL, 0x3270B8FC5BF86DDAL,
+ 0x10AE72BB29B5DD76L, 0x576AC94E7700362BL, 0x1AD112DAC61EFB8FL,
+ 0x691BC30EC5FAA427L, 0xFF246311CC327143L, 0x3142368E30E53206L,
+ 0x71380E31E02CA396L, 0x958D5C960AAD76F1L, 0xF8D6F430C16DA536L,
+ 0xC8FFD13F1BE7E1D2L, 0x7578AE66004DDBE1L, 0x05833F01067BE646L,
+ 0xBB34B5AD3BFE586DL, 0x095F34C9A12B97F0L, 0x247AB64525D60CA8L,
+ 0xDCDBC6F3017477D1L, 0x4A2E14D4DECAD24DL, 0xBDB5E6D9BE0A1EEBL,
+ 0x2A7E70F7794301ABL, 0xDEF42D8A270540FDL, 0x01078EC0A34C22C1L,
+ 0xE5DE511AF4C16387L, 0x7EBB3A52BD9A330AL, 0x77697857AA7D6435L,
+ 0x004E831603AE4C32L, 0xE7A21020AD78E312L, 0x9D41A70C6AB420F2L,
+ 0x28E06C18EA1141E6L, 0xD2B28CBD984F6B28L, 0x26B75F6C446E9D83L,
+ 0xBA47568C4D418D7FL, 0xD80BADBFE6183D8EL, 0x0E206D7F5F166044L,
+ 0xE258A43911CBCA3EL, 0x723A1746B21DC0BCL, 0xC7CAA854F5D7CDD3L,
+ 0x7CAC32883D261D9CL, 0x7690C26423BA942CL, 0x17E55524478042B8L,
+ 0xE0BE477656A2389FL, 0x4D289B5E67AB2DA0L, 0x44862B9C8FBBFD31L,
+ 0xB47CC8049D141365L, 0x822C1B362B91C793L, 0x4EB14655FB13DFD8L,
+ 0x1ECBBA0714E2A97BL, 0x6143459D5CDE5F14L, 0x53A8FBF1D5F0AC89L,
+ 0x97EA04D81C5E5B00L, 0x622181A8D4FDB3F3L, 0xE9BCD341572A1208L,
+ 0x1411258643CCE58AL, 0x9144C5FEA4C6E0A4L, 0x0D33D06565CF620FL,
+ 0x54A48D489F219CA1L, 0xC43E5EAC6D63C821L, 0xA9728B3A72770DAFL,
+ 0xD7934E7B20DF87EFL, 0xE35503B61A3E86E5L, 0xCAE321FBC819D504L,
+ 0x129A50B3AC60BFA6L, 0xCD5E68EA7E9FB6C3L, 0xB01C90199483B1C7L,
+ 0x3DE93CD5C295376CL, 0xAED52EDF2AB9AD13L, 0x2E60F512C0A07884L,
+ 0xBC3D86A3E36210C9L, 0x35269D9B163951CEL, 0x0C7D6E2AD0CDB5FAL,
+ 0x59E86297D87F5733L, 0x298EF221898DB0E7L, 0x55000029D1A5AA7EL,
+ 0x8BC08AE1B5061B45L, 0xC2C31C2B6C92703AL, 0x94CC596BAF25EF42L,
+ 0x0A1D73DB22540456L, 0x04B6A0F9D9C4179AL, 0xEFFDAFA2AE3D3C60L,
+ 0xF7C8075BB49496C4L, 0x9CC5C7141D1CD4E3L, 0x78BD1638218E5534L,
+ 0xB2F11568F850246AL, 0xEDFABCFA9502BC29L, 0x796CE5F2DA23051BL,
+ 0xAAE128B0DC93537CL, 0x3A493DA0EE4B29AEL, 0xB5DF6B2C416895D7L,
+ 0xFCABBD25122D7F37L, 0x70810B58105DC4B1L, 0xE10FDD37F7882A90L,
+ 0x524DCAB5518A3F5CL, 0x3C9E85878451255BL, 0x4029828119BD34E2L,
+ 0x74A05B6F5D3CECCBL, 0xB610021542E13ECAL, 0x0FF979D12F59E2ACL,
+ 0x6037DA27E4F9CC50L, 0x5E92975A0DF1847DL, 0xD66DE190D3E623FEL,
+ 0x5032D6B87B568048L, 0x9A36B7CE8235216EL, 0x80272A7A24F64B4AL,
+ 0x93EFED8B8C6916F7L, 0x37DDBFF44CCE1555L, 0x4B95DB5D4B99BD25L,
+ 0x92D3FDA169812FC0L, 0xFB1A4A9A90660BB6L, 0x730C196946A4B9B2L,
+ 0x81E289AA7F49DA68L, 0x64669A0F83B1A05FL, 0x27B3FF7D9644F48BL,
+ 0xCC6B615C8DB675B3L, 0x674F20B9BCEBBE95L, 0x6F31238275655982L,
+ 0x5AE488713E45CF05L, 0xBF619F9954C21157L, 0xEABAC46040A8EAE9L,
+ 0x454C6FE9F2C0C1CDL, 0x419CF6496412691CL, 0xD3DC3BEF265B0F70L,
+ 0x6D0E60F5C3578A9EL };
/** S-Box T4. */
- private static final long[] T4 = { 0x5B0E608526323C55L, 0x1A46C1A9FA1B59F5L,
- 0xA9E245A17C4C8FFAL, 0x65CA5159DB2955D7L,
- 0x05DB0A76CE35AFC2L, 0x81EAC77EA9113D45L,
- 0x528EF88AB6AC0A0DL, 0xA09EA253597BE3FFL,
- 0x430DDFB3AC48CD56L, 0xC4B3A67AF45CE46FL,
- 0x4ECECFD8FBE2D05EL, 0x3EF56F10B39935F0L,
- 0x0B22D6829CD619C6L, 0x17FD460A74DF2069L,
- 0x6CF8CC8E8510ED40L, 0xD6C824BF3A6ECAA7L,
- 0x61243D581A817049L, 0x048BACB6BBC163A2L,
- 0xD9A38AC27D44CC32L, 0x7FDDFF5BAAF410ABL,
- 0xAD6D495AA804824BL, 0xE1A6A74F2D8C9F94L,
- 0xD4F7851235DEE8E3L, 0xFD4B7F886540D893L,
- 0x247C20042AA4BFDAL, 0x096EA1C517D1327CL,
- 0xD56966B4361A6685L, 0x277DA5C31221057DL,
- 0x94D59893A43ACFF7L, 0x64F0C51CCDC02281L,
- 0x3D33BCC4FF6189DBL, 0xE005CB184CE66AF1L,
- 0xFF5CCD1D1DB99BEAL, 0xB0B854A7FE42980FL,
- 0x7BD46A6A718D4B9FL, 0xD10FA8CC22A5FD8CL,
- 0xD31484952BE4BD31L, 0xC7FA975FCB243847L,
- 0x4886ED1E5846C407L, 0x28CDDB791EB70B04L,
- 0xC2B00BE2F573417FL, 0x5C9590452180F877L,
- 0x7A6BDDFFF370EB00L, 0xCE509E38D6D9D6A4L,
- 0xEBEB0F00647FA702L, 0x1DCC06CF76606F06L,
- 0xE4D9F28BA286FF0AL, 0xD85A305DC918C262L,
- 0x475B1D8732225F54L, 0x2D4FB51668CCB5FEL,
- 0xA679B9D9D72BBA20L, 0x53841C0D912D43A5L,
- 0x3B7EAA48BF12A4E8L, 0x781E0E47F22F1DDFL,
- 0xEFF20CE60AB50973L, 0x20D261D19DFFB742L,
- 0x16A12B03062A2E39L, 0x1960EB2239650495L,
- 0x251C16FED50EB8B8L, 0x9AC0C330F826016EL,
- 0xED152665953E7671L, 0x02D63194A6369570L,
- 0x5074F08394B1C987L, 0x70BA598C90B25CE1L,
- 0x794A15810B9742F6L, 0x0D5925E9FCAF8C6CL,
- 0x3067716CD868744EL, 0x910AB077E8D7731BL,
- 0x6A61BBDB5AC42F61L, 0x93513EFBF0851567L,
- 0xF494724B9E83E9D5L, 0xE887E1985C09648DL,
- 0x34B1D3C675370CFDL, 0xDC35E433BC0D255DL,
- 0xD0AAB84234131BE0L, 0x08042A50B48B7EAFL,
- 0x9997C4EE44A3AB35L, 0x829A7B49201799D0L,
- 0x263B8307B7C54441L, 0x752F95F4FD6A6CA6L,
- 0x927217402C08C6E5L, 0x2A8AB754A795D9EEL,
- 0xA442F7552F72943DL, 0x2C31334E19781208L,
- 0x4FA98D7CEAEE6291L, 0x55C3862F665DB309L,
- 0xBD0610175D53B1F3L, 0x46FE6CB840413F27L,
- 0x3FE03792DF0CFA59L, 0xCFE700372EB85E8FL,
- 0xA7BE29E7ADBCE118L, 0xE544EE5CDE8431DDL,
- 0x8A781B1B41F1873EL, 0xA5C94C78A0D2F0E7L,
- 0x39412E2877B60728L, 0xA1265EF3AFC9A62CL,
- 0xBCC2770C6A2506C5L, 0x3AB66DD5DCE1CE12L,
- 0xE65499D04A675B37L, 0x7D8F523481BFD216L,
- 0x0F6F64FCEC15F389L, 0x74EFBE618B5B13C8L,
- 0xACDC82B714273E1DL, 0xDD40BFE003199D17L,
- 0x37E99257E7E061F8L, 0xFA52626904775AAAL,
- 0x8BBBF63A463D56F9L, 0xF0013F1543A26E64L,
- 0xA8307E9F879EC898L, 0xCC4C27A4150177CCL,
- 0x1B432F2CCA1D3348L, 0xDE1D1F8F9F6FA013L,
- 0x606602A047A7DDD6L, 0xD237AB64CC1CB2C7L,
- 0x9B938E7225FCD1D3L, 0xEC4E03708E0FF476L,
- 0xFEB2FBDA3D03C12DL, 0xAE0BCED2EE43889AL,
- 0x22CB8923EBFB4F43L, 0x69360D013CF7396DL,
- 0x855E3602D2D4E022L, 0x073805BAD01F784CL,
- 0x33E17A133852F546L, 0xDF4874058AC7B638L,
- 0xBA92B29C678AA14AL, 0x0CE89FC76CFAADCDL,
- 0x5F9D4E0908339E34L, 0xF1AFE9291F5923B9L,
- 0x6E3480F60F4A265FL, 0xEEBF3A2AB29B841CL,
- 0xE21938A88F91B4ADL, 0x57DFEFF845C6D3C3L,
- 0x2F006B0BF62CAAF2L, 0x62F479EF6F75EE78L,
- 0x11A55AD41C8916A9L, 0xF229D29084FED453L,
- 0x42F1C27B16B000E6L, 0x2B1F76749823C074L,
- 0x4B76ECA3C2745360L, 0x8C98F463B91691BDL,
- 0x14BCC93CF1ADE66AL, 0x8885213E6D458397L,
- 0x8E177DF0274D4711L, 0xB49B73B5503F2951L,
- 0x10168168C3F96B6BL, 0x0E3D963B63CAB0AEL,
- 0x8DFC4B5655A1DB14L, 0xF789F1356E14DE5CL,
- 0x683E68AF4E51DAC1L, 0xC9A84F9D8D4B0FD9L,
- 0x3691E03F52A0F9D1L, 0x5ED86E46E1878E80L,
- 0x3C711A0E99D07150L, 0x5A0865B20C4E9310L,
- 0x56FBFC1FE4F0682EL, 0xEA8D5DE3105EDF9BL,
- 0x71ABFDB12379187AL, 0x2EB99DE1BEE77B9CL,
- 0x21ECC0EA33CF4523L, 0x59A4D7521805C7A1L,
- 0x3896F5EB56AE7C72L, 0xAA638F3DB18F75DCL,
- 0x9F39358DABE9808EL, 0xB7DEFA91C00B72ACL,
- 0x6B5541FD62492D92L, 0x6DC6DEE8F92E4D5BL,
- 0x353F57ABC4BEEA7EL, 0x735769D6DA5690CEL,
- 0x0A234AA642391484L, 0xF6F9508028F80D9DL,
- 0xB8E319A27AB3F215L, 0x31AD9C1151341A4DL,
- 0x773C22A57BEF5805L, 0x45C7561A07968633L,
- 0xF913DA9E249DBE36L, 0xDA652D9B78A64C68L,
- 0x4C27A97F3BC334EFL, 0x76621220E66B17F4L,
- 0x967743899ACD7D0BL, 0xF3EE5BCAE0ED6782L,
- 0x409F753600C879FCL, 0x06D09A39B5926DB6L,
- 0x6F83AEB0317AC588L, 0x01E6CA4A86381F21L,
- 0x66FF3462D19F3025L, 0x72207C24DDFD3BFBL,
- 0x4AF6B6D3E2ECE2EBL, 0x9C994DBEC7EA08DEL,
- 0x49ACE597B09A8BC4L, 0xB38C4766CF0797BAL,
- 0x131B9373C57C2A75L, 0xB1822CCE61931E58L,
- 0x9D7555B909BA1C0CL, 0x127FAFDD937D11D2L,
- 0x29DA3BADC66D92E4L, 0xA2C1D57154C2ECBCL,
- 0x58C5134D82F6FE24L, 0x1C3AE3515B62274FL,
- 0xE907C82E01CB8126L, 0xF8ED091913E37FCBL,
- 0x3249D8F9C80046C9L, 0x80CF9BEDE388FB63L,
- 0x1881539A116CF19EL, 0x5103F3F76BD52457L,
- 0x15B7E6F5AE47F7A8L, 0xDBD7C6DED47E9CCFL,
- 0x44E55C410228BB1AL, 0xB647D4255EDB4E99L,
- 0x5D11882BB8AAFC30L, 0xF5098BBB29D3212AL,
- 0x8FB5EA14E90296B3L, 0x677B942157DD025AL,
- 0xFB58E7C0A390ACB5L, 0x89D3674C83BD4A01L,
- 0x9E2DA4DF4BF3B93BL, 0xFCC41E328CAB4829L,
- 0x03F38C96BA582C52L, 0xCAD1BDBD7FD85DB2L,
- 0xBBB442C16082AE83L, 0xB95FE86BA5DA9AB0L,
- 0xB22E04673771A93FL, 0x845358C9493152D8L,
- 0xBE2A488697B4541EL, 0x95A2DC2DD38E6966L,
- 0xC02C11AC923C852BL, 0x2388B1990DF2A87BL,
- 0x7C8008FA1B4F37BEL, 0x1F70D0C84D54E503L,
- 0x5490ADEC7ECE57D4L, 0x002B3C27D9063A3AL,
- 0x7EAEA3848030A2BFL, 0xC602326DED2003C0L,
- 0x83A7287D69A94086L, 0xC57A5FCB30F57A8AL,
- 0xB56844E479EBE779L, 0xA373B40F05DCBCE9L,
- 0xD71A786E88570EE2L, 0x879CBACDBDE8F6A0L,
- 0x976AD1BCC164A32FL, 0xAB21E25E9666D78BL,
- 0x901063AAE5E5C33CL, 0x9818B34448698D90L,
- 0xE36487AE3E1E8ABBL, 0xAFBDF931893BDCB4L,
- 0x6345A0DC5FBBD519L, 0x8628FE269B9465CAL,
- 0x1E5D01603F9C51ECL, 0x4DE44006A15049B7L,
- 0xBF6C70E5F776CBB1L, 0x411218F2EF552BEDL,
- 0xCB0C0708705A36A3L, 0xE74D14754F986044L,
- 0xCD56D9430EA8280EL, 0xC12591D7535F5065L,
- 0xC83223F1720AEF96L, 0xC3A0396F7363A51FL };
+ private static final long[] T4 = {
+ 0x5B0E608526323C55L, 0x1A46C1A9FA1B59F5L, 0xA9E245A17C4C8FFAL,
+ 0x65CA5159DB2955D7L, 0x05DB0A76CE35AFC2L, 0x81EAC77EA9113D45L,
+ 0x528EF88AB6AC0A0DL, 0xA09EA253597BE3FFL, 0x430DDFB3AC48CD56L,
+ 0xC4B3A67AF45CE46FL, 0x4ECECFD8FBE2D05EL, 0x3EF56F10B39935F0L,
+ 0x0B22D6829CD619C6L, 0x17FD460A74DF2069L, 0x6CF8CC8E8510ED40L,
+ 0xD6C824BF3A6ECAA7L, 0x61243D581A817049L, 0x048BACB6BBC163A2L,
+ 0xD9A38AC27D44CC32L, 0x7FDDFF5BAAF410ABL, 0xAD6D495AA804824BL,
+ 0xE1A6A74F2D8C9F94L, 0xD4F7851235DEE8E3L, 0xFD4B7F886540D893L,
+ 0x247C20042AA4BFDAL, 0x096EA1C517D1327CL, 0xD56966B4361A6685L,
+ 0x277DA5C31221057DL, 0x94D59893A43ACFF7L, 0x64F0C51CCDC02281L,
+ 0x3D33BCC4FF6189DBL, 0xE005CB184CE66AF1L, 0xFF5CCD1D1DB99BEAL,
+ 0xB0B854A7FE42980FL, 0x7BD46A6A718D4B9FL, 0xD10FA8CC22A5FD8CL,
+ 0xD31484952BE4BD31L, 0xC7FA975FCB243847L, 0x4886ED1E5846C407L,
+ 0x28CDDB791EB70B04L, 0xC2B00BE2F573417FL, 0x5C9590452180F877L,
+ 0x7A6BDDFFF370EB00L, 0xCE509E38D6D9D6A4L, 0xEBEB0F00647FA702L,
+ 0x1DCC06CF76606F06L, 0xE4D9F28BA286FF0AL, 0xD85A305DC918C262L,
+ 0x475B1D8732225F54L, 0x2D4FB51668CCB5FEL, 0xA679B9D9D72BBA20L,
+ 0x53841C0D912D43A5L, 0x3B7EAA48BF12A4E8L, 0x781E0E47F22F1DDFL,
+ 0xEFF20CE60AB50973L, 0x20D261D19DFFB742L, 0x16A12B03062A2E39L,
+ 0x1960EB2239650495L, 0x251C16FED50EB8B8L, 0x9AC0C330F826016EL,
+ 0xED152665953E7671L, 0x02D63194A6369570L, 0x5074F08394B1C987L,
+ 0x70BA598C90B25CE1L, 0x794A15810B9742F6L, 0x0D5925E9FCAF8C6CL,
+ 0x3067716CD868744EL, 0x910AB077E8D7731BL, 0x6A61BBDB5AC42F61L,
+ 0x93513EFBF0851567L, 0xF494724B9E83E9D5L, 0xE887E1985C09648DL,
+ 0x34B1D3C675370CFDL, 0xDC35E433BC0D255DL, 0xD0AAB84234131BE0L,
+ 0x08042A50B48B7EAFL, 0x9997C4EE44A3AB35L, 0x829A7B49201799D0L,
+ 0x263B8307B7C54441L, 0x752F95F4FD6A6CA6L, 0x927217402C08C6E5L,
+ 0x2A8AB754A795D9EEL, 0xA442F7552F72943DL, 0x2C31334E19781208L,
+ 0x4FA98D7CEAEE6291L, 0x55C3862F665DB309L, 0xBD0610175D53B1F3L,
+ 0x46FE6CB840413F27L, 0x3FE03792DF0CFA59L, 0xCFE700372EB85E8FL,
+ 0xA7BE29E7ADBCE118L, 0xE544EE5CDE8431DDL, 0x8A781B1B41F1873EL,
+ 0xA5C94C78A0D2F0E7L, 0x39412E2877B60728L, 0xA1265EF3AFC9A62CL,
+ 0xBCC2770C6A2506C5L, 0x3AB66DD5DCE1CE12L, 0xE65499D04A675B37L,
+ 0x7D8F523481BFD216L, 0x0F6F64FCEC15F389L, 0x74EFBE618B5B13C8L,
+ 0xACDC82B714273E1DL, 0xDD40BFE003199D17L, 0x37E99257E7E061F8L,
+ 0xFA52626904775AAAL, 0x8BBBF63A463D56F9L, 0xF0013F1543A26E64L,
+ 0xA8307E9F879EC898L, 0xCC4C27A4150177CCL, 0x1B432F2CCA1D3348L,
+ 0xDE1D1F8F9F6FA013L, 0x606602A047A7DDD6L, 0xD237AB64CC1CB2C7L,
+ 0x9B938E7225FCD1D3L, 0xEC4E03708E0FF476L, 0xFEB2FBDA3D03C12DL,
+ 0xAE0BCED2EE43889AL, 0x22CB8923EBFB4F43L, 0x69360D013CF7396DL,
+ 0x855E3602D2D4E022L, 0x073805BAD01F784CL, 0x33E17A133852F546L,
+ 0xDF4874058AC7B638L, 0xBA92B29C678AA14AL, 0x0CE89FC76CFAADCDL,
+ 0x5F9D4E0908339E34L, 0xF1AFE9291F5923B9L, 0x6E3480F60F4A265FL,
+ 0xEEBF3A2AB29B841CL, 0xE21938A88F91B4ADL, 0x57DFEFF845C6D3C3L,
+ 0x2F006B0BF62CAAF2L, 0x62F479EF6F75EE78L, 0x11A55AD41C8916A9L,
+ 0xF229D29084FED453L, 0x42F1C27B16B000E6L, 0x2B1F76749823C074L,
+ 0x4B76ECA3C2745360L, 0x8C98F463B91691BDL, 0x14BCC93CF1ADE66AL,
+ 0x8885213E6D458397L, 0x8E177DF0274D4711L, 0xB49B73B5503F2951L,
+ 0x10168168C3F96B6BL, 0x0E3D963B63CAB0AEL, 0x8DFC4B5655A1DB14L,
+ 0xF789F1356E14DE5CL, 0x683E68AF4E51DAC1L, 0xC9A84F9D8D4B0FD9L,
+ 0x3691E03F52A0F9D1L, 0x5ED86E46E1878E80L, 0x3C711A0E99D07150L,
+ 0x5A0865B20C4E9310L, 0x56FBFC1FE4F0682EL, 0xEA8D5DE3105EDF9BL,
+ 0x71ABFDB12379187AL, 0x2EB99DE1BEE77B9CL, 0x21ECC0EA33CF4523L,
+ 0x59A4D7521805C7A1L, 0x3896F5EB56AE7C72L, 0xAA638F3DB18F75DCL,
+ 0x9F39358DABE9808EL, 0xB7DEFA91C00B72ACL, 0x6B5541FD62492D92L,
+ 0x6DC6DEE8F92E4D5BL, 0x353F57ABC4BEEA7EL, 0x735769D6DA5690CEL,
+ 0x0A234AA642391484L, 0xF6F9508028F80D9DL, 0xB8E319A27AB3F215L,
+ 0x31AD9C1151341A4DL, 0x773C22A57BEF5805L, 0x45C7561A07968633L,
+ 0xF913DA9E249DBE36L, 0xDA652D9B78A64C68L, 0x4C27A97F3BC334EFL,
+ 0x76621220E66B17F4L, 0x967743899ACD7D0BL, 0xF3EE5BCAE0ED6782L,
+ 0x409F753600C879FCL, 0x06D09A39B5926DB6L, 0x6F83AEB0317AC588L,
+ 0x01E6CA4A86381F21L, 0x66FF3462D19F3025L, 0x72207C24DDFD3BFBL,
+ 0x4AF6B6D3E2ECE2EBL, 0x9C994DBEC7EA08DEL, 0x49ACE597B09A8BC4L,
+ 0xB38C4766CF0797BAL, 0x131B9373C57C2A75L, 0xB1822CCE61931E58L,
+ 0x9D7555B909BA1C0CL, 0x127FAFDD937D11D2L, 0x29DA3BADC66D92E4L,
+ 0xA2C1D57154C2ECBCL, 0x58C5134D82F6FE24L, 0x1C3AE3515B62274FL,
+ 0xE907C82E01CB8126L, 0xF8ED091913E37FCBL, 0x3249D8F9C80046C9L,
+ 0x80CF9BEDE388FB63L, 0x1881539A116CF19EL, 0x5103F3F76BD52457L,
+ 0x15B7E6F5AE47F7A8L, 0xDBD7C6DED47E9CCFL, 0x44E55C410228BB1AL,
+ 0xB647D4255EDB4E99L, 0x5D11882BB8AAFC30L, 0xF5098BBB29D3212AL,
+ 0x8FB5EA14E90296B3L, 0x677B942157DD025AL, 0xFB58E7C0A390ACB5L,
+ 0x89D3674C83BD4A01L, 0x9E2DA4DF4BF3B93BL, 0xFCC41E328CAB4829L,
+ 0x03F38C96BA582C52L, 0xCAD1BDBD7FD85DB2L, 0xBBB442C16082AE83L,
+ 0xB95FE86BA5DA9AB0L, 0xB22E04673771A93FL, 0x845358C9493152D8L,
+ 0xBE2A488697B4541EL, 0x95A2DC2DD38E6966L, 0xC02C11AC923C852BL,
+ 0x2388B1990DF2A87BL, 0x7C8008FA1B4F37BEL, 0x1F70D0C84D54E503L,
+ 0x5490ADEC7ECE57D4L, 0x002B3C27D9063A3AL, 0x7EAEA3848030A2BFL,
+ 0xC602326DED2003C0L, 0x83A7287D69A94086L, 0xC57A5FCB30F57A8AL,
+ 0xB56844E479EBE779L, 0xA373B40F05DCBCE9L, 0xD71A786E88570EE2L,
+ 0x879CBACDBDE8F6A0L, 0x976AD1BCC164A32FL, 0xAB21E25E9666D78BL,
+ 0x901063AAE5E5C33CL, 0x9818B34448698D90L, 0xE36487AE3E1E8ABBL,
+ 0xAFBDF931893BDCB4L, 0x6345A0DC5FBBD519L, 0x8628FE269B9465CAL,
+ 0x1E5D01603F9C51ECL, 0x4DE44006A15049B7L, 0xBF6C70E5F776CBB1L,
+ 0x411218F2EF552BEDL, 0xCB0C0708705A36A3L, 0xE74D14754F986044L,
+ 0xCD56D9430EA8280EL, 0xC12591D7535F5065L, 0xC83223F1720AEF96L,
+ 0xC3A0396F7363A51FL };
// The cached self-test result.
private static Boolean valid;
@@ -602,9 +436,6 @@ public class Tiger extends BaseHash
// The context.
private long a, b, c;
- // Constructors.
- // -----------------------------------------------------------------------
-
/**
* Trivial 0-arguments constructor.
*/
@@ -628,9 +459,6 @@ public class Tiger extends BaseHash
this.buffer = (that.buffer != null) ? (byte[]) that.buffer.clone() : null;
}
- // Instance methods implementing BaseHash.
- // -----------------------------------------------------------------------
-
public Object clone()
{
return new Tiger(this);
@@ -640,42 +468,39 @@ public class Tiger extends BaseHash
{
if (valid == null)
{
- valid = Boolean.valueOf(DIGEST0.equals(Util.toString(new Tiger().digest())));
+ String d = Util.toString(new Tiger().digest());
+ valid = Boolean.valueOf(DIGEST0.equals(d));
}
return valid.booleanValue();
}
protected byte[] padBuffer()
{
- int n = (int) (count % BLOCK_SIZE);
+ int n = (int)(count % BLOCK_SIZE);
int padding = (n < 56) ? (56 - n) : (120 - n);
byte[] pad = new byte[padding + 8];
-
pad[0] = 1;
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);
-
+ 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 byte[] getResult()
{
- return new byte[] { (byte) a, (byte) (a >>> 8), (byte) (a >>> 16),
- (byte) (a >>> 24), (byte) (a >>> 32), (byte) (a >>> 40),
- (byte) (a >>> 48), (byte) (a >>> 56), (byte) b,
- (byte) (b >>> 8), (byte) (b >>> 16), (byte) (b >>> 24),
- (byte) (b >>> 32), (byte) (b >>> 40), (byte) (b >>> 48),
- (byte) (b >>> 56), (byte) c, (byte) (c >>> 8),
- (byte) (c >>> 16), (byte) (c >>> 24), (byte) (c >>> 32),
- (byte) (c >>> 40), (byte) (c >>> 48), (byte) (c >>> 56) };
+ return new byte[] {
+ (byte) a, (byte)(a >>> 8), (byte)(a >>> 16), (byte)(a >>> 24),
+ (byte)(a >>> 32), (byte)(a >>> 40), (byte)(a >>> 48), (byte)(a >>> 56),
+ (byte) b, (byte)(b >>> 8), (byte)(b >>> 16), (byte)(b >>> 24),
+ (byte)(b >>> 32), (byte)(b >>> 40), (byte)(b >>> 48), (byte)(b >>> 56),
+ (byte) c, (byte)(c >>> 8), (byte)(c >>> 16), (byte)(c >>> 24),
+ (byte)(c >>> 32), (byte)(c >>> 40), (byte)(c >>> 48), (byte)(c >>> 56) };
}
protected void resetContext()
@@ -688,117 +513,153 @@ public class Tiger extends BaseHash
protected void transform(byte[] in, int offset)
{
long x0, x1, x2, x3, x4, x5, x6, x7;
-
- x0 = ((long) in[offset++] & 0xFF) | ((long) (in[offset++] & 0xFF) << 8)
- | ((long) (in[offset++] & 0xFF) << 16)
- | ((long) (in[offset++] & 0xFF) << 24)
- | ((long) (in[offset++] & 0xFF) << 32)
- | ((long) (in[offset++] & 0xFF) << 40)
- | ((long) (in[offset++] & 0xFF) << 48)
- | ((long) (in[offset++] & 0xFF) << 56);
- x1 = ((long) in[offset++] & 0xFF) | ((long) (in[offset++] & 0xFF) << 8)
- | ((long) (in[offset++] & 0xFF) << 16)
- | ((long) (in[offset++] & 0xFF) << 24)
- | ((long) (in[offset++] & 0xFF) << 32)
- | ((long) (in[offset++] & 0xFF) << 40)
- | ((long) (in[offset++] & 0xFF) << 48)
- | ((long) (in[offset++] & 0xFF) << 56);
- x2 = ((long) in[offset++] & 0xFF) | ((long) (in[offset++] & 0xFF) << 8)
- | ((long) (in[offset++] & 0xFF) << 16)
- | ((long) (in[offset++] & 0xFF) << 24)
- | ((long) (in[offset++] & 0xFF) << 32)
- | ((long) (in[offset++] & 0xFF) << 40)
- | ((long) (in[offset++] & 0xFF) << 48)
- | ((long) (in[offset++] & 0xFF) << 56);
- x3 = ((long) in[offset++] & 0xFF) | ((long) (in[offset++] & 0xFF) << 8)
- | ((long) (in[offset++] & 0xFF) << 16)
- | ((long) (in[offset++] & 0xFF) << 24)
- | ((long) (in[offset++] & 0xFF) << 32)
- | ((long) (in[offset++] & 0xFF) << 40)
- | ((long) (in[offset++] & 0xFF) << 48)
- | ((long) (in[offset++] & 0xFF) << 56);
- x4 = ((long) in[offset++] & 0xFF) | ((long) (in[offset++] & 0xFF) << 8)
- | ((long) (in[offset++] & 0xFF) << 16)
- | ((long) (in[offset++] & 0xFF) << 24)
- | ((long) (in[offset++] & 0xFF) << 32)
- | ((long) (in[offset++] & 0xFF) << 40)
- | ((long) (in[offset++] & 0xFF) << 48)
- | ((long) (in[offset++] & 0xFF) << 56);
- x5 = ((long) in[offset++] & 0xFF) | ((long) (in[offset++] & 0xFF) << 8)
- | ((long) (in[offset++] & 0xFF) << 16)
- | ((long) (in[offset++] & 0xFF) << 24)
- | ((long) (in[offset++] & 0xFF) << 32)
- | ((long) (in[offset++] & 0xFF) << 40)
- | ((long) (in[offset++] & 0xFF) << 48)
- | ((long) (in[offset++] & 0xFF) << 56);
- x6 = ((long) in[offset++] & 0xFF) | ((long) (in[offset++] & 0xFF) << 8)
- | ((long) (in[offset++] & 0xFF) << 16)
- | ((long) (in[offset++] & 0xFF) << 24)
- | ((long) (in[offset++] & 0xFF) << 32)
- | ((long) (in[offset++] & 0xFF) << 40)
- | ((long) (in[offset++] & 0xFF) << 48)
- | ((long) (in[offset++] & 0xFF) << 56);
- x7 = ((long) in[offset++] & 0xFF) | ((long) (in[offset++] & 0xFF) << 8)
- | ((long) (in[offset++] & 0xFF) << 16)
- | ((long) (in[offset++] & 0xFF) << 24)
- | ((long) (in[offset++] & 0xFF) << 32)
- | ((long) (in[offset++] & 0xFF) << 40)
- | ((long) (in[offset++] & 0xFF) << 48)
- | ((long) (in[offset] & 0xFF) << 56);
-
+ x0 = ((long) in[offset++] & 0xFF)
+ | ((long) (in[offset++] & 0xFF) << 8)
+ | ((long) (in[offset++] & 0xFF) << 16)
+ | ((long) (in[offset++] & 0xFF) << 24)
+ | ((long) (in[offset++] & 0xFF) << 32)
+ | ((long) (in[offset++] & 0xFF) << 40)
+ | ((long) (in[offset++] & 0xFF) << 48)
+ | ((long) (in[offset++] & 0xFF) << 56);
+ x1 = ((long) in[offset++] & 0xFF)
+ | ((long) (in[offset++] & 0xFF) << 8)
+ | ((long) (in[offset++] & 0xFF) << 16)
+ | ((long) (in[offset++] & 0xFF) << 24)
+ | ((long) (in[offset++] & 0xFF) << 32)
+ | ((long) (in[offset++] & 0xFF) << 40)
+ | ((long) (in[offset++] & 0xFF) << 48)
+ | ((long) (in[offset++] & 0xFF) << 56);
+ x2 = ((long) in[offset++] & 0xFF)
+ | ((long) (in[offset++] & 0xFF) << 8)
+ | ((long) (in[offset++] & 0xFF) << 16)
+ | ((long) (in[offset++] & 0xFF) << 24)
+ | ((long) (in[offset++] & 0xFF) << 32)
+ | ((long) (in[offset++] & 0xFF) << 40)
+ | ((long) (in[offset++] & 0xFF) << 48)
+ | ((long) (in[offset++] & 0xFF) << 56);
+ x3 = ((long) in[offset++] & 0xFF)
+ | ((long) (in[offset++] & 0xFF) << 8)
+ | ((long) (in[offset++] & 0xFF) << 16)
+ | ((long) (in[offset++] & 0xFF) << 24)
+ | ((long) (in[offset++] & 0xFF) << 32)
+ | ((long) (in[offset++] & 0xFF) << 40)
+ | ((long) (in[offset++] & 0xFF) << 48)
+ | ((long) (in[offset++] & 0xFF) << 56);
+ x4 = ((long) in[offset++] & 0xFF)
+ | ((long) (in[offset++] & 0xFF) << 8)
+ | ((long) (in[offset++] & 0xFF) << 16)
+ | ((long) (in[offset++] & 0xFF) << 24)
+ | ((long) (in[offset++] & 0xFF) << 32)
+ | ((long) (in[offset++] & 0xFF) << 40)
+ | ((long) (in[offset++] & 0xFF) << 48)
+ | ((long) (in[offset++] & 0xFF) << 56);
+ x5 = ((long) in[offset++] & 0xFF)
+ | ((long) (in[offset++] & 0xFF) << 8)
+ | ((long) (in[offset++] & 0xFF) << 16)
+ | ((long) (in[offset++] & 0xFF) << 24)
+ | ((long) (in[offset++] & 0xFF) << 32)
+ | ((long) (in[offset++] & 0xFF) << 40)
+ | ((long) (in[offset++] & 0xFF) << 48)
+ | ((long) (in[offset++] & 0xFF) << 56);
+ x6 = ((long) in[offset++] & 0xFF)
+ | ((long) (in[offset++] & 0xFF) << 8)
+ | ((long) (in[offset++] & 0xFF) << 16)
+ | ((long) (in[offset++] & 0xFF) << 24)
+ | ((long) (in[offset++] & 0xFF) << 32)
+ | ((long) (in[offset++] & 0xFF) << 40)
+ | ((long) (in[offset++] & 0xFF) << 48)
+ | ((long) (in[offset++] & 0xFF) << 56);
+ x7 = ((long) in[offset++] & 0xFF)
+ | ((long) (in[offset++] & 0xFF) << 8)
+ | ((long) (in[offset++] & 0xFF) << 16)
+ | ((long) (in[offset++] & 0xFF) << 24)
+ | ((long) (in[offset++] & 0xFF) << 32)
+ | ((long) (in[offset++] & 0xFF) << 40)
+ | ((long) (in[offset++] & 0xFF) << 48)
+ | ((long) (in[offset ] & 0xFF) << 56);
// save_abc ::=
long aa = a, bb = b, cc = c;
-
// pass(aa, bb, cc, 5) ::=
cc ^= x0;
- aa -= T1[(int) cc & 0xff] ^ T2[(int) (cc >> 16) & 0xff]
- ^ T3[(int) (cc >> 32) & 0xff] ^ T4[(int) (cc >> 48) & 0xff];
- bb += T4[(int) (cc >> 8) & 0xff] ^ T3[(int) (cc >> 24) & 0xff]
- ^ T2[(int) (cc >> 40) & 0xff] ^ T1[(int) (cc >> 56) & 0xff];
+ aa -= T1[(int) cc & 0xff]
+ ^ T2[(int)(cc >> 16) & 0xff]
+ ^ T3[(int)(cc >> 32) & 0xff]
+ ^ T4[(int)(cc >> 48) & 0xff];
+ bb += T4[(int)(cc >> 8) & 0xff]
+ ^ T3[(int)(cc >> 24) & 0xff]
+ ^ T2[(int)(cc >> 40) & 0xff]
+ ^ T1[(int)(cc >> 56) & 0xff];
bb *= 5;
aa ^= x1;
- bb -= T1[(int) aa & 0xff] ^ T2[(int) (aa >> 16) & 0xff]
- ^ T3[(int) (aa >> 32) & 0xff] ^ T4[(int) (aa >> 48) & 0xff];
- cc += T4[(int) (aa >> 8) & 0xff] ^ T3[(int) (aa >> 24) & 0xff]
- ^ T2[(int) (aa >> 40) & 0xff] ^ T1[(int) (aa >> 56) & 0xff];
+ bb -= T1[(int) aa & 0xff]
+ ^ T2[(int)(aa >> 16) & 0xff]
+ ^ T3[(int)(aa >> 32) & 0xff]
+ ^ T4[(int)(aa >> 48) & 0xff];
+ cc += T4[(int)(aa >> 8) & 0xff]
+ ^ T3[(int)(aa >> 24) & 0xff]
+ ^ T2[(int)(aa >> 40) & 0xff]
+ ^ T1[(int)(aa >> 56) & 0xff];
cc *= 5;
bb ^= x2;
- cc -= T1[(int) bb & 0xff] ^ T2[(int) (bb >> 16) & 0xff]
- ^ T3[(int) (bb >> 32) & 0xff] ^ T4[(int) (bb >> 48) & 0xff];
- aa += T4[(int) (bb >> 8) & 0xff] ^ T3[(int) (bb >> 24) & 0xff]
- ^ T2[(int) (bb >> 40) & 0xff] ^ T1[(int) (bb >> 56) & 0xff];
+ cc -= T1[(int) bb & 0xff]
+ ^ T2[(int)(bb >> 16) & 0xff]
+ ^ T3[(int)(bb >> 32) & 0xff]
+ ^ T4[(int)(bb >> 48) & 0xff];
+ aa += T4[(int)(bb >> 8) & 0xff]
+ ^ T3[(int)(bb >> 24) & 0xff]
+ ^ T2[(int)(bb >> 40) & 0xff]
+ ^ T1[(int)(bb >> 56) & 0xff];
aa *= 5;
cc ^= x3;
- aa -= T1[(int) cc & 0xff] ^ T2[(int) (cc >> 16) & 0xff]
- ^ T3[(int) (cc >> 32) & 0xff] ^ T4[(int) (cc >> 48) & 0xff];
- bb += T4[(int) (cc >> 8) & 0xff] ^ T3[(int) (cc >> 24) & 0xff]
- ^ T2[(int) (cc >> 40) & 0xff] ^ T1[(int) (cc >> 56) & 0xff];
+ aa -= T1[(int) cc & 0xff]
+ ^ T2[(int)(cc >> 16) & 0xff]
+ ^ T3[(int)(cc >> 32) & 0xff]
+ ^ T4[(int)(cc >> 48) & 0xff];
+ bb += T4[(int)(cc >> 8) & 0xff]
+ ^ T3[(int)(cc >> 24) & 0xff]
+ ^ T2[(int)(cc >> 40) & 0xff]
+ ^ T1[(int)(cc >> 56) & 0xff];
bb *= 5;
aa ^= x4;
- bb -= T1[(int) aa & 0xff] ^ T2[(int) (aa >> 16) & 0xff]
- ^ T3[(int) (aa >> 32) & 0xff] ^ T4[(int) (aa >> 48) & 0xff];
- cc += T4[(int) (aa >> 8) & 0xff] ^ T3[(int) (aa >> 24) & 0xff]
- ^ T2[(int) (aa >> 40) & 0xff] ^ T1[(int) (aa >> 56) & 0xff];
+ bb -= T1[(int) aa & 0xff]
+ ^ T2[(int)(aa >> 16) & 0xff]
+ ^ T3[(int)(aa >> 32) & 0xff]
+ ^ T4[(int)(aa >> 48) & 0xff];
+ cc += T4[(int)(aa >> 8) & 0xff]
+ ^ T3[(int)(aa >> 24) & 0xff]
+ ^ T2[(int)(aa >> 40) & 0xff]
+ ^ T1[(int)(aa >> 56) & 0xff];
cc *= 5;
bb ^= x5;
- cc -= T1[(int) bb & 0xff] ^ T2[(int) (bb >> 16) & 0xff]
- ^ T3[(int) (bb >> 32) & 0xff] ^ T4[(int) (bb >> 48) & 0xff];
- aa += T4[(int) (bb >> 8) & 0xff] ^ T3[(int) (bb >> 24) & 0xff]
- ^ T2[(int) (bb >> 40) & 0xff] ^ T1[(int) (bb >> 56) & 0xff];
+ cc -= T1[(int) bb & 0xff]
+ ^ T2[(int)(bb >> 16) & 0xff]
+ ^ T3[(int)(bb >> 32) & 0xff]
+ ^ T4[(int)(bb >> 48) & 0xff];
+ aa += T4[(int)(bb >> 8) & 0xff]
+ ^ T3[(int)(bb >> 24) & 0xff]
+ ^ T2[(int)(bb >> 40) & 0xff]
+ ^ T1[(int)(bb >> 56) & 0xff];
aa *= 5;
cc ^= x6;
- aa -= T1[(int) cc & 0xff] ^ T2[(int) (cc >> 16) & 0xff]
- ^ T3[(int) (cc >> 32) & 0xff] ^ T4[(int) (cc >> 48) & 0xff];
- bb += T4[(int) (cc >> 8) & 0xff] ^ T3[(int) (cc >> 24) & 0xff]
- ^ T2[(int) (cc >> 40) & 0xff] ^ T1[(int) (cc >> 56) & 0xff];
+ aa -= T1[(int) cc & 0xff]
+ ^ T2[(int)(cc >> 16) & 0xff]
+ ^ T3[(int)(cc >> 32) & 0xff]
+ ^ T4[(int)(cc >> 48) & 0xff];
+ bb += T4[(int)(cc >> 8) & 0xff]
+ ^ T3[(int)(cc >> 24) & 0xff]
+ ^ T2[(int)(cc >> 40) & 0xff]
+ ^ T1[(int)(cc >> 56) & 0xff];
bb *= 5;
aa ^= x7;
- bb -= T1[(int) aa & 0xff] ^ T2[(int) (aa >> 16) & 0xff]
- ^ T3[(int) (aa >> 32) & 0xff] ^ T4[(int) (aa >> 48) & 0xff];
- cc += T4[(int) (aa >> 8) & 0xff] ^ T3[(int) (aa >> 24) & 0xff]
- ^ T2[(int) (aa >> 40) & 0xff] ^ T1[(int) (aa >> 56) & 0xff];
+ bb -= T1[(int) aa & 0xff]
+ ^ T2[(int)(aa >> 16) & 0xff]
+ ^ T3[(int)(aa >> 32) & 0xff]
+ ^ T4[(int)(aa >> 48) & 0xff];
+ cc += T4[(int)(aa >> 8) & 0xff]
+ ^ T3[(int)(aa >> 24) & 0xff]
+ ^ T2[(int)(aa >> 40) & 0xff]
+ ^ T1[(int)(aa >> 56) & 0xff];
cc *= 5;
-
// key_schedule ::=
x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5L;
x1 ^= x0;
@@ -816,57 +677,87 @@ public class Tiger extends BaseHash
x5 ^= x4;
x6 += x5;
x7 -= x6 ^ 0x0123456789ABCDEFL;
-
// pass(cc, aa, bb, 7) ::=
bb ^= x0;
- cc -= T1[(int) bb & 0xff] ^ T2[(int) (bb >> 16) & 0xff]
- ^ T3[(int) (bb >> 32) & 0xff] ^ T4[(int) (bb >> 48) & 0xff];
- aa += T4[(int) (bb >> 8) & 0xff] ^ T3[(int) (bb >> 24) & 0xff]
- ^ T2[(int) (bb >> 40) & 0xff] ^ T1[(int) (bb >> 56) & 0xff];
+ cc -= T1[(int) bb & 0xff]
+ ^ T2[(int)(bb >> 16) & 0xff]
+ ^ T3[(int)(bb >> 32) & 0xff]
+ ^ T4[(int)(bb >> 48) & 0xff];
+ aa += T4[(int)(bb >> 8) & 0xff]
+ ^ T3[(int)(bb >> 24) & 0xff]
+ ^ T2[(int)(bb >> 40) & 0xff]
+ ^ T1[(int)(bb >> 56) & 0xff];
aa *= 7;
cc ^= x1;
- aa -= T1[(int) cc & 0xff] ^ T2[(int) (cc >> 16) & 0xff]
- ^ T3[(int) (cc >> 32) & 0xff] ^ T4[(int) (cc >> 48) & 0xff];
- bb += T4[(int) (cc >> 8) & 0xff] ^ T3[(int) (cc >> 24) & 0xff]
- ^ T2[(int) (cc >> 40) & 0xff] ^ T1[(int) (cc >> 56) & 0xff];
+ aa -= T1[(int) cc & 0xff]
+ ^ T2[(int)(cc >> 16) & 0xff]
+ ^ T3[(int)(cc >> 32) & 0xff]
+ ^ T4[(int)(cc >> 48) & 0xff];
+ bb += T4[(int)(cc >> 8) & 0xff]
+ ^ T3[(int)(cc >> 24) & 0xff]
+ ^ T2[(int)(cc >> 40) & 0xff]
+ ^ T1[(int)(cc >> 56) & 0xff];
bb *= 7;
aa ^= x2;
- bb -= T1[(int) aa & 0xff] ^ T2[(int) (aa >> 16) & 0xff]
- ^ T3[(int) (aa >> 32) & 0xff] ^ T4[(int) (aa >> 48) & 0xff];
- cc += T4[(int) (aa >> 8) & 0xff] ^ T3[(int) (aa >> 24) & 0xff]
- ^ T2[(int) (aa >> 40) & 0xff] ^ T1[(int) (aa >> 56) & 0xff];
+ bb -= T1[(int) aa & 0xff]
+ ^ T2[(int)(aa >> 16) & 0xff]
+ ^ T3[(int)(aa >> 32) & 0xff]
+ ^ T4[(int)(aa >> 48) & 0xff];
+ cc += T4[(int)(aa >> 8) & 0xff]
+ ^ T3[(int)(aa >> 24) & 0xff]
+ ^ T2[(int)(aa >> 40) & 0xff]
+ ^ T1[(int)(aa >> 56) & 0xff];
cc *= 7;
bb ^= x3;
- cc -= T1[(int) bb & 0xff] ^ T2[(int) (bb >> 16) & 0xff]
- ^ T3[(int) (bb >> 32) & 0xff] ^ T4[(int) (bb >> 48) & 0xff];
- aa += T4[(int) (bb >> 8) & 0xff] ^ T3[(int) (bb >> 24) & 0xff]
- ^ T2[(int) (bb >> 40) & 0xff] ^ T1[(int) (bb >> 56) & 0xff];
+ cc -= T1[(int) bb & 0xff]
+ ^ T2[(int)(bb >> 16) & 0xff]
+ ^ T3[(int)(bb >> 32) & 0xff]
+ ^ T4[(int)(bb >> 48) & 0xff];
+ aa += T4[(int)(bb >> 8) & 0xff]
+ ^ T3[(int)(bb >> 24) & 0xff]
+ ^ T2[(int)(bb >> 40) & 0xff]
+ ^ T1[(int)(bb >> 56) & 0xff];
aa *= 7;
cc ^= x4;
- aa -= T1[(int) cc & 0xff] ^ T2[(int) (cc >> 16) & 0xff]
- ^ T3[(int) (cc >> 32) & 0xff] ^ T4[(int) (cc >> 48) & 0xff];
- bb += T4[(int) (cc >> 8) & 0xff] ^ T3[(int) (cc >> 24) & 0xff]
- ^ T2[(int) (cc >> 40) & 0xff] ^ T1[(int) (cc >> 56) & 0xff];
+ aa -= T1[(int) cc & 0xff]
+ ^ T2[(int)(cc >> 16) & 0xff]
+ ^ T3[(int)(cc >> 32) & 0xff]
+ ^ T4[(int)(cc >> 48) & 0xff];
+ bb += T4[(int)(cc >> 8) & 0xff]
+ ^ T3[(int)(cc >> 24) & 0xff]
+ ^ T2[(int)(cc >> 40) & 0xff]
+ ^ T1[(int)(cc >> 56) & 0xff];
bb *= 7;
aa ^= x5;
- bb -= T1[(int) aa & 0xff] ^ T2[(int) (aa >> 16) & 0xff]
- ^ T3[(int) (aa >> 32) & 0xff] ^ T4[(int) (aa >> 48) & 0xff];
- cc += T4[(int) (aa >> 8) & 0xff] ^ T3[(int) (aa >> 24) & 0xff]
- ^ T2[(int) (aa >> 40) & 0xff] ^ T1[(int) (aa >> 56) & 0xff];
+ bb -= T1[(int) aa & 0xff]
+ ^ T2[(int)(aa >> 16) & 0xff]
+ ^ T3[(int)(aa >> 32) & 0xff]
+ ^ T4[(int)(aa >> 48) & 0xff];
+ cc += T4[(int)(aa >> 8) & 0xff]
+ ^ T3[(int)(aa >> 24) & 0xff]
+ ^ T2[(int)(aa >> 40) & 0xff]
+ ^ T1[(int)(aa >> 56) & 0xff];
cc *= 7;
bb ^= x6;
- cc -= T1[(int) bb & 0xff] ^ T2[(int) (bb >> 16) & 0xff]
- ^ T3[(int) (bb >> 32) & 0xff] ^ T4[(int) (bb >> 48) & 0xff];
- aa += T4[(int) (bb >> 8) & 0xff] ^ T3[(int) (bb >> 24) & 0xff]
- ^ T2[(int) (bb >> 40) & 0xff] ^ T1[(int) (bb >> 56) & 0xff];
+ cc -= T1[(int) bb & 0xff]
+ ^ T2[(int)(bb >> 16) & 0xff]
+ ^ T3[(int)(bb >> 32) & 0xff]
+ ^ T4[(int)(bb >> 48) & 0xff];
+ aa += T4[(int)(bb >> 8) & 0xff]
+ ^ T3[(int)(bb >> 24) & 0xff]
+ ^ T2[(int)(bb >> 40) & 0xff]
+ ^ T1[(int)(bb >> 56) & 0xff];
aa *= 7;
cc ^= x7;
- aa -= T1[(int) cc & 0xff] ^ T2[(int) (cc >> 16) & 0xff]
- ^ T3[(int) (cc >> 32) & 0xff] ^ T4[(int) (cc >> 48) & 0xff];
- bb += T4[(int) (cc >> 8) & 0xff] ^ T3[(int) (cc >> 24) & 0xff]
- ^ T2[(int) (cc >> 40) & 0xff] ^ T1[(int) (cc >> 56) & 0xff];
+ aa -= T1[(int) cc & 0xff]
+ ^ T2[(int)(cc >> 16) & 0xff]
+ ^ T3[(int)(cc >> 32) & 0xff]
+ ^ T4[(int)(cc >> 48) & 0xff];
+ bb += T4[(int)(cc >> 8) & 0xff]
+ ^ T3[(int)(cc >> 24) & 0xff]
+ ^ T2[(int)(cc >> 40) & 0xff]
+ ^ T1[(int)(cc >> 56) & 0xff];
bb *= 7;
-
// key_schedule ::=
x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5L;
x1 ^= x0;
@@ -884,57 +775,87 @@ public class Tiger extends BaseHash
x5 ^= x4;
x6 += x5;
x7 -= x6 ^ 0x0123456789ABCDEFL;
-
// pass(bb,cc,aa,9) ::=
aa ^= x0;
- bb -= T1[(int) aa & 0xff] ^ T2[(int) (aa >> 16) & 0xff]
- ^ T3[(int) (aa >> 32) & 0xff] ^ T4[(int) (aa >> 48) & 0xff];
- cc += T4[(int) (aa >> 8) & 0xff] ^ T3[(int) (aa >> 24) & 0xff]
- ^ T2[(int) (aa >> 40) & 0xff] ^ T1[(int) (aa >> 56) & 0xff];
+ bb -= T1[(int) aa & 0xff]
+ ^ T2[(int)(aa >> 16) & 0xff]
+ ^ T3[(int)(aa >> 32) & 0xff]
+ ^ T4[(int)(aa >> 48) & 0xff];
+ cc += T4[(int)(aa >> 8) & 0xff]
+ ^ T3[(int)(aa >> 24) & 0xff]
+ ^ T2[(int)(aa >> 40) & 0xff]
+ ^ T1[(int)(aa >> 56) & 0xff];
cc *= 9;
bb ^= x1;
- cc -= T1[(int) bb & 0xff] ^ T2[(int) (bb >> 16) & 0xff]
- ^ T3[(int) (bb >> 32) & 0xff] ^ T4[(int) (bb >> 48) & 0xff];
- aa += T4[(int) (bb >> 8) & 0xff] ^ T3[(int) (bb >> 24) & 0xff]
- ^ T2[(int) (bb >> 40) & 0xff] ^ T1[(int) (bb >> 56) & 0xff];
+ cc -= T1[(int) bb & 0xff]
+ ^ T2[(int)(bb >> 16) & 0xff]
+ ^ T3[(int)(bb >> 32) & 0xff]
+ ^ T4[(int)(bb >> 48) & 0xff];
+ aa += T4[(int)(bb >> 8) & 0xff]
+ ^ T3[(int)(bb >> 24) & 0xff]
+ ^ T2[(int)(bb >> 40) & 0xff]
+ ^ T1[(int)(bb >> 56) & 0xff];
aa *= 9;
cc ^= x2;
- aa -= T1[(int) cc & 0xff] ^ T2[(int) (cc >> 16) & 0xff]
- ^ T3[(int) (cc >> 32) & 0xff] ^ T4[(int) (cc >> 48) & 0xff];
- bb += T4[(int) (cc >> 8) & 0xff] ^ T3[(int) (cc >> 24) & 0xff]
- ^ T2[(int) (cc >> 40) & 0xff] ^ T1[(int) (cc >> 56) & 0xff];
+ aa -= T1[(int) cc & 0xff]
+ ^ T2[(int)(cc >> 16) & 0xff]
+ ^ T3[(int)(cc >> 32) & 0xff]
+ ^ T4[(int)(cc >> 48) & 0xff];
+ bb += T4[(int)(cc >> 8) & 0xff]
+ ^ T3[(int)(cc >> 24) & 0xff]
+ ^ T2[(int)(cc >> 40) & 0xff]
+ ^ T1[(int)(cc >> 56) & 0xff];
bb *= 9;
aa ^= x3;
- bb -= T1[(int) aa & 0xff] ^ T2[(int) (aa >> 16) & 0xff]
- ^ T3[(int) (aa >> 32) & 0xff] ^ T4[(int) (aa >> 48) & 0xff];
- cc += T4[(int) (aa >> 8) & 0xff] ^ T3[(int) (aa >> 24) & 0xff]
- ^ T2[(int) (aa >> 40) & 0xff] ^ T1[(int) (aa >> 56) & 0xff];
+ bb -= T1[(int) aa & 0xff]
+ ^ T2[(int)(aa >> 16) & 0xff]
+ ^ T3[(int)(aa >> 32) & 0xff]
+ ^ T4[(int)(aa >> 48) & 0xff];
+ cc += T4[(int)(aa >> 8) & 0xff]
+ ^ T3[(int)(aa >> 24) & 0xff]
+ ^ T2[(int)(aa >> 40) & 0xff]
+ ^ T1[(int)(aa >> 56) & 0xff];
cc *= 9;
bb ^= x4;
- cc -= T1[(int) bb & 0xff] ^ T2[(int) (bb >> 16) & 0xff]
- ^ T3[(int) (bb >> 32) & 0xff] ^ T4[(int) (bb >> 48) & 0xff];
- aa += T4[(int) (bb >> 8) & 0xff] ^ T3[(int) (bb >> 24) & 0xff]
- ^ T2[(int) (bb >> 40) & 0xff] ^ T1[(int) (bb >> 56) & 0xff];
+ cc -= T1[(int) bb & 0xff]
+ ^ T2[(int)(bb >> 16) & 0xff]
+ ^ T3[(int)(bb >> 32) & 0xff]
+ ^ T4[(int)(bb >> 48) & 0xff];
+ aa += T4[(int)(bb >> 8) & 0xff]
+ ^ T3[(int)(bb >> 24) & 0xff]
+ ^ T2[(int)(bb >> 40) & 0xff]
+ ^ T1[(int)(bb >> 56) & 0xff];
aa *= 9;
cc ^= x5;
- aa -= T1[(int) cc & 0xff] ^ T2[(int) (cc >> 16) & 0xff]
- ^ T3[(int) (cc >> 32) & 0xff] ^ T4[(int) (cc >> 48) & 0xff];
- bb += T4[(int) (cc >> 8) & 0xff] ^ T3[(int) (cc >> 24) & 0xff]
- ^ T2[(int) (cc >> 40) & 0xff] ^ T1[(int) (cc >> 56) & 0xff];
+ aa -= T1[(int) cc & 0xff]
+ ^ T2[(int)(cc >> 16) & 0xff]
+ ^ T3[(int)(cc >> 32) & 0xff]
+ ^ T4[(int)(cc >> 48) & 0xff];
+ bb += T4[(int)(cc >> 8) & 0xff]
+ ^ T3[(int)(cc >> 24) & 0xff]
+ ^ T2[(int)(cc >> 40) & 0xff]
+ ^ T1[(int)(cc >> 56) & 0xff];
bb *= 9;
aa ^= x6;
- bb -= T1[(int) aa & 0xff] ^ T2[(int) (aa >> 16) & 0xff]
- ^ T3[(int) (aa >> 32) & 0xff] ^ T4[(int) (aa >> 48) & 0xff];
- cc += T4[(int) (aa >> 8) & 0xff] ^ T3[(int) (aa >> 24) & 0xff]
- ^ T2[(int) (aa >> 40) & 0xff] ^ T1[(int) (aa >> 56) & 0xff];
+ bb -= T1[(int) aa & 0xff]
+ ^ T2[(int)(aa >> 16) & 0xff]
+ ^ T3[(int)(aa >> 32) & 0xff]
+ ^ T4[(int)(aa >> 48) & 0xff];
+ cc += T4[(int)(aa >> 8) & 0xff]
+ ^ T3[(int)(aa >> 24) & 0xff]
+ ^ T2[(int)(aa >> 40) & 0xff]
+ ^ T1[(int)(aa >> 56) & 0xff];
cc *= 9;
bb ^= x7;
- cc -= T1[(int) bb & 0xff] ^ T2[(int) (bb >> 16) & 0xff]
- ^ T3[(int) (bb >> 32) & 0xff] ^ T4[(int) (bb >> 48) & 0xff];
- aa += T4[(int) (bb >> 8) & 0xff] ^ T3[(int) (bb >> 24) & 0xff]
- ^ T2[(int) (bb >> 40) & 0xff] ^ T1[(int) (bb >> 56) & 0xff];
+ cc -= T1[(int) bb & 0xff]
+ ^ T2[(int)(bb >> 16) & 0xff]
+ ^ T3[(int)(bb >> 32) & 0xff]
+ ^ T4[(int)(bb >> 48) & 0xff];
+ aa += T4[(int)(bb >> 8) & 0xff]
+ ^ T3[(int)(bb >> 24) & 0xff]
+ ^ T2[(int)(bb >> 40) & 0xff]
+ ^ T1[(int)(bb >> 56) & 0xff];
aa *= 9;
-
// feedforward ::=
a ^= aa;
b = bb - b;
diff --git a/gnu/java/security/hash/Whirlpool.java b/gnu/java/security/hash/Whirlpool.java
index ee40d92b3..89df5c51b 100644
--- a/gnu/java/security/hash/Whirlpool.java
+++ b/gnu/java/security/hash/Whirlpool.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.hash;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.Util;
@@ -62,7 +62,8 @@ import java.util.logging.Logger;
* <a href="mailto:vincent.rijmen@iaik.tugraz.at">Vincent Rijmen</a>.</li>
* </ol>
*/
-public final class Whirlpool extends BaseHash
+public final class Whirlpool
+ extends BaseHash
{
private static final Logger log = Logger.getLogger(Whirlpool.class.getName());
private static final int BLOCK_SIZE = 64; // inner block size in bytes
@@ -77,22 +78,22 @@ public final class Whirlpool extends BaseHash
/** Whirlpool S-box; p. 19. */
private static final String S_box = // p. 19 [WHIRLPOOL]
- "\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152" +
- "\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57" +
- "\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85" +
- "\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8" +
- "\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333" +
- "\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0" +
- "\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE" +
- "\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d" +
- "\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF" +
- "\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A" +
- "\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c" +
- "\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04" +
- "\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB" +
- "\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9" +
- "\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1" +
- "\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886";
+ "\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152"
+ + "\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57"
+ + "\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85"
+ + "\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8"
+ + "\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333"
+ + "\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0"
+ + "\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE"
+ + "\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d"
+ + "\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF"
+ + "\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A"
+ + "\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c"
+ + "\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04"
+ + "\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB"
+ + "\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9"
+ + "\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1"
+ + "\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886";
/** The 64-bit lookup tables; section 7.1 p. 13. */
private static final long[] T0 = new long[256];
@@ -124,12 +125,9 @@ public final class Whirlpool extends BaseHash
/** work area for holding block cipher's intermediate values. */
private long w0, w1, w2, w3, w4, w5, w6, w7;
- // Static code - to intialise lookup tables --------------------------------
-
static
{
long time = System.currentTimeMillis();
-
int ROOT = 0x11D; // para. 2.1 [WHIRLPOOL]
int i, r, j;
long s1, s2, s4, s5, s8, s9, t;
@@ -165,7 +163,6 @@ public final class Whirlpool extends BaseHash
T6[i] = t >>> 48 | t << 16;
T7[i] = t >>> 56 | t << 8;
}
-
for (r = 0, i = 0; r < R; )
rc[r++] = (T0[i++] & 0xFF00000000000000L)
^ (T1[i++] & 0x00FF000000000000L)
@@ -175,7 +172,6 @@ public final class Whirlpool extends BaseHash
^ (T5[i++] & 0x0000000000FF0000L)
^ (T6[i++] & 0x000000000000FF00L)
^ (T7[i++] & 0x00000000000000FFL);
-
time = System.currentTimeMillis() - time;
if (Configuration.DEBUG)
{
@@ -261,9 +257,6 @@ public final class Whirlpool extends BaseHash
}
}
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Whirlpool()
{
@@ -271,7 +264,7 @@ public final class Whirlpool extends BaseHash
}
/**
- * <p>Private constructor for cloning purposes.</p>
+ * Private constructor for cloning purposes.
*
* @param md the instance to clone.
*/
@@ -291,21 +284,11 @@ public final class Whirlpool extends BaseHash
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
@@ -373,7 +356,6 @@ public final class Whirlpool extends BaseHash
| (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;
@@ -383,7 +365,6 @@ public final class Whirlpool extends BaseHash
k05 = H5;
k06 = H6;
k07 = H7;
-
nn0 = n0 ^ k00;
nn1 = n1 ^ k01;
nn2 = n2 ^ k02;
@@ -392,10 +373,8 @@ public final class Whirlpool extends BaseHash
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]
@@ -464,7 +443,6 @@ public final class Whirlpool extends BaseHash
^ T5[(int)((k02 >> 16) & 0xFFL)]
^ T6[(int)((k01 >> 8) & 0xFFL)]
^ T7[(int)( k00 & 0xFFL)];
-
k00 = Kr0;
k01 = Kr1;
k02 = Kr2;
@@ -473,7 +451,6 @@ public final class Whirlpool extends BaseHash
k05 = Kr5;
k06 = Kr6;
k07 = Kr7;
-
// 2. incrementally compute the cipher output
w0 = T0[(int)((nn0 >> 56) & 0xFFL)]
^ T1[(int)((nn7 >> 48) & 0xFFL)]
@@ -539,7 +516,6 @@ public final class Whirlpool extends BaseHash
^ T5[(int)((nn2 >> 16) & 0xFFL)]
^ T6[(int)((nn1 >> 8) & 0xFFL)]
^ T7[(int)( nn0 & 0xFFL)] ^ Kr7;
-
nn0 = w0;
nn1 = w1;
nn2 = w2;
@@ -549,7 +525,6 @@ public final class Whirlpool extends BaseHash
nn6 = w6;
nn7 = w7;
}
-
// apply the Miyaguchi-Preneel hash scheme
H0 ^= w0 ^ n0;
H1 ^= w1 ^ n1;
@@ -574,12 +549,9 @@ public final class Whirlpool extends BaseHash
// 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;
@@ -591,14 +563,13 @@ public final class Whirlpool extends BaseHash
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[] {
+ 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),
@@ -614,10 +585,8 @@ public final class Whirlpool extends BaseHash
(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
- };
+ (byte)(H7 >>> 24), (byte)(H7 >>> 16), (byte)(H7 >>> 8), (byte) H7 };
- return result;
}
protected void resetContext()
@@ -628,8 +597,10 @@ public final class Whirlpool extends BaseHash
public boolean selfTest()
{
if (valid == null)
- valid = Boolean.valueOf(DIGEST0.equals(Util.toString(new Whirlpool().digest())));
-
+ {
+ String d = Util.toString(new Whirlpool().digest());
+ valid = Boolean.valueOf(DIGEST0.equals(d));
+ }
return valid.booleanValue();
}
}
diff --git a/gnu/java/security/jce/hash/HavalSpi.java b/gnu/java/security/jce/hash/HavalSpi.java
index 05595edea..159ba3dd8 100644
--- a/gnu/java/security/jce/hash/HavalSpi.java
+++ b/gnu/java/security/jce/hash/HavalSpi.java
@@ -41,26 +41,14 @@ package gnu.java.security.jce.hash;
import gnu.java.security.Registry;
/**
- * The implementation of the <code>HAVAL</code> <i>Service Provider Interface</i>
- * (<b>SPI</b>) Adapter.<p>
+ * The implementation of the HAVAL <i>Service Provider Interface</i>
+ * (<b>SPI</b>) adapter.
*/
-public class HavalSpi extends MessageDigestAdapter
+public class HavalSpi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public HavalSpi()
{
super(Registry.HAVAL_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/hash/MD2Spi.java b/gnu/java/security/jce/hash/MD2Spi.java
index 001cbaf3c..268f2fa69 100644
--- a/gnu/java/security/jce/hash/MD2Spi.java
+++ b/gnu/java/security/jce/hash/MD2Spi.java
@@ -41,27 +41,15 @@ package gnu.java.security.jce.hash;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the MD2 <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the MD2 <i>Service Provider Interface</i> (<b>SPI</b>)
+ * adapter.
*/
-public class MD2Spi extends MessageDigestAdapter
+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/gnu/java/security/jce/hash/MD4Spi.java b/gnu/java/security/jce/hash/MD4Spi.java
index 41fef87bf..c050ef2df 100644
--- a/gnu/java/security/jce/hash/MD4Spi.java
+++ b/gnu/java/security/jce/hash/MD4Spi.java
@@ -41,27 +41,15 @@ package gnu.java.security.jce.hash;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the MD4 <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the MD4 <i>Service Provider Interface</i> (<b>SPI</b>)
+ * adapter.
*/
-public class MD4Spi extends MessageDigestAdapter
+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/gnu/java/security/jce/hash/MD5Spi.java b/gnu/java/security/jce/hash/MD5Spi.java
index aa1a8844e..629741694 100644
--- a/gnu/java/security/jce/hash/MD5Spi.java
+++ b/gnu/java/security/jce/hash/MD5Spi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the MD5 <i>Service Provider Interface</i> (<b>SPI</b>)
- * adapter.<p>
+ * adapter.
*/
-public class MD5Spi extends MessageDigestAdapter
+public class MD5Spi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public MD5Spi()
{
super(Registry.MD5_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/hash/MessageDigestAdapter.java b/gnu/java/security/jce/hash/MessageDigestAdapter.java
index e30beca3d..7342ee551 100644
--- a/gnu/java/security/jce/hash/MessageDigestAdapter.java
+++ b/gnu/java/security/jce/hash/MessageDigestAdapter.java
@@ -46,35 +46,30 @@ import java.security.MessageDigestSpi;
/**
* The implementation of a generic {@link java.security.MessageDigest} adapter
- * class to wrap gnu.crypto hash instances.<p>
- *
- * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) 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.<p>
- *
- * All the abstract methods in the {@link java.security.MessageDigestSpi} class
- * are implemented by this class and all its sub-classes.<p>
- *
+ * class to wrap GNU hash instances.
+ * <p>
+ * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) 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.
+ * <p>
+ * All the abstract methods in the {@link MessageDigestSpi} class are
+ * implemented by this class and all its sub-classes.
+ * <p>
* All the implementations which subclass this object, and which are serviced by
- * the GNU Crypto provider implement the {@link java.lang.Cloneable} interface.<p>
+ * the GNU provider implement the {@link Cloneable} interface.
*/
-class MessageDigestAdapter extends MessageDigestSpi implements Cloneable
+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)
@@ -84,7 +79,7 @@ class MessageDigestAdapter extends MessageDigestSpi implements Cloneable
/**
* Private constructor for cloning purposes.
- *
+ *
* @param adaptee a clone of the underlying hash algorithm instance.
*/
private MessageDigestAdapter(IMessageDigest adaptee)
@@ -94,12 +89,6 @@ class MessageDigestAdapter extends MessageDigestSpi implements Cloneable
this.adaptee = adaptee;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // java.security.MessageDigestSpi interface implementation
- // -------------------------------------------------------------------------
-
public Object clone()
{
return new MessageDigestAdapter((IMessageDigest) adaptee.clone());
@@ -130,9 +119,8 @@ class MessageDigestAdapter extends MessageDigestSpi implements Cloneable
{
int result = adaptee.hashSize();
if (len < result)
- {
- throw new DigestException();
- }
+ throw new DigestException();
+
byte[] md = adaptee.digest();
System.arraycopy(md, 0, buf, offset, result);
return result;
diff --git a/gnu/java/security/jce/hash/RipeMD128Spi.java b/gnu/java/security/jce/hash/RipeMD128Spi.java
index 404214d91..159a1173c 100644
--- a/gnu/java/security/jce/hash/RipeMD128Spi.java
+++ b/gnu/java/security/jce/hash/RipeMD128Spi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the RIPEMD-128 <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.<p>
+ * (<b>SPI</b>) adapter.
*/
-public class RipeMD128Spi extends MessageDigestAdapter
+public class RipeMD128Spi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public RipeMD128Spi()
{
super(Registry.RIPEMD128_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/hash/RipeMD160Spi.java b/gnu/java/security/jce/hash/RipeMD160Spi.java
index 841f46b3b..579ccb26f 100644
--- a/gnu/java/security/jce/hash/RipeMD160Spi.java
+++ b/gnu/java/security/jce/hash/RipeMD160Spi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the RIPEMD-160 <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.<p>
+ * (<b>SPI</b>) adapter.
*/
-public class RipeMD160Spi extends MessageDigestAdapter
+public class RipeMD160Spi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public RipeMD160Spi()
{
super(Registry.RIPEMD160_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/hash/Sha160Spi.java b/gnu/java/security/jce/hash/Sha160Spi.java
index 419884382..901cac191 100644
--- a/gnu/java/security/jce/hash/Sha160Spi.java
+++ b/gnu/java/security/jce/hash/Sha160Spi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the SHA-1 (160-bit) <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.<p>
+ * (<b>SPI</b>) adapter.
*/
-public class Sha160Spi extends MessageDigestAdapter
+public class Sha160Spi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Sha160Spi()
{
super(Registry.SHA160_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/hash/Sha256Spi.java b/gnu/java/security/jce/hash/Sha256Spi.java
index f07e18941..9d471e65a 100644
--- a/gnu/java/security/jce/hash/Sha256Spi.java
+++ b/gnu/java/security/jce/hash/Sha256Spi.java
@@ -41,26 +41,14 @@ package gnu.java.security.jce.hash;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the SHA-2-1 (256-bit) <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the SHA-2-1 (256-bit) <i>Service Provider Interface</i>
+ * (<b>SPI</b>) adapter.
*/
-public class Sha256Spi extends MessageDigestAdapter
+public class Sha256Spi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Sha256Spi()
{
super(Registry.SHA256_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/hash/Sha384Spi.java b/gnu/java/security/jce/hash/Sha384Spi.java
index fc17077e8..30d5fce09 100644
--- a/gnu/java/security/jce/hash/Sha384Spi.java
+++ b/gnu/java/security/jce/hash/Sha384Spi.java
@@ -41,26 +41,14 @@ package gnu.java.security.jce.hash;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the SHA-2-2 (384-bit) <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the SHA-2-2 (384-bit) <i>Service Provider Interface</i>
+ * (<b>SPI</b>) adapter.
*/
-public class Sha384Spi extends MessageDigestAdapter
+public class Sha384Spi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Sha384Spi()
{
super(Registry.SHA384_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/hash/Sha512Spi.java b/gnu/java/security/jce/hash/Sha512Spi.java
index 0b4c3d62c..a2d44ab24 100644
--- a/gnu/java/security/jce/hash/Sha512Spi.java
+++ b/gnu/java/security/jce/hash/Sha512Spi.java
@@ -41,26 +41,14 @@ package gnu.java.security.jce.hash;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the SHA-2-3 (512-bit) <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the SHA-2-3 (512-bit) <i>Service Provider Interface</i>
+ * (<b>SPI</b>) adapter.
*/
-public class Sha512Spi extends MessageDigestAdapter
+public class Sha512Spi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Sha512Spi()
{
super(Registry.SHA512_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/hash/TigerSpi.java b/gnu/java/security/jce/hash/TigerSpi.java
index 599437410..a21e5fe10 100644
--- a/gnu/java/security/jce/hash/TigerSpi.java
+++ b/gnu/java/security/jce/hash/TigerSpi.java
@@ -41,27 +41,15 @@ package gnu.java.security.jce.hash;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the Tiger <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the Tiger <i>Service Provider Interface</i>
+ * (<b>SPI</b>) adapter.
*/
-public class TigerSpi extends MessageDigestAdapter
+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/gnu/java/security/jce/hash/WhirlpoolSpi.java b/gnu/java/security/jce/hash/WhirlpoolSpi.java
index d1864bc7c..d7a7a4504 100644
--- a/gnu/java/security/jce/hash/WhirlpoolSpi.java
+++ b/gnu/java/security/jce/hash/WhirlpoolSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the Whirlpool <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.<p>
+ * (<b>SPI</b>) adapter.
*/
-public class WhirlpoolSpi extends MessageDigestAdapter
+public class WhirlpoolSpi
+ extends MessageDigestAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public WhirlpoolSpi()
{
super(Registry.WHIRLPOOL_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/HavalRandomSpi.java b/gnu/java/security/jce/prng/HavalRandomSpi.java
index 0c39a37fd..c3d4b9412 100644
--- a/gnu/java/security/jce/prng/HavalRandomSpi.java
+++ b/gnu/java/security/jce/prng/HavalRandomSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the HAVAL-based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) Adapter.<p>
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class HavalRandomSpi extends SecureRandomAdapter
+public class HavalRandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public HavalRandomSpi()
{
super(Registry.HAVAL_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/MD2RandomSpi.java b/gnu/java/security/jce/prng/MD2RandomSpi.java
index 72a7f4873..8ba286804 100644
--- a/gnu/java/security/jce/prng/MD2RandomSpi.java
+++ b/gnu/java/security/jce/prng/MD2RandomSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the MD2-based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.<p>
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class MD2RandomSpi extends SecureRandomAdapter
+public class MD2RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public MD2RandomSpi()
{
super(Registry.MD2_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/MD4RandomSpi.java b/gnu/java/security/jce/prng/MD4RandomSpi.java
index f5f98f8f3..d4d182970 100644
--- a/gnu/java/security/jce/prng/MD4RandomSpi.java
+++ b/gnu/java/security/jce/prng/MD4RandomSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the MD4-based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.<p>
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class MD4RandomSpi extends SecureRandomAdapter
+public class MD4RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public MD4RandomSpi()
{
super(Registry.MD4_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/MD5RandomSpi.java b/gnu/java/security/jce/prng/MD5RandomSpi.java
index 0181247bc..be38add0a 100644
--- a/gnu/java/security/jce/prng/MD5RandomSpi.java
+++ b/gnu/java/security/jce/prng/MD5RandomSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the MD5-based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.<p>
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class MD5RandomSpi extends SecureRandomAdapter
+public class MD5RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public MD5RandomSpi()
{
super(Registry.MD5_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/RipeMD128RandomSpi.java b/gnu/java/security/jce/prng/RipeMD128RandomSpi.java
index 5580716a4..530c3ec21 100644
--- a/gnu/java/security/jce/prng/RipeMD128RandomSpi.java
+++ b/gnu/java/security/jce/prng/RipeMD128RandomSpi.java
@@ -41,26 +41,14 @@ package gnu.java.security.jce.prng;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the RIPEMD128-based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.<p>
+ * The implementation of the RIPEMD128-based SecureRandom <i>Service Provider
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class RipeMD128RandomSpi extends SecureRandomAdapter
+public class RipeMD128RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public RipeMD128RandomSpi()
{
super(Registry.RIPEMD128_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/RipeMD160RandomSpi.java b/gnu/java/security/jce/prng/RipeMD160RandomSpi.java
index 734fe824a..6875cdfa9 100644
--- a/gnu/java/security/jce/prng/RipeMD160RandomSpi.java
+++ b/gnu/java/security/jce/prng/RipeMD160RandomSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the RIPEMD160-based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.<p>
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class RipeMD160RandomSpi extends SecureRandomAdapter
+public class RipeMD160RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public RipeMD160RandomSpi()
{
super(Registry.RIPEMD160_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/SecureRandomAdapter.java b/gnu/java/security/jce/prng/SecureRandomAdapter.java
index 70d30f153..5be402ff0 100644
--- a/gnu/java/security/jce/prng/SecureRandomAdapter.java
+++ b/gnu/java/security/jce/prng/SecureRandomAdapter.java
@@ -45,34 +45,28 @@ import java.security.SecureRandomSpi;
import java.util.Collections;
/**
- * <p>The implementation of a generic {@link java.security.SecureRandom} adapter
- * class to wrap gnu.crypto prng instances based on Message Digest algorithms.</p>
- *
- * <p>This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
+ * The implementation of a generic {@link java.security.SecureRandom} adapter
+ * class to wrap GNU PRNG instances based on Message Digest algorithms.
+ * <p>
+ * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
* the {@link java.security.SecureRandom} class, which provides the
- * functionality of a cryptographically strong pseudo-random number generator.</p>
- *
- * <p>All the abstract methods in the {@link SecureRandomSpi} class are
- * implemented by this class and all its sub-classes.</p>
+ * functionality of a cryptographically strong pseudo-random number generator.
+ * <p>
+ * All the abstract methods in the {@link SecureRandomSpi} class are implemented
+ * by this class and all its sub-classes.
*/
-abstract class SecureRandomAdapter extends SecureRandomSpi
+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)
- // -------------------------------------------------------------------------
-
/**
- * <p>Trivial protected constructor.</p>
- *
+ * Trivial protected constructor.
+ *
* @param mdName the canonical name of the underlying hash algorithm.
*/
protected SecureRandomAdapter(String mdName)
@@ -80,23 +74,14 @@ abstract class SecureRandomAdapter extends SecureRandomSpi
super();
this.mdName = mdName;
- adaptee.init (Collections.singletonMap (MDGenerator.MD_NAME, mdName));
+ adaptee.init(Collections.singletonMap(MDGenerator.MD_NAME, mdName));
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.security.SecureRandomSpi interface implementation ------------------
-
public byte[] engineGenerateSeed(int numBytes)
{
if (numBytes < 1)
- {
- return new byte[0];
- }
+ return new byte[0];
+
byte[] result = new byte[numBytes];
this.engineNextBytes(result);
return result;
@@ -104,10 +89,8 @@ abstract class SecureRandomAdapter extends SecureRandomSpi
public void engineNextBytes(byte[] bytes)
{
- if (!adaptee.isInitialised())
- {
- this.engineSetSeed(new byte[0]);
- }
+ if (! adaptee.isInitialised())
+ this.engineSetSeed(new byte[0]);
try
{
adaptee.nextBytes(bytes, 0, bytes.length);
@@ -119,6 +102,6 @@ abstract class SecureRandomAdapter extends SecureRandomSpi
public void engineSetSeed(byte[] seed)
{
- adaptee.addRandomBytes (seed);
+ adaptee.addRandomBytes(seed);
}
}
diff --git a/gnu/java/security/jce/prng/Sha160RandomSpi.java b/gnu/java/security/jce/prng/Sha160RandomSpi.java
index c93b02d3f..9fded67e0 100644
--- a/gnu/java/security/jce/prng/Sha160RandomSpi.java
+++ b/gnu/java/security/jce/prng/Sha160RandomSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the SHA1-based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.<p>
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class Sha160RandomSpi extends SecureRandomAdapter
+public class Sha160RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Sha160RandomSpi()
{
super(Registry.SHA160_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/Sha256RandomSpi.java b/gnu/java/security/jce/prng/Sha256RandomSpi.java
index 736996430..e3999ffe6 100644
--- a/gnu/java/security/jce/prng/Sha256RandomSpi.java
+++ b/gnu/java/security/jce/prng/Sha256RandomSpi.java
@@ -41,26 +41,14 @@ package gnu.java.security.jce.prng;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the SHA-256 based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.</p>
+ * The implementation of the SHA-256 based SecureRandom <i>Service Provider
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class Sha256RandomSpi extends SecureRandomAdapter
+public class Sha256RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Sha256RandomSpi()
{
super(Registry.SHA256_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/Sha384RandomSpi.java b/gnu/java/security/jce/prng/Sha384RandomSpi.java
index afbf19303..978c8fe38 100644
--- a/gnu/java/security/jce/prng/Sha384RandomSpi.java
+++ b/gnu/java/security/jce/prng/Sha384RandomSpi.java
@@ -41,26 +41,14 @@ package gnu.java.security.jce.prng;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the SHA-384 based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.</p>
+ * The implementation of the SHA-384 based SecureRandom <i>Service Provider
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class Sha384RandomSpi extends SecureRandomAdapter
+public class Sha384RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Sha384RandomSpi()
{
super(Registry.SHA384_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/Sha512RandomSpi.java b/gnu/java/security/jce/prng/Sha512RandomSpi.java
index b2b337760..a89e26f00 100644
--- a/gnu/java/security/jce/prng/Sha512RandomSpi.java
+++ b/gnu/java/security/jce/prng/Sha512RandomSpi.java
@@ -41,26 +41,14 @@ package gnu.java.security.jce.prng;
import gnu.java.security.Registry;
/**
- * <p>The implementation of the SHA-512 based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.</p>
+ * The implementation of the SHA-512 based SecureRandom <i>Service Provider
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class Sha512RandomSpi extends SecureRandomAdapter
+public class Sha512RandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Sha512RandomSpi()
{
super(Registry.SHA512_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/TigerRandomSpi.java b/gnu/java/security/jce/prng/TigerRandomSpi.java
index b4795b98e..ba4b22fb8 100644
--- a/gnu/java/security/jce/prng/TigerRandomSpi.java
+++ b/gnu/java/security/jce/prng/TigerRandomSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the Tiger based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.<p>
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class TigerRandomSpi extends SecureRandomAdapter
+public class TigerRandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public TigerRandomSpi()
{
super(Registry.TIGER_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java b/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java
index f327f9df2..9d937e65f 100644
--- a/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java
+++ b/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java
@@ -42,25 +42,13 @@ import gnu.java.security.Registry;
/**
* The implementation of the Whirlpool-based SecureRandom <i>Service Provider
- * Interface</i> (<b>SPI</b>) adapter.<p>
+ * Interface</i> (<b>SPI</b>) adapter.
*/
-public class WhirlpoolRandomSpi extends SecureRandomAdapter
+public class WhirlpoolRandomSpi
+ extends SecureRandomAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public WhirlpoolRandomSpi()
{
super(Registry.WHIRLPOOL_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/jce/sig/DSSKeyFactory.java b/gnu/java/security/jce/sig/DSSKeyFactory.java
index bb4d85c89..7b57dba70 100644
--- a/gnu/java/security/jce/sig/DSSKeyFactory.java
+++ b/gnu/java/security/jce/sig/DSSKeyFactory.java
@@ -61,10 +61,11 @@ import java.security.spec.X509EncodedKeySpec;
/**
* DSA key factory.
- *
+ *
* @author Casey Marshall (rsdio@metastatic.org)
*/
-public class DSSKeyFactory extends KeyFactorySpi
+public class DSSKeyFactory
+ extends KeyFactorySpi
{
// implicit 0-arguments constructor
@@ -80,7 +81,6 @@ public class DSSKeyFactory extends KeyFactorySpi
BigInteger y = spec.getY();
return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y);
}
-
if (keySpec instanceof X509EncodedKeySpec)
{
X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
@@ -93,12 +93,9 @@ public class DSSKeyFactory extends KeyFactorySpi
}
catch (RuntimeException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
-
throw new InvalidKeySpecException("Unsupported (public) key specification");
}
@@ -114,7 +111,6 @@ public class DSSKeyFactory extends KeyFactorySpi
BigInteger x = spec.getX();
return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x);
}
-
if (keySpec instanceof PKCS8EncodedKeySpec)
{
PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;
@@ -127,12 +123,9 @@ public class DSSKeyFactory extends KeyFactorySpi
}
catch (RuntimeException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
-
throw new InvalidKeySpecException("Unsupported (private) key specification");
}
@@ -150,7 +143,6 @@ public class DSSKeyFactory extends KeyFactorySpi
BigInteger y = dsaKey.getY();
return new DSAPublicKeySpec(y, p, q, g);
}
-
if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
{
if (key instanceof DSSPublicKey)
@@ -159,19 +151,16 @@ public class DSSKeyFactory extends KeyFactorySpi
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(
+ "Wrong key type or unsupported (public) key specification");
}
-
throw new InvalidKeySpecException("Unsupported (public) key specification");
}
-
if (key instanceof DSAPrivateKey)
{
if (keySpec.isAssignableFrom(DSAPrivateKeySpec.class))
@@ -183,7 +172,6 @@ public class DSSKeyFactory extends KeyFactorySpi
BigInteger x = dsaKey.getX();
return new DSAPrivateKeySpec(x, p, q, g);
}
-
if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
{
if (key instanceof DSSPrivateKey)
@@ -192,19 +180,16 @@ public class DSSKeyFactory extends KeyFactorySpi
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(
+ "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");
}
@@ -222,7 +207,6 @@ public class DSSKeyFactory extends KeyFactorySpi
BigInteger y = dsaKey.getY();
return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y);
}
-
if (key instanceof DSAPrivateKey)
{
DSAPrivateKey dsaKey = (DSAPrivateKey) key;
@@ -232,7 +216,6 @@ public class DSSKeyFactory extends KeyFactorySpi
BigInteger x = dsaKey.getX();
return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x);
}
-
throw new InvalidKeyException("Wrong key type");
}
}
diff --git a/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java b/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java
index 44503b26b..c44538106 100644
--- a/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java
+++ b/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java
@@ -52,33 +52,21 @@ import java.util.HashMap;
/**
* The implementation of a {@link java.security.KeyPairGenerator} adapter class
- * to wrap gnu.crypto DSS keypair generator instances.<p>
- *
- * In case the client does not explicitly initialize the KeyPairGenerator (via
- * a call to an <code>initialize()</code> method), the GNU Crypto provider
- * uses a default <i>modulus</i> size (keysize) of 1024 bits.<p>
+ * to wrap GNU DSS keypair generator instances.
+ * <p>
+ * In case the client does not explicitly initialize the KeyPairGenerator (via a
+ * call to an <code>initialize()</code> method), the GNU provider uses a
+ * default <i>modulus</i> size (keysize) of 1024 bits.
*/
-public class DSSKeyPairGeneratorSpi extends KeyPairGeneratorAdapter implements
- DSAKeyPairGenerator
+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);
@@ -90,43 +78,34 @@ public class DSSKeyPairGeneratorSpi extends KeyPairGeneratorAdapter implements
HashMap attributes = new HashMap();
if (params != null)
{
- if (!(params instanceof DSAParameterSpec))
+ if (! (params instanceof DSAParameterSpec))
throw new InvalidAlgorithmParameterException(
- "Parameters argument is not a non-null instance, or " +
- "sub-instance, of java.security.spec.DSAParameterSpec");
-
+ "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.SOURCE_OF_RANDOMNESS, random);
attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
- new Integer(Registry.ASN1_ENCODING_ID));
+ Integer.valueOf(Registry.ASN1_ENCODING_ID));
try
{
adaptee.setup(attributes);
}
catch (IllegalArgumentException x)
{
- InvalidAlgorithmParameterException y =
- new InvalidAlgorithmParameterException();
- y.initCause(x);
- throw y;
+ throw new InvalidAlgorithmParameterException(x.getMessage(), x);
}
}
- // 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");
+ "Parameters argument is either null or is not an instance, or "
+ + "sub-instance, of java.security.spec.DSAParameterSpec");
DSAParameterSpec spec = (DSAParameterSpec) params;
try
{
@@ -134,7 +113,7 @@ public class DSSKeyPairGeneratorSpi extends KeyPairGeneratorAdapter implements
}
catch (InvalidAlgorithmParameterException x)
{
- InvalidParameterException y = new InvalidParameterException();
+ InvalidParameterException y = new InvalidParameterException(x.getMessage());
y.initCause(x);
throw y;
}
@@ -144,22 +123,22 @@ public class DSSKeyPairGeneratorSpi extends KeyPairGeneratorAdapter implements
throws InvalidParameterException
{
HashMap attributes = new HashMap();
- attributes.put(DSSKeyPairGenerator.MODULUS_LENGTH, new Integer(modlen));
+ attributes.put(DSSKeyPairGenerator.MODULUS_LENGTH, Integer.valueOf(modlen));
if (random != null)
attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
attributes.put(DSSKeyPairGenerator.USE_DEFAULTS,
- Boolean.valueOf(!genParams));
+ Boolean.valueOf(! genParams));
attributes.put(DSSKeyPairGenerator.STRICT_DEFAULTS, Boolean.TRUE);
attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
- new Integer(Registry.ASN1_ENCODING_ID));
+ Integer.valueOf(Registry.ASN1_ENCODING_ID));
try
{
adaptee.setup(attributes);
}
catch (IllegalArgumentException x)
{
- InvalidParameterException y = new InvalidParameterException();
+ InvalidParameterException y = new InvalidParameterException(x.getMessage());
y.initCause(x);
throw y;
}
diff --git a/gnu/java/security/jce/sig/DSSParameters.java b/gnu/java/security/jce/sig/DSSParameters.java
index ba1f414fa..eaccb0095 100644
--- a/gnu/java/security/jce/sig/DSSParameters.java
+++ b/gnu/java/security/jce/sig/DSSParameters.java
@@ -136,7 +136,6 @@ public class DSSParameters
if (! format.equalsIgnoreCase(Registry.ASN1_ENCODING_SHORT_NAME))
throw new IOException("Unknown or unsupported format: " + format);
}
-
engineInit(params);
}
@@ -191,7 +190,6 @@ public class DSSParameters
if (! format.equalsIgnoreCase(Registry.ASN1_ENCODING_SHORT_NAME))
throw new IOException("Unknown or unsupported format: " + format);
}
-
return engineGetEncoded();
}
diff --git a/gnu/java/security/jce/sig/DSSRawSignatureSpi.java b/gnu/java/security/jce/sig/DSSRawSignatureSpi.java
index a63c51afa..9b20c03b1 100644
--- a/gnu/java/security/jce/sig/DSSRawSignatureSpi.java
+++ b/gnu/java/security/jce/sig/DSSRawSignatureSpi.java
@@ -42,27 +42,15 @@ import gnu.java.security.Registry;
import gnu.java.security.sig.dss.DSSSignatureRawCodec;
/**
- * The implementation of <i>Service Provider Interface</i> (<b>SPI</b>) adapter
- * for the DSS (Digital Signature Standard) signature scheme, encoded and/or
- * decoded in RAW format.<p>
+ * The implementation of <i>Service Provider Interface</i> (<b>SPI</b>)
+ * adapter for the DSS (Digital Signature Standard) signature scheme, encoded
+ * and/or decoded in RAW format.
*/
-public class DSSRawSignatureSpi extends SignatureAdapter
+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/gnu/java/security/jce/sig/EncodedKeyFactory.java b/gnu/java/security/jce/sig/EncodedKeyFactory.java
index bfee6cc76..19ec088c5 100644
--- a/gnu/java/security/jce/sig/EncodedKeyFactory.java
+++ b/gnu/java/security/jce/sig/EncodedKeyFactory.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.jce.sig;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.key.dss.DSSPrivateKey;
import gnu.java.security.key.dss.DSSPublicKey;
@@ -80,11 +80,6 @@ public class EncodedKeyFactory
{
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
{
@@ -97,21 +92,15 @@ public class EncodedKeyFactory
}
catch (InstantiationException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
catch (IllegalAccessException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(y);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
catch (InvocationTargetException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
@@ -125,9 +114,7 @@ public class EncodedKeyFactory
}
catch (ClassNotFoundException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
@@ -145,9 +132,7 @@ public class EncodedKeyFactory
}
catch (NoSuchMethodException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
@@ -163,15 +148,11 @@ public class EncodedKeyFactory
}
catch (IllegalAccessException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
catch (InvocationTargetException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
@@ -185,21 +166,15 @@ public class EncodedKeyFactory
}
catch (NoSuchMethodException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
- // Instance methods
- // --------------------------------------------------------------------------
-
protected PublicKey engineGeneratePublic(KeySpec keySpec)
throws InvalidKeySpecException
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "engineGeneratePublic()", keySpec);
-
PublicKey result = null;
if (keySpec instanceof DSAPublicKeySpec)
result = decodeDSSPublicKey((DSAPublicKeySpec) keySpec);
@@ -226,7 +201,6 @@ public class EncodedKeyFactory
log.log(Level.FINE, "Exception in DSSPublicKey.valueOf(). Ignore",
ignored);
}
-
if (! ok) // try RSA
try
{
@@ -240,7 +214,6 @@ public class EncodedKeyFactory
"Exception in GnuRSAPublicKey.valueOf(). Ignore",
ignored);
}
-
if (! ok) // try DH
result = decodeDHPublicKey(input);
}
@@ -254,7 +227,6 @@ public class EncodedKeyFactory
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "engineGeneratePrivate()", keySpec);
-
PrivateKey result = null;
if (keySpec instanceof DSAPrivateKeySpec)
result = decodeDSSPrivateKey((DSAPrivateKeySpec) keySpec);
@@ -281,7 +253,6 @@ public class EncodedKeyFactory
log.log(Level.FINE, "Exception in DSSPrivateKey.valueOf(). Ignore",
ignored);
}
-
if (! ok) // try RSA
try
{
@@ -295,7 +266,6 @@ public class EncodedKeyFactory
"Exception in GnuRSAPrivateKey.valueOf(). Ignore",
ignored);
}
-
if (! ok) // try DH
result = decodeDHPrivateKey(input);
}
@@ -328,7 +298,7 @@ public class EncodedKeyFactory
/**
* @param spec an instance of {@link DSAPublicKeySpec} to decode.
* @return an instance of {@link DSSPublicKey} constructed from the
- * information in the designated key-specification.
+ * information in the designated key-specification.
*/
private DSSPublicKey decodeDSSPublicKey(DSAPublicKeySpec spec)
{
@@ -342,7 +312,7 @@ public class EncodedKeyFactory
/**
* @param spec an instance of {@link RSAPublicKeySpec} to decode.
* @return an instance of {@link GnuRSAPublicKey} constructed from the
- * information in the designated key-specification.
+ * information in the designated key-specification.
*/
private GnuRSAPublicKey decodeRSAPublicKey(RSAPublicKeySpec spec)
{
@@ -365,7 +335,7 @@ public class EncodedKeyFactory
BigInteger p = spec.getP();
BigInteger g = spec.getG();
BigInteger y = spec.getY();
- Object[] params = new Object[] {new Integer(Registry.X509_ENCODING_ID),
+ Object[] params = new Object[] {Integer.valueOf(Registry.X509_ENCODING_ID),
null, p, g, y};
Object obj = invokeConstructor("gnu.javax.crypto.key.dh.GnuDHPublicKey",
params);
@@ -391,7 +361,7 @@ public class EncodedKeyFactory
/**
* @param spec an instance of {@link DSAPrivateKeySpec} to decode.
* @return an instance of {@link DSSPrivateKey} constructed from the
- * information in the designated key-specification.
+ * information in the designated key-specification.
*/
private PrivateKey decodeDSSPrivateKey(DSAPrivateKeySpec spec)
{
@@ -405,7 +375,7 @@ public class EncodedKeyFactory
/**
* @param spec an instance of {@link RSAPrivateCrtKeySpec} to decode.
* @return an instance of {@link GnuRSAPrivateKey} constructed from the
- * information in the designated key-specification.
+ * information in the designated key-specification.
*/
private PrivateKey decodeRSAPrivateKey(RSAPrivateCrtKeySpec spec)
{
@@ -435,7 +405,7 @@ public class EncodedKeyFactory
BigInteger p = spec.getP();
BigInteger g = spec.getG();
BigInteger x = spec.getX();
- Object[] params = new Object[] {new Integer(Registry.PKCS8_ENCODING_ID),
+ Object[] params = new Object[] {Integer.valueOf(Registry.PKCS8_ENCODING_ID),
null, p, g, x};
Object obj = invokeConstructor("gnu.javax.crypto.key.dh.GnuDHPrivateKey",
params);
diff --git a/gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java b/gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java
index edf19f627..bcbbe477d 100644
--- a/gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java
+++ b/gnu/java/security/jce/sig/KeyPairGeneratorAdapter.java
@@ -49,36 +49,30 @@ import java.security.spec.AlgorithmParameterSpec;
/**
* The implementation of a generic {@link java.security.KeyPairGenerator}
- * adapter class to wrap gnu.crypto keypair generator instances.<p>
- *
- * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for the
- * {@link java.security.KeyPairGenerator} class, which is used to generate pairs
- * of public and private keys.<p>
- *
+ * adapter class to wrap GNU keypair generator instances.
+ * <p>
+ * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
+ * the {@link java.security.KeyPairGenerator} class, which is used to generate
+ * pairs of public and private keys.
+ * <p>
* All the abstract methods in the {@link java.security.KeyPairGeneratorSpi}
- * class are implemented by this class and all its sub-classes.<p>
- *
- * In case the client does not explicitly initialize the KeyPairGenerator (via
- * a call to an <code>initialize()</code> method), the GNU Crypto provider
- * supplies (and document) default values to be used. For example, the GNU
- * Crypto provider uses a default <i>modulus</i> size (keysize) of 1024 bits for
- * the DSS (Digital Signature Standard) a.k.a <i>DSA</i>.<p>
+ * class are implemented by this class and all its sub-classes.
+ * <p>
+ * In case the client does not explicitly initialize the KeyPairGenerator (via a
+ * call to an <code>initialize()</code> method), the GNU provider supplies
+ * (and document) default values to be used. For example, the GNU provider uses
+ * a default <i>modulus</i> size (keysize) of 1024 bits for the DSS (Digital
+ * Signature Standard) a.k.a <i>DSA</i>.
*/
-public abstract class KeyPairGeneratorAdapter extends KeyPairGenerator
+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)
@@ -88,12 +82,6 @@ public abstract class KeyPairGeneratorAdapter extends KeyPairGenerator
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,
diff --git a/gnu/java/security/jce/sig/RSAKeyFactory.java b/gnu/java/security/jce/sig/RSAKeyFactory.java
index 674e2afb6..3ba49edc2 100644
--- a/gnu/java/security/jce/sig/RSAKeyFactory.java
+++ b/gnu/java/security/jce/sig/RSAKeyFactory.java
@@ -76,7 +76,6 @@ public class RSAKeyFactory
BigInteger e = spec.getPublicExponent();
return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e);
}
-
if (keySpec instanceof X509EncodedKeySpec)
{
X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
@@ -88,12 +87,9 @@ public class RSAKeyFactory
}
catch (RuntimeException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
-
throw new InvalidKeySpecException("Unsupported (public) key specification");
}
@@ -114,16 +110,6 @@ public class RSAKeyFactory
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;
@@ -135,12 +121,9 @@ public class RSAKeyFactory
}
catch (RuntimeException x)
{
- InvalidKeySpecException y = new InvalidKeySpecException();
- y.initCause(x);
- throw y;
+ throw new InvalidKeySpecException(x.getMessage(), x);
}
}
-
throw new InvalidKeySpecException("Unsupported (private) key specification");
}
@@ -156,7 +139,6 @@ public class RSAKeyFactory
BigInteger e = rsaKey.getPublicExponent();
return new RSAPublicKeySpec(n, e);
}
-
if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
{
if (key instanceof GnuRSAPublicKey)
@@ -171,13 +153,11 @@ public class RSAKeyFactory
byte[] encoded = key.getEncoded();
return new X509EncodedKeySpec(encoded);
}
-
- throw new InvalidKeySpecException("Wrong key type or unsupported (public) key specification");
+ 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))
{
@@ -192,7 +172,6 @@ public class RSAKeyFactory
BigInteger qInv = rsaKey.getCrtCoefficient();
return new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv);
}
-
if ((key instanceof RSAPrivateKey)
&& keySpec.isAssignableFrom(RSAPrivateKeySpec.class))
{
@@ -201,7 +180,6 @@ public class RSAKeyFactory
BigInteger d = rsaKey.getPrivateExponent();
return new RSAPrivateKeySpec(n, d);
}
-
if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
{
if (key instanceof GnuRSAPrivateKey)
@@ -210,17 +188,16 @@ public class RSAKeyFactory
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 (private) key specification");
}
-
- throw new InvalidKeySpecException("Wrong key type or unsupported key specification");
+ throw new InvalidKeySpecException(
+ "Wrong key type or unsupported key specification");
}
protected Key engineTranslateKey(Key key) throws InvalidKeyException
@@ -235,7 +212,6 @@ public class RSAKeyFactory
BigInteger e = rsaKey.getPublicExponent();
return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e);
}
-
if (key instanceof RSAPrivateCrtKey)
{
RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) key;
@@ -250,16 +226,6 @@ public class RSAKeyFactory
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/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java b/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java
index 24dc7c501..ef53b8115 100644
--- a/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java
+++ b/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java
@@ -49,43 +49,29 @@ import java.util.HashMap;
/**
* The implementation of a {@link java.security.KeyPairGenerator} adapter class
- * to wrap gnu.crypto RSA keypair generator instances.<p>
- *
- * In case the client does not explicitly initialize the KeyPairGenerator (via
- * a call to an <code>initialize()</code> method), the GNU Crypto provider
- * uses a default <i>modulus</i> size (keysize) of 1024 bits.<p>
+ * to wrap GNU RSA keypair generator instances.
+ * <p>
+ * In case the client does not explicitly initialize the KeyPairGenerator (via a
+ * call to an <code>initialize()</code> method), the GNU provider uses a
+ * default <i>modulus</i> size (keysize) of 1024 bits.
*/
-public class RSAKeyPairGeneratorSpi extends KeyPairGeneratorAdapter
+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));
+ attributes.put(RSAKeyPairGenerator.MODULUS_LENGTH, Integer.valueOf(keysize));
if (random != null)
- {
- attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
- }
+ attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
- new Integer(Registry.ASN1_ENCODING_ID));
+ Integer.valueOf(Registry.ASN1_ENCODING_ID));
adaptee.setup(attributes);
}
@@ -95,21 +81,16 @@ public class RSAKeyPairGeneratorSpi extends KeyPairGeneratorAdapter
HashMap attributes = new HashMap();
if (params != null)
{
- if (!(params instanceof RSAKeyGenParameterSpec))
- {
- throw new InvalidAlgorithmParameterException("params");
- }
+ 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.SOURCE_OF_RANDOMNESS, random);
attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
- new Integer(Registry.ASN1_ENCODING_ID));
+ Integer.valueOf(Registry.ASN1_ENCODING_ID));
adaptee.setup(attributes);
}
}
diff --git a/gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java b/gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java
index f3548d884..f1ccbde4d 100644
--- a/gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java
+++ b/gnu/java/security/jce/sig/RSAPSSRawSignatureSpi.java
@@ -42,26 +42,15 @@ import gnu.java.security.Registry;
import gnu.java.security.sig.rsa.RSAPSSSignatureRawCodec;
/**
- * The implementation of <i>Service Provider Interface</i> (<b>SPI</b>) adapter
- * for the RSA-PSS signature scheme, encoded and/or decoded in RAW format.<p>
+ * The implementation of <i>Service Provider Interface</i> (<b>SPI</b>)
+ * adapter for the RSA-PSS signature scheme, encoded and/or decoded in RAW
+ * format.
*/
-public class RSAPSSRawSignatureSpi extends SignatureAdapter
+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/gnu/java/security/jce/sig/SignatureAdapter.java b/gnu/java/security/jce/sig/SignatureAdapter.java
index 724cc260e..a65d727ee 100644
--- a/gnu/java/security/jce/sig/SignatureAdapter.java
+++ b/gnu/java/security/jce/sig/SignatureAdapter.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.jce.sig;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.sig.BaseSignature;
import gnu.java.security.sig.ISignature;
import gnu.java.security.sig.ISignatureCodec;
@@ -58,38 +58,34 @@ import java.util.logging.Logger;
/**
* The implementation of a generic {@link java.security.Signature} adapter class
- * to wrap gnu.crypto signature instances.<p>
- *
- * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) 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.<p>
- *
- * All the abstract methods in the {@link java.security.SignatureSpi} class are
- * implemented by this class and all its sub-classes.<p>
- *
+ * to wrap GNU signature instances.
+ * <p>
+ * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) 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.
+ * <p>
+ * All the abstract methods in the {@link SignatureSpi} class are implemented by
+ * this class and all its sub-classes.
+ * <p>
* All the implementations which subclass this object, and which are serviced by
- * the GNU Crypto provider implement the {@link java.lang.Cloneable} interface.<p>
+ * the GNU provider implement the {@link Cloneable} interface.
*/
-class SignatureAdapter extends SignatureSpi implements Cloneable
+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.<p>
- *
+ * Trivial protected constructor.
+ *
* @param sigName the canonical name of the signature scheme.
* @param codec the signature codec engine to use with this scheme.
*/
@@ -99,8 +95,8 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
}
/**
- * Private constructor for cloning purposes.<p>
- *
+ * 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.
*/
@@ -112,12 +108,6 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
this.codec = codec;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // java.security.SignatureSpi interface implementation
- // -------------------------------------------------------------------------
-
public Object clone()
{
return new SignatureAdapter((ISignature) adaptee.clone(), codec);
@@ -133,7 +123,7 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
}
catch (IllegalArgumentException x)
{
- throw new InvalidKeyException(String.valueOf(x));
+ throw new InvalidKeyException(x.getMessage(), x);
}
}
@@ -147,7 +137,7 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
}
catch (IllegalArgumentException x)
{
- throw new InvalidKeyException(String.valueOf(x));
+ throw new InvalidKeyException(x.getMessage(), x);
}
}
@@ -163,7 +153,7 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
}
catch (IllegalArgumentException x)
{
- throw new InvalidKeyException(String.valueOf(x));
+ throw new InvalidKeyException(x.getMessage(), x);
}
}
@@ -175,7 +165,7 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
}
catch (IllegalStateException x)
{
- throw new SignatureException(String.valueOf(x));
+ throw new SignatureException(x.getMessage(), x);
}
}
@@ -188,7 +178,7 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
}
catch (IllegalStateException x)
{
- throw new SignatureException(String.valueOf(x));
+ throw new SignatureException(x.getMessage(), x);
}
}
@@ -201,9 +191,8 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
}
catch (IllegalStateException x)
{
- throw new SignatureException(String.valueOf(x));
+ throw new SignatureException(x.getMessage(), x);
}
-
byte[] result = codec.encodeSignature(signature);
return result;
}
@@ -214,9 +203,7 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
byte[] signature = this.engineSign();
int result = signature.length;
if (result > len)
- {
- throw new SignatureException("len");
- }
+ throw new SignatureException("Not enough room to store signature");
System.arraycopy(signature, 0, outbuf, offset, result);
return result;
@@ -226,7 +213,6 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "engineVerify");
-
Object signature = codec.decodeSignature(sigBytes);
boolean result = false;
try
@@ -235,10 +221,11 @@ class SignatureAdapter extends SignatureSpi implements Cloneable
}
catch (IllegalStateException x)
{
- throw new SignatureException(String.valueOf(x));
+ throw new SignatureException(x.getMessage(), x);
}
if (Configuration.DEBUG)
- log.exiting(this.getClass().getName(), "engineVerify", Boolean.valueOf(result));
+ log.exiting(this.getClass().getName(), "engineVerify",
+ Boolean.valueOf(result));
return result;
}
diff --git a/gnu/java/security/key/IKeyPairCodec.java b/gnu/java/security/key/IKeyPairCodec.java
index 965a317d4..f09743d2b 100644
--- a/gnu/java/security/key/IKeyPairCodec.java
+++ b/gnu/java/security/key/IKeyPairCodec.java
@@ -44,16 +44,13 @@ import java.security.PrivateKey;
import java.security.PublicKey;
/**
- * <p>The visible methods of an object that knows how to encode and decode
+ * 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.</p>
+ * (b) re-creating their internal Java representation from external sources.
*/
public interface IKeyPairCodec
{
- // Constants
- // -------------------------------------------------------------------------
-
/** Constant identifying the <i>Raw</i> encoding format. */
int RAW_FORMAT = Registry.RAW_ENCODING_ID;
@@ -69,62 +66,59 @@ public interface IKeyPairCodec
*/
int ASN1_FORMAT = Registry.ASN1_ENCODING_ID;
- // Method(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the unique identifier (within this library) of the format used
- * to externalise public and private keys.</p>
- *
+ * 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();
/**
- * <p>Encodes an instance of a public key for storage or transmission purposes.</p>
- *
+ * 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.
+ * according to the format supported by this codec.
* @exception IllegalArgumentException if the designated key is not supported
- * by this codec.
+ * by this codec.
*/
byte[] encodePublicKey(PublicKey key);
/**
- * <p>Encodes an instance of a private key for storage or transmission purposes.</p>
- *
+ * 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.
+ * according to the format supported by this codec.
* @exception IllegalArgumentException if the designated key is not supported
- * by this codec.
+ * by this codec.
*/
byte[] encodePrivateKey(PrivateKey key);
/**
- * <p>Decodes an instance of an external public key into its native Java
- * representation.</p>
- *
+ * 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.
+ * 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.
+ * contain a known representation of a public key for the format
+ * supported by the concrete codec.
*/
PublicKey decodePublicKey(byte[] input);
/**
- * <p>Decodes an instance of an external private key into its native Java
- * representation.</p>
- *
+ * 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.
+ * 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.
+ * contain a known representation of a private key for the format
+ * supported by the concrete codec.
*/
PrivateKey decodePrivateKey(byte[] input);
}
diff --git a/gnu/java/security/key/IKeyPairGenerator.java b/gnu/java/security/key/IKeyPairGenerator.java
index 2e0b29928..8d7842e93 100644
--- a/gnu/java/security/key/IKeyPairGenerator.java
+++ b/gnu/java/security/key/IKeyPairGenerator.java
@@ -42,38 +42,31 @@ import java.security.KeyPair;
import java.util.Map;
/**
- * The visible methods of every asymmetric keypair generator.<p>
+ * The visible methods of every asymmetric keypair generator.
*/
public interface IKeyPairGenerator
{
-
- // Constants
- // -------------------------------------------------------------------------
-
- // Methods
- // -------------------------------------------------------------------------
-
/**
- * Returns the canonical name of this keypair generator.<p>
- *
+ * 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.<p>
- *
+ * [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.
+ * instance.
* @exception IllegalArgumentException if at least one of the mandatory
- * attributes is missing or an invalid value was specified.
+ * 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/gnu/java/security/key/KeyPairCodecFactory.java b/gnu/java/security/key/KeyPairCodecFactory.java
index 1a8b8aa03..e68a7d65c 100644
--- a/gnu/java/security/key/KeyPairCodecFactory.java
+++ b/gnu/java/security/key/KeyPairCodecFactory.java
@@ -207,10 +207,8 @@ public class KeyPairCodecFactory
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;
}
diff --git a/gnu/java/security/key/KeyPairGeneratorFactory.java b/gnu/java/security/key/KeyPairGeneratorFactory.java
index 8c2f348c9..4872fc3d1 100644
--- a/gnu/java/security/key/KeyPairGeneratorFactory.java
+++ b/gnu/java/security/key/KeyPairGeneratorFactory.java
@@ -48,68 +48,48 @@ import java.util.HashSet;
import java.util.Set;
/**
- * <p>A Factory to instantiate asymmetric keypair generators.</p>
+ * A Factory to instantiate asymmetric keypair generators.
*/
public class KeyPairGeneratorFactory
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial constructor to enforce Singleton pattern. */
private KeyPairGeneratorFactory()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns an instance of a keypair generator given its name.</p>
- *
+ * 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, or <code>null</code> if none
- * found.
+ * @return an instance of the keypair generator, or <code>null</code> if
+ * none found.
*/
public static IKeyPairGenerator getInstance(String name)
{
if (name == null)
- {
- return null;
- }
+ return null;
name = name.trim();
IKeyPairGenerator result = null;
if (name.equalsIgnoreCase(Registry.DSA_KPG)
|| name.equalsIgnoreCase(Registry.DSS_KPG))
- {
- result = new DSSKeyPairGenerator();
- }
+ result = new DSSKeyPairGenerator();
else if (name.equalsIgnoreCase(Registry.RSA_KPG))
- {
- result = new RSAKeyPairGenerator();
- }
+ result = new RSAKeyPairGenerator();
else if (name.equalsIgnoreCase(Registry.DH_KPG))
- {
- result = makeInstance ("gnu.javax.crypto.key.dh.GnuDHKeyPairGenerator");
- }
+ result = makeInstance("gnu.javax.crypto.key.dh.GnuDHKeyPairGenerator");
else if (name.equalsIgnoreCase(Registry.SRP_KPG))
- {
- result = makeInstance ("gnu.javax.crypto.key.srp6.SRPKeyPairGenerator");
- }
+ result = makeInstance("gnu.javax.crypto.key.srp6.SRPKeyPairGenerator");
return result;
}
/**
- * <p>Returns a {@link Set} of keypair generator names supported by this
+ * Returns a {@link Set} of keypair generator names supported by this
* <i>Factory</i>. Those keypair generators may be used in conjunction with
- * the digital signature schemes with appendix supported by this library.</p>
- *
+ * the digital signature schemes with appendix supported by this library.
+ *
* @return a {@link Set} of keypair generator names (Strings).
*/
public static final Set getNames()
@@ -120,26 +100,21 @@ public class KeyPairGeneratorFactory
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)
+ 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]);
+ Class c = Class.forName(clazz);
+ Constructor ctor = c.getConstructor(new Class[0]);
+ return (IKeyPairGenerator) ctor.newInstance(new Object[0]);
}
catch (Exception x)
{
throw new IllegalArgumentException(
- "strong crypto key pair generator not available: " + clazz,
- x);
+ "strong crypto key pair generator not available: " + clazz, x);
}
}
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/key/dss/DSSKey.java b/gnu/java/security/key/dss/DSSKey.java
index 40aaea893..29205605b 100644
--- a/gnu/java/security/key/dss/DSSKey.java
+++ b/gnu/java/security/key/dss/DSSKey.java
@@ -49,63 +49,61 @@ import java.security.interfaces.DSAParams;
import java.security.spec.DSAParameterSpec;
/**
- * <p>A base asbtract class for both public and private DSS (Digital Signature
+ * A base asbtract class for both public and private DSS (Digital Signature
* Standard) keys. It encapsulates the three DSS numbers: <code>p</code>,
- * <code>q</code> and <code>g</code>.</p>
- *
- * <p>According to the JDK, cryptographic <i>Keys</i> all have a <i>format</i>.
+ * <code>q</code> and <code>g</code>.
+ * <p>
+ * According to the JDK, cryptographic <i>Keys</i> all have a <i>format</i>.
* The format used in this implementation is called <i>Raw</i>, 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 <code>getEncoded()</code> methods of each of the private and
- * public keys.</p>
- *
+ * of the byte sequences and the implementation details are given in each of the
+ * relevant <code>getEncoded()</code> methods of each of the private and
+ * public keys.
+ *
* @see DSSPrivateKey#getEncoded
* @see DSSPublicKey#getEncoded
*/
-public abstract class DSSKey implements Key, DSAKey
+public abstract class DSSKey
+ implements Key, DSAKey
{
- // Constants and variables
- // -------------------------------------------------------------------------
-
/**
- * A prime modulus, where <code>2<sup>L-1</sup> &lt; p &lt; 2<sup>L</sup></code>
- * for <code>512 &lt;= L &lt;= 1024</code> and <code>L</code> a multiple of
+ * A prime modulus, where
+ * <code>2<sup>L-1</sup> &lt; p &lt; 2<sup>L</sup></code> for
+ * <code>512 &lt;= L &lt;= 1024</code> and <code>L</code> a multiple of
* <code>64</code>.
*/
protected final BigInteger p;
/**
- * A prime divisor of <code>p - 1</code>, where <code>2<sup>159</sup> &lt; q
+ * A prime divisor of <code>p - 1</code>, where
+ * <code>2<sup>159</sup> &lt; q
* &lt; 2<sup>160</sup></code>.
*/
protected final BigInteger q;
/**
- * <code>g = h<sup>(p-1)</sup>/q mod p</code>, where <code>h</code> is any
- * integer with <code>1 &lt; h &lt; p - 1</code> such that <code>h<sup>
- * (p-1)</sup>/q mod p > 1</code> (<code>g</code> has order <code>q mod p
+ * <code>g = h<sup>(p-1)</sup>/q mod p</code>, where <code>h</code> is
+ * any integer with <code>1 &lt; h &lt; p - 1</code> such that <code>h<sup>
+ * (p-1)</sup>/q mod p > 1</code> (<code>g</code>
+ * has order <code>q mod p
* </code>).
*/
protected final BigInteger g;
/**
- * Identifier of the default encoding format to use when externalizing the
- * key material.
+ * Identifier of the default encoding format to use when externalizing the key
+ * material.
*/
protected final int defaultFormat;
/** String representation of this key. Cached for speed. */
private transient String str;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Trivial protected constructor.
*
* @param defaultFormat the identifier of the encoding format to use by
- * default when externalizing the key.
+ * default when externalizing the key.
* @param p the DSS parameter <code>p</code>.
* @param q the DSS parameter <code>q</code>.
* @param g the DSS parameter <code>g</code>.
@@ -121,21 +119,11 @@ public abstract class DSSKey implements Key, DSAKey
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;
@@ -152,27 +140,23 @@ public abstract class DSSKey implements Key, DSAKey
return FormatUtil.getEncodingShortName(defaultFormat);
}
- // Other instance methods --------------------------------------------------
-
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
+ * Returns <code>true</code> if the designated object is an instance of
* {@link DSAKey} and has the same DSS (Digital Signature Standard) parameter
- * values as this one.</p>
- *
+ * values as this one.
+ *
* @param obj the other non-null DSS key to compare to.
- * @return <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> 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;
- }
+ return false;
+
+ if (! (obj instanceof DSAKey))
+ return false;
+
DSAKey that = (DSAKey) obj;
return p.equals(that.getParams().getP())
&& q.equals(that.getParams().getQ())
@@ -184,18 +168,15 @@ public abstract class DSSKey implements Key, DSAKey
if (str == null)
{
String ls = SystemProperties.getProperty("line.separator");
- str = new StringBuilder().append(ls)
- .append("defaultFormat=").append(defaultFormat).append(",").append(ls)
- .append("p=0x").append(p.toString(16)).append(",").append(ls)
- .append("q=0x").append(q.toString(16)).append(",").append(ls)
- .append("g=0x").append(g.toString(16))
- .toString();
+ str = new StringBuilder(ls)
+ .append("defaultFormat=").append(defaultFormat).append(",").append(ls)
+ .append("p=0x").append(p.toString(16)).append(",").append(ls)
+ .append("q=0x").append(q.toString(16)).append(",").append(ls)
+ .append("g=0x").append(g.toString(16))
+ .toString();
}
-
return str;
}
- // abstract methods to be implemented by subclasses ------------------------
-
public abstract byte[] getEncoded(int format);
}
diff --git a/gnu/java/security/key/dss/DSSKeyPairGenerator.java b/gnu/java/security/key/dss/DSSKeyPairGenerator.java
index ca24f36c5..1bad0b62e 100644
--- a/gnu/java/security/key/dss/DSSKeyPairGenerator.java
+++ b/gnu/java/security/key/dss/DSSKeyPairGenerator.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.key.dss;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.hash.Sha160;
import gnu.java.security.key.IKeyPairGenerator;
@@ -54,55 +54,54 @@ import java.util.Map;
import java.util.logging.Logger;
/**
- * <p>A key-pair generator for asymetric keys to use in conjunction with the DSS
- * (Digital Signature Standard).</p>
- *
- * References:<br>
+ * A key-pair generator for asymetric keys to use in conjunction with the DSS
+ * (Digital Signature Standard).
+ * <p>
+ * References:
+ * <p>
* <a href="http://www.itl.nist.gov/fipspubs/fip186.htm">Digital Signature
- * Standard (DSS)</a>, Federal Information Processing Standards Publication 186.
- * National Institute of Standards and Technology.
+ * Standard (DSS)</a>, Federal Information Processing Standards Publication
+ * 186. National Institute of Standards and Technology.
*/
-public class DSSKeyPairGenerator implements IKeyPairGenerator
+public class DSSKeyPairGenerator
+ implements IKeyPairGenerator
{
private static final Logger log = Logger.getLogger(DSSKeyPairGenerator.class.getName());
+
/** The BigInteger constant 2. */
- private static final BigInteger TWO = new BigInteger("2");
+ private static final BigInteger TWO = BigInteger.valueOf(2L);
/** Property name of the length (Integer) of the modulus (p) of a DSS key. */
public static final String MODULUS_LENGTH = "gnu.crypto.dss.L";
/**
* Property name of the Boolean indicating wether or not to use default pre-
- * computed values of <code>p</code>, <code>q</code> and <code>g</code> for
- * a given modulus length. The ultimate behaviour of this generator with
+ * computed values of <code>p</code>, <code>q</code> and <code>g</code>
+ * 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}:
- *
* <ol>
- * <li>If this property is {@link Boolean#FALSE} then this generator
- * will accept being setup for generating parameters for any modulus length
- * provided the modulus length is between <code>512</code> and
- * <code>1024</code>, and is of the form <code>512 + 64 * n</code>. In
- * addition, a new paramter set will always be generated; i.e. no pre-
- * computed values are used.</li>
- *
- * <li>If this property is {@link Boolean#TRUE} and the value of
- * {@link #STRICT_DEFAULTS} is also {@link Boolean#TRUE} then this generator
- * will only accept being setup for generating parameters for modulus
- * lengths of <code>512</code>, <code>768</code> and <code>1024</code>. Any
- * other value, of the modulus length, even if between <code>512</code> and
- * <code>1024</code>, and of the form <code>512 + 64 * n</code>, will cause
- * an {@link IllegalArgumentException} to be thrown. When those modulus
- * length (<code>512</code>, <code>768</code>, and <code>1024</code>) are
- * specified, the paramter set is always the same.</li>
- *
- * <li>Finally, if this property is {@link Boolean#TRUE} and the value of
- * {@link #STRICT_DEFAULTS} is {@link Boolean#FALSE} then this generator
- * will behave as in point 1 above, except that it will use pre-computed
- * values when possible; i.e. the modulus length is one of <code>512</code>,
- * <code>768</code>, or <code>1024</code>.</li>
+ * <li>If this property is {@link Boolean#FALSE} then this generator will
+ * accept being setup for generating parameters for any modulus length
+ * provided the modulus length is between <code>512</code> and
+ * <code>1024</code>, and is of the form <code>512 + 64 * n</code>. In
+ * addition, a new paramter set will always be generated; i.e. no pre-
+ * computed values are used.</li>
+ * <li>If this property is {@link Boolean#TRUE} and the value of
+ * {@link #STRICT_DEFAULTS} is also {@link Boolean#TRUE} then this generator
+ * will only accept being setup for generating parameters for modulus lengths
+ * of <code>512</code>, <code>768</code> and <code>1024</code>. Any
+ * other value, of the modulus length, even if between <code>512</code> and
+ * <code>1024</code>, and of the form <code>512 + 64 * n</code>, will
+ * cause an {@link IllegalArgumentException} to be thrown. When those modulus
+ * length (<code>512</code>, <code>768</code>, and <code>1024</code>)
+ * are specified, the paramter set is always the same.</li>
+ * <li>Finally, if this property is {@link Boolean#TRUE} and the value of
+ * {@link #STRICT_DEFAULTS} is {@link Boolean#FALSE} then this generator will
+ * behave as in point 1 above, except that it will use pre-computed values
+ * when possible; i.e. the modulus length is one of <code>512</code>,
+ * <code>768</code>, or <code>1024</code>.</li>
* </ol>
- *
* The default value of this property is {@link Boolean#TRUE}.
*/
public static final String USE_DEFAULTS = "gnu.crypto.dss.use.defaults";
@@ -127,8 +126,8 @@ public class DSSKeyPairGenerator implements IKeyPairGenerator
/**
* Property name of an optional {@link DSAParameterSpec} instance to use for
- * this generator's <code>p</code>, <code>q</code>, and <code>g</code> values.
- * The default is to generate these values or use pre-computed ones,
+ * this generator's <code>p</code>, <code>q</code>, and <code>g</code>
+ * values. The default is to generate these values or use pre-computed ones,
* depending on the value of the <code>USE_DEFAULTS</code> attribute.
*/
public static final String DSS_PARAMETERS = "gnu.crypto.dss.params";
@@ -147,55 +146,41 @@ public class DSSKeyPairGenerator implements IKeyPairGenerator
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 };
+ 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));
-
+ 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));
-
+ 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));
+ 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);
@@ -225,31 +210,18 @@ public class DSSKeyPairGenerator implements IKeyPairGenerator
/** 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;
}
/**
- * <p>Configures this instance.</p>
- *
+ * 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
- * <code>512 + 64j</code>.
+ * @exception IllegalArgumentException if the designated MODULUS_LENGTH value
+ * is not greater than 512, less than 1024 and not of the form
+ * <code>512 + 64j</code>.
*/
public void setup(Map attributes)
{
@@ -262,9 +234,7 @@ public class DSSKeyPairGenerator implements IKeyPairGenerator
// should we use the default pre-computed params?
Boolean useDefaults = (Boolean) attributes.get(USE_DEFAULTS);
if (useDefaults == null)
- {
- useDefaults = Boolean.TRUE;
- }
+ useDefaults = Boolean.TRUE;
Boolean strictDefaults = (Boolean) attributes.get(STRICT_DEFAULTS);
if (strictDefaults == null)
@@ -316,16 +286,12 @@ public class DSSKeyPairGenerator implements IKeyPairGenerator
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();
-
+ 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);
@@ -353,66 +319,55 @@ public class DSSKeyPairGenerator implements IKeyPairGenerator
log.fine("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 --------------------------------------------------
-
/**
- * <p>This method applies the following algorithm described in 3.1 of
- * FIPS-186:</p>
- *
+ * This method applies the following algorithm described in 3.1 of FIPS-186:
* <ol>
- * <li>XSEED = optional user input.</li>
- * <li>XVAL = (XKEY + XSEED) mod 2<sup>b</sup>.</li>
- * <li>x = G(t, XVAL) mod q.</li>
- * <li>XKEY = (1 + XKEY + x) mod 2<sup>b</sup>.</li>
+ * <li>XSEED = optional user input.</li>
+ * <li>XVAL = (XKEY + XSEED) mod 2<sup>b</sup>.</li>
+ * <li>x = G(t, XVAL) mod q.</li>
+ * <li>XKEY = (1 + XKEY + x) mod 2<sup>b</sup>.</li>
* </ol>
- *
- * <p>Where <code>b</code> is the length of a secret b-bit seed-key (XKEY).</p>
- *
- * <p>Note that in this implementation, XSEED, the optional user input, is
- * always zero.</p>
+ * <p>
+ * Where <code>b</code> is the length of a secret b-bit seed-key (XKEY).
+ * <p>
+ * 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] >>> 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;
}
/**
- * <p>Fills the designated byte array with random data.</p>
- *
+ * 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);
- }
+ rnd.nextBytes(buffer);
else
getDefaultPRNG().nextBytes(buffer);
}
diff --git a/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java b/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
index 166178fe4..06b8e849a 100644
--- a/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
+++ b/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.key.dss;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.Registry;
import gnu.java.security.der.DER;
@@ -159,11 +159,10 @@ public class DSSKeyPairPKCS8Codec
}
catch (IOException e)
{
- InvalidParameterException y = new InvalidParameterException();
+ InvalidParameterException y = new InvalidParameterException(e.getMessage());
y.initCause(e);
throw y;
}
-
return result;
}
@@ -187,7 +186,6 @@ public class DSSKeyPairPKCS8Codec
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "decodePrivateKey");
-
if (input == null)
throw new InvalidParameterException("Input bytes MUST NOT be null");
@@ -240,7 +238,7 @@ public class DSSKeyPairPKCS8Codec
}
catch (IOException e)
{
- InvalidParameterException y = new InvalidParameterException();
+ InvalidParameterException y = new InvalidParameterException(e.getMessage());
y.initCause(e);
throw y;
}
diff --git a/gnu/java/security/key/dss/DSSKeyPairRawCodec.java b/gnu/java/security/key/dss/DSSKeyPairRawCodec.java
index 7c5491d6f..b1135b75f 100644
--- a/gnu/java/security/key/dss/DSSKeyPairRawCodec.java
+++ b/gnu/java/security/key/dss/DSSKeyPairRawCodec.java
@@ -47,91 +47,72 @@ import java.security.PrivateKey;
import java.security.PublicKey;
/**
- * <p>An object that implements the {@link IKeyPairCodec} operations for the
- * <i>Raw</i> format to use with DSS keypairs.</p>
+ * An object that implements the {@link IKeyPairCodec} operations for the
+ * <i>Raw</i> format to use with DSS keypairs.
*/
-public class DSSKeyPairRawCodec implements IKeyPairCodec
+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;
}
/**
- * <p>Returns the encoded form of the designated DSS (Digital Signature
- * Standard) public key according to the <i>Raw</i> format supported by
- * this library.</p>
- *
- * <p>The <i>Raw</i> format for a DSA public key, in this implementation, is
- * a byte sequence consisting of the following:</p>
+ * Returns the encoded form of the designated DSS (Digital Signature Standard)
+ * public key according to the <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for a DSA public key, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_DSS_PUBLIC_KEY},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the DSA parameter
- * <code>p</code> in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSA parameter
- * <code>p</code>,</li>
- * <li>4-byte count of following bytes representing the DSA parameter
- * <code>q</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSA parameter
- * <code>q</code>,</li>
- * <li>4-byte count of following bytes representing the DSA parameter
- * <code>g</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSA parameter
- * <code>g</code>,</li>
- * <li>4-byte count of following bytes representing the DSA parameter
- * <code>y</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSA parameter
- * <code>y</code>,</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_DSS_PUBLIC_KEY},
+ * <li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the DSA parameter
+ * <code>p</code> in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSA parameter <code>p</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DSA parameter
+ * <code>q</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSA parameter <code>q</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DSA parameter
+ * <code>g</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSA parameter <code>g</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DSA parameter
+ * <code>y</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSA parameter <code>y</code>,
+ * </li>
* </ol>
- *
+ *
* @param key the key to encode.
* @return the <i>Raw</i> format encoding of the designated key.
* @throws IllegalArgumentException if the designated key is not a DSS
- * (Digital Signature Standard) one.
+ * (Digital Signature Standard) one.
* @see Registry#MAGIC_RAW_DSS_PUBLIC_KEY
*/
public byte[] encodePublicKey(PublicKey key)
{
- if (!(key instanceof DSSPublicKey))
- {
- throw new IllegalArgumentException("key");
- }
+ if (! (key instanceof DSSPublicKey))
+ throw new IllegalArgumentException("key");
DSSPublicKey dssKey = (DSSPublicKey) key;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
// magic
baos.write(Registry.MAGIC_RAW_DSS_PUBLIC_KEY[0]);
baos.write(Registry.MAGIC_RAW_DSS_PUBLIC_KEY[1]);
baos.write(Registry.MAGIC_RAW_DSS_PUBLIC_KEY[2]);
baos.write(Registry.MAGIC_RAW_DSS_PUBLIC_KEY[3]);
-
// version
baos.write(0x01);
-
// p
byte[] buffer = dssKey.getParams().getP().toByteArray();
int length = buffer.length;
@@ -140,7 +121,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// q
buffer = dssKey.getParams().getQ().toByteArray();
length = buffer.length;
@@ -149,7 +129,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// g
buffer = dssKey.getParams().getG().toByteArray();
length = buffer.length;
@@ -158,7 +137,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// y
buffer = dssKey.getY().toByteArray();
length = buffer.length;
@@ -167,7 +145,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -178,112 +155,106 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|| k[1] != Registry.MAGIC_RAW_DSS_PUBLIC_KEY[1]
|| k[2] != Registry.MAGIC_RAW_DSS_PUBLIC_KEY[2]
|| k[3] != Registry.MAGIC_RAW_DSS_PUBLIC_KEY[3])
- {
- throw new IllegalArgumentException("magic");
- }
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
- int i = 5;
+ 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);
+ 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);
+ 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);
-
// g
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ 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 g = new BigInteger(1, buffer);
-
// y
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ 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 y = new BigInteger(1, buffer);
-
return new DSSPublicKey(p, q, g, y);
}
/**
- * <p>Returns the encoded form of the designated DSS (Digital Signature
- * Standard) private key according to the <i>Raw</i> format supported by
- * this library.</p>
- *
- * <p>The <i>Raw</i> format for a DSA private key, in this implementation, is
- * a byte sequence consisting of the following:</p>
+ * Returns the encoded form of the designated DSS (Digital Signature Standard)
+ * private key according to the <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for a DSA private key, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_DSS_PRIVATE_KEY},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the DSA parameter
- * <code>p</code> in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSA parameter
- * <code>p</code>,</li>
- * <li>4-byte count of following bytes representing the DSA parameter
- * <code>q</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSA parameter
- * <code>q</code>,</li>
- * <li>4-byte count of following bytes representing the DSA parameter
- * <code>g</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSA parameter
- * <code>g</code>,</li>
- * <li>4-byte count of following bytes representing the DSA parameter
- * <code>x</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSA parameter
- * <code>x</code>,</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_DSS_PRIVATE_KEY},
+ * <li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the DSA parameter
+ * <code>p</code> in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSA parameter <code>p</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DSA parameter
+ * <code>q</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSA parameter <code>q</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DSA parameter
+ * <code>g</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSA parameter <code>g</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DSA parameter
+ * <code>x</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSA parameter <code>x</code>,
+ * </li>
* </ol>
- *
+ *
* @param key the key to encode.
* @return the <i>Raw</i> format encoding of the designated key.
* @throws IllegalArgumentException if the designated key is not a DSS
- * (Digital Signature Standard) one.
+ * (Digital Signature Standard) one.
*/
public byte[] encodePrivateKey(PrivateKey key)
{
- if (!(key instanceof DSSPrivateKey))
- {
- throw new IllegalArgumentException("key");
- }
+ if (! (key instanceof DSSPrivateKey))
+ throw new IllegalArgumentException("key");
DSSPrivateKey dssKey = (DSSPrivateKey) key;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
// magic
baos.write(Registry.MAGIC_RAW_DSS_PRIVATE_KEY[0]);
baos.write(Registry.MAGIC_RAW_DSS_PRIVATE_KEY[1]);
baos.write(Registry.MAGIC_RAW_DSS_PRIVATE_KEY[2]);
baos.write(Registry.MAGIC_RAW_DSS_PRIVATE_KEY[3]);
-
// version
baos.write(0x01);
-
// p
byte[] buffer = dssKey.getParams().getP().toByteArray();
int length = buffer.length;
@@ -292,7 +263,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// q
buffer = dssKey.getParams().getQ().toByteArray();
length = buffer.length;
@@ -301,7 +271,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// g
buffer = dssKey.getParams().getG().toByteArray();
length = buffer.length;
@@ -310,7 +279,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// x
buffer = dssKey.getX().toByteArray();
length = buffer.length;
@@ -319,7 +287,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -330,52 +297,51 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|| k[1] != Registry.MAGIC_RAW_DSS_PRIVATE_KEY[1]
|| k[2] != Registry.MAGIC_RAW_DSS_PRIVATE_KEY[2]
|| k[3] != Registry.MAGIC_RAW_DSS_PRIVATE_KEY[3])
- {
- throw new IllegalArgumentException("magic");
- }
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
- int i = 5;
+ 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);
+ 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);
+ 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);
-
// g
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ 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 g = new BigInteger(1, buffer);
-
// x
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ 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 x = new BigInteger(1, buffer);
-
return new DSSPrivateKey(p, q, g, x);
}
}
diff --git a/gnu/java/security/key/dss/DSSKeyPairX509Codec.java b/gnu/java/security/key/dss/DSSKeyPairX509Codec.java
index 516ef92af..5ddd6e0d6 100644
--- a/gnu/java/security/key/dss/DSSKeyPairX509Codec.java
+++ b/gnu/java/security/key/dss/DSSKeyPairX509Codec.java
@@ -157,11 +157,10 @@ public class DSSKeyPairX509Codec
}
catch (IOException x)
{
- InvalidParameterException e = new InvalidParameterException();
+ InvalidParameterException e = new InvalidParameterException(x.getMessage());
e.initCause(x);
throw e;
}
-
return result;
}
@@ -230,11 +229,10 @@ public class DSSKeyPairX509Codec
}
catch (IOException x)
{
- InvalidParameterException e = new InvalidParameterException();
+ InvalidParameterException e = new InvalidParameterException(x.getMessage());
e.initCause(x);
throw e;
}
-
return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y);
}
diff --git a/gnu/java/security/key/dss/DSSPrivateKey.java b/gnu/java/security/key/dss/DSSPrivateKey.java
index a9374557b..6c64987bc 100644
--- a/gnu/java/security/key/dss/DSSPrivateKey.java
+++ b/gnu/java/security/key/dss/DSSPrivateKey.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.key.dss;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.classpath.SystemProperties;
import gnu.java.security.Registry;
import gnu.java.security.key.IKeyPairCodec;
@@ -48,24 +48,23 @@ import java.security.PrivateKey;
import java.security.interfaces.DSAPrivateKey;
/**
- * <p>An object that embodies a DSS (Digital Signature Standard) private key.</p>
- *
+ * An object that embodies a DSS (Digital Signature Standard) private key.
+ *
* @see #getEncoded
*/
-public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey
+public class DSSPrivateKey
+ extends DSSKey
+ implements PrivateKey, DSAPrivateKey
{
/**
- * <p>A randomly or pseudorandomly generated integer with <code>0 &lt; x &lt;
- * q</code>.</p>
+ * A randomly or pseudorandomly generated integer with <code>0 &lt; x &lt;
+ * q</code>.
*/
private final BigInteger x;
/** String representation of this key. Cached for speed. */
private transient String str;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Convenience constructor. Calls the constructor with 5 arguments passing
* {@link Registry#RAW_ENCODING_ID} as the identifier of the preferred
@@ -100,13 +99,9 @@ public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey
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 <code>encodePrivateKey()</code>
* method of a DSS keypair codec object (an instance implementing
@@ -131,30 +126,22 @@ public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey
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 --------------------------------------------------
-
/**
- * <p>Returns the encoded form of this private key according to the
- * designated format.</p>
- *
+ * 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.
+ * format.
* @exception IllegalArgumentException if the format is not supported.
* @see DSSKeyPairRawCodec
*/
@@ -177,24 +164,22 @@ public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
+ * Returns <code>true</code> if the designated object is an instance of
* {@link DSAPrivateKey} and has the same DSS (Digital Signature Standard)
- * parameter values as this one.</p>
- *
+ * parameter values as this one.
+ *
* @param obj the other non-null DSS key to compare to.
- * @return <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> 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;
- }
+ return false;
+
+ if (! (obj instanceof DSAPrivateKey))
+ return false;
+
DSAPrivateKey that = (DSAPrivateKey) obj;
return super.equals(that) && x.equals(that.getX());
}
@@ -205,12 +190,12 @@ public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey
{
String ls = SystemProperties.getProperty("line.separator");
str = new StringBuilder(this.getClass().getName()).append("(")
- .append(super.toString()).append(",").append(ls)
- .append("x=0x").append(Configuration.DEBUG ? x.toString(16)
- : "**...*").append(ls)
- .append(")").toString();
+ .append(super.toString()).append(",").append(ls)
+ .append("x=0x").append(Configuration.DEBUG ? x.toString(16)
+ : "**...*").append(ls)
+ .append(")")
+ .toString();
}
-
return str;
}
}
diff --git a/gnu/java/security/key/dss/DSSPublicKey.java b/gnu/java/security/key/dss/DSSPublicKey.java
index 522921313..fa3ad04d0 100644
--- a/gnu/java/security/key/dss/DSSPublicKey.java
+++ b/gnu/java/security/key/dss/DSSPublicKey.java
@@ -47,27 +47,23 @@ import java.security.PublicKey;
import java.security.interfaces.DSAPublicKey;
/**
- * <p>An object that embodies a DSS (Digital Signature Standard) public key.</p>
+ * An object that embodies a DSS (Digital Signature Standard) public key.
*
* @see #getEncoded
*/
-public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey
+public class DSSPublicKey
+ extends DSSKey
+ implements PublicKey, DSAPublicKey
{
- // Constants and variables
- // -------------------------------------------------------------------------
-
/**
- * <code>y = g<sup>x</sup> mod p</code> where <code>x</code> is the private
- * part of the DSA key.
+ * <code>y = g<sup>x</sup> mod p</code> where <code>x</code> is the
+ * private part of the DSA key.
*/
private final BigInteger y;
/** String representation of this key. Cached for speed. */
private transient String str;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Conveience constructor. Calls the constructor with 5 arguments passing
* {@link Registry#RAW_ENCODING_ID} as the identifier of the preferred
@@ -85,8 +81,8 @@ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey
}
/**
- * Constructs a new instance of <code>DSSPublicKey</code> given the designated
- * arguments.
+ * Constructs a new instance of <code>DSSPublicKey</code> given the
+ * designated arguments.
*
* @param preferredFormat the identifier of the preferred encoding format to
* use when externalizing this key.
@@ -102,13 +98,9 @@ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey
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 <code>encodePublicKey()</code>
* method of a DSS keypair codec object (an instance implementing
@@ -133,30 +125,22 @@ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey
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 --------------------------------------------------
-
/**
- * <p>Returns the encoded form of this public key according to the designated
- * format.</p>
+ * 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.
+ * format.
* @exception IllegalArgumentException if the format is not supported.
* @see DSSKeyPairRawCodec
*/
@@ -179,24 +163,22 @@ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
+ * Returns <code>true</code> if the designated object is an instance of
* {@link DSAPublicKey} and has the same DSS (Digital Signature Standard)
- * parameter values as this one.</p>
+ * parameter values as this one.
*
* @param obj the other non-null DSS key to compare to.
- * @return <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> 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;
- }
+ return false;
+
+ if (! (obj instanceof DSAPublicKey))
+ return false;
+
DSAPublicKey that = (DSAPublicKey) obj;
return super.equals(that) && y.equals(that.getY());
}
@@ -207,11 +189,11 @@ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey
{
String ls = SystemProperties.getProperty("line.separator");
str = new StringBuilder(this.getClass().getName()).append("(")
- .append(super.toString()).append(",").append(ls)
- .append("y=0x").append(y.toString(16)).append(ls)
- .append(")").toString();
+ .append(super.toString()).append(",").append(ls)
+ .append("y=0x").append(y.toString(16)).append(ls)
+ .append(")")
+ .toString();
}
-
return str;
}
}
diff --git a/gnu/java/security/key/dss/FIPS186.java b/gnu/java/security/key/dss/FIPS186.java
index 5984bcc93..7277599bd 100644
--- a/gnu/java/security/key/dss/FIPS186.java
+++ b/gnu/java/security/key/dss/FIPS186.java
@@ -40,26 +40,21 @@ 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;
/**
- * <p>An implementation of the DSA parameters generation as described in
- * FIPS-186.</p>
- *
- * References:<br>
+ * An implementation of the DSA parameters generation as described in FIPS-186.
+ * <p>
+ * References:
+ * <p>
* <a href="http://www.itl.nist.gov/fipspubs/fip186.htm">Digital Signature
- * Standard (DSS)</a>, Federal Information Processing Standards Publication 186.
- * National Institute of Standards and Technology.
+ * Standard (DSS)</a>, Federal Information Processing Standards Publication
+ * 186. National Institute of Standards and Technology.
*/
public class FIPS186
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final int DSA_PARAMS_SEED = 0;
public static final int DSA_PARAMS_COUNTER = 1;
@@ -73,7 +68,7 @@ public class FIPS186
public static final int DSA_PARAMS_G = 5;
/** The BigInteger constant 2. */
- private static final BigInteger TWO = new BigInteger("2");
+ private static final BigInteger TWO = BigInteger.valueOf(2L);
private static final BigInteger TWO_POW_160 = TWO.pow(160);
@@ -89,9 +84,6 @@ public class FIPS186
/** Our default source of randomness. */
private PRNG prng = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public FIPS186(int L, SecureRandom rnd)
{
super();
@@ -100,38 +92,31 @@ public class FIPS186
this.rnd = rnd;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* This method generates the DSS <code>p</code>, <code>q</code>, and
* <code>g</code> parameters only when <code>L</code> (the modulus length)
* is not one of the following: <code>512</code>, <code>768</code> and
- * <code>1024</code>. For those values of <code>L</code>, this implementation
- * uses pre-computed values of <code>p</code>, <code>q</code>, and
- * <code>g</code> given in the document <i>CryptoSpec</i> included in the
- * security guide documentation of the standard JDK distribution.<p>
- *
+ * <code>1024</code>. For those values of <code>L</code>, this
+ * implementation uses pre-computed values of <code>p</code>,
+ * <code>q</code>, and <code>g</code> given in the document <i>CryptoSpec</i>
+ * included in the security guide documentation of the standard JDK
+ * distribution.
+ * <p>
* The DSS requires two primes , <code>p</code> and <code>q</code>,
* satisfying the following three conditions:
- *
* <ul>
- * <li><code>2<sup>159</sup> &lt; q &lt; 2<sup>160</sup></code></li>
- * <li><code>2<sup>L-1</sup> &lt; p &lt; 2<sup>L</sup></code> for a
- * specified <code>L</code>, where <code>L = 512 + 64j</code> for some
- * <code>0 &lt;= j &lt;= 8</code></li>
- * <li>q divides p - 1.</li>
+ * <li><code>2<sup>159</sup> &lt; q &lt; 2<sup>160</sup></code></li>
+ * <li><code>2<sup>L-1</sup> &lt; p &lt; 2<sup>L</sup></code> for a
+ * specified <code>L</code>, where <code>L = 512 + 64j</code> for some
+ * <code>0 &lt;= j &lt;= 8</code></li>
+ * <li>q divides p - 1.</li>
* </ul>
- *
* The algorithm used to find these primes is as described in FIPS-186,
* section 2.2: GENERATION OF PRIMES. This prime generation scheme starts by
- * using the {@link Sha160} and a user supplied <i>SEED</i>
- * to construct a prime, <code>q</code>, in the range 2<sup>159</sup> &lt; q
- * &lt; 2<sup>160</sup>. Once this is accomplished, the same <i>SEED</i>
- * value is used to construct an <code>X</code> in the range <code>2<sup>L-1
+ * using the {@link Sha160} and a user supplied <i>SEED</i> to construct a
+ * prime, <code>q</code>, in the range 2<sup>159</sup> &lt; q &lt; 2<sup>160</sup>.
+ * Once this is accomplished, the same <i>SEED</i> value is used to construct
+ * an <code>X</code> in the range <code>2<sup>L-1
* </sup> &lt; X &lt; 2<sup>L</sup>. The prime, <code>p</code>, is then
* formed by rounding <code>X</code> to a number congruent to <code>1 mod
* 2q</code>. In this implementation we use the same <i>SEED</i> value given
@@ -169,9 +154,8 @@ public class FIPS186
u = sha.digest();
}
for (int i = 0; i < a.length; i++)
- {
- a[i] ^= u[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
@@ -183,12 +167,9 @@ public class FIPS186
// 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;
- }
+ if (q.isProbablePrime(80))
+ break step1;
} // step1
-
// 6. Let counter = 0 and offset = 2.
counter = 0;
offset = 2;
@@ -201,9 +182,9 @@ public class FIPS186
{
for (int k = 0; k <= n; k++)
{
- a = SEED_PLUS_OFFSET.add(
- BigInteger.valueOf(k & 0xFFFFFFFFL)).mod(
- TWO_POW_160).toByteArray();
+ 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());
}
@@ -214,9 +195,8 @@ public class FIPS186
// 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[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).
@@ -228,22 +208,17 @@ public class FIPS186
{
// 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;
- }
+ if (p.isProbablePrime(80))
+ 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;
- }
+ 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
@@ -258,28 +233,21 @@ public class FIPS186
// 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;
- }
+ 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);
- }
+ rnd.nextBytes(buffer);
else
getDefaultPRNG().nextBytes(buffer);
}
diff --git a/gnu/java/security/key/rsa/GnuRSAKey.java b/gnu/java/security/key/rsa/GnuRSAKey.java
index 3009dd71f..6ff740184 100644
--- a/gnu/java/security/key/rsa/GnuRSAKey.java
+++ b/gnu/java/security/key/rsa/GnuRSAKey.java
@@ -47,14 +47,11 @@ import java.security.Key;
import java.security.interfaces.RSAKey;
/**
- * <p>A base asbtract class for both public and private RSA keys.</p>
+ * A base asbtract class for both public and private RSA keys.
*/
-public abstract class GnuRSAKey implements Key, RSAKey
+public abstract class GnuRSAKey
+ implements Key, RSAKey
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The public modulus of an RSA key pair. */
private final BigInteger n;
@@ -62,17 +59,14 @@ public abstract class GnuRSAKey implements Key, RSAKey
private final BigInteger e;
/**
- * Identifier of the default encoding format to use when externalizing the
- * key material.
+ * Identifier of the default encoding format to use when externalizing the key
+ * material.
*/
protected final int defaultFormat;
/** String representation of this key. Cached for speed. */
private transient String str;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Trivial protected constructor.
*
@@ -91,21 +85,11 @@ public abstract class GnuRSAKey implements Key, RSAKey
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;
@@ -122,11 +106,9 @@ public abstract class GnuRSAKey implements Key, RSAKey
return FormatUtil.getEncodingShortName(defaultFormat);
}
- // Other instance methods --------------------------------------------------
-
/**
- * <p>Returns the modulus <code>n</code>.</p>
- *
+ * Returns the modulus <code>n</code>.
+ *
* @return the modulus <code>n</code>.
*/
public BigInteger getN()
@@ -135,8 +117,8 @@ public abstract class GnuRSAKey implements Key, RSAKey
}
/**
- * <p>Returns the public exponent <code>e</code>.</p>
- *
+ * Returns the public exponent <code>e</code>.
+ *
* @return the public exponent <code>e</code>.
*/
public BigInteger getPublicExponent()
@@ -145,8 +127,8 @@ public abstract class GnuRSAKey implements Key, RSAKey
}
/**
- * <p>Same as {@link #getPublicExponent()}.</p>
- *
+ * Same as {@link #getPublicExponent()}.
+ *
* @return the public exponent <code>e</code>.
*/
public BigInteger getE()
@@ -155,23 +137,21 @@ public abstract class GnuRSAKey implements Key, RSAKey
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
- * {@link RSAKey} and has the same RSA parameter values as this one.</p>
- *
+ * Returns <code>true</code> 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 <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> 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;
- }
+ return false;
+
+ if (! (obj instanceof RSAKey))
+ return false;
+
final RSAKey that = (RSAKey) obj;
return n.equals(that.getModulus());
}
@@ -181,7 +161,7 @@ public abstract class GnuRSAKey implements Key, RSAKey
if (str == null)
{
String ls = SystemProperties.getProperty("line.separator");
- str = new StringBuilder().append(ls)
+ str = new StringBuilder(ls)
.append("defaultFormat=").append(defaultFormat).append(",").append(ls)
.append("n=0x").append(n.toString(16)).append(",").append(ls)
.append("e=0x").append(e.toString(16))
@@ -190,7 +170,5 @@ public abstract class GnuRSAKey implements Key, RSAKey
return str;
}
- // abstract methods to be implemented by subclasses ------------------------
-
public abstract byte[] getEncoded(int format);
}
diff --git a/gnu/java/security/key/rsa/GnuRSAPrivateKey.java b/gnu/java/security/key/rsa/GnuRSAPrivateKey.java
index bd39ee657..ef466d020 100644
--- a/gnu/java/security/key/rsa/GnuRSAPrivateKey.java
+++ b/gnu/java/security/key/rsa/GnuRSAPrivateKey.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.key.rsa;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.classpath.SystemProperties;
import gnu.java.security.Registry;
import gnu.java.security.key.IKeyPairCodec;
@@ -49,18 +49,20 @@ import java.security.interfaces.RSAPrivateCrtKey;
import java.security.interfaces.RSAPrivateKey;
/**
- * <p>An object that embodies an RSA private key.</p>
- *
- * <p>References:</p>
+ * An object that embodies an RSA private key.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
- * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
- * Primitive specification and supporting documentation.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a
+ * href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
+ * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
+ * Primitive specification and supporting documentation.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
* </ol>
*/
-public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
- RSAPrivateCrtKey
+public class GnuRSAPrivateKey
+ extends GnuRSAKey
+ implements PrivateKey, RSAPrivateCrtKey
{
/** The first prime divisor of the modulus. */
private final BigInteger p;
@@ -68,8 +70,6 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
/** 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;
@@ -85,21 +85,17 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
/** String representation of this key. Cached for speed. */
private transient String str;
- // 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)
+ public GnuRSAPrivateKey(BigInteger p, BigInteger q, BigInteger e, BigInteger d)
{
this(Registry.RAW_ENCODING_ID, p, q, e, d);
}
@@ -118,7 +114,9 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
public GnuRSAPrivateKey(int preferredFormat, BigInteger p, BigInteger q,
BigInteger e, BigInteger d)
{
- this(preferredFormat, p.multiply(q), e, d, p, q,
+ this(preferredFormat,
+ p.multiply(q),
+ e, d, p, q,
e.modInverse(p.subtract(BigInteger.ONE)),
e.modInverse(q.subtract(BigInteger.ONE)),
q.modInverse(p));
@@ -131,19 +129,20 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
* @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 <code>p</code>
- * and <code>q</code>.
+ * and <code>q</code>.
* @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
- * <code>p</code> and <code>q</code>, satisfying <code>e * dP = 1 (mod p-1)
- * </code>.
+ * <code>p</code> and <code>q</code>, satisfying
+ * <code>e * dP = 1 (mod p-1)</code>.
* @param dQ the second prime's exponent. A positive integer less than
- * <code>p</code> and <code>q</code>, satisfying <code>e * dQ = 1 (mod p-1)
- * </code>.
+ * <code>p</code> and <code>q</code>, satisfying
+ * <code>e * dQ = 1 (mod p-1)</code>.
* @param qInv the Chinese Remainder Theorem coefiicient. A positive integer
- * less than <code>p</code>, satisfying <code>q * qInv = 1 (mod p)</code>.
+ * less than <code>p</code>, satisfying
+ * <code>q * qInv = 1 (mod p)</code>.
*/
public GnuRSAPrivateKey(int preferredFormat, BigInteger n, BigInteger e,
BigInteger d, BigInteger p, BigInteger q,
@@ -152,24 +151,20 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
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),
+ // 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).
+ // q * qInv = 1 (mod p).
this.qInv = qInv;
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
* A class method that takes the output of the <code>encodePrivateKey()</code>
* method of an RSA keypair codec object (an instance implementing
@@ -194,14 +189,10 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
catch (IllegalArgumentException ignored)
{
}
-
// try PKCS#8 codec
return (GnuRSAPrivateKey) new RSAKeyPairPKCS8Codec().decodePrivateKey(k);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
public BigInteger getPrimeP()
{
return p;
@@ -227,22 +218,18 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
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.
- *
+ * 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.
+ * format.
* @throws IllegalArgumentException if the format is not supported.
* @see RSAKeyPairRawCodec
* @see RSAKeyPairPKCS8Codec
@@ -266,19 +253,18 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
- * this class and has the same RSA parameter values as this one.</p>
- *
+ * Returns <code>true</code> 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 <code>true</code> if the designated object is of the same type
- * and value as this one.
+ * and value as this one.
*/
public boolean equals(final Object obj)
{
if (obj == null)
- {
- return false;
- }
+ return false;
+
if (obj instanceof RSAPrivateKey)
{
final RSAPrivateKey that = (RSAPrivateKey) obj;
@@ -315,7 +301,8 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey,
: "**...*").append(ls)
.append("qInv=0x").append(Configuration.DEBUG ? qInv.toString(16)
: "**...*").append(ls)
- .append(")").toString();
+ .append(")")
+ .toString();
}
return str;
}
diff --git a/gnu/java/security/key/rsa/GnuRSAPublicKey.java b/gnu/java/security/key/rsa/GnuRSAPublicKey.java
index 8badede14..1bbca4fa2 100644
--- a/gnu/java/security/key/rsa/GnuRSAPublicKey.java
+++ b/gnu/java/security/key/rsa/GnuRSAPublicKey.java
@@ -47,33 +47,29 @@ import java.security.PublicKey;
import java.security.interfaces.RSAPublicKey;
/**
- * <p>An object that encapsulates an RSA public key.</p>
- *
- * <p>References:</p>
+ * An object that encapsulates an RSA public key.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
- * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
- * Primitive specification and supporting documentation.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a
+ * href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
+ * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
+ * Primitive specification and supporting documentation.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
* </ol>
*/
-public class GnuRSAPublicKey extends GnuRSAKey implements PublicKey,
- RSAPublicKey
+public class GnuRSAPublicKey
+ extends GnuRSAKey
+ implements PublicKey, RSAPublicKey
{
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** String representation of this key. Cached for speed. */
private transient String str;
- // 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.
*/
@@ -98,9 +94,6 @@ public class GnuRSAPublicKey extends GnuRSAKey implements PublicKey,
n, e);
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
* A class method that takes the output of the <code>encodePublicKey()</code>
* method of an RSA keypair codec object (an instance implementing
@@ -125,21 +118,17 @@ public class GnuRSAPublicKey extends GnuRSAKey implements PublicKey,
catch (IllegalArgumentException ignored)
{
}
-
// try X.509 codec
return (GnuRSAPublicKey) new RSAKeyPairX509Codec().decodePublicKey(k);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the encoded form of this public key according to the designated
- * format.</p>
- *
+ * 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.
+ * format.
* @throws IllegalArgumentException if the format is not supported.
* @see RSAKeyPairRawCodec
*/
@@ -162,23 +151,21 @@ public class GnuRSAPublicKey extends GnuRSAKey implements PublicKey,
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
- * this class and has the same RSA parameter values as this one.</p>
- *
+ * Returns <code>true</code> 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 <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> 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;
- }
+ return false;
+
+ if (! (obj instanceof RSAPublicKey))
+ return false;
+
final RSAPublicKey that = (RSAPublicKey) obj;
return super.equals(that)
&& getPublicExponent().equals(that.getPublicExponent());
@@ -191,7 +178,8 @@ public class GnuRSAPublicKey extends GnuRSAKey implements PublicKey,
String ls = SystemProperties.getProperty("line.separator");
str = new StringBuilder(this.getClass().getName()).append("(")
.append(super.toString()).append(",").append(ls)
- .append(")").toString();
+ .append(")")
+ .toString();
}
return str;
}
diff --git a/gnu/java/security/key/rsa/RSAKeyPairGenerator.java b/gnu/java/security/key/rsa/RSAKeyPairGenerator.java
index 127b3eac4..c31cc4cc1 100644
--- a/gnu/java/security/key/rsa/RSAKeyPairGenerator.java
+++ b/gnu/java/security/key/rsa/RSAKeyPairGenerator.java
@@ -38,11 +38,10 @@ exception statement from your version. */
package gnu.java.security.key.rsa;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
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;
@@ -54,25 +53,23 @@ import java.util.Map;
import java.util.logging.Logger;
/**
- * <p>A key-pair generator for asymetric keys to use in conjunction with the RSA
- * scheme.</p>
- *
- * <p>Reference:</p>
+ * A key-pair generator for asymetric keys to use in conjunction with the RSA
+ * scheme.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
- * RSA-PSS Signature Scheme with Appendix</a>, part B. Primitive
- * specification and supporting documentation. Jakob Jonsson and Burt Kaliski.
- * </li>
- * <li><a href="http://www.cacr.math.uwaterloo.ca/hac/">Handbook of Applied
- * Cryptography</a>, Alfred J. Menezes, Paul C. van Oorschot and Scott A.
- * Vanstone. Section 11.3 RSA and related signature schemes.</li>
+ * <li><a
+ * href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
+ * RSA-PSS Signature Scheme with Appendix</a>, part B. Primitive specification
+ * and supporting documentation. Jakob Jonsson and Burt Kaliski. </li>
+ * <li><a href="http://www.cacr.math.uwaterloo.ca/hac/">Handbook of Applied
+ * Cryptography</a>, Alfred J. Menezes, Paul C. van Oorschot and Scott A.
+ * Vanstone. Section 11.3 RSA and related signature schemes.</li>
* </ol>
*/
-public class RSAKeyPairGenerator implements IKeyPairGenerator
+public class RSAKeyPairGenerator
+ implements IKeyPairGenerator
{
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final Logger log = Logger.getLogger(RSAKeyPairGenerator.class.getName());
/** The BigInteger constant 1. */
@@ -91,8 +88,8 @@ public class RSAKeyPairGenerator implements IKeyPairGenerator
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 <code>n</code>, and <code>e</code> values. The
+ * Property name of an optional {@link RSAKeyGenParameterSpec} instance to use
+ * for this generator's <code>n</code>, and <code>e</code> values. The
* default is to generate <code>n</code> and use a fixed value for
* <code>e</.code> (Fermat's F4 number).
*/
@@ -129,27 +126,19 @@ public class RSAKeyPairGenerator implements IKeyPairGenerator
/** 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;
}
/**
- * <p>Configures this instance.</p>
- *
+ * 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.
+ * @exception IllegalArgumentException if the designated MODULUS_LENGTH value
+ * is less than 1024.
*/
public void setup(Map attributes)
{
@@ -157,10 +146,8 @@ public class RSAKeyPairGenerator implements IKeyPairGenerator
log.entering(this.getClass().getName(), "setup", 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)
{
@@ -172,11 +159,8 @@ public class RSAKeyPairGenerator implements IKeyPairGenerator
Integer l = (Integer) attributes.get(MODULUS_LENGTH);
L = (l == null ? DEFAULT_MODULUS_LENGTH : l.intValue());
}
-
if (L < 1024)
- {
- throw new IllegalArgumentException(MODULUS_LENGTH);
- }
+ throw new IllegalArgumentException(MODULUS_LENGTH);
// what is the preferred encoding format
Integer formatID = (Integer) attributes.get(PREFERRED_ENCODING_FORMAT);
@@ -187,18 +171,18 @@ public class RSAKeyPairGenerator implements IKeyPairGenerator
}
/**
- * <p>The algorithm used here is described in <i>nessie-pss-B.pdf</i>
- * document which is part of the RSA-PSS submission to NESSIE.</p>
- *
+ * <p>
+ * The algorithm used here is described in <i>nessie-pss-B.pdf</i> document
+ * which is part of the RSA-PSS submission to NESSIE.
+ * </p>
+ *
* @return an RSA keypair.
*/
public KeyPair generate()
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "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;
@@ -210,12 +194,9 @@ public class RSAKeyPairGenerator implements IKeyPairGenerator
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;
- }
+ && p.isProbablePrime(80) && 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)
@@ -223,46 +204,34 @@ public class RSAKeyPairGenerator implements IKeyPairGenerator
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;
- }
-
+ if (n.bitLength() == L && q.isProbablePrime(80) && 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);
-
KeyPair result = new KeyPair(pubK, secK);
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "generate", result);
return result;
}
- // helper methods ----------------------------------------------------------
-
/**
- * <p>Fills the designated byte array with random data.</p>
- *
+ * 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);
- }
+ rnd.nextBytes(buffer);
else
getDefaultPRNG().nextBytes(buffer);
}
diff --git a/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java b/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
index 14a0a063c..7fa9d0102 100644
--- a/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
+++ b/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.key.rsa;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.Registry;
import gnu.java.security.der.DER;
@@ -85,7 +85,6 @@ public class RSAKeyPairPKCS8Codec
/**
* Returns the PKCS#8 ASN.1 <i>PrivateKeyInfo</i> representation of an RSA
* private key. The ASN.1 specification is as follows:
- *
* <pre>
* PrivateKeyInfo ::= SEQUENCE {
* version INTEGER, -- MUST be 0
@@ -98,10 +97,9 @@ public class RSAKeyPairPKCS8Codec
* parameters ANY DEFINED BY algorithm OPTIONAL
* }
* </pre>
- *
- * <p>The <i>privateKey</i> field, which is an OCTET STRING, contains the
- * DER-encoded form of the RSA private key defined as:</p>
- *
+ * <p>
+ * The <i>privateKey</i> field, which is an OCTET STRING, contains the
+ * DER-encoded form of the RSA private key defined as:
* <pre>
* RSAPrivateKey ::= SEQUENCE {
* version INTEGER, -- MUST be 0
@@ -125,7 +123,6 @@ public class RSAKeyPairPKCS8Codec
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "encodePrivateKey()", key);
-
if (! (key instanceof GnuRSAPrivateKey))
throw new InvalidParameterException("Wrong key type");
@@ -217,7 +214,6 @@ public class RSAKeyPairPKCS8Codec
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "decodePrivateKey()", input);
-
if (input == null)
throw new InvalidParameterException("Input bytes MUST NOT be null");
@@ -287,9 +283,8 @@ public class RSAKeyPairPKCS8Codec
y.initCause(x);
throw y;
}
-
- PrivateKey result = new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID, n, e,
- d, p, q, dP, dQ, qInv);
+ PrivateKey result = new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,
+ n, e, d, p, q, dP, dQ, qInv);
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "decodePrivateKey()", result);
return result;
diff --git a/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java b/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java
index 1cca7c324..952202366 100644
--- a/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java
+++ b/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java
@@ -47,80 +47,60 @@ import java.security.PrivateKey;
import java.security.PublicKey;
/**
- * <p>An object that implements the {@link IKeyPairCodec} interface for the
- * <i>Raw</i> format to use with RSA keypairs.</p>
- *
- * @version $Revision: 1.1.4.1 $
+ * An object that implements the {@link IKeyPairCodec} interface for the <i>Raw</i>
+ * format to use with RSA keypairs.
*/
-public class RSAKeyPairRawCodec implements IKeyPairCodec
+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;
}
/**
- * <p>Returns the encoded form of the designated RSA public key according to
- * the <i>Raw</i> format supported by this library.</p>
- *
- * <p>The <i>Raw</i> format for an RSA public key, in this implementation, is
- * a byte sequence consisting of the following:</p>
- *
+ * Returns the encoded form of the designated RSA public key according to the
+ * <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for an RSA public key, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_RSA_PUBLIC_KEY},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the RSA parameter
- * <code>n</code> (the modulus) in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the RSA parameter <code>n</code>,</li>
- * <li>4-byte count of following bytes representing the RSA parameter
- * <code>e</code> (the public exponent) in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the RSA parameter <code>e</code>.</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_RSA_PUBLIC_KEY},</li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the RSA parameter
+ * <code>n</code> (the modulus) in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the RSA parameter <code>n</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the RSA parameter
+ * <code>e</code> (the public exponent) in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the RSA parameter <code>e</code>.
+ * </li>
* </ol>
*
* @param key the key to encode.
* @return the <i>Raw</i> format encoding of the designated key.
* @exception IllegalArgumentException if the designated key is not an RSA
- * one.
+ * one.
*/
public byte[] encodePublicKey(PublicKey key)
{
- if (!(key instanceof GnuRSAPublicKey))
- {
- throw new IllegalArgumentException("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;
@@ -129,7 +109,6 @@ public class RSAKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// e
buffer = rsaKey.getPublicExponent().toByteArray();
length = buffer.length;
@@ -138,7 +117,6 @@ public class RSAKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -149,92 +127,87 @@ public class RSAKeyPairRawCodec implements IKeyPairCodec
|| 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");
- }
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
- int i = 5;
+ 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);
+ 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);
+ 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);
}
/**
- * <p>Returns the encoded form of the designated RSA private key according to
- * the <i>Raw</i> format supported by this library.</p>
- *
- * <p>The <i>Raw</i> format for an RSA private key, in this implementation,
- * is a byte sequence consisting of the following:</p>
- *
+ * Returns the encoded form of the designated RSA private key according to the
+ * <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for an RSA private key, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_RSA_PRIVATE_KEY},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the RSA parameter
- * <code>p</code> (the first prime factor of the modulus) in internet
- * order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the RSA parameter <code>p</code>,</li>
- * <li>4-byte count of following bytes representing the RSA parameter
- * <code>q</code> (the second prime factor of the modulus) in internet
- * order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the RSA parameter <code>q</code>,</li>
- * <li>4-byte count of following bytes representing the RSA parameter
- * <code>e</code> (the public exponent) in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the RSA parameter <code>e</code>,</li>
- * <li>4-byte count of following bytes representing the RSA parameter
- * <code>d</code> (the private exponent) in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the RSA parameter <code>d</code>,</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_RSA_PRIVATE_KEY},</li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the RSA parameter
+ * <code>p</code> (the first prime factor of the modulus) in internet order,
+ * </li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the RSA parameter <code>p</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the RSA parameter
+ * <code>q</code> (the second prime factor of the modulus) in internet
+ * order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the RSA parameter <code>q</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the RSA parameter
+ * <code>e</code> (the public exponent) in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the RSA parameter <code>e</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the RSA parameter
+ * <code>d</code> (the private exponent) in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the RSA parameter <code>d</code>,
+ * </li>
* </ol>
- *
+ *
* @param key the key to encode.
* @return the <i>Raw</i> format encoding of the designated key.
*/
public byte[] encodePrivateKey(PrivateKey key)
{
- if (!(key instanceof GnuRSAPrivateKey))
- {
- throw new IllegalArgumentException("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;
@@ -243,7 +216,6 @@ public class RSAKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// q
buffer = rsaKey.getPrimeQ().toByteArray();
length = buffer.length;
@@ -252,7 +224,6 @@ public class RSAKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// e
buffer = rsaKey.getPublicExponent().toByteArray();
length = buffer.length;
@@ -261,7 +232,6 @@ public class RSAKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
// d
buffer = rsaKey.getPrivateExponent().toByteArray();
length = buffer.length;
@@ -270,7 +240,6 @@ public class RSAKeyPairRawCodec implements IKeyPairCodec
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -281,52 +250,51 @@ public class RSAKeyPairRawCodec implements IKeyPairCodec
|| 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");
- }
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
- int i = 5;
+ 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);
+ 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);
+ 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);
+ 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);
+ 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/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java b/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
index 87c5c3a6d..b11e1c013 100644
--- a/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
+++ b/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.key.rsa;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.Registry;
import gnu.java.security.der.BitString;
@@ -117,7 +117,6 @@ public class RSAKeyPairX509Codec
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "encodePublicKey()", key);
-
if (! (key instanceof GnuRSAPublicKey))
throw new InvalidParameterException("key");
@@ -158,7 +157,7 @@ public class RSAKeyPairX509Codec
}
catch (IOException x)
{
- InvalidParameterException y = new InvalidParameterException();
+ InvalidParameterException y = new InvalidParameterException(x.getMessage());
y.initCause(x);
throw y;
}
@@ -187,7 +186,6 @@ public class RSAKeyPairX509Codec
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "decodePublicKey()", input);
-
if (input == null)
throw new InvalidParameterException("Input bytes MUST NOT be null");
@@ -232,11 +230,10 @@ public class RSAKeyPairX509Codec
}
catch (IOException x)
{
- InvalidParameterException y = new InvalidParameterException();
+ InvalidParameterException y = new InvalidParameterException(x.getMessage());
y.initCause(x);
throw y;
}
-
PublicKey result = new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e);
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "decodePublicKey()", result);
diff --git a/gnu/java/security/pkcs/PKCS7SignedData.java b/gnu/java/security/pkcs/PKCS7SignedData.java
index de2b2f679..d59dba3cd 100644
--- a/gnu/java/security/pkcs/PKCS7SignedData.java
+++ b/gnu/java/security/pkcs/PKCS7SignedData.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.security.pkcs;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.ber.BER;
import gnu.java.security.ber.BEREncodingException;
diff --git a/gnu/java/security/pkcs/SignerInfo.java b/gnu/java/security/pkcs/SignerInfo.java
index 662bcc3b7..3066401ac 100644
--- a/gnu/java/security/pkcs/SignerInfo.java
+++ b/gnu/java/security/pkcs/SignerInfo.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.security.pkcs;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.ber.BER;
import gnu.java.security.ber.BEREncodingException;
diff --git a/gnu/java/security/prng/BasePRNG.java b/gnu/java/security/prng/BasePRNG.java
index fe815d700..3b7c8cf07 100644
--- a/gnu/java/security/prng/BasePRNG.java
+++ b/gnu/java/security/prng/BasePRNG.java
@@ -41,14 +41,11 @@ package gnu.java.security.prng;
import java.util.Map;
/**
- * <p>An abstract class to facilitate implementing PRNG algorithms.</p>
+ * An abstract class to facilitate implementing PRNG algorithms.
*/
-public abstract class BasePRNG implements IRandom
+public abstract class BasePRNG
+ implements IRandom
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The canonical name prefix of the PRNG algorithm. */
protected String name;
@@ -61,12 +58,9 @@ public abstract class BasePRNG implements IRandom
/** The index into buffer of where the next byte will come from. */
protected int ndx;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Trivial constructor for use by concrete subclasses.</p>
- *
+ * Trivial constructor for use by concrete subclasses.
+ *
* @param name the canonical name of this instance.
*/
protected BasePRNG(String name)
@@ -78,14 +72,6 @@ public abstract class BasePRNG implements IRandom
buffer = new byte[0];
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // IRandom interface implementation ----------------------------------------
-
public String name()
{
return name;
@@ -101,10 +87,9 @@ public abstract class BasePRNG implements IRandom
public byte nextByte() throws IllegalStateException, LimitReachedException
{
- if (!initialised)
- {
- throw new IllegalStateException();
- }
+ if (! initialised)
+ throw new IllegalStateException();
+
return nextByteInternal();
}
@@ -117,7 +102,7 @@ public abstract class BasePRNG implements IRandom
public void nextBytes(byte[] out, int offset, int length)
throws IllegalStateException, LimitReachedException
{
- if (!initialised)
+ if (! initialised)
throw new IllegalStateException("not initialized");
if (length == 0)
@@ -127,7 +112,6 @@ public abstract class BasePRNG implements IRandom
throw new ArrayIndexOutOfBoundsException("offset=" + offset + " length="
+ length + " limit="
+ out.length);
-
if (ndx >= buffer.length)
{
fillBlock();
@@ -163,9 +147,6 @@ public abstract class BasePRNG implements IRandom
throw new UnsupportedOperationException("random state is non-modifiable");
}
- // Instance methods
- // -------------------------------------------------------------------------
-
public boolean isInitialised()
{
return initialised;
@@ -182,8 +163,6 @@ public abstract class BasePRNG implements IRandom
return buffer[ndx++];
}
- // abstract methods to implement by subclasses -----------------------------
-
public Object clone() throws CloneNotSupportedException
{
BasePRNG result = (BasePRNG) super.clone();
diff --git a/gnu/java/security/prng/EntropySource.java b/gnu/java/security/prng/EntropySource.java
index 260c668f8..95f68f048 100644
--- a/gnu/java/security/prng/EntropySource.java
+++ b/gnu/java/security/prng/EntropySource.java
@@ -43,7 +43,6 @@ package gnu.java.security.prng;
*/
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,
diff --git a/gnu/java/security/prng/IRandom.java b/gnu/java/security/prng/IRandom.java
index 2c89e7ad5..66ad6d224 100644
--- a/gnu/java/security/prng/IRandom.java
+++ b/gnu/java/security/prng/IRandom.java
@@ -41,140 +41,134 @@ package gnu.java.security.prng;
import java.util.Map;
/**
- * <p>The basic visible methods of any pseudo-random number generator.</p>
- *
- * <p>The [HAC] defines a PRNG (as implemented in this library) as follows:</p>
- *
+ * The basic visible methods of any pseudo-random number generator.
+ * <p>
+ * The [HAC] defines a PRNG (as implemented in this library) as follows:
* <ul>
- * <li>"5.6 Definition: A pseudorandom bit generator (PRBG) is said to pass
- * the <em>next-bit test</em> if there is no polynomial-time algorithm which,
- * on input of the first <code>L</code> bits of an output sequence <code>S</code>,
- * can predict the <code>(L+1)</code>st bit of <code>S</code> with a
- * probability significantly grater than <code>1/2</code>."</li>
- *
- * <li>"5.8 Definition: A PRBG that passes the <em>next-bit test</em>
- * (possibly under some plausible but unproved mathematical assumption such
- * as the intractability of factoring integers) is called a
- * <em>cryptographically secure pseudorandom bit generator</em> (CSPRBG)."</li>
+ * <li>"5.6 Definition: A pseudorandom bit generator (PRBG) is said to pass the
+ * <em>next-bit test</em> if there is no polynomial-time algorithm which, on
+ * input of the first <code>L</code> bits of an output sequence <code>S</code>,
+ * can predict the <code>(L+1)</code><sup>st</sup> bit of <code>S</code> with a
+ * probability significantly greater than <code>1/2</code>."</li>
+ * <li>"5.8 Definition: A PRBG that passes the <em>next-bit test</em>
+ * (possibly under some plausible but unproved mathematical assumption such as
+ * the intractability of factoring integers) is called a <em>cryptographically
+ * secure pseudorandom bit generator</em> (CSPRBG)."</li>
* </ul>
- *
- * <p><b>IMPLEMENTATION NOTE</b>: Although all the concrete classes in this
+ * <p>
+ * <b>IMPLEMENTATION NOTE</b>: 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
+ * here that such an operation, for those algorithms that use an underlying
* symmetric key block cipher, <b>DOES NOT</b> 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
+ * cloned). Instead a clone of an already initialised PRNG, that uses an
* underlying symmetric key block cipher, is another instance with a clone of
- * the same cipher that operates with the <b>same block size</b> but without any
- * knowledge of neither key material nor key size.</p>
- *
- * <p>References:</p>
- *
+ * the same cipher that operates with the <b>same block size</b> but without
+ * any knowledge of neither key material nor key size.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
- * Applied Cryptography.<br>
- * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
- * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
+ * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
+ * Applied Cryptography.<br>
+ * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
+ * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
* </ol>
*/
-public interface IRandom extends Cloneable
+public interface IRandom
+ extends Cloneable
{
-
- // Constants
- // -------------------------------------------------------------------------
-
- // Methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the canonical name of this instance.</p>
- *
- * @return the canonical name of this instance. */
+ * Returns the canonical name of this instance.
+ *
+ * @return the canonical name of this instance.
+ */
String name();
/**
- * <p>Initialises the pseudo-random number generator scheme with the
- * appropriate attributes.</p>
- *
+ * 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.
+ * future instance behaviour.
* @exception IllegalArgumentException if at least one of the defined name/
- * value pairs contains invalid data.
+ * value pairs contains invalid data.
*/
void init(Map attributes);
/**
- * <p>Returns the next 8 bits of random data generated from this instance.</p>
- *
+ * 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.
+ * theoretical limit for generating non-repetitive pseudo-random
+ * data.
*/
byte nextByte() throws IllegalStateException, LimitReachedException;
/**
- * <p>Fills the designated byte array, starting from byte at index
- * <code>offset</code>, for a maximum of <code>length</code> bytes with the
- * output of this generator instance.
- *
+ * Fills the designated byte array, starting from byte at index
+ * <code>offset</code>, for a maximum of <code>length</code> bytes with
+ * the output of this generator instance.
+ *
* @param out the placeholder to contain the generated random bytes.
* @param offset the starting index in <i>out</i> to consider. This method
- * does nothing if this parameter is not within <code>0</code> and
- * <code>out.length</code>.
- * @param length the maximum number of required random bytes. This method
- * does nothing if this parameter is less than <code>1</code>.
+ * does nothing if this parameter is not within <code>0</code> and
+ * <code>out.length</code>.
+ * @param length the maximum number of required random bytes. This method does
+ * nothing if this parameter is less than <code>1</code>.
* @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.
+ * theoretical limit for generating non-repetitive pseudo-random
+ * data.
*/
void nextBytes(byte[] out, int offset, int length)
throws IllegalStateException, LimitReachedException;
/**
- * <p>Supplement, or possibly replace, the random state of this PRNG with
- * a random byte.</p>
- *
- * <p>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}.</p>
- *
+ * Supplement, or possibly replace, the random state of this PRNG with a
+ * random byte.
+ * <p>
+ * 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);
/**
- * <p>Supplement, or possibly replace, the random state of this PRNG with
- * a sequence of new random bytes.</p>
- *
- * <p>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}.</p>
- *
+ * Supplement, or possibly replace, the random state of this PRNG with a
+ * sequence of new random bytes.
+ * <p>
+ * 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);
/**
- * <p>Supplement, or possibly replace, the random state of this PRNG with
- * a sequence of new random bytes.</p>
- *
- * <p>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}.</p>
- *
+ * Supplement, or possibly replace, the random state of this PRNG with a
+ * sequence of new random bytes.
+ * <p>
+ * 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 <i>offset</i>, <i>length</i>,
- * or <i>offset</i>+<i>length</i> is out of bounds.
+ * @exception IndexOutOfBoundsException If <i>offset</i>, <i>length</i>, or
+ * <i>offset</i>+<i>length</i> is out of bounds.
*/
void addRandomBytes(byte[] in, int offset, int length);
/**
- * <p>Returns a clone copy of this instance.</p>
- *
+ * 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/gnu/java/security/prng/LimitReachedException.java b/gnu/java/security/prng/LimitReachedException.java
index 2fd8bfa7f..8d5b30baf 100644
--- a/gnu/java/security/prng/LimitReachedException.java
+++ b/gnu/java/security/prng/LimitReachedException.java
@@ -42,15 +42,9 @@ 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
+public class LimitReachedException
+ extends Exception
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public LimitReachedException()
{
super();
@@ -60,10 +54,4 @@ public class LimitReachedException extends Exception
{
super(msg);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instant methods
- // -------------------------------------------------------------------------
-} \ No newline at end of file
+}
diff --git a/gnu/java/security/prng/MDGenerator.java b/gnu/java/security/prng/MDGenerator.java
index 073c559ae..574a2f9d6 100644
--- a/gnu/java/security/prng/MDGenerator.java
+++ b/gnu/java/security/prng/MDGenerator.java
@@ -45,19 +45,17 @@ import gnu.java.security.hash.IMessageDigest;
import java.util.Map;
/**
- * <p>A simple pseudo-random number generator that relies on a hash algorithm,
- * that (a) starts its operation by hashing a <code>seed</code>, 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
+ * A simple pseudo-random number generator that relies on a hash algorithm, that
+ * (a) starts its operation by hashing a <code>seed</code>, 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
- * <code>seed</code> is given, an empty octet sequence is used.</p>
+ * <code>seed</code> is given, an empty octet sequence is used.
*/
-public class MDGenerator extends BasePRNG implements Cloneable
+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";
@@ -67,23 +65,12 @@ public class MDGenerator extends BasePRNG implements Cloneable
/** 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
@@ -95,22 +82,15 @@ public class MDGenerator extends BasePRNG implements Cloneable
// 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);
+ 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];
- }
+ seed = new byte[0];
md.update(seed, 0, seed.length);
}
@@ -122,22 +102,20 @@ public class MDGenerator extends BasePRNG implements Cloneable
md.update(buffer, 0, buffer.length);
}
- public void addRandomByte (final byte b)
+ public void addRandomByte(final byte b)
{
if (md == null)
- throw new IllegalStateException ("not initialized");
- md.update (b);
+ throw new IllegalStateException("not initialized");
+ md.update(b);
}
- public void addRandomBytes (final byte[] buf, final int off, final int len)
+ public void addRandomBytes(final byte[] buf, final int off, final int len)
{
if (md == null)
- throw new IllegalStateException ("not initialized");
- md.update (buf, off, len);
+ throw new IllegalStateException("not initialized");
+ md.update(buf, off, len);
}
- // Cloneable interface implementation ---------------------------------------
-
public Object clone() throws CloneNotSupportedException
{
MDGenerator result = (MDGenerator) super.clone();
diff --git a/gnu/java/security/prng/PRNGFactory.java b/gnu/java/security/prng/PRNGFactory.java
index 1699d9e7e..ae15d053b 100644
--- a/gnu/java/security/prng/PRNGFactory.java
+++ b/gnu/java/security/prng/PRNGFactory.java
@@ -45,56 +45,43 @@ import java.util.HashSet;
import java.util.Set;
/**
- * <p>A Factory to instantiate pseudo random number generators.</p>
+ * A Factory to instantiate pseudo random number generators.
*/
-public class PRNGFactory implements Registry
+public class PRNGFactory
+ implements Registry
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial constructor to enforce <i>Singleton</i> pattern. */
protected PRNGFactory()
{
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns an instance of a padding algorithm given its name.</p>
- *
+ * 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.
+ * test.
*/
public static final IRandom getInstance(String prng)
{
if (prng == null)
- {
- return null;
- }
+ return null;
prng = prng.trim();
IRandom result = null;
if (prng.equalsIgnoreCase(MD_PRNG))
- {
- result = new MDGenerator();
- }
+ result = new MDGenerator();
return result;
}
/**
- * <p>Returns a {@link Set} of names of padding algorithms supported by this
- * <i>Factory</i>.</p>
- *
+ * Returns a {@link Set} of names of padding algorithms supported by this
+ * <i>Factory</i>.
+ *
* @return a {@link Set} of pseudo-random number generator algorithm names
- * (Strings).
+ * (Strings).
*/
public static final Set getNames()
{
@@ -102,7 +89,4 @@ public class PRNGFactory implements Registry
hs.add(MD_PRNG);
return Collections.unmodifiableSet(hs);
}
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/java/security/prng/RandomEvent.java b/gnu/java/security/prng/RandomEvent.java
index c07062125..fc4607a8a 100644
--- a/gnu/java/security/prng/RandomEvent.java
+++ b/gnu/java/security/prng/RandomEvent.java
@@ -41,12 +41,11 @@ package gnu.java.security.prng;
import java.util.EventObject;
/**
- * An interface for entropy accumulators that will be notified of random
- * events.
+ * A type for entropy accumulators that will be notified of random events.
*/
-public class RandomEvent extends EventObject
+public class RandomEvent
+ extends EventObject
{
-
private final byte sourceNumber;
private final byte poolNumber;
@@ -61,7 +60,7 @@ public class RandomEvent extends EventObject
this.poolNumber = poolNumber;
if (data.length == 0 || data.length > 32)
throw new IllegalArgumentException(
- "random events take between 1 and 32 bytes of data");
+ "random events take between 1 and 32 bytes of data");
this.data = (byte[]) data.clone();
}
@@ -79,4 +78,4 @@ public class RandomEvent extends EventObject
{
return data;
}
-} \ No newline at end of file
+}
diff --git a/gnu/java/security/prng/RandomEventListener.java b/gnu/java/security/prng/RandomEventListener.java
index 1dc14619f..beb9087f4 100644
--- a/gnu/java/security/prng/RandomEventListener.java
+++ b/gnu/java/security/prng/RandomEventListener.java
@@ -41,10 +41,10 @@ package gnu.java.security.prng;
import java.util.EventListener;
/**
- * An interface for entropy accumulators that will be notified of random
- * events.
+ * An interface for entropy accumulators that will be notified of random events.
*/
-public interface RandomEventListener extends EventListener
+public interface RandomEventListener
+ extends EventListener
{
void addRandomEvent(RandomEvent event);
-} \ No newline at end of file
+}
diff --git a/gnu/java/security/provider/Gnu.java b/gnu/java/security/provider/Gnu.java
index 6ea96c1e4..62bb0a29e 100644
--- a/gnu/java/security/provider/Gnu.java
+++ b/gnu/java/security/provider/Gnu.java
@@ -42,12 +42,16 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.Provider;
-public final class Gnu extends Provider
+public final class Gnu
+ extends Provider
{
public Gnu()
{
- super("GNU", 1.0, "GNU provider v1.0 implementing SHA-1, MD5, DSA, RSA, X.509 Certificates and CRLs, PKIX certificate path validators, Collection cert stores, Diffie-Hellman key agreement and key pair generator");
-
+ super("GNU", 1.0,
+ "GNU provider v1.0 implementing SHA-1, MD5, DSA, RSA, X.509 "
+ + "Certificates and CRLs, PKIX certificate path validators, "
+ + "Collection cert stores, Diffie-Hellman key agreement and "
+ + "key pair generator");
AccessController.doPrivileged (new PrivilegedAction()
{
public Object run()
@@ -163,29 +167,41 @@ public final class Gnu extends Provider
put("Alg.Alias.KeyFactory.PKCS#8", "Encoded");
put("Alg.Alias.KeyFactory.PKCS8", "Encoded");
- put("MessageDigest.HAVAL", gnu.java.security.jce.hash.HavalSpi.class.getName());
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ gnu.java.security.jce.hash.WhirlpoolSpi.class.getName());
put("MessageDigest.WHIRLPOOL ImplementedIn", "Software");
put("Alg.Alias.MessageDigest.SHS", "SHA-160");
@@ -224,29 +240,41 @@ public final class Gnu extends Provider
put("SecureRandom.SHA1PRNG",
gnu.java.security.jce.prng.Sha160RandomSpi.class.getName());
- put("SecureRandom.MD2PRNG", gnu.java.security.jce.prng.MD2RandomSpi.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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ 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",
+ gnu.java.security.jce.prng.WhirlpoolRandomSpi.class.getName());
put("SecureRandom.WHIRLPOOLPRNG ImplementedIn", "Software");
put("Alg.Alias.SecureRandom.SHA-1PRNG", "SHA-160PRNG");
diff --git a/gnu/java/security/provider/PKIXCertPathValidatorImpl.java b/gnu/java/security/provider/PKIXCertPathValidatorImpl.java
index 3680f2fae..cdfad3f61 100644
--- a/gnu/java/security/provider/PKIXCertPathValidatorImpl.java
+++ b/gnu/java/security/provider/PKIXCertPathValidatorImpl.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.provider;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.Registry;
import gnu.java.security.key.dss.DSSPublicKey;
@@ -85,51 +85,45 @@ import java.util.Set;
import java.util.logging.Logger;
/**
- * An implementation of the Public Key Infrastructure's X.509
- * certificate path validation algorithm.
- *
- * <p>See <a href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280:
- * Internet X.509 Public Key Infrastructure Certificate and
- * Certificate Revocation List (CRL) Profile</a>.
- *
+ * An implementation of the Public Key Infrastructure's X.509 certificate path
+ * validation algorithm.
+ * <p>
+ * See <a href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509
+ * Public Key Infrastructure Certificate and Certificate Revocation List (CRL)
+ * Profile</a>.
+ *
* @author Casey Marshall (rsdio@metastatic.org)
*/
-public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
+public class PKIXCertPathValidatorImpl
+ extends CertPathValidatorSpi
{
private static final Logger log = Logger.getLogger(PKIXCertPathValidatorImpl.class.getName());
- public static final String ANY_POLICY = "2.5.29.32.0";
- // Constructor.
- // -------------------------------------------------------------------------
+ public static final String ANY_POLICY = "2.5.29.32.0";
public PKIXCertPathValidatorImpl()
{
super();
}
- // Instance methods.
- // -------------------------------------------------------------------------
-
public CertPathValidatorResult engineValidate(CertPath path,
CertPathParameters params)
- throws CertPathValidatorException, InvalidAlgorithmParameterException
+ throws CertPathValidatorException, InvalidAlgorithmParameterException
{
- if (!(params instanceof PKIXParameters))
+ if (! (params instanceof PKIXParameters))
throw new InvalidAlgorithmParameterException("not a PKIXParameters object");
-
// First check if the certificate path is valid.
//
// This means that:
//
- // (a) for all x in {1, ..., n-1}, the subject of certificate x is
- // the issuer of certificate x+1;
+ // (a) for all x in {1, ..., n-1}, the subject of certificate x is
+ // the issuer of certificate x+1;
//
- // (b) for all x in {1, ..., n}, the certificate was valid at the
- // time in question.
+ // (b) for all x in {1, ..., n}, the certificate was valid at the
+ // time in question.
//
// Because this is the X.509 algorithm, we also check if all
// cerificates are of type X509Certificate.
-
PolicyNodeImpl rootNode = new PolicyNodeImpl();
Set initPolicies = ((PKIXParameters) params).getInitialPolicies();
rootNode.setValidPolicy(ANY_POLICY);
@@ -152,7 +146,6 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
{
throw new CertPathValidatorException("invalid certificate path");
}
-
String sigProvider = ((PKIXParameters) params).getSigProvider();
PublicKey prevKey = null;
Date now = ((PKIXParameters) params).getDate();
@@ -170,7 +163,7 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
throw new CertPathValidatorException(ce.toString());
}
Set uce = getCritExts(p[i]);
- for (Iterator check = checks.iterator(); check.hasNext(); )
+ for (Iterator check = checks.iterator(); check.hasNext();)
{
try
{
@@ -180,23 +173,21 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
{
}
}
-
PolicyConstraint constr = null;
if (p[i] instanceof GnuPKIExtension)
{
- Extension pcx =
- ((GnuPKIExtension) p[i]).getExtension (PolicyConstraint.ID);
+ Extension pcx = ((GnuPKIExtension) p[i]).getExtension(PolicyConstraint.ID);
if (pcx != null)
constr = (PolicyConstraint) pcx.getValue();
}
else
{
- byte[] pcx = p[i].getExtensionValue (PolicyConstraint.ID.toString());
+ byte[] pcx = p[i].getExtensionValue(PolicyConstraint.ID.toString());
if (pcx != null)
{
try
{
- constr = new PolicyConstraint (pcx);
+ constr = new PolicyConstraint(pcx);
}
catch (Exception x)
{
@@ -204,14 +195,10 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
}
}
if (constr != null && constr.getRequireExplicitPolicy() >= 0)
- {
- policyConstraints.add (new int[]
- { p.length-i, constr.getRequireExplicitPolicy() });
- }
-
- updatePolicyTree(p[i], rootNode, p.length-i, (PKIXParameters) params,
- checkExplicitPolicy (p.length-i, policyConstraints));
-
+ policyConstraints.add(new int[] { p.length - i,
+ constr.getRequireExplicitPolicy() });
+ updatePolicyTree(p[i], rootNode, p.length - i, (PKIXParameters) params,
+ checkExplicitPolicy(p.length - i, policyConstraints));
// The rest of the tests involve this cert's relationship with the
// next in the path. If this cert is the end entity, we can stop.
if (i == 0)
@@ -228,36 +215,35 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
// If the DSA public key is missing its parameters, use those
// from the previous cert's key.
if (dsa == null || dsa.getP() == null || dsa.getG() == null
- || dsa.getQ() == null)
+ || dsa.getQ() == null)
{
if (prevKey == null)
throw new InvalidKeyException("DSA keys not chainable");
- if (!(prevKey instanceof DSAPublicKey))
+ if (! (prevKey instanceof DSAPublicKey))
throw new InvalidKeyException("DSA keys not chainable");
dsa = ((DSAPublicKey) prevKey).getParams();
pubKey = new DSSPublicKey(Registry.X509_ENCODING_ID,
- dsa.getP(),
- dsa.getQ(),
+ dsa.getP(), dsa.getQ(),
dsa.getG(),
((DSAPublicKey) pubKey).getY());
}
}
if (sigProvider == null)
- p[i-1].verify(pubKey);
+ p[i - 1].verify(pubKey);
else
- p[i-1].verify(pubKey, sigProvider);
+ p[i - 1].verify(pubKey, sigProvider);
prevKey = pubKey;
}
catch (Exception e)
{
throw new CertPathValidatorException(e.toString());
}
- if (!p[i].getSubjectDN().equals(p[i-1].getIssuerDN()))
+ if (! p[i].getSubjectDN().equals(p[i - 1].getIssuerDN()))
throw new CertPathValidatorException("issuer DN mismatch");
- boolean[] issuerUid = p[i-1].getIssuerUniqueID();
+ boolean[] issuerUid = p[i - 1].getIssuerUniqueID();
boolean[] subjectUid = p[i].getSubjectUniqueID();
if (issuerUid != null && subjectUid != null)
- if (!Arrays.equals(issuerUid, subjectUid))
+ if (! Arrays.equals(issuerUid, subjectUid))
throw new CertPathValidatorException("UID mismatch");
// Check the certificate against the revocation lists.
@@ -274,7 +260,7 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
}
List certStores = ((PKIXParameters) params).getCertStores();
List crls = new LinkedList();
- for (Iterator it = certStores.iterator(); it.hasNext(); )
+ for (Iterator it = certStores.iterator(); it.hasNext();)
{
CertStore cs = (CertStore) it.next();
try
@@ -289,30 +275,30 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
if (crls.isEmpty())
throw new CertPathValidatorException("no CRLs for issuer");
boolean certOk = false;
- for (Iterator it = crls.iterator(); it.hasNext(); )
+ for (Iterator it = crls.iterator(); it.hasNext();)
{
CRL crl = (CRL) it.next();
- if (!(crl instanceof X509CRL))
+ if (! (crl instanceof X509CRL))
continue;
X509CRL xcrl = (X509CRL) crl;
- if (!checkCRL(xcrl, p, now, p[i], pubKey, certStores))
+ if (! checkCRL(xcrl, p, now, p[i], pubKey, certStores))
continue;
- if (xcrl.isRevoked(p[i-1]))
+ if (xcrl.isRevoked(p[i - 1]))
throw new CertPathValidatorException("certificate is revoked");
else
certOk = true;
}
- if (!certOk)
- throw new CertPathValidatorException("certificate's validity could not be determined");
+ if (! certOk)
+ throw new CertPathValidatorException(
+ "certificate's validity could not be determined");
}
}
rootNode.setReadOnly();
-
// Now ensure that the first certificate in the chain was issued
// by a trust anchor.
Exception cause = null;
Set anchors = ((PKIXParameters) params).getTrustAnchors();
- for (Iterator i = anchors.iterator(); i.hasNext(); )
+ for (Iterator i = anchors.iterator(); i.hasNext();)
{
TrustAnchor anchor = (TrustAnchor) i.next();
X509Certificate anchorCert = null;
@@ -330,7 +316,7 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
{
if (anchorCert != null)
anchorCert.checkValidity(now);
- p[p.length-1].verify(anchorKey);
+ p[p.length - 1].verify(anchorKey);
if (anchorCert != null && anchorCert.getBasicConstraints() >= 0
&& anchorCert.getBasicConstraints() < p.length)
continue;
@@ -350,7 +336,7 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
selector.addIssuerName(anchor.getCAName());
List certStores = ((PKIXParameters) params).getCertStores();
List crls = new LinkedList();
- for (Iterator it = certStores.iterator(); it.hasNext(); )
+ for (Iterator it = certStores.iterator(); it.hasNext();)
{
CertStore cs = (CertStore) it.next();
try
@@ -364,10 +350,10 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
}
if (crls.isEmpty())
continue;
- for (Iterator it = crls.iterator(); it.hasNext(); )
+ for (Iterator it = crls.iterator(); it.hasNext();)
{
CRL crl = (CRL) it.next();
- if (!(crl instanceof X509CRL))
+ if (! (crl instanceof X509CRL))
continue;
X509CRL xcrl = (X509CRL) crl;
try
@@ -381,11 +367,10 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
Date nextUpdate = xcrl.getNextUpdate();
if (nextUpdate != null && nextUpdate.compareTo(now) < 0)
continue;
- if (xcrl.isRevoked(p[p.length-1]))
+ if (xcrl.isRevoked(p[p.length - 1]))
throw new CertPathValidatorException("certificate is revoked");
}
}
-
// The chain is valid; return the result.
return new PKIXCertPathValidatorResult(anchor, rootNode,
p[0].getPublicKey());
@@ -396,34 +381,29 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
continue;
}
}
-
// The path is not valid.
CertPathValidatorException cpve =
- new CertPathValidatorException("path validation failed");
+ new CertPathValidatorException("path validation failed");
if (cause != null)
- cpve.initCause (cause);
+ cpve.initCause(cause);
throw cpve;
}
- // Own methods.
- // -------------------------------------------------------------------------
-
/**
- * Check if a given CRL is acceptable for checking the revocation status
- * of certificates in the path being checked.
- *
- * <p>The CRL is accepted iff:</p>
- *
+ * Check if a given CRL is acceptable for checking the revocation status of
+ * certificates in the path being checked.
+ * <p>
+ * The CRL is accepted iff:
* <ol>
* <li>The <i>nextUpdate</i> field (if present) is in the future.</li>
* <li>The CRL does not contain any unsupported critical extensions.</li>
* <li>The CRL is signed by one of the certificates in the path, or,</li>
- * <li>The CRL is signed by the given public key and was issued by the
- * public key's subject, or,</li>
- * <li>The CRL is signed by a certificate in the given cert stores, and
- * that cert is signed by one of the certificates in the path.</li>
+ * <li>The CRL is signed by the given public key and was issued by the public
+ * key's subject, or,</li>
+ * <li>The CRL is signed by a certificate in the given cert stores, and that
+ * cert is signed by one of the certificates in the path.</li>
* </ol>
- *
+ *
* @param crl The CRL being checked.
* @param path The path this CRL is being checked against.
* @param now The value to use as 'now'.
@@ -431,9 +411,9 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
* @param pubKey The public key to check.
* @return True if the CRL is acceptable.
*/
- private static boolean checkCRL(X509CRL crl, X509Certificate[] path, Date now,
- X509Certificate pubKeyCert, PublicKey pubKey,
- List certStores)
+ private static boolean checkCRL(X509CRL crl, X509Certificate[] path,
+ Date now, X509Certificate pubKeyCert,
+ PublicKey pubKey, List certStores)
{
Date nextUpdate = crl.getNextUpdate();
if (nextUpdate != null && nextUpdate.compareTo(now) < 0)
@@ -442,12 +422,12 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
return false;
for (int i = 0; i < path.length; i++)
{
- if (!path[i].getSubjectDN().equals(crl.getIssuerDN()))
+ if (! path[i].getSubjectDN().equals(crl.getIssuerDN()))
continue;
boolean[] keyUsage = path[i].getKeyUsage();
if (keyUsage != null)
{
- if (!keyUsage[KeyUsage.CRL_SIGN])
+ if (! keyUsage[KeyUsage.CRL_SIGN])
continue;
}
try
@@ -466,7 +446,7 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
boolean[] keyUsage = pubKeyCert.getKeyUsage();
if (keyUsage != null)
{
- if (!keyUsage[KeyUsage.CRL_SIGN])
+ if (! keyUsage[KeyUsage.CRL_SIGN])
throw new Exception();
}
crl.verify(pubKey);
@@ -481,7 +461,7 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
X509CertSelectorImpl select = new X509CertSelectorImpl();
select.addSubjectName(crl.getIssuerDN());
List certs = new LinkedList();
- for (Iterator it = certStores.iterator(); it.hasNext(); )
+ for (Iterator it = certStores.iterator(); it.hasNext();)
{
CertStore cs = (CertStore) it.next();
try
@@ -492,17 +472,17 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
{
}
}
- for (Iterator it = certs.iterator(); it.hasNext(); )
+ for (Iterator it = certs.iterator(); it.hasNext();)
{
X509Certificate c = (X509Certificate) it.next();
for (int i = 0; i < path.length; i++)
{
- if (!c.getIssuerDN().equals(path[i].getSubjectDN()))
+ if (! c.getIssuerDN().equals(path[i].getSubjectDN()))
continue;
boolean[] keyUsage = c.getKeyUsage();
if (keyUsage != null)
{
- if (!keyUsage[KeyUsage.CRL_SIGN])
+ if (! keyUsage[KeyUsage.CRL_SIGN])
continue;
}
try
@@ -534,10 +514,10 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
if (cert instanceof GnuPKIExtension)
{
Collection exts = ((GnuPKIExtension) cert).getExtensions();
- for (Iterator it = exts.iterator(); it.hasNext(); )
+ for (Iterator it = exts.iterator(); it.hasNext();)
{
Extension ext = (Extension) it.next();
- if (ext.isCritical() && !ext.isSupported())
+ if (ext.isCritical() && ! ext.isSupported())
s.add(ext.getOid().toString());
}
}
@@ -550,13 +530,13 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
* Perform a basic sanity check on the CA certificate at <code>index</code>.
*/
private static void basicSanity(X509Certificate[] path, int index)
- throws CertPathValidatorException
+ throws CertPathValidatorException
{
X509Certificate cert = path[index];
int pathLen = 0;
for (int i = index - 1; i > 0; i--)
{
- if (!path[i].getIssuerDN().equals(path[i].getSubjectDN()))
+ if (! path[i].getIssuerDN().equals(path[i].getSubjectDN()))
pathLen++;
}
Extension e = null;
@@ -577,23 +557,27 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
if (e == null)
throw new CertPathValidatorException("no basicConstraints");
BasicConstraints bc = (BasicConstraints) e.getValue();
- if (!bc.isCA())
- throw new CertPathValidatorException("certificate cannot be used to verify signatures");
- if (bc.getPathLengthConstraint() >= 0 && bc.getPathLengthConstraint() < pathLen)
+ if (! bc.isCA())
+ throw new CertPathValidatorException(
+ "certificate cannot be used to verify signatures");
+ if (bc.getPathLengthConstraint() >= 0
+ && bc.getPathLengthConstraint() < pathLen)
throw new CertPathValidatorException("path is too long");
boolean[] keyUsage = cert.getKeyUsage();
if (keyUsage != null)
{
- if (!keyUsage[KeyUsage.KEY_CERT_SIGN])
- throw new CertPathValidatorException("certificate cannot be used to sign certificates");
+ if (! keyUsage[KeyUsage.KEY_CERT_SIGN])
+ throw new CertPathValidatorException(
+ "certificate cannot be used to sign certificates");
}
}
- private static void updatePolicyTree(X509Certificate cert, PolicyNodeImpl root,
- int depth, PKIXParameters params,
+ private static void updatePolicyTree(X509Certificate cert,
+ PolicyNodeImpl root, int depth,
+ PKIXParameters params,
boolean explicitPolicy)
- throws CertPathValidatorException
+ throws CertPathValidatorException
{
if (Configuration.DEBUG)
log.fine("updatePolicyTree depth == " + depth);
@@ -624,7 +608,7 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
}
}
}
- while (!stack.isEmpty());
+ while (! stack.isEmpty());
Extension e = null;
CertificatePolicies policies = null;
@@ -647,18 +631,18 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
log.fine("nodes are == " + nodes);
log.fine("cert policies are == " + cp);
}
- for (Iterator it = nodes.iterator(); it.hasNext(); )
+ for (Iterator it = nodes.iterator(); it.hasNext();)
{
PolicyNodeImpl parent = (PolicyNodeImpl) it.next();
if (Configuration.DEBUG)
log.fine("adding policies to " + parent);
- for (Iterator it2 = cp.iterator(); it2.hasNext(); )
+ for (Iterator it2 = cp.iterator(); it2.hasNext();)
{
OID policy = (OID) it2.next();
if (Configuration.DEBUG)
log.fine("trying to add policy == " + policy);
- if (policy.toString().equals(ANY_POLICY) &&
- params.isAnyPolicyInhibited())
+ if (policy.toString().equals(ANY_POLICY)
+ && params.isAnyPolicyInhibited())
continue;
PolicyNodeImpl child = new PolicyNodeImpl();
child.setValidPolicy(policy.toString());
@@ -673,28 +657,28 @@ public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi
parent.addChild(child);
match = true;
}
- else if (ANY_POLICY.equals (policy.toString()))
+ else if (ANY_POLICY.equals(policy.toString()))
{
- parent.addChild (child);
+ parent.addChild(child);
match = true;
}
if (match && policies != null)
{
- List qualifiers = policies.getPolicyQualifierInfos (policy);
+ List qualifiers = policies.getPolicyQualifierInfos(policy);
if (qualifiers != null)
- child.addAllPolicyQualifiers (qualifiers);
+ child.addAllPolicyQualifiers(qualifiers);
}
}
}
- if (!match && (params.isExplicitPolicyRequired() || explicitPolicy))
+ if (! match && (params.isExplicitPolicyRequired() || explicitPolicy))
throw new CertPathValidatorException("policy tree building failed");
}
- private boolean checkExplicitPolicy (int depth, List explicitPolicies)
+ private boolean checkExplicitPolicy(int depth, List explicitPolicies)
{
if (Configuration.DEBUG)
log.fine("checkExplicitPolicy depth=" + depth);
- for (Iterator it = explicitPolicies.iterator(); it.hasNext(); )
+ for (Iterator it = explicitPolicies.iterator(); it.hasNext();)
{
int[] i = (int[]) it.next();
int caDepth = i[0];
diff --git a/gnu/java/security/provider/X509CertificateFactory.java b/gnu/java/security/provider/X509CertificateFactory.java
index 1a415eabb..7d61779f9 100644
--- a/gnu/java/security/provider/X509CertificateFactory.java
+++ b/gnu/java/security/provider/X509CertificateFactory.java
@@ -59,30 +59,24 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-public class X509CertificateFactory extends CertificateFactorySpi
+public class X509CertificateFactory
+ extends CertificateFactorySpi
{
-
- // Constants.
- // ------------------------------------------------------------------------
-
public static final String BEGIN_CERTIFICATE = "-----BEGIN CERTIFICATE-----";
+
public static final String END_CERTIFICATE = "-----END CERTIFICATE-----";
+
public static final String BEGIN_X509_CRL = "-----BEGIN X509 CRL-----";
- public static final String END_X509_CRL = "-----END X509 CRL-----";
- // Constructors.
- // ------------------------------------------------------------------------
+ public static final String END_X509_CRL = "-----END X509 CRL-----";
public X509CertificateFactory()
{
super();
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public Certificate engineGenerateCertificate(InputStream inStream)
- throws CertificateException
+ throws CertificateException
{
try
{
@@ -91,13 +85,13 @@ public class X509CertificateFactory extends CertificateFactorySpi
catch (IOException ioe)
{
CertificateException ce = new CertificateException(ioe.getMessage());
- ce.initCause (ioe);
+ ce.initCause(ioe);
throw ce;
}
}
public Collection engineGenerateCertificates(InputStream inStream)
- throws CertificateException
+ throws CertificateException
{
LinkedList certs = new LinkedList();
while (true)
@@ -113,7 +107,7 @@ public class X509CertificateFactory extends CertificateFactorySpi
catch (IOException ioe)
{
CertificateException ce = new CertificateException(ioe.getMessage());
- ce.initCause (ioe);
+ ce.initCause(ioe);
throw ce;
}
}
@@ -129,13 +123,13 @@ public class X509CertificateFactory extends CertificateFactorySpi
catch (IOException ioe)
{
CRLException crle = new CRLException(ioe.getMessage());
- crle.initCause (ioe);
+ crle.initCause(ioe);
throw crle;
}
}
public Collection engineGenerateCRLs(InputStream inStream)
- throws CRLException
+ throws CRLException
{
LinkedList crls = new LinkedList();
while (true)
@@ -151,7 +145,7 @@ public class X509CertificateFactory extends CertificateFactorySpi
catch (IOException ioe)
{
CRLException crle = new CRLException(ioe.getMessage());
- crle.initCause (ioe);
+ crle.initCause(ioe);
throw crle;
}
}
@@ -164,13 +158,13 @@ public class X509CertificateFactory extends CertificateFactorySpi
}
public CertPath engineGenerateCertPath(InputStream in)
- throws CertificateEncodingException
+ throws CertificateEncodingException
{
return new X509CertPath(in);
}
public CertPath engineGenerateCertPath(InputStream in, String encoding)
- throws CertificateEncodingException
+ throws CertificateEncodingException
{
return new X509CertPath(in, encoding);
}
@@ -180,21 +174,17 @@ public class X509CertificateFactory extends CertificateFactorySpi
return X509CertPath.ENCODINGS.iterator();
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private X509Certificate generateCert(InputStream inStream)
- throws IOException, CertificateException
+ throws IOException, CertificateException
{
if (inStream == null)
throw new CertificateException("missing input stream");
- if (!inStream.markSupported())
+ if (! inStream.markSupported())
inStream = new BufferedInputStream(inStream, 8192);
inStream.mark(20);
int i = inStream.read();
if (i == -1)
throw new EOFException();
-
// If the input is in binary DER format, the first byte MUST be
// 0x30, which stands for the ASN.1 [UNIVERSAL 16], which is the
// UNIVERSAL SEQUENCE, with the CONSTRUCTED bit (0x20) set.
@@ -217,9 +207,9 @@ public class X509CertificateFactory extends CertificateFactorySpi
}
while (i != '\n' && i != '\r');
}
- while (!line.toString().equals(BEGIN_CERTIFICATE));
+ while (! line.toString().equals(BEGIN_CERTIFICATE));
X509Certificate ret = new X509Certificate(
- new BufferedInputStream(new Base64InputStream(inStream), 8192));
+ new BufferedInputStream(new Base64InputStream(inStream), 8192));
line.setLength(0);
line.append('-'); // Base64InputStream will eat this.
do
@@ -232,7 +222,7 @@ public class X509CertificateFactory extends CertificateFactorySpi
}
while (i != '\n' && i != '\r');
// XXX ???
- if (!line.toString().equals(END_CERTIFICATE))
+ if (! line.toString().equals(END_CERTIFICATE))
throw new CertificateException("no end-of-certificate marker");
return ret;
}
@@ -243,18 +233,17 @@ public class X509CertificateFactory extends CertificateFactorySpi
}
}
- private X509CRL generateCRL(InputStream inStream)
- throws IOException, CRLException
+ private X509CRL generateCRL(InputStream inStream) throws IOException,
+ CRLException
{
if (inStream == null)
throw new CRLException("missing input stream");
- if (!inStream.markSupported())
+ if (! inStream.markSupported())
inStream = new BufferedInputStream(inStream, 8192);
inStream.mark(20);
int i = inStream.read();
if (i == -1)
throw new EOFException();
-
// If the input is in binary DER format, the first byte MUST be
// 0x30, which stands for the ASN.1 [UNIVERSAL 16], which is the
// UNIVERSAL SEQUENCE, with the CONSTRUCTED bit (0x20) set.
@@ -277,9 +266,9 @@ public class X509CertificateFactory extends CertificateFactorySpi
}
while (i != '\n' && i != '\r');
}
- while (!line.toString().startsWith(BEGIN_X509_CRL));
+ while (! line.toString().startsWith(BEGIN_X509_CRL));
X509CRL ret = new X509CRL(
- new BufferedInputStream(new Base64InputStream(inStream), 8192));
+ new BufferedInputStream(new Base64InputStream(inStream), 8192));
line.setLength(0);
line.append('-'); // Base64InputStream will eat this.
do
@@ -292,7 +281,7 @@ public class X509CertificateFactory extends CertificateFactorySpi
}
while (i != '\n' && i != '\r');
// XXX ???
- if (!line.toString().startsWith(END_X509_CRL))
+ if (! line.toString().startsWith(END_X509_CRL))
throw new CRLException("no end-of-CRL marker");
return ret;
}
diff --git a/gnu/java/security/sig/BaseSignature.java b/gnu/java/security/sig/BaseSignature.java
index dd964d481..9c76cacba 100644
--- a/gnu/java/security/sig/BaseSignature.java
+++ b/gnu/java/security/sig/BaseSignature.java
@@ -49,15 +49,11 @@ import java.util.Map;
import java.util.Random;
/**
- * <p>A base abstract class to facilitate implementations of concrete
- * Signatures.</p>
+ * A base abstract class to facilitate implementations of concrete Signatures.
*/
-public abstract class BaseSignature implements ISignature
+public abstract class BaseSignature
+ implements ISignature
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The canonical name of this signature scheme. */
protected String schemeName;
@@ -79,9 +75,6 @@ public abstract class BaseSignature implements ISignature
/** Our default source of randomness. */
private PRNG prng = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Trivial constructor.
*
@@ -101,14 +94,6 @@ public abstract class BaseSignature implements ISignature
this.md = md;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // gnu.crypto.sig.ISignature interface implementation ----------------------
-
public String name()
{
return schemeName + "-" + md.name();
@@ -117,51 +102,41 @@ public abstract class BaseSignature implements ISignature
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);
- }
+ 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);
- }
+ setupForSigning(key);
}
public void update(byte b)
{
if (md == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
+
md.update(b);
}
public void update(byte[] b, int off, int len)
{
if (md == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
+
md.update(b, off, len);
}
public Object sign()
{
if (md == null || privateKey == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return generateSignature();
}
@@ -169,15 +144,11 @@ public abstract class BaseSignature implements ISignature
public boolean verify(Object sig)
{
if (md == null || publicKey == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return verifySignature(sig);
}
- // abstract methods to be implemented by concrete subclasses ---------------
-
public abstract Object clone();
protected abstract void setupForVerification(PublicKey key)
@@ -191,8 +162,6 @@ public abstract class BaseSignature implements ISignature
protected abstract boolean verifySignature(Object signature)
throws IllegalStateException;
- // Other instance methods --------------------------------------------------
-
/** Initialises the internal fields of this instance. */
protected void init()
{
@@ -204,33 +173,27 @@ public abstract class BaseSignature implements ISignature
}
/**
- * <p>Fills the designated byte array with random data.</p>
- *
+ * 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);
- }
+ 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));
- }
- }
+ try
+ {
+ irnd.nextBytes(buffer, 0, buffer.length);
+ }
+ catch (IllegalStateException x)
+ {
+ throw new RuntimeException("nextRandomBytes(): " + x);
+ }
+ catch (LimitReachedException x)
+ {
+ throw new RuntimeException("nextRandomBytes(): " + x);
+ }
else
getDefaultPRNG().nextBytes(buffer);
}
@@ -238,17 +201,12 @@ public abstract class BaseSignature implements ISignature
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;
- }
+ rnd = (Random) obj;
else if (obj instanceof IRandom)
- {
- irnd = (IRandom) obj;
- }
+ irnd = (IRandom) obj;
}
private PRNG getDefaultPRNG()
diff --git a/gnu/java/security/sig/ISignature.java b/gnu/java/security/sig/ISignature.java
index 9ad853a29..ff25f29d9 100644
--- a/gnu/java/security/sig/ISignature.java
+++ b/gnu/java/security/sig/ISignature.java
@@ -41,28 +41,24 @@ package gnu.java.security.sig;
import java.util.Map;
/**
- * <p>The visible methods of every signature-with-appendix scheme.</p>
- *
- * <p>The Handbook of Applied Cryptography (HAC), by A. Menezes &amp; al. states:
+ * The visible methods of every signature-with-appendix scheme.
+ * <p>
+ * The Handbook of Applied Cryptography (HAC), by A. Menezes &amp; al. states:
* "Digital signature schemes which require the message as input to the
- * verification algorithm are called <i>digital signature schemes with
- * appendix</i>. ... They rely on cryptographic hash functions rather than
- * customised redundancy functions, and are less prone to existential forgery
- * attacks."</p>
- *
- * <p>References:</p>
+ * verification algorithm are called <i>digital signature schemes with appendix</i>.
+ * ... They rely on cryptographic hash functions rather than customised
+ * redundancy functions, and are less prone to existential forgery attacks."
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cacr.math.uwaterloo.ca/hac/">Handbook of Applied
- * Cryptography</a>, Alfred J. Menezes, Paul C. van Oorschot and Scott A.
- * Vanstone. Section 11.2.2 Digital signature schemes with appendix.</li>
+ * <li><a href="http://www.cacr.math.uwaterloo.ca/hac/">Handbook of Applied
+ * Cryptography</a>, Alfred J. Menezes, Paul C. van Oorschot and Scott A.
+ * Vanstone. Section 11.2.2 Digital signature schemes with appendix.</li>
* </ol>
*/
-public interface ISignature extends Cloneable
+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";
@@ -71,96 +67,93 @@ public interface ISignature extends Cloneable
/**
* Property name of an optional {@link java.security.SecureRandom},
- * {@link java.util.Random}, or {@link gnu.java.security.prng.IRandom} instance to
- * use. The default is to use a classloader singleton from
+ * {@link java.util.Random}, or {@link gnu.java.security.prng.IRandom}
+ * instance to use. The default is to use a classloader singleton from
* {@link gnu.java.security.util.PRNG}.
*/
public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.sig.prng";
- // Methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the canonical name of this signature scheme.</p>
- *
+ * Returns the canonical name of this signature scheme.
+ *
* @return the canonical name of this instance.
*/
String name();
/**
- * <p>Initialises this instance for signature verification.</p>
- *
+ * 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.
+ * appropriate for this signature scheme.
* @see #SOURCE_OF_RANDOMNESS
* @see #VERIFIER_KEY
*/
void setupVerify(Map attributes) throws IllegalArgumentException;
/**
- * <p>Initialises this instance for signature generation.</p>
- *
+ * 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.
+ * appropriate for this signature scheme.
* @see #SOURCE_OF_RANDOMNESS
* @see #SIGNER_KEY
*/
void setupSign(Map attributes) throws IllegalArgumentException;
/**
- * <p>Digests one byte of a message for signing or verification purposes.</p>
- *
+ * 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.
+ * @throws IllegalStateException if this instance was not setup for signature
+ * generation/verification.
*/
void update(byte b) throws IllegalStateException;
/**
- * <p>Digests a sequence of bytes from a message for signing or verification
- * purposes.</p>
- *
+ * 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 <code>buffer</code> of the first byte
- * to consider.
- * @param length the number of bytes in <code>buffer</code> starting from the
- * byte at index <code>offset</code> to digest.
- * @throws IllegalStateException if this instance was not setup for
- * signature generation/verification.
+ * to consider.
+ * @param length the number of bytes in <code>buffer</code> starting from
+ * the byte at index <code>offset</code> to digest.
+ * @throws IllegalStateException if this instance was not setup for signature
+ * generation/verification.
*/
void update(byte[] buffer, int offset, int length)
throws IllegalStateException;
/**
- * <p>Terminates a signature generation phase by digesting and processing the
- * context of the underlying message digest algorithm instance.</p>
- *
+ * 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.
+ * scheme implementation.
+ * @throws IllegalStateException if this instance was not setup for signature
+ * generation.
*/
Object sign() throws IllegalStateException;
/**
- * <p>Terminates a signature verification phase by digesting and processing
- * the context of the underlying message digest algorithm instance.</p>
- *
+ * 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 <code>sign()</code> method.
+ * invocation of the <code>sign()</code> method.
* @return <code>true</code> 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.
+ * 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;
/**
- * <p>Returns a clone copy of this instance.</p>
- *
+ * Returns a clone copy of this instance.
+ *
* @return a clone copy of this instance.
*/
Object clone();
diff --git a/gnu/java/security/sig/ISignatureCodec.java b/gnu/java/security/sig/ISignatureCodec.java
index b6ab0ba9b..aaae6ccb0 100644
--- a/gnu/java/security/sig/ISignatureCodec.java
+++ b/gnu/java/security/sig/ISignatureCodec.java
@@ -41,23 +41,16 @@ package gnu.java.security.sig;
import gnu.java.security.Registry;
/**
- * <p>The visible methods of an object that knows how to encode and decode
+ * 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.</p>
+ * creating their internal Java representation from external sources.
*/
public interface ISignatureCodec
{
-
- // Constants
- // -------------------------------------------------------------------------
-
/** Constant identifying the <i>Raw</i> encoding format. */
int RAW_FORMAT = Registry.RAW_ENCODING_ID;
- // Method(s)
- // -------------------------------------------------------------------------
-
int getFormatID();
byte[] encodeSignature(Object signature);
diff --git a/gnu/java/security/sig/SignatureFactory.java b/gnu/java/security/sig/SignatureFactory.java
index d5bd728ad..28b68925b 100644
--- a/gnu/java/security/sig/SignatureFactory.java
+++ b/gnu/java/security/sig/SignatureFactory.java
@@ -53,38 +53,28 @@ 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 <code>null</code> if none found.
*/
public static final ISignature getInstance(String ssa)
{
if (ssa == null)
- {
- return 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();
- }
+ result = new DSSSignature();
else if (ssa.startsWith(Registry.RSA_SIG_PREFIX))
result = RSASignatureFactory.getInstance(ssa);
@@ -92,9 +82,9 @@ public class SignatureFactory
}
/**
- * Returns a {@link Set} of signature-with-appendix scheme names supported
- * by this <i>Factory</i>.
- *
+ * Returns a {@link Set} of signature-with-appendix scheme names supported by
+ * this <i>Factory</i>.
+ *
* @return a {@link Set} of signature-with-appendix scheme names (Strings).
*/
public static synchronized final Set getNames()
@@ -104,10 +94,8 @@ public class SignatureFactory
HashSet hs = new HashSet();
hs.add(Registry.DSS_SIG);
hs.addAll(RSASignatureFactory.getNames());
-
names = Collections.unmodifiableSet(hs);
}
-
return names;
}
}
diff --git a/gnu/java/security/sig/dss/DSSSignature.java b/gnu/java/security/sig/dss/DSSSignature.java
index 370a93854..1ef1bea1a 100644
--- a/gnu/java/security/sig/dss/DSSSignature.java
+++ b/gnu/java/security/sig/dss/DSSSignature.java
@@ -55,72 +55,65 @@ import java.util.Map;
import java.util.Random;
/**
- * <p>The DSS (Digital Signature Standard) algorithm makes use of the following
- * parameters:</p>
- *
+ * The DSS (Digital Signature Standard) algorithm makes use of the following
+ * parameters:
* <ol>
- * <li>p: A prime modulus, where <code>2<sup>L-1</sup> &lt; p &lt; 2<sup>L</sup>
- * </code> for <code>512 &lt;= L &lt;= 1024</code> and <code>L</code> a
- * multiple of <code>64</code>.</li>
- * <li>q: A prime divisor of <code>p - 1</code>, where <code>2<sup>159</sup>
+ * <li>p: A prime modulus, where
+ * <code>2<sup>L-1</sup> &lt; p &lt; 2<sup>L</sup> </code> for <code>512 &lt;= L
+ * &lt;= 1024</code> and <code>L</code> a multiple of <code>64</code>.</li>
+ * <li>q: A prime divisor of <code>p - 1</code>, where <code>2<sup>159</sup>
* &lt; q &lt; 2<sup>160</sup></code>.</li>
- * <li>g: Where <code>g = h<sup>(p-1)</sup>/q mod p</code>, where
- * <code>h</code> is any integer with <code>1 &lt; h &lt; p - 1</code> such
- * that <code>h<sup> (p-1)</sup>/q mod p > 1</code> (<code>g</code> has order
- * <code>q mod p</code>).</li>
- * <li>x: A randomly or pseudorandomly generated integer with <code>0 &lt; x
+ * <li>g: Where <code>g = h<sup>(p-1)</sup>/q mod p</code>, where
+ * <code>h</code> is any integer with <code>1 &lt; h &lt; p - 1</code> such
+ * that <code>h<sup> (p-1)</sup>/q mod p > 1</code> (<code>g</code> has order
+ * <code>q mod p</code>).</li>
+ * <li>x: A randomly or pseudorandomly generated integer with <code>0 &lt; x
* &lt; q</code>.</li>
- * <li>y: <code>y = g<sup>x</sup> mod p</code>.</li>
- * <li>k: A randomly or pseudorandomly generated integer with <code>0 &lt; k
+ * <li>y: <code>y = g<sup>x</sup> mod p</code>.</li>
+ * <li>k: A randomly or pseudorandomly generated integer with <code>0 &lt; k
* &lt; q</code>.</li>
* </ol>
- *
- * <p>The integers <code>p</code>, <code>q</code>, and <code>g</code> can be
+ * <p>
+ * The integers <code>p</code>, <code>q</code>, and <code>g</code> can be
* public and can be common to a group of users. A user's private and public
- * keys are <code>x</code> and <code>y</code>, respectively. They are normally
- * fixed for a period of time. Parameters <code>x</code> and <code>k</code> are
- * used for signature generation only, and must be kept secret. Parameter
- * <code>k</code> must be regenerated for each signature.</p>
- *
- * <p>The signature of a message <code>M</code> is the pair of numbers <code>r</code>
- * and <code>s</code> computed according to the equations below:</p>
- *
+ * keys are <code>x</code> and <code>y</code>, respectively. They are
+ * normally fixed for a period of time. Parameters <code>x</code> and
+ * <code>k</code> are used for signature generation only, and must be kept
+ * secret. Parameter <code>k</code> must be regenerated for each signature.
+ * <p>
+ * The signature of a message <code>M</code> is the pair of numbers
+ * <code>r</code> and <code>s</code> computed according to the equations below:
* <ul>
- * <li><code>r = (g<sup>k</sup> mod p) mod q</code> and</li>
- * <li><code>s = (k<sup>-1</sup>(SHA(M) + xr)) mod q</code>.</li>
+ * <li><code>r = (g<sup>k</sup> mod p) mod q</code> and</li>
+ * <li><code>s = (k<sup>-1</sup>(SHA(M) + xr)) mod q</code>.</li>
* </ul>
- *
- * <p>In the above, <code>k<sup>-1</sup></code> is the multiplicative inverse of
- * <code>k</code>, <code>mod q</code>; i.e., <code>(k<sup>-1</sup> k) mod q = 1
- * </code> and <code>0 &lt; k-1 &lt; q</code>. The value of <code>SHA(M)</code>
- * is a 160-bit string output by the Secure Hash Algorithm specified in FIPS 180.
- * For use in computing <code>s</code>, this string must be converted to an
- * integer.</p>
- *
- * <p>As an option, one may wish to check if <code>r == 0</code> or <code>s == 0
- * </code>. If either <code>r == 0</code> or <code>s == 0</code>, a new value
- * of <code>k</code> should be generated and the signature should be
- * recalculated (it is extremely unlikely that <code>r == 0</code> or <code>s ==
- * 0</code> if signatures are generated properly).</p>
- *
- * <p>The signature is transmitted along with the message to the verifier.</p>
- *
- * <p>References:</p>
+ * <p>
+ * In the above, <code>k<sup>-1</sup></code> is the multiplicative inverse of
+ * <code>k</code>, <code>mod q</code>; i.e., <code>(k<sup>-1</sup> k) mod q =
+ * 1</code> and <code>0 &lt; k-1 &lt; q</code>. The value of <code>SHA(M)</code>
+ * is a 160-bit string output by the Secure Hash Algorithm specified in FIPS
+ * 180. For use in computing <code>s</code>, this string must be converted to
+ * an integer.
+ * <p>
+ * As an option, one may wish to check if <code>r == 0</code> or <code>s == 0
+ * </code>.
+ * If either <code>r == 0</code> or <code>s == 0</code>, a new value of
+ * <code>k</code> should be generated and the signature should be recalculated
+ * (it is extremely unlikely that <code>r == 0</code> or <code>s == 0</code> if
+ * signatures are generated properly).
+ * <p>
+ * The signature is transmitted along with the message to the verifier.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.itl.nist.gov/fipspubs/fip186.htm">Digital
- * Signature Standard (DSS)</a>, Federal Information Processing Standards
- * Publication 186. National Institute of Standards and Technology.</li>
+ * <li><a href="http://www.itl.nist.gov/fipspubs/fip186.htm">Digital Signature
+ * Standard (DSS)</a>, Federal Information Processing Standards Publication
+ * 186. National Institute of Standards and Technology.</li>
* </ol>
*/
-public class DSSSignature extends BaseSignature
+public class DSSSignature
+ extends BaseSignature
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public DSSSignature()
{
@@ -137,16 +130,12 @@ public class DSSSignature extends BaseSignature
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);
}
@@ -157,11 +146,9 @@ public class DSSSignature extends BaseSignature
final Map attributes = new HashMap();
attributes.put(ISignature.SIGNER_KEY, k);
if (rnd != null)
- {
- attributes.put(ISignature.SOURCE_OF_RANDOMNESS, rnd);
- }
- sig.setupSign(attributes);
+ attributes.put(ISignature.SOURCE_OF_RANDOMNESS, rnd);
+ sig.setupSign(attributes);
return sig.computeRS(h);
}
@@ -172,11 +159,9 @@ public class DSSSignature extends BaseSignature
final Map attributes = new HashMap();
attributes.put(ISignature.SIGNER_KEY, k);
if (irnd != null)
- {
- attributes.put(ISignature.SOURCE_OF_RANDOMNESS, irnd);
- }
- sig.setupSign(attributes);
+ attributes.put(ISignature.SOURCE_OF_RANDOMNESS, irnd);
+ sig.setupSign(attributes);
return sig.computeRS(h);
}
@@ -187,13 +172,9 @@ public class DSSSignature extends BaseSignature
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);
@@ -202,81 +183,37 @@ public class DSSSignature extends BaseSignature
protected void setupForVerification(PublicKey k)
throws IllegalArgumentException
{
- if (!(k instanceof DSAPublicKey))
- {
- throw new 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();
- }
+ 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.<p>
- *
+ * Returns the output of a signature generation phase.
+ *
* @return an object encapsulating the DSS signature pair <code>r</code> and
- * <code>s</code>.
+ * <code>s</code>.
*/
private Object encodeSignature(BigInteger r, BigInteger s)
{
@@ -284,9 +221,9 @@ public class DSSSignature extends BaseSignature
}
/**
- * Returns the output of a previously generated signature object as a pair
- * of {@link java.math.BigInteger}.<p>
- *
+ * Returns the output of a previously generated signature object as a pair of
+ * {@link java.math.BigInteger}.
+ *
* @return the DSS signature pair <code>r</code> and <code>s</code>.
*/
private BigInteger[] decodeSignature(Object signature)
@@ -302,7 +239,6 @@ public class DSSSignature extends BaseSignature
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)
{
@@ -311,17 +247,14 @@ public class DSSSignature extends BaseSignature
k.clearBit(159);
r = g.modPow(k, p).mod(q);
if (r.equals(BigInteger.ZERO))
- {
- continue;
- }
+ continue;
+
s = m.add(x.multiply(r)).multiply(k.modInverse(q)).mod(q);
if (s.equals(BigInteger.ZERO))
- {
- continue;
- }
+ continue;
+
break;
}
-
return new BigInteger[] { r, s };
}
@@ -329,16 +262,13 @@ public class DSSSignature extends BaseSignature
{
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/gnu/java/security/sig/dss/DSSSignatureRawCodec.java b/gnu/java/security/sig/dss/DSSSignatureRawCodec.java
index b0590a573..903d7aad6 100644
--- a/gnu/java/security/sig/dss/DSSSignatureRawCodec.java
+++ b/gnu/java/security/sig/dss/DSSSignatureRawCodec.java
@@ -45,61 +45,46 @@ import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
/**
- * <p>An object that implements the {@link ISignatureCodec} operations for the
- * <i>Raw</i> format to use with DSS signatures.</p>
+ * An object that implements the {@link ISignatureCodec} operations for the
+ * <i>Raw</i> format to use with DSS signatures.
*/
-public class DSSSignatureRawCodec implements ISignatureCodec
+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;
}
/**
- * <p>Returns the encoded form of the designated DSS (Digital Signature
- * Standard) signature object according to the <i>Raw</i> format supported by
- * this library.</p>
- *
- * <p>The <i>Raw</i> format for a DSA signature, in this implementation, is a
- * byte sequence consisting of the following:</p>
- *
+ * Returns the encoded form of the designated DSS (Digital Signature Standard)
+ * signature object according to the <i>Raw</i> format supported by this
+ * library.
+ * <p>
+ * The <i>Raw</i> format for a DSA signature, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_DSS_SIGNATURE},</li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the DSS parameter
- * <code>r</code> in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSS parameter <code>r</code>,</li>
- * <li>4-byte count of following bytes representing the DSS parameter
- * <code>s</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DSS parameter <code>s</code>.</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_DSS_SIGNATURE},</li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the DSS parameter
+ * <code>r</code> in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSS parameter <code>r</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DSS parameter
+ * <code>s</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DSS parameter <code>s</code>.
+ * </li>
* </ol>
- *
+ *
* @param signature the signature to encode, consisting of the two DSS
- * parameters <code>r</code> and <code>s</code> as a {@link java.math.BigInteger}
- * array.
+ * parameters <code>r</code> and <code>s</code> as a
+ * {@link BigInteger} array.
* @return the <i>Raw</i> format encoding of the designated signature.
* @exception IllegalArgumentException if the designated signature is not a
- * DSS (Digital Signature Standard) one.
+ * DSS (Digital Signature Standard) one.
*/
public byte[] encodeSignature(Object signature)
{
@@ -112,38 +97,32 @@ public class DSSSignatureRawCodec implements ISignatureCodec
}
catch (Exception x)
{
- throw new IllegalArgumentException("key");
+ throw new IllegalArgumentException("signature");
}
-
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 >>> 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 >>> 24);
baos.write((length >>> 16) & 0xFF);
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -154,36 +133,32 @@ public class DSSSignatureRawCodec implements ISignatureCodec
|| 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");
- }
-
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
+ 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);
+ 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);
+ 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/gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java b/gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java
index efe580d51..39de01f02 100644
--- a/gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java
+++ b/gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java
@@ -47,25 +47,21 @@ import java.security.interfaces.RSAKey;
import java.util.Random;
/**
- * <p>An implementation of the EME-PKCS1-V1.5 encoding and decoding methods.</p>
- *
- * <p>EME-PKCS1-V1.5 is parameterised by the entity <code>k</code> which is the
- * byte count of an RSA public shared modulus.</p>
- *
- * <p>References:</p>
+ * An implementation of the EME-PKCS1-V1.5 encoding and decoding methods.
+ * <p>
+ * EME-PKCS1-V1.5 is parameterised by the entity <code>k</code> which is the
+ * byte count of an RSA public shared modulus.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
- * Standards (PKCS) #1:</a><br>
- * RSA Cryptography Specifications Version 2.1.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
+ * Standards (PKCS) #1:</a><br>
+ * RSA Cryptography Specifications Version 2.1.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
* </ol>
*/
public class EME_PKCS1_V1_5
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private int k;
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -73,9 +69,6 @@ public class EME_PKCS1_V1_5
/** Our default source of randomness. */
private PRNG prng = PRNG.getInstance();
- // Constructor(s)
- // -------------------------------------------------------------------------
-
private EME_PKCS1_V1_5(final int k)
{
super();
@@ -83,15 +76,11 @@ public class EME_PKCS1_V1_5
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");
- }
+ throw new IllegalArgumentException("k must be a positive integer");
+
return new EME_PKCS1_V1_5(k);
}
@@ -102,34 +91,29 @@ public class EME_PKCS1_V1_5
return EME_PKCS1_V1_5.getInstance(k);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Generates an octet string <code>PS</code> of length <code>k - mLen -
- * 3</code> consisting of pseudo-randomly generated nonzero octets. The
- * length of <code>PS</code> will be at least eight octets.</p>
- *
- * <p>The method then concatenates <code>PS</code>, the message <code>M</code>,
+ * Generates an octet string <code>PS</code> of length <code>k - mLen -
+ * 3</code> consisting of pseudo-randomly generated nonzero octets. The length
+ * of <code>PS</code> will be at least eight octets.
+ * <p>
+ * The method then concatenates <code>PS</code>, the message <code>M</code>,
* and other padding to form an encoded message <code>EM</code> of length
- * <code>k</code> octets as:</p>
- *
+ * <code>k</code> octets as:
* <pre>
- * EM = 0x00 || 0x02 || PS || 0x00 || M.
+ * EM = 0x00 || 0x02 || PS || 0x00 || M.
* </pre>
- *
- * <p>This method uses a default PRNG to obtain the padding bytes.</p>
- *
+ * <p>
+ * This method uses a default PRNG to obtain the padding bytes.
+ *
* @param M the message to encode.
* @return the encoded message <code>EM</code>.
*/
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.
+ // 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;
@@ -139,17 +123,17 @@ public class EME_PKCS1_V1_5
PS[i] = 1;
}
// b. Concatenate PS, the message M, and other padding to form an
- // encoded message EM of length k octets as
+ // encoded message EM of length k octets as
//
- // EM = 0x00 || 0x02 || PS || 0x00 || M.
+ // EM = 0x00 || 0x02 || PS || 0x00 || M.
return assembleEM(PS, M);
}
/**
- * <p>Similar to {@link #encode(byte[])} method, except that the source of
+ * 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.</p>
- *
+ * {@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 <code>EM</code>.
@@ -183,14 +167,13 @@ public class EME_PKCS1_V1_5
{
throw new RuntimeException("encode(): " + String.valueOf(x));
}
-
return assembleEM(PS, M);
}
/**
- * <p>Similar to the {@link #encode(byte[], IRandom)} method, except that
- * the source of randmoness is an instance of {@link Random}.
- *
+ * 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 <code>EM</code>.
@@ -213,33 +196,31 @@ public class EME_PKCS1_V1_5
}
break;
}
-
return assembleEM(PS, M);
}
/**
- * <p>Separate the encoded message <code>EM</code> into an octet string
+ * Separate the encoded message <code>EM</code> into an octet string
* <code>PS</code> consisting of nonzero octets and a message <code>M</code>
- * as:</p>
- *
+ * as:
* <pre>
- * EM = 0x00 || 0x02 || PS || 0x00 || M.
+ * EM = 0x00 || 0x02 || PS || 0x00 || M.
* </pre>
- *
- * <p>If the first octet of <code>EM</code> does not have hexadecimal value
- * <code>0x00</code>, if the second octet of <code>EM</code> does not have
- * hexadecimal value <code>0x02</code>, if there is no octet with hexadecimal
- * value <code>0x00</code> to separate <code>PS</code> from <code>M</code>,
- * or if the length of <code>PS</code> is less than <code>8</code> octets,
- * output "decryption error" and stop.</p>
-
+ * <p>
+ * If the first octet of <code>EM</code> does not have hexadecimal value
+ * <code>0x00</code>, if the second octet of <code>EM</code> does not
+ * have hexadecimal value <code>0x02</code>, if there is no octet with
+ * hexadecimal value <code>0x00</code> to separate <code>PS</code> from
+ * <code>M</code>, or if the length of <code>PS</code> is less than
+ * <code>8</code> octets, output "decryption error" and stop.
+ *
* @param EM the designated encoded message.
* @return the decoded message <code>M</code> framed in the designated
- * <code>EM</code> value.
+ * <code>EM</code> value.
* @throws IllegalArgumentException if the length of the designated entity
- * <code>EM</code> is different than <code>k</code> (the length in bytes of
- * the public shared modulus), or if any of the conditions described above
- * is detected.
+ * <code>EM</code> is different than <code>k</code> (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)
{
@@ -252,46 +233,34 @@ public class EME_PKCS1_V1_5
// 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.)
+ // "decryption error" and stop. (See the note below.)
final int emLen = EM.length;
if (emLen != k)
- {
- throw new IllegalArgumentException("decryption error");
- }
+ throw new IllegalArgumentException("decryption error");
if (EM[0] != 0x00)
- {
- throw new IllegalArgumentException("decryption error");
- }
+ throw new IllegalArgumentException("decryption error");
if (EM[1] != 0x02)
- {
- throw new IllegalArgumentException("decryption error");
- }
+ throw new IllegalArgumentException("decryption error");
int i = 2;
for (; i < emLen; i++)
{
if (EM[i] == 0x00)
- {
- break;
- }
+ break;
}
if (i >= emLen || i < 11)
- {
- throw new IllegalArgumentException("decryption error");
- }
+ 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
+ // encoded message EM of length k octets as
//
- // EM = 0x00 || 0x02 || PS || 0x00 || M.
+ // EM = 0x00 || 0x02 || PS || 0x00 || M.
baos.reset();
baos.write(0x00);
baos.write(0x02);
@@ -300,7 +269,6 @@ public class EME_PKCS1_V1_5
baos.write(M, 0, M.length);
final byte[] result = baos.toByteArray();
baos.reset();
-
return result;
}
}
diff --git a/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java b/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java
index d155fc88f..a0c4de17f 100644
--- a/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java
+++ b/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java
@@ -45,12 +45,12 @@ import gnu.java.security.hash.IMessageDigest;
import java.io.ByteArrayOutputStream;
/**
- * <p>An implementation of the EMSA-PKCS1-V1.5 encoding scheme.</p>
- *
- * <p>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.</p>
- *
- * <p>References:</p>
+ * An implementation of the EMSA-PKCS1-V1.5 encoding scheme.
+ * <p>
+ * 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.
+ * <p>
+ * References:
* <ol>
* <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
* Standards (PKCS) #1:</a><br>
@@ -58,12 +58,9 @@ import java.io.ByteArrayOutputStream;
* Jakob Jonsson and Burt Kaliski.</li>
* </ol>
*/
-public class EMSA_PKCS1_V1_5 implements Cloneable
+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:
@@ -75,67 +72,46 @@ public class EMSA_PKCS1_V1_5 implements Cloneable
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 };
+ 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;
@@ -146,11 +122,8 @@ public class EMSA_PKCS1_V1_5 implements Cloneable
/** The DER part of DigestInfo not containing the hash value itself. */
private byte[] prefix;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Trivial private constructor to enforce use through Factory method.</p>
+ * Trivial private constructor to enforce use through Factory method.
*
* @param hash the message digest instance to use with this scheme instance.
*/
@@ -162,41 +135,24 @@ public class EMSA_PKCS1_V1_5 implements Cloneable
hLen = hash.hashSize();
final String name = hash.name();
if (name.equals(Registry.MD2_HASH))
- {
- prefix = MD2_PREFIX;
- }
+ prefix = MD2_PREFIX;
else if (name.equals(Registry.MD5_HASH))
- {
- prefix = MD5_PREFIX;
- }
+ prefix = MD5_PREFIX;
else if (name.equals(Registry.SHA160_HASH))
- {
- prefix = SHA160_PREFIX;
- }
+ prefix = SHA160_PREFIX;
else if (name.equals(Registry.SHA256_HASH))
- {
- prefix = SHA256_PREFIX;
- }
+ prefix = SHA256_PREFIX;
else if (name.equals(Registry.SHA384_HASH))
- {
- prefix = SHA384_PREFIX;
- }
+ prefix = SHA384_PREFIX;
else if (name.equals(Registry.SHA512_HASH))
- {
- prefix = SHA512_PREFIX;
- }
+ prefix = SHA512_PREFIX;
else
- {
- throw new UnsupportedOperationException(); // should not happen
- }
+ throw new UnsupportedOperationException(); // should not happen
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns an instance of this object given a designated name of a hash
- * function.</p>
+ * 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
@@ -208,32 +164,26 @@ public class EMSA_PKCS1_V1_5 implements Cloneable
{
final IMessageDigest hash = HashFactory.getInstance(mdName);
final String name = hash.name();
- if (!(name.equals(Registry.MD2_HASH) || name.equals(Registry.MD5_HASH)
+ 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);
- }
+ || 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 -------------------------------------------------------------
-
/**
- * <p>Frames the hash of a message, along with an ID of the hash function in
+ * 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).</p>
+ * described in RFC-3447 (see class documentation).
*
* @param mHash the byte sequence resulting from applying the message digest
* algorithm Hash to the message <i>M</i>.
@@ -270,17 +220,13 @@ public class EMSA_PKCS1_V1_5 implements Cloneable
// 3. If emLen < tLen + 11, output "intended encoded message length too
// short" and stop.
if (emLen < tLen + 11)
- {
- throw new IllegalArgumentException("emLen too short");
- }
+ 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;
- }
+ 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();
diff --git a/gnu/java/security/sig/rsa/EMSA_PSS.java b/gnu/java/security/sig/rsa/EMSA_PSS.java
index 0b93abab7..97b3afcf8 100644
--- a/gnu/java/security/sig/rsa/EMSA_PSS.java
+++ b/gnu/java/security/sig/rsa/EMSA_PSS.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.sig.rsa;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.hash.HashFactory;
import gnu.java.security.hash.IMessageDigest;
import gnu.java.security.util.Util;
@@ -47,43 +47,43 @@ import java.util.Arrays;
import java.util.logging.Logger;
/**
- * <p>An implementation of the EMSA-PSS encoding/decoding scheme.</p>
- *
- * <p>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.</p>
- *
- * <p>EMSA-PSS is parameterized by the choice of hash function Hash and mask
+ * An implementation of the EMSA-PSS encoding/decoding scheme.
+ * <p>
+ * 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.
+ * <p>
+ * 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.</p>
- *
- * <p>References:</p>
+ * 1363-2000 recommends SHA-1 and RIPEMD-160.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
- * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
- * Primitive specification and supporting documentation.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a
+ * href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
+ * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
+ * Primitive specification and supporting documentation.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
* </ol>
*/
-public class EMSA_PSS implements Cloneable
+public class EMSA_PSS
+ implements Cloneable
{
private static final Logger log = Logger.getLogger(EMSA_PSS.class.getName());
+
/** 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)
- // -------------------------------------------------------------------------
-
/**
- * <p>Trivial private constructor to enforce use through Factory method.</p>
- *
+ * 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)
@@ -94,16 +94,13 @@ public class EMSA_PSS implements Cloneable
hLen = hash.hashSize();
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns an instance of this object given a designated name of a hash
- * function.</p>
- *
+ * 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.
+ * options.
*/
public static EMSA_PSS getInstance(String mdName)
{
@@ -111,51 +108,38 @@ public class EMSA_PSS implements Cloneable
return new EMSA_PSS(hash);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // Cloneable interface implementation --------------------------------------
-
public Object clone()
{
return getInstance(hash.name());
}
- // own methods -------------------------------------------------------------
-
/**
- * <p>The encoding operation EMSA-PSS-Encode computes the hash of a message
+ * The encoding operation EMSA-PSS-Encode computes the hash of a message
* <code>M</code> using a hash function and maps the result to an encoded
* message <code>EM</code> of a specified length using a mask generation
- * function.</p>
- *
+ * function.
+ *
* @param mHash the byte sequence resulting from applying the message digest
- * algorithm Hash to the message <i>M</i>.
+ * algorithm Hash to the message <i>M</i>.
* @param emBits the maximal bit length of the integer OS2IP(EM), at least
- * <code>8.hLen + 8.sLen + 9</code>.
+ * <code>8.hLen + 8.sLen + 9</code>.
* @param salt the salt to use when encoding the output.
* @return the encoded message <code>EM</code>, an octet string of length
- * <code>emLen = CEILING(emBits / 8)</code>.
+ * <code>emLen = CEILING(emBits / 8)</code>.
* @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");
- }
+ 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");
- }
+ 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.
@@ -169,9 +153,8 @@ public class EMSA_PSS implements Cloneable
synchronized (hash)
{
for (i = 0; i < 8; i++)
- {
- hash.update((byte) 0x00);
- }
+ hash.update((byte) 0x00);
+
hash.update(mHash, 0, hLen);
hash.update(salt, 0, sLen);
H = hash.digest();
@@ -191,9 +174,7 @@ public class EMSA_PSS implements Cloneable
}
// 10. Let maskedDB = DB XOR dbMask.
for (i = 0; i < DB.length; i++)
- {
- DB[i] = (byte) (DB[i] ^ dbMask[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));
@@ -208,14 +189,14 @@ public class EMSA_PSS implements Cloneable
}
/**
- * <p>The decoding operation EMSA-PSS-Decode recovers the message hash from
- * an encoded message <code>EM</code> and compares it to the hash of
- * <code>M</code>.</p>
- *
+ * The decoding operation EMSA-PSS-Decode recovers the message hash from an
+ * encoded message <code>EM</code> and compares it to the hash of
+ * <code>M</code>.
+ *
* @param mHash the byte sequence resulting from applying the message digest
- * algorithm Hash to the message <i>M</i>.
+ * algorithm Hash to the message <i>M</i>.
* @param EM the <i>encoded message</i>, an octet string of length
- * <code>emLen = CEILING(emBits/8).
+ * <code>emLen = CEILING(emBits/8).
* @param emBits the maximal bit length of the integer OS2IP(EM), at least
* <code>8.hLen + 8.sLen + 9</code>.
* @param sLen the length, in octets, of the expected salt.
@@ -234,13 +215,10 @@ public class EMSA_PSS implements Cloneable
log.fine("sLen: " + String.valueOf(sLen));
}
if (sLen < 0)
- {
- throw new IllegalArgumentException("sLen");
- }
-
+ 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.
+ // 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)
{
@@ -252,12 +230,13 @@ public class EMSA_PSS implements Cloneable
if (emBits < (8 * hLen + 8 * sLen + 9))
{
if (Configuration.DEBUG)
- log.fine("emBits < (8hLen + 8sLen + 9); sLen: " + String.valueOf(sLen));
+ log.fine("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.
+ // output 'inconsistent' and stop.
if ((EM[EM.length - 1] & 0xFF) != 0xBC)
{
if (Configuration.DEBUG)
@@ -265,9 +244,9 @@ public class EMSA_PSS implements Cloneable
return false;
}
// 5. Let maskedDB be the leftmost emLen ? hLen ? 1 octets of EM, and let
- // H be the next hLen octets.
+ // 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.
+ // maskedDB are not all equal to zero, output 'inconsistent' and stop.
if ((EM[0] & (0xFF << (8 - (8 * emLen - emBits)))) != 0)
{
if (Configuration.DEBUG)
@@ -283,9 +262,7 @@ public class EMSA_PSS implements Cloneable
// 8. Let DB = maskedDB XOR dbMask.
int i;
for (i = 0; i < DB.length; i++)
- {
- DB[i] = (byte) (DB[i] ^ dbMask[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 (Configuration.DEBUG)
@@ -294,11 +271,10 @@ public class EMSA_PSS implements Cloneable
log.fine("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.
+ // 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
+ // 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)
@@ -319,16 +295,15 @@ public class EMSA_PSS implements Cloneable
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.
+ // 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((byte) 0x00);
+
hash.update(mHash, 0, hLen);
hash.update(salt, 0, sLen);
H0 = hash.digest();
@@ -337,34 +312,30 @@ public class EMSA_PSS implements Cloneable
return Arrays.equals(H, H0);
}
- // helper methods ----------------------------------------------------------
-
/**
- * <p>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.</p>
- *
+ * 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.
+ * 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");
- }
+ 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
@@ -379,14 +350,14 @@ public class EMSA_PSS implements Cloneable
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)
+ // 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 >>> 24));
+ hashZC.update((byte)(i >>> 16));
+ hashZC.update((byte)(i >>> 8));
hashZC.update((byte) i);
t = hashZC.digest();
length = l - sofar;
diff --git a/gnu/java/security/sig/rsa/RSA.java b/gnu/java/security/sig/rsa/RSA.java
index 7d1707e19..cdd9eaa5b 100644
--- a/gnu/java/security/sig/rsa/RSA.java
+++ b/gnu/java/security/sig/rsa/RSA.java
@@ -49,31 +49,26 @@ import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
/**
- * <p>Utility methods related to the RSA algorithm.</p>
- *
- * <p>References:</p>
+ * Utility methods related to the RSA algorithm.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
- * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
- * Primitive specification and supporting documentation.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
- *
- * <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
- * Standards (PKCS) #1:</a><br>
- * RSA Cryptography Specifications Version 2.1.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
- *
- * <li><a href="http://crypto.stanford.edu/~dabo/abstracts/ssl-timing.html">
- * Remote timing attacks are practical</a><br>
- * D. Boneh and D. Brumley.</li>
+ * <li><a
+ * href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
+ * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
+ * Primitive specification and supporting documentation.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
+ * Standards (PKCS) #1:</a><br>
+ * RSA Cryptography Specifications Version 2.1.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a href="http://crypto.stanford.edu/~dabo/abstracts/ssl-timing.html">
+ * Remote timing attacks are practical</a><br>
+ * D. Boneh and D. Brumley.</li>
* </ol>
*/
public class RSA
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final BigInteger ZERO = BigInteger.ZERO;
private static final BigInteger ONE = BigInteger.ONE;
@@ -81,37 +76,28 @@ public class RSA
/** 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 --------------------------------------
-
/**
- * <p>An implementation of the <b>RSASP</b> method: Assuming that the
- * designated RSA private key is a valid one, this method computes a
- * <i>signature representative</i> for a designated <i>message
- * representative</i> signed by the holder of the designated RSA private
- * key.<p>
- *
+ * An implementation of the <b>RSASP</b> method: Assuming that the designated
+ * RSA private key is a valid one, this method computes a <i>signature
+ * representative</i> for a designated <i>message representative</i> signed
+ * by the holder of the designated RSA private key.
+ *
* @param K the RSA private key.
* @param m the <i>message representative</i>: an integer between
- * <code>0</code> and <code>n - 1</code>, where <code>n</code> is the RSA
- * <i>modulus</i>.
+ * <code>0</code> and <code>n - 1</code>, where <code>n</code>
+ * is the RSA <i>modulus</i>.
* @return the <i>signature representative</i>, an integer between
- * <code>0</code> and <code>n - 1</code>, where <code>n</code> is the RSA
- * <i>modulus</i>.
+ * <code>0</code> and <code>n - 1</code>, where <code>n</code>
+ * is the RSA <i>modulus</i>.
* @throws ClassCastException if <code>K</code> is not an RSA one.
* @throws IllegalArgumentException if <code>m</code> (the <i>message
- * representative</i>) is out of range.
+ * representative</i>) is out of range.
*/
public static final BigInteger sign(final PrivateKey K, final BigInteger m)
{
@@ -121,27 +107,27 @@ public class RSA
}
catch (IllegalArgumentException x)
{
- throw new IllegalArgumentException(
- "message representative out of range");
+ throw new IllegalArgumentException("message representative out of range");
}
}
/**
- * <p>An implementation of the <b>RSAVP</b> method: Assuming that the
- * designated RSA public key is a valid one, this method computes a
- * <i>message representative</i> for the designated <i>signature
- * representative</i> generated by an RSA private key, for a message
- * intended for the holder of the designated RSA public key.</p>
- *
+ * An implementation of the <b>RSAVP</b> method: Assuming that the designated
+ * RSA public key is a valid one, this method computes a <i>message
+ * representative</i> for the designated <i>signature representative</i>
+ * 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 <i>signature representative</i>, an integer between
- * <code>0</code> and <code>n - 1</code>, where <code>n</code> is the RSA
- * <i>modulus</i>.
+ * <code>0</code> and <code>n - 1</code>, where <code>n</code>
+ * is the RSA <i>modulus</i>.
* @return a <i>message representative</i>: an integer between <code>0</code>
- * and <code>n - 1</code>, where <code>n</code> is the RSA <i>modulus</i>.
+ * and <code>n - 1</code>, where <code>n</code> is the RSA
+ * <i>modulus</i>.
* @throws ClassCastException if <code>K</code> is not an RSA one.
* @throws IllegalArgumentException if <code>s</code> (the <i>signature
- * representative</i>) is out of range.
+ * representative</i>) is out of range.
*/
public static final BigInteger verify(final PublicKey K, final BigInteger s)
{
@@ -151,25 +137,24 @@ public class RSA
}
catch (IllegalArgumentException x)
{
- throw new IllegalArgumentException(
- "signature representative out of range");
+ throw new IllegalArgumentException("signature representative out of range");
}
}
- // Encryption and decryption methods ---------------------------------------
-
/**
- * <p>An implementation of the <code>RSAEP</code> algorithm.</p>
- *
+ * An implementation of the <code>RSAEP</code> algorithm.
+ *
* @param K the recipient's RSA public key.
* @param m the message representative as an MPI.
* @return the resulting MPI --an MPI between <code>0</code> and
- * <code>n - 1</code> (<code>n</code> being the public shared modulus)-- that
- * will eventually be padded with an appropriate framing/padding scheme.
+ * <code>n - 1</code> (<code>n</code> being the public shared
+ * modulus)-- that will eventually be padded with an appropriate
+ * framing/padding scheme.
* @throws ClassCastException if <code>K</code> is not an RSA one.
* @throws IllegalArgumentException if <code>m</code>, the message
- * representative is not between <code>0</code> and <code>n - 1</code>
- * (<code>n</code> being the public shared modulus).
+ * representative is not between <code>0</code> and
+ * <code>n - 1</code> (<code>n</code> being the public shared
+ * modulus).
*/
public static final BigInteger encrypt(final PublicKey K, final BigInteger m)
{
@@ -179,22 +164,23 @@ public class RSA
}
catch (IllegalArgumentException x)
{
- throw new IllegalArgumentException(
- "message representative out of range");
+ throw new IllegalArgumentException("message representative out of range");
}
}
/**
- * <p>An implementation of the <code>RSADP</code> algorithm.</p>
- *
+ * An implementation of the <code>RSADP</code> algorithm.
+ *
* @param K the recipient's RSA private key.
* @param c the ciphertext representative as an MPI.
* @return the message representative, an MPI between <code>0</code> and
- * <code>n - 1</code> (<code>n</code> being the shared public modulus).
+ * <code>n - 1</code> (<code>n</code> being the shared public
+ * modulus).
* @throws ClassCastException if <code>K</code> is not an RSA one.
* @throws IllegalArgumentException if <code>c</code>, the ciphertext
- * representative is not between <code>0</code> and <code>n - 1</code>
- * (<code>n</code> being the shared public modulus).
+ * representative is not between <code>0</code> and
+ * <code>n - 1</code> (<code>n</code> being the shared public
+ * modulus).
*/
public static final BigInteger decrypt(final PrivateKey K, final BigInteger c)
{
@@ -204,22 +190,19 @@ public class RSA
}
catch (IllegalArgumentException x)
{
- throw new IllegalArgumentException(
- "ciphertext representative out of range");
+ throw new IllegalArgumentException("ciphertext representative out of range");
}
}
- // Conversion methods ------------------------------------------------------
-
/**
- * <p>Converts a <i>multi-precision integer</i> (MPI) <code>s</code> into an
- * octet sequence of length <code>k</code>.</p>
- *
+ * Converts a <i>multi-precision integer</i> (MPI) <code>s</code> into an
+ * octet sequence of length <code>k</code>.
+ *
* @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 <code>s</code> is greater than <code>k</code>.
+ * bytes of <code>s</code> is greater than <code>k</code>.
*/
public static final byte[] I2OSP(final BigInteger s, final int k)
{
@@ -236,9 +219,7 @@ public class RSA
for (int i = 0; i < limit; i++)
{
if (result[i] != 0x00)
- {
- throw new IllegalArgumentException("integer too large");
- }
+ throw new IllegalArgumentException("integer too large");
}
final byte[] newResult = new byte[k];
System.arraycopy(result, limit, newResult, 0, k);
@@ -247,17 +228,13 @@ public class RSA
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.
+ // "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();
- }
+ throw new IllegalArgumentException();
// 2. Let c = m^e mod n.
final BigInteger e = K.getPublicExponent();
final BigInteger result = m.modPow(e, n);
@@ -268,16 +245,13 @@ public class RSA
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.
+ // "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();
- }
-
+ throw new IllegalArgumentException();
// 2. The representative m is computed as follows.
BigInteger result;
- if (!(K instanceof RSAPrivateCrtKey))
+ 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();
@@ -303,38 +277,32 @@ public class RSA
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:
+ // 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.
+ // 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.
+ // 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.
+ // 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);
- }
+ if (rsaBlinding) // post-decryption
+ result = result.multiply(r.modInverse(n)).mod(n);
}
-
// 3. Output m
return result;
}
/**
- * <p>Returns a random MPI with a random bit-length of the form <code>8b</code>,
- * where <code>b</code> is in the range <code>[32..64]</code>.</p>
- *
+ * Returns a random MPI with a random bit-length of the form <code>8b</code>,
+ * where <code>b</code> is in the range <code>[32..64]</code>.
+ *
* @return a random MPI whose length in bytes is between 32 and 64 inclusive.
*/
private static final BigInteger newR(final BigInteger N)
diff --git a/gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java b/gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java
index e64d30b69..76460c0ca 100644
--- a/gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java
+++ b/gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java
@@ -51,35 +51,29 @@ import java.security.interfaces.RSAPublicKey;
import java.util.Arrays;
/**
- * <p>The RSA-PKCS1-V1.5 signature scheme is a digital signature scheme with
+ * 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.</p>
- *
- * <p>References:</p>
+ * method.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
- * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
- * Primitive specification and supporting documentation.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
- *
- * <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
- * Standards (PKCS) #1:</a><br>
- * RSA Cryptography Specifications Version 2.1.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a
+ * href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
+ * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
+ * Primitive specification and supporting documentation.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
+ * Standards (PKCS) #1:</a><br>
+ * RSA Cryptography Specifications Version 2.1.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
* </ol>
*/
-public class RSAPKCS1V1_5Signature extends BaseSignature
+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.
*/
@@ -89,9 +83,9 @@ public class RSAPKCS1V1_5Signature extends BaseSignature
}
/**
- * <p>Constructs an instance of this object using the designated message
- * digest algorithm as its underlying hash function.</p>
- *
+ * 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)
@@ -117,14 +111,6 @@ public class RSAPKCS1V1_5Signature extends BaseSignature
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);
@@ -133,49 +119,46 @@ public class RSAPKCS1V1_5Signature extends BaseSignature
protected void setupForVerification(final PublicKey k)
throws IllegalArgumentException
{
- if (!(k instanceof RSAPublicKey))
- {
- throw new 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();
- }
+ 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:
+ // 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).
+ // 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.
+ // 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).
+ // 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).
+ // 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).
+ // 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);
}
@@ -184,28 +167,24 @@ public class RSAPKCS1V1_5Signature extends BaseSignature
throws IllegalStateException
{
if (publicKey == null)
- {
- throw new IllegalStateException();
- }
+ 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.
+ // output "invalid signature" and stop.
final int modBits = ((RSAPublicKey) publicKey).getModulus().bitLength();
final int k = (modBits + 7) / 8;
if (S.length != k)
- {
- return false;
- }
+ return false;
// 2. RSA verification:
- // a. Convert the signature S to an integer signature representative
- // s (see Section 4.2): s = OS2IP (S).
+ // 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.
+ // 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
{
@@ -215,10 +194,10 @@ public class RSAPKCS1V1_5Signature extends BaseSignature
{
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.
+ // 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
{
@@ -229,17 +208,17 @@ public class RSAPKCS1V1_5Signature extends BaseSignature
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.
+ // 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."
+ // If they are the same, output "valid signature"; otherwise, output
+ // "invalid signature."
return Arrays.equals(EM, EMp);
}
}
diff --git a/gnu/java/security/sig/rsa/RSAPSSSignature.java b/gnu/java/security/sig/rsa/RSAPSSSignature.java
index 3e9cad452..27c7fe620 100644
--- a/gnu/java/security/sig/rsa/RSAPSSSignature.java
+++ b/gnu/java/security/sig/rsa/RSAPSSSignature.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.sig.rsa;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.hash.HashFactory;
import gnu.java.security.hash.IMessageDigest;
@@ -53,37 +53,36 @@ import java.security.interfaces.RSAPublicKey;
import java.util.logging.Logger;
/**
- * <p>The RSA-PSS signature scheme is a public-key encryption scheme combining
- * the RSA algorithm with the Probabilistic Signature Scheme (PSS) encoding
- * method.</p>
- *
- * <p>The inventors of RSA are Ronald L. Rivest, Adi Shamir, and Leonard Adleman,
+ * The RSA-PSS signature scheme is a public-key encryption scheme combining the
+ * RSA algorithm with the Probabilistic Signature Scheme (PSS) encoding method.
+ * <p>
+ * 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.</p>
- *
- * <p>References:</pr>
+ * P1363a) to facilitate implementation and integration into existing protocols.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
- * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
- * Primitive specification and supporting documentation.<br>
- * Jakob Jonsson and Burt Kaliski.</li>
+ * <li><a
+ * href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
+ * RSA-PSS Signature Scheme with Appendix, part B.</a><br>
+ * Primitive specification and supporting documentation.<br>
+ * Jakob Jonsson and Burt Kaliski.</li>
* </ol>
*/
-public class RSAPSSSignature extends BaseSignature
+public class RSAPSSSignature
+ extends BaseSignature
{
private static final Logger log = Logger.getLogger(RSAPSSSignature.class.getName());
+
/** 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 <i>salt</i>.
@@ -94,10 +93,9 @@ public class RSAPSSSignature extends BaseSignature
}
/**
- * <p>Constructs an instance of this object using the designated message
- * digest algorithm as its underlying hash function, and having 0-octet
- * <i>salt</i>.</p>
- *
+ * Constructs an instance of this object using the designated message digest
+ * algorithm as its underlying hash function, and having 0-octet <i>salt</i>.
+ *
* @param mdName the canonical name of the underlying hash function.
*/
public RSAPSSSignature(String mdName)
@@ -106,12 +104,12 @@ public class RSAPSSSignature extends BaseSignature
}
/**
- * <p>Constructs an instance of this object using the designated message
- * digest algorithm as its underlying hash function.</p>
- *
+ * 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.
+ * decoding signatures.
*/
public RSAPSSSignature(String mdName, int sLen)
{
@@ -137,14 +135,6 @@ public class RSAPSSSignature extends BaseSignature
this.pss = (EMSA_PSS) that.pss.clone();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // Implementation of abstract methods in superclass ------------------------
-
public Object clone()
{
return new RSAPSSSignature(this);
@@ -153,32 +143,30 @@ public class RSAPSSSignature extends BaseSignature
protected void setupForVerification(PublicKey k)
throws IllegalArgumentException
{
- if (!(k instanceof RSAPublicKey))
- {
- throw new 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();
- }
+ 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.
+ // 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);
@@ -186,44 +174,40 @@ public class RSAPSSSignature extends BaseSignature
if (Configuration.DEBUG)
log.fine("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).
+ // 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).
+ // 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).
+ // 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 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);
+ 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.
+ // invalid' and stop.
int modBits = ((RSAPublicKey) publicKey).getModulus().bitLength();
int k = (modBits + 7) / 8;
if (S.length != k)
- {
- return false;
- }
+ return false;
// 2. Convert the signature S to an integer signature representative s:
- // s = OS2IP(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.
+ // 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
{
@@ -234,20 +218,18 @@ public class RSAPSSSignature extends BaseSignature
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.
+ // 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 (Configuration.DEBUG)
log.fine("EM (verify): " + Util.toString(EM));
if (EM.length > emLen)
- {
- return false;
- }
+ return false;
else if (EM.length < emLen)
{
byte[] newEM = new byte[emLen];
@@ -255,9 +237,9 @@ public class RSAPSSSignature extends BaseSignature
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.'
+ // 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
@@ -270,55 +252,4 @@ public class RSAPSSSignature extends BaseSignature
}
return result;
}
-
- // Other instance methods --------------------------------------------------
-
- /**
- * Converts the <i>signature representative</i> <code>s</code> to a signature
- * <code>S</code> of length <code>k</code> octets; i.e.
- * <code>S = I2OSP(s, k)</code>, where <code>k = CEILING(modBits/8)</code>.
- *
- * @param s the <i>signature representative</i>.
- * @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 <code>s</code> is greater than <code>k</code>, implying that
- * <code>s</code> is not less than the RSA <i>modulus</i>.
- */
- // 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.<p>
- *
- * @return the octet sequence <code>S</code>.
- */
- // private byte[] decodeSignature(Object signature) {
- // return (byte[]) signature;
- // }
}
diff --git a/gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java b/gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java
index 1ae295e36..b5e059c20 100644
--- a/gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java
+++ b/gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java
@@ -44,53 +44,41 @@ import gnu.java.security.sig.ISignatureCodec;
import java.io.ByteArrayOutputStream;
/**
- * <p>An object that implements the {@link ISignatureCodec}
- * operations for the <i>Raw</i> format to use with RSA-PSS signatures.</p>
+ * An object that implements the {@link ISignatureCodec} operations for the
+ * <i>Raw</i> format to use with RSA-PSS signatures.
*/
-public class RSAPSSSignatureRawCodec implements ISignatureCodec
+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;
}
/**
- * <p>Returns the encoded form of the designated RSA-PSS signature object
- * according to the <i>Raw</i> format supported by this library.</p>
- *
- * <p>The <i>Raw</i> format for an RSA-PSS signature, in this implementation,
- * is a byte sequence consisting of the following:</p>
- *
+ * Returns the encoded form of the designated RSA-PSS signature object
+ * according to the <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for an RSA-PSS signature, in this implementation, is
+ * a byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_RSA_PSS_SIGNATURE},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the RSA-PSS signature
- * bytes in internet order,</li>
- * <li>the RSA-PSS signature bytes in internet order.</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_RSA_PSS_SIGNATURE},
+ * <li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the RSA-PSS signature
+ * bytes in internet order,</li>
+ * <li>the RSA-PSS signature bytes in internet order.</li>
* </ol>
- *
+ *
* @param signature the signature to encode, consisting of the output of the
- * <code>sign()</code> method of a {@link RSAPSSSignature} instance --a byte
- * array.
+ * <code>sign()</code> method of a {@link RSAPSSSignature} instance
+ * --a byte array.
* @return the <i>Raw</i> format encoding of the designated signature.
* @exception IllegalArgumentException if the designated signature is not an
- * RSA-PSS one.
+ * RSA-PSS one.
*/
public byte[] encodeSignature(Object signature)
{
@@ -101,28 +89,23 @@ public class RSAPSSSignatureRawCodec implements ISignatureCodec
}
catch (Exception x)
{
- throw new IllegalArgumentException("key");
+ throw new IllegalArgumentException("signature");
}
-
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 >>> 24);
baos.write((length >>> 16) & 0xFF);
baos.write((length >>> 8) & 0xFF);
baos.write(length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -133,25 +116,19 @@ public class RSAPSSSignatureRawCodec implements ISignatureCodec
|| 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");
- }
-
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
-
+ 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);
+ 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/gnu/java/security/util/Base64.java b/gnu/java/security/util/Base64.java
index 6c4657b7c..9b2ae12dc 100644
--- a/gnu/java/security/util/Base64.java
+++ b/gnu/java/security/util/Base64.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.util;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import java.io.UnsupportedEncodingException;
import java.util.logging.Logger;
@@ -50,6 +50,7 @@ import java.util.logging.Logger;
public class Base64
{
private static final Logger log = Logger.getLogger(Base64.class.getName());
+
/** Maximum line length (76) of Base64 output. */
private static final int MAX_LINE_LENGTH = 76;
@@ -64,79 +65,58 @@ public class Base64
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) '/' };
+ 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
+ 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
* <code>encode(source, 0, source.length)</code>.
- *
+ *
* @param src the data to convert.
*/
public static final String encode(final byte[] src)
@@ -146,7 +126,7 @@ public class Base64
/**
* 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.
@@ -159,7 +139,7 @@ public class Base64
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
+ : 0)]; // New lines
int d = 0;
int e = 0;
final int len2 = len - 2;
@@ -175,13 +155,11 @@ public class Base64
lineLength = 0;
}
}
-
- if (d < len)
- { // padding needed
+ if (d < len) // padding needed
+ {
encode3to4(src, d + off, len - d, outBuff, e);
e += 4;
}
-
return new String(outBuff, 0, e);
}
@@ -238,31 +216,26 @@ public class Base64
} // end if: quartet built
} // end if: equals sign or better
}
- else
- {
- throw new IllegalArgumentException("Illegal BASE-64 character at #"
- + i + ": " + src[i]
- + "(decimal)");
- }
+ 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;
}
/**
- * <p>Encodes up to three bytes of the array <code>src</code> and writes
- * the resulting four Base64 bytes to <code>dest</code>. The source and
+ * Encodes up to three bytes of the array <code>src</code> and writes the
+ * resulting four Base64 bytes to <code>dest</code>. The source and
* destination arrays can be manipulated anywhere along their length by
- * specifying <code>sOffset</code> and <code>dOffset</code>.</p>
- *
- * <p>This method does not check to make sure the arrays are large enough to
+ * specifying <code>sOffset</code> and <code>dOffset</code>.
+ * <p>
+ * This method does not check to make sure the arrays are large enough to
* accomodate <code>sOffset + 3</code> for the <code>src</code> array or
* <code>dOffset + 4</code> for the <code>dest</code> array. The actual
* number of significant bytes in the input array is given by
- * <code>numBytes</code>.</p>
- *
+ * <code>numBytes</code>.
+ *
* @param src the array to convert.
* @param sOffset the index where conversion begins.
* @param numBytes the number of significant bytes in your array.
@@ -285,25 +258,25 @@ public class Base64
// 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)
+ 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 ] = ALPHABET[(inBuff >>> 18)];
dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
- dest[dOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3F];
- dest[dOffset + 3] = ALPHABET[(inBuff) & 0x3F];
+ dest[dOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3F];
+ dest[dOffset + 3] = ALPHABET[(inBuff) & 0x3F];
break;
case 2:
- dest[dOffset] = ALPHABET[(inBuff >>> 18)];
+ dest[dOffset ] = ALPHABET[(inBuff >>> 18)];
dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
- dest[dOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3F];
+ dest[dOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3F];
dest[dOffset + 3] = EQUALS_SIGN;
break;
case 1:
- dest[dOffset] = ALPHABET[(inBuff >>> 18)];
+ dest[dOffset ] = ALPHABET[(inBuff >>> 18)];
dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
dest[dOffset + 2] = EQUALS_SIGN;
dest[dOffset + 3] = EQUALS_SIGN;
@@ -313,19 +286,18 @@ public class Base64
}
/**
- * <p>Decodes four bytes from array <code>src</code> and writes the
- * resulting bytes (up to three of them) to <code>dest</code>.</p>
- *
- * <p>The source and destination arrays can be manipulated anywhere along
- * their length by specifying <code>sOffset</code> and <code>dOffset</code>.
- * </p>
- *
- * <p>This method does not check to make sure your arrays are large enough
- * to accomodate <code>sOffset + 4</code> for the <code>src</code> array or
+ * Decodes four bytes from array <code>src</code> and writes the resulting
+ * bytes (up to three of them) to <code>dest</code>.
+ * <p>
+ * The source and destination arrays can be manipulated anywhere along their
+ * length by specifying <code>sOffset</code> and <code>dOffset</code>.
+ * <p>
+ * This method does not check to make sure your arrays are large enough to
+ * accomodate <code>sOffset + 4</code> for the <code>src</code> array or
* <code>dOffset + 3</code> for the <code>dest</code> array. This method
* returns the actual number of bytes that were converted from the Base64
- * encoding.</p>
- *
+ * encoding.
+ *
* @param src the array to convert.
* @param sOffset the index where conversion begins.
* @param dest the array to hold the conversion.
@@ -335,32 +307,30 @@ public class Base64
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);
+ 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);
+ 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);
+ 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;
}
diff --git a/gnu/java/security/util/ExpirableObject.java b/gnu/java/security/util/ExpirableObject.java
index c14b75957..e0c4e6b59 100644
--- a/gnu/java/security/util/ExpirableObject.java
+++ b/gnu/java/security/util/ExpirableObject.java
@@ -46,26 +46,23 @@ 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.
- *
- * <p>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 <code>destroy()</code>.
- *
- * <p>Note that if a {@link DestroyFailedException} occurs when the timeout
+ * 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.
+ * <p>
+ * 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 <code>destroy()</code>.
+ * <p>
+ * Note that if a {@link DestroyFailedException} occurs when the timeout
* expires, it will not be reported.
- *
+ *
* @see Destroyable
*/
-public abstract class ExpirableObject implements Destroyable
+public abstract class ExpirableObject
+ implements Destroyable
{
-
- // Constants and fields.
- // -------------------------------------------------------------------------
-
/**
* The default timeout, used in the default constructor.
*/
@@ -82,9 +79,6 @@ public abstract class ExpirableObject implements Destroyable
*/
private final Destroyer destroyer;
- // Constructors.
- // -------------------------------------------------------------------------
-
/**
* Create a new expirable object that will expire after one hour.
*/
@@ -94,12 +88,11 @@ public abstract class ExpirableObject implements Destroyable
}
/**
- * Create a new expirable object that will expire after the specified
- * timeout.
- *
+ * Create a new expirable object that will expire after the specified timeout.
+ *
* @param delay The delay before expiration.
* @throws IllegalArgumentException If <i>delay</i> is negative, or if
- * <code>delay + System.currentTimeMillis()</code> is negative.
+ * <code>delay + System.currentTimeMillis()</code> is negative.
*/
protected ExpirableObject(final long delay)
{
@@ -107,14 +100,11 @@ public abstract class ExpirableObject implements Destroyable
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.
- *
+ * 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
@@ -126,42 +116,30 @@ public abstract class ExpirableObject implements Destroyable
/**
* 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
+ 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())
+ if (! target.isDestroyed())
target.doDestroy();
}
catch (DestroyFailedException dfe)
diff --git a/gnu/java/security/util/PRNG.java b/gnu/java/security/util/PRNG.java
index 138cc6bcb..7bb27cbf4 100644
--- a/gnu/java/security/util/PRNG.java
+++ b/gnu/java/security/util/PRNG.java
@@ -45,27 +45,20 @@ 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.
+ * 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.
+ * @param delegate the undelying {@link IRandom} object used.
*/
private PRNG(IRandom delegate)
{
@@ -74,9 +67,6 @@ public class PRNG
this.delegate = delegate;
}
- // Class methods
- // --------------------------------------------------------------------------
-
public static final PRNG getInstance()
{
IRandom delegate = new MDGenerator();
@@ -86,10 +76,10 @@ public class PRNG
// 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};
+ (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
}
@@ -97,19 +87,14 @@ public class PRNG
{
throw new ExceptionInInitializerError(x);
}
-
return new PRNG(delegate);
}
- // Instance methods
- // --------------------------------------------------------------------------
-
/**
* Completely fills the designated <code>buffer</code> with random data
* generated by the underlying delegate.
*
- * @param buffer
- * the place holder of random bytes generated by the underlying
+ * @param buffer the place holder of random bytes generated by the underlying
* delegate. On output, the contents of <code>buffer</code> are
* replaced with pseudo-random data, iff the <code>buffer</code>
* size is not zero.
diff --git a/gnu/java/security/util/Sequence.java b/gnu/java/security/util/Sequence.java
index 5edc7942e..5e3a64eaf 100644
--- a/gnu/java/security/util/Sequence.java
+++ b/gnu/java/security/util/Sequence.java
@@ -44,24 +44,18 @@ import java.util.LinkedList;
/**
* A monotonic sequence of integers in the finite field 2<sup>32</sup>.
*/
-public final class Sequence extends AbstractList
+public final class Sequence
+ extends AbstractList
{
-
- // Field.
- // ------------------------------------------------------------------------
-
private final Integer[] sequence;
- // Constructor.
- // ------------------------------------------------------------------------
-
/**
- * Create a sequence of integers from 0 to <i>end</i>, with an increment
- * of 1. If <i>end</i> 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.
- *
+ * Create a sequence of integers from 0 to <i>end</i>, with an increment of
+ * 1. If <i>end</i> 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)
@@ -71,10 +65,10 @@ public final class Sequence extends AbstractList
/**
* Create a sequence of integers from <i>start</i> to <i>end</i>, with an
- * increment of 1. If <i>end</i> is less than <i>start</i>, 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.
- *
+ * increment of 1. If <i>end</i> is less than <i>start</i>, 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.
*/
@@ -88,13 +82,13 @@ public final class Sequence extends AbstractList
* increment of <i>span</i>. If <i>end</i> is less than <i>start</i>, 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.
- *
- * <p><i>span</i> can be negative, resulting in a decresing sequence.
- *
- * <p>If <i>span</i> is 0, then the sequence will contain {<i>start</i>,
+ * <p>
+ * <i>span</i> can be negative, resulting in a decresing sequence.
+ * <p>
+ * If <i>span</i> is 0, then the sequence will contain {<i>start</i>,
* <i>end</i>} if <i>start</i> != <i>end</i>, or just the singleton
* <i>start</i> if <i>start</i> == <i>end</i>.
- *
+ *
* @param start The starting value.
* @param end The ending value.
* @param span The increment value.
@@ -104,36 +98,26 @@ public final class Sequence extends AbstractList
if (span == 0)
{
if (start != end)
- {
- sequence = new Integer[] { new Integer(start), new Integer(end) };
- }
+ sequence = new Integer[] { Integer.valueOf(start),
+ Integer.valueOf(end) };
else
- {
- sequence = new Integer[] { new Integer(start) };
- }
+ sequence = new Integer[] { Integer.valueOf(start) };
}
else
{
LinkedList l = new LinkedList();
for (int i = start; i != end; i += span)
- {
- l.add(new Integer(i));
- }
- l.add(new Integer(end));
+ l.add(Integer.valueOf(i));
+
+ l.add(Integer.valueOf(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());
- }
+ throw new IndexOutOfBoundsException("index=" + index + ", size=" + size());
return sequence[index];
}
diff --git a/gnu/java/security/util/SimpleList.java b/gnu/java/security/util/SimpleList.java
index 8636b4e14..74f3bafce 100644
--- a/gnu/java/security/util/SimpleList.java
+++ b/gnu/java/security/util/SimpleList.java
@@ -43,24 +43,18 @@ 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.
+ * 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
+public final class SimpleList
+ extends AbstractList
{
-
- // Fields.
- // ------------------------------------------------------------------------
-
private final Object[] elements;
- // Constructors.
- // ------------------------------------------------------------------------
-
/**
* Create a singleton list.
- *
+ *
* @param element The first element.
*/
public SimpleList(final Object element)
@@ -71,7 +65,7 @@ public final class SimpleList extends AbstractList
/**
* Create an ordered pair (2-tuple).
- *
+ *
* @param e1 The first element.
* @param e2 The second element.
*/
@@ -84,7 +78,7 @@ public final class SimpleList extends AbstractList
/**
* Create a 3-tuple.
- *
+ *
* @param e1 The first element.
* @param e2 The second element.
* @param e3 The third element.
@@ -99,7 +93,7 @@ public final class SimpleList extends AbstractList
/**
* Create a 4-tuple.
- *
+ *
* @param e1 The first element.
* @param e2 The second element.
* @param e3 The third element.
@@ -124,10 +118,10 @@ public final class SimpleList extends AbstractList
}
/**
- * 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.
- *
+ * 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)
@@ -135,14 +129,9 @@ public final class SimpleList extends AbstractList
elements = new Object[c.size()];
int i = 0;
for (Iterator it = c.iterator(); it.hasNext() && i < elements.length;)
- {
- elements[i++] = it.next();
- }
+ elements[i++] = it.next();
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public int size()
{
if (elements == null)
@@ -153,14 +142,9 @@ public final class SimpleList extends AbstractList
public Object get(int index)
{
if (elements == null)
- {
- throw new IndexOutOfBoundsException("list is empty");
- }
+ throw new IndexOutOfBoundsException("list is empty");
if (index < 0 || index >= elements.length)
- {
- throw new IndexOutOfBoundsException("index=" + index + ", size="
- + size());
- }
+ throw new IndexOutOfBoundsException("index=" + index + ", size=" + size());
return elements[index];
}
diff --git a/gnu/java/security/util/Util.java b/gnu/java/security/util/Util.java
index f39afb931..c7a6810fb 100644
--- a/gnu/java/security/util/Util.java
+++ b/gnu/java/security/util/Util.java
@@ -41,47 +41,37 @@ package gnu.java.security.util;
import java.math.BigInteger;
/**
- * <p>A collection of utility methods used throughout this project.</p>
+ * A collection of utility methods used throughout this project.
*/
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 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
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns a string of hexadecimal digits from a byte array. Each byte is
- * converted to 2 hex symbols; zero(es) included.</p>
- *
- * <p>This method calls the method with same name and three arguments as:</p>
- *
+ * Returns a string of hexadecimal digits from a byte array. Each byte is
+ * converted to 2 hex symbols; zero(es) included.
+ * <p>
+ * This method calls the method with same name and three arguments as:
* <pre>
- * toString(ba, 0, ba.length);
+ * toString(ba, 0, ba.length);
* </pre>
- *
+ *
* @param ba the byte array to convert.
- * @return a string of hexadecimal characters (two for each byte)
- * representing the designated input byte array.
+ * @return a string of hexadecimal characters (two for each byte) representing
+ * the designated input byte array.
*/
public static String toString(byte[] ba)
{
@@ -89,17 +79,17 @@ public class Util
}
/**
- * <p>Returns a string of hexadecimal digits from a byte array, starting at
- * <code>offset</code> and consisting of <code>length</code> bytes. Each byte
- * is converted to 2 hex symbols; zero(es) included.</p>
- *
+ * Returns a string of hexadecimal digits from a byte array, starting at
+ * <code>offset</code> and consisting of <code>length</code> 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.
+ * 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.
+ * 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)
{
@@ -108,26 +98,24 @@ public class Util
{
k = ba[offset + i++];
buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
- buf[j++] = HEX_DIGITS[k & 0x0F];
+ buf[j++] = HEX_DIGITS[ k & 0x0F];
}
return new String(buf);
}
/**
- * <p>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.</p>
- *
- * <p>This method calls the method with same name and three arguments as:</p>
- *
+ * 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.
+ * <p>
+ * This method calls the method with same name and three arguments as:
* <pre>
- * toReversedString(ba, 0, ba.length);
+ * toReversedString(ba, 0, ba.length);
* </pre>
- *
+ *
* @param ba the byte array to convert.
- * @return a string of hexadecimal characters (two for each byte)
- * representing the designated input byte array.
+ * @return a string of hexadecimal characters (two for each byte) representing
+ * the designated input byte array.
*/
public static String toReversedString(byte[] ba)
{
@@ -135,20 +123,20 @@ public class Util
}
/**
- * <p>Returns a string of hexadecimal digits from a byte array, starting at
- * <code>offset</code> and consisting of <code>length</code> bytes. Each byte
- * is converted to 2 hex symbols; zero(es) included.</p>
- *
- * <p>The byte array is treated as a large little-endian integer, and
- * is returned as a large big-endian integer.</p>
- *
+ * Returns a string of hexadecimal digits from a byte array, starting at
+ * <code>offset</code> and consisting of <code>length</code> bytes. Each
+ * byte is converted to 2 hex symbols; zero(es) included.
+ * <p>
+ * 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.
+ * 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.
+ * 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)
{
@@ -157,14 +145,16 @@ public class Util
{
k = ba[offset + i--];
buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
- buf[j++] = HEX_DIGITS[k & 0x0F];
+ buf[j++] = HEX_DIGITS[ k & 0x0F];
}
return new String(buf);
}
/**
- * <p>Returns a byte array from a string of hexadecimal digits.</p>
- *
+ * <p>
+ * Returns a byte array from a string of hexadecimal digits.
+ * </p>
+ *
* @param s a string of hexadecimal ASCII characters
* @return the decoded byte array from the input hexadecimal string.
*/
@@ -174,22 +164,20 @@ public class Util
byte[] result = new byte[((limit + 1) / 2)];
int i = 0, j = 0;
if ((limit % 2) == 1)
- {
- result[j++] = (byte) fromDigit(s.charAt(i++));
- }
+ 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++)) << 4);
result[j++] |= (byte) fromDigit(s.charAt(i++));
}
return result;
}
/**
- * <p>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.</p>
- *
+ * 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.
*/
@@ -199,45 +187,37 @@ public class Util
byte[] result = new byte[((limit + 1) / 2)];
int i = 0;
if ((limit % 2) == 1)
- {
- result[i++] = (byte) fromDigit(s.charAt(--limit));
- }
+ result[i++] = (byte) fromDigit(s.charAt(--limit));
while (limit > 0)
{
- result[i] = (byte) fromDigit(s.charAt(--limit));
+ result[i ] = (byte) fromDigit(s.charAt(--limit));
result[i++] |= (byte) (fromDigit(s.charAt(--limit)) << 4);
}
return result;
}
/**
- * <p>Returns a number from <code>0</code> to <code>15</code> corresponding
- * to the designated hexadecimal digit.</p>
- *
+ * Returns a number from <code>0</code> to <code>15</code> 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';
- }
+ return c - '0';
else if (c >= 'A' && c <= 'F')
- {
- return c - 'A' + 10;
- }
+ return c - 'A' + 10;
else if (c >= 'a' && c <= 'f')
- {
- return c - 'a' + 10;
- }
+ return c - 'a' + 10;
else
throw new IllegalArgumentException("Invalid hexadecimal digit: " + c);
}
/**
- * <p>Returns a string of 8 hexadecimal digits (most significant digit first)
- * corresponding to the unsigned integer <code>n</code>.</p>
- *
+ * Returns a string of 8 hexadecimal digits (most significant digit first)
+ * corresponding to the unsigned integer <code>n</code>.
+ *
* @param n the unsigned integer to convert.
* @return a hexadecimal string 8-character long.
*/
@@ -253,8 +233,8 @@ public class Util
}
/**
- * <p>Returns a string of hexadecimal digits from an integer array. Each int
- * is converted to 4 hex symbols.</p>
+ * Returns a string of hexadecimal digits from an integer array. Each int is
+ * converted to 4 hex symbols.
*/
public static String toString(int[] ia)
{
@@ -268,17 +248,17 @@ public class Util
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];
+ buf[j++] = HEX_DIGITS[(k >>> 8) & 0x0F];
+ buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
+ buf[j++] = HEX_DIGITS[ k & 0x0F];
}
return new String(buf);
}
/**
- * <p>Returns a string of 16 hexadecimal digits (most significant digit first)
- * corresponding to the unsigned long <code>n</code>.</p>
- *
+ * Returns a string of 16 hexadecimal digits (most significant digit first)
+ * corresponding to the unsigned long <code>n</code>.
+ *
* @param n the unsigned long to convert.
* @return a hexadecimal string 16-character long.
*/
@@ -287,18 +267,18 @@ public class Util
char[] b = new char[16];
for (int i = 15; i >= 0; i--)
{
- b[i] = HEX_DIGITS[(int) (n & 0x0FL)];
+ b[i] = HEX_DIGITS[(int)(n & 0x0FL)];
n >>>= 4;
}
return new String(b);
}
/**
- * <p>Similar to the <code>toString()</code> method except that the Unicode
+ * Similar to the <code>toString()</code> 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.</p>
- *
+ * eg. s-box values.
+ *
* @throws ArrayIndexOutOfBoundsException if the length is odd.
*/
public static String toUnicodeString(byte[] ba)
@@ -307,11 +287,11 @@ public class Util
}
/**
- * <p>Similar to the <code>toString()</code> method except that the Unicode
+ * Similar to the <code>toString()</code> 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.</p>
- *
+ * eg. s-box values.
+ *
* @throws ArrayIndexOutOfBoundsException if the length is odd.
*/
public static final String toUnicodeString(byte[] ba, int offset, int length)
@@ -324,31 +304,27 @@ public class Util
while (i < length)
{
sb.append("\\u");
-
k = ba[offset + i++];
sb.append(HEX_DIGITS[(k >>> 4) & 0x0F]);
- sb.append(HEX_DIGITS[k & 0x0F]);
-
+ sb.append(HEX_DIGITS[ k & 0x0F]);
k = ba[offset + i++];
sb.append(HEX_DIGITS[(k >>> 4) & 0x0F]);
- sb.append(HEX_DIGITS[k & 0x0F]);
-
+ sb.append(HEX_DIGITS[ k & 0x0F]);
if ((++j % 8) == 0)
- {
- sb.append("\"+").append('\n').append("\"");
- }
+ sb.append("\"+").append('\n').append("\"");
}
sb.append("\"").append('\n');
return sb.toString();
}
/**
- * <p>Similar to the <code>toString()</code> method except that the Unicode
+ * Similar to the <code>toString()</code> 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.</p>
- *
- * @throws ArrayIndexOutOfBoundsException if the length is not a multiple of 4.
+ * strings; eg. s-box values.
+ *
+ * @throws ArrayIndexOutOfBoundsException if the length is not a multiple of
+ * 4.
*/
public static String toUnicodeString(int[] ia)
{
@@ -367,14 +343,11 @@ public class Util
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]);
-
+ 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').append("\"");
}
sb.append("\"").append('\n');
return sb.toString();
@@ -388,20 +361,20 @@ public class Util
for (int i = 0; i < limit; i++)
{
c = s.charAt(i >>> 1);
- result[i] = (byte) (((i & 1) == 0) ? c >>> 8 : c);
+ result[i] = (byte)(((i & 1) == 0) ? c >>> 8 : c);
}
return result;
}
/**
- * <p>Dumps a byte array as a string, in a format that is easy to read for
+ * Dumps a byte array as a string, in a format that is easy to read for
* debugging. The string <code>m</code> is prepended to the start of each
- * line.</p>
- *
- * <p>If <code>offset</code> and <code>length</code> are omitted, the whole
+ * line.
+ * <p>
+ * If <code>offset</code> and <code>length</code> are omitted, the whole
* array is used. If <code>m</code> is omitted, nothing is prepended to each
- * line.</p>
- *
+ * line.
+ *
* @param data the byte array to be dumped.
* @param offset the offset within <i>data</i> to start from.
* @param length the number of bytes to dump.
@@ -411,23 +384,17 @@ public class Util
public static String dumpString(byte[] data, int offset, int length, String m)
{
if (data == null)
- {
- return m + "null\n";
- }
+ 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");
- }
+ 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;
- }
+ l = 4;
for (; offset < end; offset += 32)
{
if (length > 32)
@@ -437,16 +404,10 @@ public class Util
}
int i = 0;
for (; i < 32 && offset + i + 7 < end; i += 8)
- {
- sb.append(toString(data, offset + i, 8)).append(' ');
- }
+ sb.append(toString(data, offset + i, 8)).append(' ');
if (i < 32)
- {
- for (; i < 32 && offset + i < end; i++)
- {
- sb.append(byteToString(data[offset + i]));
- }
- }
+ for (; i < 32 && offset + i < end; i++)
+ sb.append(byteToString(data[offset + i]));
sb.append('\n');
}
return sb.toString();
@@ -468,9 +429,9 @@ public class Util
}
/**
- * <p>Returns a string of 2 hexadecimal digits (most significant digit first)
- * corresponding to the lowest 8 bits of <code>n</code>.</p>
- *
+ * Returns a string of 2 hexadecimal digits (most significant digit first)
+ * corresponding to the lowest 8 bits of <code>n</code>.
+ *
* @param n the byte value to convert.
* @return a string of 2 hex characters representing the input.
*/
@@ -481,15 +442,15 @@ public class Util
}
/**
- * <p>Converts a designated byte array to a Base-64 representation, with the
+ * 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).</p>
- *
- * <p>Used by SASL password file manipulation primitives.</p>
- *
+ * '.' (dot) shall be used instead of "+' (plus).
+ * <p>
+ * 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.
+ * the input.
*/
public static final String toBase64(byte[] buffer)
{
@@ -535,9 +496,7 @@ public class Util
notleading = true;
}
if (pos >= len)
- {
- break;
- }
+ break;
else
{
try
@@ -555,44 +514,38 @@ public class Util
while (true);
if (notleading)
- {
- return sb.toString();
- }
+ return sb.toString();
return "0";
}
/**
- * <p>The inverse function of the above.</p>
- *
- * <p>Converts a string representing the encoding of some bytes in Base-64
- * to their original form.</p>
- *
+ * The inverse function of the above.
+ * <p>
+ * 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 <code>str</code>.
- * @throws NumberFormatException if <code>str</code> is <code>null</code>, or
- * <code>str</code> contains an illegal Base-64 character.
+ * @throws NumberFormatException if <code>str</code> is <code>null</code>,
+ * or <code>str</code> 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");
- }
+ 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);
- }
- }
+ 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
@@ -601,42 +554,31 @@ public class Util
{
a[j] = a[i];
if (--i < 0)
- {
- break;
- }
+ break;
a[j] |= (a[i] & 0x03) << 6;
j--;
- a[j] = (byte) ((a[i] & 0x3C) >>> 2);
+ a[j] = (byte)((a[i] & 0x3C) >>> 2);
if (--i < 0)
- {
- break;
- }
+ break;
a[j] |= (a[i] & 0x0F) << 4;
j--;
- a[j] = (byte) ((a[i] & 0x30) >>> 4);
+ a[j] = (byte)((a[i] & 0x30) >>> 4);
if (--i < 0)
- {
- break;
- }
+ break;
a[j] |= (a[i] << 2);
j--;
a[j] = 0;
if (--i < 0)
- {
- break;
- }
+ break;
}
}
catch (Exception ignored)
{
}
-
try
{ // ignore leading 0-bytes
while (a[j] == 0)
- {
- j++;
- }
+ j++;
}
catch (Exception x)
{
@@ -650,36 +592,31 @@ public class Util
// BigInteger utilities ----------------------------------------------------
/**
- * <p>Treats the input as the MSB representation of a number, and discards
+ * 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.</p>
- *
+ * 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.
+ * 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;
- }
+ return in;
int len = in.length;
int i = 1;
while (in[i] == 0 && i < len)
- {
- ++i;
- }
+ ++i;
byte[] result = new byte[len - i];
System.arraycopy(in, i, result, 0, len - i);
return result;
}
/**
- * <p>Returns a hexadecimal dump of the trimmed bytes of a {@link BigInteger}.
- * </p>
- *
+ * 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}.
*/
diff --git a/gnu/java/security/x509/X509CRL.java b/gnu/java/security/x509/X509CRL.java
index d8cbe988b..7c471c972 100644
--- a/gnu/java/security/x509/X509CRL.java
+++ b/gnu/java/security/x509/X509CRL.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.x509;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.der.BitString;
import gnu.java.security.der.DER;
diff --git a/gnu/java/security/x509/X509CRLEntry.java b/gnu/java/security/x509/X509CRLEntry.java
index f3f3a93d6..26b40363c 100644
--- a/gnu/java/security/x509/X509CRLEntry.java
+++ b/gnu/java/security/x509/X509CRLEntry.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.x509;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.der.DERReader;
import gnu.java.security.der.DERValue;
diff --git a/gnu/java/security/x509/X509Certificate.java b/gnu/java/security/x509/X509Certificate.java
index cf0161701..b3f8a696a 100644
--- a/gnu/java/security/x509/X509Certificate.java
+++ b/gnu/java/security/x509/X509Certificate.java
@@ -552,7 +552,7 @@ public class X509Certificate extends java.security.cert.X509Certificate
// Certificate ::= SEQUENCE {
DERValue cert = der.read();
logger.log (Component.X509, "start Certificate len == {0}",
- new Integer (cert.getLength()));
+ Integer.valueOf(cert.getLength()));
this.encoded = cert.getEncoded();
if (!cert.isConstructed())
@@ -568,7 +568,7 @@ public class X509Certificate extends java.security.cert.X509Certificate
}
tbsCertBytes = tbsCert.getEncoded();
logger.log (Component.X509, "start TBSCertificate len == {0}",
- new Integer (tbsCert.getLength()));
+ Integer.valueOf(tbsCert.getLength()));
// Version ::= INTEGER [0] { v1(0), v2(1), v3(2) }
DERValue val = der.read();
@@ -582,7 +582,7 @@ public class X509Certificate extends java.security.cert.X509Certificate
version = 1;
}
logger.log (Component.X509, "read version == {0}",
- new Integer (version));
+ Integer.valueOf(version));
// SerialNumber ::= INTEGER
serialNo = (BigInteger) val.getValue();
@@ -596,7 +596,7 @@ public class X509Certificate extends java.security.cert.X509Certificate
}
int certAlgLen = val.getLength();
logger.log (Component.X509, "start AlgorithmIdentifier len == {0}",
- new Integer (certAlgLen));
+ Integer.valueOf(certAlgLen));
val = der.read();
// algorithm OBJECT IDENTIFIER,
@@ -677,20 +677,20 @@ public class X509Certificate extends java.security.cert.X509Certificate
{
val = der.read();
logger.log (Component.X509, "start Extensions len == {0}",
- new Integer (val.getLength()));
+ Integer.valueOf(val.getLength()));
int len = 0;
while (len < val.getLength())
{
DERValue ext = der.read();
logger.log (Component.X509, "start extension len == {0}",
- new Integer (ext.getLength()));
+ Integer.valueOf(ext.getLength()));
Extension e = new Extension(ext.getEncoded());
extensions.put(e.getOid(), e);
der.skip(ext.getLength());
len += ext.getEncodedLength();
logger.log (Component.X509, "read extension {0} == {1}",
new Object[] { e.getOid (), e });
- logger.log (Component.X509, "count == {0}", new Integer (len));
+ logger.log (Component.X509, "count == {0}", Integer.valueOf(len));
}
val = der.read ();
@@ -703,7 +703,7 @@ public class X509Certificate extends java.security.cert.X509Certificate
}
int sigAlgLen = val.getLength();
logger.log (Component.X509, "start AlgorithmIdentifier len == {0}",
- new Integer (sigAlgLen));
+ Integer.valueOf(sigAlgLen));
val = der.read();
sigAlgId = (OID) val.getValue();
logger.log (Component.X509, "read algorithm id == {0}", sigAlgId);
diff --git a/gnu/java/security/x509/ext/Extension.java b/gnu/java/security/x509/ext/Extension.java
index 4deafe23e..69251987e 100644
--- a/gnu/java/security/x509/ext/Extension.java
+++ b/gnu/java/security/x509/ext/Extension.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.security.x509.ext;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.OID;
import gnu.java.security.der.DER;
import gnu.java.security.der.DERReader;
diff --git a/gnu/java/security/x509/ext/GeneralNames.java b/gnu/java/security/x509/ext/GeneralNames.java
index 81c090f4c..b342cbd5f 100644
--- a/gnu/java/security/x509/ext/GeneralNames.java
+++ b/gnu/java/security/x509/ext/GeneralNames.java
@@ -90,7 +90,7 @@ public class GeneralNames
int tagClass = name.getTagClass();
if (tagClass != DER.CONTEXT)
throw new IOException("malformed GeneralName: Tag class is " + tagClass);
- namePair.add(new Integer(name.getTag()));
+ namePair.add(Integer.valueOf(name.getTag()));
DERValue val = null;
switch (name.getTag())
{
diff --git a/gnu/java/util/prefs/GConfBasedFactory.java b/gnu/java/util/prefs/GConfBasedFactory.java
new file mode 100644
index 000000000..ae734b609
--- /dev/null
+++ b/gnu/java/util/prefs/GConfBasedFactory.java
@@ -0,0 +1,78 @@
+/* GConfBasedFactory.java -- GConf based PreferencesFactory 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 java.util.prefs.Preferences;
+import java.util.prefs.PreferencesFactory;
+
+/**
+ * Factory object that generates a Preferences nodes that are read from a GConf
+ * daemon.
+ *
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class GConfBasedFactory implements PreferencesFactory
+{
+ /** System preference root. */
+ private static final Preferences systemPreferences
+ = new GConfBasedPreferences(null, "", false);
+
+ /** User preference root. */
+ private static final Preferences userPreferences
+ = new GConfBasedPreferences(null, "", true);
+
+ /**
+ * Returns the system root preference node.
+ *
+ * @see java.util.prefs.PreferencesFactory#systemRoot()
+ */
+ public Preferences systemRoot()
+ {
+ return systemPreferences;
+ }
+
+ /**
+ * Returns the user root preference node corresponding to the calling user.
+ *
+ * @see java.util.prefs.PreferencesFactory#userRoot()
+ */
+ public Preferences userRoot()
+ {
+ return userPreferences;
+ }
+}
diff --git a/gnu/java/util/prefs/GConfBasedPreferences.java b/gnu/java/util/prefs/GConfBasedPreferences.java
new file mode 100644
index 000000000..cbedac5c8
--- /dev/null
+++ b/gnu/java/util/prefs/GConfBasedPreferences.java
@@ -0,0 +1,406 @@
+/* GConfBasedPreferences.java -- GConf based Preferences 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.java.util.prefs.gconf.GConfNativePeer;
+
+import java.security.Permission;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
+
+/**
+ * This is a GConf based preference implementation which writes the preferences
+ * as GConf key-value pairs. System Root is defined to be the
+ * <code>"/system"</code> directory of GConf for the current user, while User
+ * Root is <code>"/apps/java"</code>. These defaults can be modified by
+ * defining two system properties:<br />
+ * <br />
+ * User Root:<br />
+ * <br />
+ *
+ * <pre>
+ * gnu.java.util.prefs.gconf.user_root
+ * </pre>
+ *
+ * <br />
+ * <br />
+ * and System Root:<br />
+ * <br />
+ *
+ * <pre>
+ * gnu.java.util.prefs.gconf.system_root
+ * </pre>
+ *
+ * <br />
+ *
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class GConfBasedPreferences
+ extends AbstractPreferences
+{
+ /** Get access to Runtime permission */
+ private static final Permission PERMISSION
+ = new RuntimePermission("preferences");
+
+ /** CGonf client backend */
+ private static GConfNativePeer backend = new GConfNativePeer();
+
+ /** Default user root path */
+ private static final String DEFAULT_USER_ROOT = "/apps/java";
+
+ /** Default system root path */
+ private static final String DEFAULT_SYSTEM_ROOT = "/system";
+
+ /** current node full path */
+ private String node = "";
+
+ /** True if this is a preference node in the user tree, false otherwise. */
+ private final boolean isUser;
+
+ /**
+ * Creates a preference root user node.
+ */
+ public GConfBasedPreferences()
+ {
+ this(true);
+ }
+
+ /**
+ * Creates a preference root node. When <code>isUser</code> is true it will
+ * be user node otherwise it will be a system node.
+ */
+ public GConfBasedPreferences(boolean isUser)
+ {
+ this(null, "", isUser);
+ }
+
+ /**
+ * Creates a new preference node given a parent node and a name, which has to
+ * be relative to its parent. When <code>isUser</code> is true it will be user
+ * node otherwise it will be a system node.
+ *
+ * @param parent The parent node of this newly created node.
+ * @param name A name relative to the parent node.
+ * @param isUser Set to <code>true</code> initializes this node to be
+ * a user node, <code>false</code> initialize it to be a system node.
+ */
+ public GConfBasedPreferences(AbstractPreferences parent, String name,
+ boolean isUser)
+ {
+ super(parent, name);
+ this.isUser = isUser;
+
+ // stores the fully qualified name of this node
+ this.node = this.getRealRoot(isUser) + this.absolutePath();
+
+ boolean nodeExist = backend.nodeExist(this.node);
+
+ this.newNode = !nodeExist;
+ backend.startWatchingNode(this.node);
+ }
+
+ /**
+ * Returns a child node with the given name.
+ * If the child node does not exists, it will be created.
+ *
+ * @param name The name of the requested node.
+ * @return A new reference to the node, creating the node if it is necessary.
+ */
+ protected AbstractPreferences childSpi(String name)
+ {
+ // we don't check anything here, if the node is a new node this will be
+ // detected in the constructor, so we simply return a new reference to
+ // the requested node.
+ return new GConfBasedPreferences(this, name, this.isUser);
+ }
+
+ /**
+ * Returns an array of names of the children of this preference node.
+ * If the current node does not have children, the returned array will be
+ * of <code>size</code> 0 (that is, not <code>null</code>).
+ *
+ * @return A <code>String</code> array of names of children of the current
+ * node.
+ * @throws BackingStoreException if this operation cannot be completed.
+ */
+ protected String[] childrenNamesSpi() throws BackingStoreException
+ {
+ List nodeList = backend.getChildrenNodes(this.node);
+ String[] nodes = new String[nodeList.size()];
+ nodeList.toArray(nodes);
+
+ return nodes;
+ }
+
+ /**
+ * Suggest a flush to the backend. Actually, this is only a suggestion as
+ * GConf handles this for us asynchronously. More over, both sync and flush
+ * have the same meaning in this class, so calling sync has exactly the same
+ * effect.
+ *
+ * @see #sync
+ * @throws BackingStoreException if this operation cannot be completed.
+ */
+ public void flush() throws BackingStoreException
+ {
+ backend.suggestSync();
+ }
+
+ /**
+ * Request a flush.
+ *
+ * @see #flush
+ * @throws BackingStoreException if this operation cannot be completed.
+ */
+ protected void flushSpi() throws BackingStoreException
+ {
+ this.flush();
+ }
+
+ /**
+ * Returns all of the key in this preference node.
+ * If the current node does not have preferences, the returned array will be
+ * of size zero.
+ *
+ * @return A <code>String</code> array of keys stored under the current
+ * node.
+ * @throws BackingStoreException if this operation cannot be completed.
+ */
+ protected String[] keysSpi() throws BackingStoreException
+ {
+ List keyList = backend.getKeys(this.node);
+ String[] keys = new String[keyList.size()];
+ keyList.toArray(keys);
+
+ return keys;
+ }
+
+ /**
+ * Does a recursive postorder traversal of the preference tree, starting from
+ * the given directory invalidating every preference found in the node.
+ *
+ * @param directory The name of the starting directory (node)
+ */
+ private void postorderRemove(String directory)
+ {
+ try
+ {
+ // gets the listing of directories in this node
+ List dirs = backend.getChildrenNodes(directory);
+
+ if (dirs.size() != 0)
+ {
+ String currentDir = null;
+
+ for (Iterator itr = dirs.iterator(); itr.hasNext();)
+ {
+ currentDir = (String) itr.next();
+
+ // recursive search inside this directory
+ postorderRemove(currentDir);
+ }
+ }
+
+ // remove all the keys associated to this directory
+ List entries = backend.getKeys(directory);
+
+ if (entries.size() != 0)
+ {
+ String key = null;
+
+ for (Iterator keys = entries.iterator(); keys.hasNext();)
+ {
+ key = (String) keys.next();
+ this.removeSpi(key);
+ }
+ }
+ }
+ catch (BackingStoreException ex)
+ {
+ /* ignore */
+ }
+ }
+
+ /**
+ * Stores the given key-value pair into this preference node.
+ *
+ * @param key The key of this preference.
+ * @param value The value of this preference.
+ */
+ protected void putSpi(String key, String value)
+ {
+ backend.setString(this.getGConfKey(key), value);
+ }
+
+ /**
+ * Removes this preference node, including all its children.
+ * Also removes the preferences associated.
+ */
+ protected void removeNodeSpi() throws BackingStoreException
+ {
+ this.postorderRemove(this.node);
+ this.flush();
+ }
+
+ /**
+ * Removes the given key from this preference node.
+ * If the key does not exist, no operation is performed.
+ *
+ * @param key The key to remove.
+ */
+ protected void removeSpi(String key)
+ {
+ backend.unset(this.getGConfKey(key));
+ }
+
+ /**
+ * Suggest a sync to the backend. Actually, this is only a suggestion as GConf
+ * handles this for us asynchronously. More over, both sync and flush have the
+ * same meaning in this class, so calling flush has exactly the same effect.
+ *
+ * @see #flush
+ * @throws BackingStoreException if this operation cannot be completed due to
+ * a failure in the backing store, or inability to communicate with
+ * it.
+ */
+ public void sync() throws BackingStoreException
+ {
+ this.flush();
+ }
+
+ /**
+ * Request a sync.
+ *
+ * @see #sync
+ * @throws BackingStoreException if this operation cannot be completed due to
+ * a failure in the backing store, or inability to communicate with
+ * it.
+ */
+ protected void syncSpi() throws BackingStoreException
+ {
+ this.sync();
+ }
+
+ /**
+ * Returns the value of the given key.
+ * If the keys does not have a value, or there is an error in the backing
+ * store, <code>null</code> is returned instead.
+ *
+ * @param key The key to retrieve.
+ * @return The value associated with the given key.
+ */
+ protected String getSpi(String key)
+ {
+ return backend.getKey(this.getGConfKey(key));
+ }
+
+ /**
+ * Returns <code>true</code> if this preference node is a user node,
+ * <code>false</code> if is a system preference node.
+ *
+ * @return <code>true</code> if this preference node is a user node,
+ * <code>false</code> if is a system preference node.
+ */
+ public boolean isUserNode()
+ {
+ return this.isUser;
+ }
+
+ /*
+ * PRIVATE METHODS
+ */
+
+ /**
+ * Builds a GConf key string suitable for operations on the backend.
+ *
+ * @param key The key to convert into a valid GConf key.
+ * @return A valid Gconf key.
+ */
+ private String getGConfKey(String key)
+ {
+
+ String nodeName = "";
+
+ if (this.node.endsWith("/"))
+ {
+ nodeName = this.node + key;
+ }
+ else
+ {
+ nodeName = this.node + "/" + key;
+ }
+
+ return nodeName;
+ }
+
+ /**
+ * Builds the root node to use for this preference.
+ *
+ * @param isUser Defines if this node is a user (<code>true</code>) or system
+ * (<code>false</code>) node.
+ * @return The real root of this preference tree.
+ */
+ private String getRealRoot(boolean isUser)
+ {
+ // not sure about this, we should have already these permissions...
+ SecurityManager security = System.getSecurityManager();
+
+ if (security != null)
+ {
+ security.checkPermission(PERMISSION);
+ }
+
+ String root = null;
+
+ if (isUser)
+ {
+ root = System.getProperty("gnu.java.util.prefs.gconf.user_root",
+ DEFAULT_USER_ROOT);
+ }
+ else
+ {
+ root = System.getProperty("gnu.java.util.prefs.gconf.system_root",
+ DEFAULT_SYSTEM_ROOT);
+ }
+
+ return root;
+ }
+}
diff --git a/gnu/java/util/prefs/gconf/GConfNativePeer.java b/gnu/java/util/prefs/gconf/GConfNativePeer.java
new file mode 100644
index 000000000..8d773f916
--- /dev/null
+++ b/gnu/java/util/prefs/gconf/GConfNativePeer.java
@@ -0,0 +1,262 @@
+/* GConfNativePeer.java -- GConf based preference peer for native 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.util.prefs.gconf;
+
+import java.util.List;
+import java.util.prefs.BackingStoreException;
+
+/**
+ * Native peer for GConf based preference backend.
+ *
+ * @author Mario Torre <neugens@limasoftware.net>
+ * @version 1.0
+ */
+public final class GConfNativePeer
+{
+ /**
+ * Object to achieve locks for methods that need to be synchronized.
+ */
+ private static final Object[] semaphore = new Object[0];
+
+ /**
+ * Creates a new instance of GConfNativePeer
+ */
+ public GConfNativePeer()
+ {
+ synchronized (semaphore)
+ {
+ init_class();
+ }
+ }
+
+ /**
+ * Queries whether the node <code>node</code> exists in theGConf database.
+ * Returns <code>true</code> or <code>false</code>.
+ *
+ * @param node the node to check.
+ */
+ public boolean nodeExist(String node)
+ {
+ if (node.endsWith("/"))
+ {
+ node = node.substring(0, node.length() - 1);
+ }
+ return gconf_client_dir_exists(node);
+ }
+
+ /**
+ * Add the node <code>node</code> to the list of nodes the GConf will watch.
+ * An event is raised everytime this node is changed. You can add a node
+ * multiple times.
+ *
+ * @param node the node to track.
+ */
+ public void startWatchingNode(String node)
+ {
+ if (node.endsWith("/"))
+ {
+ node = node.substring(0, node.length() - 1);
+ }
+ gconf_client_add_dir(node);
+ }
+
+ /**
+ * Remove the node <code>node</code> to the list of nodes the GConf is
+ * watching. Note that if a node has been added multiple times, you must
+ * remove it the same number of times before the remove takes effect.
+ *
+ * @param node the node you don't want to track anymore.
+ */
+ public void stopWatchingNode(String node)
+ {
+ if (node.endsWith("/"))
+ {
+ node = node.substring(0, node.length() - 1);
+ }
+ gconf_client_remove_dir(node);
+ }
+
+ /**
+ * Change the value of key to val. Automatically creates the key if it didn't
+ * exist before (ie it was unset or it only had a default value).
+ *
+ * @param key the key to alter (or add).
+ * @param value the new value for this key.
+ * @return true if the key was updated, false otherwise.
+ */
+ public boolean setString(String key, String value)
+ {
+ if (key.endsWith("/"))
+ {
+ key = key.substring(0, key.length() - 1);
+ }
+ return gconf_client_set_string(key, value);
+ }
+
+ /**
+ * Unsets the value of key; if key is already unset, has no effect. Depending
+ * on the GConf daemon, unsetting a key may have the side effect to remove it
+ * completely form the database.
+ *
+ * @param key the key to unset.
+ * @return true on success, false if the key was not updated.
+ */
+ public boolean unset(String key)
+ {
+ if (key.endsWith("/"))
+ {
+ key = key.substring(0, key.length() - 1);
+ }
+ return gconf_client_unset(key);
+ }
+
+ /**
+ * Gets the value of a configuration key.
+ *
+ * @param key the configuration key.
+ * @return the values of this key, null if the key is not valid.
+ */
+ public String getKey(String key)
+ {
+ if (key.endsWith("/"))
+ {
+ key = key.substring(0, key.length() - 1);
+ }
+ return gconf_client_get_string(key);
+ }
+
+ /**
+ * Lists the key in the given node. Does not list subnodes. Keys names are the
+ * stripped names (name relative to the current node) of the kyes stored in
+ * this node.
+ *
+ * @param node the node where keys are stored.
+ * @return a java.util.List of keys. If there are no keys in the given node, a
+ * list of size 0 is returned.
+ */
+ public List getKeys(String node) throws BackingStoreException
+ {
+ if (node.endsWith("/"))
+ {
+ node = node.substring(0, node.length() - 1);
+ }
+ return gconf_client_gconf_client_all_keys(node);
+ }
+
+ /**
+ * Lists the subnodes in <code>node</code>. The returned list contains
+ * allocated strings. Each string is the name relative tho the given node.
+ *
+ * @param node the node to get subnodes from. If there are no subnodes in the
+ * given node, a list of size 0 is returned.
+ */
+ public List getChildrenNodes(String node) throws BackingStoreException
+ {
+ if (node.endsWith("/"))
+ {
+ node = node.substring(0, node.length() - 1);
+ }
+ return gconf_client_gconf_client_all_nodes(node);
+ }
+
+ /**
+ * Suggest to the backend GConf daemon to synch with the database.
+ */
+ public void suggestSync() throws BackingStoreException
+ {
+ gconf_client_suggest_sync();
+ }
+
+ protected void finalize() throws Throwable
+ {
+ try
+ {
+ synchronized (semaphore)
+ {
+ finalize_class();
+ }
+ }
+ finally
+ {
+ super.finalize();
+ }
+ }
+
+ /* ***** native methods ***** */
+
+ /*
+ * Basicly, these are one to one mappings to GConfClient functions.
+ * GConfClient instances are handled by the native layer, and are hidden from
+ * the main java class.
+ */
+
+ /** */
+ native static final private void init_id_cache();
+
+ native static final private void init_class();
+
+ native static final private void finalize_class();
+
+ native static final protected boolean gconf_client_dir_exists(String node);
+
+ native static final protected void gconf_client_add_dir(String node);
+
+ native static final protected void gconf_client_remove_dir(String node);
+
+ native static final protected boolean gconf_client_set_string(String key,
+ String value);
+
+ native static final protected String gconf_client_get_string(String key);
+
+ native static final protected boolean gconf_client_unset(String key);
+
+ native static final protected void gconf_client_suggest_sync();
+
+ native static final protected List gconf_client_gconf_client_all_nodes(
+ String node);
+
+ native static final protected List gconf_client_gconf_client_all_keys(
+ String node);
+
+ static
+ {
+ System.loadLibrary("gconfpeer");
+ init_id_cache();
+ }
+}
diff --git a/gnu/javax/crypto/assembly/Assembly.java b/gnu/javax/crypto/assembly/Assembly.java
index 2d5bba364..49770675b 100644
--- a/gnu/javax/crypto/assembly/Assembly.java
+++ b/gnu/javax/crypto/assembly/Assembly.java
@@ -41,23 +41,19 @@ package gnu.javax.crypto.assembly;
import java.util.Map;
/**
- * <p>An <code>Assembly</code> is a construction consisting of a chain of
+ * An <code>Assembly</code> is a construction consisting of a chain of
* {@link Transformer} elements; each wired in pre- or post- transformation
* mode. This chain is terminated by one <code>LoopbackTransformer</code>
- * element.</p>
- *
- * <p>Once constructed, and correctly initialised, the bulk of the methods
- * available on the <code>Assembly</code> are delegated to the <i>head</i>
- * of the {@link Transformer} chain of the <code>Assembly</code>.</p>
- *
+ * element.
+ * <p>
+ * Once constructed, and correctly initialised, the bulk of the methods
+ * available on the <code>Assembly</code> are delegated to the <i>head</i> of
+ * the {@link Transformer} chain of the <code>Assembly</code>.
+ *
* @see Transformer
*/
public class Assembly
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String DIRECTION = "gnu.crypto.assembly.assembly.direction";
/** Flag that tells if the instance is initialised or not; and if yes how. */
@@ -66,9 +62,6 @@ public class Assembly
/** The first Transformer in the chain. */
private Transformer head;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Trivial constructor that sets the <i>chain</i> to a
* <code>LoopbackTransformer</code>.
@@ -81,21 +74,15 @@ public class Assembly
head = new LoopbackTransformer();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Adds the designated {@link Transformer} and signals that it should operate
* in pre-processing mode; i.e. it should apply its internal transformation
* algorithm on the input data stream, <b>before</b> it passes that stream to
* the next element in the <i>chain</i>.
- *
+ *
* @param t the {@link Transformer} to add at the head of the current chain.
- * @throws IllegalArgumentException if the designated {@link Transformer}
- * has a non-null tail; i.e. it is already an element of a chain.
+ * @throws IllegalArgumentException if the designated {@link Transformer} has
+ * a non-null tail; i.e. it is already an element of a chain.
*/
public void addPreTransformer(Transformer t)
{
@@ -107,10 +94,10 @@ public class Assembly
* in post-processing mode; i.e. it should apply its internal transformation
* algorithm on the input data stream, <b>after</b> it passes that stream to
* the next element in the <i>chain</i>.
- *
+ *
* @param t the {@link Transformer} to add at the head of the current chain.
- * @throws IllegalArgumentException if the designated {@link Transformer}
- * has a non-null tail; i.e. it is already an element of a chain.
+ * @throws IllegalArgumentException if the designated {@link Transformer} has
+ * a non-null tail; i.e. it is already an element of a chain.
*/
public void addPostTransformer(Transformer t)
{
@@ -120,22 +107,18 @@ public class Assembly
/**
* Initialises the <code>Assembly</code> for operation with specific
* characteristics.
- *
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @throws IllegalStateException if the instance is already initialised.
*/
public void init(Map attributes) throws TransformerException
{
if (wired != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == null)
- {
- flow = Direction.FORWARD;
- }
+ flow = Direction.FORWARD;
attributes.put(Transformer.DIRECTION, flow);
head.init(attributes);
wired = flow;
@@ -155,12 +138,12 @@ public class Assembly
* Convenience method that calls the method with same name and three
* arguments, using a byte array of length <code>1</code> whose contents are
* the designated byte.
- *
+ *
* @param b the byte to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #update(byte[], int, int)
*/
public byte[] update(byte b) throws TransformerException
@@ -172,12 +155,12 @@ public class Assembly
* Convenience method that calls the method with same name and three
* arguments. All bytes in <code>in</code>, starting from index position
* <code>0</code> are considered.
- *
+ *
* @param in the input data bytes.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #update(byte[], int, int)
*/
public byte[] update(byte[] in) throws TransformerException
@@ -187,34 +170,32 @@ public class Assembly
/**
* Processes a designated number of bytes from a given byte array.
- *
+ *
* @param in the input data bytes.
* @param offset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param length the count of bytes to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
*/
public byte[] update(byte[] in, int offset, int length)
throws TransformerException
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return head.update(in, offset, length);
}
/**
- * Convenience method that calls the method with same name and three
- * arguments using a 0-long byte array.
- *
+ * Convenience method that calls the method with same name and three arguments
+ * using a 0-long byte array.
+ *
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate() throws TransformerException
@@ -226,12 +207,12 @@ public class Assembly
* Convenience method that calls the method with same name and three
* arguments, using a byte array of length <code>1</code> whose contents are
* the designated byte.
- *
+ *
* @param b the byte to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate(byte b) throws TransformerException
@@ -243,12 +224,12 @@ public class Assembly
* Convenience method that calls the method with same name and three
* arguments. All bytes in <code>in</code>, starting from index position
* <code>0</code> are considered.
- *
+ *
* @param in the input data bytes.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate(byte[] in) throws TransformerException
@@ -257,39 +238,33 @@ public class Assembly
}
/**
- * Processes a designated number of bytes from a given byte array and
- * signals, at the same time, that this is the last <i>push</i> operation for
- * this <code>Assembly</code>.
- *
+ * Processes a designated number of bytes from a given byte array and signals,
+ * at the same time, that this is the last <i>push</i> operation for this
+ * <code>Assembly</code>.
+ *
* @param in the input data bytes.
* @param offset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param length the count of bytes to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
- * @throws TransformerException if a transformation-related exception
- * occurs during the operation.
+ * @throws TransformerException if a transformation-related exception occurs
+ * during the operation.
*/
public byte[] lastUpdate(byte[] in, int offset, int length)
throws TransformerException
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
byte[] result = head.lastUpdate(in, offset, length);
reset();
return result;
}
- // helper methods ----------------------------------------------------------
-
private void wireTransformer(Transformer t, Operation mode)
{
if (t.tail != null)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
t.setMode(mode);
t.tail = head;
head = t;
diff --git a/gnu/javax/crypto/assembly/Cascade.java b/gnu/javax/crypto/assembly/Cascade.java
index a35d66886..f790956a4 100644
--- a/gnu/javax/crypto/assembly/Cascade.java
+++ b/gnu/javax/crypto/assembly/Cascade.java
@@ -49,36 +49,31 @@ import java.util.Map;
import java.util.Set;
/**
- * <p>A <i>Cascade</i> Cipher is the concatenation of two or more block ciphers
+ * A <i>Cascade</i> Cipher is the concatenation of two or more block ciphers
* each with independent keys. Plaintext is input to the first stage; the output
- * of stage <code>i</code> is input to stage <code>i + 1</code>; and the output
- * of the last stage is the <i>Cascade</i>'s ciphertext output.</p>
- *
- * <p>In the simplest case, all stages in a <code>Cascade</code> have <i>k</i>-bit
+ * of stage <code>i</code> is input to stage <code>i + 1</code>; and the
+ * output of the last stage is the <i>Cascade</i>'s ciphertext output.
+ * <p>
+ * In the simplest case, all stages in a <code>Cascade</code> have <i>k</i>-bit
* keys, and the stage inputs and outputs are all n-bit quantities. The stage
* ciphers may differ (general cascade of ciphers), or all be identical (cascade
- * of identical ciphers).</p>
- *
- * <p>The term "block ciphers" used above refers to implementations of
- * {@link gnu.javax.crypto.mode.IMode}, including the {@link gnu.javax.crypto.mode.ECB}
- * mode which basically exposes a symmetric-key block cipher algorithm as a
- * <i>Mode</i> of Operations.</p>
- *
- * <p>References:</p>
- *
+ * of identical ciphers).
+ * <p>
+ * The term "block ciphers" used above refers to implementations of
+ * {@link gnu.javax.crypto.mode.IMode}, including the
+ * {@link gnu.javax.crypto.mode.ECB} mode which basically exposes a
+ * symmetric-key block cipher algorithm as a <i>Mode</i> of Operations.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
- * Applied Cryptography.<br>
- * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
- * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
+ * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
+ * Applied Cryptography.<br>
+ * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
+ * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
* </ol>
*/
public class Cascade
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String DIRECTION = "gnu.crypto.assembly.cascade.direction";
/** The map of Stages chained in this cascade. */
@@ -93,9 +88,6 @@ public class Cascade
/** The curently set block-size for this instance. */
protected int blockSize;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Cascade()
{
super();
@@ -106,12 +98,9 @@ public class Cascade
blockSize = 0;
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
* Returns the Least Common Multiple of two integers.
- *
+ *
* @param a the first integer.
* @param b the second integer.
* @return the LCM of <code>abs(a)</code> and <code>abs(b)</code>.
@@ -123,18 +112,15 @@ public class Cascade
return A.multiply(B).divide(A.gcd(B)).abs().intValue();
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Adds to the end of the current chain, a designated {@link Stage}.
- *
+ *
* @param stage the {@link Stage} to append to the chain.
* @return a unique identifier for this stage, within this cascade.
* @throws IllegalStateException if the instance is already initialised.
- * @throws IllegalArgumentException if the designated stage is already in
- * the chain, or it has incompatible characteristics with the current
- * elements already in the chain.
+ * @throws IllegalArgumentException if the designated stage is already in the
+ * chain, or it has incompatible characteristics with the current
+ * elements already in the chain.
*/
public Object append(Stage stage) throws IllegalArgumentException
{
@@ -143,13 +129,13 @@ public class Cascade
/**
* Adds to the begining of the current chain, a designated {@link Stage}.
- *
+ *
* @param stage the {@link Stage} to prepend to the chain.
* @return a unique identifier for this stage, within this cascade.
* @throws IllegalStateException if the instance is already initialised.
- * @throws IllegalArgumentException if the designated stage is already in
- * the chain, or it has incompatible characteristics with the current
- * elements already in the chain.
+ * @throws IllegalArgumentException if the designated stage is already in the
+ * chain, or it has incompatible characteristics with the current
+ * elements already in the chain.
*/
public Object prepend(Stage stage) throws IllegalArgumentException
{
@@ -159,62 +145,49 @@ public class Cascade
/**
* Inserts a {@link Stage} into the current chain, at the specified index
* (zero-based) position.
- *
+ *
* @param stage the {@link Stage} to insert into the chain.
* @return a unique identifier for this stage, within this cascade.
- * @throws IllegalArgumentException if the designated stage is already in
- * the chain, or it has incompatible characteristics with the current
- * elements already in the chain.
+ * @throws IllegalArgumentException if the designated stage is already in the
+ * chain, or it has incompatible characteristics with the current
+ * elements already in the chain.
* @throws IllegalStateException if the instance is already initialised.
* @throws IndexOutOfBoundsException if <code>index</code> is less than
- * <code>0</code> or greater than the current size of this cascade.
+ * <code>0</code> or greater than the current size of this
+ * cascade.
*/
public Object insert(int index, Stage stage) throws IllegalArgumentException,
IndexOutOfBoundsException
{
if (stages.containsValue(stage))
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
if (wired != null || stage == null)
- {
- throw new IllegalStateException();
- }
-
+ throw new IllegalStateException();
if (index < 0 || index > size())
- {
- throw new IndexOutOfBoundsException();
- }
-
+ throw new IndexOutOfBoundsException();
// check that there is a non-empty set of common block-sizes
Set set = stage.blockSizes();
if (stages.isEmpty())
{
if (set.isEmpty())
- {
- throw new IllegalArgumentException("1st stage with no block sizes");
- }
+ throw new IllegalArgumentException("1st stage with no block sizes");
}
else
{
Set common = this.blockSizes();
common.retainAll(set);
if (common.isEmpty())
- {
- throw new IllegalArgumentException("no common block sizes found");
- }
+ throw new IllegalArgumentException("no common block sizes found");
}
-
Object result = new Object();
stageKeys.add(index, result);
stages.put(result, stage);
-
return result;
}
/**
* Returns the current number of stages in this chain.
- *
+ *
* @return the current count of stages in this chain.
*/
public int size()
@@ -226,18 +199,16 @@ public class Cascade
* Returns an {@link Iterator} over the stages contained in this instance.
* Each element of this iterator is a concrete implementation of a {@link
* Stage}.
- *
+ *
* @return an {@link Iterator} over the stages contained in this instance.
- * Each element of the returned iterator is a concrete instance of a {@link
- * Stage}.
+ * Each element of the returned iterator is a concrete instance of a
+ * {@link Stage}.
*/
public Iterator stages()
{
LinkedList result = new LinkedList();
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
- {
- result.addLast(stages.get(it.next()));
- }
+ result.addLast(stages.get(it.next()));
return result.listIterator();
}
@@ -245,9 +216,9 @@ public class Cascade
* Returns the {@link Set} of supported block sizes for this
* <code>Cascade</code> that are common to all of its chained stages. Each
* element in the returned {@link Set} is an instance of {@link Integer}.
- *
- * @return a {@link Set} of supported block sizes common to all the stages
- * of the chain.
+ *
+ * @return a {@link Set} of supported block sizes common to all the stages of
+ * the chain.
*/
public Set blockSizes()
{
@@ -255,42 +226,33 @@ public class Cascade
for (Iterator it = stages.values().iterator(); it.hasNext();)
{
Stage aStage = (Stage) it.next();
- if (result == null)
- { // first time
- result = new HashSet(aStage.blockSizes());
- }
+ if (result == null) // first time
+ result = new HashSet(aStage.blockSizes());
else
- {
- result.retainAll(aStage.blockSizes());
- }
+ result.retainAll(aStage.blockSizes());
}
return result == null ? Collections.EMPTY_SET : result;
}
/**
* Initialises the chain for operation with specific characteristics.
- *
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @throws IllegalStateException if the chain, or any of its stages, is
- * already initialised.
+ * already initialised.
* @throws InvalidKeyException if the intialisation data provided with the
- * stage is incorrect or causes an invalid key to be generated.
+ * stage is incorrect or causes an invalid key to be generated.
* @see Direction#FORWARD
* @see Direction#REVERSED
*/
public void init(Map attributes) throws InvalidKeyException
{
if (wired != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == null)
- {
- flow = Direction.FORWARD;
- }
-
+ flow = Direction.FORWARD;
int optimalSize = 0;
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
{
@@ -300,30 +262,25 @@ public class Cascade
Stage stage = (Stage) stages.get(id);
stage.init(attr);
optimalSize = optimalSize == 0 ? stage.currentBlockSize()
- : lcm(optimalSize,
- stage.currentBlockSize());
- }
-
- if (flow == Direction.REVERSED)
- { // reverse order
- Collections.reverse(stageKeys);
+ : lcm(optimalSize,
+ stage.currentBlockSize());
}
+ if (flow == Direction.REVERSED) // reverse order
+ Collections.reverse(stageKeys);
wired = flow;
blockSize = optimalSize;
}
/**
* Returns the currently set block size for the chain.
- *
+ *
* @return the current block size for the chain.
* @throws IllegalStateException if the instance is not initialised.
*/
public int currentBlockSize()
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return blockSize;
}
@@ -334,25 +291,21 @@ public class Cascade
public void reset()
{
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
- {
- ((Stage) stages.get(it.next())).reset();
- }
- if (wired == Direction.REVERSED)
- { // reverse it back
- Collections.reverse(stageKeys);
- }
+ ((Stage) stages.get(it.next())).reset();
+ if (wired == Direction.REVERSED) // reverse it back
+ Collections.reverse(stageKeys);
wired = null;
blockSize = 0;
}
/**
* Processes exactly one block of <i>plaintext</i> (if initialised in the
- * {@link Direction#FORWARD} state) or <i>ciphertext</i> (if initialised in the
- * {@link Direction#REVERSED} state).
- *
+ * {@link Direction#FORWARD} state) or <i>ciphertext</i> (if initialised in
+ * the {@link Direction#REVERSED} state).
+ *
* @param in the plaintext.
* @param inOffset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param out the ciphertext.
* @param outOffset index of <code>out</code> from which to store result.
* @throws IllegalStateException if the instance is not initialised.
@@ -360,23 +313,17 @@ public class Cascade
public void update(byte[] in, int inOffset, byte[] out, int outOffset)
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
int stageBlockSize, j, i = stages.size();
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
{
Stage stage = (Stage) stages.get(it.next());
stageBlockSize = stage.currentBlockSize();
for (j = 0; j < blockSize; j += stageBlockSize)
- {
- stage.update(in, inOffset + j, out, outOffset + j);
- }
+ stage.update(in, inOffset + j, out, outOffset + j);
i--;
if (i > 0)
- {
- System.arraycopy(out, outOffset, in, inOffset, blockSize);
- }
+ System.arraycopy(out, outOffset, in, inOffset, blockSize);
}
}
@@ -385,18 +332,16 @@ public class Cascade
* encryption / decryption test(s) for all supported block and key sizes of
* underlying block cipher(s) wrapped by Mode leafs. The test also includes
* one (1) variable key Known Answer Test (KAT) for each block cipher.
- *
+ *
* @return <code>true</code> if the implementation passes simple
- * <i>correctness</i> tests. Returns <code>false</code> otherwise.
+ * <i>correctness</i> tests. Returns <code>false</code> otherwise.
*/
public boolean selfTest()
{
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
{
- if (!((Stage) stages.get(it.next())).selfTest())
- {
- return false;
- }
+ if (! ((Stage) stages.get(it.next())).selfTest())
+ return false;
}
return true;
}
diff --git a/gnu/javax/crypto/assembly/CascadeStage.java b/gnu/javax/crypto/assembly/CascadeStage.java
index 81629f5a8..b86f42e2a 100644
--- a/gnu/javax/crypto/assembly/CascadeStage.java
+++ b/gnu/javax/crypto/assembly/CascadeStage.java
@@ -44,19 +44,13 @@ import java.util.Map;
import java.util.Set;
/**
- * <p>A Cascade <i>Stage</i> in a Cascade Cipher.</p>
+ * A Cascade <i>Stage</i> in a Cascade Cipher.
*/
-class CascadeStage extends Stage
+class CascadeStage
+ extends Stage
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private Cascade delegate;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
CascadeStage(Cascade cascade, Direction forwardDirection)
{
super(forwardDirection);
@@ -64,12 +58,6 @@ class CascadeStage extends Stage
this.delegate = cascade;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public Set blockSizes()
{
return Collections.unmodifiableSet(delegate.blockSizes());
@@ -79,9 +67,7 @@ class CascadeStage extends Stage
{
Direction flow = (Direction) attributes.get(DIRECTION);
attributes.put(DIRECTION, flow.equals(forward) ? forward
- : Direction.reverse(forward));
- // delegate.init(flow.equals(forward) ? forward : backward);
- // delegate.init(flow.equals(forward) ? forward : Direction.reverse(forward));
+ : Direction.reverse(forward));
delegate.init(attributes);
}
diff --git a/gnu/javax/crypto/assembly/CascadeTransformer.java b/gnu/javax/crypto/assembly/CascadeTransformer.java
index dbbc7cd28..5fce51a15 100644
--- a/gnu/javax/crypto/assembly/CascadeTransformer.java
+++ b/gnu/javax/crypto/assembly/CascadeTransformer.java
@@ -45,19 +45,13 @@ import java.util.Map;
* An Adapter to use any {@link Cascade} as a {@link Transformer} in an
* {@link Assembly}.
*/
-class CascadeTransformer extends Transformer
+class CascadeTransformer
+ extends Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private Cascade delegate;
private int blockSize;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
CascadeTransformer(Cascade delegate)
{
super();
@@ -65,12 +59,6 @@ class CascadeTransformer extends Transformer
this.delegate = delegate;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instant methods
- // -------------------------------------------------------------------------
-
void initDelegate(Map attributes) throws TransformerException
{
attributes.put(Cascade.DIRECTION, wired);
@@ -107,11 +95,9 @@ class CascadeTransformer extends Transformer
{
if (inBuffer.size() != 0)
{
- throw new TransformerException(
- "lastUpdateDelegate()",
- new IllegalStateException(
- "Cascade transformer, after last "
- + "update, must be empty but isn't"));
+ IllegalStateException cause = new IllegalStateException(
+ "Cascade transformer, after last update, must be empty but isn't");
+ throw new TransformerException("lastUpdateDelegate()", cause);
}
return new byte[0];
}
diff --git a/gnu/javax/crypto/assembly/DeflateTransformer.java b/gnu/javax/crypto/assembly/DeflateTransformer.java
index 35328a6c1..e5c0b7a57 100644
--- a/gnu/javax/crypto/assembly/DeflateTransformer.java
+++ b/gnu/javax/crypto/assembly/DeflateTransformer.java
@@ -44,27 +44,22 @@ import java.util.zip.Deflater;
import java.util.zip.Inflater;
/**
- * <p>A {@link Transformer} Adapter allowing inclusion of a DEFLATE compression
+ * A {@link Transformer} Adapter allowing inclusion of a DEFLATE compression
* algorithm in an {@link Assembly} chain. The {@link Direction#FORWARD}
* transformation is a compression (deflate) of input data, while the
- * {@link Direction#REVERSED} one is a decompression (inflate) that restores
- * the original data.</p>
- *
- * <p>This {@link Transformer} uses a {@link Deflater} instance to carry on the
- * compression, and an {@link Inflater} to do the decompression.</p>
- *
- * <p>When using such a {@link Transformer}, in an {@link Assembly}, there must
+ * {@link Direction#REVERSED} one is a decompression (inflate) that restores the
+ * original data.
+ * <p>
+ * This {@link Transformer} uses a {@link Deflater} instance to carry on the
+ * compression, and an {@link Inflater} to do the decompression.
+ * <p>
+ * When using such a {@link Transformer}, in an {@link Assembly}, there must
* be at least one element behind this instance in the constructed chain;
- * otherwise, a {@link TransformerException} is thrown at initialisation time.</p>
- *
- * @version Revision: $
+ * otherwise, a {@link TransformerException} is thrown at initialisation time.
*/
-class DeflateTransformer extends Transformer
+class DeflateTransformer
+ extends Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private Deflater compressor;
private Inflater decompressor;
@@ -73,46 +68,31 @@ class DeflateTransformer extends Transformer
private byte[] zlibBuffer;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
DeflateTransformer()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
void initDelegate(Map attributes) throws TransformerException
{
if (tail == null)
{
- throw new TransformerException(
- "initDelegate()",
- new IllegalStateException(
- "Compression transformer missing its tail!"));
+ IllegalStateException cause = new IllegalStateException(
+ "Compression transformer missing its tail!");
+ throw new TransformerException("initDelegate()", cause);
}
outputBlockSize = tail.currentBlockSize();
zlibBuffer = new byte[outputBlockSize];
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == Direction.FORWARD)
- {
- compressor = new Deflater();
- }
+ compressor = new Deflater();
else
- {
- decompressor = new Inflater();
- }
+ decompressor = new Inflater();
}
int delegateBlockSize()
{
- // return outputBlockSize;
return 1;
}
@@ -131,68 +111,36 @@ class DeflateTransformer extends Transformer
if (wired == Direction.FORWARD)
{
compressor.setInput(in, offset, length);
- while (!compressor.needsInput())
- {
- compress();
- }
+ while (! compressor.needsInput())
+ compress();
}
- else
- { // decompression: inflate first and then update tail
- decompress(in, offset, length);
- }
-
+ else // decompression: inflate first and then update tail
+ decompress(in, offset, length);
result = inBuffer.toByteArray();
inBuffer.reset();
return result;
}
- // byte[] lastUpdateDelegate(byte[] in, int offset, int length)
- // throws TransformerException {
- // // process multiples of blocksize as much as possible
- // byte[] result = this.updateDelegate(in, offset, length);
- // inBuffer.write(result, 0, result.length);
- // if (wired == Direction.FORWARD) { // compressing
- // if (!compressor.finished()) {
- // compressor.finish();
- // while (!compressor.finished()) {
- // compress();
- // }
- // }
- // } else { // decompressing
- // if (!decompressor.finished()) {
- // throw new TransformerException("lastUpdateDelegate()",
- // new IllegalStateException("Compression transformer, after last "
- // +"update, must be finished but isn't"));
- // }
- // }
- //
- // result = inBuffer.toByteArray();
- // inBuffer.reset();
- // return result;
- // }
byte[] lastUpdateDelegate() throws TransformerException
{
// process multiples of blocksize as much as possible
- if (wired == Direction.FORWARD)
- { // compressing
- if (!compressor.finished())
+ if (wired == Direction.FORWARD) // compressing
+ {
+ if (! compressor.finished())
{
compressor.finish();
- while (!compressor.finished())
- {
- compress();
- }
+ while (! compressor.finished())
+ compress();
}
}
- else
- { // decompressing
- if (!decompressor.finished())
+ else // decompressing
+ {
+ if (! decompressor.finished())
{
- throw new TransformerException(
- "lastUpdateDelegate()",
- new IllegalStateException(
- "Compression transformer, after last "
- + "update, must be finished but isn't"));
+ IllegalStateException cause = new IllegalStateException(
+ "Compression transformer, after last update, must be finished "
+ + "but isn't");
+ throw new TransformerException("lastUpdateDelegate()", cause);
}
}
byte[] result = inBuffer.toByteArray();
@@ -204,9 +152,7 @@ class DeflateTransformer extends Transformer
{
int len = compressor.deflate(zlibBuffer);
if (len > 0)
- {
- inBuffer.write(zlibBuffer, 0, len);
- }
+ inBuffer.write(zlibBuffer, 0, len);
}
private void decompress(byte[] in, int offset, int length)
@@ -225,9 +171,7 @@ class DeflateTransformer extends Transformer
throw new TransformerException("decompress()", x);
}
if (len > 0)
- {
- inBuffer.write(zlibBuffer, 0, len);
- }
+ inBuffer.write(zlibBuffer, 0, len);
}
}
}
diff --git a/gnu/javax/crypto/assembly/Direction.java b/gnu/javax/crypto/assembly/Direction.java
index 935b9618e..48c74ed1b 100644
--- a/gnu/javax/crypto/assembly/Direction.java
+++ b/gnu/javax/crypto/assembly/Direction.java
@@ -39,32 +39,26 @@ exception statement from your version. */
package gnu.javax.crypto.assembly;
/**
- * <p>An enumeration type for wiring {@link Stage} instances into {@link
- * Cascade} Cipher chains, as well as for operating a {@link Cascade} in a
- * given direction.</p>
- *
- * <p>The possible values for this type are two:</p>
+ * An enumeration type for wiring {@link Stage} instances into {@link Cascade}
+ * Cipher chains, as well as for operating a {@link Cascade} in a given
+ * direction.
+ * <p>
+ * The possible values for this type are two:
* <ol>
- * <li>FORWARD: equivalent to {@link gnu.javax.crypto.mode.IMode#ENCRYPTION}, and
- * its inverse value</li>
- * <li>REVERSED: equivalent to {@link gnu.javax.crypto.mode.IMode#DECRYPTION}.</li>
+ * <li>FORWARD: equivalent to {@link gnu.javax.crypto.mode.IMode#ENCRYPTION},
+ * and its inverse value</li>
+ * <li>REVERSED: equivalent to {@link gnu.javax.crypto.mode.IMode#DECRYPTION}.
+ * </li>
* </ol>
*/
public final class Direction
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final Direction FORWARD = new Direction(1);
public static final Direction REVERSED = new Direction(2);
private int value;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
private Direction(int value)
{
super();
@@ -72,17 +66,11 @@ public final class Direction
this.value = value;
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static final Direction reverse(Direction d)
{
return (d.equals(FORWARD) ? REVERSED : FORWARD);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
public String toString()
{
return (this == FORWARD ? "forward" : "reversed");
diff --git a/gnu/javax/crypto/assembly/LoopbackTransformer.java b/gnu/javax/crypto/assembly/LoopbackTransformer.java
index 3c0bdfab3..bba1da778 100644
--- a/gnu/javax/crypto/assembly/LoopbackTransformer.java
+++ b/gnu/javax/crypto/assembly/LoopbackTransformer.java
@@ -44,27 +44,15 @@ import java.util.Map;
* A trivial {@link Transformer} to allow closing a chain in an {@link Assembly}.
* This class is not visible outside this package.
*/
-final class LoopbackTransformer extends Transformer
+final class LoopbackTransformer
+ extends Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
- /** Trivial protected constructor. */
+ /** Trivial package-private constructor. */
LoopbackTransformer()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public void init(Map attributes) throws TransformerException
{
}
@@ -84,8 +72,6 @@ final class LoopbackTransformer extends Transformer
return lastUpdateDelegate();
}
- // abstract methods to be implemented by concrete subclasses ---------------
-
void initDelegate(Map attributes) throws TransformerException
{
}
diff --git a/gnu/javax/crypto/assembly/ModeStage.java b/gnu/javax/crypto/assembly/ModeStage.java
index 1143348f6..253ab4ae6 100644
--- a/gnu/javax/crypto/assembly/ModeStage.java
+++ b/gnu/javax/crypto/assembly/ModeStage.java
@@ -48,25 +48,19 @@ import java.util.Map;
import java.util.Set;
/**
- * <p>An {@link IMode} {@link Stage} in a {@link Cascade} Cipher chain.</p>
- *
- * <p>Such a stage wraps an implementation of a Block Cipher Mode of Operation
+ * An {@link IMode} {@link Stage} in a {@link Cascade} Cipher chain.
+ * <p>
+ * Such a stage wraps an implementation of a Block Cipher Mode of Operation
* ({@link IMode}) to allow inclusion of such an instance in a cascade of block
- * ciphers.</p>
+ * ciphers.
*/
-class ModeStage extends Stage
+class ModeStage
+ extends Stage
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private IMode delegate;
private transient Set cachedBlockSizes;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
ModeStage(IMode mode, Direction forwardDirection)
{
super(forwardDirection);
@@ -75,21 +69,13 @@ class ModeStage extends Stage
cachedBlockSizes = null;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public Set blockSizes()
{
if (cachedBlockSizes == null)
{
HashSet result = new HashSet();
for (Iterator it = delegate.blockSizes(); it.hasNext();)
- {
- result.add(it.next());
- }
+ result.add(it.next());
cachedBlockSizes = Collections.unmodifiableSet(result);
}
return cachedBlockSizes;
@@ -99,9 +85,8 @@ class ModeStage extends Stage
{
Direction flow = (Direction) attributes.get(DIRECTION);
attributes.put(IMode.STATE,
- new Integer(flow.equals(forward) ? IMode.ENCRYPTION
- : IMode.DECRYPTION));
-
+ Integer.valueOf(flow.equals(forward) ? IMode.ENCRYPTION
+ : IMode.DECRYPTION));
delegate.init(attributes);
}
diff --git a/gnu/javax/crypto/assembly/Operation.java b/gnu/javax/crypto/assembly/Operation.java
index 34cae52ea..28fdf9412 100644
--- a/gnu/javax/crypto/assembly/Operation.java
+++ b/gnu/javax/crypto/assembly/Operation.java
@@ -39,34 +39,26 @@ exception statement from your version. */
package gnu.javax.crypto.assembly;
/**
- * <p>An enumeration type for specifying the operation type of a
- * {@link Transformer}.</p>
- *
- * <p>The possible values for this type are two:</p>
+ * An enumeration type for specifying the operation type of a
+ * {@link Transformer}.
+ * <p>
+ * The possible values for this type are two:
* <ol>
- * <li>PRE_PROCESSING: where the input data is first processed by the
- * current {@link Transformer} before being passed to the rest of the chain;
- * and</li>
- * <li>POST_PROCESSING: where the input data is first passed to the rest of
- * the chain, and the resulting bytes are then processed by the current
- * {@link Transformer}.</li>
+ * <li>PRE_PROCESSING: where the input data is first processed by the current
+ * {@link Transformer} before being passed to the rest of the chain; and</li>
+ * <li>POST_PROCESSING: where the input data is first passed to the rest of the
+ * chain, and the resulting bytes are then processed by the current
+ * {@link Transformer}.</li>
* </ol>
*/
public final class Operation
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final Operation PRE_PROCESSING = new Operation(1);
public static final Operation POST_PROCESSING = new Operation(2);
private int value;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
private Operation(int value)
{
super();
@@ -74,12 +66,6 @@ public final class Operation
this.value = value;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public String toString()
{
return (this == PRE_PROCESSING ? "pre-processing" : "post-processing");
diff --git a/gnu/javax/crypto/assembly/PaddingTransformer.java b/gnu/javax/crypto/assembly/PaddingTransformer.java
index c63f92e87..c11f4fe88 100644
--- a/gnu/javax/crypto/assembly/PaddingTransformer.java
+++ b/gnu/javax/crypto/assembly/PaddingTransformer.java
@@ -44,26 +44,20 @@ import gnu.javax.crypto.pad.WrongPaddingException;
import java.util.Map;
/**
- * <p>An Adapter to use any {@link IPad} as a {@link Transformer} in an
- * {@link Assembly}.</p>
- *
- * <p>When using such a {@link Transformer}, in an {@link Assembly}, there must
+ * An Adapter to use any {@link IPad} as a {@link Transformer} in an
+ * {@link Assembly}.
+ * <p>
+ * When using such a {@link Transformer}, in an {@link Assembly}, there must
* be at least one element behind this instance in the constructed chain;
- * otherwise, a {@link TransformerException} is thrown at initialisation time.</p>
+ * otherwise, a {@link TransformerException} is thrown at initialisation time.
*/
-class PaddingTransformer extends Transformer
+class PaddingTransformer
+ extends Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private IPad delegate;
private int outputBlockSize = 1;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
PaddingTransformer(IPad padding)
{
super();
@@ -71,20 +65,13 @@ class PaddingTransformer extends Transformer
this.delegate = padding;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
void initDelegate(Map attributes) throws TransformerException
{
if (tail == null)
{
- throw new TransformerException(
- "initDelegate()",
- new IllegalStateException(
- "Padding transformer missing its tail!"));
+ IllegalStateException cause = new IllegalStateException(
+ "Padding transformer missing its tail!");
+ throw new TransformerException("initDelegate()", cause);
}
outputBlockSize = tail.currentBlockSize();
delegate.init(outputBlockSize);
@@ -108,9 +95,10 @@ class PaddingTransformer extends Transformer
byte[] tmp = inBuffer.toByteArray();
inBuffer.reset();
byte[] result;
- if (wired == Direction.FORWARD)
- { // padding
- // buffers remaining bytes from (inBuffer + in) that are less than 1 block
+ if (wired == Direction.FORWARD) // padding
+ {
+ // buffers remaining bytes from (inBuffer + in) that are less than 1
+ // block
if (tmp.length < outputBlockSize)
{
inBuffer.write(tmp, 0, tmp.length);
@@ -124,8 +112,8 @@ class PaddingTransformer extends Transformer
System.arraycopy(tmp, 0, result, 0, newlen);
}
}
- else
- { // unpadding
+ else // unpadding
+ {
// always keep in own buffer a max of 1 block to cater for lastUpdate
if (tmp.length < outputBlockSize)
{
@@ -147,14 +135,14 @@ class PaddingTransformer extends Transformer
byte[] result;
// process multiples of blocksize as much as possible
// catenate result from processing inBuffer with last-update( tail )
- if (wired == Direction.FORWARD)
- { // padding
+ if (wired == Direction.FORWARD) // padding
+ {
result = inBuffer.toByteArray();
byte[] padding = delegate.pad(result, 0, result.length);
inBuffer.write(padding, 0, padding.length);
}
- else
- { // unpadding
+ else // unpadding
+ {
byte[] tmp = inBuffer.toByteArray();
inBuffer.reset();
int realLength;
diff --git a/gnu/javax/crypto/assembly/Stage.java b/gnu/javax/crypto/assembly/Stage.java
index 23d50bb82..d023f6283 100644
--- a/gnu/javax/crypto/assembly/Stage.java
+++ b/gnu/javax/crypto/assembly/Stage.java
@@ -45,59 +45,56 @@ import java.util.Map;
import java.util.Set;
/**
- * <p>A <i>Stage</i> in a Cascade Cipher.</p>
- *
- * <p>Each stage may be either an implementation of a Block Cipher Mode of
- * Operation ({@link IMode}) or another Cascade Cipher ({@link Cascade}). Each
- * stage has also a <i>natural</i> operational direction when constructed for
- * inclusion within a {@link Cascade}. This <i>natural</i> direction dictates
- * how data flows from one stage into another when stages are chained together
- * in a cascade. One can think of a stage and its natural direction as the
- * specification of how to wire the stage into the chain. The following diagrams
- * may help understand the paradigme. The first shows two stages chained each
- * with a {@link Direction#FORWARD} direction.</p>
+ * A <i>Stage</i> in a Cascade Cipher.
+ * <p>
+ * Each stage may be either an implementation of a Block Cipher Mode of
+ * Operation ({@link IMode}) or another Cascade Cipher ({@link Cascade}).
+ * Each stage has also a <i>natural</i> operational direction when constructed
+ * for inclusion within a {@link Cascade}. This <i>natural</i> direction
+ * dictates how data flows from one stage into another when stages are chained
+ * together in a cascade. One can think of a stage and its natural direction as
+ * the specification of how to wire the stage into the chain. The following
+ * diagrams may help understand the paradigme. The first shows two stages
+ * chained each with a {@link Direction#FORWARD} direction.
+ *
* <pre>
- * FORWARD FORWARD
- * +------+ +-------+
- * | | | |
- * | +--in --+ | +--in --+
- * ---+ | Stage | | | Stage | +---
- * +--out--+ | +--out--+ |
- * | | | |
- * +-------+ +------+
+ * FORWARD FORWARD
+ * +------+ +-------+
+ * | | | |
+ * | +--in --+ | +--in --+
+ * ---+ | Stage | | | Stage | +---
+ * +--out--+ | +--out--+ |
+ * | | | |
+ * +-------+ +------+
* </pre>
- * <p>The second diagram shows two stages, one in a {@link Direction#FORWARD}
+ *
+ * <p>
+ * The second diagram shows two stages, one in a {@link Direction#FORWARD}
* direction, while the other is wired in a {@link Direction#REVERSED}
- * direction.</p>
+ * direction.
+ *
* <pre>
- * FORWARD REVERSED
- * +------+ +------+
- * | | | |
- * | +--in --+ +--in --+ |
- * ---+ | Stage | | Stage | +---
- * +--out--+ +--out--+
- * | |
- * +---------------+
+ * FORWARD REVERSED
+ * +------+ +------+
+ * | | | |
+ * | +--in --+ +--in --+ |
+ * ---+ | Stage | | Stage | +---
+ * +--out--+ +--out--+
+ * | |
+ * +---------------+
* </pre>
- *
+ *
* @see ModeStage
* @see CascadeStage
*/
public abstract class Stage
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String DIRECTION = "gnu.crypto.assembly.stage.direction";
protected Direction forward;
protected Direction wired;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
protected Stage(Direction forwardDirection)
{
super();
@@ -106,9 +103,6 @@ public abstract class Stage
this.wired = null;
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static final Stage getInstance(IMode mode, Direction forwardDirection)
{
return new ModeStage(mode, forwardDirection);
@@ -120,32 +114,27 @@ public abstract class Stage
return new CascadeStage(cascade, forwardDirection);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Returns the {@link Set} of supported block sizes for this
* <code>Stage</code>. Each element in the returned {@link Set} is an
* instance of {@link Integer}.
- *
+ *
* @return a {@link Set} of supported block sizes.
*/
public abstract Set blockSizes();
/**
* Initialises the stage for operation with specific characteristics.
- *
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @throws IllegalStateException if the instance is already initialised.
* @throws InvalidKeyException if the key data is invalid.
*/
public void init(Map attributes) throws InvalidKeyException
{
if (wired != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == null)
{
@@ -158,7 +147,7 @@ public abstract class Stage
/**
* Returns the currently set block size for the stage.
- *
+ *
* @return the current block size for this stage.
* @throws IllegalStateException if the instance is not initialised.
*/
@@ -178,10 +167,10 @@ public abstract class Stage
* Processes exactly one block of <i>plaintext</i> (if initialised in the
* {@link Direction#FORWARD} state) or <i>ciphertext</i> (if initialised in
* the {@link Direction#REVERSED} state).
- *
+ *
* @param in the plaintext.
* @param inOffset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param out the ciphertext.
* @param outOffset index of <code>out</code> from which to store result.
* @throws IllegalStateException if the instance is not initialised.
@@ -189,9 +178,7 @@ public abstract class Stage
public void update(byte[] in, int inOffset, byte[] out, int outOffset)
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
updateDelegate(in, inOffset, out, outOffset);
}
@@ -200,14 +187,12 @@ public abstract class Stage
* encryption / decryption test(s) for all supported block and key sizes of
* underlying block cipher(s) wrapped by Mode leafs. The test also includes
* one (1) variable key Known Answer Test (KAT) for each block cipher.
- *
+ *
* @return <code>true</code> if the implementation passes simple
- * <i>correctness</i> tests. Returns <code>false</code> otherwise.
+ * <i>correctness</i> tests. Returns <code>false</code> otherwise.
*/
public abstract boolean selfTest();
- // abstract methods to be implemented by concrete subclasses ---------------
-
abstract void initDelegate(Map attributes) throws InvalidKeyException;
abstract void resetDelegate();
diff --git a/gnu/javax/crypto/assembly/Transformer.java b/gnu/javax/crypto/assembly/Transformer.java
index 74a619af0..58a991b93 100644
--- a/gnu/javax/crypto/assembly/Transformer.java
+++ b/gnu/javax/crypto/assembly/Transformer.java
@@ -44,50 +44,44 @@ import java.io.ByteArrayOutputStream;
import java.util.Map;
/**
- * <p>A <code>Transformer</code> is an abstract representation of a two-way
+ * A <code>Transformer</code> is an abstract representation of a two-way
* <i>transformation</i> that can be chained together with other instances of
* this type. Examples of such transformations in this library are:
* {@link Cascade} cipher, {@link gnu.javax.crypto.pad.IPad} algorithm, and a
* ZLib-based deflater/inflater algorithm. A special implementation of a
- * <code>Transformer</code> to close a chain is also provided.</p>
- *
- * <p>A <code>Transformer</code> is characterised by the followings:<p>
+ * <code>Transformer</code> to close a chain is also provided.
+ * <p>
+ * A <code>Transformer</code> is characterised by the followings:
* <ul>
- * <li>It can be chained to other instances, to form an {@link Assembly}.</li>
- * <li>When configured in an {@link Assembly}, it can be set to apply its
- * internal transformation on the input data stream before (pre-processing)
- * or after (post-processing) passing the input data to the next element in
- * the chain. Note that the same type <code>Transformer</code> can be used as
- * either in pre-processing or a post-processing modes.</li>
- * <li>A special transformer --<code>LoopbackTransformer</code>-- is used to
- * close the chain.</li>
- * <li>A useful type of <code>Transformer</code> --one we're interested in--
- * has internal buffers. The distinction between a casual push (update)
- * operation and the last one allows to correctly flush any intermediate
- * bytes that may exist in those buffers.</li>
+ * <li>It can be chained to other instances, to form an {@link Assembly}.</li>
+ * <li>When configured in an {@link Assembly}, it can be set to apply its
+ * internal transformation on the input data stream before (pre-processing) or
+ * after (post-processing) passing the input data to the next element in the
+ * chain. Note that the same type <code>Transformer</code> can be used as
+ * either in pre-processing or a post-processing modes.</li>
+ * <li>A special transformer --<code>LoopbackTransformer</code>-- is used
+ * to close the chain.</li>
+ * <li>A useful type of <code>Transformer</code> --one we're interested in--
+ * has internal buffers. The distinction between a casual push (update)
+ * operation and the last one allows to correctly flush any intermediate bytes
+ * that may exist in those buffers.</li>
* </ul>
- *
- * <p>To allow wiring <code>Transformer</code> instances together, a
+ * <p>
+ * To allow wiring <code>Transformer</code> instances together, a
* <i>minimal-output-size</i> in bytes is necessary. The trivial case of a
* value of <code>1</code> for such attribute practically means that no output
* buffering, from the previous element, is needed --which is independant of
- * buffering the input if the <code>Transformer</code> implementation itself is
- * block-based.</p>
- *
+ * buffering the input if the <code>Transformer</code> implementation itself
+ * is block-based.
+ *
* @see CascadeTransformer
* @see PaddingTransformer
* @see DeflateTransformer
*/
public abstract class Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String DIRECTION = "gnu.crypto.assembly.transformer.direction";
- // public static final String MODE = "gnu.crypto.assembly.transformer.mode";
-
protected Direction wired;
protected Operation mode;
@@ -98,9 +92,6 @@ public abstract class Transformer
protected ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(2048);
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial protected constructor. */
protected Transformer()
{
@@ -109,9 +100,6 @@ public abstract class Transformer
this.wired = null;
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static final Transformer getCascadeTransformer(Cascade cascade)
{
return new CascadeTransformer(cascade);
@@ -127,81 +115,69 @@ public abstract class Transformer
return new DeflateTransformer();
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Sets the operational mode of this <code>Transformer</code>.
- *
+ *
* @param mode the processing mode this <code>Transformer</code> is required
- * to operate in.
- * @throws IllegalStateException if this instance has already been assigned
- * an operational mode.
+ * to operate in.
+ * @throws IllegalStateException if this instance has already been assigned an
+ * operational mode.
*/
public void setMode(final Operation mode)
{
if (this.mode != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
this.mode = mode;
}
/**
* Returns <code>true</code> if this <code>Transformer</code> was wired in
* pre-processing mode; <code>false</code> otherwise.
- *
- * @return <code>true</code> if this <code>Transformer</code> has been wired
- * in pre-processing mode; <code>false</code> otherwise.
- * @throws IllegalStateException if this instance has not yet been assigned
- * an operational <i>type</i>.
+ *
+ * @return <code>true</code> if this <code>Transformer</code> has been
+ * wired in pre-processing mode; <code>false</code> otherwise.
+ * @throws IllegalStateException if this instance has not yet been assigned an
+ * operational <i>type</i>.
*/
public boolean isPreProcessing()
{
if (mode == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return (mode == Operation.PRE_PROCESSING);
}
/**
* Returns <code>true</code> if this <code>Transformer</code> was wired in
* post-processing mode; <code>false</code> otherwise.
- *
- * @return <code>true</code> if this <code>Transformer</code> has been wired
- * in post-processing mode; <code>false</code> otherwise.
- * @throws IllegalStateException if this instance has not yet been assigned
- * an operational <i>type</i>.
+ *
+ * @return <code>true</code> if this <code>Transformer</code> has been
+ * wired in post-processing mode; <code>false</code> otherwise.
+ * @throws IllegalStateException if this instance has not yet been assigned an
+ * operational <i>type</i>.
*/
public boolean isPostProcessing()
{
- return !isPreProcessing();
+ return ! isPreProcessing();
}
/**
* Initialises the <code>Transformer</code> for operation with specific
* characteristics.
- *
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @throws IllegalStateException if the instance is already initialised.
*/
public void init(Map attributes) throws TransformerException
{
if (wired != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == null)
- {
- flow = Direction.FORWARD;
- }
+ flow = Direction.FORWARD;
wired = flow;
inBuffer.reset();
outBuffer.reset();
-
tail.init(attributes); // initialise tail first
initDelegate(attributes); // initialise this instance
}
@@ -209,15 +185,13 @@ public abstract class Transformer
/**
* Returns the block-size of this <code>Transformer</code>. A value of
* <code>1</code> indicates that this instance is block-agnostic.
- *
+ *
* @return the current minimal required block size.
*/
public int currentBlockSize()
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return delegateBlockSize();
}
@@ -238,12 +212,12 @@ public abstract class Transformer
* Convenience method that calls the method with same name and three
* arguments, using a byte array of length <code>1</code> whose contents are
* the designated byte.
- *
+ *
* @param b the byte to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #update(byte[], int, int)
*/
public byte[] update(byte b) throws TransformerException
@@ -253,14 +227,14 @@ public abstract class Transformer
/**
* Convenience method that calls the same method with three arguments. All
- * bytes in <code>in</code>, starting from index position <code>0</code> are
- * considered.
- *
+ * bytes in <code>in</code>, starting from index position <code>0</code>
+ * are considered.
+ *
* @param in the input data bytes.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #update(byte[], int, int)
*/
public byte[] update(byte[] in) throws TransformerException
@@ -270,48 +244,42 @@ public abstract class Transformer
/**
* Processes a designated number of bytes from a given byte array.
- *
+ *
* @param in the input data bytes.
* @param offset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param length the count of bytes to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
*/
public byte[] update(byte[] in, int offset, int length)
throws TransformerException
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
- byte[] result = (wired == Direction.FORWARD ? forwardUpdate(in, offset,
- length)
- : inverseUpdate(in, offset,
- length));
+ throw new IllegalStateException();
+ byte[] result = (wired == Direction.FORWARD ? forwardUpdate(in, offset, length)
+ : inverseUpdate(in, offset, length));
return result;
}
/**
* Convenience method that calls the same method with three arguments. A
* zero-long byte array is used.
- *
+ *
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate() throws TransformerException
{
byte[] result = (wired == Direction.FORWARD ? lastForwardUpdate()
- : lastInverseUpdate());
- if (inBuffer.size() != 0)
- { // we still have some buffered bytes
- throw new TransformerException("lastUpdate(): input buffer not empty");
- }
+ : lastInverseUpdate());
+ if (inBuffer.size() != 0) // we still have some buffered bytes
+ throw new TransformerException("lastUpdate(): input buffer not empty");
return result;
}
@@ -319,12 +287,12 @@ public abstract class Transformer
* Convenience method that calls the method with same name and three
* arguments, using a byte array of length <code>1</code> whose contents are
* the designated byte.
- *
+ *
* @param b the byte to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate(byte b) throws TransformerException
@@ -334,14 +302,14 @@ public abstract class Transformer
/**
* Convenience method that calls the same method with three arguments. All
- * bytes in <code>in</code>, starting from index position <code>0</code> are
- * considered.
- *
+ * bytes in <code>in</code>, starting from index position <code>0</code>
+ * are considered.
+ *
* @param in the input data bytes.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate(byte[] in) throws TransformerException
@@ -350,18 +318,18 @@ public abstract class Transformer
}
/**
- * Processes a designated number of bytes from a given byte array and
- * signals, at the same time, that this is the last <i>push</i> operation on
- * this <code>Transformer</code>.
- *
+ * Processes a designated number of bytes from a given byte array and signals,
+ * at the same time, that this is the last <i>push</i> operation on this
+ * <code>Transformer</code>.
+ *
* @param in the input data bytes.
* @param offset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param length the count of bytes to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
*/
public byte[] lastUpdate(byte[] in, int offset, int length)
throws TransformerException
@@ -378,22 +346,18 @@ public abstract class Transformer
return result;
}
- // helper methods ----------------------------------------------------------
-
private byte[] forwardUpdate(byte[] in, int off, int len)
throws TransformerException
{
- return (isPreProcessing() ? preTransform(in, off, len) : postTransform(in,
- off,
- len));
+ return (isPreProcessing() ? preTransform(in, off, len)
+ : postTransform(in, off, len));
}
private byte[] inverseUpdate(byte[] in, int off, int len)
throws TransformerException
{
- return (isPreProcessing() ? postTransform(in, off, len) : preTransform(in,
- off,
- len));
+ return (isPreProcessing() ? postTransform(in, off, len)
+ : preTransform(in, off, len));
}
private byte[] preTransform(byte[] in, int off, int len)
@@ -444,8 +408,6 @@ public abstract class Transformer
return result;
}
- // abstract methods to be implemented by concrete subclasses ---------------
-
abstract void initDelegate(Map attributes) throws TransformerException;
abstract int delegateBlockSize();
diff --git a/gnu/javax/crypto/assembly/TransformerException.java b/gnu/javax/crypto/assembly/TransformerException.java
index 412f0f0f1..2c972f858 100644
--- a/gnu/javax/crypto/assembly/TransformerException.java
+++ b/gnu/javax/crypto/assembly/TransformerException.java
@@ -43,17 +43,11 @@ import java.io.PrintWriter;
/**
*/
-public class TransformerException extends Exception
+public class TransformerException
+ extends Exception
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private Throwable _exception = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public TransformerException()
{
super();
@@ -78,12 +72,6 @@ public class TransformerException extends Exception
this._exception = cause;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instant methods
- // -------------------------------------------------------------------------
-
public Throwable getCause()
{
return _exception;
@@ -98,61 +86,53 @@ public class TransformerException extends Exception
{
super.printStackTrace();
if (_exception != null)
- {
- _exception.printStackTrace();
- }
+ _exception.printStackTrace();
}
/**
* Prints this exception's stack trace to a print stream. If this exception
- * has a root exception; the stack trace of the root exception is also
- * printed to the print stream.
- *
+ * has a root exception; the stack trace of the root exception is also printed
+ * to the print stream.
+ *
* @param ps the non-null print stream to which to print.
*/
public void printStackTrace(PrintStream ps)
{
super.printStackTrace(ps);
if (_exception != null)
- {
- _exception.printStackTrace(ps);
- }
+ _exception.printStackTrace(ps);
}
/**
* Prints this exception's stack trace to a print writer. If this exception
- * has a root exception; the stack trace of the root exception is also
- * printed to the print writer.
- *
+ * has a root exception; the stack trace of the root exception is also printed
+ * to the print writer.
+ *
* @param pw the non-null print writer to use for output.
*/
public void printStackTrace(PrintWriter pw)
{
super.printStackTrace(pw);
if (_exception != null)
- {
- _exception.printStackTrace(pw);
- }
+ _exception.printStackTrace(pw);
}
/**
* Returns the string representation of this exception. The string
- * representation contains this exception's class name, its detailed
- * messsage, and if it has a root exception, the string representation of the
- * root exception. This string representation is meant for debugging and not
- * meant to be interpreted programmatically.
- *
+ * representation contains this exception's class name, its detailed messsage,
+ * and if it has a root exception, the string representation of the root
+ * exception. This string representation is meant for debugging and not meant
+ * to be interpreted programmatically.
+ *
* @return the non-null string representation of this exception.
* @see Throwable#getMessage()
*/
public String toString()
{
- StringBuffer sb = new StringBuffer(this.getClass().getName()).append(": ").append(
- super.toString());
+ StringBuffer sb = new StringBuffer(this.getClass().getName())
+ .append(": ").append(super.toString());
if (_exception != null)
- {
- sb.append("; caused by: ").append(_exception.toString());
- }
+ sb.append("; caused by: ").append(_exception.toString());
return sb.toString();
}
}
diff --git a/gnu/javax/crypto/cipher/Anubis.java b/gnu/javax/crypto/cipher/Anubis.java
index ed55d23c2..653957ec6 100644
--- a/gnu/javax/crypto/cipher/Anubis.java
+++ b/gnu/javax/crypto/cipher/Anubis.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.cipher;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.Util;
@@ -49,85 +49,71 @@ import java.util.Iterator;
import java.util.logging.Logger;
/**
- * <p>Anubis is a 128-bit block cipher that accepts a variable-length key. The
+ * Anubis is a 128-bit block cipher that accepts a variable-length key. The
* cipher is a uniform substitution-permutation network whose inverse only
* differs from the forward operation in the key schedule. The design of both
* the round transformation and the key schedule is based upon the Wide Trail
- * strategy and permits a wide variety of implementation trade-offs.</p>
- *
- * <p>References:</p>
- *
+ * strategy and permits a wide variety of implementation trade-offs.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://planeta.terra.com.br/informatica/paulobarreto/AnubisPage.html">The
- * ANUBIS Block Cipher</a>.<br>
- * <a href="mailto:paulo.barreto@terra.com.br">Paulo S.L.M. Barreto</a> and
- * <a href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a>.</li>
+ * <li><a
+ * href="http://planeta.terra.com.br/informatica/paulobarreto/AnubisPage.html">The
+ * ANUBIS Block Cipher</a>.<br>
+ * <a href="mailto:paulo.barreto@terra.com.br">Paulo S.L.M. Barreto</a> and <a
+ * href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a>.</li>
* </ol>
*/
-public final class Anubis extends BaseCipher
+public final class Anubis
+ extends BaseCipher
{
private static final Logger log = Logger.getLogger(Anubis.class.getName());
private static final int DEFAULT_BLOCK_SIZE = 16; // in bytes
-
private static final int DEFAULT_KEY_SIZE = 16; // in bytes
-
private static final String Sd = // p. 25 [ANUBIS]
- "\uBA54\u2F74\u53D3\uD24D\u50AC\u8DBF\u7052\u9A4C"
- + "\uEAD5\u97D1\u3351\u5BA6\uDE48\uA899\uDB32\uB7FC"
- + "\uE39E\u919B\uE2BB\u416E\uA5CB\u6B95\uA1F3\uB102"
- + "\uCCC4\u1D14\uC363\uDA5D\u5FDC\u7DCD\u7F5A\u6C5C"
- + "\uF726\uFFED\uE89D\u6F8E\u19A0\uF089\u0F07\uAFFB"
- + "\u0815\u0D04\u0164\uDF76\u79DD\u3D16\u3F37\u6D38"
- + "\uB973\uE935\u5571\u7B8C\u7288\uF62A\u3E5E\u2746"
- + "\u0C65\u6861\u03C1\u57D6\uD958\uD866\uD73A\uC83C"
- + "\uFA96\uA798\uECB8\uC7AE\u694B\uABA9\u670A\u47F2"
- + "\uB522\uE5EE\uBE2B\u8112\u831B\u0E23\uF545\u21CE"
- + "\u492C\uF9E6\uB628\u1782\u1A8B\uFE8A\u09C9\u874E"
- + "\uE12E\uE4E0\uEB90\uA41E\u8560\u0025\uF4F1\u940B"
- + "\uE775\uEF34\u31D4\uD086\u7EAD\uFD29\u303B\u9FF8"
- + "\uC613\u0605\uC511\u777C\u7A78\u361C\u3959\u1856"
- + "\uB3B0\u2420\uB292\uA3C0\u4462\u10B4\u8443\u93C2"
- + "\u4ABD\u8F2D\uBC9C\u6A40\uCFA2\u804F\u1FCA\uAA42";
-
+ "\uBA54\u2F74\u53D3\uD24D\u50AC\u8DBF\u7052\u9A4C"
+ + "\uEAD5\u97D1\u3351\u5BA6\uDE48\uA899\uDB32\uB7FC"
+ + "\uE39E\u919B\uE2BB\u416E\uA5CB\u6B95\uA1F3\uB102"
+ + "\uCCC4\u1D14\uC363\uDA5D\u5FDC\u7DCD\u7F5A\u6C5C"
+ + "\uF726\uFFED\uE89D\u6F8E\u19A0\uF089\u0F07\uAFFB"
+ + "\u0815\u0D04\u0164\uDF76\u79DD\u3D16\u3F37\u6D38"
+ + "\uB973\uE935\u5571\u7B8C\u7288\uF62A\u3E5E\u2746"
+ + "\u0C65\u6861\u03C1\u57D6\uD958\uD866\uD73A\uC83C"
+ + "\uFA96\uA798\uECB8\uC7AE\u694B\uABA9\u670A\u47F2"
+ + "\uB522\uE5EE\uBE2B\u8112\u831B\u0E23\uF545\u21CE"
+ + "\u492C\uF9E6\uB628\u1782\u1A8B\uFE8A\u09C9\u874E"
+ + "\uE12E\uE4E0\uEB90\uA41E\u8560\u0025\uF4F1\u940B"
+ + "\uE775\uEF34\u31D4\uD086\u7EAD\uFD29\u303B\u9FF8"
+ + "\uC613\u0605\uC511\u777C\u7A78\u361C\u3959\u1856"
+ + "\uB3B0\u2420\uB292\uA3C0\u4462\u10B4\u8443\u93C2"
+ + "\u4ABD\u8F2D\uBC9C\u6A40\uCFA2\u804F\u1FCA\uAA42";
private static final byte[] S = new byte[256];
-
private static final int[] T0 = new int[256];
-
private static final int[] T1 = new int[256];
-
private static final int[] T2 = new int[256];
-
private static final int[] T3 = new int[256];
-
private static final int[] T4 = new int[256];
-
private static final int[] T5 = new int[256];
-
/**
* Anubis round constants. This is the largest possible considering that we
* always use R values, R = 8 + N, and 4 &lt;= N &lt;= 10.
*/
private static final int[] rc = new int[18];
-
/**
- * KAT vector (from ecb_vk):
- * I=83
+ * KAT vector (from ecb_vk): I=83
* KEY=000000000000000000002000000000000000000000000000
* CT=2E66AB15773F3D32FB6C697509460DF4
*/
- private static final byte[] KAT_KEY = Util.toBytesFromString("000000000000000000002000000000000000000000000000");
-
- private static final byte[] KAT_CT = Util.toBytesFromString("2E66AB15773F3D32FB6C697509460DF4");
-
+ private static final byte[] KAT_KEY =
+ Util.toBytesFromString("000000000000000000002000000000000000000000000000");
+ private static final byte[] KAT_CT =
+ Util.toBytesFromString("2E66AB15773F3D32FB6C697509460DF4");
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
- // Static code - to initialise lookup tables -------------------------------
-
static
{
long time = System.currentTimeMillis();
-
int ROOT = 0x11d; // para. 2.1 [ANUBIS]
int i, s, s2, s4, s6, s8, t;
char c;
@@ -136,44 +122,30 @@ public final class Anubis extends BaseCipher
c = Sd.charAt(i >>> 1);
s = ((i & 1) == 0 ? c >>> 8 : c) & 0xFF;
S[i] = (byte) s;
-
s2 = s << 1;
if (s2 > 0xFF)
- {
- s2 ^= ROOT;
- }
-
+ s2 ^= ROOT;
s4 = s2 << 1;
if (s4 > 0xFF)
- {
- s4 ^= ROOT;
- }
-
+ s4 ^= ROOT;
s6 = s4 ^ s2;
s8 = s4 << 1;
if (s8 > 0xFF)
- {
- s8 ^= ROOT;
- }
-
- T0[i] = s << 24 | s2 << 16 | s4 << 8 | s6;
- T1[i] = s2 << 24 | s << 16 | s6 << 8 | s4;
- T2[i] = s4 << 24 | s6 << 16 | s << 8 | s2;
+ s8 ^= ROOT;
+ T0[i] = s << 24 | s2 << 16 | s4 << 8 | s6;
+ T1[i] = s2 << 24 | s << 16 | s6 << 8 | s4;
+ T2[i] = s4 << 24 | s6 << 16 | s << 8 | s2;
T3[i] = s6 << 24 | s4 << 16 | s2 << 8 | s;
-
- T4[i] = s << 24 | s << 16 | s << 8 | s;
- T5[s] = s << 24 | s2 << 16 | s6 << 8 | s8;
+ T4[i] = s << 24 | s << 16 | s << 8 | s;
+ T5[s] = s << 24 | s2 << 16 | s6 << 8 | s8;
}
-
// compute round constant
for (i = 0, s = 0; i < 18;)
- {
- rc[i++] = S[(s++) & 0xFF] << 24 | (S[(s++) & 0xFF] & 0xFF) << 16
- | (S[(s++) & 0xFF] & 0xFF) << 8 | (S[(s++) & 0xFF] & 0xFF);
- }
-
+ rc[i++] = S[(s++) & 0xFF] << 24
+ | (S[(s++) & 0xFF] & 0xFF) << 16
+ | (S[(s++) & 0xFF] & 0xFF) << 8
+ | (S[(s++) & 0xFF] & 0xFF);
time = System.currentTimeMillis() - time;
-
if (Configuration.DEBUG)
{
log.fine("Static data");
@@ -233,47 +205,55 @@ public final class Anubis extends BaseCipher
}
}
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Anubis()
{
super(Registry.ANUBIS_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
private static void anubis(byte[] in, int i, byte[] out, int j, int[][] K)
{
// extract encryption round keys
int R = K.length - 1;
int[] Ker = K[0];
-
// mu function + affine key addition
- int a0 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Ker[0];
- int a1 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Ker[1];
- int a2 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Ker[2];
- int a3 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i] & 0xFF))
- ^ Ker[3];
-
+ int a0 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Ker[0];
+ int a1 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Ker[1];
+ int a2 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Ker[2];
+ int a3 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i] & 0xFF) ) ^ Ker[3];
int b0, b1, b2, b3;
// round function
for (int r = 1; r < R; r++)
{
Ker = K[r];
- b0 = T0[a0 >>> 24] ^ T1[a1 >>> 24] ^ T2[a2 >>> 24] ^ T3[a3 >>> 24]
- ^ Ker[0];
- b1 = T0[(a0 >>> 16) & 0xFF] ^ T1[(a1 >>> 16) & 0xFF]
- ^ T2[(a2 >>> 16) & 0xFF] ^ T3[(a3 >>> 16) & 0xFF] ^ Ker[1];
- b2 = T0[(a0 >>> 8) & 0xFF] ^ T1[(a1 >>> 8) & 0xFF]
- ^ T2[(a2 >>> 8) & 0xFF] ^ T3[(a3 >>> 8) & 0xFF] ^ Ker[2];
- b3 = T0[a0 & 0xFF] ^ T1[a1 & 0xFF] ^ T2[a2 & 0xFF] ^ T3[a3 & 0xFF]
- ^ Ker[3];
+ b0 = T0[ a0 >>> 24 ]
+ ^ T1[ a1 >>> 24 ]
+ ^ T2[ a2 >>> 24 ]
+ ^ T3[ a3 >>> 24 ] ^ Ker[0];
+ b1 = T0[(a0 >>> 16) & 0xFF]
+ ^ T1[(a1 >>> 16) & 0xFF]
+ ^ T2[(a2 >>> 16) & 0xFF]
+ ^ T3[(a3 >>> 16) & 0xFF] ^ Ker[1];
+ b2 = T0[(a0 >>> 8) & 0xFF]
+ ^ T1[(a1 >>> 8) & 0xFF]
+ ^ T2[(a2 >>> 8) & 0xFF]
+ ^ T3[(a3 >>> 8) & 0xFF] ^ Ker[2];
+ b3 = T0[ a0 & 0xFF]
+ ^ T1[ a1 & 0xFF]
+ ^ T2[ a2 & 0xFF]
+ ^ T3[ a3 & 0xFF] ^ Ker[3];
a0 = b0;
a1 = b1;
a2 = b2;
@@ -282,39 +262,32 @@ public final class Anubis extends BaseCipher
log.fine("T" + r + "=" + Util.toString(a0) + Util.toString(a1)
+ Util.toString(a2) + Util.toString(a3));
}
-
// last round function
Ker = K[R];
int tt = Ker[0];
- out[j++] = (byte) (S[a0 >>> 24] ^ (tt >>> 24));
- out[j++] = (byte) (S[a1 >>> 24] ^ (tt >>> 16));
- out[j++] = (byte) (S[a2 >>> 24] ^ (tt >>> 8));
- out[j++] = (byte) (S[a3 >>> 24] ^ tt);
+ out[j++] = (byte)(S[ a0 >>> 24 ] ^ (tt >>> 24));
+ out[j++] = (byte)(S[ a1 >>> 24 ] ^ (tt >>> 16));
+ out[j++] = (byte)(S[ a2 >>> 24 ] ^ (tt >>> 8));
+ out[j++] = (byte)(S[ a3 >>> 24 ] ^ tt);
tt = Ker[1];
- out[j++] = (byte) (S[(a0 >>> 16) & 0xFF] ^ (tt >>> 24));
- out[j++] = (byte) (S[(a1 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (S[(a2 >>> 16) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (S[(a3 >>> 16) & 0xFF] ^ tt);
+ out[j++] = (byte)(S[(a0 >>> 16) & 0xFF] ^ (tt >>> 24));
+ out[j++] = (byte)(S[(a1 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(S[(a2 >>> 16) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(S[(a3 >>> 16) & 0xFF] ^ tt);
tt = Ker[2];
- out[j++] = (byte) (S[(a0 >>> 8) & 0xFF] ^ (tt >>> 24));
- out[j++] = (byte) (S[(a1 >>> 8) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (S[(a2 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (S[(a3 >>> 8) & 0xFF] ^ tt);
+ out[j++] = (byte)(S[(a0 >>> 8) & 0xFF] ^ (tt >>> 24));
+ out[j++] = (byte)(S[(a1 >>> 8) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(S[(a2 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(S[(a3 >>> 8) & 0xFF] ^ tt);
tt = Ker[3];
- out[j++] = (byte) (S[a0 & 0xFF] ^ (tt >>> 24));
- out[j++] = (byte) (S[a1 & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (S[a2 & 0xFF] ^ (tt >>> 8));
- out[j] = (byte) (S[a3 & 0xFF] ^ tt);
-
+ out[j++] = (byte)(S[ a0 & 0xFF] ^ (tt >>> 24));
+ out[j++] = (byte)(S[ a1 & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(S[ a2 & 0xFF] ^ (tt >>> 8));
+ out[j ] = (byte)(S[ a3 & 0xFF] ^ tt);
if (Configuration.DEBUG)
log.fine("T=" + Util.toString(out, j - 15, 16) + "\n");
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.lang.Cloneable interface implementation ----------------------------
-
public Object clone()
{
Anubis result = new Anubis();
@@ -323,12 +296,10 @@ public final class Anubis extends BaseCipher
return result;
}
- // IBlockCipherSpi interface implementation --------------------------------
-
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(DEFAULT_BLOCK_SIZE));
+ al.add(Integer.valueOf(DEFAULT_BLOCK_SIZE));
return Collections.unmodifiableList(al).iterator();
}
@@ -337,17 +308,14 @@ public final class Anubis extends BaseCipher
{
ArrayList al = new ArrayList();
for (int n = 4; n < 10; n++)
- {
- al.add(new Integer(n * 32 / 8));
- }
-
+ al.add(Integer.valueOf(n * 32 / 8));
return Collections.unmodifiableList(al).iterator();
}
/**
- * <p>Expands a user-supplied key material into a session key for a
- * designated <i>block size</i>.</p>
- *
+ * Expands a user-supplied key material into a session key for a designated
+ * <i>block size</i>.
+ *
* @param uk the 32N-bit user-supplied key material; 4 &lt;= N &lt;= 10.
* @param bs the desired block size in bytes.
* @return an Object encapsulating the session key.
@@ -357,95 +325,91 @@ public final class Anubis extends BaseCipher
public Object makeKey(byte[] uk, int bs) throws InvalidKeyException
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
if (uk == null)
- {
- throw new InvalidKeyException("Empty key");
- }
+ throw new InvalidKeyException("Empty key");
if ((uk.length % 4) != 0)
- {
- throw new InvalidKeyException("Key is not multiple of 32-bit.");
- }
+ throw new InvalidKeyException("Key is not multiple of 32-bit.");
int N = uk.length / 4;
if (N < 4 || N > 10)
- {
- throw new InvalidKeyException("Key is not 32N; 4 <= N <= 10");
- }
+ throw new InvalidKeyException("Key is not 32N; 4 <= N <= 10");
int R = 8 + N;
int[][] Ke = new int[R + 1][4]; // encryption round keys
int[][] Kd = new int[R + 1][4]; // decryption round keys
int[] tk = new int[N];
int[] kk = new int[N];
int r, i, j, k, k0, k1, k2, k3, tt;
-
// apply mu to k0
for (r = 0, i = 0; r < N;)
- {
- tk[r++] = uk[i++] << 24 | (uk[i++] & 0xFF) << 16
- | (uk[i++] & 0xFF) << 8 | (uk[i++] & 0xFF);
- }
+ tk[r++] = uk[i++] << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i++] & 0xFF);
for (r = 0; r <= R; r++)
{
if (r > 0)
{
// psi = key evolution function
- kk[0] = T0[(tk[0] >>> 24)] ^ T1[(tk[N - 1] >>> 16) & 0xFF]
- ^ T2[(tk[N - 2] >>> 8) & 0xFF] ^ T3[tk[N - 3] & 0xFF];
- kk[1] = T0[(tk[1] >>> 24)] ^ T1[(tk[0] >>> 16) & 0xFF]
- ^ T2[(tk[N - 1] >>> 8) & 0xFF] ^ T3[tk[N - 2] & 0xFF];
- kk[2] = T0[(tk[2] >>> 24)] ^ T1[(tk[1] >>> 16) & 0xFF]
- ^ T2[(tk[0] >>> 8) & 0xFF] ^ T3[tk[N - 1] & 0xFF];
- kk[3] = T0[(tk[3] >>> 24)] ^ T1[(tk[2] >>> 16) & 0xFF]
- ^ T2[(tk[1] >>> 8) & 0xFF] ^ T3[tk[0] & 0xFF];
-
+ kk[0] = T0[(tk[0 ] >>> 24) ]
+ ^ T1[(tk[N - 1] >>> 16) & 0xFF]
+ ^ T2[(tk[N - 2] >>> 8) & 0xFF]
+ ^ T3[ tk[N - 3] & 0xFF];
+ kk[1] = T0[(tk[1 ] >>> 24) ]
+ ^ T1[(tk[0 ] >>> 16) & 0xFF]
+ ^ T2[(tk[N - 1] >>> 8) & 0xFF]
+ ^ T3[ tk[N - 2] & 0xFF];
+ kk[2] = T0[(tk[2 ] >>> 24) ]
+ ^ T1[(tk[1 ] >>> 16) & 0xFF]
+ ^ T2[(tk[0 ] >>> 8) & 0xFF]
+ ^ T3[ tk[N - 1] & 0xFF];
+ kk[3] = T0[(tk[3 ] >>> 24) ]
+ ^ T1[(tk[2 ] >>> 16) & 0xFF]
+ ^ T2[(tk[1 ] >>> 8) & 0xFF]
+ ^ T3[ tk[0 ] & 0xFF];
for (i = 4; i < N; i++)
- {
- kk[i] = T0[tk[i] >>> 24] ^ T1[(tk[i - 1] >>> 16) & 0xFF]
- ^ T2[(tk[i - 2] >>> 8) & 0xFF] ^ T3[tk[i - 3] & 0xFF];
- }
+ kk[i] = T0[ tk[i ] >>> 24 ]
+ ^ T1[(tk[i - 1] >>> 16) & 0xFF]
+ ^ T2[(tk[i - 2] >>> 8) & 0xFF]
+ ^ T3[ tk[i - 3] & 0xFF];
// apply sigma (affine addition) to round constant
tk[0] = rc[r - 1] ^ kk[0];
for (i = 1; i < N; i++)
- {
- tk[i] = kk[i];
- }
+ tk[i] = kk[i];
}
-
// phi = key selection function
tt = tk[N - 1];
- k0 = T4[tt >>> 24];
+ k0 = T4[ tt >>> 24 ];
k1 = T4[(tt >>> 16) & 0xFF];
- k2 = T4[(tt >>> 8) & 0xFF];
- k3 = T4[tt & 0xFF];
-
+ k2 = T4[(tt >>> 8) & 0xFF];
+ k3 = T4[ tt & 0xFF];
for (k = N - 2; k >= 0; k--)
{
tt = tk[k];
- k0 = T4[tt >>> 24] ^ (T5[(k0 >>> 24) & 0xFF] & 0xFF000000)
- ^ (T5[(k0 >>> 16) & 0xFF] & 0x00FF0000)
- ^ (T5[(k0 >>> 8) & 0xFF] & 0x0000FF00)
- ^ (T5[k0 & 0xFF] & 0x000000FF);
- k1 = T4[(tt >>> 16) & 0xFF] ^ (T5[(k1 >>> 24) & 0xFF] & 0xFF000000)
- ^ (T5[(k1 >>> 16) & 0xFF] & 0x00FF0000)
- ^ (T5[(k1 >>> 8) & 0xFF] & 0x0000FF00)
- ^ (T5[k1 & 0xFF] & 0x000000FF);
- k2 = T4[(tt >>> 8) & 0xFF] ^ (T5[(k2 >>> 24) & 0xFF] & 0xFF000000)
- ^ (T5[(k2 >>> 16) & 0xFF] & 0x00FF0000)
- ^ (T5[(k2 >>> 8) & 0xFF] & 0x0000FF00)
- ^ (T5[(k2) & 0xFF] & 0x000000FF);
- k3 = T4[tt & 0xFF] ^ (T5[(k3 >>> 24) & 0xFF] & 0xFF000000)
- ^ (T5[(k3 >>> 16) & 0xFF] & 0x00FF0000)
- ^ (T5[(k3 >>> 8) & 0xFF] & 0x0000FF00)
- ^ (T5[k3 & 0xFF] & 0x000000FF);
+ k0 = T4[ tt >>> 24 ]
+ ^ (T5[(k0 >>> 24) & 0xFF] & 0xFF000000)
+ ^ (T5[(k0 >>> 16) & 0xFF] & 0x00FF0000)
+ ^ (T5[(k0 >>> 8) & 0xFF] & 0x0000FF00)
+ ^ (T5 [k0 & 0xFF] & 0x000000FF);
+ k1 = T4[(tt >>> 16) & 0xFF]
+ ^ (T5[(k1 >>> 24) & 0xFF] & 0xFF000000)
+ ^ (T5[(k1 >>> 16) & 0xFF] & 0x00FF0000)
+ ^ (T5[(k1 >>> 8) & 0xFF] & 0x0000FF00)
+ ^ (T5[ k1 & 0xFF] & 0x000000FF);
+ k2 = T4[(tt >>> 8) & 0xFF]
+ ^ (T5[(k2 >>> 24) & 0xFF] & 0xFF000000)
+ ^ (T5[(k2 >>> 16) & 0xFF] & 0x00FF0000)
+ ^ (T5[(k2 >>> 8) & 0xFF] & 0x0000FF00)
+ ^ (T5[ k2 & 0xFF] & 0x000000FF);
+ k3 = T4[ tt & 0xFF]
+ ^ (T5[(k3 >>> 24) & 0xFF] & 0xFF000000)
+ ^ (T5[(k3 >>> 16) & 0xFF] & 0x00FF0000)
+ ^ (T5[(k3 >>> 8) & 0xFF] & 0x0000FF00)
+ ^ (T5[ k3 & 0xFF] & 0x000000FF);
}
-
Ke[r][0] = k0;
Ke[r][1] = k1;
Ke[r][2] = k2;
Ke[r][3] = k3;
-
if (r == 0 || r == R)
{
Kd[R - r][0] = k0;
@@ -455,25 +419,24 @@ public final class Anubis extends BaseCipher
}
else
{
- Kd[R - r][0] = T0[S[k0 >>> 24] & 0xFF]
- ^ T1[S[(k0 >>> 16) & 0xFF] & 0xFF]
- ^ T2[S[(k0 >>> 8) & 0xFF] & 0xFF]
- ^ T3[S[k0 & 0xFF] & 0xFF];
- Kd[R - r][1] = T0[S[k1 >>> 24] & 0xFF]
- ^ T1[S[(k1 >>> 16) & 0xFF] & 0xFF]
- ^ T2[S[(k1 >>> 8) & 0xFF] & 0xFF]
- ^ T3[S[k1 & 0xFF] & 0xFF];
- Kd[R - r][2] = T0[S[k2 >>> 24] & 0xFF]
- ^ T1[S[(k2 >>> 16) & 0xFF] & 0xFF]
- ^ T2[S[(k2 >>> 8) & 0xFF] & 0xFF]
- ^ T3[S[k2 & 0xFF] & 0xFF];
- Kd[R - r][3] = T0[S[k3 >>> 24] & 0xFF]
- ^ T1[S[(k3 >>> 16) & 0xFF] & 0xFF]
- ^ T2[S[(k3 >>> 8) & 0xFF] & 0xFF]
- ^ T3[S[k3 & 0xFF] & 0xFF];
+ Kd[R - r][0] = T0[S[ k0 >>> 24 ] & 0xFF]
+ ^ T1[S[(k0 >>> 16) & 0xFF] & 0xFF]
+ ^ T2[S[(k0 >>> 8) & 0xFF] & 0xFF]
+ ^ T3[S[ k0 & 0xFF] & 0xFF];
+ Kd[R - r][1] = T0[S[ k1 >>> 24 ] & 0xFF]
+ ^ T1[S[(k1 >>> 16) & 0xFF] & 0xFF]
+ ^ T2[S[(k1 >>> 8) & 0xFF] & 0xFF]
+ ^ T3[S[ k1 & 0xFF] & 0xFF];
+ Kd[R - r][2] = T0[S[ k2 >>> 24 ] & 0xFF]
+ ^ T1[S[(k2 >>> 16) & 0xFF] & 0xFF]
+ ^ T2[S[(k2 >>> 8) & 0xFF] & 0xFF]
+ ^ T3[S[ k2 & 0xFF] & 0xFF];
+ Kd[R - r][3] = T0[S[ k3 >>> 24 ] & 0xFF]
+ ^ T1[S[(k3 >>> 16) & 0xFF] & 0xFF]
+ ^ T2[S[(k3 >>> 8) & 0xFF] & 0xFF]
+ ^ T3[S[ k3 & 0xFF] & 0xFF];
}
}
-
if (Configuration.DEBUG)
{
log.fine("Key schedule");
@@ -495,29 +458,22 @@ public final class Anubis extends BaseCipher
log.fine(sb.toString());
}
}
-
return new Object[] { Ke, Kd };
}
public void encrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
-
- int[][] K = (int[][]) ((Object[]) k)[0];
+ throw new IllegalArgumentException();
+ int[][] K = (int[][])((Object[]) k)[0];
anubis(in, i, out, j, K);
}
public void decrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
-
- int[][] K = (int[][]) ((Object[]) k)[1];
+ throw new IllegalArgumentException();
+ int[][] K = (int[][])((Object[]) k)[1];
anubis(in, i, out, j, K);
}
@@ -527,11 +483,9 @@ public final class Anubis extends BaseCipher
{
boolean result = super.selfTest(); // do symmetry tests
if (result)
- {
- result = testKat(KAT_KEY, KAT_CT);
- }
+ result = testKat(KAT_KEY, KAT_CT);
valid = Boolean.valueOf(result);
}
return valid.booleanValue();
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/BaseCipher.java b/gnu/javax/crypto/cipher/BaseCipher.java
index db72e0f3a..a5bbe6987 100644
--- a/gnu/javax/crypto/cipher/BaseCipher.java
+++ b/gnu/javax/crypto/cipher/BaseCipher.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.cipher;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import java.security.InvalidKeyException;
import java.util.Arrays;
@@ -48,36 +48,29 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * <p>A basic abstract class to facilitate implementing symmetric key block
- * ciphers.</p>
+ * A basic abstract class to facilitate implementing symmetric key block
+ * ciphers.
*/
-public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
+public abstract class BaseCipher
+ implements IBlockCipher, IBlockCipherSpi
{
private static final Logger log = Logger.getLogger(BaseCipher.class.getName());
/** The canonical name prefix of the cipher. */
protected String name;
-
/** The default block size, in bytes. */
protected int defaultBlockSize;
-
/** The default key size, in bytes. */
protected int defaultKeySize;
-
/** The current block size, in bytes. */
protected int currentBlockSize;
-
/** The session key for this instance. */
protected transient Object currentKey;
-
/** The instance lock. */
protected Object lock = new Object();
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Trivial constructor for use by concrete subclasses.</p>
- *
+ * Trivial constructor for use by concrete subclasses.
+ *
* @param name the canonical name prefix of this instance.
* @param defaultBlockSize the default block size in bytes.
* @param defaultKeySize the default key size in bytes.
@@ -91,27 +84,15 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
this.defaultKeySize = defaultKeySize;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // IBlockCipher interface implementation -----------------------------------
-
public abstract Object clone();
public String name()
{
StringBuffer sb = new StringBuffer(name).append('-');
if (currentKey == null)
- {
- sb.append(String.valueOf(8 * defaultBlockSize));
- }
+ sb.append(String.valueOf(8 * defaultBlockSize));
else
- {
- sb.append(String.valueOf(8 * currentBlockSize));
- }
+ sb.append(String.valueOf(8 * currentBlockSize));
return sb.toString();
}
@@ -130,17 +111,13 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
synchronized (lock)
{
if (currentKey != null)
- {
- throw new IllegalStateException();
- }
-
+ throw new IllegalStateException();
Integer bs = (Integer) attributes.get(CIPHER_BLOCK_SIZE);
- if (bs == null)
- { // no block size was specified.
- if (currentBlockSize == 0)
- { // happy birthday
- currentBlockSize = defaultBlockSize;
- } // else it's a clone. use as is
+ if (bs == null) // no block size was specified
+ {
+ if (currentBlockSize == 0) // happy birthday
+ currentBlockSize = defaultBlockSize;
+ // else it's a clone. use as is
}
else
{
@@ -152,17 +129,11 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
{
ok = (currentBlockSize == ((Integer) it.next()).intValue());
if (ok)
- {
- break;
- }
- }
- if (!ok)
- {
- throw new IllegalArgumentException(
- IBlockCipher.CIPHER_BLOCK_SIZE);
+ break;
}
+ if (! ok)
+ throw new IllegalArgumentException(IBlockCipher.CIPHER_BLOCK_SIZE);
}
-
byte[] k = (byte[]) attributes.get(KEY_MATERIAL);
currentKey = makeKey(k, currentBlockSize);
}
@@ -171,9 +142,7 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
public int currentBlockSize()
{
if (currentKey == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return currentBlockSize;
}
@@ -181,7 +150,6 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
{
synchronized (lock)
{
- // currentBlockSize = 0;
currentKey = null;
}
}
@@ -192,10 +160,7 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
synchronized (lock)
{
if (currentKey == null)
- {
- throw new IllegalStateException();
- }
-
+ throw new IllegalStateException();
encrypt(in, inOffset, out, outOffset, currentKey, currentBlockSize);
}
}
@@ -206,10 +171,7 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
synchronized (lock)
{
if (currentKey == null)
- {
- throw new IllegalStateException();
- }
-
+ throw new IllegalStateException();
decrypt(in, inOffset, out, outOffset, currentKey, currentBlockSize);
}
}
@@ -218,25 +180,17 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
{
int ks;
Iterator bit;
-
// do symmetry tests for all block-size/key-size combos
for (Iterator kit = keySizes(); kit.hasNext();)
{
ks = ((Integer) kit.next()).intValue();
for (bit = blockSizes(); bit.hasNext();)
- {
- if (!testSymmetry(ks, ((Integer) bit.next()).intValue()))
- {
- return false;
- }
- }
+ if (! testSymmetry(ks, ((Integer) bit.next()).intValue()))
+ return false;
}
-
return true;
}
- // own methods -------------------------------------------------------------
-
private boolean testSymmetry(int ks, int bs)
{
try
@@ -247,20 +201,13 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
byte[] cpt = new byte[bs];
int i;
for (i = 0; i < ks; i++)
- {
- kb[i] = (byte) i;
- }
+ kb[i] = (byte) i;
for (i = 0; i < bs; i++)
- {
- pt[i] = (byte) i;
- }
-
+ pt[i] = (byte) i;
Object k = makeKey(kb, bs);
encrypt(pt, 0, ct, 0, k, bs);
decrypt(ct, 0, cpt, 0, k, bs);
-
return Arrays.equals(pt, cpt);
-
}
catch (Exception x)
{
@@ -281,19 +228,14 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
{
int bs = pt.length;
byte[] t = new byte[bs];
-
Object k = makeKey(kb, bs);
-
// test encryption
encrypt(pt, 0, t, 0, k, bs);
- if (!Arrays.equals(t, ct))
- {
- return false;
- }
+ if (! Arrays.equals(t, ct))
+ return false;
// test decryption
decrypt(t, 0, t, 0, k, bs);
return Arrays.equals(t, pt);
-
}
catch (Exception x)
{
@@ -302,4 +244,4 @@ public abstract class BaseCipher implements IBlockCipher, IBlockCipherSpi
return false;
}
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/Blowfish.java b/gnu/javax/crypto/cipher/Blowfish.java
index ca1fdfbd3..68722e913 100644
--- a/gnu/javax/crypto/cipher/Blowfish.java
+++ b/gnu/javax/crypto/cipher/Blowfish.java
@@ -51,370 +51,210 @@ import java.util.Collections;
import java.util.Iterator;
/**
- * Blowfish is a 16-round, 64-bit Feistel cipher designed by Bruce
- * Schneier. It accepts a variable-length key of up to 448 bits.
- *
- * <p>References:</p>
+ * Blowfish is a 16-round, 64-bit Feistel cipher designed by Bruce Schneier. It
+ * accepts a variable-length key of up to 448 bits.
+ * <p>
+ * References:
* <ol>
- * <li>Schneier, Bruce: <i>Applied Cryptography</i>, Second Edition,
- * 336--339, 647--654 (1996 Bruce Schneier).</li>
- * <li><a href="http://www.counterpane.com/blowfish.html">The
- * Blowfish Encryption Algorithm.</a></li>
+ * <li>Schneier, Bruce: <i>Applied Cryptography</i>, Second Edition, 336--339,
+ * 647--654 (1996 Bruce Schneier).</li>
+ * <li><a href="http://www.counterpane.com/blowfish.html">The Blowfish
+ * Encryption Algorithm.</a></li>
* </ol>
*/
-public class Blowfish extends BaseCipher
+public class Blowfish
+ extends BaseCipher
{
-
- // Constants and variables
- // -----------------------------------------------------------------
-
private static final int DEFAULT_BLOCK_SIZE = 8;
-
private static final int DEFAULT_KEY_SIZE = 8;
-
private static final int MAX_KEY_LENGTH = 56;
-
/** Initial value of the p-array. */
- private static final int[] P = { 0x243f6a88, 0x85a308d3, 0x13198a2e,
- 0x03707344, 0xa4093822, 0x299f31d0,
- 0x082efa98, 0xec4e6c89, 0x452821e6,
- 0x38d01377, 0xbe5466cf, 0x34e90c6c,
- 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5,
- 0xb5470917, 0x9216d5d9, 0x8979fb1b };
-
+ private static final int[] P = {
+ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
+ 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+ 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b };
/** Initial value of S-box 1. */
- static final int[] KS0 = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
- 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
- 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
- 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
- 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
- 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
- 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
- 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
- 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
- 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
- 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
- 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
- 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
- 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
- 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
- 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
- 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
- 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
- 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
- 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
- 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
- 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
- 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
- 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
- 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
- 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
- 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
- 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
- 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
- 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
- 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
- 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
- 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
- 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
- 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
- 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
- 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
- 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
- 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
- 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
- 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
- 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
- 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
- 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
- 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
- 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
- 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
- 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
- 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
- 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
- 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
- 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
- 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
- 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
- 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
- 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
- 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
- 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
- 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
- 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
- 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
- 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
- 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
- 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a };
-
+ static final int[] KS0 = {
+ 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96,
+ 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+ 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658,
+ 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+ 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e,
+ 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+ 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6,
+ 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+ 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c,
+ 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+ 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1,
+ 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+ 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a,
+ 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+ 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176,
+ 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+ 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706,
+ 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+ 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b,
+ 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+ 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c,
+ 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+ 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a,
+ 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+ 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760,
+ 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+ 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8,
+ 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+ 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33,
+ 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+ 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0,
+ 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+ 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777,
+ 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+ 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705,
+ 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+ 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e,
+ 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+ 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9,
+ 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+ 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f,
+ 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+ 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a };
/** Initial value of S-box 2. */
- private static final int[] KS1 = { 0x4b7a70e9, 0xb5b32944, 0xdb75092e,
- 0xc4192623, 0xad6ea6b0, 0x49a7df7d,
- 0x9cee60b8, 0x8fedb266, 0xecaa8c71,
- 0x699a17ff, 0x5664526c, 0xc2b19ee1,
- 0x193602a5, 0x75094c29, 0xa0591340,
- 0xe4183a3e, 0x3f54989a, 0x5b429d65,
- 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07,
- 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
- 0x4cdd2086, 0x8470eb26, 0x6382e9c6,
- 0x021ecc5e, 0x09686b3f, 0x3ebaefc9,
- 0x3c971814, 0x6b6a70a1, 0x687f3584,
- 0x52a0e286, 0xb79c5305, 0xaa500737,
- 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec,
- 0x5716f2b8, 0xb03ada37, 0xf0500c0d,
- 0xf01c1f04, 0x0200b3ff, 0xae0cf51a,
- 0x3cb574b2, 0x25837a58, 0xdc0921bd,
- 0xd19113f9, 0x7ca92ff6, 0x94324773,
- 0x22f54701, 0x3ae5e581, 0x37c2dadc,
- 0xc8b57634, 0x9af3dda7, 0xa9446146,
- 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
- 0xe238cd99, 0x3bea0e2f, 0x3280bba1,
- 0x183eb331, 0x4e548b38, 0x4f6db908,
- 0x6f420d03, 0xf60a04bf, 0x2cb81290,
- 0x24977c79, 0x5679b072, 0xbcaf89af,
- 0xde9a771f, 0xd9930810, 0xb38bae12,
- 0xdccf3f2e, 0x5512721f, 0x2e6b7124,
- 0x501adde6, 0x9f84cd87, 0x7a584718,
- 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
- 0xec7aec3a, 0xdb851dfa, 0x63094366,
- 0xc464c3d2, 0xef1c1847, 0x3215d908,
- 0xdd433b37, 0x24c2ba16, 0x12a14d43,
- 0x2a65c451, 0x50940002, 0x133ae4dd,
- 0x71dff89e, 0x10314e55, 0x81ac77d6,
- 0x5f11199b, 0x043556f1, 0xd7a3c76b,
- 0x3c11183b, 0x5924a509, 0xf28fe6ed,
- 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
- 0x86e34570, 0xeae96fb1, 0x860e5e0a,
- 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa,
- 0x2965dcb9, 0x99e71d0f, 0x803e89d6,
- 0x5266c825, 0x2e4cc978, 0x9c10b36a,
- 0xc6150eba, 0x94e2ea78, 0xa5fc3c53,
- 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d,
- 0x1939260f, 0x19c27960, 0x5223a708,
- 0xf71312b6, 0xebadfe6e, 0xeac31f66,
- 0xe3bc4595, 0xa67bc883, 0xb17f37d1,
- 0x018cff28, 0xc332ddef, 0xbe6c5aa5,
- 0x65582185, 0x68ab9802, 0xeecea50f,
- 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
- 0x1521b628, 0x29076170, 0xecdd4775,
- 0x619f1510, 0x13cca830, 0xeb61bd96,
- 0x0334fe1e, 0xaa0363cf, 0xb5735c90,
- 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
- 0xeecc86bc, 0x60622ca7, 0x9cab5cab,
- 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca,
- 0xa02369b9, 0x655abb50, 0x40685a32,
- 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
- 0x9b540b19, 0x875fa099, 0x95f7997e,
- 0x623d7da8, 0xf837889a, 0x97e32d77,
- 0x11ed935f, 0x16681281, 0x0e358829,
- 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
- 0x57f584a5, 0x1b227263, 0x9b83c3ff,
- 0x1ac24696, 0xcdb30aeb, 0x532e3054,
- 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef,
- 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
- 0x5d4a14d9, 0xe864b7e3, 0x42105d14,
- 0x203e13e0, 0x45eee2b6, 0xa3aaabea,
- 0xdb6c4f15, 0xfacb4fd0, 0xc742f442,
- 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
- 0xd81e799e, 0x86854dc7, 0xe44b476a,
- 0x3d816250, 0xcf62a1f2, 0x5b8d2646,
- 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3,
- 0x69cb7492, 0x47848a0b, 0x5692b285,
- 0x095bbf00, 0xad19489d, 0x1462b174,
- 0x23820e00, 0x58428d2a, 0x0c55f5ea,
- 0x1dadf43e, 0x233f7061, 0x3372f092,
- 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
- 0x7cde3759, 0xcbee7460, 0x4085f2a7,
- 0xce77326e, 0xa6078084, 0x19f8509e,
- 0xe8efd855, 0x61d99735, 0xa969a7aa,
- 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
- 0x9e447a2e, 0xc3453484, 0xfdd56705,
- 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd,
- 0x675fda79, 0xe3674340, 0xc5c43465,
- 0x713e38d8, 0x3d28f89e, 0xf16dff20,
- 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b,
- 0xdb83adf7 };
-
+ private static final int[] KS1 = {
+ 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d,
+ 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+ 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65,
+ 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+ 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9,
+ 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+ 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d,
+ 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+ 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc,
+ 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+ 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908,
+ 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+ 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124,
+ 0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+ 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908,
+ 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+ 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b,
+ 0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+ 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa,
+ 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+ 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d,
+ 0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+ 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5,
+ 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+ 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96,
+ 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+ 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca,
+ 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+ 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77,
+ 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+ 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054,
+ 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+ 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea,
+ 0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+ 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646,
+ 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+ 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea,
+ 0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+ 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e,
+ 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+ 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd,
+ 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+ 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 };
/** Initial value of S-box 3. */
- private static final int[] KS2 = { 0xe93d5a68, 0x948140f7, 0xf64c261c,
- 0x94692934, 0x411520f7, 0x7602d4f7,
- 0xbcf46b2e, 0xd4a20068, 0xd4082471,
- 0x3320f46a, 0x43b7d4b7, 0x500061af,
- 0x1e39f62e, 0x97244546, 0x14214f74,
- 0xbf8b8840, 0x4d95fc1d, 0x96b591af,
- 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec,
- 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
- 0x96eb27b3, 0x55fd3941, 0xda2547e6,
- 0xabca0a9a, 0x28507825, 0x530429f4,
- 0x0a2c86da, 0xe9b66dfb, 0x68dc1462,
- 0xd7486900, 0x680ec0a4, 0x27a18dee,
- 0x4f3ffea2, 0xe887ad8c, 0xb58ce006,
- 0x7af4d6b6, 0xaace1e7c, 0xd3375fec,
- 0xce78a399, 0x406b2a42, 0x20fe9e35,
- 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
- 0x1dc9faf7, 0x4b6d1856, 0x26a36631,
- 0xeae397b2, 0x3a6efa74, 0xdd5b4332,
- 0x6841e7f7, 0xca7820fb, 0xfb0af54e,
- 0xd8feb397, 0x454056ac, 0xba489527,
- 0x55533a3a, 0x20838d87, 0xfe6ba9b7,
- 0xd096954b, 0x55a867bc, 0xa1159a58,
- 0xcca92963, 0x99e1db33, 0xa62a4a56,
- 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
- 0xfdf8e802, 0x04272f70, 0x80bb155c,
- 0x05282ce3, 0x95c11548, 0xe4c66d22,
- 0x48c1133f, 0xc70f86dc, 0x07f9c9ee,
- 0x41041f0f, 0x404779a4, 0x5d886e17,
- 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f,
- 0x41113564, 0x257b7834, 0x602a9c60,
- 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2,
- 0x02e1329e, 0xaf664fd1, 0xcad18115,
- 0x6b2395e0, 0x333e92e1, 0x3b240b62,
- 0xeebeb922, 0x85b2a20e, 0xe6ba0d99,
- 0xde720c8c, 0x2da2f728, 0xd0127845,
- 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
- 0x5449a36f, 0x877d48fa, 0xc39dfd27,
- 0xf33e8d1e, 0x0a476341, 0x992eff74,
- 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60,
- 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
- 0xc67b5510, 0x6d672c37, 0x2765d43b,
- 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3,
- 0xb5390f92, 0x690fed0b, 0x667b9ffb,
- 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
- 0xbb132f88, 0x515bad24, 0x7b9479bf,
- 0x763bd6eb, 0x37392eb3, 0xcc115979,
- 0x8026e297, 0xf42e312d, 0x6842ada7,
- 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
- 0x6a124237, 0xb79251e7, 0x06a1bbe6,
- 0x4bfb6350, 0x1a6b1018, 0x11caedfa,
- 0x3d25bdd8, 0xe2e1c3c9, 0x44421659,
- 0x0a121386, 0xd90cec6e, 0xd5abea2a,
- 0x64af674e, 0xda86a85f, 0xbebfe988,
- 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086,
- 0x60787bf8, 0x6003604d, 0xd1fd8346,
- 0xf6381fb0, 0x7745ae04, 0xd736fccc,
- 0x83426b33, 0xf01eab71, 0xb0804187,
- 0x3c005e5f, 0x77a057be, 0xbde8ae24,
- 0x55464299, 0xbf582e61, 0x4e58f48f,
- 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
- 0x5366f9c3, 0xc8b38e74, 0xb475f255,
- 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84,
- 0x846a0e79, 0x915f95e2, 0x466e598e,
- 0x20b45770, 0x8cd55591, 0xc902de4c,
- 0xb90bace1, 0xbb8205d0, 0x11a86248,
- 0x7574a99e, 0xb77f19b6, 0xe0a9dc09,
- 0x662d09a1, 0xc4324633, 0xe85a1f02,
- 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
- 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f,
- 0x2868f169, 0xdcb7da83, 0x573906fe,
- 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01,
- 0xa70683fa, 0xa002b5c4, 0x0de6d027,
- 0x9af88c27, 0x773f8641, 0xc3604c06,
- 0x61a806b5, 0xf0177a28, 0xc0f586e0,
- 0x006058aa, 0x30dc7d62, 0x11e69ed7,
- 0x2338ea63, 0x53c2dd94, 0xc2c21634,
- 0xbbcbee56, 0x90bcb6de, 0xebfc7da1,
- 0xce591d76, 0x6f05e409, 0x4b7c0188,
- 0x39720a3d, 0x7c927c24, 0x86e3725f,
- 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
- 0xed545578, 0x08fca5b5, 0xd83d7cd3,
- 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8,
- 0xa28514d9, 0x6c51133c, 0x6fd5c7e7,
- 0x56e14ec4, 0x362abfce, 0xddc6c837,
- 0xd79a3234, 0x92638212, 0x670efa8e,
- 0x406000e0 };
-
+ private static final int[] KS2 = {
+ 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7,
+ 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+ 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af,
+ 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+ 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4,
+ 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+ 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec,
+ 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+ 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332,
+ 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+ 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58,
+ 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+ 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22,
+ 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+ 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60,
+ 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+ 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99,
+ 0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+ 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74,
+ 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+ 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3,
+ 0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+ 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979,
+ 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+ 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa,
+ 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+ 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086,
+ 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+ 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24,
+ 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+ 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84,
+ 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+ 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09,
+ 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+ 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe,
+ 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+ 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0,
+ 0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+ 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188,
+ 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+ 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8,
+ 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+ 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 };
/** Initial value of S-box 4. */
- private static final int[] KS3 = { 0x3a39ce37, 0xd3faf5cf, 0xabc27737,
- 0x5ac52d1b, 0x5cb0679e, 0x4fa33742,
- 0xd3822740, 0x99bc9bbe, 0xd5118e9d,
- 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
- 0xb78c1b6b, 0x21a19045, 0xb26eb1be,
- 0x6a366eb4, 0x5748ab2f, 0xbc946e79,
- 0xc6a376d2, 0x6549c2c8, 0x530ff8ee,
- 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
- 0x2939bbdb, 0xa9ba4650, 0xac9526e8,
- 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a,
- 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8,
- 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
- 0x83c061ba, 0x9be96a4d, 0x8fe51550,
- 0xba645bd6, 0x2826a2f9, 0xa73a3ae1,
- 0x4ba99586, 0xef5562e9, 0xc72fefd3,
- 0xf752f7da, 0x3f046f69, 0x77fa0a59,
- 0x80e4a915, 0x87b08601, 0x9b09e6ad,
- 0x3b3ee593, 0xe990fd5a, 0x9e34d797,
- 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a,
- 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
- 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472,
- 0x5a88f54c, 0xe029ac71, 0xe019a5e6,
- 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d,
- 0x283b57cc, 0xf8d56629, 0x79132e28,
- 0x785f0191, 0xed756055, 0xf7960e44,
- 0xe3d35e8c, 0x15056dd4, 0x88f46dba,
- 0x03a16125, 0x0564f0bd, 0xc3eb9e15,
- 0x3c9057a2, 0x97271aec, 0xa93a072a,
- 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb,
- 0x26dcf319, 0x7533d928, 0xb155fdf5,
- 0x03563482, 0x8aba3cbb, 0x28517711,
- 0xc20ad9f8, 0xabcc5167, 0xccad925f,
- 0x4de81751, 0x3830dc8e, 0x379d5862,
- 0x9320f991, 0xea7a90c2, 0xfb3e7bce,
- 0x5121ce64, 0x774fbe32, 0xa8b6e37e,
- 0xc3293d46, 0x48de5369, 0x6413e680,
- 0xa2ae0810, 0xdd6db224, 0x69852dfd,
- 0x09072166, 0xb39a460a, 0x6445c0dd,
- 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd,
- 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
- 0xdda26a7e, 0x3a59ff45, 0x3e350a44,
- 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb,
- 0x8d6612ae, 0xbf3c6f47, 0xd29be463,
- 0x542f5d9e, 0xaec2771b, 0xf64e6370,
- 0x740e0d8d, 0xe75b1357, 0xf8721671,
- 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc,
- 0x34d2466a, 0x0115af84, 0xe1b00428,
- 0x95983a1d, 0x06b89fb4, 0xce6ea048,
- 0x6f3f3b82, 0x3520ab82, 0x011a1d4b,
- 0x277227f8, 0x611560b1, 0xe7933fdc,
- 0xbb3a792b, 0x344525bd, 0xa08839e1,
- 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
- 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3,
- 0xa1e8aac7, 0x1a908749, 0xd44fbd9a,
- 0xd0dadecb, 0xd50ada38, 0x0339c32a,
- 0xc6913667, 0x8df9317c, 0xe0b12b4f,
- 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff,
- 0x27d9459c, 0xbf97222c, 0x15e6fc2a,
- 0x0f91fc71, 0x9b941525, 0xfae59361,
- 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
- 0xb6c1075e, 0xe3056a0c, 0x10d25065,
- 0xcb03a442, 0xe0ec6e0e, 0x1698db3b,
- 0x4c98a0be, 0x3278e964, 0x9f1f9532,
- 0xe0d392df, 0xd3a0342b, 0x8971f21e,
- 0x1b0a7441, 0x4ba3348c, 0xc5be7120,
- 0xc37632d8, 0xdf359f8d, 0x9b992f2e,
- 0xe60b6f47, 0x0fe3f11d, 0xe54cda54,
- 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
- 0x1618b166, 0xfd2c1d05, 0x848fd2c5,
- 0xf6fb2299, 0xf523f357, 0xa6327623,
- 0x93a83531, 0x56cccd02, 0xacf08162,
- 0x5a75ebb5, 0x6e163697, 0x88d273cc,
- 0xde966292, 0x81b949d0, 0x4c50901b,
- 0x71c65614, 0xe6c6c7bd, 0x327a140a,
- 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd,
- 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
- 0x71126905, 0xb2040222, 0xb6cbcf7c,
- 0xcd769c2b, 0x53113ec0, 0x1640e3d3,
- 0x38abbd60, 0x2547adf0, 0xba38209c,
- 0xf746ce76, 0x77afa1c5, 0x20756060,
- 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0,
- 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c,
- 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869,
- 0xa65cdea0, 0x3f09252d, 0xc208e69f,
- 0xb74e6132, 0xce77e25b, 0x578fdfe3,
- 0x3ac372e6 };
-
+ private static final int[] KS3 = {
+ 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742,
+ 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+ 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79,
+ 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+ 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a,
+ 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+ 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1,
+ 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+ 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797,
+ 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+ 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6,
+ 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+ 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba,
+ 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+ 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5,
+ 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+ 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce,
+ 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+ 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd,
+ 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+ 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb,
+ 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+ 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc,
+ 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+ 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc,
+ 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+ 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a,
+ 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+ 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a,
+ 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+ 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b,
+ 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+ 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e,
+ 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+ 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623,
+ 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+ 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a,
+ 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+ 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3,
+ 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+ 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c,
+ 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+ 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 };
/** Cache of the self test. */
private static Boolean valid;
-
/**
* Test vector, as published in
* href="http://www.counterpane.com/vectors.txt">http://www.counterpane.com/vectors.txt</a>.
@@ -424,20 +264,13 @@ public class Blowfish extends BaseCipher
* CT=4EF997456198DD78
*/
private static final byte[] TV_KEY = Util.toBytesFromString("0000000000000000");
-
private static final byte[] TV_CT = Util.toBytesFromString("4EF997456198DD78");
- // Constructors
- // -----------------------------------------------------------------------
-
public Blowfish()
{
super(Registry.BLOWFISH_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
}
- // Clonable interface implementation.
- // -----------------------------------------------------------------------
-
public Object clone()
{
Blowfish result = new Blowfish();
@@ -445,36 +278,14 @@ public class Blowfish extends BaseCipher
return result;
}
- // Implementations of abstract methods from BaseCipher
- // -----------------------------------------------------------------------
-
public Iterator keySizes()
{
return new Sequence(8, MAX_KEY_LENGTH, 8).iterator();
- // return new Iterator() {
- // private int i = 0;
-
- // public boolean hasNext() {
- // return i <= MAX_KEY_LENGTH-8;
- // }
-
- // public Object next() {
- // if (hasNext()) {
- // i += 8;
- // return new Integer(i);
- // }
- // return null;
- // }
-
- // public void remove() {
- // throw new UnsupportedOperationException();
- // }
- // };
}
public Iterator blockSizes()
{
- return Collections.singleton(new Integer(DEFAULT_BLOCK_SIZE)).iterator();
+ return Collections.singleton(Integer.valueOf(DEFAULT_BLOCK_SIZE)).iterator();
}
public Object makeKey(byte[] k, int bs)
@@ -485,7 +296,6 @@ public class Blowfish extends BaseCipher
System.arraycopy(KS1, 0, ctx.s1, 0, KS1.length);
System.arraycopy(KS2, 0, ctx.s2, 0, KS2.length);
System.arraycopy(KS3, 0, ctx.s3, 0, KS3.length);
-
// XOR the key with the P-box
int l = 0;
for (int i = 0; i < ctx.p.length; i++)
@@ -495,13 +305,10 @@ public class Blowfish extends BaseCipher
{
data = (data << 8) | (k[l++] & 0xff);
if (l >= k.length)
- {
- l = 0;
- }
+ l = 0;
}
ctx.p[i] ^= data;
}
-
// We swap the left and right words here only, so we can avoid
// swapping altogether during encryption/decryption.
int t;
@@ -559,18 +366,22 @@ public class Blowfish extends BaseCipher
public void encrypt(byte[] in, int i, byte[] out, int o, Object k, int bs)
{
Block x = new Block();
- x.left = (in[i] & 0xff) << 24 | (in[i + 1] & 0xff) << 16
- | (in[i + 2] & 0xff) << 8 | (in[i + 3] & 0xff);
- x.right = (in[i + 4] & 0xff) << 24 | (in[i + 5] & 0xff) << 16
- | (in[i + 6] & 0xff) << 8 | (in[i + 7] & 0xff);
+ x.left = (in[i ] & 0xff) << 24
+ | (in[i + 1] & 0xff) << 16
+ | (in[i + 2] & 0xff) << 8
+ | (in[i + 3] & 0xff);
+ x.right = (in[i + 4] & 0xff) << 24
+ | (in[i + 5] & 0xff) << 16
+ | (in[i + 6] & 0xff) << 8
+ | (in[i + 7] & 0xff);
blowfishEncrypt(x, (Context) k);
- out[o] = (byte) (x.right >>> 24);
- out[o + 1] = (byte) (x.right >>> 16);
- out[o + 2] = (byte) (x.right >>> 8);
+ out[o ] = (byte)(x.right >>> 24);
+ out[o + 1] = (byte)(x.right >>> 16);
+ out[o + 2] = (byte)(x.right >>> 8);
out[o + 3] = (byte) x.right;
- out[o + 4] = (byte) (x.left >>> 24);
- out[o + 5] = (byte) (x.left >>> 16);
- out[o + 6] = (byte) (x.left >>> 8);
+ out[o + 4] = (byte)(x.left >>> 24);
+ out[o + 5] = (byte)(x.left >>> 16);
+ out[o + 6] = (byte)(x.left >>> 8);
out[o + 7] = (byte) x.left;
x.left = x.right = 0;
}
@@ -578,63 +389,96 @@ public class Blowfish extends BaseCipher
public void decrypt(byte[] in, int i, byte[] out, int o, Object k, int bs)
{
Block x = new Block();
- x.left = (in[i] & 0xff) << 24 | (in[i + 1] & 0xff) << 16
- | (in[i + 2] & 0xff) << 8 | (in[i + 3] & 0xff);
- x.right = (in[i + 4] & 0xff) << 24 | (in[i + 5] & 0xff) << 16
- | (in[i + 6] & 0xff) << 8 | (in[i + 7] & 0xff);
+ x.left = (in[i ] & 0xff) << 24
+ | (in[i + 1] & 0xff) << 16
+ | (in[i + 2] & 0xff) << 8
+ | (in[i + 3] & 0xff);
+ x.right = (in[i + 4] & 0xff) << 24
+ | (in[i + 5] & 0xff) << 16
+ | (in[i + 6] & 0xff) << 8
+ | (in[i + 7] & 0xff);
blowfishDecrypt(x, (Context) k);
- out[o] = (byte) (x.right >>> 24);
- out[o + 1] = (byte) (x.right >>> 16);
- out[o + 2] = (byte) (x.right >>> 8);
+ out[o ] = (byte)(x.right >>> 24);
+ out[o + 1] = (byte)(x.right >>> 16);
+ out[o + 2] = (byte)(x.right >>> 8);
out[o + 3] = (byte) x.right;
- out[o + 4] = (byte) (x.left >>> 24);
- out[o + 5] = (byte) (x.left >>> 16);
- out[o + 6] = (byte) (x.left >>> 8);
+ out[o + 4] = (byte)(x.left >>> 24);
+ out[o + 5] = (byte)(x.left >>> 16);
+ out[o + 6] = (byte)(x.left >>> 8);
out[o + 7] = (byte) x.left;
x.left = x.right = 0;
}
- // Own methods
- // -----------------------------------------------------------------
-
/** Encrypt a single pair of 32-bit integers. */
private void blowfishEncrypt(Block x, Context ctx)
{
int[] p = ctx.p;
int[] s0 = ctx.s0, s1 = ctx.s1, s2 = ctx.s2, s3 = ctx.s3;
x.left ^= p[0];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[1];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[2];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[3];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[4];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[5];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[6];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[7];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[8];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[9];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[10];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[11];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[12];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[13];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[14];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[15];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[16];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[1];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[2];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[3];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[4];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[5];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[6];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[7];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[8];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[9];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[10];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[11];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[12];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[13];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[14];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[15];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[16];
x.right ^= p[17];
}
@@ -644,38 +488,70 @@ public class Blowfish extends BaseCipher
int[] p = ctx.p;
int[] s0 = ctx.s0, s1 = ctx.s1, s2 = ctx.s2, s3 = ctx.s3;
x.left ^= p[17];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[16];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[15];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[14];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[13];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[12];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[11];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[10];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[9];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[8];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[7];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[6];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[5];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[4];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[3];
- x.right ^= ((s0[x.left >>> 24] + s1[x.left >>> 16 & 0xff]) ^ s2[x.left >>> 8 & 0xff])
- + s3[x.left & 0xff] ^ p[2];
- x.left ^= ((s0[x.right >>> 24] + s1[x.right >>> 16 & 0xff]) ^ s2[x.right >>> 8 & 0xff])
- + s3[x.right & 0xff] ^ p[1];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[16];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[15];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[14];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[13];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[12];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[11];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[10];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[9];
+ x.right ^= ((s0[x.left >>> 24]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[8];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[7];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[6];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[5];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[4];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[3];
+ x.right ^= ((s0[x.left >>> 24 ]
+ + s1[x.left >>> 16 & 0xff])
+ ^ s2[x.left >>> 8 & 0xff])
+ + s3[x.left & 0xff] ^ p[2];
+ x.left ^= ((s0[x.right >>> 24 ]
+ + s1[x.right >>> 16 & 0xff])
+ ^ s2[x.right >>> 8 & 0xff])
+ + s3[x.right & 0xff] ^ p[1];
x.right ^= p[0];
}
@@ -685,30 +561,19 @@ public class Blowfish extends BaseCipher
{
boolean result = super.selfTest(); // symmetry
if (result)
- {
- result = testKat(TV_KEY, TV_CT);
- }
+ result = testKat(TV_KEY, TV_CT);
valid = Boolean.valueOf(result);
}
return valid.booleanValue();
}
- // Inner classes.
- // -----------------------------------------------------------------------
-
/** A simple wrapper for the P- and S-boxes. */
- private class Context implements Cloneable
+ private class Context
+ implements Cloneable
{
-
- // Constants and variables.
- // --------------------------------------------------------------------
-
/** The P-array. */
int[] p, s0, s1, s2, s3;
- // Constructors.
- // --------------------------------------------------------------------
-
/** Default 0-arguments constructor. */
Context()
{
@@ -733,9 +598,6 @@ public class Blowfish extends BaseCipher
this.s3 = (int[]) that.s3.clone();
}
- // Clonable interface implementation.
- // --------------------------------------------------------------------
-
public Object clone()
{
return new Context(this);
@@ -746,4 +608,4 @@ public class Blowfish extends BaseCipher
{
int left, right;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/Cast5.java b/gnu/javax/crypto/cipher/Cast5.java
index a0e0c60f3..a7521530c 100644
--- a/gnu/javax/crypto/cipher/Cast5.java
+++ b/gnu/javax/crypto/cipher/Cast5.java
@@ -47,12 +47,11 @@ import java.util.Collections;
import java.util.Iterator;
/**
- * <p>An implmenetation of the <code>CAST5</code> (a.k.a. CAST-128) algorithm,
- * as per <i>RFC-2144</i>, dated May 1997.</p>
- *
- * <p>In this RFC, <i>Carlisle Adams</i> (the CA in CAST, ST stands for
- * <i>Stafford Tavares</i>) describes CAST5 as:</p>
- *
+ * An implmenetation of the <code>CAST5</code> (a.k.a. CAST-128) algorithm,
+ * as per <i>RFC-2144</i>, dated May 1997.
+ * <p>
+ * In this RFC, <i>Carlisle Adams</i> (the CA in CAST, ST stands for
+ * <i>Stafford Tavares</i>) describes CAST5 as:
* <blockquote>
* "...a DES-like Substitution-Permutation Network (SPN) cryptosystem which
* appears to have good resistance to differential cryptanalysis, linear
@@ -61,19 +60,18 @@ import java.util.Iterator;
* Strict Avalanche Criterion (SAC), Bit Independence Criterion (BIC), no
* complementation property, and an absence of weak and semi-weak keys."
* </blockquote>
- *
- * <p><code>CAST5</code> is a symmetric block cipher with a block-size of 8
+ * <p>
+ * <code>CAST5</code> is a symmetric block cipher with a block-size of 8
* bytes and a variable key-size of up to 128 bits. Its authors, and their
* employer (Entrust Technologies, a Nortel majority-owned company), made it
* available worldwide on a royalty-free basis for commercial and non-commercial
- * uses.</p>
- *
- * <p>The <code>CAST5</code> encryption algorithm has been designed to allow a
+ * uses.
+ * <p>
+ * The <code>CAST5</code> encryption algorithm has been designed to allow a
* key size that can vary from <code>40</code> bits to <code>128</code> bits,
* in 8-bit increments (that is, the allowable key sizes are <code>40, 48, 56,
* 64, ..., 112, 120,</code> and <code>128</code> bits. For variable keysize
- * operation, the specification is as follows:</p>
- *
+ * operation, the specification is as follows:
* <ol>
* <li>For key sizes up to and including <code>80</code> bits (i.e.,
* <code>40, 48, 56, 64, 72,</code> and <code>80</code> bits), the algorithm
@@ -86,25 +84,19 @@ import java.util.Iterator;
* <code>128</code> bits (since the <code>CAST5</code> key schedule assumes
* an input key of <code>128</code> bits).</li>
* </ol>
- *
- * <p>References:</p>
- *
+ * <p>
+ * References:
* <ol>
* <li><a href="http://www.ietf.org/rfc/rfc2144.txt">The CAST-128 Encryption
* Algorithm</a>.<br>
* <a href="mailto:cadams@entrust.com">Carlisle Adams</a>.</li>
* </ol>
*/
-public class Cast5 extends BaseCipher
+public class Cast5
+ extends BaseCipher
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final int DEFAULT_BLOCK_SIZE = 8; // in bytes
-
private static final int DEFAULT_KEY_SIZE = 5; // in bytes
-
/**
* KAT vector (from rfc-2144):
* 40-bit key = 01 23 45 67 12
@@ -113,727 +105,372 @@ public class Cast5 extends BaseCipher
* ciphertext = 7A C8 16 D1 6E 9B 30 2E
*/
private static final byte[] KAT_KEY = Util.toBytesFromString("0123456712");
-
private static final byte[] KAT_PT = Util.toBytesFromString("0123456789ABCDEF");
-
private static final byte[] KAT_CT = Util.toBytesFromString("7AC816D16E9B302E");
-
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
-
// CAST5 S-boxes
- private static final int[] S1 = { 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F,
- 0x3F258C7A, 0x1E213F2F, 0x9C004DD3,
- 0x6003E540, 0xCF9FC949, 0xBFD4AF27,
- 0x88BBBDB5, 0xE2034090, 0x98D09675,
- 0x6E63A0E0, 0x15C361D2, 0xC2E7661D,
- 0x22D4FF8E, 0x28683B6F, 0xC07FD059,
- 0xFF2379C8, 0x775F50E2, 0x43C340D3,
- 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D,
- 0xA1C9E0D6, 0x346C4819, 0x61B76D87,
- 0x22540F2F, 0x2ABE32E1, 0xAA54166B,
- 0x22568E3A, 0xA2D341D0, 0x66DB40C8,
- 0xA784392F, 0x004DFF2F, 0x2DB9D2DE,
- 0x97943FAC, 0x4A97C1D8, 0x527644B7,
- 0xB5F437A7, 0xB82CBAEF, 0xD751D159,
- 0x6FF7F0ED, 0x5A097A1F, 0x827B68D0,
- 0x90ECF52E, 0x22B0C054, 0xBC8E5935,
- 0x4B6D2F7F, 0x50BB64A2, 0xD2664910,
- 0xBEE5812D, 0xB7332290, 0xE93B159F,
- 0xB48EE411, 0x4BFF345D, 0xFD45C240,
- 0xAD31973F, 0xC4F6D02E, 0x55FC8165,
- 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D,
- 0xC19B0C50, 0x882240F2, 0x0C6E4F38,
- 0xA4E4BFD7, 0x4F5BA272, 0x564C1D2F,
- 0xC59C5319, 0xB949E354, 0xB04669FE,
- 0xB1B6AB8A, 0xC71358DD, 0x6385C545,
- 0x110F935D, 0x57538AD5, 0x6A390493,
- 0xE63D37E0, 0x2A54F6B3, 0x3A787D5F,
- 0x6276A0B5, 0x19A6FCDF, 0x7A42206A,
- 0x29F9D4D5, 0xF61B1891, 0xBB72275E,
- 0xAA508167, 0x38901091, 0xC6B505EB,
- 0x84C7CB8C, 0x2AD75A0F, 0x874A1427,
- 0xA2D1936B, 0x2AD286AF, 0xAA56D291,
- 0xD7894360, 0x425C750D, 0x93B39E26,
- 0x187184C9, 0x6C00B32D, 0x73E2BB14,
- 0xA0BEBC3C, 0x54623779, 0x64459EAB,
- 0x3F328B82, 0x7718CF82, 0x59A2CEA6,
- 0x04EE002E, 0x89FE78E6, 0x3FAB0950,
- 0x325FF6C2, 0x81383F05, 0x6963C5C8,
- 0x76CB5AD6, 0xD49974C9, 0xCA180DCF,
- 0x380782D5, 0xC7FA5CF6, 0x8AC31511,
- 0x35E79E13, 0x47DA91D0, 0xF40F9086,
- 0xA7E2419E, 0x31366241, 0x051EF495,
- 0xAA573B04, 0x4A805D8D, 0x548300D0,
- 0x00322A3C, 0xBF64CDDF, 0xBA57A68E,
- 0x75C6372B, 0x50AFD341, 0xA7C13275,
- 0x915A0BF5, 0x6B54BFAB, 0x2B0B1426,
- 0xAB4CC9D7, 0x449CCD82, 0xF7FBF265,
- 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324,
- 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02,
- 0xC8BD25AC, 0xEADF55B3, 0xD5BD9E98,
- 0xE31231B2, 0x2AD5AD6C, 0x954329DE,
- 0xADBE4528, 0xD8710F69, 0xAA51C90F,
- 0xAA786BF6, 0x22513F1E, 0xAA51A79B,
- 0x2AD344CC, 0x7B5A41F0, 0xD37CFBAD,
- 0x1B069505, 0x41ECE491, 0xB4C332E6,
- 0x032268D4, 0xC9600ACC, 0xCE387E6D,
- 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9,
- 0xD4DF39DE, 0xE01063DA, 0x4736F464,
- 0x5AD328D8, 0xB347CC96, 0x75BB0FC3,
- 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A,
- 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10,
- 0xAC39570A, 0x3F04442F, 0x6188B153,
- 0xE0397A2E, 0x5727CB79, 0x9CEB418F,
- 0x1CACD68D, 0x2AD37C96, 0x0175CB9D,
- 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8,
- 0xEC0E7779, 0x4744EAD4, 0xB11C3274,
- 0xDD24CB9E, 0x7E1C54BD, 0xF01144F9,
- 0xD2240EB1, 0x9675B3FD, 0xA3AC3755,
- 0xD47C27AF, 0x51C85F4D, 0x56907596,
- 0xA5BB15E6, 0x580304F0, 0xCA042CF1,
- 0x011A37EA, 0x8DBFAADB, 0x35BA3E4A,
- 0x3526FFA0, 0xC37B4D09, 0xBC306ED9,
- 0x98A52666, 0x5648F725, 0xFF5E569D,
- 0x0CED63D0, 0x7C63B2CF, 0x700B45E1,
- 0xD5EA50F1, 0x85A92872, 0xAF1FBDA7,
- 0xD4234870, 0xA7870BF3, 0x2D3B4D79,
- 0x42E04198, 0x0CD0EDE7, 0x26470DB8,
- 0xF881814C, 0x474D6AD7, 0x7C0C5E5C,
- 0xD1231959, 0x381B7298, 0xF5D2F4DB,
- 0xAB838653, 0x6E2F1E23, 0x83719C9E,
- 0xBD91E046, 0x9A56456E, 0xDC39200C,
- 0x20C8C571, 0x962BDA1C, 0xE1E696FF,
- 0xB141AB08, 0x7CCA89B9, 0x1A69E783,
- 0x02CC4843, 0xA2F7C579, 0x429EF47D,
- 0x427B169C, 0x5AC9F049, 0xDD8F0F00,
- 0x5C8165BF };
-
- private static final int[] S2 = { 0x1F201094, 0xEF0BA75B, 0x69E3CF7E,
- 0x393F4380, 0xFE61CF7A, 0xEEC5207A,
- 0x55889C94, 0x72FC0651, 0xADA7EF79,
- 0x4E1D7235, 0xD55A63CE, 0xDE0436BA,
- 0x99C430EF, 0x5F0C0794, 0x18DCDB7D,
- 0xA1D6EFF3, 0xA0B52F7B, 0x59E83605,
- 0xEE15B094, 0xE9FFD909, 0xDC440086,
- 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB,
- 0xD1DA4181, 0x3B092AB1, 0xF997F1C1,
- 0xA5E6CF7B, 0x01420DDB, 0xE4E7EF5B,
- 0x25A1FF41, 0xE180F806, 0x1FC41080,
- 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4,
- 0x98DE8B7F, 0x77E83F4E, 0x79929269,
- 0x24FA9F7B, 0xE113C85B, 0xACC40083,
- 0xD7503525, 0xF7EA615F, 0x62143154,
- 0x0D554B63, 0x5D681121, 0xC866C359,
- 0x3D63CF73, 0xCEE234C0, 0xD4D87E87,
- 0x5C672B21, 0x071F6181, 0x39F7627F,
- 0x361E3084, 0xE4EB573B, 0x602F64A4,
- 0xD63ACD9C, 0x1BBC4635, 0x9E81032D,
- 0x2701F50C, 0x99847AB4, 0xA0E3DF79,
- 0xBA6CF38C, 0x10843094, 0x2537A95E,
- 0xF46F6FFE, 0xA1FF3B1F, 0x208CFB6A,
- 0x8F458C74, 0xD9E0A227, 0x4EC73A34,
- 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088,
- 0x3559648D, 0x8A45388C, 0x1D804366,
- 0x721D9BFD, 0xA58684BB, 0xE8256333,
- 0x844E8212, 0x128D8098, 0xFED33FB4,
- 0xCE280AE1, 0x27E19BA5, 0xD5A6C252,
- 0xE49754BD, 0xC5D655DD, 0xEB667064,
- 0x77840B4D, 0xA1B6A801, 0x84DB26A9,
- 0xE0B56714, 0x21F043B7, 0xE5D05860,
- 0x54F03084, 0x066FF472, 0xA31AA153,
- 0xDADC4755, 0xB5625DBF, 0x68561BE6,
- 0x83CA6B94, 0x2D6ED23B, 0xECCF01DB,
- 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709,
- 0x33B4A34C, 0x397BC8D6, 0x5EE22B95,
- 0x5F0E5304, 0x81ED6F61, 0x20E74364,
- 0xB45E1378, 0xDE18639B, 0x881CA122,
- 0xB96726D1, 0x8049A7E8, 0x22B7DA7B,
- 0x5E552D25, 0x5272D237, 0x79D2951C,
- 0xC60D894C, 0x488CB402, 0x1BA4FE5B,
- 0xA4B09F6B, 0x1CA815CF, 0xA20C3005,
- 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9,
- 0x0BEEFF53, 0xE3214517, 0xB4542835,
- 0x9F63293C, 0xEE41E729, 0x6E1D2D7C,
- 0x50045286, 0x1E6685F3, 0xF33401C6,
- 0x30A22C95, 0x31A70850, 0x60930F13,
- 0x73F98417, 0xA1269859, 0xEC645C44,
- 0x52C877A9, 0xCDFF33A6, 0xA02B1741,
- 0x7CBAD9A2, 0x2180036F, 0x50D99C08,
- 0xCB3F4861, 0xC26BD765, 0x64A3F6AB,
- 0x80342676, 0x25A75E7B, 0xE4E6D1FC,
- 0x20C710E6, 0xCDF0B680, 0x17844D3B,
- 0x31EEF84D, 0x7E0824E4, 0x2CCB49EB,
- 0x846A3BAE, 0x8FF77888, 0xEE5D60F6,
- 0x7AF75673, 0x2FDD5CDB, 0xA11631C1,
- 0x30F66F43, 0xB3FAEC54, 0x157FD7FA,
- 0xEF8579CC, 0xD152DE58, 0xDB2FFD5E,
- 0x8F32CE19, 0x306AF97A, 0x02F03EF8,
- 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0,
- 0xC68E4906, 0xB8DA230C, 0x80823028,
- 0xDCDEF3C8, 0xD35FB171, 0x088A1BC8,
- 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D,
- 0xC72FEFFA, 0x22822E99, 0x82C570B4,
- 0xD8D94E89, 0x8B1C34BC, 0x301E16E6,
- 0x273BE979, 0xB0FFEAA6, 0x61D9B8C6,
- 0x00B24869, 0xB7FFCE3F, 0x08DC283B,
- 0x43DAF65A, 0xF7E19798, 0x7619B72F,
- 0x8F1C9BA4, 0xDC8637A0, 0x16A7D3B1,
- 0x9FC393B7, 0xA7136EEB, 0xC6BCC63E,
- 0x1A513742, 0xEF6828BC, 0x520365D6,
- 0x2D6A77AB, 0x3527ED4B, 0x821FD216,
- 0x095C6E2E, 0xDB92F2FB, 0x5EEA29CB,
- 0x145892F5, 0x91584F7F, 0x5483697B,
- 0x2667A8CC, 0x85196048, 0x8C4BACEA,
- 0x833860D4, 0x0D23E0F9, 0x6C387E8A,
- 0x0AE6D249, 0xB284600C, 0xD835731D,
- 0xDCB1C647, 0xAC4C56EA, 0x3EBD81B3,
- 0x230EABB0, 0x6438BC87, 0xF0B5B1FA,
- 0x8F5EA2B3, 0xFC184642, 0x0A036B7A,
- 0x4FB089BD, 0x649DA589, 0xA345415E,
- 0x5C038323, 0x3E5D3BB9, 0x43D79572,
- 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF,
- 0x7160A539, 0x73BFBE70, 0x83877605,
- 0x4523ECF1 };
-
- private static final int[] S3 = { 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF,
- 0xE810C907, 0x47607FFF, 0x369FE44B,
- 0x8C1FC644, 0xAECECA90, 0xBEB1F9BF,
- 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE,
- 0x920E8806, 0xF0AD0548, 0xE13C8D83,
- 0x927010D5, 0x11107D9F, 0x07647DB9,
- 0xB2E3E4D4, 0x3D4F285E, 0xB9AFA820,
- 0xFADE82E0, 0xA067268B, 0x8272792E,
- 0x553FB2C0, 0x489AE22B, 0xD4EF9794,
- 0x125E3FBC, 0x21FFFCEE, 0x825B1BFD,
- 0x9255C5ED, 0x1257A240, 0x4E1A8302,
- 0xBAE07FFF, 0x528246E7, 0x8E57140E,
- 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8,
- 0xC982B5A5, 0xA8C01DB7, 0x579FC264,
- 0x67094F31, 0xF2BD3F5F, 0x40FFF7C1,
- 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B,
- 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6,
- 0x55819D99, 0xA197C81C, 0x4A012D6E,
- 0xC5884A28, 0xCCC36F71, 0xB843C213,
- 0x6C0743F1, 0x8309893C, 0x0FEDDD5F,
- 0x2F7FE850, 0xD7C07F7E, 0x02507FBF,
- 0x5AFB9A04, 0xA747D2D0, 0x1651192E,
- 0xAF70BF3E, 0x58C31380, 0x5F98302E,
- 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82,
- 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49,
- 0x50DA88B8, 0x8427F4A0, 0x1EAC5790,
- 0x796FB449, 0x8252DC15, 0xEFBD7D9B,
- 0xA672597D, 0xADA840D8, 0x45F54504,
- 0xFA5D7403, 0xE83EC305, 0x4F91751A,
- 0x925669C2, 0x23EFE941, 0xA903F12E,
- 0x60270DF2, 0x0276E4B6, 0x94FD6574,
- 0x927985B2, 0x8276DBCB, 0x02778176,
- 0xF8AF918D, 0x4E48F79E, 0x8F616DDF,
- 0xE29D840E, 0x842F7D83, 0x340CE5C8,
- 0x96BBB682, 0x93B4B148, 0xEF303CAB,
- 0x984FAF28, 0x779FAF9B, 0x92DC560D,
- 0x224D1E20, 0x8437AA88, 0x7D29DC96,
- 0x2756D3DC, 0x8B907CEE, 0xB51FD240,
- 0xE7C07CE3, 0xE566B4A1, 0xC3E9615E,
- 0x3CF8209D, 0x6094D1E3, 0xCD9CA341,
- 0x5C76460E, 0x00EA983B, 0xD4D67881,
- 0xFD47572C, 0xF76CEDD9, 0xBDA8229C,
- 0x127DADAA, 0x438A074E, 0x1F97C090,
- 0x081BDB8A, 0x93A07EBE, 0xB938CA15,
- 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC,
- 0x64380E51, 0x68CC7BFB, 0xD90F2788,
- 0x12490181, 0x5DE5FFD4, 0xDD7EF86A,
- 0x76A2E214, 0xB9A40368, 0x925D958F,
- 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B,
- 0xFAF7933B, 0x6D498623, 0x193CBCFA,
- 0x27627545, 0x825CF47A, 0x61BD8BA0,
- 0xD11E42D1, 0xCEAD04F4, 0x127EA392,
- 0x10428DB7, 0x8272A972, 0x9270C4A8,
- 0x127DE50B, 0x285BA1C8, 0x3C62F44F,
- 0x35C0EAA5, 0xE805D231, 0x428929FB,
- 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B,
- 0x1F081FAB, 0x108618AE, 0xFCFD086D,
- 0xF9FF2889, 0x694BCC11, 0x236A5CAE,
- 0x12DECA4D, 0x2C3F8CC5, 0xD2D02DFE,
- 0xF8EF5896, 0xE4CF52DA, 0x95155B67,
- 0x494A488C, 0xB9B6A80C, 0x5C8F82BC,
- 0x89D36B45, 0x3A609437, 0xEC00C9A9,
- 0x44715253, 0x0A874B49, 0xD773BC40,
- 0x7C34671C, 0x02717EF6, 0x4FEB5536,
- 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0,
- 0x50B4EF6D, 0x07478CD1, 0x006E1888,
- 0xA2E53F55, 0xB9E6D4BC, 0xA2048016,
- 0x97573833, 0xD7207D67, 0xDE0F8F3D,
- 0x72F87B33, 0xABCC4F33, 0x7688C55D,
- 0x7B00A6B0, 0x947B0001, 0x570075D2,
- 0xF9BB88F8, 0x8942019E, 0x4264A5FF,
- 0x856302E0, 0x72DBD92B, 0xEE971B69,
- 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D,
- 0xE5C98767, 0xCF1FEBD2, 0x61EFC8C2,
- 0xF1AC2571, 0xCC8239C2, 0x67214CB8,
- 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE,
- 0xF90A5C38, 0x0FF0443D, 0x606E6DC6,
- 0x60543A49, 0x5727C148, 0x2BE98A1D,
- 0x8AB41738, 0x20E1BE24, 0xAF96DA0F,
- 0x68458425, 0x99833BE5, 0x600D457D,
- 0x282F9350, 0x8334B362, 0xD91D1120,
- 0x2B6D8DA0, 0x642B1E31, 0x9C305A00,
- 0x52BCE688, 0x1B03588A, 0xF7BAEFD5,
- 0x4142ED9C, 0xA4315C11, 0x83323EC5,
- 0xDFEF4636, 0xA133C501, 0xE9D3531C,
- 0xEE353783 };
-
- private static final int[] S4 = { 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF,
- 0xD273A298, 0x4A4F7BDB, 0x64AD8C57,
- 0x85510443, 0xFA020ED1, 0x7E287AFF,
- 0xE60FB663, 0x095F35A1, 0x79EBF120,
- 0xFD059D43, 0x6497B7B1, 0xF3641F63,
- 0x241E4ADF, 0x28147F5F, 0x4FA2B8CD,
- 0xC9430040, 0x0CC32220, 0xFDD30B30,
- 0xC0A5374F, 0x1D2D00D9, 0x24147B15,
- 0xEE4D111A, 0x0FCA5167, 0x71FF904C,
- 0x2D195FFE, 0x1A05645F, 0x0C13FEFE,
- 0x081B08CA, 0x05170121, 0x80530100,
- 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701,
- 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A,
- 0x7293EA25, 0xCE84FFDF, 0xF5718801,
- 0x3DD64B04, 0xA26F263B, 0x7ED48400,
- 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5,
- 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1,
- 0x503F7E93, 0xD3772061, 0x11B638E1,
- 0x72500E03, 0xF80EB2BB, 0xABE0502E,
- 0xEC8D77DE, 0x57971E81, 0xE14F6746,
- 0xC9335400, 0x6920318F, 0x081DBB99,
- 0xFFC304A5, 0x4D351805, 0x7F3D5CE3,
- 0xA6C866C6, 0x5D5BCCA9, 0xDAEC6FEA,
- 0x9F926F91, 0x9F46222F, 0x3991467D,
- 0xA5BF6D8E, 0x1143C44F, 0x43958302,
- 0xD0214EEB, 0x022083B8, 0x3FB6180C,
- 0x18F8931E, 0x281658E6, 0x26486E3E,
- 0x8BD78A70, 0x7477E4C1, 0xB506E07C,
- 0xF32D0A25, 0x79098B02, 0xE4EABB81,
- 0x28123B23, 0x69DEAD38, 0x1574CA16,
- 0xDF871B62, 0x211C40B7, 0xA51A9EF9,
- 0x0014377B, 0x041E8AC8, 0x09114003,
- 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5,
- 0x2F91A340, 0x557BE8DE, 0x00EAE4A7,
- 0x0CE5C2EC, 0x4DB4BBA6, 0xE756BDFF,
- 0xDD3369AC, 0xEC17B035, 0x06572327,
- 0x99AFC8B0, 0x56C8C391, 0x6B65811C,
- 0x5E146119, 0x6E85CB75, 0xBE07C002,
- 0xC2325577, 0x893FF4EC, 0x5BBFC92D,
- 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24,
- 0x20C763EF, 0xC366A5FC, 0x9C382880,
- 0x0ACE3205, 0xAAC9548A, 0xECA1D7C7,
- 0x041AFA32, 0x1D16625A, 0x6701902C,
- 0x9B757A54, 0x31D477F7, 0x9126B031,
- 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48,
- 0x56E55A79, 0x026A4CEB, 0x52437EFF,
- 0x2F8F76B4, 0x0DF980A5, 0x8674CDE3,
- 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF,
- 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20,
- 0x2E096B7C, 0x1741A254, 0xE5B6A035,
- 0x213D42F6, 0x2C1C7C26, 0x61C2F50F,
- 0x6552DAF9, 0xD2C231F8, 0x25130F69,
- 0xD8167FA2, 0x0418F2C8, 0x001A96A6,
- 0x0D1526AB, 0x63315C21, 0x5E0A72EC,
- 0x49BAFEFD, 0x187908D9, 0x8D0DBD86,
- 0x311170A7, 0x3E9B640C, 0xCC3E10D7,
- 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1,
- 0x6C728AFF, 0x71EAE2A1, 0x1F9AF36E,
- 0xCFCBD12F, 0xC1DE8417, 0xAC07BE6B,
- 0xCB44A1D8, 0x8B9B0F56, 0x013988C3,
- 0xB1C52FCA, 0xB4BE31CD, 0xD8782806,
- 0x12A3A4E2, 0x6F7DE532, 0x58FD7EB6,
- 0xD01EE900, 0x24ADFFC2, 0xF4990FC5,
- 0x9711AAC5, 0x001D7B95, 0x82E5E7D2,
- 0x109873F6, 0x00613096, 0xC32D9521,
- 0xADA121FF, 0x29908415, 0x7FBB977F,
- 0xAF9EB3DB, 0x29C9ED2A, 0x5CE2A465,
- 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091,
- 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86,
- 0x015F1919, 0x77079103, 0xDEA03AF6,
- 0x78A8565E, 0xDEE356DF, 0x21F05CBE,
- 0x8B75E387, 0xB3C50651, 0xB8A5C3EF,
- 0xD8EEB6D2, 0xE523BE77, 0xC2154529,
- 0x2F69EFDF, 0xAFE67AFB, 0xF470C4B2,
- 0xF3E0EB5B, 0xD6CC9876, 0x39E4460C,
- 0x1FDA8538, 0x1987832F, 0xCA007367,
- 0xA99144F8, 0x296B299E, 0x492FC295,
- 0x9266BEAB, 0xB5676E69, 0x9BD3DDDA,
- 0xDF7E052F, 0xDB25701C, 0x1B5E51EE,
- 0xF65324E6, 0x6AFCE36C, 0x0316CC04,
- 0x8644213E, 0xB7DC59D0, 0x7965291F,
- 0xCCD6FD43, 0x41823979, 0x932BCDF6,
- 0xB657C34D, 0x4EDFD282, 0x7AE5290C,
- 0x3CB9536B, 0x851E20FE, 0x9833557E,
- 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1,
- 0x0AEF7ED2 };
-
- private static final int[] S5 = { 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF,
- 0xA6337911, 0xB86A7FFF, 0x1DD358F5,
- 0x44DD9D44, 0x1731167F, 0x08FBF1FA,
- 0xE7F511CC, 0xD2051B00, 0x735ABA00,
- 0x2AB722D8, 0x386381CB, 0xACF6243A,
- 0x69BEFD7A, 0xE6A2E77F, 0xF0C720CD,
- 0xC4494816, 0xCCF5C180, 0x38851640,
- 0x15B0A848, 0xE68B18CB, 0x4CAADEFF,
- 0x5F480A01, 0x0412B2AA, 0x259814FC,
- 0x41D0EFE2, 0x4E40B48D, 0x248EB6FB,
- 0x8DBA1CFE, 0x41A99B02, 0x1A550A04,
- 0xBA8F65CB, 0x7251F4E7, 0x95A51725,
- 0xC106ECD7, 0x97A5980A, 0xC539B9AA,
- 0x4D79FE6A, 0xF2F3F763, 0x68AF8040,
- 0xED0C9E56, 0x11B4958B, 0xE1EB5A88,
- 0x8709E6B0, 0xD7E07156, 0x4E29FEA7,
- 0x6366E52D, 0x02D1C000, 0xC4AC8E05,
- 0x9377F571, 0x0C05372A, 0x578535F2,
- 0x2261BE02, 0xD642A0C9, 0xDF13A280,
- 0x74B55BD2, 0x682199C0, 0xD421E5EC,
- 0x53FB3CE8, 0xC8ADEDB3, 0x28A87FC9,
- 0x3D959981, 0x5C1FF900, 0xFE38D399,
- 0x0C4EFF0B, 0x062407EA, 0xAA2F4FB1,
- 0x4FB96976, 0x90C79505, 0xB0A8A774,
- 0xEF55A1FF, 0xE59CA2C2, 0xA6B62D27,
- 0xE66A4263, 0xDF65001F, 0x0EC50966,
- 0xDFDD55BC, 0x29DE0655, 0x911E739A,
- 0x17AF8975, 0x32C7911C, 0x89F89468,
- 0x0D01E980, 0x524755F4, 0x03B63CC9,
- 0x0CC844B2, 0xBCF3F0AA, 0x87AC36E9,
- 0xE53A7426, 0x01B3D82B, 0x1A9E7449,
- 0x64EE2D7E, 0xCDDBB1DA, 0x01C94910,
- 0xB868BF80, 0x0D26F3FD, 0x9342EDE7,
- 0x04A5C284, 0x636737B6, 0x50F5B616,
- 0xF24766E3, 0x8ECA36C1, 0x136E05DB,
- 0xFEF18391, 0xFB887A37, 0xD6E7F7D4,
- 0xC7FB7DC9, 0x3063FCDF, 0xB6F589DE,
- 0xEC2941DA, 0x26E46695, 0xB7566419,
- 0xF654EFC5, 0xD08D58B7, 0x48925401,
- 0xC1BACB7F, 0xE5FF550F, 0xB6083049,
- 0x5BB5D0E8, 0x87D72E5A, 0xAB6A6EE1,
- 0x223A66CE, 0xC62BF3CD, 0x9E0885F9,
- 0x68CB3E47, 0x086C010F, 0xA21DE820,
- 0xD18B69DE, 0xF3F65777, 0xFA02C3F6,
- 0x407EDAC3, 0xCBB3D550, 0x1793084D,
- 0xB0D70EBA, 0x0AB378D5, 0xD951FB0C,
- 0xDED7DA56, 0x4124BBE4, 0x94CA0B56,
- 0x0F5755D1, 0xE0E1E56E, 0x6184B5BE,
- 0x580A249F, 0x94F74BC0, 0xE327888E,
- 0x9F7B5561, 0xC3DC0280, 0x05687715,
- 0x646C6BD7, 0x44904DB3, 0x66B4F0A3,
- 0xC0F1648A, 0x697ED5AF, 0x49E92FF6,
- 0x309E374F, 0x2CB6356A, 0x85808573,
- 0x4991F840, 0x76F0AE02, 0x083BE84D,
- 0x28421C9A, 0x44489406, 0x736E4CB8,
- 0xC1092910, 0x8BC95FC6, 0x7D869CF4,
- 0x134F616F, 0x2E77118D, 0xB31B2BE1,
- 0xAA90B472, 0x3CA5D717, 0x7D161BBA,
- 0x9CAD9010, 0xAF462BA2, 0x9FE459D2,
- 0x45D34559, 0xD9F2DA13, 0xDBC65487,
- 0xF3E4F94E, 0x176D486F, 0x097C13EA,
- 0x631DA5C7, 0x445F7382, 0x175683F4,
- 0xCDC66A97, 0x70BE0288, 0xB3CDCF72,
- 0x6E5DD2F3, 0x20936079, 0x459B80A5,
- 0xBE60E2DB, 0xA9C23101, 0xEBA5315C,
- 0x224E42F2, 0x1C5C1572, 0xF6721B2C,
- 0x1AD2FFF3, 0x8C25404E, 0x324ED72F,
- 0x4067B7FD, 0x0523138E, 0x5CA3BC78,
- 0xDC0FD66E, 0x75922283, 0x784D6B17,
- 0x58EBB16E, 0x44094F85, 0x3F481D87,
- 0xFCFEAE7B, 0x77B5FF76, 0x8C2302BF,
- 0xAAF47556, 0x5F46B02A, 0x2B092801,
- 0x3D38F5F7, 0x0CA81F36, 0x52AF4A8A,
- 0x66D5E7C0, 0xDF3B0874, 0x95055110,
- 0x1B5AD7A8, 0xF61ED5AD, 0x6CF6E479,
- 0x20758184, 0xD0CEFA65, 0x88F7BE58,
- 0x4A046826, 0x0FF6F8F3, 0xA09C7F70,
- 0x5346ABA0, 0x5CE96C28, 0xE176EDA3,
- 0x6BAC307F, 0x376829D2, 0x85360FA9,
- 0x17E3FE2A, 0x24B79767, 0xF5A96B20,
- 0xD6CD2595, 0x68FF1EBF, 0x7555442C,
- 0xF19F06BE, 0xF9E0659A, 0xEEB9491D,
- 0x34010718, 0xBB30CAB8, 0xE822FE15,
- 0x88570983, 0x750E6249, 0xDA627E55,
- 0x5E76FFA8, 0xB1534546, 0x6D47DE08,
- 0xEFE9E7D4 };
-
- private static final int[] S6 = { 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867,
- 0xE2337F7C, 0x95DB08E7, 0x016843B4,
- 0xECED5CBC, 0x325553AC, 0xBF9F0960,
- 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9,
- 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732,
- 0x8989B138, 0x33F14961, 0xC01937BD,
- 0xF506C6DA, 0xE4625E7E, 0xA308EA99,
- 0x4E23E33C, 0x79CBD7CC, 0x48A14367,
- 0xA3149619, 0xFEC94BD5, 0xA114174A,
- 0xEAA01866, 0xA084DB2D, 0x09A8486F,
- 0xA888614A, 0x2900AF98, 0x01665991,
- 0xE1992863, 0xC8F30C60, 0x2E78EF3C,
- 0xD0D51932, 0xCF0FEC14, 0xF7CA07D2,
- 0xD0A82072, 0xFD41197E, 0x9305A6B0,
- 0xE86BE3DA, 0x74BED3CD, 0x372DA53C,
- 0x4C7F4448, 0xDAB5D440, 0x6DBA0EC3,
- 0x083919A7, 0x9FBAEED9, 0x49DBCFB0,
- 0x4E670C53, 0x5C3D9C01, 0x64BDB941,
- 0x2C0E636A, 0xBA7DD9CD, 0xEA6F7388,
- 0xE70BC762, 0x35F29ADB, 0x5C4CDD8D,
- 0xF0D48D8C, 0xB88153E2, 0x08A19866,
- 0x1AE2EAC8, 0x284CAF89, 0xAA928223,
- 0x9334BE53, 0x3B3A21BF, 0x16434BE3,
- 0x9AEA3906, 0xEFE8C36E, 0xF890CDD9,
- 0x80226DAE, 0xC340A4A3, 0xDF7E9C09,
- 0xA694A807, 0x5B7C5ECC, 0x221DB3A6,
- 0x9A69A02F, 0x68818A54, 0xCEB2296F,
- 0x53C0843A, 0xFE893655, 0x25BFE68A,
- 0xB4628ABC, 0xCF222EBF, 0x25AC6F48,
- 0xA9A99387, 0x53BDDB65, 0xE76FFBE7,
- 0xE967FD78, 0x0BA93563, 0x8E342BC1,
- 0xE8A11BE9, 0x4980740D, 0xC8087DFC,
- 0x8DE4BF99, 0xA11101A0, 0x7FD37975,
- 0xDA5A26C0, 0xE81F994F, 0x9528CD89,
- 0xFD339FED, 0xB87834BF, 0x5F04456D,
- 0x22258698, 0xC9C4C83B, 0x2DC156BE,
- 0x4F628DAA, 0x57F55EC5, 0xE2220ABE,
- 0xD2916EBF, 0x4EC75B95, 0x24F2C3C0,
- 0x42D15D99, 0xCD0D7FA0, 0x7B6E27FF,
- 0xA8DC8AF0, 0x7345C106, 0xF41E232F,
- 0x35162386, 0xE6EA8926, 0x3333B094,
- 0x157EC6F2, 0x372B74AF, 0x692573E4,
- 0xE9A9D848, 0xF3160289, 0x3A62EF1D,
- 0xA787E238, 0xF3A5F676, 0x74364853,
- 0x20951063, 0x4576698D, 0xB6FAD407,
- 0x592AF950, 0x36F73523, 0x4CFB6E87,
- 0x7DA4CEC0, 0x6C152DAA, 0xCB0396A8,
- 0xC50DFE5D, 0xFCD707AB, 0x0921C42F,
- 0x89DFF0BB, 0x5FE2BE78, 0x448F4F33,
- 0x754613C9, 0x2B05D08D, 0x48B9D585,
- 0xDC049441, 0xC8098F9B, 0x7DEDE786,
- 0xC39A3373, 0x42410005, 0x6A091751,
- 0x0EF3C8A6, 0x890072D6, 0x28207682,
- 0xA9A9F7BE, 0xBF32679D, 0xD45B5B75,
- 0xB353FD00, 0xCBB0E358, 0x830F220A,
- 0x1F8FB214, 0xD372CF08, 0xCC3C4A13,
- 0x8CF63166, 0x061C87BE, 0x88C98F88,
- 0x6062E397, 0x47CF8E7A, 0xB6C85283,
- 0x3CC2ACFB, 0x3FC06976, 0x4E8F0252,
- 0x64D8314D, 0xDA3870E3, 0x1E665459,
- 0xC10908F0, 0x513021A5, 0x6C5B68B7,
- 0x822F8AA0, 0x3007CD3E, 0x74719EEF,
- 0xDC872681, 0x073340D4, 0x7E432FD9,
- 0x0C5EC241, 0x8809286C, 0xF592D891,
- 0x08A930F6, 0x957EF305, 0xB7FBFFBD,
- 0xC266E96F, 0x6FE4AC98, 0xB173ECC0,
- 0xBC60B42A, 0x953498DA, 0xFBA1AE12,
- 0x2D4BD736, 0x0F25FAAB, 0xA4F3FCEB,
- 0xE2969123, 0x257F0C3D, 0x9348AF49,
- 0x361400BC, 0xE8816F4A, 0x3814F200,
- 0xA3F94043, 0x9C7A54C2, 0xBC704F57,
- 0xDA41E7F9, 0xC25AD33A, 0x54F4A084,
- 0xB17F5505, 0x59357CBE, 0xEDBD15C8,
- 0x7F97C5AB, 0xBA5AC7B5, 0xB6F6DEAF,
- 0x3A479C3A, 0x5302DA25, 0x653D7E6A,
- 0x54268D49, 0x51A477EA, 0x5017D55B,
- 0xD7D25D88, 0x44136C76, 0x0404A8C8,
- 0xB8E5A121, 0xB81A928A, 0x60ED5869,
- 0x97C55B96, 0xEAEC991B, 0x29935913,
- 0x01FDB7F1, 0x088E8DFA, 0x9AB6F6F5,
- 0x3B4CBF9F, 0x4A5DE3AB, 0xE6051D35,
- 0xA0E1D855, 0xD36B4CF1, 0xF544EDEB,
- 0xB0E93524, 0xBEBB8FBD, 0xA2D762CF,
- 0x49C92F54, 0x38B5F331, 0x7128A454,
- 0x48392905, 0xA65B1DB8, 0x851C97BD,
- 0xD675CF2F };
-
- private static final int[] S7 = { 0x85E04019, 0x332BF567, 0x662DBFFF,
- 0xCFC65693, 0x2A8D7F6F, 0xAB9BC912,
- 0xDE6008A1, 0x2028DA1F, 0x0227BCE7,
- 0x4D642916, 0x18FAC300, 0x50F18B82,
- 0x2CB2CB11, 0xB232E75C, 0x4B3695F2,
- 0xB28707DE, 0xA05FBCF6, 0xCD4181E9,
- 0xE150210C, 0xE24EF1BD, 0xB168C381,
- 0xFDE4E789, 0x5C79B0D8, 0x1E8BFD43,
- 0x4D495001, 0x38BE4341, 0x913CEE1D,
- 0x92A79C3F, 0x089766BE, 0xBAEEADF4,
- 0x1286BECF, 0xB6EACB19, 0x2660C200,
- 0x7565BDE4, 0x64241F7A, 0x8248DCA9,
- 0xC3B3AD66, 0x28136086, 0x0BD8DFA8,
- 0x356D1CF2, 0x107789BE, 0xB3B2E9CE,
- 0x0502AA8F, 0x0BC0351E, 0x166BF52A,
- 0xEB12FF82, 0xE3486911, 0xD34D7516,
- 0x4E7B3AFF, 0x5F43671B, 0x9CF6E037,
- 0x4981AC83, 0x334266CE, 0x8C9341B7,
- 0xD0D854C0, 0xCB3A6C88, 0x47BC2829,
- 0x4725BA37, 0xA66AD22B, 0x7AD61F1E,
- 0x0C5CBAFA, 0x4437F107, 0xB6E79962,
- 0x42D2D816, 0x0A961288, 0xE1A5C06E,
- 0x13749E67, 0x72FC081A, 0xB1D139F7,
- 0xF9583745, 0xCF19DF58, 0xBEC3F756,
- 0xC06EBA30, 0x07211B24, 0x45C28829,
- 0xC95E317F, 0xBC8EC511, 0x38BC46E9,
- 0xC6E6FA14, 0xBAE8584A, 0xAD4EBC46,
- 0x468F508B, 0x7829435F, 0xF124183B,
- 0x821DBA9F, 0xAFF60FF4, 0xEA2C4E6D,
- 0x16E39264, 0x92544A8B, 0x009B4FC3,
- 0xABA68CED, 0x9AC96F78, 0x06A5B79A,
- 0xB2856E6E, 0x1AEC3CA9, 0xBE838688,
- 0x0E0804E9, 0x55F1BE56, 0xE7E5363B,
- 0xB3A1F25D, 0xF7DEBB85, 0x61FE033C,
- 0x16746233, 0x3C034C28, 0xDA6D0C74,
- 0x79AAC56C, 0x3CE4E1AD, 0x51F0C802,
- 0x98F8F35A, 0x1626A49F, 0xEED82B29,
- 0x1D382FE3, 0x0C4FB99A, 0xBB325778,
- 0x3EC6D97B, 0x6E77A6A9, 0xCB658B5C,
- 0xD45230C7, 0x2BD1408B, 0x60C03EB7,
- 0xB9068D78, 0xA33754F4, 0xF430C87D,
- 0xC8A71302, 0xB96D8C32, 0xEBD4E7BE,
- 0xBE8B9D2D, 0x7979FB06, 0xE7225308,
- 0x8B75CF77, 0x11EF8DA4, 0xE083C858,
- 0x8D6B786F, 0x5A6317A6, 0xFA5CF7A0,
- 0x5DDA0033, 0xF28EBFB0, 0xF5B9C310,
- 0xA0EAC280, 0x08B9767A, 0xA3D9D2B0,
- 0x79D34217, 0x021A718D, 0x9AC6336A,
- 0x2711FD60, 0x438050E3, 0x069908A8,
- 0x3D7FEDC4, 0x826D2BEF, 0x4EEB8476,
- 0x488DCF25, 0x36C9D566, 0x28E74E41,
- 0xC2610ACA, 0x3D49A9CF, 0xBAE3B9DF,
- 0xB65F8DE6, 0x92AEAF64, 0x3AC7D5E6,
- 0x9EA80509, 0xF22B017D, 0xA4173F70,
- 0xDD1E16C3, 0x15E0D7F9, 0x50B1B887,
- 0x2B9F4FD5, 0x625ABA82, 0x6A017962,
- 0x2EC01B9C, 0x15488AA9, 0xD716E740,
- 0x40055A2C, 0x93D29A22, 0xE32DBF9A,
- 0x058745B9, 0x3453DC1E, 0xD699296E,
- 0x496CFF6F, 0x1C9F4986, 0xDFE2ED07,
- 0xB87242D1, 0x19DE7EAE, 0x053E561A,
- 0x15AD6F8C, 0x66626C1C, 0x7154C24C,
- 0xEA082B2A, 0x93EB2939, 0x17DCB0F0,
- 0x58D4F2AE, 0x9EA294FB, 0x52CF564C,
- 0x9883FE66, 0x2EC40581, 0x763953C3,
- 0x01D6692E, 0xD3A0C108, 0xA1E7160E,
- 0xE4F2DFA6, 0x693ED285, 0x74904698,
- 0x4C2B0EDD, 0x4F757656, 0x5D393378,
- 0xA132234F, 0x3D321C5D, 0xC3F5E194,
- 0x4B269301, 0xC79F022F, 0x3C997E7E,
- 0x5E4F9504, 0x3FFAFBBD, 0x76F7AD0E,
- 0x296693F4, 0x3D1FCE6F, 0xC61E45BE,
- 0xD3B5AB34, 0xF72BF9B7, 0x1B0434C0,
- 0x4E72B567, 0x5592A33D, 0xB5229301,
- 0xCFD2A87F, 0x60AEB767, 0x1814386B,
- 0x30BCC33D, 0x38A0C07D, 0xFD1606F2,
- 0xC363519B, 0x589DD390, 0x5479F8E6,
- 0x1CB8D647, 0x97FD61A9, 0xEA7759F4,
- 0x2D57539D, 0x569A58CF, 0xE84E63AD,
- 0x462E1B78, 0x6580F87E, 0xF3817914,
- 0x91DA55F4, 0x40A230F3, 0xD1988F35,
- 0xB6E318D2, 0x3FFA50BC, 0x3D40F021,
- 0xC3C0BDAE, 0x4958C24C, 0x518F36B2,
- 0x84B1D370, 0x0FEDCE83, 0x878DDADA,
- 0xF2A279C7, 0x94E01BE8, 0x90716F4B,
- 0x954B8AA3 };
-
- private static final int[] S8 = { 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD,
- 0x35648095, 0x7789F8B7, 0xE6C1121B,
- 0x0E241600, 0x052CE8B5, 0x11A9CFB0,
- 0xE5952F11, 0xECE7990A, 0x9386D174,
- 0x2A42931C, 0x76E38111, 0xB12DEF3A,
- 0x37DDDDFC, 0xDE9ADEB1, 0x0A0CC32C,
- 0xBE197029, 0x84A00940, 0xBB243A0F,
- 0xB4D137CF, 0xB44E79F0, 0x049EEDFD,
- 0x0B15A15D, 0x480D3168, 0x8BBBDE5A,
- 0x669DED42, 0xC7ECE831, 0x3F8F95E7,
- 0x72DF191B, 0x7580330D, 0x94074251,
- 0x5C7DCDFA, 0xABBE6D63, 0xAA402164,
- 0xB301D40A, 0x02E7D1CA, 0x53571DAE,
- 0x7A3182A2, 0x12A8DDEC, 0xFDAA335D,
- 0x176F43E8, 0x71FB46D4, 0x38129022,
- 0xCE949AD4, 0xB84769AD, 0x965BD862,
- 0x82F3D055, 0x66FB9767, 0x15B80B4E,
- 0x1D5B47A0, 0x4CFDE06F, 0xC28EC4B8,
- 0x57E8726E, 0x647A78FC, 0x99865D44,
- 0x608BD593, 0x6C200E03, 0x39DC5FF6,
- 0x5D0B00A3, 0xAE63AFF2, 0x7E8BD632,
- 0x70108C0C, 0xBBD35049, 0x2998DF04,
- 0x980CF42A, 0x9B6DF491, 0x9E7EDD53,
- 0x06918548, 0x58CB7E07, 0x3B74EF2E,
- 0x522FFFB1, 0xD24708CC, 0x1C7E27CD,
- 0xA4EB215B, 0x3CF1D2E2, 0x19B47A38,
- 0x424F7618, 0x35856039, 0x9D17DEE7,
- 0x27EB35E6, 0xC9AFF67B, 0x36BAF5B8,
- 0x09C467CD, 0xC18910B1, 0xE11DBF7B,
- 0x06CD1AF8, 0x7170C608, 0x2D5E3354,
- 0xD4DE495A, 0x64C6D006, 0xBCC0C62C,
- 0x3DD00DB3, 0x708F8F34, 0x77D51B42,
- 0x264F620F, 0x24B8D2BF, 0x15C1B79E,
- 0x46A52564, 0xF8D7E54E, 0x3E378160,
- 0x7895CDA5, 0x859C15A5, 0xE6459788,
- 0xC37BC75F, 0xDB07BA0C, 0x0676A3AB,
- 0x7F229B1E, 0x31842E7B, 0x24259FD7,
- 0xF8BEF472, 0x835FFCB8, 0x6DF4C1F2,
- 0x96F5B195, 0xFD0AF0FC, 0xB0FE134C,
- 0xE2506D3D, 0x4F9B12EA, 0xF215F225,
- 0xA223736F, 0x9FB4C428, 0x25D04979,
- 0x34C713F8, 0xC4618187, 0xEA7A6E98,
- 0x7CD16EFC, 0x1436876C, 0xF1544107,
- 0xBEDEEE14, 0x56E9AF27, 0xA04AA441,
- 0x3CF7C899, 0x92ECBAE6, 0xDD67016D,
- 0x151682EB, 0xA842EEDF, 0xFDBA60B4,
- 0xF1907B75, 0x20E3030F, 0x24D8C29E,
- 0xE139673B, 0xEFA63FB8, 0x71873054,
- 0xB6F2CF3B, 0x9F326442, 0xCB15A4CC,
- 0xB01A4504, 0xF1E47D8D, 0x844A1BE5,
- 0xBAE7DFDC, 0x42CBDA70, 0xCD7DAE0A,
- 0x57E85B7A, 0xD53F5AF6, 0x20CF4D8C,
- 0xCEA4D428, 0x79D130A4, 0x3486EBFB,
- 0x33D3CDDC, 0x77853B53, 0x37EFFCB5,
- 0xC5068778, 0xE580B3E6, 0x4E68B8F4,
- 0xC5C8B37E, 0x0D809EA2, 0x398FEB7C,
- 0x132A4F94, 0x43B7950E, 0x2FEE7D1C,
- 0x223613BD, 0xDD06CAA2, 0x37DF932B,
- 0xC4248289, 0xACF3EBC3, 0x5715F6B7,
- 0xEF3478DD, 0xF267616F, 0xC148CBE4,
- 0x9052815E, 0x5E410FAB, 0xB48A2465,
- 0x2EDA7FA4, 0xE87B40E4, 0xE98EA084,
- 0x5889E9E1, 0xEFD390FC, 0xDD07D35B,
- 0xDB485694, 0x38D7E5B2, 0x57720101,
- 0x730EDEBC, 0x5B643113, 0x94917E4F,
- 0x503C2FBA, 0x646F1282, 0x7523D24A,
- 0xE0779695, 0xF9C17A8F, 0x7A5B2121,
- 0xD187B896, 0x29263A4D, 0xBA510CDF,
- 0x81F47C9F, 0xAD1163ED, 0xEA7B5965,
- 0x1A00726E, 0x11403092, 0x00DA6D77,
- 0x4A0CDD61, 0xAD1F4603, 0x605BDFB0,
- 0x9EEDC364, 0x22EBE6A8, 0xCEE7D28A,
- 0xA0E736A0, 0x5564A6B9, 0x10853209,
- 0xC7EB8F37, 0x2DE705CA, 0x8951570F,
- 0xDF09822B, 0xBD691A6C, 0xAA12E4F2,
- 0x87451C0F, 0xE0F6A27A, 0x3ADA4819,
- 0x4CF1764F, 0x0D771C2B, 0x67CDB156,
- 0x350D8384, 0x5938FA0F, 0x42399EF3,
- 0x36997B07, 0x0E84093D, 0x4AA93E61,
- 0x8360D87B, 0x1FA98B0C, 0x1149382C,
- 0xE97625A5, 0x0614D1B7, 0x0E25244B,
- 0x0C768347, 0x589E8D82, 0x0D2059D1,
- 0xA466BB1E, 0xF8DA0A82, 0x04F19130,
- 0xBA6E4EC0, 0x99265164, 0x1EE7230D,
- 0x50B2AD80, 0xEAEE6801, 0x8DB2A283,
- 0xEA8BF59E };
-
+ private static final int[] S1 = {
+ 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, 0x1E213F2F, 0x9C004DD3,
+ 0x6003E540, 0xCF9FC949, 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675,
+ 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, 0x28683B6F, 0xC07FD059,
+ 0xFF2379C8, 0x775F50E2, 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D,
+ 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F, 0x2ABE32E1, 0xAA54166B,
+ 0x22568E3A, 0xA2D341D0, 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE,
+ 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7, 0xB82CBAEF, 0xD751D159,
+ 0x6FF7F0ED, 0x5A097A1F, 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935,
+ 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D, 0xB7332290, 0xE93B159F,
+ 0xB48EE411, 0x4BFF345D, 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165,
+ 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50, 0x882240F2, 0x0C6E4F38,
+ 0xA4E4BFD7, 0x4F5BA272, 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE,
+ 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D, 0x57538AD5, 0x6A390493,
+ 0xE63D37E0, 0x2A54F6B3, 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A,
+ 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167, 0x38901091, 0xC6B505EB,
+ 0x84C7CB8C, 0x2AD75A0F, 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291,
+ 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9, 0x6C00B32D, 0x73E2BB14,
+ 0xA0BEBC3C, 0x54623779, 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6,
+ 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2, 0x81383F05, 0x6963C5C8,
+ 0x76CB5AD6, 0xD49974C9, 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511,
+ 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E, 0x31366241, 0x051EF495,
+ 0xAA573B04, 0x4A805D8D, 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E,
+ 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5, 0x6B54BFAB, 0x2B0B1426,
+ 0xAB4CC9D7, 0x449CCD82, 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324,
+ 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC, 0xEADF55B3, 0xD5BD9E98,
+ 0xE31231B2, 0x2AD5AD6C, 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F,
+ 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC, 0x7B5A41F0, 0xD37CFBAD,
+ 0x1B069505, 0x41ECE491, 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D,
+ 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE, 0xE01063DA, 0x4736F464,
+ 0x5AD328D8, 0xB347CC96, 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A,
+ 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A, 0x3F04442F, 0x6188B153,
+ 0xE0397A2E, 0x5727CB79, 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D,
+ 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779, 0x4744EAD4, 0xB11C3274,
+ 0xDD24CB9E, 0x7E1C54BD, 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755,
+ 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6, 0x580304F0, 0xCA042CF1,
+ 0x011A37EA, 0x8DBFAADB, 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9,
+ 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0, 0x7C63B2CF, 0x700B45E1,
+ 0xD5EA50F1, 0x85A92872, 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79,
+ 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C, 0x474D6AD7, 0x7C0C5E5C,
+ 0xD1231959, 0x381B7298, 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E,
+ 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571, 0x962BDA1C, 0xE1E696FF,
+ 0xB141AB08, 0x7CCA89B9, 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D,
+ 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF };
+ private static final int[] S2 = {
+ 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, 0xFE61CF7A, 0xEEC5207A,
+ 0x55889C94, 0x72FC0651, 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA,
+ 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, 0xA0B52F7B, 0x59E83605,
+ 0xEE15B094, 0xE9FFD909, 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB,
+ 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B, 0x01420DDB, 0xE4E7EF5B,
+ 0x25A1FF41, 0xE180F806, 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4,
+ 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B, 0xE113C85B, 0xACC40083,
+ 0xD7503525, 0xF7EA615F, 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359,
+ 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21, 0x071F6181, 0x39F7627F,
+ 0x361E3084, 0xE4EB573B, 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D,
+ 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C, 0x10843094, 0x2537A95E,
+ 0xF46F6FFE, 0xA1FF3B1F, 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34,
+ 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D, 0x8A45388C, 0x1D804366,
+ 0x721D9BFD, 0xA58684BB, 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4,
+ 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD, 0xC5D655DD, 0xEB667064,
+ 0x77840B4D, 0xA1B6A801, 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860,
+ 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755, 0xB5625DBF, 0x68561BE6,
+ 0x83CA6B94, 0x2D6ED23B, 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709,
+ 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304, 0x81ED6F61, 0x20E74364,
+ 0xB45E1378, 0xDE18639B, 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B,
+ 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C, 0x488CB402, 0x1BA4FE5B,
+ 0xA4B09F6B, 0x1CA815CF, 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9,
+ 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C, 0xEE41E729, 0x6E1D2D7C,
+ 0x50045286, 0x1E6685F3, 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13,
+ 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9, 0xCDFF33A6, 0xA02B1741,
+ 0x7CBAD9A2, 0x2180036F, 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB,
+ 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6, 0xCDF0B680, 0x17844D3B,
+ 0x31EEF84D, 0x7E0824E4, 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6,
+ 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43, 0xB3FAEC54, 0x157FD7FA,
+ 0xEF8579CC, 0xD152DE58, 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8,
+ 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906, 0xB8DA230C, 0x80823028,
+ 0xDCDEF3C8, 0xD35FB171, 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D,
+ 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89, 0x8B1C34BC, 0x301E16E6,
+ 0x273BE979, 0xB0FFEAA6, 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B,
+ 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4, 0xDC8637A0, 0x16A7D3B1,
+ 0x9FC393B7, 0xA7136EEB, 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6,
+ 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E, 0xDB92F2FB, 0x5EEA29CB,
+ 0x145892F5, 0x91584F7F, 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA,
+ 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249, 0xB284600C, 0xD835731D,
+ 0xDCB1C647, 0xAC4C56EA, 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA,
+ 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD, 0x649DA589, 0xA345415E,
+ 0x5C038323, 0x3E5D3BB9, 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF,
+ 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 };
+ private static final int[] S3 = {
+ 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, 0x47607FFF, 0x369FE44B,
+ 0x8C1FC644, 0xAECECA90, 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE,
+ 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, 0x11107D9F, 0x07647DB9,
+ 0xB2E3E4D4, 0x3D4F285E, 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E,
+ 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC, 0x21FFFCEE, 0x825B1BFD,
+ 0x9255C5ED, 0x1257A240, 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E,
+ 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5, 0xA8C01DB7, 0x579FC264,
+ 0x67094F31, 0xF2BD3F5F, 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B,
+ 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99, 0xA197C81C, 0x4A012D6E,
+ 0xC5884A28, 0xCCC36F71, 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F,
+ 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04, 0xA747D2D0, 0x1651192E,
+ 0xAF70BF3E, 0x58C31380, 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82,
+ 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8, 0x8427F4A0, 0x1EAC5790,
+ 0x796FB449, 0x8252DC15, 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504,
+ 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2, 0x23EFE941, 0xA903F12E,
+ 0x60270DF2, 0x0276E4B6, 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176,
+ 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E, 0x842F7D83, 0x340CE5C8,
+ 0x96BBB682, 0x93B4B148, 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D,
+ 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC, 0x8B907CEE, 0xB51FD240,
+ 0xE7C07CE3, 0xE566B4A1, 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341,
+ 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C, 0xF76CEDD9, 0xBDA8229C,
+ 0x127DADAA, 0x438A074E, 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15,
+ 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51, 0x68CC7BFB, 0xD90F2788,
+ 0x12490181, 0x5DE5FFD4, 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F,
+ 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B, 0x6D498623, 0x193CBCFA,
+ 0x27627545, 0x825CF47A, 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392,
+ 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B, 0x285BA1C8, 0x3C62F44F,
+ 0x35C0EAA5, 0xE805D231, 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B,
+ 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889, 0x694BCC11, 0x236A5CAE,
+ 0x12DECA4D, 0x2C3F8CC5, 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67,
+ 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45, 0x3A609437, 0xEC00C9A9,
+ 0x44715253, 0x0A874B49, 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536,
+ 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D, 0x07478CD1, 0x006E1888,
+ 0xA2E53F55, 0xB9E6D4BC, 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D,
+ 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0, 0x947B0001, 0x570075D2,
+ 0xF9BB88F8, 0x8942019E, 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69,
+ 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767, 0xCF1FEBD2, 0x61EFC8C2,
+ 0xF1AC2571, 0xCC8239C2, 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE,
+ 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49, 0x5727C148, 0x2BE98A1D,
+ 0x8AB41738, 0x20E1BE24, 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D,
+ 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0, 0x642B1E31, 0x9C305A00,
+ 0x52BCE688, 0x1B03588A, 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5,
+ 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 };
+ private static final int[] S4 = {
+ 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, 0x4A4F7BDB, 0x64AD8C57,
+ 0x85510443, 0xFA020ED1, 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120,
+ 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, 0x28147F5F, 0x4FA2B8CD,
+ 0xC9430040, 0x0CC32220, 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15,
+ 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE, 0x1A05645F, 0x0C13FEFE,
+ 0x081B08CA, 0x05170121, 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701,
+ 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25, 0xCE84FFDF, 0xF5718801,
+ 0x3DD64B04, 0xA26F263B, 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5,
+ 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93, 0xD3772061, 0x11B638E1,
+ 0x72500E03, 0xF80EB2BB, 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746,
+ 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5, 0x4D351805, 0x7F3D5CE3,
+ 0xA6C866C6, 0x5D5BCCA9, 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D,
+ 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB, 0x022083B8, 0x3FB6180C,
+ 0x18F8931E, 0x281658E6, 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C,
+ 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23, 0x69DEAD38, 0x1574CA16,
+ 0xDF871B62, 0x211C40B7, 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003,
+ 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340, 0x557BE8DE, 0x00EAE4A7,
+ 0x0CE5C2EC, 0x4DB4BBA6, 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327,
+ 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119, 0x6E85CB75, 0xBE07C002,
+ 0xC2325577, 0x893FF4EC, 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24,
+ 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205, 0xAAC9548A, 0xECA1D7C7,
+ 0x041AFA32, 0x1D16625A, 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031,
+ 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79, 0x026A4CEB, 0x52437EFF,
+ 0x2F8F76B4, 0x0DF980A5, 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF,
+ 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C, 0x1741A254, 0xE5B6A035,
+ 0x213D42F6, 0x2C1C7C26, 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69,
+ 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB, 0x63315C21, 0x5E0A72EC,
+ 0x49BAFEFD, 0x187908D9, 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7,
+ 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF, 0x71EAE2A1, 0x1F9AF36E,
+ 0xCFCBD12F, 0xC1DE8417, 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3,
+ 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2, 0x6F7DE532, 0x58FD7EB6,
+ 0xD01EE900, 0x24ADFFC2, 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2,
+ 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF, 0x29908415, 0x7FBB977F,
+ 0xAF9EB3DB, 0x29C9ED2A, 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091,
+ 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919, 0x77079103, 0xDEA03AF6,
+ 0x78A8565E, 0xDEE356DF, 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF,
+ 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF, 0xAFE67AFB, 0xF470C4B2,
+ 0xF3E0EB5B, 0xD6CC9876, 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367,
+ 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB, 0xB5676E69, 0x9BD3DDDA,
+ 0xDF7E052F, 0xDB25701C, 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04,
+ 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43, 0x41823979, 0x932BCDF6,
+ 0xB657C34D, 0x4EDFD282, 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E,
+ 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2 };
+ private static final int[] S5 = {
+ 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF, 0xA6337911, 0xB86A7FFF, 0x1DD358F5,
+ 0x44DD9D44, 0x1731167F, 0x08FBF1FA, 0xE7F511CC, 0xD2051B00, 0x735ABA00,
+ 0x2AB722D8, 0x386381CB, 0xACF6243A, 0x69BEFD7A, 0xE6A2E77F, 0xF0C720CD,
+ 0xC4494816, 0xCCF5C180, 0x38851640, 0x15B0A848, 0xE68B18CB, 0x4CAADEFF,
+ 0x5F480A01, 0x0412B2AA, 0x259814FC, 0x41D0EFE2, 0x4E40B48D, 0x248EB6FB,
+ 0x8DBA1CFE, 0x41A99B02, 0x1A550A04, 0xBA8F65CB, 0x7251F4E7, 0x95A51725,
+ 0xC106ECD7, 0x97A5980A, 0xC539B9AA, 0x4D79FE6A, 0xF2F3F763, 0x68AF8040,
+ 0xED0C9E56, 0x11B4958B, 0xE1EB5A88, 0x8709E6B0, 0xD7E07156, 0x4E29FEA7,
+ 0x6366E52D, 0x02D1C000, 0xC4AC8E05, 0x9377F571, 0x0C05372A, 0x578535F2,
+ 0x2261BE02, 0xD642A0C9, 0xDF13A280, 0x74B55BD2, 0x682199C0, 0xD421E5EC,
+ 0x53FB3CE8, 0xC8ADEDB3, 0x28A87FC9, 0x3D959981, 0x5C1FF900, 0xFE38D399,
+ 0x0C4EFF0B, 0x062407EA, 0xAA2F4FB1, 0x4FB96976, 0x90C79505, 0xB0A8A774,
+ 0xEF55A1FF, 0xE59CA2C2, 0xA6B62D27, 0xE66A4263, 0xDF65001F, 0x0EC50966,
+ 0xDFDD55BC, 0x29DE0655, 0x911E739A, 0x17AF8975, 0x32C7911C, 0x89F89468,
+ 0x0D01E980, 0x524755F4, 0x03B63CC9, 0x0CC844B2, 0xBCF3F0AA, 0x87AC36E9,
+ 0xE53A7426, 0x01B3D82B, 0x1A9E7449, 0x64EE2D7E, 0xCDDBB1DA, 0x01C94910,
+ 0xB868BF80, 0x0D26F3FD, 0x9342EDE7, 0x04A5C284, 0x636737B6, 0x50F5B616,
+ 0xF24766E3, 0x8ECA36C1, 0x136E05DB, 0xFEF18391, 0xFB887A37, 0xD6E7F7D4,
+ 0xC7FB7DC9, 0x3063FCDF, 0xB6F589DE, 0xEC2941DA, 0x26E46695, 0xB7566419,
+ 0xF654EFC5, 0xD08D58B7, 0x48925401, 0xC1BACB7F, 0xE5FF550F, 0xB6083049,
+ 0x5BB5D0E8, 0x87D72E5A, 0xAB6A6EE1, 0x223A66CE, 0xC62BF3CD, 0x9E0885F9,
+ 0x68CB3E47, 0x086C010F, 0xA21DE820, 0xD18B69DE, 0xF3F65777, 0xFA02C3F6,
+ 0x407EDAC3, 0xCBB3D550, 0x1793084D, 0xB0D70EBA, 0x0AB378D5, 0xD951FB0C,
+ 0xDED7DA56, 0x4124BBE4, 0x94CA0B56, 0x0F5755D1, 0xE0E1E56E, 0x6184B5BE,
+ 0x580A249F, 0x94F74BC0, 0xE327888E, 0x9F7B5561, 0xC3DC0280, 0x05687715,
+ 0x646C6BD7, 0x44904DB3, 0x66B4F0A3, 0xC0F1648A, 0x697ED5AF, 0x49E92FF6,
+ 0x309E374F, 0x2CB6356A, 0x85808573, 0x4991F840, 0x76F0AE02, 0x083BE84D,
+ 0x28421C9A, 0x44489406, 0x736E4CB8, 0xC1092910, 0x8BC95FC6, 0x7D869CF4,
+ 0x134F616F, 0x2E77118D, 0xB31B2BE1, 0xAA90B472, 0x3CA5D717, 0x7D161BBA,
+ 0x9CAD9010, 0xAF462BA2, 0x9FE459D2, 0x45D34559, 0xD9F2DA13, 0xDBC65487,
+ 0xF3E4F94E, 0x176D486F, 0x097C13EA, 0x631DA5C7, 0x445F7382, 0x175683F4,
+ 0xCDC66A97, 0x70BE0288, 0xB3CDCF72, 0x6E5DD2F3, 0x20936079, 0x459B80A5,
+ 0xBE60E2DB, 0xA9C23101, 0xEBA5315C, 0x224E42F2, 0x1C5C1572, 0xF6721B2C,
+ 0x1AD2FFF3, 0x8C25404E, 0x324ED72F, 0x4067B7FD, 0x0523138E, 0x5CA3BC78,
+ 0xDC0FD66E, 0x75922283, 0x784D6B17, 0x58EBB16E, 0x44094F85, 0x3F481D87,
+ 0xFCFEAE7B, 0x77B5FF76, 0x8C2302BF, 0xAAF47556, 0x5F46B02A, 0x2B092801,
+ 0x3D38F5F7, 0x0CA81F36, 0x52AF4A8A, 0x66D5E7C0, 0xDF3B0874, 0x95055110,
+ 0x1B5AD7A8, 0xF61ED5AD, 0x6CF6E479, 0x20758184, 0xD0CEFA65, 0x88F7BE58,
+ 0x4A046826, 0x0FF6F8F3, 0xA09C7F70, 0x5346ABA0, 0x5CE96C28, 0xE176EDA3,
+ 0x6BAC307F, 0x376829D2, 0x85360FA9, 0x17E3FE2A, 0x24B79767, 0xF5A96B20,
+ 0xD6CD2595, 0x68FF1EBF, 0x7555442C, 0xF19F06BE, 0xF9E0659A, 0xEEB9491D,
+ 0x34010718, 0xBB30CAB8, 0xE822FE15, 0x88570983, 0x750E6249, 0xDA627E55,
+ 0x5E76FFA8, 0xB1534546, 0x6D47DE08, 0xEFE9E7D4 };
+ private static final int[] S6 = {
+ 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867, 0xE2337F7C, 0x95DB08E7, 0x016843B4,
+ 0xECED5CBC, 0x325553AC, 0xBF9F0960, 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9,
+ 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732, 0x8989B138, 0x33F14961, 0xC01937BD,
+ 0xF506C6DA, 0xE4625E7E, 0xA308EA99, 0x4E23E33C, 0x79CBD7CC, 0x48A14367,
+ 0xA3149619, 0xFEC94BD5, 0xA114174A, 0xEAA01866, 0xA084DB2D, 0x09A8486F,
+ 0xA888614A, 0x2900AF98, 0x01665991, 0xE1992863, 0xC8F30C60, 0x2E78EF3C,
+ 0xD0D51932, 0xCF0FEC14, 0xF7CA07D2, 0xD0A82072, 0xFD41197E, 0x9305A6B0,
+ 0xE86BE3DA, 0x74BED3CD, 0x372DA53C, 0x4C7F4448, 0xDAB5D440, 0x6DBA0EC3,
+ 0x083919A7, 0x9FBAEED9, 0x49DBCFB0, 0x4E670C53, 0x5C3D9C01, 0x64BDB941,
+ 0x2C0E636A, 0xBA7DD9CD, 0xEA6F7388, 0xE70BC762, 0x35F29ADB, 0x5C4CDD8D,
+ 0xF0D48D8C, 0xB88153E2, 0x08A19866, 0x1AE2EAC8, 0x284CAF89, 0xAA928223,
+ 0x9334BE53, 0x3B3A21BF, 0x16434BE3, 0x9AEA3906, 0xEFE8C36E, 0xF890CDD9,
+ 0x80226DAE, 0xC340A4A3, 0xDF7E9C09, 0xA694A807, 0x5B7C5ECC, 0x221DB3A6,
+ 0x9A69A02F, 0x68818A54, 0xCEB2296F, 0x53C0843A, 0xFE893655, 0x25BFE68A,
+ 0xB4628ABC, 0xCF222EBF, 0x25AC6F48, 0xA9A99387, 0x53BDDB65, 0xE76FFBE7,
+ 0xE967FD78, 0x0BA93563, 0x8E342BC1, 0xE8A11BE9, 0x4980740D, 0xC8087DFC,
+ 0x8DE4BF99, 0xA11101A0, 0x7FD37975, 0xDA5A26C0, 0xE81F994F, 0x9528CD89,
+ 0xFD339FED, 0xB87834BF, 0x5F04456D, 0x22258698, 0xC9C4C83B, 0x2DC156BE,
+ 0x4F628DAA, 0x57F55EC5, 0xE2220ABE, 0xD2916EBF, 0x4EC75B95, 0x24F2C3C0,
+ 0x42D15D99, 0xCD0D7FA0, 0x7B6E27FF, 0xA8DC8AF0, 0x7345C106, 0xF41E232F,
+ 0x35162386, 0xE6EA8926, 0x3333B094, 0x157EC6F2, 0x372B74AF, 0x692573E4,
+ 0xE9A9D848, 0xF3160289, 0x3A62EF1D, 0xA787E238, 0xF3A5F676, 0x74364853,
+ 0x20951063, 0x4576698D, 0xB6FAD407, 0x592AF950, 0x36F73523, 0x4CFB6E87,
+ 0x7DA4CEC0, 0x6C152DAA, 0xCB0396A8, 0xC50DFE5D, 0xFCD707AB, 0x0921C42F,
+ 0x89DFF0BB, 0x5FE2BE78, 0x448F4F33, 0x754613C9, 0x2B05D08D, 0x48B9D585,
+ 0xDC049441, 0xC8098F9B, 0x7DEDE786, 0xC39A3373, 0x42410005, 0x6A091751,
+ 0x0EF3C8A6, 0x890072D6, 0x28207682, 0xA9A9F7BE, 0xBF32679D, 0xD45B5B75,
+ 0xB353FD00, 0xCBB0E358, 0x830F220A, 0x1F8FB214, 0xD372CF08, 0xCC3C4A13,
+ 0x8CF63166, 0x061C87BE, 0x88C98F88, 0x6062E397, 0x47CF8E7A, 0xB6C85283,
+ 0x3CC2ACFB, 0x3FC06976, 0x4E8F0252, 0x64D8314D, 0xDA3870E3, 0x1E665459,
+ 0xC10908F0, 0x513021A5, 0x6C5B68B7, 0x822F8AA0, 0x3007CD3E, 0x74719EEF,
+ 0xDC872681, 0x073340D4, 0x7E432FD9, 0x0C5EC241, 0x8809286C, 0xF592D891,
+ 0x08A930F6, 0x957EF305, 0xB7FBFFBD, 0xC266E96F, 0x6FE4AC98, 0xB173ECC0,
+ 0xBC60B42A, 0x953498DA, 0xFBA1AE12, 0x2D4BD736, 0x0F25FAAB, 0xA4F3FCEB,
+ 0xE2969123, 0x257F0C3D, 0x9348AF49, 0x361400BC, 0xE8816F4A, 0x3814F200,
+ 0xA3F94043, 0x9C7A54C2, 0xBC704F57, 0xDA41E7F9, 0xC25AD33A, 0x54F4A084,
+ 0xB17F5505, 0x59357CBE, 0xEDBD15C8, 0x7F97C5AB, 0xBA5AC7B5, 0xB6F6DEAF,
+ 0x3A479C3A, 0x5302DA25, 0x653D7E6A, 0x54268D49, 0x51A477EA, 0x5017D55B,
+ 0xD7D25D88, 0x44136C76, 0x0404A8C8, 0xB8E5A121, 0xB81A928A, 0x60ED5869,
+ 0x97C55B96, 0xEAEC991B, 0x29935913, 0x01FDB7F1, 0x088E8DFA, 0x9AB6F6F5,
+ 0x3B4CBF9F, 0x4A5DE3AB, 0xE6051D35, 0xA0E1D855, 0xD36B4CF1, 0xF544EDEB,
+ 0xB0E93524, 0xBEBB8FBD, 0xA2D762CF, 0x49C92F54, 0x38B5F331, 0x7128A454,
+ 0x48392905, 0xA65B1DB8, 0x851C97BD, 0xD675CF2F };
+ private static final int[] S7 = {
+ 0x85E04019, 0x332BF567, 0x662DBFFF, 0xCFC65693, 0x2A8D7F6F, 0xAB9BC912,
+ 0xDE6008A1, 0x2028DA1F, 0x0227BCE7, 0x4D642916, 0x18FAC300, 0x50F18B82,
+ 0x2CB2CB11, 0xB232E75C, 0x4B3695F2, 0xB28707DE, 0xA05FBCF6, 0xCD4181E9,
+ 0xE150210C, 0xE24EF1BD, 0xB168C381, 0xFDE4E789, 0x5C79B0D8, 0x1E8BFD43,
+ 0x4D495001, 0x38BE4341, 0x913CEE1D, 0x92A79C3F, 0x089766BE, 0xBAEEADF4,
+ 0x1286BECF, 0xB6EACB19, 0x2660C200, 0x7565BDE4, 0x64241F7A, 0x8248DCA9,
+ 0xC3B3AD66, 0x28136086, 0x0BD8DFA8, 0x356D1CF2, 0x107789BE, 0xB3B2E9CE,
+ 0x0502AA8F, 0x0BC0351E, 0x166BF52A, 0xEB12FF82, 0xE3486911, 0xD34D7516,
+ 0x4E7B3AFF, 0x5F43671B, 0x9CF6E037, 0x4981AC83, 0x334266CE, 0x8C9341B7,
+ 0xD0D854C0, 0xCB3A6C88, 0x47BC2829, 0x4725BA37, 0xA66AD22B, 0x7AD61F1E,
+ 0x0C5CBAFA, 0x4437F107, 0xB6E79962, 0x42D2D816, 0x0A961288, 0xE1A5C06E,
+ 0x13749E67, 0x72FC081A, 0xB1D139F7, 0xF9583745, 0xCF19DF58, 0xBEC3F756,
+ 0xC06EBA30, 0x07211B24, 0x45C28829, 0xC95E317F, 0xBC8EC511, 0x38BC46E9,
+ 0xC6E6FA14, 0xBAE8584A, 0xAD4EBC46, 0x468F508B, 0x7829435F, 0xF124183B,
+ 0x821DBA9F, 0xAFF60FF4, 0xEA2C4E6D, 0x16E39264, 0x92544A8B, 0x009B4FC3,
+ 0xABA68CED, 0x9AC96F78, 0x06A5B79A, 0xB2856E6E, 0x1AEC3CA9, 0xBE838688,
+ 0x0E0804E9, 0x55F1BE56, 0xE7E5363B, 0xB3A1F25D, 0xF7DEBB85, 0x61FE033C,
+ 0x16746233, 0x3C034C28, 0xDA6D0C74, 0x79AAC56C, 0x3CE4E1AD, 0x51F0C802,
+ 0x98F8F35A, 0x1626A49F, 0xEED82B29, 0x1D382FE3, 0x0C4FB99A, 0xBB325778,
+ 0x3EC6D97B, 0x6E77A6A9, 0xCB658B5C, 0xD45230C7, 0x2BD1408B, 0x60C03EB7,
+ 0xB9068D78, 0xA33754F4, 0xF430C87D, 0xC8A71302, 0xB96D8C32, 0xEBD4E7BE,
+ 0xBE8B9D2D, 0x7979FB06, 0xE7225308, 0x8B75CF77, 0x11EF8DA4, 0xE083C858,
+ 0x8D6B786F, 0x5A6317A6, 0xFA5CF7A0, 0x5DDA0033, 0xF28EBFB0, 0xF5B9C310,
+ 0xA0EAC280, 0x08B9767A, 0xA3D9D2B0, 0x79D34217, 0x021A718D, 0x9AC6336A,
+ 0x2711FD60, 0x438050E3, 0x069908A8, 0x3D7FEDC4, 0x826D2BEF, 0x4EEB8476,
+ 0x488DCF25, 0x36C9D566, 0x28E74E41, 0xC2610ACA, 0x3D49A9CF, 0xBAE3B9DF,
+ 0xB65F8DE6, 0x92AEAF64, 0x3AC7D5E6, 0x9EA80509, 0xF22B017D, 0xA4173F70,
+ 0xDD1E16C3, 0x15E0D7F9, 0x50B1B887, 0x2B9F4FD5, 0x625ABA82, 0x6A017962,
+ 0x2EC01B9C, 0x15488AA9, 0xD716E740, 0x40055A2C, 0x93D29A22, 0xE32DBF9A,
+ 0x058745B9, 0x3453DC1E, 0xD699296E, 0x496CFF6F, 0x1C9F4986, 0xDFE2ED07,
+ 0xB87242D1, 0x19DE7EAE, 0x053E561A, 0x15AD6F8C, 0x66626C1C, 0x7154C24C,
+ 0xEA082B2A, 0x93EB2939, 0x17DCB0F0, 0x58D4F2AE, 0x9EA294FB, 0x52CF564C,
+ 0x9883FE66, 0x2EC40581, 0x763953C3, 0x01D6692E, 0xD3A0C108, 0xA1E7160E,
+ 0xE4F2DFA6, 0x693ED285, 0x74904698, 0x4C2B0EDD, 0x4F757656, 0x5D393378,
+ 0xA132234F, 0x3D321C5D, 0xC3F5E194, 0x4B269301, 0xC79F022F, 0x3C997E7E,
+ 0x5E4F9504, 0x3FFAFBBD, 0x76F7AD0E, 0x296693F4, 0x3D1FCE6F, 0xC61E45BE,
+ 0xD3B5AB34, 0xF72BF9B7, 0x1B0434C0, 0x4E72B567, 0x5592A33D, 0xB5229301,
+ 0xCFD2A87F, 0x60AEB767, 0x1814386B, 0x30BCC33D, 0x38A0C07D, 0xFD1606F2,
+ 0xC363519B, 0x589DD390, 0x5479F8E6, 0x1CB8D647, 0x97FD61A9, 0xEA7759F4,
+ 0x2D57539D, 0x569A58CF, 0xE84E63AD, 0x462E1B78, 0x6580F87E, 0xF3817914,
+ 0x91DA55F4, 0x40A230F3, 0xD1988F35, 0xB6E318D2, 0x3FFA50BC, 0x3D40F021,
+ 0xC3C0BDAE, 0x4958C24C, 0x518F36B2, 0x84B1D370, 0x0FEDCE83, 0x878DDADA,
+ 0xF2A279C7, 0x94E01BE8, 0x90716F4B, 0x954B8AA3 };
+ private static final int[] S8 = {
+ 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD, 0x35648095, 0x7789F8B7, 0xE6C1121B,
+ 0x0E241600, 0x052CE8B5, 0x11A9CFB0, 0xE5952F11, 0xECE7990A, 0x9386D174,
+ 0x2A42931C, 0x76E38111, 0xB12DEF3A, 0x37DDDDFC, 0xDE9ADEB1, 0x0A0CC32C,
+ 0xBE197029, 0x84A00940, 0xBB243A0F, 0xB4D137CF, 0xB44E79F0, 0x049EEDFD,
+ 0x0B15A15D, 0x480D3168, 0x8BBBDE5A, 0x669DED42, 0xC7ECE831, 0x3F8F95E7,
+ 0x72DF191B, 0x7580330D, 0x94074251, 0x5C7DCDFA, 0xABBE6D63, 0xAA402164,
+ 0xB301D40A, 0x02E7D1CA, 0x53571DAE, 0x7A3182A2, 0x12A8DDEC, 0xFDAA335D,
+ 0x176F43E8, 0x71FB46D4, 0x38129022, 0xCE949AD4, 0xB84769AD, 0x965BD862,
+ 0x82F3D055, 0x66FB9767, 0x15B80B4E, 0x1D5B47A0, 0x4CFDE06F, 0xC28EC4B8,
+ 0x57E8726E, 0x647A78FC, 0x99865D44, 0x608BD593, 0x6C200E03, 0x39DC5FF6,
+ 0x5D0B00A3, 0xAE63AFF2, 0x7E8BD632, 0x70108C0C, 0xBBD35049, 0x2998DF04,
+ 0x980CF42A, 0x9B6DF491, 0x9E7EDD53, 0x06918548, 0x58CB7E07, 0x3B74EF2E,
+ 0x522FFFB1, 0xD24708CC, 0x1C7E27CD, 0xA4EB215B, 0x3CF1D2E2, 0x19B47A38,
+ 0x424F7618, 0x35856039, 0x9D17DEE7, 0x27EB35E6, 0xC9AFF67B, 0x36BAF5B8,
+ 0x09C467CD, 0xC18910B1, 0xE11DBF7B, 0x06CD1AF8, 0x7170C608, 0x2D5E3354,
+ 0xD4DE495A, 0x64C6D006, 0xBCC0C62C, 0x3DD00DB3, 0x708F8F34, 0x77D51B42,
+ 0x264F620F, 0x24B8D2BF, 0x15C1B79E, 0x46A52564, 0xF8D7E54E, 0x3E378160,
+ 0x7895CDA5, 0x859C15A5, 0xE6459788, 0xC37BC75F, 0xDB07BA0C, 0x0676A3AB,
+ 0x7F229B1E, 0x31842E7B, 0x24259FD7, 0xF8BEF472, 0x835FFCB8, 0x6DF4C1F2,
+ 0x96F5B195, 0xFD0AF0FC, 0xB0FE134C, 0xE2506D3D, 0x4F9B12EA, 0xF215F225,
+ 0xA223736F, 0x9FB4C428, 0x25D04979, 0x34C713F8, 0xC4618187, 0xEA7A6E98,
+ 0x7CD16EFC, 0x1436876C, 0xF1544107, 0xBEDEEE14, 0x56E9AF27, 0xA04AA441,
+ 0x3CF7C899, 0x92ECBAE6, 0xDD67016D, 0x151682EB, 0xA842EEDF, 0xFDBA60B4,
+ 0xF1907B75, 0x20E3030F, 0x24D8C29E, 0xE139673B, 0xEFA63FB8, 0x71873054,
+ 0xB6F2CF3B, 0x9F326442, 0xCB15A4CC, 0xB01A4504, 0xF1E47D8D, 0x844A1BE5,
+ 0xBAE7DFDC, 0x42CBDA70, 0xCD7DAE0A, 0x57E85B7A, 0xD53F5AF6, 0x20CF4D8C,
+ 0xCEA4D428, 0x79D130A4, 0x3486EBFB, 0x33D3CDDC, 0x77853B53, 0x37EFFCB5,
+ 0xC5068778, 0xE580B3E6, 0x4E68B8F4, 0xC5C8B37E, 0x0D809EA2, 0x398FEB7C,
+ 0x132A4F94, 0x43B7950E, 0x2FEE7D1C, 0x223613BD, 0xDD06CAA2, 0x37DF932B,
+ 0xC4248289, 0xACF3EBC3, 0x5715F6B7, 0xEF3478DD, 0xF267616F, 0xC148CBE4,
+ 0x9052815E, 0x5E410FAB, 0xB48A2465, 0x2EDA7FA4, 0xE87B40E4, 0xE98EA084,
+ 0x5889E9E1, 0xEFD390FC, 0xDD07D35B, 0xDB485694, 0x38D7E5B2, 0x57720101,
+ 0x730EDEBC, 0x5B643113, 0x94917E4F, 0x503C2FBA, 0x646F1282, 0x7523D24A,
+ 0xE0779695, 0xF9C17A8F, 0x7A5B2121, 0xD187B896, 0x29263A4D, 0xBA510CDF,
+ 0x81F47C9F, 0xAD1163ED, 0xEA7B5965, 0x1A00726E, 0x11403092, 0x00DA6D77,
+ 0x4A0CDD61, 0xAD1F4603, 0x605BDFB0, 0x9EEDC364, 0x22EBE6A8, 0xCEE7D28A,
+ 0xA0E736A0, 0x5564A6B9, 0x10853209, 0xC7EB8F37, 0x2DE705CA, 0x8951570F,
+ 0xDF09822B, 0xBD691A6C, 0xAA12E4F2, 0x87451C0F, 0xE0F6A27A, 0x3ADA4819,
+ 0x4CF1764F, 0x0D771C2B, 0x67CDB156, 0x350D8384, 0x5938FA0F, 0x42399EF3,
+ 0x36997B07, 0x0E84093D, 0x4AA93E61, 0x8360D87B, 0x1FA98B0C, 0x1149382C,
+ 0xE97625A5, 0x0614D1B7, 0x0E25244B, 0x0C768347, 0x589E8D82, 0x0D2059D1,
+ 0xA466BB1E, 0xF8DA0A82, 0x04F19130, 0xBA6E4EC0, 0x99265164, 0x1EE7230D,
+ 0x50B2AD80, 0xEAEE6801, 0x8DB2A283, 0xEA8BF59E };
private static final int _12_ROUNDS = 12;
-
private static final int _16_ROUNDS = 16;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Cast5()
{
super(Registry.CAST5_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
* Assuming the input is a 32-bit block organised as: b31b30b29...b0, this
* method returns an array of 4 Java ints, containing from position 0 onward
@@ -848,26 +485,17 @@ public class Cast5 extends BaseCipher
return new int[] { x >>> 24, (x >>> 16) & 0xFF, (x >>> 8) & 0xFF, x & 0xFF };
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.lang.Cloneable interface implementation ----------------------------
-
public Object clone()
{
Cast5 result = new Cast5();
result.currentBlockSize = this.currentBlockSize;
-
return result;
}
- // IBlockCipherSpi interface implementation --------------------------------
-
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(DEFAULT_BLOCK_SIZE));
-
+ al.add(Integer.valueOf(DEFAULT_BLOCK_SIZE));
return Collections.unmodifiableList(al).iterator();
}
@@ -875,49 +503,43 @@ public class Cast5 extends BaseCipher
{
ArrayList al = new ArrayList();
for (int n = 5; n < 17; n++)
- {
- al.add(new Integer(n));
- }
-
+ al.add(Integer.valueOf(n));
return Collections.unmodifiableList(al).iterator();
}
public Object makeKey(byte[] uk, int bs) throws InvalidKeyException
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
if (uk == null)
- {
- throw new InvalidKeyException("Empty key");
- }
+ throw new InvalidKeyException("Empty key");
int len = uk.length;
if (len < 5 || len > 16)
- {
- throw new InvalidKeyException(
- "Key size (in bytes) is not in the range [5..16]");
- }
-
+ throw new InvalidKeyException("Key size (in bytes) is not in the range [5..16]");
Cast5Key result = new Cast5Key();
result.rounds = (len < 11) ? _12_ROUNDS : _16_ROUNDS;
byte[] kk = new byte[16];
System.arraycopy(uk, 0, kk, 0, len);
-
int z0z1z2z3, z4z5z6z7, z8z9zAzB, zCzDzEzF;
int z0, z1, z2, z3, z4, z5, z6, z7, z8, z9, zA, zB, zC, zD, zE, zF;
int x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, xA, xB, xC, xD, xE, xF;
int[] b;
-
- int x0x1x2x3 = kk[0] << 24 | (kk[1] & 0xFF) << 16 | (kk[2] & 0xFF) << 8
- | (kk[3] & 0xFF);
- int x4x5x6x7 = kk[4] << 24 | (kk[5] & 0xFF) << 16 | (kk[6] & 0xFF) << 8
- | (kk[7] & 0xFF);
- int x8x9xAxB = kk[8] << 24 | (kk[9] & 0xFF) << 16 | (kk[10] & 0xFF) << 8
- | (kk[11] & 0xFF);
- int xCxDxExF = kk[12] << 24 | (kk[13] & 0xFF) << 16 | (kk[14] & 0xFF) << 8
- | (kk[15] & 0xFF);
-
+ int x0x1x2x3 = kk[0 ] << 24
+ | (kk[1 ] & 0xFF) << 16
+ | (kk[2 ] & 0xFF) << 8
+ | (kk[3 ] & 0xFF);
+ int x4x5x6x7 = kk[4 ] << 24
+ | (kk[5 ] & 0xFF) << 16
+ | (kk[6 ] & 0xFF) << 8
+ | (kk[7 ] & 0xFF);
+ int x8x9xAxB = kk[8 ] << 24
+ | (kk[9 ] & 0xFF) << 16
+ | (kk[10] & 0xFF) << 8
+ | (kk[11] & 0xFF);
+ int xCxDxExF = kk[12] << 24
+ | (kk[13] & 0xFF) << 16
+ | (kk[14] & 0xFF) << 8
+ | (kk[15] & 0xFF);
b = unscramble(x0x1x2x3);
x0 = b[0];
x1 = b[1];
@@ -938,7 +560,6 @@ public class Cast5 extends BaseCipher
xD = b[1];
xE = b[2];
xF = b[3];
-
z0z1z2z3 = x0x1x2x3 ^ S5[xD] ^ S6[xF] ^ S7[xC] ^ S8[xE] ^ S7[x8];
b = unscramble(z0z1z2z3);
z0 = b[0];
@@ -963,12 +584,10 @@ public class Cast5 extends BaseCipher
zD = b[1];
zE = b[2];
zF = b[3];
-
result.Km0 = S5[z8] ^ S6[z9] ^ S7[z7] ^ S8[z6] ^ S5[z2];
result.Km1 = S5[zA] ^ S6[zB] ^ S7[z5] ^ S8[z4] ^ S6[z6];
result.Km2 = S5[zC] ^ S6[zD] ^ S7[z3] ^ S8[z2] ^ S7[z9];
result.Km3 = S5[zE] ^ S6[zF] ^ S7[z1] ^ S8[z0] ^ S8[zC];
-
x0x1x2x3 = z8z9zAzB ^ S5[z5] ^ S6[z7] ^ S7[z4] ^ S8[z6] ^ S7[z0];
b = unscramble(x0x1x2x3);
x0 = b[0];
@@ -993,12 +612,10 @@ public class Cast5 extends BaseCipher
xD = b[1];
xE = b[2];
xF = b[3];
-
result.Km4 = S5[x3] ^ S6[x2] ^ S7[xC] ^ S8[xD] ^ S5[x8];
result.Km5 = S5[x1] ^ S6[x0] ^ S7[xE] ^ S8[xF] ^ S6[xD];
result.Km6 = S5[x7] ^ S6[x6] ^ S7[x8] ^ S8[x9] ^ S7[x3];
result.Km7 = S5[x5] ^ S6[x4] ^ S7[xA] ^ S8[xB] ^ S8[x7];
-
z0z1z2z3 = x0x1x2x3 ^ S5[xD] ^ S6[xF] ^ S7[xC] ^ S8[xE] ^ S7[x8];
b = unscramble(z0z1z2z3);
z0 = b[0];
@@ -1023,12 +640,10 @@ public class Cast5 extends BaseCipher
zD = b[1];
zE = b[2];
zF = b[3];
-
result.Km8 = S5[z3] ^ S6[z2] ^ S7[zC] ^ S8[zD] ^ S5[z9];
result.Km9 = S5[z1] ^ S6[z0] ^ S7[zE] ^ S8[zF] ^ S6[zC];
result.Km10 = S5[z7] ^ S6[z6] ^ S7[z8] ^ S8[z9] ^ S7[z2];
result.Km11 = S5[z5] ^ S6[z4] ^ S7[zA] ^ S8[zB] ^ S8[z6];
-
x0x1x2x3 = z8z9zAzB ^ S5[z5] ^ S6[z7] ^ S7[z4] ^ S8[z6] ^ S7[z0];
b = unscramble(x0x1x2x3);
x0 = b[0];
@@ -1053,17 +668,14 @@ public class Cast5 extends BaseCipher
xD = b[1];
xE = b[2];
xF = b[3];
-
result.Km12 = S5[x8] ^ S6[x9] ^ S7[x7] ^ S8[x6] ^ S5[x3];
result.Km13 = S5[xA] ^ S6[xB] ^ S7[x5] ^ S8[x4] ^ S6[x7];
result.Km14 = S5[xC] ^ S6[xD] ^ S7[x3] ^ S8[x2] ^ S7[x8];
result.Km15 = S5[xE] ^ S6[xF] ^ S7[x1] ^ S8[x0] ^ S8[xD];
-
// The remaining half is identical to what is given above, carrying on
// from the last created x0..xF to generate keys K17 - K32. These keys
// will be used as the 'rotation' keys and as such only the five least
// significant bits are to be considered.
-
z0z1z2z3 = x0x1x2x3 ^ S5[xD] ^ S6[xF] ^ S7[xC] ^ S8[xE] ^ S7[x8];
b = unscramble(z0z1z2z3);
z0 = b[0];
@@ -1088,12 +700,10 @@ public class Cast5 extends BaseCipher
zD = b[1];
zE = b[2];
zF = b[3];
-
result.Kr0 = (S5[z8] ^ S6[z9] ^ S7[z7] ^ S8[z6] ^ S5[z2]) & 0x1F;
result.Kr1 = (S5[zA] ^ S6[zB] ^ S7[z5] ^ S8[z4] ^ S6[z6]) & 0x1F;
result.Kr2 = (S5[zC] ^ S6[zD] ^ S7[z3] ^ S8[z2] ^ S7[z9]) & 0x1F;
result.Kr3 = (S5[zE] ^ S6[zF] ^ S7[z1] ^ S8[z0] ^ S8[zC]) & 0x1F;
-
x0x1x2x3 = z8z9zAzB ^ S5[z5] ^ S6[z7] ^ S7[z4] ^ S8[z6] ^ S7[z0];
b = unscramble(x0x1x2x3);
x0 = b[0];
@@ -1118,12 +728,10 @@ public class Cast5 extends BaseCipher
xD = b[1];
xE = b[2];
xF = b[3];
-
result.Kr4 = (S5[x3] ^ S6[x2] ^ S7[xC] ^ S8[xD] ^ S5[x8]) & 0x1F;
result.Kr5 = (S5[x1] ^ S6[x0] ^ S7[xE] ^ S8[xF] ^ S6[xD]) & 0x1F;
result.Kr6 = (S5[x7] ^ S6[x6] ^ S7[x8] ^ S8[x9] ^ S7[x3]) & 0x1F;
result.Kr7 = (S5[x5] ^ S6[x4] ^ S7[xA] ^ S8[xB] ^ S8[x7]) & 0x1F;
-
z0z1z2z3 = x0x1x2x3 ^ S5[xD] ^ S6[xF] ^ S7[xC] ^ S8[xE] ^ S7[x8];
b = unscramble(z0z1z2z3);
z0 = b[0];
@@ -1148,12 +756,10 @@ public class Cast5 extends BaseCipher
zD = b[1];
zE = b[2];
zF = b[3];
-
result.Kr8 = (S5[z3] ^ S6[z2] ^ S7[zC] ^ S8[zD] ^ S5[z9]) & 0x1F;
result.Kr9 = (S5[z1] ^ S6[z0] ^ S7[zE] ^ S8[zF] ^ S6[zC]) & 0x1F;
result.Kr10 = (S5[z7] ^ S6[z6] ^ S7[z8] ^ S8[z9] ^ S7[z2]) & 0x1F;
result.Kr11 = (S5[z5] ^ S6[z4] ^ S7[zA] ^ S8[zB] ^ S8[z6]) & 0x1F;
-
x0x1x2x3 = z8z9zAzB ^ S5[z5] ^ S6[z7] ^ S7[z4] ^ S8[z6] ^ S7[z0];
b = unscramble(x0x1x2x3);
x0 = b[0];
@@ -1178,23 +784,19 @@ public class Cast5 extends BaseCipher
xD = b[1];
xE = b[2];
xF = b[3];
-
result.Kr12 = (S5[x8] ^ S6[x9] ^ S7[x7] ^ S8[x6] ^ S5[x3]) & 0x1F;
result.Kr13 = (S5[xA] ^ S6[xB] ^ S7[x5] ^ S8[x4] ^ S6[x7]) & 0x1F;
result.Kr14 = (S5[xC] ^ S6[xD] ^ S7[x3] ^ S8[x2] ^ S7[x8]) & 0x1F;
result.Kr15 = (S5[xE] ^ S6[xF] ^ S7[x1] ^ S8[x0] ^ S8[xD]) & 0x1F;
-
return result;
}
/**
- * <p>The full encryption algorithm is given in the following four steps.</p>
- *
+ * The full encryption algorithm is given in the following four steps.
* <pre>
* INPUT: plaintext m1...m64; key K = k1...k128.
* OUTPUT: ciphertext c1...c64.
* </pre>
- *
* <ol>
* <li>(key schedule) Compute 16 pairs of subkeys {Kmi, Kri} from a user
* key (see makeKey() method).</li>
@@ -1210,13 +812,12 @@ public class Cast5 extends BaseCipher
* <li>c1...c64 <-- (R16,L16). (Exchange final blocks L16, R16 and
* concatenate to form the ciphertext.)</li>
* </ol>
- *
- * <p>Decryption is identical to the encryption algorithm given above, except
+ * <p>
+ * Decryption is identical to the encryption algorithm given above, except
* that the rounds (and therefore the subkey pairs) are used in reverse order
- * to compute (L0,R0) from (R16,L16).</p>
- *
- * <p>Looking at the iterations/rounds in pairs we have:</p>
- *
+ * to compute (L0,R0) from (R16,L16).
+ * <p>
+ * Looking at the iterations/rounds in pairs we have:
* <pre>
* (1a) Li = Ri-1;
* (1b) Ri = Li-1 ^ Fi(Ri-1);
@@ -1249,16 +850,16 @@ public class Cast5 extends BaseCipher
public void encrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
Cast5Key K = (Cast5Key) k;
-
- int L = (in[i++] & 0xFF) << 24 | (in[i++] & 0xFF) << 16
- | (in[i++] & 0xFF) << 8 | in[i++] & 0xFF;
- int R = (in[i++] & 0xFF) << 24 | (in[i++] & 0xFF) << 16
- | (in[i++] & 0xFF) << 8 | in[i] & 0xFF;
-
+ int L = (in[i++] & 0xFF) << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | in[i++] & 0xFF;
+ int R = (in[i++] & 0xFF) << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | in[i ] & 0xFF;
L ^= f1(R, K.Km0, K.Kr0);
R ^= f2(L, K.Km1, K.Kr1); // round 2
L ^= f3(R, K.Km2, K.Kr2);
@@ -1278,30 +879,29 @@ public class Cast5 extends BaseCipher
L ^= f3(R, K.Km14, K.Kr14);
R ^= f1(L, K.Km15, K.Kr15); // round 16
}
-
- out[j++] = (byte) (R >>> 24);
- out[j++] = (byte) (R >>> 16);
- out[j++] = (byte) (R >>> 8);
+ out[j++] = (byte)(R >>> 24);
+ out[j++] = (byte)(R >>> 16);
+ out[j++] = (byte)(R >>> 8);
out[j++] = (byte) R;
- out[j++] = (byte) (L >>> 24);
- out[j++] = (byte) (L >>> 16);
- out[j++] = (byte) (L >>> 8);
- out[j] = (byte) L;
+ out[j++] = (byte)(L >>> 24);
+ out[j++] = (byte)(L >>> 16);
+ out[j++] = (byte)(L >>> 8);
+ out[j ] = (byte) L;
}
public void decrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
Cast5Key K = (Cast5Key) k;
-
- int L = (in[i++] & 0xFF) << 24 | (in[i++] & 0xFF) << 16
- | (in[i++] & 0xFF) << 8 | in[i++] & 0xFF;
- int R = (in[i++] & 0xFF) << 24 | (in[i++] & 0xFF) << 16
- | (in[i++] & 0xFF) << 8 | in[i] & 0xFF;
-
+ int L = (in[i++] & 0xFF) << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | in[i++] & 0xFF;
+ int R = (in[i++] & 0xFF) << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | in[i ] & 0xFF;
if (K.rounds == _16_ROUNDS)
{
L ^= f1(R, K.Km15, K.Kr15);
@@ -1321,15 +921,14 @@ public class Cast5 extends BaseCipher
R ^= f3(L, K.Km2, K.Kr2);
L ^= f2(R, K.Km1, K.Kr1);
R ^= f1(L, K.Km0, K.Kr0);
-
- out[j++] = (byte) (R >>> 24);
- out[j++] = (byte) (R >>> 16);
- out[j++] = (byte) (R >>> 8);
+ out[j++] = (byte)(R >>> 24);
+ out[j++] = (byte)(R >>> 16);
+ out[j++] = (byte)(R >>> 8);
out[j++] = (byte) R;
- out[j++] = (byte) (L >>> 24);
- out[j++] = (byte) (L >>> 16);
- out[j++] = (byte) (L >>> 8);
- out[j] = (byte) L;
+ out[j++] = (byte)(L >>> 24);
+ out[j++] = (byte)(L >>> 16);
+ out[j++] = (byte)(L >>> 8);
+ out[j ] = (byte) L;
}
public boolean selfTest()
@@ -1338,54 +937,51 @@ public class Cast5 extends BaseCipher
{
boolean result = super.selfTest(); // do symmetry tests
if (result)
- {
- result = testKat(KAT_KEY, KAT_CT, KAT_PT);
- }
+ result = testKat(KAT_KEY, KAT_CT, KAT_PT);
valid = Boolean.valueOf(result);
}
return valid.booleanValue();
}
- // helper methods ----------------------------------------------------------
-
private final int f1(int I, int m, int r)
{
I = m + I;
I = I << r | I >>> (32 - r);
- return (((S1[(I >>> 24) & 0xFF]) ^ S2[(I >>> 16) & 0xFF]) - S3[(I >>> 8) & 0xFF])
- + S4[I & 0xFF];
+ return (((S1[(I >>> 24) & 0xFF])
+ ^ S2[(I >>> 16) & 0xFF])
+ - S3[(I >>> 8) & 0xFF])
+ + S4[ I & 0xFF];
}
private final int f2(int I, int m, int r)
{
I = m ^ I;
I = I << r | I >>> (32 - r);
- return (((S1[(I >>> 24) & 0xFF]) - S2[(I >>> 16) & 0xFF]) + S3[(I >>> 8) & 0xFF])
- ^ S4[I & 0xFF];
+ return (((S1[(I >>> 24) & 0xFF])
+ - S2[(I >>> 16) & 0xFF])
+ + S3[(I >>> 8) & 0xFF])
+ ^ S4[ I & 0xFF];
}
private final int f3(int I, int m, int r)
{
I = m - I;
I = I << r | I >>> (32 - r);
- return (((S1[(I >>> 24) & 0xFF]) + S2[(I >>> 16) & 0xFF]) ^ S3[(I >>> 8) & 0xFF])
- - S4[I & 0xFF];
+ return (((S1[(I >>> 24) & 0xFF])
+ + S2[(I >>> 16) & 0xFF])
+ ^ S3[(I >>> 8) & 0xFF])
+ - S4[ I & 0xFF];
}
- // Inner class(es)
- // =========================================================================
-
/** An opaque CAST5 key object. */
private class Cast5Key
{
int rounds;
-
/** Masking session keys. */
- int Km0, Km1, Km2, Km3, Km4, Km5, Km6, Km7, Km8, Km9, Km10, Km11, Km12,
- Km13, Km14, Km15;
-
+ int Km0, Km1, Km2, Km3, Km4, Km5, Km6, Km7,
+ Km8, Km9, Km10, Km11, Km12, Km13, Km14, Km15;
/** Rotation session keys. */
- int Kr0, Kr1, Kr2, Kr3, Kr4, Kr5, Kr6, Kr7, Kr8, Kr9, Kr10, Kr11, Kr12,
- Kr13, Kr14, Kr15;
+ int Kr0, Kr1, Kr2, Kr3, Kr4, Kr5, Kr6, Kr7,
+ Kr8, Kr9, Kr10, Kr11, Kr12, Kr13, Kr14, Kr15;
}
}
diff --git a/gnu/javax/crypto/cipher/CipherFactory.java b/gnu/javax/crypto/cipher/CipherFactory.java
index 082bfb8fa..d6bb42253 100644
--- a/gnu/javax/crypto/cipher/CipherFactory.java
+++ b/gnu/javax/crypto/cipher/CipherFactory.java
@@ -45,105 +45,69 @@ import java.util.HashSet;
import java.util.Set;
/**
- * <p>A <i>Factory</i> to instantiate symmetric block cipher instances.</p>
+ * A <i>Factory</i> to instantiate symmetric block cipher instances.
*/
-public class CipherFactory implements Registry
+public class CipherFactory
+ implements Registry
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial constructor to enforce Singleton pattern. */
private CipherFactory()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns an instance of a block cipher given its name.</p>
- *
+ * Returns an instance of a block cipher given its name.
+ *
* @param name the case-insensitive name of the symmetric-key block cipher
- * algorithm.
+ * algorithm.
* @return an instance of the designated cipher algorithm, or
- * <code>null</code> if none is found.
- * @exception InternalError if the implementation does not pass its
- * self-test.
+ * <code>null</code> if none is found.
+ * @exception InternalError if the implementation does not pass its self-test.
*/
public static final IBlockCipher getInstance(String name)
{
if (name == null)
- {
- return null;
- }
-
+ return null;
name = name.trim();
IBlockCipher result = null;
if (name.equalsIgnoreCase(ANUBIS_CIPHER))
- {
- result = new Anubis();
- }
+ result = new Anubis();
else if (name.equalsIgnoreCase(BLOWFISH_CIPHER))
- {
- result = new Blowfish();
- }
+ result = new Blowfish();
else if (name.equalsIgnoreCase(DES_CIPHER))
- {
- result = new DES();
- }
+ result = new DES();
else if (name.equalsIgnoreCase(KHAZAD_CIPHER))
- {
- result = new Khazad();
- }
+ result = new Khazad();
else if (name.equalsIgnoreCase(RIJNDAEL_CIPHER)
|| name.equalsIgnoreCase(AES_CIPHER))
- {
- result = new Rijndael();
- }
+ result = new Rijndael();
else if (name.equalsIgnoreCase(SERPENT_CIPHER))
- {
- result = new Serpent();
- }
+ result = new Serpent();
else if (name.equalsIgnoreCase(SQUARE_CIPHER))
- {
- result = new Square();
- }
+ result = new Square();
else if (name.equalsIgnoreCase(TRIPLEDES_CIPHER)
|| name.equalsIgnoreCase(DESEDE_CIPHER))
- {
- result = new TripleDES();
- }
+ result = new TripleDES();
else if (name.equalsIgnoreCase(TWOFISH_CIPHER))
- {
- result = new Twofish();
- }
+ result = new Twofish();
else if (name.equalsIgnoreCase(CAST5_CIPHER)
- || (name.equalsIgnoreCase(CAST128_CIPHER) || (name.equalsIgnoreCase(CAST_128_CIPHER))))
- {
- result = new Cast5();
- }
+ || (name.equalsIgnoreCase(CAST128_CIPHER)
+ || (name.equalsIgnoreCase(CAST_128_CIPHER))))
+ result = new Cast5();
else if (name.equalsIgnoreCase(NULL_CIPHER))
- {
- result = new NullCipher();
- }
+ result = new NullCipher();
- if (result != null && !result.selfTest())
- {
- throw new InternalError(result.name());
- }
+ if (result != null && ! result.selfTest())
+ throw new InternalError(result.name());
return result;
}
/**
- * <p>Returns a {@link Set} of symmetric key block cipher implementation
- * names supported by this <i>Factory</i>.</p>
- *
+ * Returns a {@link Set} of symmetric key block cipher implementation names
+ * supported by this <i>Factory</i>.
+ *
* @return a {@link Set} of block cipher names (Strings).
*/
public static final Set getNames()
@@ -160,10 +124,6 @@ public class CipherFactory implements Registry
hs.add(TWOFISH_CIPHER);
hs.add(CAST5_CIPHER);
hs.add(NULL_CIPHER);
-
return Collections.unmodifiableSet(hs);
}
-
- // Instance methods
- // -------------------------------------------------------------------------
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/DES.java b/gnu/javax/crypto/cipher/DES.java
index 8b7627cea..2bb897177 100644
--- a/gnu/javax/crypto/cipher/DES.java
+++ b/gnu/javax/crypto/cipher/DES.java
@@ -48,353 +48,169 @@ import java.util.Collections;
import java.util.Iterator;
/**
- * <p>The Data Encryption Standard. DES is a 64-bit block cipher with a 56-bit
+ * The Data Encryption Standard. DES is a 64-bit block cipher with a 56-bit
* key, developed by IBM in the 1970's for the standardization process begun by
- * the National Bureau of Standards (now NIST).</p>
- *
- * <p>New applications should not use DES except for compatibility.</p>
- *
- * <p>This version is based upon the description and sample implementation in
- * [1].</p>
- *
- * <p>References:</p>
+ * the National Bureau of Standards (now NIST).
+ * <p>
+ * New applications should not use DES except for compatibility.
+ * <p>
+ * This version is based upon the description and sample implementation in
+ * [1].
+ * <p>
+ * References:
* <ol>
* <li>Bruce Schneier, <i>Applied Cryptography: Protocols, Algorithms, and
* Source Code in C, Second Edition</i>. (1996 John Wiley and Sons) ISBN
* 0-471-11709-9. Pages 265--301, 623--632.</li>
* </ol>
*/
-public class DES extends BaseCipher
+public class DES
+ extends BaseCipher
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** DES operates on 64 bit blocks. */
public static final int BLOCK_SIZE = 8;
-
/** DES uses 56 bits of a 64 bit parity-adjusted key. */
public static final int KEY_SIZE = 8;
-
// S-Boxes 1 through 8.
- private static final int[] SP1 = new int[] { 0x01010400, 0x00000000,
- 0x00010000, 0x01010404,
- 0x01010004, 0x00010404,
- 0x00000004, 0x00010000,
- 0x00000400, 0x01010400,
- 0x01010404, 0x00000400,
- 0x01000404, 0x01010004,
- 0x01000000, 0x00000004,
- 0x00000404, 0x01000400,
- 0x01000400, 0x00010400,
- 0x00010400, 0x01010000,
- 0x01010000, 0x01000404,
- 0x00010004, 0x01000004,
- 0x01000004, 0x00010004,
- 0x00000000, 0x00000404,
- 0x00010404, 0x01000000,
- 0x00010000, 0x01010404,
- 0x00000004, 0x01010000,
- 0x01010400, 0x01000000,
- 0x01000000, 0x00000400,
- 0x01010004, 0x00010000,
- 0x00010400, 0x01000004,
- 0x00000400, 0x00000004,
- 0x01000404, 0x00010404,
- 0x01010404, 0x00010004,
- 0x01010000, 0x01000404,
- 0x01000004, 0x00000404,
- 0x00010404, 0x01010400,
- 0x00000404, 0x01000400,
- 0x01000400, 0x00000000,
- 0x00010004, 0x00010400,
- 0x00000000, 0x01010004 };
-
- private static final int[] SP2 = new int[] { 0x80108020, 0x80008000,
- 0x00008000, 0x00108020,
- 0x00100000, 0x00000020,
- 0x80100020, 0x80008020,
- 0x80000020, 0x80108020,
- 0x80108000, 0x80000000,
- 0x80008000, 0x00100000,
- 0x00000020, 0x80100020,
- 0x00108000, 0x00100020,
- 0x80008020, 0x00000000,
- 0x80000000, 0x00008000,
- 0x00108020, 0x80100000,
- 0x00100020, 0x80000020,
- 0x00000000, 0x00108000,
- 0x00008020, 0x80108000,
- 0x80100000, 0x00008020,
- 0x00000000, 0x00108020,
- 0x80100020, 0x00100000,
- 0x80008020, 0x80100000,
- 0x80108000, 0x00008000,
- 0x80100000, 0x80008000,
- 0x00000020, 0x80108020,
- 0x00108020, 0x00000020,
- 0x00008000, 0x80000000,
- 0x00008020, 0x80108000,
- 0x00100000, 0x80000020,
- 0x00100020, 0x80008020,
- 0x80000020, 0x00100020,
- 0x00108000, 0x00000000,
- 0x80008000, 0x00008020,
- 0x80000000, 0x80100020,
- 0x80108020, 0x00108000 };
-
- private static final int[] SP3 = new int[] { 0x00000208, 0x08020200,
- 0x00000000, 0x08020008,
- 0x08000200, 0x00000000,
- 0x00020208, 0x08000200,
- 0x00020008, 0x08000008,
- 0x08000008, 0x00020000,
- 0x08020208, 0x00020008,
- 0x08020000, 0x00000208,
- 0x08000000, 0x00000008,
- 0x08020200, 0x00000200,
- 0x00020200, 0x08020000,
- 0x08020008, 0x00020208,
- 0x08000208, 0x00020200,
- 0x00020000, 0x08000208,
- 0x00000008, 0x08020208,
- 0x00000200, 0x08000000,
- 0x08020200, 0x08000000,
- 0x00020008, 0x00000208,
- 0x00020000, 0x08020200,
- 0x08000200, 0x00000000,
- 0x00000200, 0x00020008,
- 0x08020208, 0x08000200,
- 0x08000008, 0x00000200,
- 0x00000000, 0x08020008,
- 0x08000208, 0x00020000,
- 0x08000000, 0x08020208,
- 0x00000008, 0x00020208,
- 0x00020200, 0x08000008,
- 0x08020000, 0x08000208,
- 0x00000208, 0x08020000,
- 0x00020208, 0x00000008,
- 0x08020008, 0x00020200 };
-
- private static final int[] SP4 = new int[] { 0x00802001, 0x00002081,
- 0x00002081, 0x00000080,
- 0x00802080, 0x00800081,
- 0x00800001, 0x00002001,
- 0x00000000, 0x00802000,
- 0x00802000, 0x00802081,
- 0x00000081, 0x00000000,
- 0x00800080, 0x00800001,
- 0x00000001, 0x00002000,
- 0x00800000, 0x00802001,
- 0x00000080, 0x00800000,
- 0x00002001, 0x00002080,
- 0x00800081, 0x00000001,
- 0x00002080, 0x00800080,
- 0x00002000, 0x00802080,
- 0x00802081, 0x00000081,
- 0x00800080, 0x00800001,
- 0x00802000, 0x00802081,
- 0x00000081, 0x00000000,
- 0x00000000, 0x00802000,
- 0x00002080, 0x00800080,
- 0x00800081, 0x00000001,
- 0x00802001, 0x00002081,
- 0x00002081, 0x00000080,
- 0x00802081, 0x00000081,
- 0x00000001, 0x00002000,
- 0x00800001, 0x00002001,
- 0x00802080, 0x00800081,
- 0x00002001, 0x00002080,
- 0x00800000, 0x00802001,
- 0x00000080, 0x00800000,
- 0x00002000, 0x00802080 };
-
- private static final int[] SP5 = new int[] { 0x00000100, 0x02080100,
- 0x02080000, 0x42000100,
- 0x00080000, 0x00000100,
- 0x40000000, 0x02080000,
- 0x40080100, 0x00080000,
- 0x02000100, 0x40080100,
- 0x42000100, 0x42080000,
- 0x00080100, 0x40000000,
- 0x02000000, 0x40080000,
- 0x40080000, 0x00000000,
- 0x40000100, 0x42080100,
- 0x42080100, 0x02000100,
- 0x42080000, 0x40000100,
- 0x00000000, 0x42000000,
- 0x02080100, 0x02000000,
- 0x42000000, 0x00080100,
- 0x00080000, 0x42000100,
- 0x00000100, 0x02000000,
- 0x40000000, 0x02080000,
- 0x42000100, 0x40080100,
- 0x02000100, 0x40000000,
- 0x42080000, 0x02080100,
- 0x40080100, 0x00000100,
- 0x02000000, 0x42080000,
- 0x42080100, 0x00080100,
- 0x42000000, 0x42080100,
- 0x02080000, 0x00000000,
- 0x40080000, 0x42000000,
- 0x00080100, 0x02000100,
- 0x40000100, 0x00080000,
- 0x00000000, 0x40080000,
- 0x02080100, 0x40000100 };
-
- private static final int[] SP6 = new int[] { 0x20000010, 0x20400000,
- 0x00004000, 0x20404010,
- 0x20400000, 0x00000010,
- 0x20404010, 0x00400000,
- 0x20004000, 0x00404010,
- 0x00400000, 0x20000010,
- 0x00400010, 0x20004000,
- 0x20000000, 0x00004010,
- 0x00000000, 0x00400010,
- 0x20004010, 0x00004000,
- 0x00404000, 0x20004010,
- 0x00000010, 0x20400010,
- 0x20400010, 0x00000000,
- 0x00404010, 0x20404000,
- 0x00004010, 0x00404000,
- 0x20404000, 0x20000000,
- 0x20004000, 0x00000010,
- 0x20400010, 0x00404000,
- 0x20404010, 0x00400000,
- 0x00004010, 0x20000010,
- 0x00400000, 0x20004000,
- 0x20000000, 0x00004010,
- 0x20000010, 0x20404010,
- 0x00404000, 0x20400000,
- 0x00404010, 0x20404000,
- 0x00000000, 0x20400010,
- 0x00000010, 0x00004000,
- 0x20400000, 0x00404010,
- 0x00004000, 0x00400010,
- 0x20004010, 0x00000000,
- 0x20404000, 0x20000000,
- 0x00400010, 0x20004010 };
-
- private static final int[] SP7 = new int[] { 0x00200000, 0x04200002,
- 0x04000802, 0x00000000,
- 0x00000800, 0x04000802,
- 0x00200802, 0x04200800,
- 0x04200802, 0x00200000,
- 0x00000000, 0x04000002,
- 0x00000002, 0x04000000,
- 0x04200002, 0x00000802,
- 0x04000800, 0x00200802,
- 0x00200002, 0x04000800,
- 0x04000002, 0x04200000,
- 0x04200800, 0x00200002,
- 0x04200000, 0x00000800,
- 0x00000802, 0x04200802,
- 0x00200800, 0x00000002,
- 0x04000000, 0x00200800,
- 0x04000000, 0x00200800,
- 0x00200000, 0x04000802,
- 0x04000802, 0x04200002,
- 0x04200002, 0x00000002,
- 0x00200002, 0x04000000,
- 0x04000800, 0x00200000,
- 0x04200800, 0x00000802,
- 0x00200802, 0x04200800,
- 0x00000802, 0x04000002,
- 0x04200802, 0x04200000,
- 0x00200800, 0x00000000,
- 0x00000002, 0x04200802,
- 0x00000000, 0x00200802,
- 0x04200000, 0x00000800,
- 0x04000002, 0x04000800,
- 0x00000800, 0x00200002 };
-
- private static final int[] SP8 = new int[] { 0x10001040, 0x00001000,
- 0x00040000, 0x10041040,
- 0x10000000, 0x10001040,
- 0x00000040, 0x10000000,
- 0x00040040, 0x10040000,
- 0x10041040, 0x00041000,
- 0x10041000, 0x00041040,
- 0x00001000, 0x00000040,
- 0x10040000, 0x10000040,
- 0x10001000, 0x00001040,
- 0x00041000, 0x00040040,
- 0x10040040, 0x10041000,
- 0x00001040, 0x00000000,
- 0x00000000, 0x10040040,
- 0x10000040, 0x10001000,
- 0x00041040, 0x00040000,
- 0x00041040, 0x00040000,
- 0x10041000, 0x00001000,
- 0x00000040, 0x10040040,
- 0x00001000, 0x00041040,
- 0x10001000, 0x00000040,
- 0x10000040, 0x10040000,
- 0x10040040, 0x10000000,
- 0x00040000, 0x10001040,
- 0x00000000, 0x10041040,
- 0x00040040, 0x10000040,
- 0x10040000, 0x10001000,
- 0x10001040, 0x00000000,
- 0x10041040, 0x00041000,
- 0x00041000, 0x00001040,
- 0x00001040, 0x00040040,
- 0x10000000, 0x10041000 };
-
+ private static final int[] SP1 = new int[] {
+ 0x01010400, 0x00000000, 0x00010000, 0x01010404, 0x01010004, 0x00010404,
+ 0x00000004, 0x00010000, 0x00000400, 0x01010400, 0x01010404, 0x00000400,
+ 0x01000404, 0x01010004, 0x01000000, 0x00000004, 0x00000404, 0x01000400,
+ 0x01000400, 0x00010400, 0x00010400, 0x01010000, 0x01010000, 0x01000404,
+ 0x00010004, 0x01000004, 0x01000004, 0x00010004, 0x00000000, 0x00000404,
+ 0x00010404, 0x01000000, 0x00010000, 0x01010404, 0x00000004, 0x01010000,
+ 0x01010400, 0x01000000, 0x01000000, 0x00000400, 0x01010004, 0x00010000,
+ 0x00010400, 0x01000004, 0x00000400, 0x00000004, 0x01000404, 0x00010404,
+ 0x01010404, 0x00010004, 0x01010000, 0x01000404, 0x01000004, 0x00000404,
+ 0x00010404, 0x01010400, 0x00000404, 0x01000400, 0x01000400, 0x00000000,
+ 0x00010004, 0x00010400, 0x00000000, 0x01010004 };
+ private static final int[] SP2 = new int[] {
+ 0x80108020, 0x80008000, 0x00008000, 0x00108020, 0x00100000, 0x00000020,
+ 0x80100020, 0x80008020, 0x80000020, 0x80108020, 0x80108000, 0x80000000,
+ 0x80008000, 0x00100000, 0x00000020, 0x80100020, 0x00108000, 0x00100020,
+ 0x80008020, 0x00000000, 0x80000000, 0x00008000, 0x00108020, 0x80100000,
+ 0x00100020, 0x80000020, 0x00000000, 0x00108000, 0x00008020, 0x80108000,
+ 0x80100000, 0x00008020, 0x00000000, 0x00108020, 0x80100020, 0x00100000,
+ 0x80008020, 0x80100000, 0x80108000, 0x00008000, 0x80100000, 0x80008000,
+ 0x00000020, 0x80108020, 0x00108020, 0x00000020, 0x00008000, 0x80000000,
+ 0x00008020, 0x80108000, 0x00100000, 0x80000020, 0x00100020, 0x80008020,
+ 0x80000020, 0x00100020, 0x00108000, 0x00000000, 0x80008000, 0x00008020,
+ 0x80000000, 0x80100020, 0x80108020, 0x00108000 };
+ private static final int[] SP3 = new int[] {
+ 0x00000208, 0x08020200, 0x00000000, 0x08020008, 0x08000200, 0x00000000,
+ 0x00020208, 0x08000200, 0x00020008, 0x08000008, 0x08000008, 0x00020000,
+ 0x08020208, 0x00020008, 0x08020000, 0x00000208, 0x08000000, 0x00000008,
+ 0x08020200, 0x00000200, 0x00020200, 0x08020000, 0x08020008, 0x00020208,
+ 0x08000208, 0x00020200, 0x00020000, 0x08000208, 0x00000008, 0x08020208,
+ 0x00000200, 0x08000000, 0x08020200, 0x08000000, 0x00020008, 0x00000208,
+ 0x00020000, 0x08020200, 0x08000200, 0x00000000, 0x00000200, 0x00020008,
+ 0x08020208, 0x08000200, 0x08000008, 0x00000200, 0x00000000, 0x08020008,
+ 0x08000208, 0x00020000, 0x08000000, 0x08020208, 0x00000008, 0x00020208,
+ 0x00020200, 0x08000008, 0x08020000, 0x08000208, 0x00000208, 0x08020000,
+ 0x00020208, 0x00000008, 0x08020008, 0x00020200 };
+ private static final int[] SP4 = new int[] {
+ 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802080, 0x00800081,
+ 0x00800001, 0x00002001, 0x00000000, 0x00802000, 0x00802000, 0x00802081,
+ 0x00000081, 0x00000000, 0x00800080, 0x00800001, 0x00000001, 0x00002000,
+ 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002001, 0x00002080,
+ 0x00800081, 0x00000001, 0x00002080, 0x00800080, 0x00002000, 0x00802080,
+ 0x00802081, 0x00000081, 0x00800080, 0x00800001, 0x00802000, 0x00802081,
+ 0x00000081, 0x00000000, 0x00000000, 0x00802000, 0x00002080, 0x00800080,
+ 0x00800081, 0x00000001, 0x00802001, 0x00002081, 0x00002081, 0x00000080,
+ 0x00802081, 0x00000081, 0x00000001, 0x00002000, 0x00800001, 0x00002001,
+ 0x00802080, 0x00800081, 0x00002001, 0x00002080, 0x00800000, 0x00802001,
+ 0x00000080, 0x00800000, 0x00002000, 0x00802080 };
+ private static final int[] SP5 = new int[] {
+ 0x00000100, 0x02080100, 0x02080000, 0x42000100, 0x00080000, 0x00000100,
+ 0x40000000, 0x02080000, 0x40080100, 0x00080000, 0x02000100, 0x40080100,
+ 0x42000100, 0x42080000, 0x00080100, 0x40000000, 0x02000000, 0x40080000,
+ 0x40080000, 0x00000000, 0x40000100, 0x42080100, 0x42080100, 0x02000100,
+ 0x42080000, 0x40000100, 0x00000000, 0x42000000, 0x02080100, 0x02000000,
+ 0x42000000, 0x00080100, 0x00080000, 0x42000100, 0x00000100, 0x02000000,
+ 0x40000000, 0x02080000, 0x42000100, 0x40080100, 0x02000100, 0x40000000,
+ 0x42080000, 0x02080100, 0x40080100, 0x00000100, 0x02000000, 0x42080000,
+ 0x42080100, 0x00080100, 0x42000000, 0x42080100, 0x02080000, 0x00000000,
+ 0x40080000, 0x42000000, 0x00080100, 0x02000100, 0x40000100, 0x00080000,
+ 0x00000000, 0x40080000, 0x02080100, 0x40000100 };
+ private static final int[] SP6 = new int[] {
+ 0x20000010, 0x20400000, 0x00004000, 0x20404010, 0x20400000, 0x00000010,
+ 0x20404010, 0x00400000, 0x20004000, 0x00404010, 0x00400000, 0x20000010,
+ 0x00400010, 0x20004000, 0x20000000, 0x00004010, 0x00000000, 0x00400010,
+ 0x20004010, 0x00004000, 0x00404000, 0x20004010, 0x00000010, 0x20400010,
+ 0x20400010, 0x00000000, 0x00404010, 0x20404000, 0x00004010, 0x00404000,
+ 0x20404000, 0x20000000, 0x20004000, 0x00000010, 0x20400010, 0x00404000,
+ 0x20404010, 0x00400000, 0x00004010, 0x20000010, 0x00400000, 0x20004000,
+ 0x20000000, 0x00004010, 0x20000010, 0x20404010, 0x00404000, 0x20400000,
+ 0x00404010, 0x20404000, 0x00000000, 0x20400010, 0x00000010, 0x00004000,
+ 0x20400000, 0x00404010, 0x00004000, 0x00400010, 0x20004010, 0x00000000,
+ 0x20404000, 0x20000000, 0x00400010, 0x20004010 };
+ private static final int[] SP7 = new int[] {
+ 0x00200000, 0x04200002, 0x04000802, 0x00000000, 0x00000800, 0x04000802,
+ 0x00200802, 0x04200800, 0x04200802, 0x00200000, 0x00000000, 0x04000002,
+ 0x00000002, 0x04000000, 0x04200002, 0x00000802, 0x04000800, 0x00200802,
+ 0x00200002, 0x04000800, 0x04000002, 0x04200000, 0x04200800, 0x00200002,
+ 0x04200000, 0x00000800, 0x00000802, 0x04200802, 0x00200800, 0x00000002,
+ 0x04000000, 0x00200800, 0x04000000, 0x00200800, 0x00200000, 0x04000802,
+ 0x04000802, 0x04200002, 0x04200002, 0x00000002, 0x00200002, 0x04000000,
+ 0x04000800, 0x00200000, 0x04200800, 0x00000802, 0x00200802, 0x04200800,
+ 0x00000802, 0x04000002, 0x04200802, 0x04200000, 0x00200800, 0x00000000,
+ 0x00000002, 0x04200802, 0x00000000, 0x00200802, 0x04200000, 0x00000800,
+ 0x04000002, 0x04000800, 0x00000800, 0x00200002 };
+ private static final int[] SP8 = new int[] {
+ 0x10001040, 0x00001000, 0x00040000, 0x10041040, 0x10000000, 0x10001040,
+ 0x00000040, 0x10000000, 0x00040040, 0x10040000, 0x10041040, 0x00041000,
+ 0x10041000, 0x00041040, 0x00001000, 0x00000040, 0x10040000, 0x10000040,
+ 0x10001000, 0x00001040, 0x00041000, 0x00040040, 0x10040040, 0x10041000,
+ 0x00001040, 0x00000000, 0x00000000, 0x10040040, 0x10000040, 0x10001000,
+ 0x00041040, 0x00040000, 0x00041040, 0x00040000, 0x10041000, 0x00001000,
+ 0x00000040, 0x10040040, 0x00001000, 0x00041040, 0x10001000, 0x00000040,
+ 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x00040000, 0x10001040,
+ 0x00000000, 0x10041040, 0x00040040, 0x10000040, 0x10040000, 0x10001000,
+ 0x10001040, 0x00000000, 0x10041040, 0x00041000, 0x00041000, 0x00001040,
+ 0x00001040, 0x00040040, 0x10000000, 0x10041000 };
/**
* Constants that help in determining whether or not a byte array is parity
* adjusted.
*/
- private static final byte[] PARITY = { 8, 1, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8,
- 0, 2, 8, 0, 8, 8, 0, 8, 0, 0, 8, 8, 0,
- 0, 8, 0, 8, 8, 3, 0, 8, 8, 0, 8, 0, 0,
- 8, 8, 0, 0, 8, 0, 8, 8, 0, 8, 0, 0, 8,
- 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 0, 8, 0,
- 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8,
- 8, 0, 8, 0, 0, 8, 0, 8, 8, 0, 0, 8, 8,
- 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0,
- 0, 8, 8, 0, 8, 0, 0, 8, 0, 8, 8, 0, 8,
- 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0, 0, 8,
- 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8,
- 0, 8, 0, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0,
- 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0, 0,
- 8, 8, 0, 8, 0, 0, 8, 0, 8, 8, 0, 8, 0,
- 0, 8, 8, 0, 0, 8, 0, 8, 8, 0, 8, 0, 0,
- 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 0, 8,
- 0, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0,
- 8, 8, 0, 4, 8, 8, 0, 8, 0, 0, 8, 8, 0,
- 0, 8, 0, 8, 8, 0, 8, 5, 0, 8, 0, 8, 8,
- 0, 0, 8, 8, 0, 8, 0, 6, 8 };
-
+ private static final byte[] PARITY = {
+ 8, 1, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 2, 8,
+ 0, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 3,
+ 0, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0,
+ 8, 0, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 0, 8,
+ 0, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0,
+ 8, 0, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 0, 8,
+ 8, 0, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 0, 8,
+ 0, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0,
+ 0, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0,
+ 8, 0, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 0, 8,
+ 8, 0, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 0, 8,
+ 0, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0,
+ 8, 0, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 0, 8,
+ 0, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0,
+ 4, 8, 8, 0, 8, 0, 0, 8, 8, 0, 0, 8, 0, 8, 8, 0,
+ 8, 5, 0, 8, 0, 8, 8, 0, 0, 8, 8, 0, 8, 0, 6, 8 };
// Key schedule constants.
-
- private static final byte[] ROTARS = { 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19,
- 21, 23, 25, 27, 28 };
-
- private static final byte[] PC1 = { 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41,
- 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
- 10, 2, 59, 51, 43, 35, 62, 54, 46, 38, 30,
- 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5,
- 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11,
- 3 };
-
- private static final byte[] PC2 = { 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20,
- 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19,
- 12, 1, 40, 51, 30, 36, 46, 54, 29, 39, 50,
- 44, 32, 47, 43, 48, 38, 55, 33, 52, 45,
- 41, 49, 35, 28, 31 };
-
+ private static final byte[] ROTARS = {
+ 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28 };
+ private static final byte[] PC1 = {
+ 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1,
+ 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 62, 54, 46, 38,
+ 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36,
+ 28, 20, 12, 4, 27, 19, 11, 3 };
+ private static final byte[] PC2 = {
+ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3,
+ 25, 7, 15, 6, 26, 19, 12, 1, 40, 51, 30, 36, 46, 54, 29, 39,
+ 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
/**
* Weak keys (parity adjusted): If all the bits in each half are either 0
* or 1, then the key used for any cycle of the algorithm is the same as
* all other cycles.
*/
public static final byte[][] WEAK_KEYS = {
- Util.toBytesFromString("0101010101010101"),
- Util.toBytesFromString("01010101FEFEFEFE"),
- Util.toBytesFromString("FEFEFEFE01010101"),
- Util.toBytesFromString("FEFEFEFEFEFEFEFE") };
-
+ Util.toBytesFromString("0101010101010101"),
+ Util.toBytesFromString("01010101FEFEFEFE"),
+ Util.toBytesFromString("FEFEFEFE01010101"),
+ Util.toBytesFromString("FEFEFEFEFEFEFEFE") };
/**
* Semi-weak keys (parity adjusted): Some pairs of keys encrypt plain text
* to identical cipher text. In other words, one key in the pair can decrypt
@@ -403,73 +219,69 @@ public class DES extends BaseCipher
* generated, these semi-weak keys produce only two different sub-keys.
*/
public static final byte[][] SEMIWEAK_KEYS = {
- Util.toBytesFromString("01FE01FE01FE01FE"),
- Util.toBytesFromString("FE01FE01FE01FE01"),
- Util.toBytesFromString("1FE01FE00EF10EF1"),
- Util.toBytesFromString("E01FE01FF10EF10E"),
- Util.toBytesFromString("01E001E001F101F1"),
- Util.toBytesFromString("E001E001F101F101"),
- Util.toBytesFromString("1FFE1FFE0EFE0EFE"),
- Util.toBytesFromString("FE1FFE1FFE0EFE0E"),
- Util.toBytesFromString("011F011F010E010E"),
- Util.toBytesFromString("1F011F010E010E01"),
- Util.toBytesFromString("E0FEE0FEF1FEF1FE"),
- Util.toBytesFromString("FEE0FEE0FEF1FEF1") };
-
+ Util.toBytesFromString("01FE01FE01FE01FE"),
+ Util.toBytesFromString("FE01FE01FE01FE01"),
+ Util.toBytesFromString("1FE01FE00EF10EF1"),
+ Util.toBytesFromString("E01FE01FF10EF10E"),
+ Util.toBytesFromString("01E001E001F101F1"),
+ Util.toBytesFromString("E001E001F101F101"),
+ Util.toBytesFromString("1FFE1FFE0EFE0EFE"),
+ Util.toBytesFromString("FE1FFE1FFE0EFE0E"),
+ Util.toBytesFromString("011F011F010E010E"),
+ Util.toBytesFromString("1F011F010E010E01"),
+ Util.toBytesFromString("E0FEE0FEF1FEF1FE"),
+ Util.toBytesFromString("FEE0FEE0FEF1FEF1") };
/** Possible weak keys (parity adjusted) --produce 4 instead of 16 subkeys. */
public static final byte[][] POSSIBLE_WEAK_KEYS = {
- Util.toBytesFromString("1F1F01010E0E0101"),
- Util.toBytesFromString("011F1F01010E0E01"),
- Util.toBytesFromString("1F01011F0E01010E"),
- Util.toBytesFromString("01011F1F01010E0E"),
- Util.toBytesFromString("E0E00101F1F10101"),
- Util.toBytesFromString("FEFE0101FEFE0101"),
- Util.toBytesFromString("FEE01F01FEF10E01"),
- Util.toBytesFromString("E0FE1F01F1FE0E01"),
- Util.toBytesFromString("FEE0011FFEF1010E"),
- Util.toBytesFromString("E0FE011FF1FE010E"),
- Util.toBytesFromString("E0E01F1FF1F10E0E"),
- Util.toBytesFromString("FEFE1F1FFEFE0E0E"),
- Util.toBytesFromString("1F1F01010E0E0101"),
- Util.toBytesFromString("011F1F01010E0E01"),
- Util.toBytesFromString("1F01011F0E01010E"),
- Util.toBytesFromString("01011F1F01010E0E"),
- Util.toBytesFromString("01E0E00101F1F101"),
- Util.toBytesFromString("1FFEE0010EFEF001"),
- Util.toBytesFromString("1FE0FE010EF1FE01"),
- Util.toBytesFromString("01FEFE0101FEFE01"),
- Util.toBytesFromString("1FE0E01F0EF1F10E"),
- Util.toBytesFromString("01FEE01F01FEF10E"),
- Util.toBytesFromString("01E0FE1F01F1FE0E"),
- Util.toBytesFromString("1FFEFE1F0EFEFE0E"),
-
- Util.toBytesFromString("E00101E0F10101F1"),
- Util.toBytesFromString("FE1F01E0FE0E0EF1"),
- Util.toBytesFromString("FE011FE0FE010EF1"),
- Util.toBytesFromString("E01F1FE0F10E0EF1"),
- Util.toBytesFromString("FE0101FEFE0101FE"),
- Util.toBytesFromString("E01F01FEF10E01FE"),
- Util.toBytesFromString("E0011FFEF1010EFE"),
- Util.toBytesFromString("FE1F1FFEFE0E0EFE"),
- Util.toBytesFromString("1FFE01E00EFE01F1"),
- Util.toBytesFromString("01FE1FE001FE0EF1"),
- Util.toBytesFromString("1FE001FE0EF101FE"),
- Util.toBytesFromString("01E01FFE01F10EFE"),
- Util.toBytesFromString("0101E0E00101F1F1"),
- Util.toBytesFromString("1F1FE0E00E0EF1F1"),
- Util.toBytesFromString("1F01FEE00E01FEF1"),
- Util.toBytesFromString("011FFEE0010EFEF1"),
- Util.toBytesFromString("1F01E0FE0E01F1FE"),
- Util.toBytesFromString("011FE0FE010EF1FE"),
- Util.toBytesFromString("0101FEFE0001FEFE"),
- Util.toBytesFromString("1F1FFEFE0E0EFEFE"),
- Util.toBytesFromString("FEFEE0E0FEFEF1F1"),
- Util.toBytesFromString("E0FEFEE0F1FEFEF1"),
- Util.toBytesFromString("FEE0E0FEFEF1F1FE"),
- Util.toBytesFromString("E0E0FEFEF1F1FEFE") };
-
- // Constructor(s)
- // -------------------------------------------------------------------------
+ Util.toBytesFromString("1F1F01010E0E0101"),
+ Util.toBytesFromString("011F1F01010E0E01"),
+ Util.toBytesFromString("1F01011F0E01010E"),
+ Util.toBytesFromString("01011F1F01010E0E"),
+ Util.toBytesFromString("E0E00101F1F10101"),
+ Util.toBytesFromString("FEFE0101FEFE0101"),
+ Util.toBytesFromString("FEE01F01FEF10E01"),
+ Util.toBytesFromString("E0FE1F01F1FE0E01"),
+ Util.toBytesFromString("FEE0011FFEF1010E"),
+ Util.toBytesFromString("E0FE011FF1FE010E"),
+ Util.toBytesFromString("E0E01F1FF1F10E0E"),
+ Util.toBytesFromString("FEFE1F1FFEFE0E0E"),
+ Util.toBytesFromString("1F1F01010E0E0101"),
+ Util.toBytesFromString("011F1F01010E0E01"),
+ Util.toBytesFromString("1F01011F0E01010E"),
+ Util.toBytesFromString("01011F1F01010E0E"),
+ Util.toBytesFromString("01E0E00101F1F101"),
+ Util.toBytesFromString("1FFEE0010EFEF001"),
+ Util.toBytesFromString("1FE0FE010EF1FE01"),
+ Util.toBytesFromString("01FEFE0101FEFE01"),
+ Util.toBytesFromString("1FE0E01F0EF1F10E"),
+ Util.toBytesFromString("01FEE01F01FEF10E"),
+ Util.toBytesFromString("01E0FE1F01F1FE0E"),
+ Util.toBytesFromString("1FFEFE1F0EFEFE0E"),
+
+ Util.toBytesFromString("E00101E0F10101F1"),
+ Util.toBytesFromString("FE1F01E0FE0E0EF1"),
+ Util.toBytesFromString("FE011FE0FE010EF1"),
+ Util.toBytesFromString("E01F1FE0F10E0EF1"),
+ Util.toBytesFromString("FE0101FEFE0101FE"),
+ Util.toBytesFromString("E01F01FEF10E01FE"),
+ Util.toBytesFromString("E0011FFEF1010EFE"),
+ Util.toBytesFromString("FE1F1FFEFE0E0EFE"),
+ Util.toBytesFromString("1FFE01E00EFE01F1"),
+ Util.toBytesFromString("01FE1FE001FE0EF1"),
+ Util.toBytesFromString("1FE001FE0EF101FE"),
+ Util.toBytesFromString("01E01FFE01F10EFE"),
+ Util.toBytesFromString("0101E0E00101F1F1"),
+ Util.toBytesFromString("1F1FE0E00E0EF1F1"),
+ Util.toBytesFromString("1F01FEE00E01FEF1"),
+ Util.toBytesFromString("011FFEE0010EFEF1"),
+ Util.toBytesFromString("1F01E0FE0E01F1FE"),
+ Util.toBytesFromString("011FE0FE010EF1FE"),
+ Util.toBytesFromString("0101FEFE0001FEFE"),
+ Util.toBytesFromString("1F1FFEFE0E0EFEFE"),
+ Util.toBytesFromString("FEFEE0E0FEFEF1F1"),
+ Util.toBytesFromString("E0FEFEE0F1FEFEF1"),
+ Util.toBytesFromString("FEE0E0FEFEF1F1FE"),
+ Util.toBytesFromString("E0E0FEFEF1F1FEFE") };
/** Default 0-argument constructor. */
public DES()
@@ -477,13 +289,10 @@ public class DES extends BaseCipher
super(Registry.DES_CIPHER, BLOCK_SIZE, KEY_SIZE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Adjust the parity for a raw key array. This essentially means that each
+ * Adjust the parity for a raw key array. This essentially means that each
* byte in the array will have an odd number of '1' bits (the last bit in
- * each byte is unused.</p>
+ * each byte is unused.
*
* @param kb The key array, to be parity-adjusted.
* @param offset The starting index into the key bytes.
@@ -491,14 +300,12 @@ public class DES extends BaseCipher
public static void adjustParity(byte[] kb, int offset)
{
for (int i = offset; i < KEY_SIZE; i++)
- {
- kb[i] ^= (PARITY[kb[i] & 0xff] == 8) ? 1 : 0;
- }
+ kb[i] ^= (PARITY[kb[i] & 0xff] == 8) ? 1 : 0;
}
/**
- * <p>Test if a byte array, which must be at least 8 bytes long, is parity
- * adjusted.</p>
+ * Test if a byte array, which must be at least 8 bytes long, is parity
+ * adjusted.
*
* @param kb The key bytes.
* @param offset The starting index into the key bytes.
@@ -527,59 +334,35 @@ public class DES extends BaseCipher
}
/**
- * <p>Test if a key is a weak key.</p>
+ * Test if a key is a weak key.
*
* @param kb The key to test.
* @return <code>true</code> if the key is weak.
*/
public static boolean isWeak(byte[] kb)
{
- // return Arrays.equals(kb, WEAK_KEYS[0]) || Arrays.equals(kb, WEAK_KEYS[1])
- // || Arrays.equals(kb, WEAK_KEYS[2]) || Arrays.equals(kb, WEAK_KEYS[3])
- // || Arrays.equals(kb, WEAK_KEYS[4]) || Arrays.equals(kb, WEAK_KEYS[5])
- // || Arrays.equals(kb, WEAK_KEYS[6]) || Arrays.equals(kb, WEAK_KEYS[7]);
for (int i = 0; i < WEAK_KEYS.length; i++)
- {
- if (Arrays.equals(WEAK_KEYS[i], kb))
- {
- return true;
- }
- }
+ if (Arrays.equals(WEAK_KEYS[i], kb))
+ return true;
return false;
}
/**
- * <p>Test if a key is a semi-weak key.</p>
+ * Test if a key is a semi-weak key.
*
* @param kb The key to test.
* @return <code>true</code> if this key is semi-weak.
*/
public static boolean isSemiWeak(byte[] kb)
{
- // return Arrays.equals(kb, SEMIWEAK_KEYS[0])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[1])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[2])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[3])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[4])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[5])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[6])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[7])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[8])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[9])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[10])
- // || Arrays.equals(kb, SEMIWEAK_KEYS[11]);
for (int i = 0; i < SEMIWEAK_KEYS.length; i++)
- {
- if (Arrays.equals(SEMIWEAK_KEYS[i], kb))
- {
- return true;
- }
- }
+ if (Arrays.equals(SEMIWEAK_KEYS[i], kb))
+ return true;
return false;
}
/**
- * <p>Test if the designated byte array represents a possibly weak key.</p>
+ * Test if the designated byte array represents a possibly weak key.
*
* @param kb the byte array to test.
* @return <code>true</code> if <code>kb</code>represents a possibly weak key.
@@ -588,18 +371,14 @@ public class DES extends BaseCipher
public static boolean isPossibleWeak(byte[] kb)
{
for (int i = 0; i < POSSIBLE_WEAK_KEYS.length; i++)
- {
- if (Arrays.equals(POSSIBLE_WEAK_KEYS[i], kb))
- {
- return true;
- }
- }
+ if (Arrays.equals(POSSIBLE_WEAK_KEYS[i], kb))
+ return true;
return false;
}
/**
- * <p>The core DES function. This is used for both encryption and decryption,
- * the only difference being the key.</p>
+ * The core DES function. This is used for both encryption and decryption,
+ * the only difference being the key.
*
* @param in The input bytes.
* @param i The starting offset into the input bytes.
@@ -610,13 +389,15 @@ public class DES extends BaseCipher
private static void desFunc(byte[] in, int i, byte[] out, int o, int[] key)
{
int right, left, work;
-
// Load.
- left = (in[i++] & 0xff) << 24 | (in[i++] & 0xff) << 16
- | (in[i++] & 0xff) << 8 | in[i++] & 0xff;
- right = (in[i++] & 0xff) << 24 | (in[i++] & 0xff) << 16
- | (in[i++] & 0xff) << 8 | in[i] & 0xff;
-
+ left = (in[i++] & 0xff) << 24
+ | (in[i++] & 0xff) << 16
+ | (in[i++] & 0xff) << 8
+ | in[i++] & 0xff;
+ right = (in[i++] & 0xff) << 24
+ | (in[i++] & 0xff) << 16
+ | (in[i++] & 0xff) << 8
+ | in[i ] & 0xff;
// Initial permutation.
work = ((left >>> 4) ^ right) & 0x0F0F0F0F;
left ^= work << 4;
@@ -681,7 +462,6 @@ public class DES extends BaseCipher
t |= SP2[work & 0x3F];
right ^= t;
}
-
// The final permutation.
right = (right << 31) | (right >>> 1);
work = (left ^ right) & 0xAAAAAAAA;
@@ -705,19 +485,16 @@ public class DES extends BaseCipher
right ^= work << 4;
left ^= work;
- out[o++] = (byte) (right >>> 24);
- out[o++] = (byte) (right >>> 16);
- out[o++] = (byte) (right >>> 8);
+ out[o++] = (byte)(right >>> 24);
+ out[o++] = (byte)(right >>> 16);
+ out[o++] = (byte)(right >>> 8);
out[o++] = (byte) right;
- out[o++] = (byte) (left >>> 24);
- out[o++] = (byte) (left >>> 16);
- out[o++] = (byte) (left >>> 8);
- out[o] = (byte) left;
+ out[o++] = (byte)(left >>> 24);
+ out[o++] = (byte)(left >>> 16);
+ out[o++] = (byte)(left >>> 8);
+ out[o ] = (byte) left;
}
- // Instance methods implementing BaseCipher
- // -------------------------------------------------------------------------
-
public Object clone()
{
return new DES();
@@ -725,12 +502,12 @@ public class DES extends BaseCipher
public Iterator blockSizes()
{
- return Collections.singleton(new Integer(BLOCK_SIZE)).iterator();
+ return Collections.singleton(Integer.valueOf(BLOCK_SIZE)).iterator();
}
public Iterator keySizes()
{
- return Collections.singleton(new Integer(KEY_SIZE)).iterator();
+ return Collections.singleton(Integer.valueOf(KEY_SIZE)).iterator();
}
public Object makeKey(byte[] kb, int bs) throws InvalidKeyException
@@ -740,9 +517,7 @@ public class DES extends BaseCipher
if (Properties.checkForWeakKeys()
&& (isWeak(kb) || isSemiWeak(kb) || isPossibleWeak(kb)))
- {
- throw new WeakKeyException();
- }
+ throw new WeakKeyException();
int i, j, l, m, n;
long pc1m = 0, pcr = 0;
@@ -751,11 +526,9 @@ public class DES extends BaseCipher
{
l = PC1[i];
pc1m |= ((kb[l >>> 3] & (0x80 >>> (l & 7))) != 0) ? (1L << (55 - i))
- : 0;
+ : 0;
}
-
Context ctx = new Context();
-
// Encryption key first.
for (i = 0; i < 16; i++)
{
@@ -769,7 +542,7 @@ public class DES extends BaseCipher
pcr |= ((pc1m & 1L << (55 - l)) != 0) ? (1L << (55 - j)) : 0;
else
pcr |= ((pc1m & 1L << (55 - (l - 28))) != 0) ? (1L << (55 - j))
- : 0;
+ : 0;
}
for (j = 28; j < 56; j++)
{
@@ -778,7 +551,7 @@ public class DES extends BaseCipher
pcr |= ((pc1m & 1L << (55 - l)) != 0) ? (1L << (55 - j)) : 0;
else
pcr |= ((pc1m & 1L << (55 - (l - 28))) != 0) ? (1L << (55 - j))
- : 0;
+ : 0;
}
for (j = 0; j < 24; j++)
{
@@ -788,36 +561,37 @@ public class DES extends BaseCipher
ctx.ek[n] |= 1 << (23 - j);
}
}
-
// The decryption key is the same, but in reversed order.
for (i = 0; i < Context.EXPANDED_KEY_SIZE; i += 2)
{
ctx.dk[30 - i] = ctx.ek[i];
ctx.dk[31 - i] = ctx.ek[i + 1];
}
-
// "Cook" the keys.
for (i = 0; i < 32; i += 2)
{
int x, y;
-
x = ctx.ek[i];
y = ctx.ek[i + 1];
-
- ctx.ek[i] = ((x & 0x00FC0000) << 6) | ((x & 0x00000FC0) << 10)
- | ((y & 0x00FC0000) >>> 10) | ((y & 0x00000FC0) >>> 6);
- ctx.ek[i + 1] = ((x & 0x0003F000) << 12) | ((x & 0x0000003F) << 16)
- | ((y & 0x0003F000) >>> 4) | (y & 0x0000003F);
-
+ ctx.ek[i ] = ((x & 0x00FC0000) << 6)
+ | ((x & 0x00000FC0) << 10)
+ | ((y & 0x00FC0000) >>> 10)
+ | ((y & 0x00000FC0) >>> 6);
+ ctx.ek[i + 1] = ((x & 0x0003F000) << 12)
+ | ((x & 0x0000003F) << 16)
+ | ((y & 0x0003F000) >>> 4)
+ | (y & 0x0000003F);
x = ctx.dk[i];
y = ctx.dk[i + 1];
-
- ctx.dk[i] = ((x & 0x00FC0000) << 6) | ((x & 0x00000FC0) << 10)
- | ((y & 0x00FC0000) >>> 10) | ((y & 0x00000FC0) >>> 6);
- ctx.dk[i + 1] = ((x & 0x0003F000) << 12) | ((x & 0x0000003F) << 16)
- | ((y & 0x0003F000) >>> 4) | (y & 0x0000003F);
+ ctx.dk[i ] = ((x & 0x00FC0000) << 6)
+ | ((x & 0x00000FC0) << 10)
+ | ((y & 0x00FC0000) >>> 10)
+ | ((y & 0x00000FC0) >>> 6);
+ ctx.dk[i + 1] = ((x & 0x0003F000) << 12)
+ | ((x & 0x0000003F) << 16)
+ | ((y & 0x0003F000) >>> 4)
+ | (y & 0x0000003F);
}
-
return ctx;
}
@@ -831,19 +605,12 @@ public class DES extends BaseCipher
desFunc(in, i, out, o, ((Context) K).dk);
}
- // Inner classe(s)
- // =========================================================================
-
/**
* Simple wrapper class around the session keys. Package-private so TripleDES
* can see it.
*/
final class Context
{
-
- // Constants and variables
- // ----------------------------------------------------------------------
-
private static final int EXPANDED_KEY_SIZE = 32;
/** The encryption key. */
@@ -852,9 +619,6 @@ public class DES extends BaseCipher
/** The decryption key. */
int[] dk;
- // Constructor(s)
- // ----------------------------------------------------------------------
-
/** Default 0-arguments constructor. */
Context()
{
@@ -862,12 +626,6 @@ public class DES extends BaseCipher
dk = new int[EXPANDED_KEY_SIZE];
}
- // Class methods
- // ----------------------------------------------------------------------
-
- // Instance methods
- // ----------------------------------------------------------------------
-
byte[] getEncryptionKeyBytes()
{
return toByteArray(ek);
@@ -883,12 +641,12 @@ public class DES extends BaseCipher
byte[] result = new byte[4 * k.length];
for (int i = 0, j = 0; i < k.length; i++)
{
- result[j++] = (byte) (k[i] >>> 24);
- result[j++] = (byte) (k[i] >>> 16);
- result[j++] = (byte) (k[i] >>> 8);
+ result[j++] = (byte)(k[i] >>> 24);
+ result[j++] = (byte)(k[i] >>> 16);
+ result[j++] = (byte)(k[i] >>> 8);
result[j++] = (byte) k[i];
}
return result;
}
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/IBlockCipher.java b/gnu/javax/crypto/cipher/IBlockCipher.java
index 238ee280f..d1e32ef65 100644
--- a/gnu/javax/crypto/cipher/IBlockCipher.java
+++ b/gnu/javax/crypto/cipher/IBlockCipher.java
@@ -43,109 +43,99 @@ import java.util.Iterator;
import java.util.Map;
/**
- * <p>The basic visible methods of any symmetric key block cipher.</p>
- *
- * <p>A symmetric key block cipher is a function that maps n-bit plaintext
- * blocks to n-bit ciphertext blocks; n being the cipher's <i>block size</i>.
- * This encryption function is parameterised by a k-bit key, and is invertible.
- * Its inverse is the decryption function.</p>
- *
- * <p>Possible initialisation values for an instance of this type are:</p>
- *
+ * The basic visible methods of any symmetric key block cipher.
+ * <p>
+ * A symmetric key block cipher is a function that maps n-bit plaintext blocks
+ * to n-bit ciphertext blocks; n being the cipher's <i>block size</i>. This
+ * encryption function is parameterised by a k-bit key, and is invertible. Its
+ * inverse is the decryption function.
+ * <p>
+ * Possible initialisation values for an instance of this type are:
* <ul>
- * <li>The block size in which to operate this block cipher instance. This
- * value is <b>optional</b>, if unspecified, the block cipher's default
- * block size shall be used.</li>
- *
- * <li>The byte array containing the user supplied key material to use for
- * generating the cipher's session key(s). This value is <b>mandatory</b>
- * and should be included in the initialisation parameters. If it isn't,
- * an {@link IllegalStateException} will be thrown if any method, other than
- * <code>reset()</code> is invoked on the instance. Furthermore, the size of
- * this key material shall be taken as an indication on the key size in which
- * to operate this instance.</li>
+ * <li>The block size in which to operate this block cipher instance. This
+ * value is <b>optional</b>, if unspecified, the block cipher's default block
+ * size shall be used.</li>
+ * <li>The byte array containing the user supplied key material to use for
+ * generating the cipher's session key(s). This value is <b>mandatory</b> and
+ * should be included in the initialisation parameters. If it isn't, an
+ * {@link IllegalStateException} will be thrown if any method, other than
+ * <code>reset()</code> is invoked on the instance. Furthermore, the size of
+ * this key material shall be taken as an indication on the key size in which to
+ * operate this instance.</li>
* </ul>
- *
- * <p><b>IMPLEMENTATION NOTE</b>: Although all the concrete classes in this
+ * <p>
+ * <b>IMPLEMENTATION NOTE</b>: Although all the concrete classes in this
* package implement the {@link Cloneable} interface, it is important to note
* here that such an operation <b>DOES NOT</b> clone any session key material
* that may have been used in initialising the source cipher (the instance to be
* cloned). Instead a clone of an already initialised cipher is another instance
* that operates with the <b>same block size</b> but without any knowledge of
- * neither key material nor key size.</p>
+ * neither key material nor key size.
*/
-public interface IBlockCipher extends Cloneable
+public interface IBlockCipher
+ extends Cloneable
{
-
- // Constants
- // -------------------------------------------------------------------------
-
/**
- * <p>Property name of the block size in which to operate a block cipher.
- * The value associated with this property name is taken to be an
- * {@link Integer}.</p>
+ * Property name of the block size in which to operate a block cipher. The
+ * value associated with this property name is taken to be an {@link Integer}.
*/
String CIPHER_BLOCK_SIZE = "gnu.crypto.cipher.block.size";
-
/**
- * <p>Property name of the user-supplied key material. The value associated
- * to this property name is taken to be a byte array.</p>
+ * Property name of the user-supplied key material. The value associated to
+ * this property name is taken to be a byte array.
*/
String KEY_MATERIAL = "gnu.crypto.cipher.key.material";
- // Methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the canonical name of this instance.</p>
- *
+ * Returns the canonical name of this instance.
+ *
* @return the canonical name of this instance.
*/
String name();
/**
- * <p>Returns the default value, in bytes, of the algorithm's block size.</p>
- *
+ * Returns the default value, in bytes, of the algorithm's block size.
+ *
* @return the default value, in bytes, of the algorithm's block size.
*/
int defaultBlockSize();
/**
- * <p>Returns the default value, in bytes, of the algorithm's key size.</p>
- *
+ * Returns the default value, in bytes, of the algorithm's key size.
+ *
* @return the default value, in bytes, of the algorithm's key size.
*/
int defaultKeySize();
/**
- * <p>Returns an {@link Iterator} over the supported block sizes. Each
- * element returned by this object is an {@link Integer}.</p>
- *
+ * Returns an {@link Iterator} over the supported block sizes. Each element
+ * returned by this object is an {@link Integer}.
+ *
* @return an {@link Iterator} over the supported block sizes.
*/
Iterator blockSizes();
/**
- * <p>Returns an {@link Iterator} over the supported key sizes. Each element
- * returned by this object is an {@link Integer}.</p>
- *
+ * Returns an {@link Iterator} over the supported key sizes. Each element
+ * returned by this object is an {@link Integer}.
+ *
* @return an {@link Iterator} over the supported key sizes.
*/
Iterator keySizes();
/**
- * <p>Returns a clone of this instance.</p>
- *
+ * Returns a clone of this instance.
+ *
* @return a clone copy of this instance.
*/
Object clone();
/**
- * <p>Initialises the algorithm with designated attributes. Permissible names
- * and values are described in the class documentation above.</p>
- *
+ * Initialises the algorithm with designated attributes. Permissible names and
+ * values are described in the class documentation above.
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @exception InvalidKeyException if the key data is invalid.
* @exception IllegalStateException if the instance is already initialised.
* @see #KEY_MATERIAL
@@ -154,25 +144,25 @@ public interface IBlockCipher extends Cloneable
void init(Map attributes) throws InvalidKeyException, IllegalStateException;
/**
- * <p>Returns the currently set block size for this instance.</p>
- *
+ * Returns the currently set block size for this instance.
+ *
* @return the current block size for this instance.
* @exception IllegalStateException if the instance is not initialised.
*/
int currentBlockSize() throws IllegalStateException;
/**
- * <p>Resets the algorithm instance for re-initialisation and use with other
- * characteristics. This method always succeeds.</p>
+ * Resets the algorithm instance for re-initialisation and use with other
+ * characteristics. This method always succeeds.
*/
void reset();
/**
- * <p>Encrypts exactly one block of plaintext.</p>
- *
+ * Encrypts exactly one block of plaintext.
+ *
* @param in the plaintext.
* @param inOffset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param out the ciphertext.
* @param outOffset index of <code>out</code> from which to store result.
* @exception IllegalStateException if the instance is not initialised.
@@ -181,11 +171,11 @@ public interface IBlockCipher extends Cloneable
throws IllegalStateException;
/**
- * <p>Decrypts exactly one block of ciphertext.</p>
- *
+ * Decrypts exactly one block of ciphertext.
+ *
* @param in the plaintext.
* @param inOffset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param out the ciphertext.
* @param outOffset index of <code>out</code> from which to store result.
* @exception IllegalStateException if the instance is not initialised.
@@ -194,12 +184,12 @@ public interface IBlockCipher extends Cloneable
throws IllegalStateException;
/**
- * <p>A <i>correctness</i> test that consists of basic symmetric encryption /
+ * A <i>correctness</i> test that consists of basic symmetric encryption /
* decryption test(s) for all supported block and key sizes, as well as one
- * (1) variable key Known Answer Test (KAT).</p>
- *
+ * (1) variable key Known Answer Test (KAT).
+ *
* @return <code>true</code> if the implementation passes simple
- * <i>correctness</i> tests. Returns <code>false</code> otherwise.
+ * <i>correctness</i> tests. Returns <code>false</code> otherwise.
*/
boolean selfTest();
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/IBlockCipherSpi.java b/gnu/javax/crypto/cipher/IBlockCipherSpi.java
index 046f43f6f..1023b12d8 100644
--- a/gnu/javax/crypto/cipher/IBlockCipherSpi.java
+++ b/gnu/javax/crypto/cipher/IBlockCipherSpi.java
@@ -42,38 +42,32 @@ import java.security.InvalidKeyException;
import java.util.Iterator;
/**
- * <p>Package-private interface exposing mandatory methods to be implemented by
- * concrete {@link gnu.javax.crypto.cipher.BaseCipher} sub-classes.</p>
+ * Package-private interface exposing mandatory methods to be implemented by
+ * concrete {@link BaseCipher} sub-classes.
*/
-interface IBlockCipherSpi extends Cloneable
+interface IBlockCipherSpi
+ extends Cloneable
{
-
- // Constants
- // -------------------------------------------------------------------------
-
- // Methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns an {@link java.util.Iterator} over the supported block sizes.
- * Each element returned by this object is a {@link java.lang.Integer}.</p>
- *
+ * Returns an {@link Iterator} over the supported block sizes. Each element
+ * returned by this object is a {@link java.lang.Integer}.
+ *
* @return an <code>Iterator</code> over the supported block sizes.
*/
Iterator blockSizes();
/**
- * <p>Returns an {@link java.util.Iterator} over the supported key sizes.
- * Each element returned by this object is a {@link java.lang.Integer}.</p>
- *
+ * Returns an {@link Iterator} over the supported key sizes. Each element
+ * returned by this object is a {@link java.lang.Integer}.
+ *
* @return an <code>Iterator</code> over the supported key sizes.
*/
Iterator keySizes();
/**
- * <p>Expands a user-supplied key material into a session key for a
- * designated <i>block size</i>.</p>
- *
+ * Expands a user-supplied key material into a session key for a designated
+ * <i>block size</i>.
+ *
* @param k the user-supplied key material.
* @param bs the desired block size in bytes.
* @return an Object encapsulating the session key.
@@ -83,46 +77,48 @@ interface IBlockCipherSpi extends Cloneable
Object makeKey(byte[] k, int bs) throws InvalidKeyException;
/**
- * <p>Encrypts exactly one block of plaintext.</p>
- *
+ * Encrypts exactly one block of plaintext.
+ *
* @param in the plaintext.
* @param inOffset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param out the ciphertext.
- * @param outOffset index of <code>out</code> from which to store the result.
+ * @param outOffset index of <code>out</code> from which to store the
+ * result.
* @param k the session key to use.
* @param bs the block size to use.
* @exception IllegalArgumentException if the block size is invalid.
* @exception ArrayIndexOutOfBoundsException if there is not enough room in
- * either the plaintext or ciphertext buffers.
+ * either the plaintext or ciphertext buffers.
*/
void encrypt(byte[] in, int inOffset, byte[] out, int outOffset, Object k,
int bs);
/**
- * <p>Decrypts exactly one block of ciphertext.</p>
- *
+ * Decrypts exactly one block of ciphertext.
+ *
* @param in the ciphertext.
* @param inOffset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param out the plaintext.
- * @param outOffset index of <code>out</code> from which to store the result.
+ * @param outOffset index of <code>out</code> from which to store the
+ * result.
* @param k the session key to use.
* @param bs the block size to use.
* @exception IllegalArgumentException if the block size is invalid.
* @exception ArrayIndexOutOfBoundsException if there is not enough room in
- * either the plaintext or ciphertext buffers.
+ * either the plaintext or ciphertext buffers.
*/
void decrypt(byte[] in, int inOffset, byte[] out, int outOffset, Object k,
int bs);
/**
- * <p>A <i>correctness</i> test that consists of basic symmetric encryption /
+ * A <i>correctness</i> test that consists of basic symmetric encryption /
* decryption test(s) for all supported block and key sizes, as well as one
- * (1) variable key Known Answer Test (KAT).</p>
- *
+ * (1) variable key Known Answer Test (KAT).
+ *
* @return <code>true</code> if the implementation passes simple
- * <i>correctness</i> tests. Returns <code>false</code> otherwise.
+ * <i>correctness</i> tests. Returns <code>false</code> otherwise.
*/
boolean selfTest();
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/Khazad.java b/gnu/javax/crypto/cipher/Khazad.java
index 385e2646b..491301f5a 100644
--- a/gnu/javax/crypto/cipher/Khazad.java
+++ b/gnu/javax/crypto/cipher/Khazad.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.cipher;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.Util;
@@ -49,87 +49,68 @@ import java.util.Iterator;
import java.util.logging.Logger;
/**
- * <p>Khazad is a 64-bit (legacy-level) block cipher that accepts a 128-bit key.
+ * Khazad is a 64-bit (legacy-level) block cipher that accepts a 128-bit key.
* The cipher is a uniform substitution-permutation network whose inverse only
* differs from the forward operation in the key schedule. The overall cipher
* design follows the Wide Trail strategy, favours component reuse, and permits
- * a wide variety of implementation trade-offs.</p>
- *
- * <p>References:</p>
- *
+ * a wide variety of implementation trade-offs.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://planeta.terra.com.br/informatica/paulobarreto/KhazadPage.html">The
- * Khazad Block Cipher</a>.<br>
- * <a href="mailto:paulo.barreto@terra.com.br">Paulo S.L.M. Barreto</a> and
- * <a href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a>.</li>
+ * <li><a
+ * href="http://planeta.terra.com.br/informatica/paulobarreto/KhazadPage.html">The
+ * Khazad Block Cipher</a>.<br>
+ * <a href="mailto:paulo.barreto@terra.com.br">Paulo S.L.M. Barreto</a> and <a
+ * href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a>.</li>
* </ol>
*/
-public final class Khazad extends BaseCipher
+public final class Khazad
+ extends BaseCipher
{
private static final Logger log = Logger.getLogger(Khazad.class.getName());
private static final int DEFAULT_BLOCK_SIZE = 8; // in bytes
-
private static final int DEFAULT_KEY_SIZE = 16; // in bytes
-
private static final int R = 8; // standard number of rounds; para. 3.7
-
private static final String Sd = // p. 20 [KHAZAD]
- "\uBA54\u2F74\u53D3\uD24D\u50AC\u8DBF\u7052\u9A4C"
- + "\uEAD5\u97D1\u3351\u5BA6\uDE48\uA899\uDB32\uB7FC"
- + "\uE39E\u919B\uE2BB\u416E\uA5CB\u6B95\uA1F3\uB102"
- + "\uCCC4\u1D14\uC363\uDA5D\u5FDC\u7DCD\u7F5A\u6C5C"
- + "\uF726\uFFED\uE89D\u6F8E\u19A0\uF089\u0F07\uAFFB"
- + "\u0815\u0D04\u0164\uDF76\u79DD\u3D16\u3F37\u6D38"
- + "\uB973\uE935\u5571\u7B8C\u7288\uF62A\u3E5E\u2746"
- + "\u0C65\u6861\u03C1\u57D6\uD958\uD866\uD73A\uC83C"
- + "\uFA96\uA798\uECB8\uC7AE\u694B\uABA9\u670A\u47F2"
- + "\uB522\uE5EE\uBE2B\u8112\u831B\u0E23\uF545\u21CE"
- + "\u492C\uF9E6\uB628\u1782\u1A8B\uFE8A\u09C9\u874E"
- + "\uE12E\uE4E0\uEB90\uA41E\u8560\u0025\uF4F1\u940B"
- + "\uE775\uEF34\u31D4\uD086\u7EAD\uFD29\u303B\u9FF8"
- + "\uC613\u0605\uC511\u777C\u7A78\u361C\u3959\u1856"
- + "\uB3B0\u2420\uB292\uA3C0\u4462\u10B4\u8443\u93C2"
- + "\u4ABD\u8F2D\uBC9C\u6A40\uCFA2\u804F\u1FCA\uAA42";
-
+ "\uBA54\u2F74\u53D3\uD24D\u50AC\u8DBF\u7052\u9A4C"
+ + "\uEAD5\u97D1\u3351\u5BA6\uDE48\uA899\uDB32\uB7FC"
+ + "\uE39E\u919B\uE2BB\u416E\uA5CB\u6B95\uA1F3\uB102"
+ + "\uCCC4\u1D14\uC363\uDA5D\u5FDC\u7DCD\u7F5A\u6C5C"
+ + "\uF726\uFFED\uE89D\u6F8E\u19A0\uF089\u0F07\uAFFB"
+ + "\u0815\u0D04\u0164\uDF76\u79DD\u3D16\u3F37\u6D38"
+ + "\uB973\uE935\u5571\u7B8C\u7288\uF62A\u3E5E\u2746"
+ + "\u0C65\u6861\u03C1\u57D6\uD958\uD866\uD73A\uC83C"
+ + "\uFA96\uA798\uECB8\uC7AE\u694B\uABA9\u670A\u47F2"
+ + "\uB522\uE5EE\uBE2B\u8112\u831B\u0E23\uF545\u21CE"
+ + "\u492C\uF9E6\uB628\u1782\u1A8B\uFE8A\u09C9\u874E"
+ + "\uE12E\uE4E0\uEB90\uA41E\u8560\u0025\uF4F1\u940B"
+ + "\uE775\uEF34\u31D4\uD086\u7EAD\uFD29\u303B\u9FF8"
+ + "\uC613\u0605\uC511\u777C\u7A78\u361C\u3959\u1856"
+ + "\uB3B0\u2420\uB292\uA3C0\u4462\u10B4\u8443\u93C2"
+ + "\u4ABD\u8F2D\uBC9C\u6A40\uCFA2\u804F\u1FCA\uAA42";
private static final byte[] S = new byte[256];
-
private static final int[] T0 = new int[256];
-
private static final int[] T1 = new int[256];
-
private static final int[] T2 = new int[256];
-
private static final int[] T3 = new int[256];
-
private static final int[] T4 = new int[256];
-
private static final int[] T5 = new int[256];
-
private static final int[] T6 = new int[256];
-
private static final int[] T7 = new int[256];
-
private static final int[][] rc = new int[R + 1][2]; // round constants
-
/**
- * KAT vector (from ecb_vk):
- * I=120
- * KEY=00000000000000000000000000000100
+ * KAT vector (from ecb_vk): I=120 KEY=00000000000000000000000000000100
* CT=A0C86A1BBE2CBF4C
*/
- private static final byte[] KAT_KEY = Util.toBytesFromString("00000000000000000000000000000100");
-
+ private static final byte[] KAT_KEY =
+ Util.toBytesFromString("00000000000000000000000000000100");
private static final byte[] KAT_CT = Util.toBytesFromString("A0C86A1BBE2CBF4C");
-
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
- // Static code - to intialise lookup tables --------------------------------
-
static
{
long time = System.currentTimeMillis();
-
long ROOT = 0x11d; // para. 2.1 [KHAZAD]
int i, j;
int s, s2, s3, s4, s5, s6, s7, s8, sb;
@@ -139,46 +120,41 @@ public final class Khazad extends BaseCipher
c = Sd.charAt(i >>> 1);
s = ((i & 1) == 0 ? c >>> 8 : c) & 0xFF;
S[i] = (byte) s;
-
s2 = s << 1;
if (s2 > 0xFF)
s2 ^= ROOT;
-
s3 = s2 ^ s;
s4 = s2 << 1;
if (s4 > 0xFF)
s4 ^= ROOT;
-
s5 = s4 ^ s;
s6 = s4 ^ s2;
s7 = s6 ^ s;
s8 = s4 << 1;
if (s8 > 0xFF)
s8 ^= ROOT;
-
sb = s8 ^ s2 ^ s;
-
- T0[i] = s << 24 | s3 << 16 | s4 << 8 | s5;
- T1[i] = s3 << 24 | s << 16 | s5 << 8 | s4;
- T2[i] = s4 << 24 | s5 << 16 | s << 8 | s3;
+ T0[i] = s << 24 | s3 << 16 | s4 << 8 | s5;
+ T1[i] = s3 << 24 | s << 16 | s5 << 8 | s4;
+ T2[i] = s4 << 24 | s5 << 16 | s << 8 | s3;
T3[i] = s5 << 24 | s4 << 16 | s3 << 8 | s;
T4[i] = s6 << 24 | s8 << 16 | sb << 8 | s7;
T5[i] = s8 << 24 | s6 << 16 | s7 << 8 | sb;
T6[i] = sb << 24 | s7 << 16 | s6 << 8 | s8;
T7[i] = s7 << 24 | sb << 16 | s8 << 8 | s6;
}
-
- for (i = 0, j = 0; i < R + 1; i++)
+ for (i = 0, j = 0; i < R + 1; i++) // compute round constant
{
- // compute round constant
- rc[i][0] = S[j++] << 24 | (S[j++] & 0xFF) << 16
- | (S[j++] & 0xFF) << 8 | (S[j++] & 0xFF);
- rc[i][1] = S[j++] << 24 | (S[j++] & 0xFF) << 16
- | (S[j++] & 0xFF) << 8 | (S[j++] & 0xFF);
+ rc[i][0] = S[j++] << 24
+ | (S[j++] & 0xFF) << 16
+ | (S[j++] & 0xFF) << 8
+ | (S[j++] & 0xFF);
+ rc[i][1] = S[j++] << 24
+ | (S[j++] & 0xFF) << 16
+ | (S[j++] & 0xFF) << 8
+ | (S[j++] & 0xFF);
}
-
time = System.currentTimeMillis() - time;
-
if (Configuration.DEBUG)
{
log.fine("Static data");
@@ -254,67 +230,67 @@ public final class Khazad extends BaseCipher
}
}
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Khazad()
{
super(Registry.KHAZAD_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
private static void khazad(byte[] in, int i, byte[] out, int j, int[][] K)
{
// sigma(K[0])
int k0 = K[0][0];
int k1 = K[0][1];
- int a0 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ k0;
- int a1 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i] & 0xFF))
- ^ k1;
-
+ int a0 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ k0;
+ int a1 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i ] & 0xFF) ) ^ k1;
int b0, b1;
// round function
for (int r = 1; r < R; r++)
{
k0 = K[r][0];
k1 = K[r][1];
- b0 = T0[a0 >>> 24] ^ T1[(a0 >>> 16) & 0xFF] ^ T2[(a0 >>> 8) & 0xFF]
- ^ T3[a0 & 0xFF] ^ T4[a1 >>> 24] ^ T5[(a1 >>> 16) & 0xFF]
- ^ T6[(a1 >>> 8) & 0xFF] ^ T7[a1 & 0xFF] ^ k0;
- b1 = T0[a1 >>> 24] ^ T1[(a1 >>> 16) & 0xFF] ^ T2[(a1 >>> 8) & 0xFF]
- ^ T3[a1 & 0xFF] ^ T4[a0 >>> 24] ^ T5[(a0 >>> 16) & 0xFF]
- ^ T6[(a0 >>> 8) & 0xFF] ^ T7[a0 & 0xFF] ^ k1;
+ b0 = T0[ a0 >>> 24 ]
+ ^ T1[(a0 >>> 16) & 0xFF]
+ ^ T2[(a0 >>> 8) & 0xFF]
+ ^ T3[ a0 & 0xFF]
+ ^ T4[ a1 >>> 24 ]
+ ^ T5[(a1 >>> 16) & 0xFF]
+ ^ T6[(a1 >>> 8) & 0xFF]
+ ^ T7[ a1 & 0xFF] ^ k0;
+ b1 = T0[ a1 >>> 24 ]
+ ^ T1[(a1 >>> 16) & 0xFF]
+ ^ T2[(a1 >>> 8) & 0xFF]
+ ^ T3[ a1 & 0xFF]
+ ^ T4[ a0 >>> 24 ]
+ ^ T5[(a0 >>> 16) & 0xFF]
+ ^ T6[(a0 >>> 8) & 0xFF]
+ ^ T7[ a0 & 0xFF] ^ k1;
a0 = b0;
a1 = b1;
if (Configuration.DEBUG)
log.fine("T" + r + "=" + Util.toString(a0) + Util.toString(a1));
}
-
// sigma(K[R]) o gamma applied to previous output
k0 = K[R][0];
k1 = K[R][1];
-
- out[j++] = (byte) (S[a0 >>> 24] ^ (k0 >>> 24));
- out[j++] = (byte) (S[(a0 >>> 16) & 0xFF] ^ (k0 >>> 16));
- out[j++] = (byte) (S[(a0 >>> 8) & 0xFF] ^ (k0 >>> 8));
- out[j++] = (byte) (S[a0 & 0xFF] ^ k0);
- out[j++] = (byte) (S[a1 >>> 24] ^ (k1 >>> 24));
- out[j++] = (byte) (S[(a1 >>> 16) & 0xFF] ^ (k1 >>> 16));
- out[j++] = (byte) (S[(a1 >>> 8) & 0xFF] ^ (k1 >>> 8));
- out[j] = (byte) (S[a1 & 0xFF] ^ k1);
+ out[j++] = (byte)(S[ a0 >>> 24 ] ^ (k0 >>> 24));
+ out[j++] = (byte)(S[(a0 >>> 16) & 0xFF] ^ (k0 >>> 16));
+ out[j++] = (byte)(S[(a0 >>> 8) & 0xFF] ^ (k0 >>> 8));
+ out[j++] = (byte)(S[ a0 & 0xFF] ^ k0 );
+ out[j++] = (byte)(S[ a1 >>> 24 ] ^ (k1 >>> 24));
+ out[j++] = (byte)(S[(a1 >>> 16) & 0xFF] ^ (k1 >>> 16));
+ out[j++] = (byte)(S[(a1 >>> 8) & 0xFF] ^ (k1 >>> 8));
+ out[j ] = (byte)(S[ a1 & 0xFF] ^ k1 );
if (Configuration.DEBUG)
log.fine("T=" + Util.toString(out, j - 7, 8) + "\n");
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.lang.Cloneable interface implementation ----------------------------
-
public Object clone()
{
Khazad result = new Khazad();
@@ -323,12 +299,10 @@ public final class Khazad extends BaseCipher
return result;
}
- // IBlockCipherSpi interface implementation --------------------------------
-
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(DEFAULT_BLOCK_SIZE));
+ al.add(Integer.valueOf(DEFAULT_BLOCK_SIZE));
return Collections.unmodifiableList(al).iterator();
}
@@ -336,15 +310,14 @@ public final class Khazad extends BaseCipher
public Iterator keySizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(DEFAULT_KEY_SIZE));
-
+ al.add(Integer.valueOf(DEFAULT_KEY_SIZE));
return Collections.unmodifiableList(al).iterator();
}
/**
- * <p>Expands a user-supplied key material into a session key for a
- * designated <i>block size</i>.</p>
- *
+ * Expands a user-supplied key material into a session key for a designated
+ * <i>block size</i>.
+ *
* @param uk the 128-bit user-supplied key material.
* @param bs the desired block size in bytes.
* @return an Object encapsulating the session key.
@@ -354,54 +327,58 @@ public final class Khazad extends BaseCipher
public Object makeKey(byte[] uk, int bs) throws InvalidKeyException
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
if (uk == null)
- {
- throw new InvalidKeyException("Empty key");
- }
+ throw new InvalidKeyException("Empty key");
if (uk.length != 16)
- {
- throw new InvalidKeyException("Key is not 128-bit.");
- }
+ throw new InvalidKeyException("Key is not 128-bit.");
int[][] Ke = new int[R + 1][2]; // encryption round keys
int[][] Kd = new int[R + 1][2]; // decryption round keys
-
int r, i;
int k20, k21, k10, k11, rc0, rc1, kr0, kr1;
-
i = 0;
- k20 = uk[i++] << 24 | (uk[i++] & 0xFF) << 16 | (uk[i++] & 0xFF) << 8
- | (uk[i++] & 0xFF);
- k21 = uk[i++] << 24 | (uk[i++] & 0xFF) << 16 | (uk[i++] & 0xFF) << 8
- | (uk[i++] & 0xFF);
- k10 = uk[i++] << 24 | (uk[i++] & 0xFF) << 16 | (uk[i++] & 0xFF) << 8
- | (uk[i++] & 0xFF);
- k11 = uk[i++] << 24 | (uk[i++] & 0xFF) << 16 | (uk[i++] & 0xFF) << 8
- | (uk[i++] & 0xFF);
-
+ k20 = uk[i++] << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i++] & 0xFF);
+ k21 = uk[i++] << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i++] & 0xFF);
+ k10 = uk[i++] << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i++] & 0xFF);
+ k11 = uk[i++] << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i++] & 0xFF);
for (r = 0, i = 0; r <= R; r++)
{
rc0 = rc[r][0];
rc1 = rc[r][1];
-
- kr0 = T0[k10 >>> 24] ^ T1[(k10 >>> 16) & 0xFF] ^ T2[(k10 >>> 8) & 0xFF]
- ^ T3[k10 & 0xFF] ^ T4[(k11 >>> 24) & 0xFF]
- ^ T5[(k11 >>> 16) & 0xFF] ^ T6[(k11 >>> 8) & 0xFF]
- ^ T7[k11 & 0xFF] ^ rc0 ^ k20;
- kr1 = T0[k11 >>> 24] ^ T1[(k11 >>> 16) & 0xFF] ^ T2[(k11 >>> 8) & 0xFF]
- ^ T3[k11 & 0xFF] ^ T4[(k10 >>> 24) & 0xFF]
- ^ T5[(k10 >>> 16) & 0xFF] ^ T6[(k10 >>> 8) & 0xFF]
- ^ T7[k10 & 0xFF] ^ rc1 ^ k21;
-
+ kr0 = T0[ k10 >>> 24 ]
+ ^ T1[(k10 >>> 16) & 0xFF]
+ ^ T2[(k10 >>> 8) & 0xFF]
+ ^ T3[ k10 & 0xFF]
+ ^ T4[(k11 >>> 24) & 0xFF]
+ ^ T5[(k11 >>> 16) & 0xFF]
+ ^ T6[(k11 >>> 8) & 0xFF]
+ ^ T7[ k11 & 0xFF] ^ rc0 ^ k20;
+ kr1 = T0[ k11 >>> 24 ]
+ ^ T1[(k11 >>> 16) & 0xFF]
+ ^ T2[(k11 >>> 8) & 0xFF]
+ ^ T3[ k11 & 0xFF]
+ ^ T4[(k10 >>> 24) & 0xFF]
+ ^ T5[(k10 >>> 16) & 0xFF]
+ ^ T6[(k10 >>> 8) & 0xFF]
+ ^ T7[ k10 & 0xFF] ^ rc1 ^ k21;
Ke[r][0] = kr0;
Ke[r][1] = kr1;
k20 = k10;
k21 = k11;
k10 = kr0;
k11 = kr1;
-
if (r == 0 || r == R)
{
Kd[R - r][0] = kr0;
@@ -409,22 +386,22 @@ public final class Khazad extends BaseCipher
}
else
{
- Kd[R - r][0] = T0[S[kr0 >>> 24] & 0xFF]
- ^ T1[S[(kr0 >>> 16) & 0xFF] & 0xFF]
- ^ T2[S[(kr0 >>> 8) & 0xFF] & 0xFF]
- ^ T3[S[kr0 & 0xFF] & 0xFF]
- ^ T4[S[kr1 >>> 24] & 0xFF]
- ^ T5[S[(kr1 >>> 16) & 0xFF] & 0xFF]
- ^ T6[S[(kr1 >>> 8) & 0xFF] & 0xFF]
- ^ T7[S[kr1 & 0xFF] & 0xFF];
- Kd[R - r][1] = T0[S[kr1 >>> 24] & 0xFF]
- ^ T1[S[(kr1 >>> 16) & 0xFF] & 0xFF]
- ^ T2[S[(kr1 >>> 8) & 0xFF] & 0xFF]
- ^ T3[S[kr1 & 0xFF] & 0xFF]
- ^ T4[S[kr0 >>> 24] & 0xFF]
- ^ T5[S[(kr0 >>> 16) & 0xFF] & 0xFF]
- ^ T6[S[(kr0 >>> 8) & 0xFF] & 0xFF]
- ^ T7[S[kr0 & 0xFF] & 0xFF];
+ Kd[R - r][0] = T0[S[ kr0 >>> 24 ] & 0xFF]
+ ^ T1[S[(kr0 >>> 16) & 0xFF] & 0xFF]
+ ^ T2[S[(kr0 >>> 8) & 0xFF] & 0xFF]
+ ^ T3[S[ kr0 & 0xFF] & 0xFF]
+ ^ T4[S[ kr1 >>> 24 ] & 0xFF]
+ ^ T5[S[(kr1 >>> 16) & 0xFF] & 0xFF]
+ ^ T6[S[(kr1 >>> 8) & 0xFF] & 0xFF]
+ ^ T7[S[ kr1 & 0xFF] & 0xFF];
+ Kd[R - r][1] = T0[S[ kr1 >>> 24 ] & 0xFF]
+ ^ T1[S[(kr1 >>> 16) & 0xFF] & 0xFF]
+ ^ T2[S[(kr1 >>> 8) & 0xFF] & 0xFF]
+ ^ T3[S[ kr1 & 0xFF] & 0xFF]
+ ^ T4[S[ kr0 >>> 24 ] & 0xFF]
+ ^ T5[S[(kr0 >>> 16) & 0xFF] & 0xFF]
+ ^ T6[S[(kr0 >>> 8) & 0xFF] & 0xFF]
+ ^ T7[S[ kr0 & 0xFF] & 0xFF];
}
}
if (Configuration.DEBUG)
@@ -432,36 +409,29 @@ public final class Khazad extends BaseCipher
log.fine("Key schedule");
log.fine("Ke[]:");
for (r = 0; r < R + 1; r++)
- log.fine("#" + r + ": 0x"
- + Util.toString(Ke[r][0]) + Util.toString(Ke[r][1]));
+ log.fine("#" + r + ": 0x" + Util.toString(Ke[r][0])
+ + Util.toString(Ke[r][1]));
log.fine("Kd[]:");
for (r = 0; r < R + 1; r++)
- log.fine("#" + r + ": 0x"
- + Util.toString(Kd[r][0]) + Util.toString(Kd[r][1]));
+ log.fine("#" + r + ": 0x" + Util.toString(Kd[r][0])
+ + Util.toString(Kd[r][1]));
}
-
return new Object[] { Ke, Kd };
}
public void encrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
-
- int[][] K = (int[][]) ((Object[]) k)[0];
+ throw new IllegalArgumentException();
+ int[][] K = (int[][])((Object[]) k)[0];
khazad(in, i, out, j, K);
}
public void decrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
-
- int[][] K = (int[][]) ((Object[]) k)[1];
+ throw new IllegalArgumentException();
+ int[][] K = (int[][])((Object[]) k)[1];
khazad(in, i, out, j, K);
}
@@ -471,11 +441,9 @@ public final class Khazad extends BaseCipher
{
boolean result = super.selfTest(); // do symmetry tests
if (result)
- {
- result = testKat(KAT_KEY, KAT_CT);
- }
+ result = testKat(KAT_KEY, KAT_CT);
valid = Boolean.valueOf(result);
}
return valid.booleanValue();
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/NullCipher.java b/gnu/javax/crypto/cipher/NullCipher.java
index 09252db90..451555954 100644
--- a/gnu/javax/crypto/cipher/NullCipher.java
+++ b/gnu/javax/crypto/cipher/NullCipher.java
@@ -46,53 +46,35 @@ import java.util.Collections;
import java.util.Iterator;
/**
- * <p>The implementation of a Null block cipher.</p>
- *
- * <p>This cipher does not alter its input at all, claims to process block sizes
+ * The implementation of a Null block cipher.
+ * <p>
+ * This cipher does not alter its input at all, claims to process block sizes
* 128-, 192- and 256-bit long, and key sizes from 64- to 512-bit in 8-bit
- * increments.</p>
+ * increments.
*/
-public final class NullCipher extends BaseCipher
+public final class NullCipher
+ extends BaseCipher
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public NullCipher()
{
super(Registry.NULL_CIPHER, 16, 16);
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.lang.Cloneable interface implementation ----------------------------
-
public Object clone()
{
NullCipher result = new NullCipher();
result.currentBlockSize = this.currentBlockSize;
-
return result;
}
- // IBlockCipherSpi interface implementation --------------------------------
-
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(64 / 8));
- al.add(new Integer(128 / 8));
- al.add(new Integer(192 / 8));
- al.add(new Integer(256 / 8));
-
+ al.add(Integer.valueOf(64 / 8));
+ al.add(Integer.valueOf(128 / 8));
+ al.add(Integer.valueOf(192 / 8));
+ al.add(Integer.valueOf(256 / 8));
return Collections.unmodifiableList(al).iterator();
}
@@ -100,10 +82,7 @@ public final class NullCipher extends BaseCipher
{
ArrayList al = new ArrayList();
for (int n = 8; n < 64; n++)
- {
- al.add(new Integer(n));
- }
-
+ al.add(Integer.valueOf(n));
return Collections.unmodifiableList(al).iterator();
}
@@ -126,4 +105,4 @@ public final class NullCipher extends BaseCipher
{
return true;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/Rijndael.java b/gnu/javax/crypto/cipher/Rijndael.java
index d830cd66d..d1bc958c3 100644
--- a/gnu/javax/crypto/cipher/Rijndael.java
+++ b/gnu/javax/crypto/cipher/Rijndael.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.cipher;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.Util;
@@ -49,163 +49,122 @@ import java.util.Iterator;
import java.util.logging.Logger;
/**
- * <p>Rijndael --pronounced Reindaal-- is the AES. It is a variable block-size
+ * Rijndael --pronounced Reindaal-- is the AES. It is a variable block-size
* (128-, 192- and 256-bit), variable key-size (128-, 192- and 256-bit)
- * symmetric key block cipher.</p>
- *
- * <p>References:</p>
- *
+ * symmetric key block cipher.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.esat.kuleuven.ac.be/~rijmen/rijndael/">The
- * Rijndael Block Cipher - AES Proposal</a>.<br>
- * <a href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a> and
- * <a href="mailto:daemen.j@protonworld.com">Joan Daemen</a>.</li>
+ * <li><a href="http://www.esat.kuleuven.ac.be/~rijmen/rijndael/">The Rijndael
+ * Block Cipher - AES Proposal</a>.<br>
+ * <a href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a> and
+ * <a href="mailto:daemen.j@protonworld.com">Joan Daemen</a>.</li>
* </ol>
*/
-public final class Rijndael extends BaseCipher
+public final class Rijndael
+ extends BaseCipher
{
private static final Logger log = Logger.getLogger(Rijndael.class.getName());
private static final int DEFAULT_BLOCK_SIZE = 16; // in bytes
-
private static final int DEFAULT_KEY_SIZE = 16; // in bytes
-
- private static final String SS = "\u637C\u777B\uF26B\u6FC5\u3001\u672B\uFED7\uAB76"
- + "\uCA82\uC97D\uFA59\u47F0\uADD4\uA2AF\u9CA4\u72C0"
- + "\uB7FD\u9326\u363F\uF7CC\u34A5\uE5F1\u71D8\u3115"
- + "\u04C7\u23C3\u1896\u059A\u0712\u80E2\uEB27\uB275"
- + "\u0983\u2C1A\u1B6E\u5AA0\u523B\uD6B3\u29E3\u2F84"
- + "\u53D1\u00ED\u20FC\uB15B\u6ACB\uBE39\u4A4C\u58CF"
- + "\uD0EF\uAAFB\u434D\u3385\u45F9\u027F\u503C\u9FA8"
- + "\u51A3\u408F\u929D\u38F5\uBCB6\uDA21\u10FF\uF3D2"
- + "\uCD0C\u13EC\u5F97\u4417\uC4A7\u7E3D\u645D\u1973"
- + "\u6081\u4FDC\u222A\u9088\u46EE\uB814\uDE5E\u0BDB"
- + "\uE032\u3A0A\u4906\u245C\uC2D3\uAC62\u9195\uE479"
- + "\uE7C8\u376D\u8DD5\u4EA9\u6C56\uF4EA\u657A\uAE08"
- + "\uBA78\u252E\u1CA6\uB4C6\uE8DD\u741F\u4BBD\u8B8A"
- + "\u703E\uB566\u4803\uF60E\u6135\u57B9\u86C1\u1D9E"
- + "\uE1F8\u9811\u69D9\u8E94\u9B1E\u87E9\uCE55\u28DF"
- + "\u8CA1\u890D\uBFE6\u4268\u4199\u2D0F\uB054\uBB16";
-
+ private static final String SS =
+ "\u637C\u777B\uF26B\u6FC5\u3001\u672B\uFED7\uAB76"
+ + "\uCA82\uC97D\uFA59\u47F0\uADD4\uA2AF\u9CA4\u72C0"
+ + "\uB7FD\u9326\u363F\uF7CC\u34A5\uE5F1\u71D8\u3115"
+ + "\u04C7\u23C3\u1896\u059A\u0712\u80E2\uEB27\uB275"
+ + "\u0983\u2C1A\u1B6E\u5AA0\u523B\uD6B3\u29E3\u2F84"
+ + "\u53D1\u00ED\u20FC\uB15B\u6ACB\uBE39\u4A4C\u58CF"
+ + "\uD0EF\uAAFB\u434D\u3385\u45F9\u027F\u503C\u9FA8"
+ + "\u51A3\u408F\u929D\u38F5\uBCB6\uDA21\u10FF\uF3D2"
+ + "\uCD0C\u13EC\u5F97\u4417\uC4A7\u7E3D\u645D\u1973"
+ + "\u6081\u4FDC\u222A\u9088\u46EE\uB814\uDE5E\u0BDB"
+ + "\uE032\u3A0A\u4906\u245C\uC2D3\uAC62\u9195\uE479"
+ + "\uE7C8\u376D\u8DD5\u4EA9\u6C56\uF4EA\u657A\uAE08"
+ + "\uBA78\u252E\u1CA6\uB4C6\uE8DD\u741F\u4BBD\u8B8A"
+ + "\u703E\uB566\u4803\uF60E\u6135\u57B9\u86C1\u1D9E"
+ + "\uE1F8\u9811\u69D9\u8E94\u9B1E\u87E9\uCE55\u28DF"
+ + "\u8CA1\u890D\uBFE6\u4268\u4199\u2D0F\uB054\uBB16";
private static final byte[] S = new byte[256];
-
private static final byte[] Si = new byte[256];
-
private static final int[] T1 = new int[256];
-
private static final int[] T2 = new int[256];
-
private static final int[] T3 = new int[256];
-
private static final int[] T4 = new int[256];
-
private static final int[] T5 = new int[256];
-
private static final int[] T6 = new int[256];
-
private static final int[] T7 = new int[256];
-
private static final int[] T8 = new int[256];
-
private static final int[] U1 = new int[256];
-
private static final int[] U2 = new int[256];
-
private static final int[] U3 = new int[256];
-
private static final int[] U4 = new int[256];
-
private static final byte[] rcon = new byte[30];
-
private static final int[][][] shifts = new int[][][] {
- { { 0, 0 }, { 1, 3 },
- { 2, 2 }, { 3, 1 } },
- { { 0, 0 }, { 1, 5 },
- { 2, 4 }, { 3, 3 } },
- { { 0, 0 }, { 1, 7 },
- { 3, 5 }, { 4, 4 } } };
-
+ { { 0, 0 }, { 1, 3 }, { 2, 2 }, { 3, 1 } },
+ { { 0, 0 }, { 1, 5 }, { 2, 4 }, { 3, 3 } },
+ { { 0, 0 }, { 1, 7 }, { 3, 5 }, { 4, 4 } } };
/**
- * KAT vector (from ecb_vk):
- * I=96
+ * KAT vector (from ecb_vk): I=96
* KEY=0000000000000000000000010000000000000000000000000000000000000000
* CT=E44429474D6FC3084EB2A6B8B46AF754
*/
- private static final byte[] KAT_KEY = Util.toBytesFromString("0000000000000000000000010000000000000000000000000000000000000000");
-
- private static final byte[] KAT_CT = Util.toBytesFromString("E44429474D6FC3084EB2A6B8B46AF754");
-
+ private static final byte[] KAT_KEY = Util.toBytesFromString(
+ "0000000000000000000000010000000000000000000000000000000000000000");
+ private static final byte[] KAT_CT = Util.toBytesFromString(
+ "E44429474D6FC3084EB2A6B8B46AF754");
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
- // Static code - to intialise lookup tables --------------------------------
-
static
{
long time = System.currentTimeMillis();
-
int ROOT = 0x11B;
int i, j = 0;
-
// S-box, inverse S-box, T-boxes, U-boxes
int s, s2, s3, i2, i4, i8, i9, ib, id, ie, t;
char c;
for (i = 0; i < 256; i++)
{
c = SS.charAt(i >>> 1);
- S[i] = (byte) (((i & 1) == 0) ? c >>> 8 : c & 0xFF);
+ S[i] = (byte)(((i & 1) == 0) ? c >>> 8 : c & 0xFF);
s = S[i] & 0xFF;
Si[s] = (byte) i;
s2 = s << 1;
if (s2 >= 0x100)
- {
- s2 ^= ROOT;
- }
+ s2 ^= ROOT;
s3 = s2 ^ s;
i2 = i << 1;
if (i2 >= 0x100)
- {
- i2 ^= ROOT;
- }
+ i2 ^= ROOT;
i4 = i2 << 1;
if (i4 >= 0x100)
- {
- i4 ^= ROOT;
- }
+ i4 ^= ROOT;
i8 = i4 << 1;
if (i8 >= 0x100)
- {
- i8 ^= ROOT;
- }
+ i8 ^= ROOT;
i9 = i8 ^ i;
ib = i9 ^ i2;
id = i9 ^ i4;
ie = i8 ^ i4 ^ i2;
-
T1[i] = t = (s2 << 24) | (s << 16) | (s << 8) | s3;
- T2[i] = (t >>> 8) | (t << 24);
+ T2[i] = (t >>> 8) | (t << 24);
T3[i] = (t >>> 16) | (t << 16);
- T4[i] = (t >>> 24) | (t << 8);
-
+ T4[i] = (t >>> 24) | (t << 8);
T5[s] = U1[i] = t = (ie << 24) | (i9 << 16) | (id << 8) | ib;
- T6[s] = U2[i] = (t >>> 8) | (t << 24);
+ T6[s] = U2[i] = (t >>> 8) | (t << 24);
T7[s] = U3[i] = (t >>> 16) | (t << 16);
- T8[s] = U4[i] = (t >>> 24) | (t << 8);
+ T8[s] = U4[i] = (t >>> 24) | (t << 8);
}
- //
// round constants
- //
int r = 1;
rcon[0] = 1;
for (i = 1; i < 30; i++)
{
r <<= 1;
if (r >= 0x100)
- {
- r ^= ROOT;
- }
+ r ^= ROOT;
rcon[i] = (byte) r;
}
-
time = System.currentTimeMillis() - time;
if (Configuration.DEBUG)
{
@@ -338,22 +297,15 @@ public final class Rijndael extends BaseCipher
}
}
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Rijndael()
{
super(Registry.RIJNDAEL_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the number of rounds for a given Rijndael's key and block
- * sizes.</p>
- *
+ * Returns the number of rounds for a given Rijndael's key and block sizes.
+ *
* @param ks the size of the user key material in bytes.
* @param bs the desired block size in bytes.
* @return the number of rounds for a given Rijndael's key and block sizes.
@@ -376,7 +328,6 @@ public final class Rijndael extends BaseCipher
{
Object[] sKey = (Object[]) sessionKey; // extract encryption round keys
int[][] Ke = (int[][]) sKey[0];
-
int BC = bs / 4;
int ROUNDS = Ke.length - 1;
int SC = BC == 4 ? 0 : (BC == 6 ? 1 : 2);
@@ -386,35 +337,29 @@ public final class Rijndael extends BaseCipher
int[] a = new int[BC];
int[] t = new int[BC]; // temporary work array
int i, tt;
-
- for (i = 0; i < BC; i++)
- { // plaintext to ints + key
- t[i] = (in[inOffset++] << 24 | (in[inOffset++] & 0xFF) << 16
- | (in[inOffset++] & 0xFF) << 8 | (in[inOffset++] & 0xFF))
- ^ Ke[0][i];
- }
-
- for (int r = 1; r < ROUNDS; r++)
- { // apply round transforms
+ for (i = 0; i < BC; i++) // plaintext to ints + key
+ t[i] = (in[inOffset++] << 24
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) ) ^ Ke[0][i];
+ for (int r = 1; r < ROUNDS; r++) // apply round transforms
+ {
for (i = 0; i < BC; i++)
- {
- a[i] = (T1[(t[i] >>> 24)] ^ T2[(t[(i + s1) % BC] >>> 16) & 0xFF]
- ^ T3[(t[(i + s2) % BC] >>> 8) & 0xFF] ^ T4[t[(i + s3) % BC] & 0xFF])
- ^ Ke[r][i];
- }
-
+ a[i] = (T1[(t[ i ] >>> 24) ]
+ ^ T2[(t[(i + s1) % BC] >>> 16) & 0xFF]
+ ^ T3[(t[(i + s2) % BC] >>> 8) & 0xFF]
+ ^ T4[ t[(i + s3) % BC] & 0xFF]) ^ Ke[r][i];
System.arraycopy(a, 0, t, 0, BC);
if (Configuration.DEBUG)
log.fine("CT" + r + "=" + Util.toString(t));
}
-
- for (i = 0; i < BC; i++)
- { // last round is special
+ for (i = 0; i < BC; i++) // last round is special
+ {
tt = Ke[ROUNDS][i];
- out[outOffset++] = (byte) (S[(t[i] >>> 24)] ^ (tt >>> 24));
- out[outOffset++] = (byte) (S[(t[(i + s1) % BC] >>> 16) & 0xFF] ^ (tt >>> 16));
- out[outOffset++] = (byte) (S[(t[(i + s2) % BC] >>> 8) & 0xFF] ^ (tt >>> 8));
- out[outOffset++] = (byte) (S[t[(i + s3) % BC] & 0xFF] ^ tt);
+ out[outOffset++] = (byte)(S[(t[ i ] >>> 24) ] ^ (tt >>> 24));
+ out[outOffset++] = (byte)(S[(t[(i + s1) % BC] >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[outOffset++] = (byte)(S[(t[(i + s2) % BC] >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[outOffset++] = (byte)(S[ t[(i + s3) % BC] & 0xFF] ^ tt );
}
if (Configuration.DEBUG)
log.fine("CT=" + Util.toString(out, outOffset - bs, bs));
@@ -425,7 +370,6 @@ public final class Rijndael extends BaseCipher
{
Object[] sKey = (Object[]) sessionKey; // extract decryption round keys
int[][] Kd = (int[][]) sKey[1];
-
int BC = bs / 4;
int ROUNDS = Kd.length - 1;
int SC = BC == 4 ? 0 : (BC == 6 ? 1 : 2);
@@ -435,35 +379,29 @@ public final class Rijndael extends BaseCipher
int[] a = new int[BC];
int[] t = new int[BC]; // temporary work array
int i, tt;
-
- for (i = 0; i < BC; i++)
- { // ciphertext to ints + key
- t[i] = (in[inOffset++] << 24 | (in[inOffset++] & 0xFF) << 16
- | (in[inOffset++] & 0xFF) << 8 | (in[inOffset++] & 0xFF))
- ^ Kd[0][i];
- }
-
- for (int r = 1; r < ROUNDS; r++)
- { // apply round transforms
+ for (i = 0; i < BC; i++) // ciphertext to ints + key
+ t[i] = (in[inOffset++] << 24
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) ) ^ Kd[0][i];
+ for (int r = 1; r < ROUNDS; r++) // apply round transforms
+ {
for (i = 0; i < BC; i++)
- {
- a[i] = (T5[(t[i] >>> 24)] ^ T6[(t[(i + s1) % BC] >>> 16) & 0xFF]
- ^ T7[(t[(i + s2) % BC] >>> 8) & 0xFF] ^ T8[t[(i + s3) % BC] & 0xFF])
- ^ Kd[r][i];
- }
-
+ a[i] = (T5[(t[ i ] >>> 24) ]
+ ^ T6[(t[(i + s1) % BC] >>> 16) & 0xFF]
+ ^ T7[(t[(i + s2) % BC] >>> 8) & 0xFF]
+ ^ T8[ t[(i + s3) % BC] & 0xFF]) ^ Kd[r][i];
System.arraycopy(a, 0, t, 0, BC);
if (Configuration.DEBUG)
log.fine("PT" + r + "=" + Util.toString(t));
}
-
- for (i = 0; i < BC; i++)
- { // last round is special
+ for (i = 0; i < BC; i++) // last round is special
+ {
tt = Kd[ROUNDS][i];
- out[outOffset++] = (byte) (Si[(t[i] >>> 24)] ^ (tt >>> 24));
- out[outOffset++] = (byte) (Si[(t[(i + s1) % BC] >>> 16) & 0xFF] ^ (tt >>> 16));
- out[outOffset++] = (byte) (Si[(t[(i + s2) % BC] >>> 8) & 0xFF] ^ (tt >>> 8));
- out[outOffset++] = (byte) (Si[t[(i + s3) % BC] & 0xFF] ^ tt);
+ out[outOffset++] = (byte)(Si[(t[ i ] >>> 24) ] ^ (tt >>> 24));
+ out[outOffset++] = (byte)(Si[(t[(i + s1) % BC] >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[outOffset++] = (byte)(Si[(t[(i + s2) % BC] >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[outOffset++] = (byte)(Si[ t[(i + s3) % BC] & 0xFF] ^ tt );
}
if (Configuration.DEBUG)
log.fine("PT=" + Util.toString(out, outOffset - bs, bs));
@@ -471,32 +409,46 @@ public final class Rijndael extends BaseCipher
private static void aesEncrypt(byte[] in, int i, byte[] out, int j, Object key)
{
- int[][] Ke = (int[][]) ((Object[]) key)[0]; // extract encryption round keys
+ int[][] Ke = (int[][])((Object[]) key)[0]; // extract encryption round keys
int ROUNDS = Ke.length - 1;
int[] Ker = Ke[0];
-
// plaintext to ints + key
- int t0 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Ker[0];
- int t1 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Ker[1];
- int t2 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Ker[2];
- int t3 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Ker[3];
-
+ int t0 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Ker[0];
+ int t1 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Ker[1];
+ int t2 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Ker[2];
+ int t3 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Ker[3];
int a0, a1, a2, a3;
- for (int r = 1; r < ROUNDS; r++)
- { // apply round transforms
+ for (int r = 1; r < ROUNDS; r++) // apply round transforms
+ {
Ker = Ke[r];
- a0 = (T1[(t0 >>> 24)] ^ T2[(t1 >>> 16) & 0xFF] ^ T3[(t2 >>> 8) & 0xFF] ^ T4[t3 & 0xFF])
- ^ Ker[0];
- a1 = (T1[(t1 >>> 24)] ^ T2[(t2 >>> 16) & 0xFF] ^ T3[(t3 >>> 8) & 0xFF] ^ T4[t0 & 0xFF])
- ^ Ker[1];
- a2 = (T1[(t2 >>> 24)] ^ T2[(t3 >>> 16) & 0xFF] ^ T3[(t0 >>> 8) & 0xFF] ^ T4[t1 & 0xFF])
- ^ Ker[2];
- a3 = (T1[(t3 >>> 24)] ^ T2[(t0 >>> 16) & 0xFF] ^ T3[(t1 >>> 8) & 0xFF] ^ T4[t2 & 0xFF])
- ^ Ker[3];
+ a0 = (T1[(t0 >>> 24) ]
+ ^ T2[(t1 >>> 16) & 0xFF]
+ ^ T3[(t2 >>> 8) & 0xFF]
+ ^ T4[ t3 & 0xFF]) ^ Ker[0];
+ a1 = (T1[(t1 >>> 24) ]
+ ^ T2[(t2 >>> 16) & 0xFF]
+ ^ T3[(t3 >>> 8) & 0xFF]
+ ^ T4[ t0 & 0xFF]) ^ Ker[1];
+ a2 = (T1[(t2 >>> 24) ]
+ ^ T2[(t3 >>> 16) & 0xFF]
+ ^ T3[(t0 >>> 8) & 0xFF]
+ ^ T4[ t1 & 0xFF]) ^ Ker[2];
+ a3 = (T1[(t3 >>> 24) ]
+ ^ T2[(t0 >>> 16) & 0xFF]
+ ^ T3[(t1 >>> 8) & 0xFF]
+ ^ T4[ t2 & 0xFF]) ^ Ker[3];
t0 = a0;
t1 = a1;
t2 = a2;
@@ -508,57 +460,72 @@ public final class Rijndael extends BaseCipher
// last round is special
Ker = Ke[ROUNDS];
int tt = Ker[0];
- out[j++] = (byte) (S[(t0 >>> 24)] ^ (tt >>> 24));
- out[j++] = (byte) (S[(t1 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (S[(t2 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (S[t3 & 0xFF] ^ tt);
+ out[j++] = (byte)(S[(t0 >>> 24) ] ^ (tt >>> 24));
+ out[j++] = (byte)(S[(t1 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(S[(t2 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(S[ t3 & 0xFF] ^ tt );
tt = Ker[1];
- out[j++] = (byte) (S[(t1 >>> 24)] ^ (tt >>> 24));
- out[j++] = (byte) (S[(t2 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (S[(t3 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (S[t0 & 0xFF] ^ tt);
+ out[j++] = (byte)(S[(t1 >>> 24) ] ^ (tt >>> 24));
+ out[j++] = (byte)(S[(t2 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(S[(t3 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(S[ t0 & 0xFF] ^ tt );
tt = Ker[2];
- out[j++] = (byte) (S[(t2 >>> 24)] ^ (tt >>> 24));
- out[j++] = (byte) (S[(t3 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (S[(t0 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (S[t1 & 0xFF] ^ tt);
+ out[j++] = (byte)(S[(t2 >>> 24) ] ^ (tt >>> 24));
+ out[j++] = (byte)(S[(t3 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(S[(t0 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(S[ t1 & 0xFF] ^ tt );
tt = Ker[3];
- out[j++] = (byte) (S[(t3 >>> 24)] ^ (tt >>> 24));
- out[j++] = (byte) (S[(t0 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (S[(t1 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (S[t2 & 0xFF] ^ tt);
+ out[j++] = (byte)(S[(t3 >>> 24) ] ^ (tt >>> 24));
+ out[j++] = (byte)(S[(t0 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(S[(t1 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(S[ t2 & 0xFF] ^ tt );
if (Configuration.DEBUG)
log.fine("CT=" + Util.toString(out, j - 16, 16));
}
private static void aesDecrypt(byte[] in, int i, byte[] out, int j, Object key)
{
- int[][] Kd = (int[][]) ((Object[]) key)[1]; // extract decryption round keys
+ int[][] Kd = (int[][])((Object[]) key)[1]; // extract decryption round keys
int ROUNDS = Kd.length - 1;
int[] Kdr = Kd[0];
-
// ciphertext to ints + key
- int t0 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Kdr[0];
- int t1 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Kdr[1];
- int t2 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Kdr[2];
- int t3 = (in[i++] << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ Kdr[3];
+ int t0 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Kdr[0];
+ int t1 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Kdr[1];
+ int t2 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Kdr[2];
+ int t3 = (in[i++] << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ Kdr[3];
int a0, a1, a2, a3;
- for (int r = 1; r < ROUNDS; r++)
- { // apply round transforms
+ for (int r = 1; r < ROUNDS; r++) // apply round transforms
+ {
Kdr = Kd[r];
- a0 = (T5[(t0 >>> 24)] ^ T6[(t3 >>> 16) & 0xFF] ^ T7[(t2 >>> 8) & 0xFF] ^ T8[t1 & 0xFF])
- ^ Kdr[0];
- a1 = (T5[(t1 >>> 24)] ^ T6[(t0 >>> 16) & 0xFF] ^ T7[(t3 >>> 8) & 0xFF] ^ T8[t2 & 0xFF])
- ^ Kdr[1];
- a2 = (T5[(t2 >>> 24)] ^ T6[(t1 >>> 16) & 0xFF] ^ T7[(t0 >>> 8) & 0xFF] ^ T8[t3 & 0xFF])
- ^ Kdr[2];
- a3 = (T5[(t3 >>> 24)] ^ T6[(t2 >>> 16) & 0xFF] ^ T7[(t1 >>> 8) & 0xFF] ^ T8[t0 & 0xFF])
- ^ Kdr[3];
+ a0 = (T5[(t0 >>> 24) ]
+ ^ T6[(t3 >>> 16) & 0xFF]
+ ^ T7[(t2 >>> 8) & 0xFF]
+ ^ T8[ t1 & 0xFF]) ^ Kdr[0];
+ a1 = (T5[(t1 >>> 24) ]
+ ^ T6[(t0 >>> 16) & 0xFF]
+ ^ T7[(t3 >>> 8) & 0xFF]
+ ^ T8[ t2 & 0xFF]) ^ Kdr[1];
+ a2 = (T5[(t2 >>> 24) ]
+ ^ T6[(t1 >>> 16) & 0xFF]
+ ^ T7[(t0 >>> 8) & 0xFF]
+ ^ T8[ t3 & 0xFF]) ^ Kdr[2];
+ a3 = (T5[(t3 >>> 24) ]
+ ^ T6[(t2 >>> 16) & 0xFF]
+ ^ T7[(t1 >>> 8) & 0xFF]
+ ^ T8[ t0 & 0xFF]) ^ Kdr[3];
t0 = a0;
t1 = a1;
t2 = a2;
@@ -570,34 +537,29 @@ public final class Rijndael extends BaseCipher
// last round is special
Kdr = Kd[ROUNDS];
int tt = Kdr[0];
- out[j++] = (byte) (Si[(t0 >>> 24)] ^ (tt >>> 24));
- out[j++] = (byte) (Si[(t3 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (Si[(t2 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (Si[t1 & 0xFF] ^ tt);
+ out[j++] = (byte)(Si[(t0 >>> 24) ] ^ (tt >>> 24));
+ out[j++] = (byte)(Si[(t3 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(Si[(t2 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(Si[ t1 & 0xFF] ^ tt );
tt = Kdr[1];
- out[j++] = (byte) (Si[(t1 >>> 24)] ^ (tt >>> 24));
- out[j++] = (byte) (Si[(t0 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (Si[(t3 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (Si[t2 & 0xFF] ^ tt);
+ out[j++] = (byte)(Si[(t1 >>> 24) ] ^ (tt >>> 24));
+ out[j++] = (byte)(Si[(t0 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(Si[(t3 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(Si[ t2 & 0xFF] ^ tt );
tt = Kdr[2];
- out[j++] = (byte) (Si[(t2 >>> 24)] ^ (tt >>> 24));
- out[j++] = (byte) (Si[(t1 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (Si[(t0 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (Si[t3 & 0xFF] ^ tt);
+ out[j++] = (byte)(Si[(t2 >>> 24) ] ^ (tt >>> 24));
+ out[j++] = (byte)(Si[(t1 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(Si[(t0 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(Si[ t3 & 0xFF] ^ tt );
tt = Kdr[3];
- out[j++] = (byte) (Si[(t3 >>> 24)] ^ (tt >>> 24));
- out[j++] = (byte) (Si[(t2 >>> 16) & 0xFF] ^ (tt >>> 16));
- out[j++] = (byte) (Si[(t1 >>> 8) & 0xFF] ^ (tt >>> 8));
- out[j++] = (byte) (Si[t0 & 0xFF] ^ tt);
+ out[j++] = (byte)(Si[(t3 >>> 24) ] ^ (tt >>> 24));
+ out[j++] = (byte)(Si[(t2 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[j++] = (byte)(Si[(t1 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[j++] = (byte)(Si[ t0 & 0xFF] ^ tt );
if (Configuration.DEBUG)
log.fine("PT=" + Util.toString(out, j - 16, 16));
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.lang.Cloneable interface implementation ----------------------------
-
public Object clone()
{
Rijndael result = new Rijndael();
@@ -606,14 +568,12 @@ public final class Rijndael extends BaseCipher
return result;
}
- // IBlockCipherSpi interface implementation --------------------------------
-
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(128 / 8));
- al.add(new Integer(192 / 8));
- al.add(new Integer(256 / 8));
+ al.add(Integer.valueOf(128 / 8));
+ al.add(Integer.valueOf(192 / 8));
+ al.add(Integer.valueOf(256 / 8));
return Collections.unmodifiableList(al).iterator();
}
@@ -621,9 +581,9 @@ public final class Rijndael extends BaseCipher
public Iterator keySizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(128 / 8));
- al.add(new Integer(192 / 8));
- al.add(new Integer(256 / 8));
+ al.add(Integer.valueOf(128 / 8));
+ al.add(Integer.valueOf(192 / 8));
+ al.add(Integer.valueOf(256 / 8));
return Collections.unmodifiableList(al).iterator();
}
@@ -631,7 +591,7 @@ public final class Rijndael extends BaseCipher
/**
* Expands a user-supplied key material into a session key for a designated
* <i>block size</i>.
- *
+ *
* @param k the 128/192/256-bit user-key to use.
* @param bs the block size in bytes of this Rijndael.
* @return an Object encapsulating the session key.
@@ -641,18 +601,11 @@ public final class Rijndael extends BaseCipher
public Object makeKey(byte[] k, int bs) throws InvalidKeyException
{
if (k == null)
- {
- throw new InvalidKeyException("Empty key");
- }
- if (!(k.length == 16 || k.length == 24 || k.length == 32))
- {
- throw new InvalidKeyException("Incorrect key length");
- }
- if (!(bs == 16 || bs == 24 || bs == 32))
- {
- throw new IllegalArgumentException();
- }
-
+ throw new InvalidKeyException("Empty key");
+ if (! (k.length == 16 || k.length == 24 || k.length == 32))
+ throw new InvalidKeyException("Incorrect key length");
+ if (! (bs == 16 || bs == 24 || bs == 32))
+ throw new IllegalArgumentException();
int ROUNDS = getRounds(k.length, bs);
int BC = bs / 4;
int[][] Ke = new int[ROUNDS + 1][BC]; // encryption round keys
@@ -661,13 +614,12 @@ public final class Rijndael extends BaseCipher
int KC = k.length / 4;
int[] tk = new int[KC];
int i, j;
-
// copy user material bytes into temporary ints
for (i = 0, j = 0; i < KC;)
- {
- tk[i++] = k[j++] << 24 | (k[j++] & 0xFF) << 16 | (k[j++] & 0xFF) << 8
- | (k[j++] & 0xFF);
- }
+ tk[i++] = k[j++] << 24
+ | (k[j++] & 0xFF) << 16
+ | (k[j++] & 0xFF) << 8
+ | (k[j++] & 0xFF);
// copy values into round key arrays
int t = 0;
for (j = 0; (j < KC) && (t < ROUND_KEY_COUNT); j++, t++)
@@ -681,31 +633,23 @@ public final class Rijndael extends BaseCipher
// extrapolate using phi (the round key evolution function)
tt = tk[KC - 1];
tk[0] ^= (S[(tt >>> 16) & 0xFF] & 0xFF) << 24
- ^ (S[(tt >>> 8) & 0xFF] & 0xFF) << 16
- ^ (S[tt & 0xFF] & 0xFF) << 8 ^ (S[(tt >>> 24)] & 0xFF)
- ^ rcon[rconpointer++] << 24;
+ ^ (S[(tt >>> 8) & 0xFF] & 0xFF) << 16
+ ^ (S[ tt & 0xFF] & 0xFF) << 8
+ ^ (S[(tt >>> 24) ] & 0xFF) ^ rcon[rconpointer++] << 24;
if (KC != 8)
- {
- for (i = 1, j = 0; i < KC;)
- {
- tk[i++] ^= tk[j++];
- }
- }
+ for (i = 1, j = 0; i < KC;)
+ tk[i++] ^= tk[j++];
else
{
for (i = 1, j = 0; i < KC / 2;)
- {
- tk[i++] ^= tk[j++];
- }
+ tk[i++] ^= tk[j++];
tt = tk[KC / 2 - 1];
- tk[KC / 2] ^= (S[tt & 0xFF] & 0xFF)
- ^ (S[(tt >>> 8) & 0xFF] & 0xFF) << 8
- ^ (S[(tt >>> 16) & 0xFF] & 0xFF) << 16
- ^ S[(tt >>> 24) & 0xFF] << 24;
+ tk[KC / 2] ^= (S[ tt & 0xFF] & 0xFF)
+ ^ (S[(tt >>> 8) & 0xFF] & 0xFF) << 8
+ ^ (S[(tt >>> 16) & 0xFF] & 0xFF) << 16
+ ^ S[(tt >>> 24) & 0xFF] << 24;
for (j = KC / 2, i = j + 1; i < KC;)
- {
- tk[i++] ^= tk[j++];
- }
+ tk[i++] ^= tk[j++];
}
// copy values into round key arrays
for (j = 0; (j < KC) && (t < ROUND_KEY_COUNT); j++, t++)
@@ -714,51 +658,36 @@ public final class Rijndael extends BaseCipher
Kd[ROUNDS - (t / BC)][t % BC] = tk[j];
}
}
- for (int r = 1; r < ROUNDS; r++)
- { // inverse MixColumn where needed
- for (j = 0; j < BC; j++)
- {
- tt = Kd[r][j];
- Kd[r][j] = U1[(tt >>> 24)] ^ U2[(tt >>> 16) & 0xFF]
- ^ U3[(tt >>> 8) & 0xFF] ^ U4[tt & 0xFF];
- }
- }
-
+ for (int r = 1; r < ROUNDS; r++) // inverse MixColumn where needed
+ for (j = 0; j < BC; j++)
+ {
+ tt = Kd[r][j];
+ Kd[r][j] = U1[(tt >>> 24) ]
+ ^ U2[(tt >>> 16) & 0xFF]
+ ^ U3[(tt >>> 8) & 0xFF]
+ ^ U4[ tt & 0xFF];
+ }
return new Object[] { Ke, Kd };
}
public void encrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
- if (!(bs == 16 || bs == 24 || bs == 32))
- {
- throw new IllegalArgumentException();
- }
-
+ if (! (bs == 16 || bs == 24 || bs == 32))
+ throw new IllegalArgumentException();
if (bs == DEFAULT_BLOCK_SIZE)
- {
- aesEncrypt(in, i, out, j, k);
- }
+ aesEncrypt(in, i, out, j, k);
else
- {
- rijndaelEncrypt(in, i, out, j, k, bs);
- }
+ rijndaelEncrypt(in, i, out, j, k, bs);
}
public void decrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
- if (!(bs == 16 || bs == 24 || bs == 32))
- {
- throw new IllegalArgumentException();
- }
-
+ if (! (bs == 16 || bs == 24 || bs == 32))
+ throw new IllegalArgumentException();
if (bs == DEFAULT_BLOCK_SIZE)
- {
- aesDecrypt(in, i, out, j, k);
- }
+ aesDecrypt(in, i, out, j, k);
else
- {
- rijndaelDecrypt(in, i, out, j, k, bs);
- }
+ rijndaelDecrypt(in, i, out, j, k, bs);
}
public boolean selfTest()
@@ -767,11 +696,9 @@ public final class Rijndael extends BaseCipher
{
boolean result = super.selfTest(); // do symmetry tests
if (result)
- {
- result = testKat(KAT_KEY, KAT_CT);
- }
+ result = testKat(KAT_KEY, KAT_CT);
valid = Boolean.valueOf(result);
}
return valid.booleanValue();
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/Serpent.java b/gnu/javax/crypto/cipher/Serpent.java
index 2ed1e4b55..636e311e7 100644
--- a/gnu/javax/crypto/cipher/Serpent.java
+++ b/gnu/javax/crypto/cipher/Serpent.java
@@ -47,78 +47,57 @@ import java.util.Collections;
import java.util.Iterator;
/**
- * <p>Serpent is a 32-round substitution-permutation network block cipher,
+ * Serpent is a 32-round substitution-permutation network block cipher,
* operating on 128-bit blocks and accepting keys of 128, 192, and 256 bits in
* length. At each round the plaintext is XORed with a 128 bit portion of the
* session key -- a 4224 bit key computed from the input key -- then one of
* eight S-boxes are applied, and finally a simple linear transformation is
* done. Decryption does the exact same thing in reverse order, and using the
- * eight inverses of the S-boxes.</p>
- *
- * <p>Serpent was designed by Ross Anderson, Eli Biham, and Lars Knudsen as a
- * proposed cipher for the Advanced Encryption Standard.</p>
- *
- * <p>Serpent can be sped up greatly by replacing S-box substitution with a
- * sequence of binary operations, and the optimal implementation depends
- * upon finding the fastest sequence of binary operations that reproduce this
- * substitution. This implementation uses the S-boxes discovered by
- * <a href="http://www.ii.uib.no/~osvik/">Dag Arne Osvik</a>, which are
- * optimized for the Pentium family of processors.</p>
- *
- * <p>References:</p>
- *
+ * eight inverses of the S-boxes.
+ * <p>
+ * Serpent was designed by Ross Anderson, Eli Biham, and Lars Knudsen as a
+ * proposed cipher for the Advanced Encryption Standard.
+ * <p>
+ * Serpent can be sped up greatly by replacing S-box substitution with a
+ * sequence of binary operations, and the optimal implementation depends upon
+ * finding the fastest sequence of binary operations that reproduce this
+ * substitution. This implementation uses the S-boxes discovered by <a
+ * href="http://www.ii.uib.no/~osvik/">Dag Arne Osvik</a>, which are optimized
+ * for the Pentium family of processors.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cl.cam.ac.uk/~rja14/serpent.html">Serpent: A
- * Candidate Block Cipher for the Advanced Encryption Standard.</a></li>
+ * <li><a href="http://www.cl.cam.ac.uk/~rja14/serpent.html">Serpent: A
+ * Candidate Block Cipher for the Advanced Encryption Standard.</a></li>
* </ol>
*/
-public class Serpent extends BaseCipher
+public class Serpent
+ extends BaseCipher
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final int DEFAULT_KEY_SIZE = 16;
-
private static final int DEFAULT_BLOCK_SIZE = 16;
-
private static final int ROUNDS = 32;
-
/** The fractional part of the golden ratio, (sqrt(5)+1)/2. */
private static final int PHI = 0x9e3779b9;
-
/**
- * KAT vector (from ecb_vk):
- * I=9
+ * KAT vector (from ecb_vk): I=9
* KEY=008000000000000000000000000000000000000000000000
* CT=5587B5BCB9EE5A28BA2BACC418005240
*/
- private static final byte[] KAT_KEY = Util.toReversedBytesFromString("008000000000000000000000000000000000000000000000");
-
- private static final byte[] KAT_CT = Util.toReversedBytesFromString("5587B5BCB9EE5A28BA2BACC418005240");
-
+ private static final byte[] KAT_KEY = Util.toReversedBytesFromString(
+ "008000000000000000000000000000000000000000000000");
+ private static final byte[] KAT_CT =
+ Util.toReversedBytesFromString("5587B5BCB9EE5A28BA2BACC418005240");
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
-
private int x0, x1, x2, x3, x4;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial zero-argument constructor. */
public Serpent()
{
super(Registry.SERPENT_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.lang.Cloneable interface implementation ----------------------------
-
public Object clone()
{
Serpent result = new Serpent();
@@ -126,20 +105,17 @@ public class Serpent extends BaseCipher
return result;
}
- // IBlockCipherSpi interface implementation --------------------------------
-
public Iterator blockSizes()
{
- return Collections.singleton(new Integer(DEFAULT_BLOCK_SIZE)).iterator();
+ return Collections.singleton(Integer.valueOf(DEFAULT_BLOCK_SIZE)).iterator();
}
public Iterator keySizes()
{
ArrayList keySizes = new ArrayList();
- keySizes.add(new Integer(16));
- keySizes.add(new Integer(24));
- keySizes.add(new Integer(32));
-
+ keySizes.add(Integer.valueOf(16));
+ keySizes.add(Integer.valueOf(24));
+ keySizes.add(Integer.valueOf(32));
return Collections.unmodifiableList(keySizes).iterator();
}
@@ -148,24 +124,19 @@ public class Serpent extends BaseCipher
// Not strictly true, but here to conform with the AES proposal.
// This restriction can be removed if deemed necessary.
if (kb.length != 16 && kb.length != 24 && kb.length != 32)
- {
- throw new InvalidKeyException("Key length is not 16, 24, or 32 bytes");
- }
+ throw new InvalidKeyException("Key length is not 16, 24, or 32 bytes");
Key key = new Key();
-
// Here w is our "pre-key".
int[] w = new int[4 * (ROUNDS + 1)];
int i, j;
for (i = 0, j = 0; i < 8 && j < kb.length; i++)
- {
- w[i] = (kb[j++] & 0xff) | (kb[j++] & 0xff) << 8
- | (kb[j++] & 0xff) << 16 | (kb[j++] & 0xff) << 24;
- }
+ w[i] = (kb[j++] & 0xff)
+ | (kb[j++] & 0xff) << 8
+ | (kb[j++] & 0xff) << 16
+ | (kb[j++] & 0xff) << 24;
// Pad key if < 256 bits.
if (i != 8)
- {
- w[i] = 1;
- }
+ w[i] = 1;
// Transform using w_i-8 ... w_i-1
for (i = 8, j = 0; i < 16; i++)
{
@@ -174,16 +145,13 @@ public class Serpent extends BaseCipher
}
// Translate by 8.
for (i = 0; i < 8; i++)
- {
- w[i] = w[i + 8];
- }
+ w[i] = w[i + 8];
// Transform the rest of the key.
for (; i < w.length; i++)
{
int t = w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ PHI ^ i;
w[i] = t << 11 | t >>> 21;
}
-
// After these s-boxes the pre-key (w, above) will become the
// session key (key, below).
sbox3(w[0], w[1], w[2], w[3]);
@@ -351,7 +319,6 @@ public class Serpent extends BaseCipher
key.k129 = x1;
key.k130 = x2;
key.k131 = x3;
-
return key;
}
@@ -359,16 +326,22 @@ public class Serpent extends BaseCipher
Object K, int bs)
{
Key key = (Key) K;
-
- x0 = (in[i] & 0xff) | (in[i + 1] & 0xff) << 8 | (in[i + 2] & 0xff) << 16
- | (in[i + 3] & 0xff) << 24;
- x1 = (in[i + 4] & 0xff) | (in[i + 5] & 0xff) << 8
- | (in[i + 6] & 0xff) << 16 | (in[i + 7] & 0xff) << 24;
- x2 = (in[i + 8] & 0xff) | (in[i + 9] & 0xff) << 8
- | (in[i + 10] & 0xff) << 16 | (in[i + 11] & 0xff) << 24;
- x3 = (in[i + 12] & 0xff) | (in[i + 13] & 0xff) << 8
- | (in[i + 14] & 0xff) << 16 | (in[i + 15] & 0xff) << 24;
-
+ x0 = (in[i ] & 0xff)
+ | (in[i + 1] & 0xff) << 8
+ | (in[i + 2] & 0xff) << 16
+ | (in[i + 3] & 0xff) << 24;
+ x1 = (in[i + 4] & 0xff)
+ | (in[i + 5] & 0xff) << 8
+ | (in[i + 6] & 0xff) << 16
+ | (in[i + 7] & 0xff) << 24;
+ x2 = (in[i + 8] & 0xff)
+ | (in[i + 9] & 0xff) << 8
+ | (in[i + 10] & 0xff) << 16
+ | (in[i + 11] & 0xff) << 24;
+ x3 = (in[i + 12] & 0xff)
+ | (in[i + 13] & 0xff) << 8
+ | (in[i + 14] & 0xff) << 16
+ | (in[i + 15] & 0xff) << 24;
x0 ^= key.k0;
x1 ^= key.k1;
x2 ^= key.k2;
@@ -412,7 +385,6 @@ public class Serpent extends BaseCipher
x0 = x3;
x3 = x2;
x2 = x4;
-
x0 ^= key.k32;
x1 ^= key.k33;
x2 ^= key.k34;
@@ -456,7 +428,6 @@ public class Serpent extends BaseCipher
x0 = x3;
x3 = x2;
x2 = x4;
-
x0 ^= key.k64;
x1 ^= key.k65;
x2 ^= key.k66;
@@ -500,7 +471,6 @@ public class Serpent extends BaseCipher
x0 = x3;
x3 = x2;
x2 = x4;
-
x0 ^= key.k96;
x1 ^= key.k97;
x2 ^= key.k98;
@@ -548,39 +518,44 @@ public class Serpent extends BaseCipher
x1 ^= key.k129;
x2 ^= key.k130;
x3 ^= key.k131;
-
- out[o] = (byte) x0;
- out[o + 1] = (byte) (x0 >>> 8);
- out[o + 2] = (byte) (x0 >>> 16);
- out[o + 3] = (byte) (x0 >>> 24);
- out[o + 4] = (byte) x1;
- out[o + 5] = (byte) (x1 >>> 8);
- out[o + 6] = (byte) (x1 >>> 16);
- out[o + 7] = (byte) (x1 >>> 24);
- out[o + 8] = (byte) x2;
- out[o + 9] = (byte) (x2 >>> 8);
- out[o + 10] = (byte) (x2 >>> 16);
- out[o + 11] = (byte) (x2 >>> 24);
+ out[o ] = (byte) x0;
+ out[o + 1] = (byte)(x0 >>> 8);
+ out[o + 2] = (byte)(x0 >>> 16);
+ out[o + 3] = (byte)(x0 >>> 24);
+ out[o + 4] = (byte) x1;
+ out[o + 5] = (byte)(x1 >>> 8);
+ out[o + 6] = (byte)(x1 >>> 16);
+ out[o + 7] = (byte)(x1 >>> 24);
+ out[o + 8] = (byte) x2;
+ out[o + 9] = (byte)(x2 >>> 8);
+ out[o + 10] = (byte)(x2 >>> 16);
+ out[o + 11] = (byte)(x2 >>> 24);
out[o + 12] = (byte) x3;
- out[o + 13] = (byte) (x3 >>> 8);
- out[o + 14] = (byte) (x3 >>> 16);
- out[o + 15] = (byte) (x3 >>> 24);
+ out[o + 13] = (byte)(x3 >>> 8);
+ out[o + 14] = (byte)(x3 >>> 16);
+ out[o + 15] = (byte)(x3 >>> 24);
}
public synchronized void decrypt(byte[] in, int i, byte[] out, int o,
Object K, int bs)
{
Key key = (Key) K;
-
- x0 = (in[i] & 0xff) | (in[i + 1] & 0xff) << 8 | (in[i + 2] & 0xff) << 16
- | (in[i + 3] & 0xff) << 24;
- x1 = (in[i + 4] & 0xff) | (in[i + 5] & 0xff) << 8
- | (in[i + 6] & 0xff) << 16 | (in[i + 7] & 0xff) << 24;
- x2 = (in[i + 8] & 0xff) | (in[i + 9] & 0xff) << 8
- | (in[i + 10] & 0xff) << 16 | (in[i + 11] & 0xff) << 24;
- x3 = (in[i + 12] & 0xff) | (in[i + 13] & 0xff) << 8
- | (in[i + 14] & 0xff) << 16 | (in[i + 15] & 0xff) << 24;
-
+ x0 = (in[i ] & 0xff)
+ | (in[i + 1] & 0xff) << 8
+ | (in[i + 2] & 0xff) << 16
+ | (in[i + 3] & 0xff) << 24;
+ x1 = (in[i + 4] & 0xff)
+ | (in[i + 5] & 0xff) << 8
+ | (in[i + 6] & 0xff) << 16
+ | (in[i + 7] & 0xff) << 24;
+ x2 = (in[i + 8] & 0xff)
+ | (in[i + 9] & 0xff) << 8
+ | (in[i + 10] & 0xff) << 16
+ | (in[i + 11] & 0xff) << 24;
+ x3 = (in[i + 12] & 0xff)
+ | (in[i + 13] & 0xff) << 8
+ | (in[i + 14] & 0xff) << 16
+ | (in[i + 15] & 0xff) << 24;
x0 ^= key.k128;
x1 ^= key.k129;
x2 ^= key.k130;
@@ -629,7 +604,6 @@ public class Serpent extends BaseCipher
x1 = x3;
x3 = x4;
x4 = x2;
-
x3 ^= key.k92;
x0 ^= key.k93;
x1 ^= key.k94;
@@ -673,7 +647,6 @@ public class Serpent extends BaseCipher
x1 = x3;
x3 = x4;
x4 = x2;
-
x3 ^= key.k60;
x0 ^= key.k61;
x1 ^= key.k62;
@@ -717,7 +690,6 @@ public class Serpent extends BaseCipher
x1 = x3;
x3 = x4;
x4 = x2;
-
x3 ^= key.k28;
x0 ^= key.k29;
x1 ^= key.k30;
@@ -756,28 +728,26 @@ public class Serpent extends BaseCipher
x2 = x1;
x1 = x3;
x3 = x4;
-
x0 ^= key.k0;
x1 ^= key.k1;
x2 ^= key.k2;
x3 ^= key.k3;
-
- out[o] = (byte) x0;
- out[o + 1] = (byte) (x0 >>> 8);
- out[o + 2] = (byte) (x0 >>> 16);
- out[o + 3] = (byte) (x0 >>> 24);
- out[o + 4] = (byte) x1;
- out[o + 5] = (byte) (x1 >>> 8);
- out[o + 6] = (byte) (x1 >>> 16);
- out[o + 7] = (byte) (x1 >>> 24);
- out[o + 8] = (byte) x2;
- out[o + 9] = (byte) (x2 >>> 8);
- out[o + 10] = (byte) (x2 >>> 16);
- out[o + 11] = (byte) (x2 >>> 24);
+ out[o ] = (byte) x0;
+ out[o + 1] = (byte)(x0 >>> 8);
+ out[o + 2] = (byte)(x0 >>> 16);
+ out[o + 3] = (byte)(x0 >>> 24);
+ out[o + 4] = (byte) x1;
+ out[o + 5] = (byte)(x1 >>> 8);
+ out[o + 6] = (byte)(x1 >>> 16);
+ out[o + 7] = (byte)(x1 >>> 24);
+ out[o + 8] = (byte) x2;
+ out[o + 9] = (byte)(x2 >>> 8);
+ out[o + 10] = (byte)(x2 >>> 16);
+ out[o + 11] = (byte)(x2 >>> 24);
out[o + 12] = (byte) x3;
- out[o + 13] = (byte) (x3 >>> 8);
- out[o + 14] = (byte) (x3 >>> 16);
- out[o + 15] = (byte) (x3 >>> 24);
+ out[o + 13] = (byte)(x3 >>> 8);
+ out[o + 14] = (byte)(x3 >>> 16);
+ out[o + 15] = (byte)(x3 >>> 24);
}
public boolean selfTest()
@@ -786,19 +756,14 @@ public class Serpent extends BaseCipher
{
boolean result = super.selfTest(); // do symmetry tests
if (result)
- {
- result = testKat(KAT_KEY, KAT_CT);
- }
+ result = testKat(KAT_KEY, KAT_CT);
valid = Boolean.valueOf(result);
}
return valid.booleanValue();
}
- // Own methods. ----------------------------------------------------------
-
// These first few S-boxes operate directly on the "registers",
// x0..x4, and perform the linear transform.
-
private void sbox0()
{
x3 ^= x0;
@@ -1492,8 +1457,6 @@ public class Serpent extends BaseCipher
x2 ^= x1;
}
- // These S-Box functions are used in the key setup.
-
/** S-Box 0. */
private void sbox0(int r0, int r1, int r2, int r3)
{
@@ -1654,15 +1617,9 @@ public class Serpent extends BaseCipher
x3 = r0;
}
- // Inner classes.
- // -----------------------------------------------------------------------
-
- private class Key implements Cloneable
+ private class Key
+ implements Cloneable
{
-
- // Constants and variables.
- // --------------------------------------------------------------------
-
int k0, k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15,
k16, k17, k18, k19, k20, k21, k22, k23, k24, k25, k26, k27, k28, k29,
k30, k31, k32, k33, k34, k35, k36, k37, k38, k39, k40, k41, k42, k43,
@@ -1674,9 +1631,6 @@ public class Serpent extends BaseCipher
k112, k113, k114, k115, k116, k117, k118, k119, k120, k121, k122, k123,
k124, k125, k126, k127, k128, k129, k130, k131;
- // Constructors.
- // --------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
Key()
{
@@ -1819,12 +1773,9 @@ public class Serpent extends BaseCipher
this.k131 = that.k131;
}
- // Cloneable interface implementation.
- // --------------------------------------------------------------------
-
public Object clone()
{
return new Key(this);
}
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/Square.java b/gnu/javax/crypto/cipher/Square.java
index a73116eb4..af738da04 100644
--- a/gnu/javax/crypto/cipher/Square.java
+++ b/gnu/javax/crypto/cipher/Square.java
@@ -47,145 +47,74 @@ import java.util.Collections;
import java.util.Iterator;
/**
- * <p>Square is a 128-bit key, 128-bit block cipher algorithm developed by Joan
- * Daemen, Lars Knudsen and Vincent Rijmen.</p>
- *
- * <p>References:</p>
- *
+ * Square is a 128-bit key, 128-bit block cipher algorithm developed by Joan
+ * Daemen, Lars Knudsen and Vincent Rijmen.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.esat.kuleuven.ac.be/~rijmen/square/">The block
- * cipher Square</a>.<br>
- * <a href="mailto:daemen.j@protonworld.com">Joan Daemen</a>,
- * <a href="mailto:lars.knudsen@esat.kuleuven.ac.be">Lars Knudsen</a> and
- * <a href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a>.</li>
+ * <li><a href="http://www.esat.kuleuven.ac.be/~rijmen/square/">The block
+ * cipher Square</a>.<br>
+ * <a href="mailto:daemen.j@protonworld.com">Joan Daemen</a>, <a
+ * href="mailto:lars.knudsen@esat.kuleuven.ac.be">Lars Knudsen</a> and <a
+ * href="mailto:vincent.rijmen@esat.kuleuven.ac.be">Vincent Rijmen</a>.</li>
* </ol>
*/
-public final class Square extends BaseCipher
+public final class Square
+ extends BaseCipher
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final int DEFAULT_BLOCK_SIZE = 16; // in bytes
-
private static final int DEFAULT_KEY_SIZE = 16; // in bytes
-
private static final int ROUNDS = 8;
-
private static final int ROOT = 0x1F5; // for generating GF(2**8)
-
private static final int[] OFFSET = new int[ROUNDS];
-
- private static final String Sdata = "\uB1CE\uC395\u5AAD\uE702\u4D44\uFB91\u0C87\uA150"
- + "\uCB67\u54DD\u468F\uE14E\uF0FD\uFCEB\uF9C4\u1A6E"
- + "\u5EF5\uCC8D\u1C56\u43FE\u0761\uF875\u59FF\u0322"
- + "\u8AD1\u13EE\u8800\u0E34\u1580\u94E3\uEDB5\u5323"
- + "\u4B47\u17A7\u9035\uABD8\uB8DF\u4F57\u9A92\uDB1B"
- + "\u3CC8\u9904\u8EE0\uD77D\u85BB\u402C\u3A45\uF142"
- + "\u6520\u4118\u7225\u9370\u3605\uF20B\uA379\uEC08"
- + "\u2731\u32B6\u7CB0\u0A73\u5B7B\uB781\uD20D\u6A26"
- + "\u9E58\u9C83\u74B3\uAC30\u7A69\u770F\uAE21\uDED0"
- + "\u2E97\u10A4\u98A8\uD468\u2D62\u296D\u1649\u76C7"
- + "\uE8C1\u9637\uE5CA\uF4E9\u6312\uC2A6\u14BC\uD328"
- + "\uAF2F\uE624\u52C6\uA009\uBD8C\uCF5D\u115F\u01C5"
- + "\u9F3D\uA29B\uC93B\uBE51\u191F\u3F5C\uB2EF\u4ACD"
- + "\uBFBA\u6F64\uD9F3\u3EB4\uAADC\uD506\uC07E\uF666"
- + "\u6C84\u7138\uB91D\u7F9D\u488B\u2ADA\uA533\u8239"
- + "\uD678\u86FA\uE42B\uA91E\u8960\u6BEA\u554C\uF7E2";
-
+ private static final String Sdata =
+ "\uB1CE\uC395\u5AAD\uE702\u4D44\uFB91\u0C87\uA150"
+ + "\uCB67\u54DD\u468F\uE14E\uF0FD\uFCEB\uF9C4\u1A6E"
+ + "\u5EF5\uCC8D\u1C56\u43FE\u0761\uF875\u59FF\u0322"
+ + "\u8AD1\u13EE\u8800\u0E34\u1580\u94E3\uEDB5\u5323"
+ + "\u4B47\u17A7\u9035\uABD8\uB8DF\u4F57\u9A92\uDB1B"
+ + "\u3CC8\u9904\u8EE0\uD77D\u85BB\u402C\u3A45\uF142"
+ + "\u6520\u4118\u7225\u9370\u3605\uF20B\uA379\uEC08"
+ + "\u2731\u32B6\u7CB0\u0A73\u5B7B\uB781\uD20D\u6A26"
+ + "\u9E58\u9C83\u74B3\uAC30\u7A69\u770F\uAE21\uDED0"
+ + "\u2E97\u10A4\u98A8\uD468\u2D62\u296D\u1649\u76C7"
+ + "\uE8C1\u9637\uE5CA\uF4E9\u6312\uC2A6\u14BC\uD328"
+ + "\uAF2F\uE624\u52C6\uA009\uBD8C\uCF5D\u115F\u01C5"
+ + "\u9F3D\uA29B\uC93B\uBE51\u191F\u3F5C\uB2EF\u4ACD"
+ + "\uBFBA\u6F64\uD9F3\u3EB4\uAADC\uD506\uC07E\uF666"
+ + "\u6C84\u7138\uB91D\u7F9D\u488B\u2ADA\uA533\u8239"
+ + "\uD678\u86FA\uE42B\uA91E\u8960\u6BEA\u554C\uF7E2";
/** Substitution boxes for encryption and decryption. */
private static final byte[] Se = new byte[256];
-
private static final byte[] Sd = new byte[256];
-
/** Transposition boxes for encryption and decryption. */
private static final int[] Te = new int[256];
-
private static final int[] Td = new int[256];
-
/**
- * KAT vector (from ecb_vk):
- * I=87
- * KEY=00000000000000000000020000000000
+ * KAT vector (from ecb_vk): I=87 KEY=00000000000000000000020000000000
* CT=A9DF031B4E25E89F527EFFF89CB0BEBA
*/
- private static final byte[] KAT_KEY = Util.toBytesFromString("00000000000000000000020000000000");
-
- private static final byte[] KAT_CT = Util.toBytesFromString("A9DF031B4E25E89F527EFFF89CB0BEBA");
-
+ private static final byte[] KAT_KEY =
+ Util.toBytesFromString("00000000000000000000020000000000");
+ private static final byte[] KAT_CT =
+ Util.toBytesFromString("A9DF031B4E25E89F527EFFF89CB0BEBA");
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
-
- // Static code - to intialise lookup tables
- // -------------------------------------------------------------------------
-
static
{
int i, j;
- /*
- // Generate exp and log tables used in multiplication over GF(2 ** m)
- byte[] exp = new byte[256];
- byte[] log = new byte[256];
-
- exp[0] = 1;
- for (i = 1; i < 256; i++) {
- j = exp[i - 1] << 1;
- if ((j & 0x100) != 0) {
- j ^= ROOT; // reduce j (mod ROOT)
- }
-
- exp[i] = (byte) j;
- log[j & 0xFF] = (byte) i;
- }
-
- // Compute the substitution box Se[] and its inverse Sd[] based on
- // F(x) = x**{-1} plus affine transform of the output.
- Se[0] = 0;
- Se[1] = 1;
- for (i = 2; i < 256; i++) {
- Se[i] = exp[(255 - log[i]) & 0xFF];
- }
-
- // Let Se[i] be represented as an 8-row vector V over GF(2); the affine
- // transformation is A * V + T, where the rows of the 8 x 8 matrix A are
- // contained in trans[0]...trans[7] and the 8-row vector T is contained
- // in 0xB1.
- int[] trans = new int[] {0x01, 0x03, 0x05, 0x0F, 0x1F, 0x3D, 0x7B, 0xD6};
- int u, v;
- for (i = 0; i < 256; i++) {
- v = 0xB1; // affine part of the transform
- for (j = 0; j < 8; j++) {
- u = Se[i] & trans[j] & 0xFF; // column-wise mult. over GF(2)
- u ^= u >>> 4; // sum of all bits of u over GF(2)
- u ^= u >>> 2;
- u ^= u >>> 1;
- u &= 1;
- v ^= u << j; // row alignment of the result
- }
- Se[i] = (byte) v;
- Sd[v] = (byte) i; // inverse substitution box
- }
-
- System.out.println("Se="+Util.toUnicodeString(Se));
- System.out.println("Sd="+Util.toUnicodeString(Sd));
- */
- /**/
// re-construct Se box values
int limit = Sdata.length();
char c1;
for (i = 0, j = 0; i < limit; i++)
{
c1 = Sdata.charAt(i);
- Se[j++] = (byte) (c1 >>> 8);
+ Se[j++] = (byte)(c1 >>> 8);
Se[j++] = (byte) c1;
}
-
// compute Sd box values
for (i = 0; i < 256; i++)
- {
- Sd[Se[i] & 0xFF] = (byte) i;
- }
-
+ Sd[Se[i] & 0xFF] = (byte) i;
// generate OFFSET values
OFFSET[0] = 1;
for (i = 1; i < ROUNDS; i++)
@@ -193,9 +122,7 @@ public final class Square extends BaseCipher
OFFSET[i] = mul(OFFSET[i - 1], 2);
OFFSET[i - 1] <<= 24;
}
-
OFFSET[ROUNDS - 1] <<= 24;
-
// generate Te and Td boxes if we're not reading their values
// Notes:
// (1) The function mul() computes the product of two elements of GF(2**8)
@@ -207,111 +134,122 @@ public final class Square extends BaseCipher
for (i = 0; i < 256; i++)
{
j = Se[i] & 0xFF;
- Te[i] = (Se[i & 3] == 0) ? 0 : mul(j, 2) << 24 | j << 16 | j << 8
- | mul(j, 3);
-
+ Te[i] = (Se[i & 3] == 0) ? 0
+ : mul(j, 2) << 24
+ | j << 16
+ | j << 8
+ | mul(j, 3);
j = Sd[i] & 0xFF;
- Td[i] = (Sd[i & 3] == 0) ? 0 : mul(j, 14) << 24 | mul(j, 9) << 16
- | mul(j, 13) << 8 | mul(j, 11);
+ Td[i] = (Sd[i & 3] == 0) ? 0
+ : mul(j, 14) << 24
+ | mul(j, 9) << 16
+ | mul(j, 13) << 8
+ | mul(j, 11);
}
- /**/
}
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Square()
{
super(Registry.SQUARE_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
private static void square(byte[] in, int i, byte[] out, int j, int[][] K,
int[] T, byte[] S)
{
- int a = ((in[i++]) << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ K[0][0];
- int b = ((in[i++]) << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ K[0][1];
- int c = ((in[i++]) << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF))
- ^ K[0][2];
- int d = ((in[i++]) << 24 | (in[i++] & 0xFF) << 16 | (in[i++] & 0xFF) << 8 | (in[i] & 0xFF))
- ^ K[0][3];
-
+ int a = ((in[i++]) << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ K[0][0];
+ int b = ((in[i++]) << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ K[0][1];
+ int c = ((in[i++]) << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i++] & 0xFF) ) ^ K[0][2];
+ int d = ((in[i++]) << 24
+ | (in[i++] & 0xFF) << 16
+ | (in[i++] & 0xFF) << 8
+ | (in[i ] & 0xFF) ) ^ K[0][3];
int r, aa, bb, cc, dd;
for (r = 1; r < ROUNDS; r++)
{ // R - 1 full rounds
- aa = T[(a >>> 24)] ^ rot32R(T[(b >>> 24)], 8)
- ^ rot32R(T[(c >>> 24)], 16) ^ rot32R(T[(d >>> 24)], 24) ^ K[r][0];
- bb = T[(a >>> 16) & 0xFF] ^ rot32R(T[(b >>> 16) & 0xFF], 8)
- ^ rot32R(T[(c >>> 16) & 0xFF], 16)
- ^ rot32R(T[(d >>> 16) & 0xFF], 24) ^ K[r][1];
- cc = T[(a >>> 8) & 0xFF] ^ rot32R(T[(b >>> 8) & 0xFF], 8)
- ^ rot32R(T[(c >>> 8) & 0xFF], 16)
- ^ rot32R(T[(d >>> 8) & 0xFF], 24) ^ K[r][2];
- dd = T[a & 0xFF] ^ rot32R(T[b & 0xFF], 8) ^ rot32R(T[c & 0xFF], 16)
- ^ rot32R(T[d & 0xFF], 24) ^ K[r][3];
-
+ aa = T[(a >>> 24) ]
+ ^ rot32R(T[(b >>> 24) ], 8)
+ ^ rot32R(T[(c >>> 24) ], 16)
+ ^ rot32R(T[(d >>> 24) ], 24) ^ K[r][0];
+ bb = T[(a >>> 16) & 0xFF]
+ ^ rot32R(T[(b >>> 16) & 0xFF], 8)
+ ^ rot32R(T[(c >>> 16) & 0xFF], 16)
+ ^ rot32R(T[(d >>> 16) & 0xFF], 24) ^ K[r][1];
+ cc = T[(a >>> 8) & 0xFF]
+ ^ rot32R(T[(b >>> 8) & 0xFF], 8)
+ ^ rot32R(T[(c >>> 8) & 0xFF], 16)
+ ^ rot32R(T[(d >>> 8) & 0xFF], 24) ^ K[r][2];
+ dd = T[ a & 0xFF]
+ ^ rot32R(T[ b & 0xFF], 8)
+ ^ rot32R(T[ c & 0xFF], 16)
+ ^ rot32R(T[ d & 0xFF], 24) ^ K[r][3];
a = aa;
b = bb;
c = cc;
d = dd;
}
-
// last round (diffusion becomes only transposition)
- aa = ((S[(a >>> 24)]) << 24 | (S[(b >>> 24)] & 0xFF) << 16
- | (S[(c >>> 24)] & 0xFF) << 8 | (S[(d >>> 24)] & 0xFF))
- ^ K[r][0];
- bb = ((S[(a >>> 16) & 0xFF]) << 24 | (S[(b >>> 16) & 0xFF] & 0xFF) << 16
- | (S[(c >>> 16) & 0xFF] & 0xFF) << 8 | (S[(d >>> 16) & 0xFF] & 0xFF))
- ^ K[r][1];
- cc = ((S[(a >>> 8) & 0xFF]) << 24 | (S[(b >>> 8) & 0xFF] & 0xFF) << 16
- | (S[(c >>> 8) & 0xFF] & 0xFF) << 8 | (S[(d >>> 8) & 0xFF] & 0xFF))
- ^ K[r][2];
- dd = ((S[a & 0xFF]) << 24 | (S[b & 0xFF] & 0xFF) << 16
- | (S[c & 0xFF] & 0xFF) << 8 | (S[d & 0xFF] & 0xFF))
- ^ K[r][3];
-
- out[j++] = (byte) (aa >>> 24);
- out[j++] = (byte) (aa >>> 16);
- out[j++] = (byte) (aa >>> 8);
+ aa = ((S[(a >>> 24) ] ) << 24
+ | (S[(b >>> 24) ] & 0xFF) << 16
+ | (S[(c >>> 24) ] & 0xFF) << 8
+ | (S[(d >>> 24) ] & 0xFF) ) ^ K[r][0];
+ bb = ((S[(a >>> 16) & 0xFF] ) << 24
+ | (S[(b >>> 16) & 0xFF] & 0xFF) << 16
+ | (S[(c >>> 16) & 0xFF] & 0xFF) << 8
+ | (S[(d >>> 16) & 0xFF] & 0xFF) ) ^ K[r][1];
+ cc = ((S[(a >>> 8) & 0xFF] ) << 24
+ | (S[(b >>> 8) & 0xFF] & 0xFF) << 16
+ | (S[(c >>> 8) & 0xFF] & 0xFF) << 8
+ | (S[(d >>> 8) & 0xFF] & 0xFF) ) ^ K[r][2];
+ dd = ((S[ a & 0xFF] ) << 24
+ | (S[ b & 0xFF] & 0xFF) << 16
+ | (S[ c & 0xFF] & 0xFF) << 8
+ | (S[ d & 0xFF] & 0xFF) ) ^ K[r][3];
+ out[j++] = (byte)(aa >>> 24);
+ out[j++] = (byte)(aa >>> 16);
+ out[j++] = (byte)(aa >>> 8);
out[j++] = (byte) aa;
- out[j++] = (byte) (bb >>> 24);
- out[j++] = (byte) (bb >>> 16);
- out[j++] = (byte) (bb >>> 8);
+ out[j++] = (byte)(bb >>> 24);
+ out[j++] = (byte)(bb >>> 16);
+ out[j++] = (byte)(bb >>> 8);
out[j++] = (byte) bb;
- out[j++] = (byte) (cc >>> 24);
- out[j++] = (byte) (cc >>> 16);
- out[j++] = (byte) (cc >>> 8);
+ out[j++] = (byte)(cc >>> 24);
+ out[j++] = (byte)(cc >>> 16);
+ out[j++] = (byte)(cc >>> 8);
out[j++] = (byte) cc;
- out[j++] = (byte) (dd >>> 24);
- out[j++] = (byte) (dd >>> 16);
- out[j++] = (byte) (dd >>> 8);
- out[j] = (byte) dd;
+ out[j++] = (byte)(dd >>> 24);
+ out[j++] = (byte)(dd >>> 16);
+ out[j++] = (byte)(dd >>> 8);
+ out[j ] = (byte) dd;
}
/**
- * <p>Applies the Theta function to an input <i>in</i> in order to produce in
- * <i>out</i> an internal session sub-key.</p>
- *
- * <p>Both <i>in</i> and <i>out</i> are arrays of four ints.</p>
- *
- * <p>Pseudo-code is:</p>
- *
+ * Applies the Theta function to an input <i>in</i> in order to produce in
+ * <i>out</i> an internal session sub-key.
+ * <p>
+ * Both <i>in</i> and <i>out</i> are arrays of four ints.
+ * <p>
+ * Pseudo-code is:
* <pre>
- * for (i = 0; i < 4; i++) {
- * out[i] = 0;
- * for (j = 0, n = 24; j < 4; j++, n -= 8) {
- * k = mul(in[i] >>> 24, G[0][j]) ^
- * mul(in[i] >>> 16, G[1][j]) ^
- * mul(in[i] >>> 8, G[2][j]) ^
- * mul(in[i] , G[3][j]);
- * out[i] ^= k << n;
+ * for (i = 0; i &lt; 4; i++)
+ * {
+ * out[i] = 0;
+ * for (j = 0, n = 24; j &lt; 4; j++, n -= 8)
+ * {
+ * k = mul(in[i] &gt;&gt;&gt; 24, G[0][j]) &circ; mul(in[i] &gt;&gt;&gt; 16, G[1][j])
+ * &circ; mul(in[i] &gt;&gt;&gt; 8, G[2][j]) &circ; mul(in[i], G[3][j]);
+ * out[i] &circ;= k &lt;&lt; n;
* }
- * }
+ * }
* </pre>
*/
private static void transform(int[] in, int[] out)
@@ -332,8 +270,8 @@ public final class Square extends BaseCipher
}
/**
- * <p>Left rotate a 32-bit chunk.</p>
- *
+ * Left rotate a 32-bit chunk.
+ *
* @param x the 32-bit data to rotate
* @param s number of places to left-rotate by
* @return the newly permutated value.
@@ -344,8 +282,8 @@ public final class Square extends BaseCipher
}
/**
- * <p>Right rotate a 32-bit chunk.</p>
- *
+ * Right rotate a 32-bit chunk.
+ *
* @param x the 32-bit data to rotate
* @param s number of places to right-rotate by
* @return the newly permutated value.
@@ -356,12 +294,12 @@ public final class Square extends BaseCipher
}
/**
- * <p>Returns the product of two binary numbers a and b, using the generator
- * ROOT as the modulus: p = (a * b) mod ROOT. ROOT Generates a suitable
- * Galois Field in GF(2**8).</p>
- *
- * <p>For best performance call it with abs(b) &lt; abs(a).</p>
- *
+ * Returns the product of two binary numbers a and b, using the generator ROOT
+ * as the modulus: p = (a * b) mod ROOT. ROOT Generates a suitable Galois
+ * Field in GF(2**8).
+ * <p>
+ * For best performance call it with abs(b) &lt; abs(a).
+ *
* @param a operand for multiply.
* @param b operand for multiply.
* @return the result of (a * b) % ROOT.
@@ -369,35 +307,22 @@ public final class Square extends BaseCipher
private static final int mul(int a, int b)
{
if (a == 0)
- {
- return 0;
- }
-
+ return 0;
a &= 0xFF;
b &= 0xFF;
int result = 0;
while (b != 0)
{
if ((b & 0x01) != 0)
- {
- result ^= a;
- }
-
+ result ^= a;
b >>>= 1;
a <<= 1;
if (a > 0xFF)
- {
- a ^= ROOT;
- }
+ a ^= ROOT;
}
return result & 0xFF;
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.lang.Cloneable interface implementation ----------------------------
-
public Object clone()
{
Square result = new Square();
@@ -406,12 +331,10 @@ public final class Square extends BaseCipher
return result;
}
- // IBlockCipherSpi interface implementation --------------------------------
-
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(DEFAULT_BLOCK_SIZE));
+ al.add(Integer.valueOf(DEFAULT_BLOCK_SIZE));
return Collections.unmodifiableList(al).iterator();
}
@@ -419,7 +342,7 @@ public final class Square extends BaseCipher
public Iterator keySizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(DEFAULT_KEY_SIZE));
+ al.add(Integer.valueOf(DEFAULT_KEY_SIZE));
return Collections.unmodifiableList(al).iterator();
}
@@ -427,36 +350,35 @@ public final class Square extends BaseCipher
public Object makeKey(byte[] uk, int bs) throws InvalidKeyException
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
if (uk == null)
- {
- throw new InvalidKeyException("Empty key");
- }
+ throw new InvalidKeyException("Empty key");
if (uk.length != DEFAULT_KEY_SIZE)
- {
- throw new InvalidKeyException("Key is not 128-bit.");
- }
-
+ throw new InvalidKeyException("Key is not 128-bit.");
int[][] Ke = new int[ROUNDS + 1][4];
int[][] Kd = new int[ROUNDS + 1][4];
int[][] tK = new int[ROUNDS + 1][4];
int i = 0;
-
- Ke[0][0] = (uk[i++] & 0xFF) << 24 | (uk[i++] & 0xFF) << 16
- | (uk[i++] & 0xFF) << 8 | (uk[i++] & 0xFF);
+ Ke[0][0] = (uk[i++] & 0xFF) << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i++] & 0xFF);
tK[0][0] = Ke[0][0];
- Ke[0][1] = (uk[i++] & 0xFF) << 24 | (uk[i++] & 0xFF) << 16
- | (uk[i++] & 0xFF) << 8 | (uk[i++] & 0xFF);
+ Ke[0][1] = (uk[i++] & 0xFF) << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i++] & 0xFF);
tK[0][1] = Ke[0][1];
- Ke[0][2] = (uk[i++] & 0xFF) << 24 | (uk[i++] & 0xFF) << 16
- | (uk[i++] & 0xFF) << 8 | (uk[i++] & 0xFF);
+ Ke[0][2] = (uk[i++] & 0xFF) << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i++] & 0xFF);
tK[0][2] = Ke[0][2];
- Ke[0][3] = (uk[i++] & 0xFF) << 24 | (uk[i++] & 0xFF) << 16
- | (uk[i++] & 0xFF) << 8 | (uk[i] & 0xFF);
+ Ke[0][3] = (uk[i++] & 0xFF) << 24
+ | (uk[i++] & 0xFF) << 16
+ | (uk[i++] & 0xFF) << 8
+ | (uk[i ] & 0xFF);
tK[0][3] = Ke[0][3];
-
int j;
for (i = 1, j = 0; i < ROUNDS + 1; i++, j++)
{
@@ -464,41 +386,28 @@ public final class Square extends BaseCipher
tK[i][1] = tK[j][1] ^ tK[i][0];
tK[i][2] = tK[j][2] ^ tK[i][1];
tK[i][3] = tK[j][3] ^ tK[i][2];
-
System.arraycopy(tK[i], 0, Ke[i], 0, 4);
-
transform(Ke[j], Ke[j]);
}
-
for (i = 0; i < ROUNDS; i++)
- {
- System.arraycopy(tK[ROUNDS - i], 0, Kd[i], 0, 4);
- }
-
+ System.arraycopy(tK[ROUNDS - i], 0, Kd[i], 0, 4);
transform(tK[0], Kd[ROUNDS]);
-
return new Object[] { Ke, Kd };
}
public void encrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
-
- int[][] K = (int[][]) ((Object[]) k)[0];
+ throw new IllegalArgumentException();
+ int[][] K = (int[][])((Object[]) k)[0];
square(in, i, out, j, K, Te, Se);
}
public void decrypt(byte[] in, int i, byte[] out, int j, Object k, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
-
- int[][] K = (int[][]) ((Object[]) k)[1];
+ throw new IllegalArgumentException();
+ int[][] K = (int[][])((Object[]) k)[1];
square(in, i, out, j, K, Td, Sd);
}
@@ -508,9 +417,7 @@ public final class Square extends BaseCipher
{
boolean result = super.selfTest(); // do symmetry tests
if (result)
- {
- result = testKat(KAT_KEY, KAT_CT);
- }
+ result = testKat(KAT_KEY, KAT_CT);
valid = Boolean.valueOf(result);
}
return valid.booleanValue();
diff --git a/gnu/javax/crypto/cipher/TripleDES.java b/gnu/javax/crypto/cipher/TripleDES.java
index 9b44c9ca7..7aeb4ea96 100644
--- a/gnu/javax/crypto/cipher/TripleDES.java
+++ b/gnu/javax/crypto/cipher/TripleDES.java
@@ -45,37 +45,34 @@ import java.util.Iterator;
import java.security.InvalidKeyException;
/**
- * Triple-DES, 3DES, or DESede is a <i>combined cipher</i> that uses
- * three iterations of the Data Encryption Standard cipher to improve
- * the security (at the cost of speed) of plain DES.
- *
- * <p>Triple-DES runs the DES algorithm three times with three
- * independent 56 bit keys. To encrypt:</p>
- *
- * <blockquote><i>C<sub>i</sub> =
- * E<sub>k3</sub> ( E<sub>k2</sub><sup>-1</sup> ( E<sub>k1</sub> ( P<sub>i</sub> )))</i></blockquote>
- *
- * <p>And to decrypt:</p>
- *
- * <blockquote><i>P<sub>i</sub> =
- * E<sub>k1</sub><sup>-1</sup> ( E<sub>k2</sub> ( E<sub>k3</sub><sup>-1</sup> ( C<sub>i</sub> )))</i></blockquote>
- *
- * <p>(The "ede" comes from the encryption operation, which runs
- * Encrypt-Decrypt-Encrypt)</p>
- *
- * <p>References:</p>
+ * Triple-DES, 3DES, or DESede is a <i>combined cipher</i> that uses three
+ * iterations of the Data Encryption Standard cipher to improve the security (at
+ * the cost of speed) of plain DES.
+ * <p>
+ * Triple-DES runs the DES algorithm three times with three independent 56 bit
+ * keys. To encrypt:
+ * <blockquote><i>C<sub>i</sub> = E<sub>k3</sub> ( E<sub>k2</sub><sup>-1</sup> (
+ * E<sub>k1</sub> ( P<sub>i</sub> )))</i>
+ * </blockquote>
+ * <p>
+ * And to decrypt:
+ * <blockquote><i>P<sub>i</sub> = E<sub>k1</sub><sup>-1</sup> (
+ * E<sub>k2</sub> ( E<sub>k3</sub><sup>-1</sup> ( C<sub>i</sub> )))</i>
+ * </blockquote>
+ * <p>
+ * (The "ede" comes from the encryption operation, which runs
+ * Encrypt-Decrypt-Encrypt)
+ * <p>
+ * References:
* <ol>
- * <li>Bruce Schneier, <i>Applied Cryptography: Protocols, Algorithms,
- * and Source Code in C, Second Edition</i>. (1996 John Wiley and Sons)
- * ISBN 0-471-11709-9. Page 294--295.</li>
+ * <li>Bruce Schneier, <i>Applied Cryptography: Protocols, Algorithms, and
+ * Source Code in C, Second Edition</i>. (1996 John Wiley and Sons) ISBN
+ * 0-471-11709-9. Page 294--295.</li>
* </ol>
*/
-public class TripleDES extends BaseCipher
+public class TripleDES
+ extends BaseCipher
{
-
- // Constants and variables.
- // -----------------------------------------------------------------------
-
/** Triple-DES only operates on 64 bit blocks. */
public static final int BLOCK_SIZE = 8;
@@ -85,9 +82,6 @@ public class TripleDES extends BaseCipher
/** The underlying DES instance. */
private DES des;
- // Constructors.
- // -----------------------------------------------------------------------
-
/**
* Default 0-arguments constructor.
*/
@@ -97,13 +91,10 @@ public class TripleDES extends BaseCipher
des = new DES();
}
- // Class methods.
- // -----------------------------------------------------------------------
-
/**
* Transform a key so it will be parity adjusted.
- *
- * @param kb The key bytes to adjust.
+ *
+ * @param kb The key bytes to adjust.
* @param offset The starting offset into the key bytes.
* @see DES#adjustParity(byte[],int)
*/
@@ -116,8 +107,8 @@ public class TripleDES extends BaseCipher
/**
* Tests if a byte array has already been parity adjusted.
- *
- * @param kb The key bytes to test.
+ *
+ * @param kb The key bytes to test.
* @param offset The starting offset into the key bytes.
* @return <code>true</code> if the bytes in <i>kb</i> starting at
* <i>offset</i> are parity adjusted.
@@ -131,9 +122,6 @@ public class TripleDES extends BaseCipher
&& DES.isParityAdjusted(kb, offset + 16);
}
- // Methods implementing BaseCipher.
- // -----------------------------------------------------------------------
-
public Object clone()
{
return new TripleDES();
@@ -141,32 +129,30 @@ public class TripleDES extends BaseCipher
public Iterator blockSizes()
{
- return Collections.singleton(new Integer(BLOCK_SIZE)).iterator();
+ return Collections.singleton(Integer.valueOf(BLOCK_SIZE)).iterator();
}
public Iterator keySizes()
{
- return Collections.singleton(new Integer(KEY_SIZE)).iterator();
+ return Collections.singleton(Integer.valueOf(KEY_SIZE)).iterator();
}
public Object makeKey(byte[] kb, int bs) throws InvalidKeyException
{
if (kb.length != KEY_SIZE)
throw new InvalidKeyException("TripleDES key must be 24 bytes");
-
- if (!isParityAdjusted(kb, 0))
+ if (! isParityAdjusted(kb, 0))
adjustParity(kb, 0);
-
- byte[] k1 = new byte[DES.KEY_SIZE], k2 = new byte[DES.KEY_SIZE], k3 = new byte[DES.KEY_SIZE];
+ byte[] k1 = new byte[DES.KEY_SIZE];
+ byte[] k2 = new byte[DES.KEY_SIZE];
+ byte[] k3 = new byte[DES.KEY_SIZE];
System.arraycopy(kb, 0, k1, 0, DES.KEY_SIZE);
System.arraycopy(kb, DES.KEY_SIZE, k2, 0, DES.KEY_SIZE);
System.arraycopy(kb, 2 * DES.KEY_SIZE, k3, 0, DES.KEY_SIZE);
Context ctx = new Context();
-
ctx.k1 = (DES.Context) des.makeKey(k1, bs);
ctx.k2 = (DES.Context) des.makeKey(k2, bs);
ctx.k3 = (DES.Context) des.makeKey(k3, bs);
-
return ctx;
}
@@ -186,11 +172,8 @@ public class TripleDES extends BaseCipher
des.decrypt(temp, 0, out, o, ((Context) K).k1, bs);
}
- // Inner classes.
- // -----------------------------------------------------------------------
-
private final class Context
{
DES.Context k1, k2, k3;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/Twofish.java b/gnu/javax/crypto/cipher/Twofish.java
index d6747608c..b69324428 100644
--- a/gnu/javax/crypto/cipher/Twofish.java
+++ b/gnu/javax/crypto/cipher/Twofish.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.cipher;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.Util;
@@ -49,178 +49,131 @@ import java.util.Iterator;
import java.util.logging.Logger;
/**
- * <p>Twofish is a balanced 128-bit Feistel cipher, consisting of 16 rounds. In
+ * Twofish is a balanced 128-bit Feistel cipher, consisting of 16 rounds. In
* each round, a 64-bit S-box value is computed from 64 bits of the block, and
* this value is xored into the other half of the block. The two half-blocks are
* then exchanged, and the next round begins. Before the first round, all input
* bits are xored with key-dependent "whitening" subkeys, and after the final
* round the output bits are xored with other key-dependent whitening subkeys;
- * these subkeys are not used anywhere else in the algorithm.</p>
- *
- * <p>Twofish is designed by Bruce Schneier, Doug Whiting, John Kelsey, Chris
- * Hall, David Wagner and Niels Ferguson.</p>
- *
- * <p>References:</p>
- *
+ * these subkeys are not used anywhere else in the algorithm.
+ * <p>
+ * Twofish is designed by Bruce Schneier, Doug Whiting, John Kelsey, Chris
+ * Hall, David Wagner and Niels Ferguson.
+ * <p>
+ * References:
* <ol>
* <li><a href="http://www.counterpane.com/twofish-paper.html">Twofish: A
* 128-bit Block Cipher</a>.</li>
* </ol>
*/
-public final class Twofish extends BaseCipher
+public final class Twofish
+ extends BaseCipher
{
private static final Logger log = Logger.getLogger(Twofish.class.getName());
private static final int DEFAULT_BLOCK_SIZE = 16; // in bytes
-
private static final int DEFAULT_KEY_SIZE = 16; // in bytes
-
private static final int MAX_ROUNDS = 16; // max # rounds (for allocating subkeys)
-
private static final int ROUNDS = MAX_ROUNDS;
-
// subkey array indices
private static final int INPUT_WHITEN = 0;
-
- private static final int OUTPUT_WHITEN = INPUT_WHITEN + DEFAULT_BLOCK_SIZE
- / 4;
-
- private static final int ROUND_SUBKEYS = OUTPUT_WHITEN + DEFAULT_BLOCK_SIZE
- / 4;
-
- // private static final int TOTAL_SUBKEYS = ROUND_SUBKEYS + 2*MAX_ROUNDS;
-
+ private static final int OUTPUT_WHITEN = INPUT_WHITEN + DEFAULT_BLOCK_SIZE / 4;
+ private static final int ROUND_SUBKEYS = OUTPUT_WHITEN + DEFAULT_BLOCK_SIZE / 4;
private static final int SK_STEP = 0x02020202;
-
private static final int SK_BUMP = 0x01010101;
-
private static final int SK_ROTL = 9;
-
private static final String[] Pm = new String[] {
- // p0
- "\uA967\uB3E8\u04FD\uA376\u9A92\u8078\uE4DD\uD138"
- + "\u0DC6\u3598\u18F7\uEC6C\u4375\u3726\uFA13\u9448"
- + "\uF2D0\u8B30\u8454\uDF23\u195B\u3D59\uF3AE\uA282"
- + "\u6301\u832E\uD951\u9B7C\uA6EB\uA5BE\u160C\uE361"
- + "\uC08C\u3AF5\u732C\u250B\uBB4E\u896B\u536A\uB4F1"
- + "\uE1E6\uBD45\uE2F4\uB666\uCC95\u0356\uD41C\u1ED7"
- + "\uFBC3\u8EB5\uE9CF\uBFBA\uEA77\u39AF\u33C9\u6271"
- + "\u8179\u09AD\u24CD\uF9D8\uE5C5\uB94D\u4408\u86E7"
- + "\uA11D\uAAED\u0670\uB2D2\u417B\uA011\u31C2\u2790"
- + "\u20F6\u60FF\u965C\uB1AB\u9E9C\u521B\u5F93\u0AEF"
- + "\u9185\u49EE\u2D4F\u8F3B\u4787\u6D46\uD63E\u6964"
- + "\u2ACE\uCB2F\uFC97\u057A\uAC7F\uD51A\u4B0E\uA75A"
- + "\u2814\u3F29\u883C\u4C02\uB8DA\uB017\u551F\u8A7D"
- + "\u57C7\u8D74\uB7C4\u9F72\u7E15\u2212\u5807\u9934"
- + "\u6E50\uDE68\u65BC\uDBF8\uC8A8\u2B40\uDCFE\u32A4"
- + "\uCA10\u21F0\uD35D\u0F00\u6F9D\u3642\u4A5E\uC1E0",
- // p1
- "\u75F3\uC6F4\uDB7B\uFBC8\u4AD3\uE66B\u457D\uE84B"
- + "\uD632\uD8FD\u3771\uF1E1\u300F\uF81B\u87FA\u063F"
- + "\u5EBA\uAE5B\u8A00\uBC9D\u6DC1\uB10E\u805D\uD2D5"
- + "\uA084\u0714\uB590\u2CA3\uB273\u4C54\u9274\u3651"
- + "\u38B0\uBD5A\uFC60\u6296\u6C42\uF710\u7C28\u278C"
- + "\u1395\u9CC7\u2446\u3B70\uCAE3\u85CB\u11D0\u93B8"
- + "\uA683\u20FF\u9F77\uC3CC\u036F\u08BF\u40E7\u2BE2"
- + "\u790C\uAA82\u413A\uEAB9\uE49A\uA497\u7EDA\u7A17"
- + "\u6694\uA11D\u3DF0\uDEB3\u0B72\uA71C\uEFD1\u533E"
- + "\u8F33\u265F\uEC76\u2A49\u8188\uEE21\uC41A\uEBD9"
- + "\uC539\u99CD\uAD31\u8B01\u1823\uDD1F\u4E2D\uF948"
- + "\u4FF2\u658E\u785C\u5819\u8DE5\u9857\u677F\u0564"
- + "\uAF63\uB6FE\uF5B7\u3CA5\uCEE9\u6844\uE04D\u4369"
- + "\u292E\uAC15\u59A8\u0A9E\u6E47\uDF34\u356A\uCFDC"
- + "\u22C9\uC09B\u89D4\uEDAB\u12A2\u0D52\uBB02\u2FA9"
- + "\uD761\u1EB4\u5004\uF6C2\u1625\u8656\u5509\uBE91" };
-
+ // p0
+ "\uA967\uB3E8\u04FD\uA376\u9A92\u8078\uE4DD\uD138"
+ + "\u0DC6\u3598\u18F7\uEC6C\u4375\u3726\uFA13\u9448"
+ + "\uF2D0\u8B30\u8454\uDF23\u195B\u3D59\uF3AE\uA282"
+ + "\u6301\u832E\uD951\u9B7C\uA6EB\uA5BE\u160C\uE361"
+ + "\uC08C\u3AF5\u732C\u250B\uBB4E\u896B\u536A\uB4F1"
+ + "\uE1E6\uBD45\uE2F4\uB666\uCC95\u0356\uD41C\u1ED7"
+ + "\uFBC3\u8EB5\uE9CF\uBFBA\uEA77\u39AF\u33C9\u6271"
+ + "\u8179\u09AD\u24CD\uF9D8\uE5C5\uB94D\u4408\u86E7"
+ + "\uA11D\uAAED\u0670\uB2D2\u417B\uA011\u31C2\u2790"
+ + "\u20F6\u60FF\u965C\uB1AB\u9E9C\u521B\u5F93\u0AEF"
+ + "\u9185\u49EE\u2D4F\u8F3B\u4787\u6D46\uD63E\u6964"
+ + "\u2ACE\uCB2F\uFC97\u057A\uAC7F\uD51A\u4B0E\uA75A"
+ + "\u2814\u3F29\u883C\u4C02\uB8DA\uB017\u551F\u8A7D"
+ + "\u57C7\u8D74\uB7C4\u9F72\u7E15\u2212\u5807\u9934"
+ + "\u6E50\uDE68\u65BC\uDBF8\uC8A8\u2B40\uDCFE\u32A4"
+ + "\uCA10\u21F0\uD35D\u0F00\u6F9D\u3642\u4A5E\uC1E0",
+ // p1
+ "\u75F3\uC6F4\uDB7B\uFBC8\u4AD3\uE66B\u457D\uE84B"
+ + "\uD632\uD8FD\u3771\uF1E1\u300F\uF81B\u87FA\u063F"
+ + "\u5EBA\uAE5B\u8A00\uBC9D\u6DC1\uB10E\u805D\uD2D5"
+ + "\uA084\u0714\uB590\u2CA3\uB273\u4C54\u9274\u3651"
+ + "\u38B0\uBD5A\uFC60\u6296\u6C42\uF710\u7C28\u278C"
+ + "\u1395\u9CC7\u2446\u3B70\uCAE3\u85CB\u11D0\u93B8"
+ + "\uA683\u20FF\u9F77\uC3CC\u036F\u08BF\u40E7\u2BE2"
+ + "\u790C\uAA82\u413A\uEAB9\uE49A\uA497\u7EDA\u7A17"
+ + "\u6694\uA11D\u3DF0\uDEB3\u0B72\uA71C\uEFD1\u533E"
+ + "\u8F33\u265F\uEC76\u2A49\u8188\uEE21\uC41A\uEBD9"
+ + "\uC539\u99CD\uAD31\u8B01\u1823\uDD1F\u4E2D\uF948"
+ + "\u4FF2\u658E\u785C\u5819\u8DE5\u9857\u677F\u0564"
+ + "\uAF63\uB6FE\uF5B7\u3CA5\uCEE9\u6844\uE04D\u4369"
+ + "\u292E\uAC15\u59A8\u0A9E\u6E47\uDF34\u356A\uCFDC"
+ + "\u22C9\uC09B\u89D4\uEDAB\u12A2\u0D52\uBB02\u2FA9"
+ + "\uD761\u1EB4\u5004\uF6C2\u1625\u8656\u5509\uBE91" };
/** Fixed 8x8 permutation S-boxes */
private static final byte[][] P = new byte[2][256]; // blank final
-
/**
* Define the fixed p0/p1 permutations used in keyed S-box lookup. By
* changing the following constant definitions, the S-boxes will
* automatically get changed in the Twofish engine.
*/
private static final int P_00 = 1;
-
private static final int P_01 = 0;
-
private static final int P_02 = 0;
-
private static final int P_03 = P_01 ^ 1;
-
private static final int P_04 = 1;
-
private static final int P_10 = 0;
-
private static final int P_11 = 0;
-
private static final int P_12 = 1;
-
private static final int P_13 = P_11 ^ 1;
-
private static final int P_14 = 0;
-
private static final int P_20 = 1;
-
private static final int P_21 = 1;
-
private static final int P_22 = 0;
-
private static final int P_23 = P_21 ^ 1;
-
private static final int P_24 = 0;
-
private static final int P_30 = 0;
-
private static final int P_31 = 1;
-
private static final int P_32 = 1;
-
private static final int P_33 = P_31 ^ 1;
-
private static final int P_34 = 1;
-
/** Primitive polynomial for GF(256) */
- // private static final int GF256_FDBK = 0x169;
private static final int GF256_FDBK_2 = 0x169 / 2;
-
private static final int GF256_FDBK_4 = 0x169 / 4;
-
/** MDS matrix */
private static final int[][] MDS = new int[4][256]; // blank final
-
private static final int RS_GF_FDBK = 0x14D; // field generator
-
/**
* KAT vector (from ecb_vk):
* I=183
* KEY=0000000000000000000000000000000000000000000002000000000000000000
* CT=F51410475B33FBD3DB2117B5C17C82D4
*/
- private static final byte[] KAT_KEY = Util.toBytesFromString("0000000000000000000000000000000000000000000002000000000000000000");
-
- private static final byte[] KAT_CT = Util.toBytesFromString("F51410475B33FBD3DB2117B5C17C82D4");
-
+ private static final byte[] KAT_KEY = Util.toBytesFromString(
+ "0000000000000000000000000000000000000000000002000000000000000000");
+ private static final byte[] KAT_CT =
+ Util.toBytesFromString("F51410475B33FBD3DB2117B5C17C82D4");
/** caches the result of the correctness test, once executed. */
private static Boolean valid;
-
- // Static code - to intialise the MDS matrix and lookup tables -------------
-
static
{
long time = System.currentTimeMillis();
-
// expand the P arrays
int i;
char c;
for (i = 0; i < 256; i++)
{
c = Pm[0].charAt(i >>> 1);
- P[0][i] = (byte) ((i & 1) == 0 ? c >>> 8 : c);
-
+ P[0][i] = (byte)((i & 1) == 0 ? c >>> 8 : c);
c = Pm[1].charAt(i >>> 1);
- P[1][i] = (byte) ((i & 1) == 0 ? c >>> 8 : c);
+ P[1][i] = (byte)((i & 1) == 0 ? c >>> 8 : c);
}
-
// precompute the MDS matrix
int[] m1 = new int[2];
int[] mX = new int[2];
@@ -232,24 +185,28 @@ public final class Twofish extends BaseCipher
m1[0] = j;
mX[0] = Mx_X(j) & 0xFF;
mY[0] = Mx_Y(j) & 0xFF;
-
j = P[1][i] & 0xFF;
m1[1] = j;
mX[1] = Mx_X(j) & 0xFF;
mY[1] = Mx_Y(j) & 0xFF;
-
- MDS[0][i] = m1[P_00] << 0 | // fill matrix w/ above elements
- mX[P_00] << 8 | mY[P_00] << 16 | mY[P_00] << 24;
- MDS[1][i] = mY[P_10] << 0 | mY[P_10] << 8 | mX[P_10] << 16
- | m1[P_10] << 24;
- MDS[2][i] = mX[P_20] << 0 | mY[P_20] << 8 | m1[P_20] << 16
- | mY[P_20] << 24;
- MDS[3][i] = mX[P_30] << 0 | m1[P_30] << 8 | mY[P_30] << 16
- | mX[P_30] << 24;
+ MDS[0][i] = m1[P_00] << 0
+ | mX[P_00] << 8
+ | mY[P_00] << 16
+ | mY[P_00] << 24;
+ MDS[1][i] = mY[P_10] << 0
+ | mY[P_10] << 8
+ | mX[P_10] << 16
+ | m1[P_10] << 24;
+ MDS[2][i] = mX[P_20] << 0
+ | mY[P_20] << 8
+ | m1[P_20] << 16
+ | mY[P_20] << 24;
+ MDS[3][i] = mX[P_30] << 0
+ | m1[P_30] << 8
+ | mY[P_30] << 16
+ | mX[P_30] << 24;
}
-
time = System.currentTimeMillis() - time;
-
if (Configuration.DEBUG)
{
log.fine("Static Data");
@@ -297,14 +254,11 @@ public final class Twofish extends BaseCipher
private static final int LFSR2(int x)
{
- return (x >> 2) ^ ((x & 0x02) != 0 ? GF256_FDBK_2 : 0)
- ^ ((x & 0x01) != 0 ? GF256_FDBK_4 : 0);
+ return (x >> 2)
+ ^ ((x & 0x02) != 0 ? GF256_FDBK_2 : 0)
+ ^ ((x & 0x01) != 0 ? GF256_FDBK_4 : 0);
}
- // private static final int Mx_1(int x) {
- // return x;
- // }
-
private static final int Mx_X(int x)
{ // 5B
return x ^ LFSR2(x);
@@ -315,18 +269,12 @@ public final class Twofish extends BaseCipher
return x ^ LFSR1(x) ^ LFSR2(x);
}
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial 0-arguments constructor. */
public Twofish()
{
super(Registry.TWOFISH_CIPHER, DEFAULT_BLOCK_SIZE, DEFAULT_KEY_SIZE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
private static final int b0(int x)
{
return x & 0xFF;
@@ -359,15 +307,11 @@ public final class Twofish extends BaseCipher
{
int r = k1;
int i;
- for (i = 0; i < 4; i++)
- { // shift 1 byte at a time
- r = RS_rem(r);
- }
+ for (i = 0; i < 4; i++) // shift 1 byte at a time
+ r = RS_rem(r);
r ^= k0;
for (i = 0; i < 4; i++)
- {
- r = RS_rem(r);
- }
+ r = RS_rem(r);
return r;
}
@@ -397,15 +341,14 @@ public final class Twofish extends BaseCipher
int k1 = k32[1];
int k2 = k32[2];
int k3 = k32[3];
-
int result = 0;
switch (k64Cnt & 3)
{
case 1:
result = MDS[0][(P[P_01][b0] & 0xFF) ^ b0(k0)]
- ^ MDS[1][(P[P_11][b1] & 0xFF) ^ b1(k0)]
- ^ MDS[2][(P[P_21][b2] & 0xFF) ^ b2(k0)]
- ^ MDS[3][(P[P_31][b3] & 0xFF) ^ b3(k0)];
+ ^ MDS[1][(P[P_11][b1] & 0xFF) ^ b1(k0)]
+ ^ MDS[2][(P[P_21][b2] & 0xFF) ^ b2(k0)]
+ ^ MDS[3][(P[P_31][b3] & 0xFF) ^ b3(k0)];
break;
case 0: // same as 4
b0 = (P[P_04][b0] & 0xFF) ^ b0(k3);
@@ -418,14 +361,10 @@ public final class Twofish extends BaseCipher
b2 = (P[P_23][b2] & 0xFF) ^ b2(k2);
b3 = (P[P_33][b3] & 0xFF) ^ b3(k2);
case 2: // 128-bit keys (optimize for this case)
- result = MDS[0][(P[P_01][(P[P_02][b0] & 0xFF) ^ b0(k1)] & 0xFF)
- ^ b0(k0)]
- ^ MDS[1][(P[P_11][(P[P_12][b1] & 0xFF) ^ b1(k1)] & 0xFF)
- ^ b1(k0)]
- ^ MDS[2][(P[P_21][(P[P_22][b2] & 0xFF) ^ b2(k1)] & 0xFF)
- ^ b2(k0)]
- ^ MDS[3][(P[P_31][(P[P_32][b3] & 0xFF) ^ b3(k1)] & 0xFF)
- ^ b3(k0)];
+ result = MDS[0][(P[P_01][(P[P_02][b0] & 0xFF) ^ b0(k1)] & 0xFF) ^ b0(k0)]
+ ^ MDS[1][(P[P_11][(P[P_12][b1] & 0xFF) ^ b1(k1)] & 0xFF) ^ b1(k0)]
+ ^ MDS[2][(P[P_21][(P[P_22][b2] & 0xFF) ^ b2(k1)] & 0xFF) ^ b2(k0)]
+ ^ MDS[3][(P[P_31][(P[P_32][b3] & 0xFF) ^ b3(k1)] & 0xFF) ^ b3(k0)];
break;
}
return result;
@@ -433,23 +372,14 @@ public final class Twofish extends BaseCipher
private static final int Fe32(int[] sBox, int x, int R)
{
- return sBox[2 * _b(x, R)] ^ sBox[2 * _b(x, R + 1) + 1]
- ^ sBox[0x200 + 2 * _b(x, R + 2)]
- ^ sBox[0x200 + 2 * _b(x, R + 3) + 1];
+ return sBox[ 2 * _b(x, R ) ]
+ ^ sBox[ 2 * _b(x, R + 1) + 1]
+ ^ sBox[0x200 + 2 * _b(x, R + 2) ]
+ ^ sBox[0x200 + 2 * _b(x, R + 3) + 1];
}
private static final int _b(int x, int N)
{
- // int result = 0;
- // switch (N%4) {
- // case 0: result = b0(x); break;
- // case 1: result = b1(x); break;
- // case 2: result = b2(x); break;
- // case 3: result = b3(x); break;
- // }
- // return result;
- // profiling shows that the code spends too long in this method.
- // following constructs seem to improve, albeit marginally, performance
switch (N % 4)
{
case 0:
@@ -463,43 +393,33 @@ public final class Twofish extends BaseCipher
}
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.lang.Cloneable interface implementation ----------------------------
-
public Object clone()
{
Twofish result = new Twofish();
result.currentBlockSize = this.currentBlockSize;
-
return result;
}
- // IBlockCipherSpi interface implementation --------------------------------
-
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(DEFAULT_BLOCK_SIZE));
-
+ al.add(Integer.valueOf(DEFAULT_BLOCK_SIZE));
return Collections.unmodifiableList(al).iterator();
}
public Iterator keySizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(8)); // 64-bit
- al.add(new Integer(16)); // 128-bit
- al.add(new Integer(24)); // 192-bit
- al.add(new Integer(32)); // 256-bit
-
+ al.add(Integer.valueOf(8)); // 64-bit
+ al.add(Integer.valueOf(16)); // 128-bit
+ al.add(Integer.valueOf(24)); // 192-bit
+ al.add(Integer.valueOf(32)); // 256-bit
return Collections.unmodifiableList(al).iterator();
}
/**
- * <p>Expands a user-supplied key material into a session key for a designated
- * <i>block size</i>.</p>
+ * Expands a user-supplied key material into a session key for a designated
+ * <i>block size</i>.
*
* @param k the 64/128/192/256-bit user-key to use.
* @param bs the desired block size in bytes.
@@ -510,35 +430,30 @@ public final class Twofish extends BaseCipher
public Object makeKey(byte[] k, int bs) throws InvalidKeyException
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
if (k == null)
- {
- throw new InvalidKeyException("Empty key");
- }
+ throw new InvalidKeyException("Empty key");
int length = k.length;
- if (!(length == 8 || length == 16 || length == 24 || length == 32))
- {
- throw new InvalidKeyException("Incorrect key length");
- }
-
+ if (! (length == 8 || length == 16 || length == 24 || length == 32))
+ throw new InvalidKeyException("Incorrect key length");
int k64Cnt = length / 8;
int subkeyCnt = ROUND_SUBKEYS + 2 * ROUNDS;
int[] k32e = new int[4]; // even 32-bit entities
int[] k32o = new int[4]; // odd 32-bit entities
int[] sBoxKey = new int[4];
- //
// split user key material into even and odd 32-bit entities and
// compute S-box keys using (12, 8) Reed-Solomon code over GF(256)
- //
int i, j, offset = 0;
for (i = 0, j = k64Cnt - 1; i < 4 && offset < length; i++, j--)
{
- k32e[i] = (k[offset++] & 0xFF) | (k[offset++] & 0xFF) << 8
- | (k[offset++] & 0xFF) << 16 | (k[offset++] & 0xFF) << 24;
- k32o[i] = (k[offset++] & 0xFF) | (k[offset++] & 0xFF) << 8
- | (k[offset++] & 0xFF) << 16 | (k[offset++] & 0xFF) << 24;
+ k32e[i] = (k[offset++] & 0xFF)
+ | (k[offset++] & 0xFF) << 8
+ | (k[offset++] & 0xFF) << 16
+ | (k[offset++] & 0xFF) << 24;
+ k32o[i] = (k[offset++] & 0xFF)
+ | (k[offset++] & 0xFF) << 8
+ | (k[offset++] & 0xFF) << 16
+ | (k[offset++] & 0xFF) << 24;
sBoxKey[j] = RS_MDS_Encode(k32e[i], k32o[i]); // reverse order
}
// compute the round decryption subkeys for PHT. these same subkeys
@@ -555,7 +470,6 @@ public final class Twofish extends BaseCipher
A += B;
subKeys[2 * i + 1] = A << SK_ROTL | A >>> (32 - SK_ROTL);
}
-
// fully expand the table for speed
int k0 = sBoxKey[0];
int k1 = sBoxKey[1];
@@ -569,9 +483,9 @@ public final class Twofish extends BaseCipher
switch (k64Cnt & 3)
{
case 1:
- sBox[2 * i] = MDS[0][(P[P_01][b0] & 0xFF) ^ b0(k0)];
- sBox[2 * i + 1] = MDS[1][(P[P_11][b1] & 0xFF) ^ b1(k0)];
- sBox[0x200 + 2 * i] = MDS[2][(P[P_21][b2] & 0xFF) ^ b2(k0)];
+ sBox[ 2 * i ] = MDS[0][(P[P_01][b0] & 0xFF) ^ b0(k0)];
+ sBox[ 2 * i + 1] = MDS[1][(P[P_11][b1] & 0xFF) ^ b1(k0)];
+ sBox[0x200 + 2 * i ] = MDS[2][(P[P_21][b2] & 0xFF) ^ b2(k0)];
sBox[0x200 + 2 * i + 1] = MDS[3][(P[P_31][b3] & 0xFF) ^ b3(k0)];
break;
case 0: // same as 4
@@ -585,15 +499,14 @@ public final class Twofish extends BaseCipher
b2 = (P[P_23][b2] & 0xFF) ^ b2(k2);
b3 = (P[P_33][b3] & 0xFF) ^ b3(k2);
case 2: // 128-bit keys
- sBox[2 * i] = MDS[0][(P[P_01][(P[P_02][b0] & 0xFF) ^ b0(k1)] & 0xFF)
- ^ b0(k0)];
- sBox[2 * i + 1] = MDS[1][(P[P_11][(P[P_12][b1] & 0xFF) ^ b1(k1)] & 0xFF)
- ^ b1(k0)];
- sBox[0x200 + 2 * i] = MDS[2][(P[P_21][(P[P_22][b2] & 0xFF) ^ b2(k1)] & 0xFF)
- ^ b2(k0)];
+ sBox[ 2 * i ] = MDS[0][(P[P_01][(P[P_02][b0] & 0xFF)
+ ^ b0(k1)] & 0xFF) ^ b0(k0)];
+ sBox[ 2 * i + 1] = MDS[1][(P[P_11][(P[P_12][b1] & 0xFF)
+ ^ b1(k1)] & 0xFF) ^ b1(k0)];
+ sBox[0x200 + 2 * i ] = MDS[2][(P[P_21][(P[P_22][b2] & 0xFF)
+ ^ b2(k1)] & 0xFF) ^ b2(k0)];
sBox[0x200 + 2 * i + 1] = MDS[3][(P[P_31][(P[P_32][b3] & 0xFF)
- ^ b3(k1)] & 0xFF)
- ^ b3(k0)];
+ ^ b3(k1)] & 0xFF) ^ b3(k0)];
}
}
if (Configuration.DEBUG)
@@ -633,14 +546,14 @@ public final class Twofish extends BaseCipher
}
log.fine("User (odd, even) keys --> S-Box keys:");
for (i = 0; i < k64Cnt; i++)
- log.fine("0x" + Util.toString(k32o[i]) + " 0x" + Util.toString(k32e[i])
+ log.fine("0x" + Util.toString(k32o[i])
+ + " 0x" + Util.toString(k32e[i])
+ " --> 0x" + Util.toString(sBoxKey[k64Cnt - 1 - i]));
log.fine("Round keys:");
for (i = 0; i < ROUND_SUBKEYS + 2 * ROUNDS; i += 2)
log.fine("0x" + Util.toString(subKeys[i])
+ " 0x" + Util.toString(subKeys[i + 1]));
}
-
return new Object[] { sBox, subKeys };
}
@@ -648,24 +561,28 @@ public final class Twofish extends BaseCipher
Object sessionKey, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
-
+ throw new IllegalArgumentException();
Object[] sk = (Object[]) sessionKey; // extract S-box and session key
int[] sBox = (int[]) sk[0];
int[] sKey = (int[]) sk[1];
if (Configuration.DEBUG)
log.fine("PT=" + Util.toString(in, inOffset, bs));
- int x0 = (in[inOffset++] & 0xFF) | (in[inOffset++] & 0xFF) << 8
- | (in[inOffset++] & 0xFF) << 16 | (in[inOffset++] & 0xFF) << 24;
- int x1 = (in[inOffset++] & 0xFF) | (in[inOffset++] & 0xFF) << 8
- | (in[inOffset++] & 0xFF) << 16 | (in[inOffset++] & 0xFF) << 24;
- int x2 = (in[inOffset++] & 0xFF) | (in[inOffset++] & 0xFF) << 8
- | (in[inOffset++] & 0xFF) << 16 | (in[inOffset++] & 0xFF) << 24;
- int x3 = (in[inOffset++] & 0xFF) | (in[inOffset++] & 0xFF) << 8
- | (in[inOffset++] & 0xFF) << 16 | (in[inOffset++] & 0xFF) << 24;
-
+ int x0 = (in[inOffset++] & 0xFF)
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 24;
+ int x1 = (in[inOffset++] & 0xFF)
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 24;
+ int x2 = (in[inOffset++] & 0xFF)
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 24;
+ int x3 = (in[inOffset++] & 0xFF)
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 24;
x0 ^= sKey[INPUT_WHITEN];
x1 ^= sKey[INPUT_WHITEN + 1];
x2 ^= sKey[INPUT_WHITEN + 2];
@@ -704,21 +621,21 @@ public final class Twofish extends BaseCipher
log.fine("CTw=" + Util.toString(x0) + Util.toString(x1)
+ Util.toString(x2) + Util.toString(x3));
out[outOffset++] = (byte) x2;
- out[outOffset++] = (byte) (x2 >>> 8);
- out[outOffset++] = (byte) (x2 >>> 16);
- out[outOffset++] = (byte) (x2 >>> 24);
+ out[outOffset++] = (byte)(x2 >>> 8);
+ out[outOffset++] = (byte)(x2 >>> 16);
+ out[outOffset++] = (byte)(x2 >>> 24);
out[outOffset++] = (byte) x3;
- out[outOffset++] = (byte) (x3 >>> 8);
- out[outOffset++] = (byte) (x3 >>> 16);
- out[outOffset++] = (byte) (x3 >>> 24);
+ out[outOffset++] = (byte)(x3 >>> 8);
+ out[outOffset++] = (byte)(x3 >>> 16);
+ out[outOffset++] = (byte)(x3 >>> 24);
out[outOffset++] = (byte) x0;
- out[outOffset++] = (byte) (x0 >>> 8);
- out[outOffset++] = (byte) (x0 >>> 16);
- out[outOffset++] = (byte) (x0 >>> 24);
+ out[outOffset++] = (byte)(x0 >>> 8);
+ out[outOffset++] = (byte)(x0 >>> 16);
+ out[outOffset++] = (byte)(x0 >>> 24);
out[outOffset++] = (byte) x1;
- out[outOffset++] = (byte) (x1 >>> 8);
- out[outOffset++] = (byte) (x1 >>> 16);
- out[outOffset] = (byte) (x1 >>> 24);
+ out[outOffset++] = (byte)(x1 >>> 8);
+ out[outOffset++] = (byte)(x1 >>> 16);
+ out[outOffset ] = (byte)(x1 >>> 24);
if (Configuration.DEBUG)
log.fine("CT=" + Util.toString(out, outOffset - 15, 16) + "\n");
}
@@ -727,24 +644,28 @@ public final class Twofish extends BaseCipher
Object sessionKey, int bs)
{
if (bs != DEFAULT_BLOCK_SIZE)
- {
- throw new IllegalArgumentException();
- }
-
+ throw new IllegalArgumentException();
Object[] sk = (Object[]) sessionKey; // extract S-box and session key
int[] sBox = (int[]) sk[0];
int[] sKey = (int[]) sk[1];
if (Configuration.DEBUG)
log.fine("CT=" + Util.toString(in, inOffset, bs));
- int x2 = (in[inOffset++] & 0xFF) | (in[inOffset++] & 0xFF) << 8
- | (in[inOffset++] & 0xFF) << 16 | (in[inOffset++] & 0xFF) << 24;
- int x3 = (in[inOffset++] & 0xFF) | (in[inOffset++] & 0xFF) << 8
- | (in[inOffset++] & 0xFF) << 16 | (in[inOffset++] & 0xFF) << 24;
- int x0 = (in[inOffset++] & 0xFF) | (in[inOffset++] & 0xFF) << 8
- | (in[inOffset++] & 0xFF) << 16 | (in[inOffset++] & 0xFF) << 24;
- int x1 = (in[inOffset++] & 0xFF) | (in[inOffset++] & 0xFF) << 8
- | (in[inOffset++] & 0xFF) << 16 | (in[inOffset++] & 0xFF) << 24;
-
+ int x2 = (in[inOffset++] & 0xFF)
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 24;
+ int x3 = (in[inOffset++] & 0xFF)
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 24;
+ int x0 = (in[inOffset++] & 0xFF)
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 24;
+ int x1 = (in[inOffset++] & 0xFF)
+ | (in[inOffset++] & 0xFF) << 8
+ | (in[inOffset++] & 0xFF) << 16
+ | (in[inOffset++] & 0xFF) << 24;
x2 ^= sKey[OUTPUT_WHITEN];
x3 ^= sKey[OUTPUT_WHITEN + 1];
x0 ^= sKey[OUTPUT_WHITEN + 2];
@@ -783,21 +704,21 @@ public final class Twofish extends BaseCipher
log.fine("PTw=" + Util.toString(x2) + Util.toString(x3)
+ Util.toString(x0) + Util.toString(x1));
out[outOffset++] = (byte) x0;
- out[outOffset++] = (byte) (x0 >>> 8);
- out[outOffset++] = (byte) (x0 >>> 16);
- out[outOffset++] = (byte) (x0 >>> 24);
+ out[outOffset++] = (byte)(x0 >>> 8);
+ out[outOffset++] = (byte)(x0 >>> 16);
+ out[outOffset++] = (byte)(x0 >>> 24);
out[outOffset++] = (byte) x1;
- out[outOffset++] = (byte) (x1 >>> 8);
- out[outOffset++] = (byte) (x1 >>> 16);
- out[outOffset++] = (byte) (x1 >>> 24);
+ out[outOffset++] = (byte)(x1 >>> 8);
+ out[outOffset++] = (byte)(x1 >>> 16);
+ out[outOffset++] = (byte)(x1 >>> 24);
out[outOffset++] = (byte) x2;
- out[outOffset++] = (byte) (x2 >>> 8);
- out[outOffset++] = (byte) (x2 >>> 16);
- out[outOffset++] = (byte) (x2 >>> 24);
+ out[outOffset++] = (byte)(x2 >>> 8);
+ out[outOffset++] = (byte)(x2 >>> 16);
+ out[outOffset++] = (byte)(x2 >>> 24);
out[outOffset++] = (byte) x3;
- out[outOffset++] = (byte) (x3 >>> 8);
- out[outOffset++] = (byte) (x3 >>> 16);
- out[outOffset] = (byte) (x3 >>> 24);
+ out[outOffset++] = (byte)(x3 >>> 8);
+ out[outOffset++] = (byte)(x3 >>> 16);
+ out[outOffset ] = (byte)(x3 >>> 24);
if (Configuration.DEBUG)
log.fine("PT=" + Util.toString(out, outOffset - 15, 16) + "\n");
}
@@ -808,11 +729,9 @@ public final class Twofish extends BaseCipher
{
boolean result = super.selfTest(); // do symmetry tests
if (result)
- {
- result = testKat(KAT_KEY, KAT_CT);
- }
+ result = testKat(KAT_KEY, KAT_CT);
valid = Boolean.valueOf(result);
}
return valid.booleanValue();
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/cipher/WeakKeyException.java b/gnu/javax/crypto/cipher/WeakKeyException.java
index 4454e0e45..f89ff54d1 100644
--- a/gnu/javax/crypto/cipher/WeakKeyException.java
+++ b/gnu/javax/crypto/cipher/WeakKeyException.java
@@ -41,18 +41,12 @@ package gnu.javax.crypto.cipher;
import java.security.InvalidKeyException;
/**
- * <p>Checked exception thrown to indicate that a weak key has been generated
- * and or specified instead of a valid non-weak value.</p>
+ * Checked exception thrown to indicate that a weak key has been generated and
+ * or specified instead of a valid non-weak value.
*/
-public class WeakKeyException extends InvalidKeyException
+public class WeakKeyException
+ extends InvalidKeyException
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public WeakKeyException()
{
super();
@@ -62,10 +56,4 @@ public class WeakKeyException extends InvalidKeyException
{
super(msg);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/DiffieHellmanImpl.java b/gnu/javax/crypto/jce/DiffieHellmanImpl.java
index 02761477a..cb1748a63 100644
--- a/gnu/javax/crypto/jce/DiffieHellmanImpl.java
+++ b/gnu/javax/crypto/jce/DiffieHellmanImpl.java
@@ -99,8 +99,8 @@ public final class DiffieHellmanImpl
result = pub.getY().modPow(key.getX(), s1.getP());
if (! lastPhase)
- throw new IllegalArgumentException("This key-agreement MUST be concluded in one step only");
-
+ throw new IllegalArgumentException(
+ "This key-agreement MUST be concluded in one step only");
last_phase_done = true;
return null;
}
@@ -117,7 +117,6 @@ public final class DiffieHellmanImpl
System.arraycopy(buf, 1, buf2, 0, buf2.length);
buf = buf2;
}
-
return buf;
}
diff --git a/gnu/javax/crypto/jce/GnuCrypto.java b/gnu/javax/crypto/jce/GnuCrypto.java
index b0e73b132..fd5cefe4a 100644
--- a/gnu/javax/crypto/jce/GnuCrypto.java
+++ b/gnu/javax/crypto/jce/GnuCrypto.java
@@ -49,24 +49,14 @@ import java.util.HashSet;
import java.util.Set;
/**
- * <p>The GNU Crypto implementation of the Java Cryptographic Extension (JCE)
- * Provider.</p>
- *
+ * The additional GNU algorithm implementation as a Java Cryptographic Extension
+ * (JCE) Provider.
+ *
* @see java.security.Provider
*/
-public final class GnuCrypto extends Provider
+public final class GnuCrypto
+ extends Provider
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
- /**
- * <p>The <a href="http://www.gnu.org/software/gnu-crypto/">GNU Crypto</a>
- * Provider.</p>
- */
public GnuCrypto()
{
super(Registry.GNU_CRYPTO, 2.1, "GNU Crypto JCE Provider");
@@ -120,8 +110,7 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.AES.class.getName());
put("Cipher.PBEWithHMacHavalAndAnubis",
gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Anubis.class.getName());
- put(
- "Cipher.PBEWithHMacHavalAndBlowfish",
+ put("Cipher.PBEWithHMacHavalAndBlowfish",
gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Blowfish.class.getName());
put("Cipher.PBEWithHMacHavalAndCast5",
gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Cast5.class.getName());
@@ -133,8 +122,7 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Serpent.class.getName());
put("Cipher.PBEWithHMacHavalAndSquare",
gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Square.class.getName());
- put(
- "Cipher.PBEWithHMacHavalAndTripleDES",
+ put("Cipher.PBEWithHMacHavalAndTripleDES",
gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.TripleDES.class.getName());
put("Cipher.PBEWithHMacHavalAndTwofish",
gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Twofish.class.getName());
@@ -228,8 +216,7 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.AES.class.getName());
put("Cipher.PBEWithHMacSHA256AndAnubis",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Anubis.class.getName());
- put(
- "Cipher.PBEWithHMacSHA256AndBlowfish",
+ put("Cipher.PBEWithHMacSHA256AndBlowfish",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Blowfish.class.getName());
put("Cipher.PBEWithHMacSHA256AndCast5",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Cast5.class.getName());
@@ -237,24 +224,20 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.DES.class.getName());
put("Cipher.PBEWithHMacSHA256AndKhazad",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Khazad.class.getName());
- put(
- "Cipher.PBEWithHMacSHA256AndSerpent",
+ put("Cipher.PBEWithHMacSHA256AndSerpent",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Serpent.class.getName());
put("Cipher.PBEWithHMacSHA256AndSquare",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Square.class.getName());
- put(
- "Cipher.PBEWithHMacSHA256AndTripleDES",
+ put("Cipher.PBEWithHMacSHA256AndTripleDES",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.TripleDES.class.getName());
- put(
- "Cipher.PBEWithHMacSHA256AndTwofish",
+ put("Cipher.PBEWithHMacSHA256AndTwofish",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Twofish.class.getName());
put("Cipher.PBEWithHMacSHA384AndAES",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.AES.class.getName());
put("Cipher.PBEWithHMacSHA384AndAnubis",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Anubis.class.getName());
- put(
- "Cipher.PBEWithHMacSHA384AndBlowfish",
+ put("Cipher.PBEWithHMacSHA384AndBlowfish",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Blowfish.class.getName());
put("Cipher.PBEWithHMacSHA384AndCast5",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Cast5.class.getName());
@@ -262,24 +245,20 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.DES.class.getName());
put("Cipher.PBEWithHMacSHA384AndKhazad",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Khazad.class.getName());
- put(
- "Cipher.PBEWithHMacSHA384AndSerpent",
+ put("Cipher.PBEWithHMacSHA384AndSerpent",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Serpent.class.getName());
put("Cipher.PBEWithHMacSHA384AndSquare",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Square.class.getName());
- put(
- "Cipher.PBEWithHMacSHA384AndTripleDES",
+ put("Cipher.PBEWithHMacSHA384AndTripleDES",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.TripleDES.class.getName());
- put(
- "Cipher.PBEWithHMacSHA384AndTwofish",
+ put("Cipher.PBEWithHMacSHA384AndTwofish",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Twofish.class.getName());
put("Cipher.PBEWithHMacSHA512AndAES",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.AES.class.getName());
put("Cipher.PBEWithHMacSHA512AndAnubis",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Anubis.class.getName());
- put(
- "Cipher.PBEWithHMacSHA512AndBlowfish",
+ put("Cipher.PBEWithHMacSHA512AndBlowfish",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Blowfish.class.getName());
put("Cipher.PBEWithHMacSHA512AndCast5",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Cast5.class.getName());
@@ -287,24 +266,20 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.DES.class.getName());
put("Cipher.PBEWithHMacSHA512AndKhazad",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Khazad.class.getName());
- put(
- "Cipher.PBEWithHMacSHA512AndSerpent",
+ put("Cipher.PBEWithHMacSHA512AndSerpent",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Serpent.class.getName());
put("Cipher.PBEWithHMacSHA512AndSquare",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Square.class.getName());
- put(
- "Cipher.PBEWithHMacSHA512AndTripleDES",
+ put("Cipher.PBEWithHMacSHA512AndTripleDES",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.TripleDES.class.getName());
- put(
- "Cipher.PBEWithHMacSHA512AndTwofish",
+ put("Cipher.PBEWithHMacSHA512AndTwofish",
gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Twofish.class.getName());
put("Cipher.PBEWithHMacTigerAndAES",
gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.AES.class.getName());
put("Cipher.PBEWithHMacTigerAndAnubis",
gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Anubis.class.getName());
- put(
- "Cipher.PBEWithHMacTigerAndBlowfish",
+ put("Cipher.PBEWithHMacTigerAndBlowfish",
gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Blowfish.class.getName());
put("Cipher.PBEWithHMacTigerAndCast5",
gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Cast5.class.getName());
@@ -316,44 +291,34 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Serpent.class.getName());
put("Cipher.PBEWithHMacTigerAndSquare",
gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Square.class.getName());
- put(
- "Cipher.PBEWithHMacTigerAndTripleDES",
+ put("Cipher.PBEWithHMacTigerAndTripleDES",
gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.TripleDES.class.getName());
put("Cipher.PBEWithHMacTigerAndTwofish",
gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Twofish.class.getName());
put("Cipher.PBEWithHMacWhirlpoolAndAES",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.AES.class.getName());
- put(
- "Cipher.PBEWithHMacWhirlpoolAndAnubis",
+ put("Cipher.PBEWithHMacWhirlpoolAndAnubis",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Anubis.class.getName());
- put(
- "Cipher.PBEWithHMacWhirlpoolAndBlowfish",
+ put("Cipher.PBEWithHMacWhirlpoolAndBlowfish",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Blowfish.class.getName());
- put(
- "Cipher.PBEWithHMacWhirlpoolAndCast5",
+ put("Cipher.PBEWithHMacWhirlpoolAndCast5",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Cast5.class.getName());
put("Cipher.PBEWithHMacWhirlpoolAndDES",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.DES.class.getName());
- put(
- "Cipher.PBEWithHMacWhirlpoolAndKhazad",
+ put("Cipher.PBEWithHMacWhirlpoolAndKhazad",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Khazad.class.getName());
- put(
- "Cipher.PBEWithHMacWhirlpoolAndSerpent",
+ put("Cipher.PBEWithHMacWhirlpoolAndSerpent",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Serpent.class.getName());
- put(
- "Cipher.PBEWithHMacWhirlpoolAndSquare",
+ put("Cipher.PBEWithHMacWhirlpoolAndSquare",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Square.class.getName());
- put(
- "Cipher.PBEWithHMacWhirlpoolAndTripleDES",
+ put("Cipher.PBEWithHMacWhirlpoolAndTripleDES",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.TripleDES.class.getName());
- put(
- "Cipher.PBEWithHMacWhirlpoolAndTwofish",
+ put("Cipher.PBEWithHMacWhirlpoolAndTwofish",
gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Twofish.class.getName());
// SecretKeyFactory interface to PBKDF2.
- put(
- "SecretKeyFactory.PBKDF2WithHMacHaval",
+ put("SecretKeyFactory.PBKDF2WithHMacHaval",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacHaval.class.getName());
put("SecretKeyFactory.PBKDF2WithHMacMD2",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD2.class.getName());
@@ -361,30 +326,23 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD4.class.getName());
put("SecretKeyFactory.PBKDF2WithHMacMD5",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD5.class.getName());
- put(
- "SecretKeyFactory.PBKDF2WithHMacSHA1",
+ put("SecretKeyFactory.PBKDF2WithHMacSHA1",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA1.class.getName());
- put(
- "SecretKeyFactory.PBKDF2WithHMacSHA256",
+ put("SecretKeyFactory.PBKDF2WithHMacSHA256",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA256.class.getName());
- put(
- "SecretKeyFactory.PBKDF2WithHMacSHA384",
+ put("SecretKeyFactory.PBKDF2WithHMacSHA384",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA384.class.getName());
- put(
- "SecretKeyFactory.PBKDF2WithHMacSHA512",
+ put("SecretKeyFactory.PBKDF2WithHMacSHA512",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA512.class.getName());
- put(
- "SecretKeyFactory.PBKDF2WithHMacTiger",
+ put("SecretKeyFactory.PBKDF2WithHMacTiger",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacTiger.class.getName());
- put(
- "SecretKeyFactory.PBKDF2WithHMacWhirlpool",
+ put("SecretKeyFactory.PBKDF2WithHMacWhirlpool",
gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacWhirlpool.class.getName());
// Simple SecretKeyFactory implementations.
put("SecretKeyFactory.Anubis",
gnu.javax.crypto.jce.key.AnubisSecretKeyFactoryImpl.class.getName());
- put(
- "SecretKeyFactory.Blowfish",
+ put("SecretKeyFactory.Blowfish",
gnu.javax.crypto.jce.key.BlowfishSecretKeyFactoryImpl.class.getName());
put("SecretKeyFactory.Cast5",
gnu.javax.crypto.jce.key.Cast5SecretKeyFactoryImpl.class.getName());
@@ -392,11 +350,9 @@ public final class GnuCrypto extends Provider
gnu.javax.crypto.jce.key.DESSecretKeyFactoryImpl.class.getName());
put("SecretKeyFactory.Khazad",
gnu.javax.crypto.jce.key.KhazadSecretKeyFactoryImpl.class.getName());
- put(
- "SecretKeyFactory.Rijndael",
+ put("SecretKeyFactory.Rijndael",
gnu.javax.crypto.jce.key.RijndaelSecretKeyFactoryImpl.class.getName());
- put(
- "SecretKeyFactory.Serpent",
+ put("SecretKeyFactory.Serpent",
gnu.javax.crypto.jce.key.SerpentSecretKeyFactoryImpl.class.getName());
put("SecretKeyFactory.Square",
gnu.javax.crypto.jce.key.SquareSecretKeyFactoryImpl.class.getName());
@@ -410,7 +366,6 @@ public final class GnuCrypto extends Provider
put("AlgorithmParameters.BlockCipherParameters",
gnu.javax.crypto.jce.params.BlockCipherParameters.class.getName());
-
// KeyGenerator Adapter implementations
put("KeyGenerator.Anubis",
gnu.javax.crypto.jce.key.AnubisKeyGeneratorImpl.class.getName());
@@ -541,19 +496,25 @@ public final class GnuCrypto extends Provider
put("Alg.Alias.Cipher.RSA", "RSAES-PKCS1-v1_5");
// SecureRandom
- put("SecureRandom.ARCFOUR", gnu.javax.crypto.jce.prng.ARCFourRandomSpi.class.getName());
+ put("SecureRandom.ARCFOUR",
+ gnu.javax.crypto.jce.prng.ARCFourRandomSpi.class.getName());
put("SecureRandom.ARCFOUR ImplementedIn", "Software");
- put("SecureRandom.CSPRNG", gnu.javax.crypto.jce.prng.CSPRNGSpi.class.getName());
+ put("SecureRandom.CSPRNG",
+ gnu.javax.crypto.jce.prng.CSPRNGSpi.class.getName());
put("SecureRandom.CSPRNG ImplementedIn", "Software");
- put("SecureRandom.ICM", gnu.javax.crypto.jce.prng.ICMRandomSpi.class.getName());
+ put("SecureRandom.ICM",
+ gnu.javax.crypto.jce.prng.ICMRandomSpi.class.getName());
put("SecureRandom.ICM ImplementedIn", "Software");
- put("SecureRandom.UMAC-KDF", gnu.javax.crypto.jce.prng.UMacRandomSpi.class.getName());
+ put("SecureRandom.UMAC-KDF",
+ gnu.javax.crypto.jce.prng.UMacRandomSpi.class.getName());
put("SecureRandom.UMAC-KDF ImplementedIn", "Software");
- put("SecureRandom.Fortuna", gnu.javax.crypto.jce.prng.FortunaImpl.class.getName ());
+ put("SecureRandom.Fortuna",
+ gnu.javax.crypto.jce.prng.FortunaImpl.class.getName());
put("SecureRandom.Fortuna ImplementedIn", "Software");
// KeyStore
- put("KeyStore.GKR", gnu.javax.crypto.jce.keyring.GnuKeyring.class.getName());
+ put("KeyStore.GKR",
+ gnu.javax.crypto.jce.keyring.GnuKeyring.class.getName());
put("Alg.Alias.KeyStore.GnuKeyring", "GKR");
// KeyPairGenerator ---------------------------------------------------
@@ -587,13 +548,10 @@ public final class GnuCrypto extends Provider
});
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns a {@link Set} of names of symmetric key block cipher algorithms
- * available from this {@link Provider}.</p>
- *
+ * Returns a {@link Set} of names of symmetric key block cipher algorithms
+ * available from this {@link Provider}.
+ *
* @return a {@link Set} of cipher names (Strings).
*/
public static final Set getCipherNames()
@@ -605,16 +563,13 @@ public final class GnuCrypto extends Provider
}
/**
- * <p>Returns a {@link Set} of names of MAC algorithms available from
- * this {@link Provider}.</p>
- *
+ * Returns a {@link Set} of names of MAC algorithms available from this
+ * {@link Provider}.
+ *
* @return a {@link Set} of MAC names (Strings).
*/
public static final Set getMacNames()
{
return MacFactory.getNames();
}
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/javax/crypto/jce/GnuSasl.java b/gnu/javax/crypto/jce/GnuSasl.java
index 6ee86ae19..923b40a5f 100644
--- a/gnu/javax/crypto/jce/GnuSasl.java
+++ b/gnu/javax/crypto/jce/GnuSasl.java
@@ -47,53 +47,63 @@ import java.security.PrivilegedAction;
import java.security.Provider;
import java.util.Set;
-public final class GnuSasl extends Provider
+public final class GnuSasl
+ extends Provider
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public GnuSasl()
{
- super (Registry.GNU_SASL, 2.1, "GNU Crypto SASL Provider");
+ super(Registry.GNU_SASL, 2.1, "GNU SASL Provider");
- AccessController.doPrivileged (new PrivilegedAction()
+ AccessController.doPrivileged(new PrivilegedAction()
+ {
+ public Object run()
{
- public Object run()
- {
- // SASL Client and Server mechanisms
- put("SaslClientFactory.ANONYMOUS", gnu.javax.crypto.sasl.ClientFactory.class.getName());
- put("SaslClientFactory.PLAIN", gnu.javax.crypto.sasl.ClientFactory.class.getName());
- put("SaslClientFactory.CRAM-MD5", gnu.javax.crypto.sasl.ClientFactory.class.getName());
- put("SaslClientFactory.SRP", gnu.javax.crypto.sasl.ClientFactory.class.getName());
-
- put("SaslServerFactory.ANONYMOUS", gnu.javax.crypto.sasl.ServerFactory.class.getName());
- put("SaslServerFactory.PLAIN", gnu.javax.crypto.sasl.ServerFactory.class.getName());
- put("SaslServerFactory.CRAM-MD5", gnu.javax.crypto.sasl.ServerFactory.class.getName());
- put("SaslServerFactory.SRP-MD5", gnu.javax.crypto.sasl.ServerFactory.class.getName());
- put("SaslServerFactory.SRP-SHA-160", gnu.javax.crypto.sasl.ServerFactory.class.getName());
- put("SaslServerFactory.SRP-RIPEMD128", gnu.javax.crypto.sasl.ServerFactory.class.getName());
- put("SaslServerFactory.SRP-RIPEMD160", gnu.javax.crypto.sasl.ServerFactory.class.getName());
- put("SaslServerFactory.SRP-TIGER", gnu.javax.crypto.sasl.ServerFactory.class.getName());
- put("SaslServerFactory.SRP-WHIRLPOOL", gnu.javax.crypto.sasl.ServerFactory.class.getName());
-
- put("Alg.Alias.SaslServerFactory.SRP-SHS", "SRP-SHA-160");
- put("Alg.Alias.SaslServerFactory.SRP-SHA", "SRP-SHA-160");
- put("Alg.Alias.SaslServerFactory.SRP-SHA1", "SRP-SHA-160");
- put("Alg.Alias.SaslServerFactory.SRP-SHA-1", "SRP-SHA-160");
- put("Alg.Alias.SaslServerFactory.SRP-SHA160", "SRP-SHA-160");
- put("Alg.Alias.SaslServerFactory.SRP-RIPEMD-128", "SRP-RIPEMD128");
- put("Alg.Alias.SaslServerFactory.SRP-RIPEMD-160", "SRP-RIPEMD160");
-
- return null;
- }
- });
+ // SASL Client and Server mechanisms
+ put("SaslClientFactory.ANONYMOUS",
+ gnu.javax.crypto.sasl.ClientFactory.class.getName());
+ put("SaslClientFactory.PLAIN",
+ gnu.javax.crypto.sasl.ClientFactory.class.getName());
+ put("SaslClientFactory.CRAM-MD5",
+ gnu.javax.crypto.sasl.ClientFactory.class.getName());
+ put("SaslClientFactory.SRP",
+ gnu.javax.crypto.sasl.ClientFactory.class.getName());
+
+ put("SaslServerFactory.ANONYMOUS",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+ put("SaslServerFactory.PLAIN",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+ put("SaslServerFactory.CRAM-MD5",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+ put("SaslServerFactory.SRP-MD5",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+ put("SaslServerFactory.SRP-SHA-160",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+ put("SaslServerFactory.SRP-RIPEMD128",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+ put("SaslServerFactory.SRP-RIPEMD160",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+ put("SaslServerFactory.SRP-TIGER",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+ put("SaslServerFactory.SRP-WHIRLPOOL",
+ gnu.javax.crypto.sasl.ServerFactory.class.getName());
+
+ put("Alg.Alias.SaslServerFactory.SRP-SHS", "SRP-SHA-160");
+ put("Alg.Alias.SaslServerFactory.SRP-SHA", "SRP-SHA-160");
+ put("Alg.Alias.SaslServerFactory.SRP-SHA1", "SRP-SHA-160");
+ put("Alg.Alias.SaslServerFactory.SRP-SHA-1", "SRP-SHA-160");
+ put("Alg.Alias.SaslServerFactory.SRP-SHA160", "SRP-SHA-160");
+ put("Alg.Alias.SaslServerFactory.SRP-RIPEMD-128", "SRP-RIPEMD128");
+ put("Alg.Alias.SaslServerFactory.SRP-RIPEMD-160", "SRP-RIPEMD160");
+
+ return null;
+ }
+ });
}
/**
- * <p>Returns a {@link Set} of names of SASL Client mechanisms available from
- * this {@link Provider}.</p>
- *
+ * Returns a {@link Set} of names of SASL Client mechanisms available from
+ * this {@link Provider}.
+ *
* @return a {@link Set} of SASL Client mechanisms (Strings).
*/
public static final Set getSaslClientMechanismNames()
@@ -102,9 +112,9 @@ public final class GnuSasl extends Provider
}
/**
- * <p>Returns a {@link Set} of names of SASL Server mechanisms available from
- * this {@link Provider}.</p>
- *
+ * Returns a {@link Set} of names of SASL Server mechanisms available from
+ * this {@link Provider}.
+ *
* @return a {@link Set} of SASL Server mechanisms (Strings).
*/
public static final Set getSaslServerMechanismNames()
diff --git a/gnu/javax/crypto/jce/PBKDF2SecretKeyFactory.java b/gnu/javax/crypto/jce/PBKDF2SecretKeyFactory.java
index 59231c6c7..be7fb18b0 100644
--- a/gnu/javax/crypto/jce/PBKDF2SecretKeyFactory.java
+++ b/gnu/javax/crypto/jce/PBKDF2SecretKeyFactory.java
@@ -53,57 +53,38 @@ import gnu.java.security.prng.IRandom;
import gnu.java.security.prng.LimitReachedException;
import gnu.javax.crypto.prng.PRNGFactory;
-public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
+public abstract class PBKDF2SecretKeyFactory
+ extends SecretKeyFactorySpi
{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
-
protected String macName;
-
private static final int DEFAULT_ITERATION_COUNT = 1000;
-
private static final int DEFAULT_KEY_LEN = 32;
- // Constructor.
- // ------------------------------------------------------------------------
-
protected PBKDF2SecretKeyFactory(String macName)
{
this.macName = macName;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
protected SecretKey engineGenerateSecret(KeySpec spec)
throws InvalidKeySpecException
{
- if (!(spec instanceof PBEKeySpec))
- {
- throw new InvalidKeySpecException("not a PBEKeySpec");
- }
+ if (! (spec instanceof PBEKeySpec))
+ throw new InvalidKeySpecException("not a PBEKeySpec");
IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName);
HashMap attr = new HashMap();
attr.put(IPBE.PASSWORD, ((PBEKeySpec) spec).getPassword());
byte[] salt = ((PBEKeySpec) spec).getSalt();
if (salt == null)
- {
- salt = new byte[0];
- }
+ salt = new byte[0];
attr.put(IPBE.SALT, salt);
int ic = ((PBEKeySpec) spec).getIterationCount();
if (ic <= 0)
- {
- ic = DEFAULT_ITERATION_COUNT;
- }
- attr.put(IPBE.ITERATION_COUNT, new Integer(ic));
+ ic = DEFAULT_ITERATION_COUNT;
+ attr.put(IPBE.ITERATION_COUNT, Integer.valueOf(ic));
kdf.init(attr);
int len = ((PBEKeySpec) spec).getKeyLength();
if (len <= 0)
- {
- len = DEFAULT_KEY_LEN;
- }
+ len = DEFAULT_KEY_LEN;
byte[] dk = new byte[len];
try
{
@@ -113,7 +94,6 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
{
throw new IllegalArgumentException(lre.toString());
}
-
return new SecretKeySpec(dk, "PBKDF2");
}
@@ -128,10 +108,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
return new SecretKeySpec(key.getEncoded(), key.getAlgorithm());
}
- // Inner classes.
- // ------------------------------------------------------------------------
-
- public static class HMacHaval extends PBKDF2SecretKeyFactory
+ public static class HMacHaval
+ extends PBKDF2SecretKeyFactory
{
public HMacHaval()
{
@@ -139,7 +117,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacMD2 extends PBKDF2SecretKeyFactory
+ public static class HMacMD2
+ extends PBKDF2SecretKeyFactory
{
public HMacMD2()
{
@@ -147,7 +126,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacMD4 extends PBKDF2SecretKeyFactory
+ public static class HMacMD4
+ extends PBKDF2SecretKeyFactory
{
public HMacMD4()
{
@@ -155,7 +135,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacMD5 extends PBKDF2SecretKeyFactory
+ public static class HMacMD5
+ extends PBKDF2SecretKeyFactory
{
public HMacMD5()
{
@@ -163,7 +144,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacRipeMD128 extends PBKDF2SecretKeyFactory
+ public static class HMacRipeMD128
+ extends PBKDF2SecretKeyFactory
{
public HMacRipeMD128()
{
@@ -171,7 +153,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacRipeMD160 extends PBKDF2SecretKeyFactory
+ public static class HMacRipeMD160
+ extends PBKDF2SecretKeyFactory
{
public HMacRipeMD160()
{
@@ -179,7 +162,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacSHA1 extends PBKDF2SecretKeyFactory
+ public static class HMacSHA1
+ extends PBKDF2SecretKeyFactory
{
public HMacSHA1()
{
@@ -187,7 +171,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacSHA256 extends PBKDF2SecretKeyFactory
+ public static class HMacSHA256
+ extends PBKDF2SecretKeyFactory
{
public HMacSHA256()
{
@@ -195,7 +180,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacSHA384 extends PBKDF2SecretKeyFactory
+ public static class HMacSHA384
+ extends PBKDF2SecretKeyFactory
{
public HMacSHA384()
{
@@ -203,7 +189,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacSHA512 extends PBKDF2SecretKeyFactory
+ public static class HMacSHA512
+ extends PBKDF2SecretKeyFactory
{
public HMacSHA512()
{
@@ -211,7 +198,8 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacTiger extends PBKDF2SecretKeyFactory
+ public static class HMacTiger
+ extends PBKDF2SecretKeyFactory
{
public HMacTiger()
{
@@ -219,11 +207,12 @@ public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
}
}
- public static class HMacWhirlpool extends PBKDF2SecretKeyFactory
+ public static class HMacWhirlpool
+ extends PBKDF2SecretKeyFactory
{
public HMacWhirlpool()
{
super("HMAC-WHIRLPOOL");
}
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/cipher/AESSpi.java b/gnu/javax/crypto/jce/cipher/AESSpi.java
index 33de68956..1322e5e8a 100644
--- a/gnu/javax/crypto/jce/cipher/AESSpi.java
+++ b/gnu/javax/crypto/jce/cipher/AESSpi.java
@@ -50,23 +50,17 @@ import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
/**
- * The implementation of the AES <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.
+ * The implementation of the AES <i>Service Provider Interface</i> (<b>SPI</b>)
+ * adapter.
*/
-public final class AESSpi extends CipherAdapter
+public final class AESSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public AESSpi()
{
super(Registry.AES_CIPHER, 16);
}
- // Methods from CipherAdapter
- // -----------------------------------------------------------------------
-
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params,
SecureRandom random) throws InvalidKeyException,
InvalidAlgorithmParameterException
@@ -74,10 +68,8 @@ public final class AESSpi extends CipherAdapter
if (params instanceof BlockCipherParameterSpec)
{
if (((BlockCipherParameterSpec) params).getBlockSize() != 16)
- {
- throw new InvalidAlgorithmParameterException(
- "AES block size must be 16 bytes");
- }
+ throw new InvalidAlgorithmParameterException(
+ "AES block size must be 16 bytes");
}
super.engineInit(opmode, key, params, random);
}
@@ -90,9 +82,7 @@ public final class AESSpi extends CipherAdapter
try
{
if (params != null)
- {
- spec = params.getParameterSpec(BlockCipherParameterSpec.class);
- }
+ spec = params.getParameterSpec(BlockCipherParameterSpec.class);
}
catch (InvalidParameterSpecException ipse)
{
diff --git a/gnu/javax/crypto/jce/cipher/ARCFourSpi.java b/gnu/javax/crypto/jce/cipher/ARCFourSpi.java
index 963fa1c00..abcb486b5 100644
--- a/gnu/javax/crypto/jce/cipher/ARCFourSpi.java
+++ b/gnu/javax/crypto/jce/cipher/ARCFourSpi.java
@@ -62,29 +62,20 @@ import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;
/**
- * The <i>Service Provider Interface</i> (<b>SPI</b>) for the ARCFOUR
- * stream cipher.
+ * The <i>Service Provider Interface</i> (<b>SPI</b>) for the ARCFOUR stream
+ * cipher.
*/
-public class ARCFourSpi extends CipherSpi
+public class ARCFourSpi
+ extends CipherSpi
{
-
- // Constants and variables.
- // -----------------------------------------------------------------------
-
private IRandom keystream;
- // Constructors.
- // -----------------------------------------------------------------------
-
public ARCFourSpi()
{
super();
keystream = PRNGFactory.getInstance(Registry.ARCFOUR_PRNG);
}
- // Methods implementing CipherSpi.
- // -----------------------------------------------------------------------
-
protected int engineGetBlockSize()
{
return 0; // stream cipher.
@@ -119,14 +110,10 @@ public class ARCFourSpi extends CipherSpi
throws InvalidKeyException
{
if (mode != Cipher.ENCRYPT_MODE && mode != Cipher.DECRYPT_MODE)
- {
- throw new IllegalArgumentException(
- "arcfour is for encryption or decryption only");
- }
- if (key == null || !key.getFormat().equalsIgnoreCase("RAW"))
- {
- throw new InvalidKeyException("key must be non-null raw bytes");
- }
+ throw new IllegalArgumentException(
+ "arcfour is for encryption or decryption only");
+ if (key == null || ! key.getFormat().equalsIgnoreCase("RAW"))
+ throw new InvalidKeyException("key must be non-null raw bytes");
HashMap attrib = new HashMap();
attrib.put(ARCFour.ARCFOUR_KEY_MATERIAL, key.getEncoded());
keystream.init(attrib);
@@ -149,16 +136,12 @@ public class ARCFourSpi extends CipherSpi
protected byte[] engineUpdate(byte[] in, int offset, int length)
{
if (length < 0 || offset < 0 || length + offset > in.length)
- {
- throw new ArrayIndexOutOfBoundsException();
- }
+ throw new ArrayIndexOutOfBoundsException();
byte[] result = new byte[length];
try
{
for (int i = 0; i < length; i++)
- {
- result[i] = (byte) (in[i + offset] ^ keystream.nextByte());
- }
+ result[i] = (byte)(in[i + offset] ^ keystream.nextByte());
}
catch (LimitReachedException wontHappen)
{
@@ -171,19 +154,13 @@ public class ARCFourSpi extends CipherSpi
{
if (length < 0 || inOffset < 0 || length + inOffset > in.length
|| outOffset < 0)
- {
- throw new ArrayIndexOutOfBoundsException();
- }
+ throw new ArrayIndexOutOfBoundsException();
if (outOffset + length > out.length)
- {
- throw new ShortBufferException();
- }
+ throw new ShortBufferException();
try
{
for (int i = 0; i < length; i++)
- {
- out[i + outOffset] = (byte) (in[i + inOffset] ^ keystream.nextByte());
- }
+ out[i + outOffset] = (byte)(in[i + inOffset] ^ keystream.nextByte());
}
catch (LimitReachedException wontHappen)
{
diff --git a/gnu/javax/crypto/jce/cipher/AnubisSpi.java b/gnu/javax/crypto/jce/cipher/AnubisSpi.java
index 0fca3b491..e35e4e724 100644
--- a/gnu/javax/crypto/jce/cipher/AnubisSpi.java
+++ b/gnu/javax/crypto/jce/cipher/AnubisSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Anubis <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class AnubisSpi extends CipherAdapter
+public final class AnubisSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public AnubisSpi()
{
super(Registry.ANUBIS_CIPHER);
diff --git a/gnu/javax/crypto/jce/cipher/BlowfishSpi.java b/gnu/javax/crypto/jce/cipher/BlowfishSpi.java
index d31d7e193..fec200ca6 100644
--- a/gnu/javax/crypto/jce/cipher/BlowfishSpi.java
+++ b/gnu/javax/crypto/jce/cipher/BlowfishSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Blowfish <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class BlowfishSpi extends CipherAdapter
+public final class BlowfishSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public BlowfishSpi()
{
super(Registry.BLOWFISH_CIPHER);
diff --git a/gnu/javax/crypto/jce/cipher/Cast5Spi.java b/gnu/javax/crypto/jce/cipher/Cast5Spi.java
index b1d4cf703..bf0803400 100644
--- a/gnu/javax/crypto/jce/cipher/Cast5Spi.java
+++ b/gnu/javax/crypto/jce/cipher/Cast5Spi.java
@@ -43,26 +43,12 @@ import gnu.java.security.Registry;
/**
* The implementation of the <code>CAST5</code> (a.k.a. CAST-128) <i>Service
* Provider Interface</i> (<b>SPI</b>) Adapter.
- *
- * @version Revision: $
*/
-public class Cast5Spi extends CipherAdapter
+public class Cast5Spi
+ extends CipherAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Cast5Spi()
{
super(Registry.CAST5_CIPHER);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/cipher/CipherAdapter.java b/gnu/javax/crypto/jce/cipher/CipherAdapter.java
index f8adedce7..4e9af6ab8 100644
--- a/gnu/javax/crypto/jce/cipher/CipherAdapter.java
+++ b/gnu/javax/crypto/jce/cipher/CipherAdapter.java
@@ -38,8 +38,9 @@ exception statement from your version. */
package gnu.javax.crypto.jce.cipher;
-import gnu.javax.crypto.cipher.IBlockCipher;
+import gnu.java.security.Registry;
import gnu.javax.crypto.cipher.CipherFactory;
+import gnu.javax.crypto.cipher.IBlockCipher;
import gnu.javax.crypto.jce.spec.BlockCipherParameterSpec;
import gnu.javax.crypto.mode.IMode;
import gnu.javax.crypto.mode.ModeFactory;
@@ -67,61 +68,48 @@ import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
/**
- * <p>The implementation of a generic {@link Cipher} <i>Adapter</i> class to
- * wrap GNU Crypto cipher instances.</p>
- *
- * <p>This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
+ * The implementation of a generic {@link Cipher} <i>Adapter</i> class to wrap
+ * GNU cipher instances.
+ * <p>
+ * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
* the {@link Cipher} class, which provides the functionality of symmetric-key
- * block ciphers, such as the AES.<p>
- *
- * <p>This base class defines all of the abstract methods in {@link CipherSpi},
+ * block ciphers, such as the AES.
+ * <p>
+ * This base class defines all of the abstract methods in {@link CipherSpi},
* but does not define the (non-abstract) key wrapping functions that extended
* the base cipher SPI, and these methods thus immediately throw an
* {@link UnsupportedOperationException}. If a cipher implementation provides
* this functionality, or if it in fact accepts parameters other than the key
* and the initialization vector, the subclass should override those methods.
* Otherwise a subclass need only call the {@link #CipherAdapter(String)}
- * constructor with the name of the cipher.</p>
+ * constructor with the name of the cipher.
*/
-class CipherAdapter extends CipherSpi
+class CipherAdapter
+ extends CipherSpi
{
-
- // Constants and variables.
- // -------------------------------------------------------------------------
-
/** Our cipher instance. */
protected IBlockCipher cipher;
-
/** Our mode instance. */
protected IMode mode;
-
/** Our padding instance. */
protected IPad pad;
-
/** The current key size. */
protected int keyLen;
-
/** Our attributes map. */
protected Map attributes;
-
/** An incomplete block. */
protected byte[] partBlock;
-
/** The number of bytes in {@link #partBlock}. */
protected int partLen;
-
/** The length of blocks we are processing. */
protected int blockLen;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Protected constructor to be called by subclasses. The cipher name
- * argument should be the appropriate one listed in {@link gnu.java.security.Registry}.
- * The basic cipher instance is created, along with an instance of the
- * {@link gnu.javax.crypto.mode.ECB} mode and no padding.</p>
- *
+ * Protected constructor to be called by subclasses. The cipher name argument
+ * should be the appropriate one listed in {@link Registry}. The basic cipher
+ * instance is created, along with an instance of the
+ * {@link gnu.javax.crypto.mode.ECB} mode and no padding.
+ *
* @param cipherName The cipher to instantiate.
* @param blockLen The block length to use.
*/
@@ -131,12 +119,12 @@ class CipherAdapter extends CipherSpi
attributes = new HashMap();
this.blockLen = blockLen;
mode = ModeFactory.getInstance("ECB", cipher, blockLen);
- attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(blockLen));
+ attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));
}
/**
- * <p>Creates a new cipher adapter with the default block size.</p>
- *
+ * Creates a new cipher adapter with the default block size.
+ *
* @param cipherName The cipher to instantiate.
*/
protected CipherAdapter(String cipherName)
@@ -145,12 +133,9 @@ class CipherAdapter extends CipherSpi
blockLen = cipher.defaultBlockSize();
attributes = new HashMap();
mode = ModeFactory.getInstance("ECB", cipher, blockLen);
- attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(blockLen));
+ attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));
}
- // Instance methods implementing javax.crypto.CipherSpi.
- // -------------------------------------------------------------------------
-
protected void engineSetMode(String modeName) throws NoSuchAlgorithmException
{
if (modeName.length() >= 3
@@ -161,7 +146,7 @@ class CipherAdapter extends CipherSpi
try
{
int bs = Integer.parseInt(modeName.substring(3));
- attributes.put(IMode.MODE_BLOCK_SIZE, new Integer(bs / 8));
+ attributes.put(IMode.MODE_BLOCK_SIZE, Integer.valueOf(bs / 8));
}
catch (NumberFormatException nfe)
{
@@ -171,14 +156,10 @@ class CipherAdapter extends CipherSpi
}
}
else
- {
- attributes.remove(IMode.MODE_BLOCK_SIZE);
- }
+ attributes.remove(IMode.MODE_BLOCK_SIZE);
mode = ModeFactory.getInstance(modeName, cipher, blockLen);
if (mode == null)
- {
- throw new NoSuchAlgorithmException(modeName);
- }
+ throw new NoSuchAlgorithmException(modeName);
}
protected void engineSetPadding(String padName) throws NoSuchPaddingException
@@ -190,17 +171,13 @@ class CipherAdapter extends CipherSpi
}
pad = PadFactory.getInstance(padName);
if (pad == null)
- {
- throw new NoSuchPaddingException(padName);
- }
+ throw new NoSuchPaddingException(padName);
}
protected int engineGetBlockSize()
{
if (cipher != null)
- {
- return blockLen;
- }
+ return blockLen;
return 0;
}
@@ -214,17 +191,16 @@ class CipherAdapter extends CipherSpi
{
byte[] iv = (byte[]) attributes.get(IMode.IV);
if (iv == null)
- {
- return null;
- }
+ return null;
return (byte[]) iv.clone();
}
protected AlgorithmParameters engineGetParameters()
{
- BlockCipherParameterSpec spec = new BlockCipherParameterSpec(
- (byte[]) attributes.get(IMode.IV),
- cipher.currentBlockSize(),
+ byte[] iv = (byte[]) attributes.get(IMode.IV);
+ int cipherBlockSize = cipher.currentBlockSize();
+ BlockCipherParameterSpec spec = new BlockCipherParameterSpec(iv,
+ cipherBlockSize,
keyLen);
AlgorithmParameters params;
try
@@ -246,24 +222,44 @@ class CipherAdapter extends CipherSpi
protected void engineInit(int opmode, Key key, SecureRandom random)
throws InvalidKeyException
{
+ try
+ {
+ engineInit(opmode, key, (AlgorithmParameterSpec) null, random);
+ }
+ catch (InvalidAlgorithmParameterException e)
+ {
+ throw new InvalidKeyException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Executes initialization logic after all parameters have been handled by the
+ * engineInit()s.
+ *
+ * @param opmode the desired mode of operation for this instance.
+ * @param key the key material to use for initialization.
+ * @param random a source of randmoness to use if/when needed.
+ * @throws InvalidKeyException if <code>key</code> is invalid or the cipher
+ * needs extra parameters which can not be derived from
+ * <code>key</code>; e.g. an IV.
+ */
+ private void engineInitHandler(int opmode, Key key, SecureRandom random)
+ throws InvalidKeyException
+ {
switch (opmode)
{
case Cipher.ENCRYPT_MODE:
- attributes.put(IMode.STATE, new Integer(IMode.ENCRYPTION));
+ attributes.put(IMode.STATE, Integer.valueOf(IMode.ENCRYPTION));
break;
case Cipher.DECRYPT_MODE:
- attributes.put(IMode.STATE, new Integer(IMode.DECRYPTION));
+ attributes.put(IMode.STATE, Integer.valueOf(IMode.DECRYPTION));
break;
}
- if (!key.getFormat().equalsIgnoreCase("RAW"))
- {
- throw new InvalidKeyException("bad key format " + key.getFormat());
- }
+ if (! key.getFormat().equalsIgnoreCase("RAW"))
+ throw new InvalidKeyException("bad key format " + key.getFormat());
byte[] kb = key.getEncoded();
if (keyLen == 0)
- {
- keyLen = kb.length;
- }
+ keyLen = kb.length;
else if (keyLen < kb.length)
{
byte[] kbb = kb;
@@ -280,31 +276,48 @@ class CipherAdapter extends CipherSpi
{
if (params == null)
{
- byte[] iv = new byte[blockLen];
- random.nextBytes(iv);
- attributes.put(IMode.IV, iv);
+ // All cipher modes require parameters (like an IV) except ECB. When
+ // these cant be derived from the given key then it must be generated
+ // randomly if in ENCRYPT or WRAP mode. Parameters that have defaults
+ // for our cipher must be set to these defaults.
+ if (! mode.name().toLowerCase().startsWith(Registry.ECB_MODE + "("))
+ {
+ switch (opmode)
+ {
+ case Cipher.ENCRYPT_MODE:
+ case Cipher.WRAP_MODE:
+ byte[] iv = new byte[blockLen];
+ random.nextBytes(iv);
+ attributes.put(IMode.IV, iv);
+ break;
+ default:
+ throw new InvalidAlgorithmParameterException(
+ "Required algorithm parameters are missing for mode: "
+ + mode.name());
+ }
+ }
+ // Add default for block length etc.
blockLen = cipher.defaultBlockSize();
- attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(blockLen));
+ attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE,
+ Integer.valueOf(blockLen));
keyLen = 0;
}
else if (params instanceof BlockCipherParameterSpec)
{
- attributes.put(
- IBlockCipher.CIPHER_BLOCK_SIZE,
- new Integer(
- ((BlockCipherParameterSpec) params).getBlockSize()));
- attributes.put(IMode.IV, ((BlockCipherParameterSpec) params).getIV());
- keyLen = ((BlockCipherParameterSpec) params).getKeySize();
- blockLen = ((BlockCipherParameterSpec) params).getBlockSize();
+ BlockCipherParameterSpec bcps = (BlockCipherParameterSpec) params;
+ blockLen = bcps.getBlockSize();
+ attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));
+ attributes.put(IMode.IV, bcps.getIV());
+ keyLen = bcps.getKeySize();
}
else if (params instanceof IvParameterSpec)
{
attributes.put(IMode.IV, ((IvParameterSpec) params).getIV());
blockLen = cipher.defaultBlockSize();
- attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(blockLen));
+ attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));
keyLen = 0;
}
- engineInit(opmode, key, random);
+ engineInitHandler(opmode, key, random);
}
protected void engineInit(int opmode, Key key, AlgorithmParameters params,
@@ -315,9 +328,7 @@ class CipherAdapter extends CipherSpi
try
{
if (params != null)
- {
- spec = params.getParameterSpec(BlockCipherParameterSpec.class);
- }
+ spec = params.getParameterSpec(BlockCipherParameterSpec.class);
}
catch (InvalidParameterSpecException ignored)
{
@@ -334,91 +345,50 @@ class CipherAdapter extends CipherSpi
{
engineUpdate(input, off, len, out, 0);
}
- catch (ShortBufferException x)
- { // should not happen
+ catch (ShortBufferException x) // should not happen
+ {
x.printStackTrace(System.err);
}
return out;
}
- // protected int
- // engineUpdate(byte[] in, int inOff, int inLen, byte[] out, int outOff)
- // throws ShortBufferException
- // {
- // int blockSize = mode.currentBlockSize();
- // int count = (partLen + inLen) / blockSize;
- // if (count * blockSize > out.length - outOff) {
- // throw new ShortBufferException();
- // }
- // byte[] buf;
- // if (partLen > 0 && count > 0) {
- // buf = new byte[partLen + inLen];
- // System.arraycopy(partBlock, 0, buf, 0, partLen);
- // if (in != null && inLen > 0) {
- // System.arraycopy(in, inOff, buf, partLen, inLen);
- // }
- // partLen = 0;
- // inOff = 0;
- // } else {
- // buf = in;
- // }
- // for (int i = 0; i < count; i++) {
- // mode.update(buf, i * blockSize + inOff, out, i * blockSize + outOff);
- // }
- // if (inOff + inLen > count * blockSize) {
- // partLen = (inOff + inLen) - (count * blockSize);
- // System.arraycopy(in, count * blockSize, partBlock, 0, partLen);
- // }
- // return count * blockSize;
- // }
-
protected int engineUpdate(byte[] in, int inOff, int inLen, byte[] out,
int outOff) throws ShortBufferException
{
- if (inLen == 0)
- { // nothing to process
- return 0;
- }
+ if (inLen == 0) // nothing to process
+ return 0;
final int blockSize = mode.currentBlockSize();
final int blockCount = (partLen + inLen) / blockSize;
final int result = blockCount * blockSize;
if (result > out.length - outOff)
+ throw new ShortBufferException();
+ if (blockCount == 0) // not enough bytes for even 1 block
{
- throw new ShortBufferException();
- }
- if (blockCount == 0)
- { // not enough bytes for even 1 block
System.arraycopy(in, inOff, partBlock, partLen, inLen);
partLen += inLen;
return 0;
}
final byte[] buf;
// we have enough bytes for at least 1 block
- if (partLen == 0)
- { // if no cached bytes use input
- buf = in;
- }
- else
- { // prefix input with cached bytes
+ if (partLen == 0) // if no cached bytes use input
+ buf = in;
+ else // prefix input with cached bytes
+ {
buf = new byte[partLen + inLen];
System.arraycopy(partBlock, 0, buf, 0, partLen);
if (in != null && inLen > 0)
- {
- System.arraycopy(in, inOff, buf, partLen, inLen);
- }
+ System.arraycopy(in, inOff, buf, partLen, inLen);
inOff = 0;
}
- for (int i = 0; i < blockCount; i++)
- { // update blockCount * blockSize
+ for (int i = 0; i < blockCount; i++) // update blockCount * blockSize
+ {
mode.update(buf, inOff, out, outOff);
inOff += blockSize;
outOff += blockSize;
}
partLen += inLen - result;
- if (partLen > 0)
- { // cache remaining bytes from buf
- System.arraycopy(buf, inOff, partBlock, 0, partLen);
- }
+ if (partLen > 0) // cache remaining bytes from buf
+ System.arraycopy(buf, inOff, partBlock, 0, partLen);
return result;
}
@@ -458,9 +428,7 @@ class CipherAdapter extends CipherSpi
else
{
if (partLen > 0)
- {
- throw new IllegalBlockSizeException(partLen + " trailing bytes");
- }
+ throw new IllegalBlockSizeException(partLen + " trailing bytes");
result = buf;
}
@@ -483,9 +451,7 @@ class CipherAdapter extends CipherSpi
{
byte[] buf = engineDoFinal(in, inOff, inLen);
if (out.length + outOff < buf.length)
- {
- throw new ShortBufferException();
- }
+ throw new ShortBufferException();
System.arraycopy(buf, 0, out, outOff, buf.length);
return buf.length;
}
diff --git a/gnu/javax/crypto/jce/cipher/DESSpi.java b/gnu/javax/crypto/jce/cipher/DESSpi.java
index ff86071c4..21f62b4f0 100644
--- a/gnu/javax/crypto/jce/cipher/DESSpi.java
+++ b/gnu/javax/crypto/jce/cipher/DESSpi.java
@@ -41,15 +41,12 @@ package gnu.javax.crypto.jce.cipher;
import gnu.java.security.Registry;
/**
- * The implementation of the DES <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.
+ * The implementation of the DES <i>Service Provider Interface</i> (<b>SPI</b>)
+ * adapter.
*/
-public final class DESSpi extends CipherAdapter
+public final class DESSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public DESSpi()
{
super(Registry.DES_CIPHER);
diff --git a/gnu/javax/crypto/jce/cipher/KhazadSpi.java b/gnu/javax/crypto/jce/cipher/KhazadSpi.java
index 397c27d2e..6e744a2f2 100644
--- a/gnu/javax/crypto/jce/cipher/KhazadSpi.java
+++ b/gnu/javax/crypto/jce/cipher/KhazadSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Khazad <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class KhazadSpi extends CipherAdapter
+public final class KhazadSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public KhazadSpi()
{
super(Registry.KHAZAD_CIPHER);
diff --git a/gnu/javax/crypto/jce/cipher/NullCipherSpi.java b/gnu/javax/crypto/jce/cipher/NullCipherSpi.java
index e6d78ef39..e50e00c8e 100644
--- a/gnu/javax/crypto/jce/cipher/NullCipherSpi.java
+++ b/gnu/javax/crypto/jce/cipher/NullCipherSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Null cipher <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class NullCipherSpi extends CipherAdapter
+public final class NullCipherSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public NullCipherSpi()
{
super(Registry.NULL_CIPHER);
diff --git a/gnu/javax/crypto/jce/cipher/PBES2.java b/gnu/javax/crypto/jce/cipher/PBES2.java
index 9889ab9fc..26a6a2c2d 100644
--- a/gnu/javax/crypto/jce/cipher/PBES2.java
+++ b/gnu/javax/crypto/jce/cipher/PBES2.java
@@ -55,20 +55,13 @@ import javax.crypto.interfaces.PBEKey;
import javax.crypto.spec.SecretKeySpec;
/**
- * <p>.</p>
*/
-public abstract class PBES2 extends CipherAdapter
+public abstract class PBES2
+ extends CipherAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The HMac (PRF) algorithm name. */
protected String macName;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
protected PBES2(String cipherName, int blockLen, String macName)
{
super(cipherName, blockLen);
@@ -81,15 +74,11 @@ public abstract class PBES2 extends CipherAdapter
this.macName = macName;
}
- // Instance methods
- // -------------------------------------------------------------------------
-
protected void engineInit(int opmode, Key key, SecureRandom random)
throws InvalidKeyException
{
- if (!(key instanceof PBEKey))
+ if (! (key instanceof PBEKey))
throw new InvalidKeyException("not a PBE key");
-
super.engineInit(opmode, genkey((PBEKey) key), random);
}
@@ -97,9 +86,8 @@ public abstract class PBES2 extends CipherAdapter
SecureRandom random) throws InvalidKeyException,
InvalidAlgorithmParameterException
{
- if (!(key instanceof PBEKey))
+ if (! (key instanceof PBEKey))
throw new InvalidKeyException("not a PBE key");
-
super.engineInit(opmode, genkey((PBEKey) key), params, random);
}
@@ -107,9 +95,8 @@ public abstract class PBES2 extends CipherAdapter
SecureRandom random) throws InvalidKeyException,
InvalidAlgorithmParameterException
{
- if (!(key instanceof PBEKey))
+ if (! (key instanceof PBEKey))
throw new InvalidKeyException("not a PBE key");
-
super.engineInit(opmode, genkey((PBEKey) key), params, random);
}
@@ -117,11 +104,9 @@ public abstract class PBES2 extends CipherAdapter
{
IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName);
if (kdf == null)
- {
- throw new IllegalArgumentException("no such KDF: PBKDF2-" + macName);
- }
+ throw new IllegalArgumentException("no such KDF: PBKDF2-" + macName);
HashMap attrib = new HashMap();
- attrib.put(IPBE.ITERATION_COUNT, new Integer(key.getIterationCount()));
+ attrib.put(IPBE.ITERATION_COUNT, Integer.valueOf(key.getIterationCount()));
attrib.put(IPBE.PASSWORD, key.getPassword());
attrib.put(IPBE.SALT, key.getSalt());
try
@@ -139,21 +124,14 @@ public abstract class PBES2 extends CipherAdapter
}
catch (LimitReachedException shouldNotHappen)
{
- // throw new Error(shouldNotHappen);
throw new Error(String.valueOf(shouldNotHappen));
}
return new SecretKeySpec(dk, cipher.name());
}
- // Inner classe(s)
- // =========================================================================
-
- public static class HMacSHA1 extends PBES2
+ public static class HMacSHA1
+ extends PBES2
{
-
- // Constructor(s)
- // ---------------------------------------------------------------------
-
public HMacSHA1(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-SHA1");
@@ -164,10 +142,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-SHA1");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacSHA1
+ public static class AES
+ extends HMacSHA1
{
public AES()
{
@@ -175,7 +151,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacSHA1
+ public static class Anubis
+ extends HMacSHA1
{
public Anubis()
{
@@ -183,7 +160,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacSHA1
+ public static class Blowfish
+ extends HMacSHA1
{
public Blowfish()
{
@@ -191,7 +169,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacSHA1
+ public static class Cast5
+ extends HMacSHA1
{
public Cast5()
{
@@ -199,7 +178,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacSHA1
+ public static class DES
+ extends HMacSHA1
{
public DES()
{
@@ -207,7 +187,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacSHA1
+ public static class Khazad
+ extends HMacSHA1
{
public Khazad()
{
@@ -215,7 +196,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacSHA1
+ public static class Serpent
+ extends HMacSHA1
{
public Serpent()
{
@@ -223,7 +205,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacSHA1
+ public static class Square
+ extends HMacSHA1
{
public Square()
{
@@ -231,7 +214,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacSHA1
+ public static class TripleDES
+ extends HMacSHA1
{
public TripleDES()
{
@@ -239,7 +223,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacSHA1
+ public static class Twofish
+ extends HMacSHA1
{
public Twofish()
{
@@ -248,12 +233,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacMD5 extends PBES2
+ public static class HMacMD5
+ extends PBES2
{
-
- // Constructor(s)
- // ----------------------------------------------------------------------
-
public HMacMD5(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-MD5");
@@ -264,10 +246,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-MD5");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacMD5
+ public static class AES
+ extends HMacMD5
{
public AES()
{
@@ -275,7 +255,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacMD5
+ public static class Anubis
+ extends HMacMD5
{
public Anubis()
{
@@ -283,7 +264,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacMD5
+ public static class Blowfish
+ extends HMacMD5
{
public Blowfish()
{
@@ -291,7 +273,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacMD5
+ public static class Cast5
+ extends HMacMD5
{
public Cast5()
{
@@ -299,7 +282,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacMD5
+ public static class DES
+ extends HMacMD5
{
public DES()
{
@@ -307,7 +291,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacMD5
+ public static class Khazad
+ extends HMacMD5
{
public Khazad()
{
@@ -315,7 +300,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacMD5
+ public static class Serpent
+ extends HMacMD5
{
public Serpent()
{
@@ -323,7 +309,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacMD5
+ public static class Square
+ extends HMacMD5
{
public Square()
{
@@ -331,7 +318,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacMD5
+ public static class TripleDES
+ extends HMacMD5
{
public TripleDES()
{
@@ -339,7 +327,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacMD5
+ public static class Twofish
+ extends HMacMD5
{
public Twofish()
{
@@ -348,12 +337,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacMD2 extends PBES2
+ public static class HMacMD2
+ extends PBES2
{
-
- // Constructor(s)
- // ----------------------------------------------------------------------
-
public HMacMD2(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-MD2");
@@ -364,10 +350,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-MD2");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacMD2
+ public static class AES
+ extends HMacMD2
{
public AES()
{
@@ -375,7 +359,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacMD2
+ public static class Anubis
+ extends HMacMD2
{
public Anubis()
{
@@ -383,7 +368,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacMD2
+ public static class Blowfish
+ extends HMacMD2
{
public Blowfish()
{
@@ -391,7 +377,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacMD2
+ public static class Cast5
+ extends HMacMD2
{
public Cast5()
{
@@ -399,7 +386,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacMD2
+ public static class DES
+ extends HMacMD2
{
public DES()
{
@@ -407,7 +395,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacMD2
+ public static class Khazad
+ extends HMacMD2
{
public Khazad()
{
@@ -415,7 +404,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacMD2
+ public static class Serpent
+ extends HMacMD2
{
public Serpent()
{
@@ -423,7 +413,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacMD2
+ public static class Square
+ extends HMacMD2
{
public Square()
{
@@ -431,7 +422,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacMD2
+ public static class TripleDES
+ extends HMacMD2
{
public TripleDES()
{
@@ -439,7 +431,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacMD2
+ public static class Twofish
+ extends HMacMD2
{
public Twofish()
{
@@ -448,12 +441,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacMD4 extends PBES2
+ public static class HMacMD4
+ extends PBES2
{
-
- // Constructor(s)
- // ----------------------------------------------------------------------
-
public HMacMD4(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-MD4");
@@ -464,10 +454,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-MD4");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacMD4
+ public static class AES
+ extends HMacMD4
{
public AES()
{
@@ -475,7 +463,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacMD4
+ public static class Anubis
+ extends HMacMD4
{
public Anubis()
{
@@ -483,7 +472,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacMD4
+ public static class Blowfish
+ extends HMacMD4
{
public Blowfish()
{
@@ -491,7 +481,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacMD4
+ public static class Cast5
+ extends HMacMD4
{
public Cast5()
{
@@ -499,7 +490,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacMD4
+ public static class DES
+ extends HMacMD4
{
public DES()
{
@@ -507,7 +499,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacMD4
+ public static class Khazad
+ extends HMacMD4
{
public Khazad()
{
@@ -515,7 +508,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacMD4
+ public static class Serpent
+ extends HMacMD4
{
public Serpent()
{
@@ -523,7 +517,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacMD4
+ public static class Square
+ extends HMacMD4
{
public Square()
{
@@ -531,7 +526,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacMD4
+ public static class TripleDES
+ extends HMacMD4
{
public TripleDES()
{
@@ -539,7 +535,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacMD4
+ public static class Twofish
+ extends HMacMD4
{
public Twofish()
{
@@ -548,12 +545,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacHaval extends PBES2
+ public static class HMacHaval
+ extends PBES2
{
-
- // Constructor(s)
- // ---------------------------------------------------------------------
-
public HMacHaval(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-HAVAL");
@@ -564,10 +558,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-HAVAL");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacHaval
+ public static class AES
+ extends HMacHaval
{
public AES()
{
@@ -575,7 +567,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacHaval
+ public static class Anubis
+ extends HMacHaval
{
public Anubis()
{
@@ -583,7 +576,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacHaval
+ public static class Blowfish
+ extends HMacHaval
{
public Blowfish()
{
@@ -591,7 +585,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacHaval
+ public static class Cast5
+ extends HMacHaval
{
public Cast5()
{
@@ -599,7 +594,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacHaval
+ public static class DES
+ extends HMacHaval
{
public DES()
{
@@ -607,7 +603,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacHaval
+ public static class Khazad
+ extends HMacHaval
{
public Khazad()
{
@@ -615,7 +612,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacHaval
+ public static class Serpent
+ extends HMacHaval
{
public Serpent()
{
@@ -623,7 +621,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacHaval
+ public static class Square
+ extends HMacHaval
{
public Square()
{
@@ -631,7 +630,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacHaval
+ public static class TripleDES
+ extends HMacHaval
{
public TripleDES()
{
@@ -639,7 +639,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacHaval
+ public static class Twofish
+ extends HMacHaval
{
public Twofish()
{
@@ -648,12 +649,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacRipeMD128 extends PBES2
+ public static class HMacRipeMD128
+ extends PBES2
{
-
- // Constructor(s)
- // ----------------------------------------------------------------------
-
public HMacRipeMD128(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-RIPEMD128");
@@ -664,10 +662,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-RIPEMD128");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacRipeMD128
+ public static class AES
+ extends HMacRipeMD128
{
public AES()
{
@@ -675,7 +671,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacRipeMD128
+ public static class Anubis
+ extends HMacRipeMD128
{
public Anubis()
{
@@ -683,7 +680,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacRipeMD128
+ public static class Blowfish
+ extends HMacRipeMD128
{
public Blowfish()
{
@@ -691,7 +689,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacRipeMD128
+ public static class Cast5
+ extends HMacRipeMD128
{
public Cast5()
{
@@ -699,7 +698,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacRipeMD128
+ public static class DES
+ extends HMacRipeMD128
{
public DES()
{
@@ -707,7 +707,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacRipeMD128
+ public static class Khazad
+ extends HMacRipeMD128
{
public Khazad()
{
@@ -715,7 +716,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacRipeMD128
+ public static class Serpent
+ extends HMacRipeMD128
{
public Serpent()
{
@@ -723,7 +725,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacRipeMD128
+ public static class Square
+ extends HMacRipeMD128
{
public Square()
{
@@ -731,7 +734,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacRipeMD128
+ public static class TripleDES
+ extends HMacRipeMD128
{
public TripleDES()
{
@@ -739,7 +743,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacRipeMD128
+ public static class Twofish
+ extends HMacRipeMD128
{
public Twofish()
{
@@ -748,12 +753,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacRipeMD160 extends PBES2
+ public static class HMacRipeMD160
+ extends PBES2
{
-
- // Constructor(s)
- // ----------------------------------------------------------------------
-
public HMacRipeMD160(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-RIPEMD160");
@@ -764,10 +766,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-RIPEMD160");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacRipeMD160
+ public static class AES
+ extends HMacRipeMD160
{
public AES()
{
@@ -775,7 +775,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacRipeMD160
+ public static class Anubis
+ extends HMacRipeMD160
{
public Anubis()
{
@@ -783,7 +784,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacRipeMD160
+ public static class Blowfish
+ extends HMacRipeMD160
{
public Blowfish()
{
@@ -791,7 +793,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacRipeMD160
+ public static class Cast5
+ extends HMacRipeMD160
{
public Cast5()
{
@@ -799,7 +802,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacRipeMD160
+ public static class DES
+ extends HMacRipeMD160
{
public DES()
{
@@ -807,7 +811,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacRipeMD160
+ public static class Khazad
+ extends HMacRipeMD160
{
public Khazad()
{
@@ -815,7 +820,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacRipeMD160
+ public static class Serpent
+ extends HMacRipeMD160
{
public Serpent()
{
@@ -823,7 +829,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacRipeMD160
+ public static class Square
+ extends HMacRipeMD160
{
public Square()
{
@@ -831,7 +838,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacRipeMD160
+ public static class TripleDES
+ extends HMacRipeMD160
{
public TripleDES()
{
@@ -839,7 +847,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacRipeMD160
+ public static class Twofish
+ extends HMacRipeMD160
{
public Twofish()
{
@@ -848,12 +857,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacSHA256 extends PBES2
+ public static class HMacSHA256
+ extends PBES2
{
-
- // Constructor(s)
- // ---------------------------------------------------------------------
-
public HMacSHA256(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-SHA-256");
@@ -864,10 +870,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-SHA-256");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacSHA256
+ public static class AES
+ extends HMacSHA256
{
public AES()
{
@@ -875,7 +879,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacSHA256
+ public static class Anubis
+ extends HMacSHA256
{
public Anubis()
{
@@ -883,7 +888,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacSHA256
+ public static class Blowfish
+ extends HMacSHA256
{
public Blowfish()
{
@@ -891,7 +897,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacSHA256
+ public static class Cast5
+ extends HMacSHA256
{
public Cast5()
{
@@ -899,7 +906,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacSHA256
+ public static class DES
+ extends HMacSHA256
{
public DES()
{
@@ -907,7 +915,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacSHA256
+ public static class Khazad
+ extends HMacSHA256
{
public Khazad()
{
@@ -915,7 +924,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacSHA256
+ public static class Serpent
+ extends HMacSHA256
{
public Serpent()
{
@@ -923,7 +933,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacSHA256
+ public static class Square
+ extends HMacSHA256
{
public Square()
{
@@ -931,7 +942,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacSHA256
+ public static class TripleDES
+ extends HMacSHA256
{
public TripleDES()
{
@@ -939,7 +951,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacSHA256
+ public static class Twofish
+ extends HMacSHA256
{
public Twofish()
{
@@ -948,12 +961,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacSHA384 extends PBES2
+ public static class HMacSHA384
+ extends PBES2
{
-
- // Constructor(s)
- // ---------------------------------------------------------------------
-
public HMacSHA384(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-SHA-384");
@@ -964,10 +974,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-SHA-384");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacSHA384
+ public static class AES
+ extends HMacSHA384
{
public AES()
{
@@ -975,7 +983,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacSHA384
+ public static class Anubis
+ extends HMacSHA384
{
public Anubis()
{
@@ -983,7 +992,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacSHA384
+ public static class Blowfish
+ extends HMacSHA384
{
public Blowfish()
{
@@ -991,7 +1001,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacSHA384
+ public static class Cast5
+ extends HMacSHA384
{
public Cast5()
{
@@ -999,7 +1010,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacSHA384
+ public static class DES
+ extends HMacSHA384
{
public DES()
{
@@ -1007,7 +1019,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacSHA384
+ public static class Khazad
+ extends HMacSHA384
{
public Khazad()
{
@@ -1015,7 +1028,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacSHA384
+ public static class Serpent
+ extends HMacSHA384
{
public Serpent()
{
@@ -1023,7 +1037,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacSHA384
+ public static class Square
+ extends HMacSHA384
{
public Square()
{
@@ -1031,7 +1046,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacSHA384
+ public static class TripleDES
+ extends HMacSHA384
{
public TripleDES()
{
@@ -1039,7 +1055,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacSHA384
+ public static class Twofish
+ extends HMacSHA384
{
public Twofish()
{
@@ -1048,12 +1065,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacSHA512 extends PBES2
+ public static class HMacSHA512
+ extends PBES2
{
-
- // Constructor(s)
- // ---------------------------------------------------------------------
-
public HMacSHA512(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-SHA-512");
@@ -1064,10 +1078,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-SHA-512");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacSHA512
+ public static class AES
+ extends HMacSHA512
{
public AES()
{
@@ -1075,7 +1087,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacSHA512
+ public static class Anubis
+ extends HMacSHA512
{
public Anubis()
{
@@ -1083,7 +1096,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacSHA512
+ public static class Blowfish
+ extends HMacSHA512
{
public Blowfish()
{
@@ -1091,7 +1105,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacSHA512
+ public static class Cast5
+ extends HMacSHA512
{
public Cast5()
{
@@ -1099,7 +1114,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacSHA512
+ public static class DES
+ extends HMacSHA512
{
public DES()
{
@@ -1107,7 +1123,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacSHA512
+ public static class Khazad
+ extends HMacSHA512
{
public Khazad()
{
@@ -1115,7 +1132,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacSHA512
+ public static class Serpent
+ extends HMacSHA512
{
public Serpent()
{
@@ -1123,7 +1141,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacSHA512
+ public static class Square
+ extends HMacSHA512
{
public Square()
{
@@ -1131,7 +1150,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacSHA512
+ public static class TripleDES
+ extends HMacSHA512
{
public TripleDES()
{
@@ -1139,7 +1159,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacSHA512
+ public static class Twofish
+ extends HMacSHA512
{
public Twofish()
{
@@ -1148,12 +1169,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacTiger extends PBES2
+ public static class HMacTiger
+ extends PBES2
{
-
- // Constructor(s)
- // ---------------------------------------------------------------------
-
public HMacTiger(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-TIGER");
@@ -1164,10 +1182,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-TIGER");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacTiger
+ public static class AES
+ extends HMacTiger
{
public AES()
{
@@ -1175,7 +1191,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacTiger
+ public static class Anubis
+ extends HMacTiger
{
public Anubis()
{
@@ -1183,7 +1200,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacTiger
+ public static class Blowfish
+ extends HMacTiger
{
public Blowfish()
{
@@ -1191,7 +1209,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacTiger
+ public static class Cast5
+ extends HMacTiger
{
public Cast5()
{
@@ -1199,7 +1218,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacTiger
+ public static class DES
+ extends HMacTiger
{
public DES()
{
@@ -1207,7 +1227,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacTiger
+ public static class Khazad
+ extends HMacTiger
{
public Khazad()
{
@@ -1215,7 +1236,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacTiger
+ public static class Serpent
+ extends HMacTiger
{
public Serpent()
{
@@ -1223,7 +1245,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacTiger
+ public static class Square
+ extends HMacTiger
{
public Square()
{
@@ -1231,7 +1254,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacTiger
+ public static class TripleDES
+ extends HMacTiger
{
public TripleDES()
{
@@ -1239,7 +1263,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacTiger
+ public static class Twofish
+ extends HMacTiger
{
public Twofish()
{
@@ -1248,12 +1273,9 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class HMacWhirlpool extends PBES2
+ public static class HMacWhirlpool
+ extends PBES2
{
-
- // Constructor(s)
- // ----------------------------------------------------------------------
-
public HMacWhirlpool(String cipher, int blockLen)
{
super(cipher, blockLen, "HMAC-WHIRLPOOL");
@@ -1264,10 +1286,8 @@ public abstract class PBES2 extends CipherAdapter
super(cipher, "HMAC-WHIRLPOOL");
}
- // Inner classe(s)
- // ======================================================================
-
- public static class AES extends HMacWhirlpool
+ public static class AES
+ extends HMacWhirlpool
{
public AES()
{
@@ -1275,7 +1295,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Anubis extends HMacWhirlpool
+ public static class Anubis
+ extends HMacWhirlpool
{
public Anubis()
{
@@ -1283,7 +1304,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Blowfish extends HMacWhirlpool
+ public static class Blowfish
+ extends HMacWhirlpool
{
public Blowfish()
{
@@ -1291,7 +1313,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Cast5 extends HMacWhirlpool
+ public static class Cast5
+ extends HMacWhirlpool
{
public Cast5()
{
@@ -1299,7 +1322,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class DES extends HMacWhirlpool
+ public static class DES
+ extends HMacWhirlpool
{
public DES()
{
@@ -1307,7 +1331,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Khazad extends HMacWhirlpool
+ public static class Khazad
+ extends HMacWhirlpool
{
public Khazad()
{
@@ -1315,7 +1340,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Serpent extends HMacWhirlpool
+ public static class Serpent
+ extends HMacWhirlpool
{
public Serpent()
{
@@ -1323,7 +1349,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Square extends HMacWhirlpool
+ public static class Square
+ extends HMacWhirlpool
{
public Square()
{
@@ -1331,7 +1358,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class TripleDES extends HMacWhirlpool
+ public static class TripleDES
+ extends HMacWhirlpool
{
public TripleDES()
{
@@ -1339,7 +1367,8 @@ public abstract class PBES2 extends CipherAdapter
}
}
- public static class Twofish extends HMacWhirlpool
+ public static class Twofish
+ extends HMacWhirlpool
{
public Twofish()
{
diff --git a/gnu/javax/crypto/jce/cipher/RijndaelSpi.java b/gnu/javax/crypto/jce/cipher/RijndaelSpi.java
index 137db2c3f..ad61bca59 100644
--- a/gnu/javax/crypto/jce/cipher/RijndaelSpi.java
+++ b/gnu/javax/crypto/jce/cipher/RijndaelSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Rijndael <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class RijndaelSpi extends CipherAdapter
+public final class RijndaelSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public RijndaelSpi()
{
super(Registry.RIJNDAEL_CIPHER, 16);
diff --git a/gnu/javax/crypto/jce/cipher/SerpentSpi.java b/gnu/javax/crypto/jce/cipher/SerpentSpi.java
index 9df9685cc..fa65d34a9 100644
--- a/gnu/javax/crypto/jce/cipher/SerpentSpi.java
+++ b/gnu/javax/crypto/jce/cipher/SerpentSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Serpent <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class SerpentSpi extends CipherAdapter
+public final class SerpentSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public SerpentSpi()
{
super(Registry.SERPENT_CIPHER);
diff --git a/gnu/javax/crypto/jce/cipher/SquareSpi.java b/gnu/javax/crypto/jce/cipher/SquareSpi.java
index 96e5dee38..bdc656eae 100644
--- a/gnu/javax/crypto/jce/cipher/SquareSpi.java
+++ b/gnu/javax/crypto/jce/cipher/SquareSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Square <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class SquareSpi extends CipherAdapter
+public final class SquareSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public SquareSpi()
{
super(Registry.SQUARE_CIPHER);
diff --git a/gnu/javax/crypto/jce/cipher/TripleDESSpi.java b/gnu/javax/crypto/jce/cipher/TripleDESSpi.java
index 5c58ea551..b9ec12b51 100644
--- a/gnu/javax/crypto/jce/cipher/TripleDESSpi.java
+++ b/gnu/javax/crypto/jce/cipher/TripleDESSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Triple-DES <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class TripleDESSpi extends CipherAdapter
+public final class TripleDESSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public TripleDESSpi()
{
super(Registry.TRIPLEDES_CIPHER);
diff --git a/gnu/javax/crypto/jce/cipher/TwofishSpi.java b/gnu/javax/crypto/jce/cipher/TwofishSpi.java
index 31df5ea40..206e0d9f8 100644
--- a/gnu/javax/crypto/jce/cipher/TwofishSpi.java
+++ b/gnu/javax/crypto/jce/cipher/TwofishSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Twofish <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class TwofishSpi extends CipherAdapter
+public final class TwofishSpi
+ extends CipherAdapter
{
-
- // Constructors.
- // --------------------------------------------------------------------
-
public TwofishSpi()
{
super(Registry.TWOFISH_CIPHER);
diff --git a/gnu/javax/crypto/jce/key/AnubisKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/AnubisKeyGeneratorImpl.java
index e8d7788e8..a1cc8fd7f 100644
--- a/gnu/javax/crypto/jce/key/AnubisKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/AnubisKeyGeneratorImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class AnubisKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class AnubisKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public AnubisKeyGeneratorImpl ()
+ public AnubisKeyGeneratorImpl()
{
- super (Registry.ANUBIS_CIPHER);
+ super(Registry.ANUBIS_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/AnubisSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/AnubisSecretKeyFactoryImpl.java
index 6442cd696..bea65a6c6 100644
--- a/gnu/javax/crypto/jce/key/AnubisSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/AnubisSecretKeyFactoryImpl.java
@@ -38,7 +38,8 @@ exception statement from your version. */
package gnu.javax.crypto.jce.key;
-public class AnubisSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class AnubisSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public AnubisSecretKeyFactoryImpl()
{
diff --git a/gnu/javax/crypto/jce/key/BlowfishKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/BlowfishKeyGeneratorImpl.java
index a0e687acd..2297980fb 100644
--- a/gnu/javax/crypto/jce/key/BlowfishKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/BlowfishKeyGeneratorImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class BlowfishKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class BlowfishKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public BlowfishKeyGeneratorImpl ()
+ public BlowfishKeyGeneratorImpl()
{
- super (Registry.BLOWFISH_CIPHER);
+ super(Registry.BLOWFISH_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/BlowfishSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/BlowfishSecretKeyFactoryImpl.java
index 91f97af36..53fe8b0b4 100644
--- a/gnu/javax/crypto/jce/key/BlowfishSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/BlowfishSecretKeyFactoryImpl.java
@@ -38,7 +38,8 @@ exception statement from your version. */
package gnu.javax.crypto.jce.key;
-public class BlowfishSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class BlowfishSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public BlowfishSecretKeyFactoryImpl()
{
diff --git a/gnu/javax/crypto/jce/key/Cast5KeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/Cast5KeyGeneratorImpl.java
index 18d26e67f..b328e48b3 100644
--- a/gnu/javax/crypto/jce/key/Cast5KeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/Cast5KeyGeneratorImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class Cast5KeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class Cast5KeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public Cast5KeyGeneratorImpl ()
+ public Cast5KeyGeneratorImpl()
{
- super (Registry.CAST5_CIPHER);
+ super(Registry.CAST5_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/Cast5SecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/Cast5SecretKeyFactoryImpl.java
index 048b54474..fcebb528e 100644
--- a/gnu/javax/crypto/jce/key/Cast5SecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/Cast5SecretKeyFactoryImpl.java
@@ -38,7 +38,8 @@ exception statement from your version. */
package gnu.javax.crypto.jce.key;
-public class Cast5SecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class Cast5SecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public Cast5SecretKeyFactoryImpl()
{
diff --git a/gnu/javax/crypto/jce/key/DESKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/DESKeyGeneratorImpl.java
index 19c54653a..2cd29a67f 100644
--- a/gnu/javax/crypto/jce/key/DESKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/DESKeyGeneratorImpl.java
@@ -35,6 +35,7 @@ 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.javax.crypto.jce.key;
import gnu.java.security.Registry;
@@ -43,31 +44,25 @@ import gnu.javax.crypto.cipher.DES;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
-public class DESKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class DESKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public DESKeyGeneratorImpl ()
+ public DESKeyGeneratorImpl()
{
- super (Registry.DES_CIPHER);
+ super(Registry.DES_CIPHER);
}
- // Instance methods.
- // -------------------------------------------------------------------------
-
- protected SecretKey engineGenerateKey ()
+ protected SecretKey engineGenerateKey()
{
- if (!init)
- throw new IllegalStateException ("not initialized");
- byte[] buf = new byte [currentKeySize];
+ if (! init)
+ throw new IllegalStateException("not initialized");
+ byte[] buf = new byte[currentKeySize];
do
{
- random.nextBytes (buf);
+ random.nextBytes(buf);
}
- while (DES.isWeak (buf) || DES.isSemiWeak (buf));
- DES.adjustParity (buf, 0);
- return new SecretKeySpec (buf, algorithm);
+ while (DES.isWeak(buf) || DES.isSemiWeak(buf));
+ DES.adjustParity(buf, 0);
+ return new SecretKeySpec(buf, algorithm);
}
}
diff --git a/gnu/javax/crypto/jce/key/DESSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/DESSecretKeyFactoryImpl.java
index e0f1c5860..a138e2902 100644
--- a/gnu/javax/crypto/jce/key/DESSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/DESSecretKeyFactoryImpl.java
@@ -35,6 +35,7 @@ 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.javax.crypto.jce.key;
import java.security.InvalidKeyException;
@@ -45,36 +46,37 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.SecretKeySpec;
-public class DESSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class DESSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public DESSecretKeyFactoryImpl()
{
}
- protected SecretKey engineGenerateSecret (KeySpec spec)
- throws InvalidKeySpecException
+ protected SecretKey engineGenerateSecret(KeySpec spec)
+ throws InvalidKeySpecException
{
if (spec instanceof DESKeySpec)
- return new SecretKeySpec (((DESKeySpec) spec).getKey(), "DES");
- return super.engineGenerateSecret (spec);
+ return new SecretKeySpec(((DESKeySpec) spec).getKey(), "DES");
+ return super.engineGenerateSecret(spec);
}
- protected KeySpec engineGetKeySpec (SecretKey key, Class spec)
- throws InvalidKeySpecException
+ protected KeySpec engineGetKeySpec(SecretKey key, Class spec)
+ throws InvalidKeySpecException
{
- if (spec.isAssignableFrom (DESKeySpec.class))
+ if (spec.isAssignableFrom(DESKeySpec.class))
try
{
- return new DESKeySpec (key.getEncoded());
+ return new DESKeySpec(key.getEncoded());
}
catch (InvalidKeyException ike)
{
- InvalidKeySpecException ikse = new InvalidKeySpecException
- ("can't create DES key spec");
- ikse.initCause (ike);
+ InvalidKeySpecException ikse = new InvalidKeySpecException(
+ "can't create DES key spec");
+ ikse.initCause(ike);
throw ikse;
}
- return super.engineGetKeySpec (key, spec);
+ return super.engineGetKeySpec(key, spec);
}
}
diff --git a/gnu/javax/crypto/jce/key/DESedeSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/DESedeSecretKeyFactoryImpl.java
index 15e109940..f380603e4 100644
--- a/gnu/javax/crypto/jce/key/DESedeSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/DESedeSecretKeyFactoryImpl.java
@@ -35,6 +35,7 @@ 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.javax.crypto.jce.key;
import java.security.InvalidKeyException;
@@ -45,36 +46,37 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.SecretKeySpec;
-public class DESedeSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class DESedeSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public DESedeSecretKeyFactoryImpl()
{
}
- protected SecretKey engineGenerateSecret (KeySpec spec)
- throws InvalidKeySpecException
+ protected SecretKey engineGenerateSecret(KeySpec spec)
+ throws InvalidKeySpecException
{
if (spec instanceof DESedeKeySpec)
- return new SecretKeySpec (((DESedeKeySpec) spec).getKey(), "DESede");
- return super.engineGenerateSecret (spec);
+ return new SecretKeySpec(((DESedeKeySpec) spec).getKey(), "DESede");
+ return super.engineGenerateSecret(spec);
}
- protected KeySpec engineGetKeySpec (SecretKey key, Class spec)
- throws InvalidKeySpecException
+ protected KeySpec engineGetKeySpec(SecretKey key, Class spec)
+ throws InvalidKeySpecException
{
- if (spec.equals (DESedeKeySpec.class))
+ if (spec.equals(DESedeKeySpec.class))
try
{
- return new DESedeKeySpec (key.getEncoded());
+ return new DESedeKeySpec(key.getEncoded());
}
catch (InvalidKeyException ike)
{
- InvalidKeySpecException ikse = new InvalidKeySpecException
- ("can't create DESede key spec");
- ikse.initCause (ike);
+ InvalidKeySpecException ikse = new InvalidKeySpecException(
+ "can't create DESede key spec");
+ ikse.initCause(ike);
throw ikse;
}
- return super.engineGetKeySpec (key, spec);
+ return super.engineGetKeySpec(key, spec);
}
}
diff --git a/gnu/javax/crypto/jce/key/KhazadKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/KhazadKeyGeneratorImpl.java
index c01391e44..21ae627eb 100644
--- a/gnu/javax/crypto/jce/key/KhazadKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/KhazadKeyGeneratorImpl.java
@@ -35,18 +35,16 @@ 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.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class KhazadKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class KhazadKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public KhazadKeyGeneratorImpl ()
+ public KhazadKeyGeneratorImpl()
{
- super (Registry.KHAZAD_CIPHER);
+ super(Registry.KHAZAD_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/KhazadSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/KhazadSecretKeyFactoryImpl.java
index 6c7ab42f7..19315d22e 100644
--- a/gnu/javax/crypto/jce/key/KhazadSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/KhazadSecretKeyFactoryImpl.java
@@ -35,9 +35,11 @@ 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.javax.crypto.jce.key;
-public class KhazadSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class KhazadSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public KhazadSecretKeyFactoryImpl()
{
diff --git a/gnu/javax/crypto/jce/key/RijndaelKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/RijndaelKeyGeneratorImpl.java
index 535e573ad..b60f7d6d0 100644
--- a/gnu/javax/crypto/jce/key/RijndaelKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/RijndaelKeyGeneratorImpl.java
@@ -35,18 +35,16 @@ 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.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class RijndaelKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class RijndaelKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public RijndaelKeyGeneratorImpl ()
+ public RijndaelKeyGeneratorImpl()
{
- super (Registry.RIJNDAEL_CIPHER);
+ super(Registry.RIJNDAEL_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/RijndaelSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/RijndaelSecretKeyFactoryImpl.java
index d46191644..f88b07752 100644
--- a/gnu/javax/crypto/jce/key/RijndaelSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/RijndaelSecretKeyFactoryImpl.java
@@ -35,9 +35,11 @@ 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.javax.crypto.jce.key;
-public class RijndaelSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class RijndaelSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public RijndaelSecretKeyFactoryImpl()
{
diff --git a/gnu/javax/crypto/jce/key/SecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/SecretKeyFactoryImpl.java
index 72defe1d7..4bba171f9 100644
--- a/gnu/javax/crypto/jce/key/SecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/SecretKeyFactoryImpl.java
@@ -35,6 +35,7 @@ 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.javax.crypto.jce.key;
import java.security.InvalidKeyException;
@@ -45,43 +46,42 @@ import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactorySpi;
import javax.crypto.spec.SecretKeySpec;
-public abstract class SecretKeyFactoryImpl extends SecretKeyFactorySpi
+public abstract class SecretKeyFactoryImpl
+ extends SecretKeyFactorySpi
{
protected SecretKeyFactoryImpl()
{
}
- protected SecretKey engineGenerateSecret (KeySpec spec)
- throws InvalidKeySpecException
+ protected SecretKey engineGenerateSecret(KeySpec spec)
+ throws InvalidKeySpecException
{
if (spec instanceof SecretKeySpec)
return (SecretKey) spec;
- throw new InvalidKeySpecException ("unknown key spec: " +
- spec.getClass().getName());
+ throw new InvalidKeySpecException("unknown key spec: "
+ + spec.getClass().getName());
}
- protected KeySpec engineGetKeySpec (SecretKey key, Class spec)
- throws InvalidKeySpecException
+ protected KeySpec engineGetKeySpec(SecretKey key, Class spec)
+ throws InvalidKeySpecException
{
- if (spec.equals (SecretKeySpec.class))
+ if (spec.equals(SecretKeySpec.class))
{
if (key instanceof SecretKeySpec)
return (KeySpec) key;
else
- return new SecretKeySpec (key.getEncoded(), key.getAlgorithm());
+ return new SecretKeySpec(key.getEncoded(), key.getAlgorithm());
}
- throw new InvalidKeySpecException ("unsupported key spec: " +
- spec.getName());
+ throw new InvalidKeySpecException("unsupported key spec: " + spec.getName());
}
- protected SecretKey engineTranslateKey (SecretKey key)
- throws InvalidKeyException
+ protected SecretKey engineTranslateKey(SecretKey key)
+ throws InvalidKeyException
{
- if (!"RAW".equals (key.getFormat()))
- throw new InvalidKeyException ("only raw keys are supported");
-
+ if (! "RAW".equals(key.getFormat()))
+ throw new InvalidKeyException("only raw keys are supported");
// SecretKeySpec is good enough for our purposes.
- return new SecretKeySpec (key.getEncoded(), key.getAlgorithm());
+ return new SecretKeySpec(key.getEncoded(), key.getAlgorithm());
}
}
diff --git a/gnu/javax/crypto/jce/key/SecretKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/SecretKeyGeneratorImpl.java
index 0a6265573..319b0eaeb 100644
--- a/gnu/javax/crypto/jce/key/SecretKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/SecretKeyGeneratorImpl.java
@@ -35,6 +35,7 @@ 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.javax.crypto.jce.key;
import gnu.javax.crypto.cipher.CipherFactory;
@@ -53,12 +54,9 @@ import javax.crypto.KeyGeneratorSpi;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
-public class SecretKeyGeneratorImpl extends KeyGeneratorSpi
+public class SecretKeyGeneratorImpl
+ extends KeyGeneratorSpi
{
-
- // Fields.
- // -------------------------------------------------------------------------
-
protected final int defaultKeySize;
protected final List keySizes;
protected final String algorithm;
@@ -66,55 +64,47 @@ public class SecretKeyGeneratorImpl extends KeyGeneratorSpi
protected int currentKeySize;
protected SecureRandom random;
- // Constructors.
- // -------------------------------------------------------------------------
-
- protected SecretKeyGeneratorImpl (final String algorithm)
+ protected SecretKeyGeneratorImpl(final String algorithm)
{
this.algorithm = algorithm;
- IBlockCipher cipher = CipherFactory.getInstance (algorithm);
+ IBlockCipher cipher = CipherFactory.getInstance(algorithm);
if (cipher == null)
- throw new IllegalArgumentException ("no such cipher: "+algorithm);
- defaultKeySize = cipher.defaultKeySize ();
+ throw new IllegalArgumentException("no such cipher: " + algorithm);
+ defaultKeySize = cipher.defaultKeySize();
keySizes = new LinkedList();
- for (Iterator it = cipher.keySizes (); it.hasNext (); )
- {
- keySizes.add (it.next ());
- }
+ for (Iterator it = cipher.keySizes(); it.hasNext();)
+ keySizes.add(it.next());
init = false;
}
- // Instance methods.
- // -------------------------------------------------------------------------
-
- protected SecretKey engineGenerateKey ()
+ protected SecretKey engineGenerateKey()
{
- if (!init)
- throw new IllegalStateException ("not initialized");
- byte[] buf = new byte [currentKeySize];
- random.nextBytes (buf);
- return new SecretKeySpec (buf, algorithm);
+ if (! init)
+ throw new IllegalStateException("not initialized");
+ byte[] buf = new byte[currentKeySize];
+ random.nextBytes(buf);
+ return new SecretKeySpec(buf, algorithm);
}
- protected void engineInit (AlgorithmParameterSpec params, SecureRandom random)
- throws InvalidAlgorithmParameterException
+ protected void engineInit(AlgorithmParameterSpec params, SecureRandom random)
+ throws InvalidAlgorithmParameterException
{
- throw new InvalidAlgorithmParameterException (algorithm +
- " does not support algorithm paramaters");
+ throw new InvalidAlgorithmParameterException(
+ algorithm + " does not support algorithm paramaters");
}
- protected void engineInit (int keySize, SecureRandom random)
+ protected void engineInit(int keySize, SecureRandom random)
{
keySize >>>= 3; // Use bytes.
- if (!keySizes.contains (new Integer (keySize)))
- throw new InvalidParameterException ("unsupported key size: " + keySize);
+ if (! keySizes.contains(Integer.valueOf(keySize)))
+ throw new InvalidParameterException("unsupported key size: " + keySize);
currentKeySize = keySize;
this.random = random;
init = true;
}
- protected void engineInit (SecureRandom random)
+ protected void engineInit(SecureRandom random)
{
- engineInit (defaultKeySize << 3, random);
+ engineInit(defaultKeySize << 3, random);
}
}
diff --git a/gnu/javax/crypto/jce/key/SerpentKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/SerpentKeyGeneratorImpl.java
index 766860a96..c53190514 100644
--- a/gnu/javax/crypto/jce/key/SerpentKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/SerpentKeyGeneratorImpl.java
@@ -35,18 +35,16 @@ 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.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class SerpentKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class SerpentKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public SerpentKeyGeneratorImpl ()
+ public SerpentKeyGeneratorImpl()
{
- super (Registry.SERPENT_CIPHER);
+ super(Registry.SERPENT_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/SerpentSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/SerpentSecretKeyFactoryImpl.java
index 9f06bf329..5d5ac88df 100644
--- a/gnu/javax/crypto/jce/key/SerpentSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/SerpentSecretKeyFactoryImpl.java
@@ -35,9 +35,11 @@ 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.javax.crypto.jce.key;
-public class SerpentSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class SerpentSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public SerpentSecretKeyFactoryImpl()
{
diff --git a/gnu/javax/crypto/jce/key/SquareKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/SquareKeyGeneratorImpl.java
index 4bfbeb668..3d496e8a9 100644
--- a/gnu/javax/crypto/jce/key/SquareKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/SquareKeyGeneratorImpl.java
@@ -35,18 +35,16 @@ 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.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class SquareKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class SquareKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public SquareKeyGeneratorImpl ()
+ public SquareKeyGeneratorImpl()
{
- super (Registry.SQUARE_CIPHER);
+ super(Registry.SQUARE_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/SquareSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/SquareSecretKeyFactoryImpl.java
index fce7375b3..f35835912 100644
--- a/gnu/javax/crypto/jce/key/SquareSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/SquareSecretKeyFactoryImpl.java
@@ -35,9 +35,11 @@ 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.javax.crypto.jce.key;
-public class SquareSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class SquareSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public SquareSecretKeyFactoryImpl()
{
diff --git a/gnu/javax/crypto/jce/key/TripleDESKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/TripleDESKeyGeneratorImpl.java
index eb423fcd1..6fd557ccb 100644
--- a/gnu/javax/crypto/jce/key/TripleDESKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/TripleDESKeyGeneratorImpl.java
@@ -35,18 +35,16 @@ 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.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class TripleDESKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class TripleDESKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public TripleDESKeyGeneratorImpl ()
+ public TripleDESKeyGeneratorImpl()
{
- super (Registry.TRIPLEDES_CIPHER);
+ super(Registry.TRIPLEDES_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/TwofishKeyGeneratorImpl.java b/gnu/javax/crypto/jce/key/TwofishKeyGeneratorImpl.java
index ae7e22fee..9dd5a8f30 100644
--- a/gnu/javax/crypto/jce/key/TwofishKeyGeneratorImpl.java
+++ b/gnu/javax/crypto/jce/key/TwofishKeyGeneratorImpl.java
@@ -35,18 +35,16 @@ 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.javax.crypto.jce.key;
import gnu.java.security.Registry;
-public class TwofishKeyGeneratorImpl extends SecretKeyGeneratorImpl
+public class TwofishKeyGeneratorImpl
+ extends SecretKeyGeneratorImpl
{
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- public TwofishKeyGeneratorImpl ()
+ public TwofishKeyGeneratorImpl()
{
- super (Registry.TWOFISH_CIPHER);
+ super(Registry.TWOFISH_CIPHER);
}
}
diff --git a/gnu/javax/crypto/jce/key/TwofishSecretKeyFactoryImpl.java b/gnu/javax/crypto/jce/key/TwofishSecretKeyFactoryImpl.java
index a182d4116..0767d4cac 100644
--- a/gnu/javax/crypto/jce/key/TwofishSecretKeyFactoryImpl.java
+++ b/gnu/javax/crypto/jce/key/TwofishSecretKeyFactoryImpl.java
@@ -35,9 +35,11 @@ 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.javax.crypto.jce.key;
-public class TwofishSecretKeyFactoryImpl extends SecretKeyFactoryImpl
+public class TwofishSecretKeyFactoryImpl
+ extends SecretKeyFactoryImpl
{
public TwofishSecretKeyFactoryImpl()
{
diff --git a/gnu/javax/crypto/jce/keyring/GnuKeyring.java b/gnu/javax/crypto/jce/keyring/GnuKeyring.java
index ba89912f3..4fcf2fde7 100644
--- a/gnu/javax/crypto/jce/keyring/GnuKeyring.java
+++ b/gnu/javax/crypto/jce/keyring/GnuKeyring.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.jce.keyring;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.javax.crypto.keyring.GnuPrivateKeyring;
import gnu.javax.crypto.keyring.GnuPublicKeyring;
@@ -419,8 +419,9 @@ public class GnuKeyring
int usage = in.read();
in.reset();
if (usage != GnuPrivateKeyring.USAGE)
- throw new MalformedKeyringException("Was expecting a private keyring but got a wrong USAGE: "
- + Integer.toBinaryString(usage));
+ throw new MalformedKeyringException(
+ "Was expecting a private keyring but got a wrong USAGE: "
+ + Integer.toBinaryString(usage));
HashMap attr = new HashMap();
attr.put(IKeyring.KEYRING_DATA_IN, in);
attr.put(IKeyring.KEYRING_PASSWORD, password);
@@ -451,8 +452,9 @@ public class GnuKeyring
int usage = in.read();
in.reset();
if (usage != GnuPublicKeyring.USAGE)
- throw new MalformedKeyringException("Was expecting a public keyring but got a wrong USAGE: "
- + Integer.toBinaryString(usage));
+ throw new MalformedKeyringException(
+ "Was expecting a public keyring but got a wrong USAGE: "
+ + Integer.toBinaryString(usage));
HashMap attr = new HashMap();
attr.put(IKeyring.KEYRING_DATA_IN, in);
attr.put(IKeyring.KEYRING_PASSWORD, password);
diff --git a/gnu/javax/crypto/jce/mac/HMacHavalSpi.java b/gnu/javax/crypto/jce/mac/HMacHavalSpi.java
index df1319cbf..2967ee900 100644
--- a/gnu/javax/crypto/jce/mac/HMacHavalSpi.java
+++ b/gnu/javax/crypto/jce/mac/HMacHavalSpi.java
@@ -37,31 +37,18 @@ exception statement from your version. */
package gnu.javax.crypto.jce.mac;
+
import gnu.java.security.Registry;
/**
* The implementation of the HMAC-HAVAL <i>Service Provider Interface</i>
* (<b>SPI</b>) Adapter.
- *
- * @version Revision: $
*/
-public class HMacHavalSpi extends MacAdapter
+public class HMacHavalSpi
+ extends MacAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public HMacHavalSpi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.HAVAL_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/HMacMD2Spi.java b/gnu/javax/crypto/jce/mac/HMacMD2Spi.java
index dd489639f..dd6485866 100644
--- a/gnu/javax/crypto/jce/mac/HMacMD2Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacMD2Spi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the HMAC-MD2 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class HMacMD2Spi extends MacAdapter
+public final class HMacMD2Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public HMacMD2Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.MD2_HASH);
diff --git a/gnu/javax/crypto/jce/mac/HMacMD4Spi.java b/gnu/javax/crypto/jce/mac/HMacMD4Spi.java
index 6fadf0262..939851ff5 100644
--- a/gnu/javax/crypto/jce/mac/HMacMD4Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacMD4Spi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the HMAC-MD4 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class HMacMD4Spi extends MacAdapter
+public final class HMacMD4Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public HMacMD4Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.MD4_HASH);
diff --git a/gnu/javax/crypto/jce/mac/HMacMD5Spi.java b/gnu/javax/crypto/jce/mac/HMacMD5Spi.java
index 2ef43974f..e89fbfdba 100644
--- a/gnu/javax/crypto/jce/mac/HMacMD5Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacMD5Spi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the HMAC-MD5 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class HMacMD5Spi extends MacAdapter
+public final class HMacMD5Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public HMacMD5Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.MD5_HASH);
diff --git a/gnu/javax/crypto/jce/mac/HMacRipeMD128Spi.java b/gnu/javax/crypto/jce/mac/HMacRipeMD128Spi.java
index ad7a2340e..834ec849a 100644
--- a/gnu/javax/crypto/jce/mac/HMacRipeMD128Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacRipeMD128Spi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the HMAC-RIPEMD-128 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class HMacRipeMD128Spi extends MacAdapter
+public final class HMacRipeMD128Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public HMacRipeMD128Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.RIPEMD128_HASH);
diff --git a/gnu/javax/crypto/jce/mac/HMacRipeMD160Spi.java b/gnu/javax/crypto/jce/mac/HMacRipeMD160Spi.java
index c14e3b3bf..b973ea186 100644
--- a/gnu/javax/crypto/jce/mac/HMacRipeMD160Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacRipeMD160Spi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the HMAC-RIPEMD-160 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class HMacRipeMD160Spi extends MacAdapter
+public final class HMacRipeMD160Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public HMacRipeMD160Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.RIPEMD160_HASH);
diff --git a/gnu/javax/crypto/jce/mac/HMacSHA160Spi.java b/gnu/javax/crypto/jce/mac/HMacSHA160Spi.java
index f102c9ebc..524aa8233 100644
--- a/gnu/javax/crypto/jce/mac/HMacSHA160Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacSHA160Spi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the HMAC-SHA-160 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class HMacSHA160Spi extends MacAdapter
+public final class HMacSHA160Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public HMacSHA160Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.SHA160_HASH);
diff --git a/gnu/javax/crypto/jce/mac/HMacSHA256Spi.java b/gnu/javax/crypto/jce/mac/HMacSHA256Spi.java
index cadad1cf5..4b0493bc6 100644
--- a/gnu/javax/crypto/jce/mac/HMacSHA256Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacSHA256Spi.java
@@ -37,29 +37,18 @@ exception statement from your version. */
package gnu.javax.crypto.jce.mac;
+
import gnu.java.security.Registry;
/**
- * <p>The implementation of the HMAC-SHA-256 <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the HMAC-SHA-256 <i>Service Provider Interface</i>
+ * (<b>SPI</b>) adapter.
*/
-public final class HMacSHA256Spi extends MacAdapter
+public final class HMacSHA256Spi
+ extends MacAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -----------------------------------------------------------------------
-
public HMacSHA256Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.SHA256_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/javax/crypto/jce/mac/HMacSHA384Spi.java b/gnu/javax/crypto/jce/mac/HMacSHA384Spi.java
index 69ef38e50..92a5c9d2c 100644
--- a/gnu/javax/crypto/jce/mac/HMacSHA384Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacSHA384Spi.java
@@ -37,29 +37,18 @@ exception statement from your version. */
package gnu.javax.crypto.jce.mac;
+
import gnu.java.security.Registry;
/**
- * <p>The implementation of the HMAC-SHA-384 <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the HMAC-SHA-384 <i>Service Provider Interface</i>
+ * (<b>SPI</b>) adapter.
*/
-public class HMacSHA384Spi extends MacAdapter
+public class HMacSHA384Spi
+ extends MacAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -----------------------------------------------------------------------
-
public HMacSHA384Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.SHA384_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/javax/crypto/jce/mac/HMacSHA512Spi.java b/gnu/javax/crypto/jce/mac/HMacSHA512Spi.java
index abceb4a92..f1ecd02e5 100644
--- a/gnu/javax/crypto/jce/mac/HMacSHA512Spi.java
+++ b/gnu/javax/crypto/jce/mac/HMacSHA512Spi.java
@@ -37,29 +37,18 @@ exception statement from your version. */
package gnu.javax.crypto.jce.mac;
+
import gnu.java.security.Registry;
/**
- * <p>The implementation of the HMAC-SHA-512 <i>Service Provider Interface</i>
- * (<b>SPI</b>) adapter.</p>
+ * The implementation of the HMAC-SHA-512 <i>Service Provider Interface</i>
+ * (<b>SPI</b>) adapter.
*/
-public class HMacSHA512Spi extends MacAdapter
+public class HMacSHA512Spi
+ extends MacAdapter
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -----------------------------------------------------------------------
-
public HMacSHA512Spi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.SHA512_HASH);
}
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/javax/crypto/jce/mac/HMacTigerSpi.java b/gnu/javax/crypto/jce/mac/HMacTigerSpi.java
index 511993ea4..2d417ef4c 100644
--- a/gnu/javax/crypto/jce/mac/HMacTigerSpi.java
+++ b/gnu/javax/crypto/jce/mac/HMacTigerSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the Tiger <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class HMacTigerSpi extends MacAdapter
+public final class HMacTigerSpi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public HMacTigerSpi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.TIGER_HASH);
diff --git a/gnu/javax/crypto/jce/mac/HMacWhirlpoolSpi.java b/gnu/javax/crypto/jce/mac/HMacWhirlpoolSpi.java
index 706e0cd5a..1b936d71a 100644
--- a/gnu/javax/crypto/jce/mac/HMacWhirlpoolSpi.java
+++ b/gnu/javax/crypto/jce/mac/HMacWhirlpoolSpi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the HMAC-Whirlpool <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class HMacWhirlpoolSpi extends MacAdapter
+public final class HMacWhirlpoolSpi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public HMacWhirlpoolSpi()
{
super(Registry.HMAC_NAME_PREFIX + Registry.WHIRLPOOL_HASH);
diff --git a/gnu/javax/crypto/jce/mac/MacAdapter.java b/gnu/javax/crypto/jce/mac/MacAdapter.java
index dc019ca20..d8c800ac7 100644
--- a/gnu/javax/crypto/jce/mac/MacAdapter.java
+++ b/gnu/javax/crypto/jce/mac/MacAdapter.java
@@ -50,32 +50,26 @@ import java.util.Map;
import javax.crypto.MacSpi;
/**
- * <p>The implementation of a generic {@link javax.crypto.Mac} adapter class
- * to wrap GNU Crypto MAC instances.</p>
- *
- * <p>This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
+ * The implementation of a generic {@link javax.crypto.Mac} adapter class to
+ * wrap GNU MAC instances.
+ * <p>
+ * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
* the {@link javax.crypto.Mac} class, which provides the functionality of a
* message authentication code algorithm, such as the <i>Hashed Message
- * Authentication Code</i> (<b>HMAC</b>) algorithms.</p>
+ * Authentication Code</i> (<b>HMAC</b>) algorithms.
*/
-class MacAdapter extends MacSpi implements Cloneable
+class MacAdapter
+ extends MacSpi
+ implements Cloneable
{
-
- // Constants and variables
- // -----------------------------------------------------------------------
-
/** Our MAC instance. */
protected IMac mac;
-
/** Our MAC attributes. */
protected Map attributes;
- // Constructor(s)
- // -----------------------------------------------------------------------
-
/**
- * <p>Creates a new Mac instance for the given name.</p>
- *
+ * Creates a new Mac instance for the given name.
+ *
* @param name The name of the mac to create.
*/
protected MacAdapter(String name)
@@ -88,7 +82,7 @@ class MacAdapter extends MacSpi implements Cloneable
* Private constructor for cloning purposes.
*
* @param mac a clone of the internal {@link IMac} instance.
- * @param attributes a clone of the current {@link Map} of attributes.
+ * @param attributes a clone of the current {@link Map} of attributes.
*/
private MacAdapter(IMac mac, Map attributes)
{
@@ -98,21 +92,11 @@ class MacAdapter extends MacSpi implements Cloneable
this.attributes = attributes;
}
- // Class methods
- // -----------------------------------------------------------------------
-
- // Instance methods
- // -----------------------------------------------------------------------
-
- // Cloneable interface implementation ------------------------------------
-
public Object clone() throws CloneNotSupportedException
{
return new MacAdapter((IMac) mac.clone(), new HashMap(attributes));
}
- // Instance methods implementing javax.crypto.MacSpi ---------------------
-
protected byte[] engineDoFinal()
{
byte[] result = mac.digest();
@@ -128,10 +112,8 @@ class MacAdapter extends MacSpi implements Cloneable
protected void engineInit(Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException
{
- if (!key.getFormat().equalsIgnoreCase("RAW"))
- {
- throw new InvalidKeyException("unknown key format " + key.getFormat());
- }
+ if (! key.getFormat().equalsIgnoreCase("RAW"))
+ throw new InvalidKeyException("unknown key format " + key.getFormat());
attributes.put(IMac.MAC_KEY_MATERIAL, key.getEncoded());
mac.reset();
mac.init(attributes);
diff --git a/gnu/javax/crypto/jce/mac/OMacAnubisImpl.java b/gnu/javax/crypto/jce/mac/OMacAnubisImpl.java
index 4bfda4fd6..566e56fd1 100644
--- a/gnu/javax/crypto/jce/mac/OMacAnubisImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacAnubisImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacAnubisImpl extends MacAdapter
+public class OMacAnubisImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacAnubisImpl()
{
super(Registry.OMAC_PREFIX + Registry.ANUBIS_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacBlowfishImpl.java b/gnu/javax/crypto/jce/mac/OMacBlowfishImpl.java
index 8d168e57b..55768166f 100644
--- a/gnu/javax/crypto/jce/mac/OMacBlowfishImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacBlowfishImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacBlowfishImpl extends MacAdapter
+public class OMacBlowfishImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacBlowfishImpl()
{
super(Registry.OMAC_PREFIX + Registry.BLOWFISH_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacCast5Impl.java b/gnu/javax/crypto/jce/mac/OMacCast5Impl.java
index 3385d116b..535352c39 100644
--- a/gnu/javax/crypto/jce/mac/OMacCast5Impl.java
+++ b/gnu/javax/crypto/jce/mac/OMacCast5Impl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacCast5Impl extends MacAdapter
+public class OMacCast5Impl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacCast5Impl()
{
super(Registry.OMAC_PREFIX + Registry.CAST5_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacDESImpl.java b/gnu/javax/crypto/jce/mac/OMacDESImpl.java
index 3fb23bdef..a01c0ac87 100644
--- a/gnu/javax/crypto/jce/mac/OMacDESImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacDESImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacDESImpl extends MacAdapter
+public class OMacDESImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacDESImpl()
{
super(Registry.OMAC_PREFIX + Registry.DES_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacImpl.java b/gnu/javax/crypto/jce/mac/OMacImpl.java
index bf30d8e13..960c68aaf 100644
--- a/gnu/javax/crypto/jce/mac/OMacImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacImpl.java
@@ -40,21 +40,16 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public abstract class OMacImpl extends MacAdapter
+public abstract class OMacImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
protected OMacImpl(String name)
{
super(Registry.OMAC_PREFIX + name);
}
- // Inner classes.
- // -------------------------------------------------------------------------
-
- public class Anubis extends OMacImpl
+ public class Anubis
+ extends OMacImpl
{
public Anubis()
{
@@ -62,7 +57,8 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class Blowfish extends OMacImpl
+ public class Blowfish
+ extends OMacImpl
{
public Blowfish()
{
@@ -70,7 +66,8 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class Cast5 extends OMacImpl
+ public class Cast5
+ extends OMacImpl
{
public Cast5()
{
@@ -78,7 +75,8 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class DES extends OMacImpl
+ public class DES
+ extends OMacImpl
{
public DES()
{
@@ -86,7 +84,8 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class Khazad extends OMacImpl
+ public class Khazad
+ extends OMacImpl
{
public Khazad()
{
@@ -94,7 +93,8 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class Rijndael extends OMacImpl
+ public class Rijndael
+ extends OMacImpl
{
public Rijndael()
{
@@ -102,7 +102,8 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class Serpent extends OMacImpl
+ public class Serpent
+ extends OMacImpl
{
public Serpent()
{
@@ -110,7 +111,8 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class Square extends OMacImpl
+ public class Square
+ extends OMacImpl
{
public Square()
{
@@ -118,7 +120,8 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class TripleDES extends OMacImpl
+ public class TripleDES
+ extends OMacImpl
{
public TripleDES()
{
@@ -126,11 +129,12 @@ public abstract class OMacImpl extends MacAdapter
}
}
- public class Twofish extends OMacImpl
+ public class Twofish
+ extends OMacImpl
{
public Twofish()
{
super(Registry.TWOFISH_CIPHER);
}
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacKhazadImpl.java b/gnu/javax/crypto/jce/mac/OMacKhazadImpl.java
index 82c047c25..c349f9f5e 100644
--- a/gnu/javax/crypto/jce/mac/OMacKhazadImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacKhazadImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacKhazadImpl extends MacAdapter
+public class OMacKhazadImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacKhazadImpl()
{
super(Registry.OMAC_PREFIX + Registry.KHAZAD_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacRijndaelImpl.java b/gnu/javax/crypto/jce/mac/OMacRijndaelImpl.java
index 47d3f6aae..d63b777a3 100644
--- a/gnu/javax/crypto/jce/mac/OMacRijndaelImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacRijndaelImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacRijndaelImpl extends MacAdapter
+public class OMacRijndaelImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacRijndaelImpl()
{
super(Registry.OMAC_PREFIX + Registry.RIJNDAEL_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacSerpentImpl.java b/gnu/javax/crypto/jce/mac/OMacSerpentImpl.java
index bec2c1f5c..5c1b8a9b9 100644
--- a/gnu/javax/crypto/jce/mac/OMacSerpentImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacSerpentImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacSerpentImpl extends MacAdapter
+public class OMacSerpentImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacSerpentImpl()
{
super(Registry.OMAC_PREFIX + Registry.SERPENT_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacSquareImpl.java b/gnu/javax/crypto/jce/mac/OMacSquareImpl.java
index 0442b7caf..c9d1b1aca 100644
--- a/gnu/javax/crypto/jce/mac/OMacSquareImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacSquareImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacSquareImpl extends MacAdapter
+public class OMacSquareImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacSquareImpl()
{
super(Registry.OMAC_PREFIX + Registry.SQUARE_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacTripleDESImpl.java b/gnu/javax/crypto/jce/mac/OMacTripleDESImpl.java
index 0defdd1fd..4f58723d3 100644
--- a/gnu/javax/crypto/jce/mac/OMacTripleDESImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacTripleDESImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacTripleDESImpl extends MacAdapter
+public class OMacTripleDESImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacTripleDESImpl()
{
super(Registry.OMAC_PREFIX + Registry.TRIPLEDES_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/OMacTwofishImpl.java b/gnu/javax/crypto/jce/mac/OMacTwofishImpl.java
index a12f9f30e..4c816a096 100644
--- a/gnu/javax/crypto/jce/mac/OMacTwofishImpl.java
+++ b/gnu/javax/crypto/jce/mac/OMacTwofishImpl.java
@@ -40,14 +40,11 @@ package gnu.javax.crypto.jce.mac;
import gnu.java.security.Registry;
-public class OMacTwofishImpl extends MacAdapter
+public class OMacTwofishImpl
+ extends MacAdapter
{
-
- // Constructor.
- // -------------------------------------------------------------------------
-
public OMacTwofishImpl()
{
super(Registry.OMAC_PREFIX + Registry.TWOFISH_CIPHER);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/mac/TMMH16Spi.java b/gnu/javax/crypto/jce/mac/TMMH16Spi.java
index 1734e1e69..8a40f6e70 100644
--- a/gnu/javax/crypto/jce/mac/TMMH16Spi.java
+++ b/gnu/javax/crypto/jce/mac/TMMH16Spi.java
@@ -51,27 +51,19 @@ import java.security.spec.AlgorithmParameterSpec;
* The implementation of the TMMH16 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class TMMH16Spi extends MacAdapter
+public final class TMMH16Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public TMMH16Spi()
{
super(Registry.TMMH16);
}
- // Instance methods overriding MacAdapter.
- // -----------------------------------------------------------------------
-
protected void engineInit(Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException
{
- if (!(params instanceof TMMHParameterSpec))
- {
- throw new InvalidAlgorithmParameterException();
- }
+ if (! (params instanceof TMMHParameterSpec))
+ throw new InvalidAlgorithmParameterException();
TMMHParameterSpec spec = (TMMHParameterSpec) params;
attributes.put(TMMH16.TAG_LENGTH, spec.getTagLength());
attributes.put(TMMH16.KEYSTREAM, spec.getKeystream());
diff --git a/gnu/javax/crypto/jce/mac/UHash32Spi.java b/gnu/javax/crypto/jce/mac/UHash32Spi.java
index af678c0fa..825edc173 100644
--- a/gnu/javax/crypto/jce/mac/UHash32Spi.java
+++ b/gnu/javax/crypto/jce/mac/UHash32Spi.java
@@ -44,12 +44,9 @@ import gnu.java.security.Registry;
* The implementation of the UHash-32 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class UHash32Spi extends MacAdapter
+public final class UHash32Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public UHash32Spi()
{
super(Registry.UHASH32);
diff --git a/gnu/javax/crypto/jce/mac/UMac32Spi.java b/gnu/javax/crypto/jce/mac/UMac32Spi.java
index 4e90468b1..fc05e5321 100644
--- a/gnu/javax/crypto/jce/mac/UMac32Spi.java
+++ b/gnu/javax/crypto/jce/mac/UMac32Spi.java
@@ -51,32 +51,22 @@ import java.security.spec.AlgorithmParameterSpec;
* The implementation of the UMAC-32 <i>Service Provider Interface</i>
* (<b>SPI</b>) adapter.
*/
-public final class UMac32Spi extends MacAdapter
+public final class UMac32Spi
+ extends MacAdapter
{
-
- // Constructors.
- // -----------------------------------------------------------------------
-
public UMac32Spi()
{
super(Registry.UMAC32);
}
- // Instance methods overriding MacAdapter.
- // -----------------------------------------------------------------------
-
protected void engineInit(Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException
{
- if (!(params instanceof UMac32ParameterSpec))
- {
- throw new InvalidAlgorithmParameterException();
- }
+ if (! (params instanceof UMac32ParameterSpec))
+ throw new InvalidAlgorithmParameterException();
if (params != null)
- {
- attributes.put(UMac32.NONCE_MATERIAL,
- ((UMac32ParameterSpec) params).getNonce());
- }
+ attributes.put(UMac32.NONCE_MATERIAL,
+ ((UMac32ParameterSpec) params).getNonce());
try
{
super.engineInit(key, null);
diff --git a/gnu/javax/crypto/jce/params/BlockCipherParameters.java b/gnu/javax/crypto/jce/params/BlockCipherParameters.java
index bae7cbf88..2292678d6 100644
--- a/gnu/javax/crypto/jce/params/BlockCipherParameters.java
+++ b/gnu/javax/crypto/jce/params/BlockCipherParameters.java
@@ -48,38 +48,28 @@ import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
/**
- * An implementation of algorithm parameters for the GNU Crypto block
- * ciphers. This encompasses the cipher's block size, its key size, and
- * an optional initialization vector (IV).
+ * An implementation of algorithm parameters for the GNU block ciphers. This
+ * encompasses the cipher's block size, its key size, and an optional
+ * initialization vector (IV).
*/
-public class BlockCipherParameters extends AlgorithmParametersSpi
+public class BlockCipherParameters
+ extends AlgorithmParametersSpi
{
-
- // Constants and variables.
- // -----------------------------------------------------------------------
-
- /**
- * The underlying block cipher specification.
- */
+ /** The underlying block cipher specification. */
protected BlockCipherParameterSpec cipherSpec;
-
private static final String DEFAULT_FORMAT = "ASN.1";
- // Instance methods implementing AlgorithmParametersSpi.
- // -----------------------------------------------------------------------
-
/**
* Return these parameters encoded in ASN.1 (DER).
- *
- * <p>For GNU Crypto block ciphers we will define these parameters as
- *
- * <blockquote>
- * <pre>BlockCipherParameters ::= SEQUENCE {
- * blockSize INTEGER,
- * keySize INTEGER,
- * initializationVector OCTET STRING OPTIONAL }</pre>
- * </blockquote>
- *
+ * <p>
+ * For GNU block ciphers we will define these parameters as
+ * <pre>
+ * BlockCipherParameters ::= SEQUENCE {
+ * blockSize INTEGER,
+ * keySize INTEGER,
+ * initializationVector OCTET STRING OPTIONAL }
+ * </pre>
+ *
* @return The parameters, encoded an an ASN.1 DER sequence.
* @throws java.io.IOException If encoding these parameters fails.
*/
@@ -90,104 +80,45 @@ public class BlockCipherParameters extends AlgorithmParametersSpi
protected byte[] engineGetEncoded(String format) throws IOException
{
- if (!format.equalsIgnoreCase(DEFAULT_FORMAT)
- && !format.equalsIgnoreCase("asn1"))
- {
- throw new IOException("unknown format \"" + format + "\"");
- }
- // This is probably a bad idea.
- /*
- int len = 12 + ((cipherSpec.getIV() != null)
- ? cipherSpec.getIV().length + 2 : 0);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- out.write(0x30);
- out.write(len);
- out.write(0x02);
- out.write(4);
- out.write(cipherSpec.getBlockSize() >>> 24 & 0xff);
- out.write(cipherSpec.getBlockSize() >>> 16 & 0xff);
- out.write(cipherSpec.getBlockSize() >>> 8 & 0xff);
- out.write(cipherSpec.getBlockSize() & 0xff);
- out.write(0x02);
- out.write(4);
- out.write(cipherSpec.getKeySize() >>> 24 & 0xff);
- out.write(cipherSpec.getKeySize() >>> 16 & 0xff);
- out.write(cipherSpec.getKeySize() >>> 8 & 0xff);
- out.write(cipherSpec.getKeySize() & 0xff);
- if (cipherSpec.getIV() != null) {
- out.write(0x04);
- len = cipherSpec.getIV().length;
- out.write(len & 0xff);
- out.write(cipherSpec.getIV());
- }
- out.write(0); out.write(0);
- return out.toByteArray();*/
+ if (! format.equalsIgnoreCase(DEFAULT_FORMAT)
+ && ! format.equalsIgnoreCase("asn1"))
+ throw new IOException("unknown format \"" + format + "\"");
DERWriter writer = new DERWriter();
+ int cipherBlockSize = cipherSpec.getBlockSize();
+ int cipherKeySize = cipherSpec.getKeySize();
+ byte[] iv = cipherSpec.getIV();
return writer.joinarrays(
- writer.writeBigInteger(BigInteger.valueOf(cipherSpec.getBlockSize())),
- writer.writeBigInteger(BigInteger.valueOf(cipherSpec.getKeySize())),
- (cipherSpec.getIV() != null) ? writer.writeBigInteger(new BigInteger(
- cipherSpec.getIV()))
- : new byte[0]);
+ writer.writeBigInteger(BigInteger.valueOf(cipherBlockSize)),
+ writer.writeBigInteger(BigInteger.valueOf(cipherKeySize)),
+ (iv != null) ? writer.writeBigInteger(new BigInteger(iv))
+ : new byte[0]);
}
protected void engineInit(AlgorithmParameterSpec spec)
throws InvalidParameterSpecException
{
if (spec instanceof BlockCipherParameterSpec)
- {
- cipherSpec = (BlockCipherParameterSpec) spec;
- }
+ cipherSpec = (BlockCipherParameterSpec) spec;
else
- {
- throw new InvalidParameterSpecException();
- }
+ throw new InvalidParameterSpecException();
}
protected void engineInit(byte[] encoded, String format) throws IOException
{
- if (!format.equalsIgnoreCase(DEFAULT_FORMAT)
- && !format.equalsIgnoreCase("ASN1"))
- {
- throw new IOException("invalid format: only accepts ASN.1");
- }
+ if (! format.equalsIgnoreCase(DEFAULT_FORMAT)
+ && ! format.equalsIgnoreCase("ASN1"))
+ throw new IOException("invalid format: only accepts ASN.1");
engineInit(encoded);
}
protected void engineInit(byte[] encoded) throws IOException
{
- // This is probably an equally bad idea.
- /*if (encoded[0] != 0x30) {
- throw new IOException("malformed ASN.1 sequence");
- }
- if (encoded[2] != 0x02 || encoded[3] != 4) {
- throw new IOException("malformed ASN.1 sequence");
- }
- int blockSize = encoded[4] << 24 | encoded[5] << 16
- | encoded[6] << 8 | encoded[7];
- if (encoded[8] != 0x02 || encoded[9] != 4) {
- throw new IOException("malformed ASN.1 sequence");
- }
- int keySize = encoded[10] << 24 | encoded[11] << 16
- | encoded[12] << 8 | encoded[13];
- if (encoded[14] == 0x04) {
- int len = encoded[15] & 0xff;
- byte[] iv = new byte[len];
- System.arraycopy(encoded, 16, iv, 0, len);
- cipherSpec = new BlockCipherParameterSpec(iv, blockSize, keySize);
- } else if (encoded[14] == 0) {
- cipherSpec = new BlockCipherParameterSpec(blockSize, keySize);
- } else {
- throw new IOException("malformed ASN.1 sequence");
- }*/
DERReader reader = new DERReader(encoded);
int bs = reader.getBigInteger().intValue();
int ks = reader.getBigInteger().intValue();
byte[] iv = null;
if (reader.hasMorePrimitives())
- {
- iv = reader.getBigInteger().toByteArray();
- }
+ iv = reader.getBigInteger().toByteArray();
cipherSpec = new BlockCipherParameterSpec(iv, bs, ks);
System.out.println(cipherSpec);
}
@@ -196,9 +127,7 @@ public class BlockCipherParameters extends AlgorithmParametersSpi
throws InvalidParameterSpecException
{
if (c.isInstance(cipherSpec))
- {
- return cipherSpec;
- }
+ return cipherSpec;
throw new InvalidParameterSpecException();
}
@@ -206,4 +135,4 @@ public class BlockCipherParameters extends AlgorithmParametersSpi
{
return cipherSpec.toString();
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/params/DEREncodingException.java b/gnu/javax/crypto/jce/params/DEREncodingException.java
index ddfa6e1de..b89ceda9f 100644
--- a/gnu/javax/crypto/jce/params/DEREncodingException.java
+++ b/gnu/javax/crypto/jce/params/DEREncodingException.java
@@ -38,7 +38,8 @@ exception statement from your version. */
package gnu.javax.crypto.jce.params;
-class DEREncodingException extends java.io.IOException
+class DEREncodingException
+ extends java.io.IOException
{
public DEREncodingException()
@@ -50,4 +51,4 @@ class DEREncodingException extends java.io.IOException
{
super(msg);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/params/DERReader.java b/gnu/javax/crypto/jce/params/DERReader.java
index f61423255..68c680279 100644
--- a/gnu/javax/crypto/jce/params/DERReader.java
+++ b/gnu/javax/crypto/jce/params/DERReader.java
@@ -43,15 +43,10 @@ import java.math.BigInteger;
class DERReader
{
byte source[];
-
int pos;
-
static final int UNIVERSAL = 1;
-
static final int APPLICATION = 2;
-
static final int CONTEXT_SPECIFIC = 3;
-
static final int PRIVATE = 4;
public DERReader()
@@ -86,53 +81,37 @@ class DERReader
return new BigInteger(getPrimitive());
}
- //Reads Primitive, definite-length method
+ // Reads Primitive, definite-length method
private byte[] getPrimitive() throws DEREncodingException
{
int tmp = pos;
-
- //Read Identifier
+ // Read Identifier
byte identifier = source[tmp++];
if ((0x20 & identifier) != 0)
throw new DEREncodingException();
int type = translateLeadIdentifierByte(identifier);
- //System.out.println("Type: " + type);
-
- //get tag
+ // get tag
int tag = (0x1f & identifier);
- //if( tag == 0x1f)
- // tag = getIdentifier(tmp);
- //System.out.println("Tag: " + tag);
-
- //get length
- byte len = source[tmp]; //may be length of length parameter
+ // get length
+ byte len = source[tmp]; // may be length of length parameter
long length = 0x7f & len;
int i;
if ((0x80 & len) != 0)
{
- //System.out.println("Extra Long Length");
len &= 0x7f;
- //System.out.println("Length of Length: " + len);
- //get length here
+ // get length here
length = 0;
for (i = 0; i < len; i++)
{
tmp++;
length <<= 8;
length += (source[tmp] < 0) ? (256 + source[tmp]) : source[tmp];
- //System.out.println("Length of Length: " + length);
}
tmp++;
}
else
tmp++;
- /*System.out.println("Position: " + tmp);
- System.out.println("Length: " + length);
- for( i = 0; i < 10; i++)
- System.out.print(source[tmp + i] + " ");
- System.out.println();*/
-
byte tmpb[] = new byte[(int) length];
System.arraycopy(source, tmp, tmpb, 0, (int) length);
pos = (int) (tmp + length);
@@ -157,4 +136,4 @@ class DERReader
tpos++;
return tpos;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/params/DERWriter.java b/gnu/javax/crypto/jce/params/DERWriter.java
index 876c2cd6c..7bdea10c5 100644
--- a/gnu/javax/crypto/jce/params/DERWriter.java
+++ b/gnu/javax/crypto/jce/params/DERWriter.java
@@ -43,11 +43,8 @@ import java.math.BigInteger;
class DERWriter
{
static final int UNIVERSAL = 1;
-
static final int APPLICATION = 2;
-
static final int CONTEXT_SPECIFIC = 3;
-
static final int PRIVATE = 4;
public DERWriter()
@@ -56,7 +53,8 @@ class DERWriter
public byte[] writeBigInteger(BigInteger i)
{
- return writePrimitive(0x02, UNIVERSAL,
+ return writePrimitive(0x02,
+ UNIVERSAL,
(int) Math.ceil((double) i.bitLength() / 8),
i.toByteArray());
}
@@ -71,7 +69,7 @@ class DERWriter
public byte[] joinarrays(byte a[], byte b[])
{
byte d[] = new byte[a.length + b.length];
- System.arraycopy(a, 0, d, 0, a.length);
+ System.arraycopy(a, 0, d, 0, a.length);
System.arraycopy(b, 0, d, a.length, b.length);
return d;
}
@@ -92,7 +90,7 @@ class DERWriter
{
int count = (int) (Math.log(identifier) / Math.log(256));
b = new byte[count + 1];
- b[0] = (byte) (translateLeadIdentifierByte(identifierencoding) | 0x1f);
+ b[0] = (byte)(translateLeadIdentifierByte(identifierencoding) | 0x1f);
int i;
for (i = 1; i < (count + 1); i++)
{
@@ -100,14 +98,13 @@ class DERWriter
b[i] |= 0x80;
}
b[i - 1] ^= 0x80;
- //System.out.println("Identifier1: " + b[0]);
return b;
}
else
{
b = new byte[1];
- b[0] = (byte) ((translateLeadIdentifierByte(identifierencoding) | (byte) (identifier & 0x1f)) & 0xdf);
- //System.out.println("Identifier2: " + b[0]);
+ b[0] = (byte)((translateLeadIdentifierByte(identifierencoding)
+ | (byte)(identifier & 0x1f)) & 0xdf);
return b;
}
}
@@ -130,25 +127,17 @@ class DERWriter
if (length > 127)
{
int count = (int) Math.ceil(Math.log(length) / Math.log(256));
- //System.out.println("Length byte count: " + count);
b = new byte[count + 1];
- b[0] = (byte) ((count & 0x7f) | 0x80);
+ b[0] = (byte)((count & 0x7f) | 0x80);
for (int i = 1; i < (count + 1); i++)
- {
- b[i] = (byte) (length >>> (8 * (count - i)));
- //System.out.println("Length1 byte1: " + (length >>> (8 * ( count - i) )));
- //System.out.println("Length1 byte2: " + b[i]);
- }
-
- //System.out.println("Length1: " + length);
+ b[i] = (byte) (length >>> (8 * (count - i)));
return b;
}
else
{
b = new byte[1];
b[0] = (byte) (length & 0x7f);
- //System.out.println("Length2: " + length);
return b;
}
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java b/gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java
index 0c071561b..652793b04 100644
--- a/gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java
+++ b/gnu/javax/crypto/jce/prng/ARCFourRandomSpi.java
@@ -48,24 +48,17 @@ import java.security.SecureRandomSpi;
import java.util.HashMap;
/**
- * Implementation of the <i>Service Provider Interface</i> (<b>SPI</b>)
- * for the ARCFOUR keystream generator.
+ * Implementation of the <i>Service Provider Interface</i> (<b>SPI</b>) for
+ * the ARCFOUR keystream generator.
*/
-public class ARCFourRandomSpi extends SecureRandomSpi
+public class ARCFourRandomSpi
+ extends SecureRandomSpi
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** Our underlying prng instance. */
private IRandom adaptee;
-
/** Have we been initialized? */
private boolean virgin;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Default 0-arguments constructor.
*/
@@ -76,20 +69,10 @@ public class ARCFourRandomSpi extends SecureRandomSpi
virgin = true;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.security.SecureRandomSpi interface implementation ------------------
-
public byte[] engineGenerateSeed(int numBytes)
{
if (numBytes < 1)
- {
- return new byte[0];
- }
+ return new byte[0];
byte[] result = new byte[numBytes];
this.engineNextBytes(result);
return result;
@@ -98,9 +81,7 @@ public class ARCFourRandomSpi extends SecureRandomSpi
public void engineNextBytes(byte[] bytes)
{
if (virgin)
- {
- this.engineSetSeed(new byte[0]);
- }
+ this.engineSetSeed(new byte[0]);
try
{
adaptee.nextBytes(bytes, 0, bytes.length);
@@ -117,4 +98,4 @@ public class ARCFourRandomSpi extends SecureRandomSpi
adaptee.init(attributes);
virgin = false;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/prng/CSPRNGSpi.java b/gnu/javax/crypto/jce/prng/CSPRNGSpi.java
index acc0c8e84..6ded636aa 100644
--- a/gnu/javax/crypto/jce/prng/CSPRNGSpi.java
+++ b/gnu/javax/crypto/jce/prng/CSPRNGSpi.java
@@ -46,20 +46,14 @@ import java.net.MalformedURLException;
import java.security.SecureRandomSpi;
/**
- * The implementation of the continuously-seeded SecureRandom
- * <i>Service Provider Interface</i> (<b>SPI</b>) adapter.<p>
+ * The implementation of the continuously-seeded SecureRandom <i>Service
+ * Provider Interface</i> (<b>SPI</b>) adapter.
*/
-public class CSPRNGSpi extends SecureRandomSpi
+public class CSPRNGSpi
+ extends SecureRandomSpi
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private final IRandom adaptee;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public CSPRNGSpi() throws ClassNotFoundException, MalformedURLException,
NumberFormatException
{
@@ -68,20 +62,13 @@ public class CSPRNGSpi extends SecureRandomSpi
adaptee = CSPRNG.getSystemInstance();
}
- // Instance methods
- // -------------------------------------------------------------------------
-
protected byte[] engineGenerateSeed(final int count)
{
if (count < 0)
- {
- throw new IllegalArgumentException("count must be nonnegative");
- }
+ throw new IllegalArgumentException("count must be nonnegative");
byte[] buf = new byte[count];
if (count == 0)
- {
- return buf;
- }
+ return buf;
engineNextBytes(buf);
return buf;
}
@@ -89,9 +76,7 @@ public class CSPRNGSpi extends SecureRandomSpi
protected void engineNextBytes(final byte[] buffer)
{
if (buffer == null)
- {
- throw new NullPointerException();
- }
+ throw new NullPointerException();
try
{
adaptee.nextBytes(buffer, 0, buffer.length);
@@ -105,9 +90,7 @@ public class CSPRNGSpi extends SecureRandomSpi
protected void engineSetSeed(final byte[] seed)
{
if (seed == null)
- {
- throw new NullPointerException();
- }
+ throw new NullPointerException();
adaptee.addRandomBytes(seed, 0, seed.length);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/prng/FortunaImpl.java b/gnu/javax/crypto/jce/prng/FortunaImpl.java
index 7006bbbad..8e3782ef0 100644
--- a/gnu/javax/crypto/jce/prng/FortunaImpl.java
+++ b/gnu/javax/crypto/jce/prng/FortunaImpl.java
@@ -40,24 +40,26 @@ package gnu.javax.crypto.jce.prng;
import gnu.java.security.prng.LimitReachedException;
import gnu.javax.crypto.prng.Fortuna;
+
import java.security.SecureRandomSpi;
import java.util.Collections;
-public final class FortunaImpl extends SecureRandomSpi
+public final class FortunaImpl
+ extends SecureRandomSpi
{
private final Fortuna adaptee;
- public FortunaImpl ()
+ public FortunaImpl()
{
- adaptee = new Fortuna ();
- adaptee.init (Collections.singletonMap (Fortuna.SEED, new byte[0]));
+ adaptee = new Fortuna();
+ adaptee.init(Collections.singletonMap(Fortuna.SEED, new byte[0]));
}
-
- protected void engineSetSeed (byte[] seed)
+
+ protected void engineSetSeed(byte[] seed)
{
synchronized (adaptee)
{
- adaptee.addRandomBytes (seed);
+ adaptee.addRandomBytes(seed);
}
}
@@ -67,19 +69,19 @@ public final class FortunaImpl extends SecureRandomSpi
{
try
{
- adaptee.nextBytes (buffer);
+ adaptee.nextBytes(buffer);
}
catch (LimitReachedException shouldNotHappen)
{
- throw new Error (shouldNotHappen);
+ throw new Error(shouldNotHappen);
}
}
}
- protected byte[] engineGenerateSeed (int numbytes)
+ protected byte[] engineGenerateSeed(int numbytes)
{
byte[] seed = new byte[numbytes];
- engineNextBytes (seed);
+ engineNextBytes(seed);
return seed;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/prng/ICMRandomSpi.java b/gnu/javax/crypto/jce/prng/ICMRandomSpi.java
index 9be46e055..9855f95bd 100644
--- a/gnu/javax/crypto/jce/prng/ICMRandomSpi.java
+++ b/gnu/javax/crypto/jce/prng/ICMRandomSpi.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.jce.prng;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.prng.LimitReachedException;
import gnu.javax.crypto.cipher.IBlockCipher;
@@ -51,13 +51,14 @@ import java.util.Random;
import java.util.logging.Logger;
/**
- * <p>An <em>Adapter</em> class around {@link ICMGenerator} to allow using this
- * algorithm as a JCE {@link java.security.SecureRandom}.</p>
+ * An <em>Adapter</em> class around {@link ICMGenerator} to allow using this
+ * algorithm as a JCE {@link java.security.SecureRandom}.
*/
-public class ICMRandomSpi extends SecureRandomSpi
+public class ICMRandomSpi
+ extends SecureRandomSpi
{
private static final Logger log = Logger.getLogger(ICMRandomSpi.class.getName());
- /** Class-wide prng to generate random material for the underlying prng.*/
+ /** Class-wide prng to generate random material for the underlying prng. */
private static final ICMGenerator prng; // blank final
static
{
@@ -68,24 +69,14 @@ public class ICMRandomSpi extends SecureRandomSpi
// error messages
private static final String MSG = "Exception while setting up an "
+ Registry.ICM_PRNG + " SPI: ";
-
private static final String RETRY = "Retry...";
-
private static final String LIMIT_REACHED_MSG = "Limit reached: ";
-
private static final String RESEED = "Re-seed...";
-
/** Our underlying prng instance. */
private ICMGenerator adaptee = new ICMGenerator();
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
private static void resetLocalPRNG()
{
if (Configuration.DEBUG)
@@ -104,24 +95,16 @@ public class ICMRandomSpi extends SecureRandomSpi
// choose a random value between 1 and aesBlockSize / 2
int limit = aesBlockSize / 2;
while (ndxLen < 1 || ndxLen > limit)
- {
- ndxLen = rand.nextInt(limit + 1);
- }
- attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, new Integer(ndxLen));
+ ndxLen = rand.nextInt(limit + 1);
+ attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, Integer.valueOf(ndxLen));
byte[] index = new byte[ndxLen];
rand.nextBytes(index);
attributes.put(ICMGenerator.SEGMENT_INDEX, new BigInteger(1, index));
-
prng.setup(attributes);
if (Configuration.DEBUG)
log.exiting(ICMRandomSpi.class.getName(), "resetLocalPRNG");
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.security.SecureRandomSpi interface implementation ------------------
-
public byte[] engineGenerateSeed(int numBytes)
{
if (Configuration.DEBUG)
@@ -143,11 +126,8 @@ public class ICMRandomSpi extends SecureRandomSpi
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "engineNextBytes");
- if (!adaptee.isInitialised())
- {
- this.engineSetSeed(new byte[0]);
- }
-
+ if (! adaptee.isInitialised())
+ this.engineSetSeed(new byte[0]);
while (true)
{
try
@@ -179,7 +159,6 @@ public class ICMRandomSpi extends SecureRandomSpi
materialLength += 16; // offset size
materialLength += 8; // index size == half of an AES block
byte[] material = new byte[materialLength];
-
// use as much as possible bytes from the seed
int materialOffset = 0;
int materialLeft = material.length;
@@ -190,8 +169,8 @@ public class ICMRandomSpi extends SecureRandomSpi
materialOffset += lenToCopy;
materialLeft -= lenToCopy;
}
- if (materialOffset > 0)
- { // generate the rest
+ if (materialOffset > 0) // generate the rest
+ {
while (true)
{
try
@@ -213,14 +192,12 @@ public class ICMRandomSpi extends SecureRandomSpi
}
}
}
-
// setup the underlying adaptee instance
HashMap attributes = new HashMap();
-
// use AES cipher with 128-bit block size
attributes.put(ICMGenerator.CIPHER, Registry.AES_CIPHER);
// use an index the size of quarter of an AES block
- attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, new Integer(4));
+ attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, Integer.valueOf(4));
// specify the key
byte[] key = new byte[16];
System.arraycopy(material, 0, key, 0, 16);
@@ -233,9 +210,8 @@ public class ICMRandomSpi extends SecureRandomSpi
byte[] index = new byte[8];
System.arraycopy(material, 32, index, 0, 8);
attributes.put(ICMGenerator.SEGMENT_INDEX, new BigInteger(1, index));
-
adaptee.init(attributes);
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "engineSetSeed");
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/prng/UMacRandomSpi.java b/gnu/javax/crypto/jce/prng/UMacRandomSpi.java
index 5c60a21d8..f6949dd8d 100644
--- a/gnu/javax/crypto/jce/prng/UMacRandomSpi.java
+++ b/gnu/javax/crypto/jce/prng/UMacRandomSpi.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.jce.prng;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.prng.LimitReachedException;
import gnu.javax.crypto.cipher.IBlockCipher;
@@ -50,37 +50,29 @@ import java.util.Random;
import java.util.logging.Logger;
/**
- * <p>An <em>Adapter</em> class around {@link UMacGenerator} to allow using this
- * algorithm as a JCE {@link java.security.SecureRandom}.</p>
+ * An <em>Adapter</em> class around {@link UMacGenerator} to allow using this
+ * algorithm as a JCE {@link java.security.SecureRandom}.
*/
-public class UMacRandomSpi extends SecureRandomSpi
+public class UMacRandomSpi
+ extends SecureRandomSpi
{
private static final Logger log = Logger.getLogger(UMacRandomSpi.class.getName());
- /** Class-wide prng to generate random material for the underlying prng.*/
+ /** Class-wide prng to generate random material for the underlying prng. */
private static final UMacGenerator prng; // blank final
static
{
prng = new UMacGenerator();
resetLocalPRNG();
}
-
// error messages
private static final String MSG = "Exception while setting up a "
+ Registry.UMAC_PRNG + " SPI: ";
-
private static final String RETRY = "Retry...";
-
/** Our underlying prng instance. */
private UMacGenerator adaptee = new UMacGenerator();
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
private static void resetLocalPRNG()
{
HashMap attributes = new HashMap();
@@ -90,22 +82,14 @@ public class UMacRandomSpi extends SecureRandomSpi
rand.nextBytes(key);
attributes.put(IBlockCipher.KEY_MATERIAL, key);
int index = rand.nextInt() & 0xFF;
- attributes.put(UMacGenerator.INDEX, new Integer(index));
-
+ attributes.put(UMacGenerator.INDEX, Integer.valueOf(index));
prng.setup(attributes);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.security.SecureRandomSpi interface implementation ------------------
-
public byte[] engineGenerateSeed(int numBytes)
{
if (numBytes < 1)
- {
- return new byte[0];
- }
+ return new byte[0];
byte[] result = new byte[numBytes];
this.engineNextBytes(result);
return result;
@@ -113,11 +97,8 @@ public class UMacRandomSpi extends SecureRandomSpi
public void engineNextBytes(byte[] bytes)
{
- if (!adaptee.isInitialised())
- {
- this.engineSetSeed(new byte[0]);
- }
-
+ if (! adaptee.isInitialised())
+ this.engineSetSeed(new byte[0]);
while (true)
{
try
@@ -139,7 +120,6 @@ public class UMacRandomSpi extends SecureRandomSpi
materialLength += 16; // key material size
materialLength++; // index size
byte[] material = new byte[materialLength];
-
// use as much as possible bytes from the seed
int materialOffset = 0;
int materialLeft = material.length;
@@ -150,8 +130,8 @@ public class UMacRandomSpi extends SecureRandomSpi
materialOffset += lenToCopy;
materialLeft -= lenToCopy;
}
- if (materialOffset > 0)
- { // generate the rest
+ if (materialOffset > 0) // generate the rest
+ {
while (true)
{
try
@@ -159,8 +139,8 @@ public class UMacRandomSpi extends SecureRandomSpi
prng.nextBytes(material, materialOffset, materialLeft);
break;
}
- catch (IllegalStateException x)
- { // should not happen
+ catch (IllegalStateException x) // should not happen
+ {
throw new InternalError(MSG + String.valueOf(x));
}
catch (LimitReachedException x)
@@ -173,10 +153,8 @@ public class UMacRandomSpi extends SecureRandomSpi
}
}
}
-
// setup the underlying adaptee instance
HashMap attributes = new HashMap();
-
// use AES cipher with 128-bit block size
attributes.put(UMacGenerator.CIPHER, Registry.AES_CIPHER);
// specify the key
@@ -184,8 +162,7 @@ public class UMacRandomSpi extends SecureRandomSpi
System.arraycopy(material, 0, key, 0, 16);
attributes.put(IBlockCipher.KEY_MATERIAL, key);
// use a 1-byte index
- attributes.put(UMacGenerator.INDEX, new Integer(material[16] & 0xFF));
-
+ attributes.put(UMacGenerator.INDEX, Integer.valueOf(material[16] & 0xFF));
adaptee.init(attributes);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/sig/DHKeyFactory.java b/gnu/javax/crypto/jce/sig/DHKeyFactory.java
index 701191adc..98b265dd3 100644
--- a/gnu/javax/crypto/jce/sig/DHKeyFactory.java
+++ b/gnu/javax/crypto/jce/sig/DHKeyFactory.java
@@ -79,7 +79,6 @@ public class DHKeyFactory
BigInteger y = spec.getY();
return new GnuDHPublicKey(Registry.X509_ENCODING_ID, null, p, g, y);
}
-
if (keySpec instanceof X509EncodedKeySpec)
{
X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
@@ -97,7 +96,6 @@ public class DHKeyFactory
throw y;
}
}
-
throw new InvalidKeySpecException("Unsupported (public) key specification");
}
@@ -112,7 +110,6 @@ public class DHKeyFactory
BigInteger x = spec.getX();
return new GnuDHPrivateKey(Registry.PKCS8_ENCODING_ID, null, p, g, x);
}
-
if (keySpec instanceof PKCS8EncodedKeySpec)
{
PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;
@@ -130,7 +127,6 @@ public class DHKeyFactory
throw y;
}
}
-
throw new InvalidKeySpecException("Unsupported (private) key specification");
}
@@ -147,7 +143,6 @@ public class DHKeyFactory
BigInteger y = dssKey.getY();
return new DHPublicKeySpec(y, p, g);
}
-
if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
{
if (key instanceof GnuDHPublicKey)
@@ -156,19 +151,16 @@ public class DHKeyFactory
byte[] encoded = dhKey.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(
+ "Wrong key type or unsupported (public) key specification");
}
-
throw new InvalidKeySpecException("Unsupported (public) key specification");
}
-
if (key instanceof DHPrivateKey)
{
if (keySpec.isAssignableFrom(DHPrivateKeySpec.class))
@@ -179,7 +171,6 @@ public class DHKeyFactory
BigInteger x = dhKey.getX();
return new DHPrivateKeySpec(x, p, g);
}
-
if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
{
if (key instanceof GnuDHPrivateKey)
@@ -188,27 +179,25 @@ public class DHKeyFactory
byte[] encoded = dhKey.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 (private) key specification");
}
-
- throw new InvalidKeySpecException("Unsupported (private) key specification");
+ throw new InvalidKeySpecException(
+ "Unsupported (private) key specification");
}
-
- throw new InvalidKeySpecException("Wrong key type or unsupported key specification");
+ throw new InvalidKeySpecException(
+ "Wrong key type or unsupported key specification");
}
protected Key engineTranslateKey(Key key) throws InvalidKeyException
{
if ((key instanceof GnuDHPublicKey) || (key instanceof GnuDHPrivateKey))
return key;
-
if (key instanceof DHPublicKey)
{
DHPublicKey dsaKey = (DHPublicKey) key;
@@ -217,7 +206,6 @@ public class DHKeyFactory
BigInteger y = dsaKey.getY();
return new GnuDHPublicKey(Registry.X509_ENCODING_ID, null, p, g, y);
}
-
if (key instanceof DHPrivateKey)
{
DHPrivateKey dsaKey = (DHPrivateKey) key;
@@ -226,7 +214,6 @@ public class DHKeyFactory
BigInteger x = dsaKey.getX();
return new GnuDHPrivateKey(Registry.PKCS8_ENCODING_ID, null, p, g, x);
}
-
throw new InvalidKeyException("Wrong key type");
}
}
diff --git a/gnu/javax/crypto/jce/sig/DHKeyPairGeneratorSpi.java b/gnu/javax/crypto/jce/sig/DHKeyPairGeneratorSpi.java
index 0d09d5cef..e26f07124 100644
--- a/gnu/javax/crypto/jce/sig/DHKeyPairGeneratorSpi.java
+++ b/gnu/javax/crypto/jce/sig/DHKeyPairGeneratorSpi.java
@@ -61,12 +61,12 @@ public class DHKeyPairGeneratorSpi
public void initialize(int keysize, SecureRandom random)
{
HashMap attributes = new HashMap();
- attributes.put(GnuDHKeyPairGenerator.PRIME_SIZE, new Integer(keysize));
+ attributes.put(GnuDHKeyPairGenerator.PRIME_SIZE, Integer.valueOf(keysize));
if (random != null)
attributes.put(GnuDHKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
attributes.put(GnuDHKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
- new Integer(Registry.ASN1_ENCODING_ID));
+ Integer.valueOf(Registry.ASN1_ENCODING_ID));
adaptee.setup(attributes);
}
@@ -87,7 +87,7 @@ public class DHKeyPairGeneratorSpi
attributes.put(GnuDHKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
attributes.put(GnuDHKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
- new Integer(Registry.ASN1_ENCODING_ID));
+ Integer.valueOf(Registry.ASN1_ENCODING_ID));
adaptee.setup(attributes);
}
}
diff --git a/gnu/javax/crypto/jce/spec/BlockCipherParameterSpec.java b/gnu/javax/crypto/jce/spec/BlockCipherParameterSpec.java
index 63e7740ec..321b47795 100644
--- a/gnu/javax/crypto/jce/spec/BlockCipherParameterSpec.java
+++ b/gnu/javax/crypto/jce/spec/BlockCipherParameterSpec.java
@@ -43,40 +43,26 @@ import gnu.java.security.util.Util;
import java.security.spec.AlgorithmParameterSpec;
/**
- * Block cipher parameters in GNU Crypto are the cipher's name, its block
- * and key sizes, and an optional initialization vector.
+ * Block cipher parameters in GNU are the cipher's name, its block and key
+ * sizes, and an optional initialization vector.
*/
-public class BlockCipherParameterSpec implements AlgorithmParameterSpec
+public class BlockCipherParameterSpec
+ implements AlgorithmParameterSpec
{
-
- // Constants and variables.
- // -----------------------------------------------------------------------
-
- /**
- * The initialization vector.
- */
+ /** The initialization vector. */
protected byte[] iv;
-
- /**
- * The cipher's block size, in bytes.
- */
+ /** The cipher's block size, in bytes. */
protected int blockSize;
-
- /**
- * The cipher's key size, in bytes.
- */
+ /** The cipher's key size, in bytes. */
protected int keySize;
- // Constructors.
- // -----------------------------------------------------------------------
-
/**
* Create a new parameter specification.
- *
- * @param iv The initialization vector, or <code>null</code> if
- * there is no IV.
+ *
+ * @param iv The initialization vector, or <code>null</code> if there is no
+ * IV.
* @param blockSize The cipher's block size, in bytes.
- * @param keySize The cipher's key size, in bytes.
+ * @param keySize The cipher's key size, in bytes.
*/
public BlockCipherParameterSpec(byte[] iv, int blockSize, int keySize)
{
@@ -87,22 +73,19 @@ public class BlockCipherParameterSpec implements AlgorithmParameterSpec
/**
* Create a new parameter specification with no IV.
- *
+ *
* @param blockSize The cipher's block size, in bytes.
- * @param keySize The cipher's key size, in bytes.
+ * @param keySize The cipher's key size, in bytes.
*/
public BlockCipherParameterSpec(int blockSize, int keySize)
{
this(null, blockSize, keySize);
}
- // Instance methods.
- // -----------------------------------------------------------------------
-
/**
- * Get the initialization vector for the cipher, or <code>null</code>
- * if there is no IV.
- *
+ * Get the initialization vector for the cipher, or <code>null</code> if
+ * there is no IV.
+ *
* @return The IV.
*/
public byte[] getIV()
@@ -112,7 +95,7 @@ public class BlockCipherParameterSpec implements AlgorithmParameterSpec
/**
* Get the block size of the cipher these parameters are for.
- *
+ *
* @return The block size.
*/
public int getBlockSize()
@@ -122,7 +105,7 @@ public class BlockCipherParameterSpec implements AlgorithmParameterSpec
/**
* Get the key size of the cipher these parameters are for.
- *
+ *
* @return The block size.
*/
public int getKeySize()
@@ -133,7 +116,7 @@ public class BlockCipherParameterSpec implements AlgorithmParameterSpec
public String toString()
{
return getClass().getName() + " { "
- + ((iv != null) ? ("IV=" + Util.toString(iv)) + ", " : "") + "BS="
- + blockSize + ", KS=" + keySize + " }";
+ + ((iv != null) ? ("IV=" + Util.toString(iv)) + ", " : "")
+ + "BS=" + blockSize + ", KS=" + keySize + " }";
}
}
diff --git a/gnu/javax/crypto/jce/spec/TMMHParameterSpec.java b/gnu/javax/crypto/jce/spec/TMMHParameterSpec.java
index a3b5f26e8..356437288 100644
--- a/gnu/javax/crypto/jce/spec/TMMHParameterSpec.java
+++ b/gnu/javax/crypto/jce/spec/TMMHParameterSpec.java
@@ -46,34 +46,26 @@ import java.security.spec.AlgorithmParameterSpec;
* This class represents the algorithm parameters for the Truncated
* Multi-Modular Hash function for use with JCE-derived instances of
* {@link gnu.javax.crypto.mac.TMMH16}.
- *
- * <p>This class is little more than a container for the key stream, tag
- * length, and prefix parameters for the TMMH algorithm.
+ * <p>
+ * This class is little more than a container for the key stream, tag length,
+ * and prefix parameters for the TMMH algorithm.
*/
-public class TMMHParameterSpec implements AlgorithmParameterSpec
+public class TMMHParameterSpec
+ implements AlgorithmParameterSpec
{
-
- // Constants and variables.
- // -----------------------------------------------------------------------
-
/** The keystream. */
protected IRandom keystream;
-
/** The tag length. */
protected Integer tagLength;
-
/** The prefix. */
protected byte[] prefix;
- // Constructors.
- // -----------------------------------------------------------------------
-
/**
* Create a new parameter specification.
- *
+ *
* @param keystream The (PRNG) key stream.
* @param tagLength The tag length.
- * @param prefix The prefix.
+ * @param prefix The prefix.
*/
public TMMHParameterSpec(IRandom keystream, Integer tagLength, byte[] prefix)
{
@@ -84,7 +76,7 @@ public class TMMHParameterSpec implements AlgorithmParameterSpec
/**
* Create a new parameter specification with no prefix.
- *
+ *
* @param keystream The (PRNG) key stream.
* @param tagLength The tag length.
*/
@@ -93,12 +85,9 @@ public class TMMHParameterSpec implements AlgorithmParameterSpec
this(keystream, tagLength, null);
}
- // Instance methods.
- // -----------------------------------------------------------------------
-
/**
* Return the key stream this specification was initialized with.
- *
+ *
* @return The key stream.
*/
public IRandom getKeystream()
@@ -108,7 +97,7 @@ public class TMMHParameterSpec implements AlgorithmParameterSpec
/**
* Return the tag length this specification was initialized with.
- *
+ *
* @return The tag length.
*/
public Integer getTagLength()
@@ -117,13 +106,12 @@ public class TMMHParameterSpec implements AlgorithmParameterSpec
}
/**
- * Return the prefix, or <code>null</code> if no prefix was
- * specified.
- *
+ * Return the prefix, or <code>null</code> if no prefix was specified.
+ *
* @return The prefix.
*/
public byte[] getPrefix()
{
return prefix;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/jce/spec/UMac32ParameterSpec.java b/gnu/javax/crypto/jce/spec/UMac32ParameterSpec.java
index 47d807d49..0990cc6d4 100644
--- a/gnu/javax/crypto/jce/spec/UMac32ParameterSpec.java
+++ b/gnu/javax/crypto/jce/spec/UMac32ParameterSpec.java
@@ -41,25 +41,19 @@ package gnu.javax.crypto.jce.spec;
import java.security.spec.AlgorithmParameterSpec;
/**
- * This class represents the parameters for the UMAC-32 message
- * authentication code algorithm. In practice this means the
- * <i>Nonce</i> material used to initialize the algorithm.
+ * This class represents the parameters for the UMAC-32 message authentication
+ * code algorithm. In practice this means the <i>Nonce</i> material used to
+ * initialize the algorithm.
*/
-public class UMac32ParameterSpec implements AlgorithmParameterSpec
+public class UMac32ParameterSpec
+ implements AlgorithmParameterSpec
{
-
- // Constants and variables.
- // -----------------------------------------------------------------------
-
/** The <i>Nonce</i> material. */
protected byte[] nonce;
- // Constructors.
- // -----------------------------------------------------------------------
-
/**
* Create a new parameter instance.
- *
+ *
* @param nonce The nonce material.
*/
public UMac32ParameterSpec(byte[] nonce)
@@ -67,16 +61,13 @@ public class UMac32ParameterSpec implements AlgorithmParameterSpec
this.nonce = nonce;
}
- // Instance methods.
- // -----------------------------------------------------------------------
-
/**
* Return the nonce material.
- *
+ *
* @return The nonce material.
*/
public byte[] getNonce()
{
return nonce;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java b/gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java
index 1cf1eb14d..989567f3d 100644
--- a/gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java
+++ b/gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.key.dh;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.hash.Sha160;
import gnu.java.security.key.IKeyPairGenerator;
diff --git a/gnu/javax/crypto/key/dh/RFC2631.java b/gnu/javax/crypto/key/dh/RFC2631.java
index d6e30b4bc..7fcad8d86 100644
--- a/gnu/javax/crypto/key/dh/RFC2631.java
+++ b/gnu/javax/crypto/key/dh/RFC2631.java
@@ -40,7 +40,6 @@ package gnu.javax.crypto.key.dh;
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;
@@ -157,7 +156,7 @@ public class RFC2631
q = U.setBit(m - 1).setBit(0);
// 6. Use a robust primality algorithm to test whether q is prime.
// 7. If q is not prime then go to 4.
- if (Prime2.isProbablePrime(q))
+ if (q.isProbablePrime(80))
{
break step4;
}
@@ -190,7 +189,7 @@ public class RFC2631
// 16. If p > 2^(L-1) use a robust primality test to test whether p is
// prime. Else go to 18.
//17. If p is prime output p, q, seed, counter and stop.
- if (Prime2.isProbablePrime(p))
+ if (p.isProbablePrime(80))
{
break algorithm;
}
diff --git a/gnu/javax/crypto/key/srp6/SRPAlgorithm.java b/gnu/javax/crypto/key/srp6/SRPAlgorithm.java
index b068863ed..e59ab373f 100644
--- a/gnu/javax/crypto/key/srp6/SRPAlgorithm.java
+++ b/gnu/javax/crypto/key/srp6/SRPAlgorithm.java
@@ -38,7 +38,6 @@ exception statement from your version. */
package gnu.javax.crypto.key.srp6;
-import gnu.java.security.util.Prime2;
import gnu.javax.crypto.sasl.srp.SRPRegistry;
import java.math.BigInteger;
@@ -151,13 +150,13 @@ public class SRPAlgorithm
+ SRPRegistry.MINIMUM_MODULUS_BITLENGTH);
}
// 2. N should be a prime
- if (!Prime2.passEulerCriterion(N))
+ if (! N.isProbablePrime(80))
{
throw new IllegalArgumentException("N should be prime but isn't");
}
// 3. N should be of the form 2*q + 1, where q is prime
final BigInteger q = N.subtract(ONE).divide(TWO);
- if (!Prime2.passEulerCriterion(q))
+ if (! q.isProbablePrime(80))
{
throw new IllegalArgumentException("(N-1)/2 should be prime but isn't");
}
diff --git a/gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java b/gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java
index cf1a9cf75..562347c95 100644
--- a/gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java
+++ b/gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java
@@ -38,11 +38,10 @@ exception statement from your version. */
package gnu.javax.crypto.key.srp6;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
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;
@@ -244,10 +243,10 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
q = new BigInteger(1, qBytes);
q = q.setBit(0).setBit(l - 2).clearBit(l - 1);
}
- while (!Prime2.isProbablePrime(q));
+ while (! q.isProbablePrime(80));
p = q.multiply(TWO).add(ONE);
}
- while (p.bitLength() != l || !Prime2.isProbablePrime(p));
+ while (p.bitLength() != l || ! p.isProbablePrime(80));
// compute g. from FIPS-186, Appendix 4: e == 2
BigInteger p_minus_1 = p.subtract(ONE);
diff --git a/gnu/javax/crypto/keyring/AuthenticatedEntry.java b/gnu/javax/crypto/keyring/AuthenticatedEntry.java
index fa77c6ec6..42baf3d33 100644
--- a/gnu/javax/crypto/keyring/AuthenticatedEntry.java
+++ b/gnu/javax/crypto/keyring/AuthenticatedEntry.java
@@ -210,7 +210,7 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
HashMap macAttr = new HashMap();
macAttr.put(IMac.MAC_KEY_MATERIAL, key);
- macAttr.put(IMac.TRUNCATED_SIZE, new Integer(maclen));
+ macAttr.put(IMac.TRUNCATED_SIZE, Integer.valueOf(maclen));
mac.init(macAttr);
return mac;
}
diff --git a/gnu/javax/crypto/keyring/EncryptedEntry.java b/gnu/javax/crypto/keyring/EncryptedEntry.java
index a47a3c6fa..429e31dd0 100644
--- a/gnu/javax/crypto/keyring/EncryptedEntry.java
+++ b/gnu/javax/crypto/keyring/EncryptedEntry.java
@@ -214,7 +214,7 @@ public class EncryptedEntry extends MaskableEnvelopeEntry implements Registry
HashMap modeAttr = new HashMap();
modeAttr.put(IMode.KEY_MATERIAL, key);
- modeAttr.put(IMode.STATE, new Integer(state));
+ modeAttr.put(IMode.STATE, Integer.valueOf(state));
modeAttr.put(IMode.IV, iv);
try
{
diff --git a/gnu/javax/crypto/keyring/Entry.java b/gnu/javax/crypto/keyring/Entry.java
index a2e7e5d21..5a8431f98 100644
--- a/gnu/javax/crypto/keyring/Entry.java
+++ b/gnu/javax/crypto/keyring/Entry.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import java.io.DataInputStream;
import java.io.DataOutputStream;
diff --git a/gnu/javax/crypto/keyring/EnvelopeEntry.java b/gnu/javax/crypto/keyring/EnvelopeEntry.java
index 5e6d38312..58901475c 100644
--- a/gnu/javax/crypto/keyring/EnvelopeEntry.java
+++ b/gnu/javax/crypto/keyring/EnvelopeEntry.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
diff --git a/gnu/javax/crypto/keyring/GnuPrivateKeyring.java b/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
index 5b6829e7b..8ecedcfb9 100644
--- a/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
+++ b/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import java.io.DataInputStream;
diff --git a/gnu/javax/crypto/keyring/GnuPublicKeyring.java b/gnu/javax/crypto/keyring/GnuPublicKeyring.java
index 0828ca1a1..4e036ff63 100644
--- a/gnu/javax/crypto/keyring/GnuPublicKeyring.java
+++ b/gnu/javax/crypto/keyring/GnuPublicKeyring.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import java.io.DataInputStream;
diff --git a/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java b/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java
index e9713b369..e7c1428a4 100644
--- a/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java
+++ b/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.prng.IRandom;
import gnu.java.security.prng.LimitReachedException;
@@ -309,7 +309,7 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
HashMap macAttr = new HashMap();
macAttr.put(IMac.MAC_KEY_MATERIAL, dk);
- macAttr.put(IMac.TRUNCATED_SIZE, new Integer(maclen));
+ macAttr.put(IMac.TRUNCATED_SIZE, Integer.valueOf(maclen));
try
{
mac.init(macAttr);
diff --git a/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java b/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java
index 71c18d855..5670f3ed4 100644
--- a/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java
+++ b/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.prng.IRandom;
import gnu.java.security.prng.LimitReachedException;
@@ -313,7 +313,7 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
}
HashMap modeAttr = new HashMap();
modeAttr.put(IMode.KEY_MATERIAL, dk);
- modeAttr.put(IMode.STATE, new Integer(state));
+ modeAttr.put(IMode.STATE, Integer.valueOf(state));
modeAttr.put(IMode.IV, iv);
try
{
diff --git a/gnu/javax/crypto/keyring/PasswordProtectedEntry.java b/gnu/javax/crypto/keyring/PasswordProtectedEntry.java
index 0dcf73eb8..d5e1df900 100644
--- a/gnu/javax/crypto/keyring/PasswordProtectedEntry.java
+++ b/gnu/javax/crypto/keyring/PasswordProtectedEntry.java
@@ -50,7 +50,7 @@ public interface PasswordProtectedEntry
/**
* The iteration count for password-based KDFs.
*/
- Integer ITERATION_COUNT = new Integer(1000);
+ Integer ITERATION_COUNT = Integer.valueOf(1000);
// Method.
// ------------------------------------------------------------------------
diff --git a/gnu/javax/crypto/mac/OMAC.java b/gnu/javax/crypto/mac/OMAC.java
index b7edb5cdd..dc1f2f43b 100644
--- a/gnu/javax/crypto/mac/OMAC.java
+++ b/gnu/javax/crypto/mac/OMAC.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.mac;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.Util;
import gnu.javax.crypto.cipher.CipherFactory;
diff --git a/gnu/javax/crypto/mac/UHash32.java b/gnu/javax/crypto/mac/UHash32.java
index 8abb0255e..bb38fc8ae 100644
--- a/gnu/javax/crypto/mac/UHash32.java
+++ b/gnu/javax/crypto/mac/UHash32.java
@@ -261,13 +261,13 @@ public class UHash32 extends BaseMac
IRandom kdf4 = new UMacGenerator();
Map map = new HashMap();
map.put(IBlockCipher.KEY_MATERIAL, K);
- map.put(UMacGenerator.INDEX, new Integer(0));
+ map.put(UMacGenerator.INDEX, Integer.valueOf(0));
kdf1.init(map);
- map.put(UMacGenerator.INDEX, new Integer(1));
+ map.put(UMacGenerator.INDEX, Integer.valueOf(1));
kdf2.init(map);
- map.put(UMacGenerator.INDEX, new Integer(2));
+ map.put(UMacGenerator.INDEX, Integer.valueOf(2));
kdf3.init(map);
- map.put(UMacGenerator.INDEX, new Integer(3));
+ map.put(UMacGenerator.INDEX, Integer.valueOf(3));
kdf4.init(map);
// need to generate all bytes for use later in a Toepliz construction
diff --git a/gnu/javax/crypto/mac/UMac32.java b/gnu/javax/crypto/mac/UMac32.java
index 013888856..649df27a2 100644
--- a/gnu/javax/crypto/mac/UMac32.java
+++ b/gnu/javax/crypto/mac/UMac32.java
@@ -447,7 +447,7 @@ public class UMac32 extends BaseMac
Map map = new HashMap();
map.put(IBlockCipher.KEY_MATERIAL, K);
// map.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(128/8));
- map.put(UMacGenerator.INDEX, new Integer(128));
+ map.put(UMacGenerator.INDEX, Integer.valueOf(128));
// map.put(UMacGenerator.CIPHER, Registry.AES_CIPHER);
kdf.init(map);
byte[] Kp = new byte[KEY_LEN];
diff --git a/gnu/javax/crypto/mode/BaseMode.java b/gnu/javax/crypto/mode/BaseMode.java
index f230cbd72..2fcde78a9 100644
--- a/gnu/javax/crypto/mode/BaseMode.java
+++ b/gnu/javax/crypto/mode/BaseMode.java
@@ -178,7 +178,7 @@ public abstract class BaseMode implements IMode
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(cipherBlockSize));
+ al.add(Integer.valueOf(cipherBlockSize));
return Collections.unmodifiableList(al).iterator();
}
@@ -320,10 +320,10 @@ public abstract class BaseMode implements IMode
Map map = new HashMap();
map.put(KEY_MATERIAL, k);
- map.put(CIPHER_BLOCK_SIZE, new Integer(cipherBlockSize));
- map.put(STATE, new Integer(ENCRYPTION));
+ map.put(CIPHER_BLOCK_SIZE, Integer.valueOf(cipherBlockSize));
+ map.put(STATE, Integer.valueOf(ENCRYPTION));
map.put(IV, iv);
- map.put(MODE_BLOCK_SIZE, new Integer(bs));
+ map.put(MODE_BLOCK_SIZE, Integer.valueOf(bs));
mode.reset();
mode.init(map);
@@ -333,7 +333,7 @@ public abstract class BaseMode implements IMode
}
mode.reset();
- map.put(STATE, new Integer(DECRYPTION));
+ map.put(STATE, Integer.valueOf(DECRYPTION));
mode.init(map);
for (i = 0; i < blockCount; i++)
{
diff --git a/gnu/javax/crypto/mode/EAX.java b/gnu/javax/crypto/mode/EAX.java
index bf2609898..2aa2df540 100644
--- a/gnu/javax/crypto/mode/EAX.java
+++ b/gnu/javax/crypto/mode/EAX.java
@@ -200,12 +200,12 @@ public class EAX implements IAuthenticatedMode
Integer modeSize = (Integer) attrib.get(MODE_BLOCK_SIZE);
if (modeSize == null)
{
- modeSize = new Integer(cipherBlockSize);
+ modeSize = Integer.valueOf(cipherBlockSize);
}
HashMap ctrAttr = new HashMap();
ctrAttr.put(KEY_MATERIAL, key);
ctrAttr.put(IV, N);
- ctrAttr.put(STATE, new Integer(ENCRYPTION));
+ ctrAttr.put(STATE, Integer.valueOf(ENCRYPTION));
ctrAttr.put(MODE_BLOCK_SIZE, modeSize);
ctr.reset();
ctr.init(ctrAttr);
diff --git a/gnu/javax/crypto/pad/BasePad.java b/gnu/javax/crypto/pad/BasePad.java
index b54c77078..440026d8e 100644
--- a/gnu/javax/crypto/pad/BasePad.java
+++ b/gnu/javax/crypto/pad/BasePad.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.pad;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import java.util.logging.Level;
import java.util.logging.Logger;
diff --git a/gnu/javax/crypto/pad/PKCS1_V1_5.java b/gnu/javax/crypto/pad/PKCS1_V1_5.java
index 874908493..277097666 100644
--- a/gnu/javax/crypto/pad/PKCS1_V1_5.java
+++ b/gnu/javax/crypto/pad/PKCS1_V1_5.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.pad;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.sig.rsa.EME_PKCS1_V1_5;
import gnu.java.security.util.PRNG;
diff --git a/gnu/javax/crypto/pad/PKCS7.java b/gnu/javax/crypto/pad/PKCS7.java
index d9084d13f..28c35d197 100644
--- a/gnu/javax/crypto/pad/PKCS7.java
+++ b/gnu/javax/crypto/pad/PKCS7.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.pad;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.Util;
diff --git a/gnu/javax/crypto/pad/TBC.java b/gnu/javax/crypto/pad/TBC.java
index 64fea18fd..7302ef15b 100644
--- a/gnu/javax/crypto/pad/TBC.java
+++ b/gnu/javax/crypto/pad/TBC.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.pad;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.Util;
diff --git a/gnu/javax/crypto/prng/CSPRNG.java b/gnu/javax/crypto/prng/CSPRNG.java
index 0e39f0f5a..910d15fec 100644
--- a/gnu/javax/crypto/prng/CSPRNG.java
+++ b/gnu/javax/crypto/prng/CSPRNG.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.prng;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Properties;
import gnu.java.security.Registry;
import gnu.java.security.hash.HashFactory;
diff --git a/gnu/javax/crypto/prng/ICMGenerator.java b/gnu/javax/crypto/prng/ICMGenerator.java
index 7d4f4c9a3..1bfba64d6 100644
--- a/gnu/javax/crypto/prng/ICMGenerator.java
+++ b/gnu/javax/crypto/prng/ICMGenerator.java
@@ -214,7 +214,7 @@ public class ICMGenerator extends BasePRNG implements Cloneable
HashMap map = new HashMap();
if (cipherBlockSize != 0)
{ // only needed if new or changed
- map.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(cipherBlockSize));
+ map.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(cipherBlockSize));
}
map.put(IBlockCipher.KEY_MATERIAL, key);
try
diff --git a/gnu/javax/crypto/prng/UMacGenerator.java b/gnu/javax/crypto/prng/UMacGenerator.java
index 0e3725ce9..f7b7a16a0 100644
--- a/gnu/javax/crypto/prng/UMacGenerator.java
+++ b/gnu/javax/crypto/prng/UMacGenerator.java
@@ -198,7 +198,7 @@ public class UMacGenerator extends BasePRNG implements Cloneable
Map map = new HashMap();
if (cipherBlockSize != 0)
{ // only needed if new or changed
- map.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(cipherBlockSize));
+ map.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(cipherBlockSize));
}
map.put(IBlockCipher.KEY_MATERIAL, key);
try
diff --git a/gnu/javax/crypto/sasl/SaslInputStream.java b/gnu/javax/crypto/sasl/SaslInputStream.java
index 14de9e12f..1bd305f5f 100644
--- a/gnu/javax/crypto/sasl/SaslInputStream.java
+++ b/gnu/javax/crypto/sasl/SaslInputStream.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.sasl;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.util.Util;
import java.io.IOException;
diff --git a/gnu/javax/crypto/sasl/SaslOutputStream.java b/gnu/javax/crypto/sasl/SaslOutputStream.java
index 9d2aa020d..ce9d93242 100644
--- a/gnu/javax/crypto/sasl/SaslOutputStream.java
+++ b/gnu/javax/crypto/sasl/SaslOutputStream.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.sasl;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.util.Util;
import java.io.IOException;
diff --git a/gnu/javax/crypto/sasl/srp/KDF.java b/gnu/javax/crypto/sasl/srp/KDF.java
index 0d5eeacd1..7a761cc06 100644
--- a/gnu/javax/crypto/sasl/srp/KDF.java
+++ b/gnu/javax/crypto/sasl/srp/KDF.java
@@ -88,8 +88,8 @@ public class KDF
// }
final HashMap map = new HashMap();
map.put(UMacGenerator.CIPHER, Registry.AES_CIPHER);
- map.put(UMacGenerator.INDEX, new Integer(ndx));
- map.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(AES_BLOCK_SIZE));
+ map.put(UMacGenerator.INDEX, Integer.valueOf(ndx));
+ map.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(AES_BLOCK_SIZE));
final byte[] key = new byte[AES_KEY_SIZE];
System.arraycopy(keyMaterial, 0, key, 0, AES_KEY_SIZE);
map.put(IBlockCipher.KEY_MATERIAL, key);
diff --git a/gnu/javax/crypto/sasl/srp/SRPClient.java b/gnu/javax/crypto/sasl/srp/SRPClient.java
index 0430342eb..231a49480 100644
--- a/gnu/javax/crypto/sasl/srp/SRPClient.java
+++ b/gnu/javax/crypto/sasl/srp/SRPClient.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.sasl.srp;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.hash.MD5;
import gnu.java.security.util.PRNG;
diff --git a/gnu/javax/crypto/sasl/srp/SRPServer.java b/gnu/javax/crypto/sasl/srp/SRPServer.java
index 18452555c..fa7cdae9c 100644
--- a/gnu/javax/crypto/sasl/srp/SRPServer.java
+++ b/gnu/javax/crypto/sasl/srp/SRPServer.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.sasl.srp;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import gnu.java.security.util.PRNG;
import gnu.java.security.util.Util;
diff --git a/gnu/javax/imageio/gif/GIFFile.java b/gnu/javax/imageio/gif/GIFFile.java
new file mode 100644
index 000000000..a11a8c0c6
--- /dev/null
+++ b/gnu/javax/imageio/gif/GIFFile.java
@@ -0,0 +1,709 @@
+/* GIFFile.java -- GIF decoder
+ 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.javax.imageio.gif;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Vector;
+
+/**
+ * GIFFile - reads a GIF file.
+ *
+ * This class only does the bare minimum work, and returns the data in raw
+ * formats (described below). The class is J2ME compatible, and hopefully
+ * we can keep it that way without any significant overhead.
+ *
+ * @author Sven de Marothy.
+ */
+public class GIFFile
+{
+ // "NETSCAPE2.0" - identifier
+ private final static byte[] nsBlock = new byte[]
+ {0x4e, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2e, 0x30 };
+
+ /**
+ * Block identifiers
+ */
+ private final static int EXTENSION = 0x21;
+ private final static int LOCAL = 0x2C;
+ private final static int TERMINATOR = 0x3B;
+
+ /**
+ * Extension block types
+ */
+ private final static int EXTENSION_COMMENT = 254;
+ private final static int EXTENSION_GCONTROL = 249;
+ private final static int EXTENSION_APPLICATION = 255;
+
+ /**
+ * Undraw commands for animation.
+ */
+ private final static int UNDRAW_OVERWRITE = 1;
+ private final static int UNDRAW_RESTORE_BACKGROUND = 2;
+ private final static int UNDRAW_RESTORE_PREVIOUS = 3;
+
+ /**
+ * Image position and dimensions (images may be partial)
+ */
+ private int x, y, width, height;
+
+ /**
+ * Global dimensions
+ */
+ private int globalWidth, globalHeight;
+
+ /**
+ * Background color index.
+ */
+ private byte bgIndex;
+
+ /**
+ * Number of colors
+ */
+ private int nColors;
+
+ /**
+ * Global palette, if any
+ */
+ private byte[] globalPalette;
+
+ /**
+ * Any
+ */
+ private boolean hasGlobalColorMap;
+
+ /**
+ * Local palette, if any (used if available)
+ */
+ private byte[] localPalette;
+
+ /**
+ * Interlaced GIF or not?
+ */
+ private boolean interlaced;
+
+ /**
+ * Has transparency?
+ */
+ private boolean hasTransparency;
+
+ /**
+ * Undraw mode (animations)
+ */
+ private int undraw;
+
+ /**
+ * Transparent index;
+ */
+ private int transparentIndex;
+
+ /**
+ * The uncompressed raster
+ */
+ private byte[] raster;
+
+ /**
+ * The compressed data (freed after uncompressing)
+ */
+ private byte[] compressedData;
+
+ /**
+ * Frame delay in 100ths of a second ( centiseconds, metrically )
+ */
+ private int duration;
+
+ /**
+ * Indices used during decompression
+ */
+ private int dataBlockIndex;
+
+ /**
+ * The file comment , if a comment block exists.
+ */
+ private String comment;
+
+ /**
+ * Fields used by getBits()
+ */
+ private int remainingBits = 0;
+ private int currentBits = 0;
+
+ /**
+ * Netscape animation extension
+ */
+ private boolean isLooped = false;
+
+ /** Number of loops, 0 = infinite */
+ private int loops;
+
+ /**
+ * Additional frames if it's an animated GIF.
+ */
+ private Vector animationFrames;
+
+ /**
+ * Loads the file from an input stream, which is not closed.
+ * @throws IOException if an I/O error occured.
+ * @throws GIFException if some file parsing error occured
+ */
+ public GIFFile(InputStream in) throws IOException, GIFException
+ {
+ // Validate the signature
+ if( !readSignature( in ) )
+ throw new GIFException("Invalid GIF signature.");
+
+ {
+ byte[] data = new byte[7];
+ if (in.read(data) != 7)
+ throw new IOException("Couldn't read global descriptor.");
+
+ globalWidth = ((data[1] & 0xFF) << 8) | (data[0] & 0xFF);
+ globalHeight = ((data[3] & 0xFF) << 8) | (data[2] & 0xFF);
+ byte flags = data[4];
+ bgIndex = data[5];
+ nColors = (1 << (( flags & 0x07) + 1));
+ hasGlobalColorMap = ((flags & 0x80) != 0);
+ }
+
+ if( hasGlobalColorMap )
+ {
+ globalPalette = new byte[ nColors * 3 ];
+ if( in.read( globalPalette ) != nColors * 3 )
+ throw new IOException("Couldn't read color map.");
+ }
+
+ int c = in.read();
+ while( c == EXTENSION )
+ {
+ readExtension( in );
+ c = in.read();
+ }
+
+ if( c != LOCAL )
+ throw new GIFException("Extension blocks not followed by a local descriptor ("+c+")");
+
+ loadImage( in );
+ c = in.read();
+
+ if( c == TERMINATOR ) // Not an animated GIF.
+ return;
+
+ // Load animation frames. Just quit if an error occurs instead
+ // of throwing an exception.
+ animationFrames = new Vector();
+ try
+ {
+ while( c != TERMINATOR )
+ {
+ animationFrames.add( new GIFFile( this, in, c ) );
+ c = in.read();
+ }
+ }
+ catch(IOException ioe)
+ {
+ }
+ catch(GIFException gife)
+ {
+ }
+ }
+
+ /**
+ * Constructor for additional animation frames.
+ */
+ private GIFFile(GIFFile parent, InputStream in, int c)
+ throws IOException, GIFException
+ {
+ // Copy global properties.
+ globalWidth = parent.globalWidth;
+ globalHeight = parent.globalHeight;
+ nColors = parent.nColors;
+ globalPalette = parent.globalPalette;
+ hasGlobalColorMap = parent.hasGlobalColorMap;
+ interlaced = parent.interlaced;
+ comment = parent.comment;
+ isLooped = parent.isLooped;
+ loops = parent.loops;
+
+ while( c == EXTENSION )
+ {
+ readExtension( in );
+ c = in.read();
+ }
+
+ if( c != LOCAL )
+ throw new GIFException("Extension blocks not followed by a local descriptor ("+c+")");
+
+ loadImage( in );
+ }
+
+ /**
+ * Reads a GIF file signature from an inputstream and checks it.
+ *
+ * @param in - the stream (reads 6 bytes, does not close or reset).
+ * @return true if the signature is a valid GIF signature.
+ * @throws an IOException if the signature could not be read.
+ */
+ public static boolean readSignature( InputStream in ) throws IOException
+ {
+ byte[] data = new byte[6];
+ if (in.read(data) != 6)
+ throw new IOException("Couldn't read signature.");
+
+ if( data[0] != 0x47 || data[1] != 0x49 || data[2] != 0x46 ||
+ data[3] != 0x38 ) // GIF8
+ return false;
+
+ if( (data[4] != 0x39 && data[4] != 0x37) || // 7 | 9
+ (data[5] != 0x61 && data[5] != 0x62) ) // 'a' or 'b'
+ return false;
+ return true;
+ }
+
+
+ /**
+ * Loads the image local descriptor and then loads/decodes the image raster,
+ * and then performs any necessary postprocessing like deinterlacing.
+ */
+ private void loadImage(InputStream in)
+ throws IOException, GIFException
+ {
+ readLocal( in );
+
+ try
+ {
+ decodeRaster( in );
+ }
+ catch(ArrayIndexOutOfBoundsException aioobe)
+ {
+ throw new GIFException("Error decompressing image.");
+ }
+
+ if( interlaced ) // Clean up
+ deinterlace();
+ packPixels();
+ }
+
+ /**
+ * Pack the pixels if it's a 2, 4 or 16 color image.
+ * While GIF may support any number of colors from 2-256, we won't bother
+ * trying to pack pixels not resulting in even byte boundaries.
+ * (AWT doesn't support that anyway, and most apps do the same.)
+ */
+ private void packPixels()
+ {
+ if( nColors != 2 && nColors != 4 && nColors != 16 )
+ return;
+
+ int nbits = 1;
+ int ppbyte = 8;
+ if( nColors == 4 )
+ {
+ nbits = 2;
+ ppbyte = 4;
+ }
+ else if( nColors == 16 )
+ {
+ nbits = 4;
+ ppbyte = 2;
+ }
+
+ int rem = (width & (ppbyte - 1));
+ int w = ( rem == 0 ) ? (width / ppbyte) :
+ ((width + ppbyte - rem) / ppbyte);
+ byte[] nr = new byte[ w * height ];
+ for(int j = 0; j < height; j++)
+ {
+ for(int i = 0; i < width - ppbyte; i += ppbyte)
+ for(int k = 0; k < ppbyte; k++)
+ nr[ j * w + (i / ppbyte) ] |= (byte)((raster[ width * j + i + k ]
+ << (8 - nbits * (1 + k))));
+ for(int i = 0; i < rem; i++)
+ nr[ j * w + w - 1 ] |= (byte)((raster[ width * j + width - rem + i ]
+ << (nbits * (rem - i))));
+ }
+ raster = nr;
+ }
+
+ /**
+ * Returns the (global) width
+ */
+ public int getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Returns the image height
+ */
+ public int getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Returns the # of colors.
+ */
+ public int getNColors()
+ {
+ return nColors;
+ }
+
+ /**
+ * Returns whether the GIF has transparency.
+ */
+ public boolean hasTransparency()
+ {
+ return hasTransparency;
+ }
+
+ /**
+ * Returns the index of the transparent color.
+ */
+ public int getTransparentIndex()
+ {
+ return transparentIndex;
+ }
+
+ /**
+ * Retuns the GIF file comment, or null if none exists.
+ */
+ public String getComment()
+ {
+ return comment;
+ }
+
+ /**
+ * Get duration of the frame for animations.
+ */
+ public int getDuration()
+ {
+ return duration;
+ }
+
+ /**
+ * Deinterlaces the image.
+ */
+ private void deinterlace()
+ {
+ byte[] nr = new byte[ width * height ];
+ int n = 0;
+ for(int i = 0; i < ((height + 7) >> 3); i++)
+ {
+ System.arraycopy( raster, n, nr, width * i * 8, width );
+ n += width;
+ }
+ for(int i = 0; i < ((height + 3) >> 3); i++)
+ {
+ System.arraycopy( raster, n, nr, width * ( 8 * i + 4 ), width );
+ n += width;
+ }
+ for(int i = 0; i < (height >> 2); i++)
+ {
+ System.arraycopy( raster, n, nr, width * (4 * i + 2), width );
+ n += width;
+ }
+ for(int i = 0; i < (height >> 1); i++)
+ {
+ System.arraycopy( raster, n, nr, width * (2 * i + 1), width );
+ n += width;
+ }
+ raster = nr;
+ }
+
+ /**
+ * Reads the local descriptor
+ */
+ private void readLocal(InputStream in) throws IOException
+ {
+ byte[] data = new byte[9];
+ if (in.read(data) != 9)
+ throw new IOException("Couldn't read local descriptor.");
+ x = ((data[1] & 0xFF) << 8) | (data[0] & 0xFF);
+ y = ((data[3] & 0xFF) << 8) | (data[2] & 0xFF);
+ width = ((data[5] & 0xFF) << 8) | (data[4] & 0xFF);
+ height = ((data[7] & 0xFF) << 8) | (data[6] & 0xFF);
+ byte flags = data[8];
+ interlaced = (( flags & 0x40 ) != 0);
+ if( (flags & 0x80) != 0 )
+ { // has a local color map
+ int nLocalColors = (1 << (( flags & 0x07) + 1));
+ if( !hasGlobalColorMap )
+ nColors = nLocalColors;
+ localPalette = new byte[ nLocalColors * 3 ];
+ if( in.read( localPalette ) != nLocalColors * 3 )
+ throw new IOException("Couldn't read color map.");
+ }
+ }
+
+ /**
+ * Returns the image's palette in raw format
+ * (r0,g0,b0,r1,g1,b2..r(Ncolors-1),g(Ncolors-1),b(Ncolors-1))
+ */
+ public byte[] getRawPalette()
+ {
+ return hasGlobalColorMap ? globalPalette : localPalette;
+ }
+
+ /**
+ * Returns the image file for animated gifs.
+ */
+ public GIFFile getImage( int index )
+ {
+ if( index == 0 )
+ return this;
+ if( animationFrames == null )
+ throw new ArrayIndexOutOfBoundsException("Only one image in file");
+ return (GIFFile)animationFrames.elementAt( index - 1 );
+ }
+
+ /**
+ * Return the image's raw image data.
+ * If the color depth is 1,2 or 4 bits per pixel the pixels are packed
+ * and the scanlines padded up to the nearest byte if needed.
+ */
+ public byte[] getRawImage()
+ {
+ return raster;
+ }
+
+ /**
+ * Return the number of images in the GIF file
+ */
+ public int nImages()
+ {
+ if( animationFrames != null )
+ return 1 + animationFrames.size();
+ return 1;
+ }
+
+ /**
+ * Handles extension blocks.
+ */
+ private void readExtension(InputStream in) throws IOException, GIFException
+ {
+ int functionCode = in.read();
+ byte[] data = readData(in);
+ switch( functionCode )
+ {
+ case EXTENSION_COMMENT: // comment block
+ comment = new String(data, "8859_1");
+ break;
+
+ case EXTENSION_GCONTROL: // Graphics control extension
+ undraw = (data[0] & 0x1C) >> 2;
+ // allegedly there can be bad values of this.
+ if( undraw < 1 && undraw > 3 ) undraw = 1;
+ hasTransparency = ((data[0] & 0x01) == 1);
+ transparentIndex = (data[3] & 0xFF);
+ duration = ((data[2] & 0xFF) << 8) | (data[1] & 0xFF);
+ break;
+
+ // Application extension. We only parse the Netscape animation
+ // extension here. Which is the only one most use anyway.
+ case EXTENSION_APPLICATION:
+ boolean isNS = true;
+ for(int i = 0; i < nsBlock.length; i++ )
+ if( nsBlock[i] != data[i] )
+ isNS = false;
+ if( isNS )
+ {
+ isLooped = true;
+ loops = ((data[12] & 0xFF) << 8) | (data[13] & 0xFF);
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Reads a series of data blocks and merges them into a single one.
+ */
+ private byte[] readData(InputStream in) throws IOException
+ {
+ Vector v = new Vector();
+ int totalBytes = 0;
+
+ int n = in.read();
+ do
+ {
+ totalBytes += n;
+ byte[] block = new byte[ n ];
+ in.read(block);
+ v.add(block);
+ n = in.read();
+ }
+ while( n > 0 );
+
+ n = 0;
+ byte[] bigBuffer = new byte[ totalBytes ];
+ for( int i = 0; i < v.size(); i++ )
+ {
+ byte[] block = (byte[])v.elementAt(i);
+ System.arraycopy(block, 0, bigBuffer, n, block.length);
+ n += block.length;
+ }
+ return bigBuffer;
+ }
+
+ /**
+ * Loads a compressed image block and decompresses it.
+ */
+ private void decodeRaster(InputStream in) throws IOException
+ {
+ int initialCodeSize = in.read();
+ compressedData = readData( in );
+ dataBlockIndex = 0;
+
+ int rasterIndex = 0; // Index into the raster
+ int clearCode = (1 << initialCodeSize); // 256 usually
+ int endCode = clearCode + 1; // The stop code.
+
+ raster = new byte[ width * height ];
+
+ int codeSize = initialCodeSize + 1;
+ int code = getBits( codeSize ); // = clear
+ int nextCode = endCode + 1;
+
+ /*
+ * Initialize LZW dictionary
+ *
+ * First index - code #
+ * Second index:
+ * 0 = color index
+ * 1 = parent (-1 - no parent)
+ * 2 = first value
+ * 3 - depth
+ * The latter two aren't strictly necessary but make things faster, since
+ * copying the values forward is faster than going back and looking.
+ */
+ short[][] dictionary = new short[ 4096 ][ 4 ];
+
+ for(short i = 0; i < nColors; i ++ )
+ {
+ dictionary[i][0] = i; // color index
+ dictionary[i][1] = -1; // parent
+ dictionary[i][2] = i; // first
+ dictionary[i][3] = 1; // depth
+ }
+
+ code = getBits( codeSize ); // get second code
+ raster[ rasterIndex++ ] = (byte)dictionary[code][0];
+ int old = code;
+ code = getBits( codeSize ); // start at the third code
+ int c;
+
+ do
+ {
+ if( code == clearCode )
+ {
+ codeSize = initialCodeSize + 1;
+ nextCode = endCode + 1;
+ // get and output second code
+ code = getBits( codeSize );
+ raster[ rasterIndex++ ] = (byte)dictionary[code][0];
+ old = code;
+ }
+ else
+ {
+ dictionary[nextCode][1] = (short)old; // parent = old
+ dictionary[nextCode][2] = dictionary[old][2]; // first pixel
+ dictionary[nextCode][3] = (short)(dictionary[old][3] + 1); // depth
+
+ // appended pixel = first pixel of c
+ if( code < nextCode )
+ {
+ dictionary[nextCode][0] = dictionary[code][2];
+ old = code;
+ }
+ else // first of old
+ {
+ dictionary[nextCode][0] = dictionary[old][2];
+ old = nextCode;
+ }
+
+ c = old;
+ // output the code c
+ int depth = dictionary[c][3];
+ for( int i = depth - 1; i >= 0; i-- )
+ {
+ raster[ rasterIndex + i ] = (byte)dictionary[c][0];
+ c = dictionary[c][1]; // go to parent.
+ }
+ rasterIndex += depth;
+ nextCode ++;
+
+ if( codeSize < 12 && nextCode >= (1 << codeSize) )
+ codeSize++;
+ }
+ code = getBits( codeSize );
+ }
+ while( code != endCode && dataBlockIndex < compressedData.length );
+
+ compressedData = null; // throw away compressed data.
+ }
+
+ /**
+ * Returns nbits number of bits (in the LSBs) from compressedData
+ */
+ private int getBits( int nbits )
+ {
+ while( nbits > remainingBits )
+ {
+ int c = (compressedData[ dataBlockIndex++ ] & 0xFF) << remainingBits;
+ currentBits |= c;
+ remainingBits += 8;
+ }
+ int rval = (currentBits & ((1 << nbits) - 1));
+ currentBits = (currentBits >> nbits);
+ remainingBits -= nbits;
+ return rval;
+ }
+
+ /**
+ * Generic exception used by GIFFile to report decoding errors.
+ */
+ public static class GIFException extends Exception
+ {
+ public GIFException(String message)
+ {
+ super(message);
+ }
+ }
+}
diff --git a/gnu/javax/imageio/gif/GIFImageReader.java b/gnu/javax/imageio/gif/GIFImageReader.java
new file mode 100644
index 000000000..24e3d46db
--- /dev/null
+++ b/gnu/javax/imageio/gif/GIFImageReader.java
@@ -0,0 +1,242 @@
+/* GIFImageReader.java --
+ 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.javax.imageio.gif;
+
+import java.io.IOException;
+import java.io.InputStream;
+import javax.imageio.*;
+import javax.imageio.spi.*;
+import javax.imageio.metadata.*;
+import javax.imageio.stream.ImageInputStream;
+import java.util.Iterator;
+import java.awt.image.BufferedImage;
+import java.awt.image.IndexColorModel;
+import java.awt.image.SampleModel;
+import java.awt.image.MultiPixelPackedSampleModel;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferByte;
+import java.awt.image.Raster;
+import java.awt.image.WritableRaster;
+
+public class GIFImageReader extends ImageReader
+{
+ private GIFFile file;
+
+ protected GIFImageReader(ImageReaderSpi originatingProvider)
+ {
+ super( originatingProvider );
+ file = null;
+ }
+
+ private void readImage() throws IOException
+ {
+ if( file != null )
+ return;
+
+ try
+ {
+ if( input instanceof InputStream )
+ file = new GIFFile( (InputStream)input );
+ else
+ file = new GIFFile( new GIFStream((ImageInputStream)input) );
+ }
+ catch(GIFFile.GIFException ge)
+ {
+ throw new IIOException(ge.getMessage());
+ }
+ }
+
+ /**
+ * Returns the Global/Local palette as an IndexColorModel
+ */
+ private IndexColorModel getPalette(int index)
+ {
+ GIFFile f = file.getImage( index );
+ byte[] data = f.getRawPalette();
+ int nc = f.getNColors();
+ byte[] r = new byte[nc];
+ byte[] g = new byte[nc];
+ byte[] b = new byte[nc];
+
+ for(int i = 0; i < nc; i ++ )
+ {
+ r[i] = data[ i * 3 ];
+ g[i] = data[ i * 3 + 1 ];
+ b[i] = data[ i * 3 + 2 ];
+ }
+
+ if( f.hasTransparency() )
+ {
+ byte[] a = new byte[nc];
+ for(int i = 0; i < nc; i ++ )
+ a[i] = (byte)0xFF;
+ a[f.getTransparentIndex()] = 0;
+ return new IndexColorModel(8, nc, r, g, b, a);
+ }
+
+ return new IndexColorModel(8, nc, r, g, b);
+ }
+
+ private void validateIndex(int imageIndex)
+ throws IndexOutOfBoundsException
+ {
+ if( imageIndex < 0 || imageIndex >= getNumImages(false) )
+ throw new IndexOutOfBoundsException("Invalid image index.");
+ }
+
+ public void setInput(Object input)
+ {
+ super.setInput(input);
+ }
+
+ public void setInput(Object input,
+ boolean seekForwardOnly,
+ boolean ignoreMetadata)
+ {
+ super.setInput(input, seekForwardOnly, ignoreMetadata);
+ }
+
+ public void setInput(Object input, boolean isStreamable)
+ {
+ super.setInput(input, isStreamable);
+
+ if (!(input instanceof ImageInputStream) &&
+ !(input instanceof InputStream))
+ throw new IllegalArgumentException("Input not an ImageInputStream.");
+ }
+
+ private void checkStream() throws IOException
+ {
+ if (!(input instanceof ImageInputStream) &&
+ !(input instanceof InputStream))
+ throw new IllegalStateException("Input not an ImageInputStream or InputStream.");
+
+ if(input == null)
+ throw new IllegalStateException("No input stream.");
+ }
+
+ public int getWidth(int imageIndex) throws IOException
+ {
+ validateIndex( imageIndex );
+ return file.getImage( imageIndex ).getWidth();
+ }
+
+ public int getHeight(int imageIndex) throws IOException
+ {
+ validateIndex( imageIndex );
+ return file.getImage( imageIndex ).getHeight();
+ }
+
+ public Iterator getImageTypes(int imageIndex)
+ {
+ validateIndex( imageIndex );
+ return null;
+ }
+
+ /**
+ * Returns the number of images.
+ */
+ public int getNumImages(boolean allowSearch)
+ {
+ try // Image should be loaded here already. But just in case:
+ {
+ readImage();
+ }
+ catch(IOException ioe)
+ {
+ return 0; // Well, now we're in trouble. But return something anyway.
+ }
+ return file.nImages();
+ }
+
+
+ // FIXME: Support metadata
+ public IIOMetadata getImageMetadata(int imageIndex)
+ {
+ validateIndex( imageIndex );
+ return null;
+ }
+
+ // FIXME: Support metadata
+ public IIOMetadata getStreamMetadata()
+ {
+ return null;
+ }
+
+ /**
+ * Reads the image indexed by imageIndex and returns it as
+ * a complete BufferedImage, using a supplied ImageReadParam.
+ */
+ public BufferedImage read(int imageIndex, ImageReadParam param)
+ throws IOException, IIOException
+ {
+ validateIndex( imageIndex );
+ GIFFile f = file.getImage( imageIndex );
+ int width = f.getWidth();
+ int height = f.getHeight();
+ SampleModel sm;
+ switch( f.getNColors() )
+ {
+ case 16:
+ sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
+ width, height, 4);
+ break;
+ case 4:
+ sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
+ width, height, 2);
+ break;
+ case 2:
+ sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
+ width, height, 1);
+ break;
+ default:
+ sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE,
+ width, height,
+ new int[] {0xFF});
+ break;
+ }
+ byte[] bits = f.getRawImage();
+ for(int i = 0; i < 5; i++)
+ System.out.println("Bits "+i+":"+bits[i]);
+ DataBuffer db = new DataBufferByte(f.getRawImage(), width * height, 0);
+ WritableRaster raster = Raster.createWritableRaster(sm, db, null);
+
+ return new BufferedImage(getPalette( imageIndex ), raster, false, null);
+ }
+}
diff --git a/gnu/javax/imageio/gif/GIFImageReaderSpi.java b/gnu/javax/imageio/gif/GIFImageReaderSpi.java
new file mode 100644
index 000000000..a7b3ceb03
--- /dev/null
+++ b/gnu/javax/imageio/gif/GIFImageReaderSpi.java
@@ -0,0 +1,122 @@
+/* GIFImageReaderSpi.java --
+ 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.javax.imageio.gif;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Locale;
+import javax.imageio.ImageReader;
+import javax.imageio.spi.ImageReaderSpi;
+import javax.imageio.stream.ImageInputStream;
+
+public class GIFImageReaderSpi extends ImageReaderSpi
+{
+ static final String vendorName = "GNU";
+ static final String version = "0.1";
+ static final String readerClassName =
+ "gnu.javax.imageio.gif.GIFImageReader";
+ static final String[] names = { "Compuserve GIF" };
+ static final String[] suffixes = { ".gif" };
+ static final String[] MIMETypes = {
+ "image/gif",
+ "image/x-gif"}; // Not sure this is legal, but it seems to be used a bit
+ static final String[] writerSpiNames = null;
+ static final boolean supportsStandardStreamMetadataFormat = false;
+ static final String nativeStreamMetadataFormatName = null;
+ static final String nativeStreamMetadataFormatClassName = null;
+ static final String[] extraStreamMetadataFormatNames = null;
+ static final String[] extraStreamMetadataFormatClassNames = null;
+ static final boolean supportsStandardImageMetadataFormat = false;
+ static final String nativeImageMetadataFormatName = null;
+ static final String nativeImageMetadataFormatClassName = null;
+ static final String[] extraImageMetadataFormatNames = null;
+ static final String[] extraImageMetadataFormatClassNames = null;
+
+ public GIFImageReaderSpi()
+ {
+ super(vendorName, version,
+ names, suffixes, MIMETypes,
+ readerClassName,
+ new Class[]{ ImageInputStream.class, InputStream.class },
+ writerSpiNames,
+ supportsStandardStreamMetadataFormat,
+ nativeStreamMetadataFormatName,
+ nativeStreamMetadataFormatClassName,
+ extraStreamMetadataFormatNames,
+ extraStreamMetadataFormatClassNames,
+ supportsStandardImageMetadataFormat,
+ nativeImageMetadataFormatName,
+ nativeImageMetadataFormatClassName,
+ extraImageMetadataFormatNames,
+ extraImageMetadataFormatClassNames);
+ }
+
+ public String getDescription(Locale locale)
+ {
+ return "Compuserve GIF";
+ }
+
+ public boolean canDecodeInput(Object input)
+ throws IOException
+ {
+ if( input == null )
+ throw new IllegalArgumentException("Input object cannot be null.");
+
+ if( !(input instanceof ImageInputStream) &&
+ !(input instanceof InputStream))
+ return false;
+
+ boolean retval;
+ InputStream in;
+ if( input instanceof ImageInputStream )
+ in = new GIFStream( (ImageInputStream)input );
+ else
+ in = (InputStream)input;
+
+ in.mark(10); // we read 6 bytes
+ retval = GIFFile.readSignature( in );
+ in.reset();
+
+ return retval;
+ }
+
+ public ImageReader createReaderInstance(Object extension)
+ {
+ return new GIFImageReader(this);
+ }
+}
diff --git a/gnu/javax/imageio/gif/GIFStream.java b/gnu/javax/imageio/gif/GIFStream.java
new file mode 100644
index 000000000..630d587b8
--- /dev/null
+++ b/gnu/javax/imageio/gif/GIFStream.java
@@ -0,0 +1,102 @@
+/* GIFStream.java --
+ 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.javax.imageio.gif;
+
+import java.io.InputStream;
+import java.io.IOException;
+import javax.imageio.stream.ImageInputStream;
+
+/**
+ * Implements InputStream on an ImageInputStream
+ * The purpose of this is to avoid IIO dependencies in GIFFile
+ * (which only uses read() anyway).
+ */
+public class GIFStream extends InputStream
+{
+ private ImageInputStream is;
+
+ public GIFStream( ImageInputStream is )
+ {
+ this.is = is;
+ }
+
+ public int available()
+ {
+ return 0;
+ }
+
+ public void close() throws IOException
+ {
+ is.close();
+ }
+
+ public void mark(int readlimit)
+ {
+ is.mark();
+ }
+
+ public boolean markSupported()
+ {
+ return true;
+ }
+
+ public int read() throws IOException
+ {
+ return is.read();
+ }
+
+ public int read(byte[] b) throws IOException
+ {
+ return is.read(b);
+ }
+
+ public int read(byte[] b, int offset, int length) throws IOException
+ {
+ return is.read(b, offset, length);
+ }
+
+ public void reset() throws IOException
+ {
+ is.reset();
+ }
+
+ public long skip(long n) throws IOException
+ {
+ return is.skipBytes(n);
+ }
+}
diff --git a/gnu/javax/net/ssl/provider/KeyPool.java b/gnu/javax/net/ssl/provider/KeyPool.java
index e342700c2..18d9dc281 100644
--- a/gnu/javax/net/ssl/provider/KeyPool.java
+++ b/gnu/javax/net/ssl/provider/KeyPool.java
@@ -41,15 +41,6 @@ package gnu.javax.net.ssl.provider;
import java.math.BigInteger;
import java.security.KeyPair;
import java.security.SecureRandom;
-import java.security.Security;
-import java.util.LinkedList;
-import javax.crypto.spec.DHParameterSpec;
-
-import gnu.java.security.hash.HashFactory;
-import gnu.java.security.hash.IMessageDigest;
-import gnu.java.security.prng.IRandom;
-import gnu.java.security.prng.LimitReachedException;
-import gnu.java.security.util.Prime2;
final class KeyPool
{
@@ -92,7 +83,7 @@ final class KeyPool
nextBytes(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))
+ p.isProbablePrime(80) && p.gcd(E).equals(ONE))
break;
}
@@ -101,7 +92,7 @@ final class KeyPool
nextBytes(kb);
q = new BigInteger(1, kb).setBit(0);
n = q.multiply(p);
- if (n.bitLength() == 512 && Prime2.isProbablePrime(q) &&
+ if (n.bitLength() == 512 && q.isProbablePrime(80) &&
q.gcd(E).equals(ONE))
break;
}
diff --git a/gnu/javax/security/auth/callback/ConsoleCallbackHandler.java b/gnu/javax/security/auth/callback/ConsoleCallbackHandler.java
index 052b6c43d..d4bd9ed26 100644
--- a/gnu/javax/security/auth/callback/ConsoleCallbackHandler.java
+++ b/gnu/javax/security/auth/callback/ConsoleCallbackHandler.java
@@ -137,7 +137,7 @@ public class ConsoleCallbackHandler extends AbstractCallbackHandler
{
if (choices[i].equals(replies[j]))
{
- indices.add(new Integer(i));
+ indices.add(Integer.valueOf(i));
}
}
if (indices.size() == 0)
diff --git a/gnu/javax/security/auth/login/ConfigFileParser.java b/gnu/javax/security/auth/login/ConfigFileParser.java
index c24dba0d0..b5b506923 100644
--- a/gnu/javax/security/auth/login/ConfigFileParser.java
+++ b/gnu/javax/security/auth/login/ConfigFileParser.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.security.auth.login;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import java.io.IOException;
import java.io.Reader;
diff --git a/gnu/javax/security/auth/login/ConfigFileTokenizer.java b/gnu/javax/security/auth/login/ConfigFileTokenizer.java
index bf820f7bc..06a1d2c7c 100644
--- a/gnu/javax/security/auth/login/ConfigFileTokenizer.java
+++ b/gnu/javax/security/auth/login/ConfigFileTokenizer.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.javax.security.auth.login;
-import gnu.classpath.Configuration;
+import gnu.java.security.Configuration;
import java.io.BufferedReader;
import java.io.IOException;
diff --git a/gnu/javax/security/auth/login/GnuConfiguration.java b/gnu/javax/security/auth/login/GnuConfiguration.java
index 85b6bc3a0..8cd61c954 100644
--- a/gnu/javax/security/auth/login/GnuConfiguration.java
+++ b/gnu/javax/security/auth/login/GnuConfiguration.java
@@ -175,7 +175,7 @@ public final class GnuConfiguration extends Configuration
if (loginModules == null || loginModules.size() == 0)
return null;
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine(appName + " -> " + loginModules.size() + " entry(ies)");
return (AppConfigurationEntry[]) loginModules.toArray(new AppConfigurationEntry[0]);
}
@@ -213,22 +213,22 @@ public final class GnuConfiguration extends Configuration
{
if (processSecurityProperties())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("Using login configuration defined by Security property(ies)");
}
else if (processSystemProperty())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("Using login configuration defined by System property");
}
else if (processUserHome())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("Using login configuration defined in ${user.home}");
}
else
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("No login configuration file found");
}
}
@@ -258,7 +258,7 @@ public final class GnuConfiguration extends Configuration
s = s.trim();
if (s.length() != 0)
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("java.security.auth.login.config.url." + counter
+ " = " + s);
parseConfig(getInputStreamFromURL(s));
@@ -267,7 +267,7 @@ public final class GnuConfiguration extends Configuration
}
catch (Throwable t)
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("Exception while handling Security property at #"
+ counter + ". Continue: " + t);
}
@@ -298,7 +298,7 @@ public final class GnuConfiguration extends Configuration
}
catch (MalformedURLException x)
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("Failed opening as URL: " + s + ". Will try as File");
result = new FileInputStream(s);
}
@@ -323,7 +323,7 @@ public final class GnuConfiguration extends Configuration
s = s.trim();
if (s.length() != 0)
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("java.security.auth.login.config = " + s);
parseConfig(getInputStreamFromURL(s));
result = true;
@@ -332,7 +332,7 @@ public final class GnuConfiguration extends Configuration
}
catch (Throwable t)
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("Exception while handling System property. Continue: " + t);
}
return result;
@@ -363,7 +363,7 @@ public final class GnuConfiguration extends Configuration
if (jaasFile == null)
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("Login Configuration file, in " + userHome
+ ", does not exist or is inaccessible");
return result;
@@ -375,7 +375,7 @@ public final class GnuConfiguration extends Configuration
}
catch (Throwable t)
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("Exception (ignored) while handling ${user.home}: " + t);
}
return result;
@@ -413,7 +413,7 @@ public final class GnuConfiguration extends Configuration
String uh = System.getProperty("user.home");
if (uh == null || uh.trim().length() == 0)
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("User home path is not set or is empty");
return null;
}
@@ -421,19 +421,19 @@ public final class GnuConfiguration extends Configuration
File result = new File(uh);
if (! result.exists())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("User home '" + uh + "' does not exist");
return null;
}
if (! result.isDirectory())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("User home '" + uh + "' is not a directory");
return null;
}
if (! result.canRead())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("User home '" + uh + "' is not readable");
return null;
}
@@ -445,19 +445,19 @@ public final class GnuConfiguration extends Configuration
File result = new File(userHome, fileName);
if (! result.exists())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("File '" + fileName + "' does not exist in user's home");
return null;
}
if (! result.isFile())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("File '" + fileName + "' in user's home is not a file");
return null;
}
if (! result.canRead())
{
- if (gnu.classpath.Configuration.DEBUG)
+ if (gnu.java.security.Configuration.DEBUG)
log.fine("File '" + fileName + "' in user's home is not readable");
return null;
}
diff --git a/include/Makefile.am b/include/Makefile.am
index 5913f67ba..c69e16cb1 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -117,11 +117,15 @@ $(top_srcdir)/include/gnu_java_awt_peer_qt_QtFileDialogPeer.h \
$(top_srcdir)/include/gnu_java_awt_peer_qt_QtContainerPeer.h \
$(top_srcdir)/include/gnu_java_awt_peer_qt_QtEmbeddedWindowPeer.h
+GCONF_PREFS_FILES = \
+$(top_srcdir)/include/gnu_java_util_prefs_gconf_GConfNativePeer.h
+
H_FILES = \
$(SOUND_H_FILES) \
$(XMLJ_H_FILES) \
$(GTKPEER_H_FILES) \
$(QTPEER_H_FILES) \
+$(GCONF_PREFS_FILES) \
$(top_srcdir)/include/gnu_java_net_VMPlainDatagramSocketImpl.h \
$(top_srcdir)/include/gnu_java_net_VMPlainSocketImpl.h \
$(top_srcdir)/include/gnu_java_net_local_LocalSocketImpl.h \
@@ -172,6 +176,9 @@ $(top_srcdir)/include/gnu_javax_sound_midi_alsa_%.h: $(top_builddir)/$(CLASSDIR)
$(top_srcdir)/include/gnu_javax_sound_midi_dssi_%.h: $(top_builddir)/$(CLASSDIR)/gnu/javax/sound/midi/dssi/%.class
$(JAVAH) -o $@ gnu.javax.sound.midi.dssi.$*
+$(top_srcdir)/include/gnu_java_util_prefs_gconf_%.h: $(top_builddir)/$(CLASSDIR)/gnu/java/util/prefs/gconf/%.class
+ $(JAVAH) -o $@ gnu.java.util.prefs.gconf.$*
+
$(top_srcdir)/include/gnu_java_net_VMPlainDatagramSocketImpl.h: $(top_srcdir)/vm/reference/gnu/java/net/VMPlainDatagramSocketImpl.java
$(JAVAH) -o $@ gnu.java.net.VMPlainDatagramSocketImpl
$(top_srcdir)/include/gnu_java_net_VMPlainSocketImpl.h: $(top_srcdir)/vm/reference/gnu/java/net/VMPlainSocketImpl.java
diff --git a/include/gnu_java_awt_peer_gtk_ComponentGraphics.h b/include/gnu_java_awt_peer_gtk_ComponentGraphics.h
index 4fd597eff..2e1633452 100644
--- a/include/gnu_java_awt_peer_gtk_ComponentGraphics.h
+++ b/include/gnu_java_awt_peer_gtk_ComponentGraphics.h
@@ -17,7 +17,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_end_1gdk_1drawing (JNIEnv *env, jobject);
JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_hasXRender (JNIEnv *env, jclass);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative (JNIEnv *env, jobject, jobject, jint, jint, jint, jint, jint, jint);
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile (JNIEnv *env, jobject, jobject, jlong, jint, jint, jint, jint);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile (JNIEnv *env, jobject, jobject, jlong, jint, jint, jint, jint, jint, jint, jint, jint);
#ifdef __cplusplus
}
diff --git a/include/gnu_java_awt_peer_gtk_GtkLabelPeer.h b/include/gnu_java_awt_peer_gtk_GtkLabelPeer.h
index 485509075..3a0d35c73 100644
--- a/include/gnu_java_awt_peer_gtk_GtkLabelPeer.h
+++ b/include/gnu_java_awt_peer_gtk_GtkLabelPeer.h
@@ -13,7 +13,7 @@ extern "C"
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create (JNIEnv *env, jobject, jstring, jfloat);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont (JNIEnv *env, jobject, jstring, jint, jint);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment (JNIEnv *env, jobject, jfloat);
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText (JNIEnv *env, jobject, jstring);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeText (JNIEnv *env, jobject, jstring);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeBounds (JNIEnv *env, jobject, jint, jint, jint, jint);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetGetPreferredDimensions (JNIEnv *env, jobject, jintArray);
diff --git a/include/gnu_java_util_prefs_gconf_GConfNativePeer.h b/include/gnu_java_util_prefs_gconf_GConfNativePeer.h
new file mode 100644
index 000000000..ec902cbb8
--- /dev/null
+++ b/include/gnu_java_util_prefs_gconf_GConfNativePeer.h
@@ -0,0 +1,30 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+
+#ifndef __gnu_java_util_prefs_gconf_GConfNativePeer__
+#define __gnu_java_util_prefs_gconf_GConfNativePeer__
+
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+JNIEXPORT void JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache (JNIEnv *env, jclass);
+JNIEXPORT void JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class (JNIEnv *env, jclass);
+JNIEXPORT void JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class (JNIEnv *env, jclass);
+JNIEXPORT jboolean JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists (JNIEnv *env, jclass, jstring);
+JNIEXPORT void JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1add_1dir (JNIEnv *env, jclass, jstring);
+JNIEXPORT void JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1remove_1dir (JNIEnv *env, jclass, jstring);
+JNIEXPORT jboolean JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1set_1string (JNIEnv *env, jclass, jstring, jstring);
+JNIEXPORT jstring JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1get_1string (JNIEnv *env, jclass, jstring);
+JNIEXPORT jboolean JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1unset (JNIEnv *env, jclass, jstring);
+JNIEXPORT void JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1suggest_1sync (JNIEnv *env, jclass);
+JNIEXPORT jobject JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1nodes (JNIEnv *env, jclass, jstring);
+JNIEXPORT jobject JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1keys (JNIEnv *env, jclass, jstring);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gnu_java_util_prefs_gconf_GConfNativePeer__ */
diff --git a/java/awt/Component.java b/java/awt/Component.java
index 26df1554f..0a987ee3b 100644
--- a/java/awt/Component.java
+++ b/java/awt/Component.java
@@ -70,6 +70,7 @@ import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer;
import java.awt.peer.LightweightPeer;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
@@ -427,6 +428,24 @@ public abstract class Component
Dimension minSize;
/**
+ * Flag indicating whether the minimum size for the component has been set
+ * by a call to {@link #setMinimumSize(Dimension)} with a non-null value.
+ */
+ boolean minSizeSet;
+
+ /**
+ * The maximum size for the component.
+ * @see #setMaximumSize(Dimension)
+ */
+ Dimension maxSize;
+
+ /**
+ * A flag indicating whether the maximum size for the component has been set
+ * by a call to {@link #setMaximumSize(Dimension)} with a non-null value.
+ */
+ boolean maxSizeSet;
+
+ /**
* Cached information on the preferred size. Should have been transient.
*
* @serial ignore
@@ -434,6 +453,12 @@ public abstract class Component
Dimension prefSize;
/**
+ * Flag indicating whether the preferred size for the component has been set
+ * by a call to {@link #setPreferredSize(Dimension)} with a non-null value.
+ */
+ boolean prefSizeSet;
+
+ /**
* Set to true if an event is to be handled by this component, false if
* it is to be passed up the hierarcy.
*
@@ -607,16 +632,19 @@ public abstract class Component
}
/**
- * Sets the name of this component to the specified name.
+ * Sets the name of this component to the specified name (this is a bound
+ * property with the name 'name').
*
- * @param name the new name of this component
+ * @param name the new name (<code>null</code> permitted).
* @see #getName()
* @since 1.1
*/
public void setName(String name)
{
nameExplicitlySet = true;
+ String old = this.name;
this.name = name;
+ firePropertyChange("name", old, name);
}
/**
@@ -1584,6 +1612,7 @@ public abstract class Component
*
* @return the component's preferred size
* @see #getMinimumSize()
+ * @see #setPreferredSize(Dimension)
* @see LayoutManager
*/
public Dimension getPreferredSize()
@@ -1592,6 +1621,40 @@ public abstract class Component
}
/**
+ * Sets the preferred size that will be returned by
+ * {@link #getPreferredSize()} always, and sends a
+ * {@link PropertyChangeEvent} (with the property name 'preferredSize') to
+ * all registered listeners.
+ *
+ * @param size the preferred size (<code>null</code> permitted).
+ *
+ * @since 1.5
+ *
+ * @see #getPreferredSize()
+ */
+ public void setPreferredSize(Dimension size)
+ {
+ Dimension old = prefSizeSet ? prefSize : null;
+ prefSize = size;
+ prefSizeSet = (size != null);
+ firePropertyChange("preferredSize", old, size);
+ }
+
+ /**
+ * Returns <code>true</code> if the current preferred size is not
+ * <code>null</code> and was set by a call to
+ * {@link #setPreferredSize(Dimension)}, otherwise returns <code>false</code>.
+ *
+ * @return A boolean.
+ *
+ * @since 1.5
+ */
+ public boolean isPreferredSizeSet()
+ {
+ return prefSizeSet;
+ }
+
+ /**
* Returns the component's preferred size.
*
* @return the component's preferred size
@@ -1599,7 +1662,7 @@ public abstract class Component
*/
public Dimension preferredSize()
{
- if (prefSize == null)
+ if (!prefSizeSet)
{
if (peer == null)
prefSize = minimumSize();
@@ -1614,6 +1677,7 @@ public abstract class Component
*
* @return the component's minimum size
* @see #getPreferredSize()
+ * @see #setMinimumSize(Dimension)
* @see LayoutManager
*/
public Dimension getMinimumSize()
@@ -1622,6 +1686,39 @@ public abstract class Component
}
/**
+ * Sets the minimum size that will be returned by {@link #getMinimumSize()}
+ * always, and sends a {@link PropertyChangeEvent} (with the property name
+ * 'minimumSize') to all registered listeners.
+ *
+ * @param size the minimum size (<code>null</code> permitted).
+ *
+ * @since 1.5
+ *
+ * @see #getMinimumSize()
+ */
+ public void setMinimumSize(Dimension size)
+ {
+ Dimension old = minSizeSet ? minSize : null;
+ minSize = size;
+ minSizeSet = (size != null);
+ firePropertyChange("minimumSize", old, size);
+ }
+
+ /**
+ * Returns <code>true</code> if the current minimum size is not
+ * <code>null</code> and was set by a call to
+ * {@link #setMinimumSize(Dimension)}, otherwise returns <code>false</code>.
+ *
+ * @return A boolean.
+ *
+ * @since 1.5
+ */
+ public boolean isMinimumSizeSet()
+ {
+ return minSizeSet;
+ }
+
+ /**
* Returns the component's minimum size.
*
* @return the component's minimum size
@@ -1640,15 +1737,52 @@ public abstract class Component
*
* @return the component's maximum size
* @see #getMinimumSize()
+ * @see #setMaximumSize(Dimension)
* @see #getPreferredSize()
* @see LayoutManager
*/
public Dimension getMaximumSize()
{
- return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
+ if (maxSizeSet)
+ return maxSize;
+ else
+ return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
}
/**
+ * Sets the maximum size that will be returned by {@link #getMaximumSize()}
+ * always, and sends a {@link PropertyChangeEvent} (with the property name
+ * 'maximumSize') to all registered listeners.
+ *
+ * @param size the maximum size (<code>null</code> permitted).
+ *
+ * @since 1.5
+ *
+ * @see #getMaximumSize()
+ */
+ public void setMaximumSize(Dimension size)
+ {
+ Dimension old = maxSizeSet ? maxSize : null;
+ maxSize = size;
+ maxSizeSet = (size != null);
+ firePropertyChange("maximumSize", old, size);
+ }
+
+ /**
+ * Returns <code>true</code> if the current maximum size is not
+ * <code>null</code> and was set by a call to
+ * {@link #setMaximumSize(Dimension)}, otherwise returns <code>false</code>.
+ *
+ * @return A boolean.
+ *
+ * @since 1.5
+ */
+ public boolean isMaximumSizeSet()
+ {
+ return maxSizeSet;
+ }
+
+ /**
* Returns the preferred horizontal alignment of this component. The value
* returned will be between {@link #LEFT_ALIGNMENT} and
* {@link #RIGHT_ALIGNMENT}, inclusive.
diff --git a/java/awt/Container.java b/java/awt/Container.java
index f145d5696..3f3abc5c7 100644
--- a/java/awt/Container.java
+++ b/java/awt/Container.java
@@ -1688,7 +1688,7 @@ public class Container extends Component
int index = -1;
if (component != null)
{
- for (int i = 0; i < component.length; i++)
+ for (int i = 0; i < ncomponents; i++)
{
if (component[i] == comp)
{
diff --git a/java/awt/GridBagConstraints.java b/java/awt/GridBagConstraints.java
index 8d8b4fae5..a6a64c3bb 100644
--- a/java/awt/GridBagConstraints.java
+++ b/java/awt/GridBagConstraints.java
@@ -48,62 +48,99 @@ public class GridBagConstraints implements Cloneable, Serializable
{
static final long serialVersionUID = -1000070633030801713L;
- /** Fill in both directions. */
- public static final int BOTH = 1;
- /** Don't fill. */
+ // Fill values.
+ /**
+ * Don't fill.
+ */
public static final int NONE = 0;
- /** Fill horizontally. */
+
+ /**
+ * Fill in both directions.
+ */
+ public static final int BOTH = 1;
+
+ /**
+ * Fill horizontally.
+ */
public static final int HORIZONTAL = 2;
- /** Fill vertically. */
+
+ /**
+ * Fill vertically.
+ */
public static final int VERTICAL = 3;
- /** Position in the center. */
+ // Anchor values.
+ /**
+ * Position in the center.
+ */
public static final int CENTER = 10;
- /** Position to the east. */
- public static final int EAST = 13;
- /** Position to the north. */
+
+ /**
+ * Position to the north.
+ */
public static final int NORTH = 11;
- /** Position to the northeast. */
+
+ /**
+ * Position to the northeast.
+ */
public static final int NORTHEAST = 12;
- /** Position to the northwest. */
- public static final int NORTHWEST = 18;
- /** Position to the south. */
- public static final int SOUTH = 15;
- /** Position to the southeast. */
+
+ /**
+ * Position to the east.
+ */
+ public static final int EAST = 13;
+
+ /**
+ * Position to the southeast.
+ */
public static final int SOUTHEAST = 14;
- /** Position to the southwest. */
+
+ /**
+ * Position to the south.
+ */
+ public static final int SOUTH = 15;
+
+ /**
+ * Position to the southwest.
+ */
public static final int SOUTHWEST = 16;
- /** Position to the west. */
+
+ /**
+ * Position to the west.
+ */
public static final int WEST = 17;
- /** Occupy all remaining cells except last cell. */
+ /**
+ * Position to the northwest.
+ */
+ public static final int NORTHWEST = 18;
+
+ // gridx and gridy values.
+ /**
+ * Occupy all remaining cells except last cell.
+ */
public static final int RELATIVE = -1;
- /** Occupy all remaining cells. */
- public static final int REMAINDER = 0;
/**
- * Position to where the first text line would end. Equals to NORTHEAST for
- * horizontal left-to-right orientations.
+ * Occupy all remaining cells.
*/
- public static final int FIRST_LINE_END = 24;
+ public static final int REMAINDER = 0;
/**
- * Position to where the first text line would start. Equals to NORTHWEST for
- * horizontal left-to-right orientations.
+ * Position to where a page starts. Equals NORTH for horizontal orientations.
*/
- public static final int FIRST_LINE_START = 23;
+ public static final int PAGE_START = 19;
/**
- * Position to where the last text line would end. Equals to SOUTHEAST for
- * horizontal left-to-right orientations.
+ * Position to where a page ends. Equals SOUTH for horizontal orientations.
*/
- public static final int LAST_LINE_END = 26;
+ public static final int PAGE_END = 20;
/**
- * Position to where the last text line would start. Equals to SOUTHWEST for
- * horizontal left-to-right orientations.
+ * Position to where a text line would start. Equals to WEST for
+ * left-to-right orientations.
*/
- public static final int LAST_LINE_START = 25;
+ public static final int LINE_START = 21;
/**
* Position to where a text line would end. Equals to EAST for
@@ -112,20 +149,28 @@ public class GridBagConstraints implements Cloneable, Serializable
public static final int LINE_END = 22;
/**
- * Position to where a text line would start. Equals to WEST for
- * left-to-right orientations.
+ * Position to where the first text line would start. Equals to NORTHWEST for
+ * horizontal left-to-right orientations.
*/
- public static final int LINE_START = 21;
+ public static final int FIRST_LINE_START = 23;
/**
- * Position to where a page ends. Equals SOUTH for horizontal orientations.
+ * Position to where the first text line would end. Equals to NORTHEAST for
+ * horizontal left-to-right orientations.
*/
- public static final int PAGE_END = 20;
+ public static final int FIRST_LINE_END = 24;
/**
- * Position to where a page starts. Equals NORTH for horizontal orientations.
+ * Position to where the last text line would start. Equals to SOUTHWEST for
+ * horizontal left-to-right orientations.
*/
- public static final int PAGE_START = 19;
+ public static final int LAST_LINE_START = 25;
+
+ /**
+ * Position to where the last text line would end. Equals to SOUTHEAST for
+ * horizontal left-to-right orientations.
+ */
+ public static final int LAST_LINE_END = 26;
public int anchor;
public int fill;
@@ -139,7 +184,9 @@ public class GridBagConstraints implements Cloneable, Serializable
public double weightx;
public double weighty;
- /** Create a copy of this object. */
+ /**
+ * Create a copy of this object.
+ */
public Object clone ()
{
try
@@ -155,8 +202,10 @@ public class GridBagConstraints implements Cloneable, Serializable
}
}
- /** Create a new GridBagConstraints object with the default
- * parameters. */
+ /**
+ * Create a new GridBagConstraints object with the default
+ * parameters.
+ */
public GridBagConstraints ()
{
this.anchor = CENTER;
@@ -172,8 +221,10 @@ public class GridBagConstraints implements Cloneable, Serializable
this.weighty = 0;
}
- /** Create a new GridBagConstraints object with the indicated
- * parameters. */
+ /**
+ * Create a new GridBagConstraints object with the indicated
+ * parameters.
+ */
public GridBagConstraints (int gridx, int gridy,
int gridwidth, int gridheight,
double weightx, double weighty,
diff --git a/java/awt/GridBagLayout.java b/java/awt/GridBagLayout.java
index 20c402b78..c8d204396 100644
--- a/java/awt/GridBagLayout.java
+++ b/java/awt/GridBagLayout.java
@@ -38,8 +38,6 @@ exception statement from your version. */
package java.awt;
-import gnu.classpath.NotImplementedException;
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -323,13 +321,127 @@ public class GridBagLayout
}
/**
- * Obsolete.
+ * Move and resize a rectangle according to a set of grid bag
+ * constraints. The x, y, width and height fields of the
+ * rectangle argument are adjusted to the new values.
+ *
+ * @param constraints position and size constraints
+ * @param r rectangle to be moved and resized
*/
- protected void AdjustForGravity (GridBagConstraints gbc, Rectangle rect)
- throws NotImplementedException
+ protected void AdjustForGravity (GridBagConstraints constraints,
+ Rectangle r)
{
- // FIXME
- throw new Error ("Not implemented");
+ Rectangle result = new Rectangle (0, 0, 0, 0);
+
+ // Calculate width and height.
+
+ // Adjust width and height for fill value.
+ switch (constraints.fill)
+ {
+ case GridBagConstraints.NONE:
+ result.width = 0;
+ result.height = 0;
+ break;
+ case GridBagConstraints.BOTH:
+ result.width = r.width;
+ result.height = r.height;
+ break;
+ case GridBagConstraints.HORIZONTAL:
+ result.width = r.width;
+ result.height = 0;
+ break;
+ case GridBagConstraints.VERTICAL:
+ result.width = 0;
+ result.height = r.height;
+ break;
+ }
+
+ // Adjust width and height for insets, and clamp to minimum
+ // values of ipadx and ipady.
+ result.width = Math.max(result.width
+ - constraints.insets.left
+ - constraints.insets.right,
+ constraints.ipadx);
+ result.height = Math.max(result.height
+ - constraints.insets.top
+ - constraints.insets.bottom,
+ constraints.ipady);
+
+ // Calculate x and y.
+
+ // Do not account for the internal padding when setting the
+ // result rectangle's x and y co-ordinates.
+ int rect_width = r.width - constraints.ipadx;
+ int rect_height = r.height - constraints.ipady;
+
+ int half_width = (rect_width + constraints.insets.left
+ - constraints.insets.right) / 2;
+ int half_height = (rect_height + constraints.insets.top
+ - constraints.insets.bottom) / 2;
+
+ // Adjust x and y for anchor value.
+ switch (constraints.anchor)
+ {
+ case GridBagConstraints.CENTER:
+ result.x = r.x + half_width;
+ result.y = r.y + half_height;
+ break;
+ case GridBagConstraints.NORTH:
+ result.x = r.x + half_width;
+ result.y = r.y + constraints.insets.top;
+ break;
+ case GridBagConstraints.NORTHEAST:
+ result.x = r.x + rect_width - constraints.insets.right;
+ result.y = r.y + constraints.insets.top;
+ break;
+ case GridBagConstraints.EAST:
+ result.x = r.x + rect_width - constraints.insets.right;
+ result.y = r.y + half_height;
+ break;
+ case GridBagConstraints.SOUTHEAST:
+ result.x = r.x + rect_width - constraints.insets.right;
+ result.y = r.y + rect_height - constraints.insets.bottom;
+ break;
+ case GridBagConstraints.SOUTH:
+ result.x = r.x + half_width;
+ result.y = r.y + rect_height - constraints.insets.bottom;
+ break;
+ case GridBagConstraints.SOUTHWEST:
+ result.x = r.x + constraints.insets.left;
+ result.y = r.y + rect_height - constraints.insets.bottom;
+ break;
+ case GridBagConstraints.WEST:
+ result.x = r.x + constraints.insets.left;
+ result.y = r.y + half_height;
+ break;
+ case GridBagConstraints.NORTHWEST:
+ result.x = r.x + constraints.insets.left;
+ result.y = r.y + constraints.insets.top;
+ break;
+ }
+
+ // Adjust x and y for fill, clamping values to the external
+ // padding boundaries where necessary.
+ switch (constraints.fill)
+ {
+ case GridBagConstraints.NONE:
+ break;
+ case GridBagConstraints.BOTH:
+ result.x = r.x + constraints.insets.left;
+ result.y = r.y + constraints.insets.top;
+ break;
+ case GridBagConstraints.HORIZONTAL:
+ result.x = r.x + constraints.insets.left;
+ break;
+ case GridBagConstraints.VERTICAL:
+ result.y = r.y + constraints.insets.top;
+ break;
+ }
+
+ r.x = result.x;
+ r.y = result.y;
+ r.width = result.width;
+ r.height = result.height;
}
/**
@@ -354,10 +466,9 @@ public class GridBagLayout
// layoutInfo. So we wait until after this for loop to set
// layoutInfo.
Component lastComp = null;
- int cellx = 0;
- int celly = 0;
- int cellw = 0;
- int cellh = 0;
+
+ Rectangle cell = new Rectangle();
+
for (int i = 0; i < components.length; i++)
{
Component component = components[i];
@@ -371,29 +482,23 @@ public class GridBagLayout
if (lastComp != null
&& constraints.gridheight == GridBagConstraints.REMAINDER)
- celly += cellh;
+ cell.y += cell.height;
else
- celly = sumIntArray(info.rowHeights, constraints.gridy);
+ cell.y = sumIntArray(info.rowHeights, constraints.gridy);
if (lastComp != null
&& constraints.gridwidth == GridBagConstraints.REMAINDER)
- cellx += cellw;
+ cell.x += cell.width;
else
- cellx = sumIntArray(info.colWidths, constraints.gridx);
+ cell.x = sumIntArray(info.colWidths, constraints.gridx);
- cellw = sumIntArray(info.colWidths, constraints.gridx
- + constraints.gridwidth) - cellx;
- cellh = sumIntArray(info.rowHeights, constraints.gridy
- + constraints.gridheight) - celly;
-
- Insets insets = constraints.insets;
- if (insets != null)
- {
- cellx += insets.left;
- celly += insets.top;
- cellw -= insets.left + insets.right;
- cellh -= insets.top + insets.bottom;
- }
+ cell.width = sumIntArray(info.colWidths, constraints.gridx
+ + constraints.gridwidth) - cell.x;
+ cell.height = sumIntArray(info.rowHeights, constraints.gridy
+ + constraints.gridheight) - cell.y;
+
+ // Adjust for insets.
+ AdjustForGravity( constraints, cell );
// Note: Documentation says that padding is added on both sides, but
// visual inspection shows that the Sun implementation only adds it
@@ -404,14 +509,14 @@ public class GridBagLayout
switch (constraints.fill)
{
case GridBagConstraints.HORIZONTAL:
- dim.width = cellw;
+ dim.width = cell.width;
break;
case GridBagConstraints.VERTICAL:
- dim.height = cellh;
+ dim.height = cell.height;
break;
case GridBagConstraints.BOTH:
- dim.width = cellw;
- dim.height = cellh;
+ dim.width = cell.width;
+ dim.height = cell.height;
break;
}
@@ -421,40 +526,40 @@ public class GridBagLayout
switch (constraints.anchor)
{
case GridBagConstraints.NORTH:
- x = cellx + (cellw - dim.width) / 2;
- y = celly;
+ x = cell.x + (cell.width - dim.width) / 2;
+ y = cell.y;
break;
case GridBagConstraints.SOUTH:
- x = cellx + (cellw - dim.width) / 2;
- y = celly + cellh - dim.height;
+ x = cell.x + (cell.width - dim.width) / 2;
+ y = cell.y + cell.height - dim.height;
break;
case GridBagConstraints.WEST:
- x = cellx;
- y = celly + (cellh - dim.height) / 2;
+ x = cell.x;
+ y = cell.y + (cell.height - dim.height) / 2;
break;
case GridBagConstraints.EAST:
- x = cellx + cellw - dim.width;
- y = celly + (cellh - dim.height) / 2;
+ x = cell.x + cell.width - dim.width;
+ y = cell.y + (cell.height - dim.height) / 2;
break;
case GridBagConstraints.NORTHEAST:
- x = cellx + cellw - dim.width;
- y = celly;
+ x = cell.x + cell.width - dim.width;
+ y = cell.y;
break;
case GridBagConstraints.NORTHWEST:
- x = cellx;
- y = celly;
+ x = cell.x;
+ y = cell.y;
break;
case GridBagConstraints.SOUTHEAST:
- x = cellx + cellw - dim.width;
- y = celly + cellh - dim.height;
+ x = cell.x + cell.width - dim.width;
+ y = cell.y + cell.height - dim.height;
break;
case GridBagConstraints.SOUTHWEST:
- x = cellx;
- y = celly + cellh - dim.height;
+ x = cell.x;
+ y = cell.y + cell.height - dim.height;
break;
default:
- x = cellx + (cellw - dim.width) / 2;
- y = celly + (cellh - dim.height) / 2;
+ x = cell.x + (cell.width - dim.width) / 2;
+ y = cell.y + (cell.height - dim.height) / 2;
break;
}
component.setBounds(info.pos_x + x, info.pos_y + y, dim.width,
@@ -1086,10 +1191,18 @@ public class GridBagLayout
}
/**
+ * Move and resize a rectangle according to a set of grid bag
+ * constraints. The x, y, width and height fields of the
+ * rectangle argument are adjusted to the new values.
+ *
+ * @param constraints position and size constraints
+ * @param r rectangle to be moved and resized
+ *
* @since 1.4
*/
- protected void adjustForGravity (GridBagConstraints gbc, Rectangle rect)
+ protected void adjustForGravity (GridBagConstraints constraints,
+ Rectangle r)
{
- AdjustForGravity (gbc, rect);
+ AdjustForGravity (constraints, r);
}
}
diff --git a/java/awt/Insets.java b/java/awt/Insets.java
index 6d5bd122e..762b6975b 100644
--- a/java/awt/Insets.java
+++ b/java/awt/Insets.java
@@ -1,5 +1,5 @@
/* Insets.java -- information about a container border
- Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -149,14 +149,13 @@ public class Insets implements Cloneable, Serializable
/**
* Returns a string representation of this object, which will be non-null.
- * The format is unspecified, but appears to be <code>XXX what is it?</code>.
*
* @return a string representation of this object
*/
public String toString()
{
- return getClass().getName() + "(top=" + top + ",bottom=" + bottom +
- ",left=" + left + ",right=" + right + ')';
+ return getClass().getName() + "[top=" + top + ",left=" + left
+ + ",bottom=" + bottom + ",right=" + right + ']';
}
/**
diff --git a/java/awt/Label.java b/java/awt/Label.java
index d6db32910..71614da64 100644
--- a/java/awt/Label.java
+++ b/java/awt/Label.java
@@ -1,5 +1,6 @@
/* Label.java -- Java label widget
- Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2004, 2005, 2006, Free Software
+ Foundation, Inc.
This file is part of GNU Classpath.
@@ -45,275 +46,250 @@ import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
/**
- * This component is used for displaying simple text strings that cannot
- * be edited by the user.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- * @author Tom Tromey (tromey@cygnus.com)
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- */
+ * This component is used for displaying simple text strings that cannot
+ * be edited by the user.
+ *
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Tom Tromey (tromey@cygnus.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ */
public class Label extends Component implements Accessible
{
-/*
- * Static Variables
- */
-
-/**
- * Alignment constant aligning the text to the left of its window.
- */
-public static final int LEFT = 0;
-
-/**
- * Alignment constant aligning the text in the center of its window.
- */
-public static final int CENTER = 1;
-
-/**
- * Alignment constant aligning the text to the right of its window.
- */
-public static final int RIGHT = 2;
-
-// Serialization version constant:
-private static final long serialVersionUID = 3094126758329070636L;
-
-/*************************************************************************/
+ /**
+ * Alignment constant aligning the text to the left of its window.
+ */
+ public static final int LEFT = 0;
-/*
- * Instance Variables
- */
+ /**
+ * Alignment constant aligning the text in the center of its window.
+ */
+ public static final int CENTER = 1;
-/**
- * @serial Indicates the alignment of the text within this label's window.
- * This is one of the constants in this class. The default value is
- * <code>LEFT</code>.
- */
-private int alignment;
+ /**
+ * Alignment constant aligning the text to the right of its window.
+ */
+ public static final int RIGHT = 2;
-/**
- * @serial The text displayed in the label
- */
-private String text;
+ // Serialization version constant:
+ private static final long serialVersionUID = 3094126758329070636L;
-/*************************************************************************/
+ /**
+ * @serial Indicates the alignment of the text within this label's window.
+ * This is one of the constants in this class. The default value is
+ * <code>LEFT</code>.
+ */
+ private int alignment;
-/*
- * Constructors
- */
+ /**
+ * @serial The text displayed in the label
+ */
+ private String text;
-/**
- * Initializes a new instance of <code>Label</code> with no text.
- *
- * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
- */
-public
-Label()
-{
- this("", LEFT);
-}
+ /**
+ * Initializes a new instance of <code>Label</code> with no text.
+ *
+ * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
+ */
+ public Label()
+ {
+ this("", LEFT);
+ }
-/*************************************************************************/
+ /**
+ * Initializes a new instance of <code>Label</code> with the specified
+ * text that is aligned to the left.
+ *
+ * @param text The text of the label.
+ *
+ * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
+ */
+ public Label(String text)
+ {
+ this(text, LEFT);
+ }
-/**
- * Initializes a new instance of <code>Label</code> with the specified
- * text that is aligned to the left.
- *
- * @param text The text of the label.
- *
- * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
- */
-public
-Label(String text)
-{
- this(text, LEFT);
-}
+ /**
+ * Initializes a new instance of <code>Label</code> with the specified
+ * text and alignment.
+ *
+ * @param text The text of the label.
+ * @param alignment The desired alignment for the text in this label,
+ * which must be one of <code>LEFT</code>, <code>CENTER</code>, or
+ * <code>RIGHT</code>.
+ *
+ * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
+ */
+ public Label(String text, int alignment)
+ {
+ setAlignment(alignment);
+ setText(text);
-/*************************************************************************/
+ if (GraphicsEnvironment.isHeadless())
+ throw new HeadlessException();
+ }
-/**
- * Initializes a new instance of <code>Label</code> with the specified
- * text and alignment.
- *
- * @param text The text of the label.
- * @param alignment The desired alignment for the text in this label,
- * which must be one of <code>LEFT</code>, <code>CENTER</code>, or
- * <code>RIGHT</code>.
- *
- * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
- */
-public
-Label(String text, int alignment)
-{
- setAlignment (alignment);
- setText (text);
+ /**
+ * Returns the constant indicating the alignment of the text in this
+ * label. The value returned will be one of the alignment constants
+ * from this class.
+ *
+ * @return The alignment of the text in the label.
+ */
+ public int getAlignment()
+ {
+ return(alignment);
+ }
- if (GraphicsEnvironment.isHeadless())
- throw new HeadlessException ();
-}
+ /**
+ * Sets the text alignment of this label to the specified value.
+ *
+ * @param alignment The desired alignment for the text in this label,
+ * which must be one of <code>LEFT</code>, <code>CENTER</code>, or
+ * <code>RIGHT</code>.
+ */
+ public synchronized void setAlignment(int alignment)
+ {
+ if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
+ throw new IllegalArgumentException("invalid alignment: " + alignment);
+ this.alignment = alignment;
+ if (peer != null)
+ {
+ LabelPeer lp = (LabelPeer) peer;
+ lp.setAlignment(alignment);
+ }
+ }
-/*************************************************************************/
+ /**
+ * Returns the text displayed in this label.
+ *
+ * @return The text for this label.
+ */
+ public String getText()
+ {
+ return text;
+ }
-/*
- * Instance Variables
- */
+ /**
+ * Sets the text in this label to the specified value.
+ *
+ * @param text The new text for this label.
+ */
+ public synchronized void setText(String text)
+ {
+ if ((this.text == null && text != null)
+ || (this.text != null && ! this.text.equals(text)))
+ {
+ this.text = text;
+
+ if (peer != null)
+ {
+ LabelPeer lp = (LabelPeer) peer;
+ lp.setText(text);
+ }
+ invalidate();
+ }
+ }
-/**
- * Returns the constant indicating the alignment of the text in this
- * label. The value returned will be one of the alignment constants
- * from this class.
- *
- * @return The alignment of the text in the label.
- */
-public int
-getAlignment()
-{
- return(alignment);
-}
+ /**
+ * Notifies this label that it has been added to a container, causing
+ * the peer to be created. This method is called internally by the AWT
+ * system.
+ */
+ public void addNotify()
+ {
+ if (peer == null)
+ peer = getToolkit().createLabel(this);
+ super.addNotify();
+ }
-/*************************************************************************/
+ /**
+ * Returns a parameter string useful for debugging.
+ *
+ * @return A debugging string.
+ */
+ protected String paramString()
+ {
+ return ("text=" + getText() + ",alignment=" +
+ getAlignment() + "," + super.paramString());
+ }
-/**
- * Sets the text alignment of this label to the specified value.
- *
- * @param alignment The desired alignment for the text in this label,
- * which must be one of <code>LEFT</code>, <code>CENTER</code>, or
- * <code>RIGHT</code>.
- */
-public synchronized void
-setAlignment(int alignment)
-{
- if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
- throw new IllegalArgumentException ("invalid alignment: " + alignment);
- this.alignment = alignment;
- if (peer != null)
+ /**
+ * This class provides accessibility support for the label.
+ */
+ protected class AccessibleAWTLabel
+ extends AccessibleAWTComponent
+ {
+ /**
+ * For compatability with Sun's JDK 1.4.2 rev. 5
+ */
+ private static final long serialVersionUID = -3568967560160480438L;
+
+ /**
+ * Constructor for the accessible label.
+ */
+ public AccessibleAWTLabel()
{
- LabelPeer lp = (LabelPeer) peer;
- lp.setAlignment (alignment);
}
-}
-
-/*************************************************************************/
-
-/**
- * Returns the text displayed in this label.
- *
- * @return The text for this label.
- */
-public String
-getText()
-{
- return(text);
-}
-
-/*************************************************************************/
-/**
- * Sets the text in this label to the specified value.
- *
- * @param text The new text for this label.
- */
-public synchronized void
-setText(String text)
-{
- if ((this.text == null && text != null)
- || (this.text != null && ! this.text.equals(text)))
+ /**
+ * Returns the accessible name for the label. This is
+ * the text used in the label.
+ *
+ * @return a <code>String</code> containing the accessible
+ * name for this label.
+ */
+ public String getAccessibleName()
{
- this.text = text;
-
- if (peer != null)
- {
- LabelPeer lp = (LabelPeer) peer;
- lp.setText (text);
- }
- invalidate();
+ return getText();
}
-}
-
-/*************************************************************************/
-
-/**
- * Notifies this label that it has been added to a container, causing
- * the peer to be created. This method is called internally by the AWT
- * system.
- */
-public void
-addNotify()
-{
- if (peer == null)
- peer = getToolkit ().createLabel (this);
- super.addNotify ();
-}
-/*************************************************************************/
-
-/**
- * Returns a parameter string useful for debugging.
- *
- * @return A debugging string.
- */
-protected String
-paramString()
-{
- return ("text=" + getText() + ",alignment=" +
- getAlignment() + "," + super.paramString());
-}
+ /**
+ * Returns the accessible role for the label.
+ *
+ * @return an instance of <code>AccessibleRole</code>, describing
+ * the role of the label.
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.LABEL;
+ }
-/**
- * This class provides accessibility support for the label.
- */
-protected class AccessibleAWTLabel
- extends AccessibleAWTComponent
-{
- /**
- * For compatability with Sun's JDK 1.4.2 rev. 5
- */
- private static final long serialVersionUID = -3568967560160480438L;
+ }
/**
- * Constructor for the accessible label.
+ * Gets the AccessibleContext associated with this <code>Label</code>.
+ * The context is created, if necessary.
+ *
+ * @return the associated context
*/
- public AccessibleAWTLabel()
+ public AccessibleContext getAccessibleContext()
{
+ /* Create the context if this is the first request */
+ if (accessibleContext == null)
+ accessibleContext = new AccessibleAWTLabel();
+ return accessibleContext;
}
/**
- * Returns the accessible name for the label. This is
- * the text used in the label.
+ * Generate a unique name for this button.
*
- * @return a <code>String</code> containing the accessible
- * name for this label.
+ * @return A unique name for this button.
*/
- public String getAccessibleName()
+ String generateName()
{
- return getText();
+ return "label" + getUniqueLong();
}
-
+
/**
- * Returns the accessible role for the label.
- *
- * @return an instance of <code>AccessibleRole</code>, describing
- * the role of the label.
+ * The number used to generate the name returned by getName.
*/
- public AccessibleRole getAccessibleRole()
+ private static transient long nextLabelNumber;
+
+ private static synchronized long getUniqueLong()
{
- return AccessibleRole.LABEL;
+ return nextLabelNumber++;
}
}
-/**
- * Gets the AccessibleContext associated with this <code>Label</code>.
- * The context is created, if necessary.
- *
- * @return the associated context
- */
-public AccessibleContext getAccessibleContext()
-{
- /* Create the context if this is the first request */
- if (accessibleContext == null)
- accessibleContext = new AccessibleAWTLabel();
- return accessibleContext;
-}
-
-} // class Label
-
diff --git a/java/awt/List.java b/java/awt/List.java
index 808c4b6ed..1d703e5a6 100644
--- a/java/awt/List.java
+++ b/java/awt/List.java
@@ -161,7 +161,11 @@ List(int rows)
public
List(int rows, boolean multipleMode)
{
- this.rows = rows;
+ if (rows == 0)
+ this.rows = 4;
+ else
+ this.rows = rows;
+
this.multipleMode = multipleMode;
selected = new int[0];
@@ -645,13 +649,13 @@ clear()
* @param item The new item value.
* @param index The index of the item to replace.
*
- * @exception IllegalArgumentException If the index is not valid.
+ * @exception ArrayIndexOutOfBoundsException If the index is not valid.
*/
public synchronized void
-replaceItem(String item, int index) throws IllegalArgumentException
+replaceItem(String item, int index) throws ArrayIndexOutOfBoundsException
{
if ((index < 0) || (index >= items.size()))
- throw new IllegalArgumentException("Bad list index: " + index);
+ throw new ArrayIndexOutOfBoundsException("Bad list index: " + index);
items.insertElementAt(item, index + 1);
items.removeElementAt (index);
@@ -818,15 +822,11 @@ isSelected(int index)
/**
* This method ensures that the item at the specified index is visible.
*
- * @exception IllegalArgumentException If the specified index is out of
- * range.
+ * @param index The index of the item to be made visible.
*/
public synchronized void
makeVisible(int index) throws IllegalArgumentException
{
- if ((index < 0) || (index >= items.size()))
- throw new IllegalArgumentException("Bad list index: " + index);
-
visibleIndex = index;
if (peer != null)
{
diff --git a/java/awt/Point.java b/java/awt/Point.java
index 31b72e2cc..64bc07eaf 100644
--- a/java/awt/Point.java
+++ b/java/awt/Point.java
@@ -1,5 +1,5 @@
/* Point.java -- represents a point in 2-D space
- Copyright (C) 1999, 2002 Free Software Foundation
+ Copyright (C) 1999, 2002, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -83,7 +83,7 @@ public class Point extends Point2D implements Serializable
/**
* Initializes a new instance of <code>Point</code> representing the
- * coordiates (0,0).
+ * coordinates (0, 0).
*
* @since 1.1
*/
@@ -93,7 +93,7 @@ public class Point extends Point2D implements Serializable
/**
* Initializes a new instance of <code>Point</code> with coordinates
- * identical to the coordinates of the specified points.
+ * identical to the coordinates of the specified point.
*
* @param p the point to copy the coordinates from
* @throws NullPointerException if p is null
@@ -178,15 +178,16 @@ public class Point extends Point2D implements Serializable
/**
* Sets this object's coordinates to the specified values. This method
- * performs normal casting from double to int, so you may lose precision.
+ * rounds to the nearest integer coordinates by adding 0.5 and calling
+ * {@link Math#floor(double)}.
*
* @param x the new X coordinate
* @param y the new Y coordinate
*/
public void setLocation(double x, double y)
{
- this.x = (int) x;
- this.y = (int) y;
+ this.x = (int) Math.floor(x + 0.5);
+ this.y = (int) Math.floor(y + 0.5);
}
/**
diff --git a/java/awt/TextField.java b/java/awt/TextField.java
index ff32afa88..45be0ea51 100644
--- a/java/awt/TextField.java
+++ b/java/awt/TextField.java
@@ -96,7 +96,7 @@ private ActionListener action_listeners;
public
TextField()
{
- this("", 1);
+ this("", 0);
}
/*************************************************************************/
@@ -113,7 +113,7 @@ TextField()
public
TextField(String text)
{
- this(text, text.length());
+ this(text, (text == null) ? 0 : text.length());
}
/*************************************************************************/
@@ -147,7 +147,11 @@ public
TextField(String text, int columns)
{
super(text);
- this.columns = columns;
+
+ if (columns < 0)
+ this.columns = 0;
+ else
+ this.columns = columns;
if (GraphicsEnvironment.isHeadless())
throw new HeadlessException ();
diff --git a/java/awt/Toolkit.java b/java/awt/Toolkit.java
index 99863fab0..e2db04837 100644
--- a/java/awt/Toolkit.java
+++ b/java/awt/Toolkit.java
@@ -698,6 +698,14 @@ public abstract class Toolkit
public PrintJob getPrintJob(Frame frame, String title,
JobAttributes jobAttr, PageAttributes pageAttr)
{
+ // FIXME: it is possible this check may be removed
+ // if this method, when written, always delegates to
+ // getPrintJob(Frame, String, Properties).
+ SecurityManager sm;
+ sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPrintJobAccess();
+
return null;
}
diff --git a/java/awt/datatransfer/Clipboard.java b/java/awt/datatransfer/Clipboard.java
index 5fa1d1ab1..2029e2c35 100644
--- a/java/awt/datatransfer/Clipboard.java
+++ b/java/awt/datatransfer/Clipboard.java
@@ -1,5 +1,5 @@
/* Clipboard.java -- Class for transferring data via cut and paste.
- Copyright (C) 1999, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -182,6 +182,9 @@ public class Clipboard
public void addFlavorListener(FlavorListener listener)
{
+ if (listener == null)
+ return;
+
synchronized(listeners)
{
listeners.add(listener);
@@ -190,6 +193,9 @@ public class Clipboard
public void removeFlavorListener(FlavorListener listener)
{
+ if (listener == null)
+ return;
+
synchronized(listeners)
{
listeners.remove(listener);
diff --git a/java/awt/datatransfer/DataFlavor.java b/java/awt/datatransfer/DataFlavor.java
index 33b98379c..63a00db13 100644
--- a/java/awt/datatransfer/DataFlavor.java
+++ b/java/awt/datatransfer/DataFlavor.java
@@ -1,5 +1,5 @@
/* DataFlavor.java -- A type of data to transfer via the clipboard.
- Copyright (C) 1999, 2001, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -47,6 +47,7 @@ import java.io.InputStreamReader;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Reader;
+import java.io.Serializable;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
@@ -197,31 +198,37 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
throw new ClassNotFoundException(className);
}
- private static Class getRepresentationClassFromMime(String mimeString,
+ private static Class getRepresentationClassFromMimeThrows(String mimeString,
ClassLoader classLoader)
+ throws ClassNotFoundException
{
String classname = getParameter("class", mimeString);
if (classname != null)
- {
- try
- {
- return tryToLoadClass(classname, classLoader);
- }
- catch(Exception e)
- {
- IllegalArgumentException iae;
- iae = new IllegalArgumentException("mimeString: "
- + mimeString
- + " classLoader: "
- + classLoader);
- iae.initCause(e);
- throw iae;
- }
- }
+ return tryToLoadClass(classname, classLoader);
else
return java.io.InputStream.class;
}
-
+
+ // Same as above, but wraps any ClassNotFoundExceptions
+ private static Class getRepresentationClassFromMime(String mimeString,
+ ClassLoader classLoader)
+ {
+ try
+ {
+ return getRepresentationClassFromMimeThrows(mimeString, classLoader);
+ }
+ catch(ClassNotFoundException cnfe)
+ {
+ IllegalArgumentException iae;
+ iae = new IllegalArgumentException("mimeString: "
+ + mimeString
+ + " classLoader: "
+ + classLoader);
+ iae.initCause(cnfe);
+ throw iae;
+ }
+ }
+
/**
* Returns the value of the named MIME type parameter, or <code>null</code>
* if the parameter does not exist. Given the parameter name and the mime
@@ -240,7 +247,7 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
String value = mimeString.substring(idx + paramName.length() + 1);
- idx = value.indexOf(" ");
+ idx = value.indexOf(";");
if (idx == -1)
return(value);
else
@@ -328,6 +335,14 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
{
this.representationClass = representationClass;
this.mimeType = mimeType;
+
+ // Do some simple validity checks
+ String type = getPrimaryType() + "/" + getSubType();
+ if (type.indexOf(' ') != -1
+ || type.indexOf('=') != -1
+ || type.indexOf(';') != -1)
+ throw new IllegalArgumentException(mimeType);
+
if (humanPresentableName != null)
this.humanPresentableName = humanPresentableName;
else
@@ -375,7 +390,7 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
ClassLoader classLoader)
throws ClassNotFoundException
{
- this(getRepresentationClassFromMime(mimeType, classLoader),
+ this(getRepresentationClassFromMimeThrows(mimeType, classLoader),
mimeType, humanPresentableName);
}
@@ -417,7 +432,8 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
*/
public DataFlavor(String mimeType) throws ClassNotFoundException
{
- this(mimeType, null);
+ this(getRepresentationClassFromMimeThrows(mimeType, null),
+ mimeType, null);
}
/**
@@ -567,7 +583,7 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
*/
public boolean isRepresentationClassInputStream()
{
- return representationClass.getName().equals("java.io.InputStream");
+ return InputStream.class.isAssignableFrom(representationClass);
}
/**
@@ -579,17 +595,7 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
*/
public boolean isRepresentationClassSerializable()
{
- Class[] interfaces = representationClass.getInterfaces();
-
- int i = 0;
- while (i < interfaces.length)
- {
- if (interfaces[i].getName().equals("java.io.Serializable"))
- return true;
- ++i;
- }
-
- return false;
+ return Serializable.class.isAssignableFrom(representationClass);
}
/**
@@ -634,8 +640,10 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
*/
public boolean isFlavorJavaFileListType()
{
- if (mimeType.equals(javaFileListFlavor.mimeType)
- && representationClass.equals(javaFileListFlavor.representationClass))
+ if (getPrimaryType().equals(javaFileListFlavor.getPrimaryType())
+ && getSubType().equals(javaFileListFlavor.getSubType())
+ && javaFileListFlavor.representationClass
+ .isAssignableFrom(representationClass))
return true;
return false ;
@@ -666,7 +674,11 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
/**
* This method test the specified <code>DataFlavor</code> for equality
* against this object. This will be true if the MIME type and
- * representation type are the equal.
+ * representation class are the equal. If the primary type is 'text'
+ * then also the value of the charset parameter is compared. In such a
+ * case when the charset parameter isn't given then the charset is
+ * assumed to be equal to the default charset of the platform. All
+ * other parameters are ignored.
*
* @param flavor The <code>DataFlavor</code> to test against.
*
@@ -677,12 +689,34 @@ public class DataFlavor implements java.io.Externalizable, Cloneable
{
if (flavor == null)
return false;
-
- if (! this.mimeType.toLowerCase().equals(flavor.mimeType.toLowerCase()))
+
+ String primary = getPrimaryType();
+ if (! primary.equals(flavor.getPrimaryType()))
return false;
-
+
+ String sub = getSubType();
+ if (! sub.equals(flavor.getSubType()))
+ return false;
+
if (! this.representationClass.equals(flavor.representationClass))
return false;
+
+ if (primary.equals("text"))
+ if (! isRepresentationClassCharBuffer()
+ && ! isRepresentationClassReader()
+ && representationClass != java.lang.String.class
+ && ! (representationClass.isArray()
+ && representationClass.getComponentType() == Character.TYPE))
+ {
+ String charset = getParameter("charset");
+ String otherset = flavor.getParameter("charset");
+ String defaultset = Charset.defaultCharset().name();
+
+ if (charset == null || charset.equals(defaultset))
+ return (otherset == null || otherset.equals(defaultset));
+
+ return charset.equals(otherset);
+ }
return true;
}
diff --git a/java/awt/event/KeyEvent.java b/java/awt/event/KeyEvent.java
index d4b93ba3e..42084d733 100644
--- a/java/awt/event/KeyEvent.java
+++ b/java/awt/event/KeyEvent.java
@@ -993,6 +993,27 @@ public class KeyEvent extends InputEvent
public static final int VK_ALT_GRAPH = 65406;
/**
+ * The 'begin' key VK_BEGIN
+ *
+ * @since 1.5
+ */
+ public static final int VK_BEGIN = 65368;
+
+ /**
+ * The context-menu key VK_CONTEXT_MENU
+ *
+ * @since 1.5
+ */
+ public static final int VK_CONTEXT_MENU = 525;
+
+ /**
+ * The 'Windows' key VK_WINDOWS
+ *
+ * @since 1.5
+ */
+ public static final int VK_WINDOWS = 524;
+
+ /**
* The virtual key VK_UNDEFINED. This is used for key typed events, which
* do not have a virtual key.
*/
diff --git a/java/awt/font/FontRenderContext.java b/java/awt/font/FontRenderContext.java
index 78564a647..c50e5e509 100644
--- a/java/awt/font/FontRenderContext.java
+++ b/java/awt/font/FontRenderContext.java
@@ -83,7 +83,15 @@ public class FontRenderContext
public boolean equals (FontRenderContext rhs)
{
- return (affineTransform.equals (rhs.getTransform ())
+ if (rhs == null)
+ return false;
+
+ if (affineTransform == null && rhs.affineTransform != null
+ || affineTransform != null && rhs.affineTransform == null)
+ return false;
+
+ return ((affineTransform == rhs.affineTransform
+ || affineTransform.equals (rhs.getTransform ()))
&& isAntiAliased == rhs.isAntiAliased ()
&& usesFractionalMetrics == rhs.usesFractionalMetrics ());
}
diff --git a/java/awt/font/LineBreakMeasurer.java b/java/awt/font/LineBreakMeasurer.java
index c2a6d45d9..816c7745c 100644
--- a/java/awt/font/LineBreakMeasurer.java
+++ b/java/awt/font/LineBreakMeasurer.java
@@ -41,57 +41,41 @@ package java.awt.font;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.text.BreakIterator;
-import java.awt.font.TextLayout;
-import java.awt.font.FontRenderContext;
import java.awt.Shape;
public final class LineBreakMeasurer
{
private AttributedCharacterIterator text;
private int position;
- private FontRenderContext frc;
- private TextLayout totalLayout;
+ private TextMeasurer tm;
private int numChars;
public LineBreakMeasurer(AttributedCharacterIterator text,
BreakIterator breakIter, FontRenderContext frc)
{
- this.text = text;
- this.frc = frc;
- position = 0;
- totalLayout = new TextLayout(text, frc);
- numChars = totalLayout.getCharacterCount();
+ this( text, frc );
}
public LineBreakMeasurer(AttributedCharacterIterator text,
FontRenderContext frc)
{
this.text = text;
- this.frc = frc;
position = 0;
- totalLayout = new TextLayout(text, frc);
- numChars = totalLayout.getCharacterCount();
+ numChars = text.getEndIndex();
+ tm = new TextMeasurer( text, frc );
}
public void deleteChar(AttributedCharacterIterator newParagraph,
int deletePos)
{
- totalLayout = new TextLayout(newParagraph, frc);
- if( deletePos < 0 || deletePos > totalLayout.getCharacterCount() )
- throw new NullPointerException("Invalid deletePos:"+deletePos);
- numChars = totalLayout.getCharacterCount();
- text = newParagraph;
+ tm.deleteChar( newParagraph, deletePos );
position = 0;
}
public void insertChar(AttributedCharacterIterator newParagraph,
int insertPos)
{
- totalLayout = new TextLayout(newParagraph, frc);
- if( insertPos < 0 || insertPos > totalLayout.getCharacterCount() )
- throw new NullPointerException("Invalid insertPos:"+insertPos);
- numChars = totalLayout.getCharacterCount();
- text = newParagraph;
+ tm.insertChar( newParagraph, insertPos );
position = 0;
}
@@ -104,11 +88,9 @@ public final class LineBreakMeasurer
boolean requireNextWord)
{
int next = nextOffset( wrappingWidth, offsetLimit, requireNextWord );
- AttributedCharacterIterator aci = (new AttributedString( text,
- position, next )
- ).getIterator();
+ TextLayout tl = tm.getLayout( position, next );
position = next;
- return new TextLayout( aci, frc );
+ return tl;
}
public int nextOffset(float wrappingWidth)
@@ -119,69 +101,40 @@ public final class LineBreakMeasurer
public int nextOffset(float wrappingWidth, int offsetLimit,
boolean requireNextWord)
{
- Shape s = totalLayout.getBlackBoxBounds( position, offsetLimit );
- double remainingLength = s.getBounds2D().getWidth();
+ int guessOffset = tm.getLineBreakIndex(position, wrappingWidth);
+ if( offsetLimit > numChars )
+ offsetLimit = numChars;
- int guessOffset = (int)( ( (double)wrappingWidth / (double)remainingLength)
- * ( (double)numChars - (double)position ) );
- guessOffset += position;
if( guessOffset > offsetLimit )
- guessOffset = offsetLimit;
-
- s = totalLayout.getBlackBoxBounds( position, guessOffset );
- double guessLength = s.getBounds2D().getWidth();
-
- boolean makeSmaller = ( guessLength > wrappingWidth );
- int inc = makeSmaller ? -1 : 1;
- boolean keepGoing = true;
-
- do
{
- guessOffset = guessOffset + inc;
- if( guessOffset <= position || guessOffset > offsetLimit )
- {
- keepGoing = false;
- }
- else
- {
- s = totalLayout.getBlackBoxBounds( position, guessOffset );
- guessLength = s.getBounds2D().getWidth();
- if( makeSmaller && ( guessLength <= wrappingWidth) )
- keepGoing = false;
- if( !makeSmaller && ( guessLength >= wrappingWidth) )
- keepGoing = false;
- }
+ text.setIndex( offsetLimit );
+ return offsetLimit;
}
- while( keepGoing );
- if( !makeSmaller )
- guessOffset--;
+ text.setIndex( guessOffset );
- if( guessOffset >= offsetLimit )
- return offsetLimit;
+ // If we're on a breaking character, return directly
+ if( Character.isWhitespace( text.current() ) )
+ return guessOffset;
- text.setIndex( guessOffset );
+ // Otherwise jump forward or backward to the last such char.
if( !requireNextWord )
- {
- char c = text.previous();
- while( !Character.isWhitespace( c ) && c != '-' &&
- guessOffset > position )
- {
- guessOffset--;
- c = text.previous();
- }
- }
+ while( !Character.isWhitespace( text.previous() ) &&
+ guessOffset > position )
+ guessOffset--;
else
+ while( !Character.isWhitespace( text.next() ) &&
+ guessOffset < offsetLimit )
+ guessOffset++;
+
+ if( guessOffset > offsetLimit )
{
- char c = text.next();
- while( !Character.isWhitespace( c ) && c != '-' &&
- guessOffset < offsetLimit )
- {
- guessOffset++;
- c = text.next();
- }
+ text.setIndex( offsetLimit );
+ return offsetLimit;
}
+ text.setIndex( guessOffset );
+
return guessOffset;
}
diff --git a/java/awt/font/TextLayout.java b/java/awt/font/TextLayout.java
index a55aab235..9b85d7003 100644
--- a/java/awt/font/TextLayout.java
+++ b/java/awt/font/TextLayout.java
@@ -47,6 +47,7 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
+import java.text.CharacterIterator;
import java.text.AttributedCharacterIterator;
import java.text.Bidi;
import java.util.Map;
@@ -71,6 +72,12 @@ public final class TextLayout implements Cloneable
private int[][] runIndices;
/**
+ * Character indices.
+ * Fixt index is the glyphvector, second index is the (first) glyph.
+ */
+ private int[][] charIndices;
+
+ /**
* Base directionality, determined from the first char.
*/
private boolean leftToRight;
@@ -137,6 +144,7 @@ public final class TextLayout implements Cloneable
Font.LAYOUT_LEFT_TO_RIGHT :
Font.LAYOUT_RIGHT_TO_LEFT );
}
+ setCharIndices();
}
public TextLayout (String string,
@@ -147,9 +155,97 @@ public final class TextLayout implements Cloneable
}
public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
- throws NotImplementedException
{
- throw new Error ("not implemented");
+ // FIXME: Very rudimentary.
+ this(getText(text), getFont(text), frc);
+ }
+
+ /**
+ * Package-private constructor to make a textlayout from an existing one.
+ * This is used by TextMeasurer for returning sub-layouts, and it
+ * saves a lot of time in not having to relayout the text.
+ */
+ TextLayout(TextLayout t, int startIndex, int endIndex)
+ {
+ font = t.font;
+ frc = t.frc;
+ boundsCache = null;
+ lm = t.lm;
+ leftToRight = t.leftToRight;
+
+ if( endIndex > t.getCharacterCount() )
+ endIndex = t.getCharacterCount();
+ string = t.string.substring( startIndex, endIndex );
+
+ int startingRun = t.charIndices[startIndex][0];
+ int nRuns = 1 + t.charIndices[endIndex - 1][0] - startingRun;
+ runIndices = new int[ nRuns ][2];
+
+ runs = new GlyphVector[ nRuns ];
+ for( int i = 0; i < nRuns; i++ )
+ {
+ GlyphVector run = t.runs[ i + startingRun ];
+ // Copy only the relevant parts of the first and last runs.
+ int beginGlyphIndex = (i > 0) ? 0 : t.charIndices[startIndex][1];
+ int numEntries = ( i < nRuns - 1) ? run.getNumGlyphs() :
+ 1 + t.charIndices[endIndex - 1][1] - beginGlyphIndex;
+
+ int[] codes = run.getGlyphCodes(beginGlyphIndex, numEntries, null);
+ runs[ i ] = font.createGlyphVector( frc, codes );
+ runIndices[ i ][0] = t.runIndices[i + startingRun][0] - startIndex;
+ runIndices[ i ][1] = t.runIndices[i + startingRun][1] - startIndex;
+ }
+ runIndices[ nRuns - 1 ][1] = endIndex - 1;
+
+ setCharIndices();
+ determineWhiteSpace();
+ }
+
+ private void setCharIndices()
+ {
+ charIndices = new int[ getCharacterCount() ][2];
+ int i = 0;
+ int currentChar = 0;
+ for(int run = 0; run < runs.length; run++)
+ {
+ currentChar = -1;
+ for( int gi = 0; gi < runs[ run ].getNumGlyphs(); gi++)
+ {
+ if( runs[ run ].getGlyphCharIndex( gi ) != currentChar )
+ {
+ charIndices[ i ][0] = run;
+ charIndices[ i ][1] = gi;
+ currentChar = runs[ run ].getGlyphCharIndex( gi );
+ i++;
+ }
+ }
+ }
+ }
+
+ private static String getText(AttributedCharacterIterator iter)
+ {
+ StringBuffer sb = new StringBuffer();
+ int idx = iter.getIndex();
+ for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
+ sb.append(c);
+ iter.setIndex( idx );
+ return sb.toString();
+ }
+
+ private static Font getFont(AttributedCharacterIterator iter)
+ {
+ Font f = (Font)iter.getAttribute(TextAttribute.FONT);
+ if( f == null )
+ {
+ int size;
+ Float i = (Float)iter.getAttribute(TextAttribute.SIZE);
+ if( i != null )
+ size = (int)i.floatValue();
+ else
+ size = 14;
+ f = new Font("Dialog", Font.PLAIN, size );
+ }
+ return f;
}
/**
@@ -179,10 +275,14 @@ public final class TextLayout implements Cloneable
gotDirection = true;
break;
}
+ determineWhiteSpace();
+ }
+ private void determineWhiteSpace()
+ {
// Determine if there's whitespace in the thing.
// Ignore trailing chars.
- i = string.length() - 1;
+ int i = string.length() - 1;
hasWhitespace = false;
while( i >= 0 && Character.isWhitespace( string.charAt(i) ) )
i--;
@@ -251,56 +351,42 @@ public final class TextLayout implements Cloneable
public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint)
{
- if( firstEndpoint < 0 || secondEndpoint > getCharacterCount() )
+ if( secondEndpoint - firstEndpoint <= 0 )
+ return new Rectangle2D.Float(); // Hmm?
+
+ if( firstEndpoint < 0 || secondEndpoint > getCharacterCount())
return new Rectangle2D.Float();
GeneralPath gp = new GeneralPath();
- int i = 0; // run index
- double advance = 0;
-
- // go to first run
- while( runIndices[i + 1][1] < firstEndpoint )
- {
- advance += runs[i].getLogicalBounds().getWidth();
- i++;
- }
+
+ int ri = charIndices[ firstEndpoint ][0];
+ int gi = charIndices[ firstEndpoint ][1];
- int j = 0; // index into the run.
- if( runIndices[i][1] - runIndices[i][0] > 1 )
+ double advance = 0;
+
+ for( int i = 0; i < ri; i++ )
+ advance += runs[i].getLogicalBounds().getWidth();
+
+ for( int i = ri; i <= charIndices[ secondEndpoint - 1 ][0]; i++ )
{
- while( runs[i].getGlyphCharIndex( j + 1 ) <
- (firstEndpoint - runIndices[i][0] ) )j++;
- }
-
- gp.append(runs[i].getGlyphVisualBounds( j ), false);
- boolean keepGoing = true;;
+ int dg;
+ if( i == charIndices[ secondEndpoint - 1 ][0] )
+ dg = charIndices[ secondEndpoint - 1][1];
+ else
+ dg = runs[i].getNumGlyphs() - 1;
- do
- {
- while( j < runs[i].getNumGlyphs() &&
- runs[i].getGlyphCharIndex( j ) + runIndices[i][0] <
- secondEndpoint )
+ for( int j = 0; j <= dg; j++ )
{
Rectangle2D r2 = (runs[i].getGlyphVisualBounds( j )).
getBounds2D();
Point2D p = runs[i].getGlyphPosition( j );
- r2.setRect( advance + p.getX(), r2.getY(),
+ r2.setRect( advance + r2.getX(), r2.getY(),
r2.getWidth(), r2.getHeight() );
gp.append(r2, false);
- j++;
}
- if( j >= runs[i].getNumGlyphs() )
- {
- advance += runs[i].getLogicalBounds().getWidth();
- i++;
- j = 0;
- }
- else
- keepGoing = false;
+ advance += runs[i].getLogicalBounds().getWidth();
}
- while( keepGoing );
-
return gp;
}
@@ -384,55 +470,42 @@ public final class TextLayout implements Cloneable
public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,
Rectangle2D bounds)
{
- if( firstEndpoint < 0 || secondEndpoint > getCharacterCount() )
+ if( secondEndpoint - firstEndpoint <= 0 )
+ return new Rectangle2D.Float(); // Hmm?
+
+ if( firstEndpoint < 0 || secondEndpoint > getCharacterCount())
return new Rectangle2D.Float();
- int i = 0; // run index
- double advance = 0;
+ Rectangle2D r = null;
+ int ri = charIndices[ firstEndpoint ][0];
+ int gi = charIndices[ firstEndpoint ][1];
- // go to first run
- if( i > 0 )
- while( runIndices[i + 1][1] < firstEndpoint )
- {
- advance += runs[i].getLogicalBounds().getWidth();
- i++;
- }
+ double advance = 0;
+
+ for( int i = 0; i < ri; i++ )
+ advance += runs[i].getLogicalBounds().getWidth();
- int j = 0; // index into the run.
- if( runIndices[i][1] - runIndices[i][0] > 1 )
+ for( int i = ri; i <= charIndices[ secondEndpoint - 1 ][0]; i++ )
{
- while( runs[i].getGlyphCharIndex( j + 1 ) <
- (firstEndpoint - runIndices[i][0] ) )j++;
- }
-
- Rectangle2D r = (runs[i].getGlyphLogicalBounds( j )).getBounds2D();
- boolean keepGoing = true;;
+ int dg; // last index in this run to use.
+ if( i == charIndices[ secondEndpoint - 1 ][0] )
+ dg = charIndices[ secondEndpoint - 1][1];
+ else
+ dg = runs[i].getNumGlyphs() - 1;
- do
- {
- while( j < runs[i].getNumGlyphs() &&
- runs[i].getGlyphCharIndex( j ) + runIndices[i][0] <
- secondEndpoint )
+ for(; gi <= dg; gi++ )
{
- Rectangle2D r2 = (runs[i].getGlyphLogicalBounds( j )).
+ Rectangle2D r2 = (runs[i].getGlyphLogicalBounds( gi )).
getBounds2D();
- Point2D p = runs[i].getGlyphPosition( j );
- r2.setRect( advance + p.getX(), r2.getY(),
- r2.getWidth(), r2.getHeight() );
- r = r.createUnion( r2 );
- j++;
+ if( r == null )
+ r = r2;
+ else
+ r = r.createUnion(r2);
}
+ gi = 0; // reset glyph index into run for next run.
- if( j >= runs[i].getNumGlyphs() )
- {
- advance += runs[i].getLogicalBounds().getWidth();
- i++;
- j = 0;
- }
- else
- keepGoing = false;
+ advance += runs[i].getLogicalBounds().getWidth();
}
- while( keepGoing );
return r;
}
diff --git a/java/awt/font/TextMeasurer.java b/java/awt/font/TextMeasurer.java
index 18c286c57..e91c7ef16 100644
--- a/java/awt/font/TextMeasurer.java
+++ b/java/awt/font/TextMeasurer.java
@@ -1,5 +1,5 @@
/* TextMeasurer.java
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,67 +38,152 @@ exception statement from your version. */
package java.awt.font;
-import gnu.classpath.NotImplementedException;
-
import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
+import java.awt.Shape;
/**
- * @author Michael Koch
+ * TextMeasurer is a small utility class for measuring the length of laid-out
+ * text objects.
+ *
+ * @author Sven de Marothy
* @since 1.3
*/
public final class TextMeasurer implements Cloneable
{
- private AttributedCharacterIterator ci;
+ private AttributedCharacterIterator text;
private FontRenderContext frc;
-
+ private TextLayout totalLayout;
+ private int numChars;
+
+ /**
+ * Creates a TextMeasurer from a given text in the form of an
+ * <code>AttributedCharacterIterator</code> and a
+ * <code>FontRenderContext</code>.
+ */
public TextMeasurer (AttributedCharacterIterator text, FontRenderContext frc)
{
- this.ci = text;
+ this.text = text;
this.frc = frc;
+ totalLayout = new TextLayout( text, frc );
+ numChars = totalLayout.getCharacterCount();
}
+ /**
+ * Clones the TextMeasurer object
+ */
protected Object clone ()
{
- try
- {
- return super.clone ();
- }
- catch (CloneNotSupportedException e)
- {
- // This may never occur
- throw new InternalError ();
- }
+ return new TextMeasurer( text, frc );
}
+ /**
+ * Update the text if a character is deleted at the position deletePos
+ * @param newParagraph - the updated paragraph.
+ * @param deletePos - the deletion position
+ */
public void deleteChar (AttributedCharacterIterator newParagraph,
int deletePos)
- throws NotImplementedException
{
- throw new Error ("not implemented");
+ totalLayout = new TextLayout(newParagraph, frc);
+ if( deletePos < 0 || deletePos > totalLayout.getCharacterCount() )
+ throw new NullPointerException("Invalid deletePos:"+deletePos);
+ numChars = totalLayout.getCharacterCount();
+ text = newParagraph;
+ }
+
+ /**
+ * Update the text if a character is inserted at the position insertPos
+ * @param newParagraph - the updated paragraph.
+ * @param insertPos - the insertion position
+ */
+ public void insertChar (AttributedCharacterIterator newParagraph,
+ int insertPos)
+ {
+ totalLayout = new TextLayout(newParagraph, frc);
+ if( insertPos < 0 || insertPos > totalLayout.getCharacterCount() )
+ throw new NullPointerException("Invalid insertPos:"+insertPos);
+ numChars = totalLayout.getCharacterCount();
+ text = newParagraph;
}
+ /***
+ * Returns the total advance between two positions in the paragraph.
+ * Characters from start to limit-1 (inclusive) are included in this count.
+ *
+ * @param start - the starting character index.
+ * @param limit - the limiting index.
+ */
public float getAdvanceBetween (int start, int limit)
- throws NotImplementedException
{
- throw new Error ("not implemented");
+ Shape s = totalLayout.getLogicalHighlightShape( start, limit );
+ return (float)s.getBounds2D().getWidth();
}
+ /**
+ * Returns a <code>TextLayout</code> object corresponding to the characters
+ * from text to limit.
+ * @param start - the starting character index.
+ * @param limit - the limiting index.
+ */
public TextLayout getLayout (int start, int limit)
- throws NotImplementedException
{
- throw new Error ("not implemented");
+ return new TextLayout( totalLayout, start, limit );
}
+ /**
+ * Returns the line-break index from a given starting index and a maximum
+ * advance. The index returned is the first character outside the given
+ * advance (or the limit of the string, if all remaining characters fit.)
+ *
+ * @param start - the starting index.
+ * @param maxAdvance - the maximum advance allowed.
+ * @return the index of the first character beyond maxAdvance, or the
+ * index of the last character + 1.
+ */
public int getLineBreakIndex (int start, float maxAdvance)
- throws NotImplementedException
- {
- throw new Error ("not implemented");
- }
+ {
+ if( start < 0 )
+ throw new IllegalArgumentException("Start parameter must be > 0.");
+
+ double remainingLength = getAdvanceBetween( start, numChars );
+
+ int guessOffset = (int)( ( (double)maxAdvance / (double)remainingLength)
+ * ( (double)numChars - (double)start ) );
+ guessOffset += start;
+ if( guessOffset > numChars )
+ guessOffset = numChars;
+
+ double guessLength = getAdvanceBetween( start, guessOffset );
+ boolean makeSmaller = ( guessLength > maxAdvance );
+ int inc = makeSmaller ? -1 : 1;
+ boolean keepGoing = true;
+
+ do
+ {
+ guessOffset = guessOffset + inc;
+ if( guessOffset <= start || guessOffset > numChars )
+ {
+ keepGoing = false;
+ }
+ else
+ {
+ guessLength = getAdvanceBetween( start, guessOffset );
+ if( makeSmaller && ( guessLength <= maxAdvance) )
+ keepGoing = false;
+ if( !makeSmaller && ( guessLength >= maxAdvance) )
+ keepGoing = false;
+ }
+ }
+ while( keepGoing );
- public void insertChar (AttributedCharacterIterator newParagraph,
- int insertPos)
- throws NotImplementedException
- {
- throw new Error ("not implemented");
+ // Return first index that doesn't fit.
+ if( !makeSmaller )
+ guessOffset--;
+
+ if( guessOffset > numChars )
+ return numChars;
+
+ return guessOffset;
}
}
diff --git a/java/awt/image/BufferedImage.java b/java/awt/image/BufferedImage.java
index e79a09a0f..6026e7898 100644
--- a/java/awt/image/BufferedImage.java
+++ b/java/awt/image/BufferedImage.java
@@ -504,7 +504,10 @@ public class BufferedImage extends Image
int[] pixels = getRGB(x, y,
width, height,
(int[])null, offset, stride);
- ColorModel model = getColorModel();
+ // We already convert the color to RGB in the getRGB call, so
+ // we pass a simple RGB color model to the consumers.
+ ColorModel model = new DirectColorModel(32, 0xff0000, 0xff00, 0xff,
+ 0xff000000);
consumers.add(ic);
diff --git a/java/lang/Thread.java b/java/lang/Thread.java
index e039b4703..9a3e3a6f0 100644
--- a/java/lang/Thread.java
+++ b/java/lang/Thread.java
@@ -1254,4 +1254,19 @@ public class Thread implements Runnable
private static final long serialVersionUID = 605505746047245783L;
}
+
+ /**
+ * Returns the current state of the thread. This
+ * is designed for monitoring thread behaviour, rather
+ * than for synchronization control.
+ *
+ * @return the current thread state.
+ */
+ public State getState()
+ {
+ VMThread t = vmThread;
+ return t == null ? null : State.valueOf(t.getState());
+ }
+
+
}
diff --git a/java/lang/management/ClassLoadingMXBean.java b/java/lang/management/ClassLoadingMXBean.java
new file mode 100644
index 000000000..2a8651b9c
--- /dev/null
+++ b/java/lang/management/ClassLoadingMXBean.java
@@ -0,0 +1,103 @@
+/* ClassLoadingMXBean.java - Interface for a class loading bean
+ Copyright (C) 2006 Free Software Foundation
+
+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 java.lang.management;
+
+/**
+ * Provides access to information about the class loading
+ * behaviour of the current invocation of the virtual
+ * machine. An instance of this bean is obtained by calling
+ * {@link ManagementFactory#getClassLoadingMXBean()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public interface ClassLoadingMXBean
+{
+
+ /**
+ * Returns the number of classes currently loaded by
+ * the virtual machine.
+ *
+ * @return the number of loaded classes.
+ */
+ int getLoadedClassCount();
+
+ /**
+ * Returns the total number of classes loaded by the
+ * virtual machine since it was started. This is the
+ * sum of the currently loaded classes and those that
+ * have been unloaded.
+ *
+ * @return the total number of classes that have been
+ * loaded by the virtual machine since it started.
+ */
+ long getTotalLoadedClassCount();
+
+ /**
+ * Returns the number of classes that have been unloaded
+ * by the virtual machine since it was started.
+ *
+ * @return the number of unloaded classes.
+ */
+ long getUnloadedClassCount();
+
+ /**
+ * Returns true if the virtual machine will emit additional
+ * information when classes are loaded and unloaded. The
+ * format of the output is left up to the virtual machine.
+ *
+ * @return true if verbose class loading output is on.
+ */
+ boolean isVerbose();
+
+ /**
+ * Turns on or off the emission of additional information
+ * when classes are loaded and unloaded. The format of the
+ * output is left up to the virtual machine. This method
+ * may be called by multiple threads concurrently, but there
+ * is only one global setting of verbosity that is affected.
+ *
+ * @param verbose the new setting for verbose class loading
+ * output.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("control").
+ */
+ void setVerbose(boolean verbose);
+
+}
+
diff --git a/java/lang/management/ManagementFactory.java b/java/lang/management/ManagementFactory.java
index b3db1b96d..5f99bbe1d 100644
--- a/java/lang/management/ManagementFactory.java
+++ b/java/lang/management/ManagementFactory.java
@@ -37,6 +37,9 @@ exception statement from your version. */
package java.lang.management;
+import gnu.classpath.NotImplementedException;
+
+import gnu.java.lang.management.ClassLoadingMXBeanImpl;
import gnu.java.lang.management.OperatingSystemMXBeanImpl;
import gnu.java.lang.management.RuntimeMXBeanImpl;
@@ -71,6 +74,11 @@ public class ManagementFactory
private static RuntimeMXBean runtimeBean;
/**
+ * The class loading management bean.
+ */
+ private static ClassLoadingMXBean classLoadingBean;
+
+ /**
* Private constructor to prevent instance creation.
*/
private ManagementFactory() {}
@@ -103,4 +111,31 @@ public class ManagementFactory
return runtimeBean;
}
+ /**
+ * Returns the class loading management bean for the
+ * running virtual machine.
+ *
+ * @return an instance of {@link ClassLoadingMXBean} for
+ * this virtual machine.
+ */
+ public static ClassLoadingMXBean getClassLoadingMXBean()
+ {
+ if (classLoadingBean == null)
+ classLoadingBean = new ClassLoadingMXBeanImpl();
+ return classLoadingBean;
+ }
+
+ /**
+ * Returns the thread management bean for the running
+ * virtual machine.
+ *
+ * @return an instance of {@link ThreadMXBean} for
+ * this virtual machine.
+ */
+ public static ThreadMXBean getThreadMXBean()
+ throws NotImplementedException
+ {
+ return null;
+ }
+
}
diff --git a/java/lang/management/OperatingSystemMXBean.java b/java/lang/management/OperatingSystemMXBean.java
index 74b9ae5a1..2430a9fbf 100644
--- a/java/lang/management/OperatingSystemMXBean.java
+++ b/java/lang/management/OperatingSystemMXBean.java
@@ -39,7 +39,7 @@ package java.lang.management;
/**
* Provides access to information about the underlying operating
- * system. Instances of this bean are obtained by calling
+ * system. An instance of this bean is obtained by calling
* {@link ManagementFactory#getOperatingSystemMXBean()}.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
diff --git a/java/lang/management/RuntimeMXBean.java b/java/lang/management/RuntimeMXBean.java
index 59b6d0eb1..a2931d127 100644
--- a/java/lang/management/RuntimeMXBean.java
+++ b/java/lang/management/RuntimeMXBean.java
@@ -42,7 +42,7 @@ import java.util.Map;
/**
* Provides access to information about the underlying virtual
- * machine. Instances of this bean are obtained by calling
+ * machine. An instance of this bean is obtained by calling
* {@link ManagementFactory#getRuntimeMXBean()}.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
diff --git a/java/lang/management/ThreadInfo.java b/java/lang/management/ThreadInfo.java
new file mode 100644
index 000000000..53c6651ee
--- /dev/null
+++ b/java/lang/management/ThreadInfo.java
@@ -0,0 +1,405 @@
+/* ThreadInfo.java - Information on a thread
+ Copyright (C) 2006 Free Software Foundation
+
+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 java.lang.management;
+
+/**
+ * <p>
+ * A class which maintains information about a particular
+ * thread. This information includes:
+ * </p>
+ * <ul>
+ * <li><strong>General Thread Information:</strong>
+ * <ul>
+ * <li>The identifier of the thread.</li>
+ * <li>The name of the thread.</li>
+ * </ul>
+ * </li>
+ * <li><strong>Execution Information:</strong>
+ * <ul>
+ * <li>The current state of the thread (e.g. blocked, runnable)</li>
+ * <li>The object upon which the thread is blocked, either because
+ * the thread is waiting to obtain the monitor of that object to enter
+ * one of its synchronized monitor, or because
+ * {@link java.lang.Object#wait()} has been called while the thread
+ * was within a method of that object.</li>
+ * <li>The thread identifier of the current thread holding an object's
+ * monitor, upon which the thread described here is blocked.</li>
+ * <li>The stack trace of the thread (if requested on creation
+ * of this object</li>
+ * </ul>
+ * <li><strong>Synchronization Statistics</strong>
+ * <ul>
+ * <li>The number of times the thread has been blocked waiting for
+ * an object's monitor or in a {@link java.lang.Object#wait()} call.</li>
+ * <li>The accumulated time the thread has been blocked waiting for
+ * an object's monitor on in a {@link java.lang.Object#wait()} call.
+ * The availability of these statistics depends on the virtual machine's
+ * support for thread contention monitoring (see
+ * {@link ThreadMXBean#isThreadContentionMonitoringSupported()}.</li>
+ * </ul>
+ * </li>
+ * </ul>
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ * @see ThreadMXBean#isThreadContentionMonitoringSupported()
+ */
+public class ThreadInfo
+{
+
+ /**
+ * The thread which this instance concerns.
+ */
+ private Thread thread;
+
+ /**
+ * The maximum depth of the stack traces for this thread.
+ */
+ private int maxDepth;
+
+ /**
+ * Cache a local reference to the thread management bean.
+ */
+ private static ThreadMXBean bean = null;
+
+ /**
+ * Constructs a new {@link ThreadInfo} corresponding
+ * to the thread specified.
+ *
+ * @param thread the thread on which the new instance
+ * will be based.
+ */
+ ThreadInfo(Thread thread, int maxDepth)
+ {
+ this.thread = thread;
+ this.maxDepth = maxDepth;
+ }
+
+ /**
+ * Returns the number of times this thread has been
+ * in the {@link java.lang.Thread.State#BLOCKED} state.
+ * A thread enters this state when it is waiting to
+ * obtain an object's monitor. This may occur either
+ * on entering a synchronized method for the first time,
+ * or on re-entering it following a call to
+ * {@link java.lang.Object#wait()}.
+ *
+ * @return the number of times this thread has been blocked.
+ */
+ public long getBlockedCount()
+ {
+ return VMThreadInfo.getBlockedCount(thread);
+ }
+
+ /**
+ * <p>
+ * Returns the accumulated number of milliseconds this
+ * thread has been in the
+ * {@link java.lang.Thread.State#BLOCKED} state
+ * since thread contention monitoring was last enabled.
+ * A thread enters this state when it is waiting to
+ * obtain an object's monitor. This may occur either
+ * on entering a synchronized method for the first time,
+ * or on re-entering it following a call to
+ * {@link java.lang.Object#wait()}.
+ * </p>
+ * <p>
+ * Use of this method requires virtual machine support
+ * for thread contention monitoring and for this support
+ * to be enabled.
+ * </p>
+ *
+ * @return the accumulated time (in milliseconds) that this
+ * thread has spent in the blocked state, since
+ * thread contention monitoring was enabled, or -1
+ * if thread contention monitoring is disabled.
+ * @throws UnsupportedOperationException if the virtual
+ * machine does not
+ * support contention
+ * monitoring.
+ * @see ThreadMXBean#isThreadContentionMonitoringEnabled()
+ * @see ThreadMXBean#isThreadContentionMonitoringSupported()
+ */
+ public long getBlockedTime()
+ {
+ if (bean == null)
+ bean = ManagementFactory.getThreadMXBean();
+ // Will throw UnsupportedOperationException for us
+ if (bean.isThreadContentionMonitoringEnabled())
+ return VMThreadInfo.getBlockedTime(thread);
+ else
+ return -1;
+ }
+
+ /**
+ * <p>
+ * Returns a {@link java.lang.String} representation of
+ * the monitor lock on which this thread is blocked. If
+ * the thread is not blocked, this method returns
+ * <code>null</code>.
+ * </p>
+ * <p>
+ * The returned {@link java.lang.String} is constructed
+ * using the class name and identity hashcode (usually
+ * the memory address of the object) of the lock. The
+ * two are separated by the '@' character, and the identity
+ * hashcode is represented in hexadecimal. Thus, for a
+ * lock, <code>l</code>, the returned value is
+ * the result of concatenating
+ * <code>l.getClass().getName()</code>, <code>"@"</code>
+ * and
+ * <code>Integer.toHexString(System.identityHashCode(l))</code>.
+ * The value is only unique to the extent that the identity
+ * hash code is also unique.
+ * </p>
+ *
+ * @return a string representing the lock on which this
+ * thread is blocked, or <code>null</code> if
+ * the thread is not blocked.
+ */
+ public String getLockName()
+ {
+ if (thread.getState() == Thread.State.BLOCKED)
+ return null;
+ Object lock = VMThreadInfo.getLock(thread);
+ return lock.getClass().getName() + "@" +
+ Integer.toHexString(System.identityHashCode(lock));
+ }
+
+ /**
+ * Returns the identifier of the thread which owns the
+ * monitor lock this thread is waiting for. -1 is returned
+ * if either this thread is not blocked, or the lock is
+ * not held by any other thread.
+ *
+ * @return the thread identifier of thread holding the lock
+ * this thread is waiting for, or -1 if the thread
+ * is not blocked or the lock is not held by another
+ * thread.
+ */
+ public long getLockOwnerId()
+ {
+ if (thread.getState() == Thread.State.BLOCKED)
+ return -1;
+ Thread lockOwner = VMThreadInfo.getLockOwner(thread);
+ if (lockOwner == null)
+ return -1;
+ return lockOwner.getId();
+ }
+
+ /**
+ * Returns the name of the thread which owns the
+ * monitor lock this thread is waiting for. <code>null</code>
+ * is returned if either this thread is not blocked,
+ * or the lock is not held by any other thread.
+ *
+ * @return the thread identifier of thread holding the lock
+ * this thread is waiting for, or <code>null</code>
+ * if the thread is not blocked or the lock is not
+ * held by another thread.
+ */
+ public String getLockOwnerName()
+ {
+ if (thread.getState() == Thread.State.BLOCKED)
+ return null;
+ Thread lockOwner = VMThreadInfo.getLockOwner(thread);
+ if (lockOwner == null)
+ return null;
+ return lockOwner.getName();
+ }
+
+ /**
+ * <p>
+ * Returns the stack trace of this thread to the depth
+ * specified on creation of this {@link ThreadInfo}
+ * object. If the depth is zero, an empty array will
+ * be returned. For non-zero arrays, the elements
+ * start with the most recent trace at position zero.
+ * The bottom of the stack represents the oldest method
+ * invocation which meets the depth requirements.
+ * </p>
+ * <p>
+ * Some virtual machines may not be able to return
+ * stack trace information for a thread. In these
+ * cases, an empty array will also be returned.
+ * </p>
+ *
+ * @return an array of {@link java.lang.StackTraceElement}s
+ * representing the trace of this thread.
+ */
+ public StackTraceElement[] getStackTrace()
+ {
+ if (maxDepth == 0)
+ return new StackTraceElement[0];
+ return VMThreadInfo.getStackTrace(thread, maxDepth);
+ }
+
+ /**
+ * Returns the identifier of the thread associated with
+ * this instance of {@link ThreadInfo}.
+ *
+ * @return the thread's identifier.
+ */
+ public long getThreadId()
+ {
+ return thread.getId();
+ }
+
+ /**
+ * Returns the name of the thread associated with
+ * this instance of {@link ThreadInfo}.
+ *
+ * @return the thread's name.
+ */
+ public String getThreadName()
+ {
+ return thread.getName();
+ }
+
+ /**
+ * Returns the state of the thread associated with
+ * this instance of {@link ThreadInfo}.
+ *
+ * @return the thread's state.
+ */
+ public Thread.State getThreadState()
+ {
+ return thread.getState();
+ }
+
+ /**
+ * Returns the number of times this thread has been
+ * in the {@link java.lang.Thread.State#WAITING}
+ * or {@link java.lang.Thread.State#TIMED_WAITING} state.
+ * A thread enters one of these states when it is waiting
+ * due to a call to {@link java.lang.Object.wait()},
+ * {@link java.lang.Object.join()} or
+ * {@link java.lang.concurrent.locks.LockSupport.park()},
+ * either with an infinite or timed delay, respectively.
+ *
+ * @return the number of times this thread has been waiting.
+ */
+ public long getWaitedCount()
+ {
+ return VMThreadInfo.getWaitedCount(thread);
+ }
+
+ /**
+ * <p>
+ * Returns the accumulated number of milliseconds this
+ * thread has been in the
+ * {@link java.lang.Thread.State#WAITING} or
+ * {@link java.lang.Thread.State#TIMED_WAITING} state,
+ * since thread contention monitoring was last enabled.
+ * A thread enters one of these states when it is waiting
+ * due to a call to {@link java.lang.Object.wait()},
+ * {@link java.lang.Object.join()} or
+ * {@link java.lang.concurrent.locks.LockSupport.park()},
+ * either with an infinite or timed delay, respectively.
+ * </p>
+ * <p>
+ * Use of this method requires virtual machine support
+ * for thread contention monitoring and for this support
+ * to be enabled.
+ * </p>
+ *
+ * @return the accumulated time (in milliseconds) that this
+ * thread has spent in one of the waiting states, since
+ * thread contention monitoring was enabled, or -1
+ * if thread contention monitoring is disabled.
+ * @throws UnsupportedOperationException if the virtual
+ * machine does not
+ * support contention
+ * monitoring.
+ * @see ThreadMXBean#isThreadContentionMonitoringEnabled()
+ * @see ThreadMXBean#isThreadContentionMonitoringSupported()
+ */
+ public long getWaitedTime()
+ {
+ if (bean == null)
+ bean = ManagementFactory.getThreadMXBean();
+ // Will throw UnsupportedOperationException for us
+ if (bean.isThreadContentionMonitoringEnabled())
+ return VMThreadInfo.getWaitedTime(thread);
+ else
+ return -1;
+ }
+
+ /**
+ * Returns true if the thread is in a native method. This
+ * excludes native code which forms part of the virtual
+ * machine itself, or which results from Just-In-Time
+ * compilation.
+ *
+ * @return true if the thread is in a native method, false
+ * otherwise.
+ */
+ public boolean isInNative()
+ {
+ return VMThreadInfo.isInNative(thread);
+ }
+
+ /**
+ * Returns true if the thread has been suspended using
+ * {@link java.lang.Thread#suspend()}.
+ *
+ * @return true if the thread is suspended, false otherwise.
+ */
+ public boolean isSuspended()
+ {
+ return VMThreadInfo.isSuspended(thread);
+ }
+
+ /**
+ * Returns a {@link java.lang.String} representation of
+ * this {@link ThreadInfo} object. This takes the form
+ * <code>java.lang.ThreadInfo[id=tid, maxDepth=md]</code>,
+ * where <code>tid</code> is the thread identifier
+ * and <code>md</code> is the maximum depth used by
+ * this {@link ThreadInfo}.
+ *
+ * @return the string specified above.
+ */
+ public String toString()
+ {
+ return getClass().getName() +
+ "[id=" + thread.getId() + ", maxDepth=" +
+ maxDepth + "]";
+ }
+
+}
diff --git a/java/lang/management/ThreadMXBean.java b/java/lang/management/ThreadMXBean.java
new file mode 100644
index 000000000..2926548ad
--- /dev/null
+++ b/java/lang/management/ThreadMXBean.java
@@ -0,0 +1,497 @@
+/* ThreadMXBean.java - Interface for a thread bean
+ Copyright (C) 2006 Free Software Foundation
+
+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 java.lang.management;
+
+/**
+ * <p>
+ * Provides access to information about the threads
+ * of the virtual machine. An instance of this bean is
+ * obtained by calling
+ * {@link ManagementFactory#getThreadMXBean()}.
+ * </p>
+ * <p>
+ * Each thread within the virtual machine is given an
+ * identifier, which is guaranteed to be unique to a
+ * particular thread over its lifetime (after which it
+ * may be reused). The identifier for a thread may be
+ * obtained by calling {@link java.lang.Thread#getId()}.
+ * This identifier is used within implementations of this
+ * interface to obtain information about a particular thread
+ * (or series of threads, in the case of an array of identifiers).
+ * </p>
+ * <p>
+ * This bean supports some optional behaviour, which all
+ * virtual machines may not choose to implement. Specifically,
+ * this includes the monitoring of the CPU time used by a
+ * thread, and the monitoring of thread contention. The former
+ * is further subdivided into the monitoring of either just
+ * the current thread or all threads. The methods
+ * {@link #isThreadCpuTimeSupported()},
+ * {@link #isCurrentThreadCpuTimeSupported()} and
+ * {@link #isThreadContentionMonitoringSupported()} may be
+ * used to determine whether or not this functionality is
+ * supported.
+ * </p>
+ * <p>
+ * Furthermore, both these facilities may be disabled.
+ * In fact, thread contention monitoring is disabled by
+ * default, and must be explictly turned on by calling
+ * the {@link #setThreadContentionMonitoringEnabled(boolean)}
+ * method.
+ * </p>
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public interface ThreadMXBean
+{
+
+ /**
+ * <p>
+ * This method obtains a list of threads which are deadlocked
+ * waiting to obtain monitor ownership. On entering a synchronized
+ * method of an object, or re-entering it after returning from an
+ * {@link java.lang.Object#wait()} call, a thread obtains ownership
+ * of the object's monitor.
+ * </p>
+ * <p>
+ * Deadlocks can occur in this situation if one or more threads end up
+ * waiting for a monitor, P, while also retaining ownership of a monitor,
+ * Q, required by the thread that currently owns P. To give a simple
+ * example, imagine thread A calls a synchronized method, R, obtaining the
+ * monitor, P. It then sleeps within that method, allowing thread B
+ * to run, but still retaining ownership of P. B calls another
+ * synchronized method, S, which causes it to obtain the monitor, Q,
+ * of a different object. While in that method, it then wants to
+ * call the original synchronized method, R, called by A. Doing so
+ * requires ownership of P, which is still held by A. Hence, it
+ * becomes blocked.
+ * </p>
+ * <p>
+ * A then finishes its sleep, becomes runnable, and is then allowed
+ * to run, being the only eligible thread in this scenario. A tries
+ * to call the synchronized method, S. It also gets blocked, because
+ * B still holds the monitor, Q. Hence, the two threads, A and B,
+ * are deadlocked, as neither can give up its monitor without first
+ * obtaining the monitor held by the other thread.
+ * </p>
+ * <p>
+ * Calling this method in this scenario would return the thread IDs
+ * of A and B. Note that this method is not designed for controlling
+ * synchronization, but for troubleshooting problems which cause such
+ * deadlocks; it may be prohibitively expensive to use in normal
+ * operation.
+ * </p>
+ *
+ * @return an array of thread identifiers, corresponding to threads
+ * which are currently in a deadlocked situation.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ */
+ long[] findMonitorDeadlockedThreads();
+
+ /**
+ * Returns all live thread identifiers at the time of initial
+ * execution. Some thread identifiers in the returned array
+ * may refer to terminated threads, if this occurs during the
+ * lifetime of this method.
+ *
+ * @return an array of thread identifiers, corresponding to
+ * current live threads.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ */
+ long[] getAllThreadIds();
+
+ /**
+ * <p>
+ * Returns the total number of nanoseconds of CPU time
+ * the current thread has used. This is equivalent to calling
+ * <code>{@link #getThreadCpuTime()}(Thread.currentThread.getId())</code>.
+ * </p>
+ * <p>
+ * Note that the value is only nanosecond-precise, and not accurate; there
+ * is no guarantee that the difference between two values is really a
+ * nanosecond. Also, the value is prone to overflow if the offset
+ * exceeds 2^63. The use of this method depends on virtual machine
+ * support for measurement of the CPU time of the current thread,
+ * and on this functionality being enabled.
+ * </p>
+ *
+ * @return the total number of nanoseconds of CPU time the current
+ * thread has used, or -1 if CPU time monitoring is disabled.
+ * @throws UnsupportedOperationException if CPU time monitoring is not
+ * supported.
+ * @see #getCurrentThreadUserTime()
+ * @see #isCurrentThreadCpuTimeSupported()
+ * @see #isThreadCpuTimeEnabled()
+ * @see #setThreadCpuTimeEnabled(boolean)
+ */
+ long getCurrentThreadCpuTime();
+
+ /**
+ * <p>
+ * Returns the total number of nanoseconds of CPU time
+ * the current thread has executed in user mode. This is
+ * equivalent to calling
+ * <code>{@link #getThreadUserTime()}(Thread.currentThread.getId())</code>.
+ * </p>
+ * <p>
+ * Note that the value is only nanosecond-precise, and not accurate; there
+ * is no guarantee that the difference between two values is really a
+ * nanosecond. Also, the value is prone to overflow if the offset
+ * exceeds 2^63. The use of this method depends on virtual machine
+ * support for measurement of the CPU time of the current thread,
+ * and on this functionality being enabled.
+ * </p>
+ *
+ * @return the total number of nanoseconds of CPU time the current
+ * thread has executed in user mode, or -1 if CPU time
+ * monitoring is disabled.
+ * @throws UnsupportedOperationException if CPU time monitoring is not
+ * supported.
+ * @see #getCurrentThreadCpuTime()
+ * @see #isCurrentThreadCpuTimeSupported()
+ * @see #isThreadCpuTimeEnabled()
+ * @see #setThreadCpuTimeEnabled(boolean)
+ */
+ long getCurrentThreadUserTime();
+
+ /**
+ * Returns the number of live daemon threads.
+ *
+ * @return the number of live daemon threads.
+ */
+ int getDaemonThreadCount();
+
+ /**
+ * Returns the peak number of live threads since
+ * the virtual machine was started or the count
+ * reset using {@link #resetPeakThreadCount()}.
+ *
+ * @return the peak live thread count.
+ * @see #resetPeakThreadCount()
+ */
+ int getPeakThreadCount();
+
+ /**
+ * Returns the number of live threads, including
+ * both daemon threads and non-daemon threads.
+ *
+ * @return the current number of live threads.
+ */
+ int getThreadCount();
+
+ /**
+ * <p>
+ * Returns the total number of nanoseconds of CPU time
+ * the specified thread has used.
+ * </p>
+ * <p>
+ * Note that the value is only nanosecond-precise, and not accurate; there
+ * is no guarantee that the difference between two values is really a
+ * nanosecond. Also, the value is prone to overflow if the offset
+ * exceeds 2^63. The use of this method depends on virtual machine
+ * support for measurement of the CPU time of the current thread,
+ * and on this functionality being enabled.
+ * </p>
+ *
+ * @param id the thread identifier of the thread whose CPU time is being
+ * monitored.
+ * @return the total number of nanoseconds of CPU time the specified
+ * thread has used, or -1 if CPU time monitoring is disabled.
+ * @throws IllegalArgumentException if <code>id</code> <= 0.
+ * @throws UnsupportedOperationException if CPU time monitoring is not
+ * supported.
+ * @see #getThreadUserTime(long)
+ * @see #isThreadCpuTimeSupported()
+ * @see #isThreadCpuTimeEnabled()
+ * @see #setThreadCpuTimeEnabled(boolean)
+ */
+ long getThreadCpuTime(long id);
+
+ /**
+ * Returns information on the specified thread without any
+ * stack trace information. This is equivalent to
+ * <code>{@link #getThreadInfo}(id, 0)</code>. If the
+ * identifier specifies a thread which is either non-existant
+ * or not alive, then the method returns <code>null</code>.
+ *
+ * @param id the identifier of the thread to return information
+ * on.
+ * @return a {@link ThreadInfo} object pertaining to the specified
+ * thread, or <code>null</code> if the identifier specifies
+ * a thread that doesn't exist or is not alive.
+ * @throws IllegalArgumentException if <code>id</code> <= 0.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ */
+ ThreadInfo getThreadInfo(long id);
+
+ /**
+ * Returns information on the specified threads without any
+ * stack trace information. This is equivalent to
+ * <code>{@link #getThreadInfo}(ids, 0)</code>. If an
+ * identifier specifies a thread which is either non-existant
+ * or not alive, then the corresponding element in the returned
+ * array is <code>null</code>.
+ *
+ * @param ids an array of thread identifiers to return information
+ * on.
+ * @return an array of {@link ThreadInfo} objects matching the
+ * specified threads. The corresponding element is
+ * <code>null</code> if the identifier specifies
+ * a thread that doesn't exist or is not alive.
+ * @throws IllegalArgumentException if an identifier in the array is
+ * <= 0.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ */
+ ThreadInfo[] getThreadInfo(long[] ids);
+
+ /**
+ * Returns information on the specified thread with
+ * stack trace information to the supplied depth. If the
+ * identifier specifies a thread which is either non-existant
+ * or not alive, then the method returns <code>null</code>.
+ * A maximum depth of 0 corresponds to an empty stack trace
+ * (an empty array is returned by the appropriate
+ * {@link ThreadInfo} method). A maximum depth of
+ * <code>Integer.MAX_VALUE</code> returns the full stack trace.
+ *
+ * @param id the identifier of the thread to return information
+ * on.
+ * @param maxDepth the maximum depth of the stack trace.
+ * Values of 0 or <code>Integer.MAX_VALUE</code>
+ * correspond to an empty and full stack trace
+ * respectively.
+ * @return a {@link ThreadInfo} object pertaining to the specified
+ * thread, or <code>null</code> if the identifier specifies
+ * a thread that doesn't exist or is not alive.
+ * @throws IllegalArgumentException if <code>id</code> <= 0.
+ * @throws IllegalArgumentException if <code>maxDepth</code> <= 0.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ */
+ ThreadInfo getThreadInfo(long id, int maxDepth);
+
+ /**
+ * Returns information on the specified threads with
+ * stack trace information to the supplied depth. If an
+ * identifier specifies a thread which is either non-existant
+ * or not alive, then the corresponding element in the returned
+ * array is <code>null</code>. A maximum depth of 0 corresponds
+ * to an empty stack trace (an empty array is returned by the
+ * appropriate {@link ThreadInfo} method). A maximum depth of
+ * <code>Integer.MAX_VALUE</code> returns the full stack trace.
+ *
+ * @param ids an array of thread identifiers to return information
+ * on.
+ * @param maxDepth the maximum depth of the stack trace.
+ * Values of 0 or <code>Integer.MAX_VALUE</code>
+ * correspond to an empty and full stack trace
+ * respectively.
+ * @return an array of {@link ThreadInfo} objects matching the
+ * specified threads. The corresponding element is
+ * <code>null</code> if the identifier specifies
+ * a thread that doesn't exist or is not alive.
+ * @throws IllegalArgumentException if an identifier in the array is
+ * <= 0.
+ * @throws IllegalArgumentException if <code>maxDepth</code> <= 0.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ */
+ ThreadInfo[] getThreadInfo(long[] ids, int maxDepth);
+
+ /**
+ * <p>
+ * Returns the total number of nanoseconds of CPU time
+ * the specified thread has executed in user mode.
+ * </p>
+ * <p>
+ * Note that the value is only nanosecond-precise, and not accurate; there
+ * is no guarantee that the difference between two values is really a
+ * nanosecond. Also, the value is prone to overflow if the offset
+ * exceeds 2^63. The use of this method depends on virtual machine
+ * support for measurement of the CPU time of the current thread,
+ * and on this functionality being enabled.
+ * </p>
+ *
+ * @param id the thread identifier of the thread whose CPU time is being
+ * monitored.
+ * @return the total number of nanoseconds of CPU time the specified
+ * thread has executed in user mode, or -1 if CPU time monitoring
+ * is disabled.
+ * @throws IllegalArgumentException if <code>id</code> <= 0.
+ * @throws UnsupportedOperationException if CPU time monitoring is not
+ * supported.
+ * @see #getThreadCpuTime(long)
+ * @see #isThreadCpuTimeSupported()
+ * @see #isThreadCpuTimeEnabled()
+ * @see #setThreadCpuTimeEnabled(boolean)
+ */
+ long getThreadUserTime(long id);
+
+ /**
+ * Returns the total number of threads that have been
+ * created and started during the lifetime of the virtual
+ * machine.
+ *
+ * @return the total number of started threads.
+ */
+ long getTotalStartedThreadCount();
+
+ /**
+ * Returns true if the virtual machine supports the monitoring
+ * of the CPU time used by the current thread. This is implied
+ * by {@link isThreadCpuTimeSupported()} returning true.
+ *
+ * @return true if monitoring of the CPU time used by the current
+ * thread is supported by the virtual machine.
+ * @see #isThreadCpuTimeEnabled()
+ * @see #isThreadCpuTimeSupported()
+ * @see #setThreadCpuTimeEnabled(boolean)
+ */
+ boolean isCurrentThreadCpuTimeSupported();
+
+ /**
+ * Returns true if thread contention monitoring is currently
+ * enabled.
+ *
+ * @return true if thread contention monitoring is enabled.
+ * @throws UnsupportedOperationException if the virtual
+ * machine does not
+ * support contention
+ * monitoring.
+ * @see #isThreadContentionMonitoringSupported()
+ * @see #setThreadContentionMonitoringEnabled(boolean)
+ */
+ boolean isThreadContentionMonitoringEnabled();
+
+ /**
+ * Returns true if thread contention monitoring is supported
+ * by the virtual machine.
+ *
+ * @return true if thread contention monitoring is supported
+ * by the virtual machine.
+ * @see #isThreadContentionMonitoringEnabled()
+ * @see #setThreadContentionMonitoringEnabled(boolean)
+ */
+ boolean isThreadContentionMonitoringSupported();
+
+ /**
+ * Returns true if monitoring of the CPU time used by a thread
+ * is currently enabled.
+ *
+ * @return true if thread CPU time monitoring is enabled.
+ * @throws UnsupportedOperationException if the virtual
+ * machine does not
+ * support CPU time
+ * monitoring.
+ * @see #isCurrentThreadCpuTimeSupported()
+ * @see #isThreadCpuTimeSupported()
+ * @see #setThreadCpuTimeEnabled(boolean)
+ */
+ boolean isThreadCpuTimeEnabled();
+
+ /**
+ * Returns true if the virtual machine supports the monitoring
+ * of the CPU time used by all threads. This implies
+ * that {@link isCurrentThreadCpuTimeSupported()} returns true.
+ *
+ * @return true if monitoring of the CPU time used by the current
+ * thread is supported by the virtual machine.
+ * @see #isCurrentThreadCpuTimeSupported()
+ * @see #isThreadCpuTimeEnabled()
+ * @see #setThreadCpuTimeEnabled(boolean)
+ */
+ boolean isThreadCpuTimeSupported();
+
+ /**
+ * Resets the peak live thread count to the
+ * current number of live threads, as returned
+ * by {@link #getThreadCount()}.
+ *
+ * @see #getPeakThreadCount()
+ * @see #getThreadCount()
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("control").
+ */
+ void resetPeakThreadCount();
+
+ /**
+ * Toggles the monitoring of thread contention. Thread
+ * contention monitoring is disabled by default. Each
+ * time contention monitoring is re-enabled, the times
+ * it maintains are reset.
+ *
+ * @param enable true if monitoring should be enabled,
+ * false if it should be disabled.
+ * @throws UnsupportedOperationException if the virtual
+ * machine does not
+ * support contention
+ * monitoring.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("control").
+ * @see #isThreadContentionMonitoringEnabled()
+ * @see #isThreadContentionMonitoringSupported()
+ */
+ void setThreadContentionMonitoringEnabled(boolean enable);
+
+ /**
+ * Toggles the monitoring of CPU time used by threads. The
+ * initial setting is dependent on the underlying virtual
+ * machine. On enabling CPU time monitoring, the virtual
+ * machine may take any value up to and including the current
+ * time as the start time for monitoring.
+ *
+ * @param enable true if monitoring should be enabled,
+ * false if it should be disabled.
+ * @throws UnsupportedOperationException if the virtual
+ * machine does not
+ * support CPU time
+ * monitoring.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("control").
+ * @see #isCurrentThreadCpuTimeSupported()
+ * @see #isThreadCpuTimeEnabled()
+ * @see #isThreadCpuTimeSupported()
+ */
+ void setThreadCpuTimeEnabled(boolean enable);
+
+}
diff --git a/java/net/URL.java b/java/net/URL.java
index 967cc80f6..85037b3e7 100644
--- a/java/net/URL.java
+++ b/java/net/URL.java
@@ -482,7 +482,17 @@ public final class URL implements Serializable
}
catch (URLParseError e)
{
- throw new MalformedURLException(e.getMessage());
+ MalformedURLException mue = new MalformedURLException(e.getMessage());
+ mue.initCause(e);
+ throw mue;
+ }
+ catch (RuntimeException e)
+ {
+ // This isn't documented, but the JDK also catches
+ // RuntimeExceptions here.
+ MalformedURLException mue = new MalformedURLException(e.getMessage());
+ mue.initCause(e);
+ throw mue;
}
if (hashAt >= 0)
diff --git a/java/rmi/server/UID.java b/java/rmi/server/UID.java
index 359630422..940339e81 100644
--- a/java/rmi/server/UID.java
+++ b/java/rmi/server/UID.java
@@ -94,23 +94,23 @@ public final class UID
* The time stamp, when the UID was created.
*/
private long time;
-
+
/**
* Create the new UID that would have the described features of the
* uniqueness.
*/
public UID()
{
- time = System.currentTimeMillis();
- unique = machineId;
- if (time > last)
- {
- last = time;
- count = uidCounter = Short.MIN_VALUE;
- }
- else
+ synchronized (UID.class)
{
- synchronized (UID.class)
+ time = System.currentTimeMillis();
+ unique = machineId;
+ if (time > last)
+ {
+ last = time;
+ count = uidCounter = Short.MIN_VALUE;
+ }
+ else
{
if (uidCounter == Short.MAX_VALUE)
{
@@ -126,8 +126,7 @@ public final class UID
uidCounter = Short.MIN_VALUE;
time = last = System.currentTimeMillis();
}
-
- count = uidCounter++;
+ count = ++uidCounter;
}
}
}
@@ -210,7 +209,7 @@ public final class UID
^ hostIpHash;
}
- /**
+ /**
* Get the string representation of this UID.
*
* @return a string, uniquely identifying this id.
@@ -219,9 +218,8 @@ public final class UID
{
int max = Character.MAX_RADIX;
// Translate into object count, counting from 0.
- long lc = (count + Short.MIN_VALUE) & 0xFFFF;
- return Long.toString(time, max) + ":"
- + Long.toString(unique, max) + ":"
+ long lc = (count - Short.MIN_VALUE) & 0xFFFF;
+ return Long.toString(unique, max) + ":" + Long.toString(time, max) + "."
+ Long.toString(lc, max);
}
}
diff --git a/java/security/cert/X509CertSelector.java b/java/security/cert/X509CertSelector.java
index 205f4bcf7..154ed2e4d 100644
--- a/java/security/cert/X509CertSelector.java
+++ b/java/security/cert/X509CertSelector.java
@@ -696,7 +696,7 @@ public class X509CertSelector implements CertSelector, Cloneable
if (altNames == null)
altNames = new LinkedList();
ArrayList l = new ArrayList(2);
- l.add(new Integer(id));
+ l.add(Integer.valueOf(id));
l.add(name);
altNames.add(l);
}
@@ -715,7 +715,7 @@ public class X509CertSelector implements CertSelector, Cloneable
if (altNames == null)
altNames = new LinkedList();
ArrayList l = new ArrayList(2);
- l.add(new Integer(id));
+ l.add(Integer.valueOf(id));
l.add(name);
altNames.add(l);
}
diff --git a/java/text/AttributedString.java b/java/text/AttributedString.java
index 8528551a8..c220f6025 100644
--- a/java/text/AttributedString.java
+++ b/java/text/AttributedString.java
@@ -223,16 +223,13 @@ public class AttributedString
// If the attribute run starts before the beginning index, we
// need to junk it if it is an Annotation.
Object attrib_obj = aci.getAttribute(attrib);
- if (rs < begin)
+ rs -= begin;
+ if (rs < 0)
{
if (attrib_obj instanceof Annotation)
continue;
- rs = begin;
- }
- else
- {
- rs -= begin;
+ rs = 0;
}
// Create a map object. Yes this will only contain one attribute
@@ -245,7 +242,7 @@ public class AttributedString
c = aci.next();
}
- while(c != CharacterIterator.DONE);
+ while( aci.getIndex() < end );
attribs = new AttributeRange[accum.size()];
attribs = (AttributeRange[]) accum.toArray(attribs);
diff --git a/java/util/logging/LogManager.java b/java/util/logging/LogManager.java
index ae0f446a8..444ab6a26 100644
--- a/java/util/logging/LogManager.java
+++ b/java/util/logging/LogManager.java
@@ -39,6 +39,8 @@ exception statement from your version. */
package java.util.logging;
+import gnu.classpath.SystemProperties;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.ByteArrayInputStream;
@@ -50,12 +52,11 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
-import gnu.classpath.SystemProperties;
-
/**
* The <code>LogManager</code> maintains a hierarchical namespace
* of Logger objects and manages properties for configuring the logging
@@ -108,11 +109,23 @@ import gnu.classpath.SystemProperties;
public class LogManager
{
/**
+ * The object name for the logging management bean.
+ * @since 1.5
+ */
+ public static final String LOGGING_MXBEAN_NAME
+ = "java.util.logging:type=Logging";
+
+ /**
* The singleton LogManager instance.
*/
private static LogManager logManager;
/**
+ * The singleton logging bean.
+ */
+ private static LoggingMXBean loggingBean;
+
+ /**
* The registered named loggers; maps the name of a Logger to
* a WeakReference to it.
*/
@@ -902,4 +915,63 @@ public class LogManager
}
}
+ /**
+ * Return the logging bean. There is a single logging bean per
+ * VM instance.
+ * @since 1.5
+ */
+ public static synchronized LoggingMXBean getLoggingMXBean()
+ {
+ if (loggingBean == null)
+ {
+ loggingBean = new LoggingMXBean()
+ {
+ public String getLoggerLevel(String logger)
+ {
+ LogManager mgr = getLogManager();
+ Logger l = mgr.getLogger(logger);
+ if (l == null)
+ return null;
+ Level lev = l.getLevel();
+ if (lev == null)
+ return "";
+ return lev.getName();
+ }
+
+ public List getLoggerNames()
+ {
+ LogManager mgr = getLogManager();
+ // This is inefficient, but perhaps better for maintenance.
+ return Collections.list(mgr.getLoggerNames());
+ }
+
+ public String getParentLoggerName(String logger)
+ {
+ LogManager mgr = getLogManager();
+ Logger l = mgr.getLogger(logger);
+ if (l == null)
+ return null;
+ l = l.getParent();
+ if (l == null)
+ return "";
+ return l.getName();
+ }
+
+ public void setLoggerLevel(String logger, String level)
+ {
+ LogManager mgr = getLogManager();
+ Logger l = mgr.getLogger(logger);
+ if (l == null)
+ throw new IllegalArgumentException("no logger named " + logger);
+ Level newLevel;
+ if (level == null)
+ newLevel = null;
+ else
+ newLevel = Level.parse(level);
+ l.setLevel(newLevel);
+ }
+ };
+ }
+ return loggingBean;
+ }
}
diff --git a/java/util/logging/LoggingMXBean.java b/java/util/logging/LoggingMXBean.java
new file mode 100644
index 000000000..5f866c980
--- /dev/null
+++ b/java/util/logging/LoggingMXBean.java
@@ -0,0 +1,85 @@
+/* LoggingMxBean.java -- Management interface for logging
+ 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 java.util.logging;
+
+import java.util.List;
+
+/**
+ * This interface represents the management interface for logging.
+ * There is a single logging bean per VM instance, which can be
+ * retrieved via {@link LogManager#getLoggingMXBean()}.
+ *
+ * @since 1.5
+ */
+public interface LoggingMXBean
+{
+ /**
+ * Return the name of the logging level given the name of
+ * a logger. Returns null if no such logger exists.
+ * @param logger the logger's name
+ * @return the logging level's name, or null
+ */
+ String getLoggerLevel(String logger);
+
+ /**
+ * Return a list of all logger names.
+ */
+ List/*<String>*/ getLoggerNames();
+
+ /**
+ * Return the name of the parent of the indicated logger.
+ * If no such logger exists, returns null. If the logger
+ * is the root logger, returns the empty string.
+ * @param logger the logger's name
+ * @return the name of the logger's parent, or null
+ */
+ String getParentLoggerName(String logger);
+
+ /**
+ * Sets the logging level for a particular logger.
+ *
+ * @param logger the name of the logger
+ * @param level the name of the new logging level, or null
+ * @throws IllegalArgumentException if the level is not
+ * recognized, or if the logger does not exist
+ * @throws SecurityException if access is denied;
+ * see {@link Logger#setLevel(Level)}
+ */
+ void setLoggerLevel(String logger, String level);
+}
diff --git a/javax/imageio/spi/IIORegistry.java b/javax/imageio/spi/IIORegistry.java
index 9b2f05c61..36618d7f8 100644
--- a/javax/imageio/spi/IIORegistry.java
+++ b/javax/imageio/spi/IIORegistry.java
@@ -45,6 +45,10 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import gnu.javax.imageio.bmp.BMPImageReaderSpi;
+import gnu.javax.imageio.bmp.BMPImageWriterSpi;
+import gnu.javax.imageio.gif.GIFImageReaderSpi;
+
public final class IIORegistry extends ServiceRegistry
{
private static final HashSet defaultCategories = new HashSet();
@@ -80,6 +84,9 @@ public final class IIORegistry extends ServiceRegistry
super(defaultCategories.iterator());
// XXX: Register built-in Spis here.
+ registerServiceProvider(new GIFImageReaderSpi()); // Register GIF decoder
+ registerServiceProvider(new BMPImageReaderSpi());
+ registerServiceProvider(new BMPImageWriterSpi());
Toolkit toolkit = Toolkit.getDefaultToolkit();
diff --git a/javax/management/DynamicMBean.java b/javax/management/DynamicMBean.java
index b13baefb4..80ea72cf4 100644
--- a/javax/management/DynamicMBean.java
+++ b/javax/management/DynamicMBean.java
@@ -143,7 +143,7 @@ public interface DynamicMBean
* this exception.
* @see #getAttribute(String)
*/
- Object setAttribute(Attribute attribute)
+ void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException;
diff --git a/javax/management/MBeanFeatureInfo.java b/javax/management/MBeanFeatureInfo.java
new file mode 100644
index 000000000..72dc85996
--- /dev/null
+++ b/javax/management/MBeanFeatureInfo.java
@@ -0,0 +1,154 @@
+/* MBeanFeatureInfo.java -- Information about a bean feature.
+ 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 javax.management;
+
+import java.io.Serializable;
+
+/**
+ * A general superclass for the description of features
+ * of management beans. This allows the user to access
+ * the feature dynamically, without knowing the details
+ * beforehand. The information is immutable as standard.
+ * Of course, subclasses may change this, but this
+ * behaviour is not recommended.
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public class MBeanFeatureInfo
+ implements Serializable
+{
+
+ /**
+ * Compatible with JDK 1.5
+ */
+ private static final long serialVersionUID = 3952882688968447265L;
+
+ /**
+ * A description of the feature in human-readable form.
+ * Subclasses should access this via the {@link #getDescription()}
+ * function rather than using the value directly.
+ *
+ * @serial a description of the feature.
+ */
+ protected String description;
+
+ /**
+ * The name of the feature. Subclasses should access this
+ * via the {@link #getName()} function rather than using the
+ * value directly.
+ *
+ * @serial the name of the feature.
+ */
+ protected String name;
+
+ /**
+ * Constructs a new {@link MBeanFeatureInfo} with the specified
+ * name and description.
+ *
+ * @param name the name of the management bean feature.
+ * @param description the description of the feature.
+ */
+ public MBeanFeatureInfo(String name, String description)
+ {
+ this.name = name;
+ this.description = description;
+ }
+
+ /**
+ * Compares this feature with the supplied object. This
+ * returns true iff the object is an instance of
+ * {@link MBeanFeatureInfo} and {@link Object#equals()}
+ * returns true for a comparison of both the name and
+ * description of this feature with that of the specified
+ * object.
+ *
+ * @param obj the object to compare.
+ * @return true if the object is a {@link MBeanFeatureInfo}
+ * instance,
+ * <code>name.equals(object.getName())</code> and
+ * <code>description.equals(object.getDescription</code>.
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof MBeanFeatureInfo)
+ {
+ MBeanFeatureInfo o = (MBeanFeatureInfo) obj;
+ return ((name == null ?
+ o.getName() == null :
+ name.equals(o.getName())) &&
+ (description == null ?
+ o.getDescription() == null :
+ description.equals(o.getDescription())));
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Returns a description of this feature.
+ *
+ * @return a human-readable description.
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /**
+ * Returns the name of this feature.
+ *
+ * @return the name of the feature.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Returns the hashcode of the feature as
+ * the multiplication of the hashcodes of
+ * its name and description.
+ *
+ * @return the hashcode of this feature.
+ */
+ public int hashCode()
+ {
+ return name.hashCode() * description.hashCode();
+ }
+
+}
diff --git a/javax/swing/AbstractButton.java b/javax/swing/AbstractButton.java
index 9b2b526f3..82dc61e59 100644
--- a/javax/swing/AbstractButton.java
+++ b/javax/swing/AbstractButton.java
@@ -923,7 +923,7 @@ public abstract class AbstractButton extends JComponent
// constructor).
// This way the behavior of the JDK is matched.
if(text != null)
- this.text = text;
+ setText(text);
if (icon != null)
default_icon = icon;
diff --git a/javax/swing/DefaultListSelectionModel.java b/javax/swing/DefaultListSelectionModel.java
index b6d3e079e..d1e2da85f 100644
--- a/javax/swing/DefaultListSelectionModel.java
+++ b/javax/swing/DefaultListSelectionModel.java
@@ -150,9 +150,14 @@ public class DefaultListSelectionModel implements Cloneable,
boolean setLeadCalledFromAdd = false;
/**
- * Gets the value of the {@link #selectionMode} property.
- *
- * @return The current value of the property
+ * Returns the selection mode, which is one of {@link #SINGLE_SELECTION},
+ * {@link #SINGLE_INTERVAL_SELECTION} and
+ * {@link #MULTIPLE_INTERVAL_SELECTION}. The default value is
+ * {@link #MULTIPLE_INTERVAL_SELECTION}.
+ *
+ * @return The selection mode.
+ *
+ * @see #setSelectionMode(int)
*/
public int getSelectionMode()
{
@@ -187,13 +192,19 @@ public class DefaultListSelectionModel implements Cloneable,
/**
* Sets the value of the {@link #anchorSelectionIndex} property.
*
- * @param anchorIndex The new property value
+ * @param index The new property value
*
* @see #getAnchorSelectionIndex
*/
- public void setAnchorSelectionIndex(int anchorIndex)
+ public void setAnchorSelectionIndex(int index)
{
- anchorSelectionIndex = anchorIndex;
+ if (anchorSelectionIndex != index)
+ {
+ int old = anchorSelectionIndex;
+ anchorSelectionIndex = index;
+ if (leadAnchorNotificationEnabled)
+ fireValueChanged(index, old);
+ }
}
/**
@@ -459,12 +470,14 @@ public class DefaultListSelectionModel implements Cloneable,
if (index0 == -1 || index1 == -1)
return;
+ if (selectionMode == SINGLE_SELECTION)
+ setSelectionInterval(index0, index1);
+ else
+ {
int lo = Math.min(index0, index1);
int hi = Math.max(index0, index1);
oldSel = sel.clone();
- if (selectionMode == SINGLE_SELECTION)
- setSelectionInterval(index0, index1);
// COMPAT: Like Sun (but not like IBM), we allow calls to
// addSelectionInterval when selectionMode is
@@ -503,6 +516,7 @@ public class DefaultListSelectionModel implements Cloneable,
sel.set(lo, hi+1);
fireDifference(sel, (BitSet) oldSel);
}
+ }
}
@@ -588,27 +602,82 @@ public class DefaultListSelectionModel implements Cloneable,
* the current selection mode is <code>SINGLE_SELECTION</code> only the
* index <code>index2</code> is selected.
*
- * @param index0 The low end of the new selection
- * @param index1 The high end of the new selection
+ * @param anchor the anchor selection index.
+ * @param lead the lead selection index.
*/
- public void setSelectionInterval(int index0, int index1)
+ public void setSelectionInterval(int anchor, int lead)
{
- if (index0 == -1 || index1 == -1)
+ if (anchor == -1 || lead == -1)
return;
-
- BitSet oldSel = (BitSet) sel.clone();
- sel.clear();
if (selectionMode == SINGLE_SELECTION)
- index0 = index1;
-
- int lo = Math.min(index0, index1);
- int hi = Math.max(index0, index1);
- sel.set(lo, hi+1);
- // update the anchorSelectionIndex and leadSelectionIndex variables
- setAnchorSelectionIndex(index0);
- leadSelectionIndex=index1;
+ {
+ int lo = lead;
+ int hi = lead;
+ int selected = sel.nextSetBit(0);
+ if (selected == lead)
+ return; // the selection is not changing
+ if (selected >= 0)
+ {
+ lo = Math.min(lo, selected);
+ hi = Math.max(hi, selected);
+ }
+ if (anchorSelectionIndex >= 0)
+ {
+ lo = Math.min(lo, anchorSelectionIndex);
+ hi = Math.max(hi, anchorSelectionIndex);
+ }
+ sel.clear();
+ sel.set(lead);
+ leadSelectionIndex = lead;
+ anchorSelectionIndex = lead;
+ fireValueChanged(lo, hi);
+ }
+ else if (selectionMode == SINGLE_INTERVAL_SELECTION)
+ {
+ // determine the current interval
+ int first = sel.nextSetBit(0);
+ int last = first;
+ if (first >= 0)
+ last += (sel.cardinality() - 1);
+
+ // update the selection
+ int lo = Math.min(anchor, lead);
+ int hi = Math.max(anchor, lead);
+ if (lo == first && hi == last)
+ return; // selected interval is not being changed
+ sel.clear();
+ sel.set(lo, hi + 1);
+
+ // include the old selection in the event range
+ if (first >= 0)
+ lo = Math.min(lo, first);
+ if (last >= 0)
+ hi = Math.max(hi, last);
+ if (anchorSelectionIndex >= 0)
+ {
+ lo = Math.min(lo, anchorSelectionIndex);
+ hi = Math.max(hi, anchorSelectionIndex);
+ }
+ anchorSelectionIndex = anchor;
+ leadSelectionIndex = lead;
+ fireValueChanged(lo, hi);
+ }
+ else
+ {
+ BitSet oldSel = (BitSet) sel.clone();
+ sel.clear();
+ if (selectionMode == SINGLE_SELECTION)
+ anchor = lead;
+
+ int lo = Math.min(anchor, lead);
+ int hi = Math.max(anchor, lead);
+ sel.set(lo, hi+1);
+ // update the anchorSelectionIndex and leadSelectionIndex variables
+ setAnchorSelectionIndex(anchor);
+ leadSelectionIndex = lead;
- fireDifference(sel, oldSel);
+ fireDifference(sel, oldSel);
+ }
}
/**
diff --git a/javax/swing/JComponent.java b/javax/swing/JComponent.java
index b212c2717..230a8a33a 100644
--- a/javax/swing/JComponent.java
+++ b/javax/swing/JComponent.java
@@ -69,6 +69,7 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;
+import java.beans.VetoableChangeSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.EventListener;
@@ -683,6 +684,11 @@ public abstract class JComponent extends Container implements Serializable
*/
protected EventListenerList listenerList = new EventListenerList();
+ /**
+ * Handles VetoableChangeEvents.
+ */
+ private VetoableChangeSupport vetoableChangeSupport;
+
/**
* Storage for "client properties", which are key/value pairs associated
* with this component by a "client", such as a user application or a
@@ -874,7 +880,8 @@ public abstract class JComponent extends Container implements Serializable
*/
public void removeVetoableChangeListener(VetoableChangeListener listener)
{
- listenerList.remove(VetoableChangeListener.class, listener);
+ if (vetoableChangeSupport != null)
+ vetoableChangeSupport.removeVetoableChangeListener(listener);
}
/**
@@ -890,23 +897,6 @@ public abstract class JComponent extends Container implements Serializable
}
/**
- * Register a <code>PropertyChangeListener</code> for a specific, named
- * property. To listen to all property changes, regardless of name, use
- * {@link #addPropertyChangeListener(PropertyChangeListener)} instead.
- *
- * @param propertyName The property name to listen to
- * @param listener The listener to register
- *
- * @see #removePropertyChangeListener(String, PropertyChangeListener)
- * @see #changeSupport
- */
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener)
- {
- listenerList.add(PropertyChangeListener.class, listener);
- }
-
- /**
* Register a <code>VetoableChangeListener</code>.
*
* @param listener The listener to register
@@ -916,7 +906,10 @@ public abstract class JComponent extends Container implements Serializable
*/
public void addVetoableChangeListener(VetoableChangeListener listener)
{
- listenerList.add(VetoableChangeListener.class, listener);
+ // Lazily instantiate this, it's rarely needed.
+ if (vetoableChangeSupport == null)
+ vetoableChangeSupport = new VetoableChangeSupport(this);
+ vetoableChangeSupport.addVetoableChangeListener(listener);
}
/**
@@ -969,75 +962,76 @@ public abstract class JComponent extends Container implements Serializable
}
/**
- * A variant of {@link #firePropertyChange(String,Object,Object)}
- * for properties with <code>boolean</code> values.
+ * Call {@link VetoableChangeListener#vetoableChange} on all listeners
+ * registered to listen to a given property. Any method which changes
+ * the specified property of this component should call this method.
*
- * @specnote It seems that in JDK1.5 all property related methods have been
- * moved to java.awt.Component, except this and 2 others. We call
- * super here. I guess this will also be removed in one of the next
- * releases.
+ * @param propertyName The property which changed
+ * @param oldValue The old value of the property
+ * @param newValue The new value of the property
+ *
+ * @throws PropertyVetoException if the change was vetoed by a listener
+ *
+ * @see #addVetoableChangeListener
+ * @see #removeVetoableChangeListener
*/
- public void firePropertyChange(String propertyName, boolean oldValue,
- boolean newValue)
+ protected void fireVetoableChange(String propertyName, Object oldValue,
+ Object newValue)
+ throws PropertyVetoException
{
- super.firePropertyChange(propertyName, oldValue, newValue);
+ if (vetoableChangeSupport != null)
+ vetoableChangeSupport.fireVetoableChange(propertyName, oldValue, newValue);
}
+
/**
- * A variant of {@link #firePropertyChange(String,Object,Object)}
- * for properties with <code>char</code> values.
+ * Fires a property change for a primitive integer property.
+ *
+ * @param property the name of the property
+ * @param oldValue the old value of the property
+ * @param newValue the new value of the property
*
- * @specnote It seems that in JDK1.5 all property related methods have been
- * moved to java.awt.Component, except this and 2 others. We call
- * super here. I guess this will also be removed in one of the next
- * releases.
+ * @specnote This method is implemented in
+ * {@link Component#firePropertyChange(String, int, int)}. It is
+ * only here because it is specified to be public, whereas the
+ * Component method is protected.
*/
- public void firePropertyChange(String propertyName, char oldValue,
- char newValue)
+ public void firePropertyChange(String property, int oldValue, int newValue)
{
- super.firePropertyChange(propertyName, oldValue, newValue);
+ super.firePropertyChange(property, oldValue, newValue);
}
-
+
/**
- * A variant of {@link #firePropertyChange(String,Object,Object)}
- * for properties with <code>int</code> values.
+ * Fires a property change for a primitive boolean property.
*
- * @specnote It seems that in JDK1.5 all property related methods have been
- * moved to java.awt.Component, except this and 2 others. We call
- * super here. I guess this will also be removed in one of the next
- * releases.
+ * @param property the name of the property
+ * @param oldValue the old value of the property
+ * @param newValue the new value of the property
+ *
+ * @specnote This method is implemented in
+ * {@link Component#firePropertyChange(String, boolean, boolean)}.
+ * It is only here because it is specified to be public, whereas
+ * the Component method is protected.
*/
- public void firePropertyChange(String propertyName, int oldValue,
- int newValue)
+ public void firePropertyChange(String property, boolean oldValue,
+ boolean newValue)
{
- super.firePropertyChange(propertyName, oldValue, newValue);
+ super.firePropertyChange(property, oldValue, newValue);
}
/**
- * Call {@link VetoableChangeListener#vetoableChange} on all listeners
- * registered to listen to a given property. Any method which changes
- * the specified property of this component should call this method.
+ * Fires a property change for a primitive character property.
*
- * @param propertyName The property which changed
- * @param oldValue The old value of the property
- * @param newValue The new value of the property
- *
- * @throws PropertyVetoException if the change was vetoed by a listener
- *
- * @see #addVetoableChangeListener
- * @see #removeVetoableChangeListener
+ * @param property the name of the property
+ * @param oldValue the old value of the property
+ * @param newValue the new value of the property
*/
- protected void fireVetoableChange(String propertyName, Object oldValue,
- Object newValue)
- throws PropertyVetoException
+ public void firePropertyChange(String property, char oldValue,
+ char newValue)
{
- VetoableChangeListener[] listeners = getVetoableChangeListeners();
-
- PropertyChangeEvent evt =
- new PropertyChangeEvent(this, propertyName, oldValue, newValue);
-
- for (int i = 0; i < listeners.length; i++)
- listeners[i].vetoableChange(evt);
+ // FIXME - This method is already public in awt Component, but
+ // is included here to work around a compilation bug in gcj 4.1.
+ super.firePropertyChange(property, oldValue, newValue);
}
/**
@@ -1865,8 +1859,7 @@ public abstract class JComponent extends Container implements Serializable
continue;
Rectangle compBounds = comp.getBounds();
- boolean isOpaque = comp instanceof JComponent
- && ((JComponent) comp).isOpaque();
+ boolean isOpaque = comp.isOpaque();
// Add all the current paint rectangles that intersect with the
// component to the component's paint rectangle array.
@@ -1884,7 +1877,7 @@ public abstract class JComponent extends Container implements Serializable
int x, y, w, h;
Rectangle rect = new Rectangle();
- // The north retangle.
+ // The north rectangle.
x = Math.max(compBounds.x, r.x);
y = r.y;
w = Math.min(compBounds.width, r.width + r.x - x);
@@ -2018,7 +2011,6 @@ public abstract class JComponent extends Container implements Serializable
*/
private void paintChildrenOptimized(Graphics g)
{
- Shape originalClip = g.getClip();
Rectangle inner = SwingUtilities.calculateInnerArea(this, rectCache);
g.clipRect(inner.x, inner.y, inner.width, inner.height);
Component[] children = getComponents();
@@ -2037,20 +2029,14 @@ public abstract class JComponent extends Container implements Serializable
continue;
Rectangle bounds = children[i].getBounds(rectCache);
- Rectangle oldClip = g.getClipBounds();
- if (oldClip == null)
- oldClip = bounds;
-
if (!g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height))
continue;
- boolean translated = false;
Graphics g2 = g.create(bounds.x, bounds.y, bounds.width,
bounds.height);
children[i].paint(g2);
g2.dispose();
}
- g.setClip(originalClip);
}
/**
@@ -2118,16 +2104,13 @@ public abstract class JComponent extends Container implements Serializable
Component root = findPaintRoot(r);
// If no paint root is found, then this component is completely overlapped
// by another component and we don't need repainting.
- if (root == null)
- return;
- if (root == null || !root.isShowing())
+ if (root == null|| !root.isShowing())
return;
-
- Rectangle rootClip = SwingUtilities.convertRectangle(this, r, root);
+ SwingUtilities.convertRectangleToAncestor(this, r, root);
if (root instanceof JComponent)
- ((JComponent) root).paintImmediately2(rootClip);
+ ((JComponent) root).paintImmediately2(r);
else
- root.repaint(rootClip.x, rootClip.y, rootClip.width, rootClip.height);
+ root.repaint(r.x, r.y, r.width, r.height);
}
/**
@@ -2711,6 +2694,11 @@ public abstract class JComponent extends Container implements Serializable
*/
public void revalidate()
{
+ // As long as we don't have a parent we don't need to do any layout, since
+ // this is done anyway as soon as we get connected to a parent.
+ if (getParent() == null)
+ return;
+
if (! EventQueue.isDispatchThread())
SwingUtilities.invokeLater(new Runnable()
{
diff --git a/javax/swing/JInternalFrame.java b/javax/swing/JInternalFrame.java
index 79dcc7326..ff3ae1faa 100644
--- a/javax/swing/JInternalFrame.java
+++ b/javax/swing/JInternalFrame.java
@@ -38,9 +38,11 @@ exception statement from your version. */
package javax.swing;
+import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
+import java.awt.IllegalComponentStateException;
import java.awt.KeyboardFocusManager;
import java.awt.LayoutManager;
import java.awt.Rectangle;
@@ -490,12 +492,6 @@ public class JInternalFrame extends JComponent implements Accessible,
/** Whether the JInternalFrame has become visible for the very first time. */
private transient boolean isFirstTimeVisible = true;
- /**
- * Whether the JInternalFrame is in the transition from being a maximized
- * frame back to a regular sized frame.
- */
- private transient boolean maxTransition = false;
-
/** DOCUMENT ME! */
private transient boolean wasIcon = false;
@@ -581,11 +577,12 @@ public class JInternalFrame extends JComponent implements Accessible,
this.closable = closable;
this.maximizable = maximizable;
this.iconable = iconifiable;
- storedBounds = new Rectangle();
+ isMaximum = false;
setRootPane(createRootPane());
// JInternalFrames are invisible and opaque by default.
setVisible(false);
setOpaque(true);
+ desktopIcon = new JDesktopIcon(this);
updateUI();
setRootPaneCheckingEnabled(true); // Done the init stage, now adds go to content pane.
}
@@ -643,24 +640,25 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void dispose()
{
- setVisible(false);
- JDesktopPane pane = getDesktopPane();
- if (pane != null)
- pane.setSelectedFrame(null);
- else
+ if (isVisible())
+ setVisible(false);
+ if (isSelected())
{
- try
- {
- setSelected(false);
- }
- catch (PropertyVetoException e)
- {
- // Do nothing if they don't want to be unselected.
- }
+ try
+ {
+ setSelected(false);
+ }
+ catch (PropertyVetoException e)
+ {
+ // Do nothing if they don't want to be unselected.
+ }
+ }
+ if (! isClosed)
+ {
+ firePropertyChange(IS_CLOSED_PROPERTY, Boolean.FALSE, Boolean.TRUE);
+ isClosed = true;
}
- isClosed = true;
fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
- removeNotify();
}
/**
@@ -799,8 +797,6 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public JDesktopIcon getDesktopIcon()
{
- if (desktopIcon == null)
- desktopIcon = new JDesktopIcon(this);
return desktopIcon;
}
@@ -904,18 +900,7 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public int getLayer()
{
- JDesktopPane pane = getDesktopPane();
- if (pane != null)
- // The cast here forces the call to the instance method getLayer()
- // instead of the static method (this would lead to infinite
- // recursion).
- return pane.getLayer((Component) this);
-
- Integer layer = (Integer) getClientProperty(JLayeredPane.LAYER_PROPERTY);
- if (layer != null)
- return layer.intValue();
-
- return JLayeredPane.DEFAULT_LAYER.intValue();
+ return JLayeredPane.getLayer(this);
}
/**
@@ -970,7 +955,7 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public Rectangle getNormalBounds()
{
- if (! isMaximum() && ! maxTransition)
+ if (storedBounds == null)
return getBounds();
else
return storedBounds;
@@ -1035,20 +1020,8 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void hide()
{
- JDesktopPane pane = getDesktopPane();
- if (pane != null)
- pane.setSelectedFrame(null);
- else
- {
- try
- {
- setSelected(false);
- }
- catch (PropertyVetoException e)
- {
- // Do nothing.
- }
- }
+ if (isIcon())
+ getDesktopIcon().hide();
super.hide();
}
@@ -1162,8 +1135,9 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void moveToBack()
{
- if (getParent() instanceof JLayeredPane)
- ((JLayeredPane) getParent()).moveToBack(this);
+ Container p = getParent();
+ if (p instanceof JLayeredPane)
+ ((JLayeredPane) p).moveToBack(this);
}
/**
@@ -1172,8 +1146,9 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void moveToFront()
{
- if (getParent() instanceof JLayeredPane)
- ((JLayeredPane) getParent()).moveToFront(this);
+ Container p = getParent();
+ if (p != null && p instanceof JLayeredPane)
+ ((JLayeredPane) p).moveToFront(this);
}
/**
@@ -1196,6 +1171,7 @@ public class JInternalFrame extends JComponent implements Accessible,
// Do nothing if they don't want to be restored first.
}
setSize(getPreferredSize());
+ validate();
}
/**
@@ -1311,7 +1287,6 @@ public class JInternalFrame extends JComponent implements Accessible,
dispose();
firePropertyChange(IS_CLOSED_PROPERTY, false, true);
- fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
}
}
@@ -1468,7 +1443,9 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void setJMenuBar(JMenuBar b)
{
+ JMenuBar old = getJMenuBar();
getRootPane().setJMenuBar(b);
+ firePropertyChange(MENU_BAR_PROPERTY, old, b);
}
/**
@@ -1493,11 +1470,17 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void setLayer(Integer layer)
{
- JDesktopPane p = getDesktopPane();
- if (p != null)
+ Container p = getParent();
+ if (p instanceof JLayeredPane)
{
- int pos = p.getPosition(this);
- p.setLayer(this, layer.intValue(), pos);
+ JLayeredPane lp = (JLayeredPane) p;
+ lp.setLayer(this, layer.intValue(), lp.getPosition(this));
+ }
+ else
+ {
+ JLayeredPane.putLayer(this, layer.intValue());
+ if (p != null)
+ p.repaint(getX(), getY(), getWidth(), getHeight());
}
}
@@ -1508,6 +1491,9 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void setLayeredPane(JLayeredPane layered)
{
+ if (layered == null)
+ throw new IllegalComponentStateException("LayeredPane must not be null");
+
if (layered != getLayeredPane())
{
JLayeredPane old = getLayeredPane();
@@ -1561,15 +1547,11 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void setMaximum(boolean b) throws PropertyVetoException
{
- if (b != isMaximum())
+ if (b != isMaximum)
{
- fireVetoableChange(IS_MAXIMUM_PROPERTY, b, isMaximum);
+ fireVetoableChange(IS_MAXIMUM_PROPERTY, isMaximum, b);
isMaximum = b;
- if (b)
- setNormalBounds(getBounds());
- maxTransition = ! b;
firePropertyChange(IS_MAXIMUM_PROPERTY, ! isMaximum, isMaximum);
- maxTransition = false;
}
}
@@ -1593,7 +1575,7 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void setNormalBounds(Rectangle r)
{
- storedBounds.setBounds(r.x, r.y, r.width, r.height);
+ storedBounds = r;
}
/**
@@ -1621,8 +1603,23 @@ public class JInternalFrame extends JComponent implements Accessible,
if (rootPane != null)
remove(rootPane);
+ JRootPane old = rootPane;
rootPane = root;
- add(root);
+
+ if (rootPane != null)
+ {
+ boolean checkingEnabled = isRootPaneCheckingEnabled();
+ try
+ {
+ setRootPaneCheckingEnabled(false);
+ add(rootPane, BorderLayout.CENTER);
+ }
+ finally
+ {
+ setRootPaneCheckingEnabled(checkingEnabled);
+ }
+ }
+ firePropertyChange(ROOT_PANE_PROPERTY, old, rootPane);
}
/**
@@ -1652,27 +1649,26 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void setSelected(boolean selected) throws PropertyVetoException
{
- if (selected != isSelected())
+ if (selected != isSelected
+ && (! selected || (isIcon ? desktopIcon.isShowing() : isShowing())))
{
- fireVetoableChange(IS_SELECTED_PROPERTY, selected, isSelected);
-
- if (! selected)
- defaultFocus = getMostRecentFocusOwner();
+ fireVetoableChange(IS_SELECTED_PROPERTY, isSelected, selected);
- isSelected = selected;
+ if (! selected)
+ defaultFocus = getMostRecentFocusOwner();
- if (selected)
- restoreSubcomponentFocus();
+ isSelected = selected;
+ firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected);
- if (isShowing())
- repaint();
+ if (isSelected)
+ fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
+ else
+ fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
- firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected);
+ if (selected)
+ restoreSubcomponentFocus();
- if (isSelected)
- fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
- else
- fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
+ repaint();
}
}
@@ -1687,14 +1683,9 @@ public class JInternalFrame extends JComponent implements Accessible,
*/
public void setTitle(String title)
{
- if (title == null && this.title == null)
- return;
- if (title == null || this.title == null || ! this.title.equals(title))
- {
- String old = this.title;
- this.title = title;
- firePropertyChange(TITLE_PROPERTY, old, this.title);
- }
+ String old = this.title;
+ this.title = title;
+ firePropertyChange(TITLE_PROPERTY, old, this.title);
}
/**
@@ -1707,12 +1698,21 @@ public class JInternalFrame extends JComponent implements Accessible,
{
if (! isVisible())
{
+ if (isFirstTimeVisible)
+ {
+ isFirstTimeVisible = false;
+ fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
+ }
+
+ getDesktopIcon().setVisible(true);
+
+ toFront();
super.show();
- JDesktopPane pane = getDesktopPane();
- if (pane != null)
- pane.setSelectedFrame(this);
- else
+ if (isIcon())
+ return;
+
+ if (! isSelected())
{
try
{
@@ -1723,11 +1723,6 @@ public class JInternalFrame extends JComponent implements Accessible,
// Do nothing. if they don't want to be selected.
}
}
- if (isFirstTimeVisible)
- {
- isFirstTimeVisible = false;
- fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
- }
}
}
diff --git a/javax/swing/JLabel.java b/javax/swing/JLabel.java
index a5fe3ba1a..b3daf3bc4 100644
--- a/javax/swing/JLabel.java
+++ b/javax/swing/JLabel.java
@@ -46,6 +46,7 @@ import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeEvent;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
@@ -57,7 +58,7 @@ import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
/**
- * A swing widget that displays a text message and/or an icon.
+ * A component that displays a static text message and/or an icon.
*/
public class JLabel extends JComponent implements Accessible, SwingConstants
{
@@ -359,7 +360,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
/** The label's mnemnonic key. */
private transient int displayedMnemonic = KeyEvent.VK_UNDEFINED;
- /** The index of the menemonic character in the text. */
+ /** The index of the mnemonic character in the text. */
private transient int displayedMnemonicIndex = -1;
/** The gap between the icon and the text. */
@@ -439,7 +440,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns the label's UI delegate.
+ * Returns the label's UI delegate.
*
* @return The label's UI delegate.
*/
@@ -449,9 +450,9 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method sets the label's UI delegate.
+ * Sets the label's UI delegate.
*
- * @param ui The label's UI delegate.
+ * @param ui The label's UI delegate (<code>null</code> not permitted).
*/
public void setUI(LabelUI ui)
{
@@ -459,8 +460,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method resets the label's UI delegate to the default UI for the
- * current look and feel.
+ * Resets the label's UI delegate to the default UI for the current look and
+ * feel.
*/
public void updateUI()
{
@@ -468,10 +469,10 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns a name to identify which look and feel class will be
+ * Returns a name to identify which look and feel class will be
* the UI delegate for this label.
*
- * @return The UIClass identifier. "LabelUI"
+ * @return <code>"LabelUI"</code>
*/
public String getUIClassID()
{
@@ -518,9 +519,11 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns the label text.
+ * Returns the text displayed by the label.
*
- * @return The label text.
+ * @return The label text (possibly <code>null</code>).
+ *
+ * @see #setText(String)
*/
public String getText()
{
@@ -528,31 +531,42 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method changes the "text" property. The given text will be painted
- * in the label.
+ * Sets the text for the label and sends a {@link PropertyChangeEvent} (with
+ * the name 'text') to all registered listeners. This method will also
+ * update the <code>displayedMnemonicIndex</code>, if necessary.
*
- * @param newText The label's text.
+ * @param newText The text (<code>null</code> permitted).
+ *
+ * @see #getText()
+ * @see #getDisplayedMnemonicIndex()
*/
public void setText(String newText)
{
- if (text != newText)
- {
- String oldText = text;
- text = newText;
- firePropertyChange("text", oldText, newText);
+ if (text == null && newText == null)
+ return;
+ if (text != null && text.equals(newText))
+ return;
- if (text != null && text.length() <= displayedMnemonicIndex)
- setDisplayedMnemonicIndex(text.length() - 1);
- revalidate();
- repaint();
- }
+ String oldText = text;
+ text = newText;
+ firePropertyChange("text", oldText, newText);
+
+ if (text != null)
+ setDisplayedMnemonicIndex(text.toUpperCase().indexOf(displayedMnemonic));
+ else
+ setDisplayedMnemonicIndex(-1);
+ revalidate();
+ repaint();
}
/**
- * This method returns the active icon. The active icon is painted when the
- * label is enabled.
+ * Returns the active icon. The active icon is painted when the label is
+ * enabled.
*
* @return The active icon.
+ *
+ * @see #setIcon(Icon)
+ * @see #getDisabledIcon()
*/
public Icon getIcon()
{
@@ -560,81 +574,93 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method changes the "icon" property. This icon (the active icon) will
- * be the one displayed when the label is enabled.
+ * Sets the icon for the label (this is a bound property with the name
+ * 'icon'). This icon will be displayed when the label is enabled.
*
- * @param newIcon The active icon.
+ * @param newIcon The icon (<code>null</code> permitted).
+ *
+ * @see #getIcon()
+ * @see #setDisabledIcon(Icon)
*/
public void setIcon(Icon newIcon)
{
if (icon != newIcon)
{
- Icon oldIcon = icon;
- icon = newIcon;
- firePropertyChange("icon", oldIcon, newIcon);
- repaint();
+ Icon oldIcon = icon;
+ icon = newIcon;
+ firePropertyChange("icon", oldIcon, newIcon);
+ repaint();
}
}
/**
- * This method returns the disabled icon. The disabled icon is painted when
- * the label is disabled. If the disabled icon is null and the active icon
- * is an ImageIcon, this method returns a grayed version of the icon. The
- * grayed version of the icon becomes the disabledIcon.
+ * Returns the disabled icon. The disabled icon is painted when the label is
+ * disabled. If the disabled icon is <code>null</code> and the active icon
+ * is an {@link ImageIcon}, this method returns a grayed version of the icon.
+ * The grayed version of the icon becomes the <code>disabledIcon</code>.
*
* @return The disabled icon.
+ *
+ * @see #setDisabledIcon(Icon)
*/
public Icon getDisabledIcon()
{
if (disabledIcon == null && icon instanceof ImageIcon)
- disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) icon)
- .getImage()));
+ disabledIcon = new ImageIcon(
+ GrayFilter.createDisabledImage(((ImageIcon) icon).getImage()));
return disabledIcon;
}
/**
- * This method changes the "disabledIcon" property. This icon (the disabled
- * icon) will be the one displayed when the label is disabled.
+ * Sets the icon displayed when the label is disabled (this is a bound
+ * property with the name 'disabledIcon').
*
- * @param newIcon The disabled icon.
+ * @param newIcon The disabled icon (<code>null</code> permitted).
+ *
+ * @see #getDisabledIcon()
*/
public void setDisabledIcon(Icon newIcon)
{
if (disabledIcon != newIcon)
{
- Icon oldIcon = disabledIcon;
- disabledIcon = newIcon;
- firePropertyChange("disabledIcon", oldIcon, newIcon);
+ Icon oldIcon = disabledIcon;
+ disabledIcon = newIcon;
+ firePropertyChange("disabledIcon", oldIcon, newIcon);
}
}
/**
- * This method sets the keycode that will be the label's mnemonic. If the
- * label is used as a label for another component, the label will give
- * focus to that component when the mnemonic is activated.
+ * Sets the keycode that will be the label's mnemonic (this is a bound
+ * property with the name 'displayedMnemonic'). If the label is used as a
+ * label for another component, the label will give focus to that component
+ * when the mnemonic is activated.
*
* @param mnemonic The keycode to use for the mnemonic.
+ *
+ * @see #getDisplayedMnemonic()
*/
public void setDisplayedMnemonic(int mnemonic)
{
if (displayedMnemonic != mnemonic)
{
- firePropertyChange("displayedMnemonic",
- displayedMnemonic, mnemonic);
- displayedMnemonic = mnemonic;
-
- if (text != null)
- setDisplayedMnemonicIndex(text.toUpperCase().indexOf(mnemonic));
+ int old = displayedMnemonic;
+ displayedMnemonic = mnemonic;
+ firePropertyChange("displayedMnemonic", old, displayedMnemonic);
+ if (text != null)
+ setDisplayedMnemonicIndex(text.toUpperCase().indexOf(mnemonic));
}
}
/**
- * This method sets the character that will be the mnemonic used. If the
+ * Sets the character that will be the label's mnemonic. If the
* label is used as a label for another component, the label will give
- * focus to that component when the mnemonic is activated.
+ * focus to that component when the mnemonic is activated via the keyboard.
*
- * @param mnemonic The character to use for the mnemonic.
+ * @param mnemonic The character to use for the mnemonic (this will be
+ * converted to the equivalent upper case character).
+ *
+ * @see #getDisplayedMnemonic()
*/
public void setDisplayedMnemonic(char mnemonic)
{
@@ -642,51 +668,63 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns the keycode that is used for the label's mnemonic.
+ * Returns the keycode that is used for the label's mnemonic.
*
* @return The keycode that is used for the label's mnemonic.
+ *
+ * @see #setDisplayedMnemonic(int)
*/
public int getDisplayedMnemonic()
{
- return (int) displayedMnemonic;
+ return displayedMnemonic;
}
/**
- * This method sets which character in the text will be the underlined
- * character. If the given index is -1, then this indicates that there is
- * no mnemonic. If the index is less than -1 or if the index is equal to
- * the length, this method will throw an IllegalArgumentException.
+ * Sets the index of the character in the text that will be underlined to
+ * indicate that it is the mnemonic character for the label. You only need
+ * to call this method if you wish to override the automatically calculated
+ * character index. For instance, for a label "Find Next" with the mnemonic
+ * character 'n', you might wish to underline the second occurrence of 'n'
+ * rather than the first (which is the default).
+ * <br><br>
+ * Note that this method does not validate the character at the specified
+ * index to ensure that it matches the key code returned by
+ * {@link #getDisplayedMnemonic()}.
*
* @param newIndex The index of the character to underline.
*
- * @throws IllegalArgumentException If index less than -1 or index equals
- * length.
+ * @throws IllegalArgumentException If index less than -1 or index is greater
+ * than or equal to the label length.
+ *
+ * @see #getDisplayedMnemonicIndex()
+ * @since 1.4
*/
public void setDisplayedMnemonicIndex(int newIndex)
throws IllegalArgumentException
{
- if (newIndex < -1 || (text != null && newIndex >= text.length()))
+ int maxValid = -1;
+ if (text != null)
+ maxValid = text.length() - 1;
+ if (newIndex < -1 || newIndex > maxValid)
throw new IllegalArgumentException();
- if (newIndex == -1
- || text == null
- || text.charAt(newIndex) != displayedMnemonic)
- newIndex = -1;
-
if (newIndex != displayedMnemonicIndex)
{
- int oldIndex = displayedMnemonicIndex;
- displayedMnemonicIndex = newIndex;
- firePropertyChange("displayedMnemonicIndex",
- oldIndex, newIndex);
+ int oldIndex = displayedMnemonicIndex;
+ displayedMnemonicIndex = newIndex;
+ firePropertyChange("displayedMnemonicIndex", oldIndex, newIndex);
}
}
/**
- * This method returns which character in the text will be the underlined
- * character.
+ * Returns the index of the character in the label's text that will be
+ * underlined (to indicate that it is the mnemonic character), or -1 if no
+ * character is to be underlined.
*
* @return The index of the character that will be underlined.
+ *
+ * @see #setDisplayedMnemonicIndex(int)
+ * @since 1.4
*/
public int getDisplayedMnemonicIndex()
{
@@ -694,14 +732,16 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method ensures that the key is valid as a horizontal alignment.
- * Valid keys are: LEFT, CENTER, RIGHT, LEADING, TRAILING
+ * Checks the specified key to ensure that it is valid as a horizontal
+ * alignment, throwing an {@link IllegalArgumentException} if the key is
+ * invalid. Valid keys are {@link #LEFT}, {@link #CENTER}, {@link #RIGHT},
+ * {@link #LEADING} and {@link #TRAILING}.
*
* @param key The key to check.
* @param message The message of the exception to be thrown if the key is
* invalid.
*
- * @return The key if it's valid.
+ * @return The key if it is valid.
*
* @throws IllegalArgumentException If the key is invalid.
*/
@@ -715,14 +755,15 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method ensures that the key is valid as a vertical alignment. Valid
- * keys are: TOP, CENTER, and BOTTOM.
+ * Checks the specified key to ensure that it is valid as a vertical
+ * alignment, throwing an {@link IllegalArgumentException} if the key is
+ * invalid. Valid keys are {@link #TOP}, {@link #CENTER} and {@link #BOTTOM}.
*
* @param key The key to check.
* @param message The message of the exception to be thrown if the key is
* invalid.
*
- * @return The key if it's valid.
+ * @return The key if it is valid.
*
* @throws IllegalArgumentException If the key is invalid.
*/
@@ -735,9 +776,11 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns the gap between the icon and the text.
+ * Returns the gap between the icon and the text.
*
* @return The gap between the icon and the text.
+ *
+ * @see #setIconTextGap(int)
*/
public int getIconTextGap()
{
@@ -745,10 +788,12 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method changes the "iconTextGap" property. The iconTextGap
- * determines how much space there is between the icon and the text.
+ * Sets the gap between the icon and the text, in the case that both are
+ * visible (this is a bound property with the name 'iconTextGap').
*
- * @param newGap The gap between the icon and the text.
+ * @param newGap The gap (in pixels).
+ *
+ * @see #getIconTextGap()
*/
public void setIconTextGap(int newGap)
{
@@ -760,9 +805,13 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns the vertical alignment of the label.
+ * Returns the vertical alignment of the label (one of
+ * {@link #TOP}, {@link #CENTER} and {@link #BOTTOM}). The default value
+ * depends on the installed look and feel, but is usually {@link #CENTER}.
*
- * @return The vertical alignment of the label.
+ * @return The vertical alignment.
+ *
+ * @see #setVerticalAlignment(int)
*/
public int getVerticalAlignment()
{
@@ -770,12 +819,18 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method changes the "verticalAlignment" property of the label. The
- * vertical alignment determines how where the label will be placed
- * vertically. If the alignment is not valid, it will default to the
- * center.
+ * Sets the vertical alignment for the label (this is a bound property with
+ * the name 'verticalAlignment'). The vertical alignment determines where
+ * the label (icon and text) will be placed vertically within the component
+ * bounds. Valid alignment codes are {@link #TOP}, {@link #CENTER} and
+ * {@link #BOTTOM}.
*
* @param alignment The vertical alignment of the label.
+ *
+ * @throws IllegalArgumentException if <code>alignment</code> is not one of
+ * the specified values.
+ *
+ * @see #getVerticalAlignment()
*/
public void setVerticalAlignment(int alignment)
{
@@ -788,9 +843,14 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns the horziontal alignment of the label.
+ * Returns the horizontal alignment of the label (one of {@link #LEFT},
+ * {@link #CENTER}, {@link #RIGHT}, {@link #LEADING} and {@link #TRAILING}).
+ * The default value depends on the installed look and feel, but is usually
+ * {@link #LEFT}.
*
- * @return The horizontal alignment of the label.
+ * @return The horizontal alignment.
+ *
+ * @see #setHorizontalAlignment(int)
*/
public int getHorizontalAlignment()
{
@@ -798,10 +858,18 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method changes the "horizontalAlignment" property. The horizontal
- * alignment determines where the label will be placed horizontally.
+ * Sets the horizontal alignment for the label (this is a bound property with
+ * the name 'horizontalAlignment'). The horizontal alignment determines where
+ * the label (icon and text) will be placed horizontally within the
+ * component bounds. Valid alignment codes are {@link #LEFT},
+ * {@link #CENTER}, {@link #RIGHT}, {@link #LEADING} and {@link #TRAILING}.
*
* @param alignment The horizontal alignment of the label.
+ *
+ * @throws IllegalArgumentException if <code>alignment</code> is not one of
+ * the specified values.
+ *
+ * @see #getHorizontalAlignment()
*/
public void setHorizontalAlignment(int alignment)
{
@@ -815,9 +883,12 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns the vertical text position of the label.
- *
- * @return The vertical text position of the label.
+ * Returns the vertical position of the label's text relative to the icon.
+ * This will be one of {@link #TOP}, {@link #CENTER} and {@link #BOTTOM}.
+ *
+ * @return The vertical position of the label's text relative to the icon.
+ *
+ * @see #setVerticalTextPosition(int)
*/
public int getVerticalTextPosition()
{
@@ -825,28 +896,35 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method changes the "verticalTextPosition" property of the label. The
- * vertical text position determines where the text will be placed
- * vertically relative to the icon.
+ * Sets the vertical position of the label's text relative to the icon (this
+ * is a bound property with the name 'verticalTextPosition'). Valid
+ * positions are {@link #TOP}, {@link #CENTER} and {@link #BOTTOM}.
*
* @param textPosition The vertical text position.
+ *
+ * @throws IllegalArgumentException if <code>textPosition</code> is not one
+ * of the specified values.
*/
public void setVerticalTextPosition(int textPosition)
{
if (textPosition != verticalTextPosition)
{
- int oldPos = verticalTextPosition;
- verticalTextPosition = checkVerticalKey(textPosition,
- "verticalTextPosition");
- firePropertyChange("verticalTextPosition", oldPos,
- verticalTextPosition);
+ int oldPos = verticalTextPosition;
+ verticalTextPosition = checkVerticalKey(textPosition,
+ "verticalTextPosition");
+ firePropertyChange("verticalTextPosition", oldPos,
+ verticalTextPosition);
}
}
/**
- * This method returns the horizontal text position of the label.
- *
- * @return The horizontal text position.
+ * Returns the horizontal position of the label's text relative to the icon.
+ * This will be one of {@link #LEFT}, {@link #CENTER}, {@link #RIGHT},
+ * {@link #LEADING} and {@link #TRAILING}.
+ *
+ * @return The horizontal position of the label's text relative to the icon.
+ *
+ * @see #setHorizontalTextPosition(int)
*/
public int getHorizontalTextPosition()
{
@@ -854,28 +932,31 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method changes the "horizontalTextPosition" property of the label.
- * The horizontal text position determines where the text will be placed
- * horizontally relative to the icon.
+ * Sets the horizontal position of the label's text relative to the icon (this
+ * is a bound property with the name 'horizontalTextPosition'). Valid
+ * positions are {@link #LEFT}, {@link #CENTER}, {@link #RIGHT},
+ * {@link #LEADING} and {@link #TRAILING}.
*
* @param textPosition The horizontal text position.
+ *
+ * @throws IllegalArgumentException if <code>textPosition</code> is not one
+ * of the specified values.
*/
public void setHorizontalTextPosition(int textPosition)
{
if (textPosition != horizontalTextPosition)
{
- int oldPos = horizontalTextPosition;
- horizontalTextPosition = checkHorizontalKey(textPosition,
- "horizontalTextPosition");
- firePropertyChange("horizontalTextPosition", oldPos,
- horizontalTextPosition);
+ int oldPos = horizontalTextPosition;
+ horizontalTextPosition = checkHorizontalKey(textPosition,
+ "horizontalTextPosition");
+ firePropertyChange("horizontalTextPosition", oldPos,
+ horizontalTextPosition);
}
}
/**
- * This method simply returns false if the current icon image (current icon
- * will depend on whether the label is enabled) is not equal to the passed
- * in image.
+ * Returns false if the current icon image (current icon will depend on
+ * whether the label is enabled) is not equal to the passed in image.
*
* @param img The image to check.
* @param infoflags The bitwise inclusive OR of ABORT, ALLBITS, ERROR,
@@ -900,11 +981,11 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method returns the component that the label gives focus to when the
- * mnemonic is activated.
+ * Returns the component that this <code>JLabel</code> is providing the label
+ * for. This component will typically receive the focus when the label's
+ * mnemonic key is activated via the keyboard.
*
- * @return The component that gets focus when the label's mnemonic is
- * activated.
+ * @return The component (possibly <code>null</code>).
*/
public Component getLabelFor()
{
@@ -912,12 +993,14 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method changes the "labelFor" property. The component that the label
- * is acting as a label for will request focus when the label's mnemonic
- * is activated.
+ * Sets the component that this <code>JLabel</code> is providing the label
+ * for (this is a bound property with the name 'labelFor'). This component
+ * will typically receive the focus when the label's mnemonic key is
+ * activated via the keyboard.
*
- * @param c The component that gets focus when the label's mnemonic is
- * activated.
+ * @param c the component (<code>null</code> permitted).
+ *
+ * @see #getLabelFor()
*/
public void setLabelFor(Component c)
{
@@ -946,10 +1029,9 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * This method overrides setFont so that we can call for a repaint after the
- * font is changed.
+ * Sets the font for the label (this a bound property with the name 'font').
*
- * @param f The font for this label.
+ * @param f The font (<code>null</code> permitted).
*/
public void setFont(Font f)
{
diff --git a/javax/swing/JLayeredPane.java b/javax/swing/JLayeredPane.java
index c097c655a..d981788ec 100644
--- a/javax/swing/JLayeredPane.java
+++ b/javax/swing/JLayeredPane.java
@@ -43,6 +43,7 @@ import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Rectangle;
+import java.util.ArrayList;
import java.util.Hashtable;
import javax.accessibility.Accessible;
@@ -326,13 +327,13 @@ public class JLayeredPane extends JComponent implements Accessible
{
int pos = -1;
int index = getIndexOf(c);
- Component[] components = getComponents();
- int layer = getLayer(c);
if (index >= 0)
{
- for (int i = index; i >= 0; --i)
+ pos = 0;
+ int layer = getLayer(c);
+ for (int i = index - 1; i >= 0; --i)
{
- if (layer == getLayer(components[i]))
+ if (layer == getLayer(getComponent(i)))
pos++;
else
break;
@@ -353,9 +354,7 @@ public class JLayeredPane extends JComponent implements Accessible
*/
public void setPosition(Component c, int position)
{
- int layer = getLayer(c);
- int index = insertIndexForLayer(layer, position);
- setComponentZOrder(c, index);
+ setLayer(c, getLayer(c), position);
}
/**
@@ -478,34 +477,85 @@ public class JLayeredPane extends JComponent implements Accessible
*/
protected int insertIndexForLayer(int layer, int position)
{
- // position < 0 means insert at greatest position within layer.
- if (position < 0)
- position = Integer.MAX_VALUE;
+ return insertIndexForLayer(null, layer, position);
+ }
- Component[] components = getComponents();
- int index = 0;
+ /**
+ * Similar to {@link #insertIndexForLayer(int, int)}, only that it takes a
+ * component parameter, which should be ignored in the search. This is
+ * necessary to support {@link #setLayer(Component, int, int)} which uses
+ * Container.setComponentZOrder(), which doesn't remove the component.
+ *
+ * @param comp the component to ignore
+ * @param layer the layer
+ * @param position the position
+ *
+ * @return the insertion index
+ */
+ private int insertIndexForLayer(Component comp, int layer, int position)
+ {
+ // Create the component list to search through.
+ ArrayList l = new ArrayList();
+ int count = getComponentCount();
+ for (int i = 0; i < count; i++)
+ {
+ Component c = getComponent(i);
+ if (c != comp)
+ l.add(c);
+ }
- // Try to find the start index of the specified layer.
- int p = -1;
- for (int i = 0; i < components.length; i++)
+ count = l.size();
+ int layerStart = -1;
+ int layerEnd = -1;
+ for (int i = 0; i < count; i++)
{
- int l = getLayer(components[i]);
- if (l > layer)
- index++;
- // If we are in the layer we look for, try to find the position.
- else if (l == layer)
+ int layerOfComponent = getLayer((Component) l.get(i));
+ if (layerStart == -1 && layerOfComponent == layer)
+ layerStart = i;
+ if (layerOfComponent < layer)
{
- p++;
- if (p < position)
- index++;
+ // We are beyond the layer that we are looking for. Update the
+ // layerStart and layerEnd and exit the loop.
+ if (i == 0)
+ {
+ layerStart = 0;
+ layerEnd = 0;
+ }
else
- break;
+ layerEnd = i;
+ break;
}
- // No need to look further if the layer at i is smaller than layer.
+ }
+
+ // No layer found. The requested layer is lower than any existing layer,
+ // put the component at the end.
+ int insertIndex;
+ if (layerStart == -1 && layerEnd == -1)
+ {
+ insertIndex = count;
+ }
+ else
+ {
+ // Corner cases.
+ if (layerStart != -1 && layerEnd == -1)
+ layerEnd = count;
+ if (layerStart == -1 && layerEnd != -1)
+ layerStart = layerEnd;
+
+ // Adding to the bottom of a layer returns the end index
+ // in the layer.
+ if (position == -1)
+ insertIndex = layerEnd;
else
- break;
+ {
+ // Insert into a layer.
+ if (position > -1 && layerStart + position <= layerEnd)
+ insertIndex = layerStart + position;
+ else
+ insertIndex = layerEnd;
+ }
}
- return index;
+ return insertIndex;
}
/**
@@ -559,17 +609,29 @@ public class JLayeredPane extends JComponent implements Accessible
public void setLayer(Component c, int layer, int position)
{
Integer layerObj = getObjectForLayer(layer);
- if (c instanceof JComponent)
+
+ // Nothing to do if neither the layer nor the position is
+ // changed.
+ if (layer != getLayer(c) || position != getPosition(c))
{
- JComponent jc = (JComponent) c;
- jc.putClientProperty(LAYER_PROPERTY, layerObj);
- }
- else
- componentToLayer.put (c, layerObj);
+ // Store the layer either in the JComponent or in the hashtable
+ if (c instanceof JComponent)
+ {
+ JComponent jc = (JComponent) c;
+ jc.putClientProperty(LAYER_PROPERTY, layerObj);
+ }
+ else
+ componentToLayer.put (c, layerObj);
- // Set position only of component is already added to this layered pane.
- if (getIndexOf(c) != -1)
- setPosition(c, position);
+ // Update the component in the Z order of the Container.
+ Container parent = c.getParent();
+ if (parent == this)
+ {
+ int index = insertIndexForLayer(c, layer, position);
+ setComponentZOrder(c, index);
+ }
+ }
+ repaint(c.getX(), c.getY(), c.getWidth(), c.getHeight());
}
/**
@@ -592,14 +654,17 @@ public class JLayeredPane extends JComponent implements Accessible
{
int layer;
if (layerConstraint != null && layerConstraint instanceof Integer)
- layer = ((Integer) layerConstraint).intValue();
+ {
+ layer = ((Integer) layerConstraint).intValue();
+ setLayer(comp, layer);
+ }
else
- layer = getLayer(comp);
+ layer = getLayer(comp);
int newIdx = insertIndexForLayer(layer, index);
- setLayer(comp, layer);
super.addImpl(comp, layerConstraint, newIdx);
- repaint(comp.getX(), comp.getY(), comp.getWidth(), comp.getHeight());
+ comp.validate();
+ comp.repaint();
}
/**
diff --git a/javax/swing/JList.java b/javax/swing/JList.java
index 1710541f4..1cff9553a 100644
--- a/javax/swing/JList.java
+++ b/javax/swing/JList.java
@@ -944,17 +944,6 @@ public class JList extends JComponent implements Accessible, Scrollable
*/
ListSelectionModel selectionModel;
-
- /**
- * This property indicates that the list's selection is currently
- * "adjusting" -- perhaps due to a user actively dragging the mouse over
- * multiple list elements -- and is therefore likely to change again in
- * the near future. A {@link ListSelectionListener} might choose to delay
- * updating its view of the list's selection until this property is
- * false, meaning that the adjustment has completed.
- */
- boolean valueIsAdjusting;
-
/**
* This property indicates a <em>preference</em> for the number of rows
* displayed in the list, and will scale the
@@ -1085,8 +1074,7 @@ public class JList extends JComponent implements Accessible, Scrollable
fixedCellWidth = -1;
layoutOrientation = VERTICAL;
opaque = true;
- valueIsAdjusting = false;
- visibleRowCount = 7;
+ visibleRowCount = 8;
cellRenderer = new DefaultListCellRenderer();
listListener = new ListListener();
@@ -1196,11 +1184,13 @@ public class JList extends JComponent implements Accessible, Scrollable
}
/**
- * Gets the value of the {@link #visibleRowCount} property.
+ * Gets the value of the {@link #visibleRowCount} property. The default
+ * value is 8.
*
* @return the current value of the property.
+ *
+ * @see #setVisibleRowCount(int)
*/
-
public int getVisibleRowCount()
{
return visibleRowCount;
@@ -1210,12 +1200,19 @@ public class JList extends JComponent implements Accessible, Scrollable
* Sets the value of the {@link #visibleRowCount} property.
*
* @param vc The new property value
+ *
+ * @see #getVisibleRowCount()
*/
public void setVisibleRowCount(int vc)
{
- visibleRowCount = vc;
- revalidate();
- repaint();
+ if (visibleRowCount != vc)
+ {
+ int oldValue = visibleRowCount;
+ visibleRowCount = Math.max(vc, 0);
+ firePropertyChange("visibleRowCount", oldValue, vc);
+ revalidate();
+ repaint();
+ }
}
/**
@@ -2195,23 +2192,25 @@ public class JList extends JComponent implements Accessible, Scrollable
}
/**
- * Returns the value of the <code>valueIsAdjusting</code> property.
+ * Returns the <code>valueIsAdjusting</code> flag from the list's selection
+ * model.
*
* @return the value
*/
public boolean getValueIsAdjusting()
{
- return valueIsAdjusting;
+ return selectionModel.getValueIsAdjusting();
}
/**
- * Sets the <code>valueIsAdjusting</code> property.
+ * Sets the <code>valueIsAdjusting</code> flag in the list's selection
+ * model.
*
* @param isAdjusting the new value
*/
public void setValueIsAdjusting(boolean isAdjusting)
{
- valueIsAdjusting = isAdjusting;
+ selectionModel.setValueIsAdjusting(isAdjusting);
}
/**
@@ -2239,11 +2238,13 @@ public class JList extends JComponent implements Accessible, Scrollable
}
/**
- * Returns the layout orientation.
+ * Returns the layout orientation, which will be one of {@link #VERTICAL},
+ * {@link #VERTICAL_WRAP} and {@link #HORIZONTAL_WRAP}. The default value
+ * is {@link #VERTICAL}.
*
- * @return the orientation, one of <code>JList.VERTICAL</code>,
- * <code>JList.VERTICAL_WRAP</code> and <code>JList.HORIZONTAL_WRAP</code>
+ * @return the orientation.
*
+ * @see #setLayoutOrientation(int)
* @since 1.4
*/
public int getLayoutOrientation()
@@ -2252,15 +2253,21 @@ public class JList extends JComponent implements Accessible, Scrollable
}
/**
- * Sets the layout orientation.
+ * Sets the layout orientation (this is a bound property with the name
+ * 'layoutOrientation'). Valid orientations are {@link #VERTICAL},
+ * {@link #VERTICAL_WRAP} and {@link #HORIZONTAL_WRAP}.
*
- * @param orientation the orientation to set, one of <code>JList.VERTICAL</code>,
- * <code>JList.VERTICAL_WRAP</code> and <code>JList.HORIZONTAL_WRAP</code>
+ * @param orientation the orientation.
*
+ * @throws IllegalArgumentException if <code>orientation</code> is not one
+ * of the specified values.
* @since 1.4
+ * @see #getLayoutOrientation()
*/
public void setLayoutOrientation(int orientation)
{
+ if (orientation < JList.VERTICAL || orientation > JList.HORIZONTAL_WRAP)
+ throw new IllegalArgumentException();
if (layoutOrientation == orientation)
return;
@@ -2293,14 +2300,16 @@ public class JList extends JComponent implements Accessible, Scrollable
}
/**
- * Returns the next list element (beginning from <code>startIndex</code>
- * that starts with <code>prefix</code>. Searching is done in the direction
- * specified by <code>bias</code>.
+ * Returns the index of the next list element (beginning at
+ * <code>startIndex</code> and moving in the specified direction through the
+ * list, looping around if necessary) that starts with <code>prefix</code>
+ * (ignoring case).
*
* @param prefix the prefix to search for in the cell values
* @param startIndex the index where to start searching from
- * @param bias the search direction, either {@link Position.Bias#Forward}
- * or {@link Position.Bias#Backward}
+ * @param direction the search direction, either {@link Position.Bias#Forward}
+ * or {@link Position.Bias#Backward} (<code>null</code> is interpreted
+ * as {@link Position.Bias#Backward}.
*
* @return the index of the found element or -1 if no such element has
* been found
@@ -2310,7 +2319,8 @@ public class JList extends JComponent implements Accessible, Scrollable
*
* @since 1.4
*/
- public int getNextMatch(String prefix, int startIndex, Position.Bias bias)
+ public int getNextMatch(String prefix, int startIndex,
+ Position.Bias direction)
{
if (prefix == null)
throw new IllegalArgumentException("The argument 'prefix' must not be"
@@ -2320,37 +2330,33 @@ public class JList extends JComponent implements Accessible, Scrollable
+ " be less than zero.");
int size = model.getSize();
- if (startIndex > model.getSize())
+ if (startIndex >= model.getSize())
throw new IllegalArgumentException("The argument 'startIndex' must not"
+ " be greater than the number of"
+ " elements in the ListModel.");
- int index = -1;
- if (bias == Position.Bias.Forward)
- {
- for (int i = startIndex; i < size; i++)
- {
- String item = model.getElementAt(i).toString();
- if (item.startsWith(prefix))
- {
- index = i;
- break;
- }
- }
- }
- else
+ int result = -1;
+ int current = startIndex;
+ int delta = -1;
+ int itemCount = model.getSize();
+ boolean finished = false;
+ prefix = prefix.toUpperCase();
+
+ if (direction == Position.Bias.Forward)
+ delta = 1;
+ while (!finished)
{
- for (int i = startIndex; i >= 0; i--)
- {
- String item = model.getElementAt(i).toString();
- if (item.startsWith(prefix))
- {
- index = i;
- break;
- }
- }
+ String itemStr = model.getElementAt(current).toString().toUpperCase();
+ if (itemStr.startsWith(prefix))
+ return current;
+ current = (current + delta);
+ if (current == -1)
+ current += itemCount;
+ else
+ current = current % itemCount;
+ finished = current == startIndex;
}
- return index;
+ return result;
}
/**
diff --git a/javax/swing/JMenu.java b/javax/swing/JMenu.java
index 02cb20eab..0840509f9 100644
--- a/javax/swing/JMenu.java
+++ b/javax/swing/JMenu.java
@@ -40,6 +40,7 @@ package javax.swing;
import java.awt.Component;
import java.awt.Point;
+import java.awt.PopupMenu;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@@ -74,7 +75,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
private static final long serialVersionUID = 4227225638931828014L;
/** A Popup menu associated with this menu, which pops up when menu is selected */
- private JPopupMenu popupMenu = new JPopupMenu();
+ private JPopupMenu popupMenu = null;
/** Whenever menu is selected or deselected the MenuEvent is fired to
menu's registered listeners. */
@@ -98,6 +99,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
{
super();
setOpaque(false);
+ setDelay(200);
}
/**
@@ -108,8 +110,10 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
public JMenu(String text)
{
super(text);
+ popupMenu = new JPopupMenu();
popupMenu.setInvoker(this);
setOpaque(false);
+ setDelay(200);
}
/**
@@ -122,8 +126,10 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
{
super(action);
createActionChangeListener(this);
+ popupMenu = new JPopupMenu();
popupMenu.setInvoker(this);
setOpaque(false);
+ setDelay(200);
}
/**
@@ -137,6 +143,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
{
// FIXME: tearoff not implemented
this(text);
+ setDelay(200);
}
/**
@@ -148,7 +155,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public JMenuItem add(JMenuItem item)
{
- return popupMenu.add(item);
+ return getPopupMenu().add(item);
}
/**
@@ -160,7 +167,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public Component add(Component component)
{
- popupMenu.insert(component, -1);
+ getPopupMenu().insert(component, -1);
return component;
}
@@ -174,7 +181,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public Component add(Component component, int index)
{
- return popupMenu.add(component, index);
+ return getPopupMenu().add(component, index);
}
/**
@@ -186,7 +193,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public JMenuItem add(String text)
{
- return popupMenu.add(text);
+ return getPopupMenu().add(text);
}
/**
@@ -198,7 +205,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public JMenuItem add(Action action)
{
- return popupMenu.add(action);
+ return getPopupMenu().add(action);
}
/**
@@ -209,7 +216,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public void remove(JMenuItem item)
{
- popupMenu.remove(item);
+ getPopupMenu().remove(item);
}
/**
@@ -219,7 +226,11 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public void remove(int index)
{
- popupMenu.remove(index);
+ if (index < 0 || (index > 0 && getMenuComponentCount() == 0))
+ throw new IllegalArgumentException();
+
+ if (getMenuComponentCount() > 0)
+ popupMenu.remove(index);
}
/**
@@ -229,8 +240,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public void remove(Component component)
{
- int index = popupMenu.getComponentIndex(component);
- popupMenu.remove(index);
+ int index = getPopupMenu().getComponentIndex(component);
+ if (index >= 0)
+ getPopupMenu().remove(index);
}
/**
@@ -238,7 +250,8 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public void removeAll()
{
- popupMenu.removeAll();
+ if (popupMenu != null)
+ popupMenu.removeAll();
}
/**
@@ -267,7 +280,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
if (index < 0)
throw new IllegalArgumentException("index less than zero");
- popupMenu.insert(item, index);
+ getPopupMenu().insert(item, index);
return item;
}
@@ -381,7 +394,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
super.setSelected(false);
super.setArmed(false);
fireMenuDeselected();
- popupMenu.setVisible(false);
+ getPopupMenu().setVisible(false);
}
}
@@ -404,7 +417,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public boolean isPopupMenuVisible()
{
- return popupMenu.isVisible();
+ return getPopupMenu().isVisible();
}
/**
@@ -415,7 +428,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
public void setPopupMenuVisible(boolean popup)
{
if (getModel().isEnabled())
- popupMenu.setVisible(popup);
+ getPopupMenu().setVisible(popup);
}
/**
@@ -530,6 +543,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
if (index < 0)
throw new IllegalArgumentException("index less than 0");
+ if (getItemCount() == 0)
+ return null;
+
Component c = popupMenu.getComponentAtIndex(index);
if (c instanceof JMenuItem)
@@ -558,7 +574,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
public boolean isTearOff()
{
// NOT YET IMPLEMENTED
- return false;
+ throw new Error("The method isTearOff() has not yet been implemented.");
}
/**
@@ -568,7 +584,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public int getMenuComponentCount()
{
- return popupMenu.getComponentCount();
+ return getPopupMenu().getComponentCount();
}
/**
@@ -581,6 +597,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public Component getMenuComponent(int index)
{
+ if (getPopupMenu() == null || getMenuComponentCount() == 0)
+ return null;
+
return (Component) popupMenu.getComponentAtIndex(index);
}
@@ -591,7 +610,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public Component[] getMenuComponents()
{
- return popupMenu.getComponents();
+ return getPopupMenu().getComponents();
}
/**
@@ -626,6 +645,11 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
*/
public JPopupMenu getPopupMenu()
{
+ if (popupMenu == null)
+ {
+ popupMenu = new JPopupMenu();
+ popupMenu.setInvoker(this);
+ }
return popupMenu;
}
diff --git a/javax/swing/JSplitPane.java b/javax/swing/JSplitPane.java
index 2747686a3..5b77f5176 100644
--- a/javax/swing/JSplitPane.java
+++ b/javax/swing/JSplitPane.java
@@ -708,7 +708,8 @@ public class JSplitPane extends JComponent implements Accessible
throw new IllegalArgumentException
("proportion has to be between 0 and 1.");
- int max = (orientation == HORIZONTAL_SPLIT) ? getWidth() : getHeight();
+ int max = ((orientation == HORIZONTAL_SPLIT) ? getWidth() : getHeight())
+ - getDividerSize();
setDividerLocation((int) (proportionalLocation * max));
}
diff --git a/javax/swing/RepaintManager.java b/javax/swing/RepaintManager.java
index e9be73f84..262054319 100644
--- a/javax/swing/RepaintManager.java
+++ b/javax/swing/RepaintManager.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package javax.swing;
+import java.applet.Applet;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
@@ -77,12 +78,6 @@ public class RepaintManager
static WeakHashMap currentRepaintManagers;
/**
- * Used to disable merging of regions in commitBuffer(). This has caused
- * problems and may either need to be reworked or removed.
- */
- private static final boolean MERGE_REGIONS = false;
-
- /**
* A rectangle object to be reused in damaged regions calculation.
*/
private static Rectangle rectCache = new Rectangle();
@@ -319,26 +314,45 @@ public class RepaintManager
*/
public void addInvalidComponent(JComponent component)
{
- Component ancestor = component;
-
- while (ancestor != null
- && (! (ancestor instanceof JComponent)
- || ! ((JComponent) ancestor).isValidateRoot() ))
- ancestor = ancestor.getParent();
+ Component validateRoot = null;
+ Component c = component;
+ while (c != null)
+ {
+ // Special cases we don't bother validating are when the invalidated
+ // component (or any of it's ancestors) is inside a CellRendererPane
+ // or if it doesn't have a peer yet (== not displayable).
+ if (c instanceof CellRendererPane || ! c.isDisplayable())
+ return;
+ if (c instanceof JComponent && ((JComponent) c).isValidateRoot())
+ {
+ validateRoot = c;
+ break;
+ }
- if (ancestor != null
- && ancestor instanceof JComponent
- && ((JComponent) ancestor).isValidateRoot())
- component = (JComponent) ancestor;
+ c = c.getParent();
+ }
- if (invalidComponents.contains(component))
+ // If we didn't find a validate root, then we don't validate.
+ if (validateRoot == null)
return;
- synchronized (invalidComponents)
+ // Make sure the validate root and all of it's ancestors are visible.
+ c = validateRoot;
+ while (c != null)
{
- invalidComponents.add(component);
+ if (! c.isVisible() || ! c.isDisplayable())
+ return;
+ c = c.getParent();
}
+ if (invalidComponents.contains(validateRoot))
+ return;
+
+ //synchronized (invalidComponents)
+ // {
+ invalidComponents.add(validateRoot);
+ // }
+
if (! repaintWorker.isLive())
{
repaintWorker.setLive(true);
@@ -384,7 +398,7 @@ public class RepaintManager
{
if (w <= 0 || h <= 0 || !component.isShowing())
return;
-
+
Component parent = component.getParent();
component.computeVisibleRect(rectCache);
@@ -638,7 +652,7 @@ public class RepaintManager
}
return buffer;
}
-
+
/**
* Blits the back buffer of the specified root component to the screen. If
* the RepaintManager is currently working on a paint request, the commit
@@ -666,7 +680,7 @@ public class RepaintManager
{
// If the RepaintManager is not currently painting, then directly
// blit the requested buffer on the screen.
- if (! MERGE_REGIONS || ! repaintUnderway)
+ if (true || ! repaintUnderway)
{
blitBuffer(root, rootRect);
}
@@ -697,6 +711,9 @@ public class RepaintManager
*/
private void blitBuffer(Component root, Rectangle rootRect)
{
+ if (! root.isShowing())
+ return;
+
// Find the Window from which we use the backbuffer.
Component bufferRoot = root;
Rectangle bufferRect = rootRect.getBounds();
@@ -711,7 +728,7 @@ public class RepaintManager
// Make sure we have a sane clip at this point.
g.clipRect(rootRect.x, rootRect.y, rootRect.width, rootRect.height);
- g.drawImage(buffer, bufferRect.x - rootRect.x, bufferRect.y - rootRect.y,
+ g.drawImage(buffer, rootRect.x - bufferRect.x, rootRect.y - bufferRect.y,
root);
g.dispose();
diff --git a/javax/swing/SizeSequence.java b/javax/swing/SizeSequence.java
index 26099a154..a5f34710c 100644
--- a/javax/swing/SizeSequence.java
+++ b/javax/swing/SizeSequence.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package javax.swing;
+import java.util.Arrays;
+
/**
* A sequence of values that represent the dimensions (widths or heights) of
* some collection of items (for example, the widths of the columns in a table).
@@ -80,8 +82,8 @@ public class SizeSequence
*/
public SizeSequence(int numEntries, int value)
{
- sizes = new int[0];
- insertEntries(0, numEntries, value);
+ sizes = new int[numEntries];
+ Arrays.fill(sizes, value);
}
/**
diff --git a/javax/swing/UIManager.java b/javax/swing/UIManager.java
index e6f801163..b70d13952 100644
--- a/javax/swing/UIManager.java
+++ b/javax/swing/UIManager.java
@@ -45,6 +45,7 @@ import java.awt.Insets;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
+import java.util.Enumeration;
import java.util.Locale;
import javax.swing.border.Border;
@@ -117,6 +118,87 @@ public class UIManager implements Serializable
}
}
+ /**
+ * A UIDefaults subclass that multiplexes between itself and a 'fallback'
+ * UIDefaults instance. This is used to protect the L&F UIDefaults from beeing
+ * overwritten by applications.
+ */
+ private static class MultiplexUIDefaults
+ extends UIDefaults
+ {
+ private class MultiplexEnumeration
+ implements Enumeration
+ {
+ Enumeration[] enums;
+ int i;
+ MultiplexEnumeration(Enumeration e1, Enumeration e2)
+ {
+ enums = new Enumeration[]{ e1, e2 };
+ i = 0;
+ }
+
+ public boolean hasMoreElements()
+ {
+ return enums[i].hasMoreElements() || i < enums.length - 1;
+ }
+
+ public Object nextElement()
+ {
+ Object val = enums[i].nextElement();
+ if (! enums[i].hasMoreElements() && i < enums.length - 1)
+ i++;
+ return val;
+ }
+
+ }
+
+ UIDefaults fallback;
+
+ MultiplexUIDefaults(UIDefaults d)
+ {
+ fallback = d;
+ }
+
+ public Object get(Object key)
+ {
+ Object val = super.get(key);
+ if (val == null)
+ val = fallback.get(key);
+ return val;
+ }
+
+ public Object get(Object key, Locale l)
+ {
+ Object val = super.get(key, l);
+ if (val == null)
+ val = fallback.get(key, l);
+ return val;
+ }
+
+ public Object remove(Object key)
+ {
+ Object val = super.remove(key);
+ if (val == null)
+ val = fallback.remove(key);
+ return val;
+ }
+
+ public int size()
+ {
+ return super.size() + fallback.size();
+ }
+
+ public Enumeration keys()
+ {
+ return new MultiplexEnumeration(super.keys(), fallback.keys());
+ }
+
+ public Enumeration elements()
+ {
+ return new MultiplexEnumeration(super.elements(), fallback.elements());
+ }
+ }
+
private static final long serialVersionUID = -5547433830339189365L;
/** The installed look and feel(s). */
@@ -131,12 +213,9 @@ public class UIManager implements Serializable
/** The current look and feel. */
static LookAndFeel currentLookAndFeel;
- static UIDefaults currentUIDefaults;
+ static MultiplexUIDefaults currentUIDefaults;
- /**
- * UIDefaults set by the user.
- */
- static UIDefaults userUIDefaults;
+ static UIDefaults lookAndFeelDefaults;
/** Property change listener mechanism. */
static PropertyChangeSupport listeners
@@ -149,9 +228,7 @@ public class UIManager implements Serializable
{
if (defaultlaf != null)
{
- Class lafClass = Class.forName(defaultlaf);
- LookAndFeel laf = (LookAndFeel) lafClass.newInstance();
- setLookAndFeel(laf);
+ setLookAndFeel(defaultlaf);
}
else
{
@@ -162,6 +239,7 @@ public class UIManager implements Serializable
{
System.err.println("cannot initialize Look and Feel: " + defaultlaf);
System.err.println("error: " + ex.toString());
+ ex.printStackTrace();
System.err.println("falling back to Metal Look and Feel");
try
{
@@ -312,12 +390,7 @@ public class UIManager implements Serializable
*/
public static Object get(Object key)
{
- Object val = null;
- if (userUIDefaults != null)
- val = userUIDefaults.get(key);
- if (val == null)
- val = getLookAndFeelDefaults().get(key);
- return val;
+ return getDefaults().get(key);
}
/**
@@ -330,12 +403,7 @@ public class UIManager implements Serializable
*/
public static Object get(Object key, Locale locale)
{
- Object val = null;
- if (userUIDefaults != null)
- val = userUIDefaults.get(key, locale);
- if (val == null)
- val = getLookAndFeelDefaults().get(key, locale);
- return val;
+ return getDefaults().get(key, locale);
}
/**
@@ -414,6 +482,8 @@ public class UIManager implements Serializable
*/
public static UIDefaults getDefaults()
{
+ if (currentUIDefaults == null)
+ currentUIDefaults = new MultiplexUIDefaults(null);
return currentUIDefaults;
}
@@ -587,13 +657,7 @@ public class UIManager implements Serializable
*/
public static ComponentUI getUI(JComponent target)
{
- ComponentUI ui = null;
- if (userUIDefaults != null
- && userUIDefaults.get(target.getUIClassID()) != null)
- ui = userUIDefaults.getUI(target);
- if (ui == null)
- ui = currentUIDefaults.getUI(target);
- return ui;
+ return getDefaults().getUI(target);
}
/**
@@ -625,11 +689,7 @@ public class UIManager implements Serializable
*/
public static Object put(Object key, Object value)
{
- Object old = get(key);
- if (userUIDefaults == null)
- userUIDefaults = new UIDefaults();
- userUIDefaults.put(key, value);
- return old;
+ return getDefaults().put(key, value);
}
/**
@@ -664,7 +724,12 @@ public class UIManager implements Serializable
if (newLookAndFeel != null)
{
newLookAndFeel.initialize();
- currentUIDefaults = newLookAndFeel.getDefaults();
+ lookAndFeelDefaults = newLookAndFeel.getDefaults();
+ if (currentUIDefaults == null)
+ currentUIDefaults =
+ new MultiplexUIDefaults(lookAndFeelDefaults);
+ else
+ currentUIDefaults.fallback = lookAndFeelDefaults;
}
else
{
@@ -689,7 +754,8 @@ public class UIManager implements Serializable
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
- Class c = Class.forName(className);
+ Class c = Class.forName(className, true,
+ Thread.currentThread().getContextClassLoader());
LookAndFeel a = (LookAndFeel) c.newInstance(); // throws class-cast-exception
setLookAndFeel(a);
}
diff --git a/javax/swing/plaf/IconUIResource.java b/javax/swing/plaf/IconUIResource.java
index 659c8e7ba..8ac9e0875 100644
--- a/javax/swing/plaf/IconUIResource.java
+++ b/javax/swing/plaf/IconUIResource.java
@@ -1,5 +1,5 @@
/* IconUIResource.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -63,7 +63,8 @@ public class IconUIResource implements Icon, UIResource, Serializable
/**
- * The icon that is wrapped by this <code>IconUIResource</code>.
+ * The icon that is wrapped by this <code>IconUIResource</code> (never
+ * <code>null</code>).
*/
private Icon delegate;
@@ -73,10 +74,12 @@ public class IconUIResource implements Icon, UIResource, Serializable
* icon. All messages are forwarded to the delegate icon.
*
* @param delegate the icon that is wrapped by this
- * <code>IconUIResource</code>.
+ * <code>IconUIResource</code> (<code>null</code> not permitted).
*/
public IconUIResource(Icon delegate)
{
+ if (delegate == null)
+ throw new IllegalArgumentException("Null 'delegate' argument.");
this.delegate = delegate;
}
diff --git a/javax/swing/plaf/basic/BasicButtonListener.java b/javax/swing/plaf/basic/BasicButtonListener.java
index 89e99a29a..fe0365a50 100644
--- a/javax/swing/plaf/basic/BasicButtonListener.java
+++ b/javax/swing/plaf/basic/BasicButtonListener.java
@@ -41,10 +41,12 @@ package javax.swing.plaf.basic;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
-import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import java.awt.font.FontRenderContext;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -66,7 +68,21 @@ public class BasicButtonListener implements MouseListener, MouseMotionListener,
public void propertyChange(PropertyChangeEvent e)
{
- // TODO: What should be done here, if anything?
+ // Store the TextLayout for this in a client property for speed-up
+ // painting of the label.
+ String property = e.getPropertyName();
+ if (property.equals(AbstractButton.TEXT_CHANGED_PROPERTY)
+ || property.equals("font"))
+ {
+ AbstractButton b = (AbstractButton) e.getSource();
+ String text = b.getText();
+ if (text == null)
+ text = "";
+ FontRenderContext frc = new FontRenderContext(new AffineTransform(),
+ false, false);
+ TextLayout layout = new TextLayout(text, b.getFont(), frc);
+ b.putClientProperty(BasicGraphicsUtils.CACHED_TEXT_LAYOUT, layout);
+ }
}
protected void checkOpacity(AbstractButton b)
diff --git a/javax/swing/plaf/basic/BasicButtonUI.java b/javax/swing/plaf/basic/BasicButtonUI.java
index 0a537c4bd..d531133ba 100644
--- a/javax/swing/plaf/basic/BasicButtonUI.java
+++ b/javax/swing/plaf/basic/BasicButtonUI.java
@@ -442,13 +442,17 @@ public class BasicButtonUI extends ButtonUI
if (b.isEnabled())
{
g.setColor(b.getForeground());
- g.drawString(text, textRect.x, textRect.y + fm.getAscent());
+ // FIXME: Underline mnemonic.
+ BasicGraphicsUtils.drawString(b, g, text, -1, textRect.x,
+ textRect.y + fm.getAscent());
}
else
{
String prefix = getPropertyPrefix();
g.setColor(UIManager.getColor(prefix + "disabledText"));
- g.drawString(text, textRect.x, textRect.y + fm.getAscent());
+ // FIXME: Underline mnemonic.
+ BasicGraphicsUtils.drawString(b, g, text, -1, textRect.x,
+ textRect.y + fm.getAscent());
}
}
}
diff --git a/javax/swing/plaf/basic/BasicGraphicsUtils.java b/javax/swing/plaf/basic/BasicGraphicsUtils.java
index 068de345b..1e84be932 100644
--- a/javax/swing/plaf/basic/BasicGraphicsUtils.java
+++ b/javax/swing/plaf/basic/BasicGraphicsUtils.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package javax.swing.plaf.basic;
+import gnu.classpath.SystemProperties;
+
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
@@ -65,6 +67,14 @@ import javax.swing.SwingUtilities;
public class BasicGraphicsUtils
{
/**
+ * Used as a key for a client property to store cached TextLayouts in. This
+ * is used for speed-up drawing of text in
+ * {@link #drawString(Graphics, String, int, int, int)}.
+ */
+ static final String CACHED_TEXT_LAYOUT =
+ "BasicGraphicsUtils.cachedTextLayout";
+
+ /**
* Constructor. It is utterly unclear why this class should
* be constructable, but this is what the API specification
* says.
@@ -536,6 +546,170 @@ public class BasicGraphicsUtils
g2.fill(underline);
}
+ /**
+ * Draws a string on the specified component.
+ *
+ * @param c the component
+ * @param g the Graphics context
+ * @param text the string
+ * @param underlinedChar the character to be underlined
+ * @param x the X location
+ * @param y the Y location
+ */
+ static void drawString(JComponent c, Graphics g, String text,
+ int underlinedChar, int x, int y)
+ {
+ int index = -1;
+
+ /* It is intentional that lower case is used. In some languages,
+ * the set of lowercase characters is larger than the set of
+ * uppercase ones. Therefore, it is good practice to use lowercase
+ * for such comparisons (which really means that the author of this
+ * code can vaguely remember having read some Unicode techreport
+ * with this recommendation, but is too lazy to look for the URL).
+ */
+ if ((underlinedChar >= 0) || (underlinedChar <= 0xffff))
+ index = text.toLowerCase().indexOf(
+ Character.toLowerCase((char) underlinedChar));
+
+ drawStringUnderlineCharAt(c, g, text, index, x, y);
+ }
+
+
+ /**
+ * Draws a String at the given location, underlining the character
+ * at the specified index. Drawing is performed in the current color
+ * and font of <code>g</code>.
+ *
+ * <p><img src="doc-files/BasicGraphicsUtils-5.png" width="500"
+ * height="100" alt="[An illustration showing how to use the
+ * method]" />
+ *
+ * This is an accelerated version of the method with the same name. It
+ * uses a pre-laid out TextLayout stored in a client property.
+ *
+ * @param c the component that is drawn
+ * @param g the graphics into which the String is drawn.
+ *
+ * @param text the String to draw.
+ *
+ * @param underlinedIndex the index of the underlined character in
+ * <code>text</code>. If <code>underlinedIndex</code> falls
+ * outside the range <code>[0, text.length() - 1]</code>, the
+ * text will be drawn without underlining anything.
+ *
+ * @param x the x coordinate of the text, as it would be passed to
+ * {@link java.awt.Graphics#drawString(java.lang.String,
+ * int, int)}.
+ *
+ * @param y the y coordinate of the text, as it would be passed to
+ * {@link java.awt.Graphics#drawString(java.lang.String,
+ * int, int)}.
+ */
+ static void drawStringUnderlineCharAt(JComponent c, Graphics g, String text,
+ int underlinedIndex,
+ int x, int y)
+ {
+ Graphics2D g2;
+ Rectangle2D.Double underline;
+ FontRenderContext frc;
+ FontMetrics fmet;
+ LineMetrics lineMetrics;
+ Font font;
+ TextLayout layout;
+ double underlineX1, underlineX2;
+ boolean drawUnderline;
+ int textLength;
+
+ textLength = text.length();
+ if (textLength == 0)
+ return;
+
+ drawUnderline = (underlinedIndex >= 0) && (underlinedIndex < textLength);
+
+ // FIXME: unfortunately pango and cairo can't agree on metrics
+ // so for the time being we continue to *not* use TextLayouts.
+ if (!(g instanceof Graphics2D)
+ || SystemProperties.getProperty("gnu.javax.swing.noGraphics2D") != null)
+ {
+ /* Fall-back. This is likely to produce garbage for any text
+ * containing right-to-left (Hebrew or Arabic) characters, even
+ * if the underlined character is left-to-right.
+ */
+ g.drawString(text, x, y);
+ if (drawUnderline)
+ {
+ fmet = g.getFontMetrics();
+ g.fillRect(
+ /* x */ x + fmet.stringWidth(text.substring(0, underlinedIndex)),
+ /* y */ y + fmet.getDescent() - 1,
+ /* width */ fmet.charWidth(text.charAt(underlinedIndex)),
+ /* height */ 1);
+ }
+
+ return;
+ }
+
+ g2 = (Graphics2D) g;
+ font = g2.getFont();
+ frc = g2.getFontRenderContext();
+ lineMetrics = font.getLineMetrics(text, frc);
+ layout = (TextLayout) c.getClientProperty(CACHED_TEXT_LAYOUT);
+ if (layout == null)
+ {
+ layout = new TextLayout(text, font, frc);
+ System.err.println("Unable to use cached TextLayout for: " + text);
+ }
+
+ /* Draw the text. */
+ layout.draw(g2, x, y);
+ if (!drawUnderline)
+ return;
+
+ underlineX1 = x + layout.getLogicalHighlightShape(
+ underlinedIndex, underlinedIndex).getBounds2D().getX();
+ underlineX2 = x + layout.getLogicalHighlightShape(
+ underlinedIndex + 1, underlinedIndex + 1).getBounds2D().getX();
+
+ underline = new Rectangle2D.Double();
+ if (underlineX1 < underlineX2)
+ {
+ underline.x = underlineX1;
+ underline.width = underlineX2 - underlineX1;
+ }
+ else
+ {
+ underline.x = underlineX2;
+ underline.width = underlineX1 - underlineX2;
+ }
+
+
+ underline.height = lineMetrics.getUnderlineThickness();
+ underline.y = lineMetrics.getUnderlineOffset();
+ if (underline.y == 0)
+ {
+ /* Some fonts do not specify an underline offset, although they
+ * actually should do so. In that case, the result of calling
+ * lineMetrics.getUnderlineOffset() will be zero. Since it would
+ * look very ugly if the underline was be positioned immediately
+ * below the baseline, we check for this and move the underline
+ * below the descent, as shown in the following ASCII picture:
+ *
+ * ##### ##### #
+ * # # # #
+ * # # # #
+ * # # # #
+ * ##### ###### ---- baseline (0)
+ * #
+ * #
+ * ------------------###----------- lineMetrics.getDescent()
+ */
+ underline.y = lineMetrics.getDescent();
+ }
+
+ underline.y += y;
+ g2.fill(underline);
+ }
/**
* Draws a rectangle, simulating a dotted stroke by painting only
diff --git a/javax/swing/plaf/basic/BasicInternalFrameUI.java b/javax/swing/plaf/basic/BasicInternalFrameUI.java
index 23bcdc315..bfd97b913 100644
--- a/javax/swing/plaf/basic/BasicInternalFrameUI.java
+++ b/javax/swing/plaf/basic/BasicInternalFrameUI.java
@@ -945,41 +945,54 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public void propertyChange(PropertyChangeEvent evt)
{
- if (evt.getPropertyName().equals(JInternalFrame.IS_MAXIMUM_PROPERTY))
+ String property = evt.getPropertyName();
+ if (property.equals(JInternalFrame.IS_MAXIMUM_PROPERTY))
{
if (frame.isMaximum())
maximizeFrame(frame);
else
minimizeFrame(frame);
}
- else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY))
+ else if (property.equals(JInternalFrame.IS_ICON_PROPERTY))
{
if (frame.isIcon())
iconifyFrame(frame);
else
deiconifyFrame(frame);
}
- else if (evt.getPropertyName().equals(JInternalFrame.IS_SELECTED_PROPERTY))
+ else if (property.equals(JInternalFrame.IS_SELECTED_PROPERTY))
{
if (frame.isSelected())
activateFrame(frame);
else
deactivateFrame(frame);
}
- else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY)
- || evt.getPropertyName().equals(
- JInternalFrame.GLASS_PANE_PROPERTY))
+ else if (property.equals(JInternalFrame.ROOT_PANE_PROPERTY)
+ || property.equals(JInternalFrame.GLASS_PANE_PROPERTY))
{
Component old = (Component) evt.getOldValue();
- old.removeMouseListener(glassPaneDispatcher);
- old.removeMouseMotionListener(glassPaneDispatcher);
+ if (old != null)
+ {
+ old.removeMouseListener(glassPaneDispatcher);
+ old.removeMouseMotionListener(glassPaneDispatcher);
+ }
Component newPane = (Component) evt.getNewValue();
- newPane.addMouseListener(glassPaneDispatcher);
- newPane.addMouseMotionListener(glassPaneDispatcher);
+ if (newPane != null)
+ {
+ newPane.addMouseListener(glassPaneDispatcher);
+ newPane.addMouseMotionListener(glassPaneDispatcher);
+ }
frame.revalidate();
}
+ else if (property.equals(JInternalFrame.IS_CLOSED_PROPERTY))
+ {
+ if (evt.getNewValue() == Boolean.TRUE)
+ {
+ closeFrame(frame);
+ }
+ }
/*
* FIXME: need to add ancestor properties to JComponents. else if
* (evt.getPropertyName().equals(JComponent.ANCESTOR_PROPERTY)) { if
diff --git a/javax/swing/plaf/basic/BasicLabelUI.java b/javax/swing/plaf/basic/BasicLabelUI.java
index 60e3a9868..304e13ad7 100644
--- a/javax/swing/plaf/basic/BasicLabelUI.java
+++ b/javax/swing/plaf/basic/BasicLabelUI.java
@@ -1,5 +1,5 @@
/* BasicLabelUI.java
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,20 +37,25 @@
package javax.swing.plaf.basic;
-import gnu.classpath.NotImplementedException;
-
import java.awt.Color;
+import java.awt.Component;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import javax.swing.AbstractAction;
+import javax.swing.ActionMap;
import javax.swing.Icon;
+import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JLabel;
+import javax.swing.KeyStroke;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.plaf.ComponentUI;
@@ -369,14 +374,39 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
}
/**
- * This method installs the keyboard actions for the given {@link JLabel}.
+ * Installs the keyboard actions for the given {@link JLabel}.
*
* @param l The {@link JLabel} to install keyboard actions for.
*/
protected void installKeyboardActions(JLabel l)
- throws NotImplementedException
{
- //FIXME: implement.
+ Component c = l.getLabelFor();
+ if (c != null)
+ {
+ int mnemonic = l.getDisplayedMnemonic();
+ if (mnemonic > 0)
+ {
+ // add a keystroke for the given mnemonic mapping to 'press';
+ InputMap keyMap = new InputMap();
+ keyMap.put(KeyStroke.getKeyStroke(mnemonic, KeyEvent.VK_ALT),
+ "press");
+ SwingUtilities.replaceUIInputMap(l,
+ JComponent.WHEN_IN_FOCUSED_WINDOW, keyMap);
+
+ // add an action to focus the component when 'press' happens
+ ActionMap map = new ActionMap();
+ map.put("press", new AbstractAction() {
+ public void actionPerformed(ActionEvent event)
+ {
+ JLabel label = (JLabel) event.getSource();
+ Component c = label.getLabelFor();
+ if (c != null)
+ c.requestFocus();
+ }
+ });
+ SwingUtilities.replaceUIActionMap(l, map);
+ }
+ }
}
/**
@@ -385,9 +415,10 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
* @param l The {@link JLabel} to uninstall keyboard actions for.
*/
protected void uninstallKeyboardActions(JLabel l)
- throws NotImplementedException
{
- //FIXME: implement.
+ SwingUtilities.replaceUIActionMap(l, null);
+ SwingUtilities.replaceUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW,
+ null);
}
/**
@@ -426,5 +457,30 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
JLabel l = (JLabel) e.getSource();
BasicHTML.updateRenderer(l, text);
}
+ else if (e.getPropertyName().equals("displayedMnemonic"))
+ {
+ // update the key to action mapping
+ JLabel label = (JLabel) e.getSource();
+ if (label.getLabelFor() != null)
+ {
+ int oldMnemonic = ((Integer) e.getOldValue()).intValue();
+ int newMnemonic = ((Integer) e.getNewValue()).intValue();
+ InputMap keyMap = label.getInputMap(
+ JComponent.WHEN_IN_FOCUSED_WINDOW);
+ keyMap.put(KeyStroke.getKeyStroke(oldMnemonic,
+ KeyEvent.ALT_DOWN_MASK), null);
+ keyMap.put(KeyStroke.getKeyStroke(newMnemonic,
+ KeyEvent.ALT_DOWN_MASK), "press");
+ }
+ }
+ else if (e.getPropertyName().equals("labelFor"))
+ {
+ JLabel label = (JLabel) e.getSource();
+ InputMap keyMap = label.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
+ int mnemonic = label.getDisplayedMnemonic();
+ if (mnemonic > 0)
+ keyMap.put(KeyStroke.getKeyStroke(mnemonic, KeyEvent.ALT_DOWN_MASK),
+ "press");
+ }
}
}
diff --git a/javax/swing/plaf/basic/BasicListUI.java b/javax/swing/plaf/basic/BasicListUI.java
index a47d116c4..378792d74 100644
--- a/javax/swing/plaf/basic/BasicListUI.java
+++ b/javax/swing/plaf/basic/BasicListUI.java
@@ -38,8 +38,6 @@ exception statement from your version. */
package javax.swing.plaf.basic;
-import gnu.classpath.NotImplementedException;
-
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
@@ -61,12 +59,12 @@ import javax.swing.DefaultListSelectionModel;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JList;
-import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
+import javax.swing.TransferHandler;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.ListDataEvent;
@@ -76,8 +74,8 @@ import javax.swing.event.ListSelectionListener;
import javax.swing.event.MouseInputListener;
import javax.swing.plaf.ActionMapUIResource;
import javax.swing.plaf.ComponentUI;
-import javax.swing.plaf.InputMapUIResource;
import javax.swing.plaf.ListUI;
+import javax.swing.plaf.UIResource;
/**
* The Basic Look and Feel UI delegate for the
@@ -215,9 +213,26 @@ public class BasicListUI extends ListUI
target.actionPerformed(derivedEvent);
}
}
-
- class ListAction extends AbstractAction
+
+ /**
+ * Implements the action for the JList's keyboard commands.
+ */
+ private class ListAction
+ extends AbstractAction
{
+ // TODO: Maybe make a couple of classes out of this bulk Action.
+ // Form logical groups of Actions when doing this.
+
+ /**
+ * Creates a new ListAction for the specified command.
+ *
+ * @param cmd the actionCommand to set
+ */
+ ListAction(String cmd)
+ {
+ putValue(ACTION_COMMAND_KEY, cmd);
+ }
+
public void actionPerformed(ActionEvent e)
{
int lead = list.getLeadSelectionIndex();
@@ -398,7 +413,7 @@ public class BasicListUI extends ListUI
list.ensureIndexIsVisible(list.getLeadSelectionIndex());
}
}
-
+
/**
* A helper class which listens for {@link MouseEvent}s
* from the {@link JList}.
@@ -992,39 +1007,83 @@ public class BasicListUI extends ListUI
*/
protected void installKeyboardActions()
{
+ // Install UI InputMap.
InputMap focusInputMap = (InputMap) UIManager.get("List.focusInputMap");
- InputMapUIResource parentInputMap = new InputMapUIResource();
- // FIXME: The JDK uses a LazyActionMap for parentActionMap
- ActionMap parentActionMap = new ActionMapUIResource();
- action = new ListAction();
- Object keys[] = focusInputMap.allKeys();
- // Register key bindings in the UI InputMap-ActionMap pair
- for (int i = 0; i < keys.length; i++)
+ SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED,
+ focusInputMap);
+
+ // Install UI ActionMap.
+ ActionMap am = (ActionMap) UIManager.get("List.actionMap");
+ if (am == null)
{
- KeyStroke stroke = (KeyStroke) keys[i];
- String actionString = (String) focusInputMap.get(stroke);
- parentInputMap.put(KeyStroke.getKeyStroke(stroke.getKeyCode(),
- stroke.getModifiers()),
- actionString);
-
- parentActionMap.put(actionString,
- new ActionListenerProxy(action, actionString));
+ // Create the actionMap once and store it in the current UIDefaults
+ // for use in other components.
+ am = new ActionMapUIResource();
+ ListAction action;
+ action = new ListAction("selectPreviousRow");
+ am.put("selectPreviousRow", action);
+ action = new ListAction("selectNextRow");
+ am.put("selectNextRow", action);
+ action = new ListAction("selectPreviousRowExtendSelection");
+ am.put("selectPreviousRowExtendSelection", action);
+ action = new ListAction("selectNextRowExtendSelection");
+ am.put("selectNextRowExtendSelection", action);
+
+ action = new ListAction("selectPreviousColumn");
+ am.put("selectPreviousColumn", action);
+ action = new ListAction("selectNextColumn");
+ am.put("selectNextColumn", action);
+ action = new ListAction("selectPreviousColumnExtendSelection");
+ am.put("selectPreviousColumnExtendSelection", action);
+ action = new ListAction("selectNextColumnExtendSelection");
+ am.put("selectNextColumnExtendSelection", action);
+
+ action = new ListAction("selectFirstRow");
+ am.put("selectFirstRow", action);
+ action = new ListAction("selectLastRow");
+ am.put("selectLastRow", action);
+ action = new ListAction("selectFirstRowExtendSelection");
+ am.put("selectFirstRowExtendSelection", action);
+ action = new ListAction("selectLastRowExtendSelection");
+ am.put("selectLastRowExtendSelection", action);
+
+ action = new ListAction("scrollUp");
+ am.put("scrollUp", action);
+ action = new ListAction("scrollUpExtendSelection");
+ am.put("scrollUpExtendSelection", action);
+ action = new ListAction("scrollDown");
+ am.put("scrollDown", action);
+ action = new ListAction("scrollDownExtendSelection");
+ am.put("scrollDownExtendSelection", action);
+
+ action = new ListAction("selectAll");
+ am.put("selectAll", action);
+ action = new ListAction("clearSelection");
+ am.put("clearSelection", action);
+
+ am.put("copy", TransferHandler.getCopyAction());
+ am.put("cut", TransferHandler.getCutAction());
+ am.put("paste", TransferHandler.getPasteAction());
+
+ UIManager.put("List.actionMap", am);
}
- // Register the new InputMap-ActionMap as the parents of the list's
- // InputMap and ActionMap
- parentInputMap.setParent(list.getInputMap().getParent());
- parentActionMap.setParent(list.getActionMap().getParent());
- list.getInputMap().setParent(parentInputMap);
- list.getActionMap().setParent(parentActionMap);
+
+ SwingUtilities.replaceUIActionMap(list, am);
}
/**
* Uninstalls keyboard actions for this UI in the {@link JList}.
*/
protected void uninstallKeyboardActions()
- throws NotImplementedException
{
- // TODO: Implement this properly.
+ // Uninstall the InputMap.
+ InputMap im = SwingUtilities.getUIInputMap(list, JComponent.WHEN_FOCUSED);
+ if (im instanceof UIResource)
+ SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED, null);
+
+ // Uninstall the ActionMap.
+ if (SwingUtilities.getUIActionMap(list) instanceof UIResource)
+ SwingUtilities.replaceUIActionMap(list, null);
}
/**
diff --git a/javax/swing/plaf/basic/BasicMenuItemUI.java b/javax/swing/plaf/basic/BasicMenuItemUI.java
index 63a09bff6..c5ed2ff7e 100644
--- a/javax/swing/plaf/basic/BasicMenuItemUI.java
+++ b/javax/swing/plaf/basic/BasicMenuItemUI.java
@@ -52,11 +52,15 @@ import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
+import java.awt.font.FontRenderContext;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
import javax.swing.ActionMap;
import javax.swing.ButtonModel;
import javax.swing.Icon;
@@ -237,7 +241,8 @@ public class BasicMenuItemUI extends MenuItemUI
*/
public void propertyChange(PropertyChangeEvent e)
{
- if (e.getPropertyName() == "accelerator")
+ String property = e.getPropertyName();
+ if (property.equals("accelerator"))
{
InputMap map = SwingUtilities.getUIInputMap(menuItem,
JComponent.WHEN_IN_FOCUSED_WINDOW);
@@ -250,6 +255,19 @@ public class BasicMenuItemUI extends MenuItemUI
if (accelerator != null)
map.put(accelerator, "doClick");
}
+ // TextLayout caching for speed-up drawing of text.
+ else if (property.equals(AbstractButton.TEXT_CHANGED_PROPERTY)
+ || property.equals("font"))
+ {
+ AbstractButton b = (AbstractButton) e.getSource();
+ String text = b.getText();
+ if (text == null)
+ text = "";
+ FontRenderContext frc = new FontRenderContext(new AffineTransform(),
+ false, false);
+ TextLayout layout = new TextLayout(text, b.getFont(), frc);
+ b.putClientProperty(BasicGraphicsUtils.CACHED_TEXT_LAYOUT, layout);
+ }
}
}
@@ -833,12 +851,13 @@ public class BasicMenuItemUI extends MenuItemUI
int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
if (mnemonicIndex != -1)
- BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,
+ BasicGraphicsUtils.drawStringUnderlineCharAt(menuItem, g, text,
+ mnemonicIndex,
textRect.x,
textRect.y
+ fm.getAscent());
else
- BasicGraphicsUtils.drawString(g, text, 0, textRect.x,
+ BasicGraphicsUtils.drawString(menuItem, g, text, 0, textRect.x,
textRect.y + fm.getAscent());
}
}
diff --git a/javax/swing/plaf/basic/BasicMenuUI.java b/javax/swing/plaf/basic/BasicMenuUI.java
index f8936be5b..1473b5912 100644
--- a/javax/swing/plaf/basic/BasicMenuUI.java
+++ b/javax/swing/plaf/basic/BasicMenuUI.java
@@ -230,10 +230,8 @@ public class BasicMenuUI extends BasicMenuItemUI
*/
protected void installListeners()
{
- ((JMenu) menuItem).addMouseListener(mouseInputListener);
- ((JMenu) menuItem).addMouseMotionListener(mouseInputListener);
+ super.installListeners();
((JMenu) menuItem).addMenuListener(menuListener);
- ((JMenu) menuItem).addMenuDragMouseListener(menuDragMouseListener);
}
protected void setupPostTimer(JMenu menu)
@@ -276,9 +274,8 @@ public class BasicMenuUI extends BasicMenuItemUI
*/
protected void uninstallListeners()
{
- ((JMenu) menuItem).removeMouseListener(mouseInputListener);
+ super.uninstallListeners();
((JMenu) menuItem).removeMenuListener(menuListener);
- ((JMenu) menuItem).removePropertyChangeListener(propertyChangeListener);
}
/**
diff --git a/javax/swing/plaf/basic/BasicPopupMenuUI.java b/javax/swing/plaf/basic/BasicPopupMenuUI.java
index a26a5c7c4..5ceaecb91 100644
--- a/javax/swing/plaf/basic/BasicPopupMenuUI.java
+++ b/javax/swing/plaf/basic/BasicPopupMenuUI.java
@@ -278,9 +278,10 @@ public class BasicPopupMenuUI extends PopupMenuUI
// Adds topWindowListener to top-level window to listener to
// ComponentEvents fired by it. We need to cancel this popup menu
// if topWindow to which this popup belongs was resized or moved.
- Component invoker = popupMenu.getInvoker();
+ Component invoker = popupMenu.getInvoker();
Component rootContainer = SwingUtilities.getRoot(invoker);
- rootContainer.addComponentListener(topWindowListener);
+ if (rootContainer != null)
+ rootContainer.addComponentListener(topWindowListener);
// if this popup menu is a free floating popup menu,
// then by default its first element should be always selected when
diff --git a/javax/swing/plaf/basic/BasicTextFieldUI.java b/javax/swing/plaf/basic/BasicTextFieldUI.java
index 89c4e5a75..6792aa065 100644
--- a/javax/swing/plaf/basic/BasicTextFieldUI.java
+++ b/javax/swing/plaf/basic/BasicTextFieldUI.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package javax.swing.plaf.basic;
+import java.awt.Color;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent;
@@ -94,12 +95,24 @@ public class BasicTextFieldUI extends BasicTextUI
{
if (event.getPropertyName().equals("editable"))
{
- boolean editable = ((Boolean) event.getNewValue()).booleanValue();
-
// Changing the color only if the current background is an instance of
// ColorUIResource is the behavior of the RI.
if (textComponent.getBackground() instanceof ColorUIResource)
- textComponent.setBackground(editable ? background : inactiveBackground);
+ {
+ Color c = null;
+ Color old = textComponent.getBackground();
+ String prefix = getPropertyPrefix();
+ if (! textComponent.isEnabled())
+ c = SharedUIDefaults.getColor(prefix + ".disabledBackground");
+ if (c == null && ! textComponent.isEditable())
+ c = SharedUIDefaults.getColor(prefix + ".inactiveBackground");
+ if (c == null)
+ c = SharedUIDefaults.getColor(prefix + ".background");
+ if (c != null && c != old)
+ {
+ textComponent.setBackground(c);
+ }
+ }
}
}
}
diff --git a/javax/swing/plaf/basic/BasicTextUI.java b/javax/swing/plaf/basic/BasicTextUI.java
index 34261cfe6..5febe141d 100644
--- a/javax/swing/plaf/basic/BasicTextUI.java
+++ b/javax/swing/plaf/basic/BasicTextUI.java
@@ -418,7 +418,19 @@ public abstract class BasicTextUI extends TextUI
if (event.getPropertyName().equals("document"))
{
// Document changed.
- modelChanged();
+ Object oldValue = event.getOldValue();
+ if (oldValue != null)
+ {
+ Document oldDoc = (Document) oldValue;
+ oldDoc.removeDocumentListener(documentHandler);
+ }
+ Object newValue = event.getNewValue();
+ if (newValue != null)
+ {
+ Document newDoc = (Document) newValue;
+ newDoc.addDocumentListener(documentHandler);
+ }
+ modelChanged();
}
BasicTextUI.this.propertyChange(event);
@@ -501,18 +513,6 @@ public abstract class BasicTextUI extends TextUI
DocumentHandler documentHandler = new DocumentHandler();
/**
- * The standard background color. This is the color which is used to paint
- * text in enabled text components.
- */
- Color background;
-
- /**
- * The inactive background color. This is the color which is used to paint
- * text in disabled text components.
- */
- Color inactiveBackground;
-
- /**
* Creates a new <code>BasicTextUI</code> instance.
*/
public BasicTextUI()
@@ -558,22 +558,23 @@ public abstract class BasicTextUI extends TextUI
*/
public void installUI(final JComponent c)
{
- super.installUI(c);
-
textComponent = (JTextComponent) c;
+ installDefaults();
+ textComponent.addPropertyChangeListener(updateHandler);
Document doc = textComponent.getDocument();
if (doc == null)
{
doc = getEditorKit(textComponent).createDefaultDocument();
textComponent.setDocument(doc);
}
- installDefaults();
+ else
+ {
+ doc.addDocumentListener(documentHandler);
+ modelChanged();
+ }
+
installListeners();
installKeyboardActions();
-
- // We need to trigger this so that the view hierarchy gets initialized.
- modelChanged();
-
}
/**
@@ -581,34 +582,60 @@ public abstract class BasicTextUI extends TextUI
*/
protected void installDefaults()
{
+ String prefix = getPropertyPrefix();
+ // Install the standard properties.
+ LookAndFeel.installColorsAndFont(textComponent, prefix + ".background",
+ prefix + ".foreground", prefix + ".font");
+ LookAndFeel.installBorder(textComponent, prefix + ".border");
+ textComponent.setMargin(UIManager.getInsets(prefix + ".margin"));
+
+ // Some additional text component only properties.
+ Color color = textComponent.getCaretColor();
+ if (color == null || color instanceof UIResource)
+ {
+ color = UIManager.getColor(prefix + ".caretForeground");
+ textComponent.setCaretColor(color);
+ }
+
+ // Fetch the colors for enabled/disabled text components.
+ color = textComponent.getDisabledTextColor();
+ if (color == null || color instanceof UIResource)
+ {
+ color = UIManager.getColor(prefix + ".inactiveBackground");
+ textComponent.setDisabledTextColor(color);
+ }
+ color = textComponent.getSelectedTextColor();
+ if (color == null || color instanceof UIResource)
+ {
+ color = UIManager.getColor(prefix + ".selectionForeground");
+ textComponent.setSelectedTextColor(color);
+ }
+ color = textComponent.getSelectionColor();
+ if (color == null || color instanceof UIResource)
+ {
+ color = UIManager.getColor(prefix + ".selectionBackground");
+ textComponent.setSelectionColor(color);
+ }
+
+ Insets margin = textComponent.getMargin();
+ if (margin == null || margin instanceof UIResource)
+ {
+ margin = UIManager.getInsets(prefix + ".margin");
+ textComponent.setMargin(margin);
+ }
+
Caret caret = textComponent.getCaret();
- if (caret == null)
+ if (caret == null || caret instanceof UIResource)
{
caret = createCaret();
textComponent.setCaret(caret);
+ caret.setBlinkRate(UIManager.getInt(prefix + ".caretBlinkRate"));
}
Highlighter highlighter = textComponent.getHighlighter();
- if (highlighter == null)
+ if (highlighter == null || highlighter instanceof UIResource)
textComponent.setHighlighter(createHighlighter());
- String prefix = getPropertyPrefix();
- LookAndFeel.installColorsAndFont(textComponent, prefix + ".background",
- prefix + ".foreground", prefix + ".font");
- LookAndFeel.installBorder(textComponent, prefix + ".border");
- textComponent.setMargin(UIManager.getInsets(prefix + ".margin"));
-
- caret.setBlinkRate(UIManager.getInt(prefix + ".caretBlinkRate"));
-
- // Fetch the colors for enabled/disabled text components.
- background = UIManager.getColor(prefix + ".background");
- inactiveBackground = UIManager.getColor(prefix + ".inactiveBackground");
- textComponent.setDisabledTextColor(UIManager.getColor(prefix
- + ".inactiveForeground"));
- textComponent.setSelectedTextColor(UIManager.getColor(prefix
- + ".selectionForeground"));
- textComponent.setSelectionColor(UIManager.getColor(prefix
- + ".selectionBackground"));
}
/**
@@ -670,18 +697,6 @@ public abstract class BasicTextUI extends TextUI
protected void installListeners()
{
textComponent.addFocusListener(focuslistener);
- textComponent.addPropertyChangeListener(updateHandler);
- installDocumentListeners();
- }
-
- /**
- * Installs the document listeners on the textComponent's model.
- */
- private void installDocumentListeners()
- {
- Document doc = textComponent.getDocument();
- if (doc != null)
- doc.addDocumentListener(documentHandler);
}
/**
@@ -845,9 +860,7 @@ public abstract class BasicTextUI extends TextUI
*/
protected void uninstallListeners()
{
- textComponent.removePropertyChangeListener(updateHandler);
textComponent.removeFocusListener(focuslistener);
- textComponent.getDocument().removeDocumentListener(documentHandler);
}
/**
@@ -1361,7 +1374,6 @@ public abstract class BasicTextUI extends TextUI
Document doc = textComponent.getDocument();
if (doc == null)
return;
- installDocumentListeners();
Element elem = doc.getDefaultRootElement();
if (elem == null)
return;
diff --git a/javax/swing/plaf/basic/SharedUIDefaults.java b/javax/swing/plaf/basic/SharedUIDefaults.java
index 478764911..34278052b 100644
--- a/javax/swing/plaf/basic/SharedUIDefaults.java
+++ b/javax/swing/plaf/basic/SharedUIDefaults.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package javax.swing.plaf.basic;
+import java.awt.Color;
import java.util.HashMap;
import javax.swing.UIManager;
@@ -75,4 +76,16 @@ public class SharedUIDefaults
}
return o;
}
+
+ /**
+ * Returns a shared UI color.
+ *
+ * @param key the key
+ *
+ * @return the shared color instance
+ */
+ static Color getColor(String key)
+ {
+ return (Color) get(key);
+ }
}
diff --git a/javax/swing/plaf/metal/MetalUtils.java b/javax/swing/plaf/metal/MetalUtils.java
index 72cbb34a6..a61b8ded2 100644
--- a/javax/swing/plaf/metal/MetalUtils.java
+++ b/javax/swing/plaf/metal/MetalUtils.java
@@ -41,6 +41,7 @@ import gnu.classpath.SystemProperties;
import java.awt.Color;
import java.awt.Component;
+import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.TexturePaint;
@@ -305,6 +306,15 @@ class MetalUtils
float g1, float g2, Color c1, Color c2,
Color c3, int[][] mask)
{
+
+ if (g instanceof Graphics2D
+ && SystemProperties.getProperty("gnu.javax.swing.noGraphics2D") == null)
+ {
+ paintHorizontalGradient2D((Graphics2D) g, x, y, w, h, g1, g2, c1, c2,
+ c3, mask);
+ return;
+ }
+
// Calculate the coordinates.
int y0 = y;
int y1 = y + h;
@@ -339,7 +349,7 @@ class MetalUtils
y0 = mask[xc - x0][0] + y;
y1 = mask[xc - x0][1] + y;
}
- g.drawLine(xc, y0, xc, y1);
+ g.fillRect(xc, y0, 1, y1 - y0);
}
// Paint solid c2 area.
g.setColor(c2);
@@ -353,7 +363,7 @@ class MetalUtils
{
y0 = mask[xc - x0][0] + y;
y1 = mask[xc - x0][1] + y;
- g.drawLine(xc, y0, xc, y1);
+ g.fillRect(xc, y0, 1, y1 - y0);
}
}
@@ -377,7 +387,7 @@ class MetalUtils
y0 = mask[xc - x0][0] + y;
y1 = mask[xc - x0][1] + y;
}
- g.drawLine(xc, y0, xc, y1);
+ g.fillRect(xc, y0, 1, y1 - y0);
}
// Paint third gradient area (c1->c3).
@@ -421,9 +431,17 @@ class MetalUtils
* described above
*/
static void paintVerticalGradient(Graphics g, int x, int y, int w, int h,
- double g1, double g2, Color c1, Color c2,
+ float g1, float g2, Color c1, Color c2,
Color c3, int[][] mask)
{
+ if (g instanceof Graphics2D
+ && SystemProperties.getProperty("gnu.javax.swing.noGraphics2D") == null)
+ {
+ paintVerticalGradient2D((Graphics2D) g, x, y, w, h, g1, g2, c1, c2,
+ c3, mask);
+ return;
+ }
+
// Calculate the coordinates.
int x0 = x;
int x1 = x + w;
@@ -458,7 +476,7 @@ class MetalUtils
x0 = mask[yc - y0][0] + x;
x1 = mask[yc - y0][1] + x;
}
- g.drawLine(x0, yc, x1, yc);
+ g.fillRect(x0, yc, x1 - x0, 1);
}
// Paint solid c2 area.
g.setColor(c2);
@@ -472,7 +490,7 @@ class MetalUtils
{
x0 = mask[yc - y0][0] + x;
x1 = mask[yc - y0][1] + x;
- g.drawLine(x0, yc, x1, yc);
+ g.fillRect(x0, yc, x1 - x0, 1);
}
}
@@ -496,7 +514,7 @@ class MetalUtils
x0 = mask[yc - y0][0] + x;
x1 = mask[yc - y0][1] + x;
}
- g.drawLine(x0, yc, x1, yc);
+ g.fillRect(x0, yc, x1 - x0, 1);
}
// Paint third gradient area (c1->c3).
@@ -519,7 +537,61 @@ class MetalUtils
x0 = mask[yc - y0][0] + x;
x1 = mask[yc - y0][1] + x;
}
- g.drawLine(x0, yc, x1, yc);
+ g.fillRect(x0, yc, x1 - x0, 1);
}
}
+
+ /**
+ * Paints a horizontal gradient using Graphics2D functionality.
+ *
+ * @param g the Graphics2D instance
+ * @param x the X coordinate of the upper left corner of the rectangle
+ * @param y the Y coordinate of the upper left corner of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @param g1 the relative width of the c1->c2 gradients
+ * @param g2 the relative width of the c2 solid area
+ * @param c1 the color 1
+ * @param c2 the color 2
+ * @param c3 the color 3
+ * @param mask the mask that should be used when painting the gradient as
+ * described above
+ */
+ private static void paintHorizontalGradient2D(Graphics2D g, int x, int y,
+ int w, int h, float g1,
+ float g2, Color c1,
+ Color c2, Color c3,
+ int[][] mask)
+ {
+ // FIXME: Handle the mask somehow, or do Graphics2D clipping instead.
+ GradientPaint p1 = new GradientPaint(x, y, c1, x + w * g1, y, c2);
+ g.setPaint(p1);
+ // This fills the first gradient and the solid area in one go.
+ g.fillRect(x, y, (int) (w * (g1 + g2)), h);
+
+ GradientPaint p2 = new GradientPaint(x + (w * (g1 + g2)), y, c2, x + w, y,
+ c3);
+ g.setPaint(p2);
+ g.fillRect((int) (x + (w * (g1 + g2))), y,
+ (int) (w * (1. - (g1 + g2))), h);
+ }
+
+ private static void paintVerticalGradient2D(Graphics2D g, int x, int y,
+ int w, int h, float g1,
+ float g2, Color c1,
+ Color c2, Color c3,
+ int[][] mask)
+ {
+ // FIXME: Handle the mask somehow, or do Graphics2D clipping instead.
+ GradientPaint p1 = new GradientPaint(x, y, c1, x, y + h * g1, c2);
+ g.setPaint(p1);
+ // This fills the first gradient and the solid area in one go.
+ g.fillRect(x, y, w, (int) (h * (g1 + g2)));
+
+ GradientPaint p2 = new GradientPaint(x, y + (h * (g1 + g2)), c2, x, y + h,
+ c3);
+ g.setPaint(p2);
+ g.fillRect(x, (int) (y + (h * (g1 + g2))), w,
+ (int) (h * (1. - (g1 + g2))));
+ }
}
diff --git a/javax/swing/text/AbstractDocument.java b/javax/swing/text/AbstractDocument.java
index 801a0cdb4..8b921c08e 100644
--- a/javax/swing/text/AbstractDocument.java
+++ b/javax/swing/text/AbstractDocument.java
@@ -185,6 +185,10 @@ public abstract class AbstractDocument implements Document, Serializable
{
content = doc;
context = ctx;
+
+ // FIXME: This is determined using a Mauve test. Make the document
+ // actually use this.
+ putProperty("i18n", Boolean.FALSE);
}
/** Returns the DocumentFilter.FilterBypass instance for this
@@ -739,10 +743,16 @@ public abstract class AbstractDocument implements Document, Serializable
void removeImpl(int offset, int length) throws BadLocationException
{
+ if (offset < 0 || offset > getLength())
+ throw new BadLocationException("Invalid remove position", offset);
+
+ if (offset + length > getLength())
+ throw new BadLocationException("Invalid remove length", offset);
+
// Prevent some unneccessary method invocation (observed in the RI).
- if (length <= 0)
+ if (length == 0)
return;
-
+
DefaultDocumentEvent event =
new DefaultDocumentEvent(offset, length,
DocumentEvent.EventType.REMOVE);
@@ -1674,8 +1684,15 @@ public abstract class AbstractDocument implements Document, Serializable
/** The serialization UID (compatible with JDK1.5). */
private static final long serialVersionUID = -6037216547466333183L;
- /** The child elements of this BranchElement. */
- private Element[] children = new Element[0];
+ /**
+ * The child elements of this BranchElement.
+ */
+ private Element[] children;;
+
+ /**
+ * The number of children in the branch element.
+ */
+ private int numChildren;
/**
* The cached startOffset value. This is used in the case when a
@@ -1700,6 +1717,8 @@ public abstract class AbstractDocument implements Document, Serializable
public BranchElement(Element parent, AttributeSet attributes)
{
super(parent, attributes);
+ children = new Element[1];
+ numChildren = 0;
startOffset = -1;
endOffset = -1;
}
@@ -1716,8 +1735,8 @@ public abstract class AbstractDocument implements Document, Serializable
Vector tmp = new Vector();
- for (int index = 0; index < children.length; ++index)
- tmp.add(children[index]);
+ for (int index = 0; index < numChildren; ++index)
+ tmp.add(children[index]);
return tmp.elements();
}
@@ -1743,8 +1762,8 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public Element getElement(int index)
{
- if (index < 0 || index >= children.length)
- return null;
+ if (index < 0 || index >= numChildren)
+ return null;
return children[index];
}
@@ -1756,7 +1775,7 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public int getElementCount()
{
- return children.length;
+ return numChildren;
}
/**
@@ -1777,7 +1796,7 @@ public abstract class AbstractDocument implements Document, Serializable
// XXX: There is surely a better algorithm
// as beginning from first element each time.
- for (int index = 0; index < children.length - 1; ++index)
+ for (int index = 0; index < numChildren - 1; ++index)
{
Element elem = children[index];
@@ -1814,13 +1833,13 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public int getEndOffset()
{
- if (children.length == 0)
+ if (numChildren == 0)
{
if (endOffset == -1)
throw new NullPointerException("BranchElement has no children.");
}
else
- endOffset = children[children.length - 1].getEndOffset();
+ endOffset = children[numChildren - 1].getEndOffset();
return endOffset;
}
@@ -1848,7 +1867,7 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public int getStartOffset()
{
- if (children.length == 0)
+ if (numChildren == 0)
{
if (startOffset == -1)
throw new NullPointerException("BranchElement has no children.");
@@ -1884,7 +1903,7 @@ public abstract class AbstractDocument implements Document, Serializable
{
// XXX: There is surely a better algorithm
// as beginning from first element each time.
- for (int index = 0; index < children.length; ++index)
+ for (int index = 0; index < numChildren; ++index)
{
Element elem = children[index];
@@ -1905,14 +1924,27 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public void replace(int offset, int length, Element[] elements)
{
- Element[] target = new Element[children.length - length
- + elements.length];
- System.arraycopy(children, 0, target, 0, offset);
- System.arraycopy(elements, 0, target, offset, elements.length);
- System.arraycopy(children, offset + length, target,
- offset + elements.length,
- children.length - offset - length);
- children = target;
+ if (numChildren + elements.length - length > children.length)
+ {
+ // Gotta grow the array.
+ int newSize = Math.max(2 * children.length,
+ numChildren + elements.length - length);
+ Element[] target = new Element[newSize];
+ System.arraycopy(children, 0, target, 0, offset);
+ System.arraycopy(elements, 0, target, offset, elements.length);
+ System.arraycopy(children, offset + length, target,
+ offset + elements.length,
+ numChildren - offset - length);
+ children = target;
+ }
+ else
+ {
+ System.arraycopy(children, offset + length, children,
+ offset + elements.length,
+ numChildren - offset - length);
+ System.arraycopy(elements, 0, children, offset, elements.length);
+ }
+ numChildren += elements.length - length;
}
/**
@@ -2165,18 +2197,6 @@ public abstract class AbstractDocument implements Document, Serializable
private Position endPos;
/**
- * This gets possible added to the startOffset when a startOffset
- * outside the document range is requested.
- */
- private int startDelta;
-
- /**
- * This gets possible added to the endOffset when a endOffset
- * outside the document range is requested.
- */
- private int endDelta;
-
- /**
* Creates a new <code>LeafElement</code>.
*
* @param parent the parent of this <code>LeafElement</code>
@@ -2188,28 +2208,21 @@ public abstract class AbstractDocument implements Document, Serializable
int end)
{
super(parent, attributes);
- int len = content.length();
- startDelta = 0;
- if (start > len)
- startDelta = start - len;
- endDelta = 0;
- if (end > len)
- endDelta = end - len;
try
- {
- startPos = createPosition(start - startDelta);
- endPos = createPosition(end - endDelta);
- }
- catch (BadLocationException ex)
- {
- AssertionError as;
- as = new AssertionError("BadLocationException thrown "
- + "here. start=" + start
- + ", end=" + end
- + ", length=" + getLength());
- as.initCause(ex);
- throw as;
- }
+ {
+ startPos = createPosition(start);
+ endPos = createPosition(end);
+ }
+ catch (BadLocationException ex)
+ {
+ AssertionError as;
+ as = new AssertionError("BadLocationException thrown "
+ + "here. start=" + start
+ + ", end=" + end
+ + ", length=" + getLength());
+ as.initCause(ex);
+ throw as;
+ }
}
/**
@@ -2281,7 +2294,7 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public int getEndOffset()
{
- return endPos.getOffset() + endDelta;
+ return endPos.getOffset();
}
/**
@@ -2307,7 +2320,7 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public int getStartOffset()
{
- return startPos.getOffset() + startDelta;
+ return startPos.getOffset();
}
/**
diff --git a/javax/swing/text/DefaultCaret.java b/javax/swing/text/DefaultCaret.java
index ce93cf56e..e61e04f5d 100644
--- a/javax/swing/text/DefaultCaret.java
+++ b/javax/swing/text/DefaultCaret.java
@@ -221,9 +221,12 @@ public class DefaultCaret extends Rectangle
if (name.equals("document"))
{
Document oldDoc = (Document) e.getOldValue();
- oldDoc.removeDocumentListener(documentListener);
+ if (oldDoc != null)
+ oldDoc.removeDocumentListener(documentListener);
+
Document newDoc = (Document) e.getNewValue();
- newDoc.addDocumentListener(documentListener);
+ if (newDoc != null)
+ newDoc.addDocumentListener(documentListener);
}
else if (name.equals("editable"))
{
@@ -708,7 +711,11 @@ public class DefaultCaret extends Rectangle
propertyChangeListener = new PropertyChangeHandler();
textComponent.addPropertyChangeListener(propertyChangeListener);
documentListener = new DocumentHandler();
- textComponent.getDocument().addDocumentListener(documentListener);
+
+ Document doc = textComponent.getDocument();
+ if (doc != null)
+ doc.addDocumentListener(documentListener);
+
active = textComponent.isEditable() && textComponent.isEnabled();
repaint();
@@ -1140,6 +1147,24 @@ public class DefaultCaret extends Rectangle
}
/**
+ * Returns <code>true</code> if this <code>Caret</code> is blinking,
+ * and <code>false</code> if not. The returned value is independent of
+ * the visiblity of this <code>Caret</code> as returned by {@link #isVisible()}.
+ *
+ * @return <code>true</code> if this <code>Caret</code> is blinking,
+ * and <code>false</code> if not.
+ * @see #isVisible()
+ * @since 1.5
+ */
+ public boolean isActive()
+ {
+ if (blinkTimer != null)
+ return blinkTimer.isRunning();
+
+ return false;
+ }
+
+ /**
* Returns <code>true</code> if this <code>Caret</code> is currently visible,
* and <code>false</code> if it is not.
*
diff --git a/javax/swing/text/GapContent.java b/javax/swing/text/GapContent.java
index 4f06003b4..eacd29c7b 100644
--- a/javax/swing/text/GapContent.java
+++ b/javax/swing/text/GapContent.java
@@ -39,7 +39,13 @@ exception statement from your version. */
package javax.swing.text;
import java.io.Serializable;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import java.util.Vector;
import java.util.WeakHashMap;
@@ -73,30 +79,39 @@ public class GapContent
* The index to the positionMarks array entry, which in turn holds the
* mark into the buffer array.
*/
- int index;
+ Mark mark;
/**
* Creates a new GapContentPosition object.
*
- * @param mark the mark of this Position
+ * @param offset the offset of this Position
*/
- GapContentPosition(int mark)
+ GapContentPosition(int offset)
{
// Try to find the mark in the positionMarks array, and store the index
// to it.
synchronized (GapContent.this)
{
- int i = binarySearch(positionMarks, mark, numMarks);
+ // Try to make space.
+ garbageCollect();
+ Mark m = new Mark(offset);
+ int i = search(marks, m);
if (i >= 0) // mark found
{
- index = i;
+ m = (Mark) marks.get(i);
}
else
{
- index = -i - 1;
- insertMark(index, mark);
+ i = -i - 1;
+ marks.add(i, m);
}
+ m.refCount++;
+ mark = m;
}
+
+ // Register this position in the death queue, so we can cleanup the marks
+ // when this position object gets GC'ed.
+ new WeakReference(this, queueOfDeath);
}
/**
@@ -106,19 +121,77 @@ public class GapContent
*/
public int getOffset()
{
- synchronized (GapContent.this)
- {
- // Fetch the actual mark.
- int mark = positionMarks[index];
- // Check precondition.
- assert mark <= gapStart || mark >= gapEnd : "mark: " + mark
- + ", gapStart: " + gapStart
- + ", gapEnd: " + gapEnd;
- int res = mark;
- if (mark > gapStart)
- res -= (gapEnd - gapStart);
- return res;
- }
+ return mark.getOffset();
+ }
+ }
+
+ /**
+ * Holds a mark into the buffer that is used by GapContentPosition to find
+ * the actual offset of the position. This is pulled out of the
+ * GapContentPosition object so that the mark and position can be handled
+ * independently, and most important, so that the GapContentPosition can
+ * be garbage collected while we still hold a reference to the Mark object.
+ */
+ private class Mark
+ implements Comparable
+ {
+ /**
+ * The actual mark into the buffer.
+ */
+ int mark;
+
+ /**
+ * The number of GapContentPosition object that reference this mark. If
+ * it reaches zero, it get's deleted by {@link GapContent#garbageCollect()}.
+ */
+ int refCount;
+
+ /**
+ * Creates a new Mark object for the specified offset.
+ *
+ * @param offset the offset
+ */
+ Mark(int offset)
+ {
+ mark = offset;
+ if (mark >= gapStart && mark != 0)
+ mark += (gapEnd - gapStart);
+ }
+
+ /**
+ * Returns the offset of the mark.
+ *
+ * @return the offset of the mark
+ */
+ int getOffset()
+ {
+ assert mark == 0 || mark < gapStart || mark >= gapEnd :
+ "Invalid mark: " + mark + ", gapStart: " + gapStart
+ + ", gapEnd: " + gapEnd;
+
+ int res = mark;
+ if (mark >= gapEnd)
+ res -= (gapEnd - gapStart);
+ return res;
+ }
+
+ /**
+ * Implementation of Comparable.
+ */
+ public int compareTo(Object o)
+ {
+ Mark other = (Mark) o;
+ return mark - other.mark;
+ }
+ /**
+ * Adjustment for equals().
+ */
+ public boolean equals(Object o)
+ {
+ if (o == null || !(o instanceof Mark))
+ return false;
+ else
+ return ((Mark) o).mark == mark;
}
}
@@ -230,19 +303,21 @@ public class GapContent
/**
* Holds the marks for positions. These marks are referenced by the
* GapContentPosition instances by an index into this array.
+ *
+ * This is package private to avoid accessor synthetic methods.
*/
- int[] positionMarks;
+ ArrayList marks;
- /**
- * The number of elements in the positionMarks array. The positionMarks array
- * might be bigger than the actual number of elements.
- */
- int numMarks;
+ WeakHashMap positions;
/**
- * (Weakly) Stores the GapContentPosition instances.
+ * Queues all references to GapContentPositions that are about to be
+ * GC'ed. This is used to remove the corresponding marks from the
+ * positionMarks array if the number of references to that mark reaches zero.
+ *
+ * This is package private to avoid accessor synthetic methods.
*/
- WeakHashMap positions;
+ ReferenceQueue queueOfDeath;
/**
* Creates a new GapContent object.
@@ -265,8 +340,8 @@ public class GapContent
gapEnd = size;
buffer[0] = '\n';
positions = new WeakHashMap();
- positionMarks = new int[10];
- numMarks = 0;
+ marks = new ArrayList();
+ queueOfDeath = new ReferenceQueue();
}
/**
@@ -455,6 +530,9 @@ public class GapContent
*/
public Position createPosition(final int offset) throws BadLocationException
{
+ if (offset < 0 || offset > length())
+ throw new BadLocationException("Position offset out of bounds", offset);
+
// We try to find a GapContentPosition at the specified offset and return
// that. Otherwise we must create a new one.
GapContentPosition pos = null;
@@ -472,10 +550,7 @@ public class GapContent
// If none was found, then create and return a new one.
if (pos == null)
{
- int mark = offset;
- if (mark >= gapStart)
- mark += (gapEnd - gapStart);
- pos = new GapContentPosition(mark);
+ pos = new GapContentPosition(offset);
positions.put(pos, null);
}
@@ -497,7 +572,7 @@ public class GapContent
int delta = newSize - gapEnd + gapStart;
// Update the marks after the gapEnd.
- adjustPositionsInRange(gapEnd, buffer.length - gapEnd, delta);
+ adjustPositionsInRange(gapEnd, buffer.length, delta);
// Copy the data around.
char[] newBuf = (char[]) allocateArray(length() + newSize);
@@ -523,7 +598,7 @@ public class GapContent
{
// Update the positions between newGapStart and (old) gapStart. The marks
// must be shifted by (gapEnd - gapStart).
- adjustPositionsInRange(newGapStart, gapStart - newGapStart, gapEnd - gapStart);
+ adjustPositionsInRange(newGapStart, gapStart, gapEnd - gapStart);
System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart
- newGapStart);
gapStart = newGapStart;
@@ -533,14 +608,13 @@ public class GapContent
{
// Update the positions between newGapEnd and (old) gapEnd. The marks
// must be shifted by (gapEnd - gapStart).
- adjustPositionsInRange(gapEnd, newGapEnd - gapEnd, -(gapEnd - gapStart));
+ adjustPositionsInRange(gapEnd, newGapEnd, -(gapEnd - gapStart));
System.arraycopy(buffer, gapEnd, buffer, gapStart, newGapStart
- gapStart);
gapStart = newGapStart;
gapEnd = newGapEnd;
}
- if (gapStart == 0)
- resetMarksAtZero();
+ resetMarksAtZero();
}
/**
@@ -560,6 +634,7 @@ public class GapContent
+ "old gap start.";
setPositionsInRange(newGapStart, gapStart, false);
gapStart = newGapStart;
+ resetMarksAtZero();
}
/**
@@ -579,6 +654,7 @@ public class GapContent
+ "old gap end.";
setPositionsInRange(gapEnd, newGapEnd, false);
gapEnd = newGapEnd;
+ resetMarksAtZero();
}
/**
@@ -617,10 +693,6 @@ public class GapContent
if (addItems != null)
{
System.arraycopy(addItems, 0, buffer, gapStart, addSize);
-
-
- resetMarksAtZero();
-
gapStart += addSize;
}
}
@@ -689,102 +761,55 @@ public class GapContent
*/
private void setPositionsInRange(int start, int end, boolean toStart)
{
- // We slump together all the GapContentPositions to point to
- // one mark. So this is implemented as follows:
- // 1. Remove all the marks in the specified range.
- // 2. Insert one new mark at the correct location.
- // 3. Adjust all affected GapContentPosition instances to point to
- // this new mark.
-
synchronized (this)
{
- int startIndex = binarySearch(positionMarks, start, numMarks);
+ // Find the start and end indices in the positionMarks array.
+ Mark m = new Mark(0); // For comparison / search only.
+ m.mark = start;
+ int startIndex = search(marks, m);
if (startIndex < 0) // Translate to insertion index, if not found.
startIndex = - startIndex - 1;
- int endIndex = binarySearch(positionMarks, end, numMarks);
+ m.mark = end;
+ int endIndex = search(marks, m);
if (endIndex < 0) // Translate to insertion index - 1, if not found.
endIndex = - endIndex - 2;
- // Update the marks.
- // We have inclusive interval bounds, but let one element over for
- // filling in the new value.
- int removed = endIndex - startIndex;
- if (removed <= 0)
- return;
- System.arraycopy(positionMarks, endIndex + 1, positionMarks,
- startIndex + 1, positionMarks.length - endIndex - 1);
- numMarks -= removed;
- if (toStart)
- {
- positionMarks[startIndex] = start;
- }
- else
- {
- positionMarks[startIndex] = end;
- }
+ // Actually adjust the marks.
+ for (int i = startIndex; i <= endIndex; i++)
+ ((Mark) marks.get(i)).mark = toStart ? start : end;
+ }
- // Update all affected GapContentPositions to point to the new index
- // and all GapContentPositions that come after the interval to
- // have their index moved by -removed.
- Set positionSet = positions.keySet();
- for (Iterator i = positionSet.iterator(); i.hasNext();)
- {
- GapContentPosition p = (GapContentPosition) i.next();
- if (p.index > startIndex || p.index <= endIndex)
- p.index = startIndex;
- else if (p.index > endIndex)
- p.index -= removed;
- }
- }
}
-
+
/**
* Adjusts the mark of all <code>Position</code>s that are in the range
* specified by <code>offset</code> and </code>length</code> within
* the buffer array by <code>increment</code>
*
- * @param offset the start offset of the range to search
- * @param length the length of the range to search
+ * @param startOffs the start offset of the range to search
+ * @param endOffs the length of the range to search
* @param incr the increment
*/
- private void adjustPositionsInRange(int offset, int length, int incr)
+ private void adjustPositionsInRange(int startOffs, int endOffs, int incr)
{
- int endMark = offset + length;
-
synchronized (this)
{
// Find the start and end indices in the positionMarks array.
- int startIndex = binarySearch(positionMarks, offset, numMarks);
+ Mark m = new Mark(0); // For comparison / search only.
+
+ m.mark = startOffs;
+ int startIndex = search(marks, m);
if (startIndex < 0) // Translate to insertion index, if not found.
startIndex = - startIndex - 1;
- int endIndex = binarySearch(positionMarks, endMark, numMarks);
+
+ m.mark = endOffs;
+ int endIndex = search(marks, m);
if (endIndex < 0) // Translate to insertion index - 1, if not found.
endIndex = - endIndex - 2;
-
- // We must not change the order of the marks, this would have
- // unpredictable results while binary-searching the marks.
- assert (startIndex <= 0
- || positionMarks[startIndex - 1]
- <= positionMarks [startIndex] + incr)
- && (endIndex >= numMarks - 1
- || positionMarks[endIndex + 1]
- >= positionMarks[endIndex] + incr)
- : "Adjusting the marks must not change their order";
-
- // Some debug helper output to determine if the start or end of the
- // should ever be coalesced together with adjecent marks.
- if (startIndex > 0 && positionMarks[startIndex - 1]
- == positionMarks[startIndex] + incr)
- System.err.println("DEBUG: We could coalesce the start of the region"
- + " in GapContent.adjustPositionsInRange()");
- if (endIndex < numMarks - 1 && positionMarks[endIndex + 1]
- == positionMarks[endIndex] + incr)
- System.err.println("DEBUG: We could coalesce the end of the region"
- + " in GapContent.adjustPositionsInRange()");
-
// Actually adjust the marks.
- for (int i = startIndex; i <= endIndex; i++)
- positionMarks[i] += incr;
+ for (int i = startIndex; i <= endIndex; i++) {
+ ((Mark) marks.get(i)).mark += incr;
+ }
}
}
@@ -800,7 +825,12 @@ public class GapContent
if (gapStart != 0)
return;
- positionMarks[0] = 0;
+ for (int i = 0; i < marks.size(); i++)
+ {
+ Mark m = (Mark) marks.get(i);
+ if (m.mark <= gapEnd)
+ m.mark = 0;
+ }
}
/**
@@ -845,89 +875,60 @@ public class GapContent
*/
private void dumpMarks()
{
- System.err.print("positionMarks: ");
- for (int i = 0; i < numMarks; i++)
- System.err.print(positionMarks[i] + ", ");
- System.err.println();
+ System.out.print("positionMarks: ");
+ for (int i = 0; i < marks.size(); i++)
+ System.out.print(((Mark) marks.get(i)).mark + ", ");
+ System.out.println();
}
/**
- * Inserts a mark into the positionMarks array. This must update all the
- * GapContentPosition instances in positions that come after insertionPoint.
- *
- * This is package private to avoid synthetic accessor methods.
+ * Polls the queue of death for GapContentPositions, updates the
+ * corresponding reference count and removes the corresponding mark
+ * if the refcount reaches zero.
*
- * @param insertionPoint the index at which to insert the mark
- * @param mark the mark to insert
+ * This is package private to avoid accessor synthetic methods.
*/
- void insertMark(int insertionPoint, int mark)
+ void garbageCollect()
{
- synchronized (this)
+ Reference ref = queueOfDeath.poll();
+ while (ref != null)
{
- // Update the positions.
- Set positionSet = positions.keySet();
- for (Iterator i = positionSet.iterator(); i.hasNext();)
+ if (ref != null)
{
- GapContentPosition p = (GapContentPosition) i.next();
- if (p.index >= insertionPoint)
- p.index++;
+ GapContentPosition pos = (GapContentPosition) ref.get();
+ Mark m = pos.mark;
+ m.refCount--;
+ if (m.refCount == 0)
+ marks.remove(m);
}
-
- // Update the position marks.
- if (positionMarks.length <= numMarks)
- {
- int[] newMarks = new int[positionMarks.length + 10];
- System.arraycopy(positionMarks, 0, newMarks, 0, insertionPoint);
- newMarks[insertionPoint] = mark;
- System.arraycopy(positionMarks, insertionPoint, newMarks,
- insertionPoint + 1,
- numMarks - insertionPoint);
- positionMarks = newMarks;
- }
- else
- {
- System.arraycopy(positionMarks, insertionPoint, positionMarks,
- insertionPoint + 1,
- numMarks - insertionPoint);
- positionMarks[insertionPoint] = mark;
- }
- numMarks++;
+ ref = queueOfDeath.poll();
}
}
/**
- * An adaption of {@link java.util.Arrays#binarySearch(int[], int)} to
- * specify a maximum index up to which the array is searched. This allows
- * us to have some trailing entries that we ignore.
- *
- * This is package private to avoid synthetic accessor methods.
- *
- * @param a the array
- * @param key the key to search for
- * @param maxIndex the maximum index up to which the search is performed
+ * Searches the first occurance of object <code>o</code> in list
+ * <code>l</code>. This performs a binary search by calling
+ * {@link Collections#binarySearch(List, Object)} and when an object has been
+ * found, it searches backwards to the first occurance of that object in the
+ * list. The meaning of the return value is the same as in
+ * <code>Collections.binarySearch()</code>.
*
- * @return the index of the found entry, or (-(index)-1) for the
- * insertion point when not found
+ * @param l the list to search through
+ * @param o the object to be searched
*
- * @see java.util.Arrays#binarySearch(int[], int)
+ * @return the index of the first occurance of o in l, or -i + 1 if not found
*/
- int binarySearch(int[] a, int key, int maxIndex)
+ private int search(List l, Object o)
{
- int low = 0;
- int hi = maxIndex - 1;
- int mid = 0;
- while (low <= hi)
+ int i = Collections.binarySearch(l, o);
+ while (i > 0)
{
- mid = (low + hi) >>> 1;
- final int d = a[mid];
- if (d == key)
- return mid;
- else if (d > key)
- hi = mid - 1;
+ Object o2 = l.get(i - 1);
+ if (o2.equals(o))
+ i--;
else
- // This gets the insertion point right on the last loop.
- low = ++mid;
+ break;
}
- return -mid - 1;
+ return i;
}
}
diff --git a/javax/swing/text/JTextComponent.java b/javax/swing/text/JTextComponent.java
index 9de151dfb..6da84bfe7 100644
--- a/javax/swing/text/JTextComponent.java
+++ b/javax/swing/text/JTextComponent.java
@@ -42,6 +42,7 @@ import gnu.classpath.NotImplementedException;
import java.awt.AWTEvent;
import java.awt.Color;
+import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
@@ -90,9 +91,10 @@ public abstract class JTextComponent extends JComponent
implements Scrollable, Accessible
{
/**
- * This class implements accessibility support for the JTextComponent class.
- * It provides an implementation of the Java Accessibility API appropriate
- * to menu user-interface elements.
+ * AccessibleJTextComponent implements accessibility hooks for
+ * JTextComponent. It allows an accessibility driver to read and
+ * manipulate the text component's contents as well as update UI
+ * elements such as the caret.
*/
public class AccessibleJTextComponent extends AccessibleJComponent implements
AccessibleText, CaretListener, DocumentListener, AccessibleAction,
@@ -100,15 +102,18 @@ public abstract class JTextComponent extends JComponent
{
private static final long serialVersionUID = 7664188944091413696L;
- /** The caret's offset. */
+ /**
+ * The caret's offset.
+ */
int dot = 0;
-
- /** The current JTextComponent. */
+
+ /**
+ * The current JTextComponent.
+ */
JTextComponent textComp = JTextComponent.this;
-
+
/**
- * Constructs an AccessibleJTextComponent.
- * Adds a listener to track caret change.
+ * Construct an AccessibleJTextComponent.
*/
public AccessibleJTextComponent()
{
@@ -117,11 +122,10 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the zero-based offset of the caret. Note: The character
- * to the right of the caret will have the same index value as the
- * offset (the caret is between two characters).
- *
- * @return offset of caret
+ * Retrieve the current caret position. The index of the first
+ * caret position is 0.
+ *
+ * @return caret position
*/
public int getCaretPosition()
{
@@ -130,9 +134,10 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the portion of the text that is selected.
- *
- * @return null if no text is selected.
+ * Retrieve the current text selection. If no text is selected
+ * this method returns null.
+ *
+ * @return the currently selected text or null
*/
public String getSelectedText()
{
@@ -140,11 +145,14 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the start offset within the selected text. If there is no
- * selection, but there is a caret, the start and end offsets will be
- * the same. Return 0 if the text is empty, or the caret position if no selection.
- *
- * @return index of the start of the text >= 0.
+ * Retrieve the index of the first character in the current text
+ * selection. If there is no text in the text component, this
+ * method returns 0. If there is text in the text component, but
+ * there is no selection, this method returns the current caret
+ * position.
+ *
+ * @return the index of the first character in the selection, the
+ * current caret position or 0
*/
public int getSelectionStart()
{
@@ -154,12 +162,14 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the end offset within the selected text. If there is no
- * selection, but there is a caret, the start and end offsets will
- * be the same. Return 0 if the text is empty, or the caret position
- * if no selection.
- *
- * @return index of the end of the text >= 0.
+ * Retrieve the index of the last character in the current text
+ * selection. If there is no text in the text component, this
+ * method returns 0. If there is text in the text component, but
+ * there is no selection, this method returns the current caret
+ * position.
+ *
+ * @return the index of the last character in the selection, the
+ * current caret position or 0
*/
public int getSelectionEnd()
{
@@ -169,13 +179,10 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Handles caret updates (fire appropriate property change event, which are
- * AccessibleContext.ACCESSIBLE_CARET_PROPERTY and
- * AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY). This keeps track of
- * the dot position internally. When the caret moves, the internal position
- * is updated after firing the event.
- *
- * @param e - caret event
+ * Handle a change in the caret position and fire any applicable
+ * property change events.
+ *
+ * @param e - the caret update event
*/
public void caretUpdate(CaretEvent e)
throws NotImplementedException
@@ -185,7 +192,7 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the accessible state set of this component.
+ * Retreive the accessible state set of this component.
*
* @return the accessible state set of this component
*/
@@ -198,7 +205,7 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the accessible role of this component.
+ * Retrieve the accessible role of this component.
*
* @return the accessible role of this component
*
@@ -210,20 +217,19 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the AccessibleEditableText interface for this text component.
- *
+ * Retrieve an AccessibleEditableText object that controls this
+ * text component.
+ *
* @return this
*/
public AccessibleEditableText getAccessibleEditableText()
{
return this;
}
-
+
/**
- * Get the AccessibleText associated with this object. In the implementation
- * of the Java Accessibility API for this class, return this object,
- * which is responsible for implementing the AccessibleText interface on
- * behalf of itself.
+ * Retrieve an AccessibleText object that controls this text
+ * component.
*
* @return this
*
@@ -235,10 +241,11 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Insert update. Fire appropriate property change event which
- * is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY.
- *
- * @param e - document event
+ * Handle a text insertion event and fire an
+ * AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change
+ * event.
+ *
+ * @param e - the insertion event
*/
public void insertUpdate(DocumentEvent e)
throws NotImplementedException
@@ -247,10 +254,11 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Remove update. Fire appropriate property change event which
- * is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY.
- *
- * @param e - document event
+ * Handle a text removal event and fire an
+ * AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change
+ * event.
+ *
+ * @param e - the removal event
*/
public void removeUpdate(DocumentEvent e)
throws NotImplementedException
@@ -259,10 +267,11 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Changed update. Fire appropriate property change event which
- * is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY.
- *
- * @param e - document event
+ * Handle a text change event and fire an
+ * AccessibleContext.ACCESSIBLE_TEXT_PROPERTY property change
+ * event.
+ *
+ * @param e - text change event
*/
public void changedUpdate(DocumentEvent e)
throws NotImplementedException
@@ -271,11 +280,13 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Given a point in the coordinate system of this object, return the
- * 0-based index of the character at that point, or -1 if there is none.
+ * Get the index of the character at the given point, in component
+ * pixel co-ordinates. If the point argument is invalid this
+ * method returns -1.
*
- * @param p the point to look at
- * @return the character index, or -1
+ * @param p - a point in component pixel co-ordinates
+ *
+ * @return a character index, or -1
*/
public int getIndexAtPoint(Point p)
throws NotImplementedException
@@ -284,17 +295,14 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Determines the bounding box of the indexed character. Returns an empty
- * rectangle if the index is out of bounds. The bounds are returned in local coordinates.
- * If the index is invalid a null rectangle is returned. The screen coordinates returned are
- * "unscrolled coordinates" if the JTextComponent is contained in a JScrollPane in which
- * case the resulting rectangle should be composed with the parent coordinates.
- * Note: the JTextComponent must have a valid size (e.g. have been added to a parent
- * container whose ancestor container is a valid top-level window) for this method to
- * be able to return a meaningful (non-null) value.
+ * Calculate the bounding box of the character at the given index.
+ * The returned x and y co-ordinates are relative to this text
+ * component's top-left corner. If the index is invalid this
+ * method returns null.
+ *
+ * @param index - the character index
*
- * @param index the 0-based character index
- * @return the bounding box, may be empty or null.
+ * @return a character's bounding box, or null
*/
public Rectangle getCharacterBounds(int index)
throws NotImplementedException
@@ -303,9 +311,9 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Return the number of characters.
+ * Return the length of the text in this text component.
*
- * @return the character count
+ * @return a character length
*/
public int getCharCount()
{
@@ -313,10 +321,11 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the attributes of a character at an index, or null if the index
- * is out of bounds.
+ * Gets the character attributes of the character at index. If
+ * the index is out of bounds, null is returned.
*
- * @param index the 0-based character index
+ * @param index - index of the character
+ *
* @return the character's attributes
*/
public AttributeSet getCharacterAttribute(int index)
@@ -326,26 +335,28 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the section of text at the index, or null if the index or part
- * is invalid.
- *
- * @param part {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
- * @param index the 0-based character index
- * @return the selection of text at that index, or null
+ * Gets the text located at index. null is returned if the index
+ * or part is invalid.
+ *
+ * @param part - {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
+ * @param index - index of the part
+ *
+ * @return the part of text at that index, or null
*/
public String getAtIndex(int part, int index)
throws NotImplementedException
{
return null; // TODO
}
-
+
/**
- * Returns the section of text after the index, or null if the index or part
- * is invalid.
- *
- * @param part {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
- * @param index the 0-based character index
- * @return the selection of text after that index, or null
+ * Gets the text located after index. null is returned if the index
+ * or part is invalid.
+ *
+ * @param part - {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
+ * @param index - index after the part
+ *
+ * @return the part of text after that index, or null
*/
public String getAfterIndex(int part, int index)
throws NotImplementedException
@@ -354,12 +365,13 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Returns the section of text before the index, or null if the index or part
- * is invalid.
- *
- * @param part {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
- * @param index the 0-based character index
- * @return the selection of text before that index, or null
+ * Gets the text located before index. null is returned if the index
+ * or part is invalid.
+ *
+ * @param part - {@link #CHARACTER}, {@link #WORD}, or {@link #SENTENCE}
+ * @param index - index before the part
+ *
+ * @return the part of text before that index, or null
*/
public String getBeforeIndex(int part, int index)
throws NotImplementedException
@@ -368,10 +380,10 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Get the number possible actions for this object, with the zeroth
- * representing the default action.
+ * Returns the number of actions for this object. The zero-th
+ * object represents the default action.
*
- * @return the 0-based number of actions
+ * @return the number of actions (0-based).
*/
public int getAccessibleActionCount()
throws NotImplementedException
@@ -380,11 +392,12 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Get a description for the specified action. Returns null if out of
- * bounds.
+ * Returns the description of the i-th action. Null is returned if
+ * i is out of bounds.
*
- * @param i the action to describe, 0-based
- * @return description of the action
+ * @param i - the action to get the description for
+ *
+ * @return description of the i-th action
*/
public String getAccessibleActionDescription(int i)
throws NotImplementedException
@@ -394,10 +407,12 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Perform the specified action. Does nothing if out of bounds.
+ * Performs the i-th action. Nothing happens if i is
+ * out of bounds.
*
- * @param i the action to perform, 0-based
- * @return true if the action was performed
+ * @param i - the action to perform
+ *
+ * @return true if the action was performed successfully
*/
public boolean doAccessibleAction(int i)
throws NotImplementedException
@@ -406,9 +421,9 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Set the text contents to the given string.
+ * Sets the text contents.
*
- * @param s the new text
+ * @param s - the new text contents.
*/
public void setTextContents(String s)
throws NotImplementedException
@@ -417,10 +432,10 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Inserts the given string at the specified location.
+ * Inserts the text at the given index.
*
- * @param index the index for insertion
- * @param s the new text
+ * @param index - the index to insert the new text at.
+ * @param s - the new text
*/
public void insertTextAtIndex(int index, String s)
throws NotImplementedException
@@ -429,10 +444,10 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Return the text between two points.
+ * Gets the text between two indexes.
*
- * @param start the start position, inclusive
- * @param end the end position, exclusive
+ * @param start - the starting index (inclusive)
+ * @param end - the ending index (exclusive)
*/
public String getTextRange(int start, int end)
{
@@ -447,10 +462,10 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Delete the text between two points.
+ * Deletes the text between two indexes.
*
- * @param start the start position, inclusive
- * @param end the end position, exclusive
+ * @param start - the starting index (inclusive)
+ * @param end - the ending index (exclusive)
*/
public void delete(int start, int end)
{
@@ -458,10 +473,11 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Cut the text between two points to the system clipboard.
+ * Cuts the text between two indexes. The text is put
+ * into the system clipboard.
*
- * @param start the start position, inclusive
- * @param end the end position, exclusive
+ * @param start - the starting index (inclusive)
+ * @param end - the ending index (exclusive)
*/
public void cut(int start, int end)
{
@@ -470,9 +486,9 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Paste the text from the system clipboard at the given index.
+ * Pastes the text from the system clipboard to the given index.
*
- * @param start the start position
+ * @param start - the starting index
*/
public void paste(int start)
{
@@ -481,11 +497,12 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Replace the text between two points with the given string.
+ * Replaces the text between two indexes with the given text.
*
- * @param start the start position, inclusive
- * @param end the end position, exclusive
- * @param s the string to paste
+ *
+ * @param start - the starting index (inclusive)
+ * @param end - the ending index (exclusive)
+ * @param s - the text to paste
*/
public void replaceText(int start, int end, String s)
{
@@ -494,10 +511,10 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Select the text between two points.
+ * Selects the text between two indexes.
*
- * @param start the start position, inclusive
- * @param end the end position, exclusive
+ * @param start - the starting index (inclusive)
+ * @param end - the ending index (exclusive)
*/
public void selectText(int start, int end)
{
@@ -505,11 +522,11 @@ public abstract class JTextComponent extends JComponent
}
/**
- * Set the attributes of text between two points.
+ * Sets the attributes of all the text between two indexes.
*
- * @param start the start position, inclusive
- * @param end the end position, exclusive
- * @param s the new attribute set for the range
+ * @param start - the starting index (inclusive)
+ * @param end - the ending index (exclusive)
+ * @param s - the new attribute set for the text in the range
*/
public void setAttributes(int start, int end, AttributeSet s)
throws NotImplementedException
@@ -1163,8 +1180,19 @@ public abstract class JTextComponent extends JComponent
public void setDocument(Document newDoc)
{
Document oldDoc = doc;
- doc = newDoc;
- firePropertyChange("document", oldDoc, newDoc);
+ try
+ {
+ if (oldDoc instanceof AbstractDocument)
+ ((AbstractDocument) oldDoc).readLock();
+
+ doc = newDoc;
+ firePropertyChange("document", oldDoc, newDoc);
+ }
+ finally
+ {
+ if (oldDoc instanceof AbstractDocument)
+ ((AbstractDocument) oldDoc).readUnlock();
+ }
revalidate();
repaint();
}
@@ -1641,10 +1669,12 @@ public abstract class JTextComponent extends JComponent
public boolean getScrollableTracksViewportWidth()
{
- if (getParent() instanceof JViewport)
- return getParent().getWidth() > getPreferredSize().width;
+ boolean res = false;;
+ Container c = getParent();
+ if (c instanceof JViewport)
+ res = ((JViewport) c).getExtentSize().width > getPreferredSize().width;
- return false;
+ return res;
}
/**
diff --git a/javax/swing/text/PlainDocument.java b/javax/swing/text/PlainDocument.java
index c699dcad2..730a619da 100644
--- a/javax/swing/text/PlainDocument.java
+++ b/javax/swing/text/PlainDocument.java
@@ -56,8 +56,12 @@ public class PlainDocument extends AbstractDocument
public static final String lineLimitAttribute = "lineLimit";
public static final String tabSizeAttribute = "tabSize";
- private BranchElement rootElement;
- private int tabSize;
+ /**
+ * The default root element of this document. This is made type Element
+ * because the RI seems to accept other types of elements as well from
+ * createDefaultRoot() (when overridden by a subclass).
+ */
+ private Element rootElement;
public PlainDocument()
{
@@ -67,8 +71,10 @@ public class PlainDocument extends AbstractDocument
public PlainDocument(AbstractDocument.Content content)
{
super(content);
- tabSize = 8;
- rootElement = (BranchElement) createDefaultRoot();
+ rootElement = createDefaultRoot();
+
+ // This property has been determined using a Mauve test.
+ putProperty("tabSize", new Integer(8));
}
private void reindex()
@@ -105,10 +111,10 @@ public class PlainDocument extends AbstractDocument
protected AbstractDocument.AbstractElement createDefaultRoot()
{
BranchElement root =
- (BranchElement) createBranchElement(null, SimpleAttributeSet.EMPTY);
+ (BranchElement) createBranchElement(null, null);
Element[] array = new Element[1];
- array[0] = createLeafElement(root, SimpleAttributeSet.EMPTY, 0, 1);
+ array[0] = createLeafElement(root, null, 0, 1);
root.replace(0, 0, array);
return root;
@@ -117,116 +123,97 @@ public class PlainDocument extends AbstractDocument
protected void insertUpdate(DefaultDocumentEvent event,
AttributeSet attributes)
{
+
+ String text = null;
int offset = event.getOffset();
- int eventLength = event.getLength();
- int end = offset + event.getLength();
- int oldElementIndex, elementIndex = rootElement.getElementIndex(offset);
- Element firstElement = rootElement.getElement(elementIndex);
- oldElementIndex = elementIndex;
-
- // If we're inserting immediately after a newline we have to fix the
- // Element structure (but only if we are dealing with a line which
- // has not existed as Element before).
- if (offset > 0 && firstElement.getStartOffset() != offset)
+ int length = event.getLength();
+ try
{
- try
- {
- String s = getText(offset - 1, 1);
- if (s.equals("\n") )
- {
- int newEl2EndOffset = end;
- boolean replaceNext = false;
- if (rootElement.getElementCount() > elementIndex + 1)
- {
- replaceNext = true;
- newEl2EndOffset =
- rootElement.getElement(elementIndex + 1).getEndOffset();
- }
- Element newEl1 =
- createLeafElement(rootElement, firstElement.getAttributes(),
- firstElement.getStartOffset(), offset);
- Element newEl2 =
- createLeafElement (rootElement, firstElement.getAttributes(),
- offset, newEl2EndOffset);
- if (replaceNext)
- rootElement.replace(elementIndex, 2, new Element[] { newEl1, newEl2 });
- else
- rootElement.replace(elementIndex, 1, new Element[] { newEl1, newEl2 });
- firstElement = newEl2;
- elementIndex ++;
- }
- }
- catch (BadLocationException ble)
- {
- // This shouldn't happen.
- AssertionError ae = new AssertionError();
- ae.initCause(ble);
- throw ae;
- }
+ text = getText(offset, length);
+ }
+ catch (BadLocationException ex)
+ {
+ AssertionError err = new AssertionError();
+ err.initCause(ex);
+ throw err;
}
- // added and removed are Element arrays used to add an ElementEdit
- // to the DocumentEvent if there were entire lines added or removed.
- Element[] removed = new Element[1];
- Element[] added;
- try
+ boolean hasLineBreak = text.indexOf('\n') != -1;
+ boolean prevCharIsLineBreak = false;
+ try
{
- String str = content.getString(offset, eventLength);
- ArrayList elts = new ArrayList();
+ prevCharIsLineBreak =
+ offset > 0 && getText(offset - 1, 1).charAt(0) == '\n';
+ }
+ catch (BadLocationException ex)
+ {
+ AssertionError err = new AssertionError();
+ err.initCause(ex);
+ throw err;
+ }
+ boolean lastCharIsLineBreak = text.charAt(text.length() - 1) == '\n';
+ int lineIndex = -1;
+ int lineStart = -1;
+ int lineEnd = -1;
+ Element[] removed = null;
+ BranchElement root = (BranchElement) rootElement;
+ boolean updateStructure = true;
- // Determine how many NEW lines were added by finding the newline
- // characters within the newly inserted text
- int j = firstElement.getStartOffset();
- int i = str.indexOf('\n', 0);
- int contentLength = content.length();
-
- while (i != -1 && i <= eventLength)
- {
- // For each new line, create a new element
- elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY,
- j, offset + i + 1));
-
- j = offset + i + 1;
- if (j >= contentLength)
- break;
- i = str.indexOf('\n', i + 1);
- }
+ if (prevCharIsLineBreak && ! lastCharIsLineBreak)
+ {
+ // We must fix the structure a little if the previous char
+ // is a linebreak and the last char isn't.
+ lineIndex = root.getElementIndex(offset - 1);
+ Element prevLine = root.getElement(lineIndex);
+ Element nextLine = root.getElement(lineIndex + 1);
+ lineStart = prevLine.getStartOffset();
+ lineEnd = nextLine.getEndOffset();
+ removed = new Element[]{ prevLine, nextLine };
+ }
+ else if (hasLineBreak)
+ {
+ lineIndex = root.getElementIndex(offset);
+ Element line = root.getElement(lineIndex);
+ lineStart = line.getStartOffset();
+ lineEnd = line.getEndOffset();
+ removed = new Element[]{ line };
+ }
+ else
+ {
+ updateStructure = false;
+ }
- // If there were new lines added we have to add an ElementEdit to
- // the DocumentEvent and we have to call rootElement.replace to
- // insert the new lines
- if (elts.size() != 0)
+ if (updateStructure)
+ {
+ // Break the lines between lineStart and lineEnd.
+ ArrayList lines = new ArrayList();
+ int len = lineEnd - lineStart;
+ try
{
- // If we have created new lines test whether there are remaining
- // characters in firstElement after the inserted text and if so
- // create a new element for them.
- if (j < firstElement.getEndOffset())
- elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY, j, firstElement.getEndOffset()));
-
- // Set up the ElementEdit by filling the added and removed
- // arrays with the proper Elements
- added = new Element[elts.size()];
- elts.toArray(added);
-
- removed[0] = firstElement;
-
- // Now create and add the ElementEdit
- ElementEdit e = new ElementEdit(rootElement, elementIndex, removed,
- added);
- event.addEdit(e);
-
- // And call replace to actually make the changes
- ((BranchElement) rootElement).replace(elementIndex, 1, added);
+ text = getText(lineStart, len);
}
+ catch (BadLocationException ex)
+ {
+ AssertionError err = new AssertionError();
+ err.initCause(ex);
+ throw err;
+ }
+ int prevLineBreak = 0;
+ int lineBreak = text.indexOf('\n');
+ do
+ {
+ lineBreak++;
+ lines.add(createLeafElement(root, null, lineStart + prevLineBreak,
+ lineStart + lineBreak));
+ prevLineBreak = lineBreak;
+ lineBreak = text.indexOf('\n', prevLineBreak);
+ } while (prevLineBreak < len);
+
+ // Update the element structure and prepare document event.
+ Element[] added = (Element[]) lines.toArray(new Element[lines.size()]);
+ event.addEdit(new ElementEdit(root, lineIndex, removed, added));
+ root.replace(lineIndex, removed.length, added);
}
- catch (BadLocationException e)
- {
- // This shouldn't happen so we throw an AssertionError
- AssertionError ae = new AssertionError();
- ae.initCause(e);
- throw ae;
- }
-
super.insertUpdate(event, attributes);
}
@@ -264,7 +251,7 @@ public class PlainDocument extends AbstractDocument
event.addEdit(e);
// collapse elements if the removal spans more than 1 line
- rootElement.replace(i1, i2 - i1 + 1, added);
+ ((BranchElement) rootElement).replace(i1, i2 - i1 + 1, added);
}
}
diff --git a/javax/swing/text/rtf/RTFParser.java b/javax/swing/text/rtf/RTFParser.java
index 4f0f967c1..de1b1c6ff 100644
--- a/javax/swing/text/rtf/RTFParser.java
+++ b/javax/swing/text/rtf/RTFParser.java
@@ -140,9 +140,17 @@ class RTFParser
parseHeader();
parseDocument();
- Token t2 = scanner.readToken();
- if (t2.type != Token.RCURLY)
- throw new RTFParseException("expected right curly braces");
+ Token t2 = scanner.peekToken();
+ if (t2.type == Token.RCURLY)
+ {
+ // Eat the token.
+ scanner.readToken();
+ }
+ else
+ {
+ // Ignore this for maximum robustness when file is broken.
+ System.err.println("RTF warning: expected right curly braces");
+ }
}
diff --git a/javax/swing/text/rtf/RTFScanner.java b/javax/swing/text/rtf/RTFScanner.java
index 3cdd6e8e0..060e087eb 100644
--- a/javax/swing/text/rtf/RTFScanner.java
+++ b/javax/swing/text/rtf/RTFScanner.java
@@ -71,6 +71,11 @@ class RTFScanner
private StringBuffer buffer;
/**
+ * Lookahead token.
+ */
+ private Token lastToken;
+
+ /**
* Constructs a new RTFScanner without initializing the {@link Reader}.
*/
private RTFScanner()
@@ -120,7 +125,7 @@ class RTFScanner
*
* @throws IOException if the underlying stream has problems
*/
- public Token readToken()
+ private Token readTokenImpl()
throws IOException
{
Token token = null;
@@ -156,6 +161,27 @@ class RTFScanner
return token;
}
+ Token peekToken()
+ throws IOException
+ {
+ lastToken = readTokenImpl();
+ return lastToken;
+ }
+
+ Token readToken()
+ throws IOException
+ {
+ Token token;
+ if (lastToken != null)
+ {
+ token = lastToken;
+ lastToken = null;
+ }
+ else
+ token = readTokenImpl();
+ return token;
+ }
+
/**
* Reads in a control word and optional parameter.
*
diff --git a/lib/Makefile.am b/lib/Makefile.am
index c1d36788d..18f0da9ae 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -190,4 +190,5 @@ dist-hook:
$(FIND) $(distdir)/../gnu $(distdir)/../java $(distdir)/../javax $(distdir)/../org $(distdir)/../sun $(distdir)/../vm $(distdir)/../resource -name .cvsignore -print | xargs rm -f
$(FIND) $(distdir)/../gnu $(distdir)/../java $(distdir)/../javax $(distdir)/../org $(distdir)/../sun $(distdir)/../vm -name class-dependencies.conf -print | xargs rm -f
rm -f $(distdir)/../gnu/classpath/Configuration.java
+ rm -f $(distdir)/../gnu/java/security/Configuration.java
rm -f $(distdir)/../gnu/java/locale/LocaleData.java
diff --git a/native/jni/Makefile.am b/native/jni/Makefile.am
index 64cd35a51..2b205826c 100644
--- a/native/jni/Makefile.am
+++ b/native/jni/Makefile.am
@@ -20,14 +20,19 @@ if CREATE_QT_PEER_LIBRARIES
CLASSPATH_QT_PEER_DIR = qt-peer
endif
+if CREATE_GCONF_PEER_LIBRARIES
+ CLASSPATH_GCONF_PEER_DIR = gconf-peer
+endif
+
if CREATE_XMLJ_LIBRARY
XMLJDIR = xmlj
endif
SUBDIRS = classpath $(JNIDIRS) \
- $(ALSADIR) $(DSSIDIR) $(GTKDIR) $(CLASSPATH_QT_PEER_DIR) $(XMLJDIR)
+ $(ALSADIR) $(DSSIDIR) $(GTKDIR) $(CLASSPATH_QT_PEER_DIR) $(XMLJDIR) \
+ $(CLASSPATH_GCONF_PEER_DIR)
DIST_SUBDIRS = classpath java-io java-lang java-net java-nio java-util \
- gtk-peer qt-peer xmlj midi-alsa midi-dssi
+ gtk-peer gconf-peer qt-peer xmlj midi-alsa midi-dssi
all-local:
cd $(top_srcdir) && $(SHELL) ./scripts/check_jni_methods.sh
diff --git a/native/jni/gconf-peer/.cvsignore b/native/jni/gconf-peer/.cvsignore
new file mode 100644
index 000000000..799fc9785
--- /dev/null
+++ b/native/jni/gconf-peer/.cvsignore
@@ -0,0 +1,6 @@
+.deps
+.libs
+*.lo
+*.la
+Makefile
+Makefile.in
diff --git a/native/jni/gconf-peer/GConfNativePeer.c b/native/jni/gconf-peer/GConfNativePeer.c
new file mode 100644
index 000000000..55989f059
--- /dev/null
+++ b/native/jni/gconf-peer/GConfNativePeer.c
@@ -0,0 +1,518 @@
+/* GConfNativePeer.c -- Implements native methods for class GConfNativePeer
+ Copyright (C) 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. */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <jni.h>
+
+#include <glib.h>
+#include <gconf/gconf-client.h>
+
+#include "jcl.h"
+
+#include "gnu_java_util_prefs_gconf_GConfNativePeer.h"
+
+/*
+ * Cached id, methods and objects
+ */
+
+/** Reference count */
+static int reference_count = 0;
+
+/** GConfClient backend */
+static GConfClient *client = NULL;
+
+/** java.util.ArrayList class */
+static jclass jlist_class = NULL;
+
+/** java.util.ArrayList constructor id */
+static jmethodID jlist_init_id = NULL;
+
+/** ava.util.ArrayList add id */
+static jmethodID jlist_add_id = NULL;
+
+/* ***** PRIVATE FUNCTIONS DELCARATION ***** */
+
+/**
+ * Gets the reference of the default GConfClient and initialize the
+ * the type system.
+ * The client reference should be released with g_object_unref after use.
+ */
+static void init_gconf_client (void);
+
+/**
+ * Throws a new runtime exception after a failure, with the given message.
+ */
+static void throw_exception (JNIEnv *env, const char *msg);
+
+/**
+ * Throws the given exception after a failure, with the given message.
+ */
+static void
+throw_exception_by_name (JNIEnv *env, const char *name, const char *msg);
+
+/**
+ * Return a reference to a java.util.ArrayList class.
+ */
+static gboolean set_jlist_class (JNIEnv *env);
+
+/**
+ * Builds a new reference to a new java.util.ArrayList instace.
+ * The instance should be freed by the caller after use.
+ */
+static jclass get_jlist_reference (JNIEnv *env, jclass jlist_class);
+
+/* ***** END: PRIVATE FUNCTIONS DELCARATION ***** */
+
+/* ***** NATIVE FUNCTIONS ***** */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: init_class
+ * Signature: ()V
+ */
+JNIEXPORT void
+JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class
+ (JNIEnv *env, jclass clazz)
+{
+ if (reference_count == 0) {
+ Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache
+ (env, clazz);
+ return;
+ }
+
+ reference_count++;
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: init_id_chache
+ * Signature: ()V
+ */
+JNIEXPORT void
+JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)))
+{
+ reference_count++;
+
+ init_gconf_client ();
+
+ /* if client is null, there is probably an out or memory */
+ if (client == NULL) {
+ /* release the string and throw a runtime exception */
+ throw_exception (env,
+ "Unable to initialize GConfClient in native code\n");
+ return;
+ }
+
+ /* ***** java.util.ArrayList ***** */
+ if (set_jlist_class (env) == FALSE) {
+ throw_exception (env,
+ "Unable to get valid reference to java.util.List in native code\n");
+ return;
+ }
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_gconf_client_all_keys
+ * Signature: (Ljava/lang/String;)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1keys
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+{
+ const char *dir = NULL;
+ GError *err = NULL;
+ GSList *entries = NULL;
+ GSList *tmp;
+
+ /* java.util.ArrayList */
+ jobject jlist = NULL;
+
+ dir = JCL_jstring_to_cstring(env, node);
+ if (dir == NULL) {
+ return NULL;
+ }
+
+ entries = gconf_client_all_entries (client, dir, &err);
+ if (err != NULL) {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ err->message);
+ g_error_free (err);
+ err = NULL;
+
+ JCL_free_cstring(env, node, dir);
+ return NULL;
+ }
+
+ jlist = get_jlist_reference (env, jlist_class);
+ if (jlist == NULL) {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ "Unable to get java.util.List reference in native code\n");
+ JCL_free_cstring(env, node, dir);
+ g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
+ g_slist_free (entries);
+ return NULL;
+ }
+
+ tmp = entries;
+ while (tmp != NULL) {
+ const char *_val = gconf_entry_get_key(tmp->data);
+ _val = strrchr (_val, '/'); ++_val;
+ (*env)->CallBooleanMethod(env, jlist, jlist_add_id,
+ (*env)->NewStringUTF(env, _val));
+ tmp = g_slist_next (tmp);
+ }
+
+ /* clean up things */
+ JCL_free_cstring(env, node, dir);
+ g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
+ g_slist_free (entries);
+
+ return jlist;
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1keys */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_gconf_client_all_nodes
+ * Signature: (Ljava/lang/String;)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1nodes
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+{
+ const char *dir = NULL;
+ GError *err = NULL;
+ GSList *entries = NULL;
+ GSList *tmp;
+
+ /* java.util.ArrayList */
+ jobject jlist = NULL;
+
+ dir = JCL_jstring_to_cstring(env, node);
+ if (dir == NULL) {
+ return NULL;
+ }
+
+ entries = gconf_client_all_dirs (client, dir, &err);
+ if (err != NULL) {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ err->message);
+ g_error_free (err);
+ err = NULL;
+ JCL_free_cstring(env, node, dir);
+ return NULL;
+ }
+
+ jlist = get_jlist_reference (env, jlist_class);
+ if (jlist == NULL) {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ "Unable to get java.util.List reference in native code\n");
+ JCL_free_cstring(env, node, dir);
+ g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
+ g_slist_free (entries);
+ return NULL;
+ }
+
+ tmp = entries;
+ while (tmp != NULL) {
+ const char *_val = tmp->data;
+ _val = strrchr (_val, '/'); ++_val;
+ (*env)->CallBooleanMethod(env, jlist, jlist_add_id,
+ (*env)->NewStringUTF(env, _val));
+ tmp = g_slist_next (tmp);
+ }
+
+ /* clean up things */
+ JCL_free_cstring(env, node, dir);
+ g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
+ g_slist_free (entries);
+
+ return jlist;
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1nodes */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_suggest_sync
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1suggest_1sync
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)))
+{
+ GError *err = NULL;
+
+ gconf_client_suggest_sync (client, &err);
+ if (err != NULL) {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ err->message);
+ g_error_free (err);
+ err = NULL;
+ }
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1suggest_1sync */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_unset
+ * Signature: (Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1unset
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring key)
+{
+ const char *_key = NULL;
+ gboolean result = JNI_FALSE;
+
+ _key = JCL_jstring_to_cstring(env, key);
+ if (_key == NULL) {
+ return JNI_FALSE;
+ }
+
+ result = gconf_client_unset (client, _key, NULL);
+
+ JCL_free_cstring(env, key, _key);
+
+ return result;
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1unset */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_get_string
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1get_1string
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring key)
+{
+ const char *_key = NULL;
+ const char *_value = NULL;
+ jstring result = NULL;
+
+ _key = JCL_jstring_to_cstring(env, key);
+ if (_key == NULL) {
+ return NULL;
+ }
+
+ _value = gconf_client_get_string (client, _key, NULL);
+ JCL_free_cstring(env, key, _key);
+
+ result = (*env)->NewStringUTF (env, _value);
+ g_free ((gpointer) _value);
+
+ return result;
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1get_1string */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_set_string
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1set_1string
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)),
+ jstring key, jstring value)
+{
+ const char *_key = NULL;
+ const char *_value = NULL;
+
+ gboolean result = JNI_FALSE;
+
+ /* load an UTF string from the virtual machine. */
+ _key = JCL_jstring_to_cstring (env, key);
+ _value = JCL_jstring_to_cstring (env, value);
+ if (_key == NULL && _value == NULL) {
+ return JNI_FALSE;
+ }
+
+ result = gconf_client_set_string (client, _key, _value, NULL);
+
+ JCL_free_cstring (env, key, _key);
+ JCL_free_cstring (env, value, _value);
+
+ return (jboolean) result;
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1set_1string */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_remove_dir
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1remove_1dir
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+{
+ const char *dir = NULL;
+
+ dir = JCL_jstring_to_cstring (env, node);
+ if (dir == NULL)
+ return;
+
+ gconf_client_remove_dir (client, dir, NULL);
+
+ JCL_free_cstring (env, node, dir);
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1remove_1dir */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_add_dir
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1add_1dir
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+{
+ const char *dir = NULL;
+
+ dir = JCL_jstring_to_cstring (env, node);
+ if (dir == NULL)
+ return;
+
+ /* ignore errors */
+ gconf_client_add_dir (client, dir, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+
+ JCL_free_cstring (env, node, dir);
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1add_1dir */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: gconf_client_dir_exists
+ * Signature: (Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+{
+ const char *dir = NULL;
+ jboolean value = JNI_FALSE;
+
+ dir = JCL_jstring_to_cstring (env, node);
+ if (dir == NULL)
+ return value;
+
+ /* we ignore errors here */
+ value = gconf_client_dir_exists (client, dir, NULL);
+
+ JCL_free_cstring (env, node, dir);
+
+ return value;
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists */
+
+/*
+ * Class: gnu_java_util_prefs_gconf_GConfNativePeer
+ * Method: finalize_class
+ * Signature: ()V
+ */
+JNIEXPORT void
+JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)))
+{
+ if (reference_count == 0) {
+ /* last reference, free all resources and return */
+ g_object_unref (G_OBJECT (client));
+
+ (*env)->DeleteGlobalRef (env, jlist_class);
+
+ jlist_class = NULL;
+ jlist_init_id = NULL;
+ jlist_add_id = NULL;
+
+ return;
+ }
+
+ reference_count--;
+} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class */
+
+/* ***** END: NATIVE FUNCTIONS ***** */
+
+/* ***** PRIVATE FUNCTIONS IMPLEMENTATION ***** */
+
+static void throw_exception (JNIEnv *env, const char *msg)
+{
+ throw_exception_by_name (env, "java/lang/RuntimeException", msg);
+} /* throw_exception */
+
+static void
+throw_exception_by_name (JNIEnv *env, const char *name, const char *msg)
+{
+ JCL_ThrowException(env, name, msg);
+} /* throw_exception */
+
+static void init_gconf_client (void)
+{
+ client = gconf_client_get_default ();
+ g_type_init();
+} /* init_gconf_client */
+
+static gboolean set_jlist_class (JNIEnv *env)
+{
+ jclass local_jlist_class = NULL;
+
+ /* gets a reference to the ArrayList class */
+ local_jlist_class = JCL_FindClass (env, "java/util/ArrayList");
+ if (local_jlist_class == NULL) {
+ return FALSE;
+ }
+
+ jlist_class = (*env)->NewGlobalRef(env, local_jlist_class);
+ (*env)->DeleteLocalRef(env, local_jlist_class);
+ if (jlist_class == NULL) {
+ return FALSE;
+ }
+
+ /* and initialize it */
+ jlist_init_id = (*env)->GetMethodID (env, jlist_class, "<init>", "()V");
+ if (jlist_init_id == NULL) {
+ return FALSE;
+ }
+
+ jlist_add_id = (*env)->GetMethodID (env, jlist_class, "add",
+ "(Ljava/lang/Object;)Z");
+ if (jlist_add_id == NULL) {
+ return FALSE;
+ }
+
+ return TRUE;
+} /* set_jlist_class */
+
+static jobject get_jlist_reference (JNIEnv *env, jclass jlist_class)
+{
+ return (*env)->NewObject(env, jlist_class, jlist_init_id);
+} /* get_jlist_reference */
+
+/* ***** END: PRIVATE FUNCTIONS IMPLEMENTATION ***** */
diff --git a/native/jni/gconf-peer/Makefile.am b/native/jni/gconf-peer/Makefile.am
new file mode 100644
index 000000000..4c728fd8c
--- /dev/null
+++ b/native/jni/gconf-peer/Makefile.am
@@ -0,0 +1,14 @@
+nativeexeclib_LTLIBRARIES = libgconfpeer.la
+
+libgconfpeer_la_SOURCES = GConfNativePeer.c
+
+libgconfpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/native_state.lo \
+ $(top_builddir)/native/jni/classpath/jcl.lo
+
+AM_LDFLAGS = @CLASSPATH_MODULE@ @GCONF_LIBS@
+#@CLASSPATH_MODULE@ @GCONF_LIBS@ @CAIRO_LIBS@ @FREETYPE2_LIBS@ \
+# @PANGOFT2_LIBS@ @X_PRE_LIBS@ @X_LIBS@ @X_EXTRA_LIBS@ -lX11 -lXtst
+
+AM_CPPFLAGS = @CLASSPATH_INCLUDES@
+
+AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ @GCONF_CFLAGS@
diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
index d85ba326f..5927b21fa 100644
--- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
+++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
@@ -279,12 +279,13 @@ Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile
(JNIEnv *env, jobject obj __attribute__ ((unused)), jobject peer,
- jlong img, jint x, jint y, jint w, jint h)
+ jlong img, jint x, jint y, jint w, jint h, jint cx, jint cy, jint cw, jint ch)
{
GdkPixmap *pixmap;
GtkWidget *widget = NULL;
void *ptr = NULL;
GdkGC *gc;
+ GdkRectangle clip;
gdk_threads_enter();
ptr = NSA_GET_PTR (env, peer);
@@ -296,6 +297,13 @@ Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile
pixmap = JLONG_TO_PTR(GdkPixmap, img);
gc = gdk_gc_new(widget->window);
+
+ clip.x = cx;
+ clip.y = cy;
+ clip.width = cw;
+ clip.height = ch;
+ gdk_gc_set_clip_rectangle(gc, &clip);
+
gdk_draw_drawable(widget->window,
gc,
pixmap,
diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
index 74180a784..77021ceec 100644
--- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
+++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
@@ -147,7 +147,7 @@ Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont
}
JNIEXPORT void JNICALL
-Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText
+Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeText
(JNIEnv *env, jobject obj, jstring text)
{
const char *str;
diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
index 1c858faf5..c3ecb00c8 100644
--- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
+++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
@@ -246,7 +246,11 @@ exception statement from your version. */
#define VK_COMPOSE 65312
#define VK_ALT_GRAPH 65406
#define VK_UNDEFINED 0
+#define VK_BEGIN 65368
+#define VK_CONTEXT_MENU 525
+#define VK_WINDOWS 524
+
#define AWT_KEY_CHAR_UNDEFINED 0
#define AWT_FRAME_STATE_NORMAL 0
@@ -721,14 +725,28 @@ keysym_to_awt_keycode (GdkEventKey *event)
return VK_CUT;
return VK_COPY;
return VK_PASTE;
+ */
+ case GDK_Undo:
return VK_UNDO;
+ case GDK_Redo:
return VK_AGAIN;
+ /*
return VK_FIND;
return VK_PROPS;
return VK_STOP;
return VK_COMPOSE;
+ */
+ case GDK_ISO_Level3_Shift:
return VK_ALT_GRAPH;
+ /*
+ case VK_BEGIN:
*/
+ case GDK_Menu:
+ return VK_CONTEXT_MENU;
+ case GDK_Super_L:
+ case GDK_Super_R:
+ return VK_WINDOWS;
+
default:
return VK_UNDEFINED;
}
@@ -2115,14 +2133,27 @@ cp_gtk_awt_keycode_to_keysym (jint keyCode, jint keyLocation)
case VK_CUT:
case VK_COPY:
case VK_PASTE:
+ */
case VK_UNDO:
+ return GDK_Undo;
case VK_AGAIN:
+ return GDK_Redo;
+ /*
case VK_FIND:
case VK_PROPS:
case VK_STOP:
case VK_COMPOSE:
+ */
case VK_ALT_GRAPH:
+ return GDK_ISO_Level3_Shift;
+ /*
+ case VK_BEGIN:
*/
+ case VK_CONTEXT_MENU:
+ return GDK_Menu;
+ case VK_WINDOWS:
+ return GDK_Super_R;
+
default:
return GDK_VoidSymbol;
}
diff --git a/native/plugin/Makefile.am b/native/plugin/Makefile.am
index e1331fe45..d357e88ca 100644
--- a/native/plugin/Makefile.am
+++ b/native/plugin/Makefile.am
@@ -3,7 +3,7 @@ lib_LTLIBRARIES = libgcjwebplugin.la
libgcjwebplugin_la_SOURCES = gcjwebplugin.cc
libgcjwebplugin_la_CXXFLAGS = \
- -Wall -DAPPLETVIEWER_EXECUTABLE="\"$(bindir)/appletviewer\"" \
+ -Wall -DAPPLETVIEWER_EXECUTABLE="\"$(bindir)/gappletviewer\"" \
$(MOZILLA_CFLAGS) $(GLIB_CFLAGS) $(GTK_CFLAGS)
libgcjwebplugin_la_LDFLAGS = -avoid-version \
diff --git a/scripts/check_jni_methods.sh b/scripts/check_jni_methods.sh
index 999e143ec..ffdc7b571 100755
--- a/scripts/check_jni_methods.sh
+++ b/scripts/check_jni_methods.sh
@@ -37,6 +37,9 @@ cat > $TMPFILE3 << EOF
-Java_gnu_java_awt_peer_gtk_GtkMenuComponentPeer_dispose
-Java_java_lang_VMSystem_arraycopy
-Java_java_lang_VMSystem_identityHashCode
+-Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class
+-Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache
+-Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class
EOF
# Compare again silently.
diff --git a/tools/.cvsignore b/tools/.cvsignore
index 141547731..d2e24c413 100644
--- a/tools/.cvsignore
+++ b/tools/.cvsignore
@@ -5,3 +5,6 @@ Makefile
tools.zip
appletviewer
.deps
+gappletviewer
+gjarsigner
+gkeytool
diff --git a/tools/gnu/classpath/tools/getopt/Parser.java b/tools/gnu/classpath/tools/getopt/Parser.java
index 082cf8945..3c6cf6f46 100644
--- a/tools/gnu/classpath/tools/getopt/Parser.java
+++ b/tools/gnu/classpath/tools/getopt/Parser.java
@@ -316,6 +316,9 @@ public class Parser
int eq = option.indexOf('=');
if (eq != - 1)
justName = option.substring(0, eq);
+ char shortName = 0;
+ if (justName.length() == 1)
+ shortName = justName.charAt(0);
Option found = null;
for (int i = options.size() - 1; i >= 0; --i)
{
@@ -325,6 +328,11 @@ public class Parser
found = opt;
break;
}
+ if (shortName != 0 && opt.getShortName() == shortName)
+ {
+ found = opt;
+ break;
+ }
}
if (found == null)
{
diff --git a/vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java b/vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java
new file mode 100644
index 000000000..c1c7d13dd
--- /dev/null
+++ b/vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java
@@ -0,0 +1,89 @@
+/* VMClassLoadingMXBeanImpl.java - VM impl. of a class loading bean
+ Copyright (C) 2006 Free Software Foundation
+
+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.lang.management;
+
+/**
+ * Provides access to information about the class loading
+ * behaviour of the current invocation of the virtual
+ * machine. Instances of this bean are obtained by calling
+ * {@link ManagementFactory#getClassLoadingMXBean()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+final class VMClassLoadingMXBeanImpl
+{
+
+ /**
+ * Returns the number of classes currently loaded by
+ * the virtual machine.
+ *
+ * @return the number of loaded classes.
+ */
+ static native int getLoadedClassCount();
+
+ /**
+ * Returns the number of classes that have been unloaded
+ * by the virtual machine since it was started.
+ *
+ * @return the number of unloaded classes.
+ */
+ static native long getUnloadedClassCount();
+
+ /**
+ * Returns true if the virtual machine will emit additional
+ * information when classes are loaded and unloaded. The
+ * format of the output is left up to the virtual machine.
+ *
+ * @return true if verbose class loading output is on.
+ */
+ static native boolean isVerbose();
+
+ /**
+ * Turns on or off the emission of additional information
+ * when classes are loaded and unloaded. The format of the
+ * output is left up to the virtual machine. This method
+ * may be called by multiple threads concurrently, but there
+ * is only one global setting of verbosity that is affected.
+ *
+ * @param verbose the new setting for verbose class loading
+ * output.
+ */
+ static native void setVerbose(boolean verbose);
+
+}
diff --git a/vm/reference/java/lang/VMThread.java b/vm/reference/java/lang/VMThread.java
index 302de6c35..ff0ec6878 100644
--- a/vm/reference/java/lang/VMThread.java
+++ b/vm/reference/java/lang/VMThread.java
@@ -446,4 +446,16 @@ final class VMThread
return false;
}
}
+
+ /**
+ * Returns the current state of the thread.
+ * The value must be one of "BLOCKED", "NEW",
+ * "RUNNABLE", "TERMINATED", "TIMED_WAITING" or
+ * "WAITING".
+ *
+ * @return a string corresponding to one of the
+ * thread enumeration states specified above.
+ */
+ native String getState();
+
}
diff --git a/vm/reference/java/lang/management/VMThreadInfo.java b/vm/reference/java/lang/management/VMThreadInfo.java
new file mode 100644
index 000000000..162fe6794
--- /dev/null
+++ b/vm/reference/java/lang/management/VMThreadInfo.java
@@ -0,0 +1,159 @@
+/* VMThreadInfo.java - Information on a thread
+ Copyright (C) 2006 Free Software Foundation
+
+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 java.lang.management;
+
+/**
+ * Provides low-level information about a thread.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ * @see java.lang.management.ThreadInfo
+ */
+final class VMThreadInfo
+{
+
+ /**
+ * Return the number of times the specified thread
+ * has been in the {@link java.lang.Thread.State#BLOCKED}
+ * state.
+ *
+ * @param thread the thread to return statistics on.
+ * @return the number of times the thread has been blocked.
+ */
+ static native long getBlockedCount(Thread thread);
+
+ /**
+ * Returns the accumulated number of milliseconds the
+ * specified thread has spent in the
+ * {@link java.lang.Thread.State#BLOCKED} state. This
+ * method is only called if thread contention monitoring
+ * is both supported and enabled.
+ *
+ * @param thread the thread to return statistics on.
+ * @return the accumulated number of milliseconds the
+ * thread has been blocked for.
+ */
+ static native long getBlockedTime(Thread thread);
+
+ /**
+ * Returns the monitor lock the specified thread is
+ * waiting for. This is only called when the thread
+ * is in the {@link java.lang.Thread.State#BLOCKED}
+ * state.
+ *
+ * @param thread the thread to return statistics on.
+ * @return the monitor lock the thread is waiting for.
+ */
+ static native Object getLock(Thread thread);
+
+ /**
+ * Returns the thread which currently owns the monitor
+ * lock the specified thread is waiting for. This is
+ * only called when the thread is in the
+ * {@link java.lang.Thread.State#BLOCKED} state. It
+ * may return <code>null</code> if the lock is not held
+ * by another thread.
+ *
+ * @param thread the thread to return statistics on.
+ * @return the thread which owns the monitor lock the
+ * thread is waiting for, or <code>null</code>
+ * if it doesn't have an owner.
+ */
+ static native Thread getLockOwner(Thread thread);
+
+ /**
+ * Return the number of times the specified thread
+ * has been in the {@link java.lang.Thread.State#WAITING}
+ * or {@link java.lang.Thread.State#TIMED_WAITING} states.
+ *
+ * @param thread the thread to return statistics on.
+ * @return the number of times the thread has been in
+ * waiting state.
+ */
+ static native long getWaitedCount(Thread thread);
+
+ /**
+ * Returns the accumulated number of milliseconds the
+ * specified thread has spent in either the
+ * {@link java.lang.Thread.State#WAITING} or
+ * {@link java.lang.Thread.State#TIMED_WAITING} states.
+ * This method is only called if thread contention
+ * monitoring is both supported and enabled.
+ *
+ * @param thread the thread to return statistics on.
+ * @return the accumulated number of milliseconds the
+ * thread has been in a waiting state for.
+ */
+ static native long getWaitedTime(Thread thread);
+
+ /**
+ * Returns true if the specified thread is in a native
+ * method.
+ *
+ * @param thread the thread to return statistics on.
+ * @return true if the thread is in a native method, false
+ * otherwise.
+ */
+ static native boolean isInNative(Thread thread);
+
+ /**
+ * Returns true if the specified thread is suspended.
+ *
+ * @param thread the thread to return statistics on.
+ * @return true if the thread is suspended, false otherwise.
+ */
+ static native boolean isSuspended(Thread thread);
+
+ /**
+ * Returns a stack trace for the specified thread of
+ * the supplied depth. If the depth is
+ * <code>Integer.MAX_VALUE</code>, then the returned
+ * depth is equal to the full stack trace available.
+ * The depth will be greater than zero, due to
+ * filtering in methods prior to this call.
+ *
+ * @param thread the thread whose stack trace should
+ * be returned.
+ * @param maxDepth the maximum depth of the trace.
+ * This will be greater than zero.
+ * <code>Integer.MAX_VALUE</code>
+ * represents the full trace.
+ */
+ static native StackTraceElement[] getStackTrace(Thread thread,
+ int maxDepth);
+}