Skip to content

Commit c9aa55e

Browse files
committed
n2_crypto: Plumb fallback ahash requests properly.
Do this by putting the async fallback request at the end of an n2 specific ahash request context, then properly adjusting the request private size in our ahash ->cra_init(). We also need to put the writable state bits into the n2 request private instead of the n2 cra_ctx. With help from Herbert Xu. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 527b952 commit c9aa55e

1 file changed

Lines changed: 48 additions & 47 deletions

File tree

‎drivers/crypto/n2_core.c‎

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,10 @@ static void n2_base_ctx_init(struct n2_base_ctx *ctx)
251251
struct n2_hash_ctx {
252252
struct n2_base_ctx base;
253253

254-
struct crypto_ahash *fallback;
254+
struct crypto_ahash *fallback_tfm;
255+
};
255256

256-
/* These next three members must match the layout created by
257-
* crypto_init_shash_ops_async. This allows us to properly
258-
* plumb requests we can't do in hardware down to the fallback
259-
* operation, providing all of the data structures and layouts
260-
* expected by those paths.
261-
*/
262-
struct ahash_request fallback_req;
263-
struct shash_desc fallback_desc;
257+
struct n2_hash_req_ctx {
264258
union {
265259
struct md5_state md5;
266260
struct sha1_state sha1;
@@ -269,56 +263,62 @@ struct n2_hash_ctx {
269263

270264
unsigned char hash_key[64];
271265
unsigned char keyed_zero_hash[32];
266+
267+
struct ahash_request fallback_req;
272268
};
273269

274270
static int n2_hash_async_init(struct ahash_request *req)
275271
{
272+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
276273
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
277274
struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
278275

279-
ctx->fallback_req.base.tfm = crypto_ahash_tfm(ctx->fallback);
280-
ctx->fallback_req.base.flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
276+
ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback_tfm);
277+
rctx->fallback_req.base.flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
281278

282-
return crypto_ahash_init(&ctx->fallback_req);
279+
return crypto_ahash_init(&rctx->fallback_req);
283280
}
284281

285282
static int n2_hash_async_update(struct ahash_request *req)
286283
{
284+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
287285
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
288286
struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
289287

290-
ctx->fallback_req.base.tfm = crypto_ahash_tfm(ctx->fallback);
291-
ctx->fallback_req.base.flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
292-
ctx->fallback_req.nbytes = req->nbytes;
293-
ctx->fallback_req.src = req->src;
288+
ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback_tfm);
289+
rctx->fallback_req.base.flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
290+
rctx->fallback_req.nbytes = req->nbytes;
291+
rctx->fallback_req.src = req->src;
294292

295-
return crypto_ahash_update(&ctx->fallback_req);
293+
return crypto_ahash_update(&rctx->fallback_req);
296294
}
297295

298296
static int n2_hash_async_final(struct ahash_request *req)
299297
{
298+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
300299
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
301300
struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
302301

303-
ctx->fallback_req.base.tfm = crypto_ahash_tfm(ctx->fallback);
304-
ctx->fallback_req.base.flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
305-
ctx->fallback_req.result = req->result;
302+
ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback_tfm);
303+
rctx->fallback_req.base.flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
304+
rctx->fallback_req.result = req->result;
306305

307-
return crypto_ahash_final(&ctx->fallback_req);
306+
return crypto_ahash_final(&rctx->fallback_req);
308307
}
309308

310309
static int n2_hash_async_finup(struct ahash_request *req)
311310
{
311+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
312312
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
313313
struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
314314

315-
ctx->fallback_req.base.tfm = crypto_ahash_tfm(ctx->fallback);
316-
ctx->fallback_req.base.flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
317-
ctx->fallback_req.nbytes = req->nbytes;
318-
ctx->fallback_req.src = req->src;
319-
ctx->fallback_req.result = req->result;
315+
ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback_tfm);
316+
rctx->fallback_req.base.flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
317+
rctx->fallback_req.nbytes = req->nbytes;
318+
rctx->fallback_req.src = req->src;
319+
rctx->fallback_req.result = req->result;
320320

