Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 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 | |
| 13 | #ifndef _CRYPTO_IF_ALG_H |
| 14 | #define _CRYPTO_IF_ALG_H |
| 15 | |
| 16 | #include <linux/compiler.h> |
| 17 | #include <linux/completion.h> |
| 18 | #include <linux/if_alg.h> |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 19 | #include <linux/scatterlist.h> |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 20 | #include <linux/types.h> |
| 21 | #include <net/sock.h> |
| 22 | |
| 23 | #define ALG_MAX_PAGES 16 |
| 24 | |
| 25 | struct crypto_async_request; |
| 26 | |
| 27 | struct alg_sock { |
| 28 | /* struct sock must be the first member of struct alg_sock */ |
| 29 | struct sock sk; |
| 30 | |
| 31 | struct sock *parent; |
| 32 | |
Herbert Xu | c840ac6 | 2015-12-30 11:47:53 +0800 | [diff] [blame] | 33 | unsigned int refcnt; |
Herbert Xu | 6a93517 | 2016-01-13 14:59:03 +0800 | [diff] [blame] | 34 | unsigned int nokey_refcnt; |
Herbert Xu | c840ac6 | 2015-12-30 11:47:53 +0800 | [diff] [blame] | 35 | |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 36 | const struct af_alg_type *type; |
| 37 | void *private; |
| 38 | }; |
| 39 | |
| 40 | struct af_alg_completion { |
| 41 | struct completion completion; |
| 42 | int err; |
| 43 | }; |
| 44 | |
| 45 | struct af_alg_control { |
| 46 | struct af_alg_iv *iv; |
| 47 | int op; |
Stephan Mueller | af8e807 | 2014-12-03 20:55:42 +0100 | [diff] [blame] | 48 | unsigned int aead_assoclen; |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct af_alg_type { |
| 52 | void *(*bind)(const char *name, u32 type, u32 mask); |
| 53 | void (*release)(void *private); |
| 54 | int (*setkey)(void *private, const u8 *key, unsigned int keylen); |
| 55 | int (*accept)(void *private, struct sock *sk); |
Herbert Xu | 3776658 | 2016-01-04 13:35:18 +0900 | [diff] [blame] | 56 | int (*accept_nokey)(void *private, struct sock *sk); |
Stephan Mueller | 25fb863 | 2014-12-07 23:21:42 +0100 | [diff] [blame] | 57 | int (*setauthsize)(void *private, unsigned int authsize); |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 58 | |
| 59 | struct proto_ops *ops; |
Herbert Xu | 3776658 | 2016-01-04 13:35:18 +0900 | [diff] [blame] | 60 | struct proto_ops *ops_nokey; |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 61 | struct module *owner; |
| 62 | char name[14]; |
| 63 | }; |
| 64 | |
| 65 | struct af_alg_sgl { |
Tadeusz Struk | 66db373 | 2015-03-19 12:31:30 -0700 | [diff] [blame] | 66 | struct scatterlist sg[ALG_MAX_PAGES + 1]; |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 67 | struct page *pages[ALG_MAX_PAGES]; |
Tadeusz Struk | 66db373 | 2015-03-19 12:31:30 -0700 | [diff] [blame] | 68 | unsigned int npages; |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | int af_alg_register_type(const struct af_alg_type *type); |
| 72 | int af_alg_unregister_type(const struct af_alg_type *type); |
| 73 | |
| 74 | int af_alg_release(struct socket *sock); |
Herbert Xu | c840ac6 | 2015-12-30 11:47:53 +0800 | [diff] [blame] | 75 | void af_alg_release_parent(struct sock *sk); |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 76 | int af_alg_accept(struct sock *sk, struct socket *newsock); |
| 77 | |
Al Viro | 1d10eb2 | 2014-11-28 16:39:25 -0500 | [diff] [blame] | 78 | int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len); |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 79 | void af_alg_free_sg(struct af_alg_sgl *sgl); |
Tadeusz Struk | 66db373 | 2015-03-19 12:31:30 -0700 | [diff] [blame] | 80 | void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new); |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 81 | |
| 82 | int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con); |
| 83 | |
| 84 | int af_alg_wait_for_completion(int err, struct af_alg_completion *completion); |
| 85 | void af_alg_complete(struct crypto_async_request *req, int err); |
| 86 | |
| 87 | static inline struct alg_sock *alg_sk(struct sock *sk) |
| 88 | { |
| 89 | return (struct alg_sock *)sk; |
| 90 | } |
| 91 | |
Herbert Xu | 03c8efc | 2010-10-19 21:12:39 +0800 | [diff] [blame] | 92 | static inline void af_alg_init_completion(struct af_alg_completion *completion) |
| 93 | { |
| 94 | init_completion(&completion->completion); |
| 95 | } |
| 96 | |
| 97 | #endif /* _CRYPTO_IF_ALG_H */ |