final class GCMCipherLite extends CipherLite
CipherLite
Modifier and Type | Field and Description |
---|---|
private CipherLite |
aux
An auxiliary cipher that is used for re-processing purposes, or null if
no re-processing is in progress.
|
private long |
currentCount
The current number of bytes since the beginning of the plaintext that
have been re-encrypted and output so far.
|
private boolean |
doneFinal
True if doFinal has been called; false otherwise.
|
private byte[] |
finalBytes
The final bytes that has been computed, or null if it has not yet been
computed.
|
private boolean |
invisiblyProcessed
The last part of the plaintext has been processed by the GCM cipher but
not reflected in the
outputByteCount . |
private long |
markedCount
Used to mark the location where a reset can be made for re-processing
purposes.
|
private long |
outputByteCount
The total number of bytes (excluding the final tag) that has been output
by this cipher since the beginning of the input that have been processed
by the AES/GCM cipher.
|
private boolean |
securityViolated
True if a security exception has been thrown, which means this cipher
lite must no longer be used.
|
private static int |
TAG_LENGTH |
private int |
tagLen
Applicable only for encryption; set to zero otherwise.
|
Null
Constructor and Description |
---|
GCMCipherLite(javax.crypto.Cipher cipher,
javax.crypto.SecretKey secreteKey,
int cipherMode) |
Modifier and Type | Method and Description |
---|---|
private int |
checkMax(int delta)
Returns the input delta but only if it will not result in exceeding the
limit of the maximum number of bytes that can be processed by AES/GCM.
|
(package private) byte[] |
doFinal()
Finishes a multiple-part encryption or decryption operation, depending on
how the underlying cipher was initialized.
|
(package private) byte[] |
doFinal(byte[] input)
Encrypts or decrypts data in a single-part operation, or finishes a
multiple-part operation.
|
(package private) byte[] |
doFinal(byte[] input,
int inputOffset,
int inputLen)
Encrypts or decrypts data in a single-part operation, or finishes a
multiple-part operation.
|
private byte[] |
doFinal0(byte[] input,
int inputOffset,
int inputLen) |
(package private) long |
getCurrentCount()
For testing purposes.
|
(package private) byte[] |
getFinalBytes()
For testing purposes only.
|
(package private) long |
getMarkedCount()
For testing purposes.
|
(package private) long |
getOutputByteCount()
For testing purposes.
|
(package private) byte[] |
getTag()
For testing purposes.
|
(package private) long |
mark()
Marks the current position in this cipher lite.
|
(package private) boolean |
markSupported()
Tests if this cipher lite supports the
mark
and reset methods. |
(package private) void |
reset()
Repositions this cipher lite to the position at the time the
mark method was last called. |
(package private) byte[] |
update(byte[] input,
int inputOffset,
int inputLen)
Continues a multiple-part encryption or decryption operation (depending
on how the underlying cipher was initialized), processing another data
part.
|
createAuxiliary, createInverse, createUsingIV, getBlockSize, getCipher, getCipherAlgorithm, getCipherMode, getCipherProvider, getContentCryptoScheme, getIV, getOutputSize, getSecretKeyAlgorithm, recreate
private static final int TAG_LENGTH
private final int tagLen
private long outputByteCount
private boolean invisiblyProcessed
outputByteCount
.private long currentCount
currentCount
<
outputByteCount
, it means re-processing using AES/CTR is in
progress. If currentCount
== outputByteCount
, it means
it is not re-processing and therefore the AES/GCM cipher should be used.private long markedCount
private CipherLite aux
private byte[] finalBytes
private boolean doneFinal
private boolean securityViolated
GCMCipherLite(javax.crypto.Cipher cipher, javax.crypto.SecretKey secreteKey, int cipherMode)
byte[] doFinal() throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
CipherLite
Input data that may have been buffered during a previous
update
operation is processed, with padding (if requested)
being applied. If an AEAD mode such as GCM/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.
Note: if any exception is thrown, a new instance of this cipher lite object may need to be constructed before it can be used again. be reconstructed before it can be used again.
doFinal
in class CipherLite
javax.crypto.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.javax.crypto.BadPaddingException
- if this cipher is in decryption mode, and (un)padding has
been requested, but the decrypted data is not bounded by
the appropriate padding bytesfinal byte[] doFinal(byte[] input) throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
CipherLite
The bytes in the input
buffer, 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/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.
Note: if any exception is thrown, a new instance of this cipher lite object may need to be constructed before it can be used again.
doFinal
in class CipherLite
input
- the input bufferjavax.crypto.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.javax.crypto.BadPaddingException
- if this cipher is in decryption mode, and (un)padding has
been requested, but the decrypted data is not bounded by
the appropriate padding bytes; or if this cipher is
decrypting in an AEAD mode (such as GCM/CCM), and the
received authentication tag does not match the calculated
valuefinal byte[] doFinal(byte[] input, int inputOffset, int inputLen) throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
CipherLite
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/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.
Note: if any exception is thrown, a new instance of this cipher lite object may need to be constructed before it can be used again.
doFinal
in class CipherLite
input
- the input bufferinputOffset
- the offset in input
where the input startsinputLen
- the input lengthjavax.crypto.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.javax.crypto.BadPaddingException
- if this cipher is in decryption mode, and (un)padding has
been requested, but the decrypted data is not bounded by
the appropriate padding bytes; or if this cipher is
decrypting in an AEAD mode (such as GCM/CCM), and the
received authentication tag does not match the calculated
valueprivate final byte[] doFinal0(byte[] input, int inputOffset, int inputLen) throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
byte[] update(byte[] input, int inputOffset, int inputLen)
CipherLite
The first inputLen
bytes in the input
buffer,
starting at inputOffset
inclusive, are processed, and the
result is stored in a new buffer.
If inputLen
is zero, this method returns null
.
update
in class CipherLite
inputLen
- for mark()
and reset()
to work correctly,
inputLen should always be in multiple of 16 bytes except for
the very last part of the plaintext.input
- the input bufferinputOffset
- the offset in input
where the input startsprivate int checkMax(int delta)
java.lang.SecurityException
- if the number of bytes processed has exceeded the maximum
allowed by AES/GCM.long mark()
CipherLite
reset
method repositions this cipher lite at the last marked
position so that subsequent crypto operations will be logically performed
in an idempotent manner as if the cipher has been rewinded back to the
marked position.
The general contract of mark
is that, if the method
markSupported
returns true
, the cipher lite
somehow remembers the internal state after the call to mark
and stands ready to restore to the internal state so that it would be
able to produce the same output given the same input again if and
whenever the method reset
is called.
mark
in class CipherLite
boolean markSupported()
CipherLite
mark
and reset
methods. Returns false by default, but subclass
may override.markSupported
in class CipherLite
void reset()
CipherLite
mark
method was last called.
The general contract of reset
is:
markSupported
returns true
,
then the cipher lite is reset to the internal state since the most recent
call to mark
(or since the start of the input data, if
mark
has not been called), so that subsequent callers of the
udpate
or doFinal
method would produce the same
output given the same input data identical to the input data after the
mark
method was last called..markSupported
returns false
,
then the call to reset
may throw an
IllegalStateException
.reset
in class CipherLite
byte[] getFinalBytes()
byte[] getTag()
long getOutputByteCount()
long getCurrentCount()
long getMarkedCount()