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 int
BLOCK_SIZE
private boolean
doEncrypt
private static int[]
KP
private static int[]
KS0
private static int[]
KS1
private static int[]
KS2
private static int[]
KS3
private int[]
P
private static int
P_SZ
private static int
ROUNDS
private int[]
S0
private int[]
S1
private int[]
S2
private int[]
S3
private static int
SBOX_SK
private byte[]
workingKey
-
Constructor Summary
Constructors Constructor Description BlowFish()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
Bits32ToBytes(int in, byte[] b, int offset)
private int
BytesTo32bits(byte[] b, int i)
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.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.private int
F(int x)
java.lang.String
getAlgorithmName()
int
getBlockSize()
void
init(boolean encrypting, byte[] key)
initialise a Blowfish cipher.private void
processTable(int xl, int xr, int[] table)
apply the encryption cycle to each value pair in the table.void
reset()
private void
setKey(byte[] key)
void
transformBlock(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:
init
in 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:
transformBlock
in interfaceBlockCipher
-
reset
public void reset()
-
getBlockSize
public int getBlockSize()
- Specified by:
getBlockSize
in 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)
-
-