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 intprivate ByteArrayOutputStreamprivate intFields inherited from class AbstractOpenSslFeedbackCipher
algorithmMode, cipherMode, context, padding -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclean()intdoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) intdoFinal(ByteBuffer input, ByteBuffer output) private intevpCipherCtxCtrl(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 intvoidinit(int mode, byte[] key, AlgorithmParameterSpec params) private voidintupdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) intupdate(ByteBuffer input, ByteBuffer output) voidupdateAAD(byte[] aad) Methods inherited from class 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:
cleanin classAbstractOpenSslFeedbackCipher
-
doFinal
public int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException - Specified by:
doFinalin classAbstractOpenSslFeedbackCipher- Throws:
ShortBufferExceptionIllegalBlockSizeExceptionBadPaddingException
-
doFinal
public int doFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException - Specified by:
doFinalin classAbstractOpenSslFeedbackCipher- Throws:
ShortBufferExceptionIllegalBlockSizeExceptionBadPaddingException
-
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:
initin 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:
updatein classAbstractOpenSslFeedbackCipher- Throws:
ShortBufferException
-
update
- Specified by:
updatein classAbstractOpenSslFeedbackCipher- Throws:
ShortBufferException
-
updateAAD
public void updateAAD(byte[] aad) - Specified by:
updateAADin classAbstractOpenSslFeedbackCipher
-