Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1636901
| From | Gilad Ben-Yossef <gilad@benyossef.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [RFC 03/10] crypto: move drbg to generic async completion |
| Date | 2017-05-06 15:10 +0200 |
| Message-ID | <tE7Dc-8v0-9@gated-at.bofh.it> (permalink) |
| References | <tE7Dc-8v0-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
DRBG is starting an async. crypto op and waiting for it complete.
Move it over to generic code doing the same.
As part of the move the wait for op completion lost its
_interruptible property. However, since each invocation is
supposed to be short and since no other user in the kernel
does the same I believe this is acceptable.
In similar fashion the code now passes CRYPTO_TFM_REQ_MAY_SLEEP
flag indicating crypto request memory allocation may use GFP_KERNEL
which should be perfectly fine as the code is obviously sleeping
for the completion of the request any way.
Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
---
crypto/drbg.c | 35 ++++++++---------------------------
include/crypto/drbg.h | 3 +--
2 files changed, 9 insertions(+), 29 deletions(-)
diff --git a/crypto/drbg.c b/crypto/drbg.c
index fa749f4..101d9f0 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -1651,16 +1651,6 @@ static int drbg_fini_sym_kernel(struct drbg_state *drbg)
return 0;
}
-static void drbg_skcipher_cb(struct crypto_async_request *req, int error)
-{
- struct drbg_state *drbg = req->data;
-
- if (error == -EINPROGRESS)
- return;
- drbg->ctr_async_err = error;
- complete(&drbg->ctr_completion);
-}
-
static int drbg_init_sym_kernel(struct drbg_state *drbg)
{
struct crypto_cipher *tfm;
@@ -1699,8 +1689,9 @@ static int drbg_init_sym_kernel(struct drbg_state *drbg)
return -ENOMEM;
}
drbg->ctr_req = req;
- skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
- drbg_skcipher_cb, drbg);
+ skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
+ CRYPTO_TFM_REQ_MAY_SLEEP,
+ crypto_req_done, &drbg->ctr_wait);
alignmask = crypto_skcipher_alignmask(sk_tfm);
drbg->ctr_null_value_buf = kzalloc(DRBG_CTR_NULL_LEN + alignmask,
@@ -1761,22 +1752,12 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,
/* Output buffer may not be valid for SGL, use scratchpad */
skcipher_request_set_crypt(drbg->ctr_req, &sg_in, &sg_out,
cryptlen, drbg->V);
- ret = crypto_skcipher_encrypt(drbg->ctr_req);
- switch (ret) {
- case 0:
- break;
- case -EINPROGRESS:
- case -EBUSY:
- ret = wait_for_completion_interruptible(
- &drbg->ctr_completion);
- if (!ret && !drbg->ctr_async_err) {
- reinit_completion(&drbg->ctr_completion);
- break;
- }
- default:
+ ret = crypto_wait_req(crypto_skcipher_encrypt(drbg->ctr_req),
+ &drbg->ctr_wait);
+ if (ret)
goto out;
- }
- init_completion(&drbg->ctr_completion);
+
+ crypto_init_wait(&drbg->ctr_wait);
memcpy(outbuf, drbg->outscratchpad, cryptlen);
diff --git a/include/crypto/drbg.h b/include/crypto/drbg.h
index 22f884c..8f94110 100644
--- a/include/crypto/drbg.h
+++ b/include/crypto/drbg.h
@@ -126,8 +126,7 @@ struct drbg_state {
__u8 *ctr_null_value; /* CTR mode aligned zero buf */
__u8 *outscratchpadbuf; /* CTR mode output scratchpad */
__u8 *outscratchpad; /* CTR mode aligned outbuf */
- struct completion ctr_completion; /* CTR mode async handler */
- int ctr_async_err; /* CTR mode async error */
+ struct crypto_wait ctr_wait; /* CTR mode async wait obj */
bool seeded; /* DRBG fully seeded? */
bool pr; /* Prediction resistance enabled? */
--
2.1.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[RFC 00/10] introduce crypto wait for async op function Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
[RFC 10/10] crypto: adapt api sample to use async. op wait Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
[RFC 03/10] crypto: move drbg to generic async completion Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
[RFC 07/10] fscrypt: move to generic async completion Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
Re: [RFC 07/10] fscrypt: move to generic async completion Eric Biggers <ebiggers3@gmail.com> - 2017-05-11 06:10 +0200
[RFC 05/10] crypto: move testmgr to generic async completion Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
[RFC 09/10] ima: move to generic async completion Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
Re: [RFC 09/10] ima: move to generic async completion Mimi Zohar <zohar@linux.vnet.ibm.com> - 2017-05-10 23:30 +0200
[RFC 02/10] crypto: move pub key to generic async completion Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
[RFC 06/10] dm: move dm-verity to generic async completion Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
[RFC 08/10] cifs: move to generic async completion Gilad Ben-Yossef <gilad@benyossef.com> - 2017-05-06 15:10 +0200
Re: [RFC 08/10] cifs: move to generic async completion Pavel Shilovsky <pshilovsky@samba.org> - 2017-05-08 23:00 +0200
csiph-web