1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* 3 * BLAKE2b digest algorithm, NEON accelerated 4 * 5 * Copyright 2020 Google LLC 6 */ 7 8 #include <crypto/internal/blake2b.h> 9 #include <crypto/internal/hash.h> 10 #include <crypto/internal/simd.h> 11 12 #include <linux/module.h> 13 #include <linux/sizes.h> 14 15 #include <asm/neon.h> 16 #include <asm/simd.h> 17 18 asmlinkage void blake2b_compress_neon(struct b 19 const u8 20 21 static void blake2b_compress_arch(struct blake 22 const u8 *bl 23 { 24 if (!crypto_simd_usable()) { 25 blake2b_compress_generic(state 26 return; 27 } 28 29 do { 30 const size_t blocks = min_t(si 31 SZ 32 33 kernel_neon_begin(); 34 blake2b_compress_neon(state, b 35 kernel_neon_end(); 36 37 nblocks -= blocks; 38 block += blocks * BLAKE2B_BLOC 39 } while (nblocks); 40 } 41 42 static int crypto_blake2b_update_neon(struct s 43 const u8 44 { 45 return crypto_blake2b_update(desc, in, 46 } 47 48 static int crypto_blake2b_final_neon(struct sh 49 { 50 return crypto_blake2b_final(desc, out, 51 } 52 53 #define BLAKE2B_ALG(name, driver_name, digest_ 54 { 55 .base.cra_name = name 56 .base.cra_driver_name = driv 57 .base.cra_priority = 200, 58 .base.cra_flags = CRYP 59 .base.cra_blocksize = BLAK 60 .base.cra_ctxsize = size 61 .base.cra_module = THIS 62 .digestsize = dige 63 .setkey = cryp 64 .init = cryp 65 .update = cryp 66 .final = cryp 67 .descsize = size 68 } 69 70 static struct shash_alg blake2b_neon_algs[] = 71 BLAKE2B_ALG("blake2b-160", "blake2b-16 72 BLAKE2B_ALG("blake2b-256", "blake2b-25 73 BLAKE2B_ALG("blake2b-384", "blake2b-38 74 BLAKE2B_ALG("blake2b-512", "blake2b-51 75 }; 76 77 static int __init blake2b_neon_mod_init(void) 78 { 79 if (!(elf_hwcap & HWCAP_NEON)) 80 return -ENODEV; 81 82 return crypto_register_shashes(blake2b 83 ARRAY_S 84 } 85 86 static void __exit blake2b_neon_mod_exit(void) 87 { 88 crypto_unregister_shashes(blake2b_neon 89 ARRAY_SIZE(b 90 } 91 92 module_init(blake2b_neon_mod_init); 93 module_exit(blake2b_neon_mod_exit); 94 95 MODULE_DESCRIPTION("BLAKE2b digest algorithm, 96 MODULE_LICENSE("GPL"); 97 MODULE_AUTHOR("Eric Biggers <ebiggers@google.c 98 MODULE_ALIAS_CRYPTO("blake2b-160"); 99 MODULE_ALIAS_CRYPTO("blake2b-160-neon"); 100 MODULE_ALIAS_CRYPTO("blake2b-256"); 101 MODULE_ALIAS_CRYPTO("blake2b-256-neon"); 102 MODULE_ALIAS_CRYPTO("blake2b-384"); 103 MODULE_ALIAS_CRYPTO("blake2b-384-neon"); 104 MODULE_ALIAS_CRYPTO("blake2b-512"); 105 MODULE_ALIAS_CRYPTO("blake2b-512-neon"); 106
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.