Top Description Inners Fields Constructors Methods
org.bouncycastle.crypto.digests

public Class SkeinEngine

extends Object
implements Memoable
Class Inheritance
All Implemented Interfaces
org.bouncycastle.util.Memoable
Imports
java.util.Enumeration, .Hashtable, .Vector, org.bouncycastle.crypto.OutputLengthException, org.bouncycastle.crypto.engines.ThreefishEngine, org.bouncycastle.crypto.macs.SkeinMac, org.bouncycastle.crypto.params.SkeinParameters, org.bouncycastle.util.Arrays, .Integers, .Memoable, .Pack

Implementation of the Skein family of parameterised hash functions in 256, 512 and 1024 bit block sizes, based on the Threefish tweakable block cipher.

This is the 1.3 version of Skein defined in the Skein hash function submission to the NIST SHA-3 competition in October 2010.

Skein was designed by Niels Ferguson - Stefan Lucks - Bruce Schneier - Doug Whiting - Mihir Bellare - Tadayoshi Kohno - Jon Callas - Jesse Walker.

This implementation is the basis for SkeinDigest and SkeinMac, implementing the parameter based configuration system that allows Skein to be adapted to multiple applications.
Initialising the engine with SkeinParameters allows standard and arbitrary parameters to be applied during the Skein hash function.

Implemented:

Not implemented:

See Also
SkeinParameters

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class
private class
SkeinEngine.UBI

The Unique Block Iteration chaining mode.

private static class

Field Summary

Modifier and TypeField and Description
pack-priv long[]
chain

The current chaining/state value

private static final Hashtable<K, V>
INITIAL_STATES

Precalculated UBI(CFG) states for common state/output combinations without key or other pre-message params.

private long[]
initialState

The initial state value

private byte[]
key

The (optional) key parameter

private final int
outputSizeBytes

Size of the digest output, in bytes

private static final int
PARAM_TYPE_CONFIG

The parameter type for the Skein configuration block.

private static final int
PARAM_TYPE_KEY

The parameter type for the Skein key.

private static final int
PARAM_TYPE_MESSAGE

The parameter type for the message.

private static final int
PARAM_TYPE_OUTPUT

The parameter type for the output transformation.

private SkeinEngine.Parameter[]
postMessageParameters

Parameters to apply after the message, but prior to output

private SkeinEngine.Parameter[]
preMessageParameters

Parameters to apply prior to the message

private final byte[]
singleByte

Buffer for single byte update method

public static final int
SKEIN_1024

1024 bit block size - Skein 1024

public static final int
SKEIN_256

256 bit block size - Skein 256

public static final int
SKEIN_512

512 bit block size - Skein 512

pack-priv final ThreefishEngine
threefish

Underlying Threefish tweakable block cipher

private final SkeinEngine.UBI
ubi

The current UBI operation

Constructor Summary

AccessConstructor and Description
public
SkeinEngine(int
the internal state size in bits - one of SKEIN_256, SKEIN_512 or SKEIN_1024.
blockSizeBits
,
int
the output/digest size to produce in bits, which must be an integral number of bytes.
outputSizeBits
)

Constructs a Skein engine.

public
SkeinEngine(SkeinEngine engine)

Creates a SkeinEngine as an exact copy of an existing instance.

Method Summary

Modifier and TypeMethod and Description
private void
private static SkeinEngine.Parameter[]
public Memoable
copy()

Implements org.bouncycastle.util.Memoable.copy.

Produce a copy of this object with its configuration and in its current state.
private void
private void
createInitialState()

Calculate the initial (pre message block) chaining state.

public int
doFinal(byte[] out, int outOff)

public int
public int
public void
init(SkeinParameters
the parameters to apply to this engine, or null to use no parameters.
params
)

Initialises the Skein engine with the provided parameters.

private static void
initialState(int blockSize, int outputSize, long[] state)

private void
initParams(Hashtable<K, V> parameters)

private void
output(long outputSequence, byte[] out, int outOff, int outputBytes)

public void
reset(Memoable
an object originally copied from an object of the same type as this instance.
other
)

Implements org.bouncycastle.util.Memoable.reset.

Restore a copied object state into this object.
public void
reset()

