0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <crypto/internal/hash.h>
0015 #include <linux/init.h>
0016 #include <linux/module.h>
0017 #include <linux/mm.h>
0018 #include <linux/types.h>
0019 #include <crypto/sha1.h>
0020 #include <crypto/sha1_base.h>
0021 #include <asm/byteorder.h>
0022
0023 const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE] = {
0024 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d,
0025 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90,
0026 0xaf, 0xd8, 0x07, 0x09
0027 };
0028 EXPORT_SYMBOL_GPL(sha1_zero_message_hash);
0029
0030 static void sha1_generic_block_fn(struct sha1_state *sst, u8 const *src,
0031 int blocks)
0032 {
0033 u32 temp[SHA1_WORKSPACE_WORDS];
0034
0035 while (blocks--) {
0036 sha1_transform(sst->state, src, temp);
0037 src += SHA1_BLOCK_SIZE;
0038 }
0039 memzero_explicit(temp, sizeof(temp));
0040 }
0041
0042 int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
0043 unsigned int len)
0044 {
0045 return sha1_base_do_update(desc, data, len, sha1_generic_block_fn);
0046 }
0047 EXPORT_SYMBOL(crypto_sha1_update);
0048
0049 static int sha1_final(struct shash_desc *desc, u8 *out)
0050 {
0051 sha1_base_do_finalize(desc, sha1_generic_block_fn);
0052 return sha1_base_finish(desc, out);
0053 }
0054
0055 int crypto_sha1_finup(struct shash_desc *desc, const u8 *data,
0056 unsigned int len, u8 *out)
0057 {
0058 sha1_base_do_update(desc, data, len, sha1_generic_block_fn);
0059 return sha1_final(desc, out);
0060 }
0061 EXPORT_SYMBOL(crypto_sha1_finup);
0062
0063 static struct shash_alg alg = {
0064 .digestsize = SHA1_DIGEST_SIZE,
0065 .init = sha1_base_init,
0066 .update = crypto_sha1_update,
0067 .final = sha1_final,
0068 .finup = crypto_sha1_finup,
0069 .descsize = sizeof(struct sha1_state),
0070 .base = {
0071 .cra_name = "sha1",
0072 .cra_driver_name= "sha1-generic",
0073 .cra_priority = 100,
0074 .cra_blocksize = SHA1_BLOCK_SIZE,
0075 .cra_module = THIS_MODULE,
0076 }
0077 };
0078
0079 static int __init sha1_generic_mod_init(void)
0080 {
0081 return crypto_register_shash(&alg);
0082 }
0083
0084 static void __exit sha1_generic_mod_fini(void)
0085 {
0086 crypto_unregister_shash(&alg);
0087 }
0088
0089 subsys_initcall(sha1_generic_mod_init);
0090 module_exit(sha1_generic_mod_fini);
0091
0092 MODULE_LICENSE("GPL");
0093 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
0094
0095 MODULE_ALIAS_CRYPTO("sha1");
0096 MODULE_ALIAS_CRYPTO("sha1-generic");