Skip to content

Commit ac02c6e

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: arm64/crc32 - bring in line with generic CRC32
The arm64 CRC32 (not CRC32c) implementation was not quite doing the same thing as the generic one. Fix that. Signed-off-by: Ard Biesheuvel <[email protected]> Acked-by: Steve Capper <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f440c4e commit ac02c6e

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

arch/arm64/crypto/crc32-arm64.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,21 @@ static int chksum_final(struct shash_desc *desc, u8 *out)
147147
{
148148
struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
149149

150+
put_unaligned_le32(ctx->crc, out);
151+
return 0;
152+
}
153+
154+
static int chksumc_final(struct shash_desc *desc, u8 *out)
155+
{
156+
struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
157+
150158
put_unaligned_le32(~ctx->crc, out);
151159
return 0;
152160
}
153161

154162
static int __chksum_finup(u32 crc, const u8 *data, unsigned int len, u8 *out)
155163
{
156-
put_unaligned_le32(~crc32_arm64_le_hw(crc, data, len), out);
164+
put_unaligned_le32(crc32_arm64_le_hw(crc, data, len), out);
157165
return 0;
158166
}
159167

@@ -199,6 +207,14 @@ static int crc32_cra_init(struct crypto_tfm *tfm)
199207
{
200208
struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
201209

210+
mctx->key = 0;
211+
return 0;
212+
}
213+
214+
static int crc32c_cra_init(struct crypto_tfm *tfm)
215+
{
216+
struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
217+
202218
mctx->key = ~0;
203219
return 0;
204220
}
@@ -229,7 +245,7 @@ static struct shash_alg crc32c_alg = {
229245
.setkey = chksum_setkey,
230246
.init = chksum_init,
231247
.update = chksumc_update,
232-
.final = chksum_final,
248+
.final = chksumc_final,
233249
.finup = chksumc_finup,
234250
.digest = chksumc_digest,
235251
.descsize = sizeof(struct chksum_desc_ctx),
@@ -241,7 +257,7 @@ static struct shash_alg crc32c_alg = {
241257
.cra_alignmask = 0,
242258
.cra_ctxsize = sizeof(struct chksum_ctx),
243259
.cra_module = THIS_MODULE,
244-
.cra_init = crc32_cra_init,
260+
.cra_init = crc32c_cra_init,
245261
}
246262
};
247263

0 commit comments

Comments
 (0)