blob: 72fe480f9bd67de37747034a714379e884047e1c [file] [log] [blame]
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +01001// SPDX-License-Identifier: GPL-2.0 OR MIT
2/*
Eric Biggers669d2192020-12-23 00:09:54 -08003 * shash interface to the generic implementation of BLAKE2s
4 *
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +01005 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
6 */
7
8#include <crypto/internal/blake2s.h>
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +01009#include <crypto/internal/hash.h>
10
11#include <linux/types.h>
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +010012#include <linux/kernel.h>
13#include <linux/module.h>
14
Eric Biggers669d2192020-12-23 00:09:54 -080015static int crypto_blake2s_update_generic(struct shash_desc *desc,
16 const u8 *in, unsigned int inlen)
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +010017{
Eric Biggers669d2192020-12-23 00:09:54 -080018 return crypto_blake2s_update(desc, in, inlen, blake2s_compress_generic);
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +010019}
20
Eric Biggers669d2192020-12-23 00:09:54 -080021static int crypto_blake2s_final_generic(struct shash_desc *desc, u8 *out)
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +010022{
Eric Biggers669d2192020-12-23 00:09:54 -080023 return crypto_blake2s_final(desc, out, blake2s_compress_generic);
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +010024}
25
Eric Biggers2ccec4b2020-12-23 00:09:50 -080026#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, \
Eric Biggers669d2192020-12-23 00:09:54 -080038 .update = crypto_blake2s_update_generic, \
39 .final = crypto_blake2s_final_generic, \
Eric Biggers2ccec4b2020-12-23 00:09:50 -080040 .descsize = sizeof(struct blake2s_state), \
41 }
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +010042
Eric Biggers2ccec4b2020-12-23 00:09:50 -080043static 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};
Ard Biesheuvel7f9b0882019-11-08 13:22:30 +010053
54static int __init blake2s_mod_init(void)
55{
56 return crypto_register_shashes(blake2s_algs, ARRAY_SIZE(blake2s_algs));
57}
58
59static void __exit blake2s_mod_exit(void)
60{
61 crypto_unregister_shashes(blake2s_algs, ARRAY_SIZE(blake2s_algs));
62}
63
64subsys_initcall(blake2s_mod_init);
65module_exit(blake2s_mod_exit);
66
67MODULE_ALIAS_CRYPTO("blake2s-128");
68MODULE_ALIAS_CRYPTO("blake2s-128-generic");
69MODULE_ALIAS_CRYPTO("blake2s-160");
70MODULE_ALIAS_CRYPTO("blake2s-160-generic");
71MODULE_ALIAS_CRYPTO("blake2s-224");
72MODULE_ALIAS_CRYPTO("blake2s-224-generic");
73MODULE_ALIAS_CRYPTO("blake2s-256");
74MODULE_ALIAS_CRYPTO("blake2s-256-generic");
75MODULE_LICENSE("GPL v2");