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

public Class HPKE

extends CipherSpi
Class Inheritance
Imports
sun.security.util.CurveDB, .ECUtil, javax.crypto.BadPaddingException, .Cipher, .CipherSpi, .DecapsulateException, .IllegalBlockSizeException, .KDF, .KEM, .NoSuchPaddingException, .SecretKey, .ShortBufferException, javax.crypto.spec.GCMParameterSpec, .HPKEParameterSpec, .IvParameterSpec, java.io.ByteArrayOutputStream, java.nio.ByteBuffer, java.security.AlgorithmParameters, .AsymmetricKey, .InvalidAlgorithmParameterException, .InvalidKeyException, .Key, .NoSuchAlgorithmException, .PrivateKey, .ProviderException, .PublicKey, .SecureRandom, java.security.spec.AlgorithmParameterSpec, .ECParameterSpec, .NamedParameterSpec, java.util.Arrays

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final byte[]
private static final int
private static final int
private static final byte[]
private static final int
private static final byte[]
private HPKE.Impl
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private int

Constructor Summary

AccessConstructor and Description
public
HPKE()

Method Summary

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

protected byte[]
engineDoFinal(byte[] input, int inputOffset, int inputLen)

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.

protected int
engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.

protected byte[]
engineExportData(byte[] context, int length)

protected SecretKey
engineExportKey(String algorithm, byte[] context, int length)

protected int
engineGetBlockSize()

Implements abstract javax.crypto.CipherSpi.engineGetBlockSize.

Returns the block size (in bytes).

protected byte[]
engineGetIV()

Implements abstract javax.crypto.CipherSpi.engineGetIV.

Returns the initialization vector (IV) in a new buffer.

protected int
engineGetOutputSize(int inputLen)

Implements abstract javax.crypto.CipherSpi.engineGetOutputSize.

Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).

protected AlgorithmParameters
engineGetParameters()

Implements abstract javax.crypto.CipherSpi.engineGetParameters.

Returns the parameters used with this cipher.

protected void
engineInit(int opmode, Key key, SecureRandom random)

Implements abstract javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key and a source of randomness.

protected void
engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random)

Implements abstract javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key, a set of algorithm parameters, and a source of randomness.

protected void
engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random)

Implements abstract javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key, a set of algorithm parameters, and a source of randomness.

protected void
engineSetMode(String mode)

Implements abstract javax.crypto.CipherSpi.engineSetMode.

Sets the mode of this cipher.

protected void
engineSetPadding(String padding)

Implements abstract javax.crypto.CipherSpi.engineSetPadding.

Sets the padding mechanism of this cipher.

protected byte[]
engineUpdate(byte[] input, int inputOffset, int inputLen)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

Continues a multiple-part encryption or decryption operation (depending on how this CipherSpi object was initialized), processing another data part.

protected int
engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

Continues a multiple-part encryption or decryption operation (depending on how this CipherSpi object was initialized), processing another data part.

protected void
engineUpdateAAD(byte[] src, int offset, int len)

Overrides javax.crypto.CipherSpi.engineUpdateAAD.

Continues a multipart update of the Additional Authentication Data (AAD), using a subset of the provided buffer.

protected void
engineUpdateAAD(ByteBuffer src)

Overrides javax.crypto.CipherSpi.engineUpdateAAD.

Continues a multipart update of the Additional Authentication Data (AAD).

private void
private static boolean
Inherited from javax.crypto.CipherSpi:
engineDoFinalengineGetKeySizeengineUnwrapengineUpdateengineWrap

Field Detail

AFTER_FINALback to summary
private static final int AFTER_FINAL
BASE_NONCEback to summary
private static final byte[] BASE_NONCE
BEGINback to summary
private static final int BEGIN
ENCRYPT_AND_EXPORTback to summary
private static final int ENCRYPT_AND_EXPORT
EXPback to summary
private static final byte[] EXP
EXPORT_ONLYback to summary
private static final int EXPORT_ONLY
HPKEback to summary
private static final byte[] HPKE
implback to summary
private HPKE.Impl impl
INFO_HASHback to summary
private static final byte[] INFO_HASH
KEYback to summary
private static final byte[] KEY
PSK_ID_HASHback to summary
private static final byte[] PSK_ID_HASH
SECback to summary
private static final byte[] SEC
SECRETback to summary
private static final byte[] SECRET
stateback to summary
private int state

