APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.security.provider

public abstract Class NamedKEM

extends Object
implements KEMSpi
Class Inheritance
All Implemented Interfaces
javax.crypto.KEMSpi
Known Direct Subclasses
com.sun.crypto.provider.ML_KEM_Impls.K
Imports
sun.security.pkcs.NamedPKCS8Key, sun.security.x509.NamedX509Key, javax.crypto.DecapsulateException, .KEM, .KEMSpi, .SecretKey, javax.crypto.spec.SecretKeySpec, java.security.InvalidAlgorithmParameterException, .InvalidKeyException, .PrivateKey, .ProviderException, .PublicKey, .SecureRandom, java.security.spec.AlgorithmParameterSpec, .NamedParameterSpec, java.util.Arrays

A base class for all KEM implementations that can be configured with a named parameter set. See NamedKeyPairGenerator for more details.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
private final NamedKeyFactory
private final String

Constructor Summary

AccessConstructor and Description
protected
NamedKEM(String
the family name
fname
,
NamedKeyFactory
the KeyFactory used to translate foreign keys and perform key validation
fac
)

Creates a new NamedKEM object.

Method Summary

Modifier and TypeMethod and Description
public KEMSpi.DecapsulatorSpi
engineNewDecapsulator(PrivateKey privateKey, AlgorithmParameterSpec spec)

Implements javax.crypto.KEMSpi.engineNewDecapsulator.

Creates a KEM decapsulator on the KEM receiver side.

public KEMSpi.EncapsulatorSpi
engineNewEncapsulator(PublicKey publicKey, AlgorithmParameterSpec spec, SecureRandom secureRandom)

Implements javax.crypto.KEMSpi.engineNewEncapsulator.

Creates a KEM encapsulator on the KEM sender side.

private static NamedKEM.KeyConsumerImpl
protected Object

Returns:

a parsed key, null if none.
implCheckPrivateKey
(String
parameter name
pname
,
byte[]
private key in raw bytes
sk
)

User-defined function to validate a private key.

protected Object

Returns:

a parsed key, null if none.
implCheckPublicKey
(String
parameter name
pname
,
byte[]
public key in raw bytes
pk
)

User-defined function to validate a public key.

protected abstract byte[]

Returns:

the shared key
implDecapsulate
(String
parameter name
pname
,
byte[]
private key in raw bytes
sk
,
Object
parsed private key, null if none. See implCheckPrivateKey.
sk2
,
byte[]
the key encapsulation message
encap
)

User-defined decap function.

protected abstract byte[][]

Returns:

the key encapsulation message and the shared key (in this order)
implEncapsulate
(String
parameter name
pname
,
byte[]
public key in raw bytes
pk
,
Object
parsed public key, null if none. See implCheckPublicKey.
pk2
,
SecureRandom
SecureRandom object, null if not initialized
sr
)

User-defined encap function.

protected abstract int

Returns:

key encapsulation message length
implEncapsulationSize
(String
parameter name
pname
)

User-defined function returning key encapsulation message length.

protected abstract int

Returns:

shared secret key length
implSecretSize
(String
parameter name
pname
)

User-defined function returning shared secret key length.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

facback to summary
private final NamedKeyFactory fac
fnameback to summary
private final String fname

Constructor Detail

NamedKEMback to summary
protected NamedKEM(String fname, NamedKeyFactory fac)

Creates a new NamedKEM object.

Parameters
fname:String

the family name

fac:NamedKeyFactory

the KeyFactory used to translate foreign keys and perform key validation

Method Detail

engineNewDecapsulatorback to summary
public KEMSpi.DecapsulatorSpi engineNewDecapsulator(PrivateKey privateKey, AlgorithmParameterSpec spec) throws InvalidAlgorithmParameterException, InvalidKeyException

Implements javax.crypto.KEMSpi.engineNewDecapsulator.

Doc from javax.crypto.KEMSpi.engineNewDecapsulator.

Creates a KEM decapsulator on the KEM receiver side.

Annotations
@Override
Exceptions
InvalidAlgorithmParameterException:
if spec is invalid or one is required but spec is null
InvalidKeyException:
if privateKey is null or invalid
engineNewEncapsulatorback to summary
public KEMSpi.EncapsulatorSpi engineNewEncapsulator(PublicKey publicKey, AlgorithmParameterSpec spec, SecureRandom secureRandom) throws InvalidAlgorithmParameterException, InvalidKeyException

