|
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
|
@@ -1171,7 +1170,7 @@ static int sec_aead_setkey(struct crypto_aead *tfm, const u8 *key,
|
1171 | 1170 | goto bad_key;
|
1172 | 1171 | }
|
1173 | 1172 |
|
1174 |
| - if (ctx->a_ctx.a_key_len & SEC_SQE_LEN_RATE_MASK) { |
| 1173 | + if (ctx->a_ctx.a_key_len & WORD_MASK) { |
1175 | 1174 | ret = -EINVAL;
|
1176 | 1175 | dev_err(dev, "AUTH key length error!\n");
|
1177 | 1176 | goto bad_key;
|
@@ -1579,11 +1578,10 @@ static void sec_auth_bd_fill_ex(struct sec_auth_ctx *ctx, int dir,
|
1579 | 1578 |
|
1580 | 1579 | sec_sqe->type2.a_key_addr = cpu_to_le64(ctx->a_key_dma);
|
1581 | 1580 |
|
1582 |
| - sec_sqe->type2.mac_key_alg = cpu_to_le32(authsize / SEC_SQE_LEN_RATE); |
| 1581 | + sec_sqe->type2.mac_key_alg = cpu_to_le32(BYTES_TO_WORDS(authsize)); |
1583 | 1582 |
|
1584 | 1583 | sec_sqe->type2.mac_key_alg |=
|
1585 |
| - cpu_to_le32((u32)((ctx->a_key_len) / |
1586 |
| - SEC_SQE_LEN_RATE) << SEC_AKEY_OFFSET); |
| 1584 | + cpu_to_le32((u32)BYTES_TO_WORDS(ctx->a_key_len) << SEC_AKEY_OFFSET); |
1587 | 1585 |
|
1588 | 1586 | sec_sqe->type2.mac_key_alg |=
|
1589 | 1587 | cpu_to_le32((u32)(ctx->a_alg) << SEC_AEAD_ALG_OFFSET);
|
@@ -1635,12 +1633,10 @@ static void sec_auth_bd_fill_ex_v3(struct sec_auth_ctx *ctx, int dir,
|
1635 | 1633 | sqe3->a_key_addr = cpu_to_le64(ctx->a_key_dma);
|
1636 | 1634 |
|
1637 | 1635 | sqe3->auth_mac_key |=
|
1638 |
| - cpu_to_le32((u32)(authsize / |
1639 |
| - SEC_SQE_LEN_RATE) << SEC_MAC_OFFSET_V3); |
| 1636 | + cpu_to_le32(BYTES_TO_WORDS(authsize) << SEC_MAC_OFFSET_V3); |
1640 | 1637 |
|
1641 | 1638 | sqe3->auth_mac_key |=
|
1642 |
| - cpu_to_le32((u32)(ctx->a_key_len / |
1643 |
| - SEC_SQE_LEN_RATE) << SEC_AKEY_OFFSET_V3); |
| 1639 | + cpu_to_le32((u32)BYTES_TO_WORDS(ctx->a_key_len) << SEC_AKEY_OFFSET_V3); |
1644 | 1640 |
|
1645 | 1641 | sqe3->auth_mac_key |=
|
1646 | 1642 | cpu_to_le32((u32)(ctx->a_alg) << SEC_AUTH_ALG_OFFSET_V3);
|
@@ -2230,8 +2226,8 @@ static int sec_aead_spec_check(struct sec_ctx *ctx, struct sec_req *sreq)
|
2230 | 2226 | struct device *dev = ctx->dev;
|
2231 | 2227 | int ret;
|
2232 | 2228 |
|
2233 |
| - /* Hardware does not handle cases where authsize is less than 4 bytes */ |
2234 |
| - if (unlikely(sz < MIN_MAC_LEN)) { |
| 2229 | + /* Hardware does not handle cases where authsize is not 4 bytes aligned */ |
| 2230 | + if (c_mode == SEC_CMODE_CBC && (sz & WORD_MASK)) { |
2235 | 2231 | sreq->aead_req.fallback = true;
|
2236 | 2232 | return -EINVAL;
|
2237 | 2233 | }
|
|
0 commit comments