0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <crypto/internal/hash.h>
0011 #include <linux/init.h>
0012 #include <linux/module.h>
0013 #include <linux/mm.h>
0014 #include <linux/types.h>
0015 #include <crypto/sha2.h>
0016 #include <crypto/sha256_base.h>
0017 #include <asm/byteorder.h>
0018 #include <asm/unaligned.h>
0019
0020 const u8 sha224_zero_message_hash[SHA224_DIGEST_SIZE] = {
0021 0xd1, 0x4a, 0x02, 0x8c, 0x2a, 0x3a, 0x2b, 0xc9, 0x47,
0022 0x61, 0x02, 0xbb, 0x28, 0x82, 0x34, 0xc4, 0x15, 0xa2,
0023 0xb0, 0x1f, 0x82, 0x8e, 0xa6, 0x2a, 0xc5, 0xb3, 0xe4,
0024 0x2f
0025 };
0026 EXPORT_SYMBOL_GPL(sha224_zero_message_hash);
0027
0028 const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE] = {
0029 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
0030 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
0031 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
0032 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
0033 };
0034 EXPORT_SYMBOL_GPL(sha256_zero_message_hash);
0035
0036 int crypto_sha256_update(struct shash_desc *desc, const u8 *data,
0037 unsigned int len)
0038 {
0039 sha256_update(shash_desc_ctx(desc), data, len);
0040 return 0;
0041 }
0042 EXPORT_SYMBOL(crypto_sha256_update);
0043
0044 static int crypto_sha256_final(struct shash_desc *desc, u8 *out)
0045 {
0046 if (crypto_shash_digestsize(desc->tfm) == SHA224_DIGEST_SIZE)
0047 sha224_final(shash_desc_ctx(desc), out);
0048 else
0049 sha256_final(shash_desc_ctx(desc), out);
0050 return 0;
0051 }
0052
0053 int crypto_sha256_finup(struct shash_desc *desc, const u8 *data,
0054 unsigned int len, u8 *hash)
0055 {
0056 sha256_update(shash_desc_ctx(desc), data, len);
0057 return crypto_sha256_final(desc, hash);
0058 }
0059 EXPORT_SYMBOL(crypto_sha256_finup);
0060
0061 static struct shash_alg sha256_algs[2] = { {
0062 .digestsize = SHA256_DIGEST_SIZE,
0063 .init = sha256_base_init,
0064 .update = crypto_sha256_update,
0065 .final = crypto_sha256_final,
0066 .finup = crypto_sha256_finup,
0067 .descsize = sizeof(struct sha256_state),
0068 .base = {
0069 .cra_name = "sha256",
0070 .cra_driver_name= "sha256-generic",
0071 .cra_priority = 100,
0072 .cra_blocksize = SHA256_BLOCK_SIZE,
0073 .cra_module = THIS_MODULE,
0074 }
0075 }, {
0076 .digestsize = SHA224_DIGEST_SIZE,
0077 .init = sha224_base_init,
0078 .update = crypto_sha256_update,
0079 .final = crypto_sha256_final,
0080 .finup = crypto_sha256_finup,
0081 .descsize = sizeof(struct sha256_state),
0082 .base = {
0083 .cra_name = "sha224",
0084 .cra_driver_name= "sha224-generic",
0085 .cra_priority = 100,
0086 .cra_blocksize = SHA224_BLOCK_SIZE,
0087 .cra_module = THIS_MODULE,
0088 }
0089 } };
0090
0091 static int __init sha256_generic_mod_init(void)
0092 {
0093 return crypto_register_shashes(sha256_algs, ARRAY_SIZE(sha256_algs));
0094 }
0095
0096 static void __exit sha256_generic_mod_fini(void)
0097 {
0098 crypto_unregister_shashes(sha256_algs, ARRAY_SIZE(sha256_algs));
0099 }
0100
0101 subsys_initcall(sha256_generic_mod_init);
0102 module_exit(sha256_generic_mod_fini);
0103
0104 MODULE_LICENSE("GPL");
0105 MODULE_DESCRIPTION("SHA-224 and SHA-256 Secure Hash Algorithm");
0106
0107 MODULE_ALIAS_CRYPTO("sha224");
0108 MODULE_ALIAS_CRYPTO("sha224-generic");
0109 MODULE_ALIAS_CRYPTO("sha256");
0110 MODULE_ALIAS_CRYPTO("sha256-generic");