diff options
-rw-r--r-- | arch/i386/crypto/aes.c | 3 | ||||
-rw-r--r-- | arch/s390/crypto/aes_s390.c | 3 | ||||
-rw-r--r-- | arch/s390/crypto/des_s390.c | 13 | ||||
-rw-r--r-- | arch/x86_64/crypto/aes.c | 5 | ||||
-rw-r--r-- | crypto/aes.c | 5 | ||||
-rw-r--r-- | crypto/anubis.c | 3 | ||||
-rw-r--r-- | crypto/arc4.c | 2 | ||||
-rw-r--r-- | crypto/blowfish.c | 3 | ||||
-rw-r--r-- | crypto/cast5.c | 8 | ||||
-rw-r--r-- | crypto/cast6.c | 5 | ||||
-rw-r--r-- | crypto/cipher.c | 4 | ||||
-rw-r--r-- | crypto/crc32c.c | 5 | ||||
-rw-r--r-- | crypto/crypto_null.c | 2 | ||||
-rw-r--r-- | crypto/des.c | 6 | ||||
-rw-r--r-- | crypto/digest.c | 15 | ||||
-rw-r--r-- | crypto/khazad.c | 8 | ||||
-rw-r--r-- | crypto/michael_mic.c | 5 | ||||
-rw-r--r-- | crypto/serpent.c | 19 | ||||
-rw-r--r-- | crypto/tcrypt.c | 5 | ||||
-rw-r--r-- | crypto/tea.c | 16 | ||||
-rw-r--r-- | crypto/twofish_common.c | 6 | ||||
-rw-r--r-- | drivers/crypto/padlock-aes.c | 5 | ||||
-rw-r--r-- | include/crypto/twofish.h | 3 | ||||
-rw-r--r-- | include/linux/crypto.h | 6 |
24 files changed, 63 insertions, 92 deletions
diff --git a/arch/i386/crypto/aes.c b/arch/i386/crypto/aes.c index d3806daa3de3..49aad9397f10 100644 --- a/arch/i386/crypto/aes.c +++ b/arch/i386/crypto/aes.c | |||
@@ -379,12 +379,13 @@ static void gen_tabs(void) | |||
379 | } | 379 | } |
380 | 380 | ||
381 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | 381 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, |
382 | unsigned int key_len, u32 *flags) | 382 | unsigned int key_len) |
383 | { | 383 | { |
384 | int i; | 384 | int i; |
385 | u32 ss[8]; | 385 | u32 ss[8]; |
386 | struct aes_ctx *ctx = crypto_tfm_ctx(tfm); | 386 | struct aes_ctx *ctx = crypto_tfm_ctx(tfm); |
387 | const __le32 *key = (const __le32 *)in_key; | 387 | const __le32 *key = (const __le32 *)in_key; |
388 | u32 *flags = &tfm->crt_flags; | ||
388 | 389 | ||
389 | /* encryption schedule */ | 390 | /* encryption schedule */ |
390 | 391 | ||
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c index 5713c7e5bd16..c7c43c9de0d9 100644 --- a/arch/s390/crypto/aes_s390.c +++ b/arch/s390/crypto/aes_s390.c | |||
@@ -38,9 +38,10 @@ struct s390_aes_ctx { | |||
38 | }; | 38 | }; |
39 | 39 | ||
40 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | 40 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, |
41 | unsigned int key_len, u32 *flags) | 41 | unsigned int key_len) |
42 | { | 42 | { |
43 | struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); | 43 | struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); |
44 | u32 *flags = &tfm->crt_flags; | ||
44 | 45 | ||
45 | switch (key_len) { | 46 | switch (key_len) { |
46 | case 16: | 47 | case 16: |
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c index b3f7496a79b4..170757b3451d 100644 --- a/arch/s390/crypto/des_s390.c +++ b/arch/s390/crypto/des_s390.c | |||
@@ -45,9 +45,10 @@ struct crypt_s390_des3_192_ctx { | |||
45 | }; | 45 | }; |
46 | 46 | ||
47 | static int des_setkey(struct crypto_tfm *tfm, const u8 *key, | 47 | static int des_setkey(struct crypto_tfm *tfm, const u8 *key, |
48 | unsigned int keylen, u32 *flags) | 48 | unsigned int keylen) |
49 | { | 49 | { |
50 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); | 50 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); |
51 | u32 *flags = &tfm->crt_flags; | ||
51 | int ret; | 52 | int ret; |
52 | 53 | ||
53 | /* test if key is valid (not a weak key) */ | 54 | /* test if key is valid (not a weak key) */ |
@@ -167,11 +168,12 @@ static struct crypto_alg des_alg = { | |||
167 | * | 168 | * |
168 | */ | 169 | */ |
169 | static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key, | 170 | static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key, |
170 | unsigned int keylen, u32 *flags) | 171 | unsigned int keylen) |
171 | { | 172 | { |
172 | int i, ret; | 173 | int i, ret; |
173 | struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm); | 174 | struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm); |
174 | const u8* temp_key = key; | 175 | const u8 *temp_key = key; |
176 | u32 *flags = &tfm->crt_flags; | ||
175 | 177 | ||
176 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) { | 178 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) { |
177 | *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; | 179 | *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; |
@@ -303,11 +305,12 @@ static struct crypto_alg des3_128_alg = { | |||
303 | * | 305 | * |
304 | */ | 306 | */ |
305 | static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, | 307 | static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, |
306 | unsigned int keylen, u32 *flags) | 308 | unsigned int keylen) |
307 | { | 309 | { |
308 | int i, ret; | 310 | int i, ret; |
309 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); | 311 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); |
310 | const u8* temp_key = key; | 312 | const u8 *temp_key = key; |
313 | u32 *flags = &tfm->crt_flags; | ||
311 | 314 | ||
312 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && | 315 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && |
313 | memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], | 316 | memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], |
diff --git a/arch/x86_64/crypto/aes.c b/arch/x86_64/crypto/aes.c index 68866fab37aa..5cdb13ea5cc2 100644 --- a/arch/x86_64/crypto/aes.c +++ b/arch/x86_64/crypto/aes.c | |||
@@ -228,13 +228,14 @@ static void __init gen_tabs(void) | |||
228 | } | 228 | } |
229 | 229 | ||
230 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | 230 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, |
231 | unsigned int key_len, u32 *flags) | 231 | unsigned int key_len) |
232 | { | 232 | { |
233 | struct aes_ctx *ctx = crypto_tfm_ctx(tfm); | 233 | struct aes_ctx *ctx = crypto_tfm_ctx(tfm); |
234 | const __le32 *key = (const __le32 *)in_key; | 234 | const __le32 *key = (const __le32 *)in_key; |
235 | u32 *flags = &tfm->crt_flags; | ||
235 | u32 i, j, t, u, v, w; | 236 | u32 i, j, t, u, v, w; |
236 | 237 | ||
237 | if (key_len != 16 && key_len != 24 && key_len != 32) { | 238 | if (key_len % 8) { |
238 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | 239 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
239 | return -EINVAL; | 240 | return -EINVAL; |
240 | } | 241 | } |
diff --git a/crypto/aes.c b/crypto/aes.c index a038711831e7..e2440773878c 100644 --- a/crypto/aes.c +++ b/crypto/aes.c | |||
@@ -249,13 +249,14 @@ gen_tabs (void) | |||
249 | } | 249 | } |
250 | 250 | ||
251 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | 251 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, |
252 | unsigned int key_len, u32 *flags) | 252 | unsigned int key_len) |
253 | { | 253 | { |
254 | struct aes_ctx *ctx = crypto_tfm_ctx(tfm); | 254 | struct aes_ctx *ctx = crypto_tfm_ctx(tfm); |
255 | const __le32 *key = (const __le32 *)in_key; | 255 | const __le32 *key = (const __le32 *)in_key; |
256 | u32 *flags = &tfm->crt_flags; | ||
256 | u32 i, t, u, v, w; | 257 | u32 i, t, u, v, w; |
257 | 258 | ||
258 | if (key_len != 16 && key_len != 24 && key_len != 32) { | 259 | if (key_len % 8) { |
259 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | 260 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
260 | return -EINVAL; | 261 | return -EINVAL; |
261 | } | 262 | } |
diff --git a/crypto/anubis.c b/crypto/anubis.c index 7e2e1a29800e..1c771f7f4dc5 100644 --- a/crypto/anubis.c +++ b/crypto/anubis.c | |||
@@ -461,10 +461,11 @@ static const u32 rc[] = { | |||
461 | }; | 461 | }; |
462 | 462 | ||
463 | static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key, | 463 | static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key, |
464 | unsigned int key_len, u32 *flags) | 464 | unsigned int key_len) |
465 | { | 465 | { |
466 | struct anubis_ctx *ctx = crypto_tfm_ctx(tfm); | 466 | struct anubis_ctx *ctx = crypto_tfm_ctx(tfm); |
467 | const __be32 *key = (const __be32 *)in_key; | 467 | const __be32 *key = (const __be32 *)in_key; |
468 | u32 *flags = &tfm->crt_flags; | ||
468 | int N, R, i, r; | 469 | int N, R, i, r; |
469 | u32 kappa[ANUBIS_MAX_N]; | 470 | u32 kappa[ANUBIS_MAX_N]; |
470 | u32 inter[ANUBIS_MAX_N]; | 471 | u32 inter[ANUBIS_MAX_N]; |
diff --git a/crypto/arc4.c b/crypto/arc4.c index 5edc6a65b987..8be47e13a9e3 100644 --- a/crypto/arc4.c +++ b/crypto/arc4.c | |||
@@ -25,7 +25,7 @@ struct arc4_ctx { | |||
25 | }; | 25 | }; |
26 | 26 | ||
27 | static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key, | 27 | static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key, |
28 | unsigned int key_len, u32 *flags) | 28 | unsigned int key_len) |
29 | { | 29 | { |
30 | struct arc4_ctx *ctx = crypto_tfm_ctx(tfm); | 30 | struct arc4_ctx *ctx = crypto_tfm_ctx(tfm); |
31 | int i, j = 0, k = 0; | 31 | int i, j = 0, k = 0; |
diff --git a/crypto/blowfish.c b/crypto/blowfish.c index 490265f42b3b..55238c4e37f0 100644 --- a/crypto/blowfish.c +++ b/crypto/blowfish.c | |||
@@ -399,8 +399,7 @@ static void bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
399 | /* | 399 | /* |
400 | * Calculates the blowfish S and P boxes for encryption and decryption. | 400 | * Calculates the blowfish S and P boxes for encryption and decryption. |
401 | */ | 401 | */ |
402 | static int bf_setkey(struct crypto_tfm *tfm, const u8 *key, | 402 | static int bf_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) |
403 | unsigned int keylen, u32 *flags) | ||
404 | { | 403 | { |
405 | struct bf_ctx *ctx = crypto_tfm_ctx(tfm); | 404 | struct bf_ctx *ctx = crypto_tfm_ctx(tfm); |
406 | u32 *P = ctx->p; | 405 | u32 *P = ctx->p; |
diff --git a/crypto/cast5.c b/crypto/cast5.c index 08eef58c1d3d..13ea60abc19a 100644 --- a/crypto/cast5.c +++ b/crypto/cast5.c | |||
@@ -769,8 +769,7 @@ static void key_schedule(u32 * x, u32 * z, u32 * k) | |||
769 | } | 769 | } |
770 | 770 | ||
771 | 771 | ||
772 | static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, | 772 | static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned key_len) |
773 | unsigned key_len, u32 *flags) | ||
774 | { | 773 | { |
775 | struct cast5_ctx *c = crypto_tfm_ctx(tfm); | 774 | struct cast5_ctx *c = crypto_tfm_ctx(tfm); |
776 | int i; | 775 | int i; |
@@ -778,11 +777,6 @@ static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
778 | u32 z[4]; | 777 | u32 z[4]; |
779 | u32 k[16]; | 778 | u32 k[16]; |
780 | __be32 p_key[4]; | 779 | __be32 p_key[4]; |
781 | |||
782 | if (key_len < 5 || key_len > 16) { | ||
783 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
784 | return -EINVAL; | ||
785 | } | ||
786 | 780 | ||
787 | c->rr = key_len <= 10 ? 1 : 0; | 781 | c->rr = key_len <= 10 ? 1 : 0; |
788 | 782 | ||
diff --git a/crypto/cast6.c b/crypto/cast6.c index 08e33bfc3ad1..136ab6dfe8c5 100644 --- a/crypto/cast6.c +++ b/crypto/cast6.c | |||
@@ -382,14 +382,15 @@ static inline void W(u32 *key, unsigned int i) { | |||
382 | } | 382 | } |
383 | 383 | ||
384 | static int cast6_setkey(struct crypto_tfm *tfm, const u8 *in_key, | 384 | static int cast6_setkey(struct crypto_tfm *tfm, const u8 *in_key, |
385 | unsigned key_len, u32 *flags) | 385 | unsigned key_len) |
386 | { | 386 | { |
387 | int i; | 387 | int i; |
388 | u32 key[8]; | 388 | u32 key[8]; |
389 | __be32 p_key[8]; /* padded key */ | 389 | __be32 p_key[8]; /* padded key */ |
390 | struct cast6_ctx *c = crypto_tfm_ctx(tfm); | 390 | struct cast6_ctx *c = crypto_tfm_ctx(tfm); |
391 | u32 *flags = &tfm->crt_flags; | ||
391 | 392 | ||
392 | if (key_len < 16 || key_len > 32 || key_len % 4 != 0) { | 393 | if (key_len % 4 != 0) { |
393 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | 394 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
394 | return -EINVAL; | 395 | return -EINVAL; |
395 | } | 396 | } |
diff --git a/crypto/cipher.c b/crypto/cipher.c index b899eb97abd7..56406a4a88d4 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c | |||
@@ -264,12 +264,12 @@ static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) | |||
264 | { | 264 | { |
265 | struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher; | 265 | struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher; |
266 | 266 | ||
267 | tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; | ||
267 | if (keylen < cia->cia_min_keysize || keylen > cia->cia_max_keysize) { | 268 | if (keylen < cia->cia_min_keysize || keylen > cia->cia_max_keysize) { |
268 | tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | 269 | tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
269 | return -EINVAL; | 270 | return -EINVAL; |
270 | } else | 271 | } else |
271 | return cia->cia_setkey(tfm, key, keylen, | 272 | return cia->cia_setkey(tfm, key, keylen); |
272 | &tfm->crt_flags); | ||
273 | } | 273 | } |
274 | 274 | ||
275 | static int ecb_encrypt(struct crypto_tfm *tfm, | 275 | static int ecb_encrypt(struct crypto_tfm *tfm, |
diff --git a/crypto/crc32c.c b/crypto/crc32c.c index 91ecd895e957..0fa744392a4c 100644 --- a/crypto/crc32c.c +++ b/crypto/crc32c.c | |||
@@ -44,13 +44,12 @@ static void chksum_init(struct crypto_tfm *tfm) | |||
44 | * the seed. | 44 | * the seed. |
45 | */ | 45 | */ |
46 | static int chksum_setkey(struct crypto_tfm *tfm, const u8 *key, | 46 | static int chksum_setkey(struct crypto_tfm *tfm, const u8 *key, |
47 | unsigned int keylen, u32 *flags) | 47 | unsigned int keylen) |
48 | { | 48 | { |
49 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); | 49 | struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); |
50 | 50 | ||
51 | if (keylen != sizeof(mctx->crc)) { | 51 | if (keylen != sizeof(mctx->crc)) { |
52 | if (flags) | 52 | tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
53 | *flags = CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
54 | return -EINVAL; | 53 | return -EINVAL; |
55 | } | 54 | } |
56 | mctx->key = le32_to_cpu(*(__le32 *)key); | 55 | mctx->key = le32_to_cpu(*(__le32 *)key); |
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c index a0d956b52949..24dbb5d8617e 100644 --- a/crypto/crypto_null.c +++ b/crypto/crypto_null.c | |||
@@ -48,7 +48,7 @@ static void null_final(struct crypto_tfm *tfm, u8 *out) | |||
48 | { } | 48 | { } |
49 | 49 | ||
50 | static int null_setkey(struct crypto_tfm *tfm, const u8 *key, | 50 | static int null_setkey(struct crypto_tfm *tfm, const u8 *key, |
51 | unsigned int keylen, u32 *flags) | 51 | unsigned int keylen) |
52 | { return 0; } | 52 | { return 0; } |
53 | 53 | ||
54 | static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | 54 | static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
diff --git a/crypto/des.c b/crypto/des.c index a9d3c235a6af..1df3a714fa47 100644 --- a/crypto/des.c +++ b/crypto/des.c | |||
@@ -784,9 +784,10 @@ static void dkey(u32 *pe, const u8 *k) | |||
784 | } | 784 | } |
785 | 785 | ||
786 | static int des_setkey(struct crypto_tfm *tfm, const u8 *key, | 786 | static int des_setkey(struct crypto_tfm *tfm, const u8 *key, |
787 | unsigned int keylen, u32 *flags) | 787 | unsigned int keylen) |
788 | { | 788 | { |
789 | struct des_ctx *dctx = crypto_tfm_ctx(tfm); | 789 | struct des_ctx *dctx = crypto_tfm_ctx(tfm); |
790 | u32 *flags = &tfm->crt_flags; | ||
790 | u32 tmp[DES_EXPKEY_WORDS]; | 791 | u32 tmp[DES_EXPKEY_WORDS]; |
791 | int ret; | 792 | int ret; |
792 | 793 | ||
@@ -864,11 +865,12 @@ static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
864 | * | 865 | * |
865 | */ | 866 | */ |
866 | static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, | 867 | static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, |
867 | unsigned int keylen, u32 *flags) | 868 | unsigned int keylen) |
868 | { | 869 | { |
869 | const u32 *K = (const u32 *)key; | 870 | const u32 *K = (const u32 *)key; |
870 | struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); | 871 | struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); |
871 | u32 *expkey = dctx->expkey; | 872 | u32 *expkey = dctx->expkey; |
873 | u32 *flags = &tfm->crt_flags; | ||
872 | 874 | ||
873 | if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || | 875 | if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || |
874 | !((K[2] ^ K[4]) | (K[3] ^ K[5])))) | 876 | !((K[2] ^ K[4]) | (K[3] ^ K[5])))) |
diff --git a/crypto/digest.c b/crypto/digest.c index 603006a7bef2..0df7f392a56a 100644 --- a/crypto/digest.c +++ b/crypto/digest.c | |||
@@ -76,12 +76,16 @@ static void final(struct crypto_tfm *tfm, u8 *out) | |||
76 | tfm->__crt_alg->cra_digest.dia_final(tfm, out); | 76 | tfm->__crt_alg->cra_digest.dia_final(tfm, out); |
77 | } | 77 | } |
78 | 78 | ||
79 | static int nosetkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) | ||
80 | { | ||
81 | tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; | ||
82 | return -ENOSYS; | ||
83 | } | ||
84 | |||
79 | static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) | 85 | static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) |
80 | { | 86 | { |
81 | u32 flags; | 87 | tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; |
82 | if (tfm->__crt_alg->cra_digest.dia_setkey == NULL) | 88 | return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen); |
83 | return -ENOSYS; | ||
84 | return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen, &flags); | ||
85 | } | 89 | } |
86 | 90 | ||
87 | static void digest(struct crypto_tfm *tfm, | 91 | static void digest(struct crypto_tfm *tfm, |
@@ -100,12 +104,13 @@ int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags) | |||
100 | int crypto_init_digest_ops(struct crypto_tfm *tfm) | 104 | int crypto_init_digest_ops(struct crypto_tfm *tfm) |
101 | { | 105 | { |
102 | struct digest_tfm *ops = &tfm->crt_digest; | 106 | struct digest_tfm *ops = &tfm->crt_digest; |
107 | struct digest_alg *dalg = &tfm->__crt_alg->cra_digest; | ||
103 | 108 | ||
104 | ops->dit_init = init; | 109 | ops->dit_init = init; |
105 | ops->dit_update = update; | 110 | ops->dit_update = update; |
106 | ops->dit_final = final; | 111 | ops->dit_final = final; |
107 | ops->dit_digest = digest; | 112 | ops->dit_digest = digest; |
108 | ops->dit_setkey = setkey; | 113 | ops->dit_setkey = dalg->dia_setkey ? setkey : nosetkey; |
109 | 114 | ||
110 | return crypto_alloc_hmac_block(tfm); | 115 | return crypto_alloc_hmac_block(tfm); |
111 | } | 116 | } |
diff --git a/crypto/khazad.c b/crypto/khazad.c index d4c9d3657b36..9fa24a2dd6ff 100644 --- a/crypto/khazad.c +++ b/crypto/khazad.c | |||
@@ -755,19 +755,13 @@ static const u64 c[KHAZAD_ROUNDS + 1] = { | |||
755 | }; | 755 | }; |
756 | 756 | ||
757 | static int khazad_setkey(struct crypto_tfm *tfm, const u8 *in_key, | 757 | static int khazad_setkey(struct crypto_tfm *tfm, const u8 *in_key, |
758 | unsigned int key_len, u32 *flags) | 758 | unsigned int key_len) |
759 | { | 759 | { |
760 | struct khazad_ctx *ctx = crypto_tfm_ctx(tfm); | 760 | struct khazad_ctx *ctx = crypto_tfm_ctx(tfm); |
761 | const __be32 *key = (const __be32 *)in_key; | 761 | const __be32 *key = (const __be32 *)in_key; |
762 | int r; | 762 | int r; |
763 | const u64 *S = T7; | 763 | const u64 *S = T7; |
764 | u64 K2, K1; | 764 | u64 K2, K1; |
765 | |||
766 | if (key_len != 16) | ||
767 | { | ||
768 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
769 | return -EINVAL; | ||
770 | } | ||
771 | 765 | ||
772 | /* key is supposed to be 32-bit aligned */ | 766 | /* key is supposed to be 32-bit aligned */ |
773 | K2 = ((u64)be32_to_cpu(key[0]) << 32) | be32_to_cpu(key[1]); | 767 | K2 = ((u64)be32_to_cpu(key[0]) << 32) | be32_to_cpu(key[1]); |
diff --git a/crypto/michael_mic.c b/crypto/michael_mic.c index d061da21cfda..094397b48849 100644 --- a/crypto/michael_mic.c +++ b/crypto/michael_mic.c | |||
@@ -123,14 +123,13 @@ static void michael_final(struct crypto_tfm *tfm, u8 *out) | |||
123 | 123 | ||
124 | 124 | ||
125 | static int michael_setkey(struct crypto_tfm *tfm, const u8 *key, | 125 | static int michael_setkey(struct crypto_tfm *tfm, const u8 *key, |
126 | unsigned int keylen, u32 *flags) | 126 | unsigned int keylen) |
127 | { | 127 | { |
128 | struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm); | 128 | struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm); |
129 | const __le32 *data = (const __le32 *)key; | 129 | const __le32 *data = (const __le32 *)key; |
130 | 130 | ||
131 | if (keylen != 8) { | 131 | if (keylen != 8) { |
132 | if (flags) | 132 | tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
133 | *flags = CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
134 | return -EINVAL; | 133 | return -EINVAL; |
135 | } | 134 | } |
136 | 135 | ||
diff --git a/crypto/serpent.c b/crypto/serpent.c index de60cdddbf4a..465d091cd3ec 100644 --- a/crypto/serpent.c +++ b/crypto/serpent.c | |||
@@ -216,7 +216,7 @@ struct serpent_ctx { | |||
216 | 216 | ||
217 | 217 | ||
218 | static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key, | 218 | static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key, |
219 | unsigned int keylen, u32 *flags) | 219 | unsigned int keylen) |
220 | { | 220 | { |
221 | struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); | 221 | struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); |
222 | u32 *k = ctx->expkey; | 222 | u32 *k = ctx->expkey; |
@@ -224,13 +224,6 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
224 | u32 r0,r1,r2,r3,r4; | 224 | u32 r0,r1,r2,r3,r4; |
225 | int i; | 225 | int i; |
226 | 226 | ||
227 | if ((keylen < SERPENT_MIN_KEY_SIZE) | ||
228 | || (keylen > SERPENT_MAX_KEY_SIZE)) | ||
229 | { | ||
230 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
231 | return -EINVAL; | ||
232 | } | ||
233 | |||
234 | /* Copy key, add padding */ | 227 | /* Copy key, add padding */ |
235 | 228 | ||
236 | for (i = 0; i < keylen; ++i) | 229 | for (i = 0; i < keylen; ++i) |
@@ -497,21 +490,15 @@ static struct crypto_alg serpent_alg = { | |||
497 | }; | 490 | }; |
498 | 491 | ||
499 | static int tnepres_setkey(struct crypto_tfm *tfm, const u8 *key, | 492 | static int tnepres_setkey(struct crypto_tfm *tfm, const u8 *key, |
500 | unsigned int keylen, u32 *flags) | 493 | unsigned int keylen) |
501 | { | 494 | { |
502 | u8 rev_key[SERPENT_MAX_KEY_SIZE]; | 495 | u8 rev_key[SERPENT_MAX_KEY_SIZE]; |
503 | int i; | 496 | int i; |
504 | 497 | ||
505 | if ((keylen < SERPENT_MIN_KEY_SIZE) | ||
506 | || (keylen > SERPENT_MAX_KEY_SIZE)) { | ||
507 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
508 | return -EINVAL; | ||
509 | } | ||
510 | |||
511 | for (i = 0; i < keylen; ++i) | 498 | for (i = 0; i < keylen; ++i) |
512 | rev_key[keylen - i - 1] = key[i]; | 499 | rev_key[keylen - i - 1] = key[i]; |
513 | 500 | ||
514 | return serpent_setkey(tfm, rev_key, keylen, flags); | 501 | return serpent_setkey(tfm, rev_key, keylen); |
515 | } | 502 | } |
516 | 503 | ||
517 | static void tnepres_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | 504 | static void tnepres_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index bed225e83231..606777074671 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -118,10 +118,7 @@ static void test_hash(char *algo, struct hash_testvec *template, | |||
118 | sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize); | 118 | sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize); |
119 | 119 | ||
120 | crypto_digest_init(tfm); | 120 | crypto_digest_init(tfm); |
121 | if (tfm->crt_u.digest.dit_setkey) { | 121 | crypto_digest_setkey(tfm, hash_tv[i].key, hash_tv[i].ksize); |
122 | crypto_digest_setkey(tfm, hash_tv[i].key, | ||
123 | hash_tv[i].ksize); | ||
124 | } | ||
125 | crypto_digest_update(tfm, sg, 1); | 122 | crypto_digest_update(tfm, sg, 1); |
126 | crypto_digest_final(tfm, result); | 123 | crypto_digest_final(tfm, result); |
127 | 124 | ||
diff --git a/crypto/tea.c b/crypto/tea.c index 5367adc82fc9..1c54e26fa529 100644 --- a/crypto/tea.c +++ b/crypto/tea.c | |||
@@ -46,16 +46,10 @@ struct xtea_ctx { | |||
46 | }; | 46 | }; |
47 | 47 | ||
48 | static int tea_setkey(struct crypto_tfm *tfm, const u8 *in_key, | 48 | static int tea_setkey(struct crypto_tfm *tfm, const u8 *in_key, |
49 | unsigned int key_len, u32 *flags) | 49 | unsigned int key_len) |
50 | { | 50 | { |
51 | struct tea_ctx *ctx = crypto_tfm_ctx(tfm); | 51 | struct tea_ctx *ctx = crypto_tfm_ctx(tfm); |
52 | const __le32 *key = (const __le32 *)in_key; | 52 | const __le32 *key = (const __le32 *)in_key; |
53 | |||
54 | if (key_len != 16) | ||
55 | { | ||
56 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
57 | return -EINVAL; | ||
58 | } | ||
59 | 53 | ||
60 | ctx->KEY[0] = le32_to_cpu(key[0]); | 54 | ctx->KEY[0] = le32_to_cpu(key[0]); |
61 | ctx->KEY[1] = le32_to_cpu(key[1]); | 55 | ctx->KEY[1] = le32_to_cpu(key[1]); |
@@ -125,16 +119,10 @@ static void tea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
125 | } | 119 | } |
126 | 120 | ||
127 | static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key, | 121 | static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key, |
128 | unsigned int key_len, u32 *flags) | 122 | unsigned int key_len) |
129 | { | 123 | { |
130 | struct xtea_ctx *ctx = crypto_tfm_ctx(tfm); | 124 | struct xtea_ctx *ctx = crypto_tfm_ctx(tfm); |
131 | const __le32 *key = (const __le32 *)in_key; | 125 | const __le32 *key = (const __le32 *)in_key; |
132 | |||
133 | if (key_len != 16) | ||
134 | { | ||
135 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
136 | return -EINVAL; | ||
137 | } | ||
138 | 126 | ||
139 | ctx->KEY[0] = le32_to_cpu(key[0]); | 127 | ctx->KEY[0] = le32_to_cpu(key[0]); |
140 | ctx->KEY[1] = le32_to_cpu(key[1]); | 128 | ctx->KEY[1] = le32_to_cpu(key[1]); |
diff --git a/crypto/twofish_common.c b/crypto/twofish_common.c index 1ae0280c2513..b4b9c0c3f4ae 100644 --- a/crypto/twofish_common.c +++ b/crypto/twofish_common.c | |||
@@ -580,11 +580,11 @@ static const u8 calc_sb_tbl[512] = { | |||
580 | ctx->a[(j) + 1] = rol32(y, 9) | 580 | ctx->a[(j) + 1] = rol32(y, 9) |
581 | 581 | ||
582 | /* Perform the key setup. */ | 582 | /* Perform the key setup. */ |
583 | int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, | 583 | int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len) |
584 | unsigned int key_len, u32 *flags) | ||
585 | { | 584 | { |
586 | 585 | ||
587 | struct twofish_ctx *ctx = crypto_tfm_ctx(tfm); | 586 | struct twofish_ctx *ctx = crypto_tfm_ctx(tfm); |
587 | u32 *flags = &tfm->crt_flags; | ||
588 | 588 | ||
589 | int i, j, k; | 589 | int i, j, k; |
590 | 590 | ||
@@ -600,7 +600,7 @@ int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
600 | u8 tmp; | 600 | u8 tmp; |
601 | 601 | ||
602 | /* Check key length. */ | 602 | /* Check key length. */ |
603 | if (key_len != 16 && key_len != 24 && key_len != 32) | 603 | if (key_len % 8) |
604 | { | 604 | { |
605 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | 605 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
606 | return -EINVAL; /* unsupported key length */ | 606 | return -EINVAL; /* unsupported key length */ |
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c index 3a2a71108d35..3e683709243e 100644 --- a/drivers/crypto/padlock-aes.c +++ b/drivers/crypto/padlock-aes.c | |||
@@ -308,15 +308,16 @@ static inline struct aes_ctx *aes_ctx(struct crypto_tfm *tfm) | |||
308 | } | 308 | } |
309 | 309 | ||
310 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | 310 | static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, |
311 | unsigned int key_len, u32 *flags) | 311 | unsigned int key_len) |
312 | { | 312 | { |
313 | struct aes_ctx *ctx = aes_ctx(tfm); | 313 | struct aes_ctx *ctx = aes_ctx(tfm); |
314 | const __le32 *key = (const __le32 *)in_key; | 314 | const __le32 *key = (const __le32 *)in_key; |
315 | u32 *flags = &tfm->crt_flags; | ||
315 | uint32_t i, t, u, v, w; | 316 | uint32_t i, t, u, v, w; |
316 | uint32_t P[AES_EXTENDED_KEY_SIZE]; | 317 | uint32_t P[AES_EXTENDED_KEY_SIZE]; |
317 | uint32_t rounds; | 318 | uint32_t rounds; |
318 | 319 | ||
319 | if (key_len != 16 && key_len != 24 && key_len != 32) { | 320 | if (key_len % 8) { |
320 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | 321 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
321 | return -EINVAL; | 322 | return -EINVAL; |
322 | } | 323 | } |
diff --git a/include/crypto/twofish.h b/include/crypto/twofish.h index e4328cfaaf64..c408522595c6 100644 --- a/include/crypto/twofish.h +++ b/include/crypto/twofish.h | |||
@@ -17,7 +17,6 @@ struct twofish_ctx { | |||
17 | u32 s[4][256], w[8], k[32]; | 17 | u32 s[4][256], w[8], k[32]; |
18 | }; | 18 | }; |
19 | 19 | ||
20 | int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, | 20 | int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len); |
21 | unsigned int key_len, u32 *flags); | ||
22 | 21 | ||
23 | #endif | 22 | #endif |
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index d6e184c876b5..053bfab43e8d 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -106,7 +106,7 @@ struct cipher_alg { | |||
106 | unsigned int cia_min_keysize; | 106 | unsigned int cia_min_keysize; |
107 | unsigned int cia_max_keysize; | 107 | unsigned int cia_max_keysize; |
108 | int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, | 108 | int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
109 | unsigned int keylen, u32 *flags); | 109 | unsigned int keylen); |
110 | void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | 110 | void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
111 | void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | 111 | void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
112 | 112 | ||
@@ -131,7 +131,7 @@ struct digest_alg { | |||
131 | unsigned int len); | 131 | unsigned int len); |
132 | void (*dia_final)(struct crypto_tfm *tfm, u8 *out); | 132 | void (*dia_final)(struct crypto_tfm *tfm, u8 *out); |
133 | int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key, | 133 | int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
134 | unsigned int keylen, u32 *flags); | 134 | unsigned int keylen); |
135 | }; | 135 | }; |
136 | 136 | ||
137 | struct compress_alg { | 137 | struct compress_alg { |
@@ -397,8 +397,6 @@ static inline int crypto_digest_setkey(struct crypto_tfm *tfm, | |||
397 | const u8 *key, unsigned int keylen) | 397 | const u8 *key, unsigned int keylen) |
398 | { | 398 | { |
399 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 399 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); |
400 | if (tfm->crt_digest.dit_setkey == NULL) | ||
401 | return -ENOSYS; | ||
402 | return tfm->crt_digest.dit_setkey(tfm, key, keylen); | 400 | return tfm->crt_digest.dit_setkey(tfm, key, keylen); |
403 | } | 401 | } |
404 | 402 | ||