Class TlsAEADCipher
java.lang.Object
org.bouncycastle.tls.crypto.impl.TlsAEADCipher
- All Implemented Interfaces:
TlsCipher, TlsDTLS13Cipher
A generic AEAD cipher, covering TLS 1.2, TLS 1.3 and DTLS 1.3 record protection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionTlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encryptCipher, TlsAEADCipherImpl decryptCipher, int keySize, int macSize, int aeadType) Deprecated.Use version with extra 'nonceGeneratorFactory' parameterTlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encryptCipher, TlsAEADCipherImpl decryptCipher, int keySize, int macSize, int aeadType, AEADNonceGeneratorFactory nonceGeneratorFactory) TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encryptCipher, TlsAEADCipherImpl decryptCipher, int keySize, int macSize, int aeadType, AEADNonceGeneratorFactory nonceGeneratorFactory, TlsRecordNumberMask encryptMask, TlsRecordNumberMask decryptMask) -
Method Summary
Modifier and TypeMethodDescriptiondecodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion, byte[] ciphertext, int ciphertextOffset, int ciphertextLength) Decode the passed in ciphertext using the current bulk cipher.decodeDTLS13Ciphertext(long seqNo, byte[] record, int recordOff, int headerLen, int ciphertextLen) Decode a received DTLS 1.3 protected record.voiddecryptDTLS13RecordNumber(byte[] record, int recordOff, int recordLen) Decrypt (in place) the record number of a received DTLS 1.3 protected record (RFC 9147 4.2.3).encodeDTLS13Plaintext(long seqNo, short contentType, byte[] header, int headerOff, int headerLen, byte[] plaintext, int plaintextOffset, int plaintextLength) Encode the passed in plaintext as a DTLS 1.3 protected record (RFC 9147 4).encodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion, int headerAllocation, byte[] plaintext, int plaintextOffset, int plaintextLength) Encode the passed in plaintext using the current bulk cipher.intgetCiphertextDecodeLimit(int plaintextLimit) Return the maximum input size for a ciphertext given a maximum output size for the plaintext of plaintextLimit bytes.intgetCiphertextEncodeLimit(int plaintextLimit) Return the maximum output size for a ciphertext given a maximum input size for the plaintext of plaintextLimit bytes.intgetPlaintextDecodeLimit(int ciphertextLimit) Return the maximum output size for the plaintext given a maximum input size for the ciphertext of ciphertextLimit bytes.intgetPlaintextEncodeLimit(int ciphertextLimit) Return the maximum input size for the plaintext given a maximum output size for the ciphertext of ciphertextLimit bytes.voidvoidbooleanboolean
-
Field Details
-
AEAD_CCM
public static final int AEAD_CCM- See Also:
-
AEAD_CHACHA20_POLY1305
public static final int AEAD_CHACHA20_POLY1305- See Also:
-
AEAD_GCM
public static final int AEAD_GCM- See Also:
-
-
Constructor Details
-
TlsAEADCipher
@Deprecated public TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encryptCipher, TlsAEADCipherImpl decryptCipher, int keySize, int macSize, int aeadType) throws IOException Deprecated.Use version with extra 'nonceGeneratorFactory' parameter- Throws:
IOException
-
TlsAEADCipher
public TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encryptCipher, TlsAEADCipherImpl decryptCipher, int keySize, int macSize, int aeadType, AEADNonceGeneratorFactory nonceGeneratorFactory) throws IOException - Throws:
IOException
-
TlsAEADCipher
public TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encryptCipher, TlsAEADCipherImpl decryptCipher, int keySize, int macSize, int aeadType, AEADNonceGeneratorFactory nonceGeneratorFactory, TlsRecordNumberMask encryptMask, TlsRecordNumberMask decryptMask) throws IOException - Parameters:
encryptMask- record number encryption mask for the sending direction (DTLS 1.3 only, may be null when DTLS 1.3 will not be negotiated).decryptMask- record number encryption mask for the receiving direction (DTLS 1.3 only).- Throws:
IOException
-
-
Method Details
-
getCiphertextDecodeLimit
public int getCiphertextDecodeLimit(int plaintextLimit) Description copied from interface:TlsCipherReturn the maximum input size for a ciphertext given a maximum output size for the plaintext of plaintextLimit bytes.- Specified by:
getCiphertextDecodeLimitin interfaceTlsCipher- Parameters:
plaintextLimit- the maximum output size for the plaintext.- Returns:
- the maximum input size of the ciphertext for plaintextLimit bytes of output.
-
getCiphertextEncodeLimit
public int getCiphertextEncodeLimit(int plaintextLimit) Description copied from interface:TlsCipherReturn the maximum output size for a ciphertext given a maximum input size for the plaintext of plaintextLimit bytes.- Specified by:
getCiphertextEncodeLimitin interfaceTlsCipher- Parameters:
plaintextLimit- the maximum input size for the plaintext.- Returns:
- the maximum output size of the ciphertext for plaintextLimit bytes of input.
-
getPlaintextDecodeLimit
public int getPlaintextDecodeLimit(int ciphertextLimit) Description copied from interface:TlsCipherReturn the maximum output size for the plaintext given a maximum input size for the ciphertext of ciphertextLimit bytes.- Specified by:
getPlaintextDecodeLimitin interfaceTlsCipher- Parameters:
ciphertextLimit- the maximum input size for the ciphertext.- Returns:
- the maximum output size of the plaintext for ciphertextLimit bytes of input.
-
getPlaintextEncodeLimit
public int getPlaintextEncodeLimit(int ciphertextLimit) Description copied from interface:TlsCipherReturn the maximum input size for the plaintext given a maximum output size for the ciphertext of ciphertextLimit bytes.- Specified by:
getPlaintextEncodeLimitin interfaceTlsCipher- Parameters:
ciphertextLimit- the maximum output size for the ciphertext.- Returns:
- the maximum input size of the plaintext for ciphertextLimit bytes of output.
-
encodePlaintext
public TlsEncodeResult encodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion, int headerAllocation, byte[] plaintext, int plaintextOffset, int plaintextLength) throws IOException Description copied from interface:TlsCipherEncode the passed in plaintext using the current bulk cipher.- Specified by:
encodePlaintextin interfaceTlsCipher- Parameters:
seqNo- sequence number of the message represented by plaintext.contentType- content type of the message represented by plaintext.recordVersion-ProtocolVersionused for the record.headerAllocation- extra bytes to allocate at start of returned byte array.plaintext- array holding input plaintext to the cipher.plaintextOffset- offset into input array the plaintext starts at.plaintextLength- length of the plaintext in the array.- Returns:
- A
TlsEncodeResultcontaining the result of encoding (after 'headerAllocation' unused bytes). - Throws:
IOException
-
decodeCiphertext
public TlsDecodeResult decodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion, byte[] ciphertext, int ciphertextOffset, int ciphertextLength) throws IOException Description copied from interface:TlsCipherDecode the passed in ciphertext using the current bulk cipher.- Specified by:
decodeCiphertextin interfaceTlsCipher- Parameters:
seqNo- sequence number of the message represented by ciphertext.recordType- content type used in the record for this message.recordVersion-ProtocolVersionused for the record.ciphertext- array holding input ciphertext to the cipher.ciphertextOffset- offset into input array the ciphertext starts at.ciphertextLength- length of the ciphertext in the array.- Returns:
- A
TlsDecodeResultcontaining the result of decoding. - Throws:
IOException
-
encodeDTLS13Plaintext
public TlsEncodeResult encodeDTLS13Plaintext(long seqNo, short contentType, byte[] header, int headerOff, int headerLen, byte[] plaintext, int plaintextOffset, int plaintextLength) throws IOException Description copied from interface:TlsDTLS13CipherEncode the passed in plaintext as a DTLS 1.3 protected record (RFC 9147 4). The supplied unified header is the AEAD additional data; when its L bit is set the (zeroed) length field is filled in by this method. The returned record holds the header, with record number encryption (RFC 9147 4.2.3) applied to its sequence number bytes, followed by the encrypted record.- Specified by:
encodeDTLS13Plaintextin interfaceTlsDTLS13Cipher- Parameters:
seqNo- the 64-bit record sequence number (the epoch is not included, unlike DTLS 1.2).contentType- the true content type, written into the DTLSInnerPlaintext.header- array holding the unified header with the sequence number in the clear.headerOff- offset of the header in the array.headerLen- length of the header.plaintext- array holding input plaintext to the cipher.plaintextOffset- offset into input array the plaintext starts at.plaintextLength- length of the plaintext in the array.- Returns:
- A
TlsEncodeResultwhose buffer holds the complete record (header followed by ciphertext), with 'recordType' set to the first byte of the unified header. - Throws:
IOException
-
decryptDTLS13RecordNumber
public void decryptDTLS13RecordNumber(byte[] record, int recordOff, int recordLen) throws IOException Description copied from interface:TlsDTLS13CipherDecrypt (in place) the record number of a received DTLS 1.3 protected record (RFC 9147 4.2.3). The record starts with its unified header; at least 16 bytes of ciphertext must follow the header.- Specified by:
decryptDTLS13RecordNumberin interfaceTlsDTLS13Cipher- Parameters:
record- array holding the received record.recordOff- offset of the record (its unified header) in the array.recordLen- length of the record.- Throws:
IOException
-
decodeDTLS13Ciphertext
public TlsDecodeResult decodeDTLS13Ciphertext(long seqNo, byte[] record, int recordOff, int headerLen, int ciphertextLen) throws IOException Description copied from interface:TlsDTLS13CipherDecode a received DTLS 1.3 protected record. The unified header (with the sequence number already decrypted) at 'recordOff' is the AEAD additional data, and the ciphertext immediately follows it.- Specified by:
decodeDTLS13Ciphertextin interfaceTlsDTLS13Cipher- Parameters:
seqNo- the 64-bit record sequence number reconstructed by the caller (the epoch is not included).record- array holding the received record.recordOff- offset of the record (its unified header) in the array.headerLen- length of the unified header.ciphertextLen- length of the ciphertext following the header.- Returns:
- A
TlsDecodeResultcontaining the result of decoding. - Throws:
IOException
-
rekeyDecoder
- Specified by:
rekeyDecoderin interfaceTlsCipher- Throws:
IOException
-
rekeyEncoder
- Specified by:
rekeyEncoderin interfaceTlsCipher- Throws:
IOException
-
usesOpaqueRecordTypeDecode
public boolean usesOpaqueRecordTypeDecode()- Specified by:
usesOpaqueRecordTypeDecodein interfaceTlsCipher
-
usesOpaqueRecordTypeEncode
public boolean usesOpaqueRecordTypeEncode()- Specified by:
usesOpaqueRecordTypeEncodein interfaceTlsCipher
-