Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Cryptographic API.
0004  * Glue code for the SHA1 Secure Hash Algorithm assembler implementation
0005  *
0006  * This file is based on sha1_generic.c and sha1_ssse3_glue.c
0007  *
0008  * Copyright (c) Alan Smithee.
0009  * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
0010  * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
0011  * Copyright (c) Mathias Krause <minipli@googlemail.com>
0012  */
0013 
0014 #include <crypto/internal/hash.h>
0015 #include <linux/init.h>
0016 #include <linux/module.h>
0017 #include <linux/types.h>
0018 #include <crypto/sha1.h>
0019 #include <crypto/sha1_base.h>
0020 #include <asm/byteorder.h>
0021 
0022 #include "sha1.h"
0023 
0024 asmlinkage void sha1_block_data_order(u32 *digest,
0025         const unsigned char *data, unsigned int rounds);
0026 
0027 int sha1_update_arm(struct shash_desc *desc, const u8 *data,
0028             unsigned int len)
0029 {
0030     /* make sure casting to sha1_block_fn() is safe */
0031     BUILD_BUG_ON(offsetof(struct sha1_state, state) != 0);
0032 
0033     return sha1_base_do_update(desc, data, len,
0034                    (sha1_block_fn *)sha1_block_data_order);
0035 }
0036 EXPORT_SYMBOL_GPL(sha1_update_arm);
0037 
0038 static int sha1_final(struct shash_desc *desc, u8 *out)
0039 {
0040     sha1_base_do_finalize(desc, (sha1_block_fn *)sha1_block_data_order);
0041     return sha1_base_finish(desc, out);
0042 }
0043 
0044 int sha1_finup_arm(struct shash_desc *desc, const u8 *data,
0045            unsigned int len, u8 *out)
0046 {
0047     sha1_base_do_update(desc, data, len,
0048                 (sha1_block_fn *)sha1_block_data_order);
0049     return sha1_final(desc, out);
0050 }
0051 EXPORT_SYMBOL_GPL(sha1_finup_arm);
0052 
0053 static struct shash_alg alg = {
0054     .digestsize =   SHA1_DIGEST_SIZE,
0055     .init       =   sha1_base_init,
0056     .update     =   sha1_update_arm,
0057     .final      =   sha1_final,
0058     .finup      =   sha1_finup_arm,
0059     .descsize   =   sizeof(struct sha1_state),
0060     .base       =   {
0061         .cra_name   =   "sha1",
0062         .cra_driver_name=   "sha1-asm",
0063         .cra_priority   =   150,
0064         .cra_blocksize  =   SHA1_BLOCK_SIZE,
0065         .cra_module =   THIS_MODULE,
0066     }
0067 };
0068 
0069 
0070 static int __init sha1_mod_init(void)
0071 {
0072     return crypto_register_shash(&alg);
0073 }
0074 
0075 
0076 static void __exit sha1_mod_fini(void)
0077 {
0078     crypto_unregister_shash(&alg);
0079 }
0080 
0081 
0082 module_init(sha1_mod_init);
0083 module_exit(sha1_mod_fini);
0084 
0085 MODULE_LICENSE("GPL");
0086 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm (ARM)");
0087 MODULE_ALIAS_CRYPTO("sha1");
0088 MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>");