blob: 0c0b83a91b91aea4e4466b0bbe5e8ea8692b8147 [file] [log] [blame]
Martin Willi2546f812015-07-16 19:14:05 +02001/*
2 * Common values for the Poly1305 algorithm
3 */
4
5#ifndef _CRYPTO_POLY1305_H
6#define _CRYPTO_POLY1305_H
7
8#include <linux/types.h>
9#include <linux/crypto.h>
10
11#define POLY1305_BLOCK_SIZE 16
12#define POLY1305_KEY_SIZE 32
13#define POLY1305_DIGEST_SIZE 16
14
Eric Biggers888679d2018-11-16 17:26:27 -080015struct poly1305_key {
16 u32 r[5]; /* key, base 2^26 */
17};
18
19struct poly1305_state {
20 u32 h[5]; /* accumulator, base 2^26 */
21};
22
Martin Willi2546f812015-07-16 19:14:05 +020023struct poly1305_desc_ctx {
24 /* key */
Eric Biggers888679d2018-11-16 17:26:27 -080025 struct poly1305_key r;
Martin Willi2546f812015-07-16 19:14:05 +020026 /* finalize key */
27 u32 s[4];
28 /* accumulator */
Eric Biggers888679d2018-11-16 17:26:27 -080029 struct poly1305_state h;
Martin Willi2546f812015-07-16 19:14:05 +020030 /* partial buffer */
31 u8 buf[POLY1305_BLOCK_SIZE];
32 /* bytes used in partial buffer */
33 unsigned int buflen;
34 /* r key has been set */
35 bool rset;
36 /* s key has been set */
37 bool sset;
38};
39
Eric Biggerscc786be2018-11-16 17:26:28 -080040/*
41 * Poly1305 core functions. These implement the ε-almost-∆-universal hash
42 * function underlying the Poly1305 MAC, i.e. they don't add an encrypted nonce
43 * ("s key") at the end. They also only support block-aligned inputs.
44 */
45void poly1305_core_setkey(struct poly1305_key *key, const u8 *raw_key);
46static inline void poly1305_core_init(struct poly1305_state *state)
47{
48 memset(state->h, 0, sizeof(state->h));
49}
50void poly1305_core_blocks(struct poly1305_state *state,
51 const struct poly1305_key *key,
52 const void *src, unsigned int nblocks);
53void poly1305_core_emit(const struct poly1305_state *state, void *dst);
54
55/* Crypto API helper functions for the Poly1305 MAC */
Martin Willi2546f812015-07-16 19:14:05 +020056int crypto_poly1305_init(struct shash_desc *desc);
Martin Willi2546f812015-07-16 19:14:05 +020057unsigned int crypto_poly1305_setdesckey(struct poly1305_desc_ctx *dctx,
58 const u8 *src, unsigned int srclen);
59int crypto_poly1305_update(struct shash_desc *desc,
60 const u8 *src, unsigned int srclen);
61int crypto_poly1305_final(struct shash_desc *desc, u8 *dst);
62
63#endif