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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * ARM NEON and scalar accelerated ChaCha and XChaCha stream ciphers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * including ChaCha20 (RFC7539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2016 - 2017 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)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * it under the terms of the GNU General Public License version 2 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Based on:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * ChaCha20 256-bit cipher algorithm, RFC7539, SIMD glue code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Copyright (C) 2015 Martin Willi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * the Free Software Foundation; either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <crypto/internal/chacha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <crypto/internal/simd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <crypto/internal/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/jump_label.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/hwcap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/neon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/simd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) asmlinkage void chacha_block_xor_neon(u32 *state, u8 *dst, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 				      int nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) asmlinkage void chacha_4block_xor_neon(u32 *state, u8 *dst, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 				       int nrounds, int bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) asmlinkage void hchacha_block_neon(const u32 *state, u32 *out, int nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void chacha_doneon(u32 *state, u8 *dst, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			  int bytes, int nrounds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	while (bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		int l = min(bytes, CHACHA_BLOCK_SIZE * 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		if (l <= CHACHA_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			u8 buf[CHACHA_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			memcpy(buf, src, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			chacha_block_xor_neon(state, buf, buf, nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			memcpy(dst, buf, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			state[12] += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		chacha_4block_xor_neon(state, dst, src, nrounds, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		bytes -= l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		src += l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		dst += l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		state[12] += DIV_ROUND_UP(l, CHACHA_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (!static_branch_likely(&have_neon) || !crypto_simd_usable()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		hchacha_block_generic(state, stream, nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		hchacha_block_neon(state, stream, nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		kernel_neon_end();
^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) EXPORT_SYMBOL(hchacha_block_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	chacha_init_generic(state, key, iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) EXPORT_SYMBOL(chacha_init_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		       int nrounds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!static_branch_likely(&have_neon) || bytes <= CHACHA_BLOCK_SIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	    !crypto_simd_usable())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return chacha_crypt_generic(state, dst, src, bytes, nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		unsigned int todo = min_t(unsigned int, bytes, SZ_4K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		chacha_doneon(state, dst, src, todo, nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		bytes -= todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		src += todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		dst += todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	} while (bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) EXPORT_SYMBOL(chacha_crypt_arch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int chacha_neon_stream_xor(struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				  const struct chacha_ctx *ctx, const u8 *iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct skcipher_walk walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u32 state[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	err = skcipher_walk_virt(&walk, req, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	chacha_init_generic(state, ctx->key, iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	while (walk.nbytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		unsigned int nbytes = walk.nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (nbytes < walk.total)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			nbytes = rounddown(nbytes, walk.stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		if (!static_branch_likely(&have_neon) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		    !crypto_simd_usable()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			chacha_crypt_generic(state, walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					     walk.src.virt.addr, nbytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 					     ctx->nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			chacha_doneon(state, walk.dst.virt.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				      walk.src.virt.addr, nbytes, ctx->nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int chacha_neon(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return chacha_neon_stream_xor(req, ctx, req->iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int xchacha_neon(struct skcipher_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct chacha_ctx subctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	u32 state[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	u8 real_iv[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	chacha_init_generic(state, ctx->key, req->iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	hchacha_block_arch(state, subctx.key, ctx->nrounds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	subctx.nrounds = ctx->nrounds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	memcpy(&real_iv[0], req->iv + 24, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	memcpy(&real_iv[8], req->iv + 16, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return chacha_neon_stream_xor(req, &subctx, real_iv);
^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) static struct skcipher_alg algs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		.base.cra_name		= "chacha20",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		.base.cra_driver_name	= "chacha20-neon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		.base.cra_priority	= 300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		.base.cra_blocksize	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		.base.cra_ctxsize	= sizeof(struct chacha_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		.base.cra_module	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		.min_keysize		= CHACHA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		.max_keysize		= CHACHA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		.ivsize			= CHACHA_IV_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		.chunksize		= CHACHA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		.walksize		= 5 * CHACHA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		.setkey			= chacha20_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		.encrypt		= chacha_neon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		.decrypt		= chacha_neon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		.base.cra_name		= "xchacha20",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		.base.cra_driver_name	= "xchacha20-neon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		.base.cra_priority	= 300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		.base.cra_blocksize	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		.base.cra_ctxsize	= sizeof(struct chacha_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		.base.cra_module	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		.min_keysize		= CHACHA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		.max_keysize		= CHACHA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		.ivsize			= XCHACHA_IV_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		.chunksize		= CHACHA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		.walksize		= 5 * CHACHA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		.setkey			= chacha20_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		.encrypt		= xchacha_neon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		.decrypt		= xchacha_neon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		.base.cra_name		= "xchacha12",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		.base.cra_driver_name	= "xchacha12-neon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		.base.cra_priority	= 300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		.base.cra_blocksize	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		.base.cra_ctxsize	= sizeof(struct chacha_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		.base.cra_module	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		.min_keysize		= CHACHA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		.max_keysize		= CHACHA_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		.ivsize			= XCHACHA_IV_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		.chunksize		= CHACHA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		.walksize		= 5 * CHACHA_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		.setkey			= chacha12_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		.encrypt		= xchacha_neon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		.decrypt		= xchacha_neon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int __init chacha_simd_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (!cpu_have_named_feature(ASIMD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	static_branch_enable(&have_neon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		crypto_register_skciphers(algs, ARRAY_SIZE(algs)) : 0;
^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) static void __exit chacha_simd_mod_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) && cpu_have_named_feature(ASIMD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		crypto_unregister_skciphers(algs, ARRAY_SIZE(algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) module_init(chacha_simd_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) module_exit(chacha_simd_mod_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) MODULE_DESCRIPTION("ChaCha and XChaCha stream ciphers (NEON accelerated)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) MODULE_ALIAS_CRYPTO("chacha20");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) MODULE_ALIAS_CRYPTO("chacha20-neon");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) MODULE_ALIAS_CRYPTO("xchacha20");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) MODULE_ALIAS_CRYPTO("xchacha20-neon");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) MODULE_ALIAS_CRYPTO("xchacha12");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) MODULE_ALIAS_CRYPTO("xchacha12-neon");