Fast Poly1305 MAC implementation #27
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fast implementation of Poly1305 message authentication code, with tests and JCE registrations.
Poly1305 was designed by D.J. Bernstein and is used in the nacl and libsodium libraries (and various ports of these).
The fast polynomial calculation in this implementation is adapted from the public domain 'poly1305-donna-unrolled' C implementation by Andrew M (@floodyberry) (https://github.com/floodyberry/poly1305-donna) - primarily adapting to Java signed integer arithmetic.
JCE registrations are provided for Poly1305-* for 128 bit AES era block ciphers (AES, Serpent, Twofish etc.)
Test cases generated from poly1305 reference and nacl implementations included.
Throughput tests for MACs included to compare Poly1305 performance against reference implementation and other MACs.
Throughput testing of this implementation gives a result of about 12.7/7.3/7.0 cycles per byte for 16/256/8192 byte messages (on a 2.5GHz Core i5 Macbook Pro laptop).
This compares well with 176/29/19 for HMAC-SHA1, 43/33/31 for AES-CMAC, 120/44/37 for AES-GMAC, 124/20/15 for Skein-MAC, 23/14/13 for (unoptimised) SipHash.
It's also substantially faster than the Poly1305 'ref' implementation used in simple Java ports, which records 90/76/76 c/b in Java.