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
Show KEM_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

showsPrec :: Int -> KEM_ID -> ShowS

show :: KEM_ID -> String

showList :: [KEM_ID] -> ShowS

Eq KEM_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

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

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

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
Show KDF_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

showsPrec :: Int -> KDF_ID -> ShowS

show :: KDF_ID -> String

showList :: [KDF_ID] -> ShowS

Eq KDF_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

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

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

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
Show AEAD_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

showsPrec :: Int -> AEAD_ID -> ShowS

show :: AEAD_ID -> String

showList :: [AEAD_ID] -> ShowS

Eq AEAD_ID Source # 
Instance details

Defined in Crypto.HPKE.ID

Methods

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

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

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.

Constructors

EncodedSecretKey ByteString 

Instances

Instances details
IsString EncodedSecretKey Source # 
Instance details

Defined in Crypto.HPKE.Types

Methods

fromString :: String -> EncodedSecretKey

Show EncodedSecretKey Source # 
Instance details

Defined in Crypto.HPKE.Types

Methods

showsPrec :: Int -> EncodedSecretKey -> ShowS

show :: EncodedSecretKey -> String

showList :: [EncodedSecretKey] -> ShowS

Eq EncodedSecretKey Source # 
Instance details

Defined in Crypto.HPKE.Types

newtype EncodedPublicKey Source #

Encoded public key.

Constructors

EncodedPublicKey ByteString 

Instances

Instances details
IsString EncodedPublicKey Source # 
Instance details

Defined in Crypto.HPKE.Types

Methods

fromString :: String -> EncodedPublicKey

Show EncodedPublicKey Source # 
Instance details

Defined in Crypto.HPKE.Types

Methods

showsPrec :: Int -> EncodedPublicKey -> ShowS

show :: EncodedPublicKey -> String

showList :: [EncodedPublicKey] -> ShowS

Eq EncodedPublicKey Source # 
Instance details

Defined in Crypto.HPKE.Types

newtype SharedSecret #

Constructors

SharedSecret ScrubbedBytes 

Instances

Instances details
NFData SharedSecret # 
Instance details

Defined in Crypto.ECC

Methods

rnf :: SharedSecret -> ()

Monoid SharedSecret # 
Instance details

Defined in Crypto.ECC

Semigroup SharedSecret # 
Instance details

Defined in Crypto.ECC

Eq SharedSecret # 
Instance details

Defined in Crypto.ECC

Methods

(==) :: SharedSecret -> SharedSecret -> Bool

(/=) :: SharedSecret -> SharedSecret -> Bool

ByteArrayAccess SharedSecret # 
Instance details

Defined in Crypto.ECC

Methods

length :: SharedSecret -> Int

withByteArray :: SharedSecret -> (Ptr p -> IO a) -> IO a

copyByteArrayToPtr :: SharedSecret -> Ptr p -> IO ()

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

data HPKEError Source #

Errors for HPKE

Constructors

ValidationError String 
DeserializeError String 
EncapError String 
DecapError String 
SealError String

Original

OpenError String 
MessageLimitReachedError String 
DeriveKeyPairError String 
KeyScheduleError String

Original

Unsupported String 

Instances

Instances details
Exception HPKEError Source # 
Instance details

Defined in Crypto.HPKE.Types

Methods

toException :: HPKEError -> SomeException

fromException :: SomeException -> Maybe HPKEError

displayException :: HPKEError -> String

backtraceDesired :: HPKEError -> Bool

Show HPKEError Source # 
Instance details

Defined in Crypto.HPKE.Types

Methods

showsPrec :: Int -> HPKEError -> ShowS

show :: HPKEError -> String

showList :: [HPKEError] -> ShowS

Eq HPKEError Source # 
Instance details

Defined in Crypto.HPKE.Types

Methods

(==) :: HPKEError -> HPKEError -> Bool

(/=) :: HPKEError -> HPKEError -> Bool

Misc

nEnc :: KEM_ID -> Int Source #

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

nTag :: AEAD_ID -> Int Source #

Length of AEAD tag.