1c08a10436
These two C implementations from Zinc -- a 32x32 one and a 64x64 one, depending on the platform -- come from Andrew Moon's public domain poly1305-donna portable code, modified for usage in the kernel. The precomputation in the 32-bit version and the use of 64x64 multiplies in the 64-bit version make these perform better than the code it replaces. Moon's code is also very widespread and has received many eyeballs of scrutiny. There's a bit of interference between the x86 implementation, which relies on internal details of the old scalar implementation. In the next commit, the x86 implementation will be replaced with a faster one that doesn't rely on this, so none of this matters much. But for now, to keep this passing the tests, we inline the bits of the old implementation that the x86 implementation relied on. Also, since we now support a slightly larger key space, via the union, some offsets had to be fixed up. Nonce calculation was folded in with the emit function, to take advantage of 64x64 arithmetic. However, Adiantum appeared to rely on no nonce handling in emit, so this path was conditionalized. We also introduced a new struct, poly1305_core_key, to represent the precise amount of space that particular implementation uses. Testing with kbench9000, depending on the CPU, the update function for the 32x32 version has been improved by 4%-7%, and for the 64x64 by 19%-30%. The 32x32 gains are small, but I think there's great value in having a parallel implementation to the 64x64 one so that the two can be compared side-by-side as nice stand-alone units. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
34 lines
1.1 KiB
C
34 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Common values for the Poly1305 algorithm
|
|
*/
|
|
|
|
#ifndef _CRYPTO_INTERNAL_POLY1305_H
|
|
#define _CRYPTO_INTERNAL_POLY1305_H
|
|
|
|
#include <asm/unaligned.h>
|
|
#include <linux/types.h>
|
|
#include <crypto/poly1305.h>
|
|
|
|
/*
|
|
* Poly1305 core functions. These only accept whole blocks; the caller must
|
|
* handle any needed block buffering and padding. 'hibit' must be 1 for any
|
|
* full blocks, or 0 for the final block if it had to be padded. If 'nonce' is
|
|
* non-NULL, then it's added at the end to compute the Poly1305 MAC. Otherwise,
|
|
* only the ε-almost-∆-universal hash function (not the full MAC) is computed.
|
|
*/
|
|
|
|
void poly1305_core_setkey(struct poly1305_core_key *key, const u8 *raw_key);
|
|
static inline void poly1305_core_init(struct poly1305_state *state)
|
|
{
|
|
*state = (struct poly1305_state){};
|
|
}
|
|
|
|
void poly1305_core_blocks(struct poly1305_state *state,
|
|
const struct poly1305_core_key *key, const void *src,
|
|
unsigned int nblocks, u32 hibit);
|
|
void poly1305_core_emit(const struct poly1305_state *state, const u32 nonce[4],
|
|
void *dst);
|
|
|
|
#endif
|