hpke
Safe HaskellNone
LanguageHaskell2010

Crypto.HPKE

Description

Hybrid Public Key Encryption (RFC9180).

Synopsis

IDs

newtype KEM_ID Source #

ID for key encapsulation mechanism.

Constructors

KEM_ID 

Fields

Instances

Instances details
Eq KEM_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

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

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

Show KEM_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

newtype KDF_ID Source #

ID for key derivation function.

Constructors

KDF_ID 

Fields

Bundled Patterns

pattern HKDF_SHA256 :: KDF_ID 
pattern HKDF_SHA384 :: KDF_ID 
pattern HKDF_SHA512 :: KDF_ID 

Instances

Instances details
Eq KDF_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

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

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

Show KDF_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

newtype AEAD_ID Source #

ID for authenticated encryption with additional data

Constructors

AEAD_ID 

Fields

Bundled Patterns

pattern AES_128_GCM :: AEAD_ID 
pattern AES_256_GCM :: AEAD_ID 
pattern ChaCha20Poly1305 :: AEAD_ID 

Instances

Instances details
Eq AEAD_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

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

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

Show AEAD_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Setup

For mode_base and mode_auth

setupBaseS Source #

Arguments

:: KEM_ID 
-> KDF_ID 
-> AEAD_ID 
-> Maybe EncodedSecretKey

My ephemeral secret key. Automatically generated if Nothing

-> Maybe EncodedSecretKey

My secret key for authentication. mode_base is used if Nothing. base_auth is used, otherwise.

-> EncodedPublicKey

Peer's public key.

-> Info 
-> IO (EncodedPublicKey, ContextS) 

Setting up base/auth mode for a sender. This throws HPKEError.

setupBaseR Source #

Arguments

:: KEM_ID 
-> KDF_ID 
-> AEAD_ID 
-> EncodedSecretKey

My secret key

-> Maybe EncodedSecretKey

My secret key for authentication. mode_base is used if Nothing. base_auth is used, otherwise.

-> EncodedPublicKey

Peer's public key.

-> Info 
-> IO ContextR 

Setting up base/auth mode for a receiver with its key pair. This throws HPKEError.

For mode_psk and mode_auth_psk

setupPSKS Source #

Arguments

:: KEM_ID 
-> KDF_ID 
-> AEAD_ID 
-> Maybe EncodedSecretKey

My ephemeral secret key. Automatically generated if Nothing

-> Maybe EncodedSecretKey

My secret key for authentication. mode_base is used if Nothing. base_auth is used, otherwise.

-> EncodedPublicKey

Peer's public key.

-> Info 
-> PSK 
-> PSK_ID 
-> IO (EncodedPublicKey, ContextS) 

Setting up psk/auth_psk mode for a sender. This throws HPKEError.

setupPSKR Source #

Arguments

:: KEM_ID 
-> KDF_ID 
-> AEAD_ID 
-> EncodedSecretKey

My secret key

-> Maybe EncodedSecretKey

My secret key for authentication. mode_base is used if Nothing. base_auth is used, otherwise.

-> EncodedPublicKey

Peer's public key.

-> Info 
-> PSK 
-> PSK_ID 
-> IO ContextR 

Setting up psk/auth_psk mode for a receiver with its key pair. This throws HPKEError.

Encryption and Decyption

seal :: ContextS -> AAD -> PlainText -> IO CipherText Source #

Encryption. This throws HPKEError.

open :: ContextR -> AAD -> CipherText -> IO PlainText Source #

Decryption. This throws HPKEError.

Secret export

exportS :: ContextS -> Info -> Int -> Key Source #

Exporting secret.

exportR :: ContextR -> Info -> Int -> Key Source #

Exporting secret.

Types

data ContextS Source #

Context for senders.

data ContextR Source #

Context for receivers.

newtype EncodedSecretKey Source #

Encoded secret key.

newtype EncodedPublicKey Source #

Encoded public key.

newtype SharedSecret Source #

Secret shared via key exchange

Instances

Instances details
NFData SharedSecret Source # 
Instance details

Defined in Crypto.ECC

Methods

rnf :: SharedSecret -> () #

Monoid SharedSecret Source # 
Instance details

Defined in Crypto.ECC

Semigroup SharedSecret Source # 
Instance details

Defined in Crypto.ECC

Eq SharedSecret Source # 
Instance details

Defined in Crypto.ECC

ByteArrayAccess SharedSecret Source # 
Instance details

Defined in Crypto.ECC

type Info = ByteString Source #

Information string.

type PSK = ByteString Source #

Pre-shared key.

type PSK_ID = ByteString Source #

ID for pre-shared key.

type AAD = ByteString Source #

Additional authenticated data for AEAD.

type PlainText = ByteString Source #

Plain text.

type CipherText = ByteString Source #

Cipher text (including a authentication tag)

type Key = ByteString Source #

Encryption key.

Error

Misc

nEnc :: KEM_ID -> Int Source #

Length of "enc", aka sender's public key.

nTag :: AEAD_ID -> Int Source #

Length of AEAD tag.