APIdia Launch Partner
Top Inners Fields Constructors Methods
com.sun.crypto.provider

public Class DHKEM

extends Object
implements KEMSpi
Class Inheritance
All Implemented Interfaces
javax.crypto.KEMSpi
Imports
java.io.ByteArrayOutputStream, .IOException, .Serial, java.math.BigInteger, java.security.AsymmetricKey, .InvalidAlgorithmParameterException, .InvalidKeyException, .KeyFactory, .KeyPair, .KeyPairGenerator, .NoSuchAlgorithmException, .PrivateKey, .ProviderException, .PublicKey, .SecureRandom, java.security.interfaces.ECPublicKey, .XECPublicKey, java.security.spec.AlgorithmParameterSpec, .ECParameterSpec, .ECPoint, .ECPrivateKeySpec, .ECPublicKeySpec, .InvalidKeySpecException, .KeySpec, .NamedParameterSpec, .XECPrivateKeySpec, .XECPublicKeySpec, java.util.Arrays, .Objects, javax.crypto.DecapsulateException, .KDF, .KEM, .KEMSpi, .KeyAgreement, .SecretKey, javax.crypto.spec.HKDFParameterSpec, .SecretKeySpec, sun.security.jca.JCAUtil, sun.security.util.ArrayUtil, .CurveDB, .ECUtil, .InternalPrivateKey, .NamedCurve, .SliceableSecretKey

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
private static enum
public static class

Field Summary

Modifier and TypeField and Description
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static byte[]
concat(byte[]... inputs)

public KEMSpi.DecapsulatorSpi
public KEMSpi.EncapsulatorSpi
public KEMSpi.DecapsulatorSpi
engineNewDecapsulator(PrivateKey sk, AlgorithmParameterSpec spec)

Implements javax.crypto.KEMSpi.engineNewDecapsulator.

Creates a KEM decapsulator on the KEM receiver side.

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

Implements javax.crypto.KEMSpi.engineNewEncapsulator.

Creates a KEM encapsulator on the KEM sender side.

private static SecureRandom
public static byte[]
i2OSP(int n, int w)

public static HKDFParameterSpec
labeledExpand(HKDFParameterSpec.Builder builder, byte[] suiteId, byte[] label, byte[] info, int length)

public static HKDFParameterSpec
labeledExpand(SecretKey prk, byte[] suiteId, byte[] label, byte[] info, int length)

public static HKDFParameterSpec.Builder
labeledExtract(byte[] suiteId, byte[] label)

private static byte[]
labeledInfo(byte[] suiteId, byte[] label, byte[] info, int length)

private DHKEM.Params
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CANDIDATEback to summary
private static final byte[] CANDIDATE
DKP_PRKback to summary
private static final byte[] DKP_PRK
EAE_PRKback to summary
private static final byte[] EAE_PRK
EMPTYback to summary
private static final byte[] EMPTY
HPKE_V1back to summary
private static final byte[] HPKE_V1
KEMback to summary
private static final byte[] KEM
SHARED_SECRETback to summary
private static final byte[] SHARED_SECRET
SKback to summary
private static final byte[] SK

Constructor Detail

DHKEMback to summary
public DHKEM()

Method Detail

