Lines Matching refs:req
42 struct ahash_request req; /* must be last member */
48 struct skcipher_request req; /* must be last member */
70 static inline void async_done_continue(struct aead_request *req, int err,
74 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
77 err = cont(req);
81 aead_request_complete(req, err);
84 static void chacha_iv(u8 *iv, struct aead_request *req, u32 icb)
86 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
91 memcpy(iv + sizeof(leicb) + ctx->saltlen, req->iv,
95 static int poly_verify_tag(struct aead_request *req)
97 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
100 scatterwalk_map_and_copy(tag, req->src,
101 req->assoclen + rctx->cryptlen,
108 static int poly_copy_tag(struct aead_request *req)
110 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
112 scatterwalk_map_and_copy(rctx->tag, req->dst,
113 req->assoclen + rctx->cryptlen,
123 static int chacha_decrypt(struct aead_request *req)
125 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
126 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
134 chacha_iv(creq->iv, req, 1);
136 src = scatterwalk_ffwd(rctx->src, req->src, req->assoclen);
138 if (req->src != req->dst)
139 dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen);
141 skcipher_request_set_callback(&creq->req, rctx->flags,
142 chacha_decrypt_done, req);
143 skcipher_request_set_tfm(&creq->req, ctx->chacha);
144 skcipher_request_set_crypt(&creq->req, src, dst,
146 err = crypto_skcipher_decrypt(&creq->req);
151 return poly_verify_tag(req);
154 static int poly_tail_continue(struct aead_request *req)
156 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
158 if (rctx->cryptlen == req->cryptlen) /* encrypting */
159 return poly_copy_tag(req);
161 return chacha_decrypt(req);
169 static int poly_tail(struct aead_request *req)
171 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
173 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
181 ahash_request_set_callback(&preq->req, rctx->flags,
182 poly_tail_done, req);
183 ahash_request_set_tfm(&preq->req, ctx->poly);
184 ahash_request_set_crypt(&preq->req, preq->src,
187 err = crypto_ahash_finup(&preq->req);
191 return poly_tail_continue(req);
199 static int poly_cipherpad(struct aead_request *req)
201 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
202 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
211 ahash_request_set_callback(&preq->req, rctx->flags,
212 poly_cipherpad_done, req);
213 ahash_request_set_tfm(&preq->req, ctx->poly);
214 ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen);
216 err = crypto_ahash_update(&preq->req);
220 return poly_tail(req);
228 static int poly_cipher(struct aead_request *req)
230 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
231 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
233 struct scatterlist *crypt = req->src;
236 if (rctx->cryptlen == req->cryptlen) /* encrypting */
237 crypt = req->dst;
239 crypt = scatterwalk_ffwd(rctx->src, crypt, req->assoclen);
241 ahash_request_set_callback(&preq->req, rctx->flags,
242 poly_cipher_done, req);
243 ahash_request_set_tfm(&preq->req, ctx->poly);
244 ahash_request_set_crypt(&preq->req, crypt, NULL, rctx->cryptlen);
246 err = crypto_ahash_update(&preq->req);
250 return poly_cipherpad(req);
258 static int poly_adpad(struct aead_request *req)
260 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
261 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
270 ahash_request_set_callback(&preq->req, rctx->flags,
271 poly_adpad_done, req);
272 ahash_request_set_tfm(&preq->req, ctx->poly);
273 ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen);
275 err = crypto_ahash_update(&preq->req);
279 return poly_cipher(req);
287 static int poly_ad(struct aead_request *req)
289 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
290 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
294 ahash_request_set_callback(&preq->req, rctx->flags,
295 poly_ad_done, req);
296 ahash_request_set_tfm(&preq->req, ctx->poly);
297 ahash_request_set_crypt(&preq->req, req->src, NULL, rctx->assoclen);
299 err = crypto_ahash_update(&preq->req);
303 return poly_adpad(req);
311 static int poly_setkey(struct aead_request *req)
313 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
314 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
320 ahash_request_set_callback(&preq->req, rctx->flags,
321 poly_setkey_done, req);
322 ahash_request_set_tfm(&preq->req, ctx->poly);
323 ahash_request_set_crypt(&preq->req, preq->src, NULL, sizeof(rctx->key));
325 err = crypto_ahash_update(&preq->req);
329 return poly_ad(req);
337 static int poly_init(struct aead_request *req)
339 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
340 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
344 ahash_request_set_callback(&preq->req, rctx->flags,
345 poly_init_done, req);
346 ahash_request_set_tfm(&preq->req, ctx->poly);
348 err = crypto_ahash_init(&preq->req);
352 return poly_setkey(req);
360 static int poly_genkey(struct aead_request *req)
362 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
364 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
368 rctx->assoclen = req->assoclen;
379 chacha_iv(creq->iv, req, 0);
381 skcipher_request_set_callback(&creq->req, rctx->flags,
382 poly_genkey_done, req);
383 skcipher_request_set_tfm(&creq->req, ctx->chacha);
384 skcipher_request_set_crypt(&creq->req, creq->src, creq->src,
387 err = crypto_skcipher_decrypt(&creq->req);
391 return poly_init(req);
399 static int chacha_encrypt(struct aead_request *req)
401 struct chachapoly_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
402 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
407 if (req->cryptlen == 0)
410 chacha_iv(creq->iv, req, 1);
412 src = scatterwalk_ffwd(rctx->src, req->src, req->assoclen);
414 if (req->src != req->dst)
415 dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen);
417 skcipher_request_set_callback(&creq->req, rctx->flags,
418 chacha_encrypt_done, req);
419 skcipher_request_set_tfm(&creq->req, ctx->chacha);
420 skcipher_request_set_crypt(&creq->req, src, dst,
421 req->cryptlen, creq->iv);
422 err = crypto_skcipher_encrypt(&creq->req);
427 return poly_genkey(req);
430 static int chachapoly_encrypt(struct aead_request *req)
432 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
434 rctx->cryptlen = req->cryptlen;
435 rctx->flags = aead_request_flags(req);
449 return chacha_encrypt(req);
452 static int chachapoly_decrypt(struct aead_request *req)
454 struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
456 rctx->cryptlen = req->cryptlen - POLY1305_DIGEST_SIZE;
457 rctx->flags = aead_request_flags(req);
471 return poly_genkey(req);
528 max(offsetof(struct chacha_req, req) +
531 offsetof(struct poly_req, req) +