Package org.bouncycastle.tls.crypto.impl
Class TlsAEADCipher
- java.lang.Object
-
- org.bouncycastle.tls.crypto.impl.TlsAEADCipher
-
-
Field Summary
Fields Modifier and Type Field Description static intAEAD_CCMstatic intAEAD_CHACHA20_POLY1305static intAEAD_GCMprotected TlsCryptoParameterscryptoParamsprotected TlsAEADCipherImpldecryptCipherprotected byte[]decryptNonceprotected TlsAEADCipherImplencryptCipherprotected byte[]encryptNonceprotected intfixed_iv_lengthprotected booleanisTLSv13protected intkeySizeprotected intmacSizeprotected intnonceModeprotected intrecord_iv_length
-
Constructor Summary
Constructors Constructor Description TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encryptCipher, TlsAEADCipherImpl decryptCipher, int keySize, int macSize, int aeadType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TlsDecodeResultdecodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion, byte[] ciphertext, int ciphertextOffset, int ciphertextLength)Decode the passed in ciphertext using the current bulk cipher.TlsEncodeResultencodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion, int headerAllocation, byte[] plaintext, int plaintextOffset, int plaintextLength)Encode the passed in plaintext using the current bulk cipher.protected byte[]getAdditionalData(long seqNo, short recordType, ProtocolVersion recordVersion, int ciphertextLength, int plaintextLength)intgetCiphertextDecodeLimit(int plaintextLimit)Return the maximum input size for a ciphertext given a maximum output size for the plaintext of plaintextLimit bytes.intgetCiphertextEncodeLimit(int plaintextLength, int plaintextLimit)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.intgetPlaintextLimit(int ciphertextLimit)Return the maximum size for the plaintext given ciphertextlimit bytes of ciphertext.protected voidrekeyCipher(SecurityParameters securityParameters, TlsAEADCipherImpl cipher, byte[] nonce, boolean serverSecret)voidrekeyDecoder()voidrekeyEncoder()protected voidsetup13Cipher(TlsAEADCipherImpl cipher, byte[] nonce, TlsSecret secret, int cryptoHashAlgorithm)booleanusesOpaqueRecordType()
-
-
-
Field Detail
-
AEAD_CCM
public static final int AEAD_CCM
- See Also:
- Constant Field Values
-
AEAD_CHACHA20_POLY1305
public static final int AEAD_CHACHA20_POLY1305
- See Also:
- Constant Field Values
-
AEAD_GCM
public static final int AEAD_GCM
- See Also:
- Constant Field Values
-
cryptoParams
protected final TlsCryptoParameters cryptoParams
-
keySize
protected final int keySize
-
macSize
protected final int macSize
-
fixed_iv_length
protected final int fixed_iv_length
-
record_iv_length
protected final int record_iv_length
-
decryptCipher
protected final TlsAEADCipherImpl decryptCipher
-
encryptCipher
protected final TlsAEADCipherImpl encryptCipher
-
decryptNonce
protected final byte[] decryptNonce
-
encryptNonce
protected final byte[] encryptNonce
-
isTLSv13
protected final boolean isTLSv13
-
nonceMode
protected final int nonceMode
-
-
Constructor Detail
-
TlsAEADCipher
public TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encryptCipher, TlsAEADCipherImpl decryptCipher, int keySize, int macSize, int aeadType) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
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 plaintextLength, int plaintextLimit)Description copied from interface:TlsCipherReturn 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.- Specified by:
getCiphertextEncodeLimitin interfaceTlsCipher- Parameters:
plaintextLength- the actual input size for the plaintext.plaintextLimit- the maximum input size for the plaintext.- Returns:
- the maximum output size of the ciphertext for plaintextlimit bytes of input.
-
getPlaintextLimit
public int getPlaintextLimit(int ciphertextLimit)
Description copied from interface:TlsCipherReturn the maximum size for the plaintext given ciphertextlimit bytes of ciphertext.- Specified by:
getPlaintextLimitin interfaceTlsCipher- Parameters:
ciphertextLimit- the maximum number of bytes of ciphertext.- Returns:
- the maximum size of the plaintext for ciphertextlimit bytes of input.
-
encodePlaintext
public TlsEncodeResult encodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion, int headerAllocation, byte[] plaintext, int plaintextOffset, int plaintextLength) throws java.io.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:
java.io.IOException
-
decodeCiphertext
public TlsDecodeResult decodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion, byte[] ciphertext, int ciphertextOffset, int ciphertextLength) throws java.io.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:
java.io.IOException
-
rekeyDecoder
public void rekeyDecoder() throws java.io.IOException- Specified by:
rekeyDecoderin interfaceTlsCipher- Throws:
java.io.IOException
-
rekeyEncoder
public void rekeyEncoder() throws java.io.IOException- Specified by:
rekeyEncoderin interfaceTlsCipher- Throws:
java.io.IOException
-
usesOpaqueRecordType
public boolean usesOpaqueRecordType()
- Specified by:
usesOpaqueRecordTypein interfaceTlsCipher
-
getAdditionalData
protected byte[] getAdditionalData(long seqNo, short recordType, ProtocolVersion recordVersion, int ciphertextLength, int plaintextLength) throws java.io.IOException- Throws:
java.io.IOException
-
rekeyCipher
protected void rekeyCipher(SecurityParameters securityParameters, TlsAEADCipherImpl cipher, byte[] nonce, boolean serverSecret) throws java.io.IOException
- Throws:
java.io.IOException
-
setup13Cipher
protected void setup13Cipher(TlsAEADCipherImpl cipher, byte[] nonce, TlsSecret secret, int cryptoHashAlgorithm) throws java.io.IOException
- Throws:
java.io.IOException
-
-