concatback to summary
private static byte[] concat(byte[]... inputs)
engineNewAuthDecapsulatorback to summary
public KEMSpi.DecapsulatorSpi engineNewAuthDecapsulator(PrivateKey skR, PublicKey pkS, AlgorithmParameterSpec spec) throws InvalidAlgorithmParameterException, InvalidKeyException
engineNewAuthEncapsulatorback to summary
public KEMSpi.EncapsulatorSpi engineNewAuthEncapsulator(PublicKey pkR, PrivateKey skS, AlgorithmParameterSpec spec, SecureRandom secureRandom) throws InvalidAlgorithmParameterException, InvalidKeyException
engineNewDecapsulatorback to summary
public KEMSpi.DecapsulatorSpi engineNewDecapsulator(PrivateKey sk, 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 pk, 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
getSecureRandomback to summary
private static SecureRandom getSecureRandom(SecureRandom userSR)
i2OSPback to summary
public static byte[] i2OSP(int n, int w)
labeledExpandback to summary
public static HKDFParameterSpec labeledExpand(HKDFParameterSpec.Builder builder, byte[] suiteId, byte[] label, byte[] info, int length)
labeledExpandback to summary
public static HKDFParameterSpec labeledExpand(SecretKey prk, byte[] suiteId, byte[] label, byte[] info, int length)
labeledExtractback to summary
public static HKDFParameterSpec.Builder labeledExtract(byte[] suiteId, byte[] label)
labeledInfoback to summary
private static byte[] labeledInfo(byte[] suiteId, byte[] label, byte[] info, int length)
paramsFromKeyback to summary
private DHKEM.Params paramsFromKey(AsymmetricKey k) throws InvalidKeyException
com.sun.crypto.provider back to summary

private final Record DHKEM.Handler

extends Record
implements EncapsulatorSpi, DecapsulatorSpi
Class Inheritance
All Implemented Interfaces
javax.crypto.KEMSpi.DecapsulatorSpi, javax.crypto.KEMSpi.EncapsulatorSpi
Record Components
params:DHKEM.Params 
secureRandom:SecureRandom 
skS:PrivateKey 
pkS:PublicKey 
skR:PrivateKey 
pkR:PublicKey 

Field Summary

Modifier and TypeField and Description
private final DHKEM.Params
params

Record Component accessed by params().

private final PublicKey
pkR

Record Component accessed by pkR().

private final PublicKey
pkS

Record Component accessed by pkS().

private final SecureRandom
secureRandom

Record Component accessed by secureRandom().

private final PrivateKey
skR

Record Component accessed by skR().

private final PrivateKey
skS

Record Component accessed by skS().

Constructor Summary

AccessConstructor and Description
private
Handler(DHKEM.Params params, SecureRandom secureRandom, PrivateKey skS, PublicKey pkS, PrivateKey skR, PublicKey pkR)

Method Summary

Modifier and TypeMethod and Description
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 DHKEM.Params
params()

Record Component getter of params.

public PublicKey
pkR()

Record Component getter of pkR.

public PublicKey
pkS()

Record Component getter of pkS.

public SecureRandom
secureRandom()

Record Component getter of secureRandom.

public PrivateKey
skR()

Record Component getter of skR.

public PrivateKey
skS()

Record Component getter of skS.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

paramsback to summary
private final DHKEM.Params params

Record Component accessed by params().

pkRback to summary
private final PublicKey pkR

Record Component accessed by pkR().

pkSback to summary
private final PublicKey pkS

Record Component accessed by pkS().

secureRandomback to summary
private final SecureRandom secureRandom

Record Component accessed by secureRandom().

skRback to summary
private final PrivateKey skR

Record Component accessed by skR().

skSback to summary
private final PrivateKey skS

Record Component accessed by skS().

Constructor Detail

Handlerback to summary
private Handler(DHKEM.Params params, SecureRandom secureRandom, PrivateKey skS, PublicKey pkS, PrivateKey skR, PublicKey pkR)

Method Detail

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.

paramsback to summary
public DHKEM.Params params()

Record Component getter of params.

pkRback to summary
public PublicKey pkR()

Record Component getter of pkR.

pkSback to summary
public PublicKey pkS()

Record Component getter of pkS.

secureRandomback to summary
public SecureRandom secureRandom()

Record Component getter of secureRandom.

skRback to summary
public PrivateKey skR()

Record Component getter of skR.

skSback to summary
public PrivateKey skS()

Record Component getter of skS.

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.

com.sun.crypto.provider back to summary

private final Enum DHKEM.Params

extends Enum<DHKEM.Params>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final int
private final String
private final int
private final int
private final int
public static final DHKEM.Params
public static final DHKEM.Params
public static final DHKEM.Params
private final AlgorithmParameterSpec
private final byte[]
public static final DHKEM.Params
public static final DHKEM.Params

Constructor Summary

AccessConstructor and Description
private
Params(int kem_id, int nsecret, int nsk, int npk, String kaAlgorithm, String keyAlgorithm, AlgorithmParameterSpec spec, String hkdfAlgorithm)

Method Summary

Modifier and TypeMethod and Description
private SecretKey
deriveKey(String alg, int from, int to, byte[] kem_context, SecretKey... dhs)

public KeyPair
deriveKeyPair(byte[] ikm)

private PrivateKey
deserializePrivateKey(byte[] data)

private PublicKey
deserializePublicKey(byte[] data)

private SecretKey
private SecretKey
extractAndExpand(byte[] kem_context, String alg, SecretKey... dhs)

private KeyPair
private PublicKey
private boolean
isEC()

private byte[]
public static DHKEM.Params
public static DHKEM.Params[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

hkdfAlgorithmback to summary
private final String hkdfAlgorithm
kaAlgorithmback to summary
private final String kaAlgorithm
kem_idback to summary
private final int kem_id
keyAlgorithmback to summary
private final String keyAlgorithm
npkback to summary
private final int npk
nsecretback to summary
private final int nsecret
nskback to summary
private final int nsk
P256back to summary
public static final DHKEM.Params P256
P384back to summary
public static final DHKEM.Params P384
P521back to summary
public static final DHKEM.Params P521
specback to summary
private final AlgorithmParameterSpec spec
suiteIdback to summary
private final byte[] suiteId
X25519back to summary
public static final DHKEM.Params X25519
X448back to summary
public static final DHKEM.Params X448

Constructor Detail

Paramsback to summary
private Params(int kem_id, int nsecret, int nsk, int npk, String kaAlgorithm, String keyAlgorithm, AlgorithmParameterSpec spec, String hkdfAlgorithm)

Method Detail

deriveKeyback to summary
private SecretKey deriveKey(String alg, int from, int to, byte[] kem_context, SecretKey... dhs) throws NoSuchAlgorithmException
deriveKeyPairback to summary
public KeyPair deriveKeyPair(byte[] ikm) throws Exception
deserializePrivateKeyback to summary
private PrivateKey deserializePrivateKey(byte[] data) throws Exception
deserializePublicKeyback to summary
private PublicKey deserializePublicKey(byte[] data) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException
dhback to summary
private SecretKey dh(PrivateKey skE, PublicKey pkR) throws NoSuchAlgorithmException, InvalidKeyException
extractAndExpandback to summary
private SecretKey extractAndExpand(byte[] kem_context, String alg, SecretKey... dhs) throws NoSuchAlgorithmException
generateKeyPairback to summary
private KeyPair generateKeyPair(SecureRandom sr)
getPublicKeyback to summary
private PublicKey getPublicKey(PrivateKey sk) throws InvalidKeyException
isECback to summary
private boolean isEC()
serializePublicKeyback to summary
private byte[] serializePublicKey(PublicKey k)
valueOfback to summary
public static DHKEM.Params valueOf(String name)
valuesback to summary
public static DHKEM.Params[] values()
com.sun.crypto.provider back to summary

public Class DHKEM.RFC9180DeriveKeyPairSR

extends SecureRandom
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final byte[]
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private KeyPair
public KeyPair
derive(int kem_id)

Inherited from java.security.SecureRandom:
generateSeedgetAlgorithmgetInstancegetInstancegetInstancegetInstancegetInstancegetInstancegetInstanceStronggetParametersgetProvidergetSeednextnextBytesnextBytesnextLongreseedreseedsetSeedsetSeedtoString

Field Detail

ikmback to summary
private final byte[] ikm
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.security.SecureRandom.serialVersionUID.

Annotations
@Serial

Constructor Detail

RFC9180DeriveKeyPairSRback to summary
public RFC9180DeriveKeyPairSR(byte[] ikm)

Method Detail

deriveback to summary
private KeyPair derive(DHKEM.Params params)
deriveback to summary
public KeyPair derive(int kem_id)