Package org.conscrypt
Class OpenSSLCipherChaCha20
java.lang.Object
javax.crypto.CipherSpi
org.conscrypt.OpenSSLCipher
org.conscrypt.OpenSSLCipherChaCha20
Implementation of the ChaCha20 stream cipher.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.conscrypt.OpenSSLCipher
OpenSSLCipher.Mode, OpenSSLCipher.Padding
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private int
private int
private static final int
Fields inherited from class org.conscrypt.OpenSSLCipher
encodedKey, iv, mode
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
checkSupportedKeySize
(int keySize) Checks whether the cipher supports this particularkeySize
(in bytes) and throwsInvalidKeyException
if it doesn't.(package private) void
Checks whether the cipher supports this particular ciphermode
and throwsNoSuchAlgorithmException
if it doesn't.(package private) void
Checks whether the cipher supports this particular cipherpadding
and throwsNoSuchPaddingException
if it doesn't.(package private) int
doFinalInternal
(byte[] output, int outputOffset, int maximumLen) API-specific implementation of the final block.(package private) void
engineInitInternal
(byte[] encodedKey, AlgorithmParameterSpec params, SecureRandom random) API-specific implementation of initializing the cipher.(package private) String
Returns the standard name for the particular algorithm.(package private) int
(package private) int
getOutputSizeForFinal
(int inputLen) The size of output ifdoFinal()
is called with thisinputLen
.(package private) int
getOutputSizeForUpdate
(int inputLen) The size of output ifupdate()
is called with thisinputLen
.private void
reset()
(package private) 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 org.conscrypt.OpenSSLCipher
engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineInit, engineSetMode, engineSetPadding, engineUnwrap, engineUpdate, engineUpdate, engineWrap, getPadding, getParameterSpec, isEncrypting, supportsVariableSizeIv, supportsVariableSizeKey
Methods inherited from class javax.crypto.CipherSpi
engineDoFinal, engineUpdate, engineUpdateAAD, engineUpdateAAD
-
Field Details
-
BLOCK_SIZE_BYTES
private static final int BLOCK_SIZE_BYTES- See Also:
-
NONCE_SIZE_BYTES
private static final int NONCE_SIZE_BYTES- See Also:
-
currentBlockConsumedBytes
private int currentBlockConsumedBytes -
blockCounter
private int blockCounter
-
-
Constructor Details
-
OpenSSLCipherChaCha20
public OpenSSLCipherChaCha20()
-
-
Method Details
-
engineInitInternal
void engineInitInternal(byte[] encodedKey, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException Description copied from class:OpenSSLCipher
API-specific implementation of initializing the cipher. TheOpenSSLCipher.isEncrypting()
function will tell whether it should be initialized for encryption or decryption. TheencodedKey
will be the bytes of a supported key size.- Specified by:
engineInitInternal
in classOpenSSLCipher
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
updateInternal
int updateInternal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset, int maximumLen) throws ShortBufferException Description copied from class:OpenSSLCipher
API-specific implementation of updating the cipher. ThemaximumLen
will be the maximum length of the output as returned byOpenSSLCipher.getOutputSizeForUpdate(int)
. The return value must be the number of bytes processed and placed intooutput
. On error, an exception must be thrown.- Specified by:
updateInternal
in classOpenSSLCipher
- Throws:
ShortBufferException
-
doFinalInternal
int doFinalInternal(byte[] output, int outputOffset, int maximumLen) throws IllegalBlockSizeException, BadPaddingException, ShortBufferException Description copied from class:OpenSSLCipher
API-specific implementation of the final block. ThemaximumLen
will be the maximum length of the possible output as returned byOpenSSLCipher.getOutputSizeForFinal(int)
. The return value must be the number of bytes processed and placed intooutput
. On error, an exception must be thrown.- Specified by:
doFinalInternal
in classOpenSSLCipher
- Throws:
IllegalBlockSizeException
BadPaddingException
ShortBufferException
-
reset
private void reset() -
getBaseCipherName
String getBaseCipherName()Description copied from class:OpenSSLCipher
Returns the standard name for the particular algorithm.- Specified by:
getBaseCipherName
in classOpenSSLCipher
-
checkSupportedKeySize
Description copied from class:OpenSSLCipher
Checks whether the cipher supports this particularkeySize
(in bytes) and throwsInvalidKeyException
if it doesn't.- Specified by:
checkSupportedKeySize
in classOpenSSLCipher
- Throws:
InvalidKeyException
-
checkSupportedMode
Description copied from class:OpenSSLCipher
Checks whether the cipher supports this particular ciphermode
and throwsNoSuchAlgorithmException
if it doesn't.- Specified by:
checkSupportedMode
in classOpenSSLCipher
- Throws:
NoSuchAlgorithmException
-
checkSupportedPadding
Description copied from class:OpenSSLCipher
Checks whether the cipher supports this particular cipherpadding
and throwsNoSuchPaddingException
if it doesn't.- Specified by:
checkSupportedPadding
in classOpenSSLCipher
- Throws:
NoSuchPaddingException
-
getCipherBlockSize
int getCipherBlockSize()- Specified by:
getCipherBlockSize
in classOpenSSLCipher
-
getOutputSizeForFinal
int getOutputSizeForFinal(int inputLen) Description copied from class:OpenSSLCipher
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.- Specified by:
getOutputSizeForFinal
in classOpenSSLCipher
-
getOutputSizeForUpdate
int getOutputSizeForUpdate(int inputLen) Description copied from class:OpenSSLCipher
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.- Specified by:
getOutputSizeForUpdate
in classOpenSSLCipher
-