From ffde862e033a0825e1e9972a89c0f1f80b261a8e Mon Sep 17 00:00:00 2001
From: mark
Date: Mon, 14 Aug 2006 23:12:35 +0000
Subject: 2006-08-14 Mark Wielaard
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
---
.../classpath/gnu/javax/crypto/mode/BaseMode.java | 153 +++++++--------------
libjava/classpath/gnu/javax/crypto/mode/CBC.java | 62 +++------
libjava/classpath/gnu/javax/crypto/mode/CFB.java | 116 +++++++---------
libjava/classpath/gnu/javax/crypto/mode/CTR.java | 127 +++++------------
libjava/classpath/gnu/javax/crypto/mode/EAX.java | 127 +++++------------
libjava/classpath/gnu/javax/crypto/mode/ECB.java | 74 ++++------
.../gnu/javax/crypto/mode/IAuthenticatedMode.java | 18 ++-
libjava/classpath/gnu/javax/crypto/mode/ICM.java | 139 +++++++------------
libjava/classpath/gnu/javax/crypto/mode/IMode.java | 114 +++++++--------
.../gnu/javax/crypto/mode/ModeFactory.java | 95 ++++---------
libjava/classpath/gnu/javax/crypto/mode/OFB.java | 128 ++++++++---------
11 files changed, 395 insertions(+), 758 deletions(-)
(limited to 'libjava/classpath/gnu/javax/crypto/mode')
diff --git a/libjava/classpath/gnu/javax/crypto/mode/BaseMode.java b/libjava/classpath/gnu/javax/crypto/mode/BaseMode.java
index 0a9ab2dab1c..6d9418ccafa 100644
--- a/libjava/classpath/gnu/javax/crypto/mode/BaseMode.java
+++ b/libjava/classpath/gnu/javax/crypto/mode/BaseMode.java
@@ -49,46 +49,34 @@ import java.util.Iterator;
import java.util.Map;
/**
- * A basic abstract class to facilitate implementing block cipher modes of
- * operations. Trivial constructor for use by concrete subclasses. Returns the default value, in bytes, of the mode's block size. This
- * value is part of the construction arguments passed to the Factory methods
- * in {@link ModeFactory}. Unless changed by an invocation of any of the
+ * Returns the default value, in bytes, of the mode's block size. This value
+ * is part of the construction arguments passed to the Factory methods in
+ * {@link ModeFactory}. Unless changed by an invocation of any of the
* Returns the default value, in bytes, of the underlying block cipher
- * key size. Returns an {@link Iterator} over the supported block sizes. Each
- * element returned by this object is an {@link Integer}. The default behaviour is to return an iterator with just one value,
- * which is that currently configured for the underlying block cipher.
- * Concrete implementations may override this behaviour to signal their
- * ability to support other values.
+ * The default behaviour is to return an iterator with just one value, which
+ * is that currently configured for the underlying block cipher. Concrete
+ * implementations may override this behaviour to signal their ability to
+ * support other values.
+ *
* @return an {@link Iterator} over the supported block sizes.
*/
public Iterator blockSizes()
{
ArrayList al = new ArrayList();
- al.add(new Integer(cipherBlockSize));
-
+ al.add(Integer.valueOf(cipherBlockSize));
return Collections.unmodifiableList(al).iterator();
}
/**
- * Returns an {@link Iterator} over the supported underlying block cipher
- * key sizes. Each element returned by this object is an instance of
- * {@link Integer}.init() methods, a Mode instance would operate with
* the same block size as its underlying block cipher. As mentioned earlier,
- * the block size of the underlying block cipher itself is specified in one
- * of the method(s) available in the factory class.
- * - *Ci = EK(Pi ^ - * Ci-1
Similarly, decrypting is:
- * - *+ * The Cipher Block Chaining mode. This mode introduces feedback into the cipher + * by XORing the previous ciphertext block with the plaintext block before + * encipherment. That is, encrypting looks like this: + * + *Pi = Ci-1 ^ - * DK(Ci)
+ * Ci = EK(Piˆ Ci-1) + *+ *
+ * Similarly, decrypting is: + *
+ * Pi = Ci-1 ˆ DK(Ci) + **/ -public class CBC extends BaseMode implements Cloneable +public class CBC + extends BaseMode + implements Cloneable { - - // Constants and Variables - //------------------------------------------------------------------ - /** The last (de|en)crypted block */ private byte[] lastBlock; - /** An intermediate buffer. */ private byte[] scratch; - // Constructors - // ----------------------------------------------------------------- - /** * Package-private constructor for the factory class. - * + * * @param underlyingCipher The cipher implementation. * @param cipherBlockSize The cipher's block size. */ @@ -86,31 +81,20 @@ public class CBC extends BaseMode implements Cloneable this((IBlockCipher) that.cipher.clone(), that.cipherBlockSize); } - // Cloneable interface implementation - // ----------------------------------------------------------------- - public Object clone() { return new CBC(this); } - // Implementation of abstract methods in BaseMode - // ----------------------------------------------------------------- - public void setup() { if (modeBlockSize != cipherBlockSize) - { - throw new IllegalArgumentException(); - } + throw new IllegalArgumentException(); scratch = new byte[cipherBlockSize]; lastBlock = new byte[cipherBlockSize]; - // lastBlock gets initialized to the initialization vector. for (int i = 0; i < lastBlock.length && i < iv.length; i++) - { - lastBlock[i] = iv[i]; - } + lastBlock[i] = iv[i]; } public void teardown() @@ -122,9 +106,7 @@ public class CBC extends BaseMode implements Cloneable public void encryptBlock(byte[] in, int i, byte[] out, int o) { for (int k = 0; k < scratch.length; k++) - { - scratch[k] = (byte) (lastBlock[k] ^ in[k + i]); - } + scratch[k] = (byte)(lastBlock[k] ^ in[k + i]); cipher.encryptBlock(scratch, 0, out, o); System.arraycopy(out, o, lastBlock, 0, cipherBlockSize); } @@ -135,9 +117,7 @@ public class CBC extends BaseMode implements Cloneable System.arraycopy(in, i, buf, 0, cipherBlockSize); cipher.decryptBlock(in, i, scratch, 0); for (int k = 0; k < scratch.length; k++) - { - out[o + k] = (byte) (lastBlock[k] ^ scratch[k]); - } + out[o + k] = (byte)(lastBlock[k] ^ scratch[k]); System.arraycopy(buf, 0, lastBlock, 0, cipherBlockSize); } -} \ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/mode/CFB.java b/libjava/classpath/gnu/javax/crypto/mode/CFB.java index fef2b634cf2..6fc00637323 100644 --- a/libjava/classpath/gnu/javax/crypto/mode/CFB.java +++ b/libjava/classpath/gnu/javax/crypto/mode/CFB.java @@ -42,58 +42,48 @@ import gnu.java.security.Registry; import gnu.javax.crypto.cipher.IBlockCipher; /** - * The cipher feedback mode. CFB mode is a stream mode that operates on - * s bit blocks, where 1 <= s <= b, if - * b is the underlying cipher's block size. Encryption is: - * -
- I[1] = IV - I[j] = LSB(b-s, I[j-1]) | C[j-1] for j = 2...n - O[j] = CIPH(K, I[j]) for j = 1,2...n - C[j] = P[j] ^ MSB(s, O[j]) for j = 1,2...n -- * - *
And decryption is:
- * -- I[1] = IV - I[j] = LSB(b-s, I[j-1]) | C[j-1] for j = 2...n - O[j] = CIPH(K, I[j]) for j = 1,2...n - P[j] = C[j] ^ MSB(s, O[j]) for j = 1,2...n -- * - *
CFB mode requires an initialization vector, which need not be kept - * secret.
- * - *References:
+ * The cipher feedback mode. CFB mode is a stream mode that operates on s + * bit blocks, where 1 <= s <= b, if b is the + * underlying cipher's block size. Encryption is: + *+ * I[1] = IV + * I[j] = LSB(b-s, I[j-1]) | C[j-1] for j = 2...n + * O[j] = CIPH(K, I[j]) for j = 1,2...n + * C[j] = P[j] ˆ MSB(s, O[j]) for j = 1,2...n + *+ *
+ * And decryption is: + *
+ * I[1] = IV + * I[j] = LSB(b-s, I[j-1]) | C[j-1] for j = 2...n + * O[j] = CIPH(K, I[j]) for j = 1,2...n + * P[j] = C[j] ˆ MSB(s, O[j]) for j = 1,2...n + *+ *
+ * CFB mode requires an initialization vector, which need not be kept secret. + *
+ * References: *
The implementation of the Counter Mode.
- * - *The algorithm steps are formally described as follows:
- * + * The implementation of the Counter Mode. + *+ * The algorithm steps are formally described as follows: + * *
- * CTR Encryption: O[j] = E(K)(T[j]); for j = 1, 2...n; - * C[j] = P[j] ^ O[j]; for j = 1, 2...n. - * CTR Decryption: O[j] = E(K)(T[j]); for j = 1, 2...n; - * P[j] = C[j] ^ O[j]; for j = 1, 2...n. + * CTR Encryption: O[j] = E(K)(T[j]); for j = 1, 2...n; + * C[j] = P[j] ˆ O[j]; for j = 1, 2...n. + * CTR Decryption: O[j] = E(K)(T[j]); for j = 1, 2...n; + * P[j] = C[j] ˆ O[j]; for j = 1, 2...n. *- * - *
where P is the plaintext, C is the ciphertext,
+ *
+ *
+ * where P is the plaintext, C is the ciphertext,
* E(K) is the underlying block cipher encryption function
- * parametrised with the session key K, and T is the
- * Counter.
This implementation, uses a standard incrementing function with a step of - * 1, and an initial value similar to that described in the NIST document.
- * - *References:
- * + * parametrised with the session keyK, and T is
+ * the Counter.
+ * + * This implementation, uses a standard incrementing function with a step of 1, + * and an initial value similar to that described in the NIST document. + *
+ * References: *
Trivial package-private constructor for use by the Factory class.
- * + * Trivial package-private constructor for use by the Factory class. + * * @param underlyingCipher the underlying cipher implementation. * @param cipherBlockSize the underlying cipher block size to use. */ @@ -102,8 +93,8 @@ public class CTR extends BaseMode implements Cloneable } /** - *Private constructor for cloning purposes.
- * + * Private constructor for cloning purposes. + * * @param that the instance to clone. */ private CTR(CTR that) @@ -111,61 +102,31 @@ public class CTR extends BaseMode implements Cloneable this((IBlockCipher) that.cipher.clone(), that.cipherBlockSize); } - // Class methods - // ------------------------------------------------------------------------- - - // Cloneable interface implementation - // ------------------------------------------------------------------------- - public Object clone() { return new CTR(this); } - // Implementation of abstract methods in BaseMode - // ------------------------------------------------------------------------- - public void setup() { if (modeBlockSize > cipherBlockSize) - { - throw new IllegalArgumentException( - "mode size exceeds cipher block size"); - } + throw new IllegalArgumentException("mode size exceeds cipher block size"); off = 0; counter = new byte[cipherBlockSize]; int i = cipherBlockSize - 1; int j = iv.length - 1; while (i >= 0 && j >= 0) - { - counter[i--] = iv[j--]; - } + counter[i--] = iv[j--]; enc = new byte[cipherBlockSize]; cipher.encryptBlock(counter, 0, enc, 0); - // if (modeBlockSize != cipherBlockSize) { - // throw new IllegalArgumentException(); - // } - - // byte[] tBytes = new byte[modeBlockSize+1]; - // tBytes[0] = (byte) 0x80; - // for (int i = 0; i < modeBlockSize; i++) { - // tBytes[i+1] = (byte)(256 - modeBlockSize + i); - // } - - // T = new BigInteger(1, tBytes); } public void teardown() { if (counter != null) - { - Arrays.fill(counter, (byte) 0); - } + Arrays.fill(counter, (byte) 0); if (enc != null) - { - Arrays.fill(enc, (byte) 0); - } - // T = null; + Arrays.fill(enc, (byte) 0); } public void encryptBlock(byte[] in, int i, byte[] out, int o) @@ -183,21 +144,11 @@ public class CTR extends BaseMode implements Cloneable return new Sequence(1, cipherBlockSize).iterator(); } - // own methods - // ------------------------------------------------------------------------- - private void ctr(byte[] in, int inOffset, byte[] out, int outOffset) { - // T = T.add(BigInteger.ONE); - // byte[] O = T.toByteArray(); - // int ndx = O.length - modeBlockSize; - // cipher.encryptBlock(O, ndx, O, ndx); - // for (int i = 0; i < modeBlockSize; i++) { - // out[outOffset++] = (byte)(in[inOffset++] ^ O[ndx++]); - // } for (int i = 0; i < modeBlockSize; i++) { - out[outOffset++] = (byte) (in[inOffset++] ^ enc[off++]); + out[outOffset++] = (byte)(in[inOffset++] ^ enc[off++]); if (off == cipherBlockSize) { int j; @@ -205,17 +156,13 @@ public class CTR extends BaseMode implements Cloneable { counter[j]++; if ((counter[j] & 0xFF) != 0) - { - break; - } + break; } if (j == 0) - { - counter[cipherBlockSize - 1]++; - } + counter[cipherBlockSize - 1]++; off = 0; cipher.encryptBlock(counter, 0, enc, 0); } } } -} \ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/mode/EAX.java b/libjava/classpath/gnu/javax/crypto/mode/EAX.java index bf260989825..401616b9f1f 100644 --- a/libjava/classpath/gnu/javax/crypto/mode/EAX.java +++ b/libjava/classpath/gnu/javax/crypto/mode/EAX.java @@ -39,13 +39,11 @@ exception statement from your version. */ package gnu.javax.crypto.mode; import gnu.java.security.Registry; - import gnu.javax.crypto.cipher.IBlockCipher; import gnu.javax.crypto.mac.IMac; import gnu.javax.crypto.mac.MacFactory; import java.security.InvalidKeyException; - import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -53,64 +51,48 @@ import java.util.Iterator; import java.util.Map; /** - *A conventional two-pass authenticated-encrypted mode, EAX. EAX is a + * A conventional two-pass authenticated-encrypted mode, EAX. EAX is a * Authenticated Encryption with Additional Data (AEAD) scheme, * which provides protection and authentication for the message, and provides * authentication of an (optional) header. EAX is composed of the counter mode * (CTR) and the one-key CBC MAC (OMAC). - * - *
This class makes full use of the {@link IAuthenticatedMode} interface, - * that is, all methods of both {@link IMode} and {@link IMac} can be used - * as specified in the {@link IAuthenticatedMode} interface. - * - *
References:
+ *+ * This class makes full use of the {@link IAuthenticatedMode} interface, that + * is, all methods of both {@link IMode} and {@link IMac} can be used as + * specified in the {@link IAuthenticatedMode} interface. + *
+ * References: *
The implementation of the Electronic Codebook mode.
- * - *The Electronic Codebook (ECB) mode is a confidentiality mode that is - * defined as follows:
- * + * The implementation of the Electronic Codebook mode. + *+ * The Electronic Codebook (ECB) mode is a confidentiality mode that is defined + * as follows: *
In ECB encryption, the forward cipher function is applied directly, and + *
+ * In ECB encryption, the forward cipher function is applied directly, and * independently, to each block of the plaintext. The resulting sequence of - * output blocks is the ciphertext.
- * - *In ECB decryption, the inverse cipher function is applied directly, and + * output blocks is the ciphertext. + *
+ * In ECB decryption, the inverse cipher function is applied directly, and * independently, to each block of the ciphertext. The resulting sequence of - * output blocks is the plaintext.
- * - *References:
- * + * output blocks is the plaintext. + *+ * References: *
Trivial package-private constructor for use by the Factory class.
- * + * Trivial package-private constructor for use by the Factory class. + * * @param underlyingCipher the underlying cipher implementation. * @param cipherBlockSize the underlying cipher block size to use. */ @@ -89,8 +85,8 @@ public class ECB extends BaseMode implements Cloneable } /** - *Private constructor for cloning purposes.
- * + * Private constructor for cloning purposes. + * * @param that the mode to clone. */ private ECB(ECB that) @@ -98,27 +94,15 @@ public class ECB extends BaseMode implements Cloneable this((IBlockCipher) that.cipher.clone(), that.cipherBlockSize); } - // Class methods - // ------------------------------------------------------------------------- - - // Instance methods - // ------------------------------------------------------------------------- - - // java.lang.Cloneable interface implementation ---------------------------- - public Object clone() { return new ECB(this); } - // Implementation of abstract methods in BaseMode -------------------------- - public void setup() { if (modeBlockSize != cipherBlockSize) - { - throw new IllegalArgumentException(IMode.MODE_BLOCK_SIZE); - } + throw new IllegalArgumentException(IMode.MODE_BLOCK_SIZE); } public void teardown() @@ -134,4 +118,4 @@ public class ECB extends BaseMode implements Cloneable { cipher.decryptBlock(in, i, out, o); } -} \ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/mode/IAuthenticatedMode.java b/libjava/classpath/gnu/javax/crypto/mode/IAuthenticatedMode.java index 989e3edbcd0..703679dc0a6 100644 --- a/libjava/classpath/gnu/javax/crypto/mode/IAuthenticatedMode.java +++ b/libjava/classpath/gnu/javax/crypto/mode/IAuthenticatedMode.java @@ -43,16 +43,14 @@ import gnu.javax.crypto.mac.IMac; /** * The interface for encryption modes that also produce a message authentication * tag. - * - *This interface is merely the conjuction of the {@link IMode} and - * {@link IMac} interfaces. Encryption and decryption is done via the - * {@link IMode#update(byte[],int,byte[],int)} method, tag generation - * is done via the {@link IMac#digest()} method, and header updating - * (if supported by the mode) is done via the {@link - * IMac#update(byte[],int,int)} method. + *
+ * This interface is merely the conjuction of the {@link IMode} and {@link IMac} + * interfaces. Encryption and decryption is done via the + * {@link IMode#update(byte[],int,byte[],int)} method, tag generation is done + * via the {@link IMac#digest()} method, and header updating (if supported by + * the mode) is done via the {@link IMac#update(byte[],int,int)} method. */ -public interface IAuthenticatedMode extends IMode, IMac +public interface IAuthenticatedMode + extends IMode, IMac { - - // Trivial conjunction of IMode and IMac. } diff --git a/libjava/classpath/gnu/javax/crypto/mode/ICM.java b/libjava/classpath/gnu/javax/crypto/mode/ICM.java index d37908b5dfd..833ddb18f7f 100644 --- a/libjava/classpath/gnu/javax/crypto/mode/ICM.java +++ b/libjava/classpath/gnu/javax/crypto/mode/ICM.java @@ -44,75 +44,66 @@ import gnu.javax.crypto.cipher.IBlockCipher; import java.math.BigInteger; /** - *
An implementation of David McGrew Integer Counter Mode (ICM) as an - * {@link IMode}.
- * - *ICM is a way to define a pseudorandom keystream generator using a block - * cipher. The keystream can be used for additive encryption, key derivation, - * or any other application requiring pseudorandom data. In the case of this - * class, it is used as additive encryption, XOR-ing the keystream with the - * input text --for both encryption and decryption.
- * - *In ICM, the keystream is logically broken into segments. Each segment is + * An implementation of David McGrew Integer Counter Mode (ICM) as an + * {@link IMode}. + *
+ * ICM is a way to define a pseudorandom keystream generator using a block + * cipher. The keystream can be used for additive encryption, key derivation, or + * any other application requiring pseudorandom data. In the case of this class, + * it is used as additive encryption, XOR-ing the keystream with the input text + * --for both encryption and decryption. + *
+ * In ICM, the keystream is logically broken into segments. Each segment is * identified with a segment index, and the segments have equal lengths. This * segmentation makes ICM especially appropriate for securing packet-based * protocols. ICM also allows a variety of configurations based, among other - * things, on two parameters: the block index length and the - * segment index length. A constraint on those two values exists: The sum - * of segment index length and block index length must not - * half the block size of the underlying cipher. This requirement protects - * the ICM keystream generator from potentially failing to be pseudorandom.
- * - *For simplicity, this implementation, fixes these two values to the - * following:
- * + * things, on two parameters: the block index length and the segment + * index length. A constraint on those two values exists: The sum of + * segment index length and block index length must not + * half the block size of the underlying cipher. This requirement + * protects the ICM keystream generator from potentially failing to be + * pseudorandom. + *+ * For simplicity, this implementation, fixes these two values to the following: *
For a 128-bit block cipher, the above values imply a maximum keystream
- * length of 295,147,905,179,352,825,856 octets, since in ICM, each segment must
- * not exceed the value (256 ^ block index length) * block length
- * octets.
Finally, for this implementation of the ICM, the IV placeholder will be - * used to pass the value of the Offset in the keystream segment.
- * - *References:
- * + *
+ * For a 128-bit block cipher, the above values imply a maximum keystream length
+ * of 295,147,905,179,352,825,856 octets, since in ICM, each segment must not
+ * exceed the value
+ * (256 ^ block index length) * block length
+ * octets.
+ *
+ * Finally, for this implementation of the ICM, the IV placeholder will be used + * to pass the value of the Offset in the keystream segment. + *
+ * References: *
Trivial package-private constructor for use by the Factory class.
- * + * Trivial package-private constructor for use by the Factory class. + * * @param underlyingCipher the underlying cipher implementation. * @param cipherBlockSize the underlying cipher block size to use. */ @@ -122,8 +113,8 @@ public class ICM extends BaseMode implements Cloneable } /** - *Private constructor for cloning purposes.
- * + * Private constructor for cloning purposes. + * * @param that the instance to clone. */ private ICM(ICM that) @@ -131,27 +122,15 @@ public class ICM extends BaseMode implements Cloneable this((IBlockCipher) that.cipher.clone(), that.cipherBlockSize); } - // Class methods - // ------------------------------------------------------------------------- - - // Cloneable interface implementation - // ------------------------------------------------------------------------- - public Object clone() { return new ICM(this); } - // Implementation of abstract methods in BaseMode - // ------------------------------------------------------------------------- - public void setup() { if (modeBlockSize != cipherBlockSize) - { - throw new IllegalArgumentException(); - } - + throw new IllegalArgumentException(); counterRange = TWO_FIFTY_SIX.pow(cipherBlockSize); maxBlocksPerSegment = TWO_FIFTY_SIX.pow(cipherBlockSize / 2); BigInteger r = new BigInteger(1, iv); @@ -177,35 +156,13 @@ public class ICM extends BaseMode implements Cloneable icm(in, i, out, o); } - // Instance methods - // ------------------------------------------------------------------------- - private void icm(byte[] in, int inOffset, byte[] out, int outOffset) { if (blockNdx.compareTo(maxBlocksPerSegment) >= 0) throw new RuntimeException("Maximum blocks for segment reached"); - - // encrypt the counter for the current blockNdx - // C[i] = (C[0] + i) modulo (256^BLOCK_LENGTH). - BigInteger Ci = C0.add(blockNdx).modPow(BigInteger.ONE, counterRange); byte[] result = Ci.toByteArray(); int limit = result.length; - // if (limit < cipherBlockSize) { - // byte[] data = new byte[cipherBlockSize]; - // System.arraycopy(result, 0, data, cipherBlockSize-limit, limit); - // result = data; - // } else if (limit > cipherBlockSize) { - // byte[] data = new byte[cipherBlockSize]; - // System.arraycopy(result, limit-cipherBlockSize, data, 0, cipherBlockSize); - // result = data; - // } - // - // cipher.encryptBlock(result, 0, result, 0); - // blockNdx = blockNdx.add(BigInteger.ONE); // increment blockNdx - // for (int i = 0; i < modeBlockSize; ) { // xor result with input block - // out[outOffset++] = (byte)(in[inOffset++] ^ result[i++]); - // } int ndx = 0; if (limit < cipherBlockSize) { @@ -214,15 +171,11 @@ public class ICM extends BaseMode implements Cloneable result = data; } else if (limit > cipherBlockSize) - { - ndx = limit - cipherBlockSize; - } + ndx = limit - cipherBlockSize; cipher.encryptBlock(result, ndx, result, ndx); blockNdx = blockNdx.add(BigInteger.ONE); // increment blockNdx - for (int i = 0; i < modeBlockSize; i++) - { // xor result with input block - out[outOffset++] = (byte) (in[inOffset++] ^ result[ndx++]); - } + for (int i = 0; i < modeBlockSize; i++) // xor result with input block + out[outOffset++] = (byte)(in[inOffset++] ^ result[ndx++]); } -} \ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/mode/IMode.java b/libjava/classpath/gnu/javax/crypto/mode/IMode.java index 4cb6ca64bd9..30485117d45 100644 --- a/libjava/classpath/gnu/javax/crypto/mode/IMode.java +++ b/libjava/classpath/gnu/javax/crypto/mode/IMode.java @@ -41,105 +41,83 @@ package gnu.javax.crypto.mode; import gnu.javax.crypto.cipher.IBlockCipher; /** - *
The basic visible methods of any block cipher mode.
- * - *Block ciphers encrypt plaintext in fixed size n-bit blocks. For messages + * The basic visible methods of any block cipher mode. + *
+ * Block ciphers encrypt plaintext in fixed size n-bit blocks. For messages * larger than n bits, the simplest approach is to segment the message into * n-bit blocks and process (encrypt and/or decrypt) each one separately * (Electronic Codebook or ECB mode). But this approach has disadvantages in * most applications. The block cipher modes of operations are one way of - * working around those disadvantages.
- * - *A Mode always employs an underlying block cipher for processing its + * working around those disadvantages. + *
+ * A Mode always employs an underlying block cipher for processing its * input. For all intents and purposes, a Mode appears to behave as any - * other block cipher with the following differences:
- * + * other block cipher with the following differences: *Possible additional initialisation values for an instance of that type - * are:
- * + *+ * Possible additional initialisation values for an instance of that type are: *
reset() is invoked on the
- * instance.reset() is invoked on the instance.Property name of the state in which to operate this mode. The value
+ * Property name of the state in which to operate this mode. The value
* associated to this property name is taken to be an {@link Integer} which
- * value is either ENCRYPTION or DECRYPTION.
ENCRYPTION or DECRYPTION.
*/
String STATE = "gnu.crypto.mode.state";
-
/**
- * Property name of the block size in which to operate this mode. The - * value associated with this property name is taken to be an {@link Integer}. - * If it is not specified, the value of the block size of the underlying - * block cipher, used to construct the mode instance, shall be used.
+ * Property name of the block size in which to operate this mode. The value + * associated with this property name is taken to be an {@link Integer}. If + * it is not specified, the value of the block size of the underlying block + * cipher, used to construct the mode instance, shall be used. */ String MODE_BLOCK_SIZE = "gnu.crypto.mode.block.size"; - /** - *Property name of the initialisation vector to use, if required, with - * this instance. The value associated with this property name is taken to - * be a byte array. If the concrete instance needs such a parameter, and it - * has not been specified as part of the initialissation parameters, an - * all-zero byte array of the appropriate size shall be used.
+ * Property name of the initialisation vector to use, if required, with this + * instance. The value associated with this property name is taken to be a + * byte array. If the concrete instance needs such a parameter, and it has not + * been specified as part of the initialissation parameters, an all-zero byte + * array of the appropriate size shall be used. */ String IV = "gnu.crypto.mode.iv"; - - /** - *Constant indicating the instance is being used for encryption.
- */ + /** Constant indicating the instance is being used for encryption. */ int ENCRYPTION = 1; - - /** - *Constant indicating the instance is being used for decryption.
- */ + /** Constant indicating the instance is being used for decryption. */ int DECRYPTION = 2; - // Methods - // ------------------------------------------------------------------------- - /** - *A convenience method. Effectively invokes the encryptBlock()
+ * A convenience method. Effectively invokes the encryptBlock()
* or decryptBlock() method depending on the operational state
- * of the instance.
in from which to start considering
- * data.
+ * data.
* @param out the ciphertext.
* @param outOffset index of out from which to store result.
* @exception IllegalStateException if the instance is not initialised.
*/
void update(byte[] in, int inOffset, byte[] out, int outOffset)
throws IllegalStateException;
-}
\ No newline at end of file
+}
diff --git a/libjava/classpath/gnu/javax/crypto/mode/ModeFactory.java b/libjava/classpath/gnu/javax/crypto/mode/ModeFactory.java
index 0e949ed9e96..d1acdf4e599 100644
--- a/libjava/classpath/gnu/javax/crypto/mode/ModeFactory.java
+++ b/libjava/classpath/gnu/javax/crypto/mode/ModeFactory.java
@@ -49,16 +49,12 @@ import java.util.Iterator;
import java.util.Set;
/**
- * A Factory to instantiate block cipher modes of operations.
+ * A Factory to instantiate block cipher modes of operations. */ -public class ModeFactory implements Registry +public class ModeFactory + implements Registry { - - // Constants and variables - // ------------------------------------------------------------------------- - - // Constructor(s) - // ------------------------------------------------------------------------- + private static Set names; /** Trivial constructor to enforce Singleton pattern. */ private ModeFactory() @@ -66,37 +62,29 @@ public class ModeFactory implements Registry super(); } - // Class methods - // ------------------------------------------------------------------------- - /** - *Returns an instance of a block cipher mode of operations given its name - * and characteristics of the underlying block cipher.
- * + * Returns an instance of a block cipher mode of operations given its name and + * characteristics of the underlying block cipher. + * * @param mode the case-insensitive name of the mode of operations. * @param cipher the case-insensitive name of the block cipher. * @param cipherBlockSize the block size, in bytes, of the underlying cipher. * @return an instance of the block cipher algorithm, operating in a given - * mode of operations, ornull if none found.
+ * mode of operations, or null if none found.
* @exception InternalError if either the mode or the underlying block cipher
- * implementation does not pass its self-test.
+ * implementation does not pass its self-test.
*/
public static IMode getInstance(String mode, String cipher,
int cipherBlockSize)
{
if (mode == null || cipher == null)
- {
- return null;
- }
+ return null;
mode = mode.trim();
cipher = cipher.trim();
-
IBlockCipher cipherImpl = CipherFactory.getInstance(cipher);
if (cipherImpl == null)
- {
- return null;
- }
+ return null;
return getInstance(mode, cipherImpl, cipherBlockSize);
}
@@ -110,59 +98,36 @@ public class ModeFactory implements Registry
{
ok = (cipherBlockSize == ((Integer) it.next()).intValue());
if (ok)
- {
- break;
- }
- }
-
- if (!ok)
- {
- throw new IllegalArgumentException("cipherBlockSize");
+ break;
}
-
+ if (! ok)
+ throw new IllegalArgumentException("cipherBlockSize");
IMode result = null;
if (mode.equalsIgnoreCase(ECB_MODE))
- {
- result = new ECB(cipher, cipherBlockSize);
- }
+ result = new ECB(cipher, cipherBlockSize);
else if (mode.equalsIgnoreCase(CTR_MODE))
- {
- result = new CTR(cipher, cipherBlockSize);
- }
+ result = new CTR(cipher, cipherBlockSize);
else if (mode.equalsIgnoreCase(ICM_MODE))
- {
- result = new ICM(cipher, cipherBlockSize);
- }
+ result = new ICM(cipher, cipherBlockSize);
else if (mode.equalsIgnoreCase(OFB_MODE))
- {
- result = new OFB(cipher, cipherBlockSize);
- }
+ result = new OFB(cipher, cipherBlockSize);
else if (mode.equalsIgnoreCase(CBC_MODE))
- {
- result = new CBC(cipher, cipherBlockSize);
- }
+ result = new CBC(cipher, cipherBlockSize);
else if (mode.equalsIgnoreCase(CFB_MODE))
- {
- result = new CFB(cipher, cipherBlockSize);
- }
+ result = new CFB(cipher, cipherBlockSize);
else if (mode.equalsIgnoreCase(EAX_MODE))
- {
- result = new EAX(cipher, cipherBlockSize);
- }
+ result = new EAX(cipher, cipherBlockSize);
- if (result != null && !result.selfTest())
- {
- throw new InternalError(result.name());
- }
+ if (result != null && ! result.selfTest())
+ throw new InternalError(result.name());
return result;
}
/**
- * Returns a {@link java.util.Set} of names of mode supported by this - * Factory.
- * - * @return a {@link java.util.Set} of mode names (Strings). + * Returns a {@link Set} of names of mode supported by this Factory. + * + * @return a {@link Set} of mode names (Strings). */ public static final Set getNames() { @@ -178,15 +143,9 @@ public class ModeFactory implements Registry hs.add(CBC_MODE); hs.add(CFB_MODE); hs.add(EAX_MODE); - names = Collections.unmodifiableSet(hs); } } return names; } - - private static Set names; - - // Instance methods - // ------------------------------------------------------------------------- -} \ No newline at end of file +} diff --git a/libjava/classpath/gnu/javax/crypto/mode/OFB.java b/libjava/classpath/gnu/javax/crypto/mode/OFB.java index 68065d10b9c..c8b6d7e97e7 100644 --- a/libjava/classpath/gnu/javax/crypto/mode/OFB.java +++ b/libjava/classpath/gnu/javax/crypto/mode/OFB.java @@ -39,33 +39,33 @@ exception statement from your version. */ package gnu.javax.crypto.mode; import gnu.java.security.Registry; - import gnu.javax.crypto.cipher.IBlockCipher; /** - *The Output Feedback (OFB) mode is a confidentiality mode that requires a
+ * The Output Feedback (OFB) mode is a confidentiality mode that requires a
* unique IV for every message that is ever encrypted under the
- * given key. The OFB mode is defined as follows:
In OFB encryption, the IV is transformed by the forward
- * cipher function to produce the first output block. The first output block is
+ *
+ *
+ * In OFB encryption, the IV is transformed by the forward cipher
+ * function to produce the first output block. The first output block is
* exclusive-ORed with the first plaintext block to produce the first ciphertext
* block. The first output block is then transformed by the forward cipher
* function to produce the second output block. The second output block is
@@ -74,9 +74,9 @@ import gnu.javax.crypto.cipher.IBlockCipher;
* cipher function to produce the third output block. Thus, the successive
* output blocks are produced from enciphering the previous output blocks, and
* the output blocks are exclusive-ORed with the corresponding plaintext blocks
- * to produce the ciphertext blocks.
In OFB decryption, the IV is transformed by the forward cipher
+ * to produce the ciphertext blocks.
+ *
+ * In OFB decryption, the IV is transformed by the forward cipher
* function to produce the first output block. The first output block is
* exclusive-ORed with the first ciphertext block to recover the first plaintext
* block. The first output block is then transformed by the forward cipher
@@ -86,51 +86,46 @@ import gnu.javax.crypto.cipher.IBlockCipher;
* forward cipher function to produce the third output block. Thus, the
* successive output blocks are produced from enciphering the previous output
* blocks, and the output blocks are exclusive-ORed with the corresponding
- * ciphertext blocks to recover the plaintext blocks.
In both OFB encryption and OFB decryption, each forward cipher function + * ciphertext blocks to recover the plaintext blocks. + *
+ * In both OFB encryption and OFB decryption, each forward cipher function
* (except the first) depends on the results of the previous forward cipher
- * function; therefore, multiple forward cipher functions cannot be performed
- * in parallel. However, if the IV is known, the output blocks can
- * be generated prior to the availability of the plaintext or ciphertext data.
The OFB mode requires a unique IV for every message that is
+ * function; therefore, multiple forward cipher functions cannot be performed in
+ * parallel. However, if the IV is known, the output blocks can
+ * be generated prior to the availability of the plaintext or ciphertext data.
+ *
+ * The OFB mode requires a unique IV for every message that is
* ever encrypted under the given key. If, contrary to this requirement, the
* same IV is used for the encryption of more than one message,
* then the confidentiality of those messages may be compromised. In particular,
* if a plaintext block of any of these messages is known, say, the jth
* plaintext block, then the jth output of the forward cipher
- * function can be determined easily from the jth ciphertext block of
- * the message. This information allows the jth plaintext block of
- * any other message that is encrypted using the same IV to be
- * easily recovered from the jth ciphertext block of that message.
Confidentiality may similarly be compromised if any of the input blocks to
+ * function can be determined easily from the jth ciphertext block
+ * of the message. This information allows the jth plaintext block
+ * of any other message that is encrypted using the same IV to be
+ * easily recovered from the jth ciphertext block of that message.
+ *
+ * Confidentiality may similarly be compromised if any of the input blocks to
* the forward cipher function for the encryption of a message is used as the
- * IV for the encryption of another message under the given key.
References:
- * + *IV for the encryption of another message under the given key.
+ * + * References: *
Trivial package-private constructor for use by the Factory class.
- * + * Trivial package-private constructor for use by the Factory class. + * * @param underlyingCipher the underlying cipher implementation. * @param cipherBlockSize the underlying cipher block size to use. */ @@ -140,8 +135,8 @@ public class OFB extends BaseMode implements Cloneable } /** - *Private constructor for cloning purposes.
- * + * Private constructor for cloning purposes. + * * @param that the mode to clone. */ private OFB(OFB that) @@ -149,28 +144,15 @@ public class OFB extends BaseMode implements Cloneable this((IBlockCipher) that.cipher.clone(), that.cipherBlockSize); } - // Class methods - // ------------------------------------------------------------------------- - - // Instance methods - // ------------------------------------------------------------------------- - - // java.lang.Cloneable interface implementation ---------------------------- - public Object clone() { return new OFB(this); } - // Implementation of abstract methods in BaseMode -------------------------- - public void setup() { if (modeBlockSize != cipherBlockSize) - { - throw new IllegalArgumentException(IMode.MODE_BLOCK_SIZE); - } - + throw new IllegalArgumentException(IMode.MODE_BLOCK_SIZE); outputBlock = (byte[]) iv.clone(); } @@ -182,13 +164,11 @@ public class OFB extends BaseMode implements Cloneable { cipher.encryptBlock(outputBlock, 0, outputBlock, 0); for (int j = 0; j < cipherBlockSize;) - { - out[o++] = (byte) (in[i++] ^ outputBlock[j++]); - } + out[o++] = (byte)(in[i++] ^ outputBlock[j++]); } public void decryptBlock(byte[] in, int i, byte[] out, int o) { this.encryptBlock(in, i, out, o); } -} \ No newline at end of file +} -- cgit v1.2.3