Constructor Detail

HPKEback to summary
public HPKE()

Method Detail

concatback to summary
private static byte[] concat(byte[]... inputs)
engineDoFinalback to summary
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

Doc from javax.crypto.CipherSpi.engineDoFinal.

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this CipherSpi object was initialized.

The first inputLen bytes in the input buffer, starting at inputOffset inclusive, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. If an AEAD mode (such as GCM or CCM) is being used, the authentication tag is appended in the case of encryption, or verified in the case of decryption. The result is stored in a new buffer.

Upon finishing, this method resets this CipherSpi object to the state it was in when previously initialized via a call to engineInit. That is, the object is reset and available to encrypt or decrypt (depending on the operation mode that was specified in the call to engineInit) more data.

Note

if any exception is thrown, this CipherSpi object may need to be reset before it can be used again.

Annotations
@Override
Exceptions
IllegalBlockSizeException:
if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided
BadPaddingException:
if this CipherSpi object is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes
engineDoFinalback to summary
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

Doc from javax.crypto.CipherSpi.engineDoFinal.

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this CipherSpi object was initialized.

The first inputLen bytes in the input buffer, starting at inputOffset inclusive, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. If an AEAD mode such as GCM or CCM is being used, the authentication tag is appended in the case of encryption, or verified in the case of decryption. The result is stored in the output buffer, starting at outputOffset inclusive.

If the output buffer is too small to hold the result, a ShortBufferException is thrown.

Upon finishing, this method resets this CipherSpi object to the state it was in when previously initialized via a call to engineInit. That is, the object is reset and available to encrypt or decrypt (depending on the operation mode that was specified in the call to engineInit) more data.

Note

if any exception is thrown, this CipherSpi object may need to be reset before it can be used again.

Annotations
@Override
Exceptions
ShortBufferException:
if the given output buffer is too small to hold the result
IllegalBlockSizeException:
if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided
BadPaddingException:
if this CipherSpi object is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes
engineExportDataback to summary
protected byte[] engineExportData(byte[] context, int length)
engineExportKeyback to summary
protected SecretKey engineExportKey(String algorithm, byte[] context, int length)
engineGetBlockSizeback to summary
protected int engineGetBlockSize()

Implements abstract javax.crypto.CipherSpi.engineGetBlockSize.

Doc from javax.crypto.CipherSpi.engineGetBlockSize.

Returns the block size (in bytes).

Annotations
@Override
engineGetIVback to summary
protected byte[] engineGetIV()

Implements abstract javax.crypto.CipherSpi.engineGetIV.

Doc from javax.crypto.CipherSpi.engineGetIV.

Returns the initialization vector (IV) in a new buffer.

This is useful in the context of password-based encryption or decryption, where the IV is derived from a user-provided passphrase.

Annotations
@Override
engineGetOutputSizeback to summary
protected int engineGetOutputSize(int inputLen)

Implements abstract javax.crypto.CipherSpi.engineGetOutputSize.

Doc from javax.crypto.CipherSpi.engineGetOutputSize.

Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).

This call takes into account any unprocessed (buffered) data from a previous update call, padding, and AEAD tagging.

The actual output length of the next update or doFinal call may be smaller than the length returned by this method.

Annotations
@Override
engineGetParametersback to summary
protected AlgorithmParameters engineGetParameters()

Implements abstract javax.crypto.CipherSpi.engineGetParameters.

Doc from javax.crypto.CipherSpi.engineGetParameters.

Returns the parameters used with this cipher.

The returned parameters may be the same that were used to initialize this cipher, or may contain additional default or random parameter values used by the underlying cipher implementation. If the required parameters were not supplied and can be generated by the cipher, the generated parameters are returned. Otherwise, null is returned.

Annotations
@Override
engineInitback to summary
protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException

Implements abstract javax.crypto.CipherSpi.engineInit.

Doc from javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key and a source of randomness.

