|
57 | 57 | #define SEC_TYPE_MASK 0x0F
|
58 | 58 | #define SEC_DONE_MASK 0x0001
|
59 | 59 | #define SEC_ICV_MASK 0x000E
|
60 |
| -#define SEC_SQE_LEN_RATE_MASK 0x3 |
61 | 60 |
|
62 | 61 | #define SEC_TOTAL_IV_SZ(depth) (SEC_IV_SIZE * (depth))
|
63 | 62 | #define SEC_SGL_SGE_NR 128
|
|
80 | 79 | #define SEC_TOTAL_PBUF_SZ(depth) (PAGE_SIZE * SEC_PBUF_PAGE_NUM(depth) + \
|
81 | 80 | SEC_PBUF_LEFT_SZ(depth))
|
82 | 81 |
|
83 |
| -#define SEC_SQE_LEN_RATE 4 |
84 | 82 | #define SEC_SQE_CFLAG 2
|
85 | 83 | #define SEC_SQE_AEAD_FLAG 3
|
86 | 84 | #define SEC_SQE_DONE 0x1
|
87 | 85 | #define SEC_ICV_ERR 0x2
|
88 |
| -#define MIN_MAC_LEN 4 |
89 | 86 | #define MAC_LEN_MASK 0x1U
|
90 | 87 | #define MAX_INPUT_DATA_LEN 0xFFFE00
|
91 | 88 | #define BITS_MASK 0xFF
|
| 89 | +#define WORD_MASK 0x3 |
92 | 90 | #define BYTE_BITS 0x8
|
| 91 | +#define BYTES_TO_WORDS(bcount) ((bcount) >> 2) |
93 | 92 | #define SEC_XTS_NAME_SZ 0x3
|
94 | 93 | #define IV_CM_CAL_NUM 2
|
95 | 94 | #define IV_CL_MASK 0x7
|
@@ -1175,7 +1174,7 @@ static int sec_aead_setkey(struct crypto_aead *tfm, const u8 *key,
|
1175 | 1174 | goto bad_key;
|
1176 | 1175 | }
|
1177 | 1176 |
|
1178 |
| - if (ctx->a_ctx.a_key_len & SEC_SQE_LEN_RATE_MASK) { |
| 1177 | + if (ctx->a_ctx.a_key_len & WORD_MASK) { |
1179 | 1178 | ret = -EINVAL;
|
1180 | 1179 | dev_err(dev, "AUTH key length error!\n");
|
1181 | 1180 | goto bad_key;
|
@@ -1583,11 +1582,10 @@ static void sec_auth_bd_fill_ex(struct sec_auth_ctx *ctx, int dir,
|
1583 | 1582 |
|
1584 | 1583 | sec_sqe->type2.a_key_addr = cpu_to_le64(ctx->a_key_dma);
|
1585 | 1584 |
|
1586 |
| - sec_sqe->type2.mac_key_alg = cpu_to_le32(authsize / SEC_SQE_LEN_RATE); |
| 1585 | + sec_sqe->type2.mac_key_alg = cpu_to_le32(BYTES_TO_WORDS(authsize)); |
1587 | 1586 |
|
1588 | 1587 | sec_sqe->type2.mac_key_alg |=
|
1589 |
| - cpu_to_le32((u32)((ctx->a_key_len) / |
1590 |
| - SEC_SQE_LEN_RATE) << SEC_AKEY_OFFSET); |
| 1588 | + cpu_to_le32((u32)BYTES_TO_WORDS(ctx->a_key_len) << SEC_AKEY_OFFSET); |
1591 | 1589 |
|
1592 | 1590 | sec_sqe->type2.mac_key_alg |=
|
1593 | 1591 | cpu_to_le32((u32)(ctx->a_alg) << SEC_AEAD_ALG_OFFSET);
|
@@ -1639,12 +1637,10 @@ static void sec_auth_bd_fill_ex_v3(struct sec_auth_ctx *ctx, int dir,
|
1639 | 1637 | sqe3->a_key_addr = cpu_to_le64(ctx->a_key_dma);
|
1640 | 1638 |
|
1641 | 1639 | sqe3->auth_mac_key |=
|
1642 |
| - cpu_to_le32((u32)(authsize / |
1643 |
| - SEC_SQE_LEN_RATE) << SEC_MAC_OFFSET_V3); |
| 1640 | + cpu_to_le32(BYTES_TO_WORDS(authsize) << SEC_MAC_OFFSET_V3); |
1644 | 1641 |
|
1645 | 1642 | sqe3->auth_mac_key |=
|
1646 |
| - cpu_to_le32((u32)(ctx->a_key_len / |
1647 |
| - SEC_SQE_LEN_RATE) << SEC_AKEY_OFFSET_V3); |
| 1643 | + cpu_to_le32((u32)BYTES_TO_WORDS(ctx->a_key_len) << SEC_AKEY_OFFSET_V3); |
1648 | 1644 |
|
1649 | 1645 | sqe3->auth_mac_key |=
|
1650 | 1646 | cpu_to_le32((u32)(ctx->a_alg) << SEC_AUTH_ALG_OFFSET_V3);
|
@@ -2234,8 +2230,8 @@ static int sec_aead_spec_check(struct sec_ctx *ctx, struct sec_req *sreq)
|
2234 | 2230 | struct device *dev = ctx->dev;
|
2235 | 2231 | int ret;
|
2236 | 2232 |
|
2237 |
| - /* Hardware does not handle cases where authsize is less than 4 bytes */ |
2238 |
| - if (unlikely(sz < MIN_MAC_LEN)) { |
| 2233 | + /* Hardware does not handle cases where authsize is not 4 bytes aligned */ |
| 2234 | + if (c_mode == SEC_CMODE_CBC && (sz & WORD_MASK)) { |
2239 | 2235 | sreq->aead_req.fallback = true;
|
2240 | 2236 | return -EINVAL;
|
2241 | 2237 | }
|
|
0 commit comments