Blame view
crypto/sha1_generic.c
2.36 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> |
7c71f0f76 crypto: sha1-gene... |
28 29 |
static void sha1_generic_block_fn(struct sha1_state *sst, u8 const *src, int blocks) |
1da177e4c Linux-2.6.12-rc2 |
30 |
{ |
7c71f0f76 crypto: sha1-gene... |
31 |
u32 temp[SHA_WORKSPACE_WORDS]; |
54ccb3677 crypto: sha1 - Sw... |
32 |
|
7c71f0f76 crypto: sha1-gene... |
33 34 35 36 37 |
while (blocks--) { sha_transform(sst->state, src, temp); src += SHA1_BLOCK_SIZE; } memzero_explicit(temp, sizeof(temp)); |
1da177e4c Linux-2.6.12-rc2 |
38 |
} |
7c390170b crypto: sha1 - ex... |
39 |
int crypto_sha1_update(struct shash_desc *desc, const u8 *data, |
7c71f0f76 crypto: sha1-gene... |
40 |
unsigned int len) |
1da177e4c Linux-2.6.12-rc2 |
41 |
{ |
7c71f0f76 crypto: sha1-gene... |
42 |
return sha1_base_do_update(desc, data, len, sha1_generic_block_fn); |
1da177e4c Linux-2.6.12-rc2 |
43 |
} |
7c390170b crypto: sha1 - ex... |
44 |
EXPORT_SYMBOL(crypto_sha1_update); |
1da177e4c Linux-2.6.12-rc2 |
45 |
|
54ccb3677 crypto: sha1 - Sw... |
46 |
static int sha1_final(struct shash_desc *desc, u8 *out) |
1da177e4c Linux-2.6.12-rc2 |
47 |
{ |
7c71f0f76 crypto: sha1-gene... |
48 49 |
sha1_base_do_finalize(desc, sha1_generic_block_fn); return sha1_base_finish(desc, out); |
1da177e4c Linux-2.6.12-rc2 |
50 |
} |
7c71f0f76 crypto: sha1-gene... |
51 52 |
int crypto_sha1_finup(struct shash_desc *desc, const u8 *data, unsigned int len, u8 *out) |
e2a7ce4e1 crypto: sha1_gene... |
53 |
{ |
7c71f0f76 crypto: sha1-gene... |
54 55 |
sha1_base_do_update(desc, data, len, sha1_generic_block_fn); return sha1_final(desc, out); |
e2a7ce4e1 crypto: sha1_gene... |
56 |
} |
7c71f0f76 crypto: sha1-gene... |
57 |
EXPORT_SYMBOL(crypto_sha1_finup); |
e2a7ce4e1 crypto: sha1_gene... |
58 |
|
54ccb3677 crypto: sha1 - Sw... |
59 60 |
static struct shash_alg alg = { .digestsize = SHA1_DIGEST_SIZE, |
7c71f0f76 crypto: sha1-gene... |
61 |
.init = sha1_base_init, |
7c390170b crypto: sha1 - ex... |
62 |
.update = crypto_sha1_update, |
54ccb3677 crypto: sha1 - Sw... |
63 |
.final = sha1_final, |
7c71f0f76 crypto: sha1-gene... |
64 |
.finup = crypto_sha1_finup, |
e2a7ce4e1 crypto: sha1_gene... |
65 |
.descsize = sizeof(struct sha1_state), |
54ccb3677 crypto: sha1 - Sw... |
66 67 68 69 70 71 72 |
.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 |
73 |
}; |
3af5b90bd [CRYPTO] all: Cle... |
74 |
static int __init sha1_generic_mod_init(void) |
1da177e4c Linux-2.6.12-rc2 |
75 |
{ |
54ccb3677 crypto: sha1 - Sw... |
76 |
return crypto_register_shash(&alg); |
1da177e4c Linux-2.6.12-rc2 |
77 |
} |
3af5b90bd [CRYPTO] all: Cle... |
78 |
static void __exit sha1_generic_mod_fini(void) |
1da177e4c Linux-2.6.12-rc2 |
79 |
{ |
54ccb3677 crypto: sha1 - Sw... |
80 |
crypto_unregister_shash(&alg); |
1da177e4c Linux-2.6.12-rc2 |
81 |
} |
3af5b90bd [CRYPTO] all: Cle... |
82 83 |
module_init(sha1_generic_mod_init); module_exit(sha1_generic_mod_fini); |
1da177e4c Linux-2.6.12-rc2 |
84 85 86 |
MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm"); |
b3be9a6d9 [CRYPTO] sha: Add... |
87 |
|
5d26a105b crypto: prefix mo... |
88 |
MODULE_ALIAS_CRYPTO("sha1"); |
3e14dcf7c crypto: add missi... |
89 |
MODULE_ALIAS_CRYPTO("sha1-generic"); |