Skip to content

Commit c5a2f74

Browse files
jaingaurav2712herbertx
authored andcommitted
crypto: caam - fix asynchronous hash
ahash_alg->setkey is updated to ahash_nosetkey in ahash.c so checking setkey() function to determine hmac algorithm is not valid. to fix this added is_hmac variable in structure caam_hash_alg to determine whether the algorithm is hmac or not. Fixes: 2f1f34c ("crypto: ahash - optimize performance when wrapping shash") Signed-off-by: Gaurav Jain <[email protected]> Reviewed-by: Eric Biggers <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent e1d54d1 commit c5a2f74

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

drivers/crypto/caam/caamalg_qi2.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4545,6 +4545,7 @@ struct caam_hash_alg {
45454545
struct list_head entry;
45464546
struct device *dev;
45474547
int alg_type;
4548+
bool is_hmac;
45484549
struct ahash_alg ahash_alg;
45494550
};
45504551

@@ -4571,7 +4572,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
45714572

45724573
ctx->dev = caam_hash->dev;
45734574

4574-
if (alg->setkey) {
4575+
if (caam_hash->is_hmac) {
45754576
ctx->adata.key_dma = dma_map_single_attrs(ctx->dev, ctx->key,
45764577
ARRAY_SIZE(ctx->key),
45774578
DMA_TO_DEVICE,
@@ -4611,7 +4612,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
46114612
* For keyed hash algorithms shared descriptors
46124613
* will be created later in setkey() callback
46134614
*/
4614-
return alg->setkey ? 0 : ahash_set_sh_desc(ahash);
4615+
return caam_hash->is_hmac ? 0 : ahash_set_sh_desc(ahash);
46154616
}
46164617

46174618
static void caam_hash_cra_exit(struct crypto_tfm *tfm)
@@ -4646,12 +4647,14 @@ static struct caam_hash_alg *caam_hash_alloc(struct device *dev,
46464647
template->hmac_name);
46474648
snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
46484649
template->hmac_driver_name);
4650+
t_alg->is_hmac = true;
46494651
} else {
46504652
snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
46514653
template->name);
46524654
snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
46534655
template->driver_name);
46544656
t_alg->ahash_alg.setkey = NULL;
4657+
t_alg->is_hmac = false;
46554658
}
46564659
alg->cra_module = THIS_MODULE;
46574660
alg->cra_init = caam_hash_cra_init;

drivers/crypto/caam/caamhash.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,7 @@ static struct caam_hash_template driver_hash[] = {
17531753
struct caam_hash_alg {
17541754
struct list_head entry;
17551755
int alg_type;
1756+
bool is_hmac;
17561757
struct ahash_engine_alg ahash_alg;
17571758
};
17581759

@@ -1804,7 +1805,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
18041805
} else {
18051806
if (priv->era >= 6) {
18061807
ctx->dir = DMA_BIDIRECTIONAL;
1807-
ctx->key_dir = alg->setkey ? DMA_TO_DEVICE : DMA_NONE;
1808+
ctx->key_dir = caam_hash->is_hmac ? DMA_TO_DEVICE : DMA_NONE;
18081809
} else {
18091810
ctx->dir = DMA_TO_DEVICE;
18101811
ctx->key_dir = DMA_NONE;
@@ -1862,7 +1863,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
18621863
* For keyed hash algorithms shared descriptors
18631864
* will be created later in setkey() callback
18641865
*/
1865-
return alg->setkey ? 0 : ahash_set_sh_desc(ahash);
1866+
return caam_hash->is_hmac ? 0 : ahash_set_sh_desc(ahash);
18661867
}
18671868

18681869
static void caam_hash_cra_exit(struct crypto_tfm *tfm)
@@ -1915,12 +1916,14 @@ caam_hash_alloc(struct caam_hash_template *template,
19151916
template->hmac_name);
19161917
snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
19171918
template->hmac_driver_name);
1919+
t_alg->is_hmac = true;
19181920
} else {
19191921
snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
19201922
template->name);
19211923
snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
19221924
template->driver_name);
19231925
halg->setkey = NULL;
1926+
t_alg->is_hmac = false;
19241927
}
19251928
alg->cra_module = THIS_MODULE;
19261929
alg->cra_init = caam_hash_cra_init;

0 commit comments

Comments
 (0)