Commit 98b10235 authored by Ryder Lee's avatar Ryder Lee Committed by Herbert Xu

crypto: mediatek - add mtk_aes_gcm_tag_verify()

This patch adds mtk_aes_gcm_tag_verify() which is used to compare
authenticated tag.
Signed-off-by: default avatarRyder Lee <ryder.lee@mediatek.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 5041d714
...@@ -70,6 +70,8 @@ ...@@ -70,6 +70,8 @@
#define AES_FLAGS_ENCRYPT BIT(4) #define AES_FLAGS_ENCRYPT BIT(4)
#define AES_FLAGS_BUSY BIT(5) #define AES_FLAGS_BUSY BIT(5)
#define AES_AUTH_TAG_ERR cpu_to_le32(BIT(26))
/** /**
* Command token(CT) is a set of hardware instructions that * Command token(CT) is a set of hardware instructions that
* are used to control engine's processing flow of AES. * are used to control engine's processing flow of AES.
...@@ -306,6 +308,9 @@ static int mtk_aes_xmit(struct mtk_cryp *cryp, struct mtk_aes_rec *aes) ...@@ -306,6 +308,9 @@ static int mtk_aes_xmit(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
} }
res->hdr |= MTK_DESC_LAST; res->hdr |= MTK_DESC_LAST;
/* Pointer to current result descriptor */
ring->res_prev = res;
/* Prepare enough space for authenticated tag */ /* Prepare enough space for authenticated tag */
if (aes->flags & AES_FLAGS_GCM) if (aes->flags & AES_FLAGS_GCM)
res->hdr += AES_BLOCK_SIZE; res->hdr += AES_BLOCK_SIZE;
...@@ -799,6 +804,19 @@ mtk_aes_gcm_ctx_cast(struct mtk_aes_base_ctx *ctx) ...@@ -799,6 +804,19 @@ mtk_aes_gcm_ctx_cast(struct mtk_aes_base_ctx *ctx)
return container_of(ctx, struct mtk_aes_gcm_ctx, base); return container_of(ctx, struct mtk_aes_gcm_ctx, base);
} }
/*
* Engine will verify and compare tag automatically, so we just need
* to check returned status which stored in the result descriptor.
*/
static int mtk_aes_gcm_tag_verify(struct mtk_cryp *cryp,
struct mtk_aes_rec *aes)
{
u32 status = cryp->ring[aes->id]->res_prev->ct;
return mtk_aes_complete(cryp, aes, (status & AES_AUTH_TAG_ERR) ?
-EBADMSG : 0);
}
/* Initialize transform information of GCM mode */ /* Initialize transform information of GCM mode */
static void mtk_aes_gcm_info_init(struct mtk_cryp *cryp, static void mtk_aes_gcm_info_init(struct mtk_cryp *cryp,
struct mtk_aes_rec *aes, struct mtk_aes_rec *aes,
...@@ -902,6 +920,8 @@ static int mtk_aes_gcm_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes) ...@@ -902,6 +920,8 @@ static int mtk_aes_gcm_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
if (aes->flags & AES_FLAGS_ENCRYPT) { if (aes->flags & AES_FLAGS_ENCRYPT) {
u32 tag[4]; u32 tag[4];
aes->resume = mtk_aes_transfer_complete;
/* Compute total process length. */ /* Compute total process length. */
aes->total = len + gctx->authsize; aes->total = len + gctx->authsize;
/* Compute text length. */ /* Compute text length. */
...@@ -909,10 +929,10 @@ static int mtk_aes_gcm_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes) ...@@ -909,10 +929,10 @@ static int mtk_aes_gcm_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
/* Hardware will append authenticated tag to output buffer */ /* Hardware will append authenticated tag to output buffer */
scatterwalk_map_and_copy(tag, req->dst, len, gctx->authsize, 1); scatterwalk_map_and_copy(tag, req->dst, len, gctx->authsize, 1);
} else { } else {
aes->resume = mtk_aes_gcm_tag_verify;
aes->total = len; aes->total = len;
gctx->textlen = req->cryptlen - gctx->authsize; gctx->textlen = req->cryptlen - gctx->authsize;
} }
aes->resume = mtk_aes_transfer_complete;
return mtk_aes_gcm_dma(cryp, aes, req->src, req->dst, len); return mtk_aes_gcm_dma(cryp, aes, req->src, req->dst, len);
} }
......
...@@ -88,6 +88,7 @@ struct mtk_desc { ...@@ -88,6 +88,7 @@ struct mtk_desc {
* @cmd_dma: DMA address of command descriptor ring * @cmd_dma: DMA address of command descriptor ring
* @res_base: pointer to result descriptor ring base * @res_base: pointer to result descriptor ring base
* @res_next: pointer to the next result descriptor * @res_next: pointer to the next result descriptor
* @res_prev: pointer to the previous result descriptor
* @res_dma: DMA address of result descriptor ring * @res_dma: DMA address of result descriptor ring
* *
* A descriptor ring is a circular buffer that is used to manage * A descriptor ring is a circular buffer that is used to manage
...@@ -100,6 +101,7 @@ struct mtk_ring { ...@@ -100,6 +101,7 @@ struct mtk_ring {
dma_addr_t cmd_dma; dma_addr_t cmd_dma;
struct mtk_desc *res_base; struct mtk_desc *res_base;
struct mtk_desc *res_next; struct mtk_desc *res_next;
struct mtk_desc *res_prev;
dma_addr_t res_dma; dma_addr_t res_dma;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment