hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AMD Cryptographic Coprocessor (CCP) AES CMAC crypto API support
34 *
4
- * Copyright (C) 2013 Advanced Micro Devices, Inc.
5
+ * Copyright (C) 2013,2018 Advanced Micro Devices, Inc.
56 *
67 * Author: Tom Lendacky <thomas.lendacky@amd.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/module.h>
....@@ -264,6 +261,7 @@
264261 ccp_crypto_ahash_alg(crypto_ahash_tfm(tfm));
265262 u64 k0_hi, k0_lo, k1_hi, k1_lo, k2_hi, k2_lo;
266263 u64 rb_hi = 0x00, rb_lo = 0x87;
264
+ struct crypto_aes_ctx aes;
267265 __be64 *gk;
268266 int ret;
269267
....@@ -278,7 +276,6 @@
278276 ctx->u.aes.type = CCP_AES_TYPE_256;
279277 break;
280278 default:
281
- crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
282279 return -EINVAL;
283280 }
284281 ctx->u.aes.mode = alg->mode;
....@@ -287,14 +284,14 @@
287284 ctx->u.aes.key_len = 0;
288285
289286 /* Set the key for the AES cipher used to generate the keys */
290
- ret = crypto_cipher_setkey(ctx->u.aes.tfm_cipher, key, key_len);
287
+ ret = aes_expandkey(&aes, key, key_len);
291288 if (ret)
292289 return ret;
293290
294291 /* Encrypt a block of zeroes - use key area in context */
295292 memset(ctx->u.aes.key, 0, sizeof(ctx->u.aes.key));
296
- crypto_cipher_encrypt_one(ctx->u.aes.tfm_cipher, ctx->u.aes.key,
297
- ctx->u.aes.key);
293
+ aes_encrypt(&aes, ctx->u.aes.key, ctx->u.aes.key);
294
+ memzero_explicit(&aes, sizeof(aes));
298295
299296 /* Generate K1 and K2 */
300297 k0_hi = be64_to_cpu(*((__be64 *)ctx->u.aes.key));
....@@ -339,32 +336,13 @@
339336 {
340337 struct ccp_ctx *ctx = crypto_tfm_ctx(tfm);
341338 struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
342
- struct crypto_cipher *cipher_tfm;
343339
344340 ctx->complete = ccp_aes_cmac_complete;
345341 ctx->u.aes.key_len = 0;
346342
347343 crypto_ahash_set_reqsize(ahash, sizeof(struct ccp_aes_cmac_req_ctx));
348344
349
- cipher_tfm = crypto_alloc_cipher("aes", 0,
350
- CRYPTO_ALG_ASYNC |
351
- CRYPTO_ALG_NEED_FALLBACK);
352
- if (IS_ERR(cipher_tfm)) {
353
- pr_warn("could not load aes cipher driver\n");
354
- return PTR_ERR(cipher_tfm);
355
- }
356
- ctx->u.aes.tfm_cipher = cipher_tfm;
357
-
358345 return 0;
359
-}
360
-
361
-static void ccp_aes_cmac_cra_exit(struct crypto_tfm *tfm)
362
-{
363
- struct ccp_ctx *ctx = crypto_tfm_ctx(tfm);
364
-
365
- if (ctx->u.aes.tfm_cipher)
366
- crypto_free_cipher(ctx->u.aes.tfm_cipher);
367
- ctx->u.aes.tfm_cipher = NULL;
368346 }
369347
370348 int ccp_register_aes_cmac_algs(struct list_head *head)
....@@ -400,13 +378,13 @@
400378 snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "cmac(aes)");
401379 snprintf(base->cra_driver_name, CRYPTO_MAX_ALG_NAME, "cmac-aes-ccp");
402380 base->cra_flags = CRYPTO_ALG_ASYNC |
381
+ CRYPTO_ALG_ALLOCATES_MEMORY |
403382 CRYPTO_ALG_KERN_DRIVER_ONLY |
404383 CRYPTO_ALG_NEED_FALLBACK;
405384 base->cra_blocksize = AES_BLOCK_SIZE;
406385 base->cra_ctxsize = sizeof(struct ccp_ctx);
407386 base->cra_priority = CCP_CRA_PRIORITY;
408387 base->cra_init = ccp_aes_cmac_cra_init;
409
- base->cra_exit = ccp_aes_cmac_cra_exit;
410388 base->cra_module = THIS_MODULE;
411389
412390 ret = crypto_register_ahash(alg);