Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 OR MIT |
| 2 | /* |
Eric Biggers | 8c4a93a | 2020-12-23 00:09:54 -0800 | [diff] [blame] | 3 | * shash interface to the generic implementation of BLAKE2s |
| 4 | * |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 5 | * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. |
| 6 | */ |
| 7 | |
| 8 | #include <crypto/internal/blake2s.h> |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 9 | #include <crypto/internal/hash.h> |
| 10 | |
| 11 | #include <linux/types.h> |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
| 14 | |
Eric Biggers | 8c4a93a | 2020-12-23 00:09:54 -0800 | [diff] [blame] | 15 | static int crypto_blake2s_update_generic(struct shash_desc *desc, |
| 16 | const u8 *in, unsigned int inlen) |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 17 | { |
Eric Biggers | 8c4a93a | 2020-12-23 00:09:54 -0800 | [diff] [blame] | 18 | return crypto_blake2s_update(desc, in, inlen, blake2s_compress_generic); |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 19 | } |
| 20 | |
Eric Biggers | 8c4a93a | 2020-12-23 00:09:54 -0800 | [diff] [blame] | 21 | static int crypto_blake2s_final_generic(struct shash_desc *desc, u8 *out) |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 22 | { |
Eric Biggers | 8c4a93a | 2020-12-23 00:09:54 -0800 | [diff] [blame] | 23 | return crypto_blake2s_final(desc, out, blake2s_compress_generic); |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 24 | } |
| 25 | |
Eric Biggers | 0d39605 | 2020-12-23 00:09:50 -0800 | [diff] [blame] | 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, \ |
Eric Biggers | 8c4a93a | 2020-12-23 00:09:54 -0800 | [diff] [blame] | 38 | .update = crypto_blake2s_update_generic, \ |
| 39 | .final = crypto_blake2s_final_generic, \ |
Eric Biggers | 0d39605 | 2020-12-23 00:09:50 -0800 | [diff] [blame] | 40 | .descsize = sizeof(struct blake2s_state), \ |
| 41 | } |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 42 | |
Eric Biggers | 0d39605 | 2020-12-23 00:09:50 -0800 | [diff] [blame] | 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 | }; |
Ard Biesheuvel | 7f9b088 | 2019-11-08 13:22:30 +0100 | [diff] [blame] | 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"); |