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

public Class HC256Engine

extends Object
implements StreamCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.StreamCipher
Imports
org.bouncycastle.crypto.*, org.bouncycastle.crypto.constraints.DefaultServiceProperties, org.bouncycastle.crypto.params.KeyParameter, .ParametersWithIV

HC-256 is a software-efficient stream cipher created by Hongjun Wu. It generates keystream from a 256-bit secret key and a 256-bit initialization vector.

https://www.ecrypt.eu.org/stream/p3ciphers/hc/hc256_p3.pdf

Its brother, HC-128, is a third phase candidate in the eStream contest. The algorithm is patent-free. No attacks are known as of today (April 2007). See https://www.ecrypt.eu.org/stream/hcp3.html

Field Summary

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

private int[]
q

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
getAlgorithmName()

Implements org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.
private byte
private void
init()

public void
init(boolean
whether or not we are for encryption. Irrelevant, as encryption and decryption are the same.
forEncryption
,
CipherParameters
the parameters required to set up the cipher.
params
)

Implements org.bouncycastle.crypto.StreamCipher.init.

Initialise a HC-256 cipher.
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
)

Implements org.bouncycastle.crypto.StreamCipher.processBytes.

process a block of bytes from in putting the result into out.
public void
reset()

Implements org.bouncycastle.crypto.StreamCipher.reset.

reset the cipher.
public byte
returnByte(byte
the byte to be processed.
in
)

Implements org.bouncycastle.crypto.StreamCipher.returnByte.

encrypt/decrypt a single byte returning the result.
private static int
rotateRight(int x, int bits)

private int
step()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
private byte[] buf
cntback to summary
private int cnt
idxback to summary
private int idx
initialisedback to summary
private boolean initialised
ivback to summary
private byte[] iv
keyback to summary
private byte[] key
pback to summary
private int[] p
qback to summary
private int[] q

Constructor Detail

HC256Engineback to summary
public HC256Engine()

Method Detail

getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.

Returns:String

the name of the algorithm the cipher implements.

getByteback to summary
private byte getByte()
initback to summary
private void init()
initback to summary
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException

Implements org.bouncycastle.crypto.StreamCipher.init.

Initialise a HC-256 cipher.

Parameters
forEncryption:boolean

whether or not we are for encryption. Irrelevant, as encryption and decryption are the same.

params:CipherParameters

the parameters required to set up the cipher.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate (ie. the key is not 256 bit long).
processBytesback to summary
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException

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.StreamCipher.reset.

Doc from org.bouncycastle.crypto.StreamCipher.reset.

reset the cipher. This leaves it in the same state it was at after the last init (if there was one).

returnByteback to summary
public byte returnByte(byte in)

Implements org.bouncycastle.crypto.StreamCipher.returnByte.

Doc from org.bouncycastle.crypto.StreamCipher.returnByte.

encrypt/decrypt a single byte returning the result.

Parameters
in:byte

the byte to be processed.

Returns:byte

the result of processing the input byte.

rotateRightback to summary
private static int rotateRight(int x, int bits)
stepback to summary
private int step()