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)  * Cryptographic API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * s390 implementation of the SHA1 Secure Hash Algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Derived from cryptoapi implementation, adapted for in-place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * scatterlist interface.  Originally based on the public domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * implementation written by Steve Reid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * s390 Version:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *   Copyright IBM Corp. 2003, 2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *   Author(s): Thomas Spatzier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *		Jan Glauber (jan.glauber@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Derived from "crypto/sha1_generic.c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *   Copyright (c) Alan Smithee.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *   Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *   Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <crypto/internal/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/cpufeature.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <crypto/sha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/cpacf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "sha.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static int s390_sha1_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	sctx->state[0] = SHA1_H0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	sctx->state[1] = SHA1_H1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	sctx->state[2] = SHA1_H2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	sctx->state[3] = SHA1_H3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	sctx->state[4] = SHA1_H4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	sctx->count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	sctx->func = CPACF_KIMD_SHA_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int s390_sha1_export(struct shash_desc *desc, void *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct sha1_state *octx = out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	octx->count = sctx->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	memcpy(octx->state, sctx->state, sizeof(octx->state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	memcpy(octx->buffer, sctx->buf, sizeof(octx->buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static int s390_sha1_import(struct shash_desc *desc, const void *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	const struct sha1_state *ictx = in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	sctx->count = ictx->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	memcpy(sctx->state, ictx->state, sizeof(ictx->state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	memcpy(sctx->buf, ictx->buffer, sizeof(ictx->buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	sctx->func = CPACF_KIMD_SHA_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static struct shash_alg alg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.digestsize	=	SHA1_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.init		=	s390_sha1_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.update		=	s390_sha_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.final		=	s390_sha_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.export		=	s390_sha1_export,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.import		=	s390_sha1_import,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.descsize	=	sizeof(struct s390_sha_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.statesize	=	sizeof(struct sha1_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.base		=	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		.cra_name	=	"sha1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		.cra_driver_name=	"sha1-s390",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		.cra_priority	=	300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		.cra_blocksize	=	SHA1_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		.cra_module	=	THIS_MODULE,
^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) static int __init sha1_s390_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (!cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return crypto_register_shash(&alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static void __exit sha1_s390_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	crypto_unregister_shash(&alg);
^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) module_cpu_feature_match(MSA, sha1_s390_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) module_exit(sha1_s390_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) MODULE_ALIAS_CRYPTO("sha1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");