Package org.apache.sshd.common.cipher
Class ChaCha20Cipher
- java.lang.Object
-
- org.apache.sshd.common.cipher.ChaCha20Cipher
-
- All Implemented Interfaces:
AlgorithmNameProvider
,Cipher
,CipherInformation
,KeySizeIndicator
public class ChaCha20Cipher extends java.lang.Object implements Cipher
AEAD cipher based on the OpenSSH ChaCha20-Poly1305 cipher extension.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ChaCha20Cipher.ChaChaEngine
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.cipher.Cipher
Cipher.Mode
-
-
Field Summary
Fields Modifier and Type Field Description protected ChaCha20Cipher.ChaChaEngine
bodyEngine
protected ChaCha20Cipher.ChaChaEngine
headerEngine
protected Mac
mac
protected Cipher.Mode
mode
-
Constructor Summary
Constructors Constructor Description ChaCha20Cipher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAlgorithm()
int
getAuthenticationTagSize()
int
getCipherBlockSize()
int
getIVSize()
int
getKdfSize()
int
getKeySize()
java.lang.String
getTransformation()
void
init(Cipher.Mode mode, byte[] key, byte[] iv)
Initialize the cipher for encryption or decryption with the given key and initialization vectorvoid
update(byte[] input, int inputOffset, int inputLen)
Performs in-place encryption or decryption on the given data.void
updateAAD(byte[] data, int offset, int length)
Adds the provided input data as additional authenticated data during encryption or decryption.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.cipher.Cipher
update, updateAAD, updateWithAAD
-
-
-
-
Field Detail
-
headerEngine
protected final ChaCha20Cipher.ChaChaEngine headerEngine
-
bodyEngine
protected final ChaCha20Cipher.ChaChaEngine bodyEngine
-
mac
protected final Mac mac
-
mode
protected Cipher.Mode mode
-
-
Method Detail
-
getAlgorithm
public java.lang.String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceAlgorithmNameProvider
-
init
public void init(Cipher.Mode mode, byte[] key, byte[] iv) throws java.lang.Exception
Description copied from interface:Cipher
Initialize the cipher for encryption or decryption with the given key and initialization vector
-
updateAAD
public void updateAAD(byte[] data, int offset, int length) throws java.lang.Exception
Description copied from interface:Cipher
Adds the provided input data as additional authenticated data during encryption or decryption.
-
update
public void update(byte[] input, int inputOffset, int inputLen) throws java.lang.Exception
Description copied from interface:Cipher
Performs in-place encryption or decryption on the given data.- Specified by:
update
in interfaceCipher
- Parameters:
input
- The input/output bytesinputOffset
- The offset of the data in the data bufferinputLen
- The number of bytes to update, starting at the given offset; must be a multiple of the cipher's block size- Throws:
java.lang.Exception
- If failed to execute
-
getTransformation
public java.lang.String getTransformation()
- Specified by:
getTransformation
in interfaceCipherInformation
- Returns:
- The actual transformation used - e.g., AES/CBC/NoPadding
-
getIVSize
public int getIVSize()
- Specified by:
getIVSize
in interfaceCipherInformation
- Returns:
- Size of the initialization vector (in bytes)
-
getAuthenticationTagSize
public int getAuthenticationTagSize()
- Specified by:
getAuthenticationTagSize
in interfaceCipherInformation
- Returns:
- Size of the authentication tag (AT) in bytes or 0 if this cipher does not support authentication
-
getCipherBlockSize
public int getCipherBlockSize()
- Specified by:
getCipherBlockSize
in interfaceCipherInformation
- Returns:
- Size of block data used by the cipher (in bytes). For stream ciphers this value is (currently) used to indicate some average work buffer size to be used for the automatic re-keying mechanism described in RFC 4253 - Section 9
-
getKdfSize
public int getKdfSize()
- Specified by:
getKdfSize
in interfaceCipherInformation
- Returns:
- The block size (in bytes) used to derive the secret key for this cipher
-
getKeySize
public int getKeySize()
- Specified by:
getKeySize
in interfaceKeySizeIndicator
- Returns:
- The number of bits used in the key
-
-