Class TlsAEADCipher

  • All Implemented Interfaces:
    TlsCipher

    public class TlsAEADCipher
    extends java.lang.Object
    implements TlsCipher
    A generic TLS 1.2 AEAD cipher.
    • Field Detail

      • 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
      • decryptNonce

        protected final byte[] decryptNonce
      • encryptNonce

        protected final byte[] encryptNonce
      • isTLSv13

        protected final boolean isTLSv13
      • nonceMode

        protected final int nonceMode
    • Method Detail

      • getCiphertextDecodeLimit

        public int getCiphertextDecodeLimit​(int plaintextLimit)
        Description copied from interface: TlsCipher
        Return the maximum input size for a ciphertext given a maximum output size for the plaintext of plaintextLimit bytes.
        Specified by:
        getCiphertextDecodeLimit in interface TlsCipher
        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: TlsCipher
        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.
        Specified by:
        getCiphertextEncodeLimit in interface TlsCipher
        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: TlsCipher
        Return the maximum size for the plaintext given ciphertextlimit bytes of ciphertext.
        Specified by:
        getPlaintextLimit in interface TlsCipher
        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: TlsCipher
        Encrypt and MAC the passed in plain text using the current cipher suite.
        Specified by:
        encodePlaintext in interface TlsCipher
        Parameters:
        seqNo - sequence number of the message represented by plaintext.
        contentType - content type of the message represented by plaintext.
        recordVersion - ProtocolVersion used for the record.
        headerAllocation - extra bytes to allocate at start of returned byte array.
        plaintext - array holding input plain text to the cipher.
        plaintextOffset - offset into input array the plain text starts at.
        plaintextLength - length of the plaintext in the array.
        Returns:
        A TlsEncodeResult containing 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: TlsCipher
        Validate and decrypt the passed in cipher text using the current cipher suite.
        Specified by:
        decodeCiphertext in interface TlsCipher
        Parameters:
        seqNo - sequence number of the message represented by ciphertext.
        recordType - content type used in the record for this message.
        recordVersion - ProtocolVersion used for the record.
        ciphertext - array holding input cipher text to the cipher.
        ciphertextOffset - offset into input array the cipher text starts at.
        ciphertextLength - length of the cipher text in the array.
        Returns:
        A TlsDecodeResult containing the result of decoding.
        Throws:
        java.io.IOException
      • rekeyDecoder

        public void rekeyDecoder()
                          throws java.io.IOException
        Specified by:
        rekeyDecoder in interface TlsCipher
        Throws:
        java.io.IOException
      • rekeyEncoder

        public void rekeyEncoder()
                          throws java.io.IOException
        Specified by:
        rekeyEncoder in interface TlsCipher
        Throws:
        java.io.IOException
      • 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​(TlsAEADCipherImpl cipher,
                                   byte[] nonce,
                                   boolean serverSecret)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • setup13Cipher

        protected void setup13Cipher​(TlsAEADCipherImpl cipher,
                                     byte[] nonce,
                                     TlsSecret secret,
                                     short hash)
                              throws java.io.IOException
        Throws:
        java.io.IOException