diff options
-rw-r--r-- | crypto/chacha20poly1305.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/crypto/chacha20poly1305.c b/crypto/chacha20poly1305.c index e38a2d61819a..acbbf010222e 100644 --- a/crypto/chacha20poly1305.c +++ b/crypto/chacha20poly1305.c | |||
@@ -65,6 +65,8 @@ struct chachapoly_req_ctx { | |||
65 | unsigned int cryptlen; | 65 | unsigned int cryptlen; |
66 | /* Actual AD, excluding IV */ | 66 | /* Actual AD, excluding IV */ |
67 | unsigned int assoclen; | 67 | unsigned int assoclen; |
68 | /* request flags, with MAY_SLEEP cleared if needed */ | ||
69 | u32 flags; | ||
68 | union { | 70 | union { |
69 | struct poly_req poly; | 71 | struct poly_req poly; |
70 | struct chacha_req chacha; | 72 | struct chacha_req chacha; |
@@ -74,8 +76,12 @@ struct chachapoly_req_ctx { | |||
74 | static inline void async_done_continue(struct aead_request *req, int err, | 76 | static inline void async_done_continue(struct aead_request *req, int err, |
75 | int (*cont)(struct aead_request *)) | 77 | int (*cont)(struct aead_request *)) |
76 | { | 78 | { |
77 | if (!err) | 79 | if (!err) { |
80 | struct chachapoly_req_ctx *rctx = aead_request_ctx(req); | ||
81 | |||
82 | rctx->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP; | ||
78 | err = cont(req); | 83 | err = cont(req); |
84 | } | ||
79 | 85 | ||
80 | if (err != -EINPROGRESS && err != -EBUSY) | 86 | if (err != -EINPROGRESS && err != -EBUSY) |
81 | aead_request_complete(req, err); | 87 | aead_request_complete(req, err); |
@@ -142,7 +148,7 @@ static int chacha_decrypt(struct aead_request *req) | |||
142 | dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen); | 148 | dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen); |
143 | } | 149 | } |
144 | 150 | ||
145 | skcipher_request_set_callback(&creq->req, aead_request_flags(req), | 151 | skcipher_request_set_callback(&creq->req, rctx->flags, |
146 | chacha_decrypt_done, req); | 152 | chacha_decrypt_done, req); |
147 | skcipher_request_set_tfm(&creq->req, ctx->chacha); | 153 | skcipher_request_set_tfm(&creq->req, ctx->chacha); |
148 | skcipher_request_set_crypt(&creq->req, src, dst, | 154 | skcipher_request_set_crypt(&creq->req, src, dst, |
@@ -186,7 +192,7 @@ static int poly_tail(struct aead_request *req) | |||
186 | memcpy(&preq->tail.cryptlen, &len, sizeof(len)); | 192 | memcpy(&preq->tail.cryptlen, &len, sizeof(len)); |
187 | sg_set_buf(preq->src, &preq->tail, sizeof(preq->tail)); | 193 | sg_set_buf(preq->src, &preq->tail, sizeof(preq->tail)); |
188 | 194 | ||
189 | ahash_request_set_callback(&preq->req, aead_request_flags(req), | 195 | ahash_request_set_callback(&preq->req, rctx->flags, |
190 | poly_tail_done, req); | 196 | poly_tail_done, req); |
191 | ahash_request_set_tfm(&preq->req, ctx->poly); | 197 | ahash_request_set_tfm(&preq->req, ctx->poly); |
192 | ahash_request_set_crypt(&preq->req, preq->src, | 198 | ahash_request_set_crypt(&preq->req, preq->src, |
@@ -217,7 +223,7 @@ static int poly_cipherpad(struct aead_request *req) | |||
217 | sg_init_table(preq->src, 1); | 223 | sg_init_table(preq->src, 1); |
218 | sg_set_buf(preq->src, &preq->pad, padlen); | 224 | sg_set_buf(preq->src, &preq->pad, padlen); |
219 | 225 | ||
220 | ahash_request_set_callback(&preq->req, aead_request_flags(req), | 226 | ahash_request_set_callback(&preq->req, rctx->flags, |
221 | poly_cipherpad_done, req); | 227 | poly_cipherpad_done, req); |
222 | ahash_request_set_tfm(&preq->req, ctx->poly); | 228 | ahash_request_set_tfm(&preq->req, ctx->poly); |
223 | ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen); | 229 | ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen); |
@@ -248,7 +254,7 @@ static int poly_cipher(struct aead_request *req) | |||
248 | sg_init_table(rctx->src, 2); | 254 | sg_init_table(rctx->src, 2); |
249 | crypt = scatterwalk_ffwd(rctx->src, crypt, req->assoclen); | 255 | crypt = scatterwalk_ffwd(rctx->src, crypt, req->assoclen); |
250 | 256 | ||
251 | ahash_request_set_callback(&preq->req, aead_request_flags(req), | 257 | ahash_request_set_callback(&preq->req, rctx->flags, |
252 | poly_cipher_done, req); | 258 | poly_cipher_done, req); |
253 | ahash_request_set_tfm(&preq->req, ctx->poly); | 259 | ahash_request_set_tfm(&preq->req, ctx->poly); |
254 | ahash_request_set_crypt(&preq->req, crypt, NULL, rctx->cryptlen); | 260 | ahash_request_set_crypt(&preq->req, crypt, NULL, rctx->cryptlen); |
@@ -278,7 +284,7 @@ static int poly_adpad(struct aead_request *req) | |||
278 | sg_init_table(preq->src, 1); | 284 | sg_init_table(preq->src, 1); |
279 | sg_set_buf(preq->src, preq->pad, padlen); | 285 | sg_set_buf(preq->src, preq->pad, padlen); |
280 | 286 | ||
281 | ahash_request_set_callback(&preq->req, aead_request_flags(req), | 287 | ahash_request_set_callback(&preq->req, rctx->flags, |
282 | poly_adpad_done, req); | 288 | poly_adpad_done, req); |
283 | ahash_request_set_tfm(&preq->req, ctx->poly); | 289 | ahash_request_set_tfm(&preq->req, ctx->poly); |
284 | ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen); | 290 | ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen); |
@@ -302,7 +308,7 @@ static int poly_ad(struct aead_request *req) | |||
302 | struct poly_req *preq = &rctx->u.poly; | 308 | struct poly_req *preq = &rctx->u.poly; |
303 | int err; | 309 | int err; |
304 | 310 | ||
305 | ahash_request_set_callback(&preq->req, aead_request_flags(req), | 311 | ahash_request_set_callback(&preq->req, rctx->flags, |
306 | poly_ad_done, req); | 312 | poly_ad_done, req); |
307 | ahash_request_set_tfm(&preq->req, ctx->poly); | 313 | ahash_request_set_tfm(&preq->req, ctx->poly); |
308 | ahash_request_set_crypt(&preq->req, req->src, NULL, rctx->assoclen); | 314 | ahash_request_set_crypt(&preq->req, req->src, NULL, rctx->assoclen); |
@@ -329,7 +335,7 @@ static int poly_setkey(struct aead_request *req) | |||
329 | sg_init_table(preq->src, 1); | 335 | sg_init_table(preq->src, 1); |
330 | sg_set_buf(preq->src, rctx->key, sizeof(rctx->key)); | 336 | sg_set_buf(preq->src, rctx->key, sizeof(rctx->key)); |
331 | 337 | ||
332 | ahash_request_set_callback(&preq->req, aead_request_flags(req), | 338 | ahash_request_set_callback(&preq->req, rctx->flags, |
333 | poly_setkey_done, req); | 339 | poly_setkey_done, req); |
334 | ahash_request_set_tfm(&preq->req, ctx->poly); | 340 | ahash_request_set_tfm(&preq->req, ctx->poly); |
335 | ahash_request_set_crypt(&preq->req, preq->src, NULL, sizeof(rctx->key)); | 341 | ahash_request_set_crypt(&preq->req, preq->src, NULL, sizeof(rctx->key)); |
@@ -353,7 +359,7 @@ static int poly_init(struct aead_request *req) | |||
353 | struct poly_req *preq = &rctx->u.poly; | 359 | struct poly_req *preq = &rctx->u.poly; |
354 | int err; | 360 | int err; |
355 | 361 | ||
356 | ahash_request_set_callback(&preq->req, aead_request_flags(req), | 362 | ahash_request_set_callback(&preq->req, rctx->flags, |
357 | poly_init_done, req); | 363 | poly_init_done, req); |
358 | ahash_request_set_tfm(&preq->req, ctx->poly); | 364 | ahash_request_set_tfm(&preq->req, ctx->poly); |
359 | 365 | ||
@@ -391,7 +397,7 @@ static int poly_genkey(struct aead_request *req) | |||
391 | 397 | ||
392 | chacha_iv(creq->iv, req, 0); | 398 | chacha_iv(creq->iv, req, 0); |
393 | 399 | ||
394 | skcipher_request_set_callback(&creq->req, aead_request_flags(req), | 400 | skcipher_request_set_callback(&creq->req, rctx->flags, |
395 | poly_genkey_done, req); | 401 | poly_genkey_done, req); |
396 | skcipher_request_set_tfm(&creq->req, ctx->chacha); | 402 | skcipher_request_set_tfm(&creq->req, ctx->chacha); |
397 | skcipher_request_set_crypt(&creq->req, creq->src, creq->src, | 403 | skcipher_request_set_crypt(&creq->req, creq->src, creq->src, |
@@ -431,7 +437,7 @@ static int chacha_encrypt(struct aead_request *req) | |||
431 | dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen); | 437 | dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen); |
432 | } | 438 | } |
433 | 439 | ||
434 | skcipher_request_set_callback(&creq->req, aead_request_flags(req), | 440 | skcipher_request_set_callback(&creq->req, rctx->flags, |
435 | chacha_encrypt_done, req); | 441 | chacha_encrypt_done, req); |
436 | skcipher_request_set_tfm(&creq->req, ctx->chacha); | 442 | skcipher_request_set_tfm(&creq->req, ctx->chacha); |
437 | skcipher_request_set_crypt(&creq->req, src, dst, | 443 | skcipher_request_set_crypt(&creq->req, src, dst, |
@@ -449,6 +455,7 @@ static int chachapoly_encrypt(struct aead_request *req) | |||
449 | struct chachapoly_req_ctx *rctx = aead_request_ctx(req); | 455 | struct chachapoly_req_ctx *rctx = aead_request_ctx(req); |
450 | 456 | ||
451 | rctx->cryptlen = req->cryptlen; | 457 | rctx->cryptlen = req->cryptlen; |
458 | rctx->flags = aead_request_flags(req); | ||
452 | 459 | ||
453 | /* encrypt call chain: | 460 | /* encrypt call chain: |
454 | * - chacha_encrypt/done() | 461 | * - chacha_encrypt/done() |
@@ -470,6 +477,7 @@ static int chachapoly_decrypt(struct aead_request *req) | |||
470 | struct chachapoly_req_ctx *rctx = aead_request_ctx(req); | 477 | struct chachapoly_req_ctx *rctx = aead_request_ctx(req); |
471 | 478 | ||
472 | rctx->cryptlen = req->cryptlen - POLY1305_DIGEST_SIZE; | 479 | rctx->cryptlen = req->cryptlen - POLY1305_DIGEST_SIZE; |
480 | rctx->flags = aead_request_flags(req); | ||
473 | 481 | ||
474 | /* decrypt call chain: | 482 | /* decrypt call chain: |
475 | * - poly_genkey/done() | 483 | * - poly_genkey/done() |