Jason A. Donenfeld | 6048fdc | 2021-12-22 14:56:58 +0100 | [diff] [blame] | 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 | static int crypto_blake2s_update_arm(struct shash_desc *desc, |
| 14 | const u8 *in, unsigned int inlen) |
| 15 | { |
| 16 | return crypto_blake2s_update(desc, in, inlen, blake2s_compress); |
| 17 | } |
| 18 | |
| 19 | static int crypto_blake2s_final_arm(struct shash_desc *desc, u8 *out) |
| 20 | { |
| 21 | return crypto_blake2s_final(desc, out, blake2s_compress); |
| 22 | } |
| 23 | |
| 24 | #define BLAKE2S_ALG(name, driver_name, digest_size) \ |
| 25 | { \ |
| 26 | .base.cra_name = name, \ |
| 27 | .base.cra_driver_name = driver_name, \ |
| 28 | .base.cra_priority = 200, \ |
| 29 | .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, \ |
| 30 | .base.cra_blocksize = BLAKE2S_BLOCK_SIZE, \ |
| 31 | .base.cra_ctxsize = sizeof(struct blake2s_tfm_ctx), \ |
| 32 | .base.cra_module = THIS_MODULE, \ |
| 33 | .digestsize = digest_size, \ |
| 34 | .setkey = crypto_blake2s_setkey, \ |
| 35 | .init = crypto_blake2s_init, \ |
| 36 | .update = crypto_blake2s_update_arm, \ |
| 37 | .final = crypto_blake2s_final_arm, \ |
| 38 | .descsize = sizeof(struct blake2s_state), \ |
| 39 | } |
| 40 | |
| 41 | static struct shash_alg blake2s_arm_algs[] = { |
| 42 | BLAKE2S_ALG("blake2s-128", "blake2s-128-arm", BLAKE2S_128_HASH_SIZE), |
| 43 | BLAKE2S_ALG("blake2s-160", "blake2s-160-arm", BLAKE2S_160_HASH_SIZE), |
| 44 | BLAKE2S_ALG("blake2s-224", "blake2s-224-arm", BLAKE2S_224_HASH_SIZE), |
| 45 | BLAKE2S_ALG("blake2s-256", "blake2s-256-arm", BLAKE2S_256_HASH_SIZE), |
| 46 | }; |
| 47 | |
| 48 | static int __init blake2s_arm_mod_init(void) |
| 49 | { |
| 50 | return IS_REACHABLE(CONFIG_CRYPTO_HASH) ? |
| 51 | crypto_register_shashes(blake2s_arm_algs, |
| 52 | ARRAY_SIZE(blake2s_arm_algs)) : 0; |
| 53 | } |
| 54 | |
| 55 | static void __exit blake2s_arm_mod_exit(void) |
| 56 | { |
| 57 | if (IS_REACHABLE(CONFIG_CRYPTO_HASH)) |
| 58 | crypto_unregister_shashes(blake2s_arm_algs, |
| 59 | ARRAY_SIZE(blake2s_arm_algs)); |
| 60 | } |
| 61 | |
| 62 | module_init(blake2s_arm_mod_init); |
| 63 | module_exit(blake2s_arm_mod_exit); |
| 64 | |
| 65 | MODULE_DESCRIPTION("BLAKE2s digest algorithm, ARM scalar implementation"); |
| 66 | MODULE_LICENSE("GPL"); |
| 67 | MODULE_AUTHOR("Eric Biggers <ebiggers@google.com>"); |
| 68 | MODULE_ALIAS_CRYPTO("blake2s-128"); |
| 69 | MODULE_ALIAS_CRYPTO("blake2s-128-arm"); |
| 70 | MODULE_ALIAS_CRYPTO("blake2s-160"); |
| 71 | MODULE_ALIAS_CRYPTO("blake2s-160-arm"); |
| 72 | MODULE_ALIAS_CRYPTO("blake2s-224"); |
| 73 | MODULE_ALIAS_CRYPTO("blake2s-224-arm"); |
| 74 | MODULE_ALIAS_CRYPTO("blake2s-256"); |
| 75 | MODULE_ALIAS_CRYPTO("blake2s-256-arm"); |