Implement bink2002

This commit is contained in:
Alex Page 2023-06-20 22:09:31 -04:00
parent d86b41e039
commit 6f648b6556
7 changed files with 351 additions and 22 deletions

View file

@ -5,10 +5,11 @@ use clap::Parser;
use openssl::{
bn::{BigNum, MsbOption},
ec::{EcGroup, EcPoint},
rand::rand_bytes,
};
use serde_json::{from_reader, from_str};
use crate::{bink1998, crypto::initialize_elliptic_curve};
use crate::{bink1998, bink2002, crypto::initialize_elliptic_curve};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
@ -230,7 +231,40 @@ impl Cli {
}
fn bink2002(&mut self) -> Result<()> {
todo!()
let p_channel_id = self.options.channel_id;
if self.options.verbose {
println!("> Channel ID: {p_channel_id:03}");
}
for _ in 0..self.options.num_keys {
let mut p_auth_info_bytes = [0_u8; 4];
rand_bytes(&mut p_auth_info_bytes)?;
let p_auth_info = u32::from_ne_bytes(p_auth_info_bytes) & ((1 << 10) - 1);
if self.options.verbose {
println!("> AuthInfo: {p_auth_info}");
}
let p_key = bink2002::generate(
&self.e_curve,
&self.gen_point,
&self.gen_order,
&self.private_key,
p_channel_id,
p_auth_info,
false,
)?;
Cli::print_key(&p_key);
println!("\n");
if bink2002::verify(&self.e_curve, &self.gen_point, &self.pub_point, &p_key)? {
self.count += 1;
}
}
println!("Success count: {}/{}", self.count, self.options.num_keys);
Ok(())
}
fn confirmation_id(&mut self) -> Result<()> {