Interface KEM.Decapsulator
Decapsulator is a preview API of the Java Card platform.
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 TypeMethodDescriptionshortReturns the size of the key encapsulation message (ciphertext).shortdecapsulate(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.shortdecapsulate(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.shortReturns 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 thesharedSecretoutput buffer.The encapsulation message is read from the
cipherTextbuffer, starting atcipherTextOffset. The shared secret bytes are written to thesharedSecretoutput buffer (starting atsharedSecretOffset).In addition to returning the number of bytes written to the
sharedSecretbuffer, this method updates a global state register for additional verification using assertion methods from theSensitiveResultclass, if this class is available on the platform.- Parameters:
privateKey- the private key used for decapsulationcipherText- buffer containing the key encapsulation message inputcipherTextOffset- offset in thecipherTextbuffer where the input beginssharedSecret- buffer for the derived shared secret outputsharedSecretOffset- offset in thesharedSecretbuffer where the output begins- Returns:
- number of bytes written to the
sharedSecretoutput buffer - Throws:
CryptoException- with the following reason codes:CryptoException.UNINITIALIZED_KEYif the private key is not initialized.CryptoException.ILLEGAL_VALUEif 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_EXPANDand 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 providedSecretKeyobject.The encapsulation message is read from the
cipherTextbuffer, starting atcipherTextOffset. Only the portion of the generated secret in the specified range (from, inclusive, toto, exclusive) is used to set the value of theSecretKeyobject.In addition to returning the number of bytes used to initialize the
SecretKeyobject, this method updates a global state register for additional verification using assertion methods from theSensitiveResultclass, if this class is available on the platform.- Parameters:
privateKey- the private key used for decapsulationcipherText- buffer containing the key encapsulation message inputcipherTextOffset- offset in thecipherTextbuffer where the input beginssharedSecret- theSecretKeyobject to be initialized with the derived shared secretfrom- initial index (inclusive) of the derived secret to use for theSecretKeyto- final index (exclusive) of the derived secret to use for theSecretKey- Returns:
- number of bytes used from the derived shared secret to initialize the
SecretKeyobject - Throws:
CryptoException- with the following reason codes:CryptoException.UNINITIALIZED_KEYif the private key is not initialized.CryptoException.ILLEGAL_VALUEif 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, orto > sharedSecretSize().to - fromdoes not equal the number of bytes required to initialize theSecretKey.
CryptoException.ILLEGAL_VALUEif the KEM object was not allocated withKEM.MODE_EXPANDand the private key is a seed.
-
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
encapsulateis called.- Returns:
- the size in bytes of the key ciphertext
-
Decapsulatorwhen preview features are enabled.