streebog.bend checks
raw source on the hub · import bend-osdev-hashes@0.1.0.0/streebog.bend as Streebog
Streebog (GOST R 34.11-2012; RFC 6986, V. Dolmatov and A. Degtyarev, "GOST R 34.11-2012: Hash Function", 2013): 256- and 512-bit digests of 64-byte blocks. The compression function (section 8) g_N(h, m) = E(LPS(h xor N), m) xor h xor m, E(K, m) = X[K_13] LPS X[K_12] ... LPS X[K_1](m), K_1 = K, K_(i+1) = LPS(K_i xor C_i), where N counts the bits hashed so far; the hash (section 9) feeds the message 512 bits at a time, keeping N and the sum Sigma of the blocks modulo 2^512, then pads the last (short, possibly empty) block with a 1 bit and zeros, and finishes with g_0(h, N) and g_0(h, Sigma). Streebog-256 starts from h = (00000001)^64 and keeps the most significant 256 bits.
Byte order: RFC 6986 writes a 512-bit vector a_63 || ... || a_0; byte i of a 64-byte string in memory is a_i (its examples print messages and digests most significant byte first, the reverse of memory order). A 512-bit vector here is an Hs.HsW16 of sixteen 32-bit words, least significant first (word i holds bytes 4i .. 4i+3, little-endian), and a digest is the bytes in memory order: a_0 first. The 512-bit sums use 32-bit words with carries.
LPS runs on eight tables of 64-bit entries (each T_j[b] = l(Pi(b) << 8j); gen/streebog.py writes them from RFC 6986's Pi', tau and A, and checks them against S, P and L applied one after the other). The tables are part of the chaining value (built once by init), so a lookup is a walk down a tree of depth 8.
The hashes, as the crypto package's hash interface takes them: ~Hs.HsMdState<HsStbCv>, ~64n, ~32n, ~HsStreebog.init256(), ~HsStreebog.update, ~HsStreebog.final256, ~HsStreebog.digest256 ~Hs.HsMdState<HsStbCv>, ~64n, ~64n, ~HsStreebog.init512(), ~HsStreebog.update, ~HsStreebog.final512, ~HsStreebog.digest512
3 imports
import Base import bend-osdev-bytes@0.1.0.0/bytes.bend as B import ./hashes.bend as Hs
Types
type HsStbTab source · line 37 · raw
Data
A table of 256 64-bit entries, as a tree on the index's bits (opaque)
HsStbLeaf@v:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> HsStbTab
HsStbNode@l:HsStbTab -> @r:HsStbTab -> HsStbTab
type HsStbTabs source · line 42 · raw
Data
The eight LPS tables (opaque)
HsStbTabs@t0:HsStbTab -> @t1:HsStbTab -> @t2:HsStbTab -> @t3:HsStbTab -> @t4:HsStbTab -> @t5:HsStbTab -> @t6:HsStbTab -> @t7:HsStbTab -> HsStbTabs
type HsStbCv source · line 46 · raw
Data
The chaining value (opaque): h, N, Sigma, and the tables
HsStbCv@h:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @n:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @s:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @t:HsStbTabs -> HsStbCv
Definitions
def hs.stb.leaves source · line 49 · raw
@xs:List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2> -> List<&2, HsStbTab>
def hs.stb.pairs source · line 56 · raw
@ts:List<&2, HsStbTab> -> List<&2, HsStbTab>
def hs.stb.up source · line 63 · raw
@n:Nat -> @ts:List<&2, HsStbTab> -> List<&2, HsStbTab>
def hs.stb.root source · line 70 · raw
@ts:List<&2, HsStbTab> -> HsStbTab
def hs.stb.tab source · line 78 · raw
@xs:List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2> -> HsStbTab
the table of 256 entries (entry i is element i)
def hs.stb.pick source · line 81 · raw
@one:Bool -> @l:HsStbTab -> @r:HsStbTab -> HsStbTab
def hs.stb.get.go source · line 88 · raw
@d:Nat -> @t:HsStbTab -> @+i:U32 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2
def hs.stb.get source · line 104 · raw
@t:HsStbTab -> @+i:U32 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2
entry i (a byte) of a table
def hs.stb.x8 source · line 108 · raw
@e0:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @e1:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @e2:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @e3:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @e4:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @e5:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @e6:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @e7:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2
the XOR of eight 64-bit values
def hs.stb.join source · line 114 · raw
@o0:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @o1:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @o2:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @o3:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @o4:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @o5:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @o6:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> @o7:0xd04c3185dce130521497bf85ab03f249/hashes.HsW2 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
eight 64-bit chunks as a 512-bit vector, chunk 0 the least significant
def hs.stb.t0.list source · line 121 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2>
BEGIN GENERATED by gen/streebog.py: tables T_0[b] = l(Pi(b) << 0): each entry's low and high 32 bits
def hs.stb.t1.list source · line 188 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2>
T_1[b] = l(Pi(b) << 8): each entry's low and high 32 bits
def hs.stb.t2.list source · line 255 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2>
T_2[b] = l(Pi(b) << 16): each entry's low and high 32 bits
def hs.stb.t3.list source · line 322 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2>
T_3[b] = l(Pi(b) << 24): each entry's low and high 32 bits
def hs.stb.t4.list source · line 389 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2>
T_4[b] = l(Pi(b) << 32): each entry's low and high 32 bits
def hs.stb.t5.list source · line 456 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2>
T_5[b] = l(Pi(b) << 40): each entry's low and high 32 bits
def hs.stb.t6.list source · line 523 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2>
T_6[b] = l(Pi(b) << 48): each entry's low and high 32 bits
def hs.stb.t7.list source · line 590 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW2>
T_7[b] = l(Pi(b) << 56): each entry's low and high 32 bits
def HsStreebog.tables source · line 656 · raw
HsStbTabs
def hs.stb.c1 source · line 661 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
BEGIN GENERATED by gen/streebog.py: consts
def hs.stb.c2 source · line 664 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c3 source · line 667 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c4 source · line 670 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c5 source · line 673 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c6 source · line 676 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c7 source · line 679 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c8 source · line 682 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c9 source · line 685 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c10 source · line 688 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c11 source · line 691 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.c12 source · line 694 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.lps source · line 700 · raw
@+t:HsStbTabs -> @x:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
BEGIN GENERATED by gen/streebog.py: lps LPS(x): chunk k of the result is the XOR over j of T_j[byte k of chunk j]
def hs.stb.xor source · line 716 · raw
@a:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @b:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.words source · line 721 · raw
@a:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> List<&2, U32>
def hs.stb.of_words source · line 726 · raw
@xs:List<&2, U32> -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.bit source · line 733 · raw
@b:Bool -> U32
def hs.stb.add.go source · line 742 · raw
@xs:List<&2, U32> -> @ys:List<&2, U32> -> @+c:U32 -> List<&2, U32>
the words of x + y + c (c a carry, 0 or 1), least significant first, modulo 2^(32 n)
def hs.stb.add source · line 751 · raw
@a:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @b:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.small source · line 755 · raw
@v:U32 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
the 512-bit vector of a number below 2^32
def hs.stb.zero source · line 758 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.cs source · line 763 · raw
List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16>
def hs.stb.rounds source · line 767 · raw
@cs:List<&2, 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16> -> @+t:HsStbTabs -> @+k:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @x:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
E's rounds: x the data so far, k the round key; then the last key added
def hs.stb.g source · line 775 · raw
@+t:HsStbTabs -> @n:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @+h:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @+m:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
g_N(h, m)
def hs.stb.compress.of source · line 779 · raw
@cv:HsStbCv -> @+m:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> HsStbCv
One 64-byte block of stage 2: h = g_N(h, m), N += 512, Sigma += m
def HsStreebog.compress source · line 786 · raw
@cv:HsStbCv -> @blk:List<&2, U32> -> HsStbCv
(a block of another length gives zeros, as Hs.hs.block.le does: the engine passes only whole blocks)
def hs.stb.finish.of source · line 791 · raw
@cv:HsStbCv -> @+m:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @cnt:U32 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
Stage 3 on the chaining value: the last block m (its cnt bytes, then 1, then zeros), N += 8 cnt, Sigma += m, then g_0(h, N) and g_0(h, Sigma)
def hs.stb.finish source · line 798 · raw
@+st:0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<HsStbCv> -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
def hs.stb.out512 source · line 804 · raw
@x:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
the digests' bytes: all 64 (Streebog-512), or the most significant 32, bytes 32 to 63 (Streebog-256)
def hs.stb.out256 source · line 809 · raw
@x:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
def hs.stb.v512 source · line 818 · raw
@o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW16
The transformations on 512-bit vectors as 64-byte strings, byte i a_i (a shorter string is a number's low bytes, zeros above; bytes past 64 are ignored): LPS, and the compression function g_N(h, m) (RFC 6986, sections 7 and 8)
def HsStreebog.lps source · line 821 · raw
@x:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
def HsStreebog.g source · line 824 · raw
@n:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> @h:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> @m:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
def HsStreebog.init512 source · line 829 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<HsStbCv>
def HsStreebog.init256 source · line 832 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<HsStbCv>
def HsStreebog.update source · line 836 · raw
@s:0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<HsStbCv> -> @o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<HsStbCv>
the state after more bytes (either digest size: init chooses)
def HsStreebog.final512 source · line 841 · raw
@s:0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<HsStbCv> -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
the digests of the bytes so far (a state from init512 for final512, from init256 for final256)
def HsStreebog.final256 source · line 844 · raw
@s:0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<HsStbCv> -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
def HsStreebog.digest512 source · line 848 · raw
@o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
The digests in one call
def HsStreebog.digest256 source · line 851 · raw
@o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets