1 /* 2 * sha1-ce-glue.c - SHA-1 secure hash using ARMv8 Crypto Extensions 3 * 4 * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 */ 10 11 #include <crypto/internal/hash.h> 12 #include <crypto/internal/simd.h> 13 #include <crypto/sha.h> 14 #include <crypto/sha1_base.h> 15 #include <linux/cpufeature.h> 16 #include <linux/crypto.h> 17 #include <linux/module.h> 18 19 #include <asm/hwcap.h> 20 #include <asm/neon.h> 21 #include <asm/simd.h> 22 23 #include "sha1.h" 24 25 MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions"); 26 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); 27 MODULE_LICENSE("GPL v2"); 28 29 asmlinkage void sha1_ce_transform(struct sha1_state *sst, u8 const *src, 30 int blocks); 31 32 static int sha1_ce_update(struct shash_desc *desc, const u8 *data, 33 unsigned int len) 34 { 35 struct sha1_state *sctx = shash_desc_ctx(desc); 36 37 if (!crypto_simd_usable() || 38 (sctx->count % SHA1_BLOCK_SIZE) + len < SHA1_BLOCK_SIZE) 39 return sha1_update_arm(desc, data, len); 40 41 kernel_neon_begin(); 42 sha1_base_do_update(desc, data, len, sha1_ce_transform); 43 kernel_neon_end(); 44 45 return 0; 46 } 47 48 static int sha1_ce_finup(struct shash_desc *desc, const u8 *data, 49 unsigned int len, u8 *out) 50 { 51 if (!crypto_simd_usable()) 52 return sha1_finup_arm(desc, data, len, out); 53 54 kernel_neon_begin(); 55 if (len) 56 sha1_base_do_update(desc, data, len, sha1_ce_transform); 57 sha1_base_do_finalize(desc, sha1_ce_transform); 58 kernel_neon_end(); 59 60 return sha1_base_finish(desc, out); 61 } 62 63 static int sha1_ce_final(struct shash_desc *desc, u8 *out) 64 { 65 return sha1_ce_finup(desc, NULL, 0, out); 66 } 67 68 static struct shash_alg alg = { 69 .init = sha1_base_init, 70 .update = sha1_ce_update, 71 .final = sha1_ce_final, 72 .finup = sha1_ce_finup, 73 .descsize = sizeof(struct sha1_state), 74 .digestsize = SHA1_DIGEST_SIZE, 75 .base = { 76 .cra_name = "sha1", 77 .cra_driver_name = "sha1-ce", 78 .cra_priority = 200, 79 .cra_blocksize = SHA1_BLOCK_SIZE, 80 .cra_module = THIS_MODULE, 81 } 82 }; 83 84 static int __init sha1_ce_mod_init(void) 85 { 86 return crypto_register_shash(&alg); 87 } 88 89 static void __exit sha1_ce_mod_fini(void) 90 { 91 crypto_unregister_shash(&alg); 92 } 93 94 module_cpu_feature_match(SHA1, sha1_ce_mod_init); 95 module_exit(sha1_ce_mod_fini); 96