842.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Cryptographic API for the 842 software compression algorithm.
  4. *
  5. * Copyright (C) IBM Corporation, 2011-2015
  6. *
  7. * Original Authors: Robert Jennings <rcj@linux.vnet.ibm.com>
  8. * Seth Jennings <sjenning@linux.vnet.ibm.com>
  9. *
  10. * Rewrite: Dan Streetman <ddstreet@ieee.org>
  11. *
  12. * This is the software implementation of compression and decompression using
  13. * the 842 format. This uses the software 842 library at lib/842/ which is
  14. * only a reference implementation, and is very, very slow as compared to other
  15. * software compressors. You probably do not want to use this software
  16. * compression. If you have access to the PowerPC 842 compression hardware, you
  17. * want to use the 842 hardware compression interface, which is at:
  18. * drivers/crypto/nx/nx-842-crypto.c
  19. */
  20. #include <crypto/internal/scompress.h>
  21. #include <linux/init.h>
  22. #include <linux/module.h>
  23. #include <linux/sw842.h>
  24. static void *crypto842_alloc_ctx(void)
  25. {
  26. void *ctx;
  27. ctx = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);
  28. if (!ctx)
  29. return ERR_PTR(-ENOMEM);
  30. return ctx;
  31. }
  32. static void crypto842_free_ctx(void *ctx)
  33. {
  34. kfree(ctx);
  35. }
  36. static int crypto842_scompress(struct crypto_scomp *tfm,
  37. const u8 *src, unsigned int slen,
  38. u8 *dst, unsigned int *dlen, void *ctx)
  39. {
  40. return sw842_compress(src, slen, dst, dlen, ctx);
  41. }
  42. static int crypto842_sdecompress(struct crypto_scomp *tfm,
  43. const u8 *src, unsigned int slen,
  44. u8 *dst, unsigned int *dlen, void *ctx)
  45. {
  46. return sw842_decompress(src, slen, dst, dlen);
  47. }
  48. static struct scomp_alg scomp = {
  49. .streams = {
  50. .alloc_ctx = crypto842_alloc_ctx,
  51. .free_ctx = crypto842_free_ctx,
  52. },
  53. .compress = crypto842_scompress,
  54. .decompress = crypto842_sdecompress,
  55. .base = {
  56. .cra_name = "842",
  57. .cra_driver_name = "842-scomp",
  58. .cra_priority = 100,
  59. .cra_module = THIS_MODULE,
  60. }
  61. };
  62. static int __init crypto842_mod_init(void)
  63. {
  64. return crypto_register_scomp(&scomp);
  65. }
  66. module_init(crypto842_mod_init);
  67. static void __exit crypto842_mod_exit(void)
  68. {
  69. crypto_unregister_scomp(&scomp);
  70. }
  71. module_exit(crypto842_mod_exit);
  72. MODULE_LICENSE("GPL");
  73. MODULE_DESCRIPTION("842 Software Compression Algorithm");
  74. MODULE_ALIAS_CRYPTO("842");
  75. MODULE_ALIAS_CRYPTO("842-generic");
  76. MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");