if_alg.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. unsigned int aead_assoclen;
  37. };
  38. struct af_alg_type {
  39. void *(*bind)(const char *name, u32 type, u32 mask);
  40. void (*release)(void *private);
  41. int (*setkey)(void *private, const u8 *key, unsigned int keylen);
  42. int (*accept)(void *private, struct sock *sk);
  43. int (*setauthsize)(void *private, unsigned int authsize);
  44. struct proto_ops *ops;
  45. struct module *owner;
  46. char name[14];
  47. };
  48. struct af_alg_sgl {
  49. struct scatterlist sg[ALG_MAX_PAGES + 1];
  50. struct page *pages[ALG_MAX_PAGES];
  51. unsigned int npages;
  52. };
  53. int af_alg_register_type(const struct af_alg_type *type);
  54. int af_alg_unregister_type(const struct af_alg_type *type);
  55. int af_alg_release(struct socket *sock);
  56. int af_alg_accept(struct sock *sk, struct socket *newsock);
  57. int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len);
  58. void af_alg_free_sg(struct af_alg_sgl *sgl);
  59. void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new);
  60. int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
  61. int af_alg_wait_for_completion(int err, struct af_alg_completion *completion);
  62. void af_alg_complete(struct crypto_async_request *req, int err);
  63. static inline struct alg_sock *alg_sk(struct sock *sk)
  64. {
  65. return (struct alg_sock *)sk;
  66. }
  67. static inline void af_alg_release_parent(struct sock *sk)
  68. {
  69. sock_put(alg_sk(sk)->parent);
  70. }
  71. static inline void af_alg_init_completion(struct af_alg_completion *completion)
  72. {
  73. init_completion(&completion->completion);
  74. }
  75. #endif /* _CRYPTO_IF_ALG_H */