Merge pull request #53 from kinoru/master
[ChaChaPoly1305] fix type error of example code
This commit is contained in:
commit
99049cc66e
@ -5,7 +5,8 @@
|
|||||||
-- Stability : stable
|
-- Stability : stable
|
||||||
-- Portability : good
|
-- Portability : good
|
||||||
--
|
--
|
||||||
-- A simple AEAD scheme using ChaCha20 and Poly1305. See RFC7539.
|
-- A simple AEAD scheme using ChaCha20 and Poly1305. See
|
||||||
|
-- <https://tools.ietf.org/html/rfc7539 RFC 7539>.
|
||||||
--
|
--
|
||||||
-- The State is not modified in place, so each function changing the State,
|
-- The State is not modified in place, so each function changing the State,
|
||||||
-- returns a new State.
|
-- returns a new State.
|
||||||
@ -15,12 +16,24 @@
|
|||||||
--
|
--
|
||||||
-- Once 'finalizeAAD' has been called, no further 'appendAAD' call should be make.
|
-- Once 'finalizeAAD' has been called, no further 'appendAAD' call should be make.
|
||||||
--
|
--
|
||||||
-- > encrypt nonce key hdr inp =
|
-- >import Data.ByteString.Char8 as B
|
||||||
-- > let st1 = ChaChaPoly1305.initialize key nonce
|
-- >import Data.ByteArray
|
||||||
-- > st2 = ChaChaPoly1305.finalizeAAD $ ChaChaPoly1305.appendAAD hdr st1
|
-- >import Crypto.Error
|
||||||
-- > (out, st3) = ChaChaPoly1305.encrypt inp st2
|
-- >import Crypto.Cipher.ChaChaPoly1305 as C
|
||||||
-- > auth = ChaChaPoly1305.finalize st3
|
-- >
|
||||||
-- > in out `B.append` Data.ByteArray.convert auth
|
-- >encrypt
|
||||||
|
-- > :: ByteString -- nonce (12 random bytes)
|
||||||
|
-- > -> ByteString -- symmetric key
|
||||||
|
-- > -> ByteString -- optional associated data (won't be encrypted)
|
||||||
|
-- > -> ByteString -- input plaintext to be encrypted
|
||||||
|
-- > -> CryptoFailable ByteString -- ciphertext with a 128-bit tag attached
|
||||||
|
-- >encrypt nonce key header plaintext = do
|
||||||
|
-- > st1 <- C.nonce12 nonce >>= C.initialize key
|
||||||
|
-- > let
|
||||||
|
-- > st2 = C.finalizeAAD $ C.appendAAD header st1
|
||||||
|
-- > (out, st3) = C.encrypt plaintext st2
|
||||||
|
-- > auth = C.finalize st3
|
||||||
|
-- > return $ out `B.append` Data.ByteArray.convert auth
|
||||||
--
|
--
|
||||||
module Crypto.Cipher.ChaChaPoly1305
|
module Crypto.Cipher.ChaChaPoly1305
|
||||||
( State
|
( State
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user