Top Description Fields Constructors Methods
org.bouncycastle.crypto.modes

public Class OpenPGPCFBBlockCipher

extends Object
implements BlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.BlockCipher
Imports
org.bouncycastle.crypto.BlockCipher, .CipherParameters, .DataLengthException, .OutputLengthException

Implements OpenPGP's rather strange version of Cipher-FeedBack (CFB) mode on top of a simple cipher. This class assumes the IV has been prepended to the data stream already, and just accomodates the reset after (blockSize + 2) bytes have been read.

For further info see RFC 2440.

Field Summary

Modifier and TypeField and Description
private int
private BlockCipher
private int
private boolean
private byte[]
private byte[]
private byte[]

Constructor Summary

AccessConstructor and Description
public
OpenPGPCFBBlockCipher(BlockCipher
the block cipher to be used as the basis of the feedback mode.
cipher
)

Basic constructor.

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

the number of bytes processed and produced.
decryptBlock
(byte[]
the array containing the data to be decrypted.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the encrypted data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Do the appropriate processing for CFB IV mode decryption.

private int

Returns:

the number of bytes processed and produced.
encryptBlock
(byte[]
the array containing the data to be encrypted.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the encrypted data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Do the appropriate processing for CFB IV mode encryption.

private byte

Returns:

the encrypted byte
encryptByte
(byte
the byte to encrypt
data
,
int
offset in the current block
blockOff
)

Encrypt one byte of data according to CFB mode.

public String

Returns:

the name of the underlying algorithm followed by "/OpenPGPCFB" and the block size in bits.
getAlgorithmName
()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

return the algorithm name and mode.
public int

Returns:

the block size we are operating at (in bytes).
getBlockSize
()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

return the block size we are operating at.
public BlockCipher

Returns:

the underlying block cipher that we are wrapping.
getUnderlyingCipher
()

return the underlying block cipher that we are wrapping.

public void
init(boolean
if true the cipher is initialised for encryption, if false for decryption.
forEncryption
,
CipherParameters
the key and other data required by the cipher.
params
)

Implements org.bouncycastle.crypto.BlockCipher.init.

Initialise the cipher and, possibly, the initialisation vector (IV).
public int

Returns:

the number of bytes processed and produced.
processBlock
(byte[]
the array containing the input data.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the output data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.
public void
reset()

Implements org.bouncycastle.crypto.BlockCipher.reset.

reset the chaining vector back to the IV and reset the underlying cipher.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockSizeback to summary
private int blockSize
cipherback to summary
private BlockCipher cipher
countback to summary
private int count
forEncryptionback to summary
private boolean forEncryption
FRback to summary
private byte[] FR
FREback to summary
private byte[] FRE
IVback to summary
private byte[] IV

Constructor Detail

OpenPGPCFBBlockCipherback to summary
public OpenPGPCFBBlockCipher(BlockCipher cipher)

Basic constructor.

Parameters
cipher:BlockCipher

the block cipher to be used as the basis of the feedback mode.

Method Detail

decryptBlockback to summary
private int decryptBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Do the appropriate processing for CFB IV mode decryption.

Parameters
in:byte[]

the array containing the data to be decrypted.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the encrypted data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

Exceptions
DataLengthException:
if there isn't enough data in in, or space in out.
IllegalStateException:
if the cipher isn't initialised.
encryptBlockback to summary
private int encryptBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Do the appropriate processing for CFB IV mode encryption.

Parameters
in:byte[]

the array containing the data to be encrypted.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the encrypted data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

Exceptions
DataLengthException:
if there isn't enough data in in, or space in out.
IllegalStateException:
if the cipher isn't initialised.
encryptByteback to summary
private byte encryptByte(byte data, int blockOff)

Encrypt one byte of data according to CFB mode.

Parameters
data:byte

the byte to encrypt

blockOff:int

offset in the current block

Returns:byte

the encrypted byte

getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

return the algorithm name and mode.

Returns:String

the name of the underlying algorithm followed by "/OpenPGPCFB" and the block size in bits.

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

return the block size we are operating at.

Returns:int

the block size we are operating at (in bytes).

getUnderlyingCipherback to summary
public BlockCipher getUnderlyingCipher()

return the underlying block cipher that we are wrapping.

Returns:BlockCipher

the underlying block cipher that we are wrapping.

initback to summary
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException

Implements org.bouncycastle.crypto.BlockCipher.init.

Initialise the cipher and, possibly, the initialisation vector (IV). If an IV isn't passed as part of the parameter, the IV will be all zeros. An IV which is too short is handled in FIPS compliant fashion.

Parameters
forEncryption:boolean

if true the cipher is initialised for encryption, if false for decryption.

params:CipherParameters

the key and other data required by the cipher.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
processBlockback to summary
public int processBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.

Parameters
in:byte[]

the array containing the input data.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the output data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

Exceptions
DataLengthException:
if there isn't enough data in in, or space in out.
IllegalStateException:
if the cipher isn't initialised.
resetback to summary
public void reset()

Implements org.bouncycastle.crypto.BlockCipher.reset.

reset the chaining vector back to the IV and reset the underlying cipher.