crypto: af_alg - Add nokey compatibility path
[linux-drm-fsl-dcu.git] / include / crypto / if_alg.h
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>
19 #include <linux/scatterlist.h>
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
33         unsigned int refcnt;
34
35         const struct af_alg_type *type;
36         void *private;
37 };
38
39 struct af_alg_completion {
40         struct completion completion;
41         int err;
42 };
43
44 struct af_alg_control {
45         struct af_alg_iv *iv;
46         int op;
47         unsigned int aead_assoclen;
48 };
49
50 struct af_alg_type {
51         void *(*bind)(const char *name, u32 type, u32 mask);
52         void (*release)(void *private);
53         int (*setkey)(void *private, const u8 *key, unsigned int keylen);
54         int (*accept)(void *private, struct sock *sk);
55         int (*accept_nokey)(void *private, struct sock *sk);
56         int (*setauthsize)(void *private, unsigned int authsize);
57
58         struct proto_ops *ops;
59         struct proto_ops *ops_nokey;
60         struct module *owner;
61         char name[14];
62 };
63
64 struct af_alg_sgl {
65         struct scatterlist sg[ALG_MAX_PAGES + 1];
66         struct page *pages[ALG_MAX_PAGES];
67         unsigned int npages;
68 };
69
70 int af_alg_register_type(const struct af_alg_type *type);
71 int af_alg_unregister_type(const struct af_alg_type *type);
72
73 int af_alg_release(struct socket *sock);
74 void af_alg_release_parent(struct sock *sk);
75 int af_alg_accept(struct sock *sk, struct socket *newsock);
76
77 int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len);
78 void af_alg_free_sg(struct af_alg_sgl *sgl);
79 void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new);
80
81 int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
82
83 int af_alg_wait_for_completion(int err, struct af_alg_completion *completion);
84 void af_alg_complete(struct crypto_async_request *req, int err);
85
86 static inline struct alg_sock *alg_sk(struct sock *sk)
87 {
88         return (struct alg_sock *)sk;
89 }
90
91 static inline void af_alg_init_completion(struct af_alg_completion *completion)
92 {
93         init_completion(&completion->completion);
94 }
95
96 #endif  /* _CRYPTO_IF_ALG_H */