Back to home page

LXR

 
 

    


0001 /*
0002  * Cryptographic API.
0003  *
0004  * SHA1 Secure Hash Algorithm.
0005  *
0006  * Derived from cryptoapi implementation, adapted for in-place
0007  * scatterlist interface.
0008  *
0009  * Copyright (c) Alan Smithee.
0010  * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
0011  * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
0012  *
0013  * This program is free software; you can redistribute it and/or modify it
0014  * under the terms of the GNU General Public License as published by the Free
0015  * Software Foundation; either version 2 of the License, or (at your option)
0016  * any later version.
0017  *
0018  */
0019 #include <crypto/internal/hash.h>
0020 #include <linux/init.h>
0021 #include <linux/module.h>
0022 #include <linux/mm.h>
0023 #include <linux/cryptohash.h>
0024 #include <linux/types.h>
0025 #include <crypto/sha.h>
0026 #include <crypto/sha1_base.h>
0027 #include <asm/byteorder.h>
0028 
0029 const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE] = {
0030     0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d,
0031     0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90,
0032     0xaf, 0xd8, 0x07, 0x09
0033 };
0034 EXPORT_SYMBOL_GPL(sha1_zero_message_hash);
0035 
0036 static void sha1_generic_block_fn(struct sha1_state *sst, u8 const *src,
0037                   int blocks)
0038 {
0039     u32 temp[SHA_WORKSPACE_WORDS];
0040 
0041     while (blocks--) {
0042         sha_transform(sst->state, src, temp);
0043         src += SHA1_BLOCK_SIZE;
0044     }
0045     memzero_explicit(temp, sizeof(temp));
0046 }
0047 
0048 int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
0049                unsigned int len)
0050 {
0051     return sha1_base_do_update(desc, data, len, sha1_generic_block_fn);
0052 }
0053 EXPORT_SYMBOL(crypto_sha1_update);
0054 
0055 static int sha1_final(struct shash_desc *desc, u8 *out)
0056 {
0057     sha1_base_do_finalize(desc, sha1_generic_block_fn);
0058     return sha1_base_finish(desc, out);
0059 }
0060 
0061 int crypto_sha1_finup(struct shash_desc *desc, const u8 *data,
0062               unsigned int len, u8 *out)
0063 {
0064     sha1_base_do_update(desc, data, len, sha1_generic_block_fn);
0065     return sha1_final(desc, out);
0066 }
0067 EXPORT_SYMBOL(crypto_sha1_finup);
0068 
0069 static struct shash_alg alg = {
0070     .digestsize =   SHA1_DIGEST_SIZE,
0071     .init       =   sha1_base_init,
0072     .update     =   crypto_sha1_update,
0073     .final      =   sha1_final,
0074     .finup      =   crypto_sha1_finup,
0075     .descsize   =   sizeof(struct sha1_state),
0076     .base       =   {
0077         .cra_name   =   "sha1",
0078         .cra_driver_name=   "sha1-generic",
0079         .cra_flags  =   CRYPTO_ALG_TYPE_SHASH,
0080         .cra_blocksize  =   SHA1_BLOCK_SIZE,
0081         .cra_module =   THIS_MODULE,
0082     }
0083 };
0084 
0085 static int __init sha1_generic_mod_init(void)
0086 {
0087     return crypto_register_shash(&alg);
0088 }
0089 
0090 static void __exit sha1_generic_mod_fini(void)
0091 {
0092     crypto_unregister_shash(&alg);
0093 }
0094 
0095 module_init(sha1_generic_mod_init);
0096 module_exit(sha1_generic_mod_fini);
0097 
0098 MODULE_LICENSE("GPL");
0099 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
0100 
0101 MODULE_ALIAS_CRYPTO("sha1");
0102 MODULE_ALIAS_CRYPTO("sha1-generic");