History

crypto: cipher - remove crt_u.cipher (struct cipher_tfm)

Of the three fields in crt_u.cipher (struct cipher_tfm), ->cit_setkey() is pointless because it always points to setkey() in crypto/cipher.c. ->cit_decrypt_one() and ->cit_encrypt_one() are slightly less pointless, since if the algorithm doesn't have an alignmask, they are set directly to ->cia_encrypt() and ->cia_decrypt(). However, this "optimization" isn't worthwhile because: - The "cipher" algorithm type is the only algorithm still using crt_u, so it's bloating every struct crypto_tfm for every algorithm type. - If the algorithm has an alignmask, this "optimization" actually makes things slower, as it causes 2 indirect calls per block rather than 1. - It adds extra code complexity. - Some templates already call ->cia_encrypt()/->cia_decrypt() directly instead of going through ->cit_encrypt_one()/->cit_decrypt_one(). - The "cipher" algorithm type never gives optimal performance anyway. For that, a higher-level type such as skcipher needs to be used. Therefore, just remove the extra indirection, and make crypto_cipher_setkey(), crypto_cipher_encrypt_one(), and crypto_cipher_decrypt_one() be direct calls into crypto/cipher.c. Also remove the unused function crypto_cipher_cast().

Eric Biggers committed 6 years ago

Commit e8cfed51 parent c441a904 files · +43 −114Browse files

Showing the changes to include/linux (1 of 4 files). Show all

Unified · Split

include/linux/crypto.h+6−42
@@ -599,23 +599,10 @@ int crypto_has_alg(const char *name, u32 type, u32 mask); · 598 unmodified lines
599 * crypto_free_*(), as well as the various helpers below.599 * crypto_free_*(), as well as the various helpers below.
600 */600 */
601 601
602struct cipher_tfm {
603 int (*cit_setkey)(struct crypto_tfm *tfm,
604 const u8 *key, unsigned int keylen);
605 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
606 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
607};
608
609#define crt_cipher crt_u.cipher
610
611struct crypto_tfm {602struct crypto_tfm {
612 603
613 u32 crt_flags;604 u32 crt_flags;
614 605
615 union {
616 struct cipher_tfm cipher;
617 } crt_u;
618
619 void (*exit)(struct crypto_tfm *tfm);606 void (*exit)(struct crypto_tfm *tfm);
620 607
621 struct crypto_alg *__crt_alg;608 struct crypto_alg *__crt_alg;
@@ -752,12 +739,6 @@ static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm) · 130 unmodified lines
752 return (struct crypto_cipher *)tfm;739 return (struct crypto_cipher *)tfm;
753}740}
754 741
755static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm)
756{
757 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
758 return __crypto_cipher_cast(tfm);
759}
760
761/**742/**
762 * crypto_alloc_cipher() - allocate single block cipher handle743 * crypto_alloc_cipher() - allocate single block cipher handle
763 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the744 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
@@ -815,11 +796,6 @@ static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask) · 51 unmodified lines
815 return crypto_has_alg(alg_name, type, mask);796 return crypto_has_alg(alg_name, type, mask);
816}797}
817 798
818static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
819{
820 return &crypto_cipher_tfm(tfm)->crt_cipher;
821}
822
823/**799/**
824 * crypto_cipher_blocksize() - obtain block size for cipher800 * crypto_cipher_blocksize() - obtain block size for cipher
825 * @tfm: cipher handle801 * @tfm: cipher handle
@@ -873,12 +849,8 @@ static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm, · 47 unmodified lines
873 *849 *
874 * Return: 0 if the setting of the key was successful; < 0 if an error occurred850 * Return: 0 if the setting of the key was successful; < 0 if an error occurred
875 */851 */
876static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,852int crypto_cipher_setkey(struct crypto_cipher *tfm,
877 const u8 *key, unsigned int keylen)853 const u8 *key, unsigned int keylen);
878{
879 return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm),
880 key, keylen);
881}
882 854
883/**855/**
884 * crypto_cipher_encrypt_one() - encrypt one block of plaintext856 * crypto_cipher_encrypt_one() - encrypt one block of plaintext
@@ -889,12 +861,8 @@ static inline int crypto_cipher_setkey(struct crypto_cipher *tfm, · 4 unmodified lines
889 * Invoke the encryption operation of one block. The caller must ensure that861 * Invoke the encryption operation of one block. The caller must ensure that
890 * the plaintext and ciphertext buffers are at least one block in size.862 * the plaintext and ciphertext buffers are at least one block in size.
891 */863 */
892static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,864void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
893 u8 *dst, const u8 *src)865 u8 *dst, const u8 *src);
894{
895 crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
896 dst, src);
897}
898 866
899/**867/**
900 * crypto_cipher_decrypt_one() - decrypt one block of ciphertext868 * crypto_cipher_decrypt_one() - decrypt one block of ciphertext
@@ -905,12 +873,8 @@ static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, · 4 unmodified lines
905 * Invoke the decryption operation of one block. The caller must ensure that873 * Invoke the decryption operation of one block. The caller must ensure that
906 * the plaintext and ciphertext buffers are at least one block in size.874 * the plaintext and ciphertext buffers are at least one block in size.
907 */875 */
908static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,876void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
909 u8 *dst, const u8 *src)877 u8 *dst, const u8 *src);
910{
911 crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
912 dst, src);
913}
914 878
915static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)879static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)
916{880{

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t