Skip to content

Commit 416b846

Browse files
chleroyherbertx
authored andcommitted
crypto: talitos - Work around SEC6 ERRATA (AES-CTR mode data size error)
Talitos Security Engine AESU considers any input data size that is not a multiple of 16 bytes to be an error. This is not a problem in general, except for Counter mode that is a stream cipher and can have an input of any size. Test Manager for ctr(aes) fails on 4th test vector which has a length of 499 while all previous vectors which have a 16 bytes multiple length succeed. As suggested by Freescale, round up the input data length to the nearest 16 bytes. Fixes: 5e75ae1 ("crypto: talitos - add new crypto modes") Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent bc00598 commit 416b846

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

drivers/crypto/talitos.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,11 +1093,12 @@ static void ipsec_esp_decrypt_hwauth_done(struct device *dev,
10931093
*/
10941094
static int sg_to_link_tbl_offset(struct scatterlist *sg, int sg_count,
10951095
unsigned int offset, int datalen, int elen,
1096-
struct talitos_ptr *link_tbl_ptr)
1096+
struct talitos_ptr *link_tbl_ptr, int align)
10971097
{
10981098
int n_sg = elen ? sg_count + 1 : sg_count;
10991099
int count = 0;
11001100
int cryptlen = datalen + elen;
1101+
int padding = ALIGN(cryptlen, align) - cryptlen;
11011102

11021103
while (cryptlen && sg && n_sg--) {
11031104
unsigned int len = sg_dma_len(sg);
@@ -1121,7 +1122,7 @@ static int sg_to_link_tbl_offset(struct scatterlist *sg, int sg_count,
11211122
offset += datalen;
11221123
}
11231124
to_talitos_ptr(link_tbl_ptr + count,
1124-
sg_dma_address(sg) + offset, len, 0);
1125+
sg_dma_address(sg) + offset, sg_next(sg) ? len : len + padding, 0);
11251126
to_talitos_ptr_ext_set(link_tbl_ptr + count, 0, 0);
11261127
count++;
11271128
cryptlen -= len;
@@ -1144,33 +1145,34 @@ static int talitos_sg_map_ext(struct device *dev, struct scatterlist *src,
11441145
unsigned int len, struct talitos_edesc *edesc,
11451146
struct talitos_ptr *ptr, int sg_count,
11461147
unsigned int offset, int tbl_off, int elen,
1147-
bool force)
1148+
bool force, int align)
11481149
{
11491150
struct talitos_private *priv = dev_get_drvdata(dev);
11501151
bool is_sec1 = has_ftr_sec1(priv);
1152+
int aligned_len = ALIGN(len, align);
11511153

11521154
if (!src) {
11531155
to_talitos_ptr(ptr, 0, 0, is_sec1);
11541156
return 1;
11551157
}
11561158
to_talitos_ptr_ext_set(ptr, elen, is_sec1);
11571159
if (sg_count == 1 && !force) {
1158-
to_talitos_ptr(ptr, sg_dma_address(src) + offset, len, is_sec1);
1160+
to_talitos_ptr(ptr, sg_dma_address(src) + offset, aligned_len, is_sec1);
11591161
return sg_count;
11601162
}
11611163
if (is_sec1) {
1162-
to_talitos_ptr(ptr, edesc->dma_link_tbl + offset, len, is_sec1);
1164+
to_talitos_ptr(ptr, edesc->dma_link_tbl + offset, aligned_len, is_sec1);
11631165
return sg_count;
11641166
}
11651167
sg_count = sg_to_link_tbl_offset(src, sg_count, offset, len, elen,
1166-
&edesc->link_tbl[tbl_off]);
1168+
&edesc->link_tbl[tbl_off], align);
11671169
if (sg_count == 1 && !force) {
11681170
/* Only one segment now, so no link tbl needed*/
11691171
copy_talitos_ptr(ptr, &edesc->link_tbl[tbl_off], is_sec1);
11701172
return sg_count;
11711173
}
11721174
to_talitos_ptr(ptr, edesc->dma_link_tbl +
1173-
tbl_off * sizeof(struct talitos_ptr), len, is_sec1);
1175+
tbl_off * sizeof(struct talitos_ptr), aligned_len, is_sec1);
11741176
to_talitos_ptr_ext_or(ptr, DESC_PTR_LNKTBL_JUMP, is_sec1);
11751177

11761178
return sg_count;
@@ -1182,7 +1184,7 @@ static int talitos_sg_map(struct device *dev, struct scatterlist *src,
11821184
unsigned int offset, int tbl_off)
11831185
{
11841186
return talitos_sg_map_ext(dev, src, len, edesc, ptr, sg_count, offset,
1185-
tbl_off, 0, false);
1187+
tbl_off, 0, false, 1);
11861188
}
11871189

11881190
/*
@@ -1251,7 +1253,7 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
12511253

12521254
ret = talitos_sg_map_ext(dev, areq->src, cryptlen, edesc, &desc->ptr[4],
12531255
sg_count, areq->assoclen, tbl_off, elen,
1254-
false);
1256+
false, 1);
12551257

12561258
if (ret > 1) {
12571259
tbl_off += ret;
@@ -1271,7 +1273,7 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
12711273
elen = 0;
12721274
ret = talitos_sg_map_ext(dev, areq->dst, cryptlen, edesc, &desc->ptr[5],
12731275
sg_count, areq->assoclen, tbl_off, elen,
1274-
is_ipsec_esp && !encrypt);
1276+
is_ipsec_esp && !encrypt, 1);
12751277
tbl_off += ret;
12761278

12771279
if (!encrypt && is_ipsec_esp) {
@@ -1577,6 +1579,8 @@ static int common_nonsnoop(struct talitos_edesc *edesc,
15771579
bool sync_needed = false;
15781580
struct talitos_private *priv = dev_get_drvdata(dev);
15791581
bool is_sec1 = has_ftr_sec1(priv);
1582+
bool is_ctr = (desc->hdr & DESC_HDR_SEL0_MASK) == DESC_HDR_SEL0_AESU &&
1583+
(desc->hdr & DESC_HDR_MODE0_AESU_MASK) == DESC_HDR_MODE0_AESU_CTR;
15801584

15811585
/* first DWORD empty */
15821586

@@ -1597,8 +1601,8 @@ static int common_nonsnoop(struct talitos_edesc *edesc,
15971601
/*
15981602
* cipher in
15991603
*/
1600-
sg_count = talitos_sg_map(dev, areq->src, cryptlen, edesc,
1601-
&desc->ptr[3], sg_count, 0, 0);
1604+
sg_count = talitos_sg_map_ext(dev, areq->src, cryptlen, edesc, &desc->ptr[3],
1605+
sg_count, 0, 0, 0, false, is_ctr ? 16 : 1);
16021606
if (sg_count > 1)
16031607
sync_needed = true;
16041608

drivers/crypto/talitos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ static inline bool has_ftr_sec1(struct talitos_private *priv)
344344

345345
/* primary execution unit mode (MODE0) and derivatives */
346346
#define DESC_HDR_MODE0_ENCRYPT cpu_to_be32(0x00100000)
347+
#define DESC_HDR_MODE0_AESU_MASK cpu_to_be32(0x00600000)
347348
#define DESC_HDR_MODE0_AESU_CBC cpu_to_be32(0x00200000)
348349
#define DESC_HDR_MODE0_AESU_CTR cpu_to_be32(0x00600000)
349350
#define DESC_HDR_MODE0_DEU_CBC cpu_to_be32(0x00400000)

0 commit comments

Comments
 (0)