diff options
author | Eric Biggers <ebiggers@google.com> | 2018-05-20 01:07:37 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2018-05-26 12:12:08 -0400 |
commit | fffe7d9279a48563fe4c19b07b649a583ac91a44 (patch) | |
tree | 01f5806dedea2392ba74a63dba0538a8dc63cd7d /crypto/crc32_generic.c | |
parent | f16b613ca8b3e4960cdc5575e9b8e1dbdd7d54d5 (diff) |
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 <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/crc32_generic.c')
-rw-r--r-- | crypto/crc32_generic.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/crypto/crc32_generic.c b/crypto/crc32_generic.c index 718cbce8d169..20b879881a2d 100644 --- a/crypto/crc32_generic.c +++ b/crypto/crc32_generic.c | |||
@@ -29,6 +29,7 @@ | |||
29 | * This is crypto api shash wrappers to crc32_le. | 29 | * This is crypto api shash wrappers to crc32_le. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <asm/unaligned.h> | ||
32 | #include <linux/crc32.h> | 33 | #include <linux/crc32.h> |
33 | #include <crypto/internal/hash.h> | 34 | #include <crypto/internal/hash.h> |
34 | #include <linux/init.h> | 35 | #include <linux/init.h> |
@@ -69,7 +70,7 @@ static int crc32_setkey(struct crypto_shash *hash, const u8 *key, | |||
69 | crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN); | 70 | crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN); |
70 | return -EINVAL; | 71 | return -EINVAL; |
71 | } | 72 | } |
72 | *mctx = le32_to_cpup((__le32 *)key); | 73 | *mctx = get_unaligned_le32(key); |
73 | return 0; | 74 | return 0; |
74 | } | 75 | } |
75 | 76 | ||
@@ -96,7 +97,7 @@ static int crc32_update(struct shash_desc *desc, const u8 *data, | |||
96 | static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, | 97 | static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, |
97 | u8 *out) | 98 | u8 *out) |
98 | { | 99 | { |
99 | *(__le32 *)out = cpu_to_le32(__crc32_le(*crcp, data, len)); | 100 | put_unaligned_le32(__crc32_le(*crcp, data, len), out); |
100 | return 0; | 101 | return 0; |
101 | } | 102 | } |
102 | 103 | ||
@@ -110,7 +111,7 @@ static int crc32_final(struct shash_desc *desc, u8 *out) | |||
110 | { | 111 | { |
111 | u32 *crcp = shash_desc_ctx(desc); | 112 | u32 *crcp = shash_desc_ctx(desc); |
112 | 113 | ||
113 | *(__le32 *)out = cpu_to_le32p(crcp); | 114 | put_unaligned_le32(*crcp, out); |
114 | return 0; | 115 | return 0; |
115 | } | 116 | } |
116 | 117 | ||