public final class HMAC256Generator extends HMACGenerator
javax.crypto.Mac.getInstance("HmacSHA256").
It offers both one-shot calculation and streaming operations for different use cases.Key features:
Compatibility Note: As of 0.9.12, this class uses the standard javax.crypto.Mac implementation for improved security and compatibility.
| Modifier and Type | Class and Description |
|---|---|
(package private) static class | HMAC256Generator.HMACKeyPerformance-optimized SecretKey implementation for HMAC operations. |
| Constructor and Description |
|---|
HMAC256Generator(I2PAppContext context)Create a new HMAC256Generator. |
| Modifier and Type | Method and Description |
|---|---|
(package private) Mac | acquire()Package private for HKDF. |
void | calculate(byte[] key,
byte[] data,
int offset,
int length,
byte[] target,
int targetOffset)Calculate the HMAC of the data with the given key. |
void | calculate(SessionKey key,
byte[] data,
int offset,
int length,
byte[] target,
int targetOffset)Calculate the HMAC of the data with the given key. |
(package private) void | release(Mac mac)Release a Mac back to the pool. |
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. |
acquireTmp, releaseTmppublic HMAC256Generator(I2PAppContext context)
context - unusedMac acquire()
public void calculate(byte[] key,
byte[] data,
int offset,
int length,
byte[] target,
int targetOffset)key - first 32 bytes used as the keydata - the data to calculate the HMAC overoffset - offset into datalength - number of bytes to includetarget - output buffertargetOffset - offset into targetUnsupportedOperationException - if the JVM does not support itIllegalArgumentException - for bad key or target too smallpublic void calculate(SessionKey key, byte[] data, int offset, int length, byte[] target, int targetOffset)
calculate in class HMACGeneratorkey - the session keydata - the data to HMACoffset - the starting offset in datalength - the lengthtarget - out parameter the first 16 bytes contain the HMAC, the last 16 bytes are zerotargetOffset - offset into target to put the hmacUnsupportedOperationException - if the JVM does not support itIllegalArgumentException - for bad key or target too smallvoid release(Mac mac)
mac - the Mac to releasepublic boolean verify(SessionKey key, byte[] curData, int curOffset, int curLength, byte[] origMAC, int origMACOffset, int origMACLength)
verify in class HMACGeneratorkey - 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 verify, use 32 for HMAC256