aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/crypto.h')
-rw-r--r--include/linux/crypto.h90
1 files changed, 84 insertions, 6 deletions
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
238int crypto_alg_available(const char *name, u32 flags); 238int crypto_alg_available(const char *name, u32 flags);
239int crypto_has_alg(const char *name, u32 type, u32 mask);
239#else 240#else
240static inline int crypto_alg_available(const char *name, u32 flags) 241static inline int crypto_alg_available(const char *name, u32 flags)
241{ 242{
242 return 0; 243 return 0;
243} 244}
245
246static 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
333struct crypto_blkcipher { 340struct 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
495static 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
488static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm) 504static 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
639static 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
623static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm) 648static 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
746static 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
721static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm) 755static 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
856static inline int crypto_comp_compress(struct crypto_tfm *tfm, 890static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)
891{
892 return (struct crypto_comp *)tfm;
893}
894
895static 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
902static 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
912static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm)
913{
914 return tfm;
915}
916
917static inline void crypto_free_comp(struct crypto_comp *tfm)
918{
919 crypto_free_tfm(crypto_comp_tfm(tfm));
920}
921
922static 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
931static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm)
932{
933 return &crypto_comp_tfm(tfm)->crt_compress;
934}
935
936static 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
864static inline int crypto_comp_decompress(struct crypto_tfm *tfm, 943static 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 */