aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorVitaly Chikunov <vt@altlinux.org>2018-11-06 16:00:03 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2018-11-16 01:11:02 -0500
commit25a0b9d4e512ea04d80c84bd5e3b9e2722b92ec1 (patch)
tree74d6eebe27f0fcda43f4d08e7aab33327b7c004f /crypto
parentdfdda82e3b84c13601be09f8351ec4f15a4fbe03 (diff)
crypto: streebog - add Streebog test vectors
Add testmgr and tcrypt tests and vectors for Streebog hash function from RFC 6986 and GOST R 34.11-2012, for HMAC-Streebog vectors are from RFC 7836 and R 50.1.113-2016. Cc: linux-integrity@vger.kernel.org Signed-off-by: Vitaly Chikunov <vt@altlinux.org> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/tcrypt.c40
-rw-r--r--crypto/testmgr.c24
-rw-r--r--crypto/testmgr.h116
3 files changed, 179 insertions, 1 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 1026173d721a..5fb120474902 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -76,7 +76,9 @@ static char *check[] = {
76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", 76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
77 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", 77 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
78 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", 78 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
79 "lzo", "cts", "sha3-224", "sha3-256", "sha3-384", "sha3-512", NULL 79 "lzo", "cts", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
80 "streebog256", "streebog512",
81 NULL
80}; 82};
81 83
82static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; 84static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
@@ -1914,6 +1916,14 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1914 ret += tcrypt_test("sm3"); 1916 ret += tcrypt_test("sm3");
1915 break; 1917 break;
1916 1918
1919 case 53:
1920 ret += tcrypt_test("streebog256");
1921 break;
1922
1923 case 54:
1924 ret += tcrypt_test("streebog512");
1925 break;
1926
1917 case 100: 1927 case 100:
1918 ret += tcrypt_test("hmac(md5)"); 1928 ret += tcrypt_test("hmac(md5)");
1919 break; 1929 break;
@@ -1970,6 +1980,14 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1970 ret += tcrypt_test("hmac(sha3-512)"); 1980 ret += tcrypt_test("hmac(sha3-512)");
1971 break; 1981 break;
1972 1982
1983 case 115:
1984 ret += tcrypt_test("hmac(streebog256)");
1985 break;
1986
1987 case 116:
1988 ret += tcrypt_test("hmac(streebog512)");
1989 break;
1990
1973 case 150: 1991 case 150:
1974 ret += tcrypt_test("ansi_cprng"); 1992 ret += tcrypt_test("ansi_cprng");
1975 break; 1993 break;
@@ -2412,6 +2430,16 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
2412 test_hash_speed("sm3", sec, generic_hash_speed_template); 2430 test_hash_speed("sm3", sec, generic_hash_speed_template);
2413 if (mode > 300 && mode < 400) break; 2431 if (mode > 300 && mode < 400) break;
2414 /* fall through */ 2432 /* fall through */
2433 case 327:
2434 test_hash_speed("streebog256", sec,
2435 generic_hash_speed_template);
2436 if (mode > 300 && mode < 400) break;
2437 /* fall through */
2438 case 328:
2439 test_hash_speed("streebog512", sec,
2440 generic_hash_speed_template);
2441 if (mode > 300 && mode < 400) break;
2442 /* fall through */
2415 case 399: 2443 case 399:
2416 break; 2444 break;
2417 2445
@@ -2525,6 +2553,16 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
2525 num_mb); 2553 num_mb);
2526 if (mode > 400 && mode < 500) break; 2554 if (mode > 400 && mode < 500) break;
2527 /* fall through */ 2555 /* fall through */
2556 case 426:
2557 test_mb_ahash_speed("streebog256", sec,
2558 generic_hash_speed_template, num_mb);
2559 if (mode > 400 && mode < 500) break;
2560 /* fall through */
2561 case 427:
2562 test_mb_ahash_speed("streebog512", sec,
2563 generic_hash_speed_template, num_mb);
2564 if (mode > 400 && mode < 500) break;
2565 /* fall through */
2528 case 499: 2566 case 499:
2529 break; 2567 break;
2530 2568
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 512ebf697f7e..379794a259a7 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -3193,6 +3193,18 @@ static const struct alg_test_desc alg_test_descs[] = {
3193 .hash = __VECS(hmac_sha512_tv_template) 3193 .hash = __VECS(hmac_sha512_tv_template)
3194 } 3194 }
3195 }, { 3195 }, {
3196 .alg = "hmac(streebog256)",
3197 .test = alg_test_hash,
3198 .suite = {
3199 .hash = __VECS(hmac_streebog256_tv_template)
3200 }
3201 }, {
3202 .alg = "hmac(streebog512)",
3203 .test = alg_test_hash,
3204 .suite = {
3205 .hash = __VECS(hmac_streebog512_tv_template)
3206 }
3207 }, {
3196 .alg = "jitterentropy_rng", 3208 .alg = "jitterentropy_rng",
3197 .fips_allowed = 1, 3209 .fips_allowed = 1,
3198 .test = alg_test_null, 3210 .test = alg_test_null,
@@ -3505,6 +3517,18 @@ static const struct alg_test_desc alg_test_descs[] = {
3505 .hash = __VECS(sm3_tv_template) 3517 .hash = __VECS(sm3_tv_template)
3506 } 3518 }
3507 }, { 3519 }, {
3520 .alg = "streebog256",
3521 .test = alg_test_hash,
3522 .suite = {
3523 .hash = __VECS(streebog256_tv_template)
3524 }
3525 }, {
3526 .alg = "streebog512",
3527 .test = alg_test_hash,
3528 .suite = {
3529 .hash = __VECS(streebog512_tv_template)
3530 }
3531 }, {
3508 .alg = "tgr128", 3532 .alg = "tgr128",
3509 .test = alg_test_hash, 3533 .test = alg_test_hash,
3510 .suite = { 3534 .suite = {
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index b5b0d29761ce..fc1b6c0e9ed2 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -2307,6 +2307,122 @@ static const struct hash_testvec crct10dif_tv_template[] = {
2307 } 2307 }
2308}; 2308};
2309 2309
2310/*
2311 * Streebog test vectors from RFC 6986 and GOST R 34.11-2012
2312 */
2313static const struct hash_testvec streebog256_tv_template[] = {
2314 { /* M1 */
2315 .plaintext = "012345678901234567890123456789012345678901234567890123456789012",
2316 .psize = 63,
2317 .digest =
2318 "\x9d\x15\x1e\xef\xd8\x59\x0b\x89"
2319 "\xda\xa6\xba\x6c\xb7\x4a\xf9\x27"
2320 "\x5d\xd0\x51\x02\x6b\xb1\x49\xa4"
2321 "\x52\xfd\x84\xe5\xe5\x7b\x55\x00",
2322 },
2323 { /* M2 */
2324 .plaintext =
2325 "\xd1\xe5\x20\xe2\xe5\xf2\xf0\xe8"
2326 "\x2c\x20\xd1\xf2\xf0\xe8\xe1\xee"
2327 "\xe6\xe8\x20\xe2\xed\xf3\xf6\xe8"
2328 "\x2c\x20\xe2\xe5\xfe\xf2\xfa\x20"
2329 "\xf1\x20\xec\xee\xf0\xff\x20\xf1"
2330 "\xf2\xf0\xe5\xeb\xe0\xec\xe8\x20"
2331 "\xed\xe0\x20\xf5\xf0\xe0\xe1\xf0"
2332 "\xfb\xff\x20\xef\xeb\xfa\xea\xfb"
2333 "\x20\xc8\xe3\xee\xf0\xe5\xe2\xfb",
2334 .psize = 72,
2335 .digest =
2336 "\x9d\xd2\xfe\x4e\x90\x40\x9e\x5d"
2337 "\xa8\x7f\x53\x97\x6d\x74\x05\xb0"
2338 "\xc0\xca\xc6\x28\xfc\x66\x9a\x74"
2339 "\x1d\x50\x06\x3c\x55\x7e\x8f\x50",
2340 },
2341};
2342
2343static const struct hash_testvec streebog512_tv_template[] = {
2344 { /* M1 */
2345 .plaintext = "012345678901234567890123456789012345678901234567890123456789012",
2346 .psize = 63,
2347 .digest =
2348 "\x1b\x54\xd0\x1a\x4a\xf5\xb9\xd5"
2349 "\xcc\x3d\x86\xd6\x8d\x28\x54\x62"
2350 "\xb1\x9a\xbc\x24\x75\x22\x2f\x35"
2351 "\xc0\x85\x12\x2b\xe4\xba\x1f\xfa"
2352 "\x00\xad\x30\xf8\x76\x7b\x3a\x82"
2353 "\x38\x4c\x65\x74\xf0\x24\xc3\x11"
2354 "\xe2\xa4\x81\x33\x2b\x08\xef\x7f"
2355 "\x41\x79\x78\x91\xc1\x64\x6f\x48",
2356 },
2357 { /* M2 */
2358 .plaintext =
2359 "\xd1\xe5\x20\xe2\xe5\xf2\xf0\xe8"
2360 "\x2c\x20\xd1\xf2\xf0\xe8\xe1\xee"
2361 "\xe6\xe8\x20\xe2\xed\xf3\xf6\xe8"
2362 "\x2c\x20\xe2\xe5\xfe\xf2\xfa\x20"
2363 "\xf1\x20\xec\xee\xf0\xff\x20\xf1"
2364 "\xf2\xf0\xe5\xeb\xe0\xec\xe8\x20"
2365 "\xed\xe0\x20\xf5\xf0\xe0\xe1\xf0"
2366 "\xfb\xff\x20\xef\xeb\xfa\xea\xfb"
2367 "\x20\xc8\xe3\xee\xf0\xe5\xe2\xfb",
2368 .psize = 72,
2369 .digest =
2370 "\x1e\x88\xe6\x22\x26\xbf\xca\x6f"
2371 "\x99\x94\xf1\xf2\xd5\x15\x69\xe0"
2372 "\xda\xf8\x47\x5a\x3b\x0f\xe6\x1a"
2373 "\x53\x00\xee\xe4\x6d\x96\x13\x76"
2374 "\x03\x5f\xe8\x35\x49\xad\xa2\xb8"
2375 "\x62\x0f\xcd\x7c\x49\x6c\xe5\xb3"
2376 "\x3f\x0c\xb9\xdd\xdc\x2b\x64\x60"
2377 "\x14\x3b\x03\xda\xba\xc9\xfb\x28",
2378 },
2379};
2380
2381/*
2382 * Two HMAC-Streebog test vectors from RFC 7836 and R 50.1.113-2016 A
2383 */
2384static const struct hash_testvec hmac_streebog256_tv_template[] = {
2385 {
2386 .key = "\x00\x01\x02\x03\x04\x05\x06\x07"
2387 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
2388 "\x10\x11\x12\x13\x14\x15\x16\x17"
2389 "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
2390 .ksize = 32,
2391 .plaintext =
2392 "\x01\x26\xbd\xb8\x78\x00\xaf\x21"
2393 "\x43\x41\x45\x65\x63\x78\x01\x00",
2394 .psize = 16,
2395 .digest =
2396 "\xa1\xaa\x5f\x7d\xe4\x02\xd7\xb3"
2397 "\xd3\x23\xf2\x99\x1c\x8d\x45\x34"
2398 "\x01\x31\x37\x01\x0a\x83\x75\x4f"
2399 "\xd0\xaf\x6d\x7c\xd4\x92\x2e\xd9",
2400 },
2401};
2402
2403static const struct hash_testvec hmac_streebog512_tv_template[] = {
2404 {
2405 .key = "\x00\x01\x02\x03\x04\x05\x06\x07"
2406 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
2407 "\x10\x11\x12\x13\x14\x15\x16\x17"
2408 "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
2409 .ksize = 32,
2410 .plaintext =
2411 "\x01\x26\xbd\xb8\x78\x00\xaf\x21"
2412 "\x43\x41\x45\x65\x63\x78\x01\x00",
2413 .psize = 16,
2414 .digest =
2415 "\xa5\x9b\xab\x22\xec\xae\x19\xc6"
2416 "\x5f\xbd\xe6\xe5\xf4\xe9\xf5\xd8"
2417 "\x54\x9d\x31\xf0\x37\xf9\xdf\x9b"
2418 "\x90\x55\x00\xe1\x71\x92\x3a\x77"
2419 "\x3d\x5f\x15\x30\xf2\xed\x7e\x96"
2420 "\x4c\xb2\xee\xdc\x29\xe9\xad\x2f"
2421 "\x3a\xfe\x93\xb2\x81\x4f\x79\xf5"
2422 "\x00\x0f\xfc\x03\x66\xc2\x51\xe6",
2423 },
2424};
2425
2310/* Example vectors below taken from 2426/* Example vectors below taken from
2311 * http://www.oscca.gov.cn/UpFile/20101222141857786.pdf 2427 * http://www.oscca.gov.cn/UpFile/20101222141857786.pdf
2312 * 2428 *