pub struct Hash256(/* private fields */);Expand description
Streaming Ascon-Hash256 with a 32-byte digest.
Implementations§
Source§impl Hash256
impl Hash256
Sourcepub fn new() -> Self
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}Sourcepub fn update(&mut self, input: &[u8])
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}Sourcepub fn finalize(self) -> [u8; 32]
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§
Auto Trait Implementations§
impl Forget for Hash256
impl Freeze for Hash256
impl RefUnwindSafe for Hash256
impl Send for Hash256
impl Sync for Hash256
impl Unpin for Hash256
impl UnsafeUnpin for Hash256
impl UnwindSafe for Hash256
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more