Skip to content

Commit f68deeb

Browse files
larperaxisherbertx
authored andcommitted
crypto: axis - remove sha512 support for artpec7
The hardware cannot restore the context correctly when it operates in SHA512 mode. This is too restrictive when operating in a framework that can interleave multiple hash sessions. Signed-off-by: Lars Persson <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 971108c commit f68deeb

File tree

1 file changed

+9
-117
lines changed

1 file changed

+9
-117
lines changed

drivers/crypto/axis/artpec6_crypto.c

Lines changed: 9 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,13 @@
135135
#define regk_crypto_ext 0x00000001
136136
#define regk_crypto_hmac_sha1 0x00000007
137137
#define regk_crypto_hmac_sha256 0x00000009
138-
#define regk_crypto_hmac_sha512 0x0000000d
139138
#define regk_crypto_init 0x00000000
140139
#define regk_crypto_key_128 0x00000000
141140
#define regk_crypto_key_192 0x00000001
142141
#define regk_crypto_key_256 0x00000002
143142
#define regk_crypto_null 0x00000000
144143
#define regk_crypto_sha1 0x00000006
145144
#define regk_crypto_sha256 0x00000008
146-
#define regk_crypto_sha512 0x0000000c
147145

148146
/* DMA descriptor structures */
149147
struct pdma_descr_ctrl {
@@ -188,7 +186,6 @@ struct pdma_stat_descr {
188186
/* Hash modes (including HMAC variants) */
189187
#define ARTPEC6_CRYPTO_HASH_SHA1 1
190188
#define ARTPEC6_CRYPTO_HASH_SHA256 2
191-
#define ARTPEC6_CRYPTO_HASH_SHA512 4
192189

193190
/* Crypto modes */
194191
#define ARTPEC6_CRYPTO_CIPHER_AES_ECB 1
@@ -288,11 +285,11 @@ struct artpec6_crypto_req_common {
288285
};
289286

290287
struct artpec6_hash_request_context {
291-
char partial_buffer[SHA512_BLOCK_SIZE];
292-
char partial_buffer_out[SHA512_BLOCK_SIZE];
293-
char key_buffer[SHA512_BLOCK_SIZE];
294-
char pad_buffer[SHA512_BLOCK_SIZE + 32];
295-
unsigned char digeststate[SHA512_DIGEST_SIZE];
288+
char partial_buffer[SHA256_BLOCK_SIZE];
289+
char partial_buffer_out[SHA256_BLOCK_SIZE];
290+
char key_buffer[SHA256_BLOCK_SIZE];
291+
char pad_buffer[SHA256_BLOCK_SIZE + 32];
292+
unsigned char digeststate[SHA256_DIGEST_SIZE];
296293
size_t partial_bytes;
297294
u64 digcnt;
298295
u32 key_md;
@@ -302,16 +299,16 @@ struct artpec6_hash_request_context {
302299
};
303300

304301
struct artpec6_hash_export_state {
305-
char partial_buffer[SHA512_BLOCK_SIZE];
306-
unsigned char digeststate[SHA512_DIGEST_SIZE];
302+
char partial_buffer[SHA256_BLOCK_SIZE];
303+
unsigned char digeststate[SHA256_DIGEST_SIZE];
307304
size_t partial_bytes;
308305
u64 digcnt;
309306
int oper;
310307
unsigned int hash_flags;
311308
};
312309

313310
struct artpec6_hashalg_context {
314-
char hmac_key[SHA512_BLOCK_SIZE];
311+
char hmac_key[SHA256_BLOCK_SIZE];
315312
size_t hmac_key_length;
316313
struct crypto_shash *child_hash;
317314
};
@@ -2252,10 +2249,6 @@ artpec6_crypto_init_hash(struct ahash_request *req, u8 type, int hmac)
22522249
case ARTPEC6_CRYPTO_HASH_SHA256:
22532250
oper = hmac ? regk_crypto_hmac_sha256 : regk_crypto_sha256;
22542251
break;
2255-
case ARTPEC6_CRYPTO_HASH_SHA512:
2256-
oper = hmac ? regk_crypto_hmac_sha512 : regk_crypto_sha512;
2257-
break;
2258-
22592252
default:
22602253
pr_err("%s: Unsupported hash type 0x%x\n", MODULE_NAME, type);
22612254
return -EINVAL;
@@ -2351,31 +2344,11 @@ static int artpec6_crypto_sha256_digest(struct ahash_request *req)
23512344
return artpec6_crypto_prepare_submit_hash(req);
23522345
}
23532346

2354-
static int artpec6_crypto_sha512_init(struct ahash_request *req)
2355-
{
2356-
return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 0);
2357-
}
2358-
2359-
static int artpec6_crypto_sha512_digest(struct ahash_request *req)
2360-
{
2361-
struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
2362-
2363-
artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 0);
2364-
req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
2365-
2366-
return artpec6_crypto_prepare_submit_hash(req);
2367-
}
2368-
23692347
static int artpec6_crypto_hmac_sha256_init(struct ahash_request *req)
23702348
{
23712349
return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA256, 1);
23722350
}
23732351