321-
return crypto_ahash_finup(&ctx->fallback_req);
321+
return crypto_ahash_finup(&rctx->fallback_req);
322322
}
323323

324324
static int n2_hash_cra_init(struct crypto_tfm *tfm)
@@ -338,7 +338,10 @@ static int n2_hash_cra_init(struct crypto_tfm *tfm)
338338
goto out;
339339
}
340340

341-
ctx->fallback = fallback_tfm;
341+
crypto_ahash_set_reqsize(ahash, (sizeof(struct n2_hash_req_ctx) +
342+
crypto_ahash_reqsize(fallback_tfm)));
343+
344+
ctx->fallback_tfm = fallback_tfm;
342345
return 0;
343346

344347
out:
@@ -350,7 +353,7 @@ static void n2_hash_cra_exit(struct crypto_tfm *tfm)
350353
struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
351354
struct n2_hash_ctx *ctx = crypto_ahash_ctx(ahash);
352355

353-
crypto_free_ahash(ctx->fallback);
356+
crypto_free_ahash(ctx->fallback_tfm);
354357
}
355358

356359
static unsigned long wait_for_tail(struct spu_queue *qp)
@@ -399,14 +402,16 @@ static int n2_hash_async_digest(struct ahash_request *req,
399402
* exceed 2^16.
400403
*/
401404
if (unlikely(req->nbytes > (1 << 16))) {
402-
ctx->fallback_req.base.tfm = crypto_ahash_tfm(ctx->fallback);
403-
ctx->fallback_req.base.flags =
405+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
406+
407+
ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback_tfm);
408+
rctx->fallback_req.base.flags =
404409
req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
405-
ctx->fallback_req.nbytes = req->nbytes;
406-
ctx->fallback_req.src = req->src;
407-
ctx->fallback_req.result = req->result;
410+
rctx->fallback_req.nbytes = req->nbytes;
411+
rctx->fallback_req.src = req->src;
412+
rctx->fallback_req.result = req->result;
408413

409-
return crypto_ahash_digest(&ctx->fallback_req);
414+
return crypto_ahash_digest(&rctx->fallback_req);
410415
}
411416

412417
n2_base_ctx_init(&ctx->base);
@@ -472,9 +477,8 @@ static int n2_hash_async_digest(struct ahash_request *req,
472477

473478
static int n2_md5_async_digest(struct ahash_request *req)
474479
{
475-
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
476-
struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
477-
struct md5_state *m = &ctx->u.md5;
480+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
481+
struct md5_state *m = &rctx->u.md5;
478482

479483
if (unlikely(req->nbytes == 0)) {
480484
static const char md5_zero[MD5_DIGEST_SIZE] = {
@@ -497,9 +501,8 @@ static int n2_md5_async_digest(struct ahash_request *req)
497501

498502
static int n2_sha1_async_digest(struct ahash_request *req)
499503
{
500-
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
501-
struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
502-
struct sha1_state *s = &ctx->u.sha1;
504+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
505+
struct sha1_state *s = &rctx->u.sha1;
503506

504507
if (unlikely(req->nbytes == 0)) {
505508
static const char sha1_zero[SHA1_DIGEST_SIZE] = {
@@ -524,9 +527,8 @@ static int n2_sha1_async_digest(struct ahash_request *req)
524527

525528
static int n2_sha256_async_digest(struct ahash_request *req)
526529
{
527-
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
528-
struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
529-
struct sha256_state *s = &ctx->u.sha256;
530+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
531+
struct sha256_state *s = &rctx->u.sha256;
530532

531533
if (req->nbytes == 0) {
532534
static const char sha256_zero[SHA256_DIGEST_SIZE] = {
@@ -555,9 +557,8 @@ static int n2_sha256_async_digest(struct ahash_request *req)
555557

556558
static int n2_sha224_async_digest(struct ahash_request *req)
557559
{
558-
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
559-
struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
560-
struct sha256_state *s = &ctx->u.sha256;
560+
struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
561+
struct sha256_state *s = &rctx->u.sha256;
561562

562563
if (req->nbytes == 0) {
563564
static const char sha224_zero[SHA224_DIGEST_SIZE] = {

0 commit comments

Comments
 (0)