1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Cryptographic API. 4 * Glue code for the SHA1 Secure Hash Algorithm assembler implementation 5 * 6 * This file is based on sha1_generic.c and sha1_ssse3_glue.c 7 * 8 * Copyright (c) Alan Smithee. 9 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> 10 * Copyright (c) Jean-Francois Dive <jef@linuxbe.org> 11 * Copyright (c) Mathias Krause <minipli@googlemail.com> 12 */ 13 14 #include <crypto/internal/hash.h> 15 #include <linux/init.h> 16 #include <linux/module.h> 17 #include <linux/cryptohash.h> 18 #include <linux/types.h> 19 #include <crypto/sha.h> 20 #include <crypto/sha1_base.h> 21 #include <asm/byteorder.h> 22 23 #include "sha1.h" 24 25 asmlinkage void sha1_block_data_order(u32 *digest, 26 const unsigned char *data, unsigned int rounds); 27 28 int sha1_update_arm(struct shash_desc *desc, const u8 *data, 29 unsigned int len) 30 { 31 /* make sure casting to sha1_block_fn() is safe */ 32 BUILD_BUG_ON(offsetof(struct sha1_state, state) != 0); 33 34 return sha1_base_do_update(desc, data, len, 35 (sha1_block_fn *)sha1_block_data_order); 36 } 37 EXPORT_SYMBOL_GPL(sha1_update_arm); 38 39 static int sha1_final(struct shash_desc *desc, u8 *out) 40 { 41 sha1_base_do_finalize(desc, (sha1_block_fn *)sha1_block_data_order); 42 return sha1_base_finish(desc, out); 43 } 44 45 int sha1_finup_arm(struct shash_desc *desc, const u8 *data, 46 unsigned int len, u8 *out) 47 { 48 sha1_base_do_update(desc, data, len, 49 (sha1_block_fn *)sha1_block_data_order); 50 return sha1_final(desc, out); 51 } 52 EXPORT_SYMBOL_GPL(sha1_finup_arm); 53 54 static struct shash_alg alg = { 55 .digestsize = SHA1_DIGEST_SIZE, 56 .init = sha1_base_init, 57 .update = sha1_update_arm, 58 .final = sha1_final, 59 .finup = sha1_finup_arm, 60 .descsize = sizeof(struct sha1_state), 61 .base = { 62 .cra_name = "sha1", 63 .cra_driver_name= "sha1-asm", 64 .cra_priority = 150, 65 .cra_blocksize = SHA1_BLOCK_SIZE, 66 .cra_module = THIS_MODULE, 67 } 68 }; 69 70 71 static int __init sha1_mod_init(void) 72 { 73 return crypto_register_shash(&alg); 74 } 75 76 77 static void __exit sha1_mod_fini(void) 78 { 79 crypto_unregister_shash(&alg); 80 } 81 82 83 module_init(sha1_mod_init); 84 module_exit(sha1_mod_fini); 85 86 MODULE_LICENSE("GPL"); 87 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm (ARM)"); 88 MODULE_ALIAS_CRYPTO("sha1"); 89 MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>"); 90