0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <crypto/internal/hash.h>
0022 #include <linux/init.h>
0023 #include <linux/module.h>
0024 #include <linux/cpufeature.h>
0025 #include <crypto/sha1.h>
0026 #include <asm/cpacf.h>
0027
0028 #include "sha.h"
0029
0030 static int s390_sha1_init(struct shash_desc *desc)
0031 {
0032 struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
0033
0034 sctx->state[0] = SHA1_H0;
0035 sctx->state[1] = SHA1_H1;
0036 sctx->state[2] = SHA1_H2;
0037 sctx->state[3] = SHA1_H3;
0038 sctx->state[4] = SHA1_H4;
0039 sctx->count = 0;
0040 sctx->func = CPACF_KIMD_SHA_1;
0041
0042 return 0;
0043 }
0044
0045 static int s390_sha1_export(struct shash_desc *desc, void *out)
0046 {
0047 struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
0048 struct sha1_state *octx = out;
0049
0050 octx->count = sctx->count;
0051 memcpy(octx->state, sctx->state, sizeof(octx->state));
0052 memcpy(octx->buffer, sctx->buf, sizeof(octx->buffer));
0053 return 0;
0054 }
0055
0056 static int s390_sha1_import(struct shash_desc *desc, const void *in)
0057 {
0058 struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
0059 const struct sha1_state *ictx = in;
0060
0061 sctx->count = ictx->count;
0062 memcpy(sctx->state, ictx->state, sizeof(ictx->state));
0063 memcpy(sctx->buf, ictx->buffer, sizeof(ictx->buffer));
0064 sctx->func = CPACF_KIMD_SHA_1;
0065 return 0;
0066 }
0067
0068 static struct shash_alg alg = {
0069 .digestsize = SHA1_DIGEST_SIZE,
0070 .init = s390_sha1_init,
0071 .update = s390_sha_update,
0072 .final = s390_sha_final,
0073 .export = s390_sha1_export,
0074 .import = s390_sha1_import,
0075 .descsize = sizeof(struct s390_sha_ctx),
0076 .statesize = sizeof(struct sha1_state),
0077 .base = {
0078 .cra_name = "sha1",
0079 .cra_driver_name= "sha1-s390",
0080 .cra_priority = 300,
0081 .cra_blocksize = SHA1_BLOCK_SIZE,
0082 .cra_module = THIS_MODULE,
0083 }
0084 };
0085
0086 static int __init sha1_s390_init(void)
0087 {
0088 if (!cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_1))
0089 return -ENODEV;
0090 return crypto_register_shash(&alg);
0091 }
0092
0093 static void __exit sha1_s390_fini(void)
0094 {
0095 crypto_unregister_shash(&alg);
0096 }
0097
0098 module_cpu_feature_match(S390_CPU_FEATURE_MSA, sha1_s390_init);
0099 module_exit(sha1_s390_fini);
0100
0101 MODULE_ALIAS_CRYPTO("sha1");
0102 MODULE_LICENSE("GPL");
0103 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");