^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * NHPoly1305 - ε-almost-∆-universal hash function for Adiantum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2018 Google LLC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * "NHPoly1305" is the main component of Adiantum hashing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Specifically, it is the calculation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * H_L ← Poly1305_{K_L}(NH_{K_N}(pad_{128}(L)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * from the procedure in section 6.4 of the Adiantum paper [1]. It is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * ε-almost-∆-universal (ε-∆U) hash function for equal-length inputs over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Z/(2^{128}Z), where the "∆" operation is addition. It hashes 1024-byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * chunks of the input with the NH hash function [2], reducing the input length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * by 32x. The resulting NH digests are evaluated as a polynomial in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * GF(2^{130}-5), like in the Poly1305 MAC [3]. Note that the polynomial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * evaluation by itself would suffice to achieve the ε-∆U property; NH is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * for performance since it's over twice as fast as Poly1305.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * This is *not* a cryptographic hash function; do not use it as such!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * [1] Adiantum: length-preserving encryption for entry-level processors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * (https://eprint.iacr.org/2018/720.pdf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * [2] UMAC: Fast and Secure Message Authentication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * (https://fastcrypto.org/umac/umac_proc.pdf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * [3] The Poly1305-AES message-authentication code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * (https://cr.yp.to/mac/poly1305-20050329.pdf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <crypto/internal/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <crypto/internal/poly1305.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <crypto/nhpoly1305.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static void nh_generic(const u32 *key, const u8 *message, size_t message_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __le64 hash[NH_NUM_PASSES])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u64 sums[4] = { 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) BUILD_BUG_ON(NH_PAIR_STRIDE != 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) BUILD_BUG_ON(NH_NUM_PASSES != 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) while (message_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u32 m0 = get_unaligned_le32(message + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u32 m1 = get_unaligned_le32(message + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u32 m2 = get_unaligned_le32(message + 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u32 m3 = get_unaligned_le32(message + 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) sums[0] += (u64)(u32)(m0 + key[ 0]) * (u32)(m2 + key[ 2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) sums[1] += (u64)(u32)(m0 + key[ 4]) * (u32)(m2 + key[ 6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) sums[2] += (u64)(u32)(m0 + key[ 8]) * (u32)(m2 + key[10]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) sums[3] += (u64)(u32)(m0 + key[12]) * (u32)(m2 + key[14]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) sums[0] += (u64)(u32)(m1 + key[ 1]) * (u32)(m3 + key[ 3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) sums[1] += (u64)(u32)(m1 + key[ 5]) * (u32)(m3 + key[ 7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) sums[2] += (u64)(u32)(m1 + key[ 9]) * (u32)(m3 + key[11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) sums[3] += (u64)(u32)(m1 + key[13]) * (u32)(m3 + key[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) key += NH_MESSAGE_UNIT / sizeof(key[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) message += NH_MESSAGE_UNIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) message_len -= NH_MESSAGE_UNIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) hash[0] = cpu_to_le64(sums[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) hash[1] = cpu_to_le64(sums[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) hash[2] = cpu_to_le64(sums[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) hash[3] = cpu_to_le64(sums[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* Pass the next NH hash value through Poly1305 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static void process_nh_hash_value(struct nhpoly1305_state *state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const struct nhpoly1305_key *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) BUILD_BUG_ON(NH_HASH_BYTES % POLY1305_BLOCK_SIZE != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) poly1305_core_blocks(&state->poly_state, &key->poly_key, state->nh_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) NH_HASH_BYTES / POLY1305_BLOCK_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Feed the next portion of the source data, as a whole number of 16-byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * "NH message units", through NH and Poly1305. Each NH hash is taken over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * 1024 bytes, except possibly the final one which is taken over a multiple of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * 16 bytes up to 1024. Also, in the case where data is passed in misaligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * chunks, we combine partial hashes; the end result is the same either way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void nhpoly1305_units(struct nhpoly1305_state *state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) const struct nhpoly1305_key *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) const u8 *src, unsigned int srclen, nh_t nh_fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned int bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (state->nh_remaining == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* Starting a new NH message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) bytes = min_t(unsigned int, srclen, NH_MESSAGE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) nh_fn(key->nh_key, src, bytes, state->nh_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) state->nh_remaining = NH_MESSAGE_BYTES - bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Continuing a previous NH message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) __le64 tmp_hash[NH_NUM_PASSES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned int pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) pos = NH_MESSAGE_BYTES - state->nh_remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) bytes = min(srclen, state->nh_remaining);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) nh_fn(&key->nh_key[pos / 4], src, bytes, tmp_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) for (i = 0; i < NH_NUM_PASSES; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) le64_add_cpu(&state->nh_hash[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) le64_to_cpu(tmp_hash[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) state->nh_remaining -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (state->nh_remaining == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) process_nh_hash_value(state, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) src += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) srclen -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) } while (srclen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int crypto_nhpoly1305_setkey(struct crypto_shash *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) const u8 *key, unsigned int keylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct nhpoly1305_key *ctx = crypto_shash_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (keylen != NHPOLY1305_KEY_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) poly1305_core_setkey(&ctx->poly_key, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) key += POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) for (i = 0; i < NH_KEY_WORDS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ctx->nh_key[i] = get_unaligned_le32(key + i * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) EXPORT_SYMBOL(crypto_nhpoly1305_setkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int crypto_nhpoly1305_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct nhpoly1305_state *state = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) poly1305_core_init(&state->poly_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) state->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) state->nh_remaining = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) EXPORT_SYMBOL(crypto_nhpoly1305_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int crypto_nhpoly1305_update_helper(struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) const u8 *src, unsigned int srclen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) nh_t nh_fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct nhpoly1305_state *state = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) const struct nhpoly1305_key *key = crypto_shash_ctx(desc->tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) unsigned int bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (state->buflen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) bytes = min(srclen, (int)NH_MESSAGE_UNIT - state->buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) memcpy(&state->buffer[state->buflen], src, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) state->buflen += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (state->buflen < NH_MESSAGE_UNIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) nhpoly1305_units(state, key, state->buffer, NH_MESSAGE_UNIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) nh_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) state->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) src += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) srclen -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (srclen >= NH_MESSAGE_UNIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) bytes = round_down(srclen, NH_MESSAGE_UNIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) nhpoly1305_units(state, key, src, bytes, nh_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) src += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) srclen -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (srclen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) memcpy(state->buffer, src, srclen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) state->buflen = srclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) EXPORT_SYMBOL(crypto_nhpoly1305_update_helper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int crypto_nhpoly1305_update(struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) const u8 *src, unsigned int srclen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return crypto_nhpoly1305_update_helper(desc, src, srclen, nh_generic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) EXPORT_SYMBOL(crypto_nhpoly1305_update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int crypto_nhpoly1305_final_helper(struct shash_desc *desc, u8 *dst, nh_t nh_fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct nhpoly1305_state *state = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) const struct nhpoly1305_key *key = crypto_shash_ctx(desc->tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (state->buflen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) memset(&state->buffer[state->buflen], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) NH_MESSAGE_UNIT - state->buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) nhpoly1305_units(state, key, state->buffer, NH_MESSAGE_UNIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) nh_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (state->nh_remaining)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) process_nh_hash_value(state, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) poly1305_core_emit(&state->poly_state, NULL, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) EXPORT_SYMBOL(crypto_nhpoly1305_final_helper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) int crypto_nhpoly1305_final(struct shash_desc *desc, u8 *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return crypto_nhpoly1305_final_helper(desc, dst, nh_generic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) EXPORT_SYMBOL(crypto_nhpoly1305_final);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static struct shash_alg nhpoly1305_alg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .base.cra_name = "nhpoly1305",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .base.cra_driver_name = "nhpoly1305-generic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .base.cra_priority = 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .base.cra_ctxsize = sizeof(struct nhpoly1305_key),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .digestsize = POLY1305_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .init = crypto_nhpoly1305_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .update = crypto_nhpoly1305_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .final = crypto_nhpoly1305_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .setkey = crypto_nhpoly1305_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .descsize = sizeof(struct nhpoly1305_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int __init nhpoly1305_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return crypto_register_shash(&nhpoly1305_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static void __exit nhpoly1305_mod_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) crypto_unregister_shash(&nhpoly1305_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) subsys_initcall(nhpoly1305_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) module_exit(nhpoly1305_mod_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MODULE_DESCRIPTION("NHPoly1305 ε-almost-∆-universal hash function");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) MODULE_AUTHOR("Eric Biggers <ebiggers@google.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) MODULE_ALIAS_CRYPTO("nhpoly1305");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) MODULE_ALIAS_CRYPTO("nhpoly1305-generic");