.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License version 2 and |
---|
6 | | - * only version 2 as published by the Free Software Foundation. |
---|
7 | | - * |
---|
8 | | - * This program is distributed in the hope that it will be useful, |
---|
9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | | - * GNU General Public License for more details. |
---|
12 | 4 | */ |
---|
13 | 5 | |
---|
14 | 6 | #include <linux/device.h> |
---|
| 7 | +#include <linux/dma-mapping.h> |
---|
15 | 8 | #include <linux/interrupt.h> |
---|
16 | 9 | #include <crypto/internal/hash.h> |
---|
17 | 10 | |
---|
.. | .. |
---|
211 | 204 | |
---|
212 | 205 | static int qce_ahash_import(struct ahash_request *req, const void *in) |
---|
213 | 206 | { |
---|
214 | | - struct qce_sha_reqctx *rctx = ahash_request_ctx(req); |
---|
215 | | - unsigned long flags = rctx->flags; |
---|
216 | | - bool hmac = IS_SHA_HMAC(flags); |
---|
217 | | - int ret = -EINVAL; |
---|
| 207 | + struct qce_sha_reqctx *rctx; |
---|
| 208 | + unsigned long flags; |
---|
| 209 | + bool hmac; |
---|
| 210 | + int ret; |
---|
| 211 | + |
---|
| 212 | + ret = qce_ahash_init(req); |
---|
| 213 | + if (ret) |
---|
| 214 | + return ret; |
---|
| 215 | + |
---|
| 216 | + rctx = ahash_request_ctx(req); |
---|
| 217 | + flags = rctx->flags; |
---|
| 218 | + hmac = IS_SHA_HMAC(flags); |
---|
218 | 219 | |
---|
219 | 220 | if (IS_SHA1(flags) || IS_SHA1_HMAC(flags)) { |
---|
220 | 221 | const struct sha1_state *state = in; |
---|
.. | .. |
---|
292 | 293 | if (!sg_last) |
---|
293 | 294 | return -EINVAL; |
---|
294 | 295 | |
---|
295 | | - sg_mark_end(sg_last); |
---|
296 | | - |
---|
297 | 296 | if (rctx->buflen) { |
---|
298 | 297 | sg_init_table(rctx->sg, 2); |
---|
299 | 298 | sg_set_buf(rctx->sg, rctx->tmpbuf, rctx->buflen); |
---|
.. | .. |
---|
313 | 312 | struct qce_alg_template *tmpl = to_ahash_tmpl(req->base.tfm); |
---|
314 | 313 | struct qce_device *qce = tmpl->qce; |
---|
315 | 314 | |
---|
316 | | - if (!rctx->buflen) |
---|
| 315 | + if (!rctx->buflen) { |
---|
| 316 | + if (tmpl->hash_zero) |
---|
| 317 | + memcpy(req->result, tmpl->hash_zero, |
---|
| 318 | + tmpl->alg.ahash.halg.digestsize); |
---|
317 | 319 | return 0; |
---|
| 320 | + } |
---|
318 | 321 | |
---|
319 | 322 | rctx->last_blk = true; |
---|
320 | 323 | |
---|
.. | .. |
---|
345 | 348 | rctx->nbytes_orig = req->nbytes; |
---|
346 | 349 | rctx->first_blk = true; |
---|
347 | 350 | rctx->last_blk = true; |
---|
| 351 | + |
---|
| 352 | + if (!rctx->nbytes_orig) { |
---|
| 353 | + if (tmpl->hash_zero) |
---|
| 354 | + memcpy(req->result, tmpl->hash_zero, |
---|
| 355 | + tmpl->alg.ahash.halg.digestsize); |
---|
| 356 | + return 0; |
---|
| 357 | + } |
---|
348 | 358 | |
---|
349 | 359 | return qce->async_req_enqueue(tmpl->qce, &req->base); |
---|
350 | 360 | } |
---|
.. | .. |
---|
404 | 414 | ahash_request_set_crypt(req, &sg, ctx->authkey, keylen); |
---|
405 | 415 | |
---|
406 | 416 | ret = crypto_wait_req(crypto_ahash_digest(req), &wait); |
---|
407 | | - if (ret) |
---|
408 | | - crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
---|
409 | 417 | |
---|
410 | 418 | kfree(buf); |
---|
411 | 419 | err_free_req: |
---|
.. | .. |
---|
500 | 508 | alg->halg.digestsize = def->digestsize; |
---|
501 | 509 | alg->halg.statesize = def->statesize; |
---|
502 | 510 | |
---|
| 511 | + if (IS_SHA1(def->flags)) |
---|
| 512 | + tmpl->hash_zero = sha1_zero_message_hash; |
---|
| 513 | + else if (IS_SHA256(def->flags)) |
---|
| 514 | + tmpl->hash_zero = sha256_zero_message_hash; |
---|
| 515 | + |
---|
503 | 516 | base = &alg->halg.base; |
---|
504 | 517 | base->cra_blocksize = def->blocksize; |
---|
505 | 518 | base->cra_priority = 300; |
---|
506 | | - base->cra_flags = CRYPTO_ALG_ASYNC; |
---|
| 519 | + base->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY; |
---|
507 | 520 | base->cra_ctxsize = sizeof(struct qce_sha_ctx); |
---|
508 | 521 | base->cra_alignmask = 0; |
---|
509 | 522 | base->cra_module = THIS_MODULE; |
---|
510 | 523 | base->cra_init = qce_ahash_cra_init; |
---|
511 | | - INIT_LIST_HEAD(&base->cra_list); |
---|
512 | 524 | |
---|
513 | 525 | snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name); |
---|
514 | 526 | snprintf(base->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", |
---|