1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Common values for the Poly1305 algorithm 4 */ 5 6 #ifndef _CRYPTO_INTERNAL_POLY1305_H 7 #define _CRYPTO_INTERNAL_POLY1305_H 8 9 #include <crypto/poly1305.h> 10 #include <linux/types.h> 11 12 /* 13 * Poly1305 core functions. These only accept whole blocks; the caller must 14 * handle any needed block buffering and padding. 'hibit' must be 1 for any 15 * full blocks, or 0 for the final block if it had to be padded. If 'nonce' is 16 * non-NULL, then it's added at the end to compute the Poly1305 MAC. Otherwise, 17 * only the ε-almost-∆-universal hash function (not the full MAC) is computed. 18 */ 19 20 void poly1305_core_setkey(struct poly1305_core_key *key, 21 const u8 raw_key[POLY1305_BLOCK_SIZE]); 22 static inline void poly1305_core_init(struct poly1305_state *state) 23 { 24 *state = (struct poly1305_state){}; 25 } 26 27 void poly1305_core_blocks(struct poly1305_state *state, 28 const struct poly1305_core_key *key, const void *src, 29 unsigned int nblocks, u32 hibit); 30 void poly1305_core_emit(const struct poly1305_state *state, const u32 nonce[4], 31 void *dst); 32 33 void poly1305_block_init_arch(struct poly1305_block_state *state, 34 const u8 raw_key[POLY1305_BLOCK_SIZE]); 35 void poly1305_block_init_generic(struct poly1305_block_state *state, 36 const u8 raw_key[POLY1305_BLOCK_SIZE]); 37 void poly1305_blocks_arch(struct poly1305_block_state *state, const u8 *src, 38 unsigned int len, u32 padbit); 39 40 static inline void poly1305_blocks_generic(struct poly1305_block_state *state, 41 const u8 *src, unsigned int len, 42 u32 padbit) 43 { 44 poly1305_core_blocks(&state->h, &state->core_r, src, 45 len / POLY1305_BLOCK_SIZE, padbit); 46 } 47 48 void poly1305_emit_arch(const struct poly1305_state *state, 49 u8 digest[POLY1305_DIGEST_SIZE], const u32 nonce[4]); 50 51 static inline void poly1305_emit_generic(const struct poly1305_state *state, 52 u8 digest[POLY1305_DIGEST_SIZE], 53 const u32 nonce[4]) 54 { 55 poly1305_core_emit(state, nonce, digest); 56 } 57 58 #endif 59