Reset the engine to the initial state (with the key and any pre-message parameters , ready to accept message input.

private static void
private void
ubiComplete(int type, byte[] value)

private void
private void
ubiInit(int type)

public void
update(byte in)

public void
update(byte[] in, int inOff, int len)

private static Integer
variantIdentifier(int blockSizeBytes, int outputSizeBytes)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chainback to summary
pack-priv long[] chain

The current chaining/state value

INITIAL_STATESback to summary
private static final Hashtable<K, V> INITIAL_STATES

Precalculated UBI(CFG) states for common state/output combinations without key or other pre-message params.

initialStateback to summary
private long[] initialState

The initial state value

keyback to summary
private byte[] key

The (optional) key parameter

outputSizeBytesback to summary
private final int outputSizeBytes

Size of the digest output, in bytes

PARAM_TYPE_CONFIGback to summary
private static final int PARAM_TYPE_CONFIG

The parameter type for the Skein configuration block.

PARAM_TYPE_KEYback to summary
private static final int PARAM_TYPE_KEY

The parameter type for the Skein key.

PARAM_TYPE_MESSAGEback to summary
private static final int PARAM_TYPE_MESSAGE

The parameter type for the message.

PARAM_TYPE_OUTPUTback to summary
private static final int PARAM_TYPE_OUTPUT

The parameter type for the output transformation.

postMessageParametersback to summary
private SkeinEngine.Parameter[] postMessageParameters

Parameters to apply after the message, but prior to output

preMessageParametersback to summary
private SkeinEngine.Parameter[] preMessageParameters

Parameters to apply prior to the message

singleByteback to summary
private final byte[] singleByte

Buffer for single byte update method

SKEIN_1024back to summary
public static final int SKEIN_1024

1024 bit block size - Skein 1024

SKEIN_256back to summary
public static final int SKEIN_256

256 bit block size - Skein 256

SKEIN_512back to summary
public static final int SKEIN_512

512 bit block size - Skein 512

threefishback to summary
pack-priv final ThreefishEngine threefish

Underlying Threefish tweakable block cipher

ubiback to summary
private final SkeinEngine.UBI ubi

The current UBI operation

Constructor Detail

SkeinEngineback to summary
public SkeinEngine(int blockSizeBits, int outputSizeBits)

Constructs a Skein engine.

Parameters
blockSizeBits:int

the internal state size in bits - one of SKEIN_256, SKEIN_512 or SKEIN_1024.

outputSizeBits:int

the output/digest size to produce in bits, which must be an integral number of bytes.

SkeinEngineback to summary
public SkeinEngine(SkeinEngine engine)

Creates a SkeinEngine as an exact copy of an existing instance.

Method Detail

checkInitialisedback to summary
private void checkInitialised()
cloneback to summary
private static SkeinEngine.Parameter[] clone(SkeinEngine.Parameter[] data, SkeinEngine.Parameter[] existing)
copyback to summary
public Memoable copy()

Implements org.bouncycastle.util.Memoable.copy.

Doc from org.bouncycastle.util.Memoable.copy.

Produce a copy of this object with its configuration and in its current state.

The returned object may be used simply to store the state, or may be used as a similar object starting from the copied state.

copyInback to summary
private void copyIn(SkeinEngine engine)
createInitialStateback to summary
private void createInitialState()

Calculate the initial (pre message block) chaining state.

doFinalback to summary
public int doFinal(byte[] out, int outOff)
getBlockSizeback to summary
public int getBlockSize()
getOutputSizeback to summary
public int getOutputSize()
initback to summary
public void init(SkeinParameters params)

Initialises the Skein engine with the provided parameters. See SkeinParameters for details on the parameterisation of the Skein hash function.

Parameters
params:SkeinParameters

the parameters to apply to this engine, or null to use no parameters.

initialStateback to summary
private static void initialState(int blockSize, int outputSize, long[] state)
initParamsback to summary
private void initParams(Hashtable<K, V> parameters)
outputback to summary
private void output(long outputSequence, byte[] out, int outOff, int outputBytes)
resetback to summary
public void reset(Memoable other)

Implements org.bouncycastle.util.Memoable.reset.

Doc from org.bouncycastle.util.Memoable.reset.

Restore a copied object state into this object.

Implementations of this method should try to avoid or minimise memory allocation to perform the reset.

Parameters
other:Memoable

an object originally copied from an object of the same type as this instance.

resetback to summary
public void reset()

Reset the engine to the initial state (with the key and any pre-message parameters , ready to accept message input.

sortback to summary
private static void sort(SkeinEngine.Parameter[] params)
ubiCompleteback to summary
private void ubiComplete(int type, byte[] value)
ubiFinalback to summary
private void ubiFinal()
ubiInitback to summary
private void ubiInit(int type)
updateback to summary
public void update(byte in)
updateback to summary
public void update(byte[] in, int inOff, int len)
variantIdentifierback to summary
private static Integer variantIdentifier(int blockSizeBytes, int outputSizeBytes)
org.bouncycastle.crypto.digests back to summary

private Class SkeinEngine.Configuration

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private byte[]

Constructor Summary

AccessConstructor and Description
public
Configuration(long outputSizeBits)

Method Summary

Modifier and TypeMethod and Description
public byte[]
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bytesback to summary
private byte[] bytes

Constructor Detail

Configurationback to summary
public Configuration(long outputSizeBits)

Method Detail

getBytesback to summary
public byte[] getBytes()
org.bouncycastle.crypto.digests back to summary

public Class SkeinEngine.Parameter

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private byte[]

Constructor Summary

AccessConstructor and Description
public
Parameter(int type, byte[] value)

Method Summary

Modifier and TypeMethod and Description
public int
public byte[]
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

typeback to summary
private int type
valueback to summary
private byte[] value

Constructor Detail

Parameterback to summary
public Parameter(int type, byte[] value)

Method Detail

getTypeback to summary
public int getType()
getValueback to summary
public byte[] getValue()
org.bouncycastle.crypto.digests back to summary

private Class SkeinEngine.UBI

extends Object
Class Inheritance

The Unique Block Iteration chaining mode.

Field Summary

Modifier and TypeField and Description
private byte[]
currentBlock

Buffer for the current block of message data

private int
currentOffset

Offset into the current message block

private long[]
message

Buffer for message words for feedback into encrypted block

private final SkeinEngine.UbiTweak

Constructor Summary

AccessConstructor and Description
public
UBI(int blockSize)

Method Summary

Modifier and TypeMethod and Description
public void
doFinal(long[] output)

private void
processBlock(long[] output)

public void
public void
reset(int type)

public void
update(byte[] value, int offset, int len, long[] output)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentBlockback to summary
private byte[] currentBlock

Buffer for the current block of message data

currentOffsetback to summary
private int currentOffset

Offset into the current message block

messageback to summary
private long[] message

Buffer for message words for feedback into encrypted block

tweakback to summary
private final SkeinEngine.UbiTweak tweak

Constructor Detail

UBIback to summary
public UBI(int blockSize)

Method Detail

doFinalback to summary
public void doFinal(long[] output)
processBlockback to summary
private void processBlock(long[] output)
resetback to summary
public void reset(SkeinEngine.UBI ubi)
resetback to summary
public void reset(int type)
updateback to summary
public void update(byte[] value, int offset, int len, long[] output)
org.bouncycastle.crypto.digests back to summary

private Class SkeinEngine.UbiTweak

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private boolean
extendedPosition

Whether 64 bit position exceeded

private static final long
LOW_RANGE

Point at which position might overflow long, so switch to add with carry logic

private static final long
T1_FINAL

Bit 127 = final

private static final long
T1_FIRST

Bit 126 = first

private long[]
tweak

UBI uses a 128 bit tweak

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
advancePosition(int advance)

Advances the position in the tweak by the specified value.

public int
public long[]
public boolean
public boolean
public void
public void
public void
setFinal(boolean last)

public void
setFirst(boolean first)

public void
setType(int type)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

extendedPositionback to summary
private boolean extendedPosition

Whether 64 bit position exceeded

LOW_RANGEback to summary
private static final long LOW_RANGE

Point at which position might overflow long, so switch to add with carry logic

T1_FINALback to summary
private static final long T1_FINAL

Bit 127 = final

T1_FIRSTback to summary
private static final long T1_FIRST

Bit 126 = first

tweakback to summary
private long[] tweak

UBI uses a 128 bit tweak

Constructor Detail

UbiTweakback to summary
public UbiTweak()

Method Detail

advancePositionback to summary
public void advancePosition(int advance)

Advances the position in the tweak by the specified value.

getTypeback to summary
public int getType()
getWordsback to summary
public long[] getWords()
isFinalback to summary
public boolean isFinal()
isFirstback to summary
public boolean isFirst()
resetback to summary
public void reset(SkeinEngine.UbiTweak tweak)
resetback to summary
public void reset()
setFinalback to summary
public void setFinal(boolean last)
setFirstback to summary
public void setFirst(boolean first)
setTypeback to summary
public void setType(int type)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.