Package net.i2p.crypto
Class HMAC256Generator
java.lang.Object
net.i2p.crypto.HMACGenerator
net.i2p.crypto.HMAC256Generator
Calculate the HMAC-SHA256 of a key+message.
This is compatible with javax.crypto.Mac.getInstance("HmacSHA256").
As of 0.9.12, uses javax.crypto.Mac.
Warning - used by Syndie, don't break it.
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static final class
Like SecretKeySpec but doesn't copy the key in the construtor, for speed. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(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
Mac will be reset and initialized with a zero key.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 net.i2p.crypto.HMACGenerator
acquireTmp, releaseTmp
-
Constructor Details
-
HMAC256Generator
- Parameters:
context
- unused
-
-
Method Details
-
calculate
public void calculate(SessionKey key, byte[] data, int offset, int length, byte[] target, int targetOffset) Calculate the HMAC of the data with the given key. Outputs 32 bytes to target starting at targetOffset.- Specified by:
calculate
in classHMACGenerator
- Parameters:
target
- out parameter the first 16 bytes contain the HMAC, the last 16 bytes are zerotargetOffset
- offset into target to put the hmac- Throws:
UnsupportedOperationException
- if the JVM does not support itIllegalArgumentException
- for bad key or target too small- Since:
- 0.9.12 overrides HMACGenerator
-
calculate
public void calculate(byte[] key, byte[] data, int offset, int length, byte[] target, int targetOffset) Calculate the HMAC of the data with the given key. Outputs 32 bytes to target starting at targetOffset.- Parameters:
key
- first 32 bytes used as the key- Throws:
UnsupportedOperationException
- if the JVM does not support itIllegalArgumentException
- for bad key or target too small- Since:
- 0.9.38
-
verify
public 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.- Specified by:
verify
in classHMACGenerator
- Parameters:
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 verify, use 32 for HMAC256- Since:
- 0.9.12 overrides HMACGenerator
-
acquire
Mac acquire()Package private for HKDF.- Returns:
- cached or Mac.getInstance("HmacSHA256")
- Since:
- 0.9.48
-
release
Mac will be reset and initialized with a zero key. Package private for HKDF.- Since:
- 0.9.48
-