~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/crypto/simd.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /crypto/simd.c (Version linux-6.11-rc3) and /crypto/simd.c (Version linux-4.17.19)


  1 // SPDX-License-Identifier: GPL-2.0-or-later   << 
  2 /*                                                  1 /*
  3  * Shared crypto simd helpers                       2  * Shared crypto simd helpers
  4  *                                                  3  *
  5  * Copyright (c) 2012 Jussi Kivilinna <jussi.k      4  * Copyright (c) 2012 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
  6  * Copyright (c) 2016 Herbert Xu <herbert@gond      5  * Copyright (c) 2016 Herbert Xu <herbert@gondor.apana.org.au>
  7  * Copyright (c) 2019 Google LLC               << 
  8  *                                                  6  *
  9  * Based on aesni-intel_glue.c by:                  7  * Based on aesni-intel_glue.c by:
 10  *  Copyright (C) 2008, Intel Corp.                 8  *  Copyright (C) 2008, Intel Corp.
 11  *    Author: Huang Ying <ying.huang@intel.com      9  *    Author: Huang Ying <ying.huang@intel.com>
 12  */                                            << 
 13                                                << 
 14 /*                                             << 
 15  * Shared crypto SIMD helpers.  These function << 
 16  * an skcipher or AEAD algorithm that wraps an << 
 17  * wrapper ensures that the internal algorithm << 
 18  * where SIMD instructions are usable, i.e. wh << 
 19  * If SIMD is already usable, the wrapper dire << 
 20  * Otherwise it defers execution to a workqueu << 
 21  *                                                 10  *
 22  * This is an alternative to the internal algo !!  11  * This program is free software; you can redistribute it and/or modify
 23  * the !may_use_simd() case itself.            !!  12  * it under the terms of the GNU General Public License as published by
                                                   >>  13  * the Free Software Foundation; either version 2 of the License, or
                                                   >>  14  * (at your option) any later version.
                                                   >>  15  *
                                                   >>  16  * This program is distributed in the hope that it will be useful,
                                                   >>  17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
                                                   >>  18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                                                   >>  19  * GNU General Public License for more details.
                                                   >>  20  *
                                                   >>  21  * You should have received a copy of the GNU General Public License
                                                   >>  22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 24  *                                                 23  *
 25  * Note that the wrapper algorithm is asynchro << 
 26  * CRYPTO_ALG_ASYNC flag set.  Therefore it wo << 
 27  * explicitly allocate a synchronous algorithm << 
 28  */                                                24  */
 29                                                    25 
 30 #include <crypto/cryptd.h>                         26 #include <crypto/cryptd.h>
 31 #include <crypto/internal/aead.h>              << 
 32 #include <crypto/internal/simd.h>                  27 #include <crypto/internal/simd.h>
 33 #include <crypto/internal/skcipher.h>              28 #include <crypto/internal/skcipher.h>
 34 #include <linux/kernel.h>                          29 #include <linux/kernel.h>
 35 #include <linux/module.h>                          30 #include <linux/module.h>
 36 #include <linux/preempt.h>                         31 #include <linux/preempt.h>
 37 #include <asm/simd.h>                              32 #include <asm/simd.h>
 38                                                    33 
 39 /* skcipher support */                         << 
 40                                                << 
 41 struct simd_skcipher_alg {                         34 struct simd_skcipher_alg {
 42         const char *ialg_name;                     35         const char *ialg_name;
 43         struct skcipher_alg alg;                   36         struct skcipher_alg alg;
 44 };                                                 37 };
 45                                                    38 
 46 struct simd_skcipher_ctx {                         39 struct simd_skcipher_ctx {
 47         struct cryptd_skcipher *cryptd_tfm;        40         struct cryptd_skcipher *cryptd_tfm;
 48 };                                                 41 };
 49                                                    42 
 50 static int simd_skcipher_setkey(struct crypto_     43 static int simd_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
 51                                 unsigned int k     44                                 unsigned int key_len)
 52 {                                                  45 {
 53         struct simd_skcipher_ctx *ctx = crypto     46         struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
 54         struct crypto_skcipher *child = &ctx->     47         struct crypto_skcipher *child = &ctx->cryptd_tfm->base;
                                                   >>  48         int err;
 55                                                    49 
 56         crypto_skcipher_clear_flags(child, CRY     50         crypto_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
 57         crypto_skcipher_set_flags(child, crypt     51         crypto_skcipher_set_flags(child, crypto_skcipher_get_flags(tfm) &
 58                                          CRYPT     52                                          CRYPTO_TFM_REQ_MASK);
 59         return crypto_skcipher_setkey(child, k !!  53         err = crypto_skcipher_setkey(child, key, key_len);
                                                   >>  54         crypto_skcipher_set_flags(tfm, crypto_skcipher_get_flags(child) &
                                                   >>  55                                        CRYPTO_TFM_RES_MASK);
                                                   >>  56         return err;
 60 }                                                  57 }
 61                                                    58 
 62 static int simd_skcipher_encrypt(struct skciph     59 static int simd_skcipher_encrypt(struct skcipher_request *req)
 63 {                                                  60 {
 64         struct crypto_skcipher *tfm = crypto_s     61         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
 65         struct simd_skcipher_ctx *ctx = crypto     62         struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
 66         struct skcipher_request *subreq;           63         struct skcipher_request *subreq;
 67         struct crypto_skcipher *child;             64         struct crypto_skcipher *child;
 68                                                    65 
 69         subreq = skcipher_request_ctx(req);        66         subreq = skcipher_request_ctx(req);
 70         *subreq = *req;                            67         *subreq = *req;
 71                                                    68 
 72         if (!crypto_simd_usable() ||           !!  69         if (!may_use_simd() ||
 73             (in_atomic() && cryptd_skcipher_qu     70             (in_atomic() && cryptd_skcipher_queued(ctx->cryptd_tfm)))
 74                 child = &ctx->cryptd_tfm->base     71                 child = &ctx->cryptd_tfm->base;
 75         else                                       72         else
 76                 child = cryptd_skcipher_child(     73                 child = cryptd_skcipher_child(ctx->cryptd_tfm);
 77                                                    74 
 78         skcipher_request_set_tfm(subreq, child     75         skcipher_request_set_tfm(subreq, child);
 79                                                    76 
 80         return crypto_skcipher_encrypt(subreq)     77         return crypto_skcipher_encrypt(subreq);
 81 }                                                  78 }
 82                                                    79 
 83 static int simd_skcipher_decrypt(struct skciph     80 static int simd_skcipher_decrypt(struct skcipher_request *req)
 84 {                                                  81 {
 85         struct crypto_skcipher *tfm = crypto_s     82         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
 86         struct simd_skcipher_ctx *ctx = crypto     83         struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
 87         struct skcipher_request *subreq;           84         struct skcipher_request *subreq;
 88         struct crypto_skcipher *child;             85         struct crypto_skcipher *child;
 89                                                    86 
 90         subreq = skcipher_request_ctx(req);        87         subreq = skcipher_request_ctx(req);
 91         *subreq = *req;                            88         *subreq = *req;
 92                                                    89 
 93         if (!crypto_simd_usable() ||           !!  90         if (!may_use_simd() ||
 94             (in_atomic() && cryptd_skcipher_qu     91             (in_atomic() && cryptd_skcipher_queued(ctx->cryptd_tfm)))
 95                 child = &ctx->cryptd_tfm->base     92                 child = &ctx->cryptd_tfm->base;
 96         else                                       93         else
 97                 child = cryptd_skcipher_child(     94                 child = cryptd_skcipher_child(ctx->cryptd_tfm);
 98                                                    95 
 99         skcipher_request_set_tfm(subreq, child     96         skcipher_request_set_tfm(subreq, child);
100                                                    97 
101         return crypto_skcipher_decrypt(subreq)     98         return crypto_skcipher_decrypt(subreq);
102 }                                                  99 }
103                                                   100 
104 static void simd_skcipher_exit(struct crypto_s    101 static void simd_skcipher_exit(struct crypto_skcipher *tfm)
105 {                                                 102 {
106         struct simd_skcipher_ctx *ctx = crypto    103         struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
107                                                   104 
108         cryptd_free_skcipher(ctx->cryptd_tfm);    105         cryptd_free_skcipher(ctx->cryptd_tfm);
109 }                                                 106 }
110                                                   107 
111 static int simd_skcipher_init(struct crypto_sk    108 static int simd_skcipher_init(struct crypto_skcipher *tfm)
112 {                                                 109 {
113         struct simd_skcipher_ctx *ctx = crypto    110         struct simd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
114         struct cryptd_skcipher *cryptd_tfm;       111         struct cryptd_skcipher *cryptd_tfm;
115         struct simd_skcipher_alg *salg;           112         struct simd_skcipher_alg *salg;
116         struct skcipher_alg *alg;                 113         struct skcipher_alg *alg;
117         unsigned reqsize;                         114         unsigned reqsize;
118                                                   115 
119         alg = crypto_skcipher_alg(tfm);           116         alg = crypto_skcipher_alg(tfm);
120         salg = container_of(alg, struct simd_s    117         salg = container_of(alg, struct simd_skcipher_alg, alg);
121                                                   118 
122         cryptd_tfm = cryptd_alloc_skcipher(sal    119         cryptd_tfm = cryptd_alloc_skcipher(salg->ialg_name,
123                                            CRY    120                                            CRYPTO_ALG_INTERNAL,
124                                            CRY    121                                            CRYPTO_ALG_INTERNAL);
125         if (IS_ERR(cryptd_tfm))                   122         if (IS_ERR(cryptd_tfm))
126                 return PTR_ERR(cryptd_tfm);       123                 return PTR_ERR(cryptd_tfm);
127                                                   124 
128         ctx->cryptd_tfm = cryptd_tfm;             125         ctx->cryptd_tfm = cryptd_tfm;
129                                                   126 
130         reqsize = crypto_skcipher_reqsize(cryp !! 127         reqsize = sizeof(struct skcipher_request);
131         reqsize = max(reqsize, crypto_skcipher !! 128         reqsize += crypto_skcipher_reqsize(&cryptd_tfm->base);
132         reqsize += sizeof(struct skcipher_requ << 
133                                                   129 
134         crypto_skcipher_set_reqsize(tfm, reqsi    130         crypto_skcipher_set_reqsize(tfm, reqsize);
135                                                   131 
136         return 0;                                 132         return 0;
137 }                                                 133 }
138                                                   134 
139 struct simd_skcipher_alg *simd_skcipher_create    135 struct simd_skcipher_alg *simd_skcipher_create_compat(const char *algname,
140                                                   136                                                       const char *drvname,
141                                                   137                                                       const char *basename)
142 {                                                 138 {
143         struct simd_skcipher_alg *salg;           139         struct simd_skcipher_alg *salg;
144         struct crypto_skcipher *tfm;              140         struct crypto_skcipher *tfm;
145         struct skcipher_alg *ialg;                141         struct skcipher_alg *ialg;
146         struct skcipher_alg *alg;                 142         struct skcipher_alg *alg;
147         int err;                                  143         int err;
148                                                   144 
149         tfm = crypto_alloc_skcipher(basename,     145         tfm = crypto_alloc_skcipher(basename, CRYPTO_ALG_INTERNAL,
150                                     CRYPTO_ALG    146                                     CRYPTO_ALG_INTERNAL | CRYPTO_ALG_ASYNC);
151         if (IS_ERR(tfm))                          147         if (IS_ERR(tfm))
152                 return ERR_CAST(tfm);             148                 return ERR_CAST(tfm);
153                                                   149 
154         ialg = crypto_skcipher_alg(tfm);          150         ialg = crypto_skcipher_alg(tfm);
155                                                   151 
156         salg = kzalloc(sizeof(*salg), GFP_KERN    152         salg = kzalloc(sizeof(*salg), GFP_KERNEL);
157         if (!salg) {                              153         if (!salg) {
158                 salg = ERR_PTR(-ENOMEM);          154                 salg = ERR_PTR(-ENOMEM);
159                 goto out_put_tfm;                 155                 goto out_put_tfm;
160         }                                         156         }
161                                                   157 
162         salg->ialg_name = basename;               158         salg->ialg_name = basename;
163         alg = &salg->alg;                         159         alg = &salg->alg;
164                                                   160 
165         err = -ENAMETOOLONG;                      161         err = -ENAMETOOLONG;
166         if (snprintf(alg->base.cra_name, CRYPT    162         if (snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", algname) >=
167             CRYPTO_MAX_ALG_NAME)                  163             CRYPTO_MAX_ALG_NAME)
168                 goto out_free_salg;               164                 goto out_free_salg;
169                                                   165 
170         if (snprintf(alg->base.cra_driver_name    166         if (snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
171                      drvname) >= CRYPTO_MAX_AL    167                      drvname) >= CRYPTO_MAX_ALG_NAME)
172                 goto out_free_salg;               168                 goto out_free_salg;
173                                                   169 
174         alg->base.cra_flags = CRYPTO_ALG_ASYNC !! 170         alg->base.cra_flags = CRYPTO_ALG_ASYNC;
175                 (ialg->base.cra_flags & CRYPTO << 
176         alg->base.cra_priority = ialg->base.cr    171         alg->base.cra_priority = ialg->base.cra_priority;
177         alg->base.cra_blocksize = ialg->base.c    172         alg->base.cra_blocksize = ialg->base.cra_blocksize;
178         alg->base.cra_alignmask = ialg->base.c    173         alg->base.cra_alignmask = ialg->base.cra_alignmask;
179         alg->base.cra_module = ialg->base.cra_    174         alg->base.cra_module = ialg->base.cra_module;
180         alg->base.cra_ctxsize = sizeof(struct     175         alg->base.cra_ctxsize = sizeof(struct simd_skcipher_ctx);
181                                                   176 
182         alg->ivsize = ialg->ivsize;               177         alg->ivsize = ialg->ivsize;
183         alg->chunksize = ialg->chunksize;         178         alg->chunksize = ialg->chunksize;
184         alg->min_keysize = ialg->min_keysize;     179         alg->min_keysize = ialg->min_keysize;
185         alg->max_keysize = ialg->max_keysize;     180         alg->max_keysize = ialg->max_keysize;
186                                                   181 
187         alg->init = simd_skcipher_init;           182         alg->init = simd_skcipher_init;
188         alg->exit = simd_skcipher_exit;           183         alg->exit = simd_skcipher_exit;
189                                                   184 
190         alg->setkey = simd_skcipher_setkey;       185         alg->setkey = simd_skcipher_setkey;
191         alg->encrypt = simd_skcipher_encrypt;     186         alg->encrypt = simd_skcipher_encrypt;
192         alg->decrypt = simd_skcipher_decrypt;     187         alg->decrypt = simd_skcipher_decrypt;
193                                                   188 
194         err = crypto_register_skcipher(alg);      189         err = crypto_register_skcipher(alg);
195         if (err)                                  190         if (err)
196                 goto out_free_salg;               191                 goto out_free_salg;
197                                                   192 
198 out_put_tfm:                                      193 out_put_tfm:
199         crypto_free_skcipher(tfm);                194         crypto_free_skcipher(tfm);
200         return salg;                              195         return salg;
201                                                   196 
202 out_free_salg:                                    197 out_free_salg:
203         kfree(salg);                              198         kfree(salg);
204         salg = ERR_PTR(err);                      199         salg = ERR_PTR(err);
205         goto out_put_tfm;                         200         goto out_put_tfm;
206 }                                                 201 }
207 EXPORT_SYMBOL_GPL(simd_skcipher_create_compat)    202 EXPORT_SYMBOL_GPL(simd_skcipher_create_compat);
208                                                   203 
209 struct simd_skcipher_alg *simd_skcipher_create    204 struct simd_skcipher_alg *simd_skcipher_create(const char *algname,
210                                                   205                                                const char *basename)
211 {                                                 206 {
212         char drvname[CRYPTO_MAX_ALG_NAME];        207         char drvname[CRYPTO_MAX_ALG_NAME];
213                                                   208 
214         if (snprintf(drvname, CRYPTO_MAX_ALG_N    209         if (snprintf(drvname, CRYPTO_MAX_ALG_NAME, "simd-%s", basename) >=
215             CRYPTO_MAX_ALG_NAME)                  210             CRYPTO_MAX_ALG_NAME)
216                 return ERR_PTR(-ENAMETOOLONG);    211                 return ERR_PTR(-ENAMETOOLONG);
217                                                   212 
218         return simd_skcipher_create_compat(alg    213         return simd_skcipher_create_compat(algname, drvname, basename);
219 }                                                 214 }
220 EXPORT_SYMBOL_GPL(simd_skcipher_create);          215 EXPORT_SYMBOL_GPL(simd_skcipher_create);
221                                                   216 
222 void simd_skcipher_free(struct simd_skcipher_a    217 void simd_skcipher_free(struct simd_skcipher_alg *salg)
223 {                                                 218 {
224         crypto_unregister_skcipher(&salg->alg)    219         crypto_unregister_skcipher(&salg->alg);
225         kfree(salg);                              220         kfree(salg);
226 }                                                 221 }
227 EXPORT_SYMBOL_GPL(simd_skcipher_free);            222 EXPORT_SYMBOL_GPL(simd_skcipher_free);
228                                                   223 
229 int simd_register_skciphers_compat(struct skci    224 int simd_register_skciphers_compat(struct skcipher_alg *algs, int count,
230                                    struct simd    225                                    struct simd_skcipher_alg **simd_algs)
231 {                                                 226 {
232         int err;                                  227         int err;
233         int i;                                    228         int i;
234         const char *algname;                      229         const char *algname;
235         const char *drvname;                      230         const char *drvname;
236         const char *basename;                     231         const char *basename;
237         struct simd_skcipher_alg *simd;           232         struct simd_skcipher_alg *simd;
238                                                   233 
239         err = crypto_register_skciphers(algs,     234         err = crypto_register_skciphers(algs, count);
240         if (err)                                  235         if (err)
241                 return err;                       236                 return err;
242                                                   237 
243         for (i = 0; i < count; i++) {             238         for (i = 0; i < count; i++) {
244                 WARN_ON(strncmp(algs[i].base.c    239                 WARN_ON(strncmp(algs[i].base.cra_name, "__", 2));
245                 WARN_ON(strncmp(algs[i].base.c    240                 WARN_ON(strncmp(algs[i].base.cra_driver_name, "__", 2));
246                 algname = algs[i].base.cra_nam    241                 algname = algs[i].base.cra_name + 2;
247                 drvname = algs[i].base.cra_dri    242                 drvname = algs[i].base.cra_driver_name + 2;
248                 basename = algs[i].base.cra_dr    243                 basename = algs[i].base.cra_driver_name;
249                 simd = simd_skcipher_create_co    244                 simd = simd_skcipher_create_compat(algname, drvname, basename);
250                 err = PTR_ERR(simd);              245                 err = PTR_ERR(simd);
251                 if (IS_ERR(simd))                 246                 if (IS_ERR(simd))
252                         goto err_unregister;      247                         goto err_unregister;
253                 simd_algs[i] = simd;              248                 simd_algs[i] = simd;
254         }                                         249         }
255         return 0;                                 250         return 0;
256                                                   251 
257 err_unregister:                                   252 err_unregister:
258         simd_unregister_skciphers(algs, count,    253         simd_unregister_skciphers(algs, count, simd_algs);
259         return err;                               254         return err;
260 }                                                 255 }
261 EXPORT_SYMBOL_GPL(simd_register_skciphers_comp    256 EXPORT_SYMBOL_GPL(simd_register_skciphers_compat);
262                                                   257 
263 void simd_unregister_skciphers(struct skcipher    258 void simd_unregister_skciphers(struct skcipher_alg *algs, int count,
264                                struct simd_skc    259                                struct simd_skcipher_alg **simd_algs)
265 {                                                 260 {
266         int i;                                    261         int i;
267                                                   262 
268         crypto_unregister_skciphers(algs, coun    263         crypto_unregister_skciphers(algs, count);
269                                                   264 
270         for (i = 0; i < count; i++) {             265         for (i = 0; i < count; i++) {
271                 if (simd_algs[i]) {               266                 if (simd_algs[i]) {
272                         simd_skcipher_free(sim    267                         simd_skcipher_free(simd_algs[i]);
273                         simd_algs[i] = NULL;      268                         simd_algs[i] = NULL;
274                 }                                 269                 }
275         }                                         270         }
276 }                                                 271 }
277 EXPORT_SYMBOL_GPL(simd_unregister_skciphers);     272 EXPORT_SYMBOL_GPL(simd_unregister_skciphers);
278                                                   273 
279 /* AEAD support */                             << 
280                                                << 
281 struct simd_aead_alg {                         << 
282         const char *ialg_name;                 << 
283         struct aead_alg alg;                   << 
284 };                                             << 
285                                                << 
286 struct simd_aead_ctx {                         << 
287         struct cryptd_aead *cryptd_tfm;        << 
288 };                                             << 
289                                                << 
290 static int simd_aead_setkey(struct crypto_aead << 
291                                 unsigned int k << 
292 {                                              << 
293         struct simd_aead_ctx *ctx = crypto_aea << 
294         struct crypto_aead *child = &ctx->cryp << 
295                                                << 
296         crypto_aead_clear_flags(child, CRYPTO_ << 
297         crypto_aead_set_flags(child, crypto_ae << 
298                                      CRYPTO_TF << 
299         return crypto_aead_setkey(child, key,  << 
300 }                                              << 
301                                                << 
302 static int simd_aead_setauthsize(struct crypto << 
303 {                                              << 
304         struct simd_aead_ctx *ctx = crypto_aea << 
305         struct crypto_aead *child = &ctx->cryp << 
306                                                << 
307         return crypto_aead_setauthsize(child,  << 
308 }                                              << 
309                                                << 
310 static int simd_aead_encrypt(struct aead_reque << 
311 {                                              << 
312         struct crypto_aead *tfm = crypto_aead_ << 
313         struct simd_aead_ctx *ctx = crypto_aea << 
314         struct aead_request *subreq;           << 
315         struct crypto_aead *child;             << 
316                                                << 
317         subreq = aead_request_ctx(req);        << 
318         *subreq = *req;                        << 
319                                                << 
320         if (!crypto_simd_usable() ||           << 
321             (in_atomic() && cryptd_aead_queued << 
322                 child = &ctx->cryptd_tfm->base << 
323         else                                   << 
324                 child = cryptd_aead_child(ctx- << 
325                                                << 
326         aead_request_set_tfm(subreq, child);   << 
327                                                << 
328         return crypto_aead_encrypt(subreq);    << 
329 }                                              << 
330                                                << 
331 static int simd_aead_decrypt(struct aead_reque << 
332 {                                              << 
333         struct crypto_aead *tfm = crypto_aead_ << 
334         struct simd_aead_ctx *ctx = crypto_aea << 
335         struct aead_request *subreq;           << 
336         struct crypto_aead *child;             << 
337                                                << 
338         subreq = aead_request_ctx(req);        << 
339         *subreq = *req;                        << 
340                                                << 
341         if (!crypto_simd_usable() ||           << 
342             (in_atomic() && cryptd_aead_queued << 
343                 child = &ctx->cryptd_tfm->base << 
344         else                                   << 
345                 child = cryptd_aead_child(ctx- << 
346                                                << 
347         aead_request_set_tfm(subreq, child);   << 
348                                                << 
349         return crypto_aead_decrypt(subreq);    << 
350 }                                              << 
351                                                << 
352 static void simd_aead_exit(struct crypto_aead  << 
353 {                                              << 
354         struct simd_aead_ctx *ctx = crypto_aea << 
355                                                << 
356         cryptd_free_aead(ctx->cryptd_tfm);     << 
357 }                                              << 
358                                                << 
359 static int simd_aead_init(struct crypto_aead * << 
360 {                                              << 
361         struct simd_aead_ctx *ctx = crypto_aea << 
362         struct cryptd_aead *cryptd_tfm;        << 
363         struct simd_aead_alg *salg;            << 
364         struct aead_alg *alg;                  << 
365         unsigned reqsize;                      << 
366                                                << 
367         alg = crypto_aead_alg(tfm);            << 
368         salg = container_of(alg, struct simd_a << 
369                                                << 
370         cryptd_tfm = cryptd_alloc_aead(salg->i << 
371                                        CRYPTO_ << 
372         if (IS_ERR(cryptd_tfm))                << 
373                 return PTR_ERR(cryptd_tfm);    << 
374                                                << 
375         ctx->cryptd_tfm = cryptd_tfm;          << 
376                                                << 
377         reqsize = crypto_aead_reqsize(cryptd_a << 
378         reqsize = max(reqsize, crypto_aead_req << 
379         reqsize += sizeof(struct aead_request) << 
380                                                << 
381         crypto_aead_set_reqsize(tfm, reqsize); << 
382                                                << 
383         return 0;                              << 
384 }                                              << 
385                                                << 
386 struct simd_aead_alg *simd_aead_create_compat( << 
387                                                << 
388                                                << 
389 {                                              << 
390         struct simd_aead_alg *salg;            << 
391         struct crypto_aead *tfm;               << 
392         struct aead_alg *ialg;                 << 
393         struct aead_alg *alg;                  << 
394         int err;                               << 
395                                                << 
396         tfm = crypto_alloc_aead(basename, CRYP << 
397                                 CRYPTO_ALG_INT << 
398         if (IS_ERR(tfm))                       << 
399                 return ERR_CAST(tfm);          << 
400                                                << 
401         ialg = crypto_aead_alg(tfm);           << 
402                                                << 
403         salg = kzalloc(sizeof(*salg), GFP_KERN << 
404         if (!salg) {                           << 
405                 salg = ERR_PTR(-ENOMEM);       << 
406                 goto out_put_tfm;              << 
407         }                                      << 
408                                                << 
409         salg->ialg_name = basename;            << 
410         alg = &salg->alg;                      << 
411                                                << 
412         err = -ENAMETOOLONG;                   << 
413         if (snprintf(alg->base.cra_name, CRYPT << 
414             CRYPTO_MAX_ALG_NAME)               << 
415                 goto out_free_salg;            << 
416                                                << 
417         if (snprintf(alg->base.cra_driver_name << 
418                      drvname) >= CRYPTO_MAX_AL << 
419                 goto out_free_salg;            << 
420                                                << 
421         alg->base.cra_flags = CRYPTO_ALG_ASYNC << 
422                 (ialg->base.cra_flags & CRYPTO << 
423         alg->base.cra_priority = ialg->base.cr << 
424         alg->base.cra_blocksize = ialg->base.c << 
425         alg->base.cra_alignmask = ialg->base.c << 
426         alg->base.cra_module = ialg->base.cra_ << 
427         alg->base.cra_ctxsize = sizeof(struct  << 
428                                                << 
429         alg->ivsize = ialg->ivsize;            << 
430         alg->maxauthsize = ialg->maxauthsize;  << 
431         alg->chunksize = ialg->chunksize;      << 
432                                                << 
433         alg->init = simd_aead_init;            << 
434         alg->exit = simd_aead_exit;            << 
435                                                << 
436         alg->setkey = simd_aead_setkey;        << 
437         alg->setauthsize = simd_aead_setauthsi << 
438         alg->encrypt = simd_aead_encrypt;      << 
439         alg->decrypt = simd_aead_decrypt;      << 
440                                                << 
441         err = crypto_register_aead(alg);       << 
442         if (err)                               << 
443                 goto out_free_salg;            << 
444                                                << 
445 out_put_tfm:                                   << 
446         crypto_free_aead(tfm);                 << 
447         return salg;                           << 
448                                                << 
449 out_free_salg:                                 << 
450         kfree(salg);                           << 
451         salg = ERR_PTR(err);                   << 
452         goto out_put_tfm;                      << 
453 }                                              << 
454 EXPORT_SYMBOL_GPL(simd_aead_create_compat);    << 
455                                                << 
456 struct simd_aead_alg *simd_aead_create(const c << 
457                                        const c << 
458 {                                              << 
459         char drvname[CRYPTO_MAX_ALG_NAME];     << 
460                                                << 
461         if (snprintf(drvname, CRYPTO_MAX_ALG_N << 
462             CRYPTO_MAX_ALG_NAME)               << 
463                 return ERR_PTR(-ENAMETOOLONG); << 
464                                                << 
465         return simd_aead_create_compat(algname << 
466 }                                              << 
467 EXPORT_SYMBOL_GPL(simd_aead_create);           << 
468                                                << 
469 void simd_aead_free(struct simd_aead_alg *salg << 
470 {                                              << 
471         crypto_unregister_aead(&salg->alg);    << 
472         kfree(salg);                           << 
473 }                                              << 
474 EXPORT_SYMBOL_GPL(simd_aead_free);             << 
475                                                << 
476 int simd_register_aeads_compat(struct aead_alg << 
477                                struct simd_aea << 
478 {                                              << 
479         int err;                               << 
480         int i;                                 << 
481         const char *algname;                   << 
482         const char *drvname;                   << 
483         const char *basename;                  << 
484         struct simd_aead_alg *simd;            << 
485                                                << 
486         err = crypto_register_aeads(algs, coun << 
487         if (err)                               << 
488                 return err;                    << 
489                                                << 
490         for (i = 0; i < count; i++) {          << 
491                 WARN_ON(strncmp(algs[i].base.c << 
492                 WARN_ON(strncmp(algs[i].base.c << 
493                 algname = algs[i].base.cra_nam << 
494                 drvname = algs[i].base.cra_dri << 
495                 basename = algs[i].base.cra_dr << 
496                 simd = simd_aead_create_compat << 
497                 err = PTR_ERR(simd);           << 
498                 if (IS_ERR(simd))              << 
499                         goto err_unregister;   << 
500                 simd_algs[i] = simd;           << 
501         }                                      << 
502         return 0;                              << 
503                                                << 
504 err_unregister:                                << 
505         simd_unregister_aeads(algs, count, sim << 
506         return err;                            << 
507 }                                              << 
508 EXPORT_SYMBOL_GPL(simd_register_aeads_compat); << 
509                                                << 
510 void simd_unregister_aeads(struct aead_alg *al << 
511                            struct simd_aead_al << 
512 {                                              << 
513         int i;                                 << 
514                                                << 
515         crypto_unregister_aeads(algs, count);  << 
516                                                << 
517         for (i = 0; i < count; i++) {          << 
518                 if (simd_algs[i]) {            << 
519                         simd_aead_free(simd_al << 
520                         simd_algs[i] = NULL;   << 
521                 }                              << 
522         }                                      << 
523 }                                              << 
524 EXPORT_SYMBOL_GPL(simd_unregister_aeads);      << 
525                                                << 
526 MODULE_DESCRIPTION("Shared crypto SIMD helpers << 
527 MODULE_LICENSE("GPL");                            274 MODULE_LICENSE("GPL");
528                                                   275 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php