blob: 5c7b6c53e96f17edbf530c1c5f7c10ce59c73de0 [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
33 const struct af_alg_type *type;
34 void *private;
35};
36
37struct af_alg_completion {
38 struct completion completion;
39 int err;
40};
41
42struct af_alg_control {
43 struct af_alg_iv *iv;
44 int op;
Stephan Muelleraf8e8072014-12-03 20:55:42 +010045 unsigned int aead_assoclen;
Herbert Xu03c8efc2010-10-19 21:12:39 +080046};
47
48struct af_alg_type {
49 void *(*bind)(const char *name, u32 type, u32 mask);
50 void (*release)(void *private);
51 int (*setkey)(void *private, const u8 *key, unsigned int keylen);
52 int (*accept)(void *private, struct sock *sk);
Stephan Mueller25fb8632014-12-07 23:21:42 +010053 int (*setauthsize)(void *private, unsigned int authsize);
Herbert Xu03c8efc2010-10-19 21:12:39 +080054
55 struct proto_ops *ops;
56 struct module *owner;
57 char name[14];
58};
59
60struct af_alg_sgl {
61 struct scatterlist sg[ALG_MAX_PAGES];
62 struct page *pages[ALG_MAX_PAGES];
63};
64
65int af_alg_register_type(const struct af_alg_type *type);
66int af_alg_unregister_type(const struct af_alg_type *type);
67
68int af_alg_release(struct socket *sock);
69int af_alg_accept(struct sock *sk, struct socket *newsock);
70
71int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len,
72 int write);
73void af_alg_free_sg(struct af_alg_sgl *sgl);
74
75int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
76
77int af_alg_wait_for_completion(int err, struct af_alg_completion *completion);
78void af_alg_complete(struct crypto_async_request *req, int err);
79
80static inline struct alg_sock *alg_sk(struct sock *sk)
81{
82 return (struct alg_sock *)sk;
83}
84
85static inline void af_alg_release_parent(struct sock *sk)
86{
87 sock_put(alg_sk(sk)->parent);
88}
89
90static inline void af_alg_init_completion(struct af_alg_completion *completion)
91{
92 init_completion(&completion->completion);
93}
94
95#endif /* _CRYPTO_IF_ALG_H */