class Cryptomancer::Hash::Blake2b

Defined in:

hash/blake2b.cr

Constant Summary

BLOCK_SIZE = 128

Block size in bytes

IV = [7640891576956012808_u64, 13503953896175478587_u64, 4354685564936845355_u64, 11912009170470909681_u64, 5840696475078001361_u64, 11170449401992604703_u64, 2270897969802886507_u64, 6620516959819538809_u64]

Initialization vector (IV) - first 64 bits of the fractional parts of the square roots of the first 8 primes

ROUNDS = 12

Number of rounds

SIGMA = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3], [11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4], [7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8], [9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13], [2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9], [12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11], [13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10], [6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5], [10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3]]

Message schedule permutation table

WORD_SIZE = 8

Word size in bytes

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(digest_length : UInt8 = 64, key : Bytes | Nil = nil, salt : Bytes | Nil = nil, personalization : Bytes | Nil = nil, as_bytes : Bool = false) #

Initialize BLAKE2b hash context

  • digest_length - Output length in bytes (1-64, default: 64)
  • key - Optional key for keyed hashing (MAC mode), max 64 bytes
  • salt - Optional salt, exactly 16 bytes
  • personalization - Optional personalization string, exactly 16 bytes

[View source]

Class Method Detail

def self.hash(data : String | Bytes, digest_length : UInt8 = 64, as_bytes : Bool = false) : Bytes | String #

Compute hash of data


[View source]
def self.keyed_hash(data : String | Bytes, key : Bytes, digest_length : UInt8 = 64, as_bytes : Bool = false) : Bytes | String #

Compute keyed hash (MAC mode)


[View source]

Instance Method Detail

def final : Bytes | String #

Finalize hash and return digest


[View source]
def update(data : Pointer(UInt8), length : Int32) : Nil #

Update hash with new data


[View source]
def update(data : Bytes) : Nil #

Update hash with new data


[View source]
def update(data : String) : Nil #

Update hash with new data


[View source]