Package org.conscrypt

Class OpenSSLCipher

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  OpenSSLCipher.Mode
      Modes that a block cipher may support.
      (package private) static class  OpenSSLCipher.Padding
      Paddings that a block cipher may support.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int blockSize
      The block size of the current cipher.
      (package private) byte[] encodedKey
      May be used when reseting the cipher instance after calling doFinal.
      private boolean encrypting
      Current cipher mode: encrypting or decrypting.
      (package private) byte[] iv
      The Initial Vector (IV) used for the current cipher.
      (package private) OpenSSLCipher.Mode mode
      The current cipher mode.
      private OpenSSLCipher.Padding padding
      The current cipher padding.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      private byte[] checkAndSetEncodedKey​(int opmode, java.security.Key key)  
      (package private) abstract void checkSupportedKeySize​(int keySize)
      Checks whether the cipher supports this particular keySize (in bytes) and throws InvalidKeyException if it doesn't.
      (package private) abstract void checkSupportedMode​(OpenSSLCipher.Mode mode)
      Checks whether the cipher supports this particular cipher mode and throws NoSuchAlgorithmException if it doesn't.
      (package private) abstract void checkSupportedPadding​(OpenSSLCipher.Padding padding)
      Checks whether the cipher supports this particular cipher padding and throws NoSuchPaddingException if it doesn't.
      (package private) abstract int doFinalInternal​(byte[] output, int outputOffset, int maximumLen)
      API-specific implementation of the final block.
      protected byte[] engineDoFinal​(byte[] input, int inputOffset, int inputLen)  
      protected int engineDoFinal​(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)  
      protected int engineGetBlockSize()  
      protected byte[] engineGetIV()  
      protected int engineGetKeySize​(java.security.Key key)  
      protected int engineGetOutputSize​(int inputLen)  
      protected java.security.AlgorithmParameters engineGetParameters()  
      protected void engineInit​(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random)  
      protected void engineInit​(int opmode, java.security.Key key, java.security.SecureRandom random)  
      protected void engineInit​(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)  
      (package private) abstract void engineInitInternal​(byte[] encodedKey, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)
      API-specific implementation of initializing the cipher.
      protected void engineSetMode​(java.lang.String modeStr)  
      protected void engineSetPadding​(java.lang.String paddingStr)  
      protected java.security.Key engineUnwrap​(byte[] wrappedKey, java.lang.String wrappedKeyAlgorithm, int wrappedKeyType)  
      protected byte[] engineUpdate​(byte[] input, int inputOffset, int inputLen)  
      protected int engineUpdate​(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)  
      protected byte[] engineWrap​(java.security.Key key)  
      (package private) abstract java.lang.String getBaseCipherName()
      Returns the standard name for the particular algorithm.
      (package private) abstract int getCipherBlockSize()  
      (package private) abstract int getOutputSizeForFinal​(int inputLen)
      The size of output if doFinal() is called with this inputLen.
      (package private) abstract int getOutputSizeForUpdate​(int inputLen)
      The size of output if update() is called with this inputLen.
      (package private) OpenSSLCipher.Padding getPadding()
      Returns the padding type for which this cipher is initialized.
      protected java.security.spec.AlgorithmParameterSpec getParameterSpec​(java.security.AlgorithmParameters params)  
      (package private) boolean isEncrypting()  
      (package private) boolean supportsVariableSizeIv()  
      (package private) boolean supportsVariableSizeKey()  
      (package private) abstract int updateInternal​(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset, int maximumLen)
      API-specific implementation of updating the cipher.
      • Methods inherited from class javax.crypto.CipherSpi

        engineDoFinal, engineUpdate, engineUpdateAAD, engineUpdateAAD
      • Methods inherited from class java.lang.Object

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

      • encodedKey

        byte[] encodedKey
        May be used when reseting the cipher instance after calling doFinal.
      • iv

        byte[] iv
        The Initial Vector (IV) used for the current cipher.
      • encrypting

        private boolean encrypting
        Current cipher mode: encrypting or decrypting.
      • blockSize

        private int blockSize
        The block size of the current cipher.
    • Method Detail

      • engineInitInternal

        abstract void engineInitInternal​(byte[] encodedKey,
                                         java.security.spec.AlgorithmParameterSpec params,
                                         java.security.SecureRandom random)
                                  throws java.security.InvalidKeyException,
                                         java.security.InvalidAlgorithmParameterException
        API-specific implementation of initializing the cipher. The isEncrypting() function will tell whether it should be initialized for encryption or decryption. The encodedKey will be the bytes of a supported key size.
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • updateInternal

        abstract int updateInternal​(byte[] input,
                                    int inputOffset,
                                    int inputLen,
                                    byte[] output,
                                    int outputOffset,
                                    int maximumLen)
                             throws javax.crypto.ShortBufferException
        API-specific implementation of updating the cipher. The maximumLen will be the maximum length of the output as returned by getOutputSizeForUpdate(int). The return value must be the number of bytes processed and placed into output. On error, an exception must be thrown.
        Throws:
        javax.crypto.ShortBufferException
      • doFinalInternal

        abstract int doFinalInternal​(byte[] output,
                                     int outputOffset,
                                     int maximumLen)
                              throws javax.crypto.IllegalBlockSizeException,
                                     javax.crypto.BadPaddingException,
                                     javax.crypto.ShortBufferException
        API-specific implementation of the final block. The maximumLen will be the maximum length of the possible output as returned by getOutputSizeForFinal(int). The return value must be the number of bytes processed and placed into output. On error, an exception must be thrown.
        Throws:
        javax.crypto.IllegalBlockSizeException
        javax.crypto.BadPaddingException
        javax.crypto.ShortBufferException
      • getBaseCipherName

        abstract java.lang.String getBaseCipherName()
        Returns the standard name for the particular algorithm.
      • checkSupportedKeySize

        abstract void checkSupportedKeySize​(int keySize)
                                     throws java.security.InvalidKeyException
        Checks whether the cipher supports this particular keySize (in bytes) and throws InvalidKeyException if it doesn't.
        Throws:
        java.security.InvalidKeyException
      • checkSupportedMode

        abstract void checkSupportedMode​(OpenSSLCipher.Mode mode)
                                  throws java.security.NoSuchAlgorithmException
        Checks whether the cipher supports this particular cipher mode and throws NoSuchAlgorithmException if it doesn't.
        Throws:
        java.security.NoSuchAlgorithmException
      • checkSupportedPadding

        abstract void checkSupportedPadding​(OpenSSLCipher.Padding padding)
                                     throws javax.crypto.NoSuchPaddingException
        Checks whether the cipher supports this particular cipher padding and throws NoSuchPaddingException if it doesn't.
        Throws:
        javax.crypto.NoSuchPaddingException
      • getCipherBlockSize

        abstract int getCipherBlockSize()
      • supportsVariableSizeKey

        boolean supportsVariableSizeKey()
      • supportsVariableSizeIv

        boolean supportsVariableSizeIv()
      • engineSetMode

        protected void engineSetMode​(java.lang.String modeStr)
                              throws java.security.NoSuchAlgorithmException
        Specified by:
        engineSetMode in class javax.crypto.CipherSpi
        Throws:
        java.security.NoSuchAlgorithmException
      • engineSetPadding

        protected void engineSetPadding​(java.lang.String paddingStr)
                                 throws javax.crypto.NoSuchPaddingException
        Specified by:
        engineSetPadding in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.NoSuchPaddingException
      • getPadding

        OpenSSLCipher.Padding getPadding()
        Returns the padding type for which this cipher is initialized.
      • engineGetBlockSize

        protected int engineGetBlockSize()
        Specified by:
        engineGetBlockSize in class javax.crypto.CipherSpi
      • getOutputSizeForFinal

        abstract int getOutputSizeForFinal​(int inputLen)
        The size of output if doFinal() is called with this inputLen. If padding is enabled and the size of the input puts it right at the block size, it will add another block for the padding.
      • getOutputSizeForUpdate

        abstract int getOutputSizeForUpdate​(int inputLen)
        The size of output if update() is called with this inputLen. If padding is enabled and the size of the input puts it right at the block size, it will add another block for the padding.
      • engineGetOutputSize

        protected int engineGetOutputSize​(int inputLen)
        Specified by:
        engineGetOutputSize in class javax.crypto.CipherSpi
      • engineGetIV

        protected byte[] engineGetIV()
        Specified by:
        engineGetIV in class javax.crypto.CipherSpi
      • engineGetParameters

        protected java.security.AlgorithmParameters engineGetParameters()
        Specified by:
        engineGetParameters in class javax.crypto.CipherSpi
      • getParameterSpec

        protected java.security.spec.AlgorithmParameterSpec getParameterSpec​(java.security.AlgorithmParameters params)
                                                                      throws java.security.InvalidAlgorithmParameterException
        Throws:
        java.security.InvalidAlgorithmParameterException
      • engineInit

        protected void engineInit​(int opmode,
                                  java.security.Key key,
                                  java.security.SecureRandom random)
                           throws java.security.InvalidKeyException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
      • engineInit

        protected void engineInit​(int opmode,
                                  java.security.Key key,
                                  java.security.spec.AlgorithmParameterSpec params,
                                  java.security.SecureRandom random)
                           throws java.security.InvalidKeyException,
                                  java.security.InvalidAlgorithmParameterException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • engineInit

        protected void engineInit​(int opmode,
                                  java.security.Key key,
                                  java.security.AlgorithmParameters params,
                                  java.security.SecureRandom random)
                           throws java.security.InvalidKeyException,
                                  java.security.InvalidAlgorithmParameterException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • engineUpdate

        protected byte[] engineUpdate​(byte[] input,
                                      int inputOffset,
                                      int inputLen)
        Specified by:
        engineUpdate in class javax.crypto.CipherSpi
      • engineUpdate

        protected int engineUpdate​(byte[] input,
                                   int inputOffset,
                                   int inputLen,
                                   byte[] output,
                                   int outputOffset)
                            throws javax.crypto.ShortBufferException
        Specified by:
        engineUpdate in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.ShortBufferException
      • engineDoFinal

        protected byte[] engineDoFinal​(byte[] input,
                                       int inputOffset,
                                       int inputLen)
                                throws javax.crypto.IllegalBlockSizeException,
                                       javax.crypto.BadPaddingException
        Specified by:
        engineDoFinal in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.IllegalBlockSizeException
        javax.crypto.BadPaddingException
      • engineDoFinal

        protected int engineDoFinal​(byte[] input,
                                    int inputOffset,
                                    int inputLen,
                                    byte[] output,
                                    int outputOffset)
                             throws javax.crypto.ShortBufferException,
                                    javax.crypto.IllegalBlockSizeException,
                                    javax.crypto.BadPaddingException
        Specified by:
        engineDoFinal in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.ShortBufferException
        javax.crypto.IllegalBlockSizeException
        javax.crypto.BadPaddingException
      • engineWrap

        protected byte[] engineWrap​(java.security.Key key)
                             throws javax.crypto.IllegalBlockSizeException,
                                    java.security.InvalidKeyException
        Overrides:
        engineWrap in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.IllegalBlockSizeException
        java.security.InvalidKeyException
      • engineUnwrap

        protected java.security.Key engineUnwrap​(byte[] wrappedKey,
                                                 java.lang.String wrappedKeyAlgorithm,
                                                 int wrappedKeyType)
                                          throws java.security.InvalidKeyException,
                                                 java.security.NoSuchAlgorithmException
        Overrides:
        engineUnwrap in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        java.security.NoSuchAlgorithmException
      • engineGetKeySize

        protected int engineGetKeySize​(java.security.Key key)
                                throws java.security.InvalidKeyException
        Overrides:
        engineGetKeySize in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
      • checkAndSetEncodedKey

        private byte[] checkAndSetEncodedKey​(int opmode,
                                             java.security.Key key)
                                      throws java.security.InvalidKeyException
        Throws:
        java.security.InvalidKeyException
      • isEncrypting

        boolean isEncrypting()