xref: /openbmc/linux/arch/arm/crypto/blake2s-glue.c (revision be58f710)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * BLAKE2s digest algorithm, ARM scalar implementation
4  *
5  * Copyright 2020 Google LLC
6  */
7 
8 #include <crypto/internal/blake2s.h>
9 #include <crypto/internal/hash.h>
10 
11 #include <linux/module.h>
12 
13 /* defined in blake2s-core.S */
14 EXPORT_SYMBOL(blake2s_compress_arch);
15 
16 static int crypto_blake2s_update_arm(struct shash_desc *desc,
17 				     const u8 *in, unsigned int inlen)
18 {
19 	return crypto_blake2s_update(desc, in, inlen, blake2s_compress_arch);
20 }
21 
22 static int crypto_blake2s_final_arm(struct shash_desc *desc, u8 *out)
23 {
24 	return crypto_blake2s_final(desc, out, blake2s_compress_arch);
25 }
26 
27 #define BLAKE2S_ALG(name, driver_name, digest_size)			\
28 	{								\
29 		.base.cra_name		= name,				\
30 		.base.cra_driver_name	= driver_name,			\
31 		.base.cra_priority	= 200,				\
32 		.base.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,	\
33 		.base.cra_blocksize	= BLAKE2S_BLOCK_SIZE,		\
34 		.base.cra_ctxsize	= sizeof(struct blake2s_tfm_ctx), \
35 		.base.cra_module	= THIS_MODULE,			\
36 		.digestsize		= digest_size,			\
37 		.setkey			= crypto_blake2s_setkey,	\
38 		.init			= crypto_blake2s_init,		\
39 		.update			= crypto_blake2s_update_arm,	\
40 		.final			= crypto_blake2s_final_arm,	\
41 		.descsize		= sizeof(struct blake2s_state),	\
42 	}
43 
44 static struct shash_alg blake2s_arm_algs[] = {
45 	BLAKE2S_ALG("blake2s-128", "blake2s-128-arm", BLAKE2S_128_HASH_SIZE),
46 	BLAKE2S_ALG("blake2s-160", "blake2s-160-arm", BLAKE2S_160_HASH_SIZE),
47 	BLAKE2S_ALG("blake2s-224", "blake2s-224-arm", BLAKE2S_224_HASH_SIZE),
48 	BLAKE2S_ALG("blake2s-256", "blake2s-256-arm", BLAKE2S_256_HASH_SIZE),
49 };
50 
51 static int __init blake2s_arm_mod_init(void)
52 {
53 	return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
54 		crypto_register_shashes(blake2s_arm_algs,
55 					ARRAY_SIZE(blake2s_arm_algs)) : 0;
56 }
57 
58 static void __exit blake2s_arm_mod_exit(void)
59 {
60 	if (IS_REACHABLE(CONFIG_CRYPTO_HASH))
61 		crypto_unregister_shashes(blake2s_arm_algs,
62 					  ARRAY_SIZE(blake2s_arm_algs));
63 }
64 
65 module_init(blake2s_arm_mod_init);
66 module_exit(blake2s_arm_mod_exit);
67 
68 MODULE_DESCRIPTION("BLAKE2s digest algorithm, ARM scalar implementation");
69 MODULE_LICENSE("GPL");
70 MODULE_AUTHOR("Eric Biggers <ebiggers@google.com>");
71 MODULE_ALIAS_CRYPTO("blake2s-128");
72 MODULE_ALIAS_CRYPTO("blake2s-128-arm");
73 MODULE_ALIAS_CRYPTO("blake2s-160");
74 MODULE_ALIAS_CRYPTO("blake2s-160-arm");
75 MODULE_ALIAS_CRYPTO("blake2s-224");
76 MODULE_ALIAS_CRYPTO("blake2s-224-arm");
77 MODULE_ALIAS_CRYPTO("blake2s-256");
78 MODULE_ALIAS_CRYPTO("blake2s-256-arm");
79