TlsBlockCipher (Bouncy Castle Library 1.52 API Specification)
Date: 2015-03-01

org.bouncycastle.crypto.tls

## Class TlsBlockCipher

- java.lang.Object
- - org.bouncycastle.crypto.tls.TlsBlockCipher

- All Implemented Interfaces:
    TlsCipher

      public class TlsBlockCipher
      extends java.lang.Object
      implements TlsCipher

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

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected TlsContext` | `context`
    `protected BlockCipher` | `decryptCipher`
    `protected BlockCipher` | `encryptCipher`
    `protected boolean` | `encryptThenMAC`
    `protected byte[]` | `randomData`
    `protected TlsMac` | `readMac`
    `protected boolean` | `useExplicitIV`
    `protected TlsMac` | `writeMac`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TlsBlockCipher(TlsContext context, BlockCipher clientWriteCipher, BlockCipher serverWriteCipher, Digest clientWriteDigest, Digest serverWriteDigest, int cipherKeySize)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected int` | `checkPaddingConstantTime(byte[] buf, int off, int len, int blockSize, int macSize)`
    `protected int` | `chooseExtraPadBlocks(java.security.SecureRandom r, int max)`
    `byte[]` | `decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len)`
    `byte[]` | `encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len)`
    `int` | `getPlaintextLimit(int ciphertextLimit)`
    `TlsMac` | `getReadMac()`
    `TlsMac` | `getWriteMac()`
    `protected int` | `lowestBitSet(int x)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### context

          protected TlsContext context

    - #### randomData

          protected byte[] randomData

    - #### useExplicitIV

          protected boolean useExplicitIV

    - #### encryptThenMAC

          protected boolean encryptThenMAC

    - #### encryptCipher

          protected BlockCipher encryptCipher

    - #### decryptCipher

          protected BlockCipher decryptCipher

    - #### writeMac

          protected TlsMac writeMac

    - #### readMac

          protected TlsMac readMac

  - ### Constructor Detail

    - #### TlsBlockCipher

          public TlsBlockCipher(TlsContext context,
                        BlockCipher clientWriteCipher,
                        BlockCipher serverWriteCipher,
                        Digest clientWriteDigest,
                        Digest serverWriteDigest,
                        int cipherKeySize)
                         throws java.io.IOException

      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### getWriteMac

          public TlsMac getWriteMac()

    - #### getReadMac

          public TlsMac getReadMac()

    - #### getPlaintextLimit

          public int getPlaintextLimit(int ciphertextLimit)

      Specified by:
        `getPlaintextLimit` in interface `TlsCipher`

    - #### encodePlaintext

          public byte[] encodePlaintext(long seqNo,
                               short type,
                               byte[] plaintext,
                               int offset,
                               int len)

      Specified by:
        `encodePlaintext` in interface `TlsCipher`

    - #### decodeCiphertext

          public byte[] decodeCiphertext(long seqNo,
                                short type,
                                byte[] ciphertext,
                                int offset,
                                int len)
                                  throws java.io.IOException

      Specified by:
        `decodeCiphertext` in interface `TlsCipher`
      Throws:
        `java.io.IOException`

    - #### checkPaddingConstantTime

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

    - #### chooseExtraPadBlocks

          protected int chooseExtraPadBlocks(java.security.SecureRandom r,
                                 int max)

    - #### lowestBitSet

          protected int lowestBitSet(int x)