Class 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
    • 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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • aadBuffer

        private java.io.ByteArrayOutputStream aadBuffer
      • tagBitLen

        private int tagBitLen
      • inBuffer

        private java.io.ByteArrayOutputStream inBuffer
    • Constructor Detail

      • OpenSslGaloisCounterMode

        public OpenSslGaloisCounterMode​(long context,
                                        int algorithmMode,
                                        int padding)
    • Method Detail

      • 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 class AbstractOpenSslFeedbackCipher
        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 class AbstractOpenSslFeedbackCipher
        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 address
        type - CtrlValues
        arg - argument like a tag length
        data - 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 class AbstractOpenSslFeedbackCipher
        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 class AbstractOpenSslFeedbackCipher
        Throws:
        javax.crypto.ShortBufferException
      • update

        public int update​(java.nio.ByteBuffer input,
                          java.nio.ByteBuffer output)
                   throws javax.crypto.ShortBufferException
        Specified by:
        update in class AbstractOpenSslFeedbackCipher
        Throws:
        javax.crypto.ShortBufferException