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 <larper@axis.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Lars Persson 2019-01-23 12:59:41 +01:00 committed by Herbert Xu
parent 971108c3a8
commit f68deebabe

View File

@ -135,7 +135,6 @@
#define regk_crypto_ext 0x00000001 #define regk_crypto_ext 0x00000001
#define regk_crypto_hmac_sha1 0x00000007 #define regk_crypto_hmac_sha1 0x00000007
#define regk_crypto_hmac_sha256 0x00000009 #define regk_crypto_hmac_sha256 0x00000009
#define regk_crypto_hmac_sha512 0x0000000d
#define regk_crypto_init 0x00000000 #define regk_crypto_init 0x00000000
#define regk_crypto_key_128 0x00000000 #define regk_crypto_key_128 0x00000000
#define regk_crypto_key_192 0x00000001 #define regk_crypto_key_192 0x00000001
@ -143,7 +142,6 @@
#define regk_crypto_null 0x00000000 #define regk_crypto_null 0x00000000
#define regk_crypto_sha1 0x00000006 #define regk_crypto_sha1 0x00000006
#define regk_crypto_sha256 0x00000008 #define regk_crypto_sha256 0x00000008
#define regk_crypto_sha512 0x0000000c
/* DMA descriptor structures */ /* DMA descriptor structures */
struct pdma_descr_ctrl { struct pdma_descr_ctrl {
@ -188,7 +186,6 @@ struct pdma_stat_descr {
/* Hash modes (including HMAC variants) */ /* Hash modes (including HMAC variants) */
#define ARTPEC6_CRYPTO_HASH_SHA1 1 #define ARTPEC6_CRYPTO_HASH_SHA1 1
#define ARTPEC6_CRYPTO_HASH_SHA256 2 #define ARTPEC6_CRYPTO_HASH_SHA256 2
#define ARTPEC6_CRYPTO_HASH_SHA512 4
/* Crypto modes */ /* Crypto modes */
#define ARTPEC6_CRYPTO_CIPHER_AES_ECB 1 #define ARTPEC6_CRYPTO_CIPHER_AES_ECB 1
@ -288,11 +285,11 @@ struct artpec6_crypto_req_common {
}; };
struct artpec6_hash_request_context { struct artpec6_hash_request_context {
char partial_buffer[SHA512_BLOCK_SIZE]; char partial_buffer[SHA256_BLOCK_SIZE];
char partial_buffer_out[SHA512_BLOCK_SIZE]; char partial_buffer_out[SHA256_BLOCK_SIZE];
char key_buffer[SHA512_BLOCK_SIZE]; char key_buffer[SHA256_BLOCK_SIZE];
char pad_buffer[SHA512_BLOCK_SIZE + 32]; char pad_buffer[SHA256_BLOCK_SIZE + 32];
unsigned char digeststate[SHA512_DIGEST_SIZE]; unsigned char digeststate[SHA256_DIGEST_SIZE];
size_t partial_bytes; size_t partial_bytes;
u64 digcnt; u64 digcnt;
u32 key_md; u32 key_md;
@ -302,8 +299,8 @@ struct artpec6_hash_request_context {
}; };
struct artpec6_hash_export_state { struct artpec6_hash_export_state {
char partial_buffer[SHA512_BLOCK_SIZE]; char partial_buffer[SHA256_BLOCK_SIZE];
unsigned char digeststate[SHA512_DIGEST_SIZE]; unsigned char digeststate[SHA256_DIGEST_SIZE];
size_t partial_bytes; size_t partial_bytes;
u64 digcnt; u64 digcnt;
int oper; int oper;
@ -311,7 +308,7 @@ struct artpec6_hash_export_state {
}; };
struct artpec6_hashalg_context { struct artpec6_hashalg_context {
char hmac_key[SHA512_BLOCK_SIZE]; char hmac_key[SHA256_BLOCK_SIZE];
size_t hmac_key_length; size_t hmac_key_length;
struct crypto_shash *child_hash; struct crypto_shash *child_hash;
}; };
@ -2252,10 +2249,6 @@ artpec6_crypto_init_hash(struct ahash_request *req, u8 type, int hmac)
case ARTPEC6_CRYPTO_HASH_SHA256: case ARTPEC6_CRYPTO_HASH_SHA256:
oper = hmac ? regk_crypto_hmac_sha256 : regk_crypto_sha256; oper = hmac ? regk_crypto_hmac_sha256 : regk_crypto_sha256;
break; break;
case ARTPEC6_CRYPTO_HASH_SHA512:
oper = hmac ? regk_crypto_hmac_sha512 : regk_crypto_sha512;
break;
default: default:
pr_err("%s: Unsupported hash type 0x%x\n", MODULE_NAME, type); pr_err("%s: Unsupported hash type 0x%x\n", MODULE_NAME, type);
return -EINVAL; return -EINVAL;
@ -2351,31 +2344,11 @@ static int artpec6_crypto_sha256_digest(struct ahash_request *req)
return artpec6_crypto_prepare_submit_hash(req); return artpec6_crypto_prepare_submit_hash(req);
} }
static int artpec6_crypto_sha512_init(struct ahash_request *req)
{
return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 0);
}
static int artpec6_crypto_sha512_digest(struct ahash_request *req)
{
struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 0);
req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
return artpec6_crypto_prepare_submit_hash(req);
}
static int artpec6_crypto_hmac_sha256_init(struct ahash_request *req) static int artpec6_crypto_hmac_sha256_init(struct ahash_request *req)
{ {
return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA256, 1); return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA256, 1);
} }
static int artpec6_crypto_hmac_sha512_init(struct ahash_request *req)
{
return artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 1);
}
static int artpec6_crypto_hmac_sha256_digest(struct ahash_request *req) static int artpec6_crypto_hmac_sha256_digest(struct ahash_request *req)
{ {
struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req); 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)
return artpec6_crypto_prepare_submit_hash(req); return artpec6_crypto_prepare_submit_hash(req);
} }
static int artpec6_crypto_hmac_sha512_digest(struct ahash_request *req)
{
struct artpec6_hash_request_context *req_ctx = ahash_request_ctx(req);
artpec6_crypto_init_hash(req, ARTPEC6_CRYPTO_HASH_SHA512, 1);
req_ctx->hash_flags |= HASH_FLAG_UPDATE | HASH_FLAG_FINALIZE;
return artpec6_crypto_prepare_submit_hash(req);
}
static int artpec6_crypto_ahash_init_common(struct crypto_tfm *tfm, static int artpec6_crypto_ahash_init_common(struct crypto_tfm *tfm,
const char *base_hash_name) const char *base_hash_name)
{ {
@ -2430,11 +2393,6 @@ static int artpec6_crypto_ahash_init_hmac_sha256(struct crypto_tfm *tfm)
return artpec6_crypto_ahash_init_common(tfm, "sha256"); return artpec6_crypto_ahash_init_common(tfm, "sha256");
} }
static int artpec6_crypto_ahash_init_hmac_sha512(struct crypto_tfm *tfm)
{
return artpec6_crypto_ahash_init_common(tfm, "sha512");
}
static void artpec6_crypto_ahash_exit(struct crypto_tfm *tfm) static void artpec6_crypto_ahash_exit(struct crypto_tfm *tfm)
{ {
struct artpec6_hashalg_context *tfm_ctx = crypto_tfm_ctx(tfm); struct artpec6_hashalg_context *tfm_ctx = crypto_tfm_ctx(tfm);
@ -2705,56 +2663,6 @@ static struct ahash_alg hash_algos[] = {
}, },
}; };
static struct ahash_alg artpec7_hash_algos[] = {
/* SHA-512 */
{
.init = artpec6_crypto_sha512_init,
.update = artpec6_crypto_hash_update,
.final = artpec6_crypto_hash_final,
.digest = artpec6_crypto_sha512_digest,
.import = artpec6_crypto_hash_import,
.export = artpec6_crypto_hash_export,
.halg.digestsize = SHA512_DIGEST_SIZE,
.halg.statesize = sizeof(struct artpec6_hash_export_state),
.halg.base = {
.cra_name = "sha512",
.cra_driver_name = "artpec-sha512",
.cra_priority = 300,
.cra_flags = CRYPTO_ALG_ASYNC,
.cra_blocksize = SHA512_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct artpec6_hashalg_context),
.cra_alignmask = 3,
.cra_module = THIS_MODULE,
.cra_init = artpec6_crypto_ahash_init,
.cra_exit = artpec6_crypto_ahash_exit,
}
},
/* HMAC SHA-512 */
{
.init = artpec6_crypto_hmac_sha512_init,
.update = artpec6_crypto_hash_update,
.final = artpec6_crypto_hash_final,
.digest = artpec6_crypto_hmac_sha512_digest,
.import = artpec6_crypto_hash_import,
.export = artpec6_crypto_hash_export,
.setkey = artpec6_crypto_hash_set_key,
.halg.digestsize = SHA512_DIGEST_SIZE,
.halg.statesize = sizeof(struct artpec6_hash_export_state),
.halg.base = {
.cra_name = "hmac(sha512)",
.cra_driver_name = "artpec-hmac-sha512",
.cra_priority = 300,
.cra_flags = CRYPTO_ALG_ASYNC,
.cra_blocksize = SHA512_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct artpec6_hashalg_context),
.cra_alignmask = 3,
.cra_module = THIS_MODULE,
.cra_init = artpec6_crypto_ahash_init_hmac_sha512,
.cra_exit = artpec6_crypto_ahash_exit,
}
},
};
/* Crypto */ /* Crypto */
static struct skcipher_alg crypto_algos[] = { static struct skcipher_alg crypto_algos[] = {
/* AES - ECB */ /* AES - ECB */
@ -2992,19 +2900,10 @@ static int artpec6_crypto_probe(struct platform_device *pdev)
goto disable_hw; goto disable_hw;
} }
if (variant != ARTPEC6_CRYPTO) {
err = crypto_register_ahashes(artpec7_hash_algos,
ARRAY_SIZE(artpec7_hash_algos));
if (err) {
dev_err(dev, "Failed to register ahashes\n");
goto unregister_ahashes;
}
}
err = crypto_register_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos)); err = crypto_register_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
if (err) { if (err) {
dev_err(dev, "Failed to register ciphers\n"); dev_err(dev, "Failed to register ciphers\n");
goto unregister_a7_ahashes; goto unregister_ahashes;
} }
err = crypto_register_aeads(aead_algos, ARRAY_SIZE(aead_algos)); err = crypto_register_aeads(aead_algos, ARRAY_SIZE(aead_algos));
@ -3017,10 +2916,6 @@ static int artpec6_crypto_probe(struct platform_device *pdev)
unregister_algs: unregister_algs:
crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos)); crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
unregister_a7_ahashes:
if (variant != ARTPEC6_CRYPTO)
crypto_unregister_ahashes(artpec7_hash_algos,
ARRAY_SIZE(artpec7_hash_algos));
unregister_ahashes: unregister_ahashes:
crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos)); crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos));
disable_hw: disable_hw:
@ -3036,9 +2931,6 @@ static int artpec6_crypto_remove(struct platform_device *pdev)
int irq = platform_get_irq(pdev, 0); int irq = platform_get_irq(pdev, 0);
crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos)); crypto_unregister_ahashes(hash_algos, ARRAY_SIZE(hash_algos));
if (ac->variant != ARTPEC6_CRYPTO)
crypto_unregister_ahashes(artpec7_hash_algos,
ARRAY_SIZE(artpec7_hash_algos));
crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos)); crypto_unregister_skciphers(crypto_algos, ARRAY_SIZE(crypto_algos));
crypto_unregister_aeads(aead_algos, ARRAY_SIZE(aead_algos)); crypto_unregister_aeads(aead_algos, ARRAY_SIZE(aead_algos));