summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/crypto/caam/caamalg_qi2.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c
index 844dd9a20486..33a4df6b81de 100644
--- a/drivers/crypto/caam/caamalg_qi2.c
+++ b/drivers/crypto/caam/caamalg_qi2.c
@@ -3060,13 +3060,13 @@ static void split_key_sh_done(void *cbk_ctx, u32 err)
3060} 3060}
3061 3061
3062/* Digest hash size if it is too large */ 3062/* Digest hash size if it is too large */
3063static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in, 3063static int hash_digest_key(struct caam_hash_ctx *ctx, u32 *keylen, u8 *key,
3064 u32 *keylen, u8 *key_out, u32 digestsize) 3064 u32 digestsize)
3065{ 3065{
3066 struct caam_request *req_ctx; 3066 struct caam_request *req_ctx;
3067 u32 *desc; 3067 u32 *desc;
3068 struct split_key_sh_result result; 3068 struct split_key_sh_result result;
3069 dma_addr_t src_dma, dst_dma; 3069 dma_addr_t key_dma;
3070 struct caam_flc *flc; 3070 struct caam_flc *flc;
3071 dma_addr_t flc_dma; 3071 dma_addr_t flc_dma;
3072 int ret = -ENOMEM; 3072 int ret = -ENOMEM;
@@ -3083,17 +3083,10 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in,
3083 if (!flc) 3083 if (!flc)
3084 goto err_flc; 3084 goto err_flc;
3085 3085
3086 src_dma = dma_map_single(ctx->dev, (void *)key_in, *keylen, 3086 key_dma = dma_map_single(ctx->dev, key, *keylen, DMA_BIDIRECTIONAL);
3087 DMA_TO_DEVICE); 3087 if (dma_mapping_error(ctx->dev, key_dma)) {
3088 if (dma_mapping_error(ctx->dev, src_dma)) { 3088 dev_err(ctx->dev, "unable to map key memory\n");
3089 dev_err(ctx->dev, "unable to map key input memory\n"); 3089 goto err_key_dma;
3090 goto err_src_dma;
3091 }
3092 dst_dma = dma_map_single(ctx->dev, (void *)key_out, digestsize,
3093 DMA_FROM_DEVICE);
3094 if (dma_mapping_error(ctx->dev, dst_dma)) {
3095 dev_err(ctx->dev, "unable to map key output memory\n");
3096 goto err_dst_dma;
3097 } 3090 }
3098 3091
3099 desc = flc->sh_desc; 3092 desc = flc->sh_desc;
@@ -3118,14 +3111,14 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in,
3118 3111
3119 dpaa2_fl_set_final(in_fle, true); 3112 dpaa2_fl_set_final(in_fle, true);
3120 dpaa2_fl_set_format(in_fle, dpaa2_fl_single); 3113 dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
3121 dpaa2_fl_set_addr(in_fle, src_dma); 3114 dpaa2_fl_set_addr(in_fle, key_dma);
3122 dpaa2_fl_set_len(in_fle, *keylen); 3115 dpaa2_fl_set_len(in_fle, *keylen);
3123 dpaa2_fl_set_format(out_fle, dpaa2_fl_single); 3116 dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
3124 dpaa2_fl_set_addr(out_fle, dst_dma); 3117 dpaa2_fl_set_addr(out_fle, key_dma);
3125 dpaa2_fl_set_len(out_fle, digestsize); 3118 dpaa2_fl_set_len(out_fle, digestsize);
3126 3119
3127 print_hex_dump_debug("key_in@" __stringify(__LINE__)": ", 3120 print_hex_dump_debug("key_in@" __stringify(__LINE__)": ",
3128 DUMP_PREFIX_ADDRESS, 16, 4, key_in, *keylen, 1); 3121 DUMP_PREFIX_ADDRESS, 16, 4, key, *keylen, 1);
3129 print_hex_dump_debug("shdesc@" __stringify(__LINE__)": ", 3122 print_hex_dump_debug("shdesc@" __stringify(__LINE__)": ",
3130 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 3123 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
3131 1); 3124 1);
@@ -3145,17 +3138,15 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in,
3145 wait_for_completion(&result.completion); 3138 wait_for_completion(&result.completion);
3146 ret = result.err; 3139 ret = result.err;
3147 print_hex_dump_debug("digested key@" __stringify(__LINE__)": ", 3140 print_hex_dump_debug("digested key@" __stringify(__LINE__)": ",
3148 DUMP_PREFIX_ADDRESS, 16, 4, key_in, 3141 DUMP_PREFIX_ADDRESS, 16, 4, key,
3149 digestsize, 1); 3142 digestsize, 1);
3150 } 3143 }
3151 3144
3152 dma_unmap_single(ctx->dev, flc_dma, sizeof(flc->flc) + desc_bytes(desc), 3145 dma_unmap_single(ctx->dev, flc_dma, sizeof(flc->flc) + desc_bytes(desc),
3153 DMA_TO_DEVICE); 3146 DMA_TO_DEVICE);
3154err_flc_dma: 3147err_flc_dma:
3155 dma_unmap_single(ctx->dev, dst_dma, digestsize, DMA_FROM_DEVICE); 3148 dma_unmap_single(ctx->dev, key_dma, *keylen, DMA_BIDIRECTIONAL);
3156err_dst_dma: 3149err_key_dma:
3157 dma_unmap_single(ctx->dev, src_dma, *keylen, DMA_TO_DEVICE);
3158err_src_dma:
3159 kfree(flc); 3150 kfree(flc);
3160err_flc: 3151err_flc:
3161 kfree(req_ctx); 3152 kfree(req_ctx);
@@ -3177,12 +3168,10 @@ static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key,
3177 dev_dbg(ctx->dev, "keylen %d blocksize %d\n", keylen, blocksize); 3168 dev_dbg(ctx->dev, "keylen %d blocksize %d\n", keylen, blocksize);
3178 3169
3179 if (keylen > blocksize) { 3170 if (keylen > blocksize) {
3180 hashed_key = kmalloc_array(digestsize, sizeof(*hashed_key), 3171 hashed_key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA);
3181 GFP_KERNEL | GFP_DMA);
3182 if (!hashed_key) 3172 if (!hashed_key)
3183 return -ENOMEM; 3173 return -ENOMEM;
3184 ret = hash_digest_key(ctx, key, &keylen, hashed_key, 3174 ret = hash_digest_key(ctx, &keylen, hashed_key, digestsize);
3185 digestsize);
3186 if (ret) 3175 if (ret)
3187 goto bad_free_key; 3176 goto bad_free_key;
3188 key = hashed_key; 3177 key = hashed_key;