Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Cryptographic API. |
| 3 | * |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 4 | * s390 implementation of the SHA1 Secure Hash Algorithm. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 11 | * Copyright IBM Corp. 2003,2007 |
| 12 | * Author(s): Thomas Spatzier |
| 13 | * Jan Glauber (jan.glauber@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
Sebastian Siewior | ad5d278 | 2007-10-08 11:45:10 +0800 | [diff] [blame] | 15 | * Derived from "crypto/sha1_generic.c" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <linux/init.h> |
| 27 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/crypto.h> |
Jan Glauber | 5265eeb | 2007-10-09 22:43:13 +0800 | [diff] [blame] | 29 | #include <crypto/sha.h> |
Jan Glauber | 131a395 | 2007-04-27 16:01:54 +0200 | [diff] [blame] | 30 | |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 31 | #include "crypt_s390.h" |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 32 | #include "sha.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 34 | static void sha1_init(struct crypto_tfm *tfm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 36 | struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm); |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 37 | |
Jan Glauber | 5265eeb | 2007-10-09 22:43:13 +0800 | [diff] [blame] | 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; |
Jan Glauber | 131a395 | 2007-04-27 16:01:54 +0200 | [diff] [blame] | 43 | sctx->count = 0; |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 44 | sctx->func = KIMD_SHA_1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static struct crypto_alg alg = { |
| 48 | .cra_name = "sha1", |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 49 | .cra_driver_name= "sha1-s390", |
Herbert Xu | 65b75c3 | 2006-08-21 21:18:50 +1000 | [diff] [blame] | 50 | .cra_priority = CRYPT_S390_PRIORITY, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, |
| 52 | .cra_blocksize = SHA1_BLOCK_SIZE, |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 53 | .cra_ctxsize = sizeof(struct s390_sha_ctx), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | .cra_module = THIS_MODULE, |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 55 | .cra_list = LIST_HEAD_INIT(alg.cra_list), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .cra_u = { .digest = { |
| 57 | .dia_digestsize = SHA1_DIGEST_SIZE, |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 58 | .dia_init = sha1_init, |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 59 | .dia_update = s390_sha_update, |
| 60 | .dia_final = s390_sha_final } } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
Heiko Carstens | 9f7819c | 2008-04-17 07:46:17 +0200 | [diff] [blame] | 63 | static int __init sha1_s390_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 65 | if (!crypt_s390_func_available(KIMD_SHA_1)) |
| 66 | return -EOPNOTSUPP; |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 67 | return crypto_register_alg(&alg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Heiko Carstens | 9f7819c | 2008-04-17 07:46:17 +0200 | [diff] [blame] | 70 | static void __exit sha1_s390_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | crypto_unregister_alg(&alg); |
| 73 | } |
| 74 | |
Heiko Carstens | 9f7819c | 2008-04-17 07:46:17 +0200 | [diff] [blame] | 75 | module_init(sha1_s390_init); |
| 76 | module_exit(sha1_s390_fini); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | MODULE_ALIAS("sha1"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | MODULE_LICENSE("GPL"); |
| 80 | MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm"); |