Package com.trilead.ssh2.crypto.cipher
Class BlowFish
java.lang.Object
com.trilead.ssh2.crypto.cipher.BlowFish
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprivate static final int
private boolean
private static final int[]
private static final int[]
private static final int[]
private static final int[]
private static final int[]
private final int[]
private static final int
private static final int
private final int[]
private final int[]
private final int[]
private final int[]
private static final int
private byte[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate 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) int
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) final void
transformBlock
(byte[] in, int inOff, byte[] out, int outOff)
-
Field Details
-
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:
-
BLOCK_SIZE
private static final int BLOCK_SIZE- See Also:
-
SBOX_SK
private static final int SBOX_SK- See Also:
-
P_SZ
private static final int P_SZ- See Also:
-
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
-
-
Constructor Details
-
BlowFish
public BlowFish()
-
-
Method Details
-
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:
IllegalArgumentException
- if the params argument is inappropriate.
-
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)
-