Top Description Inners Fields Constructors Methods
org.apache.sshd.common.cipher

public Class ChaCha20Cipher

extends Object
implements Cipher
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.cipher.Cipher, org.apache.sshd.common.cipher.CipherInformation, org.apache.sshd.common.keyprovider.KeySizeIndicator, org.apache.sshd.common.AlgorithmNameProvider
Imports
java.nio.charset.StandardCharsets, java.util.Arrays, javax.crypto.AEADBadTagException, org.apache.sshd.common.mac.Mac, .Poly1305Mac, org.apache.sshd.common.util.ValidateUtils, org.apache.sshd.common.util.buffer.BufferUtils

AEAD cipher based on the OpenSSH ChaCha20-Poly1305 cipher extension.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
protected final ChaCha20Cipher.ChaChaEngine
protected final ChaCha20Cipher.ChaChaEngine
protected final Mac
protected Cipher.Mode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
public int
public int
public int
public int
public int
public String
public void
init(Cipher.Mode
Encrypt/Decrypt initialization
mode
,
byte[]
Key bytes
key
,
byte[]
Initialization vector bytes
iv
)

Implements org.apache.sshd.common.cipher.Cipher.init.

Initialize the cipher for encryption or decryption with the given key and initialization vector

public void
update(byte[]
The input/output bytes
input
,
int
The offset of the data in the data buffer
inputOffset
,
int
The number of bytes to update, starting at the given offset; must be a multiple of the cipher's block size
inputLen
)

Implements org.apache.sshd.common.cipher.Cipher.update.

Performs in-place encryption or decryption on the given data.

public void
updateAAD(byte[]
The additional data to authenticate
data
,
int
The offset of the additional data in the buffer
offset
,
int
The number of bytes in the buffer to use for authentication
length
)

Implements org.apache.sshd.common.cipher.Cipher.updateAAD.

Adds the provided input data as additional authenticated data during encryption or decryption.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bodyEngineback to summary
protected final ChaCha20Cipher.ChaChaEngine bodyEngine
headerEngineback to summary
protected final ChaCha20Cipher.ChaChaEngine headerEngine
macback to summary
protected final Mac mac
modeback to summary
protected Cipher.Mode mode

Constructor Detail

ChaCha20Cipherback to summary
public ChaCha20Cipher()

Method Detail

getAlgorithmback to summary
public String getAlgorithm()

Implements org.apache.sshd.common.AlgorithmNameProvider.getAlgorithm.

Annotations
@Override
getAuthenticationTagSizeback to summary
public int getAuthenticationTagSize()

Implements org.apache.sshd.common.cipher.CipherInformation.getAuthenticationTagSize.

Returns:int

Doc from org.apache.sshd.common.cipher.CipherInformation.getAuthenticationTagSize.

Size of the authentication tag (AT) in bytes or 0 if this cipher does not support authentication

Annotations
@Override
getCipherBlockSizeback to summary
public int getCipherBlockSize()

Implements org.apache.sshd.common.cipher.CipherInformation.getCipherBlockSize.

Returns:int

Doc from org.apache.sshd.common.cipher.CipherInformation.getCipherBlockSize.

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

Annotations
@Override
getIVSizeback to summary
public int getIVSize()

Implements org.apache.sshd.common.cipher.CipherInformation.getIVSize.

Returns:int

Doc from org.apache.sshd.common.cipher.CipherInformation.getIVSize.

Size of the initialization vector (in bytes)

Annotations
@Override
getKdfSizeback to summary
public int getKdfSize()

Implements org.apache.sshd.common.cipher.CipherInformation.getKdfSize.

Returns:int

Doc from org.apache.sshd.common.cipher.CipherInformation.getKdfSize.

The block size (in bytes) used to derive the secret key for this cipher

Annotations
@Override
getKeySizeback to summary
public int getKeySize()

Implements org.apache.sshd.common.keyprovider.KeySizeIndicator.getKeySize.

Returns:int

Doc from org.apache.sshd.common.keyprovider.KeySizeIndicator.getKeySize.

The number of bits used in the key

Annotations
@Override
getTransformationback to summary
public String getTransformation()

