public class Poly1305
extends javax.crypto.MacSpi
An application wishing to perform a MAC computation, at first has to create a
Mac object by instantiating the Mac
class through a proper
getInstance
factory method thereby specifying the MAC algorithm
to be used. Calculating a MAC based on the Poly1305 algorithm, may be
initiated as follows:
Mac poly1305Mac = Mac.getInstance("Poly1305");After properly initializing the Mac object with one entities secret key, the data to be processed is applied by one (or more) calls to the
update
methods. The MAC computation is concluded by using
doFinal
. If the data can be processed without calling any
update
method, doFinal
can be called immediately
after initializing the MAC object:
poly1305Mac.init(secret_key); byte[] mac_data = poly1305Mac.doFinal(data);After the MAC finally has been calculated, the Mac object automatically is reset for being able to be used for further MAC computations, either by using the same secret key again, or using a new key by properly re-initializing this Mac object.
Constructor and Description |
---|
Poly1305()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
engineDoFinal()
Calculate the MAC and reset this Mac object to be ready for further
MAC calculations.
|
protected int |
engineGetMacLength() |
protected void |
engineInit(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Initialize the Mac with the given 32 byte key.
|
protected void |
engineReset()
Reset this Mac object to be ready for a new MAC computation.
|
protected void |
engineUpdate(byte input)
Feed a single byte into the Mac.
|
protected void |
engineUpdate(byte[] input,
int offset,
int len)
Feed in a block of bytes into this Mac.
|
public Poly1305()
Applications shall not use this constructor. They shall use
Mac.getInstance("Poly1305", "IAIK");for creating a Mac object for the Poly1305 algorithm.
NoSuchAlgorithmException
- if there is no implementation for SHAprotected int engineGetMacLength()
engineGetMacLength
in class javax.crypto.MacSpi
protected void engineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
engineInit
in class javax.crypto.MacSpi
key
- The MAC key.params
- This implementation ignores this parameter.java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
protected void engineUpdate(byte input)
For better performance, use engineUpdate(byte[], int, int)
and feed in larger blocks.
engineUpdate
in class javax.crypto.MacSpi
input
- The input byte.protected void engineUpdate(byte[] input, int offset, int len)
engineUpdate
in class javax.crypto.MacSpi
input
- The data buffer.offset
- The start index in the buffer.len
- The length of the data block in the buffer.protected byte[] engineDoFinal()
engineDoFinal
in class javax.crypto.MacSpi
protected void engineReset()
engineReset
in class javax.crypto.MacSpi