~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/crypto/sha256_generic.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php