scompress.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/acompress.h>
  12. #include <crypto/algapi.h>
  13. #define SCOMP_SCRATCH_SIZE 131072
  14. struct acomp_req;
  15. struct crypto_scomp {
  16. struct crypto_tfm base;
  17. };
  18. /**
  19. * struct scomp_alg - synchronous compression algorithm
  20. *
  21. * @alloc_ctx: Function allocates algorithm specific context
  22. * @free_ctx: Function frees context allocated with alloc_ctx
  23. * @compress: Function performs a compress operation
  24. * @decompress: Function performs a de-compress operation
  25. * @base: Common crypto API algorithm data structure
  26. * @calg: Cmonn algorithm data structure shared with acomp
  27. */
  28. struct scomp_alg {
  29. void *(*alloc_ctx)(struct crypto_scomp *tfm);
  30. void (*free_ctx)(struct crypto_scomp *tfm, void *ctx);
  31. int (*compress)(struct crypto_scomp *tfm, const u8 *src,
  32. unsigned int slen, u8 *dst, unsigned int *dlen,
  33. void *ctx);
  34. int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
  35. unsigned int slen, u8 *dst, unsigned int *dlen,
  36. void *ctx);
  37. union {
  38. struct COMP_ALG_COMMON;
  39. struct comp_alg_common calg;
  40. };
  41. };
  42. static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
  43. {
  44. return container_of(alg, struct scomp_alg, base);
  45. }
  46. static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm)
  47. {
  48. return container_of(tfm, struct crypto_scomp, base);
  49. }
  50. static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
  51. {
  52. return &tfm->base;
  53. }
  54. static inline void crypto_free_scomp(struct crypto_scomp *tfm)
  55. {
  56. crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
  57. }
  58. static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
  59. {
  60. return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
  61. }
  62. static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
  63. {
  64. return crypto_scomp_alg(tfm)->alloc_ctx(tfm);
  65. }
  66. static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
  67. void *ctx)
  68. {
  69. return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
  70. }
  71. static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
  72. const u8 *src, unsigned int slen,
  73. u8 *dst, unsigned int *dlen, void *ctx)
  74. {
  75. return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
  76. }
  77. static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
  78. const u8 *src, unsigned int slen,
  79. u8 *dst, unsigned int *dlen,
  80. void *ctx)
  81. {
  82. return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen,
  83. ctx);
  84. }
  85. /**
  86. * crypto_register_scomp() -- Register synchronous compression algorithm
  87. *
  88. * Function registers an implementation of a synchronous
  89. * compression algorithm
  90. *
  91. * @alg: algorithm definition
  92. *
  93. * Return: zero on success; error code in case of error
  94. */
  95. int crypto_register_scomp(struct scomp_alg *alg);
  96. /**
  97. * crypto_unregister_scomp() -- Unregister synchronous compression algorithm
  98. *
  99. * Function unregisters an implementation of a synchronous
  100. * compression algorithm
  101. *
  102. * @alg: algorithm definition
  103. */
  104. void crypto_unregister_scomp(struct scomp_alg *alg);
  105. int crypto_register_scomps(struct scomp_alg *algs, int count);
  106. void crypto_unregister_scomps(struct scomp_alg *algs, int count);
  107. #endif