Top Description Fields Constructors Methods
org.bouncycastle.crypto.macs

public Class SipHash

extends Object
implements Mac
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.Mac
Known Direct Subclasses
org.bouncycastle.crypto.macs.SipHash128
Imports
org.bouncycastle.crypto.CipherParameters, .DataLengthException, .Mac, org.bouncycastle.crypto.params.KeyParameter, org.bouncycastle.util.Pack

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 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..."

Field Summary

Modifier and TypeField and Description
protected final int
c

protected final int
d

protected long
protected long
protected long
m

protected long
protected long
protected long
protected long
protected int
protected int

Constructor Summary

AccessConstructor and Description
public
SipHash()

SipHash-2-4

public
SipHash(int
the number of compression rounds
c
,
int
the number of finalization rounds
d
)

SipHash-c-d

Method Summary

Modifier and TypeMethod and Description
protected void
public long
public int
doFinal(byte[]
the array the MAC is to be output to.
out
,
int
the offset into the out buffer the output is to start at.
outOff
)

Implements org.bouncycastle.crypto.Mac.doFinal.

Compute the final stage of the MAC writing the output to the out parameter.

public String
getAlgorithmName()

Implements org.bouncycastle.crypto.Mac.getAlgorithmName.

Return the name of the algorithm the MAC implements.

public int
getMacSize()

Implements org.bouncycastle.crypto.Mac.getMacSize.

Return the block size for this MAC (in bytes).

public void
init(CipherParameters
the key and other data required by the MAC.
params
)

Implements org.bouncycastle.crypto.Mac.init.

Initialise the MAC.

protected void
public void
reset()

Implements org.bouncycastle.crypto.Mac.reset.

Reset the MAC.

protected static long
rotateLeft(long x, int n)

public void
update(byte
the byte to be processed.
input
)

Implements org.bouncycastle.crypto.Mac.update.

add a single byte to the mac for processing.

public void
update(byte[]
the array containing the input.
input
,
int
the index in the array the data begins at.
offset
,
int
the length of the input starting at inOff.
length
)

Implements org.bouncycastle.crypto.Mac.update.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cback to summary
protected final int c
dback to summary
protected final int d
k0back to summary
protected long k0
k1back to summary
protected long k1
mback to summary
protected long m
v0back to summary
protected long v0
v1back to summary
protected long v1
v2back to summary
protected long v2
v3back to summary
protected long v3
wordCountback to summary
protected int wordCount
wordPosback to summary
protected int wordPos

Constructor Detail

SipHashback to summary
public SipHash()

SipHash-2-4

SipHashback to summary
public SipHash(int c, int d)

SipHash-c-d

Parameters
c:int

the number of compression rounds

d:int

the number of finalization rounds

Method Detail

applySipRoundsback to summary
protected void applySipRounds(int n)
doFinalback to summary
public long doFinal() throws DataLengthException, IllegalStateException
doFinalback to summary
public int doFinal(byte[] out, int outOff) throws DataLengthException, IllegalStateException

Implements org.bouncycastle.crypto.Mac.doFinal.

Doc from org.bouncycastle.crypto.Mac.doFinal.

Compute the final stage of the MAC writing the output to the out parameter.

doFinal leaves the MAC in the same state it was after the last init.

Parameters
out:byte[]

the array the MAC is to be output to.

outOff:int

the offset into the out buffer the output is to start at.

Exceptions
DataLengthException:
if there isn't enough space in out.
IllegalStateException:
if the MAC is not initialised.
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.Mac.getAlgorithmName.

Doc from org.bouncycastle.crypto.Mac.getAlgorithmName.

Return the name of the algorithm the MAC implements.

Returns:String

the name of the algorithm the MAC implements.

getMacSizeback to summary
public int getMacSize()

Implements org.bouncycastle.crypto.Mac.getMacSize.

Doc from org.bouncycastle.crypto.Mac.getMacSize.

Return the block size for this MAC (in bytes).

Returns:int

the block size for this MAC in bytes.

initback to summary
public void init(CipherParameters params) throws IllegalArgumentException

Implements org.bouncycastle.crypto.Mac.init.

Doc from org.bouncycastle.crypto.Mac.init.

Initialise the MAC.

Parameters
params:CipherParameters

the key and other data required by the MAC.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
processMessageWordback to summary
protected void processMessageWord()
resetback to summary
public void reset()

Implements org.bouncycastle.crypto.Mac.reset.

Doc from org.bouncycastle.crypto.Mac.reset.

Reset the MAC. At the end of resetting the MAC should be in the in the same state it was after the last init (if there was one).

rotateLeftback to summary
protected static long rotateLeft(long x, int n)
updateback to summary
public void update(byte input) throws IllegalStateException

Implements org.bouncycastle.crypto.Mac.update.

Doc from org.bouncycastle.crypto.Mac.update.

add a single byte to the mac for processing.

Parameters
input:byte

the byte to be processed.

Exceptions
IllegalStateException:
if the MAC is not initialised.
updateback to summary
public void update(byte[] input, int offset, int length) throws DataLengthException, IllegalStateException

Implements org.bouncycastle.crypto.Mac.update.

Parameters
input:byte[]

Doc from org.bouncycastle.crypto.Mac.update.

the array containing the input.

offset:int

Doc from org.bouncycastle.crypto.Mac.update.

the index in the array the data begins at.

length:int

Doc from org.bouncycastle.crypto.Mac.update.

the length of the input starting at inOff.

Exceptions
DataLengthException:

Doc from org.bouncycastle.crypto.Mac.update.

if there isn't enough data in in.

IllegalStateException:

Doc from org.bouncycastle.crypto.Mac.update.

if the MAC is not initialised.