crypto: api - remove crypto_tfm::crt_u
cover crypto: api - remove crypto_tfm::crt_u
This series removes the per-algorithm-type union from struct crypto_tfm now that its only remaining users are the "compress" and "cipher" algorithm types, and it's not really needed for them.
This shrinks every crypto transform for every algorithm by 28 bytes on 64-bit platforms (12 bytes on 32-bit), and also removes some code.
Note that the new-style strongly-typed algorithms (i.e. everything other than "compress" and "cipher") don't need crt_u, since they embed struct crypto_tfm in a per-algorithm-type custom struct instead.
Eric Biggers (2):
crypto: compress - remove crt_u.compress (struct compress_tfm)
crypto: cipher - remove crt_u.cipher (struct cipher_tfm)
crypto/api.c | 15 +------ crypto/cipher.c | 92 +++++++++++++++++------------------------- crypto/compress.c | 31 ++++++-------- crypto/internal.h | 3 -- include/linux/crypto.h | 91 ++++++----------------------------------- 5 files changed, 61 insertions(+), 171 deletions(-)
Signature · 1 line
2.24.0.393.g34dc348eaf-goog
PATCH 1/2 crypto: compress - remove crt_u.compress (struct compress_tfm)
From: Eric Biggers <[email protected]>
crt_u.compress (struct compress_tfm) is pointless because its two fields, ->cot_compress() and ->cot_decompress(), always point to crypto_compress() and crypto_decompress().
Remove this pointless indirection, and just make crypto_comp_compress() and crypto_comp_decompress() be direct calls to what used to be crypto_compress() and crypto_decompress().
Also remove the unused function crypto_comp_cast().
--- crypto/api.c | 2 +- crypto/compress.c | 31 ++++++++++++------------------ crypto/internal.h | 1 - include/linux/crypto.h | 43 ++++++------------------------------------ 4 files changed, 19 insertions(+), 58 deletions(-)
crypto/api.c +1 -1
@@ -301,7 +301,7 @@ static int crypto_init_ops(struct crypto_tfm *tfm, u32 type, u32 mask)return crypto_init_cipher_ops (tfm);case CRYPTO_ALG_TYPE_COMPRESS : -return crypto_init_compress_ops (tfm); +return 0 ;default :break ;
crypto/compress.c +12 -19
@@ -6,34 +6,27 @@* * Copyright (c) 2002 James Morris <[email protected]> */ -#include <linux/types.h> #include <linux/crypto.h> -#include <linux/errno.h> -#include <linux/string.h> #include "internal.h" -static int crypto_compress (struct crypto_tfm *tfm, -const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen) +int crypto_comp_compress (struct crypto_comp *comp, +const u8 *src,unsigned int slen, +u8 *dst,unsigned int *dlen) { +struct crypto_tfm *tfm =crypto_comp_tfm (comp); +return tfm->__crt_alg->cra_compress.coa_compress (tfm, src, slen, dst, dlen); } +EXPORT_SYMBOL_GPL (crypto_comp_compress); -static int crypto_decompress (struct crypto_tfm *tfm, -const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen) +int crypto_comp_decompress (struct crypto_comp *comp, +const u8 *src,unsigned int slen, +u8 *dst,unsigned int *dlen) { +struct crypto_tfm *tfm =crypto_comp_tfm (comp); +return tfm->__crt_alg->cra_compress.coa_decompress (tfm, src, slen, dst, dlen); } - -int crypto_init_compress_ops (struct crypto_tfm *tfm) -{ -struct compress_tfm *ops = &tfm->crt_compress; - - ops->cot_compress = crypto_compress; - ops->cot_decompress = crypto_decompress; - -return 0 ; -} +EXPORT_SYMBOL_GPL (crypto_comp_decompress);
crypto/internal.h +0 -1
@@ -59,7 +59,6 @@ struct crypto_alg *crypto_mod_get(struct crypto_alg *alg);struct crypto_alg *crypto_alg_mod_lookup (const char *name,u32 type,u32 mask);int crypto_init_cipher_ops (struct crypto_tfm *tfm); -int crypto_init_compress_ops (struct crypto_tfm *tfm);struct crypto_larval *crypto_larval_alloc (const char *name,u32 type,u32 mask);void crypto_larval_kill (struct crypto_alg *alg);
include/linux/crypto.h +6 -37
69 lines not on this page · raw message
Signature · 1 line
2.24.0.393.g34dc348eaf-goog
PATCH 2/2 crypto: cipher - remove crt_u.cipher (struct cipher_tfm)
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
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().
--- crypto/api.c | 15 +------ crypto/cipher.c | 92 +++++++++++++++++------------------------- crypto/internal.h | 2 - include/linux/crypto.h | 48 +++------------------- 4 files changed, 43 insertions(+), 114 deletions(-)
crypto/api.c +1 -14
@@ -295,20 +295,7 @@ static int crypto_init_ops(struct crypto_tfm *tfm, u32 type, u32 mask)if (type_obj)return type_obj->init (tfm, type, mask); - -switch (crypto_tfm_alg_type (tfm)) { -case CRYPTO_ALG_TYPE_CIPHER : -return crypto_init_cipher_ops (tfm); - -case CRYPTO_ALG_TYPE_COMPRESS : -return 0 ; - -default : -break ; - } - -BUG (); -return -EINVAL ; +return 0 ; }static void crypto_exit_ops (struct crypto_tfm *tfm)
crypto/cipher.c +36 -56
137 lines not on this page · raw message
crypto/internal.h +0 -2
@@ -58,8 +58,6 @@ static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg)struct crypto_alg *crypto_mod_get (struct crypto_alg *alg);struct crypto_alg *crypto_alg_mod_lookup (const char *name,u32 type,u32 mask); -int crypto_init_cipher_ops (struct crypto_tfm *tfm); -struct crypto_larval *crypto_larval_alloc (const char *name,u32 type,u32 mask);void crypto_larval_kill (struct crypto_alg *alg);void crypto_alg_tested (const char *name,int err);
include/linux/crypto.h +6 -42
88 lines not on this page · raw message
Signature · 1 line
2.24.0.393.g34dc348eaf-goog
Quoted 8 lines · Eric Biggers
This series removes the per-algorithm-type union from struct
crypto_tfmnow that its only remaining users are the "compress" and "cipher" algorithm types, and it's not really needed for them.This shrinks every crypto transform for every algorithm by 28 bytes on 64-bit platforms (12 bytes on 32-bit), and also removes some code.
Quoted 8 lines
Note that the new-style strongly-typed algorithms (i.e. everything other than "compress" and "cipher") don't need
crt_u, since they embed structcrypto_tfmin a per-algorithm-type custom struct instead.Eric Biggers (2):
crypto: compress - remove crt_u.compress (structcompress_tfm)
crypto: cipher - remove crt_u.cipher (structcipher_tfm)
Good riddance
Quoted 10 lines
crypto/api.c | 15 +------ crypto/cipher.c | 92 +++++++++++++++++------------------------- crypto/compress.c | 31 ++++++-------- crypto/internal.h | 3 -- include/linux/crypto.h | 91 ++++++----------------------------------- 5 files changed, 61 insertions(+), 171 deletions(-)--
2.24.0.393.g34dc348eaf-goog
Herbert Xu
maintainerQuoted 15 lines · Eric Biggers
This series removes the per-algorithm-type union from struct
crypto_tfmnow that its only remaining users are the "compress" and "cipher" algorithm types, and it's not really needed for them.This shrinks every crypto transform for every algorithm by 28 bytes on 64-bit platforms (12 bytes on 32-bit), and also removes some code.
Note that the new-style strongly-typed algorithms (i.e. everything other than "compress" and "cipher") don't need
crt_u, since they embed structcrypto_tfmin a per-algorithm-type custom struct instead.Eric Biggers (2):
crypto: compress - remove crt_u.compress (structcompress_tfm)
crypto: cipher - remove crt_u.cipher (structcipher_tfm)
Quoted 6 lines
crypto/api.c | 15 +------ crypto/cipher.c | 92 +++++++++++++++++------------------------- crypto/compress.c | 31 ++++++-------- crypto/internal.h | 3 -- include/linux/crypto.h | 91 ++++++----------------------------------- 5 files changed, 61 insertions(+), 171 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt