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
599599 * crypto_free_*(), as well as the various helpers below.
600600 */
601601
602−struct 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−
611602 struct crypto_tfm {
612603
613604 u32 crt_flags;
614605
615− union {
616− struct cipher_tfm cipher;
617− } crt_u;
618−
619606 void (*exit)(struct crypto_tfm *tfm);
620607
621608 struct crypto_alg *__crt_alg;
@@ -752,12 +739,6 @@ static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm) · 130 unmodified lines
752739 return (struct crypto_cipher *)tfm;
753740 }
754741
755−static 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−
761742 /**
762743 * crypto_alloc_cipher() - allocate single block cipher handle
763744 * @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
815796 return crypto_has_alg(alg_name, type, mask);
816797 }
817798
818−static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
819−{
820− return &crypto_cipher_tfm(tfm)->crt_cipher;
821−}
822−
823799 /**
824800 * crypto_cipher_blocksize() - obtain block size for cipher
825801 * @tfm: cipher handle
@@ -873,12 +849,8 @@ static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm, · 47 unmodified lines
873849 *
874850 * Return: 0 if the setting of the key was successful; < 0 if an error occurred
875851 */
876−static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,
877− const u8 *key, unsigned int keylen)
878−{
879− return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm),
880− key, keylen);
881−}
852+int crypto_cipher_setkey(struct crypto_cipher *tfm,
853+ const u8 *key, unsigned int keylen);
882854
883855 /**
884856 * 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
889861 * Invoke the encryption operation of one block. The caller must ensure that
890862 * the plaintext and ciphertext buffers are at least one block in size.
891863 */
892−static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
893− u8 *dst, const u8 *src)
894−{
895− crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
896− dst, src);
897−}
864+void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
865+ u8 *dst, const u8 *src);
898866
899867 /**
900868 * 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
905873 * Invoke the decryption operation of one block. The caller must ensure that
906874 * the plaintext and ciphertext buffers are at least one block in size.
907875 */
908−static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
909− u8 *dst, const u8 *src)
910−{
911− crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
912− dst, src);
913−}
876+void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
877+ u8 *dst, const u8 *src);
914878
915879 static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)
916880 {

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