0001
0002
0003
0004
0005
0006 #ifndef _NHPOLY1305_H
0007 #define _NHPOLY1305_H
0008
0009 #include <crypto/hash.h>
0010 #include <crypto/internal/poly1305.h>
0011
0012
0013
0014
0015
0016
0017
0018 #define NH_PAIR_STRIDE 2
0019 #define NH_MESSAGE_UNIT (NH_PAIR_STRIDE * 2 * sizeof(u32))
0020
0021
0022 #define NH_NUM_PASSES 4
0023 #define NH_HASH_BYTES (NH_NUM_PASSES * sizeof(u64))
0024
0025
0026 #define NH_NUM_STRIDES 64
0027 #define NH_MESSAGE_WORDS (NH_PAIR_STRIDE * 2 * NH_NUM_STRIDES)
0028 #define NH_MESSAGE_BYTES (NH_MESSAGE_WORDS * sizeof(u32))
0029 #define NH_KEY_WORDS (NH_MESSAGE_WORDS + \
0030 NH_PAIR_STRIDE * 2 * (NH_NUM_PASSES - 1))
0031 #define NH_KEY_BYTES (NH_KEY_WORDS * sizeof(u32))
0032
0033 #define NHPOLY1305_KEY_SIZE (POLY1305_BLOCK_SIZE + NH_KEY_BYTES)
0034
0035 struct nhpoly1305_key {
0036 struct poly1305_core_key poly_key;
0037 u32 nh_key[NH_KEY_WORDS];
0038 };
0039
0040 struct nhpoly1305_state {
0041
0042
0043 struct poly1305_state poly_state;
0044
0045
0046 u8 buffer[NH_MESSAGE_UNIT];
0047 unsigned int buflen;
0048
0049
0050
0051
0052
0053 unsigned int nh_remaining;
0054
0055 __le64 nh_hash[NH_NUM_PASSES];
0056 };
0057
0058 typedef void (*nh_t)(const u32 *key, const u8 *message, size_t message_len,
0059 __le64 hash[NH_NUM_PASSES]);
0060
0061 int crypto_nhpoly1305_setkey(struct crypto_shash *tfm,
0062 const u8 *key, unsigned int keylen);
0063
0064 int crypto_nhpoly1305_init(struct shash_desc *desc);
0065 int crypto_nhpoly1305_update(struct shash_desc *desc,
0066 const u8 *src, unsigned int srclen);
0067 int crypto_nhpoly1305_update_helper(struct shash_desc *desc,
0068 const u8 *src, unsigned int srclen,
0069 nh_t nh_fn);
0070 int crypto_nhpoly1305_final(struct shash_desc *desc, u8 *dst);
0071 int crypto_nhpoly1305_final_helper(struct shash_desc *desc, u8 *dst,
0072 nh_t nh_fn);
0073
0074 #endif