diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2006-08-06 09:03:08 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2006-09-20 21:41:01 -0400 |
commit | 25cdbcd9e5d20e431f829cafce48a418830011f4 (patch) | |
tree | 0dff8422d2b0b1da1d3505b0ad0e840f6f0fd66d /crypto/crc32c.c | |
parent | 58ec4152895b96f047dcf5e490ee49b4c574dec3 (diff) |
[CRYPTO] crc32c: Fix unconventional setkey usage
The convention for setkey is that once it is set it should not change,
in particular, init must not wipe out the key set by it. In fact, init
should always be used after setkey before any digestion is performed.
The only user of crc32c that sets the key is tcrypt. This patch adds
the necessary init calls there.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/crc32c.c')
-rw-r--r-- | crypto/crc32c.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/crypto/crc32c.c b/crypto/crc32c.c index f2660123aeb4..91ecd895e957 100644 --- a/crypto/crc32c.c +++ b/crypto/crc32c.c | |||
@@ -16,14 +16,14 @@ | |||
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/crypto.h> | 17 | #include <linux/crypto.h> |
18 | #include <linux/crc32c.h> | 18 | #include <linux/crc32c.h> |
19 | #include <linux/types.h> | 19 | #include <linux/kernel.h> |
20 | #include <asm/byteorder.h> | ||
21 | 20 | ||
22 | #define CHKSUM_BLOCK_SIZE 32 | 21 | #define CHKSUM_BLOCK_SIZE 32 |
23 | #define CHKSUM_DIGEST_SIZE 4 | 22 | #define CHKSUM_DIGEST_SIZE 4 |
24 | 23 | ||
25 | struct chksum_ctx { | 24 | struct chksum_ctx { |
26 | u32 crc; | 25 | u32 crc; |
26 | u32 key; | ||
27 | }; | 27 | }; |
28 | 28 | ||
29 | /* | 29 | /* |
@@ -35,7 +35,7 @@ static void chksum_init(struct crypto_tfm *tfm) | |||
35 | { | 35 | { |
36 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); | 36 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); |
37 | 37 | ||
38 | mctx->crc = ~(u32)0; /* common usage */ | 38 | mctx->crc = mctx->key; |
39 | } | 39 | } |
40 | 40 | ||
41 | /* | 41 | /* |
@@ -53,7 +53,7 @@ static int chksum_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
53 | *flags = CRYPTO_TFM_RES_BAD_KEY_LEN; | 53 | *flags = CRYPTO_TFM_RES_BAD_KEY_LEN; |
54 | return -EINVAL; | 54 | return -EINVAL; |
55 | } | 55 | } |
56 | mctx->crc = __cpu_to_le32(*(u32 *)key); | 56 | mctx->key = le32_to_cpu(*(__le32 *)key); |
57 | return 0; | 57 | return 0; |
58 | } | 58 | } |
59 | 59 | ||
@@ -61,19 +61,23 @@ static void chksum_update(struct crypto_tfm *tfm, const u8 *data, | |||
61 | unsigned int length) | 61 | unsigned int length) |
62 | { | 62 | { |
63 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); | 63 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); |
64 | u32 mcrc; | ||
65 | 64 | ||
66 | mcrc = crc32c(mctx->crc, data, (size_t)length); | 65 | mctx->crc = crc32c(mctx->crc, data, length); |
67 | |||
68 | mctx->crc = mcrc; | ||
69 | } | 66 | } |
70 | 67 | ||
71 | static void chksum_final(struct crypto_tfm *tfm, u8 *out) | 68 | static void chksum_final(struct crypto_tfm *tfm, u8 *out) |
72 | { | 69 | { |
73 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); | 70 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); |
74 | u32 mcrc = (mctx->crc ^ ~(u32)0); | ||
75 | 71 | ||
76 | *(u32 *)out = __le32_to_cpu(mcrc); | 72 | *(__le32 *)out = ~cpu_to_le32(mctx->crc); |
73 | } | ||
74 | |||
75 | static int crc32c_cra_init(struct crypto_tfm *tfm) | ||
76 | { | ||
77 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); | ||
78 | |||
79 | mctx->key = ~0; | ||
80 | return 0; | ||
77 | } | 81 | } |
78 | 82 | ||
79 | static struct crypto_alg alg = { | 83 | static struct crypto_alg alg = { |
@@ -83,6 +87,7 @@ static struct crypto_alg alg = { | |||
83 | .cra_ctxsize = sizeof(struct chksum_ctx), | 87 | .cra_ctxsize = sizeof(struct chksum_ctx), |
84 | .cra_module = THIS_MODULE, | 88 | .cra_module = THIS_MODULE, |
85 | .cra_list = LIST_HEAD_INIT(alg.cra_list), | 89 | .cra_list = LIST_HEAD_INIT(alg.cra_list), |
90 | .cra_init = crc32c_cra_init, | ||
86 | .cra_u = { | 91 | .cra_u = { |
87 | .digest = { | 92 | .digest = { |
88 | .dia_digestsize= CHKSUM_DIGEST_SIZE, | 93 | .dia_digestsize= CHKSUM_DIGEST_SIZE, |