scompress.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Synchronous Compression operations
  3. *
  4. * Copyright 2015 LG Electronics Inc.
  5. * Copyright (c) 2016, Intel Corporation
  6. * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. *
  13. */
  14. #ifndef _CRYPTO_SCOMP_INT_H
  15. #define _CRYPTO_SCOMP_INT_H
  16. #include <linux/crypto.h>
  17. #define SCOMP_SCRATCH_SIZE 131072
  18. struct crypto_scomp {
  19. struct crypto_tfm base;
  20. };
  21. /**
  22. * struct scomp_alg - synchronous compression algorithm
  23. *
  24. * @alloc_ctx: Function allocates algorithm specific context
  25. * @free_ctx: Function frees context allocated with alloc_ctx
  26. * @compress: Function performs a compress operation
  27. * @decompress: Function performs a de-compress operation
  28. * @base: Common crypto API algorithm data structure
  29. */
  30. struct scomp_alg {
  31. void *(*alloc_ctx)(struct crypto_scomp *tfm);
  32. void (*free_ctx)(struct crypto_scomp *tfm, void *ctx);
  33. int (*compress)(struct crypto_scomp *tfm, const u8 *src,
  34. unsigned int slen, u8 *dst, unsigned int *dlen,
  35. void *ctx);
  36. int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
  37. unsigned int slen, u8 *dst, unsigned int *dlen,
  38. void *ctx);
  39. struct crypto_alg base;
  40. };
  41. static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
  42. {
  43. return container_of(alg, struct scomp_alg, base);
  44. }
  45. static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm)
  46. {
  47. return container_of(tfm, struct crypto_scomp, base);
  48. }
  49. static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
  50. {
  51. return &tfm->base;
  52. }
  53. static inline void crypto_free_scomp(struct crypto_scomp *tfm)
  54. {
  55. crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
  56. }
  57. static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
  58. {
  59. return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
  60. }
  61. static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
  62. {
  63. return crypto_scomp_alg(tfm)->alloc_ctx(tfm);
  64. }
  65. static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
  66. void *ctx)
  67. {
  68. return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
  69. }
  70. static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
  71. const u8 *src, unsigned int slen,
  72. u8 *dst, unsigned int *dlen, void *ctx)
  73. {
  74. return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
  75. }
  76. static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
  77. const u8 *src, unsigned int slen,
  78. u8 *dst, unsigned int *dlen,
  79. void *ctx)
  80. {
  81. return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen,
  82. ctx);
  83. }
  84. int crypto_init_scomp_ops_async(struct crypto_tfm *tfm);
  85. struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req);
  86. void crypto_acomp_scomp_free_ctx(struct acomp_req *req);
  87. /**
  88. * crypto_register_scomp() -- Register synchronous compression algorithm
  89. *
  90. * Function registers an implementation of a synchronous
  91. * compression algorithm
  92. *
  93. * @alg: algorithm definition
  94. *
  95. * Return: zero on success; error code in case of error
  96. */
  97. int crypto_register_scomp(struct scomp_alg *alg);
  98. /**
  99. * crypto_unregister_scomp() -- Unregister synchronous compression algorithm
  100. *
  101. * Function unregisters an implementation of a synchronous
  102. * compression algorithm
  103. *
  104. * @alg: algorithm definition
  105. *
  106. * Return: zero on success; error code in case of error
  107. */
  108. int crypto_unregister_scomp(struct scomp_alg *alg);
  109. int crypto_register_scomps(struct scomp_alg *algs, int count);
  110. void crypto_unregister_scomps(struct scomp_alg *algs, int count);
  111. #endif