Sha256 structv0.1.0

Source
An incremental SHA-256 or SHA-224.
pub struct Sha256 {
    // private fields
}

Structural Copy; copying takes an independent snapshot of the digest state.

Constructors

Sha256

pub func Sha256() -> Sha256

A SHA-256 state.

Returns: a hasher producing a 256-bit digest

Source

Associated functions

New224

pub func New224() -> Sha256

A SHA-224 state: the same compression function from a different start, keeping seven words of the result.

Returns: a hasher producing a 224-bit digest

Source

Implements Digest

Sha256 conforms to Digest.

Update

pub func Update(self: &var Sha256, bytes: char8[..])

Adds bytes to the message. Any split of the same bytes gives the same digest: whatever does not complete a block is buffered, and the buffer is only compressed once it is full.

NameTypeDescription
byteschar8[..]the bytes to absorb

Source

Finish

pub func Finish(self: &var Sha256, into: var char8[..])

Writes the digest into into. The padding is a one bit, then zeros, then the message length in bits as a big-endian sixty-four bit count. When fewer than nine bytes remain in the final block there is no room for that count, so the block is finished with zeros and a whole further block carries it — the case that separates a correct implementation from one that passes the short vectors.

NameTypeDescription
intovar char8[..]receives the output

Source

DigestLength

pub func DigestLength(self: &Sha256) -> uint

Thirty-two bytes for SHA-256, twenty-eight for SHA-224.

Returns: how many bytes a digest occupies

Source

BlockLength

pub func BlockLength(self: &Sha256) -> uint

Sixty-four bytes, for both.

Returns: how many bytes the compression function consumes at a time

Source

Sha256Of

pub func Sha256Of(bytes: char8[..], into: var char8[..])

The SHA-256 digest of bytes, in one call.

Source

Parameters

NameTypeDescription
byteschar8[..]the bytes to absorb
intovar char8[..]receives the output

Sha224Of

pub func Sha224Of(bytes: char8[..], into: var char8[..])

The SHA-224 digest of bytes, in one call.

Source

Parameters

NameTypeDescription
byteschar8[..]the bytes to absorb
intovar char8[..]receives the output