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 enum
Modes that a block cipher may support.(package private) static enum
Paddings that a block cipher may support. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
The block size of the current cipher.(package private) byte[]
May be used when reseting the cipher instance after callingdoFinal
.private boolean
Current cipher mode: encrypting or decrypting.(package private) byte[]
The Initial Vector (IV) used for the current cipher.(package private) OpenSSLCipher.Mode
The current cipher mode.private OpenSSLCipher.Padding
The current cipher padding. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]
checkAndSetEncodedKey
(int opmode, Key key) (package private) abstract void
checkSupportedKeySize
(int keySize) Checks whether the cipher supports this particularkeySize
(in bytes) and throwsInvalidKeyException
if it doesn't.(package private) abstract void
Checks whether the cipher supports this particular ciphermode
and throwsNoSuchAlgorithmException
if it doesn't.(package private) abstract void
Checks whether the cipher supports this particular cipherpadding
and throwsNoSuchPaddingException
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
protected byte[]
protected int
engineGetKeySize
(Key key) protected int
engineGetOutputSize
(int inputLen) protected AlgorithmParameters
protected void
engineInit
(int opmode, Key key, AlgorithmParameters params, SecureRandom random) protected void
engineInit
(int opmode, Key key, SecureRandom random) protected void
engineInit
(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) (package private) abstract void
engineInitInternal
(byte[] encodedKey, AlgorithmParameterSpec params, SecureRandom random) API-specific implementation of initializing the cipher.protected void
engineSetMode
(String modeStr) protected void
engineSetPadding
(String paddingStr) protected Key
engineUnwrap
(byte[] wrappedKey, 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
(Key key) (package private) abstract String
Returns the standard name for the particular algorithm.(package private) abstract int
(package private) abstract int
getOutputSizeForFinal
(int inputLen) The size of output ifdoFinal()
is called with thisinputLen
.(package private) abstract int
getOutputSizeForUpdate
(int inputLen) The size of output ifupdate()
is called with thisinputLen
.(package private) OpenSSLCipher.Padding
Returns the padding type for which this cipher is initialized.protected AlgorithmParameterSpec
getParameterSpec
(AlgorithmParameters params) (package private) boolean
(package private) boolean
(package private) boolean
(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
-
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. TheencodedKey
will 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. ThemaximumLen
will 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. ThemaximumLen
will 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 throwsInvalidKeyException
if it doesn't.- Throws:
InvalidKeyException
-
checkSupportedMode
Checks whether the cipher supports this particular ciphermode
and throwsNoSuchAlgorithmException
if it doesn't.- Throws:
NoSuchAlgorithmException
-
checkSupportedPadding
Checks whether the cipher supports this particular cipherpadding
and throwsNoSuchPaddingException
if it doesn't.- Throws:
NoSuchPaddingException
-
getCipherBlockSize
abstract int getCipherBlockSize() -
supportsVariableSizeKey
boolean supportsVariableSizeKey() -
supportsVariableSizeIv
boolean supportsVariableSizeIv() -
engineSetMode
- Specified by:
engineSetMode
in classCipherSpi
- Throws:
NoSuchAlgorithmException
-
engineSetPadding
- Specified by:
engineSetPadding
in classCipherSpi
- Throws:
NoSuchPaddingException
-
getPadding
OpenSSLCipher.Padding getPadding()Returns the padding type for which this cipher is initialized. -
engineGetBlockSize
protected int engineGetBlockSize()- Specified by:
engineGetBlockSize
in 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:
engineGetOutputSize
in classCipherSpi
-
engineGetIV
protected byte[] engineGetIV()- Specified by:
engineGetIV
in classCipherSpi
-
engineGetParameters
- Specified by:
engineGetParameters
in classCipherSpi
-
getParameterSpec
protected AlgorithmParameterSpec getParameterSpec(AlgorithmParameters params) throws InvalidAlgorithmParameterException -
engineInit
- Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException - Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException - Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
engineUpdate
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) - Specified by:
engineUpdate
in classCipherSpi
-
engineUpdate
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException - Specified by:
engineUpdate
in classCipherSpi
- Throws:
ShortBufferException
-
engineDoFinal
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException - Specified by:
engineDoFinal
in classCipherSpi
- Throws:
IllegalBlockSizeException
BadPaddingException
-
engineDoFinal
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException - Specified by:
engineDoFinal
in classCipherSpi
- Throws:
ShortBufferException
IllegalBlockSizeException
BadPaddingException
-
engineWrap
- Overrides:
engineWrap
in classCipherSpi
- Throws:
IllegalBlockSizeException
InvalidKeyException
-
engineUnwrap
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException - Overrides:
engineUnwrap
in classCipherSpi
- Throws:
InvalidKeyException
NoSuchAlgorithmException
-
engineGetKeySize
- Overrides:
engineGetKeySize
in classCipherSpi
- Throws:
InvalidKeyException
-
checkAndSetEncodedKey
- Throws:
InvalidKeyException
-
isEncrypting
boolean isEncrypting()
-