diff options
-rw-r--r-- | crypto/cipher.c | 34 | ||||
-rw-r--r-- | include/linux/crypto.h | 48 |
2 files changed, 64 insertions, 18 deletions
diff --git a/crypto/cipher.c b/crypto/cipher.c index 326461780673..9e03701cfdcc 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c | |||
@@ -23,6 +23,28 @@ | |||
23 | #include "internal.h" | 23 | #include "internal.h" |
24 | #include "scatterwalk.h" | 24 | #include "scatterwalk.h" |
25 | 25 | ||
26 | struct cipher_alg_compat { | ||
27 | unsigned int cia_min_keysize; | ||
28 | unsigned int cia_max_keysize; | ||
29 | int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, | ||
30 | unsigned int keylen); | ||
31 | void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | ||
32 | void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | ||
33 | |||
34 | unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc, | ||
35 | u8 *dst, const u8 *src, | ||
36 | unsigned int nbytes); | ||
37 | unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc, | ||
38 | u8 *dst, const u8 *src, | ||
39 | unsigned int nbytes); | ||
40 | unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc, | ||
41 | u8 *dst, const u8 *src, | ||
42 | unsigned int nbytes); | ||
43 | unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc, | ||
44 | u8 *dst, const u8 *src, | ||
45 | unsigned int nbytes); | ||
46 | }; | ||
47 | |||
26 | static inline void xor_64(u8 *a, const u8 *b) | 48 | static inline void xor_64(u8 *a, const u8 *b) |
27 | { | 49 | { |
28 | ((u32 *)a)[0] ^= ((u32 *)b)[0]; | 50 | ((u32 *)a)[0] ^= ((u32 *)b)[0]; |
@@ -276,7 +298,7 @@ static int ecb_encrypt(struct crypto_tfm *tfm, | |||
276 | struct scatterlist *src, unsigned int nbytes) | 298 | struct scatterlist *src, unsigned int nbytes) |
277 | { | 299 | { |
278 | struct cipher_desc desc; | 300 | struct cipher_desc desc; |
279 | struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; | 301 | struct cipher_alg_compat *cipher = (void *)&tfm->__crt_alg->cra_cipher; |
280 | 302 | ||
281 | desc.tfm = tfm; | 303 | desc.tfm = tfm; |
282 | desc.crfn = cipher->cia_encrypt; | 304 | desc.crfn = cipher->cia_encrypt; |
@@ -291,7 +313,7 @@ static int ecb_decrypt(struct crypto_tfm *tfm, | |||
291 | unsigned int nbytes) | 313 | unsigned int nbytes) |
292 | { | 314 | { |
293 | struct cipher_desc desc; | 315 | struct cipher_desc desc; |
294 | struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; | 316 | struct cipher_alg_compat *cipher = (void *)&tfm->__crt_alg->cra_cipher; |
295 | 317 | ||
296 | desc.tfm = tfm; | 318 | desc.tfm = tfm; |
297 | desc.crfn = cipher->cia_decrypt; | 319 | desc.crfn = cipher->cia_decrypt; |
@@ -306,7 +328,7 @@ static int cbc_encrypt(struct crypto_tfm *tfm, | |||
306 | unsigned int nbytes) | 328 | unsigned int nbytes) |
307 | { | 329 | { |
308 | struct cipher_desc desc; | 330 | struct cipher_desc desc; |
309 | struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; | 331 | struct cipher_alg_compat *cipher = (void *)&tfm->__crt_alg->cra_cipher; |
310 | 332 | ||
311 | desc.tfm = tfm; | 333 | desc.tfm = tfm; |
312 | desc.crfn = cipher->cia_encrypt; | 334 | desc.crfn = cipher->cia_encrypt; |
@@ -322,7 +344,7 @@ static int cbc_encrypt_iv(struct crypto_tfm *tfm, | |||
322 | unsigned int nbytes, u8 *iv) | 344 | unsigned int nbytes, u8 *iv) |
323 | { | 345 | { |
324 | struct cipher_desc desc; | 346 | struct cipher_desc desc; |
325 | struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; | 347 | struct cipher_alg_compat *cipher = (void *)&tfm->__crt_alg->cra_cipher; |
326 | 348 | ||
327 | desc.tfm = tfm; | 349 | desc.tfm = tfm; |
328 | desc.crfn = cipher->cia_encrypt; | 350 | desc.crfn = cipher->cia_encrypt; |
@@ -338,7 +360,7 @@ static int cbc_decrypt(struct crypto_tfm *tfm, | |||
338 | unsigned int nbytes) | 360 | unsigned int nbytes) |
339 | { | 361 | { |
340 | struct cipher_desc desc; | 362 | struct cipher_desc desc; |
341 | struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; | 363 | struct cipher_alg_compat *cipher = (void *)&tfm->__crt_alg->cra_cipher; |
342 | 364 | ||
343 | desc.tfm = tfm; | 365 | desc.tfm = tfm; |
344 | desc.crfn = cipher->cia_decrypt; | 366 | desc.crfn = cipher->cia_decrypt; |
@@ -354,7 +376,7 @@ static int cbc_decrypt_iv(struct crypto_tfm *tfm, | |||
354 | unsigned int nbytes, u8 *iv) | 376 | unsigned int nbytes, u8 *iv) |
355 | { | 377 | { |
356 | struct cipher_desc desc; | 378 | struct cipher_desc desc; |
357 | struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; | 379 | struct cipher_alg_compat *cipher = (void *)&tfm->__crt_alg->cra_cipher; |
358 | 380 | ||
359 | desc.tfm = tfm; | 381 | desc.tfm = tfm; |
360 | desc.crfn = cipher->cia_decrypt; | 382 | desc.crfn = cipher->cia_decrypt; |
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 5a5466d518e8..0be666b50463 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <asm/atomic.h> | 20 | #include <asm/atomic.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
23 | #include <linux/types.h> | ||
24 | #include <linux/list.h> | 23 | #include <linux/list.h> |
25 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
26 | #include <linux/string.h> | 25 | #include <linux/string.h> |
@@ -137,16 +136,16 @@ struct cipher_alg { | |||
137 | 136 | ||
138 | unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc, | 137 | unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc, |
139 | u8 *dst, const u8 *src, | 138 | u8 *dst, const u8 *src, |
140 | unsigned int nbytes); | 139 | unsigned int nbytes) __deprecated; |
141 | unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc, | 140 | unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc, |
142 | u8 *dst, const u8 *src, | 141 | u8 *dst, const u8 *src, |
143 | unsigned int nbytes); | 142 | unsigned int nbytes) __deprecated; |
144 | unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc, | 143 | unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc, |
145 | u8 *dst, const u8 *src, | 144 | u8 *dst, const u8 *src, |
146 | unsigned int nbytes); | 145 | unsigned int nbytes) __deprecated; |
147 | unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc, | 146 | unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc, |
148 | u8 *dst, const u8 *src, | 147 | u8 *dst, const u8 *src, |
149 | unsigned int nbytes); | 148 | unsigned int nbytes) __deprecated; |
150 | }; | 149 | }; |
151 | 150 | ||
152 | struct digest_alg { | 151 | struct digest_alg { |
@@ -358,18 +357,23 @@ static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm) | |||
358 | return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; | 357 | return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; |
359 | } | 358 | } |
360 | 359 | ||
360 | static unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) | ||
361 | __deprecated; | ||
361 | static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) | 362 | static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) |
362 | { | 363 | { |
363 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 364 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
364 | return tfm->__crt_alg->cra_cipher.cia_min_keysize; | 365 | return tfm->__crt_alg->cra_cipher.cia_min_keysize; |
365 | } | 366 | } |
366 | 367 | ||
368 | static unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) | ||
369 | __deprecated; | ||
367 | static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) | 370 | static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) |
368 | { | 371 | { |
369 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 372 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
370 | return tfm->__crt_alg->cra_cipher.cia_max_keysize; | 373 | return tfm->__crt_alg->cra_cipher.cia_max_keysize; |
371 | } | 374 | } |
372 | 375 | ||
376 | static unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) __deprecated; | ||
373 | static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) | 377 | static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) |
374 | { | 378 | { |
375 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 379 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
@@ -622,6 +626,13 @@ static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm, | |||
622 | crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags); | 626 | crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags); |
623 | } | 627 | } |
624 | 628 | ||
629 | static inline int crypto_cipher_setkey(struct crypto_cipher *tfm, | ||
630 | const u8 *key, unsigned int keylen) | ||
631 | { | ||
632 | return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm), | ||
633 | key, keylen); | ||
634 | } | ||
635 | |||
625 | static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, | 636 | static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, |
626 | u8 *dst, const u8 *src) | 637 | u8 *dst, const u8 *src) |
627 | { | 638 | { |
@@ -671,13 +682,10 @@ static inline int crypto_digest_setkey(struct crypto_tfm *tfm, | |||
671 | return tfm->crt_digest.dit_setkey(tfm, key, keylen); | 682 | return tfm->crt_digest.dit_setkey(tfm, key, keylen); |
672 | } | 683 | } |
673 | 684 | ||
674 | static inline int crypto_cipher_setkey(struct crypto_tfm *tfm, | 685 | static int crypto_cipher_encrypt(struct crypto_tfm *tfm, |
675 | const u8 *key, unsigned int keylen) | 686 | struct scatterlist *dst, |
676 | { | 687 | struct scatterlist *src, |
677 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 688 | unsigned int nbytes) __deprecated; |
678 | return tfm->crt_cipher.cit_setkey(tfm, key, keylen); | ||
679 | } | ||
680 | |||
681 | static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, | 689 | static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, |
682 | struct scatterlist *dst, | 690 | struct scatterlist *dst, |
683 | struct scatterlist *src, | 691 | struct scatterlist *src, |
@@ -687,6 +695,10 @@ static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, | |||
687 | return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes); | 695 | return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes); |
688 | } | 696 | } |
689 | 697 | ||
698 | static int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, | ||
699 | struct scatterlist *dst, | ||
700 | struct scatterlist *src, | ||
701 | unsigned int nbytes, u8 *iv) __deprecated; | ||
690 | static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, | 702 | static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, |
691 | struct scatterlist *dst, | 703 | struct scatterlist *dst, |
692 | struct scatterlist *src, | 704 | struct scatterlist *src, |
@@ -696,6 +708,10 @@ static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, | |||
696 | return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv); | 708 | return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv); |
697 | } | 709 | } |
698 | 710 | ||
711 | static int crypto_cipher_decrypt(struct crypto_tfm *tfm, | ||
712 | struct scatterlist *dst, | ||
713 | struct scatterlist *src, | ||
714 | unsigned int nbytes) __deprecated; | ||
699 | static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, | 715 | static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, |
700 | struct scatterlist *dst, | 716 | struct scatterlist *dst, |
701 | struct scatterlist *src, | 717 | struct scatterlist *src, |
@@ -705,6 +721,10 @@ static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, | |||
705 | return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes); | 721 | return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes); |
706 | } | 722 | } |
707 | 723 | ||
724 | static int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, | ||
725 | struct scatterlist *dst, | ||
726 | struct scatterlist *src, | ||
727 | unsigned int nbytes, u8 *iv) __deprecated; | ||
708 | static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, | 728 | static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, |
709 | struct scatterlist *dst, | 729 | struct scatterlist *dst, |
710 | struct scatterlist *src, | 730 | struct scatterlist *src, |
@@ -714,6 +734,8 @@ static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, | |||
714 | return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv); | 734 | return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv); |
715 | } | 735 | } |
716 | 736 | ||
737 | static void crypto_cipher_set_iv(struct crypto_tfm *tfm, | ||
738 | const u8 *src, unsigned int len) __deprecated; | ||
717 | static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, | 739 | static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, |
718 | const u8 *src, unsigned int len) | 740 | const u8 *src, unsigned int len) |
719 | { | 741 | { |
@@ -721,6 +743,8 @@ static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, | |||
721 | memcpy(tfm->crt_cipher.cit_iv, src, len); | 743 | memcpy(tfm->crt_cipher.cit_iv, src, len); |
722 | } | 744 | } |
723 | 745 | ||
746 | static void crypto_cipher_get_iv(struct crypto_tfm *tfm, | ||
747 | u8 *dst, unsigned int len) __deprecated; | ||
724 | static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, | 748 | static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, |
725 | u8 *dst, unsigned int len) | 749 | u8 *dst, unsigned int len) |
726 | { | 750 | { |