if_alg.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * if_alg: User-space algorithm interface
  3. *
  4. * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. */
  12. #ifndef _CRYPTO_IF_ALG_H
  13. #define _CRYPTO_IF_ALG_H
  14. #include <linux/compiler.h>
  15. #include <linux/completion.h>
  16. #include <linux/if_alg.h>
  17. #include <linux/types.h>
  18. #include <net/sock.h>
  19. #define ALG_MAX_PAGES 16
  20. struct crypto_async_request;
  21. struct alg_sock {
  22. /* struct sock must be the first member of struct alg_sock */
  23. struct sock sk;
  24. struct sock *parent;
  25. const struct af_alg_type *type;
  26. void *private;
  27. };
  28. struct af_alg_completion {
  29. struct completion completion;
  30. int err;
  31. };
  32. struct af_alg_control {
  33. struct af_alg_iv *iv;
  34. int op;
  35. };
  36. struct af_alg_type {
  37. void *(*bind)(const char *name, u32 type, u32 mask);
  38. void (*release)(void *private);
  39. int (*setkey)(void *private, const u8 *key, unsigned int keylen);
  40. int (*accept)(void *private, struct sock *sk);
  41. struct proto_ops *ops;
  42. struct module *owner;
  43. char name[14];
  44. };
  45. struct af_alg_sgl {
  46. struct scatterlist sg[ALG_MAX_PAGES];
  47. struct page *pages[ALG_MAX_PAGES];
  48. };
  49. int af_alg_register_type(const struct af_alg_type *type);
  50. int af_alg_unregister_type(const struct af_alg_type *type);
  51. int af_alg_release(struct socket *sock);
  52. int af_alg_accept(struct sock *sk, struct socket *newsock);
  53. int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len,
  54. int write);
  55. void af_alg_free_sg(struct af_alg_sgl *sgl);
  56. int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
  57. int af_alg_wait_for_completion(int err, struct af_alg_completion *completion);
  58. void af_alg_complete(struct crypto_async_request *req, int err);
  59. static inline struct alg_sock *alg_sk(struct sock *sk)
  60. {
  61. return (struct alg_sock *)sk;
  62. }
  63. static inline void af_alg_release_parent(struct sock *sk)
  64. {
  65. sock_put(alg_sk(sk)->parent);
  66. }
  67. static inline void af_alg_init_completion(struct af_alg_completion *completion)
  68. {
  69. init_completion(&completion->completion);
  70. }
  71. #endif /* _CRYPTO_IF_ALG_H */