]>
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: | |
86aa9fc2 JG |
11 | * Copyright IBM Corp. 2003,2007 |
12 | * Author(s): Thomas Spatzier | |
13 | * Jan Glauber ([email protected]) | |
1da177e4 | 14 | * |
ad5d2789 | 15 | * Derived from "crypto/sha1_generic.c" |
1da177e4 LT |
16 | * Copyright (c) Alan Smithee. |
17 | * Copyright (c) Andrew McDonald <[email protected]> | |
18 | * Copyright (c) Jean-Francois Dive <[email protected]> | |
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> | |
5265eeb2 | 29 | #include <crypto/sha.h> |
131a395c | 30 | |
c1e26e1e | 31 | #include "crypt_s390.h" |
604973f1 | 32 | #include "sha.h" |
1da177e4 | 33 | |
563f346d | 34 | static int sha1_init(struct shash_desc *desc) |
1da177e4 | 35 | { |
563f346d | 36 | struct s390_sha_ctx *sctx = shash_desc_ctx(desc); |
131a395c | 37 | |
5265eeb2 JG |
38 | sctx->state[0] = SHA1_H0; |
39 | sctx->state[1] = SHA1_H1; | |
40 | sctx->state[2] = SHA1_H2; | |
41 | sctx->state[3] = SHA1_H3; | |
42 | sctx->state[4] = SHA1_H4; | |
131a395c | 43 | sctx->count = 0; |
604973f1 | 44 | sctx->func = KIMD_SHA_1; |
563f346d HX |
45 | |
46 | return 0; | |
1da177e4 LT |
47 | } |
48 | ||
406f104b HX |
49 | static int sha1_export(struct shash_desc *desc, void *out) |
50 | { | |
51 | struct s390_sha_ctx *sctx = shash_desc_ctx(desc); | |
52 | struct sha1_state *octx = out; | |
53 | ||
54 | octx->count = sctx->count; | |
55 | memcpy(octx->state, sctx->state, sizeof(octx->state)); | |
56 | memcpy(octx->buffer, sctx->buf, sizeof(octx->buffer)); | |
57 | return 0; | |
58 | } | |
59 | ||
81bd5f6c | 60 | static int sha1_import(struct shash_desc *desc, const void *in) |
406f104b | 61 | { |
2a549c36 | 62 | struct s390_sha_ctx *sctx = shash_desc_ctx(desc); |
81bd5f6c | 63 | const struct sha1_state *ictx = in; |
406f104b HX |
64 | |
65 | sctx->count = ictx->count; | |
66 | memcpy(sctx->state, ictx->state, sizeof(ictx->state)); | |
67 | memcpy(sctx->buf, ictx->buffer, sizeof(ictx->buffer)); | |
68 | sctx->func = KIMD_SHA_1; | |
69 | return 0; | |
70 | } | |
71 | ||
563f346d HX |
72 | static struct shash_alg alg = { |
73 | .digestsize = SHA1_DIGEST_SIZE, | |
74 | .init = sha1_init, | |
75 | .update = s390_sha_update, | |
76 | .final = s390_sha_final, | |
406f104b HX |
77 | .export = sha1_export, |
78 | .import = sha1_import, | |
563f346d | 79 | .descsize = sizeof(struct s390_sha_ctx), |
406f104b | 80 | .statesize = sizeof(struct sha1_state), |
563f346d HX |
81 | .base = { |
82 | .cra_name = "sha1", | |
83 | .cra_driver_name= "sha1-s390", | |
84 | .cra_priority = CRYPT_S390_PRIORITY, | |
85 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, | |
86 | .cra_blocksize = SHA1_BLOCK_SIZE, | |
87 | .cra_module = THIS_MODULE, | |
88 | } | |
1da177e4 LT |
89 | }; |
90 | ||
9f7819c1 | 91 | static int __init sha1_s390_init(void) |
1da177e4 | 92 | { |
1822bc90 | 93 | if (!crypt_s390_func_available(KIMD_SHA_1, CRYPT_S390_MSA)) |
86aa9fc2 | 94 | return -EOPNOTSUPP; |
563f346d | 95 | return crypto_register_shash(&alg); |
1da177e4 LT |
96 | } |
97 | ||
9f7819c1 | 98 | static void __exit sha1_s390_fini(void) |
1da177e4 | 99 | { |
563f346d | 100 | crypto_unregister_shash(&alg); |
1da177e4 LT |
101 | } |
102 | ||
9f7819c1 HC |
103 | module_init(sha1_s390_init); |
104 | module_exit(sha1_s390_fini); | |
1da177e4 LT |
105 | |
106 | MODULE_ALIAS("sha1"); | |
1da177e4 LT |
107 | MODULE_LICENSE("GPL"); |
108 | MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm"); |