]> git.sesse.net Git - bcachefs-tools-debian/blob - linux/crypto/sha256_generic.c
New on disk format - encryption
[bcachefs-tools-debian] / linux / crypto / sha256_generic.c
1 /*
2  * Cryptographic API.
3  *
4  * SHA-256, as specified in
5  * http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf
6  *
7  * SHA-256 code by Jean-Luc Cooke <jlcooke@certainkey.com>.
8  *
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>
13  *
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) 
17  * any later version.
18  *
19  */
20
21 #include <linux/bitops.h>
22 #include <linux/byteorder.h>
23 #include <linux/types.h>
24 #include <asm/unaligned.h>
25
26 #include <linux/crypto.h>
27 #include <crypto/internal/hash.h>
28
29 #include <sodium/crypto_hash_sha256.h>
30
31 static int sha256_init(struct shash_desc *desc)
32 {
33         crypto_hash_sha256_state *state = shash_desc_ctx(desc);
34
35         return crypto_hash_sha256_init(state);
36 }
37
38 static int sha256_update(struct shash_desc *desc, const u8 *data,
39                           unsigned int len)
40 {
41         crypto_hash_sha256_state *state = shash_desc_ctx(desc);
42
43         return crypto_hash_sha256_update(state, data, len);
44 }
45
46 static int sha256_final(struct shash_desc *desc, u8 *out)
47 {
48         crypto_hash_sha256_state *state = shash_desc_ctx(desc);
49
50         return crypto_hash_sha256_final(state, out);
51 }
52
53 static struct shash_alg sha256_alg = {
54         .digestsize     = crypto_hash_sha256_BYTES,
55         .init           = sha256_init,
56         .update         = sha256_update,
57         .final          = sha256_final,
58         .descsize       = sizeof(crypto_hash_sha256_state),
59         .base           = {
60                 .cra_name       = "sha256",
61                 .cra_flags      = CRYPTO_ALG_TYPE_SHASH,
62         }
63 };
64
65 __attribute__((constructor(110)))
66 static int __init sha256_generic_mod_init(void)
67 {
68         return crypto_register_shash(&sha256_alg);
69 }