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

Quick Search    Search Deep

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

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

public final class Blowfish
extends BlockCipher

This class implements the Blowfish algorithm (standard, 16 round version). Blowfish is a symmetric block cipher, with a 64-bit blocksize and a variable key length (between 40 and 448 bits inclusive, in 8-bit increments).

References:

The implementation is heavily optimized (but we can still do better):

Speed optimizations thanks to Peter Hjelt . Additional speed and size optimizations by gelderen .

Version:
$Revision: 1.6 $

Field Summary
private static int BLOCK_SIZE
          Self eplanatory constants
private static java.lang.String cP
          Compressed initial values for the P-box and S-boxes
private static java.lang.String cS
          Compressed initial values for the P-box and S-boxes
private  int K00
          Individual ints representing the session key taken from int[] P.
private  int K01
          Individual ints representing the session key taken from int[] P.
private  int K02
          Individual ints representing the session key taken from int[] P.
private  int K03
          Individual ints representing the session key taken from int[] P.
private  int K04
          Individual ints representing the session key taken from int[] P.
private  int K05
          Individual ints representing the session key taken from int[] P.
private  int K06
          Individual ints representing the session key taken from int[] P.
private  int K07
          Individual ints representing the session key taken from int[] P.
private  int K08
          Individual ints representing the session key taken from int[] P.
private  int K09
          Individual ints representing the session key taken from int[] P.
private  int K10
          Individual ints representing the session key taken from int[] P.
private  int K11
          Individual ints representing the session key taken from int[] P.
private  int K12
          Individual ints representing the session key taken from int[] P.
private  int K13
          Individual ints representing the session key taken from int[] P.
private  int K14
          Individual ints representing the session key taken from int[] P.
private  int K15
          Individual ints representing the session key taken from int[] P.
private  int K16
          Individual ints representing the session key taken from int[] P.
private  int K17
          Individual ints representing the session key taken from int[] P.
private static int MAX_USER_KEY_LENGTH
          Self eplanatory constants
private static int MIN_USER_KEY_LENGTH
          Self eplanatory constants
private  int[] P
          P-box, used during key-setup
private static int ROUNDS
          Self eplanatory constants
private  int[] S0
          4 S-boxes
private  int[] S1
          4 S-boxes
private  int[] S2
          4 S-boxes
private  int[] S3
          4 S-boxes
private static int[] sP
          P-box and S-boxes
private static int[] sS
          P-box and S-boxes
 
Fields inherited from class cryptix.jce.provider.cipher.BlockCipher
 
Constructor Summary
Blowfish()
           
 
Method Summary
protected  void coreCrypt(byte[] in, int inOffset, byte[] out, int outOffset)
          Encrypt or decrypt a single block of data.
protected  void coreInit(java.security.Key key, boolean decrypt)
          Initialize the object for encryption or decryption, given a Key.
private  void keyEncrypt(int L, int R, int[] out, int outOff)
          Perform a Blowfish encryption.
 
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

cP

private static final java.lang.String cP
Compressed initial values for the P-box and S-boxes

See Also:
Constant Field Values

cS

private static final java.lang.String cS
Compressed initial values for the P-box and S-boxes

See Also:
Constant Field Values

ROUNDS

private static final int ROUNDS
Self eplanatory constants

See Also:
Constant Field Values

BLOCK_SIZE

private static final int BLOCK_SIZE
Self eplanatory constants

See Also:
Constant Field Values

MIN_USER_KEY_LENGTH

private static final int MIN_USER_KEY_LENGTH
Self eplanatory constants

See Also:
Constant Field Values

MAX_USER_KEY_LENGTH

private static final int MAX_USER_KEY_LENGTH
Self eplanatory constants

See Also:
Constant Field Values

sP

private static final int[] sP
P-box and S-boxes


sS

private static final int[] sS
P-box and S-boxes


P

private final int[] P
P-box, used during key-setup


K00

private int K00
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K01

private int K01
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K02

private int K02
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K03

private int K03
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K04

private int K04
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K05

private int K05
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K06

private int K06
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K07

private int K07
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K08

private int K08
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K09

private int K09
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K10

private int K10
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K11

private int K11
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K12

private int K12
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K13

private int K13
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K14

private int K14
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K15

private int K15
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K16

private int K16
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


K17

private int K17
Individual ints representing the session key taken from int[] P. We use these as a speedup instead of the P-array itself.


S0

private final int[] S0
4 S-boxes


S1

private final int[] S1
4 S-boxes


S2

private final int[] S2
4 S-boxes


S3

private final int[] S3
4 S-boxes

Constructor Detail

Blowfish

public Blowfish()
Method Detail

coreInit

protected void coreInit(java.security.Key key,
                        boolean decrypt)
                 throws java.security.InvalidKeyException
Initialize the object for encryption or decryption, given a Key.

This method expects a key with algorithm 'Blowfish' and format 'RAW'. Both are case insensitive.

FIXME: checks need overhaul (or moved out to superclass).

Specified by:
coreInit in class BlockCipher

coreCrypt

protected void coreCrypt(byte[] in,
                         int inOffset,
                         byte[] out,
                         int outOffset)
Encrypt or decrypt a single block of data.

Specified by:
coreCrypt in class BlockCipher

keyEncrypt

private void keyEncrypt(int L,
                        int R,
                        int[] out,
                        int outOff)
Perform a Blowfish encryption. This method is only called by the makeKey method to generate the key schedule from user data. It outputs the result to an int array.