Skip to content

Commit d1d787b

Browse files
montjoieherbertx
authored andcommitted
crypto: sun4i-ss - fix big endian issues
When testing BigEndian kernel, the sun4i-ss was failling all crypto tests. This patch fix endian issues with it. Fixes: 6298e94 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Signed-off-by: Corentin Labbe <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 2edf864 commit d1d787b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static int sun4i_hash(struct ahash_request *areq)
187187
*/
188188
unsigned int i = 0, end, fill, min_fill, nwait, nbw = 0, j = 0, todo;
189189
unsigned int in_i = 0;
190-
u32 spaces, rx_cnt = SS_RX_DEFAULT, bf[32] = {0}, wb = 0, v, ivmode = 0;
190+
u32 spaces, rx_cnt = SS_RX_DEFAULT, bf[32] = {0}, v, ivmode = 0;
191191
struct sun4i_req_ctx *op = ahash_request_ctx(areq);
192192
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
193193
struct sun4i_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
@@ -196,6 +196,7 @@ static int sun4i_hash(struct ahash_request *areq)
196196
struct sg_mapping_iter mi;
197197
int in_r, err = 0;
198198
size_t copied = 0;
199+
__le32 wb = 0;
199200

200201
dev_dbg(ss->dev, "%s %s bc=%llu len=%u mode=%x wl=%u h0=%0x",
201202
__func__, crypto_tfm_alg_name(areq->base.tfm),
@@ -407,7 +408,7 @@ static int sun4i_hash(struct ahash_request *areq)
407408

408409
nbw = op->len - 4 * nwait;
409410
if (nbw) {
410-
wb = *(u32 *)(op->buf + nwait * 4);
411+
wb = cpu_to_le32(*(u32 *)(op->buf + nwait * 4));
411412
wb &= GENMASK((nbw * 8) - 1, 0);
412413

413414
op->byte_count += nbw;
@@ -416,7 +417,7 @@ static int sun4i_hash(struct ahash_request *areq)
416417

417418
/* write the remaining bytes of the nbw buffer */
418419
wb |= ((1 << 7) << (nbw * 8));
419-
bf[j++] = wb;
420+
bf[j++] = le32_to_cpu(wb);
420421

421422
/*
422423
* number of space to pad to obtain 64o minus 8(size) minus 4 (final 1)
@@ -435,13 +436,13 @@ static int sun4i_hash(struct ahash_request *areq)
435436

436437
/* write the length of data */
437438
if (op->mode == SS_OP_SHA1) {
438-
__be64 bits = cpu_to_be64(op->byte_count << 3);
439-
bf[j++] = lower_32_bits(bits);
440-
bf[j++] = upper_32_bits(bits);
439+
__be64 *bits = (__be64 *)&bf[j];
440+
*bits = cpu_to_be64(op->byte_count << 3);
441+
j += 2;
441442
} else {
442-
__le64 bits = op->byte_count << 3;
443-
bf[j++] = lower_32_bits(bits);
444-
bf[j++] = upper_32_bits(bits);
443+
__le64 *bits = (__le64 *)&bf[j];
444+
*bits = cpu_to_le64(op->byte_count << 3);
445+
j += 2;
445446
}
446447
writesl(ss->base + SS_RXFIFO, bf, j);
447448

@@ -483,7 +484,7 @@ static int sun4i_hash(struct ahash_request *areq)
483484
}
484485
} else {
485486
for (i = 0; i < 4; i++) {
486-
v = readl(ss->base + SS_MD0 + i * 4);
487+
v = cpu_to_le32(readl(ss->base + SS_MD0 + i * 4));
487488
memcpy(areq->result + i * 4, &v, 4);
488489
}
489490
}

0 commit comments

Comments
 (0)