Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Cryptographic API. |
| 3 | * |
| 4 | * s390 implementation of the SHA256 Secure Hash Algorithm. |
| 5 | * |
| 6 | * s390 Version: |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 7 | * Copyright IBM Corp. 2005,2007 |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 8 | * Author(s): Jan Glauber (jang@de.ibm.com) |
| 9 | * |
Sebastian Siewior | ad5d278 | 2007-10-08 11:45:10 +0800 | [diff] [blame] | 10 | * Derived from "crypto/sha256_generic.c" |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 11 | * and "arch/s390/crypto/sha1_s390.c" |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the Free |
| 15 | * Software Foundation; either version 2 of the License, or (at your option) |
| 16 | * any later version. |
| 17 | * |
| 18 | */ |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/crypto.h> |
Jan Glauber | 5265eeb | 2007-10-09 22:43:13 +0800 | [diff] [blame] | 22 | #include <crypto/sha.h> |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 23 | |
| 24 | #include "crypt_s390.h" |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 25 | #include "sha.h" |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 26 | |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 27 | static void sha256_init(struct crypto_tfm *tfm) |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 28 | { |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 29 | struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm); |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 30 | |
Jan Glauber | 5265eeb | 2007-10-09 22:43:13 +0800 | [diff] [blame] | 31 | sctx->state[0] = SHA256_H0; |
| 32 | sctx->state[1] = SHA256_H1; |
| 33 | sctx->state[2] = SHA256_H2; |
| 34 | sctx->state[3] = SHA256_H3; |
| 35 | sctx->state[4] = SHA256_H4; |
| 36 | sctx->state[5] = SHA256_H5; |
| 37 | sctx->state[6] = SHA256_H6; |
| 38 | sctx->state[7] = SHA256_H7; |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 39 | sctx->count = 0; |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 40 | sctx->func = KIMD_SHA_256; |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static struct crypto_alg alg = { |
| 44 | .cra_name = "sha256", |
Herbert Xu | 65b75c3 | 2006-08-21 21:18:50 +1000 | [diff] [blame] | 45 | .cra_driver_name = "sha256-s390", |
| 46 | .cra_priority = CRYPT_S390_PRIORITY, |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 47 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, |
| 48 | .cra_blocksize = SHA256_BLOCK_SIZE, |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 49 | .cra_ctxsize = sizeof(struct s390_sha_ctx), |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 50 | .cra_module = THIS_MODULE, |
| 51 | .cra_list = LIST_HEAD_INIT(alg.cra_list), |
| 52 | .cra_u = { .digest = { |
| 53 | .dia_digestsize = SHA256_DIGEST_SIZE, |
Jan Glauber | 7ffbc9d | 2006-01-14 13:20:56 -0800 | [diff] [blame] | 54 | .dia_init = sha256_init, |
Jan Glauber | 604973f | 2008-03-06 19:50:20 +0800 | [diff] [blame] | 55 | .dia_update = s390_sha_update, |
| 56 | .dia_final = s390_sha_final } } |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Heiko Carstens | 9f7819c | 2008-04-17 07:46:17 +0200 | [diff] [blame] | 59 | static int sha256_s390_init(void) |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 60 | { |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 61 | if (!crypt_s390_func_available(KIMD_SHA_256)) |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 62 | return -EOPNOTSUPP; |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 63 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 64 | return crypto_register_alg(&alg); |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Heiko Carstens | 9f7819c | 2008-04-17 07:46:17 +0200 | [diff] [blame] | 67 | static void __exit sha256_s390_fini(void) |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 68 | { |
| 69 | crypto_unregister_alg(&alg); |
| 70 | } |
| 71 | |
Heiko Carstens | 9f7819c | 2008-04-17 07:46:17 +0200 | [diff] [blame] | 72 | module_init(sha256_s390_init); |
| 73 | module_exit(sha256_s390_fini); |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 74 | |
| 75 | MODULE_ALIAS("sha256"); |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 76 | MODULE_LICENSE("GPL"); |
| 77 | MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm"); |