if_alg.h 2.5 KB

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