Single-shot API
Single-shot seal/open and export APIs (RFC 9180 §6).
- class rfc9180.single_shot.HPKESingleShot(setup)[source]
Bases:
objectSingle-shot HPKE APIs (RFC 9180 §6).
Provides convenient single-shot encryption/decryption operations that combine setup and encryption/decryption in one call.
- Parameters:
setup (HPKESetup) – HPKE setup instance for context creation.
- open_base(enc, skR, info, aad, ct)[source]
Open (decrypt) a message using Base mode.
- Parameters:
- Returns:
Decrypted plaintext.
- Return type:
- Raises:
OpenError – If decryption fails.
- seal_psk(pkR, info, aad, pt, psk, psk_id)[source]
Seal (encrypt) a message using PSK mode.
- Parameters:
- Returns:
Tuple of (encapsulated key, ciphertext).
- Return type:
- Raises:
ValueError – If PSK has insufficient entropy.
- open_psk(enc, skR, info, aad, ct, psk, psk_id)[source]
Open (decrypt) a message using PSK mode.
- Parameters:
enc (bytes) – Encapsulated public key.
skR (Key Object) – Recipient’s private key.
info (bytes) – Application-supplied information.
aad (bytes) – Additional authenticated data.
ct (bytes) – Ciphertext to decrypt.
psk (bytes) – Pre-shared key (must have at least 32 bytes of entropy).
psk_id (bytes) – Pre-shared key identifier.
- Returns:
Decrypted plaintext.
- Return type:
- Raises:
ValueError – If PSK has insufficient entropy.
OpenError – If decryption fails.
- open_auth(enc, skR, info, aad, ct, pkS)[source]
Open (decrypt) a message using Auth mode.
- Parameters:
- Returns:
Decrypted plaintext.
- Return type:
- Raises:
OpenError – If decryption fails.
- seal_auth_psk(pkR, info, aad, pt, psk, psk_id, skS)[source]
Seal (encrypt) a message using AuthPSK mode.
- Parameters:
pkR (Key Object) – Recipient’s public key.
info (bytes) – Application-supplied information.
aad (bytes) – Additional authenticated data.
pt (bytes) – Plaintext to encrypt.
psk (bytes) – Pre-shared key (must have at least 32 bytes of entropy).
psk_id (bytes) – Pre-shared key identifier.
skS (Key Object) – Sender’s private key.
- Returns:
Tuple of (encapsulated key, ciphertext).
- Return type:
- Raises:
ValueError – If PSK has insufficient entropy.
- open_auth_psk(enc, skR, info, aad, ct, psk, psk_id, pkS)[source]
Open (decrypt) a message using AuthPSK mode.
- Parameters:
enc (bytes) – Encapsulated public key.
skR (Key Object) – Recipient’s private key.
info (bytes) – Application-supplied information.
aad (bytes) – Additional authenticated data.
ct (bytes) – Ciphertext to decrypt.
psk (bytes) – Pre-shared key (must have at least 32 bytes of entropy).
psk_id (bytes) – Pre-shared key identifier.
pkS (Key Object) – Sender’s public key.
- Returns:
Decrypted plaintext.
- Return type:
- Raises:
ValueError – If PSK has insufficient entropy.
OpenError – If decryption fails.
- send_export_base(pkR, info, exporter_context, L)[source]
Export a secret using Base mode (sender side).
- receive_export_base(enc, skR, info, exporter_context, L)[source]
Export a secret using Base mode (recipient side).
- send_export_psk(pkR, info, exporter_context, L, psk, psk_id)[source]
Export a secret using PSK mode (sender side).
- Parameters:
- Returns:
Tuple of (encapsulated key, exported secret).
- Return type:
- Raises:
ValueError – If PSK has insufficient entropy.
- receive_export_psk(enc, skR, info, exporter_context, L, psk, psk_id)[source]
Export a secret using PSK mode (recipient side).
- Parameters:
enc (bytes) – Encapsulated public key.
skR (Key Object) – Recipient’s private key.
info (bytes) – Application-supplied information.
exporter_context (bytes) – Exporter context.
L (int) – Length of exported secret in bytes.
psk (bytes) – Pre-shared key (must have at least 32 bytes of entropy).
psk_id (bytes) – Pre-shared key identifier.
- Returns:
Exported secret.
- Return type:
- Raises:
ValueError – If PSK has insufficient entropy.
- send_export_auth(pkR, info, exporter_context, L, skS)[source]
Export a secret using Auth mode (sender side).
- Parameters:
- Returns:
Tuple of (encapsulated key, exported secret).
- Return type:
- receive_export_auth(enc, skR, info, exporter_context, L, pkS)[source]
Export a secret using Auth mode (recipient side).
- Parameters:
- Returns:
Exported secret.
- Return type:
- send_export_auth_psk(pkR, info, exporter_context, L, psk, psk_id, skS)[source]
Export a secret using AuthPSK mode (sender side).
- Parameters:
pkR (Key Object) – Recipient’s public key.
info (bytes) – Application-supplied information.
exporter_context (bytes) – Exporter context.
L (int) – Length of exported secret in bytes.
psk (bytes) – Pre-shared key (must have at least 32 bytes of entropy).
psk_id (bytes) – Pre-shared key identifier.
skS (Key Object) – Sender’s private key.
- Returns:
Tuple of (encapsulated key, exported secret).
- Return type:
- Raises:
ValueError – If PSK has insufficient entropy.
- receive_export_auth_psk(enc, skR, info, exporter_context, L, psk, psk_id, pkS)[source]
Export a secret using AuthPSK mode (recipient side).
- Parameters:
enc (bytes) – Encapsulated public key.
skR (Key Object) – Recipient’s private key.
info (bytes) – Application-supplied information.
exporter_context (bytes) – Exporter context.
L (int) – Length of exported secret in bytes.
psk (bytes) – Pre-shared key (must have at least 32 bytes of entropy).
psk_id (bytes) – Pre-shared key identifier.
pkS (Key Object) – Sender’s public key.
- Returns:
Exported secret.
- Return type:
- Raises:
ValueError – If PSK has insufficient entropy.