Package org.conscrypt
Class OpenSSLCipher
java.lang.Object
javax.crypto.CipherSpi
org.conscrypt.OpenSSLCipher
- Direct Known Subclasses:
OpenSSLAeadCipher,OpenSSLCipherChaCha20,OpenSSLEvpCipher
An implementation of
Cipher using BoringSSL as the backing library.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumModes that a block cipher may support.(package private) static enumPaddings that a block cipher may support. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe block size of the current cipher.(package private) byte[]May be used when reseting the cipher instance after callingdoFinal.private booleanCurrent cipher mode: encrypting or decrypting.(package private) byte[]The Initial Vector (IV) used for the current cipher.(package private) OpenSSLCipher.ModeThe current cipher mode.private OpenSSLCipher.PaddingThe current cipher padding. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]checkAndSetEncodedKey(int opmode, 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 voidChecks whether the cipher supports this particular ciphermodeand throwsNoSuchAlgorithmExceptionif it doesn't.(package private) abstract voidChecks 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 intprotected byte[]protected intengineGetKeySize(Key key) protected intengineGetOutputSize(int inputLen) protected AlgorithmParametersprotected voidengineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) protected voidengineInit(int opmode, Key key, SecureRandom random) protected voidengineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) (package private) abstract voidengineInitInternal(byte[] encodedKey, AlgorithmParameterSpec params, SecureRandom random) API-specific implementation of initializing the cipher.protected voidengineSetMode(String modeStr) protected voidengineSetPadding(String paddingStr) protected KeyengineUnwrap(byte[] wrappedKey, 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(Key key) (package private) abstract StringReturns the standard name for the particular algorithm.(package private) abstract int(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.PaddingReturns the padding type for which this cipher is initialized.protected AlgorithmParameterSpecgetParameterSpec(AlgorithmParameters params) (package private) boolean(package private) boolean(package private) boolean(package private) abstract intupdateInternal(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
-
Field Details
-
mode
OpenSSLCipher.Mode modeThe current cipher mode. -
padding
The current cipher padding. -
encodedKey
byte[] encodedKeyMay be used when reseting the cipher instance after callingdoFinal. -
iv
byte[] ivThe Initial Vector (IV) used for the current cipher. -
encrypting
private boolean encryptingCurrent cipher mode: encrypting or decrypting. -
blockSize
private int blockSizeThe block size of the current cipher.
-
-
Constructor Details
-
OpenSSLCipher
OpenSSLCipher() -
OpenSSLCipher
OpenSSLCipher(OpenSSLCipher.Mode mode, OpenSSLCipher.Padding padding)
-
-
Method Details
-
engineInitInternal
abstract void engineInitInternal(byte[] encodedKey, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException API-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. -
updateInternal
abstract int updateInternal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset, int maximumLen) throws ShortBufferException API-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:
ShortBufferException
-
doFinalInternal
abstract int doFinalInternal(byte[] output, int outputOffset, int maximumLen) throws IllegalBlockSizeException, BadPaddingException, ShortBufferException API-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. -
getBaseCipherName
Returns the standard name for the particular algorithm. -
checkSupportedKeySize
Checks whether the cipher supports this particularkeySize(in bytes) and throwsInvalidKeyExceptionif it doesn't.- Throws:
InvalidKeyException
-
checkSupportedMode
Checks whether the cipher supports this particular ciphermodeand throwsNoSuchAlgorithmExceptionif it doesn't.- Throws:
NoSuchAlgorithmException
-
checkSupportedPadding
Checks whether the cipher supports this particular cipherpaddingand throwsNoSuchPaddingExceptionif it doesn't.- Throws:
NoSuchPaddingException
-
getCipherBlockSize
abstract int getCipherBlockSize() -
supportsVariableSizeKey
boolean supportsVariableSizeKey() -
supportsVariableSizeIv
boolean supportsVariableSizeIv() -
engineSetMode
- Specified by:
engineSetModein classCipherSpi- Throws:
NoSuchAlgorithmException
-
engineSetPadding
- Specified by:
engineSetPaddingin classCipherSpi- Throws:
NoSuchPaddingException
-
getPadding
OpenSSLCipher.Padding getPadding()Returns the padding type for which this cipher is initialized. -
engineGetBlockSize
protected int engineGetBlockSize()- Specified by:
engineGetBlockSizein classCipherSpi
-
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 classCipherSpi
-
engineGetIV
protected byte[] engineGetIV()- Specified by:
engineGetIVin classCipherSpi
-
engineGetParameters
- Specified by:
engineGetParametersin classCipherSpi
-
getParameterSpec
protected AlgorithmParameterSpec getParameterSpec(AlgorithmParameters params) throws InvalidAlgorithmParameterException -
engineInit
- Specified by:
engineInitin classCipherSpi- Throws:
InvalidKeyException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException - Specified by:
engineInitin classCipherSpi- Throws:
InvalidKeyExceptionInvalidAlgorithmParameterException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException - Specified by:
engineInitin classCipherSpi- Throws:
InvalidKeyExceptionInvalidAlgorithmParameterException
-
engineUpdate
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) - Specified by:
engineUpdatein classCipherSpi
-
engineUpdate
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException - Specified by:
engineUpdatein classCipherSpi- Throws:
ShortBufferException
-
engineDoFinal
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException - Specified by:
engineDoFinalin classCipherSpi- Throws:
IllegalBlockSizeExceptionBadPaddingException
-
engineDoFinal
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException - Specified by:
engineDoFinalin classCipherSpi- Throws:
ShortBufferExceptionIllegalBlockSizeExceptionBadPaddingException
-
engineWrap
- Overrides:
engineWrapin classCipherSpi- Throws:
IllegalBlockSizeExceptionInvalidKeyException
-
engineUnwrap
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException - Overrides:
engineUnwrapin classCipherSpi- Throws:
InvalidKeyExceptionNoSuchAlgorithmException
-
engineGetKeySize
- Overrides:
engineGetKeySizein classCipherSpi- Throws:
InvalidKeyException
-
checkAndSetEncodedKey
- Throws:
InvalidKeyException
-
isEncrypting
boolean isEncrypting()
-