Maven module :un.api : api-encoding :
Class : un.impl.cryptography.algorithms.Salsa20
Extends/Implements : un.impl.cryptography.algorithms.CipherAlgorithm
Subclasses : -

A word is an element of { 0, 1, ... , 2³²−1 }.
http://edipermadi.files.wordpress.com/2008/06/salsa20-spec.pdf
author  Bertrand COTE


Variables : -
Functions : cipher, invCipher, getNewCipher, circularLeftShift, quarterRound, rowRound, columnRound, doubleRound, littleEndian, invLittleEndian, hash, expansion, encryption, main, byteArrayToHexString, byteArrayToString





public byte[] cipher (byte[] input)

public byte[] invCipher (byte[] input)

public CipherAlgorithm getNewCipher (byte[] key)


Circular left shift of the register.
E.g:
circularLeftShift(0xc0a8787e, 5) returns 0x150f0fd8
param  register
param  leftShift
return
public int circularLeftShift (int register, int leftShift)


Computes zWords as:

(<<< means circular left shift)

@param y a 4-word sequence.
@return zWords a 4-word sequence if y is a 4-word sequence.
public int[] quarterRound (int[] y)



@param y a 16-word sequence.
@return z a 16-word sequence if y is a 16-word sequence.
public int[] rowRound (int[] y)




@param x a 16-word sequence.
@return y a 16-word sequence.
public int[] columnRound (int[] x)


A double round is a column round followed by a row round:
doubleRound(x) = rowRound(columnRound(x)).
One can visualize a double round as modifying the columns of the input in
parallel, and then modifying the rows in parallel. Each word is modified
twice.
param  x a 16-word sequence.
return  a 16-word sequence.
public int[] doubleRound (int[] x)


If b = (b0 , b1 , b2 , b3 ) then
littleEndian(b) = b3*2²⁴ + b2*2¹⁶ + b1*2⁸ + b0.
Note that littleEndian is invertible.
param  b a 4-byte sequence.
return  a word.
public int littleEndian (byte[] b)

public byte[] invLittleEndian (int w)


param  x a 64-byte sequence.
return  a 64-byte sequence.
public byte[] hash (byte[] x)


“Expansion” refers to the expansion of (k, n) into Salsa20_k (n).
It also refers to the expansion of k into a long stream of Salsa20k
outputs for various n’s; see Section 10.
The constants σ0 σ1 σ2 σ3 and τ0 τ1 τ2 τ3 are “expand 32-byte k” and
“expand 16-byte k” in ASCII.
param  k a 32-byte or 16-byte sequence.
param  n a 16-byte sequence.
return  a 64-byte sequence.
public byte[] expansion (byte[] k, byte[] n)


The Salsa20 encryption of m with nonce v under key k, denoted
Salsa20_k(v)⊕m, is an l-byte sequence.
param  k the secret key: a 32-byte or 16-byte sequence (preferably 32 bytes).
param  v the nonce: an 8-byte sequence (a unique message number).
param  m the plaintext message: an l-byte sequence for some l ∈ { 0, 1, ... , 2⁷⁰ }.
return  the ciphertext message: an l-byte sequence (Salsa20_k(v)⊕m).
public byte[] encryption (byte[] k, byte[] v, byte[] m)

public void main (String[] args)

public String byteArrayToHexString (byte[] byteArray)

public String byteArrayToString (byte[] byteArray)