]>
Commit | Line | Data |
---|---|---|
7f9b0880 AB |
1 | // SPDX-License-Identifier: GPL-2.0 OR MIT |
2 | /* | |
8c4a93a1 EB |
3 | * shash interface to the generic implementation of BLAKE2s |
4 | * | |
7f9b0880 AB |
5 | * Copyright (C) 2015-2019 Jason A. Donenfeld <[email protected]>. All Rights Reserved. |
6 | */ | |
7 | ||
8 | #include <crypto/internal/blake2s.h> | |
7f9b0880 AB |
9 | #include <crypto/internal/hash.h> |
10 | ||
11 | #include <linux/types.h> | |
7f9b0880 AB |
12 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | |
14 | ||
8c4a93a1 EB |
15 | static int crypto_blake2s_update_generic(struct shash_desc *desc, |
16 | const u8 *in, unsigned int inlen) | |
7f9b0880 | 17 | { |
8c4a93a1 | 18 | return crypto_blake2s_update(desc, in, inlen, blake2s_compress_generic); |
7f9b0880 AB |
19 | } |
20 | ||
8c4a93a1 | 21 | static int crypto_blake2s_final_generic(struct shash_desc *desc, u8 *out) |
7f9b0880 | 22 | { |
8c4a93a1 | 23 | return crypto_blake2s_final(desc, out, blake2s_compress_generic); |
7f9b0880 AB |
24 | } |
25 | ||
0d396058 EB |
26 | #define BLAKE2S_ALG(name, driver_name, digest_size) \ |
27 | { \ | |
28 | .base.cra_name = name, \ | |
29 | .base.cra_driver_name = driver_name, \ | |
30 | .base.cra_priority = 100, \ | |
31 | .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, \ | |
32 | .base.cra_blocksize = BLAKE2S_BLOCK_SIZE, \ | |
33 | .base.cra_ctxsize = sizeof(struct blake2s_tfm_ctx), \ | |
34 | .base.cra_module = THIS_MODULE, \ | |
35 | .digestsize = digest_size, \ | |
36 | .setkey = crypto_blake2s_setkey, \ | |
37 | .init = crypto_blake2s_init, \ | |
8c4a93a1 EB |
38 | .update = crypto_blake2s_update_generic, \ |
39 | .final = crypto_blake2s_final_generic, \ | |
0d396058 EB |
40 | .descsize = sizeof(struct blake2s_state), \ |
41 | } | |
42 | ||
43 | static struct shash_alg blake2s_algs[] = { | |
44 | BLAKE2S_ALG("blake2s-128", "blake2s-128-generic", | |
45 | BLAKE2S_128_HASH_SIZE), | |
46 | BLAKE2S_ALG("blake2s-160", "blake2s-160-generic", | |
47 | BLAKE2S_160_HASH_SIZE), | |
48 | BLAKE2S_ALG("blake2s-224", "blake2s-224-generic", | |
49 | BLAKE2S_224_HASH_SIZE), | |
50 | BLAKE2S_ALG("blake2s-256", "blake2s-256-generic", | |
51 | BLAKE2S_256_HASH_SIZE), | |
52 | }; | |
7f9b0880 AB |
53 | |
54 | static int __init blake2s_mod_init(void) | |
55 | { | |
56 | return crypto_register_shashes(blake2s_algs, ARRAY_SIZE(blake2s_algs)); | |
57 | } | |
58 | ||
59 | static void __exit blake2s_mod_exit(void) | |
60 | { | |
61 | crypto_unregister_shashes(blake2s_algs, ARRAY_SIZE(blake2s_algs)); | |
62 | } | |
63 | ||
64 | subsys_initcall(blake2s_mod_init); | |
65 | module_exit(blake2s_mod_exit); | |
66 | ||
67 | MODULE_ALIAS_CRYPTO("blake2s-128"); | |
68 | MODULE_ALIAS_CRYPTO("blake2s-128-generic"); | |
69 | MODULE_ALIAS_CRYPTO("blake2s-160"); | |
70 | MODULE_ALIAS_CRYPTO("blake2s-160-generic"); | |
71 | MODULE_ALIAS_CRYPTO("blake2s-224"); | |
72 | MODULE_ALIAS_CRYPTO("blake2s-224-generic"); | |
73 | MODULE_ALIAS_CRYPTO("blake2s-256"); | |
74 | MODULE_ALIAS_CRYPTO("blake2s-256-generic"); | |
75 | MODULE_LICENSE("GPL v2"); |