.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for ARTPEC-6 crypto block using the kernel asynchronous crypto api. |
---|
3 | 4 | * |
---|
.. | .. |
---|
135 | 136 | #define regk_crypto_ext 0x00000001 |
---|
136 | 137 | #define regk_crypto_hmac_sha1 0x00000007 |
---|
137 | 138 | #define regk_crypto_hmac_sha256 0x00000009 |
---|
138 | | -#define regk_crypto_hmac_sha384 0x0000000b |
---|
139 | | -#define regk_crypto_hmac_sha512 0x0000000d |
---|
140 | 139 | #define regk_crypto_init 0x00000000 |
---|
141 | 140 | #define regk_crypto_key_128 0x00000000 |
---|
142 | 141 | #define regk_crypto_key_192 0x00000001 |
---|
.. | .. |
---|
144 | 143 | #define regk_crypto_null 0x00000000 |
---|
145 | 144 | #define regk_crypto_sha1 0x00000006 |
---|
146 | 145 | #define regk_crypto_sha256 0x00000008 |
---|
147 | | -#define regk_crypto_sha384 0x0000000a |
---|
148 | | -#define regk_crypto_sha512 0x0000000c |
---|
149 | 146 | |
---|
150 | 147 | /* DMA descriptor structures */ |
---|
151 | 148 | struct pdma_descr_ctrl { |
---|
.. | .. |
---|
190 | 187 | /* Hash modes (including HMAC variants) */ |
---|
191 | 188 | #define ARTPEC6_CRYPTO_HASH_SHA1 1 |
---|
192 | 189 | #define ARTPEC6_CRYPTO_HASH_SHA256 2 |
---|
193 | | -#define ARTPEC6_CRYPTO_HASH_SHA384 3 |
---|
194 | | -#define ARTPEC6_CRYPTO_HASH_SHA512 4 |
---|
195 | 190 | |
---|
196 | 191 | /* Crypto modes */ |
---|
197 | 192 | #define ARTPEC6_CRYPTO_CIPHER_AES_ECB 1 |
---|
.. | .. |
---|
292 | 287 | }; |
---|
293 | 288 | |
---|
294 | 289 | 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]; |
---|
300 | 295 | size_t partial_bytes; |
---|
301 | 296 | u64 digcnt; |
---|
302 | 297 | u32 key_md; |
---|
.. | .. |
---|
306 | 301 | }; |
---|
307 | 302 | |
---|
308 | 303 | 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]; |
---|
311 | 306 | size_t partial_bytes; |
---|
312 | 307 | u64 digcnt; |
---|
313 | 308 | int oper; |
---|
.. | .. |
---|
315 | 310 | }; |
---|
316 | 311 | |
---|
317 | 312 | struct artpec6_hashalg_context { |
---|
318 | | - char hmac_key[SHA512_BLOCK_SIZE]; |
---|
| 313 | + char hmac_key[SHA256_BLOCK_SIZE]; |
---|
319 | 314 | size_t hmac_key_length; |
---|
320 | 315 | struct crypto_shash *child_hash; |
---|
321 | 316 | }; |
---|
.. | .. |
---|
331 | 326 | size_t key_length; |
---|
332 | 327 | u32 key_md; |
---|
333 | 328 | int crypto_type; |
---|
334 | | - struct crypto_skcipher *fallback; |
---|
| 329 | + struct crypto_sync_skcipher *fallback; |
---|
335 | 330 | }; |
---|
336 | 331 | |
---|
337 | 332 | struct artpec6_crypto_aead_hw_ctx { |
---|
.. | .. |
---|
671 | 666 | * to be written. |
---|
672 | 667 | */ |
---|
673 | 668 | 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, |
---|
676 | 671 | DMA_BIDIRECTIONAL, |
---|
677 | 672 | &dma->stat_dma_addr); |
---|
678 | 673 | } |
---|
.. | .. |
---|
1200 | 1195 | pr_debug("counter %x will overflow (nblks %u), falling back\n", |
---|
1201 | 1196 | counter, counter + nblks); |
---|
1202 | 1197 | |
---|
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); |
---|
1205 | 1200 | if (ret) |
---|
1206 | 1201 | return ret; |
---|
1207 | 1202 | |
---|
1208 | 1203 | { |
---|
1209 | | - SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback); |
---|
| 1204 | + SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback); |
---|
1210 | 1205 | |
---|
1211 | | - skcipher_request_set_tfm(subreq, ctx->fallback); |
---|
| 1206 | + skcipher_request_set_sync_tfm(subreq, ctx->fallback); |
---|
1212 | 1207 | skcipher_request_set_callback(subreq, req->base.flags, |
---|
1213 | 1208 | NULL, NULL); |
---|
1214 | 1209 | skcipher_request_set_crypt(subreq, req->src, req->dst, |
---|
.. | .. |
---|
1254 | 1249 | { |
---|
1255 | 1250 | struct artpec6_cryptotfm_context *ctx = crypto_tfm_ctx(&tfm->base); |
---|
1256 | 1251 | |
---|
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) |
---|
1259 | 1253 | return -EINVAL; |
---|
1260 | | - } |
---|
1261 | 1254 | |
---|
1262 | 1255 | ctx->key_length = len; |
---|
1263 | 1256 | |
---|
.. | .. |
---|
1316 | 1309 | struct artpec6_hashalg_context *ctx = crypto_tfm_ctx(areq->base.tfm); |
---|
1317 | 1310 | struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(areq); |
---|
1318 | 1311 | 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; |
---|
1321 | 1313 | size_t blocksize = crypto_tfm_alg_blocksize( |
---|
1322 | 1314 | crypto_ahash_tfm(crypto_ahash_reqtfm(areq))); |
---|
1323 | 1315 | struct artpec6_crypto_req_common *common = &req_ctx->common; |
---|
.. | .. |
---|
1457 | 1449 | |
---|
1458 | 1450 | /* Finalize */ |
---|
1459 | 1451 | if (req_ctx->hash_flags & HASH_FLAG_FINALIZE) { |
---|
1460 | | - bool needtrim = contextsize != digestsize; |
---|
1461 | 1452 | size_t hash_pad_len; |
---|
1462 | 1453 | u64 digest_bits; |
---|
1463 | 1454 | u32 oper; |
---|
.. | .. |
---|
1503 | 1494 | /* Descriptor for the final result */ |
---|
1504 | 1495 | error = artpec6_crypto_setup_in_descr(common, areq->result, |
---|
1505 | 1496 | digestsize, |
---|
1506 | | - !needtrim); |
---|
| 1497 | + true); |
---|
1507 | 1498 | if (error) |
---|
1508 | 1499 | 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 | | - } |
---|
1518 | 1500 | |
---|
1519 | 1501 | } else { /* This is not the final operation for this request */ |
---|
1520 | 1502 | if (!run_hw) |
---|
.. | .. |
---|
1562 | 1544 | { |
---|
1563 | 1545 | struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm); |
---|
1564 | 1546 | |
---|
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); |
---|
1569 | 1550 | if (IS_ERR(ctx->fallback)) |
---|
1570 | 1551 | return PTR_ERR(ctx->fallback); |
---|
1571 | 1552 | |
---|
.. | .. |
---|
1606 | 1587 | { |
---|
1607 | 1588 | struct artpec6_cryptotfm_context *ctx = crypto_skcipher_ctx(tfm); |
---|
1608 | 1589 | |
---|
1609 | | - crypto_free_skcipher(ctx->fallback); |
---|
| 1590 | + crypto_free_sync_skcipher(ctx->fallback); |
---|
1610 | 1591 | artpec6_crypto_aes_exit(tfm); |
---|
1611 | 1592 | } |
---|
1612 | 1593 | |
---|
.. | .. |
---|
1623 | 1604 | case 32: |
---|
1624 | 1605 | break; |
---|
1625 | 1606 | default: |
---|
1626 | | - crypto_skcipher_set_flags(cipher, |
---|
1627 | | - CRYPTO_TFM_RES_BAD_KEY_LEN); |
---|
1628 | 1607 | return -EINVAL; |
---|
1629 | 1608 | } |
---|
1630 | 1609 | |
---|
.. | .. |
---|
1651 | 1630 | case 64: |
---|
1652 | 1631 | break; |
---|
1653 | 1632 | default: |
---|
1654 | | - crypto_skcipher_set_flags(cipher, |
---|
1655 | | - CRYPTO_TFM_RES_BAD_KEY_LEN); |
---|
1656 | 1633 | return -EINVAL; |
---|
1657 | 1634 | } |
---|
1658 | 1635 | |
---|
.. | .. |
---|
1925 | 1902 | /* For the decryption, cryptlen includes the tag. */ |
---|
1926 | 1903 | input_length = areq->cryptlen; |
---|
1927 | 1904 | if (req_ctx->decrypt) |
---|
1928 | | - input_length -= AES_BLOCK_SIZE; |
---|
| 1905 | + input_length -= crypto_aead_authsize(cipher); |
---|
1929 | 1906 | |
---|
1930 | 1907 | /* Prepare the context buffer */ |
---|
1931 | 1908 | req_ctx->hw_ctx.aad_length_bits = |
---|
.. | .. |
---|
1990 | 1967 | size_t output_len = areq->cryptlen; |
---|
1991 | 1968 | |
---|
1992 | 1969 | if (req_ctx->decrypt) |
---|
1993 | | - output_len -= AES_BLOCK_SIZE; |
---|
| 1970 | + output_len -= crypto_aead_authsize(cipher); |
---|
1994 | 1971 | |
---|
1995 | 1972 | artpec6_crypto_walk_init(&walk, areq->dst); |
---|
1996 | 1973 | |
---|
.. | .. |
---|
2019 | 1996 | * the output ciphertext. For decryption it is put in a context |
---|
2020 | 1997 | * buffer for later compare against the input tag. |
---|
2021 | 1998 | */ |
---|
2022 | | - count = AES_BLOCK_SIZE; |
---|
2023 | 1999 | |
---|
2024 | 2000 | if (req_ctx->decrypt) { |
---|
2025 | 2001 | ret = artpec6_crypto_setup_in_descr(common, |
---|
2026 | | - req_ctx->decryption_tag, count, false); |
---|
| 2002 | + req_ctx->decryption_tag, AES_BLOCK_SIZE, false); |
---|
2027 | 2003 | if (ret) |
---|
2028 | 2004 | return ret; |
---|
2029 | 2005 | |
---|
2030 | 2006 | } 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 | + |
---|
2031 | 2012 | ret = artpec6_crypto_setup_sg_descrs_in(common, &walk, |
---|
2032 | | - count); |
---|
| 2013 | + authsize); |
---|
2033 | 2014 | if (ret) |
---|
2034 | 2015 | 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 | + } |
---|
2035 | 2025 | } |
---|
2036 | 2026 | |
---|
2037 | 2027 | } |
---|
.. | .. |
---|
2105 | 2095 | list_for_each_entry_safe(req, n, &ac->pending, list) { |
---|
2106 | 2096 | struct artpec6_crypto_dma_descriptors *dma = req->dma; |
---|
2107 | 2097 | u32 stat; |
---|
| 2098 | + dma_addr_t stataddr; |
---|
2108 | 2099 | |
---|
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, |
---|
2111 | 2104 | DMA_BIDIRECTIONAL); |
---|
2112 | 2105 | |
---|
2113 | 2106 | stat = req->dma->stat[req->dma->in_cnt-1]; |
---|
.. | .. |
---|
2129 | 2122 | |
---|
2130 | 2123 | list_move_tail(&req->list, &complete_done); |
---|
2131 | 2124 | |
---|
2132 | | - artpec6_crypto_dma_unmap_all(req); |
---|
2133 | | - artpec6_crypto_copy_bounce_buffers(req); |
---|
2134 | | - |
---|
2135 | 2125 | ac->pending_count--; |
---|
2136 | | - artpec6_crypto_common_destroy(req); |
---|
2137 | 2126 | } |
---|
2138 | 2127 | |
---|
2139 | 2128 | artpec6_crypto_process_queue(ac, &complete_in_progress); |
---|
.. | .. |
---|
2144 | 2133 | * to allow new request submissions from the callbacks. |
---|
2145 | 2134 | */ |
---|
2146 | 2135 | 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 | + |
---|
2147 | 2140 | req->complete(req->req); |
---|
2148 | 2141 | } |
---|
2149 | 2142 | |
---|
.. | .. |
---|
2189 | 2182 | /* Verify GCM hashtag. */ |
---|
2190 | 2183 | struct aead_request *areq = container_of(req, |
---|
2191 | 2184 | struct aead_request, base); |
---|
| 2185 | + struct crypto_aead *aead = crypto_aead_reqtfm(areq); |
---|
2192 | 2186 | struct artpec6_crypto_aead_req_ctx *req_ctx = aead_request_ctx(areq); |
---|
2193 | 2187 | |
---|
2194 | 2188 | if (req_ctx->decrypt) { |
---|
2195 | 2189 | u8 input_tag[AES_BLOCK_SIZE]; |
---|
| 2190 | + unsigned int authsize = crypto_aead_authsize(aead); |
---|
2196 | 2191 | |
---|
2197 | 2192 | sg_pcopy_to_buffer(areq->src, |
---|
2198 | 2193 | sg_nents(areq->src), |
---|
2199 | 2194 | input_tag, |
---|
2200 | | - AES_BLOCK_SIZE, |
---|
| 2195 | + authsize, |
---|
2201 | 2196 | areq->assoclen + areq->cryptlen - |
---|
2202 | | - AES_BLOCK_SIZE); |
---|
| 2197 | + authsize); |
---|
2203 | 2198 | |
---|
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)) { |
---|
2207 | 2202 | pr_debug("***EBADMSG:\n"); |
---|
2208 | 2203 | print_hex_dump_debug("ref:", DUMP_PREFIX_ADDRESS, 32, 1, |
---|
2209 | | - input_tag, AES_BLOCK_SIZE, true); |
---|
| 2204 | + input_tag, authsize, true); |
---|
2210 | 2205 | print_hex_dump_debug("out:", DUMP_PREFIX_ADDRESS, 32, 1, |
---|
2211 | 2206 | req_ctx->decryption_tag, |
---|
2212 | | - AES_BLOCK_SIZE, true); |
---|
| 2207 | + authsize, true); |
---|
2213 | 2208 | |
---|
2214 | 2209 | result = -EBADMSG; |
---|
2215 | 2210 | } |
---|
.. | .. |
---|
2244 | 2239 | blocksize = crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); |
---|
2245 | 2240 | |
---|
2246 | 2241 | 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 | | - |
---|
2253 | 2242 | 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); |
---|
2256 | 2246 | if (ret) |
---|
2257 | 2247 | return ret; |
---|
2258 | | - |
---|
2259 | 2248 | } else { |
---|
2260 | 2249 | memcpy(tfm_ctx->hmac_key, key, keylen); |
---|
2261 | 2250 | tfm_ctx->hmac_key_length = keylen; |
---|
.. | .. |
---|
2285 | 2274 | case ARTPEC6_CRYPTO_HASH_SHA256: |
---|
2286 | 2275 | oper = hmac ? regk_crypto_hmac_sha256 : regk_crypto_sha256; |
---|
2287 | 2276 | 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 | | - |
---|
2295 | 2277 | default: |
---|
2296 | 2278 | pr_err("%s: Unsupported hash type 0x%x\n", MODULE_NAME, type); |
---|
2297 | 2279 | return -EINVAL; |
---|
.. | .. |
---|
2328 | 2310 | |
---|
2329 | 2311 | case ARTPEC6_CRYPTO_PREPARE_HASH_NO_START: |
---|
2330 | 2312 | ret = 0; |
---|
2331 | | - /* Fallthrough */ |
---|
| 2313 | + fallthrough; |
---|
2332 | 2314 | |
---|
2333 | 2315 | default: |
---|
2334 | 2316 | artpec6_crypto_common_destroy(&req_ctx->common); |
---|
.. | .. |
---|
2387 | 2369 | return artpec6_crypto_prepare_submit_hash(req); |
---|
2388 | 2370 | } |
---|
2389 | 2371 | |
---|
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 | | - |
---|
2421 | 2372 | static int artpec6_crypto_hmac_sha256_init(struct ahash_request *req) |
---|
2422 | 2373 | { |
---|
2423 | 2374 | 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); |
---|
2435 | 2375 | } |
---|
2436 | 2376 | |
---|
2437 | 2377 | static int artpec6_crypto_hmac_sha256_digest(struct ahash_request *req) |
---|
.. | .. |
---|
2439 | 2379 | struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req); |
---|
2440 | 2380 | |
---|
2441 | 2381 | 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); |
---|
2463 | 2382 | req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE; |
---|
2464 | 2383 | |
---|
2465 | 2384 | return artpec6_crypto_prepare_submit_hash(req); |
---|
.. | .. |
---|
2497 | 2416 | static int artpec6_crypto_ahash_init_hmac_sha256(struct crypto_tfm *tfm) |
---|
2498 | 2417 | { |
---|
2499 | 2418 | 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"); |
---|
2511 | 2419 | } |
---|
2512 | 2420 | |
---|
2513 | 2421 | static void artpec6_crypto_ahash_exit(struct crypto_tfm *tfm) |
---|
.. | .. |
---|
2722 | 2630 | .cra_name = "sha1", |
---|
2723 | 2631 | .cra_driver_name = "artpec-sha1", |
---|
2724 | 2632 | .cra_priority = 300, |
---|
2725 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 2633 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 2634 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
2726 | 2635 | .cra_blocksize = SHA1_BLOCK_SIZE, |
---|
2727 | 2636 | .cra_ctxsize = sizeof(struct artpec6_hashalg_context), |
---|
2728 | 2637 | .cra_alignmask = 3, |
---|
.. | .. |
---|
2745 | 2654 | .cra_name = "sha256", |
---|
2746 | 2655 | .cra_driver_name = "artpec-sha256", |
---|
2747 | 2656 | .cra_priority = 300, |
---|
2748 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 2657 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 2658 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
2749 | 2659 | .cra_blocksize = SHA256_BLOCK_SIZE, |
---|
2750 | 2660 | .cra_ctxsize = sizeof(struct artpec6_hashalg_context), |
---|
2751 | 2661 | .cra_alignmask = 3, |
---|
.. | .. |
---|
2769 | 2679 | .cra_name = "hmac(sha256)", |
---|
2770 | 2680 | .cra_driver_name = "artpec-hmac-sha256", |
---|
2771 | 2681 | .cra_priority = 300, |
---|
2772 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 2682 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 2683 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
2773 | 2684 | .cra_blocksize = SHA256_BLOCK_SIZE, |
---|
2774 | 2685 | .cra_ctxsize = sizeof(struct artpec6_hashalg_context), |
---|
2775 | 2686 | .cra_alignmask = 3, |
---|
2776 | 2687 | .cra_module = THIS_MODULE, |
---|
2777 | 2688 | .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, |
---|
2875 | 2689 | .cra_exit = artpec6_crypto_ahash_exit, |
---|
2876 | 2690 | } |
---|
2877 | 2691 | }, |
---|
.. | .. |
---|
2885 | 2699 | .cra_name = "ecb(aes)", |
---|
2886 | 2700 | .cra_driver_name = "artpec6-ecb-aes", |
---|
2887 | 2701 | .cra_priority = 300, |
---|
2888 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 2702 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 2703 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
2889 | 2704 | .cra_blocksize = AES_BLOCK_SIZE, |
---|
2890 | 2705 | .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), |
---|
2891 | 2706 | .cra_alignmask = 3, |
---|
.. | .. |
---|
2906 | 2721 | .cra_driver_name = "artpec6-ctr-aes", |
---|
2907 | 2722 | .cra_priority = 300, |
---|
2908 | 2723 | .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 2724 | + CRYPTO_ALG_ALLOCATES_MEMORY | |
---|
2909 | 2725 | CRYPTO_ALG_NEED_FALLBACK, |
---|
2910 | 2726 | .cra_blocksize = 1, |
---|
2911 | 2727 | .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), |
---|
.. | .. |
---|
2927 | 2743 | .cra_name = "cbc(aes)", |
---|
2928 | 2744 | .cra_driver_name = "artpec6-cbc-aes", |
---|
2929 | 2745 | .cra_priority = 300, |
---|
2930 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 2746 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 2747 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
2931 | 2748 | .cra_blocksize = AES_BLOCK_SIZE, |
---|
2932 | 2749 | .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), |
---|
2933 | 2750 | .cra_alignmask = 3, |
---|
.. | .. |
---|
2948 | 2765 | .cra_name = "xts(aes)", |
---|
2949 | 2766 | .cra_driver_name = "artpec6-xts-aes", |
---|
2950 | 2767 | .cra_priority = 300, |
---|
2951 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 2768 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 2769 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
2952 | 2770 | .cra_blocksize = 1, |
---|
2953 | 2771 | .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), |
---|
2954 | 2772 | .cra_alignmask = 3, |
---|
.. | .. |
---|
2979 | 2797 | .cra_driver_name = "artpec-gcm-aes", |
---|
2980 | 2798 | .cra_priority = 300, |
---|
2981 | 2799 | .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 2800 | + CRYPTO_ALG_ALLOCATES_MEMORY | |
---|
2982 | 2801 | CRYPTO_ALG_KERN_DRIVER_ONLY, |
---|
2983 | 2802 | .cra_blocksize = 1, |
---|
2984 | 2803 | .cra_ctxsize = sizeof(struct artpec6_cryptotfm_context), |
---|
.. | .. |
---|
3003 | 2822 | { |
---|
3004 | 2823 | dbgfs_root = debugfs_create_dir("artpec6_crypto", NULL); |
---|
3005 | 2824 | |
---|
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 | | - |
---|
3012 | 2825 | #ifdef CONFIG_FAULT_INJECTION |
---|
3013 | 2826 | fault_create_debugfs_attr("fail_status_read", dbgfs_root, |
---|
3014 | 2827 | &artpec6_crypto_fail_status_read); |
---|
.. | .. |
---|
3020 | 2833 | |
---|
3021 | 2834 | static void artpec6_crypto_free_debugfs(void) |
---|
3022 | 2835 | { |
---|
3023 | | - if (!dbgfs_root) |
---|
3024 | | - return; |
---|
3025 | | - |
---|
3026 | 2836 | debugfs_remove_recursive(dbgfs_root); |
---|
3027 | 2837 | dbgfs_root = NULL; |
---|
3028 | 2838 | } |
---|
.. | .. |
---|
3042 | 2852 | struct artpec6_crypto *ac; |
---|
3043 | 2853 | struct device *dev = &pdev->dev; |
---|
3044 | 2854 | void __iomem *base; |
---|
3045 | | - struct resource *res; |
---|
3046 | 2855 | int irq; |
---|
3047 | 2856 | int err; |
---|
3048 | 2857 | |
---|
.. | .. |
---|
3055 | 2864 | |
---|
3056 | 2865 | variant = (enum artpec6_crypto_variant)match->data; |
---|
3057 | 2866 | |
---|
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); |
---|
3060 | 2868 | if (IS_ERR(base)) |
---|
3061 | 2869 | return PTR_ERR(base); |
---|
3062 | 2870 | |
---|
.. | .. |
---|
3123 | 2931 | goto disable_hw; |
---|
3124 | 2932 | } |
---|
3125 | 2933 | |
---|
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 | | - |
---|
3135 | 2934 | err = crypto_register_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos)); |
---|
3136 | 2935 | if (err) { |
---|
3137 | 2936 | dev_err(dev, "Failed to register ciphers\n"); |
---|
3138 | | - goto unregister_a7_ahashes; |
---|
| 2937 | + goto unregister_ahashes; |
---|
3139 | 2938 | } |
---|
3140 | 2939 | |
---|
3141 | 2940 | err = crypto_register_aeads(aead_algos, ARRAY_SIZE(aead_algos)); |
---|
.. | .. |
---|
3148 | 2947 | |
---|
3149 | 2948 | unregister_algs: |
---|
3150 | 2949 | 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)); |
---|
3155 | 2950 | unregister_ahashes: |
---|
3156 | 2951 | crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos)); |
---|
3157 | 2952 | disable_hw: |
---|
.. | .. |
---|
3167 | 2962 | int irq = platform_get_irq(pdev, 0); |
---|
3168 | 2963 | |
---|
3169 | 2964 | 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)); |
---|
3173 | 2965 | crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos)); |
---|
3174 | 2966 | crypto_unregister_aeads(aead_algos, ARRAY_SIZE(aead_algos)); |
---|
3175 | 2967 | |
---|
.. | .. |
---|
3192 | 2984 | .remove = artpec6_crypto_remove, |
---|
3193 | 2985 | .driver = { |
---|
3194 | 2986 | .name = "artpec6-crypto", |
---|
3195 | | - .owner = THIS_MODULE, |
---|
3196 | 2987 | .of_match_table = artpec6_crypto_of_match, |
---|
3197 | 2988 | }, |
---|
3198 | 2989 | }; |
---|