tiny_keccak

Struct Sha3

Source
pub struct Sha3 { /* private fields */ }
Expand description

The SHA3 hash functions defined in FIPS-202.

§Usage

[dependencies]
tiny-keccak = { version = "2.0.0", features = ["sha3"] }

§Example

let input = b"hello world";
let mut output = [0; 32];
let expected = b"\
    \x64\x4b\xcc\x7e\x56\x43\x73\x04\x09\x99\xaa\xc8\x9e\x76\x22\xf3\
    \xca\x71\xfb\xa1\xd9\x72\xfd\x94\xa3\x1c\x3b\xfb\xf2\x4e\x39\x38\
";
let mut sha3 = Sha3::v256();
sha3.update(input);
sha3.finalize(&mut output);
assert_eq!(expected, &output);

Implementations§

Source§

impl Sha3

Source

pub fn v224() -> Sha3

Creates new Sha3 hasher with a security level of 224 bits.

Source

pub fn v256() -> Sha3

Creates new Sha3 hasher with a security level of 256 bits.

Examples found in repository?
examples/sha3.rs (line 4)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let mut sha3 = Sha3::v256();
    let mut output = [0; 32];
    let expected = b"\
        \x64\x4b\xcc\x7e\x56\x43\x73\x04\x09\x99\xaa\xc8\x9e\x76\x22\xf3\
        \xca\x71\xfb\xa1\xd9\x72\xfd\x94\xa3\x1c\x3b\xfb\xf2\x4e\x39\x38\
    ";

    sha3.update(b"hello");
    sha3.update(b" ");
    sha3.update(b"world");
    sha3.finalize(&mut output);

    assert_eq!(expected, &output);
}
Source

pub fn v384() -> Sha3

Creates new Sha3 hasher with a security level of 384 bits.

Source

pub fn v512() -> Sha3

Creates new Sha3 hasher with a security level of 512 bits.

Trait Implementations§

Source§

impl Clone for Sha3

Source§

fn clone(&self) -> Sha3

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Hasher for Sha3

Source§

fn update(&mut self, input: &[u8])

Absorb additional input. Can be called multiple times.
Source§

fn finalize(self, output: &mut [u8])

Pad and squeeze the state to the output.

Auto Trait Implementations§

§

impl Freeze for Sha3

§

impl RefUnwindSafe for Sha3

§

impl Send for Sha3

§

impl Sync for Sha3

§

impl Unpin for Sha3

§

impl UnwindSafe for Sha3

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.