2374-
static int artpec6_crypto_hmac_sha512_init(struct ahash_request *req)
2375-
{
2376-
return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 1);
2377-
}
2378-
23792352
static int artpec6_crypto_hmac_sha256_digest(struct ahash_request *req)
23802353
{
23812354
struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
@@ -2386,16 +2359,6 @@ static int artpec6_crypto_hmac_sha256_digest(struct ahash_request *req)
23862359
return artpec6_crypto_prepare_submit_hash(req);
23872360
}
23882361

2389-
static int artpec6_crypto_hmac_sha512_digest(struct ahash_request *req)
2390-
{
2391-
struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
2392-
2393-
artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 1);
2394-
req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
2395-
2396-
return artpec6_crypto_prepare_submit_hash(req);
2397-
}
2398-
23992362
static int artpec6_crypto_ahash_init_common(struct crypto_tfm *tfm,
24002363
const char *base_hash_name)
24012364
{
@@ -2430,11 +2393,6 @@ static int artpec6_crypto_ahash_init_hmac_sha256(struct crypto_tfm *tfm)
24302393
return artpec6_crypto_ahash_init_common(tfm, "sha256");
24312394
}
24322395

2433-
static int artpec6_crypto_ahash_init_hmac_sha512(struct crypto_tfm *tfm)
2434-
{
2435-
return artpec6_crypto_ahash_init_common(tfm, "sha512");
2436-
}
2437-
24382396
static void artpec6_crypto_ahash_exit(struct crypto_tfm *tfm)
24392397
{
24402398
struct artpec6_hashalg_context *tfm_ctx = crypto_tfm_ctx(tfm);
@@ -2705,56 +2663,6 @@ static struct ahash_alg hash_algos[] = {
27052663
},
27062664
};
27072665

