crc64_rocksoft_generic.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/crc64.h>
  3. #include <linux/module.h>
  4. #include <crypto/internal/hash.h>
  5. #include <asm/unaligned.h>
  6. static int chksum_init(struct shash_desc *desc)
  7. {
  8. u64 *crc = shash_desc_ctx(desc);
  9. *crc = 0;
  10. return 0;
  11. }
  12. static int chksum_update(struct shash_desc *desc, const u8 *data,
  13. unsigned int length)
  14. {
  15. u64 *crc = shash_desc_ctx(desc);
  16. *crc = crc64_rocksoft_generic(*crc, data, length);
  17. return 0;
  18. }
  19. static int chksum_final(struct shash_desc *desc, u8 *out)
  20. {
  21. u64 *crc = shash_desc_ctx(desc);
  22. put_unaligned_le64(*crc, out);
  23. return 0;
  24. }
  25. static int __chksum_finup(u64 crc, const u8 *data, unsigned int len, u8 *out)
  26. {
  27. crc = crc64_rocksoft_generic(crc, data, len);
  28. put_unaligned_le64(crc, out);
  29. return 0;
  30. }
  31. static int chksum_finup(struct shash_desc *desc, const u8 *data,
  32. unsigned int len, u8 *out)
  33. {
  34. u64 *crc = shash_desc_ctx(desc);
  35. return __chksum_finup(*crc, data, len, out);
  36. }
  37. static int chksum_digest(struct shash_desc *desc, const u8 *data,
  38. unsigned int length, u8 *out)
  39. {
  40. return __chksum_finup(0, data, length, out);
  41. }
  42. static struct shash_alg alg = {
  43. .digestsize = sizeof(u64),
  44. .init = chksum_init,
  45. .update = chksum_update,
  46. .final = chksum_final,
  47. .finup = chksum_finup,
  48. .digest = chksum_digest,
  49. .descsize = sizeof(u64),
  50. .base = {
  51. .cra_name = CRC64_ROCKSOFT_STRING,
  52. .cra_driver_name = "crc64-rocksoft-generic",
  53. .cra_priority = 200,
  54. .cra_blocksize = 1,
  55. .cra_module = THIS_MODULE,
  56. }
  57. };
  58. static int __init crc64_rocksoft_init(void)
  59. {
  60. return crypto_register_shash(&alg);
  61. }
  62. static void __exit crc64_rocksoft_exit(void)
  63. {
  64. crypto_unregister_shash(&alg);
  65. }
  66. module_init(crc64_rocksoft_init);
  67. module_exit(crc64_rocksoft_exit);
  68. MODULE_LICENSE("GPL");
  69. MODULE_DESCRIPTION("Rocksoft model CRC64 calculation.");
  70. MODULE_ALIAS_CRYPTO("crc64-rocksoft");
  71. MODULE_ALIAS_CRYPTO("crc64-rocksoft-generic");