^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) * OpenSSL/Cryptogams accelerated Poly1305 transform for ARM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2019 Linaro Ltd. <ard.biesheuvel@linaro.org>
^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) #include <asm/hwcap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/neon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/simd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <crypto/internal/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <crypto/internal/poly1305.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <crypto/internal/simd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/cpufeature.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/jump_label.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) void poly1305_init_arm(void *state, const u8 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) void poly1305_blocks_arm(void *state, const u8 *src, u32 len, u32 hibit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) void poly1305_blocks_neon(void *state, const u8 *src, u32 len, u32 hibit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void poly1305_emit_arm(void *state, u8 *digest, const u32 *nonce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void __weak poly1305_blocks_neon(void *state, const u8 *src, u32 len, u32 hibit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) poly1305_init_arm(&dctx->h, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) dctx->s[0] = get_unaligned_le32(key + 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) dctx->s[1] = get_unaligned_le32(key + 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) dctx->s[2] = get_unaligned_le32(key + 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) dctx->s[3] = get_unaligned_le32(key + 28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) dctx->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) EXPORT_SYMBOL(poly1305_init_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int arm_poly1305_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) dctx->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) dctx->rset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) dctx->sset = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static void arm_poly1305_blocks(struct poly1305_desc_ctx *dctx, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u32 len, u32 hibit, bool do_neon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (unlikely(!dctx->sset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (!dctx->rset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) poly1305_init_arm(&dctx->h, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) src += POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) len -= POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) dctx->rset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (len >= POLY1305_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) dctx->s[0] = get_unaligned_le32(src + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dctx->s[1] = get_unaligned_le32(src + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) dctx->s[2] = get_unaligned_le32(src + 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) dctx->s[3] = get_unaligned_le32(src + 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) src += POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) len -= POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) dctx->sset = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (len < POLY1305_BLOCK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) len &= ~(POLY1305_BLOCK_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (static_branch_likely(&have_neon) && likely(do_neon))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) poly1305_blocks_neon(&dctx->h, src, len, hibit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) poly1305_blocks_arm(&dctx->h, src, len, hibit);
^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) static void arm_poly1305_do_update(struct poly1305_desc_ctx *dctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) const u8 *src, u32 len, bool do_neon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (unlikely(dctx->buflen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u32 bytes = min(len, POLY1305_BLOCK_SIZE - dctx->buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) memcpy(dctx->buf + dctx->buflen, src, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) src += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) len -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) dctx->buflen += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (dctx->buflen == POLY1305_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) arm_poly1305_blocks(dctx, dctx->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) POLY1305_BLOCK_SIZE, 1, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dctx->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (likely(len >= POLY1305_BLOCK_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) arm_poly1305_blocks(dctx, src, len, 1, do_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) src += round_down(len, POLY1305_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) len %= POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (unlikely(len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) dctx->buflen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) memcpy(dctx->buf, src, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int arm_poly1305_update(struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) const u8 *src, unsigned int srclen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) arm_poly1305_do_update(dctx, src, srclen, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int __maybe_unused arm_poly1305_update_neon(struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) unsigned int srclen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) bool do_neon = crypto_simd_usable() && srclen > 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (static_branch_likely(&have_neon) && do_neon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) arm_poly1305_do_update(dctx, src, srclen, do_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (static_branch_likely(&have_neon) && do_neon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void poly1305_update_arch(struct poly1305_desc_ctx *dctx, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsigned int nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) bool do_neon = IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) crypto_simd_usable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (unlikely(dctx->buflen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) u32 bytes = min(nbytes, POLY1305_BLOCK_SIZE - dctx->buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) memcpy(dctx->buf + dctx->buflen, src, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) src += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) nbytes -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) dctx->buflen += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (dctx->buflen == POLY1305_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) poly1305_blocks_arm(&dctx->h, dctx->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) POLY1305_BLOCK_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) dctx->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (likely(nbytes >= POLY1305_BLOCK_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) unsigned int len = round_down(nbytes, POLY1305_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (static_branch_likely(&have_neon) && do_neon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) unsigned int todo = min_t(unsigned int, len, SZ_4K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) poly1305_blocks_neon(&dctx->h, src, todo, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) len -= todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) src += todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) } while (len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) poly1305_blocks_arm(&dctx->h, src, len, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) src += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) nbytes %= POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (unlikely(nbytes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) dctx->buflen = nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) memcpy(dctx->buf, src, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) EXPORT_SYMBOL(poly1305_update_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) void poly1305_final_arch(struct poly1305_desc_ctx *dctx, u8 *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (unlikely(dctx->buflen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) dctx->buf[dctx->buflen++] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) memset(dctx->buf + dctx->buflen, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) POLY1305_BLOCK_SIZE - dctx->buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) poly1305_blocks_arm(&dctx->h, dctx->buf, POLY1305_BLOCK_SIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) poly1305_emit_arm(&dctx->h, dst, dctx->s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) *dctx = (struct poly1305_desc_ctx){};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) EXPORT_SYMBOL(poly1305_final_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static int arm_poly1305_final(struct shash_desc *desc, u8 *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (unlikely(!dctx->sset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) poly1305_final_arch(dctx, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static struct shash_alg arm_poly1305_algs[] = {{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .init = arm_poly1305_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) .update = arm_poly1305_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .final = arm_poly1305_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .digestsize = POLY1305_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .descsize = sizeof(struct poly1305_desc_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .base.cra_name = "poly1305",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .base.cra_driver_name = "poly1305-arm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .base.cra_priority = 150,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .base.cra_blocksize = POLY1305_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #ifdef CONFIG_KERNEL_MODE_NEON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .init = arm_poly1305_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .update = arm_poly1305_update_neon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .final = arm_poly1305_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .digestsize = POLY1305_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .descsize = sizeof(struct poly1305_desc_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .base.cra_name = "poly1305",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .base.cra_driver_name = "poly1305-neon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .base.cra_priority = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .base.cra_blocksize = POLY1305_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .base.cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int __init arm_poly1305_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) (elf_hwcap & HWCAP_NEON))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static_branch_enable(&have_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) else if (IS_REACHABLE(CONFIG_CRYPTO_HASH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* register only the first entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return crypto_register_shash(&arm_poly1305_algs[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) crypto_register_shashes(arm_poly1305_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ARRAY_SIZE(arm_poly1305_algs)) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static void __exit arm_poly1305_mod_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!IS_REACHABLE(CONFIG_CRYPTO_HASH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!static_branch_likely(&have_neon)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) crypto_unregister_shash(&arm_poly1305_algs[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) crypto_unregister_shashes(arm_poly1305_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ARRAY_SIZE(arm_poly1305_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) module_init(arm_poly1305_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) module_exit(arm_poly1305_mod_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_ALIAS_CRYPTO("poly1305");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) MODULE_ALIAS_CRYPTO("poly1305-arm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_ALIAS_CRYPTO("poly1305-neon");