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

pack-priv Class Salsa20Engine

extends Object
implements SkippingStreamCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.internal.SkippingStreamCipher, org.bouncycastle.crypto.internal.SkippingCipher, org.bouncycastle.crypto.internal.StreamCipher
Known Direct Subclasses
org.bouncycastle.crypto.general.ChaCha7539Engine
Imports
org.bouncycastle.crypto.internal.CipherParameters, .DataLengthException, .MaxBytesExceededException, .OutputLengthException, .SkippingStreamCipher, org.bouncycastle.crypto.internal.params.KeyParameter, .ParametersWithIV, org.bouncycastle.util.Pack, .Strings

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

Field Summary

Modifier and TypeField and Description
private int
private int
private int
public static final int
protected int[]
private int
private boolean
private byte[]
protected int
protected static final byte[]
sigma

Deprecated
private static final int
STATE_SIZE

Constants

protected static final byte[]
tau

Deprecated
private static final int[]
protected int[]
x

Constructor Summary

AccessConstructor and Description
public
Salsa20Engine()

Creates a 20 round Salsa20 engine.

public
Salsa20Engine(int
the number of rounds (must be an even number).
rounds
)

Creates a Salsa20 engine with a specific number of rounds.

Method Summary

Modifier and TypeMethod and Description
protected void
advanceCounter(long diff)

protected void
protected void
generateKeyStream(byte[] output)

public String
getAlgorithmName()

Implements org.bouncycastle.crypto.internal.StreamCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.
protected long
protected int
public long
getPosition()

Implements org.bouncycastle.crypto.internal.SkippingCipher.getPosition.

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

Implements org.bouncycastle.crypto.internal.StreamCipher.init.

initialise a Salsa20 cipher.
private boolean
private boolean
limitExceeded(int len)

protected void
packTauOrSigma(int keyLength, int[] state, int stateOffset)

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.internal.StreamCipher.processBytes.

process a block of bytes from in putting the result into out.
public void
protected void
private void
protected void
retreatCounter(long diff)

protected void
public byte
returnByte(byte
the byte to be processed.
in
)

Implements org.bouncycastle.crypto.internal.StreamCipher.returnByte.

encrypt/decrypt a single byte returning the result.
protected static int

Returns:

rotated x
rotl
(int
value to rotate
x
,
int
amount to rotate x
y
)

Rotate left

public static void
salsaCore(int rounds, int[]
input data
input
,
int[] x)

Salsa20 function

public long
seekTo(long
the number of bytes in to set the cipher state to.
position
)

Implements org.bouncycastle.crypto.internal.SkippingCipher.seekTo.

Reset the cipher and then skip forward to a given position.
protected void
setKey(byte[] keyBytes, byte[] ivBytes)

public long
skip(long
the number of bytes to skip (positive forward, negative backwards).
numberOfBytes
)

Implements org.bouncycastle.crypto.internal.SkippingCipher.skip.

Skip numberOfBytes forwards, or backwards.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cW0back to summary
private int cW0
cW1back to summary
private int cW1
cW2back to summary
private int cW2
DEFAULT_ROUNDSback to summary
public static final int DEFAULT_ROUNDS
engineStateback to summary
protected int[] engineState
indexback to summary
private int index
initialisedback to summary
private boolean initialised
keyStreamback to summary
private byte[] keyStream
roundsback to summary
protected int rounds
sigmaback to summary
protected static final byte[] sigma

Deprecated

STATE_SIZEback to summary
private static final int STATE_SIZE

Constants

tauback to summary
protected static final byte[] tau

Deprecated

TAU_SIGMAback to summary
private static final int[] TAU_SIGMA
xback to summary
protected int[] x

Constructor Detail

Salsa20Engineback to summary
public Salsa20Engine()

Creates a 20 round Salsa20 engine.

Salsa20Engineback to summary
public Salsa20Engine(int rounds)

Creates a Salsa20 engine with a specific number of rounds.

Parameters
rounds:int

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

Method Detail

advanceCounterback to summary
protected void advanceCounter(long diff)
advanceCounterback to summary
protected void advanceCounter()
generateKeyStreamback to summary
protected void generateKeyStream(byte[] output)
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.internal.StreamCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.internal.StreamCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.

Returns:String

the name of the algorithm the cipher implements.

getCounterback to summary
protected long getCounter()
getNonceSizeback to summary
protected int getNonceSize()
getPositionback to summary
public long getPosition()

Implements org.bouncycastle.crypto.internal.SkippingCipher.getPosition.

Doc from org.bouncycastle.crypto.internal.SkippingCipher.getPosition.

Return the current "position" of the cipher

Returns:long

the current byte position.

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

Implements org.bouncycastle.crypto.internal.StreamCipher.init.

initialise a Salsa20 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.
limitExceededback to summary
private boolean limitExceeded()
limitExceededback to summary
private boolean limitExceeded(int len)
packTauOrSigmaback to summary
protected void packTauOrSigma(int keyLength, int[] state, int stateOffset)
processBytesback to summary
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff)

Implements org.bouncycastle.crypto.internal.StreamCipher.processBytes.

Doc from org.bouncycastle.crypto.internal.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.

resetback to summary
public void reset()

Implements org.bouncycastle.crypto.internal.StreamCipher.reset.

Doc from org.bouncycastle.crypto.internal.StreamCipher.reset.

reset the cipher. This leaves it in the same state it was at after the last init (if there was one).

resetCounterback to summary
protected void resetCounter()
resetLimitCounterback to summary
private void resetLimitCounter()
retreatCounterback to summary
protected void retreatCounter(long diff)
retreatCounterback to summary
protected void retreatCounter()
returnByteback to summary
public byte returnByte(byte in)

Implements org.bouncycastle.crypto.internal.StreamCipher.returnByte.

Doc from org.bouncycastle.crypto.internal.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.

rotlback to summary
protected static int rotl(int x, int y)

Rotate left

Parameters
x:int

value to rotate

y:int

amount to rotate x

Returns:int

rotated x

salsaCoreback to summary
public static void salsaCore(int rounds, int[] input, int[] x)

Salsa20 function

Parameters
input:int[]

input data

seekToback to summary
public long seekTo(long position)

Implements org.bouncycastle.crypto.internal.SkippingCipher.seekTo.

Doc from org.bouncycastle.crypto.internal.SkippingCipher.seekTo.

Reset the cipher and then skip forward to a given position.

Parameters
position:long

the number of bytes in to set the cipher state to.

Returns:long

the byte position moved to.

setKeyback to summary
protected void setKey(byte[] keyBytes, byte[] ivBytes)
skipback to summary
public long skip(long numberOfBytes)

Implements org.bouncycastle.crypto.internal.SkippingCipher.skip.

Doc from org.bouncycastle.crypto.internal.SkippingCipher.skip.

Skip numberOfBytes forwards, or backwards.

Parameters
numberOfBytes:long

the number of bytes to skip (positive forward, negative backwards).

Returns:long

the number of bytes actually skipped.