hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/crypto/tcrypt.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Quick & dirty crypto testing module.
34 *
....@@ -14,12 +15,6 @@
1415 * Gabriele Paoloni <gabriele.paoloni@intel.com>
1516 * Tadeusz Struk (tadeusz.struk@intel.com)
1617 * Copyright (c) 2010, Intel Corporation.
17
- *
18
- * This program is free software; you can redistribute it and/or modify it
19
- * under the terms of the GNU General Public License as published by the Free
20
- * Software Foundation; either version 2 of the License, or (at your option)
21
- * any later version.
22
- *
2318 */
2419
2520 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -68,19 +63,21 @@
6863 static u32 mask;
6964 static int mode;
7065 static u32 num_mb = 8;
66
+static unsigned int klen;
7167 static char *tvmem[TVMEMSIZE];
7268
73
-static char *check[] = {
69
+static const char *check[] = {
7470 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
7571 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
7672 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
7773 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
7874 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
79
- "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
75
+ "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384",
76
+ "sha3-512", "streebog256", "streebog512",
8077 NULL
8178 };
8279
83
-static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
80
+static u32 block_sizes[] = { 16, 64, 256, 1024, 1472, 8192, 0 };
8481 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
8582
8683 #define XBUFSIZE 8
....@@ -402,7 +399,7 @@
402399 ret = do_one_aead_op(cur->req, ret);
403400
404401 if (ret) {
405
- pr_err("calculating auth failed failed (%d)\n",
402
+ pr_err("calculating auth failed (%d)\n",
406403 ret);
407404 break;
408405 }
....@@ -652,7 +649,7 @@
652649 crypto_aead_encrypt(req));
653650
654651 if (ret) {
655
- pr_err("calculating auth failed failed (%d)\n",
652
+ pr_err("calculating auth failed (%d)\n",
656653 ret);
657654 break;
658655 }
....@@ -868,8 +865,8 @@
868865 goto out;
869866 }
870867
871
- if (speed[i].klen)
872
- crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
868
+ if (klen)
869
+ crypto_ahash_setkey(tfm, tvmem[0], klen);
873870
874871 for (k = 0; k < num_mb; k++)
875872 ahash_request_set_crypt(data[k].req, data[k].sg,
....@@ -1103,8 +1100,8 @@
11031100 break;
11041101 }
11051102
1106
- if (speed[i].klen)
1107
- crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
1103
+ if (klen)
1104
+ crypto_ahash_setkey(tfm, tvmem[0], klen);
11081105
11091106 pr_info("test%3u "
11101107 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
....@@ -1518,8 +1515,8 @@
15181515 return;
15191516 }
15201517
1521
- pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1522
- get_driver_name(crypto_skcipher, tfm), e);
1518
+ pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync",
1519
+ algo, get_driver_name(crypto_skcipher, tfm), e);
15231520
15241521 req = skcipher_request_alloc(tfm, GFP_KERNEL);
15251522 if (!req) {
....@@ -1638,7 +1635,7 @@
16381635
16391636 static void test_available(void)
16401637 {
1641
- char **name = check;
1638
+ const char **name = check;
16421639
16431640 while (*name) {
16441641 printk("alg %s ", *name);
....@@ -1736,6 +1733,7 @@
17361733 ret += tcrypt_test("xts(aes)");
17371734 ret += tcrypt_test("ctr(aes)");
17381735 ret += tcrypt_test("rfc3686(ctr(aes))");
1736
+ ret += tcrypt_test("ofb(aes)");
17391737 ret += tcrypt_test("cfb(aes)");
17401738 break;
17411739
....@@ -1882,10 +1880,6 @@
18821880 ret += tcrypt_test("ecb(seed)");
18831881 break;
18841882
1885
- case 44:
1886
- ret += tcrypt_test("zlib");
1887
- break;
1888
-
18891883 case 45:
18901884 ret += tcrypt_test("rfc4309(ccm(aes))");
18911885 break;
....@@ -1916,6 +1910,14 @@
19161910
19171911 case 52:
19181912 ret += tcrypt_test("sm3");
1913
+ break;
1914
+
1915
+ case 53:
1916
+ ret += tcrypt_test("streebog256");
1917
+ break;
1918
+
1919
+ case 54:
1920
+ ret += tcrypt_test("streebog512");
19191921 break;
19201922
19211923 case 100:
....@@ -1972,6 +1974,14 @@
19721974
19731975 case 114:
19741976 ret += tcrypt_test("hmac(sha3-512)");
1977
+ break;
1978
+
1979
+ case 115:
1980
+ ret += tcrypt_test("hmac(streebog256)");
1981
+ break;
1982
+
1983
+ case 116:
1984
+ ret += tcrypt_test("hmac(streebog512)");
19751985 break;
19761986
19771987 case 150:
....@@ -2037,6 +2047,8 @@
20372047 break;
20382048 case 191:
20392049 ret += tcrypt_test("ecb(sm4)");
2050
+ ret += tcrypt_test("cbc(sm4)");
2051
+ ret += tcrypt_test("ctr(sm4)");
20402052 break;
20412053 case 200:
20422054 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
....@@ -2290,6 +2302,21 @@
22902302 num_mb);
22912303 break;
22922304
2305
+ case 218:
2306
+ test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2307
+ speed_template_16);
2308
+ test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2309
+ speed_template_16);
2310
+ test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2311
+ speed_template_16);
2312
+ test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2313
+ speed_template_16);
2314
+ test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2315
+ speed_template_16);
2316
+ test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2317
+ speed_template_16);
2318
+ break;
2319
+
22932320 case 219:
22942321 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
22952322 0, speed_template_32);
....@@ -2301,116 +2328,143 @@
23012328 0, speed_template_32);
23022329 break;
23032330
2331
+ case 220:
2332
+ test_acipher_speed("essiv(cbc(aes),sha256)",
2333
+ ENCRYPT, sec, NULL, 0,
2334
+ speed_template_16_24_32);
2335
+ test_acipher_speed("essiv(cbc(aes),sha256)",
2336
+ DECRYPT, sec, NULL, 0,
2337
+ speed_template_16_24_32);
2338
+ break;
2339
+
2340
+ case 221:
2341
+ test_aead_speed("aegis128", ENCRYPT, sec,
2342
+ NULL, 0, 16, 8, speed_template_16);
2343
+ test_aead_speed("aegis128", DECRYPT, sec,
2344
+ NULL, 0, 16, 8, speed_template_16);
2345
+ break;
2346
+
23042347 case 300:
23052348 if (alg) {
23062349 test_hash_speed(alg, sec, generic_hash_speed_template);
23072350 break;
23082351 }
2309
- /* fall through */
2352
+ fallthrough;
23102353 case 301:
23112354 test_hash_speed("md4", sec, generic_hash_speed_template);
23122355 if (mode > 300 && mode < 400) break;
2313
- /* fall through */
2356
+ fallthrough;
23142357 case 302:
23152358 test_hash_speed("md5", sec, generic_hash_speed_template);
23162359 if (mode > 300 && mode < 400) break;
2317
- /* fall through */
2360
+ fallthrough;
23182361 case 303:
23192362 test_hash_speed("sha1", sec, generic_hash_speed_template);
23202363 if (mode > 300 && mode < 400) break;
2321
- /* fall through */
2364
+ fallthrough;
23222365 case 304:
23232366 test_hash_speed("sha256", sec, generic_hash_speed_template);
23242367 if (mode > 300 && mode < 400) break;
2325
- /* fall through */
2368
+ fallthrough;
23262369 case 305:
23272370 test_hash_speed("sha384", sec, generic_hash_speed_template);
23282371 if (mode > 300 && mode < 400) break;
2329
- /* fall through */
2372
+ fallthrough;
23302373 case 306:
23312374 test_hash_speed("sha512", sec, generic_hash_speed_template);
23322375 if (mode > 300 && mode < 400) break;
2333
- /* fall through */
2376
+ fallthrough;
23342377 case 307:
23352378 test_hash_speed("wp256", sec, generic_hash_speed_template);
23362379 if (mode > 300 && mode < 400) break;
2337
- /* fall through */
2380
+ fallthrough;
23382381 case 308:
23392382 test_hash_speed("wp384", sec, generic_hash_speed_template);
23402383 if (mode > 300 && mode < 400) break;
2341
- /* fall through */
2384
+ fallthrough;
23422385 case 309:
23432386 test_hash_speed("wp512", sec, generic_hash_speed_template);
23442387 if (mode > 300 && mode < 400) break;
2345
- /* fall through */
2388
+ fallthrough;
23462389 case 310:
23472390 test_hash_speed("tgr128", sec, generic_hash_speed_template);
23482391 if (mode > 300 && mode < 400) break;
2349
- /* fall through */
2392
+ fallthrough;
23502393 case 311:
23512394 test_hash_speed("tgr160", sec, generic_hash_speed_template);
23522395 if (mode > 300 && mode < 400) break;
2353
- /* fall through */
2396
+ fallthrough;
23542397 case 312:
23552398 test_hash_speed("tgr192", sec, generic_hash_speed_template);
23562399 if (mode > 300 && mode < 400) break;
2357
- /* fall through */
2400
+ fallthrough;
23582401 case 313:
23592402 test_hash_speed("sha224", sec, generic_hash_speed_template);
23602403 if (mode > 300 && mode < 400) break;
2361
- /* fall through */
2404
+ fallthrough;
23622405 case 314:
23632406 test_hash_speed("rmd128", sec, generic_hash_speed_template);
23642407 if (mode > 300 && mode < 400) break;
2365
- /* fall through */
2408
+ fallthrough;
23662409 case 315:
23672410 test_hash_speed("rmd160", sec, generic_hash_speed_template);
23682411 if (mode > 300 && mode < 400) break;
2369
- /* fall through */
2412
+ fallthrough;
23702413 case 316:
23712414 test_hash_speed("rmd256", sec, generic_hash_speed_template);
23722415 if (mode > 300 && mode < 400) break;
2373
- /* fall through */
2416
+ fallthrough;
23742417 case 317:
23752418 test_hash_speed("rmd320", sec, generic_hash_speed_template);
23762419 if (mode > 300 && mode < 400) break;
2377
- /* fall through */
2420
+ fallthrough;
23782421 case 318:
2379
- test_hash_speed("ghash-generic", sec, hash_speed_template_16);
2422
+ klen = 16;
2423
+ test_hash_speed("ghash", sec, generic_hash_speed_template);
23802424 if (mode > 300 && mode < 400) break;
2381
- /* fall through */
2425
+ fallthrough;
23822426 case 319:
23832427 test_hash_speed("crc32c", sec, generic_hash_speed_template);
23842428 if (mode > 300 && mode < 400) break;
2385
- /* fall through */
2429
+ fallthrough;
23862430 case 320:
23872431 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
23882432 if (mode > 300 && mode < 400) break;
2389
- /* fall through */
2433
+ fallthrough;
23902434 case 321:
23912435 test_hash_speed("poly1305", sec, poly1305_speed_template);
23922436 if (mode > 300 && mode < 400) break;
2393
- /* fall through */
2437
+ fallthrough;
23942438 case 322:
23952439 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
23962440 if (mode > 300 && mode < 400) break;
2397
- /* fall through */
2441
+ fallthrough;
23982442 case 323:
23992443 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
24002444 if (mode > 300 && mode < 400) break;
2401
- /* fall through */
2445
+ fallthrough;
24022446 case 324:
24032447 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
24042448 if (mode > 300 && mode < 400) break;
2405
- /* fall through */
2449
+ fallthrough;
24062450 case 325:
24072451 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
24082452 if (mode > 300 && mode < 400) break;
2409
- /* fall through */
2453
+ fallthrough;
24102454 case 326:
24112455 test_hash_speed("sm3", sec, generic_hash_speed_template);
24122456 if (mode > 300 && mode < 400) break;
2413
- /* fall through */
2457
+ fallthrough;
2458
+ case 327:
2459
+ test_hash_speed("streebog256", sec,
2460
+ generic_hash_speed_template);
2461
+ if (mode > 300 && mode < 400) break;
2462
+ fallthrough;
2463
+ case 328:
2464
+ test_hash_speed("streebog512", sec,
2465
+ generic_hash_speed_template);
2466
+ if (mode > 300 && mode < 400) break;
2467
+ fallthrough;
24142468 case 399:
24152469 break;
24162470
....@@ -2419,111 +2473,121 @@
24192473 test_ahash_speed(alg, sec, generic_hash_speed_template);
24202474 break;
24212475 }
2422
- /* fall through */
2476
+ fallthrough;
24232477 case 401:
24242478 test_ahash_speed("md4", sec, generic_hash_speed_template);
24252479 if (mode > 400 && mode < 500) break;
2426
- /* fall through */
2480
+ fallthrough;
24272481 case 402:
24282482 test_ahash_speed("md5", sec, generic_hash_speed_template);
24292483 if (mode > 400 && mode < 500) break;
2430
- /* fall through */
2484
+ fallthrough;
24312485 case 403:
24322486 test_ahash_speed("sha1", sec, generic_hash_speed_template);
24332487 if (mode > 400 && mode < 500) break;
2434
- /* fall through */
2488
+ fallthrough;
24352489 case 404:
24362490 test_ahash_speed("sha256", sec, generic_hash_speed_template);
24372491 if (mode > 400 && mode < 500) break;
2438
- /* fall through */
2492
+ fallthrough;
24392493 case 405:
24402494 test_ahash_speed("sha384", sec, generic_hash_speed_template);
24412495 if (mode > 400 && mode < 500) break;
2442
- /* fall through */
2496
+ fallthrough;
24432497 case 406:
24442498 test_ahash_speed("sha512", sec, generic_hash_speed_template);
24452499 if (mode > 400 && mode < 500) break;
2446
- /* fall through */
2500
+ fallthrough;
24472501 case 407:
24482502 test_ahash_speed("wp256", sec, generic_hash_speed_template);
24492503 if (mode > 400 && mode < 500) break;
2450
- /* fall through */
2504
+ fallthrough;
24512505 case 408:
24522506 test_ahash_speed("wp384", sec, generic_hash_speed_template);
24532507 if (mode > 400 && mode < 500) break;
2454
- /* fall through */
2508
+ fallthrough;
24552509 case 409:
24562510 test_ahash_speed("wp512", sec, generic_hash_speed_template);
24572511 if (mode > 400 && mode < 500) break;
2458
- /* fall through */
2512
+ fallthrough;
24592513 case 410:
24602514 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
24612515 if (mode > 400 && mode < 500) break;
2462
- /* fall through */
2516
+ fallthrough;
24632517 case 411:
24642518 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
24652519 if (mode > 400 && mode < 500) break;
2466
- /* fall through */
2520
+ fallthrough;
24672521 case 412:
24682522 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
24692523 if (mode > 400 && mode < 500) break;
2470
- /* fall through */
2524
+ fallthrough;
24712525 case 413:
24722526 test_ahash_speed("sha224", sec, generic_hash_speed_template);
24732527 if (mode > 400 && mode < 500) break;
2474
- /* fall through */
2528
+ fallthrough;
24752529 case 414:
24762530 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
24772531 if (mode > 400 && mode < 500) break;
2478
- /* fall through */
2532
+ fallthrough;
24792533 case 415:
24802534 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
24812535 if (mode > 400 && mode < 500) break;
2482
- /* fall through */
2536
+ fallthrough;
24832537 case 416:
24842538 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
24852539 if (mode > 400 && mode < 500) break;
2486
- /* fall through */
2540
+ fallthrough;
24872541 case 417:
24882542 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
24892543 if (mode > 400 && mode < 500) break;
2490
- /* fall through */
2544
+ fallthrough;
24912545 case 418:
24922546 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
24932547 if (mode > 400 && mode < 500) break;
2494
- /* fall through */
2548
+ fallthrough;
24952549 case 419:
24962550 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
24972551 if (mode > 400 && mode < 500) break;
2498
- /* fall through */
2552
+ fallthrough;
24992553 case 420:
25002554 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
25012555 if (mode > 400 && mode < 500) break;
2502
- /* fall through */
2556
+ fallthrough;
25032557 case 421:
25042558 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
25052559 if (mode > 400 && mode < 500) break;
2506
- /* fall through */
2560
+ fallthrough;
25072561 case 422:
25082562 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
25092563 num_mb);
25102564 if (mode > 400 && mode < 500) break;
2511
- /* fall through */
2565
+ fallthrough;
25122566 case 423:
25132567 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
25142568 num_mb);
25152569 if (mode > 400 && mode < 500) break;
2516
- /* fall through */
2570
+ fallthrough;
25172571 case 424:
25182572 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
25192573 num_mb);
25202574 if (mode > 400 && mode < 500) break;
2521
- /* fall through */
2575
+ fallthrough;
25222576 case 425:
25232577 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
25242578 num_mb);
25252579 if (mode > 400 && mode < 500) break;
2526
- /* fall through */
2580
+ fallthrough;
2581
+ case 426:
2582
+ test_mb_ahash_speed("streebog256", sec,
2583
+ generic_hash_speed_template, num_mb);
2584
+ if (mode > 400 && mode < 500) break;
2585
+ fallthrough;
2586
+ case 427:
2587
+ test_mb_ahash_speed("streebog512", sec,
2588
+ generic_hash_speed_template, num_mb);
2589
+ if (mode > 400 && mode < 500) break;
2590
+ fallthrough;
25272591 case 499:
25282592 break;
25292593
....@@ -3002,7 +3066,7 @@
30023066 */
30033067 static void __exit tcrypt_mod_fini(void) { }
30043068
3005
-module_init(tcrypt_mod_init);
3069
+subsys_initcall(tcrypt_mod_init);
30063070 module_exit(tcrypt_mod_fini);
30073071
30083072 module_param(alg, charp, 0);
....@@ -3014,6 +3078,8 @@
30143078 "(defaults to zero which uses CPU cycles instead)");
30153079 module_param(num_mb, uint, 0000);
30163080 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3081
+module_param(klen, uint, 0);
3082
+MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
30173083
30183084 MODULE_LICENSE("GPL");
30193085 MODULE_DESCRIPTION("Quick & dirty crypto testing module");