1 /* 2 * sha512-neon-glue.c - accelerated SHA-384/512 for ARM NEON 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/sha512_base.h> 15 #include <linux/crypto.h> 16 #include <linux/module.h> 17 18 #include <asm/simd.h> 19 #include <asm/neon.h> 20 21 #include "sha512.h" 22 23 MODULE_ALIAS_CRYPTO("sha384-neon"); 24 MODULE_ALIAS_CRYPTO("sha512-neon"); 25 26 asmlinkage void sha512_block_data_order_neon(u64 *state, u8 const *src, 27 int blocks); 28 29 static int sha512_neon_update(struct shash_desc *desc, const u8 *data, 30 unsigned int len) 31 { 32 struct sha512_state *sctx = shash_desc_ctx(desc); 33 34 if (!crypto_simd_usable() || 35 (sctx->count[0] % SHA512_BLOCK_SIZE) + len < SHA512_BLOCK_SIZE) 36 return sha512_arm_update(desc, data, len); 37 38 kernel_neon_begin(); 39 sha512_base_do_update(desc, data, len, 40 (sha512_block_fn *)sha512_block_data_order_neon); 41 kernel_neon_end(); 42 43 return 0; 44 } 45 46 static int sha512_neon_finup(struct shash_desc *desc, const u8 *data, 47 unsigned int len, u8 *out) 48 { 49 if (!crypto_simd_usable()) 50 return sha512_arm_finup(desc, data, len, out); 51 52 kernel_neon_begin(); 53 if (len) 54 sha512_base_do_update(desc, data, len, 55 (sha512_block_fn *)sha512_block_data_order_neon); 56 sha512_base_do_finalize(desc, 57 (sha512_block_fn *)sha512_block_data_order_neon); 58 kernel_neon_end(); 59 60 return sha512_base_finish(desc, out); 61 } 62 63 static int sha512_neon_final(struct shash_desc *desc, u8 *out) 64 { 65 return sha512_neon_finup(desc, NULL, 0, out); 66 } 67 68 struct shash_alg sha512_neon_algs[] = { { 69 .init = sha384_base_init, 70 .update = sha512_neon_update, 71 .final = sha512_neon_final, 72 .finup = sha512_neon_finup, 73 .descsize = sizeof(struct sha512_state), 74 .digestsize = SHA384_DIGEST_SIZE, 75 .base = { 76 .cra_name = "sha384", 77 .cra_driver_name = "sha384-neon", 78 .cra_priority = 300, 79 .cra_blocksize = SHA384_BLOCK_SIZE, 80 .cra_module = THIS_MODULE, 81 82 } 83 }, { 84 .init = sha512_base_init, 85 .update = sha512_neon_update, 86 .final = sha512_neon_final, 87 .finup = sha512_neon_finup, 88 .descsize = sizeof(struct sha512_state), 89 .digestsize = SHA512_DIGEST_SIZE, 90 .base = { 91 .cra_name = "sha512", 92 .cra_driver_name = "sha512-neon", 93 .cra_priority = 300, 94 .cra_blocksize = SHA512_BLOCK_SIZE, 95 .cra_module = THIS_MODULE, 96 } 97 } }; 98