Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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 arm64
^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) asmlinkage void poly1305_init_arm64(void *state, const u8 *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) asmlinkage void poly1305_blocks(void *state, const u8 *src, u32 len, u32 hibit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) asmlinkage void poly1305_blocks_neon(void *state, const u8 *src, u32 len, u32 hibit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) asmlinkage void poly1305_emit(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) static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	poly1305_init_arm64(&dctx->h, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	dctx->s[0] = get_unaligned_le32(key + 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	dctx->s[1] = get_unaligned_le32(key + 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	dctx->s[2] = get_unaligned_le32(key + 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	dctx->s[3] = get_unaligned_le32(key + 28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	dctx->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) EXPORT_SYMBOL(poly1305_init_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int neon_poly1305_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	dctx->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	dctx->rset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	dctx->sset = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static void neon_poly1305_blocks(struct poly1305_desc_ctx *dctx, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				 u32 len, u32 hibit, bool do_neon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (unlikely(!dctx->sset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		if (!dctx->rset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			poly1305_init_arch(dctx, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			src += POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			len -= POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			dctx->rset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		if (len >= POLY1305_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			dctx->s[0] = get_unaligned_le32(src +  0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			dctx->s[1] = get_unaligned_le32(src +  4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			dctx->s[2] = get_unaligned_le32(src +  8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			dctx->s[3] = get_unaligned_le32(src + 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			src += POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			len -= POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			dctx->sset = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		if (len < POLY1305_BLOCK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	len &= ~(POLY1305_BLOCK_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (static_branch_likely(&have_neon) && likely(do_neon))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		poly1305_blocks_neon(&dctx->h, src, len, hibit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		poly1305_blocks(&dctx->h, src, len, hibit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static void neon_poly1305_do_update(struct poly1305_desc_ctx *dctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 				    const u8 *src, u32 len, bool do_neon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (unlikely(dctx->buflen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		u32 bytes = min(len, POLY1305_BLOCK_SIZE - dctx->buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		memcpy(dctx->buf + dctx->buflen, src, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		src += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		len -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		dctx->buflen += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (dctx->buflen == POLY1305_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			neon_poly1305_blocks(dctx, dctx->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 					     POLY1305_BLOCK_SIZE, 1, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			dctx->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (likely(len >= POLY1305_BLOCK_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		neon_poly1305_blocks(dctx, src, len, 1, do_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		src += round_down(len, POLY1305_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		len %= POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (unlikely(len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		dctx->buflen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		memcpy(dctx->buf, src, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int neon_poly1305_update(struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				const u8 *src, unsigned int srclen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	bool do_neon = crypto_simd_usable() && srclen > 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (static_branch_likely(&have_neon) && do_neon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	neon_poly1305_do_update(dctx, src, srclen, do_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (static_branch_likely(&have_neon) && do_neon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return 0;
^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) void poly1305_update_arch(struct poly1305_desc_ctx *dctx, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			  unsigned int nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (unlikely(dctx->buflen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		u32 bytes = min(nbytes, POLY1305_BLOCK_SIZE - dctx->buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		memcpy(dctx->buf + dctx->buflen, src, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		src += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		nbytes -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		dctx->buflen += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (dctx->buflen == POLY1305_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			poly1305_blocks(&dctx->h, dctx->buf, POLY1305_BLOCK_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			dctx->buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (likely(nbytes >= POLY1305_BLOCK_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		unsigned int len = round_down(nbytes, POLY1305_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		if (static_branch_likely(&have_neon) && crypto_simd_usable()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				unsigned int todo = min_t(unsigned int, len, SZ_4K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				poly1305_blocks_neon(&dctx->h, src, todo, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				len -= todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				src += todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			} while (len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			poly1305_blocks(&dctx->h, src, len, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			src += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		nbytes %= POLY1305_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (unlikely(nbytes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		dctx->buflen = nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		memcpy(dctx->buf, src, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) EXPORT_SYMBOL(poly1305_update_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) void poly1305_final_arch(struct poly1305_desc_ctx *dctx, u8 *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (unlikely(dctx->buflen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		dctx->buf[dctx->buflen++] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		memset(dctx->buf + dctx->buflen, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		       POLY1305_BLOCK_SIZE - dctx->buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		poly1305_blocks(&dctx->h, dctx->buf, POLY1305_BLOCK_SIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	poly1305_emit(&dctx->h, dst, dctx->s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	*dctx = (struct poly1305_desc_ctx){};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) EXPORT_SYMBOL(poly1305_final_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int neon_poly1305_final(struct shash_desc *desc, u8 *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (unlikely(!dctx->sset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	poly1305_final_arch(dctx, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static struct shash_alg neon_poly1305_alg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	.init			= neon_poly1305_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	.update			= neon_poly1305_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	.final			= neon_poly1305_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.digestsize		= POLY1305_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.descsize		= sizeof(struct poly1305_desc_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.base.cra_name		= "poly1305",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	.base.cra_driver_name	= "poly1305-neon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	.base.cra_priority	= 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	.base.cra_blocksize	= POLY1305_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	.base.cra_module	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int __init neon_poly1305_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (!cpu_have_named_feature(ASIMD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	static_branch_enable(&have_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		crypto_register_shash(&neon_poly1305_alg) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static void __exit neon_poly1305_mod_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (IS_REACHABLE(CONFIG_CRYPTO_HASH) && cpu_have_named_feature(ASIMD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		crypto_unregister_shash(&neon_poly1305_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) module_init(neon_poly1305_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) module_exit(neon_poly1305_mod_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) MODULE_ALIAS_CRYPTO("poly1305");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) MODULE_ALIAS_CRYPTO("poly1305-neon");