scompress.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Synchronous Compression operations
  4. *
  5. * Copyright 2015 LG Electronics Inc.
  6. * Copyright (c) 2016, Intel Corporation
  7. * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
  8. */
  9. #ifndef _CRYPTO_SCOMP_INT_H
  10. #define _CRYPTO_SCOMP_INT_H
  11. #include <crypto/internal/acompress.h>
  12. struct crypto_scomp {
  13. struct crypto_tfm base;
  14. };
  15. /**
  16. * struct scomp_alg - synchronous compression algorithm
  17. *
  18. * @compress: Function performs a compress operation
  19. * @decompress: Function performs a de-compress operation
  20. * @streams: Per-cpu memory for algorithm
  21. * @calg: Cmonn algorithm data structure shared with acomp
  22. */
  23. struct scomp_alg {
  24. int (*compress)(struct crypto_scomp *tfm, const u8 *src,
  25. unsigned int slen, u8 *dst, unsigned int *dlen,
  26. void *ctx);
  27. int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
  28. unsigned int slen, u8 *dst, unsigned int *dlen,
  29. void *ctx);
  30. struct crypto_acomp_streams streams;
  31. union {
  32. struct COMP_ALG_COMMON;
  33. struct comp_alg_common calg;
  34. };
  35. };
  36. static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
  37. {
  38. return container_of(alg, struct scomp_alg, base);
  39. }
  40. static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm)
  41. {
  42. return container_of(tfm, struct crypto_scomp, base);
  43. }
  44. static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
  45. {
  46. return &tfm->base;
  47. }
  48. static inline void crypto_free_scomp(struct crypto_scomp *tfm)
  49. {
  50. crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
  51. }
  52. static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
  53. {
  54. return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
  55. }
  56. static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
  57. const u8 *src, unsigned int slen,
  58. u8 *dst, unsigned int *dlen, void *ctx)
  59. {
  60. return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
  61. }
  62. static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
  63. const u8 *src, unsigned int slen,
  64. u8 *dst, unsigned int *dlen,
  65. void *ctx)
  66. {
  67. return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen,
  68. ctx);
  69. }
  70. /**
  71. * crypto_register_scomp() -- Register synchronous compression algorithm
  72. *
  73. * Function registers an implementation of a synchronous
  74. * compression algorithm
  75. *
  76. * @alg: algorithm definition
  77. *
  78. * Return: zero on success; error code in case of error
  79. */
  80. int crypto_register_scomp(struct scomp_alg *alg);
  81. /**
  82. * crypto_unregister_scomp() -- Unregister synchronous compression algorithm
  83. *
  84. * Function unregisters an implementation of a synchronous
  85. * compression algorithm
  86. *
  87. * @alg: algorithm definition
  88. */
  89. void crypto_unregister_scomp(struct scomp_alg *alg);
  90. int crypto_register_scomps(struct scomp_alg *algs, int count);
  91. void crypto_unregister_scomps(struct scomp_alg *algs, int count);
  92. #endif