ccs.crypt
Class DuplexBlockCipher
java.lang.Object
ccs.crypt.DuplexBlockCipher
- All Implemented Interfaces:
- org.bouncycastle.crypto.BlockCipher
public class DuplexBlockCipher
- extends java.lang.Object
- implements org.bouncycastle.crypto.BlockCipher
BouncyCastle BlockCipher engines have monolithic initialisers: you
set encrypt/decrypt and the key all in one operation. However, BeeTree
requires its ciphers to alternate frequently, between encrypt and decrypt;
under these conditions monolithic init is a performance loss, especially
for blowfish which isn't very key-agile. This class is a wrapper which
maintains two engines, one set to encrypt, the other to decrypt. This
allows rapid changeover, at the cost of reducing key-agility further
(evey key change needs two initialisations, one each way). For BeeTree
this is a good tradeoff.
Method Summary |
java.lang.String |
getAlgorithmName()
|
int |
getBlockSize()
|
void |
init(boolean isEncrypt,
org.bouncycastle.crypto.CipherParameters param)
Initialise the cipher engines with a new key, or merely change
direction. |
int |
processBlock(byte[] in,
int inOff,
byte[] out,
int outOff)
|
void |
reset()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DuplexBlockCipher
public DuplexBlockCipher(java.lang.Class enginec)
- Constructor.
- Parameters:
enginec
- The class of the engine. Must implement BlockCipher.
getAlgorithmName
public java.lang.String getAlgorithmName()
- Specified by:
getAlgorithmName
in interface org.bouncycastle.crypto.BlockCipher
getBlockSize
public int getBlockSize()
- Specified by:
getBlockSize
in interface org.bouncycastle.crypto.BlockCipher
init
public void init(boolean isEncrypt,
org.bouncycastle.crypto.CipherParameters param)
- Initialise the cipher engines with a new key, or merely change
direction.
- Specified by:
init
in interface org.bouncycastle.crypto.BlockCipher
- Parameters:
isEncrypt
- Set whether we're encrypting or decrypting.param
- If not null, the engines are reinitialised using this.
Set this when actually re-keying, rather than just changing direction.
Typically this needs to be a KeyParameter
.
This cut-out also neutralises the braindeadness of the CBCBlockCipher
layer, which would have you reinitialise the underlying cipher for
every new IV.
processBlock
public int processBlock(byte[] in,
int inOff,
byte[] out,
int outOff)
- Specified by:
processBlock
in interface org.bouncycastle.crypto.BlockCipher
reset
public void reset()
- Specified by:
reset
in interface org.bouncycastle.crypto.BlockCipher