blob: b3cb5a89b00d08a37030c80ca53940ef9bc3af16 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Cryptographic API.
3 *
Jan Glauberc1e26e12006-01-06 00:19:17 -08004 * s390 implementation of the SHA1 Secure Hash Algorithm.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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 Glauber86aa9fc2007-02-05 21:18:14 +010011 * Copyright IBM Corp. 2003,2007
12 * Author(s): Thomas Spatzier
13 * Jan Glauber (jan.glauber@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 *
Sebastian Siewiorad5d2782007-10-08 11:45:10 +080015 * Derived from "crypto/sha1_generic.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * 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 Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/crypto.h>
Jan Glauber5265eeb2007-10-09 22:43:13 +080029#include <crypto/sha.h>
Jan Glauber131a3952007-04-27 16:01:54 +020030
Jan Glauberc1e26e12006-01-06 00:19:17 -080031#include "crypt_s390.h"
Jan Glauber604973f2008-03-06 19:50:20 +080032#include "sha.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Herbert Xu6c2bb982006-05-16 22:09:29 +100034static void sha1_init(struct crypto_tfm *tfm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Jan Glauber604973f2008-03-06 19:50:20 +080036 struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm);
Jan Glauber86aa9fc2007-02-05 21:18:14 +010037
Jan Glauber5265eeb2007-10-09 22:43:13 +080038 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 Glauber131a3952007-04-27 16:01:54 +020043 sctx->count = 0;
Jan Glauber604973f2008-03-06 19:50:20 +080044 sctx->func = KIMD_SHA_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
47static struct crypto_alg alg = {
48 .cra_name = "sha1",
Jan Glauber86aa9fc2007-02-05 21:18:14 +010049 .cra_driver_name= "sha1-s390",
Herbert Xu65b75c32006-08-21 21:18:50 +100050 .cra_priority = CRYPT_S390_PRIORITY,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
52 .cra_blocksize = SHA1_BLOCK_SIZE,
Jan Glauber604973f2008-03-06 19:50:20 +080053 .cra_ctxsize = sizeof(struct s390_sha_ctx),
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .cra_module = THIS_MODULE,
Jan Glauber86aa9fc2007-02-05 21:18:14 +010055 .cra_list = LIST_HEAD_INIT(alg.cra_list),
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .cra_u = { .digest = {
57 .dia_digestsize = SHA1_DIGEST_SIZE,
Jan Glauber86aa9fc2007-02-05 21:18:14 +010058 .dia_init = sha1_init,
Jan Glauber604973f2008-03-06 19:50:20 +080059 .dia_update = s390_sha_update,
60 .dia_final = s390_sha_final } }
Linus Torvalds1da177e2005-04-16 15:20:36 -070061};
62
Heiko Carstens9f7819c2008-04-17 07:46:17 +020063static int __init sha1_s390_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Jan Glauber86aa9fc2007-02-05 21:18:14 +010065 if (!crypt_s390_func_available(KIMD_SHA_1))
66 return -EOPNOTSUPP;
Jan Glauber86aa9fc2007-02-05 21:18:14 +010067 return crypto_register_alg(&alg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Heiko Carstens9f7819c2008-04-17 07:46:17 +020070static void __exit sha1_s390_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
72 crypto_unregister_alg(&alg);
73}
74
Heiko Carstens9f7819c2008-04-17 07:46:17 +020075module_init(sha1_s390_init);
76module_exit(sha1_s390_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78MODULE_ALIAS("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -070079MODULE_LICENSE("GPL");
80MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");