Interface KEM.Decapsulator

Enclosing class:
KEMPREVIEW

public static interface KEM.Decapsulator
Decapsulator is a preview API of the Java Card platform.
Programs can only use Decapsulator when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java Card platform.
The Decapsulator interface is implemented by KEMPREVIEW instances that support the key decapsulation operation of Key Encapsulation Mechanism (KEM) algorithms.

Instances supporting this interface are obtained by creating a KEMPREVIEW object in decapsulation mode (see KEM.getInstance(short, AlgorithmParameterSpec, short)PREVIEW factory method).

The decapsulation operation enables a receiver to recover a shared secret key from a key encapsulation message, using their private key. This allows two parties to securely establish a common secret using asymmetric cryptography.

Since:
preview
  • Method Summary

    Modifier and Type
    Method
    Description
    short
    Returns the size of the key encapsulation message (ciphertext).
    short
    decapsulate(PrivateKey privateKey, byte[] cipherText, short cipherTextOffset, byte[] sharedSecret, short sharedSecretOffset)
    Performs the key decapsulation operation, computing the shared secret from the provided key encapsulation message, as specified by the KEM algorithm and parameters.
    short
    decapsulate(PrivateKey privateKey, byte[] cipherText, short cipherTextOffset, SecretKey sharedSecret, short from, short to)
    Performs the key decapsulation operation, computing the shared secret from the provided key encapsulation message, as specified by the KEM algorithm and parameters.
    short
    Returns the size of the shared secret.
  • Method Details

    • decapsulate

      short decapsulate(PrivateKey privateKey, byte[] cipherText, short cipherTextOffset, byte[] sharedSecret, short sharedSecretOffset) throws CryptoException
      Performs the key decapsulation operation, computing the shared secret from the provided key encapsulation message, as specified by the KEM algorithm and parameters. The derived shared secret bytes are written to the sharedSecret output buffer.

      The encapsulation message is read from the cipherText buffer, starting at cipherTextOffset. The shared secret bytes are written to the sharedSecret output buffer (starting at sharedSecretOffset).

      In addition to returning the number of bytes written to the sharedSecret buffer, this method updates a global state register for additional verification using assertion methods from the SensitiveResult class, if this class is available on the platform.

      Parameters:
      privateKey - the private key used for decapsulation
      cipherText - buffer containing the key encapsulation message input
      cipherTextOffset - offset in the cipherText buffer where the input begins
      sharedSecret - buffer for the derived shared secret output
      sharedSecretOffset - offset in the sharedSecret buffer where the output begins
      Returns:
      number of bytes written to the sharedSecret output buffer
      Throws:
      CryptoException - with the following reason codes:
      • CryptoException.UNINITIALIZED_KEY if the private key is not initialized.
      • CryptoException.ILLEGAL_VALUE if any of the following conditions are met:
        • cipherText.length - cipherTextOffset < cipherTextSize().
        • the decapsulation private key is invalid because key consistency checks, if performed by the implementation, fail.
        • the KEM object was not allocated with KEM.MODE_EXPAND and the private key is a seed.
    • decapsulate

      short decapsulate(PrivateKey privateKey, byte[] cipherText, short cipherTextOffset, SecretKey sharedSecret, short from, short to) throws CryptoException
      Performs the key decapsulation operation, computing the shared secret from the provided key encapsulation message, as specified by the KEM algorithm and parameters. The derived shared secret is set into the provided SecretKey object.

      The encapsulation message is read from the cipherText buffer, starting at cipherTextOffset. Only the portion of the generated secret in the specified range (from, inclusive, to to, exclusive) is used to set the value of the SecretKey object.

      In addition to returning the number of bytes used to initialize the SecretKey object, this method updates a global state register for additional verification using assertion methods from the SensitiveResult class, if this class is available on the platform.

      Parameters:
      privateKey - the private key used for decapsulation
      cipherText - buffer containing the key encapsulation message input
      cipherTextOffset - offset in the cipherText buffer where the input begins
      sharedSecret - the SecretKey object to be initialized with the derived shared secret
      from - initial index (inclusive) of the derived secret to use for the SecretKey
      to - final index (exclusive) of the derived secret to use for the SecretKey
      Returns:
      number of bytes used from the derived shared secret to initialize the SecretKey object
      Throws:
      CryptoException - with the following reason codes:
      • CryptoException.UNINITIALIZED_KEY if the private key is not initialized.
      • CryptoException.ILLEGAL_VALUE if any of the following conditions are met:
        • cipherText.length - cipherTextOffset < cipherTextSize().
        • the decapsulation private key is invalid because key consistency checks, if performed by the implementation, fail.
        • from < 0, from > to, or to > sharedSecretSize().
        • to - from does not equal the number of bytes required to initialize the SecretKey.
      • CryptoException.ILLEGAL_VALUE if the KEM object was not allocated with KEM.MODE_EXPAND and the private key is a seed.
    • sharedSecretSize

      short sharedSecretSize()
      Returns the size of the shared secret.

      This method can be called to find out the length of the shared secret before decapsulate is called.

      Returns:
      the size in bytes of the shared secret
    • cipherTextSize

      short cipherTextSize()
      Returns the size of the key encapsulation message (ciphertext).

      This method can be called to find out the length of the ciphertext before encapsulate is called.

      Returns:
      the size in bytes of the key ciphertext