Table of Contents

Class TlsBlockCipher

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

A generic TLS 1.0-1.2 block cipher. This can be used for AES or 3DES for example.

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

Constructors

TlsBlockCipher(TlsCryptoParameters, TlsBlockCipherImpl, TlsBlockCipherImpl, TlsHmac, TlsHmac, int)

public TlsBlockCipher(TlsCryptoParameters cryptoParams, TlsBlockCipherImpl encryptCipher, TlsBlockCipherImpl decryptCipher, TlsHmac clientMac, TlsHmac serverMac, int cipherKeySize)

Parameters

cryptoParams TlsCryptoParameters
encryptCipher TlsBlockCipherImpl
decryptCipher TlsBlockCipherImpl
clientMac TlsHmac
serverMac TlsHmac
cipherKeySize int

Exceptions

IOException

Fields

m_acceptExtraPadding

protected readonly bool m_acceptExtraPadding

Field Value

bool

m_cryptoParams

protected readonly TlsCryptoParameters m_cryptoParams

Field Value

TlsCryptoParameters

m_decryptCipher

protected readonly TlsBlockCipherImpl m_decryptCipher

Field Value

TlsBlockCipherImpl

m_decryptConnectionID

protected readonly byte[] m_decryptConnectionID

Field Value

byte[]

m_decryptUseInnerPlaintext

protected readonly bool m_decryptUseInnerPlaintext

Field Value

bool

m_encryptCipher

protected readonly TlsBlockCipherImpl m_encryptCipher

Field Value

TlsBlockCipherImpl

m_encryptConnectionID

protected readonly byte[] m_encryptConnectionID

Field Value

byte[]

m_encryptThenMac

protected readonly bool m_encryptThenMac

Field Value

bool

m_encryptUseInnerPlaintext

protected readonly bool m_encryptUseInnerPlaintext

Field Value

bool

m_randomData

protected readonly byte[] m_randomData

Field Value

byte[]

m_readMac

protected readonly TlsSuiteHmac m_readMac

Field Value

TlsSuiteHmac

m_useExplicitIV

protected readonly bool m_useExplicitIV

Field Value

bool

m_useExtraPadding

protected readonly bool m_useExtraPadding

Field Value

bool

m_writeMac

protected readonly TlsSuiteHmac m_writeMac

Field Value

TlsSuiteHmac

Properties

UsesOpaqueRecordType

public virtual bool UsesOpaqueRecordType { get; }

Property Value

bool

Methods

CheckPaddingConstantTime(byte[], int, int, int, int)

protected virtual int CheckPaddingConstantTime(byte[] buf, int off, int len, int blockSize, int macSize)

Parameters

buf byte[]
off int
len int
blockSize int
macSize int

Returns

int

ChooseExtraPadBlocks(int)

protected virtual int ChooseExtraPadBlocks(int max)

Parameters

max int

Returns

int

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 offset, int len)

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.

offset int

offset into input array the ciphertext starts at.

len int

length of the ciphertext in the array.

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 offset, int len)

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.

offset int

offset into input array the plaintext starts at.

len int

length of the plaintext in the array.

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

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.

GetCiphertextLength(int, int, int, int)

protected virtual int GetCiphertextLength(int blockSize, int macSize, int maxPadding, int plaintextLength)

Parameters

blockSize int
macSize int
maxPadding int
plaintextLength int

Returns

int

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

GetPlaintextLength(int, int, int)

protected virtual int GetPlaintextLength(int blockSize, int macSize, int ciphertextLength)

Parameters

blockSize int
macSize int
ciphertextLength 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.

RekeyDecoder()

public virtual void RekeyDecoder()

Exceptions

IOException

RekeyEncoder()

public virtual void RekeyEncoder()

Exceptions

IOException