bcgit/bc-java — pull request #27 by timw (2013-07-17 11:41:52+00:00)
Title: Fast Poly1305 MAC implementation

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.