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

public Class Zuc128CoreEngine

extends Object
implements StreamCipher, Memoable
Class Inheritance
All Implemented Interfaces
org.bouncycastle.util.Memoable, org.bouncycastle.crypto.StreamCipher
Known Direct Subclasses
org.bouncycastle.crypto.engines.Zuc128Engine, org.bouncycastle.crypto.engines.Zuc256CoreEngine, org.bouncycastle.crypto.macs.Zuc128Mac.InternalZuc128Engine
Imports
org.bouncycastle.crypto.CipherParameters, .CryptoServicePurpose, .CryptoServicesRegistrar, .DataLengthException, .OutputLengthException, .StreamCipher, org.bouncycastle.crypto.constraints.DefaultServiceProperties, org.bouncycastle.crypto.params.KeyParameter, .ParametersWithIV, org.bouncycastle.util.Memoable

Zuc128Engine implementation. Based on https://www.gsma.com/aboutus/wp-content/uploads/2014/12/eea3eia3zucv16.pdf

Field Summary

Modifier and TypeField and Description
private final int[]
private static final short[]
private final int[]
F

private final byte[]
keyStream

Advanced stream.

private final int[]
LFSR

State.

private static final byte[]
private static final byte[]
private int
theIndex

index of next byte in keyStream.

private int
theIterations

The iterations.

private Zuc128CoreEngine
theResetState

Reset state.

Constructor Summary

AccessConstructor and Description
protected
Zuc128CoreEngine()

Constructor.

