cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

blake2s-shash.c (2347B)


      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
     13static 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, false);
     17}
     18
     19static int crypto_blake2s_final_arm(struct shash_desc *desc, u8 *out)
     20{
     21	return crypto_blake2s_final(desc, out, false);
     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
     41static 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
     48static 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
     55static 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
     62module_init(blake2s_arm_mod_init);
     63module_exit(blake2s_arm_mod_exit);
     64
     65MODULE_DESCRIPTION("BLAKE2s digest algorithm, ARM scalar implementation");
     66MODULE_LICENSE("GPL");
     67MODULE_AUTHOR("Eric Biggers <ebiggers@google.com>");
     68MODULE_ALIAS_CRYPTO("blake2s-128");
     69MODULE_ALIAS_CRYPTO("blake2s-128-arm");
     70MODULE_ALIAS_CRYPTO("blake2s-160");
     71MODULE_ALIAS_CRYPTO("blake2s-160-arm");
     72MODULE_ALIAS_CRYPTO("blake2s-224");
     73MODULE_ALIAS_CRYPTO("blake2s-224-arm");
     74MODULE_ALIAS_CRYPTO("blake2s-256");
     75MODULE_ALIAS_CRYPTO("blake2s-256-arm");