Table of Contents

Class TlsAeadCipher

Namespace
Org.BouncyCastle.Tls.Crypto.Impl
Assembly
BouncyCastle.Cryptography.dll

A generic TLS 1.2 AEAD cipher.

public class TlsAeadCipher : TlsCipher, TlsCipherExt
Inheritance
TlsAeadCipher
Implements
Inherited Members

Constructors

TlsAeadCipher(TlsCryptoParameters, TlsAeadCipherImpl, TlsAeadCipherImpl, int, int, int)

public TlsAeadCipher(TlsCryptoParameters cryptoParams, TlsAeadCipherImpl encryptCipher, TlsAeadCipherImpl decryptCipher, int keySize, int macSize, int aeadType)

Parameters

cryptoParams TlsCryptoParameters
encryptCipher TlsAeadCipherImpl
decryptCipher TlsAeadCipherImpl
keySize int
macSize int
aeadType int

Exceptions

IOException

Fields

AEAD_CCM

public const int AEAD_CCM = 1

Field Value

int

AEAD_CHACHA20_POLY1305

public const int AEAD_CHACHA20_POLY1305 = 2

Field Value

int

AEAD_GCM

public const int AEAD_GCM = 3

Field Value

int

m_cryptoParams

protected readonly TlsCryptoParameters m_cryptoParams

Field Value

TlsCryptoParameters

m_decryptCipher

protected readonly TlsAeadCipherImpl m_decryptCipher

Field Value

TlsAeadCipherImpl

m_decryptConnectionID

protected readonly byte[] m_decryptConnectionID

Field Value

byte[]

m_decryptNonce

protected readonly byte[] m_decryptNonce

Field Value

byte[]

m_decryptUseInnerPlaintext

protected readonly bool m_decryptUseInnerPlaintext

Field Value

bool

m_encryptCipher

protected readonly TlsAeadCipherImpl m_encryptCipher

Field Value

TlsAeadCipherImpl

m_encryptConnectionID

protected readonly byte[] m_encryptConnectionID

Field Value

byte[]

m_encryptNonce

protected readonly byte[] m_encryptNonce

Field Value

byte[]

m_encryptUseInnerPlaintext

protected readonly bool m_encryptUseInnerPlaintext

Field Value

bool

m_fixed_iv_length

protected readonly int m_fixed_iv_length

Field Value

int

m_isTlsV13

protected readonly bool m_isTlsV13

Field Value

bool

m_keySize

protected readonly int m_keySize

Field Value

int

m_macSize

protected readonly int m_macSize

Field Value

int

m_nonceMode

protected readonly int m_nonceMode

Field Value

int

m_record_iv_length

protected readonly int m_record_iv_length

Field Value

int

Properties

UsesOpaqueRecordType

public virtual bool UsesOpaqueRecordType { get; }

Property Value

bool

Methods

DecodeCiphertext(long, short, ProtocolVersion, byte[], int, int)

Decode the passed in ciphertext using the current bulk cipher.

public virtual TlsDecodeResult DecodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion, byte[] ciphertext, int ciphertextOffset, int ciphertextLength)

Parameters

seqNo long

sequence number of the message represented by ciphertext.

recordType short

content type used in the record for this message.

recordVersion ProtocolVersion

ProtocolVersion used for the record.

ciphertext byte[]

array holding input ciphertext to the cipher.

ciphertextOffset int
ciphertextLength int

Returns

TlsDecodeResult

A TlsDecodeResult containing the result of decoding.

Exceptions

IOException

EncodePlaintext(long, short, ProtocolVersion, int, byte[], int, int)

Encode the passed in plaintext using the current bulk cipher.

public virtual TlsEncodeResult EncodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion, int headerAllocation, byte[] plaintext, int plaintextOffset, int plaintextLength)

Parameters

seqNo long

sequence number of the message represented by plaintext.

contentType short

content type of the message represented by plaintext.

recordVersion ProtocolVersion

ProtocolVersion used for the record.

headerAllocation int

