diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-14 23:12:35 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-14 23:12:35 +0000 |
commit | ffde862e033a0825e1e9972a89c0f1f80b261a8e (patch) | |
tree | 97037d2c09c8384d80531f67ec36a01205df6bdb /libjava/classpath/gnu/javax/crypto/jce/cipher | |
parent | b415ff10527e977c3758234fd930e2c027bfa17d (diff) | |
download | ppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.tar.gz ppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.zip |
2006-08-14 Mark Wielaard <mark@klomp.org>
Imported GNU Classpath 0.92
* HACKING: Add more importing hints. Update automake version
requirement.
* configure.ac (gconf-peer): New enable AC argument.
Add --disable-gconf-peer and --enable-default-preferences-peer
to classpath configure when gconf is disabled.
* scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and
gnu/java/awt/dnd/peer/gtk to bc. Classify
gnu/java/security/Configuration.java as generated source file.
* gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java,
gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java,
gnu/java/lang/management/VMClassLoadingMXBeanImpl.java,
gnu/java/lang/management/VMRuntimeMXBeanImpl.java,
gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java,
gnu/java/lang/management/VMThreadMXBeanImpl.java,
gnu/java/lang/management/VMMemoryMXBeanImpl.java,
gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub
classes.
* java/lang/management/VMManagementFactory.java: Likewise.
* java/net/VMURLConnection.java: Likewise.
* gnu/java/nio/VMChannel.java: Likewise.
* java/lang/Thread.java (getState): Add stub implementation.
* java/lang/Class.java (isEnum): Likewise.
* java/lang/Class.h (isEnum): Likewise.
* gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed.
* javax/naming/spi/NamingManager.java: New override for StackWalker
functionality.
* configure, sources.am, Makefile.in, gcj/Makefile.in,
include/Makefile.in, testsuite/Makefile.in: Regenerated.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116139 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/gnu/javax/crypto/jce/cipher')
21 files changed, 1187 insertions, 505 deletions
diff --git a/libjava/classpath/gnu/javax/crypto/jce/cipher/AES128KeyWrapSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/AES128KeyWrapSpi.java new file mode 100644 index 00000000000..14ce480ae6f --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/jce/cipher/AES128KeyWrapSpi.java @@ -0,0 +1,54 @@ +/* AESKeyWrapSpi.java -- AES (128-bit key) Key Wrapping Algorithm JCE Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto.jce.cipher; + +import gnu.java.security.Registry; + +/** + * The JCE Cipher Adapter implementation over the GNU AES Key Wrapping + * Algorithm with a 128-bit key-size. + */ +public final class AES128KeyWrapSpi + extends AESKeyWrapSpi +{ + public AES128KeyWrapSpi() + { + super(Registry.AES128_KWA, 128 / 8, Registry.ECB_MODE); + } +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/cipher/AES192KeyWrapSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/AES192KeyWrapSpi.java new file mode 100644 index 00000000000..784fc5a1516 --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/jce/cipher/AES192KeyWrapSpi.java @@ -0,0 +1,54 @@ +/* AES192KeyWrapSpi.java -- AES (192-bit key) Key Wrapping Algorithm JCE Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto.jce.cipher; + +import gnu.java.security.Registry; + +/** + * The JCE Cipher Adapter implementation over the GNU AES Key Wrapping + * Algorithm with a 192-bit key-size. + */ +public final class AES192KeyWrapSpi + extends AESKeyWrapSpi +{ + public AES192KeyWrapSpi() + { + super(Registry.AES192_KWA, 192 / 8, Registry.ECB_MODE); + } +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/cipher/AES256KeyWrapSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/AES256KeyWrapSpi.java new file mode 100644 index 00000000000..dd7357b0e09 --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/jce/cipher/AES256KeyWrapSpi.java @@ -0,0 +1,54 @@ +/* AES256KeyWrapSpi.java -- AES (256-bit key) Key Wrapping Algorithm JCE Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto.jce.cipher; + +import gnu.java.security.Registry; + +/** + * The JCE Cipher Adapter implementation over the GNU AES Key Wrapping + * Algorithm with a 256-bit key-size. + */ +public final class AES256KeyWrapSpi + extends AESKeyWrapSpi +{ + public AES256KeyWrapSpi() + { + super(Registry.AES256_KWA, 256 / 8, Registry.ECB_MODE); + } +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/cipher/AESKeyWrapSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/AESKeyWrapSpi.java new file mode 100644 index 00000000000..973f5890bb4 --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/jce/cipher/AESKeyWrapSpi.java @@ -0,0 +1,88 @@ +/* AESKeyWrapSpi.java -- Common AES Key Wrapping Algorithm 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.javax.crypto.jce.cipher; + +/** + * Base abstract class to group common AES Key Wrapping Algorithm Adapter + * methods. + */ +abstract class AESKeyWrapSpi + extends KeyWrappingAlgorithmAdapter +{ + protected AESKeyWrapSpi(String name, int keySize, String supportedMode) + { + super(name, 16, keySize, supportedMode); + } + + /** + * AES Key Wrapping algorithms operate on an 8-byte block; a block half the + * size of the AES block itself. + * <p> + * In wrapping, the number of 8-byte output blocks is ALWAYS one block longer + * than the input. + * + * @param inputLength the size of the plain text. + * @return the size in bytes of <code>n + 1</code> 8-byte blocks where + * <code>n</code> is the smallest number of 8-byte blocks that contain the + * designated number of input bytes. + */ + protected int getOutputSizeForWrap(int inputLength) + { + int n = (inputLength + 7) / 8; + return 8 * (n + 1); + } + + /** + * AES Key Wrapping algorithms operate on an 8-byte block; a block half the + * size of the AES block itself. + * <p> + * In unwrapping, the number of 8-byte output blocks is ALWAYS one block + * shorter than the input. + * + * @param inputLength the size of the cipher text. + * @return the size in bytes of <code>n - 1</code> 8-byte blocks where + * <code>n</code> is the smallest number of 8-byte blocks that contain the + * designated number of input bytes. + */ + protected int getOutputSizeForUnwrap(int inputLength) + { + int n = (inputLength + 7) / 8; + return 8 * (n - 1); + } +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/cipher/AESSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/AESSpi.java index 33de6895613..1322e5e8a1a 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/AESSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/ARCFourSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/ARCFourSpi.java index 963fa1c0081..abcb486b59b 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/ARCFourSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/AnubisSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/AnubisSpi.java index 0fca3b49104..e35e4e724ac 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/AnubisSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/BlowfishSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/BlowfishSpi.java index d31d7e19390..fec200ca6c9 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/BlowfishSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/Cast5Spi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/Cast5Spi.java index b1d4cf70374..bf080340001 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/Cast5Spi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/CipherAdapter.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/CipherAdapter.java index 5eaa31b779b..b7cd755f5b4 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/CipherAdapter.java +++ b/libjava/classpath/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; @@ -56,6 +57,7 @@ import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.InvalidParameterSpecException; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import javax.crypto.BadPaddingException; @@ -67,61 +69,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.crypto.Registry}. - * The basic cipher instance is created, along with an instance of the - * {@link gnu.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 +120,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 +134,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 +147,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 +157,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 +172,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 +192,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,25 +223,75 @@ 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(); + int kbLength = kb.length; if (keyLen == 0) { - keyLen = kb.length; + // no key-size given; instead key-material is provided in kb --which + // can be more than what we need. if we don't cull this down to what + // the cipher likes/wants we may get an InvalidKeyException. + // + // try to find the largest key-size value that is less than or equal + // to kbLength + for (Iterator it = cipher.keySizes(); it.hasNext();) + { + int aKeySize = ((Integer) it.next()).intValue(); + if (aKeySize == kbLength) + { + keyLen = aKeySize; + break; + } + else if (aKeySize < kbLength) + keyLen = aKeySize; + else // all remaining key-sizes are longer than kb.length + break; + } } - else if (keyLen < kb.length) + if (keyLen == 0) + { + // we were unable to find a key-size, among those advertised by the + // cipher, that is less than or equal to the length of the kb array. + // set keyLen to kbLength. either the cipher implementation will throw + // an InvalidKeyException, or it is implemented in a way which can deal + // with an unsupported key-size. + keyLen = kbLength; + } + if (keyLen < kbLength) { byte[] kbb = kb; kb = new byte[keyLen]; @@ -280,31 +307,54 @@ 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) { + // The size of the IV must match the block size + if (((IvParameterSpec) params).getIV().length != cipher.defaultBlockSize()) + { + throw new InvalidAlgorithmParameterException(); + } + 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 +365,7 @@ class CipherAdapter extends CipherSpi try { if (params != null) - { - spec = params.getParameterSpec(BlockCipherParameterSpec.class); - } + spec = params.getParameterSpec(BlockCipherParameterSpec.class); } catch (InvalidParameterSpecException ignored) { @@ -334,91 +382,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 +465,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 +488,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/libjava/classpath/gnu/javax/crypto/jce/cipher/DESSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/DESSpi.java index ff86071c4ee..21f62b4f046 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/DESSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/KeyWrappingAlgorithmAdapter.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/KeyWrappingAlgorithmAdapter.java new file mode 100644 index 00000000000..03356a236f7 --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/jce/cipher/KeyWrappingAlgorithmAdapter.java @@ -0,0 +1,423 @@ +/* KeyWrappingAlgorithmAdapter.java -- Base Adapter for Key Wrapping algorithms + 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.crypto.jce.cipher; + +import gnu.java.security.Configuration; +import gnu.java.security.Registry; +import gnu.javax.crypto.jce.spec.BlockCipherParameterSpec; +import gnu.javax.crypto.kwa.IKeyWrappingAlgorithm; +import gnu.javax.crypto.kwa.KeyUnwrappingException; +import gnu.javax.crypto.kwa.KeyWrappingAlgorithmFactory; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.InvalidParameterSpecException; +import java.security.spec.X509EncodedKeySpec; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.CipherSpi; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.ShortBufferException; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * An abstract base class to facilitate implementations of JCE Adapters for + * symmetric key block ciphers capable of providing key-wrapping functionality. + */ +abstract class KeyWrappingAlgorithmAdapter + extends CipherSpi +{ + private static final Logger log = Logger.getLogger(KeyWrappingAlgorithmAdapter.class.getName()); + /** JCE canonical name of a null-padder. */ + private static final String NO_PADDING = "nopadding"; + /** Concrete Key Wrapping Algorithm SPI. */ + protected IKeyWrappingAlgorithm kwAlgorithm; + /** Size in bytes of the padding block to be provided by external padders. */ + protected int kwaBlockSize; + /** KEK size in bytes. */ + protected int kwaKeySize; + /** Name of the supported mode. */ + protected String supportedMode; + /** Operational mode in which this instance was initialised. */ + protected int opmode = -1; + /** Initialisation Vector if/when user wants to override default one. */ + byte[] iv; + + /** + * Creates a new JCE Adapter for the designated Key Wrapping Algorithm name. + * + * @param name the canonical name of the key-wrapping algorithm. + * @param blockSize the block size in bytes of the underlying symmetric-key + * block cipher algorithm. + * @param keySize the allowed size in bytes of the KEK bytes to initialise the + * underlying symmetric-key block cipher algorithm with. + * @param supportedMode canonical name of the block mode the underlying cipher + * is supporting. + */ + protected KeyWrappingAlgorithmAdapter(String name, int blockSize, int keySize, + String supportedMode) + { + super(); + + this.kwAlgorithm = KeyWrappingAlgorithmFactory.getInstance(name); + this.kwaBlockSize = blockSize; + this.kwaKeySize = keySize; + this.supportedMode = supportedMode; + } + + /** + * Wraps the encoded form of a designated {@link Key}. + * + * @param key the key-material to wrap. + * @return the wrapped key. + * @throws InvalidKeyException If the key cannot be wrapped. + */ + protected byte[] engineWrap(Key key) + throws InvalidKeyException, IllegalBlockSizeException + { + byte[] keyMaterial = key.getEncoded(); + byte[] result = kwAlgorithm.wrap(keyMaterial, 0, keyMaterial.length); + return result; + } + + /** + * Unwraps a previously-wrapped key-material. + * + * @param wrappedKey the wrapped key-material to unwrap. + * @param wrappedKeyAlgorithm the canonical name of the algorithm, which the + * unwrapped key-material represents. This name is used to + * instantiate a concrete instance of a {@link Key} for that + * algorithm. For example, if the value of this parameter is + * <code>DSS</code> and the type (the next parameter) is + * {@link Cipher#PUBLIC_KEY} then an attempt to construct a concrete + * instance of a {@link java.security.interfaces.DSAPublicKey}, + * using the unwrapped key material, shall be made. + * @param wrappedKeyType the type of wrapped key-material. MUST be one of + * {@link Cipher#PRIVATE_KEY}, {@link Cipher#PUBLIC_KEY}, or + * {@link Cipher#SECRET_KEY}. + * @return the unwrapped key-material as an instance of {@link Key} or one of + * its subclasses. + * @throws InvalidKeyException If the key cannot be unwrapped, or if + * <code>wrappedKeyType</code> is an inappropriate type for the + * unwrapped key. + * @throws NoSuchAlgorithmException If the <code>wrappedKeyAlgorithm</code> + * is unknown to every currently installed Security Provider. + */ + protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, + int wrappedKeyType) + throws InvalidKeyException, NoSuchAlgorithmException + { + byte[] keyBytes; + try + { + keyBytes = kwAlgorithm.unwrap(wrappedKey, 0, wrappedKey.length); + } + catch (KeyUnwrappingException x) + { + InvalidKeyException y = new InvalidKeyException("engineUnwrap()"); + y.initCause(x); + throw y; + } + Key result; + switch (wrappedKeyType) + { + case Cipher.SECRET_KEY: + result = new SecretKeySpec(keyBytes, wrappedKeyAlgorithm); + break; + case Cipher.PRIVATE_KEY: + case Cipher.PUBLIC_KEY: + X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); + KeyFactory keyFactory = KeyFactory.getInstance(wrappedKeyAlgorithm); + try + { + if (wrappedKeyType == Cipher.PRIVATE_KEY) + result = keyFactory.generatePrivate(keySpec); + else + result = keyFactory.generatePublic(keySpec); + } + catch (InvalidKeySpecException x) + { + InvalidKeyException y = new InvalidKeyException("engineUnwrap()"); + y.initCause(x); + throw y; + } + break; + default: + IllegalArgumentException x = new IllegalArgumentException("Invalid 'wrappedKeyType': " + + wrappedKeyType); + InvalidKeyException y = new InvalidKeyException("engineUnwrap()"); + y.initCause(x); + throw y; + } + return result; + } + + protected int engineGetBlockSize() + { + return kwaBlockSize; + } + + protected byte[] engineGetIV() + { + return iv == null ? null : (byte[]) iv.clone(); + } + + protected int engineGetOutputSize(int inputLength) + { + switch (opmode) + { + case Cipher.WRAP_MODE: + return getOutputSizeForWrap(inputLength); + case Cipher.UNWRAP_MODE: + return getOutputSizeForUnwrap(inputLength); + default: + throw new IllegalStateException(); + } + } + + protected AlgorithmParameters engineGetParameters() + { + BlockCipherParameterSpec spec = new BlockCipherParameterSpec(iv, + kwaBlockSize, + kwaKeySize); + AlgorithmParameters result = null; + try + { + result = AlgorithmParameters.getInstance("BlockCipherParameters"); + result.init(spec); + } + catch (NoSuchAlgorithmException x) + { + if (Configuration.DEBUG) + log.fine("Unable to find BlockCipherParameters. Return null"); + } + catch (InvalidParameterSpecException x) + { + if (Configuration.DEBUG) + log.fine("Unable to initialise BlockCipherParameters. Return null"); + } + return result; + } + + protected void engineInit(int opmode, Key key, SecureRandom random) + throws InvalidKeyException + { + checkOpMode(opmode); + byte[] kekBytes = checkAndGetKekBytes(key); + initAlgorithm(opmode, kekBytes, null, random); + } + + protected void engineInit(int opmode, Key key, AlgorithmParameters params, + SecureRandom random) + throws InvalidAlgorithmParameterException, InvalidKeyException + { + AlgorithmParameterSpec spec = null; + try + { + if (params != null) + spec = params.getParameterSpec(BlockCipherParameterSpec.class); + } + catch (InvalidParameterSpecException x) + { + if (Configuration.DEBUG) + log.fine("Unable to translate algorithm parameters into an instance " + + "of BlockCipherParameterSpec. Discard"); + } + engineInit(opmode, key, spec, random); + } + + protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, + SecureRandom random) + throws InvalidAlgorithmParameterException, InvalidKeyException + { + checkOpMode(opmode); + byte[] kekBytes = checkAndGetKekBytes(key); + byte[] ivBytes = null; + if (params instanceof BlockCipherParameterSpec) + ivBytes = ((BlockCipherParameterSpec) params).getIV(); + else if (params instanceof IvParameterSpec) + ivBytes = ((IvParameterSpec) params).getIV(); + + initAlgorithm(opmode, kekBytes, ivBytes, random); + } + + protected void engineSetMode(String mode) throws NoSuchAlgorithmException + { + if (! supportedMode.equalsIgnoreCase(mode)) + throw new UnsupportedOperationException("Only " + supportedMode + + " is supported"); + } + + /** + * NoPadding is the only padding algorithm supported by Key Wrapping Algorithm + * implementations in RI. + */ + protected void engineSetPadding(String padding) throws NoSuchPaddingException + { + if (! NO_PADDING.equalsIgnoreCase(padding)) + throw new UnsupportedOperationException("Only NoPadding is supported"); + } + + protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLength) + { + throw new UnsupportedOperationException(); + } + + protected int engineUpdate(byte[] input, int inputOffset, int inputLength, + byte[] output, int outputOffset) + throws ShortBufferException + { + throw new UnsupportedOperationException(); + } + + protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLength) + throws IllegalBlockSizeException, BadPaddingException + { + throw new UnsupportedOperationException(); + } + + protected int engineDoFinal(byte[] input, int inputOffset, int inputLength, + byte[] output, int outputOffset) + throws IllegalBlockSizeException, BadPaddingException, ShortBufferException + { + throw new UnsupportedOperationException(); + } + + /** + * Return the minimum size in bytes of a place holder large enough to receive + * the cipher text resulting from a wrap method with the designated size of + * the plain text. + * <p> + * This default implementation ALWAYS returns the smallest multiple of the + * <code>kwaBlockSize</code> --passed to this method through its + * constructor-- greater than or equal to the designated + * <code>inputLength</code>. + * + * @param inputLength the size of a plain text. + * @return an estimate of the size, in bytes, of the place holder to receive + * the resulting bytes of a wrap method. + */ + protected int getOutputSizeForWrap(int inputLength) + { + return kwaBlockSize * (inputLength + kwaBlockSize - 1) / kwaBlockSize; + } + + /** + * Return the minimum size in bytes of a place holder large enough to receive + * the plain text resulting from an unwrap method with the designated size of + * the cipher text. + * <p> + * This default implementation ALWAYS returns the smallest multiple of the + * <code>paddingBlockSize</code> --passed to this method through its + * constructor-- greater than or equal to the designated + * <code>inputLength</code>. + * + * @param inputLength the size of a cipher text. + * @return an estimate of the size, in bytes, of the place holder to receive + * the resulting bytes of an uwrap method. + */ + protected int getOutputSizeForUnwrap(int inputLength) + { + return kwaBlockSize * (inputLength + kwaBlockSize - 1) / kwaBlockSize; + } + + private void checkOpMode(int opmode) + { + switch (opmode) + { + case Cipher.WRAP_MODE: + case Cipher.UNWRAP_MODE: + return; + } + throw new IllegalArgumentException("Unsupported operational mode: " + opmode); + } + + /** + * Returns the key bytes, iff it was in RAW format. + * + * @param key the opaque JCE secret key to use as the KEK. + * @return the bytes of the encoded form of the designated kek, iff it was in + * RAW format. + * @throws InvalidKeyException if the designated key is not in the RAW format. + */ + private byte[] checkAndGetKekBytes(Key key) throws InvalidKeyException + { + if (! Registry.RAW_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat())) + throw new InvalidKeyException("Only RAW key format is supported"); + byte[] result = key.getEncoded(); + int kekSize = result.length; + if (kekSize != kwaKeySize) + throw new InvalidKeyException("Invalid key material size. Expected " + + kwaKeySize + " but found " + kekSize); + return result; + } + + private void initAlgorithm(int opmode, byte[] kek, byte[] ivBytes, + SecureRandom rnd) + throws InvalidKeyException + { + this.opmode = opmode; + Map attributes = new HashMap(); + attributes.put(IKeyWrappingAlgorithm.KEY_ENCRYPTION_KEY_MATERIAL, kek); + if (ivBytes != null) + { + this.iv = (byte[]) ivBytes.clone(); + attributes.put(IKeyWrappingAlgorithm.INITIAL_VALUE, this.iv); + } + else + this.iv = null; + if (rnd != null) + attributes.put(IKeyWrappingAlgorithm.SOURCE_OF_RANDOMNESS, rnd); + + kwAlgorithm.init(attributes); + } +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/cipher/KhazadSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/KhazadSpi.java index 397c27d2ed7..6e744a2f2d9 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/KhazadSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/NullCipherSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/NullCipherSpi.java index e6d78ef393e..e50e00c8eae 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/NullCipherSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/PBES2.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/PBES2.java index 9889ab9fc86..26a6a2c2db9 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/PBES2.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/RijndaelSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/RijndaelSpi.java index 137db2c3fa4..ad61bca599d 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/RijndaelSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/SerpentSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/SerpentSpi.java index 9df9685cc38..fa65d34a9be 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/SerpentSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/SquareSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/SquareSpi.java index 96e5dee38b1..bdc656eaedb 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/SquareSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/TripleDESKeyWrapSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/TripleDESKeyWrapSpi.java new file mode 100644 index 00000000000..55087755e21 --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/jce/cipher/TripleDESKeyWrapSpi.java @@ -0,0 +1,54 @@ +/* TripleDESKeyWrapSpi.java -- DES-EDE Key Wrapping Algorithm JCE Adapter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto.jce.cipher; + +import gnu.java.security.Registry; + +/** + * The JCE Cipher Adapter implementation over the GNU TripleDES Key Wrapping + * Algorithm. + */ +public final class TripleDESKeyWrapSpi + extends KeyWrappingAlgorithmAdapter +{ + public TripleDESKeyWrapSpi() + { + super(Registry.TRIPLEDES_KWA, 8, 192 / 8, Registry.CBC_MODE); + } +} diff --git a/libjava/classpath/gnu/javax/crypto/jce/cipher/TripleDESSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/TripleDESSpi.java index 5c58ea5515e..b9ec12b5110 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/TripleDESSpi.java +++ b/libjava/classpath/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/libjava/classpath/gnu/javax/crypto/jce/cipher/TwofishSpi.java b/libjava/classpath/gnu/javax/crypto/jce/cipher/TwofishSpi.java index 31df5ea4068..206e0d9f877 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/cipher/TwofishSpi.java +++ b/libjava/classpath/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); |