blob: 19c03fb6ba7eee64d773ab0cdb5d0c1d556c05c0 [file] [log] [blame]
Jan Glauber0a497c172006-01-06 00:19:18 -08001/*
2 * Cryptographic API.
3 *
4 * s390 implementation of the SHA256 Secure Hash Algorithm.
5 *
6 * s390 Version:
Jan Glauber86aa9fc2007-02-05 21:18:14 +01007 * Copyright IBM Corp. 2005,2007
Jan Glauber0a497c172006-01-06 00:19:18 -08008 * Author(s): Jan Glauber (jang@de.ibm.com)
9 *
Sebastian Siewiorad5d2782007-10-08 11:45:10 +080010 * Derived from "crypto/sha256_generic.c"
Jan Glauber0a497c172006-01-06 00:19:18 -080011 * 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 Glauber5265eeb2007-10-09 22:43:13 +080022#include <crypto/sha.h>
Jan Glauber0a497c172006-01-06 00:19:18 -080023
24#include "crypt_s390.h"
Jan Glauber604973f2008-03-06 19:50:20 +080025#include "sha.h"
Jan Glauber0a497c172006-01-06 00:19:18 -080026
Herbert Xu6c2bb982006-05-16 22:09:29 +100027static void sha256_init(struct crypto_tfm *tfm)
Jan Glauber0a497c172006-01-06 00:19:18 -080028{
Jan Glauber604973f2008-03-06 19:50:20 +080029 struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm);
Jan Glauber0a497c172006-01-06 00:19:18 -080030
Jan Glauber5265eeb2007-10-09 22:43:13 +080031 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 Glauber0a497c172006-01-06 00:19:18 -080039 sctx->count = 0;
Jan Glauber604973f2008-03-06 19:50:20 +080040 sctx->func = KIMD_SHA_256;
Jan Glauber0a497c172006-01-06 00:19:18 -080041}
42
43static struct crypto_alg alg = {
44 .cra_name = "sha256",
Herbert Xu65b75c32006-08-21 21:18:50 +100045 .cra_driver_name = "sha256-s390",
46 .cra_priority = CRYPT_S390_PRIORITY,
Jan Glauber0a497c172006-01-06 00:19:18 -080047 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
48 .cra_blocksize = SHA256_BLOCK_SIZE,
Jan Glauber604973f2008-03-06 19:50:20 +080049 .cra_ctxsize = sizeof(struct s390_sha_ctx),
Jan Glauber0a497c172006-01-06 00:19:18 -080050 .cra_module = THIS_MODULE,
51 .cra_list = LIST_HEAD_INIT(alg.cra_list),
52 .cra_u = { .digest = {
53 .dia_digestsize = SHA256_DIGEST_SIZE,
Jan Glauber7ffbc9d2006-01-14 13:20:56 -080054 .dia_init = sha256_init,
Jan Glauber604973f2008-03-06 19:50:20 +080055 .dia_update = s390_sha_update,
56 .dia_final = s390_sha_final } }
Jan Glauber0a497c172006-01-06 00:19:18 -080057};
58
Heiko Carstens9f7819c2008-04-17 07:46:17 +020059static int sha256_s390_init(void)
Jan Glauber0a497c172006-01-06 00:19:18 -080060{
Jan Glauber0a497c172006-01-06 00:19:18 -080061 if (!crypt_s390_func_available(KIMD_SHA_256))
Jan Glauber86aa9fc2007-02-05 21:18:14 +010062 return -EOPNOTSUPP;
Jan Glauber0a497c172006-01-06 00:19:18 -080063
Jan Glauber86aa9fc2007-02-05 21:18:14 +010064 return crypto_register_alg(&alg);
Jan Glauber0a497c172006-01-06 00:19:18 -080065}
66
Heiko Carstens9f7819c2008-04-17 07:46:17 +020067static void __exit sha256_s390_fini(void)
Jan Glauber0a497c172006-01-06 00:19:18 -080068{
69 crypto_unregister_alg(&alg);
70}
71
Heiko Carstens9f7819c2008-04-17 07:46:17 +020072module_init(sha256_s390_init);
73module_exit(sha256_s390_fini);
Jan Glauber0a497c172006-01-06 00:19:18 -080074
75MODULE_ALIAS("sha256");
Jan Glauber0a497c172006-01-06 00:19:18 -080076MODULE_LICENSE("GPL");
77MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm");