Table of Contents

Class Salsa20Engine

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

Implementation of Daniel J. Bernstein's Salsa20 stream cipher, Snuffle 2005

public class Salsa20Engine : IStreamCipher
Inheritance
Salsa20Engine
Implements
Derived
Inherited Members

Constructors

Salsa20Engine()

Creates a 20 round Salsa20 engine.

public Salsa20Engine()

Salsa20Engine(int)

Creates a Salsa20 engine with a specific number of rounds.

public Salsa20Engine(int rounds)

Parameters

rounds int

the number of rounds (must be an even number).

Fields

DEFAULT_ROUNDS

public static readonly int DEFAULT_ROUNDS

Field Value

int

rounds

protected int rounds

Field Value

int

Properties

AlgorithmName

The name of the algorithm this cipher implements.

public virtual string AlgorithmName { get; }

Property Value

string

NonceSize

protected virtual int NonceSize { get; }

Property Value

int

Methods

AdvanceCounter()

protected virtual void AdvanceCounter()

GenerateKeyStream(byte[])

protected virtual void GenerateKeyStream(byte[] output)

Parameters

output byte[]

Init(bool, ICipherParameters)

Initialise the cipher.

public virtual void Init(bool forEncryption, ICipherParameters parameters)

Parameters

forEncryption bool

If true the cipher is initialised for encryption, if false for decryption.

parameters ICipherParameters

The key and other data required by the cipher.

Exceptions

ArgumentException

If the parameters argument is inappropriate.

ProcessBytes(byte[], int, int, byte[], int)

Process a block of bytes from input, putting the result into output.

public virtual void ProcessBytes(byte[] inBytes, int inOff, int len, byte[] outBytes, int outOff)

Parameters

inBytes byte[]
inOff int

The offset into input where the data to be processed starts.

len int
outBytes byte[]
outOff int

The offset into output the processed data starts at.

Exceptions

DataLengthException

If the input buffer is too small.

OutputLengthException

If the output buffer is too small.

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

Process a block of bytes from input, putting the result into output.

public virtual void ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output)

Parameters

input ReadOnlySpan<byte>

The input span.

output Span<byte>

The output span.

Exceptions

OutputLengthException

If the output span is too small.

Reset()

Reset the cipher to the same state as it was after the last init (if there was one).

public virtual void Reset()

ResetCounter()

protected virtual void ResetCounter()

ReturnByte(byte)

encrypt/decrypt a single byte returning the result.

public virtual byte ReturnByte(byte input)

Parameters

input byte

the byte to be processed.

Returns

byte

the result of processing the input byte.

SetKey(byte[], byte[])

protected virtual void SetKey(byte[] keyBytes, byte[] ivBytes)

Parameters

keyBytes byte[]
ivBytes byte[]