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
;
69 struct skcipher_request req
;
72 #define MAX_SGL_ENTS ((4096 - sizeof(struct skcipher_sg_list)) / \
73 sizeof(struct scatterlist) - 1)
75 static void skcipher_free_async_sgls(struct skcipher_async_req
*sreq
)
77 struct skcipher_async_rsgl
*rsgl
, *tmp
;
78 struct scatterlist
*sgl
;
79 struct scatterlist
*sg
;
82 list_for_each_entry_safe(rsgl
, tmp
, &sreq
->list
, list
) {
83 af_alg_free_sg(&rsgl
->sgl
);
84 if (rsgl
!= &sreq
->first_sgl
)
89 for_each_sg(sgl
, sg
, n
, i
)
90 put_page(sg_page(sg
));
95 static void skcipher_async_cb(struct crypto_async_request
*req
, int err
)
97 struct skcipher_async_req
*sreq
= req
->data
;
98 struct kiocb
*iocb
= sreq
->iocb
;
100 atomic_dec(sreq
->inflight
);
101 skcipher_free_async_sgls(sreq
);
103 iocb
->ki_complete(iocb
, err
, err
);
106 static inline int skcipher_sndbuf(struct sock
*sk
)
108 struct alg_sock
*ask
= alg_sk(sk
);
109 struct skcipher_ctx
*ctx
= ask
->private;
111 return max_t(int, max_t(int, sk
->sk_sndbuf
& PAGE_MASK
, PAGE_SIZE
) -
115 static inline bool skcipher_writable(struct sock
*sk
)
117 return PAGE_SIZE
<= skcipher_sndbuf(sk
);
120 static int skcipher_alloc_sgl(struct sock
*sk
)
122 struct alg_sock
*ask
= alg_sk(sk
);
123 struct skcipher_ctx
*ctx
= ask
->private;
124 struct skcipher_sg_list
*sgl
;
125 struct scatterlist
*sg
= NULL
;
127 sgl
= list_entry(ctx
->tsgl
.prev
, struct skcipher_sg_list
, list
);
128 if (!list_empty(&ctx
->tsgl
))
131 if (!sg
|| sgl
->cur
>= MAX_SGL_ENTS
) {
132 sgl
= sock_kmalloc(sk
, sizeof(*sgl
) +
133 sizeof(sgl
->sg
[0]) * (MAX_SGL_ENTS
+ 1),
138 sg_init_table(sgl
->sg
, MAX_SGL_ENTS
+ 1);
142 sg_chain(sg
, MAX_SGL_ENTS
+ 1, sgl
->sg
);
144 list_add_tail(&sgl
->list
, &ctx
->tsgl
);
150 static void skcipher_pull_sgl(struct sock
*sk
, size_t used
, int put
)
152 struct alg_sock
*ask
= alg_sk(sk
);
153 struct skcipher_ctx
*ctx
= ask
->private;
154 struct skcipher_sg_list
*sgl
;
155 struct scatterlist
*sg
;
158 while (!list_empty(&ctx
->tsgl
)) {
159 sgl
= list_first_entry(&ctx
->tsgl
, struct skcipher_sg_list
,
163 for (i
= 0; i
< sgl
->cur
; i
++) {
164 size_t plen
= min_t(size_t, used
, sg
[i
].length
);
166 if (!sg_page(sg
+ i
))
169 sg
[i
].length
-= plen
;
170 sg
[i
].offset
+= plen
;
178 put_page(sg_page(sg
+ i
));
179 sg_assign_page(sg
+ i
, NULL
);
182 list_del(&sgl
->list
);
183 sock_kfree_s(sk
, sgl
,
184 sizeof(*sgl
) + sizeof(sgl
->sg
[0]) *
192 static void skcipher_free_sgl(struct sock
*sk
)
194 struct alg_sock
*ask
= alg_sk(sk
);
195 struct skcipher_ctx
*ctx
= ask
->private;
197 skcipher_pull_sgl(sk
, ctx
->used
, 1);
200 static int skcipher_wait_for_wmem(struct sock
*sk
, unsigned flags
)
202 DEFINE_WAIT_FUNC(wait
, woken_wake_function
);
203 int err
= -ERESTARTSYS
;
206 if (flags
& MSG_DONTWAIT
)
209 sk_set_bit(SOCKWQ_ASYNC_NOSPACE
, sk
);
211 add_wait_queue(sk_sleep(sk
), &wait
);
213 if (signal_pending(current
))
215 timeout
= MAX_SCHEDULE_TIMEOUT
;
216 if (sk_wait_event(sk
, &timeout
, skcipher_writable(sk
), &wait
)) {
221 remove_wait_queue(sk_sleep(sk
), &wait
);
226 static void skcipher_wmem_wakeup(struct sock
*sk
)
228 struct socket_wq
*wq
;
230 if (!skcipher_writable(sk
))
234 wq
= rcu_dereference(sk
->sk_wq
);
235 if (skwq_has_sleeper(wq
))
236 wake_up_interruptible_sync_poll(&wq
->wait
, POLLIN
|
239 sk_wake_async(sk
, SOCK_WAKE_WAITD
, POLL_IN
);
243 static int skcipher_wait_for_data(struct sock
*sk
, unsigned flags
)
245 DEFINE_WAIT_FUNC(wait
, woken_wake_function
);
246 struct alg_sock
*ask
= alg_sk(sk
);
247 struct skcipher_ctx
*ctx
= ask
->private;
249 int err
= -ERESTARTSYS
;
251 if (flags
& MSG_DONTWAIT
) {
255 sk_set_bit(SOCKWQ_ASYNC_WAITDATA
, sk
);
257 add_wait_queue(sk_sleep(sk
), &wait
);
259 if (signal_pending(current
))
261 timeout
= MAX_SCHEDULE_TIMEOUT
;
262 if (sk_wait_event(sk
, &timeout
, ctx
->used
, &wait
)) {
267 remove_wait_queue(sk_sleep(sk
), &wait
);
269 sk_clear_bit(SOCKWQ_ASYNC_WAITDATA
, sk
);
274 static void skcipher_data_wakeup(struct sock
*sk
)
276 struct alg_sock
*ask
= alg_sk(sk
);
277 struct skcipher_ctx
*ctx
= ask
->private;
278 struct socket_wq
*wq
;
284 wq
= rcu_dereference(sk
->sk_wq
);
285 if (skwq_has_sleeper(wq
))
286 wake_up_interruptible_sync_poll(&wq
->wait
, POLLOUT
|
289 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
293 static int skcipher_sendmsg(struct socket
*sock
, struct msghdr
*msg
,
296 struct sock
*sk
= sock
->sk
;
297 struct alg_sock
*ask
= alg_sk(sk
);
298 struct sock
*psk
= ask
->parent
;
299 struct alg_sock
*pask
= alg_sk(psk
);
300 struct skcipher_ctx
*ctx
= ask
->private;
301 struct skcipher_tfm
*skc
= pask
->private;
302 struct crypto_skcipher
*tfm
= skc
->skcipher
;
303 unsigned ivsize
= crypto_skcipher_ivsize(tfm
);
304 struct skcipher_sg_list
*sgl
;
305 struct af_alg_control con
= {};
312 if (msg
->msg_controllen
) {
313 err
= af_alg_cmsg_send(msg
, &con
);
329 if (con
.iv
&& con
.iv
->ivlen
!= ivsize
)
336 if (!ctx
->more
&& ctx
->used
)
342 memcpy(ctx
->iv
, con
.iv
->iv
, ivsize
);
346 struct scatterlist
*sg
;
347 unsigned long len
= size
;
351 sgl
= list_entry(ctx
->tsgl
.prev
,
352 struct skcipher_sg_list
, list
);
353 sg
= sgl
->sg
+ sgl
->cur
- 1;
354 len
= min_t(unsigned long, len
,
355 PAGE_SIZE
- sg
->offset
- sg
->length
);
357 err
= memcpy_from_msg(page_address(sg_page(sg
)) +
358 sg
->offset
+ sg
->length
,
364 ctx
->merge
= (sg
->offset
+ sg
->length
) &
373 if (!skcipher_writable(sk
)) {
374 err
= skcipher_wait_for_wmem(sk
, msg
->msg_flags
);
379 len
= min_t(unsigned long, len
, skcipher_sndbuf(sk
));
381 err
= skcipher_alloc_sgl(sk
);
385 sgl
= list_entry(ctx
->tsgl
.prev
, struct skcipher_sg_list
, list
);
388 sg_unmark_end(sg
+ sgl
->cur
- 1);
391 plen
= min_t(size_t, len
, PAGE_SIZE
);
393 sg_assign_page(sg
+ i
, alloc_page(GFP_KERNEL
));
395 if (!sg_page(sg
+ i
))
398 err
= memcpy_from_msg(page_address(sg_page(sg
+ i
)),
401 __free_page(sg_page(sg
+ i
));
402 sg_assign_page(sg
+ i
, NULL
);
412 } while (len
&& sgl
->cur
< MAX_SGL_ENTS
);
415 sg_mark_end(sg
+ sgl
->cur
- 1);
417 ctx
->merge
= plen
& (PAGE_SIZE
- 1);
422 ctx
->more
= msg
->msg_flags
& MSG_MORE
;
425 skcipher_data_wakeup(sk
);
428 return copied
?: err
;
431 static ssize_t
skcipher_sendpage(struct socket
*sock
, struct page
*page
,
432 int offset
, size_t size
, int flags
)
434 struct sock
*sk
= sock
->sk
;
435 struct alg_sock
*ask
= alg_sk(sk
);
436 struct skcipher_ctx
*ctx
= ask
->private;
437 struct skcipher_sg_list
*sgl
;
440 if (flags
& MSG_SENDPAGE_NOTLAST
)
444 if (!ctx
->more
&& ctx
->used
)
450 if (!skcipher_writable(sk
)) {
451 err
= skcipher_wait_for_wmem(sk
, flags
);
456 err
= skcipher_alloc_sgl(sk
);
461 sgl
= list_entry(ctx
->tsgl
.prev
, struct skcipher_sg_list
, list
);
464 sg_unmark_end(sgl
->sg
+ sgl
->cur
- 1);
466 sg_mark_end(sgl
->sg
+ sgl
->cur
);
468 sg_set_page(sgl
->sg
+ sgl
->cur
, page
, size
, offset
);
473 ctx
->more
= flags
& MSG_MORE
;
476 skcipher_data_wakeup(sk
);
482 static int skcipher_all_sg_nents(struct skcipher_ctx
*ctx
)
484 struct skcipher_sg_list
*sgl
;
485 struct scatterlist
*sg
;
488 list_for_each_entry(sgl
, &ctx
->tsgl
, list
) {
494 nents
+= sg_nents(sg
);
499 static int skcipher_recvmsg_async(struct socket
*sock
, struct msghdr
*msg
,
502 struct sock
*sk
= sock
->sk
;
503 struct alg_sock
*ask
= alg_sk(sk
);
504 struct sock
*psk
= ask
->parent
;
505 struct alg_sock
*pask
= alg_sk(psk
);
506 struct skcipher_ctx
*ctx
= ask
->private;
507 struct skcipher_tfm
*skc
= pask
->private;
508 struct crypto_skcipher
*tfm
= skc
->skcipher
;
509 struct skcipher_sg_list
*sgl
;
510 struct scatterlist
*sg
;
511 struct skcipher_async_req
*sreq
;
512 struct skcipher_request
*req
;
513 struct skcipher_async_rsgl
*last_rsgl
= NULL
;
514 unsigned int txbufs
= 0, len
= 0, tx_nents
;
515 unsigned int reqsize
= crypto_skcipher_reqsize(tfm
);
516 unsigned int ivsize
= crypto_skcipher_ivsize(tfm
);
521 sreq
= kzalloc(sizeof(*sreq
) + reqsize
+ ivsize
, GFP_KERNEL
);
526 iv
= (char *)(req
+ 1) + reqsize
;
527 sreq
->iocb
= msg
->msg_iocb
;
528 INIT_LIST_HEAD(&sreq
->list
);
529 sreq
->inflight
= &ctx
->inflight
;
532 tx_nents
= skcipher_all_sg_nents(ctx
);
533 sreq
->tsg
= kcalloc(tx_nents
, sizeof(*sg
), GFP_KERNEL
);
534 if (unlikely(!sreq
->tsg
))
536 sg_init_table(sreq
->tsg
, tx_nents
);
537 memcpy(iv
, ctx
->iv
, ivsize
);
538 skcipher_request_set_tfm(req
, tfm
);
539 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_SLEEP
,
540 skcipher_async_cb
, sreq
);
542 while (iov_iter_count(&msg
->msg_iter
)) {
543 struct skcipher_async_rsgl
*rsgl
;
547 err
= skcipher_wait_for_data(sk
, flags
);
551 sgl
= list_first_entry(&ctx
->tsgl
,
552 struct skcipher_sg_list
, list
);
558 used
= min_t(unsigned long, ctx
->used
,
559 iov_iter_count(&msg
->msg_iter
));
560 used
= min_t(unsigned long, used
, sg
->length
);
562 if (txbufs
== tx_nents
) {
563 struct scatterlist
*tmp
;
565 /* Ran out of tx slots in async request
567 tmp
= kcalloc(tx_nents
* 2, sizeof(*tmp
),
574 sg_init_table(tmp
, tx_nents
* 2);
575 for (x
= 0; x
< tx_nents
; x
++)
576 sg_set_page(&tmp
[x
], sg_page(&sreq
->tsg
[x
]),
578 sreq
->tsg
[x
].offset
);
584 /* Need to take over the tx sgl from ctx
585 * to the asynch req - these sgls will be freed later */
586 sg_set_page(sreq
->tsg
+ txbufs
++, sg_page(sg
), sg
->length
,
589 if (list_empty(&sreq
->list
)) {
590 rsgl
= &sreq
->first_sgl
;
591 list_add_tail(&rsgl
->list
, &sreq
->list
);
593 rsgl
= kmalloc(sizeof(*rsgl
), GFP_KERNEL
);
598 list_add_tail(&rsgl
->list
, &sreq
->list
);
601 used
= af_alg_make_sg(&rsgl
->sgl
, &msg
->msg_iter
, used
);
606 af_alg_link_sg(&last_rsgl
->sgl
, &rsgl
->sgl
);
610 skcipher_pull_sgl(sk
, used
, 0);
611 iov_iter_advance(&msg
->msg_iter
, used
);
615 sg_mark_end(sreq
->tsg
+ txbufs
- 1);
617 skcipher_request_set_crypt(req
, sreq
->tsg
, sreq
->first_sgl
.sgl
.sg
,
619 err
= ctx
->enc
? crypto_skcipher_encrypt(req
) :
620 crypto_skcipher_decrypt(req
);
621 if (err
== -EINPROGRESS
) {
622 atomic_inc(&ctx
->inflight
);
628 skcipher_free_async_sgls(sreq
);
630 skcipher_wmem_wakeup(sk
);
637 static int skcipher_recvmsg_sync(struct socket
*sock
, struct msghdr
*msg
,
640 struct sock
*sk
= sock
->sk
;
641 struct alg_sock
*ask
= alg_sk(sk
);
642 struct sock
*psk
= ask
->parent
;
643 struct alg_sock
*pask
= alg_sk(psk
);
644 struct skcipher_ctx
*ctx
= ask
->private;
645 struct skcipher_tfm
*skc
= pask
->private;
646 struct crypto_skcipher
*tfm
= skc
->skcipher
;
647 unsigned bs
= crypto_skcipher_blocksize(tfm
);
648 struct skcipher_sg_list
*sgl
;
649 struct scatterlist
*sg
;
655 while (msg_data_left(msg
)) {
657 err
= skcipher_wait_for_data(sk
, flags
);
662 used
= min_t(unsigned long, ctx
->used
, msg_data_left(msg
));
664 used
= af_alg_make_sg(&ctx
->rsgl
, &msg
->msg_iter
, used
);
669 if (ctx
->more
|| used
< ctx
->used
)
676 sgl
= list_first_entry(&ctx
->tsgl
,
677 struct skcipher_sg_list
, list
);
683 skcipher_request_set_crypt(&ctx
->req
, sg
, ctx
->rsgl
.sg
, used
,
686 err
= af_alg_wait_for_completion(
688 crypto_skcipher_encrypt(&ctx
->req
) :
689 crypto_skcipher_decrypt(&ctx
->req
),
693 af_alg_free_sg(&ctx
->rsgl
);
699 skcipher_pull_sgl(sk
, used
, 1);
700 iov_iter_advance(&msg
->msg_iter
, used
);
706 skcipher_wmem_wakeup(sk
);
709 return copied
?: err
;
712 static int skcipher_recvmsg(struct socket
*sock
, struct msghdr
*msg
,
713 size_t ignored
, int flags
)
715 return (msg
->msg_iocb
&& !is_sync_kiocb(msg
->msg_iocb
)) ?
716 skcipher_recvmsg_async(sock
, msg
, flags
) :
717 skcipher_recvmsg_sync(sock
, msg
, flags
);
720 static unsigned int skcipher_poll(struct file
*file
, struct socket
*sock
,
723 struct sock
*sk
= sock
->sk
;
724 struct alg_sock
*ask
= alg_sk(sk
);
725 struct skcipher_ctx
*ctx
= ask
->private;
728 sock_poll_wait(file
, sk_sleep(sk
), wait
);
732 mask
|= POLLIN
| POLLRDNORM
;
734 if (skcipher_writable(sk
))
735 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
740 static struct proto_ops algif_skcipher_ops
= {
743 .connect
= sock_no_connect
,
744 .socketpair
= sock_no_socketpair
,
745 .getname
= sock_no_getname
,
746 .ioctl
= sock_no_ioctl
,
747 .listen
= sock_no_listen
,
748 .shutdown
= sock_no_shutdown
,
749 .getsockopt
= sock_no_getsockopt
,
750 .mmap
= sock_no_mmap
,
751 .bind
= sock_no_bind
,
752 .accept
= sock_no_accept
,
753 .setsockopt
= sock_no_setsockopt
,
755 .release
= af_alg_release
,
756 .sendmsg
= skcipher_sendmsg
,
757 .sendpage
= skcipher_sendpage
,
758 .recvmsg
= skcipher_recvmsg
,
759 .poll
= skcipher_poll
,
762 static int skcipher_check_key(struct socket
*sock
)
766 struct alg_sock
*pask
;
767 struct skcipher_tfm
*tfm
;
768 struct sock
*sk
= sock
->sk
;
769 struct alg_sock
*ask
= alg_sk(sk
);
776 pask
= alg_sk(ask
->parent
);
780 lock_sock_nested(psk
, SINGLE_DEPTH_NESTING
);
800 static int skcipher_sendmsg_nokey(struct socket
*sock
, struct msghdr
*msg
,
805 err
= skcipher_check_key(sock
);
809 return skcipher_sendmsg(sock
, msg
, size
);
812 static ssize_t
skcipher_sendpage_nokey(struct socket
*sock
, struct page
*page
,
813 int offset
, size_t size
, int flags
)
817 err
= skcipher_check_key(sock
);
821 return skcipher_sendpage(sock
, page
, offset
, size
, flags
);
824 static int skcipher_recvmsg_nokey(struct socket
*sock
, struct msghdr
*msg
,
825 size_t ignored
, int flags
)
829 err
= skcipher_check_key(sock
);
833 return skcipher_recvmsg(sock
, msg
, ignored
, flags
);
836 static struct proto_ops algif_skcipher_ops_nokey
= {
839 .connect
= sock_no_connect
,
840 .socketpair
= sock_no_socketpair
,
841 .getname
= sock_no_getname
,
842 .ioctl
= sock_no_ioctl
,
843 .listen
= sock_no_listen
,
844 .shutdown
= sock_no_shutdown
,
845 .getsockopt
= sock_no_getsockopt
,
846 .mmap
= sock_no_mmap
,
847 .bind
= sock_no_bind
,
848 .accept
= sock_no_accept
,
849 .setsockopt
= sock_no_setsockopt
,
851 .release
= af_alg_release
,
852 .sendmsg
= skcipher_sendmsg_nokey
,
853 .sendpage
= skcipher_sendpage_nokey
,
854 .recvmsg
= skcipher_recvmsg_nokey
,
855 .poll
= skcipher_poll
,
858 static void *skcipher_bind(const char *name
, u32 type
, u32 mask
)
860 struct skcipher_tfm
*tfm
;
861 struct crypto_skcipher
*skcipher
;
863 tfm
= kzalloc(sizeof(*tfm
), GFP_KERNEL
);
865 return ERR_PTR(-ENOMEM
);
867 skcipher
= crypto_alloc_skcipher(name
, type
, mask
);
868 if (IS_ERR(skcipher
)) {
870 return ERR_CAST(skcipher
);
873 tfm
->skcipher
= skcipher
;
878 static void skcipher_release(void *private)
880 struct skcipher_tfm
*tfm
= private;
882 crypto_free_skcipher(tfm
->skcipher
);
886 static int skcipher_setkey(void *private, const u8
*key
, unsigned int keylen
)
888 struct skcipher_tfm
*tfm
= private;
891 err
= crypto_skcipher_setkey(tfm
->skcipher
, key
, keylen
);
897 static void skcipher_wait(struct sock
*sk
)
899 struct alg_sock
*ask
= alg_sk(sk
);
900 struct skcipher_ctx
*ctx
= ask
->private;
903 while (atomic_read(&ctx
->inflight
) && ctr
++ < 100)
907 static void skcipher_sock_destruct(struct sock
*sk
)
909 struct alg_sock
*ask
= alg_sk(sk
);
910 struct skcipher_ctx
*ctx
= ask
->private;
911 struct crypto_skcipher
*tfm
= crypto_skcipher_reqtfm(&ctx
->req
);
913 if (atomic_read(&ctx
->inflight
))
916 skcipher_free_sgl(sk
);
917 sock_kzfree_s(sk
, ctx
->iv
, crypto_skcipher_ivsize(tfm
));
918 sock_kfree_s(sk
, ctx
, ctx
->len
);
919 af_alg_release_parent(sk
);
922 static int skcipher_accept_parent_nokey(void *private, struct sock
*sk
)
924 struct skcipher_ctx
*ctx
;
925 struct alg_sock
*ask
= alg_sk(sk
);
926 struct skcipher_tfm
*tfm
= private;
927 struct crypto_skcipher
*skcipher
= tfm
->skcipher
;
928 unsigned int len
= sizeof(*ctx
) + crypto_skcipher_reqsize(skcipher
);
930 ctx
= sock_kmalloc(sk
, len
, GFP_KERNEL
);
934 ctx
->iv
= sock_kmalloc(sk
, crypto_skcipher_ivsize(skcipher
),
937 sock_kfree_s(sk
, ctx
, len
);
941 memset(ctx
->iv
, 0, crypto_skcipher_ivsize(skcipher
));
943 INIT_LIST_HEAD(&ctx
->tsgl
);
949 atomic_set(&ctx
->inflight
, 0);
950 af_alg_init_completion(&ctx
->completion
);
954 skcipher_request_set_tfm(&ctx
->req
, skcipher
);
955 skcipher_request_set_callback(&ctx
->req
, CRYPTO_TFM_REQ_MAY_SLEEP
|
956 CRYPTO_TFM_REQ_MAY_BACKLOG
,
957 af_alg_complete
, &ctx
->completion
);
959 sk
->sk_destruct
= skcipher_sock_destruct
;
964 static int skcipher_accept_parent(void *private, struct sock
*sk
)
966 struct skcipher_tfm
*tfm
= private;
968 if (!tfm
->has_key
&& crypto_skcipher_has_setkey(tfm
->skcipher
))
971 return skcipher_accept_parent_nokey(private, sk
);
974 static const struct af_alg_type algif_type_skcipher
= {
975 .bind
= skcipher_bind
,
976 .release
= skcipher_release
,
977 .setkey
= skcipher_setkey
,
978 .accept
= skcipher_accept_parent
,
979 .accept_nokey
= skcipher_accept_parent_nokey
,
980 .ops
= &algif_skcipher_ops
,
981 .ops_nokey
= &algif_skcipher_ops_nokey
,
986 static int __init
algif_skcipher_init(void)
988 return af_alg_register_type(&algif_type_skcipher
);
991 static void __exit
algif_skcipher_exit(void)
993 int err
= af_alg_unregister_type(&algif_type_skcipher
);
997 module_init(algif_skcipher_init
);
998 module_exit(algif_skcipher_exit
);
999 MODULE_LICENSE("GPL");