~/bend-docscommunity

sha256.bend checks

raw source on the hub · import 0xfbc4773809086afacef84e7fba6d620c/sha256.bend as Sha256

SHA-256 (FIPS 180-4), for Digest authentication with SHA-256 (RFC 7616). Bytes are U32s below 256; a block is 16 big-endian words.

1 import
import Base

Types

type Sha source · line 56 · raw

Data

The eight words of the state.

Definitions

def Sha.rotr source · line 6 · raw

@+x:U32 -> @+n:Nat -> U32

x rotated right by n bits (0 < n < 32).

def Sha.k source · line 11 · raw

List<&2, U32>

The round constants: the first 32 bits of the fractional parts of the cube roots of the first 64 primes.

def Sha.s0 source · line 24 · raw

@+x:U32 -> U32

def Sha.s1 source · line 27 · raw

@+x:U32 -> U32

def Sha.at.or source · line 30 · raw

@m:Maybe<&2, U32> -> U32

def Sha.at source · line 37 · raw

@xs:List<&2, U32> -> @i:Nat -> U32

def Sha.more source · line 42 · raw

@n:Nat -> @+win:List<&2, U32> -> @acc:List<&2, U32> -> List<&2, U32>

The message schedule: n more words after a window of the last 16 (the oldest first), each made of four of them; onto acc, the last first.

def Sha.sched source · line 52 · raw

@+ws:List<&2, U32> -> List<&2, U32>

The 64 words of a block's schedule, from its 16.

def Sha.steps source · line 60 · raw

@ks:List<&2, U32> -> @ws:List<&2, U32> -> @st:Sha -> Sha

The 64 steps over one block: a constant and a schedule word each.

def Sha.sum source · line 72 · raw

@x:Sha -> @y:Sha -> Sha

def Sha.words source · line 79 · raw

@n:Nat -> @bs:List<&2, U32> -> List<&2, U32>

The first n big-endian words of a byte list.

def Sha.blocks source · line 88 · raw

@fuel:Nat -> @+bs:List<&2, U32> -> @+st:Sha -> Sha

Every 64-byte block folded into the state; fuel: the block count.

def Sha.zeros source · line 96 · raw

@n:Nat -> List<&2, U32>

def Sha.be source · line 104 · raw

@+x:U32 -> List<&2, U32>

A word's four bytes, big-endian.

def Sha.pad source · line 110 · raw

@+bs:List<&2, U32> -> List<&2, U32>

The message padded: a 1 bit, zeros up to 56 mod 64, the bit length in 64 bits (messages here are far below 512 MB, so its high word is 0).

def Sha.out source · line 116 · raw

@st:Sha -> List<&2, U32>

def Sha.run source · line 123 · raw

@+p:List<&2, U32> -> List<&2, U32>

def Sha.hash source · line 129 · raw

@bs:List<&2, U32> -> List<&2, U32>

The 32 bytes of the SHA-256 of bs.