Package org.apache.commons.crypto.cipher
Class OpenSslGaloisCounterMode
java.lang.Object
org.apache.commons.crypto.cipher.AbstractOpenSslFeedbackCipher
org.apache.commons.crypto.cipher.OpenSslGaloisCounterMode
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
FieldsModifier and TypeFieldDescriptionprivate ByteArrayOutputStream
(package private) static final int
private ByteArrayOutputStream
private int
Fields inherited from class org.apache.commons.crypto.cipher.AbstractOpenSslFeedbackCipher
algorithmMode, cipherMode, context, padding
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clean()
int
doFinal
(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) int
doFinal
(ByteBuffer input, ByteBuffer output) private int
evpCipherCtxCtrl
(long context, int type, int arg, 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
void
init
(int mode, byte[] key, AlgorithmParameterSpec params) private void
int
update
(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) int
update
(ByteBuffer input, ByteBuffer output) void
updateAAD
(byte[] aad) Methods inherited from class org.apache.commons.crypto.cipher.AbstractOpenSslFeedbackCipher
checkState
-
Field Details
-
DEFAULT_TAG_LEN
static final int DEFAULT_TAG_LEN- See Also:
-
aadBuffer
-
tagBitLen
private int tagBitLen -
inBuffer
-
-
Constructor Details
-
OpenSslGaloisCounterMode
public OpenSslGaloisCounterMode(long context, int algorithmMode, int padding)
-
-
Method Details
-
clean
public void clean()- Overrides:
clean
in classAbstractOpenSslFeedbackCipher
-
doFinal
public int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException - Specified by:
doFinal
in classAbstractOpenSslFeedbackCipher
- Throws:
ShortBufferException
IllegalBlockSizeException
BadPaddingException
-
doFinal
public int doFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException - Specified by:
doFinal
in classAbstractOpenSslFeedbackCipher
- Throws:
ShortBufferException
IllegalBlockSizeException
BadPaddingException
-
evpCipherCtxCtrl
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, AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException - Specified by:
init
in classAbstractOpenSslFeedbackCipher
- Throws:
InvalidAlgorithmParameterException
-
processAAD
private void processAAD() -
update
public int update(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException - Specified by:
update
in classAbstractOpenSslFeedbackCipher
- Throws:
ShortBufferException
-
update
- Specified by:
update
in classAbstractOpenSslFeedbackCipher
- Throws:
ShortBufferException
-
updateAAD
public void updateAAD(byte[] aad) - Specified by:
updateAAD
in classAbstractOpenSslFeedbackCipher
-