|
|||||||||
Home >> All >> cryptix >> jce >> provider >> [ cipher overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |
cryptix.jce.provider.cipher
Class RC2

java.lang.Objectjavax.crypto.CipherSpi
cryptix.jce.provider.cipher.BlockCipher
cryptix.jce.provider.cipher.RC2
- public final class RC2
- extends BlockCipher
RC2TM
The source code (C version) from which this port was done, and (most of) the programming notes, are by P. Gutmann (pgut01@cs.auckland.ac.nz) -- as obtained from Usenet.
Eric Young (eay@mincom.oz.au) implementation, also based on Gutmann's work, and included in Eric's colossal SSL library ver 0.6.6 14 Jan 1997, was also used for the initial key data and the computation of the session key schedule. Code to tailor the session key for a specified length in bits is included in this Java implementation but is crippled (commented out). The current code behaves as if the session key is fixed at 1024-bit.
The RC2 algorithm is word (16-bit entity) oriented, operating on a block of 64 bits (or 8 Java bytes) divided into four words, with a key table of 64 words.
RC2 (TM) was designed by Ron Rivest, and was previously a trade secret of RSA Data Security, Inc. The algorithm has since been published as an RFC [reference?]. The name "RC2" is a trademark of RSA Data Security, Inc.
- Version:
- $Revision: 1.5 $
Field Summary | |
static int |
BLOCK_SIZE
The block size, in bytes, of this cipher. |
private boolean |
decrypt
|
private static int[] |
S_BOX
RC2 uses a single 256-byte S-box derived from the ciphertext contents of Beale Cipher No.1 XOR'd with a one-time pad. |
private int[] |
sKey
The session key. |
Fields inherited from class cryptix.jce.provider.cipher.BlockCipher |
|
Constructor Summary | |
RC2()
|
Method Summary | |
private void |
blockDecrypt(byte[] in,
int inOff,
byte[] out,
int outOff)
Decrypt a single block. |
private void |
blockEncrypt(byte[] in,
int inOff,
byte[] out,
int outOff)
Encrypt a single block. |
protected void |
coreCrypt(byte[] in,
int inOffset,
byte[] out,
int outOffset)
Encrypt a given buffer. |
protected void |
coreInit(java.security.Key key,
boolean decrypt)
|
private void |
makeKey(java.security.Key key)
Expands a user key to a working RC2 key. |
Methods inherited from class cryptix.jce.provider.cipher.BlockCipher |
clone, coreGetBlockSize, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate |
Methods inherited from class javax.crypto.CipherSpi |
engineDoFinal, engineUnwrap, engineUpdate, engineWrap |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
BLOCK_SIZE
public static final int BLOCK_SIZE
- The block size, in bytes, of this cipher.
- See Also:
- Constant Field Values
S_BOX
private static final int[] S_BOX
- RC2 uses a single 256-byte S-box derived from the ciphertext contents
of Beale Cipher No.1 XOR'd with a one-time pad. The Beale Ciphers
predate modern cryptography by enough time that there should be no
concerns about trapdoors hidden in the data. They have been published
widely, and the S-box can be easily recreated from the one-time pad
values and the Beale Cipher data taken from a standard source. To
initialise the S-box:
for i = 0 to 255 do sBox[ i ] = ( beale[ i ] mod 256 ) ^ pad[ i ];
The following table gives the computed values based on the above. Thanks Eric :))
sKey
private int[] sKey
- The session key. We're using the lower 16 bits of each int only.
decrypt
private boolean decrypt
Constructor Detail |
RC2
public RC2()
Method Detail |
coreInit
protected void coreInit(java.security.Key key, boolean decrypt) throws java.security.InvalidKeyException
- Specified by:
coreInit
in classBlockCipher
coreCrypt
protected void coreCrypt(byte[] in, int inOffset, byte[] out, int outOffset)
- Description copied from class:
BlockCipher
- Encrypt a given buffer. in and out can point to the same buffer if
(outOffset == inOffset) || (outOffset >= (inOffset+coreGetBlockSize))
That is: the buffers may not partially overlap...
- Specified by:
coreCrypt
in classBlockCipher
makeKey
private void makeKey(java.security.Key key) throws java.security.InvalidKeyException
- Expands a user key to a working RC2 key.
The secret key is first expanded to fill 128 bytes (64 words). The expansion consists of taking the sum of the first and last bytes in the user key, looking up the sum (modulo 256) in the S-box, and appending the result to the key. The operation is repeated with the second byte and new last byte of the key until all 128 bytes have been generated. Note that the following pseudocode treats the S array (the session key) as an array of 128 bytes rather than 64 words:
for j = 0 to length-1 do S[ j ] = K[ j ]; for j = length to 127 do S[ j ] = sBox[ ( S[ j-length ] + S[ j-1 ] ) mod 256 ];
blockEncrypt
private void blockEncrypt(byte[] in, int inOff, byte[] out, int outOff)
- Encrypt a single block. Input and output may overlap.
The cipher has 16 full rounds, each divided into 4 subrounds. In addition the fifth and eleventh rounds add the contents of the S-box indexed by one of the data words to another of the data words following the four subrounds.
blockDecrypt
private void blockDecrypt(byte[] in, int inOff, byte[] out, int outOff)
- Decrypt a single block. Input and output may overlap.
|
|||||||||
Home >> All >> cryptix >> jce >> provider >> [ cipher overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |