Skip to content

Commit 4621875

Browse files
committed
crypto: caam - Use new IV convention
This patch converts rfc4106 to the new calling convention where the IV is now part of the AD and needs to be skipped. Signed-off-by: Herbert Xu <[email protected]>
1 parent c3d2194 commit 4621875

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

drivers/crypto/caam/caamalg.c

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
#define DESC_GCM_DEC_LEN (DESC_GCM_BASE + 12 * CAAM_CMD_SZ)
8888

8989
#define DESC_RFC4106_BASE (3 * CAAM_CMD_SZ)
90-
#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 10 * CAAM_CMD_SZ)
91-
#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 10 * CAAM_CMD_SZ)
90+
#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 12 * CAAM_CMD_SZ)
91+
#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 12 * CAAM_CMD_SZ)
9292

9393
#define DESC_RFC4543_BASE (3 * CAAM_CMD_SZ)
9494
#define DESC_RFC4543_ENC_LEN (DESC_RFC4543_BASE + 11 * CAAM_CMD_SZ)
@@ -976,29 +976,32 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead)
976976
append_operation(desc, ctx->class1_alg_type |
977977
OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
978978

979-
append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
979+
append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, 8);
980980
append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
981981

982-
/* Skip assoc data */
983-
append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
984-
985982
/* Read assoc data */
986983
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
987984
FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
988985

989-
/* cryptlen = seqoutlen - assoclen */
990-
append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
986+
/* Skip IV */
987+
append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
991988

992989
/* Will read cryptlen bytes */
993990
append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
994991

995-
/* Write encrypted data */
996-
append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
997-
998992
/* Read payload data */
999993
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1000994
FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
1001995

996+
/* Skip assoc data */
997+
append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
998+
999+
/* cryptlen = seqoutlen - assoclen */
1000+
append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1001+
1002+
/* Write encrypted data */
1003+
append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1004+
10021005
/* Write ICV */
10031006
append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
10041007
LDST_SRCDST_BYTE_CONTEXT);
@@ -1044,29 +1047,32 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead)
10441047
append_operation(desc, ctx->class1_alg_type |
10451048
OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
10461049

1047-
append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
1050+
append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, 8);
10481051
append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
10491052

1050-
/* Skip assoc data */
1051-
append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
1052-
10531053
/* Read assoc data */
10541054
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
10551055
FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
10561056

1057-
/* Will write cryptlen bytes */
1058-
append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1057+
/* Skip IV */
1058+
append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
10591059

10601060
/* Will read cryptlen bytes */
1061-
append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1062-
1063-
/* Store payload data */
1064-
append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1061+
append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG3, CAAM_CMD_SZ);
10651062

10661063
/* Read encrypted data */
10671064
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
10681065
FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
10691066

1067+
/* Skip assoc data */
1068+
append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
1069+
1070+
/* Will write cryptlen bytes */
1071+
append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1072+
1073+
/* Store payload data */
1074+
append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1075+
10701076
/* Read ICV */
10711077
append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
10721078
FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
@@ -2685,6 +2691,14 @@ static int gcm_encrypt(struct aead_request *req)
26852691
return ret;
26862692
}
26872693

2694+
static int ipsec_gcm_encrypt(struct aead_request *req)
2695+
{
2696+
if (req->assoclen < 8)
2697+
return -EINVAL;
2698+
2699+
return gcm_encrypt(req);
2700+
}
2701+
26882702
static int old_aead_encrypt(struct aead_request *req)
26892703
{
26902704
struct aead_edesc *edesc;
@@ -2757,6 +2771,14 @@ static int gcm_decrypt(struct aead_request *req)
27572771
return ret;
27582772
}
27592773

2774+
static int ipsec_gcm_decrypt(struct aead_request *req)
2775+
{
2776+
if (req->assoclen < 8)
2777+
return -EINVAL;
2778+
2779+
return gcm_decrypt(req);
2780+
}
2781+
27602782
static int old_aead_decrypt(struct aead_request *req)
27612783
{
27622784
struct aead_edesc *edesc;
@@ -4058,8 +4080,8 @@ static struct caam_aead_alg driver_aeads[] = {
40584080
},
40594081
.setkey = rfc4106_setkey,
40604082
.setauthsize = rfc4106_setauthsize,
4061-
.encrypt = gcm_encrypt,
4062-
.decrypt = gcm_decrypt,
4083+
.encrypt = ipsec_gcm_encrypt,
4084+
.decrypt = ipsec_gcm_decrypt,
40634085
.ivsize = 8,
40644086
.maxauthsize = AES_BLOCK_SIZE,
40654087
},
@@ -4076,8 +4098,8 @@ static struct caam_aead_alg driver_aeads[] = {
40764098
},
40774099
.setkey = rfc4543_setkey,
40784100
.setauthsize = rfc4543_setauthsize,
4079-
.encrypt = gcm_encrypt,
4080-
.decrypt = gcm_decrypt,
4101+
.encrypt = ipsec_gcm_encrypt,
4102+
.decrypt = ipsec_gcm_decrypt,
40814103
.ivsize = 8,
40824104
.maxauthsize = AES_BLOCK_SIZE,
40834105
},
@@ -4260,7 +4282,8 @@ static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
42604282
alg->base.cra_module = THIS_MODULE;
42614283
alg->base.cra_priority = CAAM_CRA_PRIORITY;
42624284
alg->base.cra_ctxsize = sizeof(struct caam_ctx);
4263-
alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
4285+
alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
4286+
CRYPTO_ALG_AEAD_NEW;
42644287

42654288
alg->init = caam_aead_init;
42664289
alg->exit = caam_aead_exit;

0 commit comments

Comments
 (0)