~/bend-docscommunity

hash.bend checks

raw source on the hub · import bend-osdev-crypto@0.1.0.0/hash.bend as Hash

The hash interface.

A hash (template arguments, in this order): ~H: Data the state ~bsize: Nat the block size in bytes (HMAC's B) ~dsize: Nat the digest size in bytes (HMAC's L) ~init: H the state before any byte ~update: H -> B.Octets -> H the state after more bytes ~final: H -> B.Octets the digest of the bytes so far ~digest: B.Octets -> B.Octets the digest in one call Laws (README.md, "Laws"): streaming update(s, a ++ b) == update(update(s, a), b), for every state s, so pieces may be fed in any split split final(update(update(init, a), b)) == digest(a ++ b): the streaming result equals the one-shot result for every split length final(s) has dsize bytes (tested)

A hash whose one-shot form is not separate code takes CrHash.digest_of (the streaming form in one call) as its ~digest. The instances: inst_crc.bend (CRC-32 and CRC-64 of any parameter set, non-cryptographic), inst_sha2.bend (SHA-256, SHA-512), and the hashes package's MD4, MD5, SHA-1, RIPEMD-160, SM3 and Streebog (their defs directly; each file's header gives its tuple). Generic algorithms over any hash: hmac.bend, hkdf.bend.

2 imports
import Base
import bend-osdev-bytes@0.1.0.0/bytes.bend as B

Templates

template cr.hash.feed source · line 27 · raw

@-H:Data -> @-update:(@_:H -> @_:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> H) -> @ps:List<&2, 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets> -> @s:H -> H

template CrHash.update_all source · line 35 · raw

@-H:Data -> @-update:(@_:H -> @_:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> H) -> @s:H -> @ps:List<&2, 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets> -> H

the state after each piece in turn

template CrHash.of_pieces source · line 39 · raw

@-H:Data -> @-init:H -> @-update:(@_:H -> @_:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> H) -> @-final:(@_:H -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets) -> @ps:List<&2, 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets> -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets

the digest of the pieces joined, through the streaming interface

template CrHash.digest_of source · line 44 · raw

@-H:Data -> @-init:H -> @-update:(@_:H -> @_:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> H) -> @-final:(@_:H -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets) -> @m:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets

the streaming interface in one call: a ~digest for a hash with no one-shot code of its own