It should be noted that the specified limit of 236 bytes is not supported. This is because all bytes are cached in a ByteArrayOutputStream object (which has a limit of a little less than 231 bytes), and are output on the doFinal() call (which can only process a maximum of 231 bytes).
The practical limit of 231 - 24 bytes is policed, and attempts to breach the limit will be rejected
In order to properly support the higher limit, an extended form of ByteArrayOutputStream would be needed which would use multiple arrays to store the data. In addition, a new doOutput method would be required (similar to that in XOF digests), which would allow the data to be output over multiple calls. Alternatively an extended form of ByteArrayInputStream could be used to deliver the data.
| Modifier and Type | Class and Description |
|---|---|
| private static class | GCMSIVBlockCipher.GCMSIVCache
GCMSIVCache. |
| private class | GCMSIVBlockCipher.GCMSIVHasher
Hash Control. |
| Modifier and Type | Field and Description |
|---|---|
| private static final byte | ADD
The addition constant. |
| private static final int | AEAD_COMPLETE
The aeadComplete flag. |
| private static final int | BUFLEN
The buffer length. |
| private boolean | forEncryption
Are we encrypting? |
| private static final int | HALFBUFLEN
The halfBuffer length. |
| private static final int | INIT
The initialisation flag. |
| private byte[] | |
| private static final byte | MASK
The top bit mask. |
| private static final int | MAX_DATALEN
The maximum data length (AEAD/PlainText). |
| private static final int | NONCELEN
The nonce length. |
| private final GCMSIVBlockCipher. | theAEADHasher
The aeadHasher. |
| private final BlockCipher | theCipher
The cipher. |
| private final GCMSIVBlockCipher. | theDataHasher
The dataHasher. |
| private GCMSIVBlockCipher. | theEncData
The encryptedDataStream (decryption only). |
| private int | theFlags
The flags. |
| private final byte[] | theGHash
The gHash buffer. |
| private byte[] | theInitialAEAD
The initialAEAD. |
| private final GCMMultiplier | theMultiplier
The multiplier. |
| private byte[] | theNonce
The nonce. |
| private GCMSIVBlockCipher. | thePlain
The plainDataStream. |
| private final byte[] | theReverse
The reverse buffer. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | GCMSIVBlockCipher(final BlockCipher
the underlying cipher pCipher, final GCMMultiplier the multiplier pMultiplier)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| private static int | Returns: the lengththe buffere pBuffer)Obtain buffer length (allowing for null). |
| private byte[] | |
| private void | |
| private static void | checkBuffer(final byte[]
the buffer pBuffer, final int the offset pOffset, final int the length pLen, final boolean is this an output buffer? pOutput)Check buffer. |
| private void | |
| private byte[] | |
| private void | |
| private void | |
| public int | doFinal(final byte[]
space for any resulting output data. pOutput, final int offset into out to start copying the data at. pOffset)Implements org. |
| private int | Returns: the length of data encryptedthe counter pCounter, final byte[] the target buffer pTarget, final int the target offset pOffset)encrypt data stream. |
| private static void | fillReverse(final byte[]
the input buffer pInput, final int the offset pOffset, final int the length of data (<= BUFLEN) pLength, final byte[] the output buffer pOutput)Byte reverse a buffer. |
| public String | getAlgorithmName()
Implements org. |
| public byte[] | getMac()
Implements org. |
| public int | getOutputSize(final int
the length of the input. pLen)Implements org. |
| public BlockCipher | getUnderlyingCipher()
Implements org. BlockCipher this object wraps.
|
| public int | getUpdateOutputSize(final int
the length of the input. pLen)Implements org. |
| private void | |
| private void | |
| private static void | |
| public void | init(final boolean
true if we are setting up for encryption, false otherwise. pEncrypt, final CipherParameters the necessary parameters for the underlying cipher to be initialised. cipherParameters)Implements org. |
| private static void | |
| public void | processAADByte(final byte
the byte to be processed. pByte)Implements org. |
| public void | processAADBytes(final byte[]
the input byte array. pData, final int the offset into the in array where the data to be processed starts. pOffset, final int the number of bytes to be processed. pLen)Implements org. |
| public int | processByte(final byte
the byte to be processed. pByte, final byte[] the output buffer the processed byte goes into. pOutput, final int the offset into the output byte array the processed data starts at. pOutOffset)Implements org. |
| public int | processBytes(final byte[]
the input byte array. pData, final int the offset into the in array where the data to be processed starts. pOffset, final int the number of bytes to be processed. pLen, final byte[] the output buffer the processed bytes go into. pOutput, final int the offset into the output byte array the processed data starts at. pOutOffset)Implements org. |
| public void | |
| private void | |
| private static void | xorBlock(final byte[]
the left operand and result pLeft, final byte[] the right operand pRight)xor a full block buffer. |
| private static void | xorBlock(final byte[]
the left operand and result pLeft, final byte[] the right operand pRight, final int the offset in the right operand pOffset, final int the length of data in the right operand pLength)xor a partial block buffer. |
| ADD | back to summary |
|---|---|
| private static final byte ADD The addition constant. | |
| AEAD_COMPLETE | back to summary |
|---|---|
| private static final int AEAD_COMPLETE The aeadComplete flag. | |
| BUFLEN | back to summary |
|---|---|
| private static final int BUFLEN The buffer length. | |
| forEncryption | back to summary |
|---|---|
| private boolean forEncryption Are we encrypting? | |
| HALFBUFLEN | back to summary |
|---|---|
| private static final int HALFBUFLEN The halfBuffer length. | |
| INIT | back to summary |
|---|---|
| private static final int INIT The initialisation flag. | |
| macBlock | back to summary |
|---|---|
| private byte[] macBlock | |
| MASK | back to summary |
|---|---|
| private static final byte MASK The top bit mask. | |
| MAX_DATALEN | back to summary |
|---|---|
| private static final int MAX_DATALEN The maximum data length (AEAD/PlainText). Due to implementation constraints this is restricted to the maximum array length (https://programming.guide/java/array-maximum-length.html) minus the BUFLEN to allow for the MAC | |
| NONCELEN | back to summary |
|---|---|
| private static final int NONCELEN The nonce length. | |
| theAEADHasher | back to summary |
|---|---|
| private final GCMSIVBlockCipher. The aeadHasher. | |
| theCipher | back to summary |
|---|---|
| private final BlockCipher theCipher The cipher. | |
| theDataHasher | back to summary |
|---|---|
| private final GCMSIVBlockCipher. The dataHasher. | |
| theEncData | back to summary |
|---|---|
| private GCMSIVBlockCipher. The encryptedDataStream (decryption only). | |
| theFlags | back to summary |
|---|---|
| private int theFlags The flags. | |
| theGHash | back to summary |
|---|---|
| private final byte[] theGHash The gHash buffer. | |
| theInitialAEAD | back to summary |
|---|---|
| private byte[] theInitialAEAD The initialAEAD. | |
| theMultiplier | back to summary |
|---|---|
| private final GCMMultiplier theMultiplier The multiplier. | |
| theNonce | back to summary |
|---|---|
| private byte[] theNonce The nonce. | |
| thePlain | back to summary |
|---|---|
| private GCMSIVBlockCipher. The plainDataStream. | |
| theReverse | back to summary |
|---|---|
| private final byte[] theReverse The reverse buffer. | |
| GCMSIVBlockCipher | back to summary |
|---|---|
| public GCMSIVBlockCipher() Constructor. | |
| GCMSIVBlockCipher | back to summary |
|---|---|
| public GCMSIVBlockCipher(final BlockCipher pCipher) Constructor.
| |
| GCMSIVBlockCipher | back to summary |
|---|---|
| public GCMSIVBlockCipher(final BlockCipher pCipher, final GCMMultiplier pMultiplier) Constructor.
| |
| bufLength | back to summary |
|---|---|
| private static int bufLength(final byte[] pBuffer) Obtain buffer length (allowing for null).
| |
| calculateTag | back to summary |
|---|---|
| private byte[] calculateTag() calculate tag.
| |
| checkAEADStatus | back to summary |
|---|---|
| private void checkAEADStatus(final int pLen) check AEAD status.
| |
| checkBuffer | back to summary |
|---|---|
| private static void checkBuffer(final byte[] pBuffer, final int pOffset, final int pLen, final boolean pOutput) Check buffer.
| |
| checkStatus | back to summary |
|---|---|
| private void checkStatus(final int pLen) check status.
| |
| completePolyVal | back to summary |
|---|---|
| private byte[] completePolyVal() complete polyVAL.
| |
| decryptPlain | back to summary |
|---|---|
| private void decryptPlain() throws InvalidCipherTextException decrypt data stream.
| |
| deriveKeys | back to summary |
|---|---|
| private void deriveKeys(final KeyParameter pKey) Derive Keys.
| |
| doFinal | back to summary |
|---|---|
| public int doFinal(final byte[] pOutput, final int pOffset) throws IllegalStateException, InvalidCipherTextException Implements org. Doc from org. Finish the operation either appending or verifying the MAC at the end of the data.
| |
| encryptPlain | back to summary |
|---|---|
| private int encryptPlain(final byte[] pCounter, final byte[] pTarget, final int pOffset) encrypt data stream.
| |
| fillReverse | back to summary |
|---|---|
| private static void fillReverse(final byte[] pInput, final int pOffset, final int pLength, final byte[] pOutput) Byte reverse a buffer.
| |
| getAlgorithmName | back to summary |
|---|---|
| public String getAlgorithmName() Implements org. Doc from org. Return the name of the algorithm.
| |
| getMac | back to summary |
|---|---|
| public byte[] getMac() Implements org. Doc from org. Return the value of the MAC associated with the last stream processed.
| |
| getOutputSize | back to summary |
|---|---|
| public int getOutputSize(final int pLen) Implements org. Doc from org. return the size of the output buffer required for a processBytes plus a doFinal with an input of len bytes.
The returned size may be dependent on the initialisation of this cipher
and may not be accurate once subsequent input data is processed - this method
should be invoked immediately prior to a call to final processing of input data
and a call to
| |
| getUnderlyingCipher | back to summary |
|---|---|
| public BlockCipher getUnderlyingCipher() Implements org. Doc from org. return the
| |
| getUpdateOutputSize | back to summary |
|---|---|
| public int getUpdateOutputSize(final int pLen) Implements org. Doc from org. return the size of the output buffer required for a processBytes an input of len bytes. The returned size may be dependent on the initialisation of this cipher and may not be accurate once subsequent input data is processed - this method should be invoked immediately prior to input data being processed.
| |
| gHASH | back to summary |
|---|---|
| private void gHASH(final byte[] pNext) perform the next GHASH step.
| |
| gHashLengths | back to summary |
|---|---|
| private void gHashLengths() process lengths. | |
| incrementCounter | back to summary |
|---|---|
| private static void incrementCounter(final byte[] pCounter) increment the counter.
| |
| init | back to summary |
|---|---|
| public void init(final boolean pEncrypt, final CipherParameters cipherParameters) throws IllegalArgumentException Implements org. Doc from org. initialise the underlying cipher. Parameter can either be an AEADParameters or a ParametersWithIV object.
| |
| mulX | back to summary |
|---|---|
| private static void mulX(final byte[] pValue) multiply by X.
| |
| processAADByte | back to summary |
|---|---|
| public void processAADByte(final byte pByte) Implements org. Doc from org. Add a single byte to the associated data check.
| |
| processAADBytes | back to summary |
|---|---|
| public void processAADBytes(final byte[] pData, final int pOffset, final int pLen) Implements org. Doc from org. Add a sequence of bytes to the associated data check.
| |
| processByte | back to summary |
|---|---|
| public int processByte(final byte pByte, final byte[] pOutput, final int pOutOffset) throws DataLengthException Implements org. Doc from org. encrypt/decrypt a single byte.
| |
| processBytes | back to summary |
|---|---|
| public int processBytes(final byte[] pData, final int pOffset, final int pLen, final byte[] pOutput, final int pOutOffset) throws DataLengthException Implements org. Doc from org. process a block of bytes from in putting the result into out.
| |
| reset | back to summary |
|---|---|
| public void reset() Implements org. Doc from org. Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one). | |
| resetStreams | back to summary |
|---|---|
| private void resetStreams() Reset Streams. | |
| xorBlock | back to summary |
|---|---|
| private static void xorBlock(final byte[] pLeft, final byte[] pRight) xor a full block buffer.
| |
| xorBlock | back to summary |
|---|---|
| private static void xorBlock(final byte[] pLeft, final byte[] pRight, final int pOffset, final int pLength) xor a partial block buffer.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv byte[] |
| GCMSIVCache | back to summary |
|---|---|
| pack-priv GCMSIVCache() Constructor. | |
| clearBuffer | back to summary |
|---|---|
| pack-priv void clearBuffer() Clear the buffer. | |
| getBuffer | back to summary |
|---|---|
| pack-priv byte[] getBuffer() Obtain the buffer.
| |
| Modifier and Type | Field and Description |
|---|---|
| private int | numActive
Count of active bytes in cache. |
| private long | numHashed
Count of hashed bytes. |
| private final byte[] | theBuffer
Cache. |
| private final byte[] | theByte
Single byte cache. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv long | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | updateHash(final byte[]
the buffer pBuffer, final int the offset within the buffer pOffset, final int the length of data pLen)update hash. |
| numActive | back to summary |
|---|---|
| private int numActive Count of active bytes in cache. | |
| numHashed | back to summary |
|---|---|
| private long numHashed Count of hashed bytes. | |
| theBuffer | back to summary |
|---|---|
| private final byte[] theBuffer Cache. | |
| theByte | back to summary |
|---|---|
| private final byte[] theByte Single byte cache. | |
| GCMSIVHasher | back to summary |
|---|---|
| private GCMSIVHasher() | |
| completeHash | back to summary |
|---|---|
| pack-priv void completeHash() complete hash. | |
| getBytesProcessed | back to summary |
|---|---|
| pack-priv long getBytesProcessed() Obtain the count of bytes hashed.
| |
| reset | back to summary |
|---|---|
| pack-priv void reset() Reset the hasher. | |
| updateHash | back to summary |
|---|---|
| pack-priv void updateHash(final byte pByte) update hash.
| |
| updateHash | back to summary |
|---|---|
| pack-priv void updateHash(final byte[] pBuffer, final int pOffset, final int pLen) update hash.
| |