hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/crypto/ccp/ccp-crypto-sha.c
....@@ -1,14 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AMD Cryptographic Coprocessor (CCP) SHA crypto API support
34 *
4
- * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
5
+ * Copyright (C) 2013,2018 Advanced Micro Devices, Inc.
56 *
67 * Author: Tom Lendacky <thomas.lendacky@amd.com>
78 * 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.
129 */
1310
1411 #include <linux/module.h>
....@@ -22,6 +19,7 @@
2219 #include <crypto/internal/hash.h>
2320 #include <crypto/sha.h>
2421 #include <crypto/scatterwalk.h>
22
+#include <linux/string.h>
2523
2624 #include "ccp-crypto.h"
2725
....@@ -275,9 +273,6 @@
275273 {
276274 struct ccp_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm));
277275 struct crypto_shash *shash = ctx->u.sha.hmac_tfm;
278
-
279
- SHASH_DESC_ON_STACK(sdesc, shash);
280
-
281276 unsigned int block_size = crypto_shash_blocksize(shash);
282277 unsigned int digest_size = crypto_shash_digestsize(shash);
283278 int i, ret;
....@@ -292,16 +287,10 @@
292287
293288 if (key_len > block_size) {
294289 /* 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)
303293 return -EINVAL;
304
- }
305294
306295 key_len = digest_size;
307296 } else {
....@@ -436,7 +425,7 @@
436425 *ccp_alg = *base_alg;
437426 INIT_LIST_HEAD(&ccp_alg->entry);
438427
439
- strncpy(ccp_alg->child_alg, def->name, CRYPTO_MAX_ALG_NAME);
428
+ strscpy(ccp_alg->child_alg, def->name, CRYPTO_MAX_ALG_NAME);
440429
441430 alg = &ccp_alg->alg;
442431 alg->setkey = ccp_sha_setkey;
....@@ -498,6 +487,7 @@
498487 snprintf(base->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
499488 def->drv_name);
500489 base->cra_flags = CRYPTO_ALG_ASYNC |
490
+ CRYPTO_ALG_ALLOCATES_MEMORY |
501491 CRYPTO_ALG_KERN_DRIVER_ONLY |
502492 CRYPTO_ALG_NEED_FALLBACK;
503493 base->cra_blocksize = def->block_size;