Skip to main content

Hash256

Struct Hash256 

Source
pub struct Hash256(/* private fields */);
Expand description

Streaming Ascon-Hash256 with a 32-byte digest.

Implementations§

Source§

impl Hash256

Source

pub fn new() -> Self

Start a new hash.

Examples found in repository?
examples/basic.rs (line 13)
3fn main() -> Result<(), ascon::Error> {
4    // Demonstration values only. Provision a secret key and a fresh nonce in use.
5    let cipher = Aead128::new(&[0x42; 16]);
6    let nonce = [0x01; 16];
7    let mut message = *b"Hello from Rust";
8    let tag = cipher.encrypt_in_place(&nonce, b"example", &mut message);
9    println!("Ciphertext: {message:02x?}\nTag: {tag:02x?}");
10    cipher.decrypt_in_place(&nonce, b"example", &mut message, &tag)?;
11    assert_eq!(&message, b"Hello from Rust");
12
13    let mut hash = Hash256::new();
14    hash.update(b"Hello ");
15    hash.update(b"from Rust");
16    println!("Hash: {:02x?}", hash.finalize());
17
18    let mut cxof = Cxof128::new(b"example protocol v1")?;
19    cxof.update(&message);
20    let mut reader = cxof.finalize();
21    let mut output = [0; 48];
22    reader.read(&mut output[..17]);
23    reader.read(&mut output[17..]);
24    println!("CXOF: {output:02x?}");
25    Ok(())
26}
Source

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

Absorb another message chunk. Empty chunks are allowed.

Examples found in repository?
examples/basic.rs (line 14)
3fn main() -> Result<(), ascon::Error> {
4    // Demonstration values only. Provision a secret key and a fresh nonce in use.
5    let cipher = Aead128::new(&[0x42; 16]);
6    let nonce = [0x01; 16];
7    let mut message = *b"Hello from Rust";
8    let tag = cipher.encrypt_in_place(&nonce, b"example", &mut message);
9    println!("Ciphertext: {message:02x?}\nTag: {tag:02x?}");
10    cipher.decrypt_in_place(&nonce, b"example", &mut message, &tag)?;
11    assert_eq!(&message, b"Hello from Rust");
12
13    let mut hash = Hash256::new();
14    hash.update(b"Hello ");
15    hash.update(b"from Rust");
16    println!("Hash: {:02x?}", hash.finalize());
17
18    let mut cxof = Cxof128::new(b"example protocol v1")?;
19    cxof.update(&message);
20    let mut reader = cxof.finalize();
21    let mut output = [0; 48];
22    reader.read(&mut output[..17]);
23    reader.read(&mut output[17..]);
24    println!("CXOF: {output:02x?}");
25    Ok(())
26}
Source

pub fn finalize(self) -> [u8; 32]

Finish the hash, consuming the absorbing state.

Examples found in repository?
examples/basic.rs (line 16)
3fn main() -> Result<(), ascon::Error> {
4    // Demonstration values only. Provision a secret key and a fresh nonce in use.
5    let cipher = Aead128::new(&[0x42; 16]);
6    let nonce = [0x01; 16];
7    let mut message = *b"Hello from Rust";
8    let tag = cipher.encrypt_in_place(&nonce, b"example", &mut message);
9    println!("Ciphertext: {message:02x?}\nTag: {tag:02x?}");
10    cipher.decrypt_in_place(&nonce, b"example", &mut message, &tag)?;
11    assert_eq!(&message, b"Hello from Rust");
12
13    let mut hash = Hash256::new();
14    hash.update(b"Hello ");
15    hash.update(b"from Rust");
16    println!("Hash: {:02x?}", hash.finalize());
17
18    let mut cxof = Cxof128::new(b"example protocol v1")?;
19    cxof.update(&message);
20    let mut reader = cxof.finalize();
21    let mut output = [0; 48];
22    reader.read(&mut output[..17]);
23    reader.read(&mut output[17..]);
24    println!("CXOF: {output:02x?}");
25    Ok(())
26}

Trait Implementations§

Source§

impl Default for Hash256

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.