Blame view
crypto/sha256_generic.c
3.34 KB
2874c5fd2 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4c Linux-2.6.12-rc2 |
2 |
/* |
08c327f63 crypto: sha256_ge... |
3 |
* Crypto API wrapper for the generic SHA256 code from lib/crypto/sha256.c |
1da177e4c Linux-2.6.12-rc2 |
4 5 6 7 |
* * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com> * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
cd12fb906 [CRYPTO] sha256-g... |
8 |
* SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com> |
1da177e4c Linux-2.6.12-rc2 |
9 |
*/ |
50e109b5b crypto: sha256 - ... |
10 |
#include <crypto/internal/hash.h> |
1da177e4c Linux-2.6.12-rc2 |
11 12 13 |
#include <linux/init.h> #include <linux/module.h> #include <linux/mm.h> |
06ace7a9b [CRYPTO] Use stan... |
14 |
#include <linux/types.h> |
5265eeb2b [CRYPTO] sha: Add... |
15 |
#include <crypto/sha.h> |
a2e5ba4fe crypto: sha256-ge... |
16 |
#include <crypto/sha256_base.h> |
1da177e4c Linux-2.6.12-rc2 |
17 |
#include <asm/byteorder.h> |
be34c4ef6 crypto: sha - Han... |
18 |
#include <asm/unaligned.h> |
1da177e4c Linux-2.6.12-rc2 |
19 |
|
0c4c78de0 crypto: hash - ad... |
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
const u8 sha224_zero_message_hash[SHA224_DIGEST_SIZE] = { 0xd1, 0x4a, 0x02, 0x8c, 0x2a, 0x3a, 0x2b, 0xc9, 0x47, 0x61, 0x02, 0xbb, 0x28, 0x82, 0x34, 0xc4, 0x15, 0xa2, 0xb0, 0x1f, 0x82, 0x8e, 0xa6, 0x2a, 0xc5, 0xb3, 0xe4, 0x2f }; EXPORT_SYMBOL_GPL(sha224_zero_message_hash); const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE] = { 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55 }; EXPORT_SYMBOL_GPL(sha256_zero_message_hash); |
08c327f63 crypto: sha256_ge... |
35 |
static int crypto_sha256_init(struct shash_desc *desc) |
1da177e4c Linux-2.6.12-rc2 |
36 |
{ |
08c327f63 crypto: sha256_ge... |
37 |
return sha256_init(shash_desc_ctx(desc)); |
1da177e4c Linux-2.6.12-rc2 |
38 |
} |
08c327f63 crypto: sha256_ge... |
39 |
static int crypto_sha224_init(struct shash_desc *desc) |
1da177e4c Linux-2.6.12-rc2 |
40 |
{ |
08c327f63 crypto: sha256_ge... |
41 |
return sha224_init(shash_desc_ctx(desc)); |
1da177e4c Linux-2.6.12-rc2 |
42 |
} |
35d2c9d0c crypto: sha256 - ... |
43 |
int crypto_sha256_update(struct shash_desc *desc, const u8 *data, |
6c2bb98bc [CRYPTO] all: Pas... |
44 |
unsigned int len) |
1da177e4c Linux-2.6.12-rc2 |
45 |
{ |
08c327f63 crypto: sha256_ge... |
46 |
return sha256_update(shash_desc_ctx(desc), data, len); |
1da177e4c Linux-2.6.12-rc2 |
47 |
} |
35d2c9d0c crypto: sha256 - ... |
48 |
EXPORT_SYMBOL(crypto_sha256_update); |
1da177e4c Linux-2.6.12-rc2 |
49 |
|
08c327f63 crypto: sha256_ge... |
50 |
static int crypto_sha256_final(struct shash_desc *desc, u8 *out) |
1da177e4c Linux-2.6.12-rc2 |
51 |
{ |
08c327f63 crypto: sha256_ge... |
52 53 54 55 |
if (crypto_shash_digestsize(desc->tfm) == SHA224_DIGEST_SIZE) return sha224_final(shash_desc_ctx(desc), out); else return sha256_final(shash_desc_ctx(desc), out); |
1da177e4c Linux-2.6.12-rc2 |
56 |
} |
a2e5ba4fe crypto: sha256-ge... |
57 58 |
int crypto_sha256_finup(struct shash_desc *desc, const u8 *data, unsigned int len, u8 *hash) |
cd12fb906 [CRYPTO] sha256-g... |
59 |
{ |
08c327f63 crypto: sha256_ge... |
60 61 |
sha256_update(shash_desc_ctx(desc), data, len); return crypto_sha256_final(desc, hash); |
9b2fda7b9 crypto: sha256_ge... |
62 |
} |
a2e5ba4fe crypto: sha256-ge... |
63 |
EXPORT_SYMBOL(crypto_sha256_finup); |
9b2fda7b9 crypto: sha256_ge... |
64 |
|
6aeb49bc5 crypto: sha256 - ... |
65 |
static struct shash_alg sha256_algs[2] = { { |
50e109b5b crypto: sha256 - ... |
66 |
.digestsize = SHA256_DIGEST_SIZE, |
08c327f63 crypto: sha256_ge... |
67 |
.init = crypto_sha256_init, |
35d2c9d0c crypto: sha256 - ... |
68 |
.update = crypto_sha256_update, |
08c327f63 crypto: sha256_ge... |
69 |
.final = crypto_sha256_final, |
a2e5ba4fe crypto: sha256-ge... |
70 |
.finup = crypto_sha256_finup, |
9b2fda7b9 crypto: sha256_ge... |
71 |
.descsize = sizeof(struct sha256_state), |
50e109b5b crypto: sha256 - ... |
72 73 74 |
.base = { .cra_name = "sha256", .cra_driver_name= "sha256-generic", |
b73b7ac0a crypto: sha256_ge... |
75 |
.cra_priority = 100, |
50e109b5b crypto: sha256 - ... |
76 77 78 |
.cra_blocksize = SHA256_BLOCK_SIZE, .cra_module = THIS_MODULE, } |
6aeb49bc5 crypto: sha256 - ... |
79 |
}, { |
50e109b5b crypto: sha256 - ... |
80 |
.digestsize = SHA224_DIGEST_SIZE, |
08c327f63 crypto: sha256_ge... |
81 |
.init = crypto_sha224_init, |
35d2c9d0c crypto: sha256 - ... |
82 |
.update = crypto_sha256_update, |
08c327f63 crypto: sha256_ge... |
83 |
.final = crypto_sha256_final, |
a2e5ba4fe crypto: sha256-ge... |
84 |
.finup = crypto_sha256_finup, |
9b2fda7b9 crypto: sha256_ge... |
85 |
.descsize = sizeof(struct sha256_state), |
50e109b5b crypto: sha256 - ... |
86 87 88 |
.base = { .cra_name = "sha224", .cra_driver_name= "sha224-generic", |
b73b7ac0a crypto: sha256_ge... |
89 |
.cra_priority = 100, |
50e109b5b crypto: sha256 - ... |
90 91 92 |
.cra_blocksize = SHA224_BLOCK_SIZE, .cra_module = THIS_MODULE, } |
6aeb49bc5 crypto: sha256 - ... |
93 |
} }; |
1da177e4c Linux-2.6.12-rc2 |
94 |
|
3af5b90bd [CRYPTO] all: Cle... |
95 |
static int __init sha256_generic_mod_init(void) |
1da177e4c Linux-2.6.12-rc2 |
96 |
{ |
6aeb49bc5 crypto: sha256 - ... |
97 |
return crypto_register_shashes(sha256_algs, ARRAY_SIZE(sha256_algs)); |
1da177e4c Linux-2.6.12-rc2 |
98 |
} |
3af5b90bd [CRYPTO] all: Cle... |
99 |
static void __exit sha256_generic_mod_fini(void) |
1da177e4c Linux-2.6.12-rc2 |
100 |
{ |
6aeb49bc5 crypto: sha256 - ... |
101 |
crypto_unregister_shashes(sha256_algs, ARRAY_SIZE(sha256_algs)); |
1da177e4c Linux-2.6.12-rc2 |
102 |
} |
c4741b230 crypto: run initc... |
103 |
subsys_initcall(sha256_generic_mod_init); |
3af5b90bd [CRYPTO] all: Cle... |
104 |
module_exit(sha256_generic_mod_fini); |
1da177e4c Linux-2.6.12-rc2 |
105 106 |
MODULE_LICENSE("GPL"); |
cd12fb906 [CRYPTO] sha256-g... |
107 |
MODULE_DESCRIPTION("SHA-224 and SHA-256 Secure Hash Algorithm"); |
b3be9a6d9 [CRYPTO] sha: Add... |
108 |
|
5d26a105b crypto: prefix mo... |
109 |
MODULE_ALIAS_CRYPTO("sha224"); |
3e14dcf7c crypto: add missi... |
110 |
MODULE_ALIAS_CRYPTO("sha224-generic"); |
5d26a105b crypto: prefix mo... |
111 |
MODULE_ALIAS_CRYPTO("sha256"); |
3e14dcf7c crypto: add missi... |
112 |
MODULE_ALIAS_CRYPTO("sha256-generic"); |