Package org.apache.commons.crypto.cipher
Class OpenSslGaloisCounterMode
- java.lang.Object
-
- org.apache.commons.crypto.cipher.AbstractOpenSslFeedbackCipher
-
- org.apache.commons.crypto.cipher.OpenSslGaloisCounterMode
-
final class OpenSslGaloisCounterMode extends AbstractOpenSslFeedbackCipher
This class do the real work(Encryption/Decryption/Authentication) for the authenticated mode: GCM. It calls the OpenSSL API to implement the JCE-like behavior- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.ByteArrayOutputStream
aadBuffer
(package private) static int
DEFAULT_TAG_LEN
private java.io.ByteArrayOutputStream
inBuffer
private int
tagBitLen
-
Fields inherited from class org.apache.commons.crypto.cipher.AbstractOpenSslFeedbackCipher
algorithmMode, cipherMode, context, padding
-
-
Constructor Summary
Constructors Constructor Description OpenSslGaloisCounterMode(long context, int algorithmMode, int padding)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clean()
int
doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
int
doFinal(java.nio.ByteBuffer input, java.nio.ByteBuffer output)
private int
evpCipherCtxCtrl(long context, int type, int arg, java.nio.ByteBuffer data)
Wraps of OpenSslNative.ctrl(long context, int type, int arg, byte[] data) Since native interface EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) is generic, it may set/get any native char or long type to the data buffer(ptr).private int
getTagLen()
void
init(int mode, byte[] key, java.security.spec.AlgorithmParameterSpec params)
private void
processAAD()
int
update(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
int
update(java.nio.ByteBuffer input, java.nio.ByteBuffer output)
void
updateAAD(byte[] aad)
-
Methods inherited from class org.apache.commons.crypto.cipher.AbstractOpenSslFeedbackCipher
checkState
-
-
-
-
Field Detail
-
DEFAULT_TAG_LEN
static final int DEFAULT_TAG_LEN
- See Also:
- Constant Field Values
-
aadBuffer
private java.io.ByteArrayOutputStream aadBuffer
-
tagBitLen
private int tagBitLen
-
inBuffer
private java.io.ByteArrayOutputStream inBuffer
-
-
Method Detail
-
clean
public void clean()
- Overrides:
clean
in classAbstractOpenSslFeedbackCipher
-
doFinal
public int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws javax.crypto.ShortBufferException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
- Specified by:
doFinal
in classAbstractOpenSslFeedbackCipher
- Throws:
javax.crypto.ShortBufferException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
-
doFinal
public int doFinal(java.nio.ByteBuffer input, java.nio.ByteBuffer output) throws javax.crypto.ShortBufferException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
- Specified by:
doFinal
in classAbstractOpenSslFeedbackCipher
- Throws:
javax.crypto.ShortBufferException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
-
evpCipherCtxCtrl
private int evpCipherCtxCtrl(long context, int type, int arg, java.nio.ByteBuffer data)
Wraps of OpenSslNative.ctrl(long context, int type, int arg, byte[] data) Since native interface EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) is generic, it may set/get any native char or long type to the data buffer(ptr). Here we use ByteBuffer and set nativeOrder to handle the endianness.- Parameters:
context
- The cipher context addresstype
- CtrlValuesarg
- argument like a tag lengthdata
- byte buffer or null- Returns:
- return 0 if there is any error, else return 1.
-
getTagLen
private int getTagLen()
-
init
public void init(int mode, byte[] key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidAlgorithmParameterException
- Specified by:
init
in classAbstractOpenSslFeedbackCipher
- Throws:
java.security.InvalidAlgorithmParameterException
-
processAAD
private void processAAD()
-
update
public int update(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws javax.crypto.ShortBufferException
- Specified by:
update
in classAbstractOpenSslFeedbackCipher
- Throws:
javax.crypto.ShortBufferException
-
update
public int update(java.nio.ByteBuffer input, java.nio.ByteBuffer output) throws javax.crypto.ShortBufferException
- Specified by:
update
in classAbstractOpenSslFeedbackCipher
- Throws:
javax.crypto.ShortBufferException
-
updateAAD
public void updateAAD(byte[] aad)
- Specified by:
updateAAD
in classAbstractOpenSslFeedbackCipher
-
-