Poly1305 computes a 128-bit (16 bytes) authenticator, using a 128 bit nonce and a 256 bit key consisting of a 128 bit key applied to an underlying cipher, and a 128 bit key (with 106 effective key bits) used in the authenticator.
The polynomial calculation in this implementation is adapted from the public domain poly1305-donna-unrolled C implementation by Andrew M (@floodyberry).
Poly1305KeyGenerator
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private final BlockCipher | |
| private final byte[] | currentBlock
Current block of buffered input |
| private int | currentBlockOffset
Current offset in input buffer |
| private int | h0
Polynomial accumulator |
| private int | h1
Polynomial accumulator |
| private int | h2
Polynomial accumulator |
| private int | h3
Polynomial accumulator |
| private int | h4
Polynomial accumulator |
| private int | k0
Encrypted nonce |
| private int | k1
Encrypted nonce |
| private int | k2
Encrypted nonce |
| private int | k3
Encrypted nonce |
| private int | r0
Polynomial key |
| private int | r1
Polynomial key |
| private int | r2
Polynomial key |
| private int | r3
Polynomial key |
| private int | r4
Polynomial key |
| private int | s1
Precomputed 5 * r[1..4] |
| private int | s2
Precomputed 5 * r[1..4] |
| private int | s3
Precomputed 5 * r[1..4] |
| private int | s4
Precomputed 5 * r[1..4] |
| private final byte[] |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | doFinal(final byte[]
the array the MAC is to be output to. out, final int the offset into the out buffer the output is to start at. outOff)Implements org. |
| public String | getAlgorithmName()
Implements org. |
| public int | getMacSize()
Implements org. |
| public void | init(CipherParameters
if used with a block cipher, then a params)ParametersWithIV containing a 128 bit
nonce and a KeyParameter with a 256 bit key complying to the
Poly1305 key format, otherwise just the
KeyParameter.Implements org. |
| private static final long | |
| private void | |
| public void | |
| private void | |
| public void | update(final byte
the byte to be processed. in)Implements org. |
| public void | update(final byte[]
the array containing the input. in, final int the index in the array the data begins at. inOff, final int the length of the input starting at inOff. len)Implements org. |
| BLOCK_SIZE | back to summary |
|---|---|
| private static final int BLOCK_SIZE | |
| cipher | back to summary |
|---|---|
| private final BlockCipher cipher | |
| currentBlock | back to summary |
|---|---|
| private final byte[] currentBlock Current block of buffered input | |
| currentBlockOffset | back to summary |
|---|---|
| private int currentBlockOffset Current offset in input buffer | |
| h0 | back to summary |
|---|---|
| private int h0 Polynomial accumulator | |
| h1 | back to summary |
|---|---|
| private int h1 Polynomial accumulator | |
| h2 | back to summary |
|---|---|
| private int h2 Polynomial accumulator | |
| h3 | back to summary |
|---|---|
| private int h3 Polynomial accumulator | |
| h4 | back to summary |
|---|---|
| private int h4 Polynomial accumulator | |
| k0 | back to summary |
|---|---|
| private int k0 Encrypted nonce | |
| k1 | back to summary |
|---|---|
| private int k1 Encrypted nonce | |
| k2 | back to summary |
|---|---|
| private int k2 Encrypted nonce | |
| k3 | back to summary |
|---|---|
| private int k3 Encrypted nonce | |
| r0 | back to summary |
|---|---|
| private int r0 Polynomial key | |
| r1 | back to summary |
|---|---|
| private int r1 Polynomial key | |
| r2 | back to summary |
|---|---|
| private int r2 Polynomial key | |
| r3 | back to summary |
|---|---|
| private int r3 Polynomial key | |
| r4 | back to summary |
|---|---|
| private int r4 Polynomial key | |
| s1 | back to summary |
|---|---|
| private int s1 Precomputed 5 * r[1..4] | |
| s2 | back to summary |
|---|---|
| private int s2 Precomputed 5 * r[1..4] | |
| s3 | back to summary |
|---|---|
| private int s3 Precomputed 5 * r[1..4] | |
| s4 | back to summary |
|---|---|
| private int s4 Precomputed 5 * r[1..4] | |
| singleByte | back to summary |
|---|---|
| private final byte[] singleByte | |
| Poly1305 | back to summary |
|---|---|
| public Poly1305() Constructs a Poly1305 MAC, where the key passed to init() will be used directly. | |
| Poly1305 | back to summary |
|---|---|
| public Poly1305(final BlockCipher cipher) Constructs a Poly1305 MAC, using a 128 bit block cipher. | |
| doFinal | back to summary |
|---|---|
| public int doFinal(final byte[] out, final int outOff) throws DataLengthException, IllegalStateException Implements org. Doc from org. 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.
| |
| getAlgorithmName | back to summary |
|---|---|
| public String getAlgorithmName() Implements org. Doc from org. Return the name of the algorithm the MAC implements.
| |
| getMacSize | back to summary |
|---|---|
| public int getMacSize() Implements org. Doc from org. Return the block size for this MAC (in bytes).
| |
| init | back to summary |
|---|---|
| public void init(CipherParameters params) throws IllegalArgumentException Implements org. Initialises the Poly1305 MAC.
| |
| mul32x32_64 | back to summary |
|---|---|
| private static final long mul32x32_64(int i1, int i2) | |
| processBlock | back to summary |
|---|---|
| private void processBlock() | |
| reset | back to summary |
|---|---|
| public void reset() Implements org. Doc from org. 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). | |
| setKey | back to summary |
|---|---|
| private void setKey(final byte[] key, final byte[] nonce) | |
| update | back to summary |
|---|---|
| public void update(final byte in) throws IllegalStateException Implements org. Doc from org. add a single byte to the mac for processing.
| |
| update | back to summary |
|---|---|
| public void update(final byte[] in, final int inOff, final int len) throws DataLengthException, IllegalStateException Implements org.
| |