crypto: streebog - add Streebog hash function
Subsystems (2)
cover crypto: streebog - add Streebog hash function
Add GOST/IETF Streebog hash function (GOST R 34.11-2012, RFC 6986) generic hash transformation with appropriate testmgr and tcrypt tests and vectors.
Streebog Hash Function (GOST R 34.11-2012, RFC 6986) is one of the Russian cryptographic standard algorithms (called GOST algorithms).
References:
https://tc26.ru/upload/iblock/fed/feddbb4d26b685903faa2ba11aea43f6.pdf
https://tools.ietf.org/html/rfc6986
Tested using testmgr and tcrypt on x86_64.
Vitaly Chikunov (2):
crypto: streebog - add Streebog hash function
crypto: streebog - add Streebog test vectors
crypto/Kconfig | 12 + crypto/Makefile | 1 + crypto/streebog_generic.c | 1142 +++++++++++++++++++++++++++++++++++++++++++++ crypto/tcrypt.c | 27 ++ crypto/testmgr.c | 12 + crypto/testmgr.h | 71 +++ include/crypto/streebog.h | 34 ++ 7 files changed, 1299 insertions(+) create mode 100644 crypto/streebog_generic.c create mode 100644 include/crypto/streebog.h
Signature · 1 line
2.11.0
PATCH 1/2 crypto: streebog - add Streebog hash function
Add GOST/IETF Streebog hash function (GOST R 34.11-2012, RFC 6986) generic hash transformation.
--- crypto/Kconfig | 12 + crypto/Makefile | 1 + crypto/streebog_generic.c | 1142 +++++++++++++++++++++++++++++++++++++++++++++ include/crypto/streebog.h | 34 ++ 4 files changed, 1189 insertions(+) create mode 100644 crypto/streebog_generic.c create mode 100644 include/crypto/streebog.h
crypto/Kconfig +12 -0
@@ -986,6 +986,18 @@ config CRYPTO_SM3 http://www.oscca.gov.cn/UpFile/20101222141857786.pdf https://datatracker.ietf.org/doc/html/draft-shen-sm3-hash +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 tristate "Tiger digest algorithms" select CRYPTO_HASH
crypto/Makefile +1 -0
@@ -70,6 +70,7 @@ obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o obj-$(CONFIG_CRYPTO_SHA512) += sha512_generic.o obj-$(CONFIG_CRYPTO_SHA3) += sha3_generic.o obj-$(CONFIG_CRYPTO_SM3) += sm3_generic.o +obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o obj-$(CONFIG_CRYPTO_WP512) += wp512.o CFLAGS_wp512.o := $(call cc-option,-fno-schedule-insns) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149 obj-$(CONFIG_CRYPTO_TGR192) += tgr192.o
crypto/streebog_generic.c new file +1142 -0
1,142 lines not on this page · raw message
include/crypto/streebog.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */ +/* +* Copyright (c) 2013 Alexey Degtyarev <[email protected]> +* Copyright (c) 2018 Vitaly Chikunov <[email protected]> +* +* 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_ */
Signature · 1 line
2.11.0
PATCH 2/2 crypto: streebog - add Streebog test vectors
In reply to Vitaly ChikunovAdd testmgr and tcrypt tests and vectors for Streebog hash function from RFC 6986 and GOST R 34.11-2012.
--- crypto/tcrypt.c | 27 +++++++++++++++++++++ crypto/testmgr.c | 12 ++++++++++ crypto/testmgr.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+)
crypto/tcrypt.c +27 -0
@@ -77,6 +77,7 @@ static char *check[] = {"khazad" ,"wp512" ,"wp384" ,"wp256" ,"tnepres" ,"xeta" ,"fcrypt" ,"camellia" ,"seed" ,"salsa20" ,"rmd128" ,"rmd160" ,"rmd256" ,"rmd320" ,"lzo" ,"cts" ,"zlib" ,"sha3-224" ,"sha3-256" ,"sha3-384" ,"sha3-512" , +"sb256" ,"sb512" ,NULL };
@@ -1914,6 +1915,14 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) ret +=tcrypt_test ("sm3" );break ; +case 53 : + ret +=tcrypt_test ("sb256" ); +break ; + +case 54 : + ret +=tcrypt_test ("sb512" ); +break ; +case 100 : ret +=tcrypt_test ("hmac(md5)" );break ;
@@ -2392,6 +2401,14 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)test_hash_speed ("sm3" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ;/* fall through */ +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 :break ;
@@ -2505,6 +2522,16 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) num_mb);if (mode >400 && mode <500 )break ;/* fall through */ +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 :break ;
crypto/testmgr.c +12 -0
@@ -3428,6 +3428,18 @@ static const struct alg_test_desc alg_test_descs[] = { .cipher = __VECS(salsa20_stream_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", .test = alg_test_hash, .fips_allowed = 1,
crypto/testmgr.h +71 -0
77 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 23 lines · Vitaly Chikunov
Add GOST/IETF Streebog hash function (GOST R 34.11-2012, RFC 6986) generic hash transformation.
Signed-off-by Vitaly Chikunov <[email protected]>--- crypto/Kconfig | 12 + crypto/Makefile | 1 + crypto/streebog_generic.c | 1142 +++++++++++++++++++++++++++++++++++++++++++++ include/crypto/streebog.h | 34 ++ 4 files changed, 1189 insertions(+) create mode 100644 crypto/streebog_generic.c create mode 100644 include/crypto/streebog.hcrypto/streebog_generic.c new file +0
-0@@ -0,0 +1,1142 @@Quoted 1 line
...
crypto/streebog_generic.c new file +5
-0+static inline void add512 (const struct streebog_uint512 *x, +const struct streebog_uint512 *y, +struct streebog_uint512 *r) +{ +u64 carry =0 ;
crypto/streebog_generic.c line 995
Quoted 10 lines
crypto/streebog_generic.c new file +10
-0+int i; + +for (i =0 ; i <8 ; i++) { +const u64 left =le64_to_cpu (x->qword[i]); +u64 sum; + + sum = left +le64_to_cpu (y->qword[i]) + carry; +if (sum != left) + carry = (sum < left); + r->qword[i] = sum;
Last assignment should be: r->qword[i] = cpu_to_le64(sum).