18 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/net.h>
41 struct sock *
sk = sock->
sk;
54 err = crypto_ahash_init(&ctx->
req);
63 unsigned long seglen = iov->
iov_len;
67 int len =
min_t(
unsigned long, seglen, limit);
72 err = copied ? 0 : newlen;
76 ahash_request_set_crypt(&ctx->
req, ctx->
sgl.sg,
NULL,
80 crypto_ahash_update(&ctx->
req),
106 return err ?: copied;
112 struct sock *sk = sock->
sk;
119 sg_set_page(ctx->
sgl.sg, page, size, offset);
121 ahash_request_set_crypt(&ctx->
req, ctx->
sgl.sg, ctx->
result, size);
130 err = crypto_ahash_init(&ctx->
req);
135 err = crypto_ahash_update(&ctx->
req);
150 static int hash_recvmsg(
struct kiocb *unused,
struct socket *sock,
151 struct msghdr *msg,
size_t len,
int flags)
153 struct sock *sk = sock->
sk;
156 unsigned ds = crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->
req));
182 static int hash_accept(
struct socket *sock,
struct socket *newsock,
int flags)
184 struct sock *sk = sock->
sk;
188 char state[crypto_ahash_statesize(crypto_ahash_reqtfm(req))];
194 err = crypto_ahash_export(req, state);
207 err = crypto_ahash_import(&ctx2->
req, state);
216 static struct proto_ops algif_hash_ops = {
232 .sendmsg = hash_sendmsg,
233 .sendpage = hash_sendpage,
234 .recvmsg = hash_recvmsg,
235 .accept = hash_accept,
243 static void hash_release(
void *
private)
245 crypto_free_ahash(
private);
248 static int hash_setkey(
void *
private,
const u8 *
key,
unsigned int keylen)
253 static void hash_sock_destruct(
struct sock *sk)
259 crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->
req)));
261 af_alg_release_parent(sk);
264 static int hash_accept_parent(
void *
private,
struct sock *sk)
268 unsigned len =
sizeof(*ctx) + crypto_ahash_reqsize(
private);
269 unsigned ds = crypto_ahash_digestsize(
private);
289 ahash_request_set_tfm(&ctx->
req,
private);
298 static const struct af_alg_type algif_type_hash = {
300 .release = hash_release,
301 .setkey = hash_setkey,
302 .accept = hash_accept_parent,
303 .ops = &algif_hash_ops,
308 static int __init algif_hash_init(
void)
313 static void __exit algif_hash_exit(
void)