|
11 | 11 | * any later version. |
12 | 12 | */ |
13 | 13 |
|
14 | | -#include <crypto/cryptd.h> |
15 | 14 | #include <crypto/internal/aead.h> |
| 15 | +#include <crypto/internal/simd.h> |
16 | 16 | #include <crypto/internal/skcipher.h> |
17 | 17 | #include <crypto/scatterwalk.h> |
18 | 18 | #include <linux/module.h> |
@@ -242,146 +242,49 @@ static void crypto_aegis256_aesni_exit_tfm(struct crypto_aead *aead) |
242 | 242 | { |
243 | 243 | } |
244 | 244 |
|
245 | | -static int cryptd_aegis256_aesni_setkey(struct crypto_aead *aead, |
246 | | - const u8 *key, unsigned int keylen) |
247 | | -{ |
248 | | - struct cryptd_aead **ctx = crypto_aead_ctx(aead); |
249 | | - struct cryptd_aead *cryptd_tfm = *ctx; |
250 | | - |
251 | | - return crypto_aead_setkey(&cryptd_tfm->base, key, keylen); |
252 | | -} |
253 | | - |
254 | | -static int cryptd_aegis256_aesni_setauthsize(struct crypto_aead *aead, |
255 | | - unsigned int authsize) |
256 | | -{ |
257 | | - struct cryptd_aead **ctx = crypto_aead_ctx(aead); |
258 | | - struct cryptd_aead *cryptd_tfm = *ctx; |
259 | | - |
260 | | - return crypto_aead_setauthsize(&cryptd_tfm->base, authsize); |
261 | | -} |
262 | | - |
263 | | -static int cryptd_aegis256_aesni_encrypt(struct aead_request *req) |
264 | | -{ |
265 | | - struct crypto_aead *aead = crypto_aead_reqtfm(req); |
266 | | - struct cryptd_aead **ctx = crypto_aead_ctx(aead); |
267 | | - struct cryptd_aead *cryptd_tfm = *ctx; |
268 | | - |
269 | | - aead = &cryptd_tfm->base; |
270 | | - if (irq_fpu_usable() && (!in_atomic() || |
271 | | - !cryptd_aead_queued(cryptd_tfm))) |
272 | | - aead = cryptd_aead_child(cryptd_tfm); |
273 | | - |
274 | | - aead_request_set_tfm(req, aead); |
275 | | - |
276 | | - return crypto_aead_encrypt(req); |
277 | | -} |
278 | | - |
279 | | -static int cryptd_aegis256_aesni_decrypt(struct aead_request *req) |
280 | | -{ |
281 | | - struct crypto_aead *aead = crypto_aead_reqtfm(req); |
282 | | - struct cryptd_aead **ctx = crypto_aead_ctx(aead); |
283 | | - struct cryptd_aead *cryptd_tfm = *ctx; |
284 | | - |
285 | | - aead = &cryptd_tfm->base; |
286 | | - if (irq_fpu_usable() && (!in_atomic() || |
287 | | - !cryptd_aead_queued(cryptd_tfm))) |
288 | | - aead = cryptd_aead_child(cryptd_tfm); |
289 | | - |
290 | | - aead_request_set_tfm(req, aead); |
291 | | - |
292 | | - return crypto_aead_decrypt(req); |
293 | | -} |
294 | | - |
295 | | -static int cryptd_aegis256_aesni_init_tfm(struct crypto_aead *aead) |
296 | | -{ |
297 | | - struct cryptd_aead *cryptd_tfm; |
298 | | - struct cryptd_aead **ctx = crypto_aead_ctx(aead); |
299 | | - |
300 | | - cryptd_tfm = cryptd_alloc_aead("__aegis256-aesni", CRYPTO_ALG_INTERNAL, |
301 | | - CRYPTO_ALG_INTERNAL); |
302 | | - if (IS_ERR(cryptd_tfm)) |
303 | | - return PTR_ERR(cryptd_tfm); |
304 | | - |
305 | | - *ctx = cryptd_tfm; |
306 | | - crypto_aead_set_reqsize(aead, crypto_aead_reqsize(&cryptd_tfm->base)); |
307 | | - return 0; |
308 | | -} |
309 | | - |
310 | | -static void cryptd_aegis256_aesni_exit_tfm(struct crypto_aead *aead) |
311 | | -{ |
312 | | - struct cryptd_aead **ctx = crypto_aead_ctx(aead); |
313 | | - |
314 | | - cryptd_free_aead(*ctx); |
315 | | -} |
316 | | - |
317 | | -static struct aead_alg crypto_aegis256_aesni_alg[] = { |
318 | | - { |
319 | | - .setkey = crypto_aegis256_aesni_setkey, |
320 | | - .setauthsize = crypto_aegis256_aesni_setauthsize, |
321 | | - .encrypt = crypto_aegis256_aesni_encrypt, |
322 | | - .decrypt = crypto_aegis256_aesni_decrypt, |
323 | | - .init = crypto_aegis256_aesni_init_tfm, |
324 | | - .exit = crypto_aegis256_aesni_exit_tfm, |
325 | | - |
326 | | - .ivsize = AEGIS256_NONCE_SIZE, |
327 | | - .maxauthsize = AEGIS256_MAX_AUTH_SIZE, |
328 | | - .chunksize = AEGIS256_BLOCK_SIZE, |
329 | | - |
330 | | - .base = { |
331 | | - .cra_flags = CRYPTO_ALG_INTERNAL, |
332 | | - .cra_blocksize = 1, |
333 | | - .cra_ctxsize = sizeof(struct aegis_ctx) + |
334 | | - __alignof__(struct aegis_ctx), |
335 | | - .cra_alignmask = 0, |
336 | | - |
337 | | - .cra_name = "__aegis256", |
338 | | - .cra_driver_name = "__aegis256-aesni", |
339 | | - |
340 | | - .cra_module = THIS_MODULE, |
341 | | - } |
342 | | - }, { |
343 | | - .setkey = cryptd_aegis256_aesni_setkey, |
344 | | - .setauthsize = cryptd_aegis256_aesni_setauthsize, |
345 | | - .encrypt = cryptd_aegis256_aesni_encrypt, |
346 | | - .decrypt = cryptd_aegis256_aesni_decrypt, |
347 | | - .init = cryptd_aegis256_aesni_init_tfm, |
348 | | - .exit = cryptd_aegis256_aesni_exit_tfm, |
349 | | - |
350 | | - .ivsize = AEGIS256_NONCE_SIZE, |
351 | | - .maxauthsize = AEGIS256_MAX_AUTH_SIZE, |
352 | | - .chunksize = AEGIS256_BLOCK_SIZE, |
353 | | - |
354 | | - .base = { |
355 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
356 | | - .cra_blocksize = 1, |
357 | | - .cra_ctxsize = sizeof(struct cryptd_aead *), |
358 | | - .cra_alignmask = 0, |
359 | | - |
360 | | - .cra_priority = 400, |
361 | | - |
362 | | - .cra_name = "aegis256", |
363 | | - .cra_driver_name = "aegis256-aesni", |
364 | | - |
365 | | - .cra_module = THIS_MODULE, |
366 | | - } |
| 245 | +static struct aead_alg crypto_aegis256_aesni_alg = { |
| 246 | + .setkey = crypto_aegis256_aesni_setkey, |
| 247 | + .setauthsize = crypto_aegis256_aesni_setauthsize, |
| 248 | + .encrypt = crypto_aegis256_aesni_encrypt, |
| 249 | + .decrypt = crypto_aegis256_aesni_decrypt, |
| 250 | + .init = crypto_aegis256_aesni_init_tfm, |
| 251 | + .exit = crypto_aegis256_aesni_exit_tfm, |
| 252 | + |
| 253 | + .ivsize = AEGIS256_NONCE_SIZE, |
| 254 | + .maxauthsize = AEGIS256_MAX_AUTH_SIZE, |
| 255 | + .chunksize = AEGIS256_BLOCK_SIZE, |
| 256 | + |
| 257 | + .base = { |
| 258 | + .cra_flags = CRYPTO_ALG_INTERNAL, |
| 259 | + .cra_blocksize = 1, |
| 260 | + .cra_ctxsize = sizeof(struct aegis_ctx) + |
| 261 | + __alignof__(struct aegis_ctx), |
| 262 | + .cra_alignmask = 0, |
| 263 | + .cra_priority = 400, |
| 264 | + |
| 265 | + .cra_name = "__aegis256", |
| 266 | + .cra_driver_name = "__aegis256-aesni", |
| 267 | + |
| 268 | + .cra_module = THIS_MODULE, |
367 | 269 | } |
368 | 270 | }; |
369 | 271 |
|
| 272 | +static struct simd_aead_alg *simd_alg; |
| 273 | + |
370 | 274 | static int __init crypto_aegis256_aesni_module_init(void) |
371 | 275 | { |
372 | 276 | if (!boot_cpu_has(X86_FEATURE_XMM2) || |
373 | 277 | !boot_cpu_has(X86_FEATURE_AES) || |
374 | 278 | !cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL)) |
375 | 279 | return -ENODEV; |
376 | 280 |
|
377 | | - return crypto_register_aeads(crypto_aegis256_aesni_alg, |
378 | | - ARRAY_SIZE(crypto_aegis256_aesni_alg)); |
| 281 | + return simd_register_aeads_compat(&crypto_aegis256_aesni_alg, 1, |
| 282 | + &simd_alg); |
379 | 283 | } |
380 | 284 |
|
381 | 285 | static void __exit crypto_aegis256_aesni_module_exit(void) |
382 | 286 | { |
383 | | - crypto_unregister_aeads(crypto_aegis256_aesni_alg, |
384 | | - ARRAY_SIZE(crypto_aegis256_aesni_alg)); |
| 287 | + simd_unregister_aeads(&crypto_aegis256_aesni_alg, 1, &simd_alg); |
385 | 288 | } |
386 | 289 |
|
387 | 290 | module_init(crypto_aegis256_aesni_module_init); |
|
0 commit comments