]> git.sesse.net Git - bcachefs-tools-debian/blob - linux/crypto/sha256_generic.c
remove library from bcachefs-tools Rust package
[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/hash.h>
28
29 #include <sodium/crypto_hash_sha256.h>
30
31 static struct shash_alg sha256_alg;
32
33 static int sha256_init(struct shash_desc *desc)
34 {
35         crypto_hash_sha256_state *state = (void *) desc->ctx;
36
37         return crypto_hash_sha256_init(state);
38 }
39
40 static int sha256_update(struct shash_desc *desc, const u8 *data,
41                           unsigned int len)
42 {
43         crypto_hash_sha256_state *state = (void *) desc->ctx;
44
45         return crypto_hash_sha256_update(state, data, len);
46 }
47
48 static int sha256_final(struct shash_desc *desc, u8 *out)
49 {
50         crypto_hash_sha256_state *state = (void *) desc->ctx;
51
52         return crypto_hash_sha256_final(state, out);
53 }
54
55 static void *sha256_alloc_tfm(void)
56 {
57         struct crypto_shash *tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
58
59         if (!tfm)
60                 return NULL;
61
62         tfm->base.alg = &sha256_alg.base;
63         tfm->descsize = sizeof(crypto_hash_sha256_state);
64         return tfm;
65 }
66
67 static struct shash_alg sha256_alg = {
68         .digestsize     = crypto_hash_sha256_BYTES,
69         .init           = sha256_init,
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,
75 };
76
77 __attribute__((constructor(110)))
78 static int __init sha256_generic_mod_init(void)
79 {
80         return crypto_register_shash(&sha256_alg);
81 }