| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Crypto.HPKE
Description
Hybrid Public Key Encryption (RFC9180).
Synopsis
- newtype KEM_ID where
- KEM_ID {
- fromKEM_ID :: Word16
- pattern DHKEM_P256_HKDF_SHA256 :: KEM_ID
- pattern DHKEM_P384_HKDF_SHA384 :: KEM_ID
- pattern DHKEM_P521_HKDF_SHA512 :: KEM_ID
- pattern DHKEM_X25519_HKDF_SHA256 :: KEM_ID
- pattern DHKEM_X448_HKDF_SHA512 :: KEM_ID
- KEM_ID {
- newtype KDF_ID where
- KDF_ID {
- fromKDF_ID :: Word16
- pattern HKDF_SHA256 :: KDF_ID
- pattern HKDF_SHA384 :: KDF_ID
- pattern HKDF_SHA512 :: KDF_ID
- KDF_ID {
- newtype AEAD_ID where
- AEAD_ID {
- fromAEAD_ID :: Word16
- pattern AES_128_GCM :: AEAD_ID
- pattern AES_256_GCM :: AEAD_ID
- pattern ChaCha20Poly1305 :: AEAD_ID
- AEAD_ID {
- setupBaseS :: KEM_ID -> KDF_ID -> AEAD_ID -> Maybe EncodedSecretKey -> Maybe EncodedSecretKey -> EncodedPublicKey -> Info -> IO (EncodedPublicKey, ContextS)
- setupBaseR :: KEM_ID -> KDF_ID -> AEAD_ID -> EncodedSecretKey -> Maybe EncodedSecretKey -> EncodedPublicKey -> Info -> IO ContextR
- setupPSKS :: KEM_ID -> KDF_ID -> AEAD_ID -> Maybe EncodedSecretKey -> Maybe EncodedSecretKey -> EncodedPublicKey -> Info -> PSK -> PSK_ID -> IO (EncodedPublicKey, ContextS)
- setupPSKR :: KEM_ID -> KDF_ID -> AEAD_ID -> EncodedSecretKey -> Maybe EncodedSecretKey -> EncodedPublicKey -> Info -> PSK -> PSK_ID -> IO ContextR
- seal :: ContextS -> AAD -> PlainText -> IO CipherText
- open :: ContextR -> AAD -> CipherText -> IO PlainText
- exportS :: ContextS -> Info -> Int -> Key
- exportR :: ContextR -> Info -> Int -> Key
- data ContextS
- data ContextR
- newtype EncodedSecretKey = EncodedSecretKey ByteString
- newtype EncodedPublicKey = EncodedPublicKey ByteString
- newtype SharedSecret = SharedSecret ScrubbedBytes
- type Info = ByteString
- type PSK = ByteString
- type PSK_ID = ByteString
- type AAD = ByteString
- type PlainText = ByteString
- type CipherText = ByteString
- type Key = ByteString
- data HPKEError
- = ValidationError String
- | DeserializeError String
- | EncapError String
- | DecapError String
- | SealError String
- | OpenError String
- | MessageLimitReachedError String
- | DeriveKeyPairError String
- | KeyScheduleError String
- | Unsupported String
- nEnc :: KEM_ID -> Int
- nTag :: AEAD_ID -> Int
IDs
ID for key encapsulation mechanism.
Constructors
| KEM_ID | |
Fields
| |
Bundled Patterns
| pattern DHKEM_P256_HKDF_SHA256 :: KEM_ID | |
| pattern DHKEM_P384_HKDF_SHA384 :: KEM_ID | |
| pattern DHKEM_P521_HKDF_SHA512 :: KEM_ID | |
| pattern DHKEM_X25519_HKDF_SHA256 :: KEM_ID | |
| pattern DHKEM_X448_HKDF_SHA512 :: KEM_ID |
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 |
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 |
Setup
For mode_base and mode_auth
Arguments
| :: KEM_ID | |
| -> KDF_ID | |
| -> AEAD_ID | |
| -> Maybe EncodedSecretKey | My ephemeral secret key. Automatically generated if |
| -> Maybe EncodedSecretKey | My secret key for authentication.
|
| -> EncodedPublicKey | Peer's public key. |
| -> Info | |
| -> IO (EncodedPublicKey, ContextS) |
Setting up base/auth mode for a sender.
This throws HPKEError.
Arguments
| :: KEM_ID | |
| -> KDF_ID | |
| -> AEAD_ID | |
| -> EncodedSecretKey | My secret key |
| -> Maybe EncodedSecretKey | My secret key for authentication.
|
| -> 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
Arguments
| :: KEM_ID | |
| -> KDF_ID | |
| -> AEAD_ID | |
| -> Maybe EncodedSecretKey | My ephemeral secret key. Automatically generated if |
| -> Maybe EncodedSecretKey | My secret key for authentication.
|
| -> EncodedPublicKey | Peer's public key. |
| -> Info | |
| -> PSK | |
| -> PSK_ID | |
| -> IO (EncodedPublicKey, ContextS) |
Setting up psk/auth_psk mode for a sender.
This throws HPKEError.
Arguments
| :: KEM_ID | |
| -> KDF_ID | |
| -> AEAD_ID | |
| -> EncodedSecretKey | My secret key |
| -> Maybe EncodedSecretKey | My secret key for authentication.
|
| -> 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
Secret export
Types
newtype EncodedSecretKey Source #
Encoded secret key.
Constructors
| EncodedSecretKey ByteString |
Instances
| IsString EncodedSecretKey Source # | |
Defined in Crypto.HPKE.Types Methods fromString :: String -> EncodedSecretKey | |
| Show EncodedSecretKey Source # | |
Defined in Crypto.HPKE.Types Methods showsPrec :: Int -> EncodedSecretKey -> ShowS show :: EncodedSecretKey -> String showList :: [EncodedSecretKey] -> ShowS | |
| Eq EncodedSecretKey Source # | |
Defined in Crypto.HPKE.Types Methods (==) :: EncodedSecretKey -> EncodedSecretKey -> Bool (/=) :: EncodedSecretKey -> EncodedSecretKey -> Bool | |
newtype EncodedPublicKey Source #
Encoded public key.
Constructors
| EncodedPublicKey ByteString |
Instances
| IsString EncodedPublicKey Source # | |
Defined in Crypto.HPKE.Types Methods fromString :: String -> EncodedPublicKey | |
| Show EncodedPublicKey Source # | |
Defined in Crypto.HPKE.Types Methods showsPrec :: Int -> EncodedPublicKey -> ShowS show :: EncodedPublicKey -> String showList :: [EncodedPublicKey] -> ShowS | |
| Eq EncodedPublicKey Source # | |
Defined in Crypto.HPKE.Types Methods (==) :: EncodedPublicKey -> EncodedPublicKey -> Bool (/=) :: EncodedPublicKey -> EncodedPublicKey -> Bool | |
type CipherText = ByteString Source #
Cipher text (including a authentication tag)
Error
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
| Exception HPKEError Source # | |
Defined in Crypto.HPKE.Types Methods toException :: HPKEError -> SomeException fromException :: SomeException -> Maybe HPKEError displayException :: HPKEError -> String backtraceDesired :: HPKEError -> Bool | |
| Show HPKEError Source # | |
| Eq HPKEError Source # | |