.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * Cryptographic API. |
---|
3 | 4 | * |
---|
.. | .. |
---|
5 | 6 | * |
---|
6 | 7 | * Copyright (c) 2012 Eukréa Electromatique - ATMEL |
---|
7 | 8 | * Author: Nicolas Royer <nicolas@eukrea.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 published |
---|
11 | | - * by the Free Software Foundation. |
---|
12 | 9 | * |
---|
13 | 10 | * Some ideas are from omap-sham.c drivers. |
---|
14 | 11 | */ |
---|
.. | .. |
---|
24 | 21 | #include <linux/platform_device.h> |
---|
25 | 22 | |
---|
26 | 23 | #include <linux/device.h> |
---|
| 24 | +#include <linux/dmaengine.h> |
---|
27 | 25 | #include <linux/init.h> |
---|
28 | 26 | #include <linux/errno.h> |
---|
29 | 27 | #include <linux/interrupt.h> |
---|
.. | .. |
---|
33 | 31 | #include <linux/of_device.h> |
---|
34 | 32 | #include <linux/delay.h> |
---|
35 | 33 | #include <linux/crypto.h> |
---|
36 | | -#include <linux/cryptohash.h> |
---|
37 | 34 | #include <crypto/scatterwalk.h> |
---|
38 | 35 | #include <crypto/algapi.h> |
---|
39 | 36 | #include <crypto/sha.h> |
---|
40 | 37 | #include <crypto/hash.h> |
---|
41 | 38 | #include <crypto/internal/hash.h> |
---|
42 | | -#include <linux/platform_data/crypto-atmel.h> |
---|
43 | 39 | #include "atmel-sha-regs.h" |
---|
44 | 40 | #include "atmel-authenc.h" |
---|
| 41 | + |
---|
| 42 | +#define ATMEL_SHA_PRIORITY 300 |
---|
45 | 43 | |
---|
46 | 44 | /* SHA flags */ |
---|
47 | 45 | #define SHA_FLAGS_BUSY BIT(0) |
---|
.. | .. |
---|
137 | 135 | void __iomem *io_base; |
---|
138 | 136 | |
---|
139 | 137 | spinlock_t lock; |
---|
140 | | - int err; |
---|
141 | 138 | struct tasklet_struct done_task; |
---|
142 | 139 | struct tasklet_struct queue_task; |
---|
143 | 140 | |
---|
.. | .. |
---|
363 | 360 | static void atmel_sha_fill_padding(struct atmel_sha_reqctx *ctx, int length) |
---|
364 | 361 | { |
---|
365 | 362 | unsigned int index, padlen; |
---|
366 | | - u64 bits[2]; |
---|
| 363 | + __be64 bits[2]; |
---|
367 | 364 | u64 size[2]; |
---|
368 | 365 | |
---|
369 | 366 | size[0] = ctx->digcnt[0]; |
---|
.. | .. |
---|
854 | 851 | 0, final); |
---|
855 | 852 | } |
---|
856 | 853 | |
---|
857 | | -static int atmel_sha_update_dma_stop(struct atmel_sha_dev *dd) |
---|
| 854 | +static void atmel_sha_update_dma_stop(struct atmel_sha_dev *dd) |
---|
858 | 855 | { |
---|
859 | 856 | struct atmel_sha_reqctx *ctx = ahash_request_ctx(dd->req); |
---|
860 | 857 | |
---|
.. | .. |
---|
873 | 870 | dma_unmap_single(dd->dev, ctx->dma_addr, ctx->buflen + |
---|
874 | 871 | ctx->block_size, DMA_TO_DEVICE); |
---|
875 | 872 | } |
---|
876 | | - |
---|
877 | | - return 0; |
---|
878 | 873 | } |
---|
879 | 874 | |
---|
880 | 875 | static int atmel_sha_update_req(struct atmel_sha_dev *dd) |
---|
.. | .. |
---|
1028 | 1023 | if (!(SHA_FLAGS_INIT & dd->flags)) { |
---|
1029 | 1024 | atmel_sha_write(dd, SHA_CR, SHA_CR_SWRST); |
---|
1030 | 1025 | dd->flags |= SHA_FLAGS_INIT; |
---|
1031 | | - dd->err = 0; |
---|
1032 | 1026 | } |
---|
1033 | 1027 | |
---|
1034 | 1028 | return 0; |
---|
.. | .. |
---|
1039 | 1033 | return atmel_sha_read(dd, SHA_HW_VERSION) & 0x00000fff; |
---|
1040 | 1034 | } |
---|
1041 | 1035 | |
---|
1042 | | -static void atmel_sha_hw_version_init(struct atmel_sha_dev *dd) |
---|
| 1036 | +static int atmel_sha_hw_version_init(struct atmel_sha_dev *dd) |
---|
1043 | 1037 | { |
---|
1044 | | - atmel_sha_hw_init(dd); |
---|
| 1038 | + int err; |
---|
| 1039 | + |
---|
| 1040 | + err = atmel_sha_hw_init(dd); |
---|
| 1041 | + if (err) |
---|
| 1042 | + return err; |
---|
1045 | 1043 | |
---|
1046 | 1044 | dd->hw_version = atmel_sha_get_version(dd); |
---|
1047 | 1045 | |
---|
.. | .. |
---|
1049 | 1047 | "version: 0x%x\n", dd->hw_version); |
---|
1050 | 1048 | |
---|
1051 | 1049 | clk_disable(dd->iclk); |
---|
| 1050 | + |
---|
| 1051 | + return 0; |
---|
1052 | 1052 | } |
---|
1053 | 1053 | |
---|
1054 | 1054 | static int atmel_sha_handle_queue(struct atmel_sha_dev *dd, |
---|
.. | .. |
---|
1251 | 1251 | return 0; |
---|
1252 | 1252 | } |
---|
1253 | 1253 | |
---|
| 1254 | +static void atmel_sha_alg_init(struct ahash_alg *alg) |
---|
| 1255 | +{ |
---|
| 1256 | + alg->halg.base.cra_priority = ATMEL_SHA_PRIORITY; |
---|
| 1257 | + alg->halg.base.cra_flags = CRYPTO_ALG_ASYNC; |
---|
| 1258 | + alg->halg.base.cra_ctxsize = sizeof(struct atmel_sha_ctx); |
---|
| 1259 | + alg->halg.base.cra_module = THIS_MODULE; |
---|
| 1260 | + alg->halg.base.cra_init = atmel_sha_cra_init; |
---|
| 1261 | + |
---|
| 1262 | + alg->halg.statesize = sizeof(struct atmel_sha_reqctx); |
---|
| 1263 | + |
---|
| 1264 | + alg->init = atmel_sha_init; |
---|
| 1265 | + alg->update = atmel_sha_update; |
---|
| 1266 | + alg->final = atmel_sha_final; |
---|
| 1267 | + alg->finup = atmel_sha_finup; |
---|
| 1268 | + alg->digest = atmel_sha_digest; |
---|
| 1269 | + alg->export = atmel_sha_export; |
---|
| 1270 | + alg->import = atmel_sha_import; |
---|
| 1271 | +} |
---|
| 1272 | + |
---|
1254 | 1273 | static struct ahash_alg sha_1_256_algs[] = { |
---|
1255 | 1274 | { |
---|
1256 | | - .init = atmel_sha_init, |
---|
1257 | | - .update = atmel_sha_update, |
---|
1258 | | - .final = atmel_sha_final, |
---|
1259 | | - .finup = atmel_sha_finup, |
---|
1260 | | - .digest = atmel_sha_digest, |
---|
1261 | | - .export = atmel_sha_export, |
---|
1262 | | - .import = atmel_sha_import, |
---|
1263 | | - .halg = { |
---|
1264 | | - .digestsize = SHA1_DIGEST_SIZE, |
---|
1265 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
1266 | | - .base = { |
---|
1267 | | - .cra_name = "sha1", |
---|
1268 | | - .cra_driver_name = "atmel-sha1", |
---|
1269 | | - .cra_priority = 100, |
---|
1270 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
1271 | | - .cra_blocksize = SHA1_BLOCK_SIZE, |
---|
1272 | | - .cra_ctxsize = sizeof(struct atmel_sha_ctx), |
---|
1273 | | - .cra_alignmask = 0, |
---|
1274 | | - .cra_module = THIS_MODULE, |
---|
1275 | | - .cra_init = atmel_sha_cra_init, |
---|
1276 | | - } |
---|
1277 | | - } |
---|
| 1275 | + .halg.base.cra_name = "sha1", |
---|
| 1276 | + .halg.base.cra_driver_name = "atmel-sha1", |
---|
| 1277 | + .halg.base.cra_blocksize = SHA1_BLOCK_SIZE, |
---|
| 1278 | + |
---|
| 1279 | + .halg.digestsize = SHA1_DIGEST_SIZE, |
---|
1278 | 1280 | }, |
---|
1279 | 1281 | { |
---|
1280 | | - .init = atmel_sha_init, |
---|
1281 | | - .update = atmel_sha_update, |
---|
1282 | | - .final = atmel_sha_final, |
---|
1283 | | - .finup = atmel_sha_finup, |
---|
1284 | | - .digest = atmel_sha_digest, |
---|
1285 | | - .export = atmel_sha_export, |
---|
1286 | | - .import = atmel_sha_import, |
---|
1287 | | - .halg = { |
---|
1288 | | - .digestsize = SHA256_DIGEST_SIZE, |
---|
1289 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
1290 | | - .base = { |
---|
1291 | | - .cra_name = "sha256", |
---|
1292 | | - .cra_driver_name = "atmel-sha256", |
---|
1293 | | - .cra_priority = 100, |
---|
1294 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
1295 | | - .cra_blocksize = SHA256_BLOCK_SIZE, |
---|
1296 | | - .cra_ctxsize = sizeof(struct atmel_sha_ctx), |
---|
1297 | | - .cra_alignmask = 0, |
---|
1298 | | - .cra_module = THIS_MODULE, |
---|
1299 | | - .cra_init = atmel_sha_cra_init, |
---|
1300 | | - } |
---|
1301 | | - } |
---|
| 1282 | + .halg.base.cra_name = "sha256", |
---|
| 1283 | + .halg.base.cra_driver_name = "atmel-sha256", |
---|
| 1284 | + .halg.base.cra_blocksize = SHA256_BLOCK_SIZE, |
---|
| 1285 | + |
---|
| 1286 | + .halg.digestsize = SHA256_DIGEST_SIZE, |
---|
1302 | 1287 | }, |
---|
1303 | 1288 | }; |
---|
1304 | 1289 | |
---|
1305 | 1290 | static struct ahash_alg sha_224_alg = { |
---|
1306 | | - .init = atmel_sha_init, |
---|
1307 | | - .update = atmel_sha_update, |
---|
1308 | | - .final = atmel_sha_final, |
---|
1309 | | - .finup = atmel_sha_finup, |
---|
1310 | | - .digest = atmel_sha_digest, |
---|
1311 | | - .export = atmel_sha_export, |
---|
1312 | | - .import = atmel_sha_import, |
---|
1313 | | - .halg = { |
---|
1314 | | - .digestsize = SHA224_DIGEST_SIZE, |
---|
1315 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
1316 | | - .base = { |
---|
1317 | | - .cra_name = "sha224", |
---|
1318 | | - .cra_driver_name = "atmel-sha224", |
---|
1319 | | - .cra_priority = 100, |
---|
1320 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
1321 | | - .cra_blocksize = SHA224_BLOCK_SIZE, |
---|
1322 | | - .cra_ctxsize = sizeof(struct atmel_sha_ctx), |
---|
1323 | | - .cra_alignmask = 0, |
---|
1324 | | - .cra_module = THIS_MODULE, |
---|
1325 | | - .cra_init = atmel_sha_cra_init, |
---|
1326 | | - } |
---|
1327 | | - } |
---|
| 1291 | + .halg.base.cra_name = "sha224", |
---|
| 1292 | + .halg.base.cra_driver_name = "atmel-sha224", |
---|
| 1293 | + .halg.base.cra_blocksize = SHA224_BLOCK_SIZE, |
---|
| 1294 | + |
---|
| 1295 | + .halg.digestsize = SHA224_DIGEST_SIZE, |
---|
1328 | 1296 | }; |
---|
1329 | 1297 | |
---|
1330 | 1298 | static struct ahash_alg sha_384_512_algs[] = { |
---|
1331 | 1299 | { |
---|
1332 | | - .init = atmel_sha_init, |
---|
1333 | | - .update = atmel_sha_update, |
---|
1334 | | - .final = atmel_sha_final, |
---|
1335 | | - .finup = atmel_sha_finup, |
---|
1336 | | - .digest = atmel_sha_digest, |
---|
1337 | | - .export = atmel_sha_export, |
---|
1338 | | - .import = atmel_sha_import, |
---|
1339 | | - .halg = { |
---|
1340 | | - .digestsize = SHA384_DIGEST_SIZE, |
---|
1341 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
1342 | | - .base = { |
---|
1343 | | - .cra_name = "sha384", |
---|
1344 | | - .cra_driver_name = "atmel-sha384", |
---|
1345 | | - .cra_priority = 100, |
---|
1346 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
1347 | | - .cra_blocksize = SHA384_BLOCK_SIZE, |
---|
1348 | | - .cra_ctxsize = sizeof(struct atmel_sha_ctx), |
---|
1349 | | - .cra_alignmask = 0x3, |
---|
1350 | | - .cra_module = THIS_MODULE, |
---|
1351 | | - .cra_init = atmel_sha_cra_init, |
---|
1352 | | - } |
---|
1353 | | - } |
---|
| 1300 | + .halg.base.cra_name = "sha384", |
---|
| 1301 | + .halg.base.cra_driver_name = "atmel-sha384", |
---|
| 1302 | + .halg.base.cra_blocksize = SHA384_BLOCK_SIZE, |
---|
| 1303 | + .halg.base.cra_alignmask = 0x3, |
---|
| 1304 | + |
---|
| 1305 | + .halg.digestsize = SHA384_DIGEST_SIZE, |
---|
1354 | 1306 | }, |
---|
1355 | 1307 | { |
---|
1356 | | - .init = atmel_sha_init, |
---|
1357 | | - .update = atmel_sha_update, |
---|
1358 | | - .final = atmel_sha_final, |
---|
1359 | | - .finup = atmel_sha_finup, |
---|
1360 | | - .digest = atmel_sha_digest, |
---|
1361 | | - .export = atmel_sha_export, |
---|
1362 | | - .import = atmel_sha_import, |
---|
1363 | | - .halg = { |
---|
1364 | | - .digestsize = SHA512_DIGEST_SIZE, |
---|
1365 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
1366 | | - .base = { |
---|
1367 | | - .cra_name = "sha512", |
---|
1368 | | - .cra_driver_name = "atmel-sha512", |
---|
1369 | | - .cra_priority = 100, |
---|
1370 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
1371 | | - .cra_blocksize = SHA512_BLOCK_SIZE, |
---|
1372 | | - .cra_ctxsize = sizeof(struct atmel_sha_ctx), |
---|
1373 | | - .cra_alignmask = 0x3, |
---|
1374 | | - .cra_module = THIS_MODULE, |
---|
1375 | | - .cra_init = atmel_sha_cra_init, |
---|
1376 | | - } |
---|
1377 | | - } |
---|
| 1308 | + .halg.base.cra_name = "sha512", |
---|
| 1309 | + .halg.base.cra_driver_name = "atmel-sha512", |
---|
| 1310 | + .halg.base.cra_blocksize = SHA512_BLOCK_SIZE, |
---|
| 1311 | + .halg.base.cra_alignmask = 0x3, |
---|
| 1312 | + |
---|
| 1313 | + .halg.digestsize = SHA512_DIGEST_SIZE, |
---|
1378 | 1314 | }, |
---|
1379 | 1315 | }; |
---|
1380 | 1316 | |
---|
.. | .. |
---|
1398 | 1334 | if (SHA_FLAGS_DMA_ACTIVE & dd->flags) { |
---|
1399 | 1335 | dd->flags &= ~SHA_FLAGS_DMA_ACTIVE; |
---|
1400 | 1336 | atmel_sha_update_dma_stop(dd); |
---|
1401 | | - if (dd->err) { |
---|
1402 | | - err = dd->err; |
---|
1403 | | - goto finish; |
---|
1404 | | - } |
---|
1405 | 1337 | } |
---|
1406 | 1338 | if (SHA_FLAGS_OUTPUT_READY & dd->flags) { |
---|
1407 | 1339 | /* hash or semi-hash ready */ |
---|
.. | .. |
---|
1496 | 1428 | struct scatterlist *sg; |
---|
1497 | 1429 | int nents; |
---|
1498 | 1430 | |
---|
1499 | | - dmaengine_terminate_all(dma->chan); |
---|
1500 | 1431 | dma_unmap_sg(dd->dev, dma->sg, dma->nents, DMA_TO_DEVICE); |
---|
1501 | 1432 | |
---|
1502 | 1433 | sg = dma->sg; |
---|
.. | .. |
---|
2082 | 2013 | atmel_sha_hmac_key_release(&hmac->hkey); |
---|
2083 | 2014 | } |
---|
2084 | 2015 | |
---|
| 2016 | +static void atmel_sha_hmac_alg_init(struct ahash_alg *alg) |
---|
| 2017 | +{ |
---|
| 2018 | + alg->halg.base.cra_priority = ATMEL_SHA_PRIORITY; |
---|
| 2019 | + alg->halg.base.cra_flags = CRYPTO_ALG_ASYNC; |
---|
| 2020 | + alg->halg.base.cra_ctxsize = sizeof(struct atmel_sha_hmac_ctx); |
---|
| 2021 | + alg->halg.base.cra_module = THIS_MODULE; |
---|
| 2022 | + alg->halg.base.cra_init = atmel_sha_hmac_cra_init; |
---|
| 2023 | + alg->halg.base.cra_exit = atmel_sha_hmac_cra_exit; |
---|
| 2024 | + |
---|
| 2025 | + alg->halg.statesize = sizeof(struct atmel_sha_reqctx); |
---|
| 2026 | + |
---|
| 2027 | + alg->init = atmel_sha_hmac_init; |
---|
| 2028 | + alg->update = atmel_sha_update; |
---|
| 2029 | + alg->final = atmel_sha_final; |
---|
| 2030 | + alg->digest = atmel_sha_hmac_digest; |
---|
| 2031 | + alg->setkey = atmel_sha_hmac_setkey; |
---|
| 2032 | + alg->export = atmel_sha_export; |
---|
| 2033 | + alg->import = atmel_sha_import; |
---|
| 2034 | +} |
---|
| 2035 | + |
---|
2085 | 2036 | static struct ahash_alg sha_hmac_algs[] = { |
---|
2086 | 2037 | { |
---|
2087 | | - .init = atmel_sha_hmac_init, |
---|
2088 | | - .update = atmel_sha_update, |
---|
2089 | | - .final = atmel_sha_final, |
---|
2090 | | - .digest = atmel_sha_hmac_digest, |
---|
2091 | | - .setkey = atmel_sha_hmac_setkey, |
---|
2092 | | - .export = atmel_sha_export, |
---|
2093 | | - .import = atmel_sha_import, |
---|
2094 | | - .halg = { |
---|
2095 | | - .digestsize = SHA1_DIGEST_SIZE, |
---|
2096 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
2097 | | - .base = { |
---|
2098 | | - .cra_name = "hmac(sha1)", |
---|
2099 | | - .cra_driver_name = "atmel-hmac-sha1", |
---|
2100 | | - .cra_priority = 100, |
---|
2101 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
2102 | | - .cra_blocksize = SHA1_BLOCK_SIZE, |
---|
2103 | | - .cra_ctxsize = sizeof(struct atmel_sha_hmac_ctx), |
---|
2104 | | - .cra_alignmask = 0, |
---|
2105 | | - .cra_module = THIS_MODULE, |
---|
2106 | | - .cra_init = atmel_sha_hmac_cra_init, |
---|
2107 | | - .cra_exit = atmel_sha_hmac_cra_exit, |
---|
2108 | | - } |
---|
2109 | | - } |
---|
| 2038 | + .halg.base.cra_name = "hmac(sha1)", |
---|
| 2039 | + .halg.base.cra_driver_name = "atmel-hmac-sha1", |
---|
| 2040 | + .halg.base.cra_blocksize = SHA1_BLOCK_SIZE, |
---|
| 2041 | + |
---|
| 2042 | + .halg.digestsize = SHA1_DIGEST_SIZE, |
---|
2110 | 2043 | }, |
---|
2111 | 2044 | { |
---|
2112 | | - .init = atmel_sha_hmac_init, |
---|
2113 | | - .update = atmel_sha_update, |
---|
2114 | | - .final = atmel_sha_final, |
---|
2115 | | - .digest = atmel_sha_hmac_digest, |
---|
2116 | | - .setkey = atmel_sha_hmac_setkey, |
---|
2117 | | - .export = atmel_sha_export, |
---|
2118 | | - .import = atmel_sha_import, |
---|
2119 | | - .halg = { |
---|
2120 | | - .digestsize = SHA224_DIGEST_SIZE, |
---|
2121 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
2122 | | - .base = { |
---|
2123 | | - .cra_name = "hmac(sha224)", |
---|
2124 | | - .cra_driver_name = "atmel-hmac-sha224", |
---|
2125 | | - .cra_priority = 100, |
---|
2126 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
2127 | | - .cra_blocksize = SHA224_BLOCK_SIZE, |
---|
2128 | | - .cra_ctxsize = sizeof(struct atmel_sha_hmac_ctx), |
---|
2129 | | - .cra_alignmask = 0, |
---|
2130 | | - .cra_module = THIS_MODULE, |
---|
2131 | | - .cra_init = atmel_sha_hmac_cra_init, |
---|
2132 | | - .cra_exit = atmel_sha_hmac_cra_exit, |
---|
2133 | | - } |
---|
2134 | | - } |
---|
| 2045 | + .halg.base.cra_name = "hmac(sha224)", |
---|
| 2046 | + .halg.base.cra_driver_name = "atmel-hmac-sha224", |
---|
| 2047 | + .halg.base.cra_blocksize = SHA224_BLOCK_SIZE, |
---|
| 2048 | + |
---|
| 2049 | + .halg.digestsize = SHA224_DIGEST_SIZE, |
---|
2135 | 2050 | }, |
---|
2136 | 2051 | { |
---|
2137 | | - .init = atmel_sha_hmac_init, |
---|
2138 | | - .update = atmel_sha_update, |
---|
2139 | | - .final = atmel_sha_final, |
---|
2140 | | - .digest = atmel_sha_hmac_digest, |
---|
2141 | | - .setkey = atmel_sha_hmac_setkey, |
---|
2142 | | - .export = atmel_sha_export, |
---|
2143 | | - .import = atmel_sha_import, |
---|
2144 | | - .halg = { |
---|
2145 | | - .digestsize = SHA256_DIGEST_SIZE, |
---|
2146 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
2147 | | - .base = { |
---|
2148 | | - .cra_name = "hmac(sha256)", |
---|
2149 | | - .cra_driver_name = "atmel-hmac-sha256", |
---|
2150 | | - .cra_priority = 100, |
---|
2151 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
2152 | | - .cra_blocksize = SHA256_BLOCK_SIZE, |
---|
2153 | | - .cra_ctxsize = sizeof(struct atmel_sha_hmac_ctx), |
---|
2154 | | - .cra_alignmask = 0, |
---|
2155 | | - .cra_module = THIS_MODULE, |
---|
2156 | | - .cra_init = atmel_sha_hmac_cra_init, |
---|
2157 | | - .cra_exit = atmel_sha_hmac_cra_exit, |
---|
2158 | | - } |
---|
2159 | | - } |
---|
| 2052 | + .halg.base.cra_name = "hmac(sha256)", |
---|
| 2053 | + .halg.base.cra_driver_name = "atmel-hmac-sha256", |
---|
| 2054 | + .halg.base.cra_blocksize = SHA256_BLOCK_SIZE, |
---|
| 2055 | + |
---|
| 2056 | + .halg.digestsize = SHA256_DIGEST_SIZE, |
---|
2160 | 2057 | }, |
---|
2161 | 2058 | { |
---|
2162 | | - .init = atmel_sha_hmac_init, |
---|
2163 | | - .update = atmel_sha_update, |
---|
2164 | | - .final = atmel_sha_final, |
---|
2165 | | - .digest = atmel_sha_hmac_digest, |
---|
2166 | | - .setkey = atmel_sha_hmac_setkey, |
---|
2167 | | - .export = atmel_sha_export, |
---|
2168 | | - .import = atmel_sha_import, |
---|
2169 | | - .halg = { |
---|
2170 | | - .digestsize = SHA384_DIGEST_SIZE, |
---|
2171 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
2172 | | - .base = { |
---|
2173 | | - .cra_name = "hmac(sha384)", |
---|
2174 | | - .cra_driver_name = "atmel-hmac-sha384", |
---|
2175 | | - .cra_priority = 100, |
---|
2176 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
2177 | | - .cra_blocksize = SHA384_BLOCK_SIZE, |
---|
2178 | | - .cra_ctxsize = sizeof(struct atmel_sha_hmac_ctx), |
---|
2179 | | - .cra_alignmask = 0, |
---|
2180 | | - .cra_module = THIS_MODULE, |
---|
2181 | | - .cra_init = atmel_sha_hmac_cra_init, |
---|
2182 | | - .cra_exit = atmel_sha_hmac_cra_exit, |
---|
2183 | | - } |
---|
2184 | | - } |
---|
| 2059 | + .halg.base.cra_name = "hmac(sha384)", |
---|
| 2060 | + .halg.base.cra_driver_name = "atmel-hmac-sha384", |
---|
| 2061 | + .halg.base.cra_blocksize = SHA384_BLOCK_SIZE, |
---|
| 2062 | + |
---|
| 2063 | + .halg.digestsize = SHA384_DIGEST_SIZE, |
---|
2185 | 2064 | }, |
---|
2186 | 2065 | { |
---|
2187 | | - .init = atmel_sha_hmac_init, |
---|
2188 | | - .update = atmel_sha_update, |
---|
2189 | | - .final = atmel_sha_final, |
---|
2190 | | - .digest = atmel_sha_hmac_digest, |
---|
2191 | | - .setkey = atmel_sha_hmac_setkey, |
---|
2192 | | - .export = atmel_sha_export, |
---|
2193 | | - .import = atmel_sha_import, |
---|
2194 | | - .halg = { |
---|
2195 | | - .digestsize = SHA512_DIGEST_SIZE, |
---|
2196 | | - .statesize = sizeof(struct atmel_sha_reqctx), |
---|
2197 | | - .base = { |
---|
2198 | | - .cra_name = "hmac(sha512)", |
---|
2199 | | - .cra_driver_name = "atmel-hmac-sha512", |
---|
2200 | | - .cra_priority = 100, |
---|
2201 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
2202 | | - .cra_blocksize = SHA512_BLOCK_SIZE, |
---|
2203 | | - .cra_ctxsize = sizeof(struct atmel_sha_hmac_ctx), |
---|
2204 | | - .cra_alignmask = 0, |
---|
2205 | | - .cra_module = THIS_MODULE, |
---|
2206 | | - .cra_init = atmel_sha_hmac_cra_init, |
---|
2207 | | - .cra_exit = atmel_sha_hmac_cra_exit, |
---|
2208 | | - } |
---|
2209 | | - } |
---|
| 2066 | + .halg.base.cra_name = "hmac(sha512)", |
---|
| 2067 | + .halg.base.cra_driver_name = "atmel-hmac-sha512", |
---|
| 2068 | + .halg.base.cra_blocksize = SHA512_BLOCK_SIZE, |
---|
| 2069 | + |
---|
| 2070 | + .halg.digestsize = SHA512_DIGEST_SIZE, |
---|
2210 | 2071 | }, |
---|
2211 | 2072 | }; |
---|
2212 | 2073 | |
---|
.. | .. |
---|
2345 | 2206 | EXPORT_SYMBOL_GPL(atmel_sha_authenc_free); |
---|
2346 | 2207 | |
---|
2347 | 2208 | int atmel_sha_authenc_setkey(struct atmel_sha_authenc_ctx *auth, |
---|
2348 | | - const u8 *key, unsigned int keylen, |
---|
2349 | | - u32 *flags) |
---|
| 2209 | + const u8 *key, unsigned int keylen, u32 flags) |
---|
2350 | 2210 | { |
---|
2351 | 2211 | struct crypto_ahash *tfm = auth->tfm; |
---|
2352 | | - int err; |
---|
2353 | 2212 | |
---|
2354 | 2213 | crypto_ahash_clear_flags(tfm, CRYPTO_TFM_REQ_MASK); |
---|
2355 | | - crypto_ahash_set_flags(tfm, *flags & CRYPTO_TFM_REQ_MASK); |
---|
2356 | | - err = crypto_ahash_setkey(tfm, key, keylen); |
---|
2357 | | - *flags = crypto_ahash_get_flags(tfm); |
---|
2358 | | - |
---|
2359 | | - return err; |
---|
| 2214 | + crypto_ahash_set_flags(tfm, flags & CRYPTO_TFM_REQ_MASK); |
---|
| 2215 | + return crypto_ahash_setkey(tfm, key, keylen); |
---|
2360 | 2216 | } |
---|
2361 | 2217 | EXPORT_SYMBOL_GPL(atmel_sha_authenc_setkey); |
---|
2362 | 2218 | |
---|
.. | .. |
---|
2559 | 2415 | int err, i, j; |
---|
2560 | 2416 | |
---|
2561 | 2417 | for (i = 0; i < ARRAY_SIZE(sha_1_256_algs); i++) { |
---|
| 2418 | + atmel_sha_alg_init(&sha_1_256_algs[i]); |
---|
| 2419 | + |
---|
2562 | 2420 | err = crypto_register_ahash(&sha_1_256_algs[i]); |
---|
2563 | 2421 | if (err) |
---|
2564 | 2422 | goto err_sha_1_256_algs; |
---|
2565 | 2423 | } |
---|
2566 | 2424 | |
---|
2567 | 2425 | if (dd->caps.has_sha224) { |
---|
| 2426 | + atmel_sha_alg_init(&sha_224_alg); |
---|
| 2427 | + |
---|
2568 | 2428 | err = crypto_register_ahash(&sha_224_alg); |
---|
2569 | 2429 | if (err) |
---|
2570 | 2430 | goto err_sha_224_algs; |
---|
.. | .. |
---|
2572 | 2432 | |
---|
2573 | 2433 | if (dd->caps.has_sha_384_512) { |
---|
2574 | 2434 | for (i = 0; i < ARRAY_SIZE(sha_384_512_algs); i++) { |
---|
| 2435 | + atmel_sha_alg_init(&sha_384_512_algs[i]); |
---|
| 2436 | + |
---|
2575 | 2437 | err = crypto_register_ahash(&sha_384_512_algs[i]); |
---|
2576 | 2438 | if (err) |
---|
2577 | 2439 | goto err_sha_384_512_algs; |
---|
.. | .. |
---|
2580 | 2442 | |
---|
2581 | 2443 | if (dd->caps.has_hmac) { |
---|
2582 | 2444 | for (i = 0; i < ARRAY_SIZE(sha_hmac_algs); i++) { |
---|
| 2445 | + atmel_sha_hmac_alg_init(&sha_hmac_algs[i]); |
---|
| 2446 | + |
---|
2583 | 2447 | err = crypto_register_ahash(&sha_hmac_algs[i]); |
---|
2584 | 2448 | if (err) |
---|
2585 | 2449 | goto err_sha_hmac_algs; |
---|
.. | .. |
---|
2606 | 2470 | return err; |
---|
2607 | 2471 | } |
---|
2608 | 2472 | |
---|
2609 | | -static bool atmel_sha_filter(struct dma_chan *chan, void *slave) |
---|
| 2473 | +static int atmel_sha_dma_init(struct atmel_sha_dev *dd) |
---|
2610 | 2474 | { |
---|
2611 | | - struct at_dma_slave *sl = slave; |
---|
2612 | | - |
---|
2613 | | - if (sl && sl->dma_dev == chan->device->dev) { |
---|
2614 | | - chan->private = sl; |
---|
2615 | | - return true; |
---|
2616 | | - } else { |
---|
2617 | | - return false; |
---|
2618 | | - } |
---|
2619 | | -} |
---|
2620 | | - |
---|
2621 | | -static int atmel_sha_dma_init(struct atmel_sha_dev *dd, |
---|
2622 | | - struct crypto_platform_data *pdata) |
---|
2623 | | -{ |
---|
2624 | | - dma_cap_mask_t mask_in; |
---|
2625 | | - |
---|
2626 | | - /* Try to grab DMA channel */ |
---|
2627 | | - dma_cap_zero(mask_in); |
---|
2628 | | - dma_cap_set(DMA_SLAVE, mask_in); |
---|
2629 | | - |
---|
2630 | | - dd->dma_lch_in.chan = dma_request_slave_channel_compat(mask_in, |
---|
2631 | | - atmel_sha_filter, &pdata->dma_slave->rxdata, dd->dev, "tx"); |
---|
2632 | | - if (!dd->dma_lch_in.chan) { |
---|
2633 | | - dev_warn(dd->dev, "no DMA channel available\n"); |
---|
2634 | | - return -ENODEV; |
---|
| 2475 | + dd->dma_lch_in.chan = dma_request_chan(dd->dev, "tx"); |
---|
| 2476 | + if (IS_ERR(dd->dma_lch_in.chan)) { |
---|
| 2477 | + dev_err(dd->dev, "DMA channel is not available\n"); |
---|
| 2478 | + return PTR_ERR(dd->dma_lch_in.chan); |
---|
2635 | 2479 | } |
---|
2636 | 2480 | |
---|
2637 | | - dd->dma_lch_in.dma_conf.direction = DMA_MEM_TO_DEV; |
---|
2638 | 2481 | dd->dma_lch_in.dma_conf.dst_addr = dd->phys_base + |
---|
2639 | 2482 | SHA_REG_DIN(0); |
---|
2640 | 2483 | dd->dma_lch_in.dma_conf.src_maxburst = 1; |
---|
.. | .. |
---|
2707 | 2550 | }; |
---|
2708 | 2551 | |
---|
2709 | 2552 | MODULE_DEVICE_TABLE(of, atmel_sha_dt_ids); |
---|
2710 | | - |
---|
2711 | | -static struct crypto_platform_data *atmel_sha_of_init(struct platform_device *pdev) |
---|
2712 | | -{ |
---|
2713 | | - struct device_node *np = pdev->dev.of_node; |
---|
2714 | | - struct crypto_platform_data *pdata; |
---|
2715 | | - |
---|
2716 | | - if (!np) { |
---|
2717 | | - dev_err(&pdev->dev, "device node not found\n"); |
---|
2718 | | - return ERR_PTR(-EINVAL); |
---|
2719 | | - } |
---|
2720 | | - |
---|
2721 | | - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
---|
2722 | | - if (!pdata) |
---|
2723 | | - return ERR_PTR(-ENOMEM); |
---|
2724 | | - |
---|
2725 | | - pdata->dma_slave = devm_kzalloc(&pdev->dev, |
---|
2726 | | - sizeof(*(pdata->dma_slave)), |
---|
2727 | | - GFP_KERNEL); |
---|
2728 | | - if (!pdata->dma_slave) |
---|
2729 | | - return ERR_PTR(-ENOMEM); |
---|
2730 | | - |
---|
2731 | | - return pdata; |
---|
2732 | | -} |
---|
2733 | | -#else /* CONFIG_OF */ |
---|
2734 | | -static inline struct crypto_platform_data *atmel_sha_of_init(struct platform_device *dev) |
---|
2735 | | -{ |
---|
2736 | | - return ERR_PTR(-EINVAL); |
---|
2737 | | -} |
---|
2738 | 2553 | #endif |
---|
2739 | 2554 | |
---|
2740 | 2555 | static int atmel_sha_probe(struct platform_device *pdev) |
---|
2741 | 2556 | { |
---|
2742 | 2557 | struct atmel_sha_dev *sha_dd; |
---|
2743 | | - struct crypto_platform_data *pdata; |
---|
2744 | 2558 | struct device *dev = &pdev->dev; |
---|
2745 | 2559 | struct resource *sha_res; |
---|
2746 | 2560 | int err; |
---|
2747 | 2561 | |
---|
2748 | 2562 | sha_dd = devm_kzalloc(&pdev->dev, sizeof(*sha_dd), GFP_KERNEL); |
---|
2749 | | - if (sha_dd == NULL) { |
---|
2750 | | - err = -ENOMEM; |
---|
2751 | | - goto sha_dd_err; |
---|
2752 | | - } |
---|
| 2563 | + if (!sha_dd) |
---|
| 2564 | + return -ENOMEM; |
---|
2753 | 2565 | |
---|
2754 | 2566 | sha_dd->dev = dev; |
---|
2755 | 2567 | |
---|
.. | .. |
---|
2770 | 2582 | if (!sha_res) { |
---|
2771 | 2583 | dev_err(dev, "no MEM resource info\n"); |
---|
2772 | 2584 | err = -ENODEV; |
---|
2773 | | - goto res_err; |
---|
| 2585 | + goto err_tasklet_kill; |
---|
2774 | 2586 | } |
---|
2775 | 2587 | sha_dd->phys_base = sha_res->start; |
---|
2776 | 2588 | |
---|
2777 | 2589 | /* Get the IRQ */ |
---|
2778 | 2590 | sha_dd->irq = platform_get_irq(pdev, 0); |
---|
2779 | 2591 | if (sha_dd->irq < 0) { |
---|
2780 | | - dev_err(dev, "no IRQ resource info\n"); |
---|
2781 | 2592 | err = sha_dd->irq; |
---|
2782 | | - goto res_err; |
---|
| 2593 | + goto err_tasklet_kill; |
---|
2783 | 2594 | } |
---|
2784 | 2595 | |
---|
2785 | 2596 | err = devm_request_irq(&pdev->dev, sha_dd->irq, atmel_sha_irq, |
---|
2786 | 2597 | IRQF_SHARED, "atmel-sha", sha_dd); |
---|
2787 | 2598 | if (err) { |
---|
2788 | 2599 | dev_err(dev, "unable to request sha irq.\n"); |
---|
2789 | | - goto res_err; |
---|
| 2600 | + goto err_tasklet_kill; |
---|
2790 | 2601 | } |
---|
2791 | 2602 | |
---|
2792 | 2603 | /* Initializing the clock */ |
---|
.. | .. |
---|
2794 | 2605 | if (IS_ERR(sha_dd->iclk)) { |
---|
2795 | 2606 | dev_err(dev, "clock initialization failed.\n"); |
---|
2796 | 2607 | err = PTR_ERR(sha_dd->iclk); |
---|
2797 | | - goto res_err; |
---|
| 2608 | + goto err_tasklet_kill; |
---|
2798 | 2609 | } |
---|
2799 | 2610 | |
---|
2800 | 2611 | sha_dd->io_base = devm_ioremap_resource(&pdev->dev, sha_res); |
---|
2801 | 2612 | if (IS_ERR(sha_dd->io_base)) { |
---|
2802 | 2613 | dev_err(dev, "can't ioremap\n"); |
---|
2803 | 2614 | err = PTR_ERR(sha_dd->io_base); |
---|
2804 | | - goto res_err; |
---|
| 2615 | + goto err_tasklet_kill; |
---|
2805 | 2616 | } |
---|
2806 | 2617 | |
---|
2807 | 2618 | err = clk_prepare(sha_dd->iclk); |
---|
2808 | 2619 | if (err) |
---|
2809 | | - goto res_err; |
---|
| 2620 | + goto err_tasklet_kill; |
---|
2810 | 2621 | |
---|
2811 | | - atmel_sha_hw_version_init(sha_dd); |
---|
| 2622 | + err = atmel_sha_hw_version_init(sha_dd); |
---|
| 2623 | + if (err) |
---|
| 2624 | + goto err_iclk_unprepare; |
---|
2812 | 2625 | |
---|
2813 | 2626 | atmel_sha_get_cap(sha_dd); |
---|
2814 | 2627 | |
---|
2815 | 2628 | if (sha_dd->caps.has_dma) { |
---|
2816 | | - pdata = pdev->dev.platform_data; |
---|
2817 | | - if (!pdata) { |
---|
2818 | | - pdata = atmel_sha_of_init(pdev); |
---|
2819 | | - if (IS_ERR(pdata)) { |
---|
2820 | | - dev_err(&pdev->dev, "platform data not available\n"); |
---|
2821 | | - err = PTR_ERR(pdata); |
---|
2822 | | - goto iclk_unprepare; |
---|
2823 | | - } |
---|
2824 | | - } |
---|
2825 | | - if (!pdata->dma_slave) { |
---|
2826 | | - err = -ENXIO; |
---|
2827 | | - goto iclk_unprepare; |
---|
2828 | | - } |
---|
2829 | | - err = atmel_sha_dma_init(sha_dd, pdata); |
---|
| 2629 | + err = atmel_sha_dma_init(sha_dd); |
---|
2830 | 2630 | if (err) |
---|
2831 | | - goto err_sha_dma; |
---|
| 2631 | + goto err_iclk_unprepare; |
---|
2832 | 2632 | |
---|
2833 | 2633 | dev_info(dev, "using %s for DMA transfers\n", |
---|
2834 | 2634 | dma_chan_name(sha_dd->dma_lch_in.chan)); |
---|
.. | .. |
---|
2854 | 2654 | spin_unlock(&atmel_sha.lock); |
---|
2855 | 2655 | if (sha_dd->caps.has_dma) |
---|
2856 | 2656 | atmel_sha_dma_cleanup(sha_dd); |
---|
2857 | | -err_sha_dma: |
---|
2858 | | -iclk_unprepare: |
---|
| 2657 | +err_iclk_unprepare: |
---|
2859 | 2658 | clk_unprepare(sha_dd->iclk); |
---|
2860 | | -res_err: |
---|
| 2659 | +err_tasklet_kill: |
---|
2861 | 2660 | tasklet_kill(&sha_dd->queue_task); |
---|
2862 | 2661 | tasklet_kill(&sha_dd->done_task); |
---|
2863 | | -sha_dd_err: |
---|
2864 | | - dev_err(dev, "initialization failed.\n"); |
---|
2865 | 2662 | |
---|
2866 | 2663 | return err; |
---|
2867 | 2664 | } |
---|