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

pack-priv abstract Class GaloisCounterMode

extends CipherSpi
Class Inheritance
Known Direct Subclasses
com.sun.crypto.provider.GaloisCounterMode.AESGCM, com.sun.crypto.provider.GaloisCounterMode.AES128, com.sun.crypto.provider.GaloisCounterMode.AES192, com.sun.crypto.provider.GaloisCounterMode.AES256
Imports
java.lang.invoke.MethodHandles, .VarHandle, java.nio.Buffer, .ByteBuffer, .ByteOrder, java.security.*, java.security.spec.AlgorithmParameterSpec, .InvalidParameterSpecException, java.util.Arrays, javax.crypto.*, javax.crypto.spec.GCMParameterSpec, jdk.internal.access.JavaNioAccess, .SharedSecrets, jdk.internal.misc.Unsafe, jdk.internal.vm.annotation.IntrinsicCandidate, sun.nio.ch.DirectBuffer, sun.security.jca.JCAUtil, sun.security.util.ArrayUtil

This class represents ciphers in GaloisCounter (GCM) mode.

This mode currently should only be used w/ AES cipher. Although no checking is done, caller should only pass AES Cipher to the constructor.

Note

Unlike other modes, when used for decryption, this class will buffer all processed outputs internally and won't return them until the tag has been successfully verified.

Since
1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
public static class
public static class
pack-priv static class
GaloisCounterMode.DecryptOp

This class is for decryption when both GCTR and GHASH can operation in parallel.

pack-priv static class
GaloisCounterMode.EncryptOp

This class is for encryption when both GCTR and GHASH can operation in parallel.

pack-priv class
GaloisCounterMode.GCMDecrypt

Decryption Engine object

pack-priv class
GaloisCounterMode.GCMEncrypt

Encryption Engine object

pack-priv abstract class
GaloisCounterMode.GCMEngine

Abstract class for GCMEncrypt and GCMDecrypt internal context objects

public static interface
GaloisCounterMode.GCMOperation

Interface to organize encryption and decryption operations in the proper order for GHASH and GCTR.

Field Summary

Modifier and TypeField and Description
pack-priv final SymmetricCipher
private static final int
private static final int
pack-priv static final byte[]
private boolean
private GaloisCounterMode.GCMEngine
private boolean
pack-priv byte[]
private final int
pack-priv byte[]
pack-priv byte[]
private static final int
private static final JavaNioAccess
private static final int
pack-priv SecureRandom
pack-priv boolean
private static final int
pack-priv int
private static final int
private static final VarHandle

Constructor Summary

AccessConstructor and Description
pack-priv
GaloisCounterMode(int
length of key.
keySize
,
SymmetricCipher
Cipher object, such as AES_Crypt.
embeddedCipher
)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
private static byte[]

Returns:

a 16-byte array containing the random nonce.
createIv
(SecureRandom
a SecureRandom object. If null is provided a new SecureRandom object will be instantiated.
rand
)

Create a random 16-byte iv.

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 int
engineDoFinal(ByteBuffer src, ByteBuffer dst)

Overrides javax.crypto.CipherSpi.engineDoFinal.

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

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
engineGetKeySize(Key key)

Overrides javax.crypto.CipherSpi.engineGetKeySize.

Returns the key size of the given key object in bits.

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 Key
engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType)

Overrides javax.crypto.CipherSpi.engineUnwrap.

Unwrap a previously wrapped key.

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 int
engineUpdate(ByteBuffer src, ByteBuffer dst)

Overrides 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).

protected byte[]
private static byte[]
expandToOneBlock(byte[] in, int inOfs, int len, int blockSize)

private static byte[]
getJ0(byte[] iv, byte[] subkeyH, int blockSize)

private static byte[]
getLengthBlock(int ivLenInBytes)

private static byte[]
getLengthBlock(int aLenInBytes, int cLenInBytes)

private static int
implGCMCrypt(byte[] in, int inOfs, int inLen, byte[] ct, int ctOfs, byte[] out, int outOfs, GCTR gctr, GHASH ghash)

Wrapper function around Combined AES-GCM intrinsic method that splits large chunks of data into 1MB sized chunks.

private static int

Returns:

number of processed bytes
implGCMCrypt0
(byte[]
input buffer
in
,
int
input offset
inOfs
,
int
input length
inLen
,
byte[]
buffer that ghash will read (in for encrypt, out for decrypt)
ct
,
int
offset for ct buffer
ctOfs
,
byte[]
output buffer
out
,
int
output offset
outOfs
,
GCTR
object for the GCTR operation
gctr
,
GHASH
object for the GHASH operation
ghash
)

Intrinsic for the combined AES Galois Counter Mode implementation.

pack-priv static void
increment32(byte[] value)

pack-priv void
init(int opmode, Key key, GCMParameterSpec spec)

Initializes the cipher in the specified mode with the given key and iv.