diff mbox

[1/2] crypto: arm64/crc32: bring in line with generic CRC32

Message ID 1430730017-3712-1-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel May 4, 2015, 9 a.m. UTC
The arm64 CRC32 (not CRC32c) implementation was not quite doing
the same thing as the generic one. Fix that.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/crypto/crc32-arm64.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

Steve Capper May 5, 2015, 10:08 a.m. UTC | #1
On 4 May 2015 at 10:00, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> The arm64 CRC32 (not CRC32c) implementation was not quite doing
> the same thing as the generic one. Fix that.

Thanks Ard,
I agree the bitwise inverse at the end is applicable to Castagnoli,
but not to the vanilla CRC-32 in the kernel.

>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Steve Capper <steve.capper@linaro.org>

Cheers,
--
Steve

> ---
>  arch/arm64/crypto/crc32-arm64.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/crypto/crc32-arm64.c b/arch/arm64/crypto/crc32-arm64.c
> index 9499199924ae..6a37c3c6b11d 100644
> --- a/arch/arm64/crypto/crc32-arm64.c
> +++ b/arch/arm64/crypto/crc32-arm64.c
> @@ -147,13 +147,21 @@ static int chksum_final(struct shash_desc *desc, u8 *out)
>  {
>         struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
>
> +       put_unaligned_le32(ctx->crc, out);
> +       return 0;
> +}
> +
> +static int chksumc_final(struct shash_desc *desc, u8 *out)
> +{
> +       struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
> +
>         put_unaligned_le32(~ctx->crc, out);
>         return 0;
>  }
>
>  static int __chksum_finup(u32 crc, const u8 *data, unsigned int len, u8 *out)
>  {
> -       put_unaligned_le32(~crc32_arm64_le_hw(crc, data, len), out);
> +       put_unaligned_le32(crc32_arm64_le_hw(crc, data, len), out);
>         return 0;
>  }
>
> @@ -199,6 +207,14 @@ static int crc32_cra_init(struct crypto_tfm *tfm)
>  {
>         struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
>
> +       mctx->key = 0;
> +       return 0;
> +}
> +
> +static int crc32c_cra_init(struct crypto_tfm *tfm)
> +{
> +       struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
> +
>         mctx->key = ~0;
>         return 0;
>  }
> @@ -229,7 +245,7 @@ static struct shash_alg crc32c_alg = {
>         .setkey                 =       chksum_setkey,
>         .init                   =       chksum_init,
>         .update                 =       chksumc_update,
> -       .final                  =       chksum_final,
> +       .final                  =       chksumc_final,
>         .finup                  =       chksumc_finup,
>         .digest                 =       chksumc_digest,
>         .descsize               =       sizeof(struct chksum_desc_ctx),
> @@ -241,7 +257,7 @@ static struct shash_alg crc32c_alg = {
>                 .cra_alignmask          =       0,
>                 .cra_ctxsize            =       sizeof(struct chksum_ctx),
>                 .cra_module             =       THIS_MODULE,
> -               .cra_init               =       crc32_cra_init,
> +               .cra_init               =       crc32c_cra_init,
>         }
>  };
>
> --
> 1.9.1
>
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/arm64/crypto/crc32-arm64.c b/arch/arm64/crypto/crc32-arm64.c
index 9499199924ae..6a37c3c6b11d 100644
--- a/arch/arm64/crypto/crc32-arm64.c
+++ b/arch/arm64/crypto/crc32-arm64.c
@@ -147,13 +147,21 @@  static int chksum_final(struct shash_desc *desc, u8 *out)
 {
 	struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 
+	put_unaligned_le32(ctx->crc, out);
+	return 0;
+}
+
+static int chksumc_final(struct shash_desc *desc, u8 *out)
+{
+	struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
+
 	put_unaligned_le32(~ctx->crc, out);
 	return 0;
 }
 
 static int __chksum_finup(u32 crc, const u8 *data, unsigned int len, u8 *out)
 {
-	put_unaligned_le32(~crc32_arm64_le_hw(crc, data, len), out);
+	put_unaligned_le32(crc32_arm64_le_hw(crc, data, len), out);
 	return 0;
 }
 
@@ -199,6 +207,14 @@  static int crc32_cra_init(struct crypto_tfm *tfm)
 {
 	struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
 
+	mctx->key = 0;
+	return 0;
+}
+
+static int crc32c_cra_init(struct crypto_tfm *tfm)
+{
+	struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
+
 	mctx->key = ~0;
 	return 0;
 }
@@ -229,7 +245,7 @@  static struct shash_alg crc32c_alg = {
 	.setkey			=	chksum_setkey,
 	.init			=	chksum_init,
 	.update			=	chksumc_update,
-	.final			=	chksum_final,
+	.final			=	chksumc_final,
 	.finup			=	chksumc_finup,
 	.digest			=	chksumc_digest,
 	.descsize		=	sizeof(struct chksum_desc_ctx),
@@ -241,7 +257,7 @@  static struct shash_alg crc32c_alg = {
 		.cra_alignmask		=	0,
 		.cra_ctxsize		=	sizeof(struct chksum_ctx),
 		.cra_module		=	THIS_MODULE,
-		.cra_init		=	crc32_cra_init,
+		.cra_init		=	crc32c_cra_init,
 	}
 };