hc
2024-02-20 e636c8d336489bf3eed5878299e6cc045bbad077
kernel/drivers/crypto/amcc/crypto4xx_alg.c
....@@ -1,18 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /**
23 * AMCC SoC PPC4xx Crypto Driver
34 *
45 * Copyright (c) 2008 Applied Micro Circuits Corporation.
56 * All rights reserved. James Hsiao <jhsiao@amcc.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
167 *
178 * This file implements the Linux crypto algorithms.
189 */
....@@ -64,7 +55,7 @@
6455 sa->sa_command_1.w = 0;
6556 sa->sa_command_1.bf.crypto_mode31 = (cm & 4) >> 2;
6657 sa->sa_command_1.bf.crypto_mode9_8 = cm & 3;
67
- sa->sa_command_1.bf.feedback_mode = cfb,
58
+ sa->sa_command_1.bf.feedback_mode = cfb;
6859 sa->sa_command_1.bf.sa_rev = 1;
6960 sa->sa_command_1.bf.hmac_muting = hmac_mc;
7061 sa->sa_command_1.bf.extended_seq_num = esn;
....@@ -137,12 +128,9 @@
137128 struct dynamic_sa_ctl *sa;
138129 int rc;
139130
140
- if (keylen != AES_KEYSIZE_256 &&
141
- keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_128) {
142
- crypto_skcipher_set_flags(cipher,
143
- CRYPTO_TFM_RES_BAD_KEY_LEN);
131
+ if (keylen != AES_KEYSIZE_256 && keylen != AES_KEYSIZE_192 &&
132
+ keylen != AES_KEYSIZE_128)
144133 return -EINVAL;
145
- }
146134
147135 /* Create SA */
148136 if (ctx->sa_in || ctx->sa_out)
....@@ -278,10 +266,10 @@
278266 * overlow.
279267 */
280268 if (counter + nblks < counter) {
281
- struct skcipher_request *subreq = skcipher_request_ctx(req);
269
+ SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->sw_cipher.cipher);
282270 int ret;
283271
284
- skcipher_request_set_tfm(subreq, ctx->sw_cipher.cipher);
272
+ skcipher_request_set_sync_tfm(subreq, ctx->sw_cipher.cipher);
285273 skcipher_request_set_callback(subreq, req->base.flags,
286274 NULL, NULL);
287275 skcipher_request_set_crypt(subreq, req->src, req->dst,
....@@ -301,19 +289,11 @@
301289 const u8 *key,
302290 unsigned int keylen)
303291 {
304
- int rc;
305
-
306
- crypto_skcipher_clear_flags(ctx->sw_cipher.cipher,
292
+ crypto_sync_skcipher_clear_flags(ctx->sw_cipher.cipher,
307293 CRYPTO_TFM_REQ_MASK);
308
- crypto_skcipher_set_flags(ctx->sw_cipher.cipher,
294
+ crypto_sync_skcipher_set_flags(ctx->sw_cipher.cipher,
309295 crypto_skcipher_get_flags(cipher) & CRYPTO_TFM_REQ_MASK);
310
- rc = crypto_skcipher_setkey(ctx->sw_cipher.cipher, key, keylen);
311
- crypto_skcipher_clear_flags(cipher, CRYPTO_TFM_RES_MASK);
312
- crypto_skcipher_set_flags(cipher,
313
- crypto_skcipher_get_flags(ctx->sw_cipher.cipher) &
314
- CRYPTO_TFM_RES_MASK);
315
-
316
- return rc;
296
+ return crypto_sync_skcipher_setkey(ctx->sw_cipher.cipher, key, keylen);
317297 }
318298
319299 int crypto4xx_setkey_aes_ctr(struct crypto_skcipher *cipher,
....@@ -388,18 +368,10 @@
388368 const u8 *key,
389369 unsigned int keylen)
390370 {
391
- int rc;
392
-
393371 crypto_aead_clear_flags(ctx->sw_cipher.aead, CRYPTO_TFM_REQ_MASK);
394372 crypto_aead_set_flags(ctx->sw_cipher.aead,
395373 crypto_aead_get_flags(cipher) & CRYPTO_TFM_REQ_MASK);
396
- rc = crypto_aead_setkey(ctx->sw_cipher.aead, key, keylen);
397
- crypto_aead_clear_flags(cipher, CRYPTO_TFM_RES_MASK);
398
- crypto_aead_set_flags(cipher,
399
- crypto_aead_get_flags(ctx->sw_cipher.aead) &
400
- CRYPTO_TFM_RES_MASK);
401
-
402
- return rc;
374
+ return crypto_aead_setkey(ctx->sw_cipher.aead, key, keylen);
403375 }
404376
405377 /**
....@@ -536,29 +508,20 @@
536508 static int crypto4xx_compute_gcm_hash_key_sw(__le32 *hash_start, const u8 *key,
537509 unsigned int keylen)
538510 {
539
- struct crypto_cipher *aes_tfm = NULL;
511
+ struct crypto_aes_ctx ctx;
540512 uint8_t src[16] = { 0 };
541
- int rc = 0;
513
+ int rc;
542514
543
- aes_tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC |
544
- CRYPTO_ALG_NEED_FALLBACK);
545
- if (IS_ERR(aes_tfm)) {
546
- rc = PTR_ERR(aes_tfm);
547
- pr_warn("could not load aes cipher driver: %d\n", rc);
515
+ rc = aes_expandkey(&ctx, key, keylen);
516
+ if (rc) {
517
+ pr_err("aes_expandkey() failed: %d\n", rc);
548518 return rc;
549519 }
550520
551
- rc = crypto_cipher_setkey(aes_tfm, key, keylen);
552
- if (rc) {
553
- pr_err("setkey() failed: %d\n", rc);
554
- goto out;
555
- }
556
-
557
- crypto_cipher_encrypt_one(aes_tfm, src, src);
521
+ aes_encrypt(&ctx, src, src);
558522 crypto4xx_memcpy_to_le32(hash_start, src, 16);
559
-out:
560
- crypto_free_cipher(aes_tfm);
561
- return rc;
523
+ memzero_explicit(&ctx, sizeof(ctx));
524
+ return 0;
562525 }
563526
564527 int crypto4xx_setkey_aes_gcm(struct crypto_aead *cipher,
....@@ -569,10 +532,8 @@
569532 struct dynamic_sa_ctl *sa;
570533 int rc = 0;
571534
572
- if (crypto4xx_aes_gcm_validate_keylen(keylen) != 0) {
573
- crypto_aead_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
535
+ if (crypto4xx_aes_gcm_validate_keylen(keylen) != 0)
574536 return -EINVAL;
575
- }
576537
577538 rc = crypto4xx_aead_setup_fallback(ctx, cipher, key, keylen);
578539 if (rc)