Z-Botan-0.4.0.0: Crypto for Haskell
CopyrightDong Han 2021
AnJie Dong 2021
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.Crypto.PubKey

Description

This module is used for Public key cryptography. Public key cryptography (also called asymmetric cryptography) is a collection of techniques allowing for encryption, signatures, and key agreement.

Synopsis

Asymmetric cryptography algorithms

data KeyType Source #

Public key cryptography algorithms.

Constructors

RSA Word32

RSA key of the given size, namely n bits, support encryption and signature.

SM2 ECGroup

Public key algorithms specified by China, support encryption and signature.

ElGamal DLGroup

ElGamal encryption system, support encryption.

DSA DLGroup

Digital Signature Algorithm based on the discrete logarithm problem.

ECDSA ECGroup

Digital Signature Algorithm which uses elliptic curve cryptography.

ECKCDSA ECGroup

Korean Certificate-based Digital Signature Algorithm.

ECGDSA ECGroup

Elliptic Curve German Digital Signature Algorithm.

GOST_34'10 ECGroup

Cryptographic algorithms defined by the Russian national standards, support signature.

Ed25519

Ed25519 elliptic-curve signatures, see ed25519.

XMSS XMSSType

eXtended Merkle Signature Scheme, see https://botan.randombit.net/handbook/api_ref/pubkey.html#extended-merkle-signature-scheme-xmss.

DH DLGroup

The Diffie–Hellman key exchange.

ECDH ECGroup

The Elliptic-curve Diffie–Hellman key exchange.

Curve25519

The Curve25519 Diffie–Hellman key exchange.

Key generation and manipulation

data PrivKey Source #

An opaque data type for a private-public key pair.

Instances

Instances details
Show PrivKey Source # 
Instance details

Defined in Z.Crypto.PubKey

Generic PrivKey Source # 
Instance details

Defined in Z.Crypto.PubKey

Associated Types

type Rep PrivKey :: Type -> Type #

Methods

from :: PrivKey -> Rep PrivKey x #

to :: Rep PrivKey x -> PrivKey #

Print PrivKey Source # 
Instance details

Defined in Z.Crypto.PubKey

Methods

toUTF8BuilderP :: Int -> PrivKey -> Builder () #

type Rep PrivKey Source # 
Instance details

Defined in Z.Crypto.PubKey

