// SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause
/*
* Streebog hash function as specified by GOST R 34.11-2012 and
* described at https://tools.ietf.org/html/rfc6986
*
* 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.
*/
#include <crypto/internal/hash.h>
#include <linux/module.h>
#include <linux/crypto.h>
#include <crypto/streebog.h>
static const struct streebog_uint512 buffer0 = { {
0, 0, 0, 0, 0, 0, 0, 0
} };
static const struct streebog_uint512 buffer512 = { {
cpu_to_le64(0x200), 0, 0, 0, 0, 0, 0, 0
} };
static const struct streebog_uint512 C[12] = {
{ {
cpu_to_le64(0xdd806559f2a64507ULL),
cpu_to_le64(0x05767436cc744d23ULL),
cpu_to_le64(0xa2422a08a460d315ULL),
cpu_to_le64(0x4b7ce09192676901ULL),
cpu_to_le64(0x714eb88d7585c4fcULL),
cpu_to_le64(0x2f6a76432e45d016ULL),
cpu_to_le64(0xebcb2f81c0657c1fULL),
cpu_to_le64(0xb1085bda1ecadae9ULL)
} },
{ {
cpu_to_le64(0xe679047021b19bb7ULL),
cpu_to_le64(0x55dda21bd7cbcd56ULL),
cpu_to_le64(0x5cb561c2db0aa7caULL),
cpu_to_le64(0x9ab5176b12d69958ULL),
cpu_to_le64(0x61d55e0f16b50131ULL),
cpu_to_le64(0xf3feea720a232b98ULL),
cpu_to_le64(0x4fe39d460f70b5d7ULL),
cpu_to_le64(0x6fa3b58aa99d2f1aULL)
} },
{ {
cpu_to_le64(0x991e96f50aba0ab2ULL),
cpu_to_le64(0xc2b6f443867adb31ULL),
cpu_to_le64(0xc1c93a376062db09ULL),
cpu_to_le64(0xd3e20fe490359eb1ULL),
cpu_to_le64(0xf2ea7514b1297b7bULL),
cpu_to_le64(0x06f15e5f529c1f8bULL),
cpu_to_le64(0x0a39fc286a3d8435ULL),
cpu_to_le64(0xf574dcac2bce2fc7ULL)
} },
{ {
cpu_to_le64(0x220cbebc84e3d12eULL),
cpu_to_le64(0x3453eaa193e837f1ULL),
cpu_to_le64(0xd8b71333935203beULL),
cpu_to_le64(0xa9d72c82ed03d675ULL),
cpu_to_le64(0x9d721cad685e353fULL),
cpu_to_le64(0x488e857e335c3c7dULL),
cpu_to_le64(0xf948e1a05d71e4ddULL),
cpu_to_le64(0xef1fdfb3e81566d2ULL)
} },
{ {
cpu_to_le64(0x601758fd7c6cfe57ULL),
cpu_to_le64(0x7a56a27ea9ea63f5ULL),
cpu_to_le64(0xdfff00b723271a16ULL),
cpu_to_le64(0xbfcd1747253af5a3ULL),
cpu_to_le64(0x359e35d7800fffbdULL),
cpu_to_le64(0x7f151c1f1686104aULL),
cpu_to_le64(0x9a3f410c6ca92363ULL),
cpu_to_le64(0x4bea6bacad474799ULL)
} },
{ {
cpu_to_le64(0xfa68407a46647d6eULL),
cpu_to_le64(0xbf71c57236904f35ULL),
cpu_to_le64(0x0af21f66c2bec6b6ULL),
cpu_to_le64(0xcffaa6b71c9ab7b4ULL),
cpu_to_le64(0x187f9ab49af08ec6ULL),
cpu_to_le64(0x2d66c4f95142a46cULL),
cpu_to_le64(0x6fa4c33b7a3039c0ULL),
cpu_to_le64(0xae4faeae1d3ad3d9ULL)
} },
{ {
cpu_to_le64(0x8886564d3a14d493ULL),
cpu_to_le64(0x3517454ca23c4af3ULL),
cpu_to_le64(0x06476983284a0504ULL),
cpu_to_le64(0x0992abc52d822c37ULL),
cpu_to_le64(0xd3473e33197a93c9ULL),
cpu_to_le64(0x399ec6c7e6bf87c9ULL),
cpu_to_le64(0x51ac86febf240954ULL),
cpu_to_le64(0xf4c70e16eeaac5ecULL)
} },
{ {
cpu_to_le64(0xa47f0dd4bf02e71eULL),
cpu_to_le64(0x36acc2355951a8d9ULL),
cpu_to_le64(0x69d18d2bd1a5c42fULL),
cpu_to_le64(0xf4892bcb929b0690ULL),
cpu_to_le64(0x89b4443b4ddbc49aULL),
cpu_to_le64(0x4eb7f8719c36de1eULL),
cpu_to_le64(0x03e7aa020c6e4141ULL),
cpu_to_le64(0x9b1f5b424d93c9a7ULL)
} },
{ {
cpu_to_le64(0x7261445183235adbULL),
cpu_to_le64(0x0e38dc92cb1f2a60ULL),
cpu_to_le64(0x7b2b8a9aa6079c54ULL),
cpu_to_le64(0x800a440bdbb2ceb1ULL),
cpu_to_le64(0x3cd955b7e00d0984ULL),
cpu_to_le64(0x3a7d3a1b25894224ULL),
cpu_to_le64(0x944c9ad8ec165fdeULL),
cpu_to_le64(0x378f5a541631229bULL)
} },
{ {
cpu_to_le64(0x74b4c7fb98459cedULL),
cpu_to_le64(0x3698fad1153bb6c3ULL),
cpu_to_le64(0x7a1e6c303b7652f4ULL),
cpu_to_le64(0x9fe76702af69334bULL),
cpu_to_le64(0x1fffe18a1b336103ULL),
cpu_to_le64(0x8941e71cff8a78dbULL),
cpu_to_le64(0x382ae548b2e4f3f3ULL),
cpu_to_le64(0xabbedea680056f52ULL)
} },
{ {
cpu_to_le64(0x6bcaa4cd81f32d1bULL),
cpu_to_le64(0xdea2594ac06fd85dULL),
cpu_to_le64(0xefbacd1d7d476e98ULL),
cpu_to_le64(0x8a1d71efea48b9caULL),
cpu_to_le64(0x2001802114846679ULL),
cpu_to_le64(0xd8fa6bbbebab0761ULL),
cpu_to_le64(0x3002c6cd635afe94ULL),
cpu_to_le64(0x7bcd9ed0efc889fbULL)
} },
{ {
cpu_to_le64(0x48bc924af11bd720ULL),
cpu_to_le64(0xfaf417d5d9b21b99ULL),
cpu_to_le64(0xe71da4aa88e12852ULL),
cpu_to_le64(0x5d80ef9d1891cc86ULL),
cpu_to_le64(0xf82012d430219f9bULL),
cpu_to_le64(0xcda43c32bcdf1d77ULL),
cpu_to_le64(0xd21380b00449b17aULL),
cpu_to_le64(0x378ee767f11631baULL)
} }
};
static const unsigned long long Ax[8][256] = {
{
0xd01f715b5c7ef8e6ULL, 0x16fa240980778325ULL, 0xa8a42e857ee049c8ULL,
0x6ac1068fa186465bULL, 0x6e417bd7a2e9320bULL, 0x665c8167a437daabULL,
0x7666681aa89617f6ULL, 0x4b959163700bdcf5ULL, 0xf14be6b78df36248ULL,
0xc585bd689a625cffULL, 0x9557d7fca67d82cbULL, 0x89f0b969af6dd366ULL,
0xb0833d48749f6c35ULL, 0xa1998c23b1ecbc7cULL, 0x8d70c431ac02a736ULL,
0xd6dfbc2fd0a8b69eULL, 0x37aeb3e551fa198bULL, 0x0b7d128a40b5cf9cULL,
0x5a8f2008b5780cbcULL, 0xedec882284e333e5ULL, 0xd25fc177d3c7c2ceULL,
0x5e0f5d50b61778ecULL, 0x1d873683c0c24cb9ULL, 0xad040bcbb45d208cULL,
0x2f89a0285b853c76ULL, 0x5732fff6791b8d58ULL, 0x3e9311439ef6ec3fULL,
0xc9183a809fd3c00fULL, 0x83adf3f5260a01eeULL, 0xa6791941f4e8ef10ULL