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