blake2s_generic.c (2275B)
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 15static 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 21static 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 43static 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 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");