KEM
class. A security provider implements this interface to provide an
implementation of a Key Encapsulation Mechanism (KEM) algorithm.
A KEM algorithm may support a family of configurations. Each configuration
may accept different types of keys, cryptographic primitives, and sizes of
shared secrets and key encapsulation messages. A configuration is defined
by the KEM algorithm name, the key it uses, and an optional
AlgorithmParameterSpec argument that is specified when creating
an encapsulator or decapsulator. The result of calling
engineNewEncapsulator or engineNewDecapsulator must return
an encapsulator or decapsulator that maps to a single configuration,
where its engineSecretSize() and engineEncapsulationSize()
methods return constant values.
A KEMSpi implementation must be immutable. It must be safe to
call multiple engineNewEncapsulator and engineNewDecapsulator
methods at the same time.
EncapsulatorSpi and DecapsulatorSpi implementations must also
be immutable. It must be safe to invoke multiple encapsulate and
decapsulate methods at the same time. Each invocation of
encapsulate should generate a new shared secret and key
encapsulation message.
For example,
public static class MyKEMImpl implements KEMSpi { @Override public KEMSpi.EncapsulatorSpi engineNewEncapsulator(PublicKey publicKey, AlgorithmParameterSpec spec, SecureRandom secureRandom) throws InvalidAlgorithmParameterException, InvalidKeyException { if (!checkPublicKey(publicKey)) { throw new InvalidKeyException("unsupported key"); } if (!checkParameters(spec)) { throw new InvalidAlgorithmParameterException("unsupported params"); } return new MyEncapsulator(publicKey, spec, secureRandom); } class MyEncapsulator implements KEMSpi.EncapsulatorSpi { MyEncapsulator(PublicKey publicKey, AlgorithmParameterSpec spec, SecureRandom secureRandom){ this.spec = spec != null ? spec : getDefaultParameters(); this.secureRandom = secureRandom != null ? secureRandom : getDefaultSecureRandom(); this.publicKey = publicKey; } @Override public KEM.Encapsulated encapsulate(int from, int to, String algorithm) { byte[] encapsulation; byte[] secret; // calculating... return new KEM.Encapsulated( new SecretKeySpec(secret, from, to - from, algorithm), encapsulation, null); } // ... } // ... }
KEM
| Modifier and Type | Class and Description |
|---|---|
| public static interface | KEMSpi.
The KEM decapsulator implementation, generated by
|
| public static interface | KEMSpi.
The KEM encapsulator implementation, generated by
|
| Modifier and Type | Method and Description |
|---|---|
| public KEMSpi. | Returns: the decapsulator for this keythe receiver's private key, must not be privateKey, AlgorithmParameterSpec nullthe optional parameter, can be spec)nullCreates a KEM decapsulator on the KEM receiver side. |
| public KEMSpi. | Returns: the encapsulator for this keythe receiver's public key, must not be publicKey, AlgorithmParameterSpec nullthe optional parameter, can be spec, SecureRandom nullthe source of randomness for encapsulation.
If secureRandom)null, the implementation must provide
a default one.Creates a KEM encapsulator on the KEM sender side. |
| engineNewDecapsulator | back to summary |
|---|---|
| public KEMSpi. Creates a KEM decapsulator on the KEM receiver side.
| |
| engineNewEncapsulator | back to summary |
|---|---|
| public KEMSpi. Creates a KEM encapsulator on the KEM sender side.
| |
engineNewDecapsulator on the KEM receiver side.
KEM.Decapsulator
| Modifier and Type | Method and Description |
|---|---|
| public SecretKey | Returns: a portion of the shared secret as aSecretKey with
the specified algorithmthe key encapsulation message from the sender.
The size must be equal to the value returned by
encapsulation, int engineEncapsulationSize() ()}, or a
DecapsulateException must be thrown.the initial index of the shared secret byte array
to be returned, inclusive from, int the final index of the shared secret byte array
to be returned, exclusive to, String the algorithm name for the secret key that is returned.
See the SecretKey Algorithms section in the
Java Security Standard Algorithm Names Specification
for information about standard secret key algorithm names.
Specify "Generic" if the output will be used as the input keying
material of a key derivation function (KDF). algorithm)The key decapsulation function. |
| public int | Returns: the size of the key encapsulation message as a finite non-negative integerReturns the size of the key encapsulation message. |
| public int | Returns: the size of the shared secret as a finite non-negative integerReturns the size of the shared secret. |
| engineDecapsulate | back to summary |
|---|---|
| public SecretKey engineDecapsulate(byte[] encapsulation, int from, int to, String algorithm) throws DecapsulateException The key decapsulation function. An invocation of this method recovers the secret key from the key encapsulation message.
An implementation must support the case where
| |
| engineEncapsulationSize | back to summary |
|---|---|
| public int engineEncapsulationSize() Returns the size of the key encapsulation message.
| |
| engineSecretSize | back to summary |
|---|---|
| public int engineSecretSize() Returns the size of the shared secret.
| |
engineNewEncapsulator on the KEM sender side.
KEM.Encapsulator
| Modifier and Type | Method and Description |
|---|---|
| public KEM. | Returns: anKEM. object containing a portion of
the shared secret as a key with the specified algorithm,
key encapsulation message, and optional parameters.the initial index of the shared secret byte array
to be returned, inclusive from, int the final index of the shared secret byte array
to be returned, exclusive to, String the algorithm name for the secret key that is returned.
See the SecretKey Algorithms section in the
Java Security Standard Algorithm Names Specification
for information about standard secret key algorithm names.
Specify "Generic" if the output will be used as the input keying
material of a key derivation function (KDF). algorithm)The key encapsulation function. |
| public int | Returns: the size of the key encapsulation message as a finite non-negative integerReturns the size of the key encapsulation message. |
| public int | Returns: the size of the shared secret as a finite non-negative integerReturns the size of the shared secret. |
| engineEncapsulate | back to summary |
|---|---|
| public KEM. The key encapsulation function.
Each invocation of this method must generate a new secret key and key
encapsulation message that is returned in an
An implementation must support the case where
| |
| engineEncapsulationSize | back to summary |
|---|---|
| public int engineEncapsulationSize() Returns the size of the key encapsulation message.
| |
| engineSecretSize | back to summary |
|---|---|
| public int engineSecretSize() Returns the size of the shared secret.
| |