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 Object implements HpkeSpi
Implementation of HpkeSpi. Should not be used directly, but rather by one of the subclasses of HpkeContext.
  • Field Details

  • Constructor Details

    • HpkeImpl

      public HpkeImpl(HpkeSuite hpkeSuite)
  • Method Details

    • getRecipientPublicKeyBytes

      abstract byte[] getRecipientPublicKeyBytes(PublicKey recipientKey) throws InvalidKeyException
      Throws:
      InvalidKeyException
    • engineInitSender

      public void engineInitSender(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id) throws InvalidKeyException
      Description copied from interface: HpkeSpi
      Initialises an HPKE sender SPI.
      Specified by:
      engineInitSender in interface HpkeSpi
      Parameters:
      recipientKey - public key of the recipient
      info - application-supplied information, may be null or empty
      senderKey - private key of the sender, for symmetric auth modes only, else null
      psk - pre-shared key, for PSK auth modes only, else null
      psk_id - pre-shared key ID, for PSK auth modes only, else null
      Throws:
      InvalidKeyException - if recipientKey is null or an unsupported key format
    • engineInitSenderForTesting

      public void engineInitSenderForTesting(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id, byte[] sKe) throws InvalidKeyException
      Description copied from interface: HpkeSpi
      Initialises an HPKE sender SPI.
      Specified by:
      engineInitSenderForTesting in interface HpkeSpi
      Parameters:
      recipientKey - public key of the recipient
      info - application-supplied information, may be null or empty
      senderKey - private key of the sender, for symmetric auth modes only, else null
      psk - pre-shared key, for PSK auth modes only, else null
      psk_id - pre-shared key ID, for PSK auth modes only, else null
      sKe - 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 format
    • getPrivateRecipientKeyBytes

      abstract byte[] getPrivateRecipientKeyBytes(PrivateKey recipientKey) throws InvalidKeyException
      Throws:
      InvalidKeyException
    • engineInitRecipient

      public void engineInitRecipient(byte[] encapsulated, PrivateKey recipientKey, byte[] info, PublicKey senderKey, byte[] psk, byte[] psk_id) throws InvalidKeyException
      Description copied from interface: HpkeSpi
      Initialises an HPKE recipient SPI.
      Specified by:
      engineInitRecipient in interface HpkeSpi
      Parameters:
      encapsulated - encapsulated ephemeral key from a sender
      recipientKey - private key of the recipient
      info - application-supplied information, may be null or empty
      senderKey - public key of sender, for asymmetric auth modes only, else null
      psk - pre-shared key, for PSK auth modes only, else null
      psk_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 format
    • checkArgumentsForBaseModeOnly

      private void checkArgumentsForBaseModeOnly(Key senderKey, byte[] psk, byte[] psk_id)
    • engineSeal

      public byte[] engineSeal(byte[] plaintext, byte[] aad)
      Description copied from interface: HpkeSpi
      Seals a message, using the internal key schedule maintained by an HPKE sender.
      Specified by:
      engineSeal in interface HpkeSpi
      Parameters:
      plaintext - the plaintext
      aad - optional associated data, may be null or empty
      Returns:
      the ciphertext
    • engineExport

      public byte[] engineExport(int length, byte[] exporterContext)
      Description copied from interface: HpkeSpi
      Exports secret key material from this SPI as described in RFC 9180.
      Specified by:
      engineExport in interface HpkeSpi
      Parameters:
      length - expected output length
      exporterContext - optional context string, may be null or empty
      Returns:
      exported value
    • engineOpen

      public byte[] engineOpen(byte[] ciphertext, byte[] aad) throws GeneralSecurityException
      Description copied from interface: HpkeSpi
      Opens a message, using the internal key schedule maintained by an HPKE recipient.
      Specified by:
      engineOpen in interface HpkeSpi
      Parameters:
      ciphertext - the ciphertext
      aad - optional associated data, may be null or empty
      Returns:
      the plaintext
      Throws:
      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: HpkeSpi
      Returns the encapsulated key material for an HPKE sender.
      Specified by:
      getEncapsulated in interface HpkeSpi
      Returns:
      the key material