public class HMACGenerator extends Object
I2PHMac
Keys are always 32 bytes.
This is used only by UDP.
Use deprecated outside the router, this may move to router.jar.
NOTE THIS IS NOT COMPATIBLE with javax.crypto.Mac.getInstance("HmacMD5")
as we tell I2PHMac that the digest length is 32 bytes, so it generates
a different result.
Quote jrandom:
"The HMAC is hardcoded to use SHA256 digest size
for backwards compatability. next time we have a backwards
incompatible change, we should update this."
Does this mean he intended it to be compatible with MD5?
See also 2005-07-05 status notes.Modifier and Type | Field and Description |
---|---|
protected LinkedBlockingQueue<I2PHMac> |
_available
set of available HMAC instances for calculate
|
Constructor and Description |
---|
HMACGenerator(I2PAppContext context) |
Modifier and Type | Method and Description |
---|---|
protected I2PHMac |
acquire() |
protected byte[] |
acquireTmp()
32 bytes from the byte array cache.
|
Hash |
calculate(SessionKey key,
byte[] data)
Deprecated.
unused (not even by Syndie)
|
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) |
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.
|
protected final LinkedBlockingQueue<I2PHMac> _available
public HMACGenerator(I2PAppContext context)
context
- unused@Deprecated public Hash calculate(SessionKey key, byte[] data)
public void calculate(SessionKey key, byte[] data, int offset, int length, byte[] target, int targetOffset)
target
- out parameter the first 16 bytes contain the HMAC, the last 16 bytes are zerotargetOffset
- offset into target to put the hmacIllegalArgumentException
- for bad key or target too smallpublic boolean verify(SessionKey key, byte[] curData, int curOffset, int curLength, byte[] origMAC, int origMACOffset, int origMACLength)
key
- session key to verify the MAC withcurData
- MAC to verifycurOffset
- index into curData to MACcurLength
- how much data in curData do we want to run the HMAC overorigMAC
- what do we expect the MAC of curData to equalorigMACOffset
- index into origMACorigMACLength
- how much of the MAC do we want to verifyIllegalArgumentException
- for bad keyprotected I2PHMac acquire()
protected byte[] acquireTmp()
protected void releaseTmp(byte[] tmp)