silk/sha3
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
Portable fixed-output SHA-3 digests with allocation-free streaming states.
When to use
Use Sha3_224, Sha3_256, Sha3_384, or Sha3_512 when a protocol
requires the related fixed-output SHA-3 algorithm. Use silk.hash for collection keys.
Details
The actors return 28-byte, 32-byte, 48-byte, and 64-byte digests. Each actor supports
incremental update, consuming finish, and one-shot hash operations without allocation.
Gotchas
These actors implement fixed-output SHA-3. They do not implement SHAKE or another extendable-output function.
Examples
Compare segmented and one-shot SHA3-256 input
import silk.sha3 {Sha3_256}
pub fn main() -> i32 {
let mut state = Sha3_256.make()
state.update(b"a")
state.update(b"bc")
let segmented = state.finish()
let oneShot = Sha3_256.hash(b"abc")
let mut index: usize = 0
while index < 32 {
if segmented[index] != oneShot[index] {
return 1
}
index = index + 1
}
if segmented[0] != 58 {
return 2
}
return 0
}Import as Sha3_256 with import silk.sha3 { Sha3_256 }.
Public declarations: 4.
Sha3_224
pub struct Sha3_224An allocation-free streaming SHA3-224 state with a 28-byte fixed digest.
Details
Call update zero or more times, then call finish one time. Use hash for one complete
borrowed byte sequence. Finalization consumes the state.
Associated function Sha3_224.make
pub fn make() -> Sha3_224Creates an empty SHA3-224 streaming state without allocation.
Method Sha3_224.update
pub fn update<'life0, 'life1>(self: &'life0 mut Sha3_224, bytes: &'life1 [u8]) -> ()Absorbs bytes in order into this SHA3-224 state.
Details
An empty slice does not change the digest. Any chunking of the same byte sequence gives the same digest.
Method Sha3_224.finish
pub fn finish(self: Sha3_224) -> Array<u8, 28>Consumes this state and returns its standardized 28-byte SHA3-224 digest.
Associated function Sha3_224.hash
pub fn hash<'life0>(bytes: &'life0 [u8]) -> Array<u8, 28>Returns the standardized 28-byte SHA3-224 digest of bytes.
Details
This function uses the same make, update, and consuming finish lifecycle as streaming
use. It does not allocate.
Sha3_256
pub struct Sha3_256An allocation-free streaming SHA3-256 state with a 32-byte fixed digest.
Details
Call update zero or more times, then call finish one time. Use hash for one complete
borrowed byte sequence. Finalization consumes the state.
Associated function Sha3_256.make
pub fn make() -> Sha3_256Creates an empty SHA3-256 streaming state without allocation.
Method Sha3_256.update
pub fn update<'life0, 'life1>(self: &'life0 mut Sha3_256, bytes: &'life1 [u8]) -> ()Absorbs bytes in order into this SHA3-256 state.
Details
An empty slice does not change the digest. Any chunking of the same byte sequence gives the same digest.
Method Sha3_256.finish
pub fn finish(self: Sha3_256) -> Array<u8, 32>Consumes this state and returns its standardized 32-byte SHA3-256 digest.
Associated function Sha3_256.hash
pub fn hash<'life0>(bytes: &'life0 [u8]) -> Array<u8, 32>Returns the standardized 32-byte SHA3-256 digest of bytes.
Details
This function uses the same make, update, and consuming finish lifecycle as streaming
use. It does not allocate.
Sha3_384
pub struct Sha3_384An allocation-free streaming SHA3-384 state with a 48-byte fixed digest.
Details
Call update zero or more times, then call finish one time. Use hash for one complete
borrowed byte sequence. Finalization consumes the state.
Associated function Sha3_384.make
pub fn make() -> Sha3_384Creates an empty SHA3-384 streaming state without allocation.
Method Sha3_384.update
pub fn update<'life0, 'life1>(self: &'life0 mut Sha3_384, bytes: &'life1 [u8]) -> ()Absorbs bytes in order into this SHA3-384 state.
Details
An empty slice does not change the digest. Any chunking of the same byte sequence gives the same digest.
Method Sha3_384.finish
pub fn finish(self: Sha3_384) -> Array<u8, 48>Consumes this state and returns its standardized 48-byte SHA3-384 digest.
Associated function Sha3_384.hash
pub fn hash<'life0>(bytes: &'life0 [u8]) -> Array<u8, 48>Returns the standardized 48-byte SHA3-384 digest of bytes.
Details
This function uses the same make, update, and consuming finish lifecycle as streaming
use. It does not allocate.
Sha3_512
pub struct Sha3_512An allocation-free streaming SHA3-512 state with a 64-byte fixed digest.
Details
Call update zero or more times, then call finish one time. Use hash for one complete
borrowed byte sequence. Finalization consumes the state.
Associated function Sha3_512.make
pub fn make() -> Sha3_512Creates an empty SHA3-512 streaming state without allocation.
Method Sha3_512.update
pub fn update<'life0, 'life1>(self: &'life0 mut Sha3_512, bytes: &'life1 [u8]) -> ()Absorbs bytes in order into this SHA3-512 state.
Details
An empty slice does not change the digest. Any chunking of the same byte sequence gives the same digest.
Method Sha3_512.finish
pub fn finish(self: Sha3_512) -> Array<u8, 64>Consumes this state and returns its standardized 64-byte SHA3-512 digest.
Associated function Sha3_512.hash
pub fn hash<'life0>(bytes: &'life0 [u8]) -> Array<u8, 64>Returns the standardized 64-byte SHA3-512 digest of bytes.
Details
This function uses the same make, update, and consuming finish lifecycle as streaming
use. It does not allocate.