Commit | Line | Data |
---|---|---|
9fa1db4c | 1 | // SPDX-License-Identifier: GPL-2.0+ |
1da177e4 LT |
2 | /* |
3 | * Cryptographic API. | |
4 | * | |
c1e26e1e | 5 | * s390 implementation of the SHA1 Secure Hash Algorithm. |
1da177e4 LT |
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: | |
a53c8fab | 12 | * Copyright IBM Corp. 2003, 2007 |
86aa9fc2 JG |
13 | * Author(s): Thomas Spatzier |
14 | * Jan Glauber (jan.glauber@de.ibm.com) | |
1da177e4 | 15 | * |
ad5d2789 | 16 | * Derived from "crypto/sha1_generic.c" |
1da177e4 LT |
17 | * Copyright (c) Alan Smithee. |
18 | * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> | |
19 | * Copyright (c) Jean-Francois Dive <jef@linuxbe.org> | |
1da177e4 | 20 | */ |
563f346d | 21 | #include <crypto/internal/hash.h> |
1da177e4 LT |
22 | #include <linux/init.h> |
23 | #include <linux/module.h> | |
d05377c1 | 24 | #include <linux/cpufeature.h> |
5265eeb2 | 25 | #include <crypto/sha.h> |
c7d4d259 | 26 | #include <asm/cpacf.h> |
131a395c | 27 | |
604973f1 | 28 | #include "sha.h" |
1da177e4 | 29 | |
563f346d | 30 | static int sha1_init(struct shash_desc *desc) |
1da177e4 | 31 | { |
563f346d | 32 | struct s390_sha_ctx *sctx = shash_desc_ctx(desc); |
131a395c | 33 | |
5265eeb2 JG |
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; | |
131a395c | 39 | sctx->count = 0; |
c7d4d259 | 40 | sctx->func = CPACF_KIMD_SHA_1; |
563f346d HX |
41 | |
42 | return 0; | |
1da177e4 LT |
43 | } |
44 | ||
406f104b HX |
45 | static int 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 | ||
81bd5f6c | 56 | static int sha1_import(struct shash_desc *desc, const void *in) |
406f104b | 57 | { |
2a549c36 | 58 | struct s390_sha_ctx *sctx = shash_desc_ctx(desc); |
81bd5f6c | 59 | const struct sha1_state *ictx = in; |
406f104b HX |
60 | |
61 | sctx->count = ictx->count; | |
62 | memcpy(sctx->state, ictx->state, sizeof(ictx->state)); | |
63 | memcpy(sctx->buf, ictx->buffer, sizeof(ictx->buffer)); | |
c7d4d259 | 64 | sctx->func = CPACF_KIMD_SHA_1; |
406f104b HX |
65 | return 0; |
66 | } | |
67 | ||
563f346d HX |
68 | static struct shash_alg alg = { |
69 | .digestsize = SHA1_DIGEST_SIZE, | |
70 | .init = sha1_init, | |
71 | .update = s390_sha_update, | |
72 | .final = s390_sha_final, | |
406f104b HX |
73 | .export = sha1_export, |
74 | .import = sha1_import, | |
563f346d | 75 | .descsize = sizeof(struct s390_sha_ctx), |
406f104b | 76 | .statesize = sizeof(struct sha1_state), |
563f346d HX |
77 | .base = { |
78 | .cra_name = "sha1", | |
79 | .cra_driver_name= "sha1-s390", | |
c7d4d259 | 80 | .cra_priority = 300, |
563f346d HX |
81 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
82 | .cra_blocksize = SHA1_BLOCK_SIZE, | |
83 | .cra_module = THIS_MODULE, | |
84 | } | |
1da177e4 LT |
85 | }; |
86 | ||
9f7819c1 | 87 | static int __init sha1_s390_init(void) |
1da177e4 | 88 | { |
69c0e360 | 89 | if (!cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_1)) |
86aa9fc2 | 90 | return -EOPNOTSUPP; |
563f346d | 91 | return crypto_register_shash(&alg); |
1da177e4 LT |
92 | } |
93 | ||
9f7819c1 | 94 | static void __exit sha1_s390_fini(void) |
1da177e4 | 95 | { |
563f346d | 96 | crypto_unregister_shash(&alg); |
1da177e4 LT |
97 | } |
98 | ||
d05377c1 | 99 | module_cpu_feature_match(MSA, sha1_s390_init); |
9f7819c1 | 100 | module_exit(sha1_s390_fini); |
1da177e4 | 101 | |
5d26a105 | 102 | MODULE_ALIAS_CRYPTO("sha1"); |
1da177e4 LT |
103 | MODULE_LICENSE("GPL"); |
104 | MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm"); |