Interface HpkeSpi
- All Known Implementing Classes:
DuckTypedHpkeSpi, HpkeImpl, HpkeImpl.HpkeMlKemImpl, HpkeImpl.HpkeX25519Impl, HpkeImpl.HpkeXwingImpl, HpkeImpl.MlKem1024HkdfSha256Aes128Gcm, HpkeImpl.MlKem1024HkdfSha256Aes256Gcm, HpkeImpl.MlKem1024HkdfSha256ChaCha20Poly1305, HpkeImpl.MlKem768HkdfSha256Aes128Gcm, HpkeImpl.MlKem768HkdfSha256Aes256Gcm, HpkeImpl.MlKem768HkdfSha256ChaCha20Poly1305, HpkeImpl.X25519_AES_128, HpkeImpl.X25519_AES_256, HpkeImpl.X25519_CHACHA20, HpkeImpl.XwingHkdfSha256Aes128Gcm, HpkeImpl.XwingHkdfSha256Aes256Gcm, HpkeImpl.XwingHkdfSha256ChaCha20Poly1305
public interface HpkeSpi
SPI for HPKE clients to communicate with implementations. The client API can use any
implementation which implements this interface, by duck-typing if necessary.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]static final byte[] -
Method Summary
Modifier and TypeMethodDescriptionbyte[]engineExport(int length, byte[] context) Exports secret key material from this SPI as described in RFC 9180.voidengineInitRecipient(byte[] encapsulated, PrivateKey recipientKey, byte[] info, PublicKey senderKey, byte[] psk, byte[] psk_id) Initialises an HPKE recipient SPI.voidengineInitSender(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id) Initialises an HPKE sender SPI.voidengineInitSenderForTesting(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id, byte[] sKe) Initialises an HPKE sender SPI.byte[]engineOpen(byte[] ciphertext, byte[] aad) Opens a message, using the internal key schedule maintained by an HPKE recipient.byte[]engineSeal(byte[] plaintext, byte[] aad) Seals a message, using the internal key schedule maintained by an HPKE sender.byte[]Returns the encapsulated key material for an HPKE sender.
-
Field Details
-
DEFAULT_PSK
static final byte[] DEFAULT_PSK -
DEFAULT_PSK_ID
static final byte[] DEFAULT_PSK_ID
-
-
Method Details
-
engineInitSender
void engineInitSender(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id) throws InvalidKeyException Initialises an HPKE sender SPI.- Parameters:
recipientKey- public key of the recipientinfo- application-supplied information, may be null or emptysenderKey- private key of the sender, for symmetric auth modes only, else nullpsk- pre-shared key, for PSK auth modes only, else nullpsk_id- pre-shared key ID, for PSK auth modes only, else null- Throws:
InvalidKeyException- if recipientKey is null or an unsupported key formatUnsupportedOperationException- if mode is not a supported HPKE modeIllegalStateException- if this SPI has already been initialised
-
engineInitSenderForTesting
void engineInitSenderForTesting(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id, byte[] sKe) throws InvalidKeyException Initialises an HPKE sender SPI.- Parameters:
recipientKey- public key of the recipientinfo- application-supplied information, may be null or emptysenderKey- private key of the sender, for symmetric auth modes only, else nullpsk- pre-shared key, for PSK auth modes only, else nullpsk_id- pre-shared key ID, for PSK auth modes only, else nullsKe- optional random seed, should be null for all uses except for validation against known test vectors- Throws:
InvalidKeyException- if recipientKey is null or an unsupported key format or senderKey is an unsupported key formatUnsupportedOperationException- if mode is not a supported HPKE modeIllegalStateException- if this SPI has already been initialised
-
engineInitRecipient
void engineInitRecipient(byte[] encapsulated, PrivateKey recipientKey, byte[] info, PublicKey senderKey, byte[] psk, byte[] psk_id) throws InvalidKeyException Initialises an HPKE recipient SPI.- Parameters:
encapsulated- encapsulated ephemeral key from a senderrecipientKey- private key of the recipientinfo- application-supplied information, may be null or emptysenderKey- public key of sender, for asymmetric auth modes only, else nullpsk- pre-shared key, for PSK auth modes only, else nullpsk_id- pre-shared key ID, for PSK auth modes only, else null- Throws:
InvalidKeyException- if recipientKey is null or an unsupported key format or senderKey is an unsupported key formatUnsupportedOperationException- if mode is not a supported HPKE modeIllegalStateException- if this SPI has already been initialised
-
engineSeal
byte[] engineSeal(byte[] plaintext, byte[] aad) Seals a message, using the internal key schedule maintained by an HPKE sender.- Parameters:
plaintext- the plaintextaad- optional associated data, may be null or empty- Returns:
- the ciphertext
- Throws:
NullPointerException- if the plaintext is nullIllegalStateException- if this SPI has not been initialised or if it was initialised as a recipient
-
engineOpen
Opens a message, using the internal key schedule maintained by an HPKE recipient.- Parameters:
ciphertext- the ciphertextaad- optional associated data, may be null or empty- Returns:
- the plaintext
- Throws:
IllegalStateException- if this SPI has not been initialised or if it was initialised as a senderGeneralSecurityException- on decryption failures
-
engineExport
byte[] engineExport(int length, byte[] context) Exports secret key material from this SPI as described in RFC 9180.- Parameters:
length- expected output lengthcontext- optional context string, may be null or empty- Returns:
- exported value
- Throws:
IllegalArgumentException- if the length is not valid for the KDF in useIllegalStateException- if this SPI has not been initialised
-
getEncapsulated
byte[] getEncapsulated()Returns the encapsulated key material for an HPKE sender.- Returns:
- the key material
- Throws:
IllegalStateException- if this SPI has not been initialised or if it was initialised as a recipient
-