From c2cb49e7b3f73d8b36b3f0164aceaf5fdb4db39a Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 19 May 2018 22:07:37 -0700 Subject: crypto: crc32-generic - use unaligned access macros when needed crc32-generic doesn't have a cra_alignmask set, which is desired as its ->update() works with any alignment. However, it incorrectly assumes 4-byte alignment in ->setkey() and when outputting the final digest. Fix this by using the unaligned access macros in those cases. Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu --- crypto/crc32_generic.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crypto/crc32_generic.c') diff --git a/crypto/crc32_generic.c b/crypto/crc32_generic.c index 718cbce8..20b87988 100644 --- a/crypto/crc32_generic.c +++ b/crypto/crc32_generic.c @@ -29,6 +29,7 @@ * This is crypto api shash wrappers to crc32_le. */ +#include #include #include #include @@ -69,7 +70,7 @@ static int crc32_setkey(struct crypto_shash *hash, const u8 *key, crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN); return -EINVAL; } - *mctx = le32_to_cpup((__le32 *)key); + *mctx = get_unaligned_le32(key); return 0; } @@ -96,7 +97,7 @@ static int crc32_update(struct shash_desc *desc, const u8 *data, static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out) { - *(__le32 *)out = cpu_to_le32(__crc32_le(*crcp, data, len)); + put_unaligned_le32(__crc32_le(*crcp, data, len), out); return 0; } @@ -110,7 +111,7 @@ static int crc32_final(struct shash_desc *desc, u8 *out) { u32 *crcp = shash_desc_ctx(desc); - *(__le32 *)out = cpu_to_le32p(crcp); + put_unaligned_le32(*crcp, out); return 0; } -- cgit v1.2.3 From da2ed725c9c72fba32df8834f5cd2baeed244dbd Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 19 May 2018 22:07:39 -0700 Subject: crypto: crc32-generic - remove __crc32_le() The __crc32_le() wrapper function is pointless. Just call crc32_le() directly instead. Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu --- crypto/crc32_generic.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'crypto/crc32_generic.c') diff --git a/crypto/crc32_generic.c b/crypto/crc32_generic.c index 20b87988..00facd27 100644 --- a/crypto/crc32_generic.c +++ b/crypto/crc32_generic.c @@ -40,11 +40,6 @@ #define CHKSUM_BLOCK_SIZE 1 #define CHKSUM_DIGEST_SIZE 4 -static u32 __crc32_le(u32 crc, unsigned char const *p, size_t len) -{ - return crc32_le(crc, p, len); -} - /** No default init with ~0 */ static int crc32_cra_init(struct crypto_tfm *tfm) { @@ -55,7 +50,6 @@ static int crc32_cra_init(struct crypto_tfm *tfm) return 0; } - /* * Setting the seed allows arbitrary accumulators and flexible XOR policy * If your algorithm starts with ~0, then XOR with ~0 before you set @@ -89,7 +83,7 @@ static int crc32_update(struct shash_desc *desc, const u8 *data, { u32 *crcp = shash_desc_ctx(desc); - *crcp = __crc32_le(*crcp, data, len); + *crcp = crc32_le(*crcp, data, len); return 0; } @@ -97,7 +91,7 @@ static int crc32_update(struct shash_desc *desc, const u8 *data, static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out) { - put_unaligned_le32(__crc32_le(*crcp, data, len), out); + put_unaligned_le32(crc32_le(*crcp, data, len), out); return 0; } -- cgit v1.2.3