scompress.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. * @init: Initialize the cryptographic transformation object.
  29. * This function is used to initialize the cryptographic
  30. * transformation object. This function is called only once at
  31. * the instantiation time, right after the transformation context
  32. * was allocated. In case the cryptographic hardware has some
  33. * special requirements which need to be handled by software, this
  34. * function shall check for the precise requirement of the
  35. * transformation and put any software fallbacks in place.
  36. * @exit: Deinitialize the cryptographic transformation object. This is a
  37. * counterpart to @init, used to remove various changes set in
  38. * @init.
  39. * @base: Common crypto API algorithm data structure
  40. */
  41. struct scomp_alg {
  42. void *(*alloc_ctx)(struct crypto_scomp *tfm);
  43. void (*free_ctx)(struct crypto_scomp *tfm, void *ctx);
  44. int (*compress)(struct crypto_scomp *tfm, const u8 *src,
  45. unsigned int slen, u8 *dst, unsigned int *dlen,
  46. void *ctx);
  47. int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
  48. unsigned int slen, u8 *dst, unsigned int *dlen,
  49. void *ctx);
  50. struct crypto_alg base;
  51. };
  52. static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
  53. {
  54. return container_of(alg, struct scomp_alg, base);
  55. }
  56. static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm)
  57. {
  58. return container_of(tfm, struct crypto_scomp, base);
  59. }
  60. static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
  61. {
  62. return &tfm->base;
  63. }
  64. static inline void crypto_free_scomp(struct crypto_scomp *tfm)
  65. {
  66. crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
  67. }
  68. static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
  69. {
  70. return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
  71. }
  72. static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
  73. {
  74. return crypto_scomp_alg(tfm)->alloc_ctx(tfm);
  75. }
  76. static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
  77. void *ctx)
  78. {
  79. return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
  80. }
  81. static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
  82. const u8 *src, unsigned int slen,
  83. u8 *dst, unsigned int *dlen, void *ctx)
  84. {
  85. return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
  86. }
  87. static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
  88. const u8 *src, unsigned int slen,
  89. u8 *dst, unsigned int *dlen,
  90. void *ctx)
  91. {
  92. return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen,
  93. ctx);
  94. }
  95. int crypto_init_scomp_ops_async(struct crypto_tfm *tfm);
  96. struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req);
  97. void crypto_acomp_scomp_free_ctx(struct acomp_req *req);
  98. /**
  99. * crypto_register_scomp() -- Register synchronous compression algorithm
  100. *
  101. * Function registers 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_register_scomp(struct scomp_alg *alg);
  109. /**
  110. * crypto_unregister_scomp() -- Unregister synchronous compression algorithm
  111. *
  112. * Function unregisters an implementation of a synchronous
  113. * compression algorithm
  114. *
  115. * @alg: algorithm definition
  116. *
  117. * Return: zero on success; error code in case of error
  118. */
  119. int crypto_unregister_scomp(struct scomp_alg *alg);
  120. int crypto_register_scomps(struct scomp_alg *algs, int count);
  121. void crypto_unregister_scomps(struct scomp_alg *algs, int count);
  122. #endif