HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulecrypton-1.0.4Haskell2010

Crypto.Cipher.XSalsa

Implementation of XSalsa20 algorithm https://cr.yp.to/snuffle/xsalsa-20081128.pdf Based on the Salsa20 algorithm with 256 bit key extended with 192 bit nonce

  • 1 type
  • 4 values
  • Packagecrypton-1.0.4
  • Exports5
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceXSalsa.hs
valueinitialize
  1. :: (ByteArrayAccess key, ByteArrayAccess nonce)
  2. => Int

    number of rounds (8,12,20)

  3. -> key

    the key (256 bits)

  4. -> nonce

    the nonce (192 bits)

  5. -> State

    the initial XSalsa state

#

Initialize a new XSalsa context with the number of rounds, the key and the nonce associated.

valuederive
  1. :: ByteArrayAccess nonce
  2. => State

    base XSalsa state

  3. -> nonce

    the remainder nonce (128 bits)

  4. -> State

    the new XSalsa state

#

Use an already initialized context and new nonce material to derive another XSalsa context.

This allows a multi-level cascade where a first key k1 and nonce n1 is used to get HState(k1,n1), and this value is then used as key k2 to build XSalsa(k2,n2). Function initialize is to be called with the first 192 bits of n1|n2, and the call to derive should add the remaining 128 bits.

The output context always uses the same number of rounds as the input context.

valuecombine
  1. :: ByteArray ba
  2. => State

    the current Salsa state

  3. -> ba

    the source to xor with the generator

  4. -> (ba, State)
#

Combine the salsa output and an arbitrary message with a xor, and return the combined output and the new state.

valuegenerate
  1. :: ByteArray ba
  2. => State

    the current Salsa state

  3. -> Int

    the length of data to generate

  4. -> (ba, State)
#

Generate a number of bytes from the Salsa output directly

newtypenewtype State
#

Salsa context

Instances1NFData
  • NFData StateDefined in crypton-1.0.4 · Crypto.Cipher.Salsa