blob: 589716f2ee8a47c4ef0488020719080a82e97042 [file] [log] [blame]
Herbert Xu03c8efc2010-10-19 21:12:39 +08001/*
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 Dobriyanb7f080c2011-06-16 11:01:34 +000019#include <linux/scatterlist.h>
Herbert Xu03c8efc2010-10-19 21:12:39 +080020#include <linux/types.h>
21#include <net/sock.h>
22
23#define ALG_MAX_PAGES 16
24
25struct crypto_async_request;
26
27struct 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 Xuc840ac62015-12-30 11:47:53 +080033 unsigned int refcnt;
34
Herbert Xu03c8efc2010-10-19 21:12:39 +080035 const struct af_alg_type *type;
36 void *private;
37};
38
39struct af_alg_completion {
40 struct completion completion;
41 int err;
42};
43
44struct af_alg_control {
45 struct af_alg_iv *iv;
46 int op;
Stephan Muelleraf8e8072014-12-03 20:55:42 +010047 unsigned int aead_assoclen;
Herbert Xu03c8efc2010-10-19 21:12:39 +080048};
49
50struct 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);
Stephan Mueller25fb8632014-12-07 23:21:42 +010055 int (*setauthsize)(void *private, unsigned int authsize);
Herbert Xu03c8efc2010-10-19 21:12:39 +080056
57 struct proto_ops *ops;
58 struct module *owner;
59 char name[14];
60};
61
62struct af_alg_sgl {
Tadeusz Struk66db3732015-03-19 12:31:30 -070063 struct scatterlist sg[ALG_MAX_PAGES + 1];
Herbert Xu03c8efc2010-10-19 21:12:39 +080064 struct page *pages[ALG_MAX_PAGES];
Tadeusz Struk66db3732015-03-19 12:31:30 -070065 unsigned int npages;
Herbert Xu03c8efc2010-10-19 21:12:39 +080066};
67
68int af_alg_register_type(const struct af_alg_type *type);
69int af_alg_unregister_type(const struct af_alg_type *type);
70
71int af_alg_release(struct socket *sock);
Herbert Xuc840ac62015-12-30 11:47:53 +080072void af_alg_release_parent(struct sock *sk);
Herbert Xu03c8efc2010-10-19 21:12:39 +080073int af_alg_accept(struct sock *sk, struct socket *newsock);
74
Al Viro1d10eb22014-11-28 16:39:25 -050075int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len);
Herbert Xu03c8efc2010-10-19 21:12:39 +080076void af_alg_free_sg(struct af_alg_sgl *sgl);
Tadeusz Struk66db3732015-03-19 12:31:30 -070077void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new);
Herbert Xu03c8efc2010-10-19 21:12:39 +080078
79int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
80
81int af_alg_wait_for_completion(int err, struct af_alg_completion *completion);
82void af_alg_complete(struct crypto_async_request *req, int err);
83
84static inline struct alg_sock *alg_sk(struct sock *sk)
85{
86 return (struct alg_sock *)sk;
87}
88
Herbert Xu03c8efc2010-10-19 21:12:39 +080089static inline void af_alg_init_completion(struct af_alg_completion *completion)
90{
91 init_completion(&completion->completion);
92}
93
94#endif /* _CRYPTO_IF_ALG_H */