Blame view
crypto/sha1_generic.c
2.58 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* * Cryptographic API. * * SHA1 Secure Hash Algorithm. * * Derived from cryptoapi implementation, adapted for in-place * scatterlist interface. * * Copyright (c) Alan Smithee. * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> * Copyright (c) Jean-Francois Dive <jef@linuxbe.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * */ |
54ccb3677 crypto: sha1 - Sw... |
19 |
#include <crypto/internal/hash.h> |
1da177e4c Linux-2.6.12-rc2 |
20 21 22 |
#include <linux/init.h> #include <linux/module.h> #include <linux/mm.h> |
1da177e4c Linux-2.6.12-rc2 |
23 |
#include <linux/cryptohash.h> |
06ace7a9b [CRYPTO] Use stan... |
24 |
#include <linux/types.h> |
5265eeb2b [CRYPTO] sha: Add... |
25 |
#include <crypto/sha.h> |
7c71f0f76 crypto: sha1-gene... |
26 |
#include <crypto/sha1_base.h> |
1da177e4c Linux-2.6.12-rc2 |
27 |
#include <asm/byteorder.h> |
0c4c78de0 crypto: hash - ad... |
28 29 30 31 32 33 |
const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE] = { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 }; EXPORT_SYMBOL_GPL(sha1_zero_message_hash); |
7c71f0f76 crypto: sha1-gene... |
34 35 |
static void sha1_generic_block_fn(struct sha1_state *sst, u8 const *src, int blocks) |
1da177e4c Linux-2.6.12-rc2 |
36 |
{ |
7c71f0f76 crypto: sha1-gene... |
37 |
u32 temp[SHA_WORKSPACE_WORDS]; |
54ccb3677 crypto: sha1 - Sw... |
38 |
|
7c71f0f76 crypto: sha1-gene... |
39 40 41 42 43 |
while (blocks--) { sha_transform(sst->state, src, temp); src += SHA1_BLOCK_SIZE; } memzero_explicit(temp, sizeof(temp)); |
1da177e4c Linux-2.6.12-rc2 |
44 |
} |
7c390170b crypto: sha1 - ex... |
45 |
int crypto_sha1_update(struct shash_desc *desc, const u8 *data, |
7c71f0f76 crypto: sha1-gene... |
46 |
unsigned int len) |
1da177e4c Linux-2.6.12-rc2 |
47 |
{ |
7c71f0f76 crypto: sha1-gene... |
48 |
return sha1_base_do_update(desc, data, len, sha1_generic_block_fn); |
1da177e4c Linux-2.6.12-rc2 |
49 |
} |
7c390170b crypto: sha1 - ex... |
50 |
EXPORT_SYMBOL(crypto_sha1_update); |
1da177e4c Linux-2.6.12-rc2 |
51 |
|
54ccb3677 crypto: sha1 - Sw... |
52 |
static int sha1_final(struct shash_desc *desc, u8 *out) |
1da177e4c Linux-2.6.12-rc2 |
53 |
{ |
7c71f0f76 crypto: sha1-gene... |
54 55 |
sha1_base_do_finalize(desc, sha1_generic_block_fn); return sha1_base_finish(desc, out); |
1da177e4c Linux-2.6.12-rc2 |
56 |
} |
7c71f0f76 crypto: sha1-gene... |
57 58 |
int crypto_sha1_finup(struct shash_desc *desc, const u8 *data, unsigned int len, u8 *out) |
e2a7ce4e1 crypto: sha1_gene... |
59 |
{ |
7c71f0f76 crypto: sha1-gene... |
60 61 |
sha1_base_do_update(desc, data, len, sha1_generic_block_fn); return sha1_final(desc, out); |
e2a7ce4e1 crypto: sha1_gene... |
62 |
} |
7c71f0f76 crypto: sha1-gene... |
63 |
EXPORT_SYMBOL(crypto_sha1_finup); |
e2a7ce4e1 crypto: sha1_gene... |
64 |
|
54ccb3677 crypto: sha1 - Sw... |
65 66 |
static struct shash_alg alg = { .digestsize = SHA1_DIGEST_SIZE, |
7c71f0f76 crypto: sha1-gene... |
67 |
.init = sha1_base_init, |
7c390170b crypto: sha1 - ex... |
68 |
.update = crypto_sha1_update, |
54ccb3677 crypto: sha1 - Sw... |
69 |
.final = sha1_final, |
7c71f0f76 crypto: sha1-gene... |
70 |
.finup = crypto_sha1_finup, |
e2a7ce4e1 crypto: sha1_gene... |
71 |
.descsize = sizeof(struct sha1_state), |
54ccb3677 crypto: sha1 - Sw... |
72 73 74 75 76 77 78 |
.base = { .cra_name = "sha1", .cra_driver_name= "sha1-generic", .cra_flags = CRYPTO_ALG_TYPE_SHASH, .cra_blocksize = SHA1_BLOCK_SIZE, .cra_module = THIS_MODULE, } |
1da177e4c Linux-2.6.12-rc2 |
79 |
}; |
3af5b90bd [CRYPTO] all: Cle... |
80 |
static int __init sha1_generic_mod_init(void) |
1da177e4c Linux-2.6.12-rc2 |
81 |
{ |
54ccb3677 crypto: sha1 - Sw... |
82 |
return crypto_register_shash(&alg); |
1da177e4c Linux-2.6.12-rc2 |
83 |
} |
3af5b90bd [CRYPTO] all: Cle... |
84 |
static void __exit sha1_generic_mod_fini(void) |
1da177e4c Linux-2.6.12-rc2 |
85 |
{ |
54ccb3677 crypto: sha1 - Sw... |
86 |
crypto_unregister_shash(&alg); |
1da177e4c Linux-2.6.12-rc2 |
87 |
} |
3af5b90bd [CRYPTO] all: Cle... |
88 89 |
module_init(sha1_generic_mod_init); module_exit(sha1_generic_mod_fini); |
1da177e4c Linux-2.6.12-rc2 |
90 91 92 |
MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm"); |
b3be9a6d9 [CRYPTO] sha: Add... |
93 |
|
5d26a105b crypto: prefix mo... |
94 |
MODULE_ALIAS_CRYPTO("sha1"); |
3e14dcf7c crypto: add missi... |
95 |
MODULE_ALIAS_CRYPTO("sha1-generic"); |