crypto: streebog - add Streebog hash function

Signed-off-by: Carlos Jimenez (JavaShin-X) <javashin1986@gmail.com>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
This commit is contained in:
Vitaly Chikunov 2020-10-24 19:39:49 -04:00 committed by Cyber Knight
parent b8baf0954b
commit 63253831bc
No known key found for this signature in database
GPG Key ID: 23BD4CCD326E9D64
7 changed files with 1301 additions and 0 deletions

View File

@ -888,6 +888,18 @@ config CRYPTO_SHA3
References: References:
http://keccak.noekeon.org/ http://keccak.noekeon.org/
config CRYPTO_STREEBOG
tristate "Streebog Hash Function"
select CRYPTO_HASH
help
Streebog Hash Function (GOST R 34.11-2012, RFC 6986) is one of the Russian
cryptographic standard algorithms (called GOST algorithms).
This setting enables two hash algorithms with 256 and 512 bits output.
References:
https://tc26.ru/upload/iblock/fed/feddbb4d26b685903faa2ba11aea43f6.pdf
https://tools.ietf.org/html/rfc6986
config CRYPTO_TGR192 config CRYPTO_TGR192
tristate "Tiger digest algorithms" tristate "Tiger digest algorithms"
select CRYPTO_HASH select CRYPTO_HASH

View File

@ -138,6 +138,7 @@ obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o
obj-$(CONFIG_CRYPTO_USER_API_RNG) += algif_rng.o obj-$(CONFIG_CRYPTO_USER_API_RNG) += algif_rng.o
obj-$(CONFIG_CRYPTO_USER_API_AEAD) += algif_aead.o obj-$(CONFIG_CRYPTO_USER_API_AEAD) += algif_aead.o
obj-$(CONFIG_CRYPTO_ZSTD) += zstd.o obj-$(CONFIG_CRYPTO_ZSTD) += zstd.o
obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o
ecdh_generic-y := ecc.o ecdh_generic-y := ecc.o
ecdh_generic-y += ecdh.o ecdh_generic-y += ecdh.o

