HORIZON HASKELLDocslts/ghc-10.0.x8174fa42026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11

Modulecrypton-2.1.7Haskell2010

Crypto.Cipher.Types

Symmetric cipher basic types

  • 9 types
  • 4 classes
  • 11 values
  • Packagecrypton-2.1.7
  • Exports24
  • LanguageHaskell2010
  • LicenceBSD-3-Clause AND MIT AND ISC
  • SourceTypes.hs

Cipher classes

6 declarations
classclass Cipher cipher where
#

Symmetric cipher class.

Methods

Instances19Cipher, …
classclass Cipher cipher => BlockCipher cipher where
#

Symmetric block cipher class

Methods

  • blockSize :: cipher -> Int

    Return the size of block required for this block cipher

  • ecbEncrypt :: ByteArray ba => cipher -> ba -> ba

    Encrypt blocks

    the input string need to be multiple of the block size

  • ecbDecrypt :: ByteArray ba => cipher -> ba -> ba

    Decrypt blocks

    the input string need to be multiple of the block size

  • cbcEncrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba

    encrypt using the CBC mode.

    input need to be a multiple of the blocksize

  • cbcDecrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba

    decrypt using the CBC mode.

    input need to be a multiple of the blocksize

  • cfbEncrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba

    encrypt using the CFB mode.

    input need to be a multiple of the blocksize

  • cfbDecrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba

    decrypt using the CFB mode.

    input need to be a multiple of the blocksize

  • ctrCombine :: ByteArray ba => cipher -> IV cipher -> ba -> ba

    combine using the CTR mode.

    CTR mode produce a stream of randomized data that is combined (by XOR operation) with the input stream.

    encryption and decryption are the same operation.

    input can be of any size

  • aeadInit :: ByteArrayAccess iv => AEADMode -> cipher -> iv -> CryptoFailable (AEAD cipher)

    Initialize a new AEAD State

    When Nothing is returns, it means the mode is not handled.

Instances19BlockCipher, …
classclass BlockCipher cipher => BlockCipher128 cipher where
#

class of block cipher with a 128 bits block size

Methods

  • xtsEncrypt :: ByteArray ba => (cipher, cipher) -> IV cipher -> DataUnitOffset -> ba -> ba

    encrypt using the XTS mode.

    input need to be a multiple of the blocksize, and the cipher need to process 128 bits block only

  • xtsDecrypt :: ByteArray ba => (cipher, cipher) -> IV cipher -> DataUnitOffset -> ba -> ba

    decrypt using the XTS mode.

    input need to be a multiple of the blocksize, and the cipher need to process 128 bits block only

Instances4BlockCipher128

AEAD functions

13 declarations
valueaeadSimpleDecrypt
  1. :: (ByteArrayAccess aad, ByteArray ba)
  2. => AEAD a

    An AEAD Context

  3. -> aad

    Associated/additional data

  4. -> ba

    Ciphertext

  5. -> AuthTag

    The authentication tag

  6. -> Maybe ba

    Plaintext

#

Simple AEAD decryptio.

The number of bytes compared is the length of authTag. That is the caller's choice of tag length, so a caller reading a tag off the wire must check its length against the one it expects: passing an attacker-supplied tag straight in lets the attacker pick how much of it is verified. Tags shorter than minimumTagLength are rejected outright.

valueminimumTagLength :: Int
#

The shortest authentication tag any mode here produces, four bytes (CCM_M4). Modes that truncate their tag -- GCM and OCB3 -- will compute one of whatever length they are asked for, down to nothing, so aeadSimpleDecrypt refuses a shorter tag than this rather than authenticate fewer bytes than any supported mode ever emits.

valuetryAeadSimpleDecrypt
  1. :: (ByteArrayAccess aad, ByteArray ba)
  2. => AEAD a

    An AEAD Context

  3. -> aad

    Associated/additional data

  4. -> ba

    Ciphertext

  5. -> Int

    The tag length to authenticate, which the tag must match

  6. -> AuthTag

    The authentication tag

  7. -> Maybe ba

    Plaintext

#

Simple AEAD decryption with the tag length given by the caller.

aeadSimpleDecrypt authenticates as many octets as the tag it is handed is long. That is the caller's choice only for as long as the tag is: one read off the wire is the peer's, and an attacker who truncates it picks how much of it gets verified, down to minimumTagLength.

Here the length is a separate argument and a tag that is not exactly that long is refused before anything is compared, so the peer cannot weaken the check. Prefer this wherever the tag is attacker reachable.

datadata AEADModeImpl st
#

AEAD Implementation

Constructors

Initial Vector type and constructor

4 declarations
datadata IV c
#

an IV parametrized by the cipher

Instances2Eq, ByteArrayAccess
valuenullIV :: BlockCipher c => IV c
#

Create an IV that is effectively representing the number 0

valueivAdd :: IV c -> Int -> IV c
#

Increment an IV by a number.

Assume the IV is in Big Endian format.

Authentification Tag

1 declaration