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/internal/hash.h>
29 #include <sodium/crypto_hash_sha256.h>
31 static int sha256_init(struct shash_desc *desc)
33 crypto_hash_sha256_state *state = shash_desc_ctx(desc);
35 return crypto_hash_sha256_init(state);
38 static int sha256_update(struct shash_desc *desc, const u8 *data,
41 crypto_hash_sha256_state *state = shash_desc_ctx(desc);
43 return crypto_hash_sha256_update(state, data, len);
46 static int sha256_final(struct shash_desc *desc, u8 *out)
48 crypto_hash_sha256_state *state = shash_desc_ctx(desc);
50 return crypto_hash_sha256_final(state, out);
53 static struct shash_alg sha256_alg = {
54 .digestsize = crypto_hash_sha256_BYTES,
56 .update = sha256_update,
57 .final = sha256_final,
58 .descsize = sizeof(crypto_hash_sha256_state),
61 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
65 __attribute__((constructor(110)))
66 static int __init sha256_generic_mod_init(void)
68 return crypto_register_shash(&sha256_alg);