PageRenderTime 86ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/cryptocipher/Crypto/Cipher.hs

http://github.com/vincenthz/hs-cryptocipher
Haskell | 57 lines | 28 code | 1 blank | 28 comment | 0 complexity | 1bfa16e008e125a4d7da58af0413a22e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. -- |
  2. -- Module : Crypto.Cipher
  3. -- License : BSD-style
  4. -- Maintainer : Vincent Hanquez <vincent@snarc.org>
  5. -- Stability : stable
  6. -- Portability : good
  7. --
  8. -- All the cipher functionalities are available through the
  9. -- BlockCipher and StreamCipher classes.
  10. --
  11. -- A simplified example (with simplified error handling):
  12. --
  13. -- > import Crypto.Cipher
  14. -- > import Data.ByteString (ByteString)
  15. -- > import qualified Data.ByteString as B
  16. -- >
  17. -- > initAES256 :: ByteString -> AES256
  18. -- > initAES256 = either (error . show) cipherInit . makeKey
  19. -- >
  20. -- > cbcEncryption :: AES256 -> ByteString -> ByteString -> ByteString
  21. -- > cbcEncryption ctx ivRaw plainText = cbcEncrypt ctx iv plainText
  22. -- > where iv = maybe (error "invalid IV") id $ ivRaw
  23. --
  24. module Crypto.Cipher
  25. (
  26. -- * Cipher classes
  27. Cipher(..)
  28. , BlockCipher(..)
  29. , StreamCipher(..)
  30. -- * Key
  31. , Key
  32. , makeKey
  33. -- * Initialization Vector (IV)
  34. , IV
  35. , makeIV
  36. , nullIV
  37. , ivAdd
  38. -- * Authenticated Encryption with Associated Data (AEAD)
  39. , AEAD
  40. , aeadAppendHeader
  41. , aeadEncrypt
  42. , aeadDecrypt
  43. , aeadFinalize
  44. -- * Cipher implementations
  45. , AES128, AES192, AES256
  46. , Blowfish, Blowfish64, Blowfish128, Blowfish256, Blowfish448
  47. , DES
  48. , DES_EEE3, DES_EDE3, DES_EEE2, DES_EDE2
  49. , Camellia128
  50. ) where
  51. import Crypto.Cipher.Types
  52. import Crypto.Cipher.AES (AES128, AES192, AES256)
  53. import Crypto.Cipher.Blowfish
  54. import Crypto.Cipher.DES
  55. import Crypto.Cipher.TripleDES
  56. import Crypto.Cipher.Camellia