74 lines
1.9 KiB
Rust
74 lines
1.9 KiB
Rust
use std::{
|
|
pin::Pin,
|
|
thread::{spawn, JoinHandle},
|
|
time::Duration,
|
|
};
|
|
|
|
mod cpu;
|
|
pub type Key = [u8; 32];
|
|
|
|
struct ProgressCounter(pub *mut u64);
|
|
unsafe impl Send for ProgressCounter {}
|
|
unsafe impl Sync for ProgressCounter {}
|
|
impl ProgressCounter {
|
|
fn incr(&mut self) {
|
|
unsafe {
|
|
*self.0 += 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn work(mut progress: ProgressCounter) -> JoinHandle<()> {
|
|
spawn(move || {
|
|
let mut rng = {
|
|
use rand::SeedableRng;
|
|
rand_xoshiro::Xoshiro256StarStar::from_rng(rand::thread_rng()).unwrap()
|
|
};
|
|
|
|
loop {
|
|
let key = cpu::generate_privkey(&mut rng);
|
|
let pub_key = cpu::get_pubkey(&key);
|
|
|
|
progress.incr();
|
|
|
|
// b64(pub_key).starts_with("char/")
|
|
if pub_key[0] == 0x72 && pub_key[1] == 0x16 && pub_key[2] == 0xab && pub_key[3] >= 0xfc
|
|
{
|
|
let key_str = base64::encode(key);
|
|
let pub_key_str = base64::encode(pub_key);
|
|
println!("{} -> {}", key_str, pub_key_str);
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
const NUM_THREADS: usize = 32;
|
|
|
|
struct Progress([u64; NUM_THREADS]);
|
|
impl Progress {
|
|
fn new() -> Self {
|
|
Progress([0; NUM_THREADS])
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let mut progress = Box::pin(Progress::new());
|
|
let _handles: Vec<_> = (0..NUM_THREADS)
|
|
.map(|id| {
|
|
let ptr = unsafe { progress.0.as_mut_ptr().add(id) };
|
|
let progress = ProgressCounter(ptr);
|
|
work(progress)
|
|
})
|
|
.collect();
|
|
|
|
let mut last_total_progress = 0;
|
|
loop {
|
|
let total_progress = progress.0.iter().sum();
|
|
let delta = total_progress - last_total_progress;
|
|
last_total_progress = total_progress;
|
|
|
|
println!("Guess/sec ≈ {}", delta);
|
|
std::thread::sleep(Duration::from_millis(1000));
|
|
}
|
|
}
|