2708-
static struct ahash_alg artpec7_hash_algos[] = {
2709-
/* SHA-512 */
2710-
{
2711-
.init = artpec6_crypto_sha512_init,
2712-
.update = artpec6_crypto_hash_update,
2713-
.final = artpec6_crypto_hash_final,
2714-
.digest = artpec6_crypto_sha512_digest,
2715-
.import = artpec6_crypto_hash_import,
2716-
.export = artpec6_crypto_hash_export,
2717-
.halg.digestsize = SHA512_DIGEST_SIZE,
2718-
.halg.statesize = sizeof(struct artpec6_hash_export_state),
2719-
.halg.base = {
2720-
.cra_name = "sha512",
2721-
.cra_driver_name = "artpec-sha512",
2722-
.cra_priority = 300,
2723-
.cra_flags = CRYPTO_ALG_ASYNC,
2724-
.cra_blocksize = SHA512_BLOCK_SIZE,
2725-
.cra_ctxsize = sizeof(struct artpec6_hashalg_context),
2726-
.cra_alignmask = 3,
2727-
.cra_module = THIS_MODULE,
2728-
.cra_init = artpec6_crypto_ahash_init,
2729-
.cra_exit = artpec6_crypto_ahash_exit,
2730-
}
2731-
},
2732-
/* HMAC SHA-512 */
2733-
{
2734-
.init = artpec6_crypto_hmac_sha512_init,
2735-
.update = artpec6_crypto_hash_update,
2736-
.final = artpec6_crypto_hash_final,
2737-
.digest = artpec6_crypto_hmac_sha512_digest,
2738-
.import = artpec6_crypto_hash_import,
2739-
.export = artpec6_crypto_hash_export,
2740-
.setkey = artpec6_crypto_hash_set_key,
2741-
.halg.digestsize = SHA512_DIGEST_SIZE,
2742-
.halg.statesize = sizeof(struct artpec6_hash_export_state),
2743-
.halg.base = {
2744-
.cra_name = "hmac(sha512)",
2745-
.cra_driver_name = "artpec-hmac-sha512",
2746-
.cra_priority = 300,
2747-
.cra_flags = CRYPTO_ALG_ASYNC,
2748-
.cra_blocksize = SHA512_BLOCK_SIZE,
2749-
.cra_ctxsize = sizeof(struct artpec6_hashalg_context),
2750-
.cra_alignmask = 3,
2751-
.cra_module = THIS_MODULE,
2752-
.cra_init = artpec6_crypto_ahash_init_hmac_sha512,
2753-
.cra_exit = artpec6_crypto_ahash_exit,
2754-
}
2755-
},
2756-
};
2757-
27582666
/* Crypto */
27592667
static struct skcipher_alg crypto_algos[] = {
27602668
/* AES - ECB */
@@ -2992,19 +2900,10 @@ static int artpec6_crypto_probe(struct platform_device *pdev)
29922900
goto disable_hw;
29932901
}
29942902

2995-
if (variant != ARTPEC6_CRYPTO) {
2996-
err = crypto_register_ahashes(artpec7_hash_algos,
2997-
ARRAY_SIZE(artpec7_hash_algos));
2998-
if (err) {
2999-
dev_err(dev, "Failed to register ahashes\n");
3000-
goto unregister_ahashes;
3001-
}
3002-
}
3003-
30042903
err = crypto_register_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
30052904
if (err) {
30062905
dev_err(dev, "Failed to register ciphers\n");
3007-
goto unregister_a7_ahashes;
2906+
goto unregister_ahashes;
30082907
}
30092908

30102909
err = crypto_register_aeads(aead_algos, ARRAY_SIZE(aead_algos));
@@ -3017,10 +2916,6 @@ static int artpec6_crypto_probe(struct platform_device *pdev)
30172916

30182917
unregister_algs:
30192918
crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
3020-
unregister_a7_ahashes:
3021-
if (variant != ARTPEC6_CRYPTO)
3022-
crypto_unregister_ahashes(artpec7_hash_algos,
3023-
ARRAY_SIZE(artpec7_hash_algos));
30242919
unregister_ahashes:
30252920
crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos));
30262921
disable_hw:
@@ -3036,9 +2931,6 @@ static int artpec6_crypto_remove(struct platform_device *pdev)
30362931
int irq = platform_get_irq(pdev, 0);
30372932

30382933
crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos));
3039-
if (ac->variant != ARTPEC6_CRYPTO)
3040-
crypto_unregister_ahashes(artpec7_hash_algos,
3041-
ARRAY_SIZE(artpec7_hash_algos));
30422934
crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
30432935
crypto_unregister_aeads(aead_algos, ARRAY_SIZE(aead_algos));
30442936

0 commit comments

Comments
 (0)