Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: simd - Remove unused skcipher support

Remove the skcipher algorithm support from crypto/simd.c. It is no
longer used, and it is unlikely to gain any new user in the future,
given the performance issues with this code.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
7c622c4f bab1adf3

+5 -249
+5 -230
crypto/simd.c
··· 13 13 14 14 /* 15 15 * Shared crypto SIMD helpers. These functions dynamically create and register 16 - * an skcipher or AEAD algorithm that wraps another, internal algorithm. The 17 - * wrapper ensures that the internal algorithm is only executed in a context 18 - * where SIMD instructions are usable, i.e. where may_use_simd() returns true. 19 - * If SIMD is already usable, the wrapper directly calls the internal algorithm. 20 - * Otherwise it defers execution to a workqueue via cryptd. 16 + * an AEAD algorithm that wraps another, internal algorithm. The wrapper 17 + * ensures that the internal algorithm is only executed in a context where SIMD 18 + * instructions are usable, i.e. where may_use_simd() returns true. If SIMD is 19 + * already usable, the wrapper directly calls the internal algorithm. Otherwise 20 + * it defers execution to a workqueue via cryptd. 21 21 * 22 22 * This is an alternative to the internal algorithm implementing a fallback for 23 23 * the !may_use_simd() case itself. ··· 30 30 #include <crypto/cryptd.h> 31 31 #include <crypto/internal/aead.h> 32 32 #include <crypto/internal/simd.h> 33 - #include <crypto/internal/skcipher.h> 34 33 #include <linux/kernel.h> 35 34 #include <linux/module.h> 36 35 #include <linux/preempt.h> 37 36 #include <asm/simd.h> 38 - 39 - /* skcipher support */ 40 - 41 - struct simd_skcipher_alg { 42 - const char *ialg_name; 43 - struct skcipher_alg alg; 44 - }; 45 - 46 - struct simd_skcipher_ctx { 47 - struct cryptd_skcipher *cryptd_tfm; 48 - }; 49 - 50 - static int simd_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key, 51 - unsigned int key_len) 52 - { 53 - struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm); 54 - struct crypto_skcipher *child = &ctx->cryptd_tfm->base; 55 - 56 - crypto_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK); 57 - crypto_skcipher_set_flags(child, crypto_skcipher_get_flags(tfm) & 58 - CRYPTO_TFM_REQ_MASK); 59 - return crypto_skcipher_setkey(child, key, key_len); 60 - } 61 - 62 - static int simd_skcipher_encrypt(struct skcipher_request *req) 63 - { 64 - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 65 - struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm); 66 - struct skcipher_request *subreq; 67 - struct crypto_skcipher *child; 68 - 69 - subreq = skcipher_request_ctx(req); 70 - *subreq = *req; 71 - 72 - if (!crypto_simd_usable() || 73 - (in_atomic() && cryptd_skcipher_queued(ctx->cryptd_tfm))) 74 - child = &ctx->cryptd_tfm->base; 75 - else 76 - child = cryptd_skcipher_child(ctx->cryptd_tfm); 77 - 78 - skcipher_request_set_tfm(subreq, child); 79 - 80 - return crypto_skcipher_encrypt(subreq); 81 - } 82 - 83 - static int simd_skcipher_decrypt(struct skcipher_request *req) 84 - { 85 - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 86 - struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm); 87 - struct skcipher_request *subreq; 88 - struct crypto_skcipher *child; 89 - 90 - subreq = skcipher_request_ctx(req); 91 - *subreq = *req; 92 - 93 - if (!crypto_simd_usable() || 94 - (in_atomic() && cryptd_skcipher_queued(ctx->cryptd_tfm))) 95 - child = &ctx->cryptd_tfm->base; 96 - else 97 - child = cryptd_skcipher_child(ctx->cryptd_tfm); 98 - 99 - skcipher_request_set_tfm(subreq, child); 100 - 101 - return crypto_skcipher_decrypt(subreq); 102 - } 103 - 104 - static void simd_skcipher_exit(struct crypto_skcipher *tfm) 105 - { 106 - struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm); 107 - 108 - cryptd_free_skcipher(ctx->cryptd_tfm); 109 - } 110 - 111 - static int simd_skcipher_init(struct crypto_skcipher *tfm) 112 - { 113 - struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm); 114 - struct cryptd_skcipher *cryptd_tfm; 115 - struct simd_skcipher_alg *salg; 116 - struct skcipher_alg *alg; 117 - unsigned reqsize; 118 - 119 - alg = crypto_skcipher_alg(tfm); 120 - salg = container_of(alg, struct simd_skcipher_alg, alg); 121 - 122 - cryptd_tfm = cryptd_alloc_skcipher(salg->ialg_name, 123 - CRYPTO_ALG_INTERNAL, 124 - CRYPTO_ALG_INTERNAL); 125 - if (IS_ERR(cryptd_tfm)) 126 - return PTR_ERR(cryptd_tfm); 127 - 128 - ctx->cryptd_tfm = cryptd_tfm; 129 - 130 - reqsize = crypto_skcipher_reqsize(cryptd_skcipher_child(cryptd_tfm)); 131 - reqsize = max(reqsize, crypto_skcipher_reqsize(&cryptd_tfm->base)); 132 - reqsize += sizeof(struct skcipher_request); 133 - 134 - crypto_skcipher_set_reqsize(tfm, reqsize); 135 - 136 - return 0; 137 - } 138 - 139 - struct simd_skcipher_alg *simd_skcipher_create_compat(struct skcipher_alg *ialg, 140 - const char *algname, 141 - const char *drvname, 142 - const char *basename) 143 - { 144 - struct simd_skcipher_alg *salg; 145 - struct skcipher_alg *alg; 146 - int err; 147 - 148 - salg = kzalloc_obj(*salg); 149 - if (!salg) { 150 - salg = ERR_PTR(-ENOMEM); 151 - goto out; 152 - } 153 - 154 - salg->ialg_name = basename; 155 - alg = &salg->alg; 156 - 157 - err = -ENAMETOOLONG; 158 - if (snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", algname) >= 159 - CRYPTO_MAX_ALG_NAME) 160 - goto out_free_salg; 161 - 162 - if (snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", 163 - drvname) >= CRYPTO_MAX_ALG_NAME) 164 - goto out_free_salg; 165 - 166 - alg->base.cra_flags = CRYPTO_ALG_ASYNC | 167 - (ialg->base.cra_flags & CRYPTO_ALG_INHERITED_FLAGS); 168 - alg->base.cra_priority = ialg->base.cra_priority; 169 - alg->base.cra_blocksize = ialg->base.cra_blocksize; 170 - alg->base.cra_alignmask = ialg->base.cra_alignmask; 171 - alg->base.cra_module = ialg->base.cra_module; 172 - alg->base.cra_ctxsize = sizeof(struct simd_skcipher_ctx); 173 - 174 - alg->ivsize = ialg->ivsize; 175 - alg->chunksize = ialg->chunksize; 176 - alg->min_keysize = ialg->min_keysize; 177 - alg->max_keysize = ialg->max_keysize; 178 - 179 - alg->init = simd_skcipher_init; 180 - alg->exit = simd_skcipher_exit; 181 - 182 - alg->setkey = simd_skcipher_setkey; 183 - alg->encrypt = simd_skcipher_encrypt; 184 - alg->decrypt = simd_skcipher_decrypt; 185 - 186 - err = crypto_register_skcipher(alg); 187 - if (err) 188 - goto out_free_salg; 189 - 190 - out: 191 - return salg; 192 - 193 - out_free_salg: 194 - kfree(salg); 195 - salg = ERR_PTR(err); 196 - goto out; 197 - } 198 - EXPORT_SYMBOL_GPL(simd_skcipher_create_compat); 199 - 200 - void simd_skcipher_free(struct simd_skcipher_alg *salg) 201 - { 202 - crypto_unregister_skcipher(&salg->alg); 203 - kfree(salg); 204 - } 205 - EXPORT_SYMBOL_GPL(simd_skcipher_free); 206 - 207 - int simd_register_skciphers_compat(struct skcipher_alg *algs, int count, 208 - struct simd_skcipher_alg **simd_algs) 209 - { 210 - int err; 211 - int i; 212 - const char *algname; 213 - const char *drvname; 214 - const char *basename; 215 - struct simd_skcipher_alg *simd; 216 - 217 - for (i = 0; i < count; i++) { 218 - if (WARN_ON(strncmp(algs[i].base.cra_name, "__", 2) || 219 - strncmp(algs[i].base.cra_driver_name, "__", 2))) 220 - return -EINVAL; 221 - } 222 - 223 - err = crypto_register_skciphers(algs, count); 224 - if (err) 225 - return err; 226 - 227 - for (i = 0; i < count; i++) { 228 - algname = algs[i].base.cra_name + 2; 229 - drvname = algs[i].base.cra_driver_name + 2; 230 - basename = algs[i].base.cra_driver_name; 231 - simd = simd_skcipher_create_compat(algs + i, algname, drvname, basename); 232 - err = PTR_ERR(simd); 233 - if (IS_ERR(simd)) 234 - goto err_unregister; 235 - simd_algs[i] = simd; 236 - } 237 - return 0; 238 - 239 - err_unregister: 240 - simd_unregister_skciphers(algs, count, simd_algs); 241 - return err; 242 - } 243 - EXPORT_SYMBOL_GPL(simd_register_skciphers_compat); 244 - 245 - void simd_unregister_skciphers(struct skcipher_alg *algs, int count, 246 - struct simd_skcipher_alg **simd_algs) 247 - { 248 - int i; 249 - 250 - crypto_unregister_skciphers(algs, count); 251 - 252 - for (i = 0; i < count; i++) { 253 - if (simd_algs[i]) { 254 - simd_skcipher_free(simd_algs[i]); 255 - simd_algs[i] = NULL; 256 - } 257 - } 258 - } 259 - EXPORT_SYMBOL_GPL(simd_unregister_skciphers); 260 - 261 - /* AEAD support */ 262 37 263 38 struct simd_aead_alg { 264 39 const char *ialg_name;
-19
include/crypto/internal/simd.h
··· 10 10 #include <linux/percpu.h> 11 11 #include <linux/types.h> 12 12 13 - /* skcipher support */ 14 - 15 - struct simd_skcipher_alg; 16 - struct skcipher_alg; 17 - 18 - struct simd_skcipher_alg *simd_skcipher_create_compat(struct skcipher_alg *ialg, 19 - const char *algname, 20 - const char *drvname, 21 - const char *basename); 22 - void simd_skcipher_free(struct simd_skcipher_alg *alg); 23 - 24 - int simd_register_skciphers_compat(struct skcipher_alg *algs, int count, 25 - struct simd_skcipher_alg **simd_algs); 26 - 27 - void simd_unregister_skciphers(struct skcipher_alg *algs, int count, 28 - struct simd_skcipher_alg **simd_algs); 29 - 30 - /* AEAD support */ 31 - 32 13 struct simd_aead_alg; 33 14 struct aead_alg; 34 15