Crypto.Cipher.ChaCha: exported symbols usage examples

Symbols

  • combine See 2 Occurences [+] Collapse [-]
    Found in Crypto.Cipher.ChaChaPoly1305 from the package cryptonite
    encrypt :: ByteArray ba => ba -> State -> (ba, State)
    encrypt input (State encState macState aadLength plainLength) =
        (output, State newEncState newMacState aadLength newPlainLength)
      where
        (output, newEncState) = ChaCha.combine encState input
        newMacState           = Poly1305.update macState output
        newPlainLength        = plainLength + fromIntegral (B.length input)
    
    -- | Decrypt a piece of data and returns the decrypted Data and the
    -- updated State.
    decrypt :: ByteArray ba => ba -> State -> (ba, State)
    decrypt input (State encState macState aadLength plainLength) =
        (output, State newEncState newMacState aadLength newPlainLength)
      where
        (output, newEncState) = ChaCha.combine encState input
        newMacState           = Poly1305.update macState input
        newPlainLength        = plainLength + fromIntegral (B.length input)
    
    -- | Generate an authentication tag from the State.
    finalize :: State -> Poly1305.Auth
    

    Found in Crypto.Cipher.ChaChaPoly1305 from the package cryptonite
    -- | Finalize the Authenticated Data and return the finalized State
    finalizeAAD :: State -> State
    finalizeAAD (State encState macState aadLength plainLength) =
        State encState newMacState aadLength plainLength
      where
        newMacState = Poly1305.update macState $ pad16 aadLength
    
    -- | Encrypt a piece of data and returns the encrypted Data and the
    -- updated State.
    encrypt :: ByteArray ba => ba -> State -> (ba, State)
    encrypt input (State encState macState aadLength plainLength) =
        (output, State newEncState newMacState aadLength newPlainLength)
      where
        (output, newEncState) = ChaCha.combine encState input
        newMacState           = Poly1305.update macState output
        newPlainLength        = plainLength + fromIntegral (B.length input)
    
    -- | Decrypt a piece of data and returns the decrypted Data and the
    -- updated State.
    

    generate See 4 Occurences [+] Collapse [-]
    Found in Crypto.Cipher.ChaChaPoly1305 from the package cryptonite
    -- The key length need to be 256 bits, and the nonce
    -- procured using either `nonce8` or `nonce12`
    initialize :: ByteArrayAccess key
               => key -> Nonce -> CryptoFailable State
    initialize key (Nonce8  nonce) = initialize' key nonce
    initialize key (Nonce12 nonce) = initialize' key nonce
    
    initialize' :: ByteArrayAccess key
                => key -> Bytes -> CryptoFailable State
    initialize' key nonce
        | B.length key /= 32 = CryptoFailed CryptoError_KeySizeInvalid
        | otherwise          = CryptoPassed $ State encState polyState 0 0
      where
        rootState           = ChaCha.initialize 20 key nonce
        (polyKey, encState) = ChaCha.generate rootState 64
        polyState           = throwCryptoError $ Poly1305.initialize (B.take 32 polyKey :: ScrubbedBytes)
    
    -- | Append Authenticated Data to the State and return
    -- the new modified State.
    --
    

    Found in Crypto.Random.ChaChaDRG from the package cryptonite
    -- | Initialize a new ChaCha context with the number of rounds,
    -- the key and the nonce associated.
    initialize :: B.ByteArrayAccess seed
               => seed        -- ^ 40 bytes of seed
               -> ChaChaDRG   -- ^ the initial ChaCha state
    initialize seed = ChaChaDRG $ C.initializeSimple seed
    
    -- | Initialize a new ChaCha context from 5-tuple of words64.
    -- This interface is useful when creating a RNG out of tests generators (e.g. QuickCheck).
    initializeWords :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
    initializeWords (a,b,c,d,e) = initialize (B.allocAndFreeze 40 fill :: ScrubbedBytes)
      where fill s = mapM_ (uncurry (pokeElemOff s)) [(0,a), (1,b), (2,c), (3,d), (4,e)]
    
    generate :: ByteArray output => Int -> ChaChaDRG -> (output, ChaChaDRG)
    generate nbBytes st@(ChaChaDRG prevSt)
        | nbBytes <= 0 = (B.empty, st)
        | otherwise    = let (output, newSt) = C.generateSimple prevSt nbBytes in (output, ChaChaDRG newSt)
    

    Found in Crypto.Random.ChaChaDRG from the package cryptonite
    -- | Initialize a new ChaCha context with the number of rounds,
    -- the key and the nonce associated.
    initialize :: B.ByteArrayAccess seed
               => seed        -- ^ 40 bytes of seed
               -> ChaChaDRG   -- ^ the initial ChaCha state
    initialize seed = ChaChaDRG $ C.initializeSimple seed
    
    -- | Initialize a new ChaCha context from 5-tuple of words64.
    -- This interface is useful when creating a RNG out of tests generators (e.g. QuickCheck).
    initializeWords :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
    initializeWords (a,b,c,d,e) = initialize (B.allocAndFreeze 40 fill :: ScrubbedBytes)
      where fill s = mapM_ (uncurry (pokeElemOff s)) [(0,a), (1,b), (2,c), (3,d), (4,e)]
    
    generate :: ByteArray output => Int -> ChaChaDRG -> (output, ChaChaDRG)
    generate nbBytes st@(ChaChaDRG prevSt)
        | nbBytes <= 0 = (B.empty, st)
        | otherwise    = let (output, newSt) = C.generateSimple prevSt nbBytes in (output, ChaChaDRG newSt)
    

    Found in Crypto.Random.ChaChaDRG from the package cryptonite
        ( ChaChaDRG
        , initialize
        , initializeWords
        ) where
    
    import           Crypto.Random.Types
    import           Crypto.Internal.Imports
    import           Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, ScrubbedBytes)
    import qualified Crypto.Internal.ByteArray as B
    import           Foreign.Storable (pokeElemOff)
    
    import qualified Crypto.Cipher.ChaCha as C
    
    instance DRG ChaChaDRG where
        randomBytesGenerate = generate
    
    -- | ChaCha Deterministic Random Generator
    newtype ChaChaDRG = ChaChaDRG C.StateSimple
        deriving (NFData)
    

    generateSimple See 1 Occurences [+] Collapse [-]
    Found in Crypto.Random.ChaChaDRG from the package cryptonite
    initialize :: B.ByteArrayAccess seed
               => seed        -- ^ 40 bytes of seed
               -> ChaChaDRG   -- ^ the initial ChaCha state
    initialize seed = ChaChaDRG $ C.initializeSimple seed
    
    -- | Initialize a new ChaCha context from 5-tuple of words64.
    -- This interface is useful when creating a RNG out of tests generators (e.g. QuickCheck).
    initializeWords :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
    initializeWords (a,b,c,d,e) = initialize (B.allocAndFreeze 40 fill :: ScrubbedBytes)
      where fill s = mapM_ (uncurry (pokeElemOff s)) [(0,a), (1,b), (2,c), (3,d), (4,e)]
    
    generate :: ByteArray output => Int -> ChaChaDRG -> (output, ChaChaDRG)
    generate nbBytes st@(ChaChaDRG prevSt)
        | nbBytes <= 0 = (B.empty, st)
        | otherwise    = let (output, newSt) = C.generateSimple prevSt nbBytes in (output, ChaChaDRG newSt)
    

    initialize See 4 Occurences [+] Collapse [-]
    Found in Crypto.Random.ChaChaDRG from the package cryptonite
    -- | ChaCha Deterministic Random Generator
    newtype ChaChaDRG = ChaChaDRG C.StateSimple
        deriving (NFData)
    
    -- | Initialize a new ChaCha context with the number of rounds,
    -- the key and the nonce associated.
    initialize :: B.ByteArrayAccess seed
               => seed        -- ^ 40 bytes of seed
               -> ChaChaDRG   -- ^ the initial ChaCha state
    initialize seed = ChaChaDRG $ C.initializeSimple seed
    
    -- | Initialize a new ChaCha context from 5-tuple of words64.
    -- This interface is useful when creating a RNG out of tests generators (e.g. QuickCheck).
    initializeWords :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
    initializeWords (a,b,c,d,e) = initialize (B.allocAndFreeze 40 fill :: ScrubbedBytes)
      where fill s = mapM_ (uncurry (pokeElemOff s)) [(0,a), (1,b), (2,c), (3,d), (4,e)]
    
    generate :: ByteArray output => Int -> ChaChaDRG -> (output, ChaChaDRG)
    generate nbBytes st@(ChaChaDRG prevSt)
        | nbBytes <= 0 = (B.empty, st)
    

    Found in Crypto.Random.ChaChaDRG from the package cryptonite
    import qualified Crypto.Cipher.ChaCha as C
    
    instance DRG ChaChaDRG where
        randomBytesGenerate = generate
    
    -- | ChaCha Deterministic Random Generator
    newtype ChaChaDRG = ChaChaDRG C.StateSimple
        deriving (NFData)
    
    -- | Initialize a new ChaCha context with the number of rounds,
    -- the key and the nonce associated.
    initialize :: B.ByteArrayAccess seed
               => seed        -- ^ 40 bytes of seed
               -> ChaChaDRG   -- ^ the initial ChaCha state
    initialize seed = ChaChaDRG $ C.initializeSimple seed
    
    -- | Initialize a new ChaCha context from 5-tuple of words64.
    -- This interface is useful when creating a RNG out of tests generators (e.g. QuickCheck).
    initializeWords :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
    initializeWords (a,b,c,d,e) = initialize (B.allocAndFreeze 40 fill :: ScrubbedBytes)
    

    Found in Crypto.Random.ChaChaDRG from the package cryptonite
    import qualified Crypto.Internal.ByteArray as B
    import           Foreign.Storable (pokeElemOff)
    
    import qualified Crypto.Cipher.ChaCha as C
    
    instance DRG ChaChaDRG where
        randomBytesGenerate = generate
    
    -- | ChaCha Deterministic Random Generator
    newtype ChaChaDRG = ChaChaDRG C.StateSimple
        deriving (NFData)
    
    -- | Initialize a new ChaCha context with the number of rounds,
    -- the key and the nonce associated.
    initialize :: B.ByteArrayAccess seed
               => seed        -- ^ 40 bytes of seed
               -> ChaChaDRG   -- ^ the initial ChaCha state
    initialize seed = ChaChaDRG $ C.initializeSimple seed
    
    -- | Initialize a new ChaCha context from 5-tuple of words64.
    

    Found in Crypto.Random.ChaChaDRG from the package cryptonite
    -- |
    -- Module      : Crypto.Random.ChaChaDRG
    -- License     : BSD-style
    -- Maintainer  : Vincent Hanquez <vincent@snarc.org>
    -- Stability   : stable
    -- Portability : good
    --
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    module Crypto.Random.ChaChaDRG
        ( ChaChaDRG
        , initialize
        , initializeWords
        ) where
    
    import           Crypto.Random.Types
    import           Crypto.Internal.Imports
    

    initializeSimple See 1 Occurences [+] Collapse [-]
    Found in Crypto.Random.ChaChaDRG from the package cryptonite
    import qualified Crypto.Cipher.ChaCha as C
    
    instance DRG ChaChaDRG where
        randomBytesGenerate = generate
    
    -- | ChaCha Deterministic Random Generator
    newtype ChaChaDRG = ChaChaDRG C.StateSimple
        deriving (NFData)
    
    -- | Initialize a new ChaCha context with the number of rounds,
    -- the key and the nonce associated.
    initialize :: B.ByteArrayAccess seed
               => seed        -- ^ 40 bytes of seed
               -> ChaChaDRG   -- ^ the initial ChaCha state
    initialize seed = ChaChaDRG $ C.initializeSimple seed
    
    -- | Initialize a new ChaCha context from 5-tuple of words64.
    -- This interface is useful when creating a RNG out of tests generators (e.g. QuickCheck).
    initializeWords :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
    initializeWords (a,b,c,d,e) = initialize (B.allocAndFreeze 40 fill :: ScrubbedBytes)
    

    State No usage example found for this symbol :( Collapse [-]
    StateSimple No usage example found for this symbol :( Collapse [-]