type Rep PrivKey = D1 ('MetaData "PrivKey" "Z.Crypto.PubKey" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'True) (C1 ('MetaCons "PrivKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BotanStruct)))

data PubKey Source #

A newtype wrapper.

Instances

Instances details
Eq PubKey Source # 
Instance details

Defined in Z.Crypto.PubKey

Methods

(==) :: PubKey -> PubKey -> Bool #

(/=) :: PubKey -> PubKey -> Bool #

Ord PubKey Source # 
Instance details

Defined in Z.Crypto.PubKey

Show PubKey Source # 
Instance details

Defined in Z.Crypto.PubKey

Generic PubKey Source # 
Instance details

Defined in Z.Crypto.PubKey

Associated Types

type Rep PubKey :: Type -> Type #

Methods

from :: PubKey -> Rep PubKey x #

to :: Rep PubKey x -> PubKey #

Print PubKey Source # 
Instance details

Defined in Z.Crypto.PubKey

Methods

toUTF8BuilderP :: Int -> PubKey -> Builder () #

type Rep PubKey Source # 
Instance details

Defined in Z.Crypto.PubKey

type Rep PubKey = D1 ('MetaData "PubKey" "Z.Crypto.PubKey" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'True) (C1 ('MetaCons "PubKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BotanStruct)))

newPrivKey Source #

Arguments

:: HasCallStack 
=> KeyType

Algorithm name and some algorithm specific arguments.

-> RNG 
-> IO PrivKey 

Creating a private key.

Creating a private key requires two things:

  • a source of random numbers
  • some algorithm specific arguments that define the security level of the resulting key.

newKeyPair Source #

Arguments

:: HasCallStack 
=> KeyType

Algorithm name and some algorithm specific arguments.

-> RNG 
-> IO (PrivKey, PubKey) 

Creating a new key pair.

privKeyToPubKey :: PrivKey -> PubKey Source #

Export a public key from a given key pair.

loadPrivKey Source #

Arguments

:: HasCallStack 
=> RNG 
-> Bytes 
-> CBytes

Password.

-> IO PrivKey 

Load a private key. If the key is encrypted, password will be used to attempt decryption.

privKeyAlgoName :: PrivKey -> IO Text Source #

Get the algorithm name of a private key.

privKeyParam Source #

Arguments

:: HasCallStack 
=> PrivKey

key

-> CBytes

field name

-> MPI 

Read an algorithm specific field from the key pair object.

exportPrivKeyDER :: HasCallStack => PrivKey -> Bytes Source #

Export a private key in DER binary format.

exportPrivKeyPEM :: HasCallStack => PrivKey -> Text Source #

Export a private key in PEM textual format.

exportPrivKeyEncryptedDER Source #

Arguments

:: HasCallStack 
=> PrivKey 
-> RNG 
-> CBytes

password

-> IO Bytes 

Export a private key with password.

exportPrivKeyEncryptedPEM Source #

Arguments

:: HasCallStack 
=> PrivKey 
-> RNG 
-> CBytes

password

-> IO Text 

Export a private key with password in PEM textual format.

loadPubKey :: HasCallStack => Bytes -> IO PubKey Source #

Load a publickey.

pubKeyAlgoName :: PubKey -> CBytes Source #

Get the algorithm name of a public key.

pubKeyParam Source #

Arguments

:: PubKey

key

-> CBytes

field name

-> MPI 

Read an algorithm specific field from the public key object.

exportPubKeyDER :: HasCallStack => PubKey -> Bytes Source #

Export a public key in DER binary format..

exportPubKeyPEM :: HasCallStack => PubKey -> Text Source #

Export a public key in PEM textual format.

estStrength :: PubKey -> Int Source #

Estimate the strength of a public key.

fingerPrintPubKey :: PubKey -> HashType -> Bytes Source #

Fingerprint a given publickey.

Encrypt & Decrypt

pkEncrypt Source #

Arguments

:: HasCallStack 
=> PubKey 
-> EncParam 
-> RNG 
-> Bytes

plaintext

-> IO Bytes

ciphertext

Encrypt a message, returning the ciphertext.

Though botan support DLIES and ECIES but only EME are exported via FFI, please use an algorithm that directly support eme encryption such as RSA and ElGamal.

pkDecrypt Source #

Arguments

:: HasCallStack 
=> PrivKey 
-> EncParam 
-> Bytes

ciphertext

-> IO Bytes

plaintext

Decrypt a message, returning the plaintext.

Though botan support DLIES and ECIES but only EME are exported via FFI, please use an algorithm that directly support decryption such as RSA and ElGamal.

data EncParam Source #

Sets of allowed params for public key types.

The recommended values for eme is EME1_SHA1 or EME1_SHA256. If you need compatibility with protocols using the PKCS #1 v1.5 standard, you can also use EME_PKCS1_v15'.

To use SM2 encryption, use SM2EncParam.

Sign & verify

data SignParam Source #

Signature params.

Currently available values for EMSA include EMSA1, EMSA2, EMSA3, EMSA4, and Raw. All of them, except Raw, take a parameter naming a message digest function to hash the message with. The Raw encoding signs the input directly; if the message is too big, the signing operation will fail. Raw is not useful except in very specialized applications. For RSA, use EMSA4 (also called PSS) unless you need compatibility with software that uses the older PKCS #1 v1.5 standard, in which case use EMSA3 (also called “EMSA-PKCS1-v1_5”). For DSA, ECDSA, ECKCDSA, ECGDSA and GOST 34.10-2001 you should use EMSA1.

Constructors

EMSA1 HashType 
EMSA2 HashType 
EMSA3_RAW (Maybe HashType) 
EMSA3 HashType 
EMSA4_Raw HashType (Maybe Int)

hash, salt size

EMSA4 HashType (Maybe Int)

hash, salt size

ISO_9796_DS2 HashType Bool (Maybe Int)

hash, implicit, salt size

ISO_9796_DS3 HashType Bool

hash, implicit

EMSA_Raw 
Ed25519Pure

pure Ed25519

Ed25519ph

rfc8032 HashEdDSA variant

Ed25519Hash HashType

HashEdDSA

SM2SignParam CBytes HashType

userid, hash(GM/T 0009-2012 specifies "1234567812345678" as the default userid)

XMSSEmptyParam

XMSS do not need param

Instances

Instances details
Eq SignParam Source # 
Instance details

Defined in Z.Crypto.PubKey

Ord SignParam Source # 
Instance details

Defined in Z.Crypto.PubKey

Read SignParam Source # 
Instance details

Defined in Z.Crypto.PubKey

Show SignParam Source # 
Instance details

Defined in Z.Crypto.PubKey

Generic SignParam Source # 
Instance details

Defined in Z.Crypto.PubKey

Associated Types

type Rep SignParam :: Type -> Type #

JSON SignParam Source # 
Instance details

Defined in Z.Crypto.PubKey

Print SignParam Source # 
Instance details

Defined in Z.Crypto.PubKey

Methods

toUTF8BuilderP :: Int -> SignParam -> Builder () #

type Rep SignParam Source # 
Instance details

Defined in Z.Crypto.PubKey

type Rep SignParam = D1 ('MetaData "SignParam" "Z.Crypto.PubKey" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'False) (((C1 ('MetaCons "EMSA1" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType)) :+: (C1 ('MetaCons "EMSA2" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType)) :+: C1 ('MetaCons "EMSA3_RAW" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe HashType))))) :+: ((C1 ('MetaCons "EMSA3" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType)) :+: C1 ('MetaCons "EMSA4_Raw" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int)))) :+: (C1 ('MetaCons "EMSA4" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int))) :+: C1 ('MetaCons "ISO_9796_DS2" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int))))))) :+: ((C1 ('MetaCons "ISO_9796_DS3" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :+: (C1 ('MetaCons "EMSA_Raw" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Ed25519Pure" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "Ed25519ph" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Ed25519Hash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType))) :+: (C1 ('MetaCons "SM2SignParam" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CBytes) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType)) :+: C1 ('MetaCons "XMSSEmptyParam" 'PrefixI 'False) (U1 :: Type -> Type)))))

data SignFmt Source #

Constructors

DER_SEQUENCE 
IEEE_1363 

Instances

Instances details
Enum SignFmt Source # 
Instance details

Defined in Z.Crypto.PubKey

Eq SignFmt Source # 
Instance details

Defined in Z.Crypto.PubKey

Methods

(==) :: SignFmt -> SignFmt -> Bool #

(/=) :: SignFmt -> SignFmt -> Bool #

Ord SignFmt Source # 
Instance details

Defined in Z.Crypto.PubKey

Show SignFmt Source # 
Instance details

Defined in Z.Crypto.PubKey

Generic SignFmt Source # 
Instance details

Defined in Z.Crypto.PubKey

Associated Types

type Rep SignFmt :: Type -> Type #

Methods

from :: SignFmt -> Rep SignFmt x #

to :: Rep SignFmt x -> SignFmt #

Print SignFmt Source # 
Instance details

Defined in Z.Crypto.PubKey

Methods

toUTF8BuilderP :: Int -> SignFmt -> Builder () #

type Rep SignFmt Source # 
Instance details

Defined in Z.Crypto.PubKey

type Rep SignFmt = D1 ('MetaData "SignFmt" "Z.Crypto.PubKey" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'False) (C1 ('MetaCons "DER_SEQUENCE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "IEEE_1363" 'PrefixI 'False) (U1 :: Type -> Type))

data Signer Source #

Instances

Instances details
Show Signer Source # 
Instance details

Defined in Z.Crypto.PubKey

Generic Signer Source # 
Instance details

Defined in Z.Crypto.PubKey

Associated Types

type Rep Signer :: Type -> Type #

Methods

from :: Signer -> Rep Signer x #

to :: Rep Signer x -> Signer #

Print Signer Source # 
Instance details

Defined in Z.Crypto.PubKey

Methods

toUTF8BuilderP :: Int -> Signer -> Builder () #

type Rep Signer Source # 
Instance details

Defined in Z.Crypto.PubKey

type Rep Signer = D1 ('MetaData "Signer" "Z.Crypto.PubKey" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'False) (C1 ('MetaCons "Signer" 'PrefixI 'True) (S1 ('MetaSel ('Just "signerStruct") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 BotanStruct) :*: S1 ('MetaSel ('Just "signerSize") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)))

signerSize :: Signer -> Int Source #

output signature length

data Verifier Source #

Instances

Instances details
Show Verifier Source # 
Instance details

Defined in Z.Crypto.PubKey

Generic Verifier Source # 
Instance details

Defined in Z.Crypto.PubKey

Associated Types

type Rep Verifier :: Type -> Type #

Methods

from :: Verifier -> Rep Verifier x #

to :: Rep Verifier x -> Verifier #

Print Verifier Source # 
Instance details

Defined in Z.Crypto.PubKey

Methods

toUTF8BuilderP :: Int -> Verifier -> Builder () #

type Rep Verifier Source # 
Instance details

Defined in Z.Crypto.PubKey

type Rep Verifier = D1 ('MetaData "Verifier" "Z.Crypto.PubKey" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'True) (C1 ('MetaCons "Verifier" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BotanStruct)))

finalSigner :: HasCallStack => Signer -> RNG -> IO Bytes Source #

Produce a signature over all of the bytes passed to Signer. Afterwards, the sign operator is reset and may be used to sign a new message.

sinkToSigner :: HasCallStack => HasCallStack => Signer -> Sink Bytes Source #

Trun Signer to a Bytes sink, update Signer by write bytes to the sink.

sign Source #

Arguments

:: HasCallStack 
=> PrivKey 
-> SignParam 
-> SignFmt 
-> Bytes

input

-> IO Bytes

signature

Directly sign a message, with system RNG.

signChunks :: HasCallStack => PrivKey -> SignParam -> SignFmt -> [Bytes] -> IO Bytes Source #

Directly compute a chunked message's mac with system RNG.

sinkToVerifier :: HasCallStack => Verifier -> Sink Bytes Source #

Trun Verifier to a Bytes sink, update Verifier by write bytes to the sink.

verify Source #

Arguments

:: HasCallStack 
=> PubKey 
-> SignParam 
-> SignFmt 
-> Bytes

input

-> Bytes

signature

-> IO Bool 

Directly sign a message.

verifyChunks Source #

Arguments

:: HasCallStack 
=> PubKey 
-> SignParam 
-> SignFmt 
-> [Bytes] 
-> Bytes

signature

-> IO Bool 

Directly compute a chunked message's mac.

Key agreement

data KeyAgreement Source #

Key agreement object.

Instances

Instances details
Show KeyAgreement Source # 
Instance details

Defined in Z.Crypto.PubKey

Generic KeyAgreement Source # 
Instance details

Defined in Z.Crypto.PubKey

Associated Types

type Rep KeyAgreement :: Type -> Type #

Print KeyAgreement Source # 
Instance details

Defined in Z.Crypto.PubKey

type Rep KeyAgreement Source # 
Instance details

Defined in Z.Crypto.PubKey

type Rep KeyAgreement = D1 ('MetaData "KeyAgreement" "Z.Crypto.PubKey" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'False) (C1 ('MetaCons "KeyAgreement" 'PrefixI 'True) (S1 ('MetaSel ('Just "keyAgreementStruct") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 BotanStruct) :*: S1 ('MetaSel ('Just "keyAgreementSize") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)))

keyAgreementSize :: KeyAgreement -> Int Source #

size of the agreed key

newKeyAgreement :: HasCallStack => PrivKey -> KDFType -> IO KeyAgreement Source #

Create a new key agreement operation with a given key pair and KDF algorithm.

Please use a key type that support key agreement, such as DH, ECDH, or Curve25519.

exportKeyAgreementPublic :: HasCallStack => PrivKey -> IO Bytes Source #

Produce the public value to send to other party.

keyAgree Source #

Arguments

:: HasCallStack 
=> KeyAgreement 
-> Bytes

other key's public

-> Bytes

salt

-> IO Secret 

How key agreement works is that you trade public values with some other party, and then each of you runs a computation with the other’s value and your key (this should return the same result to both parties).

RSA specific

getRSAParams Source #

Arguments

:: PrivKey 
-> (MPI, MPI, MPI, MPI, MPI)

(p, q, n, d, e)

Get RSA parameters

  • Set p to the first RSA prime.
  • Set q to the second RSA prime.
  • Set n to the RSA modulus.
  • Set d to the RSA private exponent.
  • Set e to the RSA public exponent.

newRSAPrivKey :: HasCallStack => MPI -> MPI -> MPI -> PrivKey Source #

Initialize a RSA key pair using arguments p, q, and e.

getRSAPubParams Source #

Arguments

:: PubKey 
-> (MPI, MPI)

(n, e)

Get RSA Public parameters

  • Set n to the RSA modulus.
  • Set e to the RSA public exponent.

newRSAPubKey :: HasCallStack => MPI -> MPI -> PubKey Source #

Initialize a public RSA key using arguments n and e.

DSA specific

getDSAPrivParams Source #

Arguments

:: PrivKey 
-> (MPI, MPI, MPI, MPI)

(p, q, g, x)

Get DSA parameters

  • Set p, q, g to group parameters
  • Set x to the private key

newDSAPrivKey :: HasCallStack => MPI -> MPI -> MPI -> MPI -> PrivKey Source #

Initialize a DSA key pair using arguments p, q, g and x.

getDSAPubParams Source #

Arguments

:: PubKey 
-> (MPI, MPI, MPI, MPI)

(p, q, g, y)

Get DSA parameters

  • Set p, q, g to group parameters
  • Set y to the public key

newDSAPubKey :: HasCallStack => MPI -> MPI -> MPI -> MPI -> PubKey Source #

Initialize a DSA public key using arguments p, q, g and y.

ElGamal specific

getElGamalPrivParams Source #

Arguments

:: PrivKey 
-> (MPI, MPI, MPI)

(p, g, x)

Get ElGamal parameters

  • Set p, g to group parameters
  • Set x to the private key

getElGamalPubParams Source #

Arguments

:: PubKey 
-> (MPI, MPI, MPI)

(p, g, y)

Get ElGamal parameters

  • Set p, g to group parameters
  • Set y to the public key

Diffie-Hellman specific

getDHPrivParams Source #

Arguments

:: PrivKey 
-> (MPI, MPI, MPI)

(p, g, x)

Get Diffie-Hellman parameters

  • Set p, g to group parameters
  • Set x to the private key

getDHPubParams Source #

Arguments

:: PubKey 
-> (MPI, MPI, MPI)

(p, g, y)

Get Diffie-Hellman parameters

  • Set p, g to group parameters
  • Set y to the public key

constants

type XMSSType = CBytes Source #

A type wrapper.

type ECGroup = CBytes Source #

An elliptic curve.

type DLGroup = CBytes Source #

Discrete Logarithm Group

re-exports

data HashType Source #

Available Hashs

Constructors

BLAKE2b Int

A recently designed hash function. Very fast on 64-bit processors. Can output a hash of any length between 1 and 64 bytes, this is specified by passing desired byte length.

BLAKE2b256

Alias for Blake2b 32

BLAKE2b512

Alias for Blake2b 64

Keccak1600_224

An older (and incompatible) variant of SHA-3, but sometimes used. Prefer SHA-3 in new code.

Keccak1600_256 
Keccak1600_384 
Keccak1600_512 
MD4

An old hash function that is now known to be trivially breakable. It is very fast, and may still be suitable as a (non-cryptographic) checksum.

MD5

Widely used, now known to be broken.

RIPEMD160

A 160 bit hash function, quite old but still thought to be secure (up to the limit of 2**80 computation required for a collision which is possible with any 160 bit hash function). Somewhat deprecated these days.

SHA160

Widely adopted NSA designed hash function. Starting to show significant signs of weakness, and collisions can now be generated. Avoid in new designs.

SHA256

Relatively fast 256 bit hash function, thought to be secure. Also includes the variant SHA-224. There is no real reason to use SHA-224.

SHA224 
SHA512

SHA-512 is faster than SHA-256 on 64-bit processors. Also includes the truncated variants SHA-384 and SHA-512/256, which have the advantage of avoiding message extension attacks.

SHA384 
SHA512_256 
SHA3_224

The new NIST standard hash. Fairly slow. Supports 224, 256, 384 or 512 bit outputs. SHA-3 is faster with smaller outputs. Use as “SHA3_256” or “SHA3_512”. Plain “SHA-3” selects default 512 bit output.

SHA3_256 
SHA3_384 
SHA3_512 
SHAKE128 Int

These are actually XOFs (extensible output functions) based on SHA-3, which can output a value of any byte length. For example “SHAKE128 @128” will produce 1024 bits of output.

SHAKE256 Int 
SM3

Chinese national hash function, 256 bit output. Widely used in industry there. Fast and seemingly secure, but no reason to prefer it over SHA-2 or SHA-3 unless required.

Skein512 Int CBytes

A contender for the NIST SHA-3 competition. Very fast on 64-bit systems. Can output a hash of any length between 1 and 64 bytes. It also accepts an optional “personalization string” which can create variants of the hash. This is useful for domain separation.

Streebog256

Newly designed Russian national hash function. Due to use of input-dependent table lookups, it is vulnerable to side channels. There is no reason to use it unless compatibility is needed. Warning: The Streebog Sbox has recently been revealed to have a hidden structure which interacts with its linear layer in a way which may provide a backdoor when used in certain ways. Avoid Streebog if at all possible.

Streebog512 
Whirlpool

A 512-bit hash function standardized by ISO and NESSIE. Relatively slow, and due to the table based implementation it is potentially vulnerable to cache based side channels.

Parallel HashType HashType

Parallel simply concatenates multiple hash functions. For example “Parallel SHA256 SHA512 outputs a 256+512 bit hash created by hashing the input with both SHA256 and SHA512 and concatenating the outputs.

Comb4P HashType HashType

This combines two cryptographic hashes in such a way that preimage and collision attacks are provably at least as hard as a preimage or collision attack on the strongest hash.

Adler32

Checksums, not suitable for cryptographic use, but can be used for error checking purposes.

CRC24 
CRC32 

Instances

Instances details
Eq HashType Source # 
Instance details

Defined in Z.Crypto.Hash

Ord HashType Source # 
Instance details

Defined in Z.Crypto.Hash

Read HashType Source # 
Instance details

Defined in Z.Crypto.Hash

Show HashType Source # 
Instance details

Defined in Z.Crypto.Hash

Generic HashType Source # 
Instance details

Defined in Z.Crypto.Hash

Associated Types

type Rep HashType :: Type -> Type #

Methods

from :: HashType -> Rep HashType x #

to :: Rep HashType x -> HashType #

JSON HashType Source # 
Instance details

Defined in Z.Crypto.Hash

Print HashType Source # 
Instance details

Defined in Z.Crypto.Hash

Methods

toUTF8BuilderP :: Int -> HashType -> Builder () #

type Rep HashType Source # 
Instance details

Defined in Z.Crypto.Hash

type Rep HashType = D1 ('MetaData "HashType" "Z.Crypto.Hash" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'False) (((((C1 ('MetaCons "BLAKE2b" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :+: C1 ('MetaCons "BLAKE2b256" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "BLAKE2b512" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Keccak1600_224" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "Keccak1600_256" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Keccak1600_384" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Keccak1600_512" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MD4" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: (((C1 ('MetaCons "MD5" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "RIPEMD160" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "SHA160" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SHA256" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "SHA224" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SHA512" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "SHA384" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SHA512_256" 'PrefixI 'False) (U1 :: Type -> Type))))) :+: ((((C1 ('MetaCons "SHA3_224" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SHA3_256" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "SHA3_384" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SHA3_512" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "SHAKE128" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :+: C1 ('MetaCons "SHAKE256" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int))) :+: (C1 ('MetaCons "SM3" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Skein512" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CBytes))))) :+: (((C1 ('MetaCons "Streebog256" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Streebog512" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Whirlpool" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Parallel" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType)))) :+: ((C1 ('MetaCons "Comb4P" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType)) :+: C1 ('MetaCons "Adler32" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CRC24" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CRC32" 'PrefixI 'False) (U1 :: Type -> Type))))))

data KDFType Source #

Key derivation functions are used to turn some amount of shared secret material into uniform random keys suitable for use with symmetric algorithms. An example of an input which is useful for a KDF is a shared secret created using Diffie-Hellman key agreement.

Constructors

HKDF MACType 
HKDF_Extract MACType 
HKDF_Expand MACType

Defined in RFC 5869, HKDF uses HMAC to process inputs. Also available are variants HKDF-Extract and HKDF-Expand. HKDF is the combined Extract+Expand operation. Use the combined HKDF unless you need compatibility with some other system.

KDF2 HashType

KDF2 comes from IEEE 1363. It uses a hash function.

KDF1_18033 HashType

KDF1 from ISO 18033-2. Very similar to (but incompatible with) KDF2.

KDF1 HashType

KDF1 from IEEE 1363. It can only produce an output at most the length of the hash function used.

TLS_PRF

A KDF from ANSI X9.42. Sometimes used for Diffie-Hellman.

TLS_12_PRF MACType 
SP800_108_Counter MACType

KDFs from NIST SP 800-108. Variants include “SP800-108-Counter”, “SP800-108-Feedback” and “SP800-108-Pipeline”.

SP800_108_Feedback MACType 
SP800_108_Pipeline MACType 
SP800_56AHash HashType

NIST SP 800-56A KDF using hash function

SP800_56AMAC MACType

NIST SP 800-56A KDF using HMAC

SP800_56C MACType

NIST SP 800-56C KDF using HMAC

Instances

Instances details
Eq KDFType Source # 
Instance details

Defined in Z.Crypto.KDF

Methods

(==) :: KDFType -> KDFType -> Bool #

(/=) :: KDFType -> KDFType -> Bool #

Ord KDFType Source # 
Instance details

Defined in Z.Crypto.KDF

Read KDFType Source # 
Instance details

Defined in Z.Crypto.KDF

Show KDFType Source # 
Instance details

Defined in Z.Crypto.KDF

Generic KDFType Source # 
Instance details

Defined in Z.Crypto.KDF

Associated Types

type Rep KDFType :: Type -> Type #

Methods

from :: KDFType -> Rep KDFType x #

to :: Rep KDFType x -> KDFType #

JSON KDFType Source # 
Instance details

Defined in Z.Crypto.KDF

Print KDFType Source # 
Instance details

Defined in Z.Crypto.KDF

Methods

toUTF8BuilderP :: Int -> KDFType -> Builder () #

type Rep KDFType Source # 
Instance details

Defined in Z.Crypto.KDF

type Rep KDFType = D1 ('MetaData "KDFType" "Z.Crypto.KDF" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'False) (((C1 ('MetaCons "HKDF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType)) :+: (C1 ('MetaCons "HKDF_Extract" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType)) :+: C1 ('MetaCons "HKDF_Expand" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType)))) :+: ((C1 ('MetaCons "KDF2" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType)) :+: C1 ('MetaCons "KDF1_18033" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType))) :+: (C1 ('MetaCons "KDF1" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType)) :+: C1 ('MetaCons "TLS_PRF" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "TLS_12_PRF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType)) :+: (C1 ('MetaCons "SP800_108_Counter" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType)) :+: C1 ('MetaCons "SP800_108_Feedback" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType)))) :+: ((C1 ('MetaCons "SP800_108_Pipeline" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType)) :+: C1 ('MetaCons "SP800_56AHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HashType))) :+: (C1 ('MetaCons "SP800_56AMAC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType)) :+: C1 ('MetaCons "SP800_56C" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MACType))))))

data RNG Source #

Opaque botan RNG type.

Instances

Instances details
Show RNG Source # 
Instance details

Defined in Z.Crypto.RNG

Methods

showsPrec :: Int -> RNG -> ShowS #

show :: RNG -> String #

showList :: [RNG] -> ShowS #

Generic RNG Source # 
Instance details

Defined in Z.Crypto.RNG

Associated Types

type Rep RNG :: Type -> Type #

Methods

from :: RNG -> Rep RNG x #

to :: Rep RNG x -> RNG #

Print RNG Source # 
Instance details

Defined in Z.Crypto.RNG

Methods

toUTF8BuilderP :: Int -> RNG -> Builder () #

type Rep RNG Source # 
Instance details

Defined in Z.Crypto.RNG

type Rep RNG = D1 ('MetaData "RNG" "Z.Crypto.RNG" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'True) (C1 ('MetaCons "RNG" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BotanStruct)))

getRNG :: HasCallStack => IO RNG Source #

Get an autoseeded RNG from a global RNG pool divide by haskell capability.

Botan internal use a lock to protect user-space RNG, which may cause contention if shared. This function will fetch an autoseeded RNG from a global RNG pool, which is recommended under concurrent settings.

internal

withPrivKey :: HasCallStack => PrivKey -> (BotanStructT -> IO r) -> IO r Source #

Pass PrivKey to FFI.

withPubKey :: PubKey -> (BotanStructT -> IO r) -> IO r Source #

Pass PubKey to FFI.

botanStructToPubKey :: BotanStruct -> PubKey Source #

Unsafe construct a PubKey from a botan struct.