sm3.bend checks
raw source on the hub · import bend-osdev-hashes@0.1.0.0/sm3.bend as Sm3
SM3 (GB/T 32905-2016, Information security techniques - SM3 cryptographic hash algorithm; in English, draft-shen-sm3-hash-01, S. Shen and X. Lee, "SM3 Hash Function", 2014): a 256-bit digest of 64-byte blocks, a message expansion to 68 + 64 words and 64 rounds (unrolled by gen/rounds.py). Big-endian words; the length in bits is padded in big-endian, as SHA-256.
bend-collections-laws-crypto@1.0.0.0 has no SM3 (it was checked file by file), so it is written here, from the specification.
The hash, as the crypto package's hash interface takes it: ~Hs.HsMdState<Hs.HsW8>, ~64n, ~32n, ~HsSm3.init(), ~HsSm3.update, ~HsSm3.final, ~HsSm3.digest
3 imports
import Base import bend-osdev-bytes@0.1.0.0/bytes.bend as B import ./hashes.bend as Hs
Definitions
def hs.sm3.p0 source · line 18 · raw
@+x:U32 -> U32
the permutations P0 and P1
def hs.sm3.p1 source · line 21 · raw
@+x:U32 -> U32
def hs.sm3.ff0 source · line 25 · raw
@x:U32 -> @y:U32 -> @z:U32 -> U32
the boolean functions FF_j and GG_j: for rounds 0 to 15, and 16 to 63
def hs.sm3.ff1 source · line 28 · raw
@+x:U32 -> @+y:U32 -> @+z:U32 -> U32
def hs.sm3.gg0 source · line 31 · raw
@x:U32 -> @y:U32 -> @z:U32 -> U32
def hs.sm3.gg1 source · line 34 · raw
@+x:U32 -> @y:U32 -> @z:U32 -> U32
def hs.sm3.rounds source · line 38 · raw
@x:0xd04c3185dce130521497bf85ab03f249/hashes.HsW16 -> @cv:0xd04c3185dce130521497bf85ab03f249/hashes.HsW8 -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW8
BEGIN GENERATED by gen/rounds.py: sm3
def HsSm3.iv source · line 549 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsW8
The chaining value before any block (IV)
def HsSm3.compress source · line 554 · raw
@cv:0xd04c3185dce130521497bf85ab03f249/hashes.HsW8 -> @blk:List<&2, U32> -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsW8
One 64-byte block (a list of another length is read as zero words: the engine passes only whole blocks)
def HsSm3.init source · line 557 · raw
0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<0xd04c3185dce130521497bf85ab03f249/hashes.HsW8>
def HsSm3.update source · line 560 · raw
@s:0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<0xd04c3185dce130521497bf85ab03f249/hashes.HsW8> -> @o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<0xd04c3185dce130521497bf85ab03f249/hashes.HsW8>
def HsSm3.final source · line 565 · raw
@s:0xd04c3185dce130521497bf85ab03f249/hashes.HsMdState<0xd04c3185dce130521497bf85ab03f249/hashes.HsW8> -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
the digest of the bytes so far: the padding, then the eight words big-endian
def HsSm3.digest source · line 569 · raw
@o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets
The digest in one call