hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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): ",
....@@ -1284,15 +1281,6 @@
12841281 testmgr_free_buf(data[i].xbuf);
12851282 goto out_free_tfm;
12861283 }
1287
-
1288
-
1289
- for (i = 0; i < num_mb; ++i)
1290
- if (testmgr_alloc_buf(data[i].xbuf)) {
1291
- while (i--)
1292
- testmgr_free_buf(data[i].xbuf);
1293
- goto out_free_tfm;
1294
- }
1295
-
12961284
12971285 for (i = 0; i < num_mb; ++i) {
12981286 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
....@@ -1518,8 +1506,8 @@
15181506 return;
15191507 }
15201508
1521
- pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1522
- get_driver_name(crypto_skcipher, tfm), e);
1509
+ pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync",
1510
+ algo, get_driver_name(crypto_skcipher, tfm), e);
15231511
15241512 req = skcipher_request_alloc(tfm, GFP_KERNEL);
15251513 if (!req) {
....@@ -1638,7 +1626,7 @@
16381626
16391627 static void test_available(void)
16401628 {
1641
- char **name = check;
1629
+ const char **name = check;
16421630
16431631 while (*name) {
16441632 printk("alg %s ", *name);
....@@ -1736,6 +1724,7 @@
17361724 ret += tcrypt_test("xts(aes)");
17371725 ret += tcrypt_test("ctr(aes)");
17381726 ret += tcrypt_test("rfc3686(ctr(aes))");
1727
+ ret += tcrypt_test("ofb(aes)");
17391728 ret += tcrypt_test("cfb(aes)");
17401729 break;
17411730
....@@ -1882,10 +1871,6 @@
18821871 ret += tcrypt_test("ecb(seed)");
18831872 break;
18841873
1885
- case 44:
1886
- ret += tcrypt_test("zlib");
1887
- break;
1888
-
18891874 case 45:
18901875 ret += tcrypt_test("rfc4309(ccm(aes))");
18911876 break;
....@@ -1916,6 +1901,14 @@
19161901
19171902 case 52:
19181903 ret += tcrypt_test("sm3");
1904
+ break;
1905
+
1906
+ case 53:
1907
+ ret += tcrypt_test("streebog256");
1908
+ break;
1909
+
1910
+ case 54:
1911
+ ret += tcrypt_test("streebog512");
19191912 break;
19201913
19211914 case 100:
....@@ -1972,6 +1965,14 @@
19721965
19731966 case 114:
19741967 ret += tcrypt_test("hmac(sha3-512)");
1968
+ break;
1969
+
1970
+ case 115:
1971
+ ret += tcrypt_test("hmac(streebog256)");
1972
+ break;
1973
+
1974
+ case 116:
1975
+ ret += tcrypt_test("hmac(streebog512)");
19751976 break;
19761977
19771978 case 150:
....@@ -2037,6 +2038,8 @@
20372038 break;
20382039 case 191:
20392040 ret += tcrypt_test("ecb(sm4)");
2041
+ ret += tcrypt_test("cbc(sm4)");
2042
+ ret += tcrypt_test("ctr(sm4)");
20402043 break;
20412044 case 200:
20422045 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
....@@ -2290,6 +2293,21 @@
22902293 num_mb);
22912294 break;
22922295
2296
+ case 218:
2297
+ test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2298
+ speed_template_16);
2299
+ test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2300
+ speed_template_16);
2301
+ test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2302
+ speed_template_16);
2303
+ test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2304
+ speed_template_16);
2305
+ test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2306
+ speed_template_16);
2307
+ test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2308
+ speed_template_16);
2309
+ break;
2310
+
22932311 case 219:
22942312 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
22952313 0, speed_template_32);
....@@ -2301,116 +2319,143 @@
23012319 0, speed_template_32);
23022320 break;
23032321
2322
+ case 220:
2323
+ test_acipher_speed("essiv(cbc(aes),sha256)",
2324
+ ENCRYPT, sec, NULL, 0,
2325
+ speed_template_16_24_32);
2326
+ test_acipher_speed("essiv(cbc(aes),sha256)",
2327
+ DECRYPT, sec, NULL, 0,
2328
+ speed_template_16_24_32);
2329
+ break;
2330
+
2331
+ case 221:
2332
+ test_aead_speed("aegis128", ENCRYPT, sec,
2333
+ NULL, 0, 16, 8, speed_template_16);
2334
+ test_aead_speed("aegis128", DECRYPT, sec,
2335
+ NULL, 0, 16, 8, speed_template_16);
2336
+ break;
2337
+
23042338 case 300:
23052339 if (alg) {
23062340 test_hash_speed(alg, sec, generic_hash_speed_template);
23072341 break;
23082342 }
2309
- /* fall through */
2343
+ fallthrough;
23102344 case 301:
23112345 test_hash_speed("md4", sec, generic_hash_speed_template);
23122346 if (mode > 300 && mode < 400) break;
2313
- /* fall through */
2347
+ fallthrough;
23142348 case 302:
23152349 test_hash_speed("md5", sec, generic_hash_speed_template);
23162350 if (mode > 300 && mode < 400) break;
2317
- /* fall through */
2351
+ fallthrough;
23182352 case 303:
23192353 test_hash_speed("sha1", sec, generic_hash_speed_template);
23202354 if (mode > 300 && mode < 400) break;
2321
- /* fall through */
2355
+ fallthrough;
23222356 case 304:
23232357 test_hash_speed("sha256", sec, generic_hash_speed_template);
23242358 if (mode > 300 && mode < 400) break;
2325
- /* fall through */
2359
+ fallthrough;
23262360 case 305:
23272361 test_hash_speed("sha384", sec, generic_hash_speed_template);
23282362 if (mode > 300 && mode < 400) break;
2329
- /* fall through */
2363
+ fallthrough;
23302364 case 306:
23312365 test_hash_speed("sha512", sec, generic_hash_speed_template);
23322366 if (mode > 300 && mode < 400) break;
2333
- /* fall through */
2367
+ fallthrough;
23342368 case 307:
23352369 test_hash_speed("wp256", sec, generic_hash_speed_template);
23362370 if (mode > 300 && mode < 400) break;
2337
- /* fall through */
2371
+ fallthrough;
23382372 case 308:
23392373 test_hash_speed("wp384", sec, generic_hash_speed_template);
23402374 if (mode > 300 && mode < 400) break;
2341
- /* fall through */
2375
+ fallthrough;
23422376 case 309:
23432377 test_hash_speed("wp512", sec, generic_hash_speed_template);
23442378 if (mode > 300 && mode < 400) break;
2345
- /* fall through */
2379
+ fallthrough;
23462380 case 310:
23472381 test_hash_speed("tgr128", sec, generic_hash_speed_template);
23482382 if (mode > 300 && mode < 400) break;
2349
- /* fall through */
2383
+ fallthrough;
23502384 case 311:
23512385 test_hash_speed("tgr160", sec, generic_hash_speed_template);
23522386 if (mode > 300 && mode < 400) break;
2353
- /* fall through */
2387
+ fallthrough;
23542388 case 312:
23552389 test_hash_speed("tgr192", sec, generic_hash_speed_template);
23562390 if (mode > 300 && mode < 400) break;
2357
- /* fall through */
2391
+ fallthrough;
23582392 case 313:
23592393 test_hash_speed("sha224", sec, generic_hash_speed_template);
23602394 if (mode > 300 && mode < 400) break;
2361
- /* fall through */
2395
+ fallthrough;
23622396 case 314:
23632397 test_hash_speed("rmd128", sec, generic_hash_speed_template);
23642398 if (mode > 300 && mode < 400) break;
2365
- /* fall through */
2399
+ fallthrough;
23662400 case 315:
23672401 test_hash_speed("rmd160", sec, generic_hash_speed_template);
23682402 if (mode > 300 && mode < 400) break;
2369
- /* fall through */
2403
+ fallthrough;
23702404 case 316:
23712405 test_hash_speed("rmd256", sec, generic_hash_speed_template);
23722406 if (mode > 300 && mode < 400) break;
2373
- /* fall through */
2407
+ fallthrough;
23742408 case 317:
23752409 test_hash_speed("rmd320", sec, generic_hash_speed_template);
23762410 if (mode > 300 && mode < 400) break;
2377
- /* fall through */
2411
+ fallthrough;
23782412 case 318:
2379
- test_hash_speed("ghash-generic", sec, hash_speed_template_16);
2413
+ klen = 16;
2414
+ test_hash_speed("ghash", sec, generic_hash_speed_template);
23802415 if (mode > 300 && mode < 400) break;
2381
- /* fall through */
2416
+ fallthrough;
23822417 case 319:
23832418 test_hash_speed("crc32c", sec, generic_hash_speed_template);
23842419 if (mode > 300 && mode < 400) break;
2385
- /* fall through */
2420
+ fallthrough;
23862421 case 320:
23872422 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
23882423 if (mode > 300 && mode < 400) break;
2389
- /* fall through */
2424
+ fallthrough;
23902425 case 321:
23912426 test_hash_speed("poly1305", sec, poly1305_speed_template);
23922427 if (mode > 300 && mode < 400) break;
2393
- /* fall through */
2428
+ fallthrough;
23942429 case 322:
23952430 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
23962431 if (mode > 300 && mode < 400) break;
2397
- /* fall through */
2432
+ fallthrough;
23982433 case 323:
23992434 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
24002435 if (mode > 300 && mode < 400) break;
2401
- /* fall through */
2436
+ fallthrough;
24022437 case 324:
24032438 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
24042439 if (mode > 300 && mode < 400) break;
2405
- /* fall through */
2440
+ fallthrough;
24062441 case 325:
24072442 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
24082443 if (mode > 300 && mode < 400) break;
2409
- /* fall through */
2444
+ fallthrough;
24102445 case 326:
24112446 test_hash_speed("sm3", sec, generic_hash_speed_template);
24122447 if (mode > 300 && mode < 400) break;
2413
- /* fall through */
2448
+ fallthrough;
2449
+ case 327:
2450
+ test_hash_speed("streebog256", sec,
2451
+ generic_hash_speed_template);
2452
+ if (mode > 300 && mode < 400) break;
2453
+ fallthrough;
2454
+ case 328:
2455
+ test_hash_speed("streebog512", sec,
2456
+ generic_hash_speed_template);
2457
+ if (mode > 300 && mode < 400) break;
2458
+ fallthrough;
24142459 case 399:
24152460 break;
24162461
....@@ -2419,111 +2464,121 @@
24192464 test_ahash_speed(alg, sec, generic_hash_speed_template);
24202465 break;
24212466 }
2422
- /* fall through */
2467
+ fallthrough;
24232468 case 401:
24242469 test_ahash_speed("md4", sec, generic_hash_speed_template);
24252470 if (mode > 400 && mode < 500) break;
2426
- /* fall through */
2471
+ fallthrough;
24272472 case 402:
24282473 test_ahash_speed("md5", sec, generic_hash_speed_template);
24292474 if (mode > 400 && mode < 500) break;
2430
- /* fall through */
2475
+ fallthrough;
24312476 case 403:
24322477 test_ahash_speed("sha1", sec, generic_hash_speed_template);
24332478 if (mode > 400 && mode < 500) break;
2434
- /* fall through */
2479
+ fallthrough;
24352480 case 404:
24362481 test_ahash_speed("sha256", sec, generic_hash_speed_template);
24372482 if (mode > 400 && mode < 500) break;
2438
- /* fall through */
2483
+ fallthrough;
24392484 case 405:
24402485 test_ahash_speed("sha384", sec, generic_hash_speed_template);
24412486 if (mode > 400 && mode < 500) break;
2442
- /* fall through */
2487
+ fallthrough;
24432488 case 406:
24442489 test_ahash_speed("sha512", sec, generic_hash_speed_template);
24452490 if (mode > 400 && mode < 500) break;
2446
- /* fall through */
2491
+ fallthrough;
24472492 case 407:
24482493 test_ahash_speed("wp256", sec, generic_hash_speed_template);
24492494 if (mode > 400 && mode < 500) break;
2450
- /* fall through */
2495
+ fallthrough;
24512496 case 408:
24522497 test_ahash_speed("wp384", sec, generic_hash_speed_template);
24532498 if (mode > 400 && mode < 500) break;
2454
- /* fall through */
2499
+ fallthrough;
24552500 case 409:
24562501 test_ahash_speed("wp512", sec, generic_hash_speed_template);
24572502 if (mode > 400 && mode < 500) break;
2458
- /* fall through */
2503
+ fallthrough;
24592504 case 410:
24602505 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
24612506 if (mode > 400 && mode < 500) break;
2462
- /* fall through */
2507
+ fallthrough;
24632508 case 411:
24642509 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
24652510 if (mode > 400 && mode < 500) break;
2466
- /* fall through */
2511
+ fallthrough;
24672512 case 412:
24682513 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
24692514 if (mode > 400 && mode < 500) break;
2470
- /* fall through */
2515
+ fallthrough;
24712516 case 413:
24722517 test_ahash_speed("sha224", sec, generic_hash_speed_template);
24732518 if (mode > 400 && mode < 500) break;
2474
- /* fall through */
2519
+ fallthrough;
24752520 case 414:
24762521 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
24772522 if (mode > 400 && mode < 500) break;
2478
- /* fall through */
2523
+ fallthrough;
24792524 case 415:
24802525 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
24812526 if (mode > 400 && mode < 500) break;
2482
- /* fall through */
2527
+ fallthrough;
24832528 case 416:
24842529 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
24852530 if (mode > 400 && mode < 500) break;
2486
- /* fall through */
2531
+ fallthrough;
24872532 case 417:
24882533 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
24892534 if (mode > 400 && mode < 500) break;
2490
- /* fall through */
2535
+ fallthrough;
24912536 case 418:
24922537 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
24932538 if (mode > 400 && mode < 500) break;
2494
- /* fall through */
2539
+ fallthrough;
24952540 case 419:
24962541 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
24972542 if (mode > 400 && mode < 500) break;
2498
- /* fall through */
2543
+ fallthrough;
24992544 case 420:
25002545 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
25012546 if (mode > 400 && mode < 500) break;
2502
- /* fall through */
2547
+ fallthrough;
25032548 case 421:
25042549 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
25052550 if (mode > 400 && mode < 500) break;
2506
- /* fall through */
2551
+ fallthrough;
25072552 case 422:
25082553 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
25092554 num_mb);
25102555 if (mode > 400 && mode < 500) break;
2511
- /* fall through */
2556
+ fallthrough;
25122557 case 423:
25132558 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
25142559 num_mb);
25152560 if (mode > 400 && mode < 500) break;
2516
- /* fall through */
2561
+ fallthrough;
25172562 case 424:
25182563 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
25192564 num_mb);
25202565 if (mode > 400 && mode < 500) break;
2521
- /* fall through */
2566
+ fallthrough;
25222567 case 425:
25232568 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
25242569 num_mb);
25252570 if (mode > 400 && mode < 500) break;
2526
- /* fall through */
2571
+ fallthrough;
2572
+ case 426:
2573
+ test_mb_ahash_speed("streebog256", sec,
2574
+ generic_hash_speed_template, num_mb);
2575
+ if (mode > 400 && mode < 500) break;
2576
+ fallthrough;
2577
+ case 427:
2578
+ test_mb_ahash_speed("streebog512", sec,
2579
+ generic_hash_speed_template, num_mb);
2580
+ if (mode > 400 && mode < 500) break;
2581
+ fallthrough;
25272582 case 499:
25282583 break;
25292584
....@@ -3002,7 +3057,7 @@
30023057 */
30033058 static void __exit tcrypt_mod_fini(void) { }
30043059
3005
-module_init(tcrypt_mod_init);
3060
+subsys_initcall(tcrypt_mod_init);
30063061 module_exit(tcrypt_mod_fini);
30073062
30083063 module_param(alg, charp, 0);
....@@ -3014,6 +3069,8 @@
30143069 "(defaults to zero which uses CPU cycles instead)");
30153070 module_param(num_mb, uint, 0000);
30163071 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3072
+module_param(klen, uint, 0);
3073
+MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
30173074
30183075 MODULE_LICENSE("GPL");
30193076 MODULE_DESCRIPTION("Quick & dirty crypto testing module");