Table of Contents

Class ThreefishEngine

Namespace
Org.BouncyCastle.Crypto.Engines
Assembly
BouncyCastle.Cryptography.dll

Implementation of the Threefish tweakable large block cipher in 256, 512 and 1024 bit block sizes.

public class ThreefishEngine : IBlockCipher
Inheritance
ThreefishEngine
Implements
Inherited Members

Remarks

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

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

This implementation inlines all round functions, unrolls 8 rounds, and uses 1.2k of static tables to speed up key schedule injection.
2 x block size state is retained by each cipher instance.

Constructors

ThreefishEngine(int)

Constructs a new Threefish cipher, with a specified block size.

public ThreefishEngine(int blocksizeBits)

Parameters

blocksizeBits int

the block size in bits, one of BLOCKSIZE_256, BLOCKSIZE_512, BLOCKSIZE_1024 .

Fields

BLOCKSIZE_1024

1024 bit block size - Threefish-1024

public const int BLOCKSIZE_1024 = 1024

Field Value

int

BLOCKSIZE_256

256 bit block size - Threefish-256

public const int BLOCKSIZE_256 = 256

Field Value

int

BLOCKSIZE_512

512 bit block size - Threefish-512

public const int BLOCKSIZE_512 = 512

Field Value

int

Properties

AlgorithmName

The name of the algorithm this cipher implements.

public virtual string AlgorithmName { get; }

Property Value

string

Methods

GetBlockSize()

public virtual int GetBlockSize()

Returns

int

The block size for this cipher, in bytes.

Init(bool, ICipherParameters)

Initialise the engine.

public virtual void Init(bool forEncryption, ICipherParameters parameters)

Parameters

forEncryption bool

Initialise for encryption if true, for decryption if false.

parameters ICipherParameters

an instance of TweakableBlockCipherParameters or KeyParameter (to use a 0 tweak)

ProcessBlock(byte[], int, byte[], int)

Process a block.

public virtual int ProcessBlock(byte[] inBytes, int inOff, byte[] outBytes, int outOff)

Parameters

inBytes byte[]
inOff int

The offset into that the input block begins.

outBytes byte[]
outOff int

The offset into to write the output block.

Returns

int

The number of bytes processed and produced.

Exceptions

DataLengthException

If input block is wrong size, or outBuf too small.

ProcessBlock(ReadOnlySpan<byte>, Span<byte>)

Process a block.

public virtual int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output)

Parameters

input ReadOnlySpan<byte>

The input block as a span.

output Span<byte>

The output span.

Returns

int

The number of bytes processed and produced.

Exceptions

DataLengthException

If input block is wrong size, or output span too small.