-
Notifications
You must be signed in to change notification settings - Fork 2
/
deck_function.rs
66 lines (52 loc) · 2.04 KB
/
deck_function.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
extern crate hex;
use rand::{thread_rng, RngCore};
use xoofff::Xoofff;
fn main() {
const KLEN: usize = 32; // bytes
const MSG0_LEN: usize = 32; // bytes
const MSG1_LEN: usize = 64; // bytes
const MSG2_LEN: usize = 128; // bytes
const MSG3_LEN: usize = 256; // bytes
const DLEN: usize = 32; // bytes
const DOMAIN_SEPERATOR: u8 = 0b11;
const DOMAIN_SEPERATOR_BIT_WIDTH: usize = 2;
const OFFSET: usize = 17; // bytes
let mut rng = thread_rng();
let mut key = vec![0u8; KLEN];
let mut msg0 = vec![0u8; MSG0_LEN];
let mut msg1 = vec![0u8; MSG1_LEN];
let mut msg2 = vec![0u8; MSG2_LEN];
let mut msg3 = vec![0u8; MSG3_LEN];
let mut dig = vec![0u8; DLEN];
// random sample (demo) key
rng.fill_bytes(&mut key);
// random sample four messages, creating a message sequence
rng.fill_bytes(&mut msg0);
rng.fill_bytes(&mut msg1);
rng.fill_bytes(&mut msg2);
rng.fill_bytes(&mut msg3);
let mut deck = Xoofff::new(&key);
// absorb first message
deck.absorb(&msg0);
deck.finalize(DOMAIN_SEPERATOR, DOMAIN_SEPERATOR_BIT_WIDTH, OFFSET);
deck.squeeze(&mut dig);
println!("Digest after consuming msg0 = {}", hex::encode(&dig));
deck.restart(); // restart absorb->squeeze->finalize cycle
// absorb second message
deck.absorb(&msg1);
deck.finalize(DOMAIN_SEPERATOR, DOMAIN_SEPERATOR_BIT_WIDTH, OFFSET);
deck.squeeze(&mut dig);
println!("Digest after consuming msg1 = {}", hex::encode(&dig));
deck.restart(); // restart absorb->squeeze->finalize cycle
// absorb third message
deck.absorb(&msg2);
deck.finalize(DOMAIN_SEPERATOR, DOMAIN_SEPERATOR_BIT_WIDTH, OFFSET);
deck.squeeze(&mut dig);
println!("Digest after consuming msg2 = {}", hex::encode(&dig));
deck.restart(); // restart absorb->squeeze->finalize cycle
// absorb last message
deck.absorb(&msg3);
deck.finalize(DOMAIN_SEPERATOR, DOMAIN_SEPERATOR_BIT_WIDTH, OFFSET);
deck.squeeze(&mut dig);
println!("Digest after consuming msg3 = {}", hex::encode(&dig));
}