crypto::sha3
sha3: SHA3 hashing algorithm
The sha3 module implements the SHA-3 family of cryptographic hash and extendable-output functions as defined in FIPS 202. Namely, the SHA3-224, SHA3-256, SHA3-384, and SHA3-512 cryptographic hash functions and the SHAKE128 and SHAKE256 extendable-output functions.
Index
Types
type hash = struct {
hash::hash,
e: sponge,
};
type sponge = struct {
rate: size,
ds: u8,
s: [25]u64,
pos: size,
};
type xof = struct {
stream: io::stream,
e: sponge,
};
Constants
def BLOCKSZ224: size = 144;
def BLOCKSZ256: size = 136;
def BLOCKSZ384: size = 104;
def BLOCKSZ512: size = 72;
def SHAKE_BLOCKSZ128: size = 168;
def SHAKE_BLOCKSZ256: size = 136;
def SZ224: size = 28;
def SZ256: size = 32;
def SZ384: size = 48;
def SZ512: size = 64;
Functions
fn sha3_224() hash;
fn sha3_256() hash;
fn sha3_384() hash;
fn sha3_512() hash;
fn shake128() xof;
fn shake256() xof;
Types
type hash
Show undocumented member
type hash = struct {
hash::hash,
e: sponge,
};
type sponge
Show undocumented member
type sponge = struct {
rate: size,
ds: u8,
s: [25]u64,
pos: size,
};
type xof
Show undocumented member
type xof = struct {
stream: io::stream,
e: sponge,
};
Constants
def BLOCKSZ224
def BLOCKSZ224: size = 144;
The rate or block size, in bytes, of a SHA3-224 hash.
def BLOCKSZ256
def BLOCKSZ256: size = 136;
The rate or block size, in bytes, of a SHA3-256 hash.
def BLOCKSZ384
def BLOCKSZ384: size = 104;
The rate or block size, in bytes, of a SHA3-384 hash.
def BLOCKSZ512
def BLOCKSZ512: size = 72;
The rate or block size, in bytes, of a SHA3-512 hash.
def SHAKE_BLOCKSZ128
def SHAKE_BLOCKSZ128: size = 168;
The rate or block size, in bytes, of a SHAKE128 XOF.
def SHAKE_BLOCKSZ256
def SHAKE_BLOCKSZ256: size = 136;
The rate or block size, in bytes, of a SHAKE256 XOF.
def SZ224
def SZ224: size = 28;
The size, in bytes, of a SHA3-224 digest.
def SZ256
def SZ256: size = 32;
The size, in bytes, of a SHA3-256 digest.
def SZ384
def SZ384: size = 48;
The size, in bytes, of a SHA3-384 digest.
def SZ512
def SZ512: size = 64;
The size, in bytes, of a SHA3-512 digest.
Functions
fn sha3_224
fn sha3_224() hash;
Creates a hash::hash which computes a SHA3-224 hash. 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 sha3_256
fn sha3_256() hash;
Creates a hash::hash which computes a SHA3-256 hash. 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 sha3_384
fn sha3_384() hash;
Creates a hash::hash which computes a SHA3-384 hash. 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 sha3_512
fn sha3_512() hash;
Creates a hash::hash which computes a SHA3-512 hash. 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 shake128
fn shake128() xof;
Creates an io::stream that acts as a SHAKE128 eXtendable-Output Function (XOF). XOFs produce an output of unlimited size given some input data.
let shake = sha3::shake128();
// Absorb some input:
io::write(&shake, strings::toutf8("hello "))!;
io::write(&shake, strings::toutf8("hare!"))!;
// Copying the XOF copies its state:
let dup = shake;
// Squeeze some output:
let buf: []u8 = alloc([0...], 1337);
io::read(&shake, buf[..42])!;
io::read(&shake, buf[42..])!;
// Absorbing (i.e. writing) more input is an error:
assert(io::write(&shake, []) is errors::unsupported);
All calls to io::write while absorbing and to io::read always write/read the full specified buffer and never fail. If this stream is used to write sensitive information, the caller should call io::close to erase sensitive data from memory after use; if not, the use of io::close is optional.
fn shake256
fn shake256() xof;
Creates an io::stream that acts as a SHAKE256 eXtendable-Output Function (XOF). See shake128 for more information.