def len_hi

bend-collections-laws-crypto@1.0.0.0 · src/crypto/sha/core.bend:669

import bend-collections-laws-crypto@1.0.0.0/src/crypto/sha/core.bend as Core
import Base

669# Big-endian words of the 64-bit message bit length 8n, computed from n with
670# exactly the digit expressions bit_length produces, but without building and
671# matching an eight-element list. bit_length(n) is [o(d6), .., o(d0), low]
672# where d0 = n / 32, d(k+1) = dk / 256 and o(x) = x mod 256.
673def len_hi(+n: Nat) -> U32:
674  +d0 = Nat.div(n, 32n)
675  +d1 = Nat.div(d0, 256n)
676  +d2 = Nat.div(d1, 256n)
677  +d3 = Nat.div(d2, 256n)
678  +d4 = Nat.div(d3, 256n)
679  +d5 = Nat.div(d4, 256n)
680  +d6 = Nat.div(d5, 256n)
681  pack(U32.from_nat(Nat.mod(d6, 256n)), U32.from_nat(Nat.mod(d5, 256n)),
682    U32.from_nat(Nat.mod(d4, 256n)), U32.from_nat(Nat.mod(d3, 256n)))

Uses (6)

Used by (65)