hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/crypto/axis/artpec6_crypto.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for ARTPEC-6 crypto block using the kernel asynchronous crypto api.
34 *
....@@ -135,8 +136,6 @@
135136 #define regk_crypto_ext 0x00000001
136137 #define regk_crypto_hmac_sha1 0x00000007
137138 #define regk_crypto_hmac_sha256 0x00000009
138
-#define regk_crypto_hmac_sha384 0x0000000b
139
-#define regk_crypto_hmac_sha512 0x0000000d
140139 #define regk_crypto_init 0x00000000
141140 #define regk_crypto_key_128 0x00000000
142141 #define regk_crypto_key_192 0x00000001
....@@ -144,8 +143,6 @@
144143 #define regk_crypto_null 0x00000000
145144 #define regk_crypto_sha1 0x00000006
146145 #define regk_crypto_sha256 0x00000008
147
-#define regk_crypto_sha384 0x0000000a
148
-#define regk_crypto_sha512 0x0000000c
149146
150147 /* DMA descriptor structures */
151148 struct pdma_descr_ctrl {
....@@ -190,8 +187,6 @@
190187 /* Hash modes (including HMAC variants) */
191188 #define ARTPEC6_CRYPTO_HASH_SHA1 1
192189 #define ARTPEC6_CRYPTO_HASH_SHA256 2
193
-#define ARTPEC6_CRYPTO_HASH_SHA384 3
194
-#define ARTPEC6_CRYPTO_HASH_SHA512 4
195190
196191 /* Crypto modes */
197192 #define ARTPEC6_CRYPTO_CIPHER_AES_ECB 1
....@@ -292,11 +287,11 @@
292287 };
293288
294289 struct artpec6_hash_request_context {
295
- char partial_buffer[SHA512_BLOCK_SIZE];
296
- char partial_buffer_out[SHA512_BLOCK_SIZE];
297
- char key_buffer[SHA512_BLOCK_SIZE];
298
- char pad_buffer[SHA512_BLOCK_SIZE + 32];
299
- unsigned char digeststate[SHA512_DIGEST_SIZE];
290
+ char partial_buffer[SHA256_BLOCK_SIZE];
291
+ char partial_buffer_out[SHA256_BLOCK_SIZE];
292
+ char key_buffer[SHA256_BLOCK_SIZE];
293
+ char pad_buffer[SHA256_BLOCK_SIZE + 32];
294
+ unsigned char digeststate[SHA256_DIGEST_SIZE];
300295 size_t partial_bytes;
301296 u64 digcnt;
302297 u32 key_md;
....@@ -306,8 +301,8 @@
306301 };
307302
308303 struct artpec6_hash_export_state {
309
- char partial_buffer[SHA512_BLOCK_SIZE];
310
- unsigned char digeststate[SHA512_DIGEST_SIZE];
304
+ char partial_buffer[SHA256_BLOCK_SIZE];
305
+ unsigned char digeststate[SHA256_DIGEST_SIZE];
311306 size_t partial_bytes;
312307 u64 digcnt;
313308 int oper;
....@@ -315,7 +310,7 @@
315310 };
316311
317312 struct artpec6_hashalg_context {
318
- char hmac_key[SHA512_BLOCK_SIZE];
313
+ char hmac_key[SHA256_BLOCK_SIZE];
319314 size_t hmac_key_length;
320315 struct crypto_shash *child_hash;
321316 };
....@@ -331,7 +326,7 @@
331326 size_t key_length;
332327 u32 key_md;
333328 int crypto_type;
334
- struct crypto_skcipher *fallback;
329
+ struct crypto_sync_skcipher *fallback;
335330 };
336331
337332 struct artpec6_crypto_aead_hw_ctx {
....@@ -671,8 +666,8 @@
671666 * to be written.
672667 */
673668 return artpec6_crypto_dma_map_single(common,
674
- dma->stat + dma->in_cnt - 1,
675
- sizeof(dma->stat[0]),
669
+ dma->stat,
670
+ sizeof(dma->stat[0]) * dma->in_cnt,
676671 DMA_BIDIRECTIONAL,
677672 &dma->stat_dma_addr);
678673 }
....@@ -1200,15 +1195,15 @@
12001195 pr_debug("counter %x will overflow (nblks %u), falling back\n",
12011196 counter, counter + nblks);
12021197
1203
- ret = crypto_skcipher_setkey(ctx->fallback, ctx->aes_key,
1204
- ctx->key_length);
1198
+ ret = crypto_sync_skcipher_setkey(ctx->fallback, ctx->aes_key,
1199
+ ctx->key_length);
12051200 if (ret)
12061201 return ret;
12071202
12081203 {
1209
- SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback);
1204
+ SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback);
12101205
1211
- skcipher_request_set_tfm(subreq, ctx->fallback);
1206
+ skcipher_request_set_sync_tfm(subreq, ctx->fallback);
12121207 skcipher_request_set_callback(subreq, req->base.flags,
12131208 NULL, NULL);
12141209 skcipher_request_set_crypt(subreq, req->src, req->dst,
....@@ -1254,10 +1249,8 @@
12541249 {
12551250 struct artpec6_cryptotfm_context *ctx = crypto_tfm_ctx(&tfm->base);
12561251
1257
- if (len != 16 && len != 24 && len != 32) {
1258
- crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
1252
+ if (len != 16 && len != 24 && len != 32)
12591253 return -EINVAL;
1260
- }
12611254
12621255 ctx->key_length = len;
12631256
....@@ -1316,8 +1309,7 @@
13161309 struct artpec6_hashalg_context *ctx = crypto_tfm_ctx(areq->base.tfm);
13171310 struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(areq);
13181311 size_t digestsize = crypto_ahash_digestsize(crypto_ahash_reqtfm(areq));
1319
- size_t contextsize = digestsize == SHA384_DIGEST_SIZE ?
1320
- SHA512_DIGEST_SIZE : digestsize;
1312
+ size_t contextsize = digestsize;
13211313 size_t blocksize = crypto_tfm_alg_blocksize(
13221314 crypto_ahash_tfm(crypto_ahash_reqtfm(areq)));
13231315 struct artpec6_crypto_req_common *common = &req_ctx->common;
....@@ -1457,7 +1449,6 @@
14571449
14581450 /* Finalize */
14591451 if (req_ctx->hash_flags & HASH_FLAG_FINALIZE) {
1460
- bool needtrim = contextsize != digestsize;
14611452 size_t hash_pad_len;
14621453 u64 digest_bits;
14631454 u32 oper;
....@@ -1503,18 +1494,9 @@
15031494 /* Descriptor for the final result */
15041495 error = artpec6_crypto_setup_in_descr(common, areq->result,
15051496 digestsize,
1506
- !needtrim);
1497
+ true);
15071498 if (error)
15081499 return error;
1509
-
1510
- if (needtrim) {
1511
- /* Discard the extra context bytes for SHA-384 */
1512
- error = artpec6_crypto_setup_in_descr(common,
1513
- req_ctx->partial_buffer,
1514
- digestsize - contextsize, true);
1515
- if (error)
1516
- return error;
1517
- }
15181500
15191501 } else { /* This is not the final operation for this request */
15201502 if (!run_hw)
....@@ -1562,10 +1544,9 @@
15621544 {
15631545 struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm);
15641546
1565
- ctx->fallback = crypto_alloc_skcipher(crypto_tfm_alg_name(&tfm->base),
1566
- 0,
1567
- CRYPTO_ALG_ASYNC |
1568
- CRYPTO_ALG_NEED_FALLBACK);
1547
+ ctx->fallback =
1548
+ crypto_alloc_sync_skcipher(crypto_tfm_alg_name(&tfm->base),
1549
+ 0, CRYPTO_ALG_NEED_FALLBACK);
15691550 if (IS_ERR(ctx->fallback))
15701551 return PTR_ERR(ctx->fallback);
15711552
....@@ -1606,7 +1587,7 @@
16061587 {
16071588 struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm);
16081589
1609
- crypto_free_skcipher(ctx->fallback);
1590
+ crypto_free_sync_skcipher(ctx->fallback);
16101591 artpec6_crypto_aes_exit(tfm);
16111592 }
16121593
....@@ -1623,8 +1604,6 @@
16231604 case 32:
16241605 break;
16251606 default:
1626
- crypto_skcipher_set_flags(cipher,
1627
- CRYPTO_TFM_RES_BAD_KEY_LEN);
16281607 return -EINVAL;
16291608 }
16301609
....@@ -1651,8 +1630,6 @@
16511630 case 64:
16521631 break;
16531632 default:
1654
- crypto_skcipher_set_flags(cipher,
1655
- CRYPTO_TFM_RES_BAD_KEY_LEN);
16561633 return -EINVAL;
16571634 }
16581635
....@@ -1925,7 +1902,7 @@
19251902 /* For the decryption, cryptlen includes the tag. */
19261903 input_length = areq->cryptlen;
19271904 if (req_ctx->decrypt)
1928
- input_length -= AES_BLOCK_SIZE;
1905
+ input_length -= crypto_aead_authsize(cipher);
19291906
19301907 /* Prepare the context buffer */
19311908 req_ctx->hw_ctx.aad_length_bits =
....@@ -1990,7 +1967,7 @@
19901967 size_t output_len = areq->cryptlen;
19911968
19921969 if (req_ctx->decrypt)
1993
- output_len -= AES_BLOCK_SIZE;
1970
+ output_len -= crypto_aead_authsize(cipher);
19941971
19951972 artpec6_crypto_walk_init(&walk, areq->dst);
19961973
....@@ -2019,19 +1996,32 @@
20191996 * the output ciphertext. For decryption it is put in a context
20201997 * buffer for later compare against the input tag.
20211998 */
2022
- count = AES_BLOCK_SIZE;
20231999
20242000 if (req_ctx->decrypt) {
20252001 ret = artpec6_crypto_setup_in_descr(common,
2026
- req_ctx->decryption_tag, count, false);
2002
+ req_ctx->decryption_tag, AES_BLOCK_SIZE, false);
20272003 if (ret)
20282004 return ret;
20292005
20302006 } else {
2007
+ /* For encryption the requested tag size may be smaller
2008
+ * than the hardware's generated tag.
2009
+ */
2010
+ size_t authsize = crypto_aead_authsize(cipher);
2011
+
20312012 ret = artpec6_crypto_setup_sg_descrs_in(common, &walk,
2032
- count);
2013
+ authsize);
20332014 if (ret)
20342015 return ret;
2016
+
2017
+ if (authsize < AES_BLOCK_SIZE) {
2018
+ count = AES_BLOCK_SIZE - authsize;
2019
+ ret = artpec6_crypto_setup_in_descr(common,
2020
+ ac->pad_buffer,
2021
+ count, false);
2022
+ if (ret)
2023
+ return ret;
2024
+ }
20352025 }
20362026
20372027 }
....@@ -2105,9 +2095,12 @@
21052095 list_for_each_entry_safe(req, n, &ac->pending, list) {
21062096 struct artpec6_crypto_dma_descriptors *dma = req->dma;
21072097 u32 stat;
2098
+ dma_addr_t stataddr;
21082099
2109
- dma_sync_single_for_cpu(artpec6_crypto_dev, dma->stat_dma_addr,
2110
- sizeof(dma->stat[0]),
2100
+ stataddr = dma->stat_dma_addr + 4 * (req->dma->in_cnt - 1);
2101
+ dma_sync_single_for_cpu(artpec6_crypto_dev,
2102
+ stataddr,
2103
+ 4,
21112104 DMA_BIDIRECTIONAL);
21122105
21132106 stat = req->dma->stat[req->dma->in_cnt-1];
....@@ -2129,11 +2122,7 @@
21292122
21302123 list_move_tail(&req->list, &complete_done);
21312124
2132
- artpec6_crypto_dma_unmap_all(req);
2133
- artpec6_crypto_copy_bounce_buffers(req);
2134
-
21352125 ac->pending_count--;
2136
- artpec6_crypto_common_destroy(req);
21372126 }
21382127
21392128 artpec6_crypto_process_queue(ac, &complete_in_progress);
....@@ -2144,6 +2133,10 @@
21442133 * to allow new request submissions from the callbacks.
21452134 */
21462135 list_for_each_entry_safe(req, n, &complete_done, list) {
2136
+ artpec6_crypto_dma_unmap_all(req);
2137
+ artpec6_crypto_copy_bounce_buffers(req);
2138
+ artpec6_crypto_common_destroy(req);
2139
+
21472140 req->complete(req->req);
21482141 }
21492142
....@@ -2189,27 +2182,29 @@
21892182 /* Verify GCM hashtag. */
21902183 struct aead_request *areq = container_of(req,
21912184 struct aead_request, base);
2185
+ struct crypto_aead *aead = crypto_aead_reqtfm(areq);
21922186 struct artpec6_crypto_aead_req_ctx *req_ctx = aead_request_ctx(areq);
21932187
21942188 if (req_ctx->decrypt) {
21952189 u8 input_tag[AES_BLOCK_SIZE];
2190
+ unsigned int authsize = crypto_aead_authsize(aead);
21962191
21972192 sg_pcopy_to_buffer(areq->src,
21982193 sg_nents(areq->src),
21992194 input_tag,
2200
- AES_BLOCK_SIZE,
2195
+ authsize,
22012196 areq->assoclen + areq->cryptlen -
2202
- AES_BLOCK_SIZE);
2197
+ authsize);
22032198
2204
- if (memcmp(req_ctx->decryption_tag,
2205
- input_tag,
2206
- AES_BLOCK_SIZE)) {
2199
+ if (crypto_memneq(req_ctx->decryption_tag,
2200
+ input_tag,
2201
+ authsize)) {
22072202 pr_debug("***EBADMSG:\n");
22082203 print_hex_dump_debug("ref:", DUMP_PREFIX_ADDRESS, 32, 1,
2209
- input_tag, AES_BLOCK_SIZE, true);
2204
+ input_tag, authsize, true);
22102205 print_hex_dump_debug("out:", DUMP_PREFIX_ADDRESS, 32, 1,
22112206 req_ctx->decryption_tag,
2212
- AES_BLOCK_SIZE, true);
2207
+ authsize, true);
22132208
22142209 result = -EBADMSG;
22152210 }
....@@ -2244,18 +2239,12 @@
22442239 blocksize = crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
22452240
22462241 if (keylen > blocksize) {
2247
- SHASH_DESC_ON_STACK(hdesc, tfm_ctx->child_hash);
2248
-
2249
- hdesc->tfm = tfm_ctx->child_hash;
2250
- hdesc->flags = crypto_ahash_get_flags(tfm) &
2251
- CRYPTO_TFM_REQ_MAY_SLEEP;
2252
-
22532242 tfm_ctx->hmac_key_length = blocksize;
2254
- ret = crypto_shash_digest(hdesc, key, keylen,
2255
- tfm_ctx->hmac_key);
2243
+
2244
+ ret = crypto_shash_tfm_digest(tfm_ctx->child_hash, key, keylen,
2245
+ tfm_ctx->hmac_key);
22562246 if (ret)
22572247 return ret;
2258
-
22592248 } else {
22602249 memcpy(tfm_ctx->hmac_key, key, keylen);
22612250 tfm_ctx->hmac_key_length = keylen;
....@@ -2285,13 +2274,6 @@
22852274 case ARTPEC6_CRYPTO_HASH_SHA256:
22862275 oper = hmac ? regk_crypto_hmac_sha256 : regk_crypto_sha256;
22872276 break;
2288
- case ARTPEC6_CRYPTO_HASH_SHA384:
2289
- oper = hmac ? regk_crypto_hmac_sha384 : regk_crypto_sha384;
2290
- break;
2291
- case ARTPEC6_CRYPTO_HASH_SHA512:
2292
- oper = hmac ? regk_crypto_hmac_sha512 : regk_crypto_sha512;
2293
- break;
2294
-
22952277 default:
22962278 pr_err("%s: Unsupported hash type 0x%x\n", MODULE_NAME, type);
22972279 return -EINVAL;
....@@ -2328,7 +2310,7 @@
23282310
23292311 case ARTPEC6_CRYPTO_PREPARE_HASH_NO_START:
23302312 ret = 0;
2331
- /* Fallthrough */
2313
+ fallthrough;
23322314
23332315 default:
23342316 artpec6_crypto_common_destroy(&req_ctx->common);
....@@ -2387,51 +2369,9 @@
23872369 return artpec6_crypto_prepare_submit_hash(req);
23882370 }
23892371
2390
-static int __maybe_unused artpec6_crypto_sha384_init(struct ahash_request *req)
2391
-{
2392
- return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA384, 0);
2393
-}
2394
-
2395
-static int __maybe_unused
2396
-artpec6_crypto_sha384_digest(struct ahash_request *req)
2397
-{
2398
- struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
2399
-
2400
- artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA384, 0);
2401
- req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
2402
-
2403
- return artpec6_crypto_prepare_submit_hash(req);
2404
-}
2405
-
2406
-static int artpec6_crypto_sha512_init(struct ahash_request *req)
2407
-{
2408
- return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 0);
2409
-}
2410
-
2411
-static int artpec6_crypto_sha512_digest(struct ahash_request *req)
2412
-{
2413
- struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
2414
-
2415
- artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 0);
2416
- req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
2417
-
2418
- return artpec6_crypto_prepare_submit_hash(req);
2419
-}
2420
-
24212372 static int artpec6_crypto_hmac_sha256_init(struct ahash_request *req)
24222373 {
24232374 return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA256, 1);
2424
-}
2425
-
2426
-static int __maybe_unused
2427
-artpec6_crypto_hmac_sha384_init(struct ahash_request *req)
2428
-{
2429
- return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA384, 1);
2430
-}
2431
-
2432
-static int artpec6_crypto_hmac_sha512_init(struct ahash_request *req)
2433
-{
2434
- return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 1);
24352375 }
24362376
24372377 static int artpec6_crypto_hmac_sha256_digest(struct ahash_request *req)
....@@ -2439,27 +2379,6 @@
24392379 struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
24402380
24412381 artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA256, 1);
2442
- req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
2443
-
2444
- return artpec6_crypto_prepare_submit_hash(req);
2445
-}
2446
-
2447
-static int __maybe_unused
2448
-artpec6_crypto_hmac_sha384_digest(struct ahash_request *req)
2449
-{
2450
- struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
2451
-
2452
- artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA384, 1);
2453
- req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
2454
-
2455
- return artpec6_crypto_prepare_submit_hash(req);
2456
-}
2457
-
2458
-static int artpec6_crypto_hmac_sha512_digest(struct ahash_request *req)
2459
-{
2460
- struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
2461
-
2462
- artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 1);
24632382 req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
24642383
24652384 return artpec6_crypto_prepare_submit_hash(req);
....@@ -2497,17 +2416,6 @@
24972416 static int artpec6_crypto_ahash_init_hmac_sha256(struct crypto_tfm *tfm)
24982417 {
24992418 return artpec6_crypto_ahash_init_common(tfm, "sha256");
2500
-}
2501
-
2502
-static int __maybe_unused
2503
-artpec6_crypto_ahash_init_hmac_sha384(struct crypto_tfm *tfm)
2504
-{
2505
- return artpec6_crypto_ahash_init_common(tfm, "sha384");
2506
-}
2507
-
2508
-static int artpec6_crypto_ahash_init_hmac_sha512(struct crypto_tfm *tfm)
2509
-{
2510
- return artpec6_crypto_ahash_init_common(tfm, "sha512");
25112419 }
25122420
25132421 static void artpec6_crypto_ahash_exit(struct crypto_tfm *tfm)
....@@ -2722,7 +2630,8 @@
27222630 .cra_name = "sha1",
27232631 .cra_driver_name = "artpec-sha1",
27242632 .cra_priority = 300,
2725
- .cra_flags = CRYPTO_ALG_ASYNC,
2633
+ .cra_flags = CRYPTO_ALG_ASYNC |
2634
+ CRYPTO_ALG_ALLOCATES_MEMORY,
27262635 .cra_blocksize = SHA1_BLOCK_SIZE,
27272636 .cra_ctxsize = sizeof(struct artpec6_hashalg_context),
27282637 .cra_alignmask = 3,
....@@ -2745,7 +2654,8 @@
27452654 .cra_name = "sha256",
27462655 .cra_driver_name = "artpec-sha256",
27472656 .cra_priority = 300,
2748
- .cra_flags = CRYPTO_ALG_ASYNC,
2657
+ .cra_flags = CRYPTO_ALG_ASYNC |
2658
+ CRYPTO_ALG_ALLOCATES_MEMORY,
27492659 .cra_blocksize = SHA256_BLOCK_SIZE,
27502660 .cra_ctxsize = sizeof(struct artpec6_hashalg_context),
27512661 .cra_alignmask = 3,
....@@ -2769,109 +2679,13 @@
27692679 .cra_name = "hmac(sha256)",
27702680 .cra_driver_name = "artpec-hmac-sha256",
27712681 .cra_priority = 300,
2772
- .cra_flags = CRYPTO_ALG_ASYNC,
2682
+ .cra_flags = CRYPTO_ALG_ASYNC |
2683
+ CRYPTO_ALG_ALLOCATES_MEMORY,
27732684 .cra_blocksize = SHA256_BLOCK_SIZE,
27742685 .cra_ctxsize = sizeof(struct artpec6_hashalg_context),
27752686 .cra_alignmask = 3,
27762687 .cra_module = THIS_MODULE,
27772688 .cra_init = artpec6_crypto_ahash_init_hmac_sha256,
2778
- .cra_exit = artpec6_crypto_ahash_exit,
2779
- }
2780
- },
2781
-};
2782
-
2783
-static struct ahash_alg artpec7_hash_algos[] = {
2784
- /* SHA-384 */
2785
- {
2786
- .init = artpec6_crypto_sha384_init,
2787
- .update = artpec6_crypto_hash_update,
2788
- .final = artpec6_crypto_hash_final,
2789
- .digest = artpec6_crypto_sha384_digest,
2790
- .import = artpec6_crypto_hash_import,
2791
- .export = artpec6_crypto_hash_export,
2792
- .halg.digestsize = SHA384_DIGEST_SIZE,
2793
- .halg.statesize = sizeof(struct artpec6_hash_export_state),
2794
- .halg.base = {
2795
- .cra_name = "sha384",
2796
- .cra_driver_name = "artpec-sha384",
2797
- .cra_priority = 300,
2798
- .cra_flags = CRYPTO_ALG_ASYNC,
2799
- .cra_blocksize = SHA384_BLOCK_SIZE,
2800
- .cra_ctxsize = sizeof(struct artpec6_hashalg_context),
2801
- .cra_alignmask = 3,
2802
- .cra_module = THIS_MODULE,
2803
- .cra_init = artpec6_crypto_ahash_init,
2804
- .cra_exit = artpec6_crypto_ahash_exit,
2805
- }
2806
- },
2807
- /* HMAC SHA-384 */
2808
- {
2809
- .init = artpec6_crypto_hmac_sha384_init,
2810
- .update = artpec6_crypto_hash_update,
2811
- .final = artpec6_crypto_hash_final,
2812
- .digest = artpec6_crypto_hmac_sha384_digest,
2813
- .import = artpec6_crypto_hash_import,
2814
- .export = artpec6_crypto_hash_export,
2815
- .setkey = artpec6_crypto_hash_set_key,
2816
- .halg.digestsize = SHA384_DIGEST_SIZE,
2817
- .halg.statesize = sizeof(struct artpec6_hash_export_state),
2818
- .halg.base = {
2819
- .cra_name = "hmac(sha384)",
2820
- .cra_driver_name = "artpec-hmac-sha384",
2821
- .cra_priority = 300,
2822
- .cra_flags = CRYPTO_ALG_ASYNC,
2823
- .cra_blocksize = SHA384_BLOCK_SIZE,
2824
- .cra_ctxsize = sizeof(struct artpec6_hashalg_context),
2825
- .cra_alignmask = 3,
2826
- .cra_module = THIS_MODULE,
2827
- .cra_init = artpec6_crypto_ahash_init_hmac_sha384,
2828
- .cra_exit = artpec6_crypto_ahash_exit,
2829
- }
2830
- },
2831
- /* SHA-512 */
2832
- {
2833
- .init = artpec6_crypto_sha512_init,
2834
- .update = artpec6_crypto_hash_update,
2835
- .final = artpec6_crypto_hash_final,
2836
- .digest = artpec6_crypto_sha512_digest,
2837
- .import = artpec6_crypto_hash_import,
2838
- .export = artpec6_crypto_hash_export,
2839
- .halg.digestsize = SHA512_DIGEST_SIZE,
2840
- .halg.statesize = sizeof(struct artpec6_hash_export_state),
2841
- .halg.base = {
2842
- .cra_name = "sha512",
2843
- .cra_driver_name = "artpec-sha512",
2844
- .cra_priority = 300,
2845
- .cra_flags = CRYPTO_ALG_ASYNC,
2846
- .cra_blocksize = SHA512_BLOCK_SIZE,
2847
- .cra_ctxsize = sizeof(struct artpec6_hashalg_context),
2848
- .cra_alignmask = 3,
2849
- .cra_module = THIS_MODULE,
2850
- .cra_init = artpec6_crypto_ahash_init,
2851
- .cra_exit = artpec6_crypto_ahash_exit,
2852
- }
2853
- },
2854
- /* HMAC SHA-512 */
2855
- {
2856
- .init = artpec6_crypto_hmac_sha512_init,
2857
- .update = artpec6_crypto_hash_update,
2858
- .final = artpec6_crypto_hash_final,
2859
- .digest = artpec6_crypto_hmac_sha512_digest,
2860
- .import = artpec6_crypto_hash_import,
2861
- .export = artpec6_crypto_hash_export,
2862
- .setkey = artpec6_crypto_hash_set_key,
2863
- .halg.digestsize = SHA512_DIGEST_SIZE,
2864
- .halg.statesize = sizeof(struct artpec6_hash_export_state),
2865
- .halg.base = {
2866
- .cra_name = "hmac(sha512)",
2867
- .cra_driver_name = "artpec-hmac-sha512",
2868
- .cra_priority = 300,
2869
- .cra_flags = CRYPTO_ALG_ASYNC,
2870
- .cra_blocksize = SHA512_BLOCK_SIZE,
2871
- .cra_ctxsize = sizeof(struct artpec6_hashalg_context),
2872
- .cra_alignmask = 3,
2873
- .cra_module = THIS_MODULE,
2874
- .cra_init = artpec6_crypto_ahash_init_hmac_sha512,
28752689 .cra_exit = artpec6_crypto_ahash_exit,
28762690 }
28772691 },
....@@ -2885,7 +2699,8 @@
28852699 .cra_name = "ecb(aes)",
28862700 .cra_driver_name = "artpec6-ecb-aes",
28872701 .cra_priority = 300,
2888
- .cra_flags = CRYPTO_ALG_ASYNC,
2702
+ .cra_flags = CRYPTO_ALG_ASYNC |
2703
+ CRYPTO_ALG_ALLOCATES_MEMORY,
28892704 .cra_blocksize = AES_BLOCK_SIZE,
28902705 .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context),
28912706 .cra_alignmask = 3,
....@@ -2906,6 +2721,7 @@
29062721 .cra_driver_name = "artpec6-ctr-aes",
29072722 .cra_priority = 300,
29082723 .cra_flags = CRYPTO_ALG_ASYNC |
2724
+ CRYPTO_ALG_ALLOCATES_MEMORY |
29092725 CRYPTO_ALG_NEED_FALLBACK,
29102726 .cra_blocksize = 1,
29112727 .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context),
....@@ -2927,7 +2743,8 @@
29272743 .cra_name = "cbc(aes)",
29282744 .cra_driver_name = "artpec6-cbc-aes",
29292745 .cra_priority = 300,
2930
- .cra_flags = CRYPTO_ALG_ASYNC,
2746
+ .cra_flags = CRYPTO_ALG_ASYNC |
2747
+ CRYPTO_ALG_ALLOCATES_MEMORY,
29312748 .cra_blocksize = AES_BLOCK_SIZE,
29322749 .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context),
29332750 .cra_alignmask = 3,
....@@ -2948,7 +2765,8 @@
29482765 .cra_name = "xts(aes)",
29492766 .cra_driver_name = "artpec6-xts-aes",
29502767 .cra_priority = 300,
2951
- .cra_flags = CRYPTO_ALG_ASYNC,
2768
+ .cra_flags = CRYPTO_ALG_ASYNC |
2769
+ CRYPTO_ALG_ALLOCATES_MEMORY,
29522770 .cra_blocksize = 1,
29532771 .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context),
29542772 .cra_alignmask = 3,
....@@ -2979,6 +2797,7 @@
29792797 .cra_driver_name = "artpec-gcm-aes",
29802798 .cra_priority = 300,
29812799 .cra_flags = CRYPTO_ALG_ASYNC |
2800
+ CRYPTO_ALG_ALLOCATES_MEMORY |
29822801 CRYPTO_ALG_KERN_DRIVER_ONLY,
29832802 .cra_blocksize = 1,
29842803 .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context),
....@@ -3003,12 +2822,6 @@
30032822 {
30042823 dbgfs_root = debugfs_create_dir("artpec6_crypto", NULL);
30052824
3006
- if (!dbgfs_root || IS_ERR(dbgfs_root)) {
3007
- dbgfs_root = NULL;
3008
- pr_err("%s: Could not initialise debugfs!\n", MODULE_NAME);
3009
- return;
3010
- }
3011
-
30122825 #ifdef CONFIG_FAULT_INJECTION
30132826 fault_create_debugfs_attr("fail_status_read", dbgfs_root,
30142827 &artpec6_crypto_fail_status_read);
....@@ -3020,9 +2833,6 @@
30202833
30212834 static void artpec6_crypto_free_debugfs(void)
30222835 {
3023
- if (!dbgfs_root)
3024
- return;
3025
-
30262836 debugfs_remove_recursive(dbgfs_root);
30272837 dbgfs_root = NULL;
30282838 }
....@@ -3042,7 +2852,6 @@
30422852 struct artpec6_crypto *ac;
30432853 struct device *dev = &pdev->dev;
30442854 void __iomem *base;
3045
- struct resource *res;
30462855 int irq;
30472856 int err;
30482857
....@@ -3055,8 +2864,7 @@
30552864
30562865 variant = (enum artpec6_crypto_variant)match->data;
30572866
3058
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3059
- base = devm_ioremap_resource(&pdev->dev, res);
2867
+ base = devm_platform_ioremap_resource(pdev, 0);
30602868 if (IS_ERR(base))
30612869 return PTR_ERR(base);
30622870
....@@ -3123,19 +2931,10 @@
31232931 goto disable_hw;
31242932 }
31252933
3126
- if (variant != ARTPEC6_CRYPTO) {
3127
- err = crypto_register_ahashes(artpec7_hash_algos,
3128
- ARRAY_SIZE(artpec7_hash_algos));
3129
- if (err) {
3130
- dev_err(dev, "Failed to register ahashes\n");
3131
- goto unregister_ahashes;
3132
- }
3133
- }
3134
-
31352934 err = crypto_register_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
31362935 if (err) {
31372936 dev_err(dev, "Failed to register ciphers\n");
3138
- goto unregister_a7_ahashes;
2937
+ goto unregister_ahashes;
31392938 }
31402939
31412940 err = crypto_register_aeads(aead_algos, ARRAY_SIZE(aead_algos));
....@@ -3148,10 +2947,6 @@
31482947
31492948 unregister_algs:
31502949 crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
3151
-unregister_a7_ahashes:
3152
- if (variant != ARTPEC6_CRYPTO)
3153
- crypto_unregister_ahashes(artpec7_hash_algos,
3154
- ARRAY_SIZE(artpec7_hash_algos));
31552950 unregister_ahashes:
31562951 crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos));
31572952 disable_hw:
....@@ -3167,9 +2962,6 @@
31672962 int irq = platform_get_irq(pdev, 0);
31682963
31692964 crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos));
3170
- if (ac->variant != ARTPEC6_CRYPTO)
3171
- crypto_unregister_ahashes(artpec7_hash_algos,
3172
- ARRAY_SIZE(artpec7_hash_algos));
31732965 crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
31742966 crypto_unregister_aeads(aead_algos, ARRAY_SIZE(aead_algos));
31752967
....@@ -3192,7 +2984,6 @@
31922984 .remove = artpec6_crypto_remove,
31932985 .driver = {
31942986 .name = "artpec6-crypto",
3195
- .owner = THIS_MODULE,
31962987 .of_match_table = artpec6_crypto_of_match,
31972988 },
31982989 };