Merge tag 'x86_cpu_for_v5.18_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[platform/kernel/linux-starfive.git] / crypto / blake2s_generic.c
1 // SPDX-License-Identifier: GPL-2.0 OR MIT
2 /*
3  * shash interface to the generic implementation of BLAKE2s
4  *
5  * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
6  */
7
8 #include <crypto/internal/blake2s.h>
9 #include <crypto/internal/hash.h>
10
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14
15 static int crypto_blake2s_update_generic(struct shash_desc *desc,
16                                          const u8 *in, unsigned int inlen)
17 {
18         return crypto_blake2s_update(desc, in, inlen, true);
19 }
20
21 static int crypto_blake2s_final_generic(struct shash_desc *desc, u8 *out)
22 {
23         return crypto_blake2s_final(desc, out, true);
24 }
25
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,          \
38                 .update                 = crypto_blake2s_update_generic, \
39                 .final                  = crypto_blake2s_final_generic, \
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 };
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");