algif_aead.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /*
  2. * algif_aead: User-space interface for AEAD algorithms
  3. *
  4. * Copyright (C) 2014, Stephan Mueller <smueller@chronox.de>
  5. *
  6. * This file provides the user-space API for AEAD ciphers.
  7. *
  8. * This file is derived from algif_skcipher.c.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License, or (at your option)
  13. * any later version.
  14. */
  15. #include <crypto/aead.h>
  16. #include <crypto/scatterwalk.h>
  17. #include <crypto/if_alg.h>
  18. #include <linux/init.h>
  19. #include <linux/list.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mm.h>
  22. #include <linux/module.h>
  23. #include <linux/net.h>
  24. #include <net/sock.h>
  25. struct aead_sg_list {
  26. unsigned int cur;
  27. struct scatterlist sg[ALG_MAX_PAGES];
  28. };
  29. struct aead_tfm {
  30. struct crypto_aead *aead;
  31. bool has_key;
  32. };
  33. struct aead_ctx {
  34. struct aead_sg_list tsgl;
  35. /*
  36. * RSGL_MAX_ENTRIES is an artificial limit where user space at maximum
  37. * can cause the kernel to allocate RSGL_MAX_ENTRIES * ALG_MAX_PAGES
  38. * pages
  39. */
  40. #define RSGL_MAX_ENTRIES ALG_MAX_PAGES
  41. struct af_alg_sgl rsgl[RSGL_MAX_ENTRIES];
  42. void *iv;
  43. struct af_alg_completion completion;
  44. unsigned long used;
  45. unsigned int len;
  46. bool more;
  47. bool merge;
  48. bool enc;
  49. size_t aead_assoclen;
  50. struct aead_request aead_req;
  51. };
  52. static inline int aead_sndbuf(struct sock *sk)
  53. {
  54. struct alg_sock *ask = alg_sk(sk);
  55. struct aead_ctx *ctx = ask->private;
  56. return max_t(int, max_t(int, sk->sk_sndbuf & PAGE_MASK, PAGE_SIZE) -
  57. ctx->used, 0);
  58. }
  59. static inline bool aead_writable(struct sock *sk)
  60. {
  61. return PAGE_SIZE <= aead_sndbuf(sk);
  62. }
  63. static inline bool aead_sufficient_data(struct aead_ctx *ctx)
  64. {
  65. unsigned as = crypto_aead_authsize(crypto_aead_reqtfm(&ctx->aead_req));
  66. return ctx->used >= ctx->aead_assoclen + as;
  67. }
  68. static void aead_put_sgl(struct sock *sk)
  69. {
  70. struct alg_sock *ask = alg_sk(sk);
  71. struct aead_ctx *ctx = ask->private;
  72. struct aead_sg_list *sgl = &ctx->tsgl;
  73. struct scatterlist *sg = sgl->sg;
  74. unsigned int i;
  75. for (i = 0; i < sgl->cur; i++) {
  76. if (!sg_page(sg + i))
  77. continue;
  78. put_page(sg_page(sg + i));
  79. sg_assign_page(sg + i, NULL);
  80. }
  81. sg_init_table(sg, ALG_MAX_PAGES);
  82. sgl->cur = 0;
  83. ctx->used = 0;
  84. ctx->more = 0;
  85. ctx->merge = 0;
  86. }
  87. static void aead_wmem_wakeup(struct sock *sk)
  88. {
  89. struct socket_wq *wq;
  90. if (!aead_writable(sk))
  91. return;
  92. rcu_read_lock();
  93. wq = rcu_dereference(sk->sk_wq);
  94. if (wq_has_sleeper(wq))
  95. wake_up_interruptible_sync_poll(&wq->wait, POLLIN |
  96. POLLRDNORM |
  97. POLLRDBAND);
  98. sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
  99. rcu_read_unlock();
  100. }
  101. static int aead_wait_for_data(struct sock *sk, unsigned flags)
  102. {
  103. struct alg_sock *ask = alg_sk(sk);
  104. struct aead_ctx *ctx = ask->private;
  105. long timeout;
  106. DEFINE_WAIT(wait);
  107. int err = -ERESTARTSYS;
  108. if (flags & MSG_DONTWAIT)
  109. return -EAGAIN;
  110. sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk);
  111. for (;;) {
  112. if (signal_pending(current))
  113. break;
  114. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  115. timeout = MAX_SCHEDULE_TIMEOUT;
  116. if (sk_wait_event(sk, &timeout, !ctx->more)) {
  117. err = 0;
  118. break;
  119. }
  120. }
  121. finish_wait(sk_sleep(sk), &wait);
  122. sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk);
  123. return err;
  124. }
  125. static void aead_data_wakeup(struct sock *sk)
  126. {
  127. struct alg_sock *ask = alg_sk(sk);
  128. struct aead_ctx *ctx = ask->private;
  129. struct socket_wq *wq;
  130. if (ctx->more)
  131. return;
  132. if (!ctx->used)
  133. return;
  134. rcu_read_lock();
  135. wq = rcu_dereference(sk->sk_wq);
  136. if (wq_has_sleeper(wq))
  137. wake_up_interruptible_sync_poll(&wq->wait, POLLOUT |
  138. POLLRDNORM |
  139. POLLRDBAND);
  140. sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
  141. rcu_read_unlock();
  142. }
  143. static int aead_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
  144. {
  145. struct sock *sk = sock->sk;
  146. struct alg_sock *ask = alg_sk(sk);
  147. struct aead_ctx *ctx = ask->private;
  148. unsigned ivsize =
  149. crypto_aead_ivsize(crypto_aead_reqtfm(&ctx->aead_req));
  150. struct aead_sg_list *sgl = &ctx->tsgl;
  151. struct af_alg_control con = {};
  152. long copied = 0;
  153. bool enc = 0;
  154. bool init = 0;
  155. int err = -EINVAL;
  156. if (msg->msg_controllen) {
  157. err = af_alg_cmsg_send(msg, &con);
  158. if (err)
  159. return err;
  160. init = 1;
  161. switch (con.op) {
  162. case ALG_OP_ENCRYPT:
  163. enc = 1;
  164. break;
  165. case ALG_OP_DECRYPT:
  166. enc = 0;
  167. break;
  168. default:
  169. return -EINVAL;
  170. }
  171. if (con.iv && con.iv->ivlen != ivsize)
  172. return -EINVAL;
  173. }
  174. lock_sock(sk);
  175. if (!ctx->more && ctx->used)
  176. goto unlock;
  177. if (init) {
  178. ctx->enc = enc;
  179. if (con.iv)
  180. memcpy(ctx->iv, con.iv->iv, ivsize);
  181. ctx->aead_assoclen = con.aead_assoclen;
  182. }
  183. while (size) {
  184. unsigned long len = size;
  185. struct scatterlist *sg = NULL;
  186. /* use the existing memory in an allocated page */
  187. if (ctx->merge) {
  188. sg = sgl->sg + sgl->cur - 1;
  189. len = min_t(unsigned long, len,
  190. PAGE_SIZE - sg->offset - sg->length);
  191. err = memcpy_from_msg(page_address(sg_page(sg)) +
  192. sg->offset + sg->length,
  193. msg, len);
  194. if (err)
  195. goto unlock;
  196. sg->length += len;
  197. ctx->merge = (sg->offset + sg->length) &
  198. (PAGE_SIZE - 1);
  199. ctx->used += len;
  200. copied += len;
  201. size -= len;
  202. continue;
  203. }
  204. if (!aead_writable(sk)) {
  205. /* user space sent too much data */
  206. aead_put_sgl(sk);
  207. err = -EMSGSIZE;
  208. goto unlock;
  209. }
  210. /* allocate a new page */
  211. len = min_t(unsigned long, size, aead_sndbuf(sk));
  212. while (len) {
  213. int plen = 0;
  214. if (sgl->cur >= ALG_MAX_PAGES) {
  215. aead_put_sgl(sk);
  216. err = -E2BIG;
  217. goto unlock;
  218. }
  219. sg = sgl->sg + sgl->cur;
  220. plen = min_t(int, len, PAGE_SIZE);
  221. sg_assign_page(sg, alloc_page(GFP_KERNEL));
  222. err = -ENOMEM;
  223. if (!sg_page(sg))
  224. goto unlock;
  225. err = memcpy_from_msg(page_address(sg_page(sg)),
  226. msg, plen);
  227. if (err) {
  228. __free_page(sg_page(sg));
  229. sg_assign_page(sg, NULL);
  230. goto unlock;
  231. }
  232. sg->offset = 0;
  233. sg->length = plen;
  234. len -= plen;
  235. ctx->used += plen;
  236. copied += plen;
  237. sgl->cur++;
  238. size -= plen;
  239. ctx->merge = plen & (PAGE_SIZE - 1);
  240. }
  241. }
  242. err = 0;
  243. ctx->more = msg->msg_flags & MSG_MORE;
  244. if (!ctx->more && !aead_sufficient_data(ctx)) {
  245. aead_put_sgl(sk);
  246. err = -EMSGSIZE;
  247. }
  248. unlock:
  249. aead_data_wakeup(sk);
  250. release_sock(sk);
  251. return err ?: copied;
  252. }
  253. static ssize_t aead_sendpage(struct socket *sock, struct page *page,
  254. int offset, size_t size, int flags)
  255. {
  256. struct sock *sk = sock->sk;
  257. struct alg_sock *ask = alg_sk(sk);
  258. struct aead_ctx *ctx = ask->private;
  259. struct aead_sg_list *sgl = &ctx->tsgl;
  260. int err = -EINVAL;
  261. if (flags & MSG_SENDPAGE_NOTLAST)
  262. flags |= MSG_MORE;
  263. if (sgl->cur >= ALG_MAX_PAGES)
  264. return -E2BIG;
  265. lock_sock(sk);
  266. if (!ctx->more && ctx->used)
  267. goto unlock;
  268. if (!size)
  269. goto done;
  270. if (!aead_writable(sk)) {
  271. /* user space sent too much data */
  272. aead_put_sgl(sk);
  273. err = -EMSGSIZE;
  274. goto unlock;
  275. }
  276. ctx->merge = 0;
  277. get_page(page);
  278. sg_set_page(sgl->sg + sgl->cur, page, size, offset);
  279. sgl->cur++;
  280. ctx->used += size;
  281. err = 0;
  282. done:
  283. ctx->more = flags & MSG_MORE;
  284. if (!ctx->more && !aead_sufficient_data(ctx)) {
  285. aead_put_sgl(sk);
  286. err = -EMSGSIZE;
  287. }
  288. unlock:
  289. aead_data_wakeup(sk);
  290. release_sock(sk);
  291. return err ?: size;
  292. }
  293. static int aead_recvmsg(struct socket *sock, struct msghdr *msg, size_t ignored, int flags)
  294. {
  295. struct sock *sk = sock->sk;
  296. struct alg_sock *ask = alg_sk(sk);
  297. struct aead_ctx *ctx = ask->private;
  298. unsigned as = crypto_aead_authsize(crypto_aead_reqtfm(&ctx->aead_req));
  299. struct aead_sg_list *sgl = &ctx->tsgl;
  300. unsigned int i = 0;
  301. int err = -EINVAL;
  302. unsigned long used = 0;
  303. size_t outlen = 0;
  304. size_t usedpages = 0;
  305. unsigned int cnt = 0;
  306. /* Limit number of IOV blocks to be accessed below */
  307. if (msg->msg_iter.nr_segs > RSGL_MAX_ENTRIES)
  308. return -ENOMSG;
  309. lock_sock(sk);
  310. /*
  311. * AEAD memory structure: For encryption, the tag is appended to the
  312. * ciphertext which implies that the memory allocated for the ciphertext
  313. * must be increased by the tag length. For decryption, the tag
  314. * is expected to be concatenated to the ciphertext. The plaintext
  315. * therefore has a memory size of the ciphertext minus the tag length.
  316. *
  317. * The memory structure for cipher operation has the following
  318. * structure:
  319. * AEAD encryption input: assoc data || plaintext
  320. * AEAD encryption output: cipherntext || auth tag
  321. * AEAD decryption input: assoc data || ciphertext || auth tag
  322. * AEAD decryption output: plaintext
  323. */
  324. if (ctx->more) {
  325. err = aead_wait_for_data(sk, flags);
  326. if (err)
  327. goto unlock;
  328. }
  329. used = ctx->used;
  330. /*
  331. * Make sure sufficient data is present -- note, the same check is
  332. * is also present in sendmsg/sendpage. The checks in sendpage/sendmsg
  333. * shall provide an information to the data sender that something is
  334. * wrong, but they are irrelevant to maintain the kernel integrity.
  335. * We need this check here too in case user space decides to not honor
  336. * the error message in sendmsg/sendpage and still call recvmsg. This
  337. * check here protects the kernel integrity.
  338. */
  339. if (!aead_sufficient_data(ctx))
  340. goto unlock;
  341. outlen = used;
  342. /*
  343. * The cipher operation input data is reduced by the associated data
  344. * length as this data is processed separately later on.
  345. */
  346. used -= ctx->aead_assoclen + (ctx->enc ? as : 0);
  347. /* convert iovecs of output buffers into scatterlists */
  348. while (iov_iter_count(&msg->msg_iter)) {
  349. size_t seglen = min_t(size_t, iov_iter_count(&msg->msg_iter),
  350. (outlen - usedpages));
  351. /* make one iovec available as scatterlist */
  352. err = af_alg_make_sg(&ctx->rsgl[cnt], &msg->msg_iter,
  353. seglen);
  354. if (err < 0)
  355. goto unlock;
  356. usedpages += err;
  357. /* chain the new scatterlist with previous one */
  358. if (cnt)
  359. af_alg_link_sg(&ctx->rsgl[cnt-1], &ctx->rsgl[cnt]);
  360. /* we do not need more iovecs as we have sufficient memory */
  361. if (outlen <= usedpages)
  362. break;
  363. iov_iter_advance(&msg->msg_iter, err);
  364. cnt++;
  365. }
  366. err = -EINVAL;
  367. /* ensure output buffer is sufficiently large */
  368. if (usedpages < outlen)
  369. goto unlock;
  370. sg_mark_end(sgl->sg + sgl->cur - 1);
  371. aead_request_set_crypt(&ctx->aead_req, sgl->sg, ctx->rsgl[0].sg,
  372. used, ctx->iv);
  373. aead_request_set_ad(&ctx->aead_req, ctx->aead_assoclen);
  374. err = af_alg_wait_for_completion(ctx->enc ?
  375. crypto_aead_encrypt(&ctx->aead_req) :
  376. crypto_aead_decrypt(&ctx->aead_req),
  377. &ctx->completion);
  378. if (err) {
  379. /* EBADMSG implies a valid cipher operation took place */
  380. if (err == -EBADMSG)
  381. aead_put_sgl(sk);
  382. goto unlock;
  383. }
  384. aead_put_sgl(sk);
  385. err = 0;
  386. unlock:
  387. for (i = 0; i < cnt; i++)
  388. af_alg_free_sg(&ctx->rsgl[i]);
  389. aead_wmem_wakeup(sk);
  390. release_sock(sk);
  391. return err ? err : outlen;
  392. }
  393. static unsigned int aead_poll(struct file *file, struct socket *sock,
  394. poll_table *wait)
  395. {
  396. struct sock *sk = sock->sk;
  397. struct alg_sock *ask = alg_sk(sk);
  398. struct aead_ctx *ctx = ask->private;
  399. unsigned int mask;
  400. sock_poll_wait(file, sk_sleep(sk), wait);
  401. mask = 0;
  402. if (!ctx->more)
  403. mask |= POLLIN | POLLRDNORM;
  404. if (aead_writable(sk))
  405. mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
  406. return mask;
  407. }
  408. static struct proto_ops algif_aead_ops = {
  409. .family = PF_ALG,
  410. .connect = sock_no_connect,
  411. .socketpair = sock_no_socketpair,
  412. .getname = sock_no_getname,
  413. .ioctl = sock_no_ioctl,
  414. .listen = sock_no_listen,
  415. .shutdown = sock_no_shutdown,
  416. .getsockopt = sock_no_getsockopt,
  417. .mmap = sock_no_mmap,
  418. .bind = sock_no_bind,
  419. .accept = sock_no_accept,
  420. .setsockopt = sock_no_setsockopt,
  421. .release = af_alg_release,
  422. .sendmsg = aead_sendmsg,
  423. .sendpage = aead_sendpage,
  424. .recvmsg = aead_recvmsg,
  425. .poll = aead_poll,
  426. };
  427. static int aead_check_key(struct socket *sock)
  428. {
  429. int err = 0;
  430. struct sock *psk;
  431. struct alg_sock *pask;
  432. struct aead_tfm *tfm;
  433. struct sock *sk = sock->sk;
  434. struct alg_sock *ask = alg_sk(sk);
  435. lock_sock(sk);
  436. if (ask->refcnt)
  437. goto unlock_child;
  438. psk = ask->parent;
  439. pask = alg_sk(ask->parent);
  440. tfm = pask->private;
  441. err = -ENOKEY;
  442. lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
  443. if (!tfm->has_key)
  444. goto unlock;
  445. if (!pask->refcnt++)
  446. sock_hold(psk);
  447. ask->refcnt = 1;
  448. sock_put(psk);
  449. err = 0;
  450. unlock:
  451. release_sock(psk);
  452. unlock_child:
  453. release_sock(sk);
  454. return err;
  455. }
  456. static int aead_sendmsg_nokey(struct socket *sock, struct msghdr *msg,
  457. size_t size)
  458. {
  459. int err;
  460. err = aead_check_key(sock);
  461. if (err)
  462. return err;
  463. return aead_sendmsg(sock, msg, size);
  464. }
  465. static ssize_t aead_sendpage_nokey(struct socket *sock, struct page *page,
  466. int offset, size_t size, int flags)
  467. {
  468. int err;
  469. err = aead_check_key(sock);
  470. if (err)
  471. return err;
  472. return aead_sendpage(sock, page, offset, size, flags);
  473. }
  474. static int aead_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
  475. size_t ignored, int flags)
  476. {
  477. int err;
  478. err = aead_check_key(sock);
  479. if (err)
  480. return err;
  481. return aead_recvmsg(sock, msg, ignored, flags);
  482. }
  483. static struct proto_ops algif_aead_ops_nokey = {
  484. .family = PF_ALG,
  485. .connect = sock_no_connect,
  486. .socketpair = sock_no_socketpair,
  487. .getname = sock_no_getname,
  488. .ioctl = sock_no_ioctl,
  489. .listen = sock_no_listen,
  490. .shutdown = sock_no_shutdown,
  491. .getsockopt = sock_no_getsockopt,
  492. .mmap = sock_no_mmap,
  493. .bind = sock_no_bind,
  494. .accept = sock_no_accept,
  495. .setsockopt = sock_no_setsockopt,
  496. .release = af_alg_release,
  497. .sendmsg = aead_sendmsg_nokey,
  498. .sendpage = aead_sendpage_nokey,
  499. .recvmsg = aead_recvmsg_nokey,
  500. .poll = aead_poll,
  501. };
  502. static void *aead_bind(const char *name, u32 type, u32 mask)
  503. {
  504. struct aead_tfm *tfm;
  505. struct crypto_aead *aead;
  506. tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
  507. if (!tfm)
  508. return ERR_PTR(-ENOMEM);
  509. aead = crypto_alloc_aead(name, type, mask);
  510. if (IS_ERR(aead)) {
  511. kfree(tfm);
  512. return ERR_CAST(aead);
  513. }
  514. tfm->aead = aead;
  515. return tfm;
  516. }
  517. static void aead_release(void *private)
  518. {
  519. struct aead_tfm *tfm = private;
  520. crypto_free_aead(tfm->aead);
  521. kfree(tfm);
  522. }
  523. static int aead_setauthsize(void *private, unsigned int authsize)
  524. {
  525. struct aead_tfm *tfm = private;
  526. return crypto_aead_setauthsize(tfm->aead, authsize);
  527. }
  528. static int aead_setkey(void *private, const u8 *key, unsigned int keylen)
  529. {
  530. struct aead_tfm *tfm = private;
  531. int err;
  532. err = crypto_aead_setkey(tfm->aead, key, keylen);
  533. tfm->has_key = !err;
  534. return err;
  535. }
  536. static void aead_sock_destruct(struct sock *sk)
  537. {
  538. struct alg_sock *ask = alg_sk(sk);
  539. struct aead_ctx *ctx = ask->private;
  540. unsigned int ivlen = crypto_aead_ivsize(
  541. crypto_aead_reqtfm(&ctx->aead_req));
  542. aead_put_sgl(sk);
  543. sock_kzfree_s(sk, ctx->iv, ivlen);
  544. sock_kfree_s(sk, ctx, ctx->len);
  545. af_alg_release_parent(sk);
  546. }
  547. static int aead_accept_parent_nokey(void *private, struct sock *sk)
  548. {
  549. struct aead_ctx *ctx;
  550. struct alg_sock *ask = alg_sk(sk);
  551. struct aead_tfm *tfm = private;
  552. struct crypto_aead *aead = tfm->aead;
  553. unsigned int len = sizeof(*ctx) + crypto_aead_reqsize(aead);
  554. unsigned int ivlen = crypto_aead_ivsize(aead);
  555. ctx = sock_kmalloc(sk, len, GFP_KERNEL);
  556. if (!ctx)
  557. return -ENOMEM;
  558. memset(ctx, 0, len);
  559. ctx->iv = sock_kmalloc(sk, ivlen, GFP_KERNEL);
  560. if (!ctx->iv) {
  561. sock_kfree_s(sk, ctx, len);
  562. return -ENOMEM;
  563. }
  564. memset(ctx->iv, 0, ivlen);
  565. ctx->len = len;
  566. ctx->used = 0;
  567. ctx->more = 0;
  568. ctx->merge = 0;
  569. ctx->enc = 0;
  570. ctx->tsgl.cur = 0;
  571. ctx->aead_assoclen = 0;
  572. af_alg_init_completion(&ctx->completion);
  573. sg_init_table(ctx->tsgl.sg, ALG_MAX_PAGES);
  574. ask->private = ctx;
  575. aead_request_set_tfm(&ctx->aead_req, aead);
  576. aead_request_set_callback(&ctx->aead_req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  577. af_alg_complete, &ctx->completion);
  578. sk->sk_destruct = aead_sock_destruct;
  579. return 0;
  580. }
  581. static int aead_accept_parent(void *private, struct sock *sk)
  582. {
  583. struct aead_tfm *tfm = private;
  584. if (!tfm->has_key)
  585. return -ENOKEY;
  586. return aead_accept_parent_nokey(private, sk);
  587. }
  588. static const struct af_alg_type algif_type_aead = {
  589. .bind = aead_bind,
  590. .release = aead_release,
  591. .setkey = aead_setkey,
  592. .setauthsize = aead_setauthsize,
  593. .accept = aead_accept_parent,
  594. .accept_nokey = aead_accept_parent_nokey,
  595. .ops = &algif_aead_ops,
  596. .ops_nokey = &algif_aead_ops_nokey,
  597. .name = "aead",
  598. .owner = THIS_MODULE
  599. };
  600. static int __init algif_aead_init(void)
  601. {
  602. return af_alg_register_type(&algif_type_aead);
  603. }
  604. static void __exit algif_aead_exit(void)
  605. {
  606. int err = af_alg_unregister_type(&algif_type_aead);
  607. BUG_ON(err);
  608. }
  609. module_init(algif_aead_init);
  610. module_exit(algif_aead_exit);
  611. MODULE_LICENSE("GPL");
  612. MODULE_AUTHOR("Stephan Mueller <smueller@chronox.de>");
  613. MODULE_DESCRIPTION("AEAD kernel crypto API user space interface");