Implements javax.crypto.KEMSpi.engineNewEncapsulator.

Doc from javax.crypto.KEMSpi.engineNewEncapsulator.

Creates a KEM encapsulator on the KEM sender side.

Annotations
@Override
Exceptions
InvalidAlgorithmParameterException:
if spec is invalid or one is required but spec is null
InvalidKeyException:
if publicKey is null or invalid
getKeyConsumerImplback to summary
private static NamedKEM.KeyConsumerImpl getKeyConsumerImpl(NamedKEM kem, NamedParameterSpec nps, byte[] key, Object k2, SecureRandom sr)
implCheckPrivateKeyback to summary
protected Object implCheckPrivateKey(String pname, byte[] sk) throws InvalidKeyException

User-defined function to validate a private key.

This method will be called in newDecapsulator. This gives the provider a chance to reject the key so an InvalidKeyException can be thrown earlier. An implementation can optionally return a "parsed key" as an Object value. This object will be passed into the implDecapsulate method along with the raw key.

The default implementation returns null.

Parameters
pname:String

parameter name

sk:byte[]

private key in raw bytes

Returns:Object

a parsed key, null if none.

Exceptions
InvalidKeyException:
if the key is invalid
implCheckPublicKeyback to summary
protected Object implCheckPublicKey(String pname, byte[] pk) throws InvalidKeyException

User-defined function to validate a public key.

This method will be called in newEncapsulator. This gives the provider a chance to reject the key so an InvalidKeyException can be thrown earlier. An implementation can optionally return a "parsed key" as an Object value. This object will be passed into the implEncapsulate method along with the raw key.

The default implementation returns null.

Parameters
pname:String

parameter name

pk:byte[]

public key in raw bytes

Returns:Object

a parsed key, null if none.

Exceptions
InvalidKeyException:
if the key is invalid
implDecapsulateback to summary
protected abstract byte[] implDecapsulate(String pname, byte[] sk, Object sk2, byte[] encap) throws DecapsulateException

User-defined decap function.

Parameters
pname:String

parameter name

sk:byte[]

private key in raw bytes

sk2:Object

parsed private key, null if none. See implCheckPrivateKey.

encap:byte[]

the key encapsulation message

Returns:byte[]

the shared key

Exceptions
DecapsulateException:
if there is another error
ProviderException:
if there is an internal error
implEncapsulateback to summary
protected abstract byte[][] implEncapsulate(String pname, byte[] pk, Object pk2, SecureRandom sr)

User-defined encap function.

Parameters
pname:String

parameter name

pk:byte[]

public key in raw bytes

pk2:Object

parsed public key, null if none. See implCheckPublicKey.

sr:SecureRandom

SecureRandom object, null if not initialized

Returns:byte[][]

the key encapsulation message and the shared key (in this order)

Exceptions
ProviderException:
if there is an internal error
implEncapsulationSizeback to summary
protected abstract int implEncapsulationSize(String pname)

User-defined function returning key encapsulation message length.

Parameters
pname:String

parameter name

Returns:int

key encapsulation message length

Exceptions
ProviderException:
if there is an internal error
implSecretSizeback to summary
protected abstract int implSecretSize(String pname)

User-defined function returning shared secret key length.

Parameters
pname:String

parameter name

Returns:int

shared secret key length

Exceptions
ProviderException:
if there is an internal error
sun.security.provider back to summary

private final Record NamedKEM.KeyConsumerImpl

extends Record
implements EncapsulatorSpi, DecapsulatorSpi
Class Inheritance
All Implemented Interfaces
javax.crypto.KEMSpi.DecapsulatorSpi, javax.crypto.KEMSpi.EncapsulatorSpi
Record Components
kem:NamedKEM 
pname:String 
sslen:int 
clen:int 
key:byte[] 
k2:Object 
sr:SecureRandom 

Field Summary

Modifier and TypeField and Description
private final int
clen

Record Component accessed by clen().

private final Object
k2

Record Component accessed by k2().

private final NamedKEM
kem

Record Component accessed by kem().

private final byte[]
key

Record Component accessed by key().

private final String
pname

