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

org.bouncycastle.crypto.tls

## Class TlsMac

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

-     public class TlsMac
      extends java.lang.Object

  A generic TLS MAC implementation, acting as an HMAC based on some underlying Digest.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected TlsContext` | `context`
    `protected int` | `digestBlockSize`
    `protected int` | `digestOverhead`
    `protected Mac` | `mac`
    `protected int` | `macLength`
    `protected byte[]` | `secret`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TlsMac(TlsContext context, Digest digest, byte[] key, int keyOff, int keyLen)` Generate a new instance of an TlsMac.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `calculateMac(long seqNo, short type, byte[] message, int offset, int length)` Calculate the MAC for some given data.
    `byte[]` | `calculateMacConstantTime(long seqNo, short type, byte[] message, int offset, int length, int fullLength, byte[] dummyData)`
    `protected int` | `getDigestBlockCount(int inputLength)`
    `byte[]` | `getMACSecret()`
    `int` | `getSize()`
    `protected byte[]` | `truncate(byte[] bs)`

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

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

- - ### Field Detail

    - #### context

          protected TlsContext context

    - #### secret

          protected byte[] secret

    - #### mac

          protected Mac mac

    - #### digestBlockSize

          protected int digestBlockSize

    - #### digestOverhead

          protected int digestOverhead

    - #### macLength

          protected int macLength

  - ### Constructor Detail

    - #### TlsMac

          public TlsMac(TlsContext context,
                Digest digest,
                byte[] key,
                int keyOff,
                int keyLen)

      Generate a new instance of an TlsMac.
      Parameters:
        `context` - the TLS client context
        `digest` - The digest to use.
        `key` - A byte-array where the key for this MAC is located.
        `keyOff` - The number of bytes to skip, before the key starts in the buffer.
        `keyLen` - The length of the key.

  - ### Method Detail

    - #### getMACSecret

          public byte[] getMACSecret()

      Returns:
        the MAC write secret

    - #### getSize

          public int getSize()

      Returns:
        The output length of this MAC.

    - #### calculateMac

          public byte[] calculateMac(long seqNo,
                            short type,
                            byte[] message,
                            int offset,
                            int length)

      Calculate the MAC for some given data.
      Parameters:
        `type` - The message type of the message.
        `message` - A byte-buffer containing the message.
        `offset` - The number of bytes to skip, before the message starts.
        `length` - The length of the message.
      Returns:
        A new byte-buffer containing the MAC value.

    - #### calculateMacConstantTime

          public byte[] calculateMacConstantTime(long seqNo,
                                        short type,
                                        byte[] message,
                                        int offset,
                                        int length,
                                        int fullLength,
                                        byte[] dummyData)

    - #### getDigestBlockCount

          protected int getDigestBlockCount(int inputLength)

    - #### truncate

          protected byte[] truncate(byte[] bs)