Bouncy Castle Cryptography Library 1.47

org.bouncycastle.crypto.tls
Class TlsMac

java.lang.Object
  extended by org.bouncycastle.crypto.tls.TlsMac

public class TlsMac
extends java.lang.Object

A generic TLS MAC implementation, which can be used with any kind of Digest to act as an HMAC.


Field Summary
protected  TlsClientContext context
           
protected  Mac mac
           
protected  byte[] secret
           
protected  long seqNo
           
 
Constructor Summary
TlsMac(TlsClientContext context, Digest digest, byte[] key_block, int offset, int len)
          Generate a new instance of an TlsMac.
 
Method Summary
 byte[] calculateMac(short type, byte[] message, int offset, int len)
          Calculate the mac for some given data.
 byte[] getMACSecret()
           
 long getSequenceNumber()
           
 int getSize()
           
 void incSequenceNumber()
          Increment the current write sequence number
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected TlsClientContext context

seqNo

protected long seqNo

secret

protected byte[] secret

mac

protected Mac mac
Constructor Detail

TlsMac

public TlsMac(TlsClientContext context,
              Digest digest,
              byte[] key_block,
              int offset,
              int len)
Generate a new instance of an TlsMac.

Parameters:
context - the TLS client context
digest - The digest to use.
key_block - A byte-array where the key for this mac is located.
offset - The number of bytes to skip, before the key starts in the buffer.
len - The length of the key.
Method Detail

getMACSecret

public byte[] getMACSecret()
Returns:
the MAC write secret

getSequenceNumber

public long getSequenceNumber()
Returns:
the current write sequence number

incSequenceNumber

public void incSequenceNumber()
Increment the current write sequence number


getSize

public int getSize()
Returns:
The Keysize of the mac.

calculateMac

public byte[] calculateMac(short type,
                           byte[] message,
                           int offset,
                           int len)
Calculate the mac for some given data.

TlsMac will keep track of the sequence number internally.

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.
len - The length of the message.
Returns:
A new byte-buffer containing the mac value.

Bouncy Castle Cryptography Library 1.47