protected
Zuc128CoreEngine(final Zuc128CoreEngine
the source engine
pSource
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

the result
AddM
(final int
value A
a
,
final int
value B
b
)

Modular add c = a + b mod (2^31 � 1).

private void
BitReorganization()

BitReorganization.

public Memoable

Returns:

the copy
copy
()

Implements org.bouncycastle.util.Memoable.copy.

Create a copy of the engine.
public static void
encode32be(int
the value to encode
val
,
byte[]
the output buffer
buf
,
int
the output offset
off
)

Encode a 32-bit value into a buffer (little-endian).

pack-priv int
F()

F.

public String

Returns:

the name
getAlgorithmName
()

Implements org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

Obtain Algorithm Name.
protected int

Returns:

the maximum iterations
getMaxIterations
()

Obtain Max iterations.

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

Implements org.bouncycastle.crypto.StreamCipher.init.

initialise a Snow3G cipher.
private static int

Returns:

the result
L1
(final int
the input integer.
X
)

L1.

private static int

Returns:

the result
L2
(final int
the input integer.
X
)

L2.

private void
LFSRWithInitialisationMode(final int u)

LFSR with initialisation mode.

private void
LFSRWithWorkMode()

LFSR with work mode.

private void
makeKeyStream()

Create the next byte keyStream.

protected int

Returns:

the next word
makeKeyStreamWord
()

Create the next keyStream word.

private static int

Returns:

the built integer
MAKEU31
(final byte
part A
a
,
final short
part B
b
,
final byte
part C
c
)

Build a 31-bit integer from constituent parts.

private static int

Returns:

the built integer
MAKEU32
(final byte
part A
a
,
final byte
part B
b
,
final byte
part C
c
,
final byte
part D
d
)

Build a 32-bit integer from constituent parts.

private static int

Returns:

the result
MulByPow2
(final int
input value
x
,
final int
the power of two
k
)

Multiply by power of two.

public int

Returns:

the number of bytes returned in the output buffer
processBytes
(final byte[]
the input buffer
in
,
final int
the starting offset in the input buffer
inOff
,
final int
the length of data in the input buffer
len
,
final byte[]
the output buffer
out
,
final int
the starting offset in the output buffer
outOff
)

Implements org.bouncycastle.crypto.StreamCipher.processBytes.

Process bytes.
public void
reset()

Implements org.bouncycastle.crypto.StreamCipher.reset.

Reset the engine.
public void
reset(final Memoable
the state to restore
pState
)

Implements org.bouncycastle.util.Memoable.reset.

Reset from saved engine state.
public byte

Returns:

the output byte
returnByte
(final byte
the input byte
in
)

Implements org.bouncycastle.crypto.StreamCipher.returnByte.

Process single byte.
pack-priv static int

Returns:

the result
ROT
(int
the integer
a
,
int
the shift
k
)

Rotate integer.

protected void
setKeyAndIV(final int[]
the LFSR
pLFSR
,
final byte[]
the key
k
,
final byte[]
the iv
iv
)

Process key and IV into LFSR.

private void
setKeyAndIV(final byte[]
the key
k
,
final byte[]
the IV
iv
)

Process key and IV.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BRCback to summary
private final int[] BRC
EK_dback to summary
private static final short[] EK_d
Fback to summary
private final int[] F
keyStreamback to summary
private final byte[] keyStream

Advanced stream.

LFSRback to summary
private final int[] LFSR

State.

S0back to summary
private static final byte[] S0
S1back to summary
private static final byte[] S1
theIndexback to summary
private int theIndex

index of next byte in keyStream.

theIterationsback to summary
private int theIterations

The iterations.

theResetStateback to summary
private Zuc128CoreEngine theResetState

Reset state.

Constructor Detail

Zuc128CoreEngineback to summary
protected Zuc128CoreEngine()

Constructor.

Zuc128CoreEngineback to summary
protected Zuc128CoreEngine(final Zuc128CoreEngine pSource)

Constructor.

Parameters
pSource:Zuc128CoreEngine

the source engine

Method Detail

AddMback to summary
private int AddM(final int a, final int b)

Modular add c = a + b mod (2^31 � 1).

Parameters
a:int

value A

b:int

value B

Returns:int

the result

BitReorganizationback to summary
private void BitReorganization()

BitReorganization.

copyback to summary
public Memoable copy()

Implements org.bouncycastle.util.Memoable.copy.

Create a copy of the engine.

Returns:Memoable

the copy

encode32beback to summary
public static void encode32be(int val, byte[] buf, int off)

Encode a 32-bit value into a buffer (little-endian).

Parameters
val:int

the value to encode

buf:byte[]

the output buffer

off:int

the output offset

Fback to summary
pack-priv int F()

F.

getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

Obtain Algorithm Name.

Returns:String

the name

getMaxIterationsback to summary
protected int getMaxIterations()

Obtain Max iterations.

Returns:int

the maximum iterations

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

Implements org.bouncycastle.crypto.StreamCipher.init.

initialise a Snow3G cipher.

Parameters
forEncryption:boolean

whether or not we are for encryption.

params:CipherParameters

the parameters required to set up the cipher.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
L1back to summary
private static int L1(final int X)

L1.

Parameters
X:int

the input integer.

Returns:int

the result

L2back to summary
private static int L2(final int X)

L2.

Parameters
X:int

the input integer.

Returns:int

the result

LFSRWithInitialisationModeback to summary
private void LFSRWithInitialisationMode(final int u)

LFSR with initialisation mode.

LFSRWithWorkModeback to summary
private void LFSRWithWorkMode()

LFSR with work mode.

makeKeyStreamback to summary
private void makeKeyStream()

Create the next byte keyStream.

makeKeyStreamWordback to summary
protected int makeKeyStreamWord()

Create the next keyStream word.

Returns:int

the next word

MAKEU31back to summary
private static int MAKEU31(final byte a, final short b, final byte c)

Build a 31-bit integer from constituent parts.

Parameters
a:byte

part A

b:short

part B

c:byte

part C

Returns:int

the built integer

MAKEU32back to summary
private static int MAKEU32(final byte a, final byte b, final byte c, final byte d)

Build a 32-bit integer from constituent parts.

Parameters
a:byte

part A

b:byte

part B

c:byte

part C

d:byte

part D

Returns:int

the built integer

MulByPow2back to summary
private static int MulByPow2(final int x, final int k)

Multiply by power of two.

Parameters
x:int

input value

k:int

the power of two

Returns:int

the result

processBytesback to summary
public int processBytes(final byte[] in, final int inOff, final int len, final byte[] out, final int outOff)

Implements org.bouncycastle.crypto.StreamCipher.processBytes.

Process bytes.

Parameters
in:byte[]

the input buffer

inOff:int

the starting offset in the input buffer

len:int

the length of data in the input buffer

out:byte[]

the output buffer

outOff:int

the starting offset in the output buffer

Returns:int

the number of bytes returned in the output buffer

resetback to summary
public void reset()

Implements org.bouncycastle.crypto.StreamCipher.reset.

Reset the engine.

resetback to summary
public void reset(final Memoable pState)

Implements org.bouncycastle.util.Memoable.reset.

Reset from saved engine state.

Parameters
pState:Memoable

the state to restore

returnByteback to summary
public byte returnByte(final byte in)

Implements org.bouncycastle.crypto.StreamCipher.returnByte.

Process single byte.

Parameters
in:byte

the input byte

Returns:byte

the output byte

ROTback to summary
pack-priv static int ROT(int a, int k)

Rotate integer.

Parameters
a:int

the integer

k:int

the shift

Returns:int

the result

setKeyAndIVback to summary
protected void setKeyAndIV(final int[] pLFSR, final byte[] k, final byte[] iv)

Process key and IV into LFSR.

Parameters
pLFSR:int[]

the LFSR

k:byte[]

the key

iv:byte[]

the iv

setKeyAndIVback to summary
private void setKeyAndIV(final byte[] k, final byte[] iv)

Process key and IV.

Parameters
k:byte[]

the key

iv:byte[]

the IV