xref: /openbmc/linux/arch/arm/crypto/sha1_glue.c (revision f5c27da4)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Cryptographic API.
4  * Glue code for the SHA1 Secure Hash Algorithm assembler implementation
5  *
6  * This file is based on sha1_generic.c and sha1_ssse3_glue.c
7  *
8  * Copyright (c) Alan Smithee.
9  * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
10  * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
11  * Copyright (c) Mathias Krause <minipli@googlemail.com>
12  */
13 
14 #include <crypto/internal/hash.h>
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <crypto/sha1.h>
19 #include <crypto/sha1_base.h>
20 #include <asm/byteorder.h>
21 
22 #include "sha1.h"
23 
24 asmlinkage void sha1_block_data_order(u32 *digest,
25 		const unsigned char *data, unsigned int rounds);
26 
27 int sha1_update_arm(struct shash_desc *desc, const u8 *data,
28 		    unsigned int len)
29 {
30 	/* make sure casting to sha1_block_fn() is safe */
31 	BUILD_BUG_ON(offsetof(struct sha1_state, state) != 0);
32 
33 	return sha1_base_do_update(desc, data, len,
34 				   (sha1_block_fn *)sha1_block_data_order);
35 }
36 EXPORT_SYMBOL_GPL(sha1_update_arm);
37 
38 static int sha1_final(struct shash_desc *desc, u8 *out)
39 {
40 	sha1_base_do_finalize(desc, (sha1_block_fn *)sha1_block_data_order);
41 	return sha1_base_finish(desc, out);
42 }
43 
44 int sha1_finup_arm(struct shash_desc *desc, const u8 *data,
45 		   unsigned int len, u8 *out)
46 {
47 	sha1_base_do_update(desc, data, len,
48 			    (sha1_block_fn *)sha1_block_data_order);
49 	return sha1_final(desc, out);
50 }
51 EXPORT_SYMBOL_GPL(sha1_finup_arm);
52 
53 static struct shash_alg alg = {
54 	.digestsize	=	SHA1_DIGEST_SIZE,
55 	.init		=	sha1_base_init,
56 	.update		=	sha1_update_arm,
57 	.final		=	sha1_final,
58 	.finup		=	sha1_finup_arm,
59 	.descsize	=	sizeof(struct sha1_state),
60 	.base		=	{
61 		.cra_name	=	"sha1",
62 		.cra_driver_name=	"sha1-asm",
63 		.cra_priority	=	150,
64 		.cra_blocksize	=	SHA1_BLOCK_SIZE,
65 		.cra_module	=	THIS_MODULE,
66 	}
67 };
68 
69 
70 static int __init sha1_mod_init(void)
71 {
72 	return crypto_register_shash(&alg);
73 }
74 
75 
76 static void __exit sha1_mod_fini(void)
77 {
78 	crypto_unregister_shash(&alg);
79 }
80 
81 
82 module_init(sha1_mod_init);
83 module_exit(sha1_mod_fini);
84 
85 MODULE_LICENSE("GPL");
86 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm (ARM)");
87 MODULE_ALIAS_CRYPTO("sha1");
88 MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>");
89