Package com.trilead.ssh2.crypto.cipher
Class BlowFish
- java.lang.Object
-
- com.trilead.ssh2.crypto.cipher.BlowFish
-
- All Implemented Interfaces:
BlockCipher
public class BlowFish extends java.lang.Object implements BlockCipher
A class that provides Blowfish key encryption operations, such as encoding data and generating keys. All the algorithms herein are from Applied Cryptography and implement a simplified cryptography interface.- Version:
- $Id: BlowFish.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
-
-
Field Summary
Fields Modifier and Type Field Description private static intBLOCK_SIZEprivate booleandoEncryptprivate static int[]KPprivate static int[]KS0private static int[]KS1private static int[]KS2private static int[]KS3private int[]Pprivate static intP_SZprivate static intROUNDSprivate int[]S0private int[]S1private int[]S2private int[]S3private static intSBOX_SKprivate byte[]workingKey
-
Constructor Summary
Constructors Constructor Description BlowFish()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidBits32ToBytes(int in, byte[] b, int offset)private intBytesTo32bits(byte[] b, int i)private voiddecryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)Decrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset.private voidencryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)Encrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset.private intF(int x)java.lang.StringgetAlgorithmName()intgetBlockSize()voidinit(boolean encrypting, byte[] key)initialise a Blowfish cipher.private voidprocessTable(int xl, int xr, int[] table)apply the encryption cycle to each value pair in the table.voidreset()private voidsetKey(byte[] key)voidtransformBlock(byte[] in, int inOff, byte[] out, int outOff)
-
-
-
Field Detail
-
KP
private static final int[] KP
-
KS0
private static final int[] KS0
-
KS1
private static final int[] KS1
-
KS2
private static final int[] KS2
-
KS3
private static final int[] KS3
-
ROUNDS
private static final int ROUNDS
- See Also:
- Constant Field Values
-
BLOCK_SIZE
private static final int BLOCK_SIZE
- See Also:
- Constant Field Values
-
SBOX_SK
private static final int SBOX_SK
- See Also:
- Constant Field Values
-
P_SZ
private static final int P_SZ
- See Also:
- Constant Field Values
-
S0
private final int[] S0
-
S1
private final int[] S1
-
S2
private final int[] S2
-
S3
private final int[] S3
-
P
private final int[] P
-
doEncrypt
private boolean doEncrypt
-
workingKey
private byte[] workingKey
-
-
Method Detail
-
init
public void init(boolean encrypting, byte[] key)initialise a Blowfish cipher.- Specified by:
initin interfaceBlockCipher- Parameters:
encrypting- whether or not we are for encryption.key- the key required to set up the cipher.- Throws:
java.lang.IllegalArgumentException- if the params argument is inappropriate.
-
getAlgorithmName
public java.lang.String getAlgorithmName()
-
transformBlock
public final void transformBlock(byte[] in, int inOff, byte[] out, int outOff)- Specified by:
transformBlockin interfaceBlockCipher
-
reset
public void reset()
-
getBlockSize
public int getBlockSize()
- Specified by:
getBlockSizein interfaceBlockCipher
-
F
private int F(int x)
-
processTable
private void processTable(int xl, int xr, int[] table)apply the encryption cycle to each value pair in the table.
-
setKey
private void setKey(byte[] key)
-
encryptBlock
private void encryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)Encrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset. The input will be an exact multiple of our blocksize.
-
decryptBlock
private void decryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)Decrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset. The input will be an exact multiple of our blocksize.
-
BytesTo32bits
private int BytesTo32bits(byte[] b, int i)
-
Bits32ToBytes
private void Bits32ToBytes(int in, byte[] b, int offset)
-
-