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