summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/gnu/javax/crypto/mode/CFB.java
diff options
context:
space:
mode:
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-08-14 23:12:35 +0000
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-08-14 23:12:35 +0000
commitffde862e033a0825e1e9972a89c0f1f80b261a8e (patch)
tree97037d2c09c8384d80531f67ec36a01205df6bdb /libjava/classpath/gnu/javax/crypto/mode/CFB.java
parentb415ff10527e977c3758234fd930e2c027bfa17d (diff)
downloadppe42-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/mode/CFB.java')
-rw-r--r--libjava/classpath/gnu/javax/crypto/mode/CFB.java116
1 files changed, 48 insertions, 68 deletions
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
- * <i>s</i> bit blocks, where 1 &lt;= <i>s</i> &lt;= <i>b</i>, if
- * <i>b</i> is the underlying cipher's block size. Encryption is:
- *
- <pre>
- 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
- </pre>
- *
- * <p>And decryption is:</p>
- *
- <pre>
- 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
- </pre>
- *
- * <p>CFB mode requires an initialization vector, which need not be kept
- * secret.</p>
- *
- * <p>References:</p>
+ * The cipher feedback mode. CFB mode is a stream mode that operates on <i>s</i>
+ * bit blocks, where 1 &lt;= <i>s</i> &lt;= <i>b</i>, if <i>b</i> is the
+ * underlying cipher's block size. Encryption is:
+ * <pre>
+ * 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] &circ; MSB(s, O[j]) for j = 1,2...n
+ * </pre>
+ * <p>
+ * And decryption is:
+ * <pre>
+ * 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] &circ; MSB(s, O[j]) for j = 1,2...n
+ * </pre>
+ * <p>
+ * CFB mode requires an initialization vector, which need not be kept secret.
+ * <p>
+ * References:
* <ol>
- * <li>Bruce Schneier, <i>Applied Cryptography: Protocols, Algorithms,
- * and Source Code in C, Second Edition</i>. (1996 John Wiley and Sons)
- * ISBN 0-471-11709-9.</li>
- *
- * <li><a href="http://csrc.nist.gov/encryption/modes/Recommendation/Modes01.pdf">
+ * <li>Bruce Schneier, <i>Applied Cryptography: Protocols, Algorithms, and
+ * Source Code in C, Second Edition</i>. (1996 John Wiley and Sons) ISBN
+ * 0-471-11709-9.</li>
+ * <li><a
+ * href="http://csrc.nist.gov/encryption/modes/Recommendation/Modes01.pdf">
* Recommendation for Block Cipher Modes of Operation Methods and Techniques</a>,
* Morris Dworkin.</li>
* </ol>
*/
-public class CFB extends BaseMode
+public class CFB
+ extends BaseMode
{
-
- // Constants and variables.
- // -----------------------------------------------------------------------
-
/** The shift register, the input block to the block cipher. */
private byte[] shiftRegister;
-
/** The output block from the block cipher. */
private byte[] scratch;
- // Constructors.
- // -----------------------------------------------------------------------
-
/**
* Package-private constructor for the factory class.
- *
+ *
* @param underlyingCipher The cipher implementation.
* @param cipherBlockSize The cipher's block size.
*/
@@ -104,7 +94,7 @@ public class CFB extends BaseMode
/**
* Cloneing constructor.
- *
+ *
* @param that The instance being cloned.
*/
private CFB(CFB that)
@@ -112,9 +102,6 @@ public class CFB extends BaseMode
this((IBlockCipher) that.cipher.clone(), that.cipherBlockSize);
}
- // Instance methods implementing BaseMode.
- // -----------------------------------------------------------------------
-
public Object clone()
{
return new CFB(this);
@@ -123,25 +110,20 @@ public class CFB extends BaseMode
public void setup()
{
if (modeBlockSize > cipherBlockSize)
- {
- throw new IllegalArgumentException(
- "CFB block size cannot be larger than the cipher block size");
- }
+ throw new IllegalArgumentException(
+ "CFB block size cannot be larger than the cipher block size");
shiftRegister = new byte[cipherBlockSize];
scratch = new byte[cipherBlockSize];
- System.arraycopy(iv, 0, shiftRegister, 0, Math.min(iv.length,
- cipherBlockSize));
+ System.arraycopy(iv, 0,
+ shiftRegister, 0,
+ Math.min(iv.length, cipherBlockSize));
}
public void teardown()
{
if (shiftRegister != null)
- {
- for (int i = 0; i < shiftRegister.length; i++)
- {
- shiftRegister[i] = 0;
- }
- }
+ for (int i = 0; i < shiftRegister.length; i++)
+ shiftRegister[i] = 0;
shiftRegister = null;
}
@@ -149,13 +131,12 @@ public class CFB extends BaseMode
{
cipher.encryptBlock(shiftRegister, 0, scratch, 0);
for (int i = 0; i < modeBlockSize; i++)
- {
- out[outOffset + i] = (byte) (in[inOffset + i] ^ scratch[i]);
- }
- System.arraycopy(shiftRegister, modeBlockSize, shiftRegister, 0,
+ out[outOffset + i] = (byte)(in[inOffset + i] ^ scratch[i]);
+ System.arraycopy(shiftRegister, modeBlockSize,
+ shiftRegister, 0,
cipherBlockSize - modeBlockSize);
- System.arraycopy(out, outOffset, shiftRegister, cipherBlockSize
- - modeBlockSize,
+ System.arraycopy(out, outOffset,
+ shiftRegister, cipherBlockSize - modeBlockSize,
modeBlockSize);
}
@@ -163,13 +144,12 @@ public class CFB extends BaseMode
{
cipher.encryptBlock(shiftRegister, 0, scratch, 0);
for (int i = 0; i < modeBlockSize; i++)
- {
- out[outOffset + i] = (byte) (in[inOffset + i] ^ scratch[i]);
- }
- System.arraycopy(shiftRegister, modeBlockSize, shiftRegister, 0,
+ out[outOffset + i] = (byte)(in[inOffset + i] ^ scratch[i]);
+ System.arraycopy(shiftRegister, modeBlockSize,
+ shiftRegister, 0,
cipherBlockSize - modeBlockSize);
- System.arraycopy(in, inOffset, shiftRegister, cipherBlockSize
- - modeBlockSize,
+ System.arraycopy(in, inOffset,
+ shiftRegister, cipherBlockSize - modeBlockSize,
modeBlockSize);
}
-} \ No newline at end of file
+}
OpenPOWER on IntegriCloud