public final class TwofishEngine extends java.lang.Object implements BlockCipher
Modifier and Type | Field and Description |
---|---|
private static int |
BLOCK_SIZE |
private boolean |
encrypting |
private static int |
GF256_FDBK |
private static int |
GF256_FDBK_2 |
private static int |
GF256_FDBK_4 |
private int[] |
gMDS0 |
private int[] |
gMDS1 |
private int[] |
gMDS2 |
private int[] |
gMDS3 |
private int[] |
gSBox |
private int[] |
gSubKeys
gSubKeys[] and gSBox[] are eventually used in the
encryption and decryption methods.
|
private static int |
INPUT_WHITEN |
private int |
k64Cnt |
private static int |
MAX_KEY_BITS |
private static int |
MAX_ROUNDS |
private static int |
OUTPUT_WHITEN |
private static byte[][] |
P |
private static int |
P_00
Define the fixed p0/p1 permutations used in keyed S-box lookup.
|
private static int |
P_01 |
private static int |
P_02 |
private static int |
P_03 |
private static int |
P_04 |
private static int |
P_10 |
private static int |
P_11 |
private static int |
P_12 |
private static int |
P_13 |
private static int |
P_14 |
private static int |
P_20 |
private static int |
P_21 |
private static int |
P_22 |
private static int |
P_23 |
private static int |
P_24 |
private static int |
P_30 |
private static int |
P_31 |
private static int |
P_32 |
private static int |
P_33 |
private static int |
P_34 |
private static int |
ROUND_SUBKEYS |
private static int |
ROUNDS |
private static int |
RS_GF_FDBK |
private static int |
SK_BUMP |
private static int |
SK_ROTL |
private static int |
SK_STEP |
private static int |
TOTAL_SUBKEYS |
private byte[] |
workingKey |
Constructor and Description |
---|
TwofishEngine() |
Modifier and Type | Method and Description |
---|---|
private int |
b0(int x) |
private int |
b1(int x) |
private int |
b2(int x) |
private int |
b3(int x) |
private void |
Bits32ToBytes(int in,
byte[] b,
int offset) |
private int |
BytesTo32Bits(byte[] b,
int p) |
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 |
F32(int x,
int[] k32) |
private int |
Fe32_0(int x) |
private int |
Fe32_3(int x) |
java.lang.String |
getAlgorithmName()
Return the name of the algorithm the cipher implements.
|
int |
getBlockSize()
Return the block size for this cipher (in bytes).
|
void |
init(boolean encrypting,
CipherParameters params)
initialise a Twofish cipher.
|
private int |
LFSR1(int x) |
private int |
LFSR2(int x) |
private int |
Mx_X(int x) |
private int |
Mx_Y(int x) |
int |
processBlock(byte[] in,
int inOff,
byte[] out,
int outOff)
Process one block of input from the array in and write it to
the out array.
|
void |
reset()
Reset the cipher.
|
private int |
RS_MDS_Encode(int k0,
int k1)
Use (12, 8) Reed-Solomon code over GF(256) to produce
a key S-box 32-bit entity from 2 key material 32-bit
entities.
|
private int |
RS_rem(int x)
Reed-Solomon code parameters: (12,8) reversible code:
|
private void |
setKey(byte[] key) |
private static final byte[][] P
private static final int P_00
private static final int P_01
private static final int P_02
private static final int P_03
private static final int P_04
private static final int P_10
private static final int P_11
private static final int P_12
private static final int P_13
private static final int P_14
private static final int P_20
private static final int P_21
private static final int P_22
private static final int P_23
private static final int P_24
private static final int P_30
private static final int P_31
private static final int P_32
private static final int P_33
private static final int P_34
private static final int GF256_FDBK
private static final int GF256_FDBK_2
private static final int GF256_FDBK_4
private static final int RS_GF_FDBK
private static final int ROUNDS
private static final int MAX_ROUNDS
private static final int BLOCK_SIZE
private static final int MAX_KEY_BITS
private static final int INPUT_WHITEN
private static final int OUTPUT_WHITEN
private static final int ROUND_SUBKEYS
private static final int TOTAL_SUBKEYS
private static final int SK_STEP
private static final int SK_BUMP
private static final int SK_ROTL
private boolean encrypting
private int[] gMDS0
private int[] gMDS1
private int[] gMDS2
private int[] gMDS3
private int[] gSubKeys
private int[] gSBox
private int k64Cnt
private byte[] workingKey
public void init(boolean encrypting, CipherParameters params)
init
in interface BlockCipher
encrypting
- whether or not we are for encryption.params
- the parameters required to set up the cipher.java.lang.IllegalArgumentException
- if the params argument is
inappropriate.public java.lang.String getAlgorithmName()
BlockCipher
getAlgorithmName
in interface BlockCipher
public int processBlock(byte[] in, int inOff, byte[] out, int outOff)
BlockCipher
processBlock
in interface BlockCipher
in
- the array containing the input data.inOff
- offset into the in array the data starts at.out
- the array the output data will be copied into.outOff
- the offset into the out array the output will start at.public void reset()
BlockCipher
reset
in interface BlockCipher
public int getBlockSize()
BlockCipher
getBlockSize
in interface BlockCipher
private void setKey(byte[] key)
private void encryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)
private void decryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)
private int F32(int x, int[] k32)
private int RS_MDS_Encode(int k0, int k1)
k0
- first 32-bit entityk1
- second 32-bit entityprivate int RS_rem(int x)
g(x) = x^4 + (a+1/a)x^3 + ax^2 + (a+1/a)x + 1where a = primitive root of field generator 0x14D
private int LFSR1(int x)
private int LFSR2(int x)
private int Mx_X(int x)
private int Mx_Y(int x)
private int b0(int x)
private int b1(int x)
private int b2(int x)
private int b3(int x)
private int Fe32_0(int x)
private int Fe32_3(int x)
private int BytesTo32Bits(byte[] b, int p)
private void Bits32ToBytes(int in, byte[] b, int offset)