4 * SHA-256, as specified in
5 * http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf
7 * SHA-256 code by Jean-Luc Cooke <jlcooke@certainkey.com>.
9 * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com>
10 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
11 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
12 * SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option)
21 #include <linux/bitops.h>
22 #include <linux/byteorder.h>
23 #include <linux/types.h>
24 #include <asm/unaligned.h>
26 #include <linux/crypto.h>
27 #include <crypto/hash.h>
29 #include <sodium/crypto_hash_sha256.h>
31 static struct shash_alg sha256_alg;
33 static int sha256_init(struct shash_desc *desc)
35 crypto_hash_sha256_state *state = (void *) desc->ctx;
37 return crypto_hash_sha256_init(state);
40 static int sha256_update(struct shash_desc *desc, const u8 *data,
43 crypto_hash_sha256_state *state = (void *) desc->ctx;
45 return crypto_hash_sha256_update(state, data, len);
48 static int sha256_final(struct shash_desc *desc, u8 *out)
50 crypto_hash_sha256_state *state = (void *) desc->ctx;
52 return crypto_hash_sha256_final(state, out);
55 static void *sha256_alloc_tfm(void)
57 struct crypto_shash *tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
62 tfm->base.alg = &sha256_alg.base;
63 tfm->descsize = sizeof(crypto_hash_sha256_state);
67 static struct shash_alg sha256_alg = {
68 .digestsize = crypto_hash_sha256_BYTES,
70 .update = sha256_update,
71 .final = sha256_final,
72 .descsize = sizeof(crypto_hash_sha256_state),
73 .base.cra_name = "sha256",
74 .base.alloc_tfm = sha256_alloc_tfm,
77 __attribute__((constructor(110)))
78 static int __init sha256_generic_mod_init(void)
80 return crypto_register_shash(&sha256_alg);