Package org.conscrypt
Class OpenSSLCipher
- java.lang.Object
-
- javax.crypto.CipherSpi
-
- org.conscrypt.OpenSSLCipher
-
- Direct Known Subclasses:
OpenSSLAeadCipher,OpenSSLCipherChaCha20,OpenSSLEvpCipher
@Internal public abstract class OpenSSLCipher extends javax.crypto.CipherSpi
An implementation ofCipherusing BoringSSL as the backing library.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classOpenSSLCipher.ModeModes that a block cipher may support.(package private) static classOpenSSLCipher.PaddingPaddings that a block cipher may support.
-
Field Summary
Fields Modifier and Type Field Description private intblockSizeThe block size of the current cipher.(package private) byte[]encodedKeyMay be used when reseting the cipher instance after callingdoFinal.private booleanencryptingCurrent cipher mode: encrypting or decrypting.(package private) byte[]ivThe Initial Vector (IV) used for the current cipher.(package private) OpenSSLCipher.ModemodeThe current cipher mode.private OpenSSLCipher.PaddingpaddingThe current cipher padding.
-
Constructor Summary
Constructors Constructor Description OpenSSLCipher()OpenSSLCipher(OpenSSLCipher.Mode mode, OpenSSLCipher.Padding 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 voidcheckSupportedKeySize(int keySize)Checks whether the cipher supports this particularkeySize(in bytes) and throwsInvalidKeyExceptionif it doesn't.(package private) abstract voidcheckSupportedMode(OpenSSLCipher.Mode mode)Checks whether the cipher supports this particular ciphermodeand throwsNoSuchAlgorithmExceptionif it doesn't.(package private) abstract voidcheckSupportedPadding(OpenSSLCipher.Padding padding)Checks whether the cipher supports this particular cipherpaddingand throwsNoSuchPaddingExceptionif it doesn't.(package private) abstract intdoFinalInternal(byte[] output, int outputOffset, int maximumLen)API-specific implementation of the final block.protected byte[]engineDoFinal(byte[] input, int inputOffset, int inputLen)protected intengineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)protected intengineGetBlockSize()protected byte[]engineGetIV()protected intengineGetKeySize(java.security.Key key)protected intengineGetOutputSize(int inputLen)protected java.security.AlgorithmParametersengineGetParameters()protected voidengineInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random)protected voidengineInit(int opmode, java.security.Key key, java.security.SecureRandom random)protected voidengineInit(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)(package private) abstract voidengineInitInternal(byte[] encodedKey, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)API-specific implementation of initializing the cipher.protected voidengineSetMode(java.lang.String modeStr)protected voidengineSetPadding(java.lang.String paddingStr)protected java.security.KeyengineUnwrap(byte[] wrappedKey, java.lang.String wrappedKeyAlgorithm, int wrappedKeyType)protected byte[]engineUpdate(byte[] input, int inputOffset, int inputLen)protected intengineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)protected byte[]engineWrap(java.security.Key key)(package private) abstract java.lang.StringgetBaseCipherName()Returns the standard name for the particular algorithm.(package private) abstract intgetCipherBlockSize()(package private) abstract intgetOutputSizeForFinal(int inputLen)The size of output ifdoFinal()is called with thisinputLen.(package private) abstract intgetOutputSizeForUpdate(int inputLen)The size of output ifupdate()is called with thisinputLen.(package private) OpenSSLCipher.PaddinggetPadding()Returns the padding type for which this cipher is initialized.protected java.security.spec.AlgorithmParameterSpecgetParameterSpec(java.security.AlgorithmParameters params)(package private) booleanisEncrypting()(package private) booleansupportsVariableSizeIv()(package private) booleansupportsVariableSizeKey()(package private) abstract intupdateInternal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset, int maximumLen)API-specific implementation of updating the cipher.
-
-
-
Field Detail
-
mode
OpenSSLCipher.Mode mode
The current cipher mode.
-
padding
private OpenSSLCipher.Padding padding
The current cipher padding.
-
encodedKey
byte[] encodedKey
May be used when reseting the cipher instance after callingdoFinal.
-
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.
-
-
Constructor Detail
-
OpenSSLCipher
OpenSSLCipher()
-
OpenSSLCipher
OpenSSLCipher(OpenSSLCipher.Mode mode, OpenSSLCipher.Padding padding)
-
-
Method Detail
-
engineInitInternal
abstract void engineInitInternal(byte[] encodedKey, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionAPI-specific implementation of initializing the cipher. TheisEncrypting()function will tell whether it should be initialized for encryption or decryption. TheencodedKeywill be the bytes of a supported key size.- Throws:
java.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterException
-
updateInternal
abstract int updateInternal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset, int maximumLen) throws javax.crypto.ShortBufferExceptionAPI-specific implementation of updating the cipher. ThemaximumLenwill be the maximum length of the output as returned bygetOutputSizeForUpdate(int). The return value must be the number of bytes processed and placed intooutput. 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.ShortBufferExceptionAPI-specific implementation of the final block. ThemaximumLenwill be the maximum length of the possible output as returned bygetOutputSizeForFinal(int). The return value must be the number of bytes processed and placed intooutput. On error, an exception must be thrown.- Throws:
javax.crypto.IllegalBlockSizeExceptionjavax.crypto.BadPaddingExceptionjavax.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.InvalidKeyExceptionChecks whether the cipher supports this particularkeySize(in bytes) and throwsInvalidKeyExceptionif 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 ciphermodeand throwsNoSuchAlgorithmExceptionif 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 cipherpaddingand throwsNoSuchPaddingExceptionif 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:
engineSetModein classjavax.crypto.CipherSpi- Throws:
java.security.NoSuchAlgorithmException
-
engineSetPadding
protected void engineSetPadding(java.lang.String paddingStr) throws javax.crypto.NoSuchPaddingException- Specified by:
engineSetPaddingin classjavax.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:
engineGetBlockSizein classjavax.crypto.CipherSpi
-
getOutputSizeForFinal
abstract int getOutputSizeForFinal(int inputLen)
The size of output ifdoFinal()is called with thisinputLen. 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 ifupdate()is called with thisinputLen. 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:
engineGetOutputSizein classjavax.crypto.CipherSpi
-
engineGetIV
protected byte[] engineGetIV()
- Specified by:
engineGetIVin classjavax.crypto.CipherSpi
-
engineGetParameters
protected java.security.AlgorithmParameters engineGetParameters()
- Specified by:
engineGetParametersin classjavax.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:
engineInitin classjavax.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:
engineInitin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyExceptionjava.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:
engineInitin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterException
-
engineUpdate
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen)- Specified by:
engineUpdatein classjavax.crypto.CipherSpi
-
engineUpdate
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws javax.crypto.ShortBufferException- Specified by:
engineUpdatein classjavax.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:
engineDoFinalin classjavax.crypto.CipherSpi- Throws:
javax.crypto.IllegalBlockSizeExceptionjavax.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:
engineDoFinalin classjavax.crypto.CipherSpi- Throws:
javax.crypto.ShortBufferExceptionjavax.crypto.IllegalBlockSizeExceptionjavax.crypto.BadPaddingException
-
engineWrap
protected byte[] engineWrap(java.security.Key key) throws javax.crypto.IllegalBlockSizeException, java.security.InvalidKeyException- Overrides:
engineWrapin classjavax.crypto.CipherSpi- Throws:
javax.crypto.IllegalBlockSizeExceptionjava.security.InvalidKeyException
-
engineUnwrap
protected java.security.Key engineUnwrap(byte[] wrappedKey, java.lang.String wrappedKeyAlgorithm, int wrappedKeyType) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException- Overrides:
engineUnwrapin classjavax.crypto.CipherSpi- Throws:
java.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmException
-
engineGetKeySize
protected int engineGetKeySize(java.security.Key key) throws java.security.InvalidKeyException- Overrides:
engineGetKeySizein classjavax.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()
-
-