xcrypt 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +106 -0
- data/ext/libxcrypt/AUTHORS +38 -0
- data/ext/libxcrypt/COPYING.LIB +502 -0
- data/ext/libxcrypt/ChangeLog +239 -0
- data/ext/libxcrypt/INSTALL +380 -0
- data/ext/libxcrypt/LICENSING +152 -0
- data/ext/libxcrypt/Makefile.am +704 -0
- data/ext/libxcrypt/Makefile.in +4110 -0
- data/ext/libxcrypt/NEWS +630 -0
- data/ext/libxcrypt/README +1 -0
- data/ext/libxcrypt/README.md +179 -0
- data/ext/libxcrypt/THANKS +13 -0
- data/ext/libxcrypt/TODO +1 -0
- data/ext/libxcrypt/TODO.md +100 -0
- data/ext/libxcrypt/aclocal.m4 +2617 -0
- data/ext/libxcrypt/autogen.sh +33 -0
- data/ext/libxcrypt/autom4te.cache/output.0 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.1 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.2 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.3 +19885 -0
- data/ext/libxcrypt/autom4te.cache/requests +714 -0
- data/ext/libxcrypt/autom4te.cache/traces.0 +4088 -0
- data/ext/libxcrypt/autom4te.cache/traces.1 +1060 -0
- data/ext/libxcrypt/autom4te.cache/traces.2 +4088 -0
- data/ext/libxcrypt/autom4te.cache/traces.3 +1060 -0
- data/ext/libxcrypt/build-aux/ci/ci-log-dependency-versions +79 -0
- data/ext/libxcrypt/build-aux/ci/ci-log-logfiles +22 -0
- data/ext/libxcrypt/build-aux/ci/clang-gcov-wrapper +2 -0
- data/ext/libxcrypt/build-aux/ci/configure-wrapper +10 -0
- data/ext/libxcrypt/build-aux/ci/summarize-coverage +24 -0
- data/ext/libxcrypt/build-aux/m4/ax_append_compile_flags.m4 +46 -0
- data/ext/libxcrypt/build-aux/m4/ax_append_flag.m4 +50 -0
- data/ext/libxcrypt/build-aux/m4/ax_check_compile_flag.m4 +53 -0
- data/ext/libxcrypt/build-aux/m4/ax_check_vscript.m4 +142 -0
- data/ext/libxcrypt/build-aux/m4/ax_gcc_func_attribute.m4 +246 -0
- data/ext/libxcrypt/build-aux/m4/ax_require_defined.m4 +37 -0
- data/ext/libxcrypt/build-aux/m4/ax_valgrind_check.m4 +239 -0
- data/ext/libxcrypt/build-aux/m4/libtool.m4 +8488 -0
- data/ext/libxcrypt/build-aux/m4/ltoptions.m4 +467 -0
- data/ext/libxcrypt/build-aux/m4/ltsugar.m4 +124 -0
- data/ext/libxcrypt/build-aux/m4/ltversion.m4 +24 -0
- data/ext/libxcrypt/build-aux/m4/lt~obsolete.m4 +99 -0
- data/ext/libxcrypt/build-aux/m4/pkg_compat.m4 +88 -0
- data/ext/libxcrypt/build-aux/m4/zw_alignment.m4 +90 -0
- data/ext/libxcrypt/build-aux/m4/zw_automodern.m4 +307 -0
- data/ext/libxcrypt/build-aux/m4/zw_detect_asan.m4 +24 -0
- data/ext/libxcrypt/build-aux/m4/zw_endianness.m4 +152 -0
- data/ext/libxcrypt/build-aux/m4/zw_ld_wrap.m4 +47 -0
- data/ext/libxcrypt/build-aux/m4/zw_prog_perl.m4 +40 -0
- data/ext/libxcrypt/build-aux/m4/zw_simple_warnings.m4 +150 -0
- data/ext/libxcrypt/build-aux/m4/zw_static_assert.m4 +68 -0
- data/ext/libxcrypt/build-aux/m4-autogen/compile +364 -0
- data/ext/libxcrypt/build-aux/m4-autogen/config.guess +1815 -0
- data/ext/libxcrypt/build-aux/m4-autogen/config.sub +2354 -0
- data/ext/libxcrypt/build-aux/m4-autogen/depcomp +792 -0
- data/ext/libxcrypt/build-aux/m4-autogen/install-sh +541 -0
- data/ext/libxcrypt/build-aux/m4-autogen/ltmain.sh +11524 -0
- data/ext/libxcrypt/build-aux/m4-autogen/missing +236 -0
- data/ext/libxcrypt/build-aux/m4-autogen/test-driver +160 -0
- data/ext/libxcrypt/build-aux/scripts/BuildCommon.pm +712 -0
- data/ext/libxcrypt/build-aux/scripts/check-perlcritic-config +76 -0
- data/ext/libxcrypt/build-aux/scripts/compute-symver-floor +116 -0
- data/ext/libxcrypt/build-aux/scripts/expand-selected-hashes +80 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-h +131 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-hashes-h +141 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-symbol-vers-h +150 -0
- data/ext/libxcrypt/build-aux/scripts/gen-libcrypt-map +67 -0
- data/ext/libxcrypt/build-aux/scripts/move-if-change +84 -0
- data/ext/libxcrypt/build-aux/scripts/skip-if-exec-format-error +78 -0
- data/ext/libxcrypt/codecov.yml +4 -0
- data/ext/libxcrypt/config.h.in +303 -0
- data/ext/libxcrypt/configure +19885 -0
- data/ext/libxcrypt/configure.ac +549 -0
- data/ext/libxcrypt/doc/crypt.3 +512 -0
- data/ext/libxcrypt/doc/crypt.5 +343 -0
- data/ext/libxcrypt/doc/crypt_checksalt.3 +106 -0
- data/ext/libxcrypt/doc/crypt_gensalt.3 +285 -0
- data/ext/libxcrypt/doc/crypt_gensalt_ra.3 +1 -0
- data/ext/libxcrypt/doc/crypt_gensalt_rn.3 +1 -0
- data/ext/libxcrypt/doc/crypt_preferred_method.3 +68 -0
- data/ext/libxcrypt/doc/crypt_r.3 +1 -0
- data/ext/libxcrypt/doc/crypt_ra.3 +1 -0
- data/ext/libxcrypt/doc/crypt_rn.3 +1 -0
- data/ext/libxcrypt/lib/alg-des-tables.c +3858 -0
- data/ext/libxcrypt/lib/alg-des.c +269 -0
- data/ext/libxcrypt/lib/alg-des.h +74 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-const.h +313 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-core.c +238 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-core.h +51 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.c +78 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.h +46 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-precalc.h +1426 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-ref.h +67 -0
- data/ext/libxcrypt/lib/alg-hmac-sha1.c +140 -0
- data/ext/libxcrypt/lib/alg-hmac-sha1.h +35 -0
- data/ext/libxcrypt/lib/alg-md4.c +270 -0
- data/ext/libxcrypt/lib/alg-md4.h +43 -0
- data/ext/libxcrypt/lib/alg-md5.c +291 -0
- data/ext/libxcrypt/lib/alg-md5.h +43 -0
- data/ext/libxcrypt/lib/alg-sha1.c +288 -0
- data/ext/libxcrypt/lib/alg-sha1.h +34 -0
- data/ext/libxcrypt/lib/alg-sha256.c +630 -0
- data/ext/libxcrypt/lib/alg-sha256.h +123 -0
- data/ext/libxcrypt/lib/alg-sha512.c +311 -0
- data/ext/libxcrypt/lib/alg-sha512.h +81 -0
- data/ext/libxcrypt/lib/alg-sm3-hmac.c +113 -0
- data/ext/libxcrypt/lib/alg-sm3-hmac.h +42 -0
- data/ext/libxcrypt/lib/alg-sm3.c +449 -0
- data/ext/libxcrypt/lib/alg-sm3.h +63 -0
- data/ext/libxcrypt/lib/alg-yescrypt-common.c +713 -0
- data/ext/libxcrypt/lib/alg-yescrypt-opt.c +1568 -0
- data/ext/libxcrypt/lib/alg-yescrypt-platform.c +106 -0
- data/ext/libxcrypt/lib/alg-yescrypt.h +360 -0
- data/ext/libxcrypt/lib/byteorder.h +164 -0
- data/ext/libxcrypt/lib/crypt-bcrypt.c +1061 -0
- data/ext/libxcrypt/lib/crypt-des-obsolete.c +215 -0
- data/ext/libxcrypt/lib/crypt-des.c +491 -0
- data/ext/libxcrypt/lib/crypt-gensalt-static.c +40 -0
- data/ext/libxcrypt/lib/crypt-gost-yescrypt.c +182 -0
- data/ext/libxcrypt/lib/crypt-md5.c +232 -0
- data/ext/libxcrypt/lib/crypt-nthash.c +134 -0
- data/ext/libxcrypt/lib/crypt-obsolete.h +40 -0
- data/ext/libxcrypt/lib/crypt-pbkdf1-sha1.c +260 -0
- data/ext/libxcrypt/lib/crypt-port.h +514 -0
- data/ext/libxcrypt/lib/crypt-scrypt.c +247 -0
- data/ext/libxcrypt/lib/crypt-sha256.c +308 -0
- data/ext/libxcrypt/lib/crypt-sha512.c +323 -0
- data/ext/libxcrypt/lib/crypt-sm3-yescrypt.c +189 -0
- data/ext/libxcrypt/lib/crypt-sm3.c +308 -0
- data/ext/libxcrypt/lib/crypt-static.c +44 -0
- data/ext/libxcrypt/lib/crypt-sunmd5.c +314 -0
- data/ext/libxcrypt/lib/crypt-yescrypt.c +177 -0
- data/ext/libxcrypt/lib/crypt.c +421 -0
- data/ext/libxcrypt/lib/crypt.h.in +249 -0
- data/ext/libxcrypt/lib/gen-des-tables.c +363 -0
- data/ext/libxcrypt/lib/hashes.conf +59 -0
- data/ext/libxcrypt/lib/libcrypt.map.in +48 -0
- data/ext/libxcrypt/lib/libcrypt.minver +97 -0
- data/ext/libxcrypt/lib/libxcrypt.pc.in +15 -0
- data/ext/libxcrypt/lib/util-base64.c +26 -0
- data/ext/libxcrypt/lib/util-gensalt-sha.c +88 -0
- data/ext/libxcrypt/lib/util-get-random-bytes.c +154 -0
- data/ext/libxcrypt/lib/util-make-failure-token.c +48 -0
- data/ext/libxcrypt/lib/util-xbzero.c +43 -0
- data/ext/libxcrypt/lib/util-xstrcpy.c +42 -0
- data/ext/libxcrypt/lib/xcrypt.h.in +58 -0
- data/ext/libxcrypt/libxcrypt.spec.rpkg +481 -0
- data/ext/libxcrypt/rpkg.conf +2 -0
- data/ext/libxcrypt/rpkg.macros +86 -0
- data/ext/libxcrypt/test/TestCommon.pm +326 -0
- data/ext/libxcrypt/test/alg-des.c +80 -0
- data/ext/libxcrypt/test/alg-gost3411-2012-hmac.c +90 -0
- data/ext/libxcrypt/test/alg-gost3411-2012.c +191 -0
- data/ext/libxcrypt/test/alg-hmac-sha1.c +187 -0
- data/ext/libxcrypt/test/alg-md4.c +111 -0
- data/ext/libxcrypt/test/alg-md5.c +134 -0
- data/ext/libxcrypt/test/alg-pbkdf-hmac-sha256.c +269 -0
- data/ext/libxcrypt/test/alg-sha1.c +111 -0
- data/ext/libxcrypt/test/alg-sha256.c +141 -0
- data/ext/libxcrypt/test/alg-sha512.c +170 -0
- data/ext/libxcrypt/test/alg-sm3-hmac.c +149 -0
- data/ext/libxcrypt/test/alg-sm3.c +168 -0
- data/ext/libxcrypt/test/alg-yescrypt.c +466 -0
- data/ext/libxcrypt/test/badsalt.c +726 -0
- data/ext/libxcrypt/test/badsetting.c +350 -0
- data/ext/libxcrypt/test/byteorder.c +254 -0
- data/ext/libxcrypt/test/checksalt.c +265 -0
- data/ext/libxcrypt/test/compile-strong-alias.c +43 -0
- data/ext/libxcrypt/test/crypt-badargs.c +392 -0
- data/ext/libxcrypt/test/crypt-gost-yescrypt.c +149 -0
- data/ext/libxcrypt/test/crypt-nested-call.c +180 -0
- data/ext/libxcrypt/test/crypt-sm3-yescrypt.c +149 -0
- data/ext/libxcrypt/test/crypt-too-long-phrase.c +157 -0
- data/ext/libxcrypt/test/des-cases.h +196 -0
- data/ext/libxcrypt/test/des-obsolete.c +206 -0
- data/ext/libxcrypt/test/des-obsolete_r.c +207 -0
- data/ext/libxcrypt/test/explicit-bzero.c +334 -0
- data/ext/libxcrypt/test/gensalt-bcrypt_x.c +54 -0
- data/ext/libxcrypt/test/gensalt-extradata.c +246 -0
- data/ext/libxcrypt/test/gensalt-nested-call.c +126 -0
- data/ext/libxcrypt/test/gensalt-nthash.c +65 -0
- data/ext/libxcrypt/test/gensalt.c +599 -0
- data/ext/libxcrypt/test/getrandom-fallbacks.c +295 -0
- data/ext/libxcrypt/test/getrandom-interface.c +211 -0
- data/ext/libxcrypt/test/ka-table-gen.py +945 -0
- data/ext/libxcrypt/test/ka-table.inc +5849 -0
- data/ext/libxcrypt/test/ka-tester.c +240 -0
- data/ext/libxcrypt/test/preferred-method.c +133 -0
- data/ext/libxcrypt/test/short-outbuf.c +119 -0
- data/ext/libxcrypt/test/special-char-salt.c +1160 -0
- data/ext/libxcrypt/test/symbols-compat.pl +137 -0
- data/ext/libxcrypt/test/symbols-renames.pl +107 -0
- data/ext/libxcrypt/test/symbols-static.pl +87 -0
- data/ext/xcrypt/xcrypt.c +9 -0
- data/lib/xcrypt/ffi.rb +76 -0
- data/lib/xcrypt/version.rb +5 -0
- data/lib/xcrypt.rb +89 -0
- metadata +267 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2013, Alexey Degtyarev <alexey@renatasystems.org>.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* GOST R 34.11-2012 core and API functions.
|
|
6
|
+
*
|
|
7
|
+
* $Id$
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "crypt-port.h"
|
|
11
|
+
|
|
12
|
+
#if INCLUDE_gost_yescrypt
|
|
13
|
+
|
|
14
|
+
#include "alg-gost3411-2012-core.h"
|
|
15
|
+
|
|
16
|
+
#pragma GCC diagnostic ignored "-Wcast-align"
|
|
17
|
+
|
|
18
|
+
#define BSWAP64(x) \
|
|
19
|
+
(((x & 0xFF00000000000000ULL) >> 56) | \
|
|
20
|
+
((x & 0x00FF000000000000ULL) >> 40) | \
|
|
21
|
+
((x & 0x0000FF0000000000ULL) >> 24) | \
|
|
22
|
+
((x & 0x000000FF00000000ULL) >> 8) | \
|
|
23
|
+
((x & 0x00000000FF000000ULL) << 8) | \
|
|
24
|
+
((x & 0x0000000000FF0000ULL) << 24) | \
|
|
25
|
+
((x & 0x000000000000FF00ULL) << 40) | \
|
|
26
|
+
((x & 0x00000000000000FFULL) << 56))
|
|
27
|
+
|
|
28
|
+
void
|
|
29
|
+
GOST34112012Cleanup(GOST34112012Context *CTX)
|
|
30
|
+
{
|
|
31
|
+
explicit_bzero(CTX, sizeof (GOST34112012Context));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void
|
|
35
|
+
GOST34112012Init(GOST34112012Context *CTX, const unsigned int digest_size)
|
|
36
|
+
{
|
|
37
|
+
unsigned int i;
|
|
38
|
+
|
|
39
|
+
memset(CTX, 0, sizeof (GOST34112012Context));
|
|
40
|
+
CTX->digest_size = digest_size;
|
|
41
|
+
|
|
42
|
+
for (i = 0; i < 8; i++)
|
|
43
|
+
{
|
|
44
|
+
if (digest_size == 256)
|
|
45
|
+
CTX->h.QWORD[i] = 0x0101010101010101ULL;
|
|
46
|
+
else
|
|
47
|
+
CTX->h.QWORD[i] = 0x00ULL;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static inline void
|
|
52
|
+
pad(GOST34112012Context *CTX)
|
|
53
|
+
{
|
|
54
|
+
if (CTX->bufsize < sizeof CTX->buffer)
|
|
55
|
+
{
|
|
56
|
+
memset (CTX->buffer + CTX->bufsize, 0,
|
|
57
|
+
sizeof(CTX->buffer) - CTX->bufsize);
|
|
58
|
+
CTX->buffer[CTX->bufsize] = 0x01;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static inline void
|
|
63
|
+
add512(const uint512_u *x, const uint512_u *y, uint512_u *r)
|
|
64
|
+
{
|
|
65
|
+
#ifndef __GOST3411_BIG_ENDIAN__
|
|
66
|
+
unsigned int CF;
|
|
67
|
+
unsigned int i;
|
|
68
|
+
|
|
69
|
+
CF = 0;
|
|
70
|
+
for (i = 0; i < 8; i++)
|
|
71
|
+
{
|
|
72
|
+
const unsigned long long left = x->QWORD[i];
|
|
73
|
+
unsigned long long sum;
|
|
74
|
+
|
|
75
|
+
sum = left + y->QWORD[i] + CF;
|
|
76
|
+
if (sum != left)
|
|
77
|
+
CF = (sum < left);
|
|
78
|
+
r->QWORD[i] = sum;
|
|
79
|
+
}
|
|
80
|
+
#else
|
|
81
|
+
const unsigned char *xp, *yp;
|
|
82
|
+
unsigned char *rp;
|
|
83
|
+
unsigned int i;
|
|
84
|
+
int buf;
|
|
85
|
+
|
|
86
|
+
xp = (const unsigned char *) &x[0];
|
|
87
|
+
yp = (const unsigned char *) &y[0];
|
|
88
|
+
rp = (unsigned char *) &r[0];
|
|
89
|
+
|
|
90
|
+
buf = 0;
|
|
91
|
+
for (i = 0; i < 64; i++)
|
|
92
|
+
{
|
|
93
|
+
buf = xp[i] + yp[i] + (buf >> 8);
|
|
94
|
+
rp[i] = (unsigned char) (buf & 0xFF);
|
|
95
|
+
}
|
|
96
|
+
#endif
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static void
|
|
100
|
+
g(uint512_u *h, const uint512_u *N, const unsigned char *m)
|
|
101
|
+
{
|
|
102
|
+
#ifdef __GOST3411_HAS_SSE2__
|
|
103
|
+
__m128i xmm0, xmm2, xmm4, xmm6; /* XMMR0-quadruple */
|
|
104
|
+
__m128i xmm1, xmm3, xmm5, xmm7; /* XMMR1-quadruple */
|
|
105
|
+
unsigned int i;
|
|
106
|
+
|
|
107
|
+
LOAD(N, xmm0, xmm2, xmm4, xmm6);
|
|
108
|
+
XLPS128M(h, xmm0, xmm2, xmm4, xmm6);
|
|
109
|
+
|
|
110
|
+
LOAD(m, xmm1, xmm3, xmm5, xmm7);
|
|
111
|
+
XLPS128R(xmm0, xmm2, xmm4, xmm6, xmm1, xmm3, xmm5, xmm7);
|
|
112
|
+
|
|
113
|
+
for (i = 0; i < 11; i++)
|
|
114
|
+
ROUND128(i, xmm0, xmm2, xmm4, xmm6, xmm1, xmm3, xmm5, xmm7);
|
|
115
|
+
|
|
116
|
+
XLPS128M((&C[11]), xmm0, xmm2, xmm4, xmm6);
|
|
117
|
+
X128R(xmm0, xmm2, xmm4, xmm6, xmm1, xmm3, xmm5, xmm7);
|
|
118
|
+
|
|
119
|
+
X128M(h, xmm0, xmm2, xmm4, xmm6);
|
|
120
|
+
X128M(m, xmm0, xmm2, xmm4, xmm6);
|
|
121
|
+
|
|
122
|
+
UNLOAD(h, xmm0, xmm2, xmm4, xmm6);
|
|
123
|
+
|
|
124
|
+
/* Restore the Floating-point status on the CPU */
|
|
125
|
+
_mm_empty();
|
|
126
|
+
#else
|
|
127
|
+
uint512_u Ki, data;
|
|
128
|
+
unsigned int i;
|
|
129
|
+
|
|
130
|
+
XLPS(h, N, (&data));
|
|
131
|
+
|
|
132
|
+
/* Starting E() */
|
|
133
|
+
Ki = data;
|
|
134
|
+
XLPS((&Ki), ((const uint512_u *) &m[0]), (&data));
|
|
135
|
+
|
|
136
|
+
for (i = 0; i < 11; i++)
|
|
137
|
+
ROUND(i, (&Ki), (&data));
|
|
138
|
+
|
|
139
|
+
XLPS((&Ki), (&C[11]), (&Ki));
|
|
140
|
+
X((&Ki), (&data), (&data));
|
|
141
|
+
/* E() done */
|
|
142
|
+
|
|
143
|
+
X((&data), h, (&data));
|
|
144
|
+
X((&data), ((const uint512_u *) &m[0]), h);
|
|
145
|
+
#endif
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static inline void
|
|
149
|
+
stage2(GOST34112012Context *CTX, const unsigned char *data)
|
|
150
|
+
{
|
|
151
|
+
uint512_u m;
|
|
152
|
+
|
|
153
|
+
memcpy(&m, data, sizeof(m));
|
|
154
|
+
g(&(CTX->h), &(CTX->N), (const unsigned char *)&m);
|
|
155
|
+
|
|
156
|
+
add512(&(CTX->N), &buffer512, &(CTX->N));
|
|
157
|
+
add512(&(CTX->Sigma), &m, &(CTX->Sigma));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static inline void
|
|
161
|
+
stage3(GOST34112012Context *CTX)
|
|
162
|
+
{
|
|
163
|
+
uint512_u buf = {{ 0 }};
|
|
164
|
+
|
|
165
|
+
#ifndef __GOST3411_BIG_ENDIAN__
|
|
166
|
+
buf.QWORD[0] = CTX->bufsize << 3;
|
|
167
|
+
#else
|
|
168
|
+
buf.QWORD[0] = BSWAP64(CTX->bufsize << 3);
|
|
169
|
+
#endif
|
|
170
|
+
|
|
171
|
+
pad(CTX);
|
|
172
|
+
|
|
173
|
+
g(&(CTX->h), &(CTX->N), (const unsigned char *) &(CTX->buffer));
|
|
174
|
+
|
|
175
|
+
add512(&(CTX->N), &buf, &(CTX->N));
|
|
176
|
+
add512(&(CTX->Sigma), (const uint512_u *) &CTX->buffer[0],
|
|
177
|
+
&(CTX->Sigma));
|
|
178
|
+
|
|
179
|
+
g(&(CTX->h), &buffer0, (const unsigned char *) &(CTX->N));
|
|
180
|
+
|
|
181
|
+
g(&(CTX->h), &buffer0, (const unsigned char *) &(CTX->Sigma));
|
|
182
|
+
memcpy(&(CTX->hash), &(CTX->h), sizeof (uint512_u));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void
|
|
186
|
+
GOST34112012Update(GOST34112012Context *CTX, const unsigned char *data, size_t len)
|
|
187
|
+
{
|
|
188
|
+
size_t chunksize;
|
|
189
|
+
|
|
190
|
+
if (CTX->bufsize) {
|
|
191
|
+
chunksize = 64 - CTX->bufsize;
|
|
192
|
+
if (chunksize > len)
|
|
193
|
+
chunksize = len;
|
|
194
|
+
|
|
195
|
+
memcpy(&CTX->buffer[CTX->bufsize], data, chunksize);
|
|
196
|
+
|
|
197
|
+
CTX->bufsize += chunksize;
|
|
198
|
+
len -= chunksize;
|
|
199
|
+
data += chunksize;
|
|
200
|
+
|
|
201
|
+
if (CTX->bufsize == 64)
|
|
202
|
+
{
|
|
203
|
+
stage2(CTX, CTX->buffer);
|
|
204
|
+
|
|
205
|
+
CTX->bufsize = 0;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
while (len > 63)
|
|
210
|
+
{
|
|
211
|
+
stage2(CTX, data);
|
|
212
|
+
|
|
213
|
+
data += 64;
|
|
214
|
+
len -= 64;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (len) {
|
|
218
|
+
memcpy(&CTX->buffer, data, len);
|
|
219
|
+
CTX->bufsize = len;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
void
|
|
224
|
+
GOST34112012Final(GOST34112012Context *CTX, unsigned char *digest)
|
|
225
|
+
{
|
|
226
|
+
stage3(CTX);
|
|
227
|
+
|
|
228
|
+
CTX->bufsize = 0;
|
|
229
|
+
|
|
230
|
+
if (CTX->digest_size == 256)
|
|
231
|
+
memcpy(digest, &(CTX->hash.QWORD[4]), 32);
|
|
232
|
+
else
|
|
233
|
+
memcpy(digest, &(CTX->hash.QWORD[0]), 64);
|
|
234
|
+
|
|
235
|
+
GOST34112012Cleanup(CTX);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
#endif /* INCLUDE_gost_yescrypt */
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2013, Alexey Degtyarev <alexey@renatasystems.org>.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* $Id$
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef _CRYPT_ALG_GOST3411_2012_CORE_H
|
|
9
|
+
#define _CRYPT_ALG_GOST3411_2012_CORE_H
|
|
10
|
+
|
|
11
|
+
#if defined __GOST3411_HAS_SSE41__
|
|
12
|
+
#include "alg-gost3411-2012-sse41.h"
|
|
13
|
+
#elif defined __GOST3411_HAS_SSE2__
|
|
14
|
+
#include "alg-gost3411-2012-sse2.h"
|
|
15
|
+
#elif defined __GOST3411_HAS_MMX__
|
|
16
|
+
#include "alg-gost3411-2012-mmx.h"
|
|
17
|
+
#else
|
|
18
|
+
#include "alg-gost3411-2012-ref.h"
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
typedef union uint512_u
|
|
22
|
+
{
|
|
23
|
+
unsigned long long QWORD[8];
|
|
24
|
+
} uint512_u;
|
|
25
|
+
|
|
26
|
+
#include "alg-gost3411-2012-const.h"
|
|
27
|
+
#include "alg-gost3411-2012-precalc.h"
|
|
28
|
+
|
|
29
|
+
typedef struct GOST34112012Context
|
|
30
|
+
{
|
|
31
|
+
unsigned char buffer[64];
|
|
32
|
+
uint512_u hash;
|
|
33
|
+
uint512_u h;
|
|
34
|
+
uint512_u N;
|
|
35
|
+
uint512_u Sigma;
|
|
36
|
+
size_t bufsize;
|
|
37
|
+
unsigned int digest_size;
|
|
38
|
+
} GOST34112012Context;
|
|
39
|
+
|
|
40
|
+
extern void GOST34112012Init(GOST34112012Context *CTX,
|
|
41
|
+
const unsigned int digest_size);
|
|
42
|
+
|
|
43
|
+
extern void GOST34112012Update(GOST34112012Context *CTX,
|
|
44
|
+
const unsigned char *data, size_t len);
|
|
45
|
+
|
|
46
|
+
extern void GOST34112012Final(GOST34112012Context *CTX,
|
|
47
|
+
unsigned char *digest);
|
|
48
|
+
|
|
49
|
+
extern void GOST34112012Cleanup(GOST34112012Context *CTX);
|
|
50
|
+
|
|
51
|
+
#endif /* alg-gost3411-2012-core.h */
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/* Copyright (C) 2018 vt@altlinux.org
|
|
2
|
+
* Copyright (C) 2018 Björn Esser <besser82@fedoraproject.org>
|
|
3
|
+
*
|
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
|
5
|
+
* modification, are permitted.
|
|
6
|
+
*
|
|
7
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
8
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
9
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
10
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
11
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
12
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
13
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
14
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
15
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
16
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
17
|
+
* SUCH DAMAGE.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
#include "crypt-port.h"
|
|
22
|
+
|
|
23
|
+
#if INCLUDE_gost_yescrypt
|
|
24
|
+
|
|
25
|
+
#include "alg-gost3411-2012-hmac.h"
|
|
26
|
+
|
|
27
|
+
/* GOST2012_256 */
|
|
28
|
+
void
|
|
29
|
+
gost_hash256 (const uint8_t *t, size_t n, uint8_t *out32,
|
|
30
|
+
GOST34112012Context *ctx)
|
|
31
|
+
{
|
|
32
|
+
GOST34112012Init (ctx, GOSTR3411_2012_BITS);
|
|
33
|
+
GOST34112012Update (ctx, t, n);
|
|
34
|
+
GOST34112012Final (ctx, out32);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* HMAC_GOSTR3411_2012_256 */
|
|
38
|
+
void
|
|
39
|
+
gost_hmac256 (const uint8_t *k, size_t n, const uint8_t *t, size_t len,
|
|
40
|
+
uint8_t *out32, gost_hmac_256_t *gostbuf)
|
|
41
|
+
{
|
|
42
|
+
size_t i;
|
|
43
|
+
|
|
44
|
+
/* R 50.1.113-2016 only allowed N to be in range 256..512 bits */
|
|
45
|
+
assert (n >= GOSTR3411_2012_L && n <= GOSTR3411_2012_B);
|
|
46
|
+
|
|
47
|
+
for (i = 0; i < sizeof (gostbuf->pad); i++)
|
|
48
|
+
gostbuf->kstar[i] = i < n ? k[i] : 0;
|
|
49
|
+
|
|
50
|
+
GOST34112012Init (&gostbuf->ctx, GOSTR3411_2012_BITS);
|
|
51
|
+
|
|
52
|
+
for (i = 0; i < sizeof (gostbuf->pad); i++)
|
|
53
|
+
gostbuf->pad[i] = gostbuf->kstar[i] ^ 0x36; /* ipad */
|
|
54
|
+
|
|
55
|
+
GOST34112012Update (&gostbuf->ctx, gostbuf->pad,
|
|
56
|
+
sizeof (gostbuf->pad));
|
|
57
|
+
GOST34112012Update (&gostbuf->ctx, t, len);
|
|
58
|
+
GOST34112012Final (&gostbuf->ctx, gostbuf->digest);
|
|
59
|
+
|
|
60
|
+
/* Clear the context state. */
|
|
61
|
+
explicit_bzero (&gostbuf->ctx, sizeof (GOST34112012Context));
|
|
62
|
+
|
|
63
|
+
GOST34112012Init (&gostbuf->ctx, GOSTR3411_2012_BITS);
|
|
64
|
+
|
|
65
|
+
for (i = 0; i < sizeof (gostbuf->pad); i++)
|
|
66
|
+
gostbuf->pad[i] = gostbuf->kstar[i] ^ 0x5c; /* opad */
|
|
67
|
+
|
|
68
|
+
GOST34112012Update (&gostbuf->ctx, gostbuf->pad,
|
|
69
|
+
sizeof (gostbuf->pad));
|
|
70
|
+
GOST34112012Update (&gostbuf->ctx, gostbuf->digest,
|
|
71
|
+
sizeof (gostbuf->digest));
|
|
72
|
+
GOST34112012Final (&gostbuf->ctx, out32);
|
|
73
|
+
|
|
74
|
+
/* Clear the context state. */
|
|
75
|
+
explicit_bzero (gostbuf, sizeof (gost_hmac_256_t));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#endif /* INCLUDE_gost_yescrypt */
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* Copyright (C) 2018 vt@altlinux.org
|
|
2
|
+
* Copyright (C) 2018 Björn Esser <besser82@fedoraproject.org>
|
|
3
|
+
*
|
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
|
5
|
+
* modification, are permitted.
|
|
6
|
+
*
|
|
7
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
8
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
9
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
10
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
11
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
12
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
13
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
14
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
15
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
16
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
17
|
+
* SUCH DAMAGE.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#ifndef _CRYPT_ALG_GOST3411_2012_HMAC_H
|
|
21
|
+
#define _CRYPT_ALG_GOST3411_2012_HMAC_H
|
|
22
|
+
|
|
23
|
+
#include "alg-gost3411-2012-core.h"
|
|
24
|
+
|
|
25
|
+
/* Constants for HMAC_GOSTR3411_2012_256 */
|
|
26
|
+
#define GOSTR3411_2012_L 32 /* hash output len */
|
|
27
|
+
#define GOSTR3411_2012_B 64 /* hash input len (512) */
|
|
28
|
+
#define GOSTR3411_2012_BITS GOSTR3411_2012_L * 8 /* 256 */
|
|
29
|
+
|
|
30
|
+
typedef struct
|
|
31
|
+
{
|
|
32
|
+
GOST34112012Context ctx;
|
|
33
|
+
unsigned char pad[GOSTR3411_2012_B]; /* ipad and opad */
|
|
34
|
+
unsigned char kstar[GOSTR3411_2012_B]; /* derived key */
|
|
35
|
+
unsigned char digest[GOSTR3411_2012_L];
|
|
36
|
+
} gost_hmac_256_t;
|
|
37
|
+
|
|
38
|
+
extern void
|
|
39
|
+
gost_hash256 (const uint8_t *t, size_t n, uint8_t *out32,
|
|
40
|
+
GOST34112012Context *ctx);
|
|
41
|
+
|
|
42
|
+
extern void
|
|
43
|
+
gost_hmac256 (const uint8_t *k, size_t n, const uint8_t *t, size_t len,
|
|
44
|
+
uint8_t *out32, gost_hmac_256_t *gostbuf);
|
|
45
|
+
|
|
46
|
+
#endif /* alg-gost3411-2012-hmac.h */
|