if_alg.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/scatterlist.h>
  18. #include <linux/types.h>
  19. #include <net/sock.h>
  20. #define ALG_MAX_PAGES 16
  21. struct crypto_async_request;
  22. struct alg_sock {
  23. /* struct sock must be the first member of struct alg_sock */
  24. struct sock sk;
  25. struct sock *parent;
  26. const struct af_alg_type *type;
  27. void *private;
  28. };
  29. struct af_alg_completion {
  30. struct completion completion;
  31. int err;
  32. };
  33. struct af_alg_control {
  34. struct af_alg_iv *iv;
  35. int op;
  36. };
  37. struct af_alg_type {
  38. void *(*bind)(const char *name, u32 type, u32 mask);
  39. void (*release)(void *private);
  40. int (*setkey)(void *private, const u8 *key, unsigned int keylen);
  41. int (*accept)(void *private, struct sock *sk);
  42. struct proto_ops *ops;
  43. struct module *owner;
  44. char name[14];
  45. };
  46. struct af_alg_sgl {
  47. struct scatterlist sg[ALG_MAX_PAGES];
  48. struct page *pages[ALG_MAX_PAGES];
  49. };
  50. int af_alg_register_type(const struct af_alg_type *type);
  51. int af_alg_unregister_type(const struct af_alg_type *type);
  52. int af_alg_release(struct socket *sock);
  53. int af_alg_accept(struct sock *sk, struct socket *newsock);
  54. int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len,
  55. int write);
  56. void af_alg_free_sg(struct af_alg_sgl *sgl);
  57. int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
  58. int af_alg_wait_for_completion(int err, struct af_alg_completion *completion);
  59. void af_alg_complete(struct crypto_async_request *req, int err);
  60. static inline struct alg_sock *alg_sk(struct sock *sk)
  61. {
  62. return (struct alg_sock *)sk;
  63. }
  64. static inline void af_alg_release_parent(struct sock *sk)
  65. {
  66. sock_put(alg_sk(sk)->parent);
  67. }
  68. static inline void af_alg_init_completion(struct af_alg_completion *completion)
  69. {
  70. init_completion(&completion->completion);
  71. }
  72. #endif /* _CRYPTO_IF_ALG_H */