ublk_drv: remove nr_aborted_queues from ublk_device
[linux-block.git] / crypto / sha1_generic.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
1da177e4
LT
2/*
3 * Cryptographic API.
4 *
5 * SHA1 Secure Hash Algorithm.
6 *
7 * Derived from cryptoapi implementation, adapted for in-place
8 * scatterlist interface.
9 *
10 * Copyright (c) Alan Smithee.
11 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
12 * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
1da177e4 13 */
54ccb367 14#include <crypto/internal/hash.h>
1da177e4
LT
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/mm.h>
06ace7a9 18#include <linux/types.h>
a24d22b2 19#include <crypto/sha1.h>
7c71f0f7 20#include <crypto/sha1_base.h>
1da177e4
LT
21#include <asm/byteorder.h>
22
0c4c78de
LC
23const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE] = {
24 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d,
25 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90,
26 0xaf, 0xd8, 0x07, 0x09
27};
28EXPORT_SYMBOL_GPL(sha1_zero_message_hash);
29
7c71f0f7
AB
30static void sha1_generic_block_fn(struct sha1_state *sst, u8 const *src,
31 int blocks)
1da177e4 32{
6b0b0fa2 33 u32 temp[SHA1_WORKSPACE_WORDS];
54ccb367 34
7c71f0f7 35 while (blocks--) {
6b0b0fa2 36 sha1_transform(sst->state, src, temp);
7c71f0f7
AB
37 src += SHA1_BLOCK_SIZE;
38 }
39 memzero_explicit(temp, sizeof(temp));
1da177e4
LT
40}
41
7c390170 42int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
7c71f0f7 43 unsigned int len)
1da177e4 44{
7c71f0f7 45 return sha1_base_do_update(desc, data, len, sha1_generic_block_fn);
1da177e4 46}
7c390170 47EXPORT_SYMBOL(crypto_sha1_update);
1da177e4 48
54ccb367 49static int sha1_final(struct shash_desc *desc, u8 *out)
1da177e4 50{
7c71f0f7
AB
51 sha1_base_do_finalize(desc, sha1_generic_block_fn);
52 return sha1_base_finish(desc, out);
1da177e4
LT
53}
54
7c71f0f7
AB
55int crypto_sha1_finup(struct shash_desc *desc, const u8 *data,
56 unsigned int len, u8 *out)
e2a7ce4e 57{
7c71f0f7
AB
58 sha1_base_do_update(desc, data, len, sha1_generic_block_fn);
59 return sha1_final(desc, out);
e2a7ce4e 60}
7c71f0f7 61EXPORT_SYMBOL(crypto_sha1_finup);
e2a7ce4e 62
54ccb367
AKR
63static struct shash_alg alg = {
64 .digestsize = SHA1_DIGEST_SIZE,
7c71f0f7 65 .init = sha1_base_init,
7c390170 66 .update = crypto_sha1_update,
54ccb367 67 .final = sha1_final,
7c71f0f7 68 .finup = crypto_sha1_finup,
e2a7ce4e 69 .descsize = sizeof(struct sha1_state),
54ccb367
AKR
70 .base = {
71 .cra_name = "sha1",
72 .cra_driver_name= "sha1-generic",
90ef3e48 73 .cra_priority = 100,
54ccb367
AKR
74 .cra_blocksize = SHA1_BLOCK_SIZE,
75 .cra_module = THIS_MODULE,
76 }
1da177e4
LT
77};
78
3af5b90b 79static int __init sha1_generic_mod_init(void)
1da177e4 80{
54ccb367 81 return crypto_register_shash(&alg);
1da177e4
LT
82}
83
3af5b90b 84static void __exit sha1_generic_mod_fini(void)
1da177e4 85{
54ccb367 86 crypto_unregister_shash(&alg);
1da177e4
LT
87}
88
c4741b23 89subsys_initcall(sha1_generic_mod_init);
3af5b90b 90module_exit(sha1_generic_mod_fini);
1da177e4
LT
91
92MODULE_LICENSE("GPL");
93MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
b3be9a6d 94
5d26a105 95MODULE_ALIAS_CRYPTO("sha1");
3e14dcf7 96MODULE_ALIAS_CRYPTO("sha1-generic");