-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelay_function.rs
More file actions
50 lines (38 loc) · 1.17 KB
/
delay_function.rs
File metadata and controls
50 lines (38 loc) · 1.17 KB
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
#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! argon2 = "0.5.3"
//! hex = "0.4.3"
//! ```
use argon2::{
password_hash::{PasswordHasher, Salt},
Algorithm, Argon2, Params,
};
const SALT: &str = "T1JBT19ORVRXT1JL";
const M_COST: u32 = 16 * 1024 * 1024;
const T_COST: u32 = 2048;
const P_COST: u32 = 1;
const OUTPUT_SIZE: Option<usize> = Some(32);
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 2 {
eprintln!("Expected args: {} <beacon input>", args[0]);
std::process::exit(1);
}
let mut hash = [0_u8; 32];
let beacon_input = hex::decode(&args[1]).expect("beacon input must be 32 byte hex");
hash.copy_from_slice(
beacon_input
.get(..32)
.expect("beacon input must be 32 byte hex"),
);
let argon2 = Argon2::new(
Algorithm::Argon2d,
Default::default(),
Params::new(M_COST, T_COST, P_COST, OUTPUT_SIZE).unwrap(),
);
let salt = Salt::from_b64(SALT).unwrap();
let result = argon2.hash_password(&hash[..], salt).unwrap().hash.unwrap();
hash.copy_from_slice(result.as_bytes());
println!("{}", hex::encode(hash));
}