compress.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Compress: Compression algorithms under the cryptographic API.
  3. *
  4. * Copyright 2008 Sony Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program.
  17. * If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _CRYPTO_COMPRESS_H
  20. #define _CRYPTO_COMPRESS_H
  21. #include <linux/crypto.h>
  22. struct comp_request {
  23. const void *next_in; /* next input byte */
  24. void *next_out; /* next output byte */
  25. unsigned int avail_in; /* bytes available at next_in */
  26. unsigned int avail_out; /* bytes available at next_out */
  27. };
  28. enum zlib_comp_params {
  29. ZLIB_COMP_LEVEL = 1, /* e.g. Z_DEFAULT_COMPRESSION */
  30. ZLIB_COMP_METHOD, /* e.g. Z_DEFLATED */
  31. ZLIB_COMP_WINDOWBITS, /* e.g. MAX_WBITS */
  32. ZLIB_COMP_MEMLEVEL, /* e.g. DEF_MEM_LEVEL */
  33. ZLIB_COMP_STRATEGY, /* e.g. Z_DEFAULT_STRATEGY */
  34. __ZLIB_COMP_MAX,
  35. };
  36. #define ZLIB_COMP_MAX (__ZLIB_COMP_MAX - 1)
  37. enum zlib_decomp_params {
  38. ZLIB_DECOMP_WINDOWBITS = 1, /* e.g. DEF_WBITS */
  39. __ZLIB_DECOMP_MAX,
  40. };
  41. #define ZLIB_DECOMP_MAX (__ZLIB_DECOMP_MAX - 1)
  42. struct crypto_pcomp {
  43. struct crypto_tfm base;
  44. };
  45. struct pcomp_alg {
  46. int (*compress_setup)(struct crypto_pcomp *tfm, void *params,
  47. unsigned int len);
  48. int (*compress_init)(struct crypto_pcomp *tfm);
  49. int (*compress_update)(struct crypto_pcomp *tfm,
  50. struct comp_request *req);
  51. int (*compress_final)(struct crypto_pcomp *tfm,
  52. struct comp_request *req);
  53. int (*decompress_setup)(struct crypto_pcomp *tfm, void *params,
  54. unsigned int len);
  55. int (*decompress_init)(struct crypto_pcomp *tfm);
  56. int (*decompress_update)(struct crypto_pcomp *tfm,
  57. struct comp_request *req);
  58. int (*decompress_final)(struct crypto_pcomp *tfm,
  59. struct comp_request *req);
  60. struct crypto_alg base;
  61. };
  62. extern struct crypto_pcomp *crypto_alloc_pcomp(const char *alg_name, u32 type,
  63. u32 mask);
  64. static inline struct crypto_tfm *crypto_pcomp_tfm(struct crypto_pcomp *tfm)
  65. {
  66. return &tfm->base;
  67. }
  68. static inline void crypto_free_pcomp(struct crypto_pcomp *tfm)
  69. {
  70. crypto_destroy_tfm(tfm, crypto_pcomp_tfm(tfm));
  71. }
  72. static inline struct pcomp_alg *__crypto_pcomp_alg(struct crypto_alg *alg)
  73. {
  74. return container_of(alg, struct pcomp_alg, base);
  75. }
  76. static inline struct pcomp_alg *crypto_pcomp_alg(struct crypto_pcomp *tfm)
  77. {
  78. return __crypto_pcomp_alg(crypto_pcomp_tfm(tfm)->__crt_alg);
  79. }
  80. static inline int crypto_compress_setup(struct crypto_pcomp *tfm,
  81. void *params, unsigned int len)
  82. {
  83. return crypto_pcomp_alg(tfm)->compress_setup(tfm, params, len);
  84. }
  85. static inline int crypto_compress_init(struct crypto_pcomp *tfm)
  86. {
  87. return crypto_pcomp_alg(tfm)->compress_init(tfm);
  88. }
  89. static inline int crypto_compress_update(struct crypto_pcomp *tfm,
  90. struct comp_request *req)
  91. {
  92. return crypto_pcomp_alg(tfm)->compress_update(tfm, req);
  93. }
  94. static inline int crypto_compress_final(struct crypto_pcomp *tfm,
  95. struct comp_request *req)
  96. {
  97. return crypto_pcomp_alg(tfm)->compress_final(tfm, req);
  98. }
  99. static inline int crypto_decompress_setup(struct crypto_pcomp *tfm,
  100. void *params, unsigned int len)
  101. {
  102. return crypto_pcomp_alg(tfm)->decompress_setup(tfm, params, len);
  103. }
  104. static inline int crypto_decompress_init(struct crypto_pcomp *tfm)
  105. {
  106. return crypto_pcomp_alg(tfm)->decompress_init(tfm);
  107. }
  108. static inline int crypto_decompress_update(struct crypto_pcomp *tfm,
  109. struct comp_request *req)
  110. {
  111. return crypto_pcomp_alg(tfm)->decompress_update(tfm, req);
  112. }
  113. static inline int crypto_decompress_final(struct crypto_pcomp *tfm,
  114. struct comp_request *req)
  115. {
  116. return crypto_pcomp_alg(tfm)->decompress_final(tfm, req);
  117. }
  118. #endif /* _CRYPTO_COMPRESS_H */