Implementation of SipHash as specified in "SipHash: a fast short-input PRF", by Jean-Philippe Aumasson and Daniel J. Bernstein (https://131002.net/siphash/siphash.pdf). "SipHash is a family of PRFs SipHash-c-d where the integer parameters c and d are the number of compression rounds and the numb
| 16 | * (possibly empty) byte string m, SipHash-c-d returns a 64-bit value..." |
| 17 | */ |
| 18 | public class SipHash |
| 19 | implements Mac |
| 20 | { |
| 21 | protected final int c, d; |
| 22 | |
| 23 | protected long k0, k1; |
| 24 | protected long v0, v1, v2, v3; |
| 25 | |
| 26 | protected long m = 0; |
| 27 | protected int wordPos = 0; |
| 28 | protected int wordCount = 0; |
| 29 | |
| 30 | /** |
| 31 | * SipHash-2-4 |
| 32 | */ |
| 33 | public SipHash() |
| 34 | { |
| 35 | // use of 'this' confuses the flow analyser on earlier JDKs. |
| 36 | this.c = 2; |
| 37 | this.d = 4; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * SipHash-c-d |
| 42 | * |
| 43 | * @param c the number of compression rounds |
| 44 | * @param d the number of finalization rounds |
| 45 | */ |
| 46 | public SipHash(int c, int d) |
| 47 | { |
| 48 | this.c = c; |
| 49 | this.d = d; |
| 50 | } |
| 51 | |
| 52 | public String getAlgorithmName() |
| 53 | { |
| 54 | return "SipHash-" + c + "-" + d; |
| 55 | } |
| 56 | |
| 57 | public int getMacSize() |
| 58 | { |
| 59 | return 8; |
| 60 | } |
| 61 | |
| 62 | public void init(CipherParameters params) |
| 63 | throws IllegalArgumentException |
| 64 | { |
| 65 | if (!(params instanceof KeyParameter)) |
| 66 | { |
| 67 | throw new IllegalArgumentException("'params' must be an instance of KeyParameter"); |
| 68 | } |
| 69 | KeyParameter keyParameter = (KeyParameter)params; |
| 70 | byte[] key = keyParameter.getKey(); |
| 71 | if (key.length != 16) |
| 72 | { |
| 73 | throw new IllegalArgumentException("'params' must be a 128-bit key"); |
| 74 | } |
| 75 |
nothing calls this directly
no outgoing calls
no test coverage detected