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

public Class SICBlockCipher

extends StreamBlockCipher
implements CTRModeCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.modes.CTRModeCipher, org.bouncycastle.crypto.SkippingStreamCipher, org.bouncycastle.crypto.SkippingCipher, org.bouncycastle.crypto.StreamCipher, org.bouncycastle.crypto.MultiBlockCipher, org.bouncycastle.crypto.BlockCipher
Imports
org.bouncycastle.crypto.BlockCipher, .CipherParameters, .DataLengthException, .OutputLengthException, .StreamBlockCipher, org.bouncycastle.crypto.params.ParametersWithIV, org.bouncycastle.util.Arrays, .Pack

Implements the Segmented Integer Counter (SIC) mode on top of a simple block cipher. This mode is also known as CTR mode.

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
SICBlockCipher(BlockCipher
the block cipher to be used.
c
)

Deprecated use newInstance() method.
Basic constructor.

Method Summary

Modifier and TypeMethod and Description
private void
adjustCounter(long n)

protected byte
private void
private void
private void
public String
public int
getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

Return the block size for this cipher (in bytes).
public long
getPosition()

Implements org.bouncycastle.crypto.SkippingCipher.getPosition.

Return the current "position" of the cipher
private void
private void
incrementCounter(int offSet)

private void
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, org.bouncycastle.crypto.StreamCipher.init.

Initialise the cipher.
public static CTRModeCipher
newInstance(BlockCipher
the base cipher for the SIC/CTR mode.
cipher
)

Return a new SIC/CTR mode cipher based on the passed in base cipher

public int
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 int
processBytes(byte[]
the input byte array.
in
,
int
the offset into the in array where the data to be processed starts.
inOff
,
int
the number of bytes to be processed.
len
,
byte[]
the output buffer the processed bytes go into.
out
,
int
the offset into the output byte array the processed data starts at.
outOff
)

Overrides org.bouncycastle.crypto.StreamBlockCipher.processBytes.

Implements org.bouncycastle.crypto.StreamCipher.processBytes.

process a block of bytes from in putting the result into out.
public void
public long
seekTo(long
the number of bytes in to set the cipher state to.
position
)

Implements org.bouncycastle.crypto.SkippingCipher.seekTo.

Reset the cipher and then skip forward to a given position.
public long
skip(long
the number of bytes to skip (positive forward, negative backwards).
numberOfBytes
)

Implements org.bouncycastle.crypto.SkippingCipher.skip.

Skip numberOfBytes forwards, or backwards.
Inherited from org.bouncycastle.crypto.StreamBlockCipher:
getUnderlyingCipherreturnByte

Field Detail

blockSizeback to summary
private final int blockSize
byteCountback to summary
private int byteCount
cipherback to summary
private final BlockCipher cipher

Hides org.bouncycastle.crypto.StreamBlockCipher.cipher.

counterback to summary
private byte[] counter
counterOutback to summary
private byte[] counterOut
IVback to summary
private byte[] IV

Constructor Detail

SICBlockCipherback to summary
public SICBlockCipher(BlockCipher c)

Deprecated

use newInstance() method.

Basic constructor.

Parameters
c:BlockCipher

the block cipher to be used.

Method Detail

adjustCounterback to summary
private void adjustCounter(long n)
calculateByteback to summary
protected byte calculateByte(byte in) throws DataLengthException, IllegalStateException

Implements abstract org.bouncycastle.crypto.StreamBlockCipher.calculateByte.

checkCounterback to summary
private void checkCounter()
checkLastIncrementback to summary
private void checkLastIncrement()
decrementCounterAtback to summary
private void decrementCounterAt(int pos)
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName, org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.

Returns:String

the name of the algorithm the cipher implements.

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

Doc from org.bouncycastle.crypto.BlockCipher.getBlockSize.

Return the block size for this cipher (in bytes).

Returns:int

the block size for this cipher in bytes.

getPositionback to summary
public long getPosition()

Implements org.bouncycastle.crypto.SkippingCipher.getPosition.

Doc from org.bouncycastle.crypto.SkippingCipher.getPosition.

Return the current "position" of the cipher

Returns:long

the current byte position.

incrementCounterback to summary
private void incrementCounter()
incrementCounterback to summary
private void incrementCounter(int offSet)
incrementCounterAtback to summary
private void incrementCounterAt(int pos)
initback to summary
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException

Implements org.bouncycastle.crypto.BlockCipher.init, org.bouncycastle.crypto.StreamCipher.init.

Doc from org.bouncycastle.crypto.BlockCipher.init.

Initialise the cipher.

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.
newInstanceback to summary
public static CTRModeCipher newInstance(BlockCipher cipher)

Return a new SIC/CTR mode cipher based on the passed in base cipher

Parameters
cipher:BlockCipher

the base cipher for the SIC/CTR mode.

processBlockback to summary
public int processBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Doc from 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 input , or space in out.
IllegalStateException:
if the cipher isn't initialised.
processBytesback to summary
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException

Overrides org.bouncycastle.crypto.StreamBlockCipher.processBytes.

Implements org.bouncycastle.crypto.StreamCipher.processBytes.

Doc from org.bouncycastle.crypto.StreamCipher.processBytes.

process a block of bytes from in putting the result into out.

Parameters
in:byte[]

the input byte array.

inOff:int

the offset into the in array where the data to be processed starts.

len:int

the number of bytes to be processed.

out:byte[]

the output buffer the processed bytes go into.

outOff:int

the offset into the output byte array the processed data starts at.

Returns:int

the number of bytes produced - should always be len.

Exceptions
DataLengthException:
if the output buffer is too small.
resetback to summary
public void reset()

Implements org.bouncycastle.crypto.BlockCipher.reset, org.bouncycastle.crypto.StreamCipher.reset.

Doc from org.bouncycastle.crypto.BlockCipher.reset.

Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one).

seekToback to summary
public long seekTo(long position)

Implements org.bouncycastle.crypto.SkippingCipher.seekTo.

Doc from org.bouncycastle.crypto.SkippingCipher.seekTo.

Reset the cipher and then skip forward to a given position.

Parameters
position:long

the number of bytes in to set the cipher state to.

Returns:long

the byte position moved to.

skipback to summary
public long skip(long numberOfBytes)

Implements org.bouncycastle.crypto.SkippingCipher.skip.

Doc from org.bouncycastle.crypto.SkippingCipher.skip.

Skip numberOfBytes forwards, or backwards.

Parameters
numberOfBytes:long

the number of bytes to skip (positive forward, negative backwards).

Returns:long

the number of bytes actually skipped.