Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

cryptix.jce.provider.cipher
Class Square  view Square download Square.java

java.lang.Object
  extended byjavax.crypto.CipherSpi
      extended bycryptix.jce.provider.cipher.BlockCipher
          extended bycryptix.jce.provider.cipher.Square

public final class Square
extends BlockCipher

The Square algorithm.

Square is a cipher algorithm developed by Joan Daemen and Vincent Rijmen

References:

  • The Square home page has up-to-date comments, implementations, and certification data.
  • J. Daemen, L.R. Knudsen, V. Rijmen, " The block cipher Square," Fast Software Encryption, LNCS 1267, E. Biham, Ed., Springer-Verlag, 1997, pp. 149-165.

Version:
$Revision: 1.4 $

Field Summary
private static int BLOCK_SIZE
           
private  boolean decrypt
          Are we decrypting?
private static int KEY_LENGTH
           
private static int[] OFFSET
           
private static int R
           
private static int ROOT
           
private static byte[] SD
          Encryption and decryption Square S-Box values
private static byte[] SE
          Encryption and decryption Square S-Box values
private  int[][] sKey
          This instance's Square key schedule.
private static int[] TD
          Transposition boxes for encryption and decryption
private static int[] TE
          Transposition boxes for encryption and decryption
 
Fields inherited from class cryptix.jce.provider.cipher.BlockCipher
 
Constructor Summary
Square()
           
 
Method Summary
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, boolean doEncrypt)
          Expands a user-key to a working key schedule.
private static int mul(int a, int b)
          Returns the product of two binary numbers a and b, using the generator ROOT as the modulus: p = (a * b) mod ROOT.
private static int rot32L(int x, int s)
          Left rotate a 32-bit chunk.
private static int rot32R(int x, int s)
          Right rotate a 32-bit chunk.
private  void square(byte[] in, int off, byte[] out, int outOff, int[] T, byte[] S)
          Applies the Square algorithm (for both encryption and decryption since it is the same) on a 128-bit plain/cipher text into a same length cipher/ plain text using the Square formulae, relevant sub-keys, transposition and S-Box values.
private static void transform(int[] in, int[] out)
          Applies the Theta function to an input in in order to produce in out an internal session sub-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

private static final int BLOCK_SIZE
See Also:
Constant Field Values

KEY_LENGTH

private static final int KEY_LENGTH
See Also:
Constant Field Values

R

private static final int R
See Also:
Constant Field Values

SE

private static final byte[] SE
Encryption and decryption Square S-Box values


SD

private static final byte[] SD
Encryption and decryption Square S-Box values


TE

private static final int[] TE
Transposition boxes for encryption and decryption


TD

private static final int[] TD
Transposition boxes for encryption and decryption


ROOT

private static final int ROOT
See Also:
Constant Field Values

OFFSET

private static final int[] OFFSET

sKey

private int[][] sKey
This instance's Square key schedule.


decrypt

private boolean decrypt
Are we decrypting?

Constructor Detail

Square

public Square()
Method Detail

coreInit

protected void coreInit(java.security.Key key,
                        boolean decrypt)
                 throws java.security.InvalidKeyException
Specified by:
coreInit in class BlockCipher

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 class BlockCipher

makeKey

private void makeKey(java.security.Key key,
                     boolean doEncrypt)
              throws java.security.InvalidKeyException
Expands a user-key to a working key schedule.


transform

private static void transform(int[] in,
                              int[] out)
Applies the Theta function to an input in in order to produce in out an internal session sub-key.

Both in and out are arrays of four ints.

Pseudo-code is:

    for (i = 0; i < 4; i++) {
        out[i] = 0;
        for (j = 0, n = 24; j < 4; j++, n -= 8) {
            k = mul(in[i] >>> 24, G[0][j]) ^
                mul(in[i] >>> 16, G[1][j]) ^
                mul(in[i] >>>  8, G[2][j]) ^
                mul(in[i]       , G[3][j]);
            out[i] ^= k << n;
        }
    }
 


rot32L

private static int rot32L(int x,
                          int s)
Left rotate a 32-bit chunk.


rot32R

private static int rot32R(int x,
                          int s)
Right rotate a 32-bit chunk.


mul

private static final int mul(int a,
                             int b)
Returns the product of two binary numbers a and b, using the generator ROOT as the modulus: p = (a * b) mod ROOT. ROOT Generates a suitable Galois Field in GF(2 ** 8).

For best performance call it with abs(b) < abs(a).


square

private void square(byte[] in,
                    int off,
                    byte[] out,
                    int outOff,
                    int[] T,
                    byte[] S)
Applies the Square algorithm (for both encryption and decryption since it is the same) on a 128-bit plain/cipher text into a same length cipher/ plain text using the Square formulae, relevant sub-keys, transposition and S-Box values.