Record Component accessed by pname().

private final SecureRandom
sr

Record Component accessed by sr().

private final int
sslen

Record Component accessed by sslen().

Constructor Summary

AccessConstructor and Description
private
KeyConsumerImpl(NamedKEM kem, String pname, int sslen, int clen, byte[] key, Object k2, SecureRandom sr)

Method Summary

Modifier and TypeMethod and Description
public int
clen()

Record Component getter of clen.

public SecretKey
engineDecapsulate(byte[] encapsulation, int from, int to, String algorithm)

Implements javax.crypto.KEMSpi.DecapsulatorSpi.engineDecapsulate.

The key decapsulation function.

public KEM.Encapsulated
engineEncapsulate(int from, int to, String algorithm)

Implements javax.crypto.KEMSpi.EncapsulatorSpi.engineEncapsulate.

The key encapsulation function.

public int
public int
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public Object
k2()

Record Component getter of k2.

public NamedKEM
kem()

Record Component getter of kem.

public byte[]
key()

Record Component getter of key.

public String
pname()

Record Component getter of pname.

public SecureRandom
sr()

Record Component getter of sr.

public int
sslen()

Record Component getter of sslen.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

clenback to summary
private final int clen

Record Component accessed by clen().

k2back to summary
private final Object k2

Record Component accessed by k2().

kemback to summary
private final NamedKEM kem

Record Component accessed by kem().

keyback to summary
private final byte[] key

Record Component accessed by key().

pnameback to summary
private final String pname

Record Component accessed by pname().

srback to summary
private final SecureRandom sr

Record Component accessed by sr().

sslenback to summary
private final int sslen

Record Component accessed by sslen().

Constructor Detail

KeyConsumerImplback to summary
private KeyConsumerImpl(NamedKEM kem, String pname, int sslen, int clen, byte[] key, Object k2, SecureRandom sr)

Method Detail

clenback to summary
public int clen()

Record Component getter of clen.

engineDecapsulateback to summary
public SecretKey engineDecapsulate(byte[] encapsulation, int from, int to, String algorithm) throws DecapsulateException

Implements javax.crypto.KEMSpi.DecapsulatorSpi.engineDecapsulate.

Doc from javax.crypto.KEMSpi.DecapsulatorSpi.engineDecapsulate.

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 from is 0, to is the same as the return value of secretSize(), and algorithm is "Generic".

Annotations
@Override
Exceptions
DecapsulateException:
if an error occurs during the decapsulation process
engineEncapsulateback to summary
public KEM.Encapsulated engineEncapsulate(int from, int to, String algorithm)

Implements javax.crypto.KEMSpi.EncapsulatorSpi.engineEncapsulate.

Doc from javax.crypto.KEMSpi.EncapsulatorSpi.engineEncapsulate.

The key encapsulation function.

Each invocation of this method must generate a new secret key and key encapsulation message that is returned in an KEM.Encapsulated object.

An implementation must support the case where from is 0, to is the same as the return value of secretSize(), and algorithm is "Generic".

Annotations
@Override
engineEncapsulationSizeback to summary
public int engineEncapsulationSize()

Implements javax.crypto.KEMSpi.EncapsulatorSpi.engineEncapsulationSize, javax.crypto.KEMSpi.DecapsulatorSpi.engineEncapsulationSize.

Doc from javax.crypto.KEMSpi.EncapsulatorSpi.engineEncapsulationSize.

Returns the size of the key encapsulation message.

Annotations
@Override
engineSecretSizeback to summary
public int engineSecretSize()

Implements javax.crypto.KEMSpi.EncapsulatorSpi.engineSecretSize, javax.crypto.KEMSpi.DecapsulatorSpi.engineSecretSize.

Doc from javax.crypto.KEMSpi.EncapsulatorSpi.engineSecretSize.

Returns the size of the shared secret.

Annotations
@Override
equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

k2back to summary
public Object k2()

Record Component getter of k2.

kemback to summary
public NamedKEM kem()

Record Component getter of kem.

keyback to summary
public byte[] key()

Record Component getter of key.

pnameback to summary
public String pname()

Record Component getter of pname.

srback to summary
public SecureRandom sr()

Record Component getter of sr.

sslenback to summary
public int sslen()

Record Component getter of sslen.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.