Class HMACGenerator

java.lang.Object
net.i2p.crypto.HMACGenerator
Direct Known Subclasses:
HMAC256Generator, SSUHMACGenerator

public abstract class HMACGenerator
extends Object
Calculate the HMAC of a key+message. As of 0.9.42, this is just a stub. See net.i2p.router.transport.udp.SSUHMACGenerator for the HMAC used in SSU (what was originally this class), and SHA256Generator for the HMAC used in Syndie.
  • Constructor Summary

    Constructors 
    Constructor Description
    HMACGenerator()  
  • Method Summary

    Modifier and Type Method Description
    protected byte[] acquireTmp()
    32 bytes from the byte array cache.
    abstract void calculate​(SessionKey key, byte[] data, int offset, int length, byte[] target, int targetOffset)
    Calculate the HMAC of the data with the given key
    protected void releaseTmp​(byte[] tmp)  
    abstract boolean verify​(SessionKey key, byte[] curData, int curOffset, int curLength, byte[] origMAC, int origMACOffset, int origMACLength)
    Verify the MAC inline, reducing some unnecessary memory churn.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • calculate

      public abstract void calculate​(SessionKey key, byte[] data, int offset, int length, byte[] target, int targetOffset)
      Calculate the HMAC of the data with the given key
      Parameters:
      target - out parameter the first 16 bytes contain the HMAC, the last 16 bytes are zero
      targetOffset - offset into target to put the hmac
      Throws:
      IllegalArgumentException - for bad key or target too small
    • verify

      public abstract boolean verify​(SessionKey key, byte[] curData, int curOffset, int curLength, byte[] origMAC, int origMACOffset, int origMACLength)
      Verify the MAC inline, reducing some unnecessary memory churn.
      Parameters:
      key - session key to verify the MAC with
      curData - MAC to verify
      curOffset - index into curData to MAC
      curLength - how much data in curData do we want to run the HMAC over
      origMAC - what do we expect the MAC of curData to equal
      origMACOffset - index into origMAC
      origMACLength - how much of the MAC do we want to verify
      Throws:
      IllegalArgumentException - for bad key
    • acquireTmp

      protected byte[] acquireTmp()
      32 bytes from the byte array cache. Does NOT zero.
    • releaseTmp

      protected void releaseTmp​(byte[] tmp)