Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Cryptographic API.
4 *
5 * powerpc implementation of the SHA1 Secure Hash Algorithm.
6 *
7 * Derived from cryptoapi implementation, adapted for in-place
8 * scatterlist interface.
9 *
10 * Derived from "crypto/sha1.c"
11 * Copyright (c) Alan Smithee.
12 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
13 * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
14 */
15#include <crypto/internal/hash.h>
16#include <crypto/sha1.h>
17#include <crypto/sha1_base.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20
21asmlinkage void powerpc_sha_transform(u32 *state, const u8 *src);
22
23static void powerpc_sha_block(struct sha1_state *sctx, const u8 *data,
24 int blocks)
25{
26 do {
27 powerpc_sha_transform(sctx->state, data);
28 data += 64;
29 } while (--blocks);
30}
31
32static int powerpc_sha1_update(struct shash_desc *desc, const u8 *data,
33 unsigned int len)
34{
35 return sha1_base_do_update_blocks(desc, data, len, powerpc_sha_block);
36}
37
38/* Add padding and return the message digest. */
39static int powerpc_sha1_finup(struct shash_desc *desc, const u8 *src,
40 unsigned int len, u8 *out)
41{
42 sha1_base_do_finup(desc, src, len, powerpc_sha_block);
43 return sha1_base_finish(desc, out);
44}
45
46static struct shash_alg alg = {
47 .digestsize = SHA1_DIGEST_SIZE,
48 .init = sha1_base_init,
49 .update = powerpc_sha1_update,
50 .finup = powerpc_sha1_finup,
51 .descsize = SHA1_STATE_SIZE,
52 .base = {
53 .cra_name = "sha1",
54 .cra_driver_name= "sha1-powerpc",
55 .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY,
56 .cra_blocksize = SHA1_BLOCK_SIZE,
57 .cra_module = THIS_MODULE,
58 }
59};
60
61static int __init sha1_powerpc_mod_init(void)
62{
63 return crypto_register_shash(&alg);
64}
65
66static void __exit sha1_powerpc_mod_fini(void)
67{
68 crypto_unregister_shash(&alg);
69}
70
71module_init(sha1_powerpc_mod_init);
72module_exit(sha1_powerpc_mod_fini);
73
74MODULE_LICENSE("GPL");
75MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
76
77MODULE_ALIAS_CRYPTO("sha1");
78MODULE_ALIAS_CRYPTO("sha1-powerpc");