class

Beryl::Crypto::V1::BlockHashFunction

Inherits Digest < Reference < Object

The shared shape of MD5, SHA-1 and SHA-2: the message is cut into fixed-size blocks, each block is mixed into a running state, and the last block carries padding and the message length (the Merkle–Damgård construction of FIPS 180-4 §5 and RFC 1321 §3).

Each hash function supplies its block size, its compression function and the layout of its length field and digest (as private methods); this class supplies buffering, padding, and the ::Digest streaming interface (update, final, reset, hexfinal).

Constants

LARGEST_BLOCK_SIZE = 128

The largest block of any hash in this shard, in bytes (SHA-512).

LARGEST_DIGEST_SIZE = 64

The largest digest of any hash in this shard, in bytes (SHA-512).

MAXIMUM_MESSAGE_BYTESIZE = (1_u64 << 61) - 1

Every length field in this family counts bits in at least 64 bits, so a message may hold at most 2^61 - 1 bytes.

Constructors

Instance methods

block_size

Returns the number of bytes the compression function consumes per step.

Source
compress(list_of_blocks : Bytes) : Nil

Mixes list_of_blocks, whose size is a whole number of blocks, into the running state.

Source
copy_running_state_from(source : self) : Nil

Takes over the running state of source, and nothing else.

Source
copy_state_from(source : self) : Nil

Makes this instance continue from the exact point source has reached, without allocating. Both must be the same hash function.

Source
encode_digest(dst : Bytes) : Nil

Writes the digest, taken from the running state, into dst.

Source
encode_message_bit_length(message_bytesize : UInt64, length_field : Bytes) : Nil

Writes the message length in bits into length_field.

Source
length_field_bytesize

Returns the number of bytes at the end of the last block that hold the message length.

Source
reset_state

Sets the running state to the hash function's initial value.

Source