2 * algif_skcipher: User-space interface for skcipher algorithms
4 * This file provides the user-space API for symmetric key ciphers.
6 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
15 #include <crypto/scatterwalk.h>
16 #include <crypto/skcipher.h>
17 #include <crypto/if_alg.h>
18 #include <linux/init.h>
19 #include <linux/list.h>
20 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/net.h>
26 struct skcipher_sg_list
{
27 struct list_head list
;
31 struct scatterlist sg
[0];
35 struct crypto_skcipher
*skcipher
;
40 struct list_head tsgl
;
41 struct af_alg_sgl rsgl
;
45 struct af_alg_completion completion
;
55 struct skcipher_request req
;
58 struct skcipher_async_rsgl
{
59 struct af_alg_sgl sgl
;
60 struct list_head list
;
63 struct skcipher_async_req
{
65 struct skcipher_async_rsgl first_sgl
;
66 struct list_head list
;
67 struct scatterlist
*tsg
;
71 #define GET_SREQ(areq, ctx) (struct skcipher_async_req *)((char *)areq + \
72 crypto_skcipher_reqsize(crypto_skcipher_reqtfm(&ctx->req)))
74 #define GET_REQ_SIZE(ctx) \
75 crypto_skcipher_reqsize(crypto_skcipher_reqtfm(&ctx->req))
77 #define GET_IV_SIZE(ctx) \
78 crypto_skcipher_ivsize(crypto_skcipher_reqtfm(&ctx->req))
80 #define MAX_SGL_ENTS ((4096 - sizeof(struct skcipher_sg_list)) / \
81 sizeof(struct scatterlist) - 1)
83 static void skcipher_free_async_sgls(struct skcipher_async_req
*sreq
)
85 struct skcipher_async_rsgl
*rsgl
, *tmp
;
86 struct scatterlist
*sgl
;
87 struct scatterlist
*sg
;
90 list_for_each_entry_safe(rsgl
, tmp
, &sreq
->list
, list
) {
91 af_alg_free_sg(&rsgl
->sgl
);
92 if (rsgl
!= &sreq
->first_sgl
)
97 for_each_sg(sgl
, sg
, n
, i
)
98 put_page(sg_page(sg
));
103 static void skcipher_async_cb(struct crypto_async_request
*req
, int err
)
105 struct sock
*sk
= req
->data
;
106 struct alg_sock
*ask
= alg_sk(sk
);
107 struct skcipher_ctx
*ctx
= ask
->private;
108 struct skcipher_async_req
*sreq
= GET_SREQ(req
, ctx
);
109 struct kiocb
*iocb
= sreq
->iocb
;
111 atomic_dec(&ctx
->inflight
);
112 skcipher_free_async_sgls(sreq
);
114 iocb
->ki_complete(iocb
, err
, err
);
117 static inline int skcipher_sndbuf(struct sock
*sk
)
119 struct alg_sock
*ask
= alg_sk(sk
);
120 struct skcipher_ctx
*ctx
= ask
->private;
122 return max_t(int, max_t(int, sk
->sk_sndbuf
& PAGE_MASK
, PAGE_SIZE
) -
126 static inline bool skcipher_writable(struct sock
*sk
)
128 return PAGE_SIZE
<= skcipher_sndbuf(sk
);
131 static int skcipher_alloc_sgl(struct sock
*sk
)
133 struct alg_sock
*ask
= alg_sk(sk
);
134 struct skcipher_ctx
*ctx
= ask
->private;
135 struct skcipher_sg_list
*sgl
;
136 struct scatterlist
*sg
= NULL
;
138 sgl
= list_entry(ctx
->tsgl
.prev
, struct skcipher_sg_list
, list
);
139 if (!list_empty(&ctx
->tsgl
))
142 if (!sg
|| sgl
->cur
>= MAX_SGL_ENTS
) {
143 sgl
= sock_kmalloc(sk
, sizeof(*sgl
) +
144 sizeof(sgl
->sg
[0]) * (MAX_SGL_ENTS
+ 1),
149 sg_init_table(sgl
->sg
, MAX_SGL_ENTS
+ 1);
153 sg_chain(sg
, MAX_SGL_ENTS
+ 1, sgl
->sg
);
155 list_add_tail(&sgl
->list
, &ctx
->tsgl
);
161 static void skcipher_pull_sgl(struct sock
*sk
, size_t used
, int put
)
163 struct alg_sock
*ask
= alg_sk(sk
);
164 struct skcipher_ctx
*ctx
= ask
->private;
165 struct skcipher_sg_list
*sgl
;
166 struct scatterlist
*sg
;
169 while (!list_empty(&ctx
->tsgl
)) {
170 sgl
= list_first_entry(&ctx
->tsgl
, struct skcipher_sg_list
,
174 for (i
= 0; i
< sgl
->cur
; i
++) {
175 size_t plen
= min_t(size_t, used
, sg
[i
].length
);
177 if (!sg_page(sg
+ i
))
180 sg
[i
].length
-= plen
;
181 sg
[i
].offset
+= plen
;
189 put_page(sg_page(sg
+ i
));
190 sg_assign_page(sg
+ i
, NULL
);
193 list_del(&sgl
->list
);
194 sock_kfree_s(sk
, sgl
,
195 sizeof(*sgl
) + sizeof(sgl
->sg
[0]) *
203 static void skcipher_free_sgl(struct sock
*sk
)
205 struct alg_sock
*ask
= alg_sk(sk
);
206 struct skcipher_ctx
*ctx
= ask
->private;
208 skcipher_pull_sgl(sk
, ctx
->used
, 1);
211 static int skcipher_wait_for_wmem(struct sock
*sk
, unsigned flags
)
215 int err
= -ERESTARTSYS
;
217 if (flags
& MSG_DONTWAIT
)
220 sk_set_bit(SOCKWQ_ASYNC_NOSPACE
, sk
);
223 if (signal_pending(current
))
225 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
226 timeout
= MAX_SCHEDULE_TIMEOUT
;
227 if (sk_wait_event(sk
, &timeout
, skcipher_writable(sk
))) {
232 finish_wait(sk_sleep(sk
), &wait
);
237 static void skcipher_wmem_wakeup(struct sock
*sk
)
239 struct socket_wq
*wq
;
241 if (!skcipher_writable(sk
))
245 wq
= rcu_dereference(sk
->sk_wq
);
246 if (wq_has_sleeper(wq
))
247 wake_up_interruptible_sync_poll(&wq
->wait
, POLLIN
|
250 sk_wake_async(sk
, SOCK_WAKE_WAITD
, POLL_IN
);
254 static int skcipher_wait_for_data(struct sock
*sk
, unsigned flags
)
256 struct alg_sock
*ask
= alg_sk(sk
);
257 struct skcipher_ctx
*ctx
= ask
->private;
260 int err
= -ERESTARTSYS
;
262 if (flags
& MSG_DONTWAIT
) {
266 sk_set_bit(SOCKWQ_ASYNC_WAITDATA
, sk
);
269 if (signal_pending(current
))
271 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
272 timeout
= MAX_SCHEDULE_TIMEOUT
;
273 if (sk_wait_event(sk
, &timeout
, ctx
->used
)) {
278 finish_wait(sk_sleep(sk
), &wait
);
280 sk_clear_bit(SOCKWQ_ASYNC_WAITDATA
, sk
);
285 static void skcipher_data_wakeup(struct sock
*sk
)
287 struct alg_sock
*ask
= alg_sk(sk
);
288 struct skcipher_ctx
*ctx
= ask
->private;
289 struct socket_wq
*wq
;
295 wq
= rcu_dereference(sk
->sk_wq
);
296 if (wq_has_sleeper(wq
))
297 wake_up_interruptible_sync_poll(&wq
->wait
, POLLOUT
|
300 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
304 static int skcipher_sendmsg(struct socket
*sock
, struct msghdr
*msg
,
307 struct sock
*sk
= sock
->sk
;
308 struct alg_sock
*ask
= alg_sk(sk
);
309 struct skcipher_ctx
*ctx
= ask
->private;
310 struct crypto_skcipher
*tfm
= crypto_skcipher_reqtfm(&ctx
->req
);
311 unsigned ivsize
= crypto_skcipher_ivsize(tfm
);
312 struct skcipher_sg_list
*sgl
;
313 struct af_alg_control con
= {};
320 if (msg
->msg_controllen
) {
321 err
= af_alg_cmsg_send(msg
, &con
);
337 if (con
.iv
&& con
.iv
->ivlen
!= ivsize
)
344 if (!ctx
->more
&& ctx
->used
)
350 memcpy(ctx
->iv
, con
.iv
->iv
, ivsize
);
354 struct scatterlist
*sg
;
355 unsigned long len
= size
;
359 sgl
= list_entry(ctx
->tsgl
.prev
,
360 struct skcipher_sg_list
, list
);
361 sg
= sgl
->sg
+ sgl
->cur
- 1;
362 len
= min_t(unsigned long, len
,
363 PAGE_SIZE
- sg
->offset
- sg
->length
);
365 err
= memcpy_from_msg(page_address(sg_page(sg
)) +
366 sg
->offset
+ sg
->length
,
372 ctx
->merge
= (sg
->offset
+ sg
->length
) &
381 if (!skcipher_writable(sk
)) {
382 err
= skcipher_wait_for_wmem(sk
, msg
->msg_flags
);
387 len
= min_t(unsigned long, len
, skcipher_sndbuf(sk
));
389 err
= skcipher_alloc_sgl(sk
);
393 sgl
= list_entry(ctx
->tsgl
.prev
, struct skcipher_sg_list
, list
);
395 sg_unmark_end(sg
+ sgl
->cur
);
398 plen
= min_t(size_t, len
, PAGE_SIZE
);
400 sg_assign_page(sg
+ i
, alloc_page(GFP_KERNEL
));
402 if (!sg_page(sg
+ i
))
405 err
= memcpy_from_msg(page_address(sg_page(sg
+ i
)),
408 __free_page(sg_page(sg
+ i
));
409 sg_assign_page(sg
+ i
, NULL
);
419 } while (len
&& sgl
->cur
< MAX_SGL_ENTS
);
422 sg_mark_end(sg
+ sgl
->cur
- 1);
424 ctx
->merge
= plen
& (PAGE_SIZE
- 1);
429 ctx
->more
= msg
->msg_flags
& MSG_MORE
;
432 skcipher_data_wakeup(sk
);
435 return copied
?: err
;
438 static ssize_t
skcipher_sendpage(struct socket
*sock
, struct page
*page
,
439 int offset
, size_t size
, int flags
)
441 struct sock
*sk
= sock
->sk
;
442 struct alg_sock
*ask
= alg_sk(sk
);
443 struct skcipher_ctx
*ctx
= ask
->private;
444 struct skcipher_sg_list
*sgl
;
447 if (flags
& MSG_SENDPAGE_NOTLAST
)
451 if (!ctx
->more
&& ctx
->used
)
457 if (!skcipher_writable(sk
)) {
458 err
= skcipher_wait_for_wmem(sk
, flags
);
463 err
= skcipher_alloc_sgl(sk
);
468 sgl
= list_entry(ctx
->tsgl
.prev
, struct skcipher_sg_list
, list
);
471 sg_unmark_end(sgl
->sg
+ sgl
->cur
- 1);
473 sg_mark_end(sgl
->sg
+ sgl
->cur
);
475 sg_set_page(sgl
->sg
+ sgl
->cur
, page
, size
, offset
);
480 ctx
->more
= flags
& MSG_MORE
;
483 skcipher_data_wakeup(sk
);
489 static int skcipher_all_sg_nents(struct skcipher_ctx
*ctx
)
491 struct skcipher_sg_list
*sgl
;
492 struct scatterlist
*sg
;
495 list_for_each_entry(sgl
, &ctx
->tsgl
, list
) {
501 nents
+= sg_nents(sg
);
506 static int skcipher_recvmsg_async(struct socket
*sock
, struct msghdr
*msg
,
509 struct sock
*sk
= sock
->sk
;
510 struct alg_sock
*ask
= alg_sk(sk
);
511 struct skcipher_ctx
*ctx
= ask
->private;
512 struct skcipher_sg_list
*sgl
;
513 struct scatterlist
*sg
;
514 struct skcipher_async_req
*sreq
;
515 struct skcipher_request
*req
;
516 struct skcipher_async_rsgl
*last_rsgl
= NULL
;
517 unsigned int txbufs
= 0, len
= 0, tx_nents
= skcipher_all_sg_nents(ctx
);
518 unsigned int reqlen
= sizeof(struct skcipher_async_req
) +
519 GET_REQ_SIZE(ctx
) + GET_IV_SIZE(ctx
);
524 req
= kmalloc(reqlen
, GFP_KERNEL
);
528 sreq
= GET_SREQ(req
, ctx
);
529 sreq
->iocb
= msg
->msg_iocb
;
530 memset(&sreq
->first_sgl
, '\0', sizeof(struct skcipher_async_rsgl
));
531 INIT_LIST_HEAD(&sreq
->list
);
532 sreq
->tsg
= kcalloc(tx_nents
, sizeof(*sg
), GFP_KERNEL
);
533 if (unlikely(!sreq
->tsg
)) {
537 sg_init_table(sreq
->tsg
, tx_nents
);
538 memcpy(sreq
->iv
, ctx
->iv
, GET_IV_SIZE(ctx
));
539 skcipher_request_set_tfm(req
, crypto_skcipher_reqtfm(&ctx
->req
));
540 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
541 skcipher_async_cb
, sk
);
543 while (iov_iter_count(&msg
->msg_iter
)) {
544 struct skcipher_async_rsgl
*rsgl
;
548 err
= skcipher_wait_for_data(sk
, flags
);
552 sgl
= list_first_entry(&ctx
->tsgl
,
553 struct skcipher_sg_list
, list
);
559 used
= min_t(unsigned long, ctx
->used
,
560 iov_iter_count(&msg
->msg_iter
));
561 used
= min_t(unsigned long, used
, sg
->length
);
563 if (txbufs
== tx_nents
) {
564 struct scatterlist
*tmp
;
566 /* Ran out of tx slots in async request
568 tmp
= kcalloc(tx_nents
* 2, sizeof(*tmp
),
573 sg_init_table(tmp
, tx_nents
* 2);
574 for (x
= 0; x
< tx_nents
; x
++)
575 sg_set_page(&tmp
[x
], sg_page(&sreq
->tsg
[x
]),
577 sreq
->tsg
[x
].offset
);
583 /* Need to take over the tx sgl from ctx
584 * to the asynch req - these sgls will be freed later */
585 sg_set_page(sreq
->tsg
+ txbufs
++, sg_page(sg
), sg
->length
,
588 if (list_empty(&sreq
->list
)) {
589 rsgl
= &sreq
->first_sgl
;
590 list_add_tail(&rsgl
->list
, &sreq
->list
);
592 rsgl
= kmalloc(sizeof(*rsgl
), GFP_KERNEL
);
597 list_add_tail(&rsgl
->list
, &sreq
->list
);
600 used
= af_alg_make_sg(&rsgl
->sgl
, &msg
->msg_iter
, used
);
605 af_alg_link_sg(&last_rsgl
->sgl
, &rsgl
->sgl
);
609 skcipher_pull_sgl(sk
, used
, 0);
610 iov_iter_advance(&msg
->msg_iter
, used
);
614 sg_mark_end(sreq
->tsg
+ txbufs
- 1);
616 skcipher_request_set_crypt(req
, sreq
->tsg
, sreq
->first_sgl
.sgl
.sg
,
618 err
= ctx
->enc
? crypto_skcipher_encrypt(req
) :
619 crypto_skcipher_decrypt(req
);
620 if (err
== -EINPROGRESS
) {
621 atomic_inc(&ctx
->inflight
);
626 skcipher_free_async_sgls(sreq
);
629 skcipher_wmem_wakeup(sk
);
634 static int skcipher_recvmsg_sync(struct socket
*sock
, struct msghdr
*msg
,
637 struct sock
*sk
= sock
->sk
;
638 struct alg_sock
*ask
= alg_sk(sk
);
639 struct skcipher_ctx
*ctx
= ask
->private;
640 unsigned bs
= crypto_skcipher_blocksize(crypto_skcipher_reqtfm(
642 struct skcipher_sg_list
*sgl
;
643 struct scatterlist
*sg
;
649 while (msg_data_left(msg
)) {
650 sgl
= list_first_entry(&ctx
->tsgl
,
651 struct skcipher_sg_list
, list
);
658 err
= skcipher_wait_for_data(sk
, flags
);
663 used
= min_t(unsigned long, ctx
->used
, msg_data_left(msg
));
665 used
= af_alg_make_sg(&ctx
->rsgl
, &msg
->msg_iter
, used
);
670 if (ctx
->more
|| used
< ctx
->used
)
677 skcipher_request_set_crypt(&ctx
->req
, sg
, ctx
->rsgl
.sg
, used
,
680 err
= af_alg_wait_for_completion(
682 crypto_skcipher_encrypt(&ctx
->req
) :
683 crypto_skcipher_decrypt(&ctx
->req
),
687 af_alg_free_sg(&ctx
->rsgl
);
693 skcipher_pull_sgl(sk
, used
, 1);
694 iov_iter_advance(&msg
->msg_iter
, used
);
700 skcipher_wmem_wakeup(sk
);
703 return copied
?: err
;
706 static int skcipher_recvmsg(struct socket
*sock
, struct msghdr
*msg
,
707 size_t ignored
, int flags
)
709 return (msg
->msg_iocb
&& !is_sync_kiocb(msg
->msg_iocb
)) ?
710 skcipher_recvmsg_async(sock
, msg
, flags
) :
711 skcipher_recvmsg_sync(sock
, msg
, flags
);
714 static unsigned int skcipher_poll(struct file
*file
, struct socket
*sock
,
717 struct sock
*sk
= sock
->sk
;
718 struct alg_sock
*ask
= alg_sk(sk
);
719 struct skcipher_ctx
*ctx
= ask
->private;
722 sock_poll_wait(file
, sk_sleep(sk
), wait
);
726 mask
|= POLLIN
| POLLRDNORM
;
728 if (skcipher_writable(sk
))
729 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
734 static struct proto_ops algif_skcipher_ops
= {
737 .connect
= sock_no_connect
,
738 .socketpair
= sock_no_socketpair
,
739 .getname
= sock_no_getname
,
740 .ioctl
= sock_no_ioctl
,
741 .listen
= sock_no_listen
,
742 .shutdown
= sock_no_shutdown
,
743 .getsockopt
= sock_no_getsockopt
,
744 .mmap
= sock_no_mmap
,
745 .bind
= sock_no_bind
,
746 .accept
= sock_no_accept
,
747 .setsockopt
= sock_no_setsockopt
,
749 .release
= af_alg_release
,
750 .sendmsg
= skcipher_sendmsg
,
751 .sendpage
= skcipher_sendpage
,
752 .recvmsg
= skcipher_recvmsg
,
753 .poll
= skcipher_poll
,
756 static int skcipher_check_key(struct socket
*sock
)
760 struct alg_sock
*pask
;
761 struct skcipher_tfm
*tfm
;
762 struct sock
*sk
= sock
->sk
;
763 struct alg_sock
*ask
= alg_sk(sk
);
769 pask
= alg_sk(ask
->parent
);
791 static int skcipher_sendmsg_nokey(struct socket
*sock
, struct msghdr
*msg
,
796 err
= skcipher_check_key(sock
);
800 return skcipher_sendmsg(sock
, msg
, size
);
803 static ssize_t
skcipher_sendpage_nokey(struct socket
*sock
, struct page
*page
,
804 int offset
, size_t size
, int flags
)
808 err
= skcipher_check_key(sock
);
812 return skcipher_sendpage(sock
, page
, offset
, size
, flags
);
815 static int skcipher_recvmsg_nokey(struct socket
*sock
, struct msghdr
*msg
,
816 size_t ignored
, int flags
)
820 err
= skcipher_check_key(sock
);
824 return skcipher_recvmsg(sock
, msg
, ignored
, flags
);
827 static struct proto_ops algif_skcipher_ops_nokey
= {
830 .connect
= sock_no_connect
,
831 .socketpair
= sock_no_socketpair
,
832 .getname
= sock_no_getname
,
833 .ioctl
= sock_no_ioctl
,
834 .listen
= sock_no_listen
,
835 .shutdown
= sock_no_shutdown
,
836 .getsockopt
= sock_no_getsockopt
,
837 .mmap
= sock_no_mmap
,
838 .bind
= sock_no_bind
,
839 .accept
= sock_no_accept
,
840 .setsockopt
= sock_no_setsockopt
,
842 .release
= af_alg_release
,
843 .sendmsg
= skcipher_sendmsg_nokey
,
844 .sendpage
= skcipher_sendpage_nokey
,
845 .recvmsg
= skcipher_recvmsg_nokey
,
846 .poll
= skcipher_poll
,
849 static void *skcipher_bind(const char *name
, u32 type
, u32 mask
)
851 struct skcipher_tfm
*tfm
;
852 struct crypto_skcipher
*skcipher
;
854 tfm
= kzalloc(sizeof(*tfm
), GFP_KERNEL
);
856 return ERR_PTR(-ENOMEM
);
858 skcipher
= crypto_alloc_skcipher(name
, type
, mask
);
859 if (IS_ERR(skcipher
)) {
861 return ERR_CAST(skcipher
);
864 tfm
->skcipher
= skcipher
;
869 static void skcipher_release(void *private)
871 struct skcipher_tfm
*tfm
= private;
873 crypto_free_skcipher(tfm
->skcipher
);
877 static int skcipher_setkey(void *private, const u8
*key
, unsigned int keylen
)
879 struct skcipher_tfm
*tfm
= private;
882 err
= crypto_skcipher_setkey(tfm
->skcipher
, key
, keylen
);
888 static void skcipher_wait(struct sock
*sk
)
890 struct alg_sock
*ask
= alg_sk(sk
);
891 struct skcipher_ctx
*ctx
= ask
->private;
894 while (atomic_read(&ctx
->inflight
) && ctr
++ < 100)
898 static void skcipher_sock_destruct_common(struct sock
*sk
)
900 struct alg_sock
*ask
= alg_sk(sk
);
901 struct skcipher_ctx
*ctx
= ask
->private;
902 struct crypto_skcipher
*tfm
= crypto_skcipher_reqtfm(&ctx
->req
);
904 if (atomic_read(&ctx
->inflight
))
907 skcipher_free_sgl(sk
);
908 sock_kzfree_s(sk
, ctx
->iv
, crypto_skcipher_ivsize(tfm
));
909 sock_kfree_s(sk
, ctx
, ctx
->len
);
912 static void skcipher_sock_destruct(struct sock
*sk
)
914 skcipher_sock_destruct_common(sk
);
915 af_alg_release_parent(sk
);
918 static void skcipher_release_parent_nokey(struct sock
*sk
)
920 struct alg_sock
*ask
= alg_sk(sk
);
923 sock_put(ask
->parent
);
927 af_alg_release_parent(sk
);
930 static void skcipher_sock_destruct_nokey(struct sock
*sk
)
932 skcipher_sock_destruct_common(sk
);
933 skcipher_release_parent_nokey(sk
);
936 static int skcipher_accept_parent_common(void *private, struct sock
*sk
)
938 struct skcipher_ctx
*ctx
;
939 struct alg_sock
*ask
= alg_sk(sk
);
940 struct skcipher_tfm
*tfm
= private;
941 struct crypto_skcipher
*skcipher
= tfm
->skcipher
;
942 unsigned int len
= sizeof(*ctx
) + crypto_skcipher_reqsize(skcipher
);
944 ctx
= sock_kmalloc(sk
, len
, GFP_KERNEL
);
948 ctx
->iv
= sock_kmalloc(sk
, crypto_skcipher_ivsize(skcipher
),
951 sock_kfree_s(sk
, ctx
, len
);
955 memset(ctx
->iv
, 0, crypto_skcipher_ivsize(skcipher
));
957 INIT_LIST_HEAD(&ctx
->tsgl
);
963 atomic_set(&ctx
->inflight
, 0);
964 af_alg_init_completion(&ctx
->completion
);
968 skcipher_request_set_tfm(&ctx
->req
, skcipher
);
969 skcipher_request_set_callback(&ctx
->req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
970 af_alg_complete
, &ctx
->completion
);
972 sk
->sk_destruct
= skcipher_sock_destruct
;
977 static int skcipher_accept_parent(void *private, struct sock
*sk
)
979 struct skcipher_tfm
*tfm
= private;
984 return skcipher_accept_parent_common(private, sk
);
987 static int skcipher_accept_parent_nokey(void *private, struct sock
*sk
)
991 err
= skcipher_accept_parent_common(private, sk
);
995 sk
->sk_destruct
= skcipher_sock_destruct_nokey
;
1001 static const struct af_alg_type algif_type_skcipher
= {
1002 .bind
= skcipher_bind
,
1003 .release
= skcipher_release
,
1004 .setkey
= skcipher_setkey
,
1005 .accept
= skcipher_accept_parent
,
1006 .accept_nokey
= skcipher_accept_parent_nokey
,
1007 .ops
= &algif_skcipher_ops
,
1008 .ops_nokey
= &algif_skcipher_ops_nokey
,
1010 .owner
= THIS_MODULE
1013 static int __init
algif_skcipher_init(void)
1015 return af_alg_register_type(&algif_type_skcipher
);
1018 static void __exit
algif_skcipher_exit(void)
1020 int err
= af_alg_unregister_type(&algif_type_skcipher
);
1024 module_init(algif_skcipher_init
);
1025 module_exit(algif_skcipher_exit
);
1026 MODULE_LICENSE("GPL");