acompress.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Asynchronous Compression operations
  4. *
  5. * Copyright (c) 2016, Intel Corporation
  6. * Authors: Weigang Li <weigang.li@intel.com>
  7. * Giovanni Cabiddu <giovanni.cabiddu@intel.com>
  8. */
  9. #ifndef _CRYPTO_ACOMP_INT_H
  10. #define _CRYPTO_ACOMP_INT_H
  11. #include <crypto/acompress.h>
  12. #include <crypto/algapi.h>
  13. /**
  14. * struct acomp_alg - asynchronous compression algorithm
  15. *
  16. * @compress: Function performs a compress operation
  17. * @decompress: Function performs a de-compress operation
  18. * @dst_free: Frees destination buffer if allocated inside the algorithm
  19. * @init: Initialize the cryptographic transformation object.
  20. * This function is used to initialize the cryptographic
  21. * transformation object. This function is called only once at
  22. * the instantiation time, right after the transformation context
  23. * was allocated. In case the cryptographic hardware has some
  24. * special requirements which need to be handled by software, this
  25. * function shall check for the precise requirement of the
  26. * transformation and put any software fallbacks in place.
  27. * @exit: Deinitialize the cryptographic transformation object. This is a
  28. * counterpart to @init, used to remove various changes set in
  29. * @init.
  30. *
  31. * @reqsize: Context size for (de)compression requests
  32. * @base: Common crypto API algorithm data structure
  33. * @calg: Cmonn algorithm data structure shared with scomp
  34. */
  35. struct acomp_alg {
  36. int (*compress)(struct acomp_req *req);
  37. int (*decompress)(struct acomp_req *req);
  38. void (*dst_free)(struct scatterlist *dst);
  39. int (*init)(struct crypto_acomp *tfm);
  40. void (*exit)(struct crypto_acomp *tfm);
  41. unsigned int reqsize;
  42. union {
  43. struct COMP_ALG_COMMON;
  44. struct comp_alg_common calg;
  45. };
  46. };
  47. /*
  48. * Transform internal helpers.
  49. */
  50. static inline void *acomp_request_ctx(struct acomp_req *req)
  51. {
  52. return req->__ctx;
  53. }
  54. static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm)
  55. {
  56. return tfm->base.__crt_ctx;
  57. }
  58. static inline void acomp_request_complete(struct acomp_req *req,
  59. int err)
  60. {
  61. crypto_request_complete(&req->base, err);
  62. }
  63. static inline struct acomp_req *__acomp_request_alloc_noprof(struct crypto_acomp *tfm)
  64. {
  65. struct acomp_req *req;
  66. req = kzalloc_noprof(sizeof(*req) + crypto_acomp_reqsize(tfm), GFP_KERNEL);
  67. if (likely(req))
  68. acomp_request_set_tfm(req, tfm);
  69. return req;
  70. }
  71. #define __acomp_request_alloc(...) alloc_hooks(__acomp_request_alloc_noprof(__VA_ARGS__))
  72. static inline void __acomp_request_free(struct acomp_req *req)
  73. {
  74. kfree_sensitive(req);
  75. }
  76. /**
  77. * crypto_register_acomp() -- Register asynchronous compression algorithm
  78. *
  79. * Function registers an implementation of an asynchronous
  80. * compression algorithm
  81. *
  82. * @alg: algorithm definition
  83. *
  84. * Return: zero on success; error code in case of error
  85. */
  86. int crypto_register_acomp(struct acomp_alg *alg);
  87. /**
  88. * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm
  89. *
  90. * Function unregisters an implementation of an asynchronous
  91. * compression algorithm
  92. *
  93. * @alg: algorithm definition
  94. */
  95. void crypto_unregister_acomp(struct acomp_alg *alg);
  96. int crypto_register_acomps(struct acomp_alg *algs, int count);
  97. void crypto_unregister_acomps(struct acomp_alg *algs, int count);
  98. #endif