diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-12 18:42:14 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-12 18:53:11 +0200 |
commit | 70d2d999761bf913f26299f748041a989ff2d983 (patch) | |
tree | 601251a7a9c4b7597ae4e46bfa8fd12fb92f1b1d /src/crypto/zinc/poly1305/poly1305-donna64.h | |
parent | 1a6ae009c4d296f6cf70656d167932b2e8afa04a (diff) |
poly1305: precompute 5*r in init instead of blocks
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/zinc/poly1305/poly1305-donna64.h')
-rw-r--r-- | src/crypto/zinc/poly1305/poly1305-donna64.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/crypto/zinc/poly1305/poly1305-donna64.h b/src/crypto/zinc/poly1305/poly1305-donna64.h index 2aa2570..de7ab12 100644 --- a/src/crypto/zinc/poly1305/poly1305-donna64.h +++ b/src/crypto/zinc/poly1305/poly1305-donna64.h @@ -11,6 +11,7 @@ typedef __uint128_t u128; struct poly1305_internal { u64 r[3]; u64 h[3]; + u64 s[2]; }; static void poly1305_init_generic(void *ctx, const u8 key[16]) @@ -26,6 +27,10 @@ static void poly1305_init_generic(void *ctx, const u8 key[16]) st->r[1] = ((t0 >> 44) | (t1 << 20)) & 0xfffffc0ffff; st->r[2] = ((t1 >> 24)) & 0x00ffffffc0f; + /* s = 20*r */ + st->s[0] = st->r[1] * 20; + st->s[1] = st->r[2] * 20; + /* h = 0 */ st->h[0] = 0; st->h[1] = 0; @@ -51,8 +56,8 @@ static void poly1305_blocks_generic(void *ctx, const u8 *input, size_t len, h1 = st->h[1]; h2 = st->h[2]; - s1 = r1 * (5 << 2); - s2 = r2 * (5 << 2); + s1 = st->s[0]; + s2 = st->s[1]; while (len >= POLY1305_BLOCK_SIZE) { u64 t0, t1; |