extra bytes to allocate at start of returned byte array.

plaintext byte[]

array holding input plaintext to the cipher.

plaintextOffset int
plaintextLength int

Returns

TlsEncodeResult

A TlsEncodeResult containing the result of encoding (after 'headerAllocation' unused bytes).

Exceptions

IOException

EncodePlaintext(long, short, ProtocolVersion, int, ReadOnlySpan<byte>)

public virtual TlsEncodeResult EncodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion, int headerAllocation, ReadOnlySpan<byte> plaintext)

Parameters

seqNo long
contentType short
recordVersion ProtocolVersion
headerAllocation int
plaintext ReadOnlySpan<byte>

Returns

TlsEncodeResult

GetAdditionalData(long, short, ProtocolVersion, int, int)

protected virtual byte[] GetAdditionalData(long seqNo, short recordType, ProtocolVersion recordVersion, int ciphertextLength, int plaintextLength)

Parameters

seqNo long
recordType short
recordVersion ProtocolVersion
ciphertextLength int
plaintextLength int

Returns

byte[]

GetAdditionalData(long, short, ProtocolVersion, int, int, byte[])

protected virtual byte[] GetAdditionalData(long seqNo, short recordType, ProtocolVersion recordVersion, int ciphertextLength, int plaintextLength, byte[] connectionID)

Parameters

seqNo long
recordType short
recordVersion ProtocolVersion
ciphertextLength int
plaintextLength int
connectionID byte[]

Returns

byte[]

GetCiphertextDecodeLimit(int)

Return the maximum input size for a ciphertext given a maximum output size for the plaintext of plaintextLimit bytes.

public virtual int GetCiphertextDecodeLimit(int plaintextLimit)

Parameters

plaintextLimit int

the maximum output size for the plaintext.

Returns

int

the maximum input size of the ciphertext for plaintextlimit bytes of output.

GetCiphertextEncodeLimit(int, int)

Return the maximum output size for a ciphertext given an actual input plaintext size of plaintextLength bytes and a maximum input plaintext size of plaintextLimit bytes.

public virtual int GetCiphertextEncodeLimit(int plaintextLength, int plaintextLimit)

Parameters

plaintextLength int

the actual input size for the plaintext.

plaintextLimit int

the maximum input size for the plaintext.

Returns

int

the maximum output size of the ciphertext for plaintextlimit bytes of input.

GetPlaintextDecodeLimit(int)

public virtual int GetPlaintextDecodeLimit(int ciphertextLimit)

Parameters

ciphertextLimit int

Returns

int

GetPlaintextEncodeLimit(int)

public virtual int GetPlaintextEncodeLimit(int ciphertextLimit)

Parameters

ciphertextLimit int

Returns

int

GetPlaintextLimit(int)

Return the maximum size for the plaintext given ciphertextlimit bytes of ciphertext.

public virtual int GetPlaintextLimit(int ciphertextLimit)

Parameters

ciphertextLimit int

the maximum number of bytes of ciphertext.

Returns

int

the maximum size of the plaintext for ciphertextlimit bytes of input.

RekeyCipher(SecurityParameters, TlsAeadCipherImpl, byte[], bool)

protected virtual void RekeyCipher(SecurityParameters securityParameters, TlsAeadCipherImpl cipher, byte[] nonce, bool serverSecret)

Parameters

securityParameters SecurityParameters
cipher TlsAeadCipherImpl
nonce byte[]
serverSecret bool

RekeyDecoder()

public virtual void RekeyDecoder()

Exceptions

IOException

RekeyEncoder()

public virtual void RekeyEncoder()

Exceptions

IOException

Setup13Cipher(TlsAeadCipherImpl, byte[], TlsSecret, int)

protected virtual void Setup13Cipher(TlsAeadCipherImpl cipher, byte[] nonce, TlsSecret secret, int cryptoHashAlgorithm)

Parameters

cipher TlsAeadCipherImpl
nonce byte[]
secret TlsSecret
cryptoHashAlgorithm int