| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Crypto.HPKE.Internal
Synopsis
- data HPKEMap = HPKEMap {}
- defaultHPKEMap :: HPKEMap
- setupS :: HPKEMap -> Mode -> KEM_ID -> KDF_ID -> AEAD_ID -> Maybe EncodedSecretKey -> Maybe EncodedSecretKey -> EncodedPublicKey -> Info -> PSK -> PSK_ID -> IO (EncodedPublicKey, ContextS)
- setupR :: HPKEMap -> Mode -> KEM_ID -> KDF_ID -> AEAD_ID -> EncodedSecretKey -> Maybe EncodedPublicKey -> EncodedPublicKey -> Info -> PSK -> PSK_ID -> IO ContextR
- data KEMAlg = HPKEKEM kem => KEMAlg (Proxy kem)
- data KDFHash = (HashAlgorithm h, KDF h) => KDFHash h
- data AEADCipher = Aead a => AEADCipher (Proxy a)
- class Aead a where
- class KDF h where
- class (KEM kem, EncapsulationKey kem ~ EncodedPublicKey, DecapsulationKey kem ~ EncodedSecretKey, Ciphertext kem ~ EncodedPublicKey, Coins kem ~ EncodedSecretKey) => HPKEKEM kem where
- generateCoins :: MonadRandom m => proxy kem -> m EncodedSecretKey
- authEncapWith :: proxy kem -> EncodedSecretKey -> EncodedPublicKey -> EncodedSecretKey -> Either HPKEError (EncodedPublicKey, SharedSecret)
- authDecap :: proxy kem -> EncodedPublicKey -> EncodedSecretKey -> EncodedPublicKey -> Either HPKEError SharedSecret
- toEncapsulationKey :: proxy kem -> EncodedSecretKey -> Either HPKEError EncodedPublicKey
- data Mode
- type PublicKey group = Point group
- type SecretKey group = Scalar group
- type Seal = Nonce -> AAD -> PlainText -> Either HPKEError CipherText
- type Open = Nonce -> AAD -> CipherText -> Either HPKEError PlainText
- type Nonce = ByteString
- type Suite = ByteString
- type Salt = ByteString
- type Label = ByteString
- type IKM = ByteString
- genKeyPair :: HPKEMap -> KEM_ID -> IO (EncodedPublicKey, EncodedSecretKey)
- toPublicKey :: HPKEMap -> KEM_ID -> EncodedSecretKey -> Either HPKEError EncodedPublicKey
Extensible map
Arguments
| :: HPKEMap | |
| -> Mode | |
| -> KEM_ID | |
| -> KDF_ID | |
| -> AEAD_ID | |
| -> Maybe EncodedSecretKey | My ephemeral secret key. Automatically generated if |
| -> Maybe EncodedSecretKey | My secret key, for the authenticated modes. |
| -> EncodedPublicKey | Peer's public key. |
| -> Info | |
| -> PSK | |
| -> PSK_ID | |
| -> IO (EncodedPublicKey, ContextS) |
Arguments
| :: HPKEMap | |
| -> Mode | |
| -> KEM_ID | |
| -> KDF_ID | |
| -> AEAD_ID | |
| -> EncodedSecretKey | My secret key |
| -> Maybe EncodedPublicKey | The sender's public key, for the authenticated modes. |
| -> EncodedPublicKey | The encapsulated key, |
| -> Info | |
| -> PSK | |
| -> PSK_ID | |
| -> IO ContextR |
Unified types
A KEM that HPKE can run over, with its identity forgotten, for the
table that turns a KEM_ID into one.
data AEADCipher Source #
Constructors
| Aead a => AEADCipher (Proxy a) |
API
Instances
| Aead AES128 Source # | From RFC 9180 A.1
|
| Aead AES256 Source # | From RFC 9180 A.6
|
| Aead ChaCha20Poly1305 Source # | From RFC 9180 A.5
|
Methods
labeledExtract :: Suite -> Salt -> Label -> IKM -> PRK h Source #
labeledExpand :: Suite -> PRK h -> Label -> Info -> Int -> Either HPKEError Key Source #
RFC 9180 section 5.3 allows an output of at most 255 * Nh octets,
which is also what HKDF's counter can reach. A longer one is refused
here rather than left to the HKDF underneath, whose way of saying so
is an exception.
class (KEM kem, EncapsulationKey kem ~ EncodedPublicKey, DecapsulationKey kem ~ EncodedSecretKey, Ciphertext kem ~ EncodedPublicKey, Coins kem ~ EncodedSecretKey) => HPKEKEM kem where Source #
What HPKE needs of a KEM beyond what crypton's KEM class says.
RFC 9180 section 4.1 gives DHKEM four operations and the class has room
for two: Encap is encapsulate, Decap is decapsulate. AuthEncap
and AuthDecap take a static sender key, which the class has no argument
for, so they are here. They default to refusing, which is what a KEM
with no authenticated mode -- any post-quantum one -- should do.
The equalities pin the four associated types to the serialized forms of
section 4, which is what travels and what this package's entry points
take, so that setupS can be written once for every KEM.
Minimal complete definition
Methods
generateCoins :: MonadRandom m => proxy kem -> m EncodedSecretKey Source #
Draw what encapsulate would have drawn, so that the
authenticated forms can generate their ephemeral key the same way.
For every KEM here the coins are a secret key, so the default is to draw a key pair and keep the half that is one.
Arguments
| :: proxy kem | |
| -> EncodedSecretKey |
|
| -> EncodedPublicKey | pkR |
| -> EncodedSecretKey | skE |
| -> Either HPKEError (EncodedPublicKey, SharedSecret) |
AuthEncap of section 4.1, with the ephemeral key supplied.
Arguments
| :: proxy kem | |
| -> EncodedPublicKey |
|
| -> EncodedSecretKey | skR |
| -> EncodedPublicKey | enc |
| -> Either HPKEError SharedSecret |
AuthDecap of section 4.1. The sender is named by its public
key: a receiver does not have the other side's secret key, and
asking for one would be asking for the wrong thing.
toEncapsulationKey :: proxy kem -> EncodedSecretKey -> Either HPKEError EncodedPublicKey Source #
The encapsulation key a decapsulation key belongs to.
Instances
Types
Constructors
| ModeBase | |
| ModePsk | |
| ModeAuth | |
| ModeAuthPsk |
Generating key pair
genKeyPair :: HPKEMap -> KEM_ID -> IO (EncodedPublicKey, EncodedSecretKey) Source #
Generating a pair of public key and secret key based on
KEM_ID.
toPublicKey :: HPKEMap -> KEM_ID -> EncodedSecretKey -> Either HPKEError EncodedPublicKey Source #
The public key that goes with a secret key, for the KEM named by the
KEM_ID. A receiver authenticating a sender is given the sender's
public key; this is how the sender arrives at one to publish.