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

public Class HC128Engine

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

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

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

It is a third phase candidate in the eStream contest, and 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
private static int
dim(int x, int y)

private static int
f1(int x)

private static int
f2(int x)

private int
g1(int x, int y, int z)

private int
g2(int x, int y, int z)

public String
getAlgorithmName()

Implements org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.
private byte
private int
h1(int x)

private int
h2(int x)

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-128 cipher.
private static int
mod1024(int x)

private static int
mod512(int x)

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
rotateLeft(int x, int bits)

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

HC128Engineback to summary
public HC128Engine()

Method Detail

dimback to summary
private static int dim(int x, int y)
f1back to summary
private static int f1(int x)
f2back to summary
private static int f2(int x)
g1back to summary
private int g1(int x, int y, int z)
g2back to summary
private int g2(int x, int y, int z)
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()
h1back to summary
private int h1(int x)
h2back to summary
private int h2(int x)
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-128 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 128 bit long).
mod1024back to summary
private static int mod1024(int x)
mod512back to summary
private static int mod512(int x)
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.

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