Implements org.apache.sshd.common.cipher.CipherInformation.getTransformation.

Returns:String

Doc from org.apache.sshd.common.cipher.CipherInformation.getTransformation.

The actual transformation used - e.g., AES/CBC/NoPadding

Annotations
@Override
initback to summary
public void init(Cipher.Mode mode, byte[] key, byte[] iv) throws Exception

Implements org.apache.sshd.common.cipher.Cipher.init.

Doc from org.apache.sshd.common.cipher.Cipher.init.

Initialize the cipher for encryption or decryption with the given key and initialization vector

Parameters
mode:Cipher.Mode

Encrypt/Decrypt initialization

key:byte[]

Key bytes

iv:byte[]

Initialization vector bytes

Annotations
@Override
Exceptions
Exception:
If failed to initialize
updateback to summary
public void update(byte[] input, int inputOffset, int inputLen) throws Exception

Implements org.apache.sshd.common.cipher.Cipher.update.

Doc from org.apache.sshd.common.cipher.Cipher.update.

Performs in-place encryption or decryption on the given data.

Parameters
input:byte[]

The input/output bytes

inputOffset:int

The offset of the data in the data buffer

inputLen:int

The number of bytes to update, starting at the given offset; must be a multiple of the cipher's block size

Annotations
@Override
Exceptions
Exception:
If failed to execute
updateAADback to summary
public void updateAAD(byte[] data, int offset, int length) throws Exception

Implements org.apache.sshd.common.cipher.Cipher.updateAAD.

Doc from org.apache.sshd.common.cipher.Cipher.updateAAD.

Adds the provided input data as additional authenticated data during encryption or decryption.

Parameters
data:byte[]

The additional data to authenticate

offset:int

The offset of the additional data in the buffer

length:int

The number of bytes in the buffer to use for authentication

Annotations
@Override
Exceptions
Exception:
If failed to execute
org.apache.sshd.common.cipher back to summary

protected Class ChaCha20Cipher.ChaChaEngine

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private static final int[]
protected final int[]
protected long
private static final int
private static final int
private static final int
protected final byte[]
protected final byte[]
private static final int
protected long

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
crypt(byte[] in, int offset, int length, byte[] out, int outOffset)

protected void
initCounter(long counter)

protected void
initKey(byte[] key)

protected void
initNonce(byte[] nonce)

protected byte[]
protected void
setKeyStream(int[] engine)

private static void
unpackIntsLE(byte[] buf, int off, int nrInts, int[] dst, int dstOff)

private static int[]
unpackSigmaString(byte[] buf)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BLOCK_BYTESback to summary
private static final int BLOCK_BYTES
BLOCK_INTSback to summary
private static final int BLOCK_INTS
COUNTER_OFFSETback to summary
private static final int COUNTER_OFFSET
ENGINE_STATE_HEADERback to summary
private static final int[] ENGINE_STATE_HEADER
engineStateback to summary
protected final int[] engineState
initialNonceback to summary
protected long initialNonce
KEY_BYTESback to summary
private static final int KEY_BYTES
KEY_INTSback to summary
private static final int KEY_INTS
KEY_OFFSETback to summary
private static final int KEY_OFFSET
keyStreamback to summary
protected final byte[] keyStream
nonceback to summary
protected final byte[] nonce
NONCE_OFFSETback to summary
private static final int NONCE_OFFSET
nonceValback to summary
protected long nonceVal

Constructor Detail

ChaChaEngineback to summary
protected ChaChaEngine()

Method Detail

advanceNonceback to summary
protected void advanceNonce()
cryptback to summary
protected void crypt(byte[] in, int offset, int length, byte[] out, int outOffset)
initCounterback to summary
protected void initCounter(long counter)
initKeyback to summary
protected void initKey(byte[] key)
initNonceback to summary
protected void initNonce(byte[] nonce)
polyKeyback to summary
protected byte[] polyKey()
setKeyStreamback to summary
protected void setKeyStream(int[] engine)
unpackIntsLEback to summary
private static void unpackIntsLE(byte[] buf, int off, int nrInts, int[] dst, int dstOff)
unpackSigmaStringback to summary
private static int[] unpackSigmaString(byte[] buf)