std/digest/sha512

std/digest/src/sha512.trb

Sha512, the SHA-512 of FIPS 180-4: the hash Ed25519 is defined over (RFC 8032 section 5.1, std/signature), and the same shape as Sha256 - fed at once or in pieces, answering a Digest of 64 bytes.

Its words are 64 bits wide, so they are UInt64s and every sum is UInt64.addedWrapping, the one arithmetic of the language that wraps instead of panicking; the shifts of an unsigned word are logical. No native, and the same bytes give the same digest in both back ends.

type Sha512

type Sha512 with Hasher

SHA-512, fed in pieces: Sha512.add takes the next bytes and Sha512.finished answers the digest of everything added so far without changing the hasher, so a hasher can be read, fed more, and read again.

Examples

print Sha512.of("abc".bytes()).hex()

fn empty

static fn empty(): Self

A hasher with nothing fed yet, the same as Self().

fn of

static fn of(bytes: Bytes): Digest

The digest of bytes in one call.

fn blockSize

static fn blockSize(): Int

SHA-512 works in 128-byte blocks, twice Sha256's: its words are 64 bits wide, sixteen of them to a block.

fn digestLength

static fn digestLength(): Int

64: a SHA-512 digest is 512 bits.

fn add

var fn add(bytes: Bytes)

Feeds the next bytes.

fn finished

fn finished(): Digest

The digest of everything added so far. The hasher itself is unchanged and may be fed more.