Package org.conscrypt
Class HpkeImpl
- java.lang.Object
-
- org.conscrypt.HpkeImpl
-
- All Implemented Interfaces:
HpkeSpi
- Direct Known Subclasses:
HpkeImpl.HpkeMlKemImpl,HpkeImpl.HpkeX25519Impl,HpkeImpl.HpkeXwingImpl
@Internal public abstract class HpkeImpl extends java.lang.Object implements HpkeSpi
Implementation ofHpkeSpi. Should not be used directly, but rather by one of the subclasses ofHpkeContext.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classHpkeImpl.HpkeMlKemImplprivate static classHpkeImpl.HpkeX25519Implprivate static classHpkeImpl.HpkeXwingImplstatic classHpkeImpl.MlKem1024HkdfSha256Aes128GcmImplementation of MLKEM_1024/HKDF_SHA256/AES_128_GCM.static classHpkeImpl.MlKem1024HkdfSha256Aes256GcmImplementation of MLKEM_1024/HKDF_SHA256/AES_256_GCM.static classHpkeImpl.MlKem1024HkdfSha256ChaCha20Poly1305Implementation of MLKEM_1024/HKDF_SHA256/CHACHA20_POLY1305.static classHpkeImpl.MlKem768HkdfSha256Aes128GcmImplementation of MLKEM_768/HKDF_SHA256/AES_128_GCM.static classHpkeImpl.MlKem768HkdfSha256Aes256GcmImplementation of MLKEM_768/HKDF_SHA256/AES_256_GCM.static classHpkeImpl.MlKem768HkdfSha256ChaCha20Poly1305Implementation of MLKEM_768/HKDF_SHA256/CHACHA20_POLY1305.static classHpkeImpl.X25519_AES_128Implementation of X25519/HKDF_SHA256/AES_128_GCM.static classHpkeImpl.X25519_AES_256Implementation of X25519/HKDF_SHA256/AES_256_GCM.static classHpkeImpl.X25519_CHACHA20Implementation of X25519/HKDF_SHA256/CHACHA20_POLY1305.static classHpkeImpl.XwingHkdfSha256Aes128GcmImplementation of XWING/HKDF_SHA256/AES_128_GCM.static classHpkeImpl.XwingHkdfSha256Aes256GcmImplementation of XWING/HKDF_SHA256/AES_256_GCM.static classHpkeImpl.XwingHkdfSha256ChaCha20Poly1305Implementation of XWING/HKDF_SHA256/CHACHA20_POLY1305.
-
Field Summary
Fields Modifier and Type Field Description private NativeRef.EVP_HPKE_CTXctxprivate byte[]encapsulatedprivate HpkeSuitehpkeSuiteprivate static OpenSslXwingKeyFactoryxwingKeyFactory-
Fields inherited from interface org.conscrypt.HpkeSpi
DEFAULT_PSK, DEFAULT_PSK_ID
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidcheckArgumentsForBaseModeOnly(java.security.Key senderKey, byte[] psk, byte[] psk_id)private voidcheckInitialised()private voidcheckIsRecipient()private voidcheckIsSender()private voidcheckNotInitialised()byte[]engineExport(int length, byte[] exporterContext)Exports secret key material from this SPI as described in RFC 9180.voidengineInitRecipient(byte[] encapsulated, java.security.PrivateKey recipientKey, byte[] info, java.security.PublicKey senderKey, byte[] psk, byte[] psk_id)Initialises an HPKE recipient SPI.voidengineInitSender(java.security.PublicKey recipientKey, byte[] info, java.security.PrivateKey senderKey, byte[] psk, byte[] psk_id)Initialises an HPKE sender SPI.voidengineInitSenderForTesting(java.security.PublicKey recipientKey, byte[] info, java.security.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[]getEncapsulated()Returns the encapsulated key material for an HPKE sender.(package private) abstract byte[]getPrivateRecipientKeyBytes(java.security.PrivateKey recipientKey)(package private) abstract byte[]getRecipientPublicKeyBytes(java.security.PublicKey recipientKey)
-
-
-
Field Detail
-
hpkeSuite
private final HpkeSuite hpkeSuite
-
ctx
private NativeRef.EVP_HPKE_CTX ctx
-
encapsulated
private byte[] encapsulated
-
xwingKeyFactory
private static final OpenSslXwingKeyFactory xwingKeyFactory
-
-
Constructor Detail
-
HpkeImpl
public HpkeImpl(HpkeSuite hpkeSuite)
-
-
Method Detail
-
getRecipientPublicKeyBytes
abstract byte[] getRecipientPublicKeyBytes(java.security.PublicKey recipientKey) throws java.security.InvalidKeyException- Throws:
java.security.InvalidKeyException
-
engineInitSender
public void engineInitSender(java.security.PublicKey recipientKey, byte[] info, java.security.PrivateKey senderKey, byte[] psk, byte[] psk_id) throws java.security.InvalidKeyExceptionDescription copied from interface:HpkeSpiInitialises an HPKE sender SPI.- Specified by:
engineInitSenderin interfaceHpkeSpi- 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:
java.security.InvalidKeyException- if recipientKey is null or an unsupported key format
-
engineInitSenderForTesting
public void engineInitSenderForTesting(java.security.PublicKey recipientKey, byte[] info, java.security.PrivateKey senderKey, byte[] psk, byte[] psk_id, byte[] sKe) throws java.security.InvalidKeyExceptionDescription copied from interface:HpkeSpiInitialises an HPKE sender SPI.- Specified by:
engineInitSenderForTestingin interfaceHpkeSpi- 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:
java.security.InvalidKeyException- if recipientKey is null or an unsupported key format or senderKey is an unsupported key format
-
getPrivateRecipientKeyBytes
abstract byte[] getPrivateRecipientKeyBytes(java.security.PrivateKey recipientKey) throws java.security.InvalidKeyException- Throws:
java.security.InvalidKeyException
-
engineInitRecipient
public void engineInitRecipient(byte[] encapsulated, java.security.PrivateKey recipientKey, byte[] info, java.security.PublicKey senderKey, byte[] psk, byte[] psk_id) throws java.security.InvalidKeyExceptionDescription copied from interface:HpkeSpiInitialises an HPKE recipient SPI.- Specified by:
engineInitRecipientin interfaceHpkeSpi- 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:
java.security.InvalidKeyException- if recipientKey is null or an unsupported key format or senderKey is an unsupported key format
-
checkArgumentsForBaseModeOnly
private void checkArgumentsForBaseModeOnly(java.security.Key senderKey, byte[] psk, byte[] psk_id)
-
engineSeal
public byte[] engineSeal(byte[] plaintext, byte[] aad)Description copied from interface:HpkeSpiSeals a message, using the internal key schedule maintained by an HPKE sender.- Specified by:
engineSealin interfaceHpkeSpi- Parameters:
plaintext- the plaintextaad- optional associated data, may be null or empty- Returns:
- the ciphertext
-
engineExport
public byte[] engineExport(int length, byte[] exporterContext)Description copied from interface:HpkeSpiExports secret key material from this SPI as described in RFC 9180.- Specified by:
engineExportin interfaceHpkeSpi- Parameters:
length- expected output lengthexporterContext- optional context string, may be null or empty- Returns:
- exported value
-
engineOpen
public byte[] engineOpen(byte[] ciphertext, byte[] aad) throws java.security.GeneralSecurityExceptionDescription copied from interface:HpkeSpiOpens a message, using the internal key schedule maintained by an HPKE recipient.- Specified by:
engineOpenin interfaceHpkeSpi- Parameters:
ciphertext- the ciphertextaad- optional associated data, may be null or empty- Returns:
- the plaintext
- Throws:
java.security.GeneralSecurityException- on decryption failures
-
checkInitialised
private void checkInitialised()
-
checkNotInitialised
private void checkNotInitialised()
-
checkIsSender
private void checkIsSender()
-
checkIsRecipient
private void checkIsRecipient()
-
getEncapsulated
public byte[] getEncapsulated()
Description copied from interface:HpkeSpiReturns the encapsulated key material for an HPKE sender.- Specified by:
getEncapsulatedin interfaceHpkeSpi- Returns:
- the key material
-
-