public class SipHash extends java.lang.Object implements Mac
"SipHash is a family of PRFs SipHash-c-d where the integer parameters c and d are the number of compression rounds and the number of finalization rounds. A compression round is identical to a finalization round and this round function is called SipRound. Given a 128-bit key k and a (possibly empty) byte string m, SipHash-c-d returns a 64-bit value..."
Modifier and Type | Field and Description |
---|---|
protected int |
c |
protected int |
d |
protected long |
k0 |
protected long |
k1 |
protected long |
m |
protected long |
v0 |
protected long |
v1 |
protected long |
v2 |
protected long |
v3 |
protected int |
wordCount |
protected int |
wordPos |
Constructor and Description |
---|
SipHash()
SipHash-2-4
|
SipHash(int c,
int d)
SipHash-c-d
|
Modifier and Type | Method and Description |
---|---|
protected void |
applySipRounds(int n) |
long |
doFinal() |
int |
doFinal(byte[] out,
int outOff)
Compute the final stage of the MAC writing the output to the out
parameter.
|
java.lang.String |
getAlgorithmName()
Return the name of the algorithm the MAC implements.
|
int |
getMacSize()
Return the block size for this MAC (in bytes).
|
void |
init(CipherParameters params)
Initialise the MAC.
|
protected void |
processMessageWord() |
void |
reset()
Reset the MAC.
|
protected static long |
rotateLeft(long x,
int n) |
void |
update(byte input)
add a single byte to the mac for processing.
|
void |
update(byte[] input,
int offset,
int length) |
protected final int c
protected final int d
protected long k0
protected long k1
protected long v0
protected long v1
protected long v2
protected long v3
protected long m
protected int wordPos
protected int wordCount
public SipHash()
public SipHash(int c, int d)
c
- the number of compression roundsd
- the number of finalization roundspublic java.lang.String getAlgorithmName()
Mac
getAlgorithmName
in interface Mac
public int getMacSize()
Mac
getMacSize
in interface Mac
public void init(CipherParameters params) throws java.lang.IllegalArgumentException
Mac
public void update(byte input) throws java.lang.IllegalStateException
Mac
public void update(byte[] input, int offset, int length) throws DataLengthException, java.lang.IllegalStateException
update
in interface Mac
input
- the array containing the input.offset
- the index in the array the data begins at.length
- the length of the input starting at inOff.DataLengthException
- if there isn't enough data in in.java.lang.IllegalStateException
- if the MAC is not initialised.public long doFinal() throws DataLengthException, java.lang.IllegalStateException
DataLengthException
java.lang.IllegalStateException
public int doFinal(byte[] out, int outOff) throws DataLengthException, java.lang.IllegalStateException
Mac
doFinal leaves the MAC in the same state it was after the last init.
doFinal
in interface Mac
out
- the array the MAC is to be output to.outOff
- the offset into the out buffer the output is to start at.DataLengthException
- if there isn't enough space in out.java.lang.IllegalStateException
- if the MAC is not initialised.public void reset()
Mac
protected void processMessageWord()
protected void applySipRounds(int n)
protected static long rotateLeft(long x, int n)