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 ofCipher
using BoringSSL as the backing library.
-
-
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 callingdoFinal
.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.
-
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 void
checkSupportedKeySize(int keySize)
Checks whether the cipher supports this particularkeySize
(in bytes) and throwsInvalidKeyException
if it doesn't.(package private) abstract void
checkSupportedMode(OpenSSLCipher.Mode mode)
Checks whether the cipher supports this particular ciphermode
and throwsNoSuchAlgorithmException
if it doesn't.(package private) abstract void
checkSupportedPadding(OpenSSLCipher.Padding padding)
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
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 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
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.
-
-
-
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.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.- 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. 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:
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. 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.- 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 particularkeySize
(in bytes) and throwsInvalidKeyException
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 ciphermode
and throwsNoSuchAlgorithmException
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 cipherpadding
and throwsNoSuchPaddingException
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 classjavax.crypto.CipherSpi
- Throws:
java.security.NoSuchAlgorithmException
-
engineSetPadding
protected void engineSetPadding(java.lang.String paddingStr) throws javax.crypto.NoSuchPaddingException
- Specified by:
engineSetPadding
in 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:
engineGetBlockSize
in 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:
engineGetOutputSize
in classjavax.crypto.CipherSpi
-
engineGetIV
protected byte[] engineGetIV()
- Specified by:
engineGetIV
in classjavax.crypto.CipherSpi
-
engineGetParameters
protected java.security.AlgorithmParameters engineGetParameters()
- Specified by:
engineGetParameters
in 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:
engineInit
in 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:
engineInit
in classjavax.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 classjavax.crypto.CipherSpi
- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
engineUpdate
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen)
- Specified by:
engineUpdate
in classjavax.crypto.CipherSpi
-
engineUpdate
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws javax.crypto.ShortBufferException
- Specified by:
engineUpdate
in 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:
engineDoFinal
in classjavax.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 classjavax.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 classjavax.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 classjavax.crypto.CipherSpi
- Throws:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
-
engineGetKeySize
protected int engineGetKeySize(java.security.Key key) throws java.security.InvalidKeyException
- Overrides:
engineGetKeySize
in 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()
-
-