Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Cryptographic API. | |
3 | * | |
c1e26e1e | 4 | * s390 implementation of the SHA1 Secure Hash Algorithm. |
1da177e4 LT |
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: | |
a53c8fab | 11 | * Copyright IBM Corp. 2003, 2007 |
86aa9fc2 JG |
12 | * Author(s): Thomas Spatzier |
13 | * Jan Glauber (jan.glauber@de.ibm.com) | |
1da177e4 | 14 | * |
ad5d2789 | 15 | * Derived from "crypto/sha1_generic.c" |
1da177e4 LT |
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 | */ | |
563f346d | 26 | #include <crypto/internal/hash.h> |
1da177e4 LT |
27 | #include <linux/init.h> |
28 | #include <linux/module.h> | |
d05377c1 | 29 | #include <linux/cpufeature.h> |
5265eeb2 | 30 | #include <crypto/sha.h> |
c7d4d259 | 31 | #include <asm/cpacf.h> |
131a395c | 32 | |
604973f1 | 33 | #include "sha.h" |
1da177e4 | 34 | |
563f346d | 35 | static int sha1_init(struct shash_desc *desc) |
1da177e4 | 36 | { |
563f346d | 37 | struct s390_sha_ctx *sctx = shash_desc_ctx(desc); |
131a395c | 38 | |
5265eeb2 JG |
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; | |
131a395c | 44 | sctx->count = 0; |
c7d4d259 | 45 | sctx->func = CPACF_KIMD_SHA_1; |
563f346d HX |
46 | |
47 | return 0; | |
1da177e4 LT |
48 | } |
49 | ||
406f104b HX |
50 | static 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 | ||
81bd5f6c | 61 | static int sha1_import(struct shash_desc *desc, const void *in) |
406f104b | 62 | { |
2a549c36 | 63 | struct s390_sha_ctx *sctx = shash_desc_ctx(desc); |
81bd5f6c | 64 | const struct sha1_state *ictx = in; |
406f104b HX |
65 | |
66 | sctx->count = ictx->count; | |
67 | memcpy(sctx->state, ictx->state, sizeof(ictx->state)); | |
68 | memcpy(sctx->buf, ictx->buffer, sizeof(ictx->buffer)); | |
c7d4d259 | 69 | sctx->func = CPACF_KIMD_SHA_1; |
406f104b HX |
70 | return 0; |
71 | } | |
72 | ||
563f346d HX |
73 | static struct shash_alg alg = { |
74 | .digestsize = SHA1_DIGEST_SIZE, | |
75 | .init = sha1_init, | |
76 | .update = s390_sha_update, | |
77 | .final = s390_sha_final, | |
406f104b HX |
78 | .export = sha1_export, |
79 | .import = sha1_import, | |
563f346d | 80 | .descsize = sizeof(struct s390_sha_ctx), |
406f104b | 81 | .statesize = sizeof(struct sha1_state), |
563f346d HX |
82 | .base = { |
83 | .cra_name = "sha1", | |
84 | .cra_driver_name= "sha1-s390", | |
c7d4d259 | 85 | .cra_priority = 300, |
563f346d HX |
86 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
87 | .cra_blocksize = SHA1_BLOCK_SIZE, | |
88 | .cra_module = THIS_MODULE, | |
89 | } | |
1da177e4 LT |
90 | }; |
91 | ||
9f7819c1 | 92 | static int __init sha1_s390_init(void) |
1da177e4 | 93 | { |
c7d4d259 | 94 | if (!cpacf_query(CPACF_KIMD, CPACF_KIMD_SHA_1)) |
86aa9fc2 | 95 | return -EOPNOTSUPP; |
563f346d | 96 | return crypto_register_shash(&alg); |
1da177e4 LT |
97 | } |
98 | ||
9f7819c1 | 99 | static void __exit sha1_s390_fini(void) |
1da177e4 | 100 | { |
563f346d | 101 | crypto_unregister_shash(&alg); |
1da177e4 LT |
102 | } |
103 | ||
d05377c1 | 104 | module_cpu_feature_match(MSA, sha1_s390_init); |
9f7819c1 | 105 | module_exit(sha1_s390_fini); |
1da177e4 | 106 | |
5d26a105 | 107 | MODULE_ALIAS_CRYPTO("sha1"); |
1da177e4 LT |
108 | MODULE_LICENSE("GPL"); |
109 | MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm"); |