.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * AMD Cryptographic Coprocessor (CCP) SHA crypto API support |
---|
3 | 4 | * |
---|
4 | | - * Copyright (C) 2013,2017 Advanced Micro Devices, Inc. |
---|
| 5 | + * Copyright (C) 2013,2018 Advanced Micro Devices, Inc. |
---|
5 | 6 | * |
---|
6 | 7 | * Author: Tom Lendacky <thomas.lendacky@amd.com> |
---|
7 | 8 | * Author: Gary R Hook <gary.hook@amd.com> |
---|
8 | | - * |
---|
9 | | - * This program is free software; you can redistribute it and/or modify |
---|
10 | | - * it under the terms of the GNU General Public License version 2 as |
---|
11 | | - * published by the Free Software Foundation. |
---|
12 | 9 | */ |
---|
13 | 10 | |
---|
14 | 11 | #include <linux/module.h> |
---|
.. | .. |
---|
22 | 19 | #include <crypto/internal/hash.h> |
---|
23 | 20 | #include <crypto/sha.h> |
---|
24 | 21 | #include <crypto/scatterwalk.h> |
---|
| 22 | +#include <linux/string.h> |
---|
25 | 23 | |
---|
26 | 24 | #include "ccp-crypto.h" |
---|
27 | 25 | |
---|
.. | .. |
---|
275 | 273 | { |
---|
276 | 274 | struct ccp_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm)); |
---|
277 | 275 | struct crypto_shash *shash = ctx->u.sha.hmac_tfm; |
---|
278 | | - |
---|
279 | | - SHASH_DESC_ON_STACK(sdesc, shash); |
---|
280 | | - |
---|
281 | 276 | unsigned int block_size = crypto_shash_blocksize(shash); |
---|
282 | 277 | unsigned int digest_size = crypto_shash_digestsize(shash); |
---|
283 | 278 | int i, ret; |
---|
.. | .. |
---|
292 | 287 | |
---|
293 | 288 | if (key_len > block_size) { |
---|
294 | 289 | /* Must hash the input key */ |
---|
295 | | - sdesc->tfm = shash; |
---|
296 | | - sdesc->flags = crypto_ahash_get_flags(tfm) & |
---|
297 | | - CRYPTO_TFM_REQ_MAY_SLEEP; |
---|
298 | | - |
---|
299 | | - ret = crypto_shash_digest(sdesc, key, key_len, |
---|
300 | | - ctx->u.sha.key); |
---|
301 | | - if (ret) { |
---|
302 | | - crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
---|
| 290 | + ret = crypto_shash_tfm_digest(shash, key, key_len, |
---|
| 291 | + ctx->u.sha.key); |
---|
| 292 | + if (ret) |
---|
303 | 293 | return -EINVAL; |
---|
304 | | - } |
---|
305 | 294 | |
---|
306 | 295 | key_len = digest_size; |
---|
307 | 296 | } else { |
---|
.. | .. |
---|
436 | 425 | *ccp_alg = *base_alg; |
---|
437 | 426 | INIT_LIST_HEAD(&ccp_alg->entry); |
---|
438 | 427 | |
---|
439 | | - strncpy(ccp_alg->child_alg, def->name, CRYPTO_MAX_ALG_NAME); |
---|
| 428 | + strscpy(ccp_alg->child_alg, def->name, CRYPTO_MAX_ALG_NAME); |
---|
440 | 429 | |
---|
441 | 430 | alg = &ccp_alg->alg; |
---|
442 | 431 | alg->setkey = ccp_sha_setkey; |
---|
.. | .. |
---|
498 | 487 | snprintf(base->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", |
---|
499 | 488 | def->drv_name); |
---|
500 | 489 | base->cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 490 | + CRYPTO_ALG_ALLOCATES_MEMORY | |
---|
501 | 491 | CRYPTO_ALG_KERN_DRIVER_ONLY | |
---|
502 | 492 | CRYPTO_ALG_NEED_FALLBACK; |
---|
503 | 493 | base->cra_blocksize = def->block_size; |
---|