1142
crypto/streebog_generic.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -76,6 +76,7 @@ static char *check[] = {
"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
"camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
"lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
"sb256", "sb512",
NULL NULL
}; };
@ -1276,6 +1277,14 @@ static int do_test(const char *alg, u32 type, u32 mask, int m)
ret += tcrypt_test("sha3-512"); ret += tcrypt_test("sha3-512");
break; break;
case 53:
ret += tcrypt_test("sb256");
break;
case 54:
ret += tcrypt_test("sb512");
break;
case 100: case 100:
ret += tcrypt_test("hmac(md5)"); ret += tcrypt_test("hmac(md5)");
break; break;
@ -1729,6 +1738,15 @@ static int do_test(const char *alg, u32 type, u32 mask, int m)
test_hash_speed("sha3-512", sec, generic_hash_speed_template); test_hash_speed("sha3-512", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break; if (mode > 300 && mode < 400) break;
case 327:
test_hash_speed("sb256", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
/* fall through */
case 328:
test_hash_speed("sb512", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
/* fall through */
case 399: case 399:
break; break;
@ -1836,6 +1854,16 @@ static int do_test(const char *alg, u32 type, u32 mask, int m)
case 424: case 424:
test_mb_ahash_speed("sha512", sec, generic_hash_speed_template); test_mb_ahash_speed("sha512", sec, generic_hash_speed_template);
if (mode > 400 && mode < 500) break; if (mode > 400 && mode < 500) break;
case 426:
test_mb_ahash_speed("sb256", sec, generic_hash_speed_template,
num_mb);
if (mode > 400 && mode < 500) break;
/* fall through */
case 427:
test_mb_ahash_speed("sb512", sec, generic_hash_speed_template,
num_mb);
if (mode > 400 && mode < 500) break;
/* fall through */
case 499: case 499:
break; break;

View File

@ -3466,6 +3466,18 @@ static const struct alg_test_desc alg_test_descs[] = {
.enc = __VECS(salsa20_stream_enc_tv_template) .enc = __VECS(salsa20_stream_enc_tv_template)
} }
} }
}, {
.alg = "sb256",
.test = alg_test_hash,
.suite = {
.hash = __VECS(sb256_tv_template)
}
}, {
.alg = "sb512",
.test = alg_test_hash,
.suite = {
.hash = __VECS(sb512_tv_template)
}
}, { }, {
.alg = "sha1", .alg = "sha1",
.test = alg_test_hash, .test = alg_test_hash,

View File

@ -38084,4 +38084,76 @@ static const struct comp_testvec zstd_decomp_tv_template[] = {
"functions.", "functions.",
}, },
}; };
/*
+ * Streebog test vectors from RFC 6986 and GOST R 34.11-2012
+ */
static const struct hash_testvec sb256_tv_template[] = {
{ /* M1 */
.plaintext = "012345678901234567890123456789012345678901234567890123456789012",
.psize = 63,
.digest =
"\x9d\x15\x1e\xef\xd8\x59\x0b\x89"
"\xda\xa6\xba\x6c\xb7\x4a\xf9\x27"
"\x5d\xd0\x51\x02\x6b\xb1\x49\xa4"
"\x52\xfd\x84\xe5\xe5\x7b\x55\x00",
},
{ /* M2 */
.plaintext =
"\xd1\xe5\x20\xe2\xe5\xf2\xf0\xe8"
"\x2c\x20\xd1\xf2\xf0\xe8\xe1\xee"
"\xe6\xe8\x20\xe2\xed\xf3\xf6\xe8"
"\x2c\x20\xe2\xe5\xfe\xf2\xfa\x20"
"\xf1\x20\xec\xee\xf0\xff\x20\xf1"
"\xf2\xf0\xe5\xeb\xe0\xec\xe8\x20"
"\xed\xe0\x20\xf5\xf0\xe0\xe1\xf0"
"\xfb\xff\x20\xef\xeb\xfa\xea\xfb"
"\x20\xc8\xe3\xee\xf0\xe5\xe2\xfb",
.psize = 72,
.digest =
"\x9d\xd2\xfe\x4e\x90\x40\x9e\x5d"
"\xa8\x7f\x53\x97\x6d\x74\x05\xb0"
"\xc0\xca\xc6\x28\xfc\x66\x9a\x74"
"\x1d\x50\x06\x3c\x55\x7e\x8f\x50",
},
};
static const struct hash_testvec sb512_tv_template[] = {
{ /* M1 */
.plaintext = "012345678901234567890123456789012345678901234567890123456789012",
.psize = 63,
.digest =
"\x1b\x54\xd0\x1a\x4a\xf5\xb9\xd5"
"\xcc\x3d\x86\xd6\x8d\x28\x54\x62"
"\xb1\x9a\xbc\x24\x75\x22\x2f\x35"
"\xc0\x85\x12\x2b\xe4\xba\x1f\xfa"
"\x00\xad\x30\xf8\x76\x7b\x3a\x82"
"\x38\x4c\x65\x74\xf0\x24\xc3\x11"
"\xe2\xa4\x81\x33\x2b\x08\xef\x7f"
"\x41\x79\x78\x91\xc1\x64\x6f\x48",
},
{ /* M2 */
.plaintext =
"\xd1\xe5\x20\xe2\xe5\xf2\xf0\xe8"
"\x2c\x20\xd1\xf2\xf0\xe8\xe1\xee"
"\xe6\xe8\x20\xe2\xed\xf3\xf6\xe8"
"\x2c\x20\xe2\xe5\xfe\xf2\xfa\x20"
"\xf1\x20\xec\xee\xf0\xff\x20\xf1"
"\xf2\xf0\xe5\xeb\xe0\xec\xe8\x20"
"\xed\xe0\x20\xf5\xf0\xe0\xe1\xf0"
"\xfb\xff\x20\xef\xeb\xfa\xea\xfb"
"\x20\xc8\xe3\xee\xf0\xe5\xe2\xfb",
.psize = 72,
.digest =
"\x1e\x88\xe6\x22\x26\xbf\xca\x6f"
"\x99\x94\xf1\xf2\xd5\x15\x69\xe0"
"\xda\xf8\x47\x5a\x3b\x0f\xe6\x1a"
"\x53\x00\xee\xe4\x6d\x96\x13\x76"
"\x03\x5f\xe8\x35\x49\xad\xa2\xb8"
"\x62\x0f\xcd\x7c\x49\x6c\xe5\xb3"
"\x3f\x0c\xb9\xdd\xdc\x2b\x64\x60"
"\x14\x3b\x03\xda\xba\xc9\xfb\x28",
},
};
#endif /* _CRYPTO_TESTMGR_H */ #endif /* _CRYPTO_TESTMGR_H */

34
include/crypto/streebog.h Normal file
View File

@ -0,0 +1,34 @@
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
/*
* Copyright (c) 2013 Alexey Degtyarev <alexey@renatasystems.org>
* Copyright (c) 2018 Vitaly Chikunov <vt@altlinux.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*/
#ifndef _CRYPTO_STREEBOG_H_
#define _CRYPTO_STREEBOG_H_
#include <linux/types.h>
#define STREEBOG256_DIGEST_SIZE 32
#define STREEBOG512_DIGEST_SIZE 64
#define STREEBOG_BLOCK_SIZE 64
struct streebog_uint512 {
u64 qword[8];
} __aligned(16);
struct streebog_state {
u8 buffer[64] __aligned(16);
struct streebog_uint512 hash;
struct streebog_uint512 h;
struct streebog_uint512 N;
struct streebog_uint512 Sigma;
size_t bufsize;
};
#endif /* !_CRYPTO_STREEBOG_H_ */