This source file includes following definitions.
- crc32_cra_init
- crc32_setkey
- crc32_init
- crc32_update
- __crc32_finup
- crc32_finup
- crc32_final
- crc32_digest
- crc32_mod_init
- crc32_mod_fini
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  23 
  24 
  25 
  26 
  27 
  28 
  29 
  30 
  31 
  32 #include <asm/unaligned.h>
  33 #include <linux/crc32.h>
  34 #include <crypto/internal/hash.h>
  35 #include <linux/init.h>
  36 #include <linux/module.h>
  37 #include <linux/string.h>
  38 #include <linux/kernel.h>
  39 
  40 #define CHKSUM_BLOCK_SIZE       1
  41 #define CHKSUM_DIGEST_SIZE      4
  42 
  43 
  44 static int crc32_cra_init(struct crypto_tfm *tfm)
  45 {
  46         u32 *key = crypto_tfm_ctx(tfm);
  47 
  48         *key = 0;
  49 
  50         return 0;
  51 }
  52 
  53 
  54 
  55 
  56 
  57 
  58 static int crc32_setkey(struct crypto_shash *hash, const u8 *key,
  59                         unsigned int keylen)
  60 {
  61         u32 *mctx = crypto_shash_ctx(hash);
  62 
  63         if (keylen != sizeof(u32)) {
  64                 crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
  65                 return -EINVAL;
  66         }
  67         *mctx = get_unaligned_le32(key);
  68         return 0;
  69 }
  70 
  71 static int crc32_init(struct shash_desc *desc)
  72 {
  73         u32 *mctx = crypto_shash_ctx(desc->tfm);
  74         u32 *crcp = shash_desc_ctx(desc);
  75 
  76         *crcp = *mctx;
  77 
  78         return 0;
  79 }
  80 
  81 static int crc32_update(struct shash_desc *desc, const u8 *data,
  82                         unsigned int len)
  83 {
  84         u32 *crcp = shash_desc_ctx(desc);
  85 
  86         *crcp = crc32_le(*crcp, data, len);
  87         return 0;
  88 }
  89 
  90 
  91 static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len,
  92                          u8 *out)
  93 {
  94         put_unaligned_le32(crc32_le(*crcp, data, len), out);
  95         return 0;
  96 }
  97 
  98 static int crc32_finup(struct shash_desc *desc, const u8 *data,
  99                        unsigned int len, u8 *out)
 100 {
 101         return __crc32_finup(shash_desc_ctx(desc), data, len, out);
 102 }
 103 
 104 static int crc32_final(struct shash_desc *desc, u8 *out)
 105 {
 106         u32 *crcp = shash_desc_ctx(desc);
 107 
 108         put_unaligned_le32(*crcp, out);
 109         return 0;
 110 }
 111 
 112 static int crc32_digest(struct shash_desc *desc, const u8 *data,
 113                         unsigned int len, u8 *out)
 114 {
 115         return __crc32_finup(crypto_shash_ctx(desc->tfm), data, len,
 116                              out);
 117 }
 118 static struct shash_alg alg = {
 119         .setkey         = crc32_setkey,
 120         .init           = crc32_init,
 121         .update         = crc32_update,
 122         .final          = crc32_final,
 123         .finup          = crc32_finup,
 124         .digest         = crc32_digest,
 125         .descsize       = sizeof(u32),
 126         .digestsize     = CHKSUM_DIGEST_SIZE,
 127         .base           = {
 128                 .cra_name               = "crc32",
 129                 .cra_driver_name        = "crc32-generic",
 130                 .cra_priority           = 100,
 131                 .cra_flags              = CRYPTO_ALG_OPTIONAL_KEY,
 132                 .cra_blocksize          = CHKSUM_BLOCK_SIZE,
 133                 .cra_ctxsize            = sizeof(u32),
 134                 .cra_module             = THIS_MODULE,
 135                 .cra_init               = crc32_cra_init,
 136         }
 137 };
 138 
 139 static int __init crc32_mod_init(void)
 140 {
 141         return crypto_register_shash(&alg);
 142 }
 143 
 144 static void __exit crc32_mod_fini(void)
 145 {
 146         crypto_unregister_shash(&alg);
 147 }
 148 
 149 subsys_initcall(crc32_mod_init);
 150 module_exit(crc32_mod_fini);
 151 
 152 MODULE_AUTHOR("Alexander Boyko <alexander_boyko@xyratex.com>");
 153 MODULE_DESCRIPTION("CRC32 calculations wrapper for lib/crc32");
 154 MODULE_LICENSE("GPL");
 155 MODULE_ALIAS_CRYPTO("crc32");
 156 MODULE_ALIAS_CRYPTO("crc32-generic");