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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Glue code for the SHA256 Secure Hash Algorithm assembly implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * using optimized ARM assembler and NEON instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright © 2015 Google Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This file is based on sha256_ssse3_glue.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *   Copyright (C) 2013 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   Author: Tim Chen <tim.c.chen@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^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 <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <crypto/sha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <crypto/sha256_base.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/simd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/neon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "sha256_glue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) asmlinkage void sha256_block_data_order(u32 *digest, const void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 					unsigned int num_blks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) int crypto_sha256_arm_update(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			     unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* make sure casting to sha256_block_fn() is safe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	BUILD_BUG_ON(offsetof(struct sha256_state, state) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	return sha256_base_do_update(desc, data, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 				(sha256_block_fn *)sha256_block_data_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) EXPORT_SYMBOL(crypto_sha256_arm_update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static int crypto_sha256_arm_final(struct shash_desc *desc, u8 *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	sha256_base_do_finalize(desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 				(sha256_block_fn *)sha256_block_data_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return sha256_base_finish(desc, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) int crypto_sha256_arm_finup(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			    unsigned int len, u8 *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	sha256_base_do_update(desc, data, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			      (sha256_block_fn *)sha256_block_data_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return crypto_sha256_arm_final(desc, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) EXPORT_SYMBOL(crypto_sha256_arm_finup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static struct shash_alg algs[] = { {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.digestsize	=	SHA256_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.init		=	sha256_base_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.update		=	crypto_sha256_arm_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.final		=	crypto_sha256_arm_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.finup		=	crypto_sha256_arm_finup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.descsize	=	sizeof(struct sha256_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.base		=	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		.cra_name	=	"sha256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		.cra_driver_name =	"sha256-asm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		.cra_priority	=	150,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		.cra_blocksize	=	SHA256_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		.cra_module	=	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.digestsize	=	SHA224_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.init		=	sha224_base_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.update		=	crypto_sha256_arm_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.final		=	crypto_sha256_arm_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.finup		=	crypto_sha256_arm_finup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.descsize	=	sizeof(struct sha256_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	.base		=	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		.cra_name	=	"sha224",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		.cra_driver_name =	"sha224-asm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		.cra_priority	=	150,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		.cra_blocksize	=	SHA224_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		.cra_module	=	THIS_MODULE,
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static int __init sha256_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int res = crypto_register_shashes(algs, ARRAY_SIZE(algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && cpu_has_neon()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		res = crypto_register_shashes(sha256_neon_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 					      ARRAY_SIZE(sha256_neon_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
^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) 	return res;
^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) static void __exit sha256_mod_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && cpu_has_neon())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		crypto_unregister_shashes(sha256_neon_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 					  ARRAY_SIZE(sha256_neon_algs));
^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) module_init(sha256_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) module_exit(sha256_mod_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm (ARM), including NEON");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) MODULE_ALIAS_CRYPTO("sha256");