diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2006-08-26 03:35:45 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2006-09-20 21:46:21 -0400 |
commit | fce32d70ba834129b164c40c2d4260e5a7a7d850 (patch) | |
tree | 25076d25f1b95c93b276db253bc8cd301bae6289 | |
parent | 35058687912aa2f0b4554383cc10be4e0683b9a4 (diff) |
[CRYPTO] api: Add crypto_comp and crypto_has_*
This patch adds the crypto_comp type to complete the compile-time checking
conversion. The functions crypto_has_alg and crypto_has_cipher, etc. are
also added to replace crypto_alg_available.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/api.c | 14 | ||||
-rw-r--r-- | include/linux/crypto.h | 90 |
2 files changed, 98 insertions, 6 deletions
diff --git a/crypto/api.c b/crypto/api.c index edaa843d8e83..2e84d4b54790 100644 --- a/crypto/api.c +++ b/crypto/api.c | |||
@@ -482,3 +482,17 @@ int crypto_alg_available(const char *name, u32 flags) | |||
482 | EXPORT_SYMBOL_GPL(crypto_alloc_tfm); | 482 | EXPORT_SYMBOL_GPL(crypto_alloc_tfm); |
483 | EXPORT_SYMBOL_GPL(crypto_free_tfm); | 483 | EXPORT_SYMBOL_GPL(crypto_free_tfm); |
484 | EXPORT_SYMBOL_GPL(crypto_alg_available); | 484 | EXPORT_SYMBOL_GPL(crypto_alg_available); |
485 | |||
486 | int crypto_has_alg(const char *name, u32 type, u32 mask) | ||
487 | { | ||
488 | int ret = 0; | ||
489 | struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); | ||
490 | |||
491 | if (!IS_ERR(alg)) { | ||
492 | crypto_mod_put(alg); | ||
493 | ret = 1; | ||
494 | } | ||
495 | |||
496 | return ret; | ||
497 | } | ||
498 | EXPORT_SYMBOL_GPL(crypto_has_alg); | ||
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 929fb9ad1314..cf91c4c0638b 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -236,11 +236,17 @@ int crypto_unregister_alg(struct crypto_alg *alg); | |||
236 | */ | 236 | */ |
237 | #ifdef CONFIG_CRYPTO | 237 | #ifdef CONFIG_CRYPTO |
238 | int crypto_alg_available(const char *name, u32 flags); | 238 | int crypto_alg_available(const char *name, u32 flags); |
239 | int crypto_has_alg(const char *name, u32 type, u32 mask); | ||
239 | #else | 240 | #else |
240 | static inline int crypto_alg_available(const char *name, u32 flags) | 241 | static inline int crypto_alg_available(const char *name, u32 flags) |
241 | { | 242 | { |
242 | return 0; | 243 | return 0; |
243 | } | 244 | } |
245 | |||
246 | static inline int crypto_has_alg(const char *name, u32 type, u32 mask) | ||
247 | { | ||
248 | return 0; | ||
249 | } | ||
244 | #endif | 250 | #endif |
245 | 251 | ||
246 | /* | 252 | /* |
@@ -329,6 +335,7 @@ struct crypto_tfm { | |||
329 | }; | 335 | }; |
330 | 336 | ||
331 | #define crypto_cipher crypto_tfm | 337 | #define crypto_cipher crypto_tfm |
338 | #define crypto_comp crypto_tfm | ||
332 | 339 | ||
333 | struct crypto_blkcipher { | 340 | struct crypto_blkcipher { |
334 | struct crypto_tfm base; | 341 | struct crypto_tfm base; |
@@ -485,6 +492,15 @@ static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm) | |||
485 | crypto_free_tfm(crypto_blkcipher_tfm(tfm)); | 492 | crypto_free_tfm(crypto_blkcipher_tfm(tfm)); |
486 | } | 493 | } |
487 | 494 | ||
495 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) | ||
496 | { | ||
497 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
498 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | ||
499 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
500 | |||
501 | return crypto_has_alg(alg_name, type, mask); | ||
502 | } | ||
503 | |||
488 | static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm) | 504 | static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm) |
489 | { | 505 | { |
490 | return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm)); | 506 | return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm)); |
@@ -620,6 +636,15 @@ static inline void crypto_free_cipher(struct crypto_cipher *tfm) | |||
620 | crypto_free_tfm(crypto_cipher_tfm(tfm)); | 636 | crypto_free_tfm(crypto_cipher_tfm(tfm)); |
621 | } | 637 | } |
622 | 638 | ||
639 | static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask) | ||
640 | { | ||
641 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
642 | type |= CRYPTO_ALG_TYPE_CIPHER; | ||
643 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
644 | |||
645 | return crypto_has_alg(alg_name, type, mask); | ||
646 | } | ||
647 | |||
623 | static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm) | 648 | static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm) |
624 | { | 649 | { |
625 | return &crypto_cipher_tfm(tfm)->crt_cipher; | 650 | return &crypto_cipher_tfm(tfm)->crt_cipher; |
@@ -718,6 +743,15 @@ static inline void crypto_free_hash(struct crypto_hash *tfm) | |||
718 | crypto_free_tfm(crypto_hash_tfm(tfm)); | 743 | crypto_free_tfm(crypto_hash_tfm(tfm)); |
719 | } | 744 | } |
720 | 745 | ||
746 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) | ||
747 | { | ||
748 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
749 | type |= CRYPTO_ALG_TYPE_HASH; | ||
750 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; | ||
751 | |||
752 | return crypto_has_alg(alg_name, type, mask); | ||
753 | } | ||
754 | |||
721 | static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm) | 755 | static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm) |
722 | { | 756 | { |
723 | return &crypto_hash_tfm(tfm)->crt_hash; | 757 | return &crypto_hash_tfm(tfm)->crt_hash; |
@@ -853,20 +887,64 @@ static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, | |||
853 | memcpy(dst, tfm->crt_cipher.cit_iv, len); | 887 | memcpy(dst, tfm->crt_cipher.cit_iv, len); |
854 | } | 888 | } |
855 | 889 | ||
856 | static inline int crypto_comp_compress(struct crypto_tfm *tfm, | 890 | static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm) |
891 | { | ||
892 | return (struct crypto_comp *)tfm; | ||
893 | } | ||
894 | |||
895 | static inline struct crypto_comp *crypto_comp_cast(struct crypto_tfm *tfm) | ||
896 | { | ||
897 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_COMPRESS) & | ||
898 | CRYPTO_ALG_TYPE_MASK); | ||
899 | return __crypto_comp_cast(tfm); | ||
900 | } | ||
901 | |||
902 | static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name, | ||
903 | u32 type, u32 mask) | ||
904 | { | ||
905 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
906 | type |= CRYPTO_ALG_TYPE_COMPRESS; | ||
907 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
908 | |||
909 | return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask)); | ||
910 | } | ||
911 | |||
912 | static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm) | ||
913 | { | ||
914 | return tfm; | ||
915 | } | ||
916 | |||
917 | static inline void crypto_free_comp(struct crypto_comp *tfm) | ||
918 | { | ||
919 | crypto_free_tfm(crypto_comp_tfm(tfm)); | ||
920 | } | ||
921 | |||
922 | static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask) | ||
923 | { | ||
924 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
925 | type |= CRYPTO_ALG_TYPE_COMPRESS; | ||
926 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
927 | |||
928 | return crypto_has_alg(alg_name, type, mask); | ||
929 | } | ||
930 | |||
931 | static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm) | ||
932 | { | ||
933 | return &crypto_comp_tfm(tfm)->crt_compress; | ||
934 | } | ||
935 | |||
936 | static inline int crypto_comp_compress(struct crypto_comp *tfm, | ||
857 | const u8 *src, unsigned int slen, | 937 | const u8 *src, unsigned int slen, |
858 | u8 *dst, unsigned int *dlen) | 938 | u8 *dst, unsigned int *dlen) |
859 | { | 939 | { |
860 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); | 940 | return crypto_comp_crt(tfm)->cot_compress(tfm, src, slen, dst, dlen); |
861 | return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen); | ||
862 | } | 941 | } |
863 | 942 | ||
864 | static inline int crypto_comp_decompress(struct crypto_tfm *tfm, | 943 | static inline int crypto_comp_decompress(struct crypto_comp *tfm, |
865 | const u8 *src, unsigned int slen, | 944 | const u8 *src, unsigned int slen, |
866 | u8 *dst, unsigned int *dlen) | 945 | u8 *dst, unsigned int *dlen) |
867 | { | 946 | { |
868 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); | 947 | return crypto_comp_crt(tfm)->cot_decompress(tfm, src, slen, dst, dlen); |
869 | return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen); | ||
870 | } | 948 | } |
871 | 949 | ||
872 | #endif /* _LINUX_CRYPTO_H */ | 950 | #endif /* _LINUX_CRYPTO_H */ |