pcompress.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Cryptographic API.
  3. *
  4. * Partial (de)compression operations.
  5. *
  6. * Copyright 2008 Sony Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program.
  19. * If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/crypto.h>
  22. #include <linux/errno.h>
  23. #include <linux/module.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/string.h>
  26. #include <linux/cryptouser.h>
  27. #include <net/netlink.h>
  28. #include <crypto/compress.h>
  29. #include <crypto/internal/compress.h>
  30. #include "internal.h"
  31. static int crypto_pcomp_init(struct crypto_tfm *tfm, u32 type, u32 mask)
  32. {
  33. return 0;
  34. }
  35. static int crypto_pcomp_init_tfm(struct crypto_tfm *tfm)
  36. {
  37. return 0;
  38. }
  39. #ifdef CONFIG_NET
  40. static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
  41. {
  42. struct crypto_report_comp rpcomp;
  43. strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
  44. if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
  45. sizeof(struct crypto_report_comp), &rpcomp))
  46. goto nla_put_failure;
  47. return 0;
  48. nla_put_failure:
  49. return -EMSGSIZE;
  50. }
  51. #else
  52. static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
  53. {
  54. return -ENOSYS;
  55. }
  56. #endif
  57. static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
  58. __attribute__ ((unused));
  59. static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
  60. {
  61. seq_printf(m, "type : pcomp\n");
  62. }
  63. static const struct crypto_type crypto_pcomp_type = {
  64. .extsize = crypto_alg_extsize,
  65. .init = crypto_pcomp_init,
  66. .init_tfm = crypto_pcomp_init_tfm,
  67. #ifdef CONFIG_PROC_FS
  68. .show = crypto_pcomp_show,
  69. #endif
  70. .report = crypto_pcomp_report,
  71. .maskclear = ~CRYPTO_ALG_TYPE_MASK,
  72. .maskset = CRYPTO_ALG_TYPE_MASK,
  73. .type = CRYPTO_ALG_TYPE_PCOMPRESS,
  74. .tfmsize = offsetof(struct crypto_pcomp, base),
  75. };
  76. struct crypto_pcomp *crypto_alloc_pcomp(const char *alg_name, u32 type,
  77. u32 mask)
  78. {
  79. return crypto_alloc_tfm(alg_name, &crypto_pcomp_type, type, mask);
  80. }
  81. EXPORT_SYMBOL_GPL(crypto_alloc_pcomp);
  82. int crypto_register_pcomp(struct pcomp_alg *alg)
  83. {
  84. struct crypto_alg *base = &alg->base;
  85. base->cra_type = &crypto_pcomp_type;
  86. base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
  87. base->cra_flags |= CRYPTO_ALG_TYPE_PCOMPRESS;
  88. return crypto_register_alg(base);
  89. }
  90. EXPORT_SYMBOL_GPL(crypto_register_pcomp);
  91. int crypto_unregister_pcomp(struct pcomp_alg *alg)
  92. {
  93. return crypto_unregister_alg(&alg->base);
  94. }
  95. EXPORT_SYMBOL_GPL(crypto_unregister_pcomp);
  96. MODULE_LICENSE("GPL");
  97. MODULE_DESCRIPTION("Partial (de)compression type");
  98. MODULE_AUTHOR("Sony Corporation");