crypto::blake2
blake2: BLAKE2b and BLAKE2s cryptographic hash functions per RFC 7693
BLAKE2b is optimized for 64-bit platforms and produces digests of any size between 1 and 64 bytes. BLAKE2s is optimized for 8- to 32-bit platforms and produces digests of any size between 1 and 32 bytes. Both implement the hash::hash interface and support keyed hashing (MAC).
This is a low-level module which implements cryptographic primitives. Direct use of cryptographic primitives is not recommended for non-experts, as incorrect use of these primitives can easily lead to the introduction of security vulnerabilities. Non-experts are advised to use the high-level operations available in the top-level crypto:: module.
Be advised that Hare's cryptography implementations have not been audited.
Index
Types
type digest2b;
type digest2s;
Constants
def BLOCKSZ2B: size = 128;
def BLOCKSZ2S: size = 64;
def MAXKEYSZ2B: size = 64;
def MAXKEYSZ2S: size = 32;
def SZ2B_256: size = 32;
def SZ2B_512: size = 64;
def SZ2S_128: size = 16;
def SZ2S_256: size = 32;
Functions
fn blake2b(key: []u8, sz: size) digest2b;
fn blake2s(key: []u8, sz: size) digest2s;
Types
type digest2b
type digest2b = struct {
hash::hash,
h: [8]u64,
tlow: u64,
thigh: u64,
block: [BLOCKSZ2B]u8,
blocklen: size,
h_init: [8]u64,
block_init: [BLOCKSZ2B]u8,
blocklen_init: size,
};
BLAKE2b digest state.
type digest2s
type digest2s = struct {
hash::hash,
h: [8]u32,
tlow: u32,
thigh: u32,
block: [BLOCKSZ2S]u8,
blocklen: size,
h_init: [8]u32,
block_init: [BLOCKSZ2S]u8,
blocklen_init: size,
};
BLAKE2s digest state.
Constants
def BLOCKSZ2B
def BLOCKSZ2B: size = 128;
The block size, in bytes, of a BLAKE2b hash.
def BLOCKSZ2S
def BLOCKSZ2S: size = 64;
The block size, in bytes, of a BLAKE2s hash.
def MAXKEYSZ2B
def MAXKEYSZ2B: size = 64;
The maximum key size, in bytes, for BLAKE2b keyed hashing.
def MAXKEYSZ2S
def MAXKEYSZ2S: size = 32;
The maximum key size, in bytes, for BLAKE2s keyed hashing.
def SZ2B_256
def SZ2B_256: size = 32;
The size, in bytes, of a BLAKE2b-256 digest.
def SZ2B_512
def SZ2B_512: size = 64;
The size, in bytes, of a BLAKE2b-512 digest.
def SZ2S_128
def SZ2S_128: size = 16;
The size, in bytes, of a BLAKE2s-128 digest.
def SZ2S_256
def SZ2S_256: size = 32;
The size, in bytes, of a BLAKE2s-256 digest.
Functions
fn blake2b
fn blake2b(key: []u8, sz: size) digest2b;
Creates a hash::hash which computes a BLAKE2b hash with a given key and a given hash size. The size must be between 1 and SZ2B_512, inclusive. The key must be at most MAXKEYSZ2B bytes. If this function is used to hash sensitive information, the caller should call hash::close to erase sensitive data from memory after use; if not, the use of hash::close is optional.
fn blake2s
fn blake2s(key: []u8, sz: size) digest2s;
Creates a hash::hash which computes a BLAKE2s hash with a given key and a given hash size. The size must be between 1 and SZ2S_256, inclusive. The key must be at most MAXKEYSZ2S bytes. If this function is used to hash sensitive information, the caller should call hash::close to erase sensitive data from memory after use; if not, the use of hash::close is optional.