1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * sm3-ce-glue.c - SM3 secure hash using ARMv8.2 Crypto Extensions 4 * 5 * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org> 6 */ 7 8 #include <asm/neon.h> 9 #include <crypto/internal/hash.h> 10 #include <crypto/sm3.h> 11 #include <crypto/sm3_base.h> 12 #include <linux/cpufeature.h> 13 #include <linux/kernel.h> 14 #include <linux/module.h> 15 16 MODULE_DESCRIPTION("SM3 secure hash using ARMv8 Crypto Extensions"); 17 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); 18 MODULE_LICENSE("GPL v2"); 19 20 asmlinkage void sm3_ce_transform(struct sm3_state *sst, u8 const *src, 21 int blocks); 22 23 static int sm3_ce_update(struct shash_desc *desc, const u8 *data, 24 unsigned int len) 25 { 26 int remain; 27 28 kernel_neon_begin(); 29 remain = sm3_base_do_update_blocks(desc, data, len, sm3_ce_transform); 30 kernel_neon_end(); 31 return remain; 32 } 33 34 static int sm3_ce_finup(struct shash_desc *desc, const u8 *data, 35 unsigned int len, u8 *out) 36 { 37 kernel_neon_begin(); 38 sm3_base_do_finup(desc, data, len, sm3_ce_transform); 39 kernel_neon_end(); 40 return sm3_base_finish(desc, out); 41 } 42 43 static struct shash_alg sm3_alg = { 44 .digestsize = SM3_DIGEST_SIZE, 45 .init = sm3_base_init, 46 .update = sm3_ce_update, 47 .finup = sm3_ce_finup, 48 .descsize = SM3_STATE_SIZE, 49 .base.cra_name = "sm3", 50 .base.cra_driver_name = "sm3-ce", 51 .base.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY | 52 CRYPTO_AHASH_ALG_FINUP_MAX, 53 .base.cra_blocksize = SM3_BLOCK_SIZE, 54 .base.cra_module = THIS_MODULE, 55 .base.cra_priority = 400, 56 }; 57 58 static int __init sm3_ce_mod_init(void) 59 { 60 return crypto_register_shash(&sm3_alg); 61 } 62 63 static void __exit sm3_ce_mod_fini(void) 64 { 65 crypto_unregister_shash(&sm3_alg); 66 } 67 68 module_cpu_feature_match(SM3, sm3_ce_mod_init); 69 module_exit(sm3_ce_mod_fini); 70