The CipherSpi object is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters that cannot be derived from the given key, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidKeyException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a CipherSpi object is initialized, it loses all previously-acquired state. In other words, initializing a CipherSpi object is equivalent to creating a new instance of that CipherSpi object and initializing it.

Annotations
@Override
Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher, or requires algorithm parameters that cannot be determined from the given key
engineInitback to summary
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.CipherSpi.engineInit.

Doc from javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key, a set of algorithm parameters, and a source of randomness.

The CipherSpi object is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a CipherSpi object is initialized, it loses all previously-acquired state. In other words, initializing a CipherSpi object is equivalent to creating a new instance of that CipherSpi object and initializing it.

Annotations
@Override
Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher, or if this cipher requires algorithm parameters and params is null
engineInitback to summary
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.CipherSpi.engineInit.

Doc from javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key, a set of algorithm parameters, and a source of randomness.

The CipherSpi object is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a CipherSpi object is initialized, it loses all previously-acquired state. In other words, initializing a CipherSpi object is equivalent to creating a new instance of that CipherSpi object and initializing it.

Annotations
@Override
Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher, or if this cipher requires algorithm parameters and params is null
engineSetModeback to summary
protected void engineSetMode(String mode) throws NoSuchAlgorithmException

Implements abstract javax.crypto.CipherSpi.engineSetMode.

Doc from javax.crypto.CipherSpi.engineSetMode.

Sets the mode of this cipher.

Annotations
@Override
Exceptions
NoSuchAlgorithmException:
if the requested cipher mode does not exist
engineSetPaddingback to summary
protected void engineSetPadding(String padding) throws NoSuchPaddingException

Implements abstract javax.crypto.CipherSpi.engineSetPadding.

Doc from javax.crypto.CipherSpi.engineSetPadding.

Sets the padding mechanism of this cipher.

Annotations
@Override
Exceptions
NoSuchPaddingException:
if the requested padding mechanism does not exist
engineUpdateback to summary
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

Doc from javax.crypto.CipherSpi.engineUpdate.

Continues a multiple-part encryption or decryption operation (depending on how this CipherSpi object was initialized), processing another data part.

The first inputLen bytes in the input buffer, starting at inputOffset inclusive, are processed, and the result is stored in a new buffer.

Annotations
@Override
engineUpdateback to summary
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException

Implements abstract javax.crypto.CipherSpi.engineUpdate.

Doc from javax.crypto.CipherSpi.engineUpdate.

Continues a multiple-part encryption or decryption operation (depending on how this CipherSpi object was initialized), processing another data part.

The first inputLen bytes in the input buffer, starting at inputOffset inclusive, are processed, and the result is stored in the output buffer, starting at outputOffset inclusive.

If the output buffer is too small to hold the result, a ShortBufferException is thrown.

Annotations
@Override
Exceptions
ShortBufferException:
if the given output buffer is too small to hold the result
engineUpdateAADback to summary
protected void engineUpdateAAD(byte[] src, int offset, int len)

Overrides javax.crypto.CipherSpi.engineUpdateAAD.

Doc from javax.crypto.CipherSpi.engineUpdateAAD.

Continues a multipart update of the Additional Authentication Data (AAD), using a subset of the provided buffer.

Calls to this method provide AAD to the cipher when operating in modes such as AEAD (GCM or CCM). If this cipher is operating in either GCM or CCM mode, all AAD must be supplied before beginning operations on the ciphertext (via the update and doFinal methods).

Annotations
@Override
engineUpdateAADback to summary
protected void engineUpdateAAD(ByteBuffer src)

Overrides javax.crypto.CipherSpi.engineUpdateAAD.

Doc from javax.crypto.CipherSpi.engineUpdateAAD.

Continues a multipart update of the Additional Authentication Data (AAD).

Calls to this method provide AAD to the cipher when operating in modes such as AEAD (GCM or CCM). If this cipher is operating in either GCM or CCM mode, all AAD must be supplied before beginning operations on the ciphertext (via the update and doFinal methods).

All src.remaining() bytes starting at src.position() are processed. Upon return, the input buffer's position will be equal to its limit; its limit will not have changed.

Annotations
@Override
maybeReinitInternalCipherback to summary
private void maybeReinitInternalCipher()
usePSKback to summary
private static boolean usePSK(SecretKey psk)
com.sun.crypto.provider back to summary

private Class HPKE.AEAD

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Cipher
pack-priv final int
pack-priv final int
pack-priv final int
pack-priv final int

Constructor Summary

AccessConstructor and Description
public
AEAD(int id)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
start(int opmode, SecretKey key, byte[] nonce)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cipherback to summary
pack-priv final Cipher cipher
idback to summary
pack-priv final int id
nkback to summary
pack-priv final int nk
nnback to summary
pack-priv final int nn
ntback to summary
pack-priv final int nt

Constructor Detail

AEADback to summary
public AEAD(int id) throws InvalidAlgorithmParameterException

Method Detail

startback to summary
pack-priv void start(int opmode, SecretKey key, byte[] nonce)
com.sun.crypto.provider back to summary

private Class HPKE.Impl

extends Object
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
pack-priv HPKE.AEAD
pack-priv HPKE.Impl.Context
pack-priv String
pack-priv int
pack-priv byte[]
pack-priv final int
pack-priv HPKEParameterSpec
pack-priv byte[]

Constructor Summary

AccessConstructor and Description
public
Impl(int opmode)

Method Summary

Modifier and TypeMethod and Description
private static void
checkMatch(boolean inSpec, AsymmetricKey k, int kem_id)

public boolean
public void
private KEM
kem()

private HPKE.Impl.Context
keySchedule(int mode, SecretKey shared_secret, byte[] info, SecretKey psk, byte[] psk_id)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aeadback to summary
pack-priv HPKE.AEAD aead
contextback to summary
pack-priv HPKE.Impl.Context context
kdfAlgback to summary
pack-priv String kdfAlg
kdfNhback to summary
pack-priv int kdfNh
kemEncapsback to summary
pack-priv byte[] kemEncaps
opmodeback to summary
pack-priv final int opmode
paramsback to summary
pack-priv HPKEParameterSpec params
suite_idback to summary
pack-priv byte[] suite_id

Constructor Detail

Implback to summary
public Impl(int opmode)

Method Detail

checkMatchback to summary
private static void checkMatch(boolean inSpec, AsymmetricKey k, int kem_id) throws InvalidKeyException, InvalidAlgorithmParameterException
hasEncryptback to summary
public boolean hasEncrypt()
initback to summary
public void init(AsymmetricKey key, HPKEParameterSpec p, SecureRandom rand) throws InvalidKeyException, InvalidAlgorithmParameterException
kemback to summary
private KEM kem()
keyScheduleback to summary
private HPKE.Impl.Context keySchedule(int mode, SecretKey shared_secret, byte[] info, SecretKey psk, byte[] psk_id)
setParamsback to summary
private void setParams(HPKEParameterSpec p) throws InvalidAlgorithmParameterException
com.sun.crypto.provider back to summary

pack-priv Class HPKE.Impl.Context

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final byte[]
pack-priv final SecretKey
pack-priv final SecretKey
k

pack-priv byte[]

Constructor Summary

AccessConstructor and Description
public
Context(SecretKey sk, byte[] base_nonce, SecretKey exporter_secret)

Method Summary

Modifier and TypeMethod and Description
private byte[]
pack-priv byte[]
exportData(byte[] exporter_context, int length)

pack-priv SecretKey
exportKey(String algorithm, byte[] exporter_context, int length)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

base_nonceback to summary
pack-priv final byte[] base_nonce
exporter_secretback to summary
pack-priv final SecretKey exporter_secret
kback to summary
pack-priv final SecretKey k
seqback to summary
pack-priv byte[] seq

Constructor Detail

Contextback to summary
public Context(SecretKey sk, byte[] base_nonce, SecretKey exporter_secret)

Method Detail

computeNonceback to summary
private byte[] computeNonce()
exportDataback to summary
pack-priv byte[] exportData(byte[] exporter_context, int length)
exportKeyback to summary
pack-priv SecretKey exportKey(String algorithm, byte[] exporter_context, int length)
IncrementSeqback to